<?php
if(!defined('DATALIFEENGINE'))
{
  die("Hacking attempt!");
}
	if ($cstart) { $post_num_id = $cstart; }
	
	if ($fixpost and $cstart)
	{
		$post_num_id = $post_num_id - 1;
	}
	
	if ($check_moderator)
	{
		$deny_edit_post = moderator_value('edit_post', $forum_id, $m_member);
		
		$deny_del_post = moderator_value('delete_post', $forum_id, $m_member);;
	}
	
	if ($user_group[$member_id['user_group']]['forum_post_edit']){
		$group_post_edit = true;
	}else{
        $group_post_edit = false;
    }
	
	if ($user_group[$member_id['user_group']]['forum_post_del']){
		$group_post_del = true;
	}else{
		$group_post_del = false;
	}
	
	$posts_found = false;
	
	while ($row = $db->get_row($result_posts))
	{
		$post_num_id++;
		
		if (!$row['user_group']) $row['user_group'] = 5;
		
		if ($ajax_adds) $post_num_id = "--";
		
		if ($row['hidden'] == "1")
		{
			if ($check_moderator)
			{
				$row['post_text'] = "<div class=\"hidden_post\">{$f_lang['h_post']}:<br />".$row['post_text']."</div>";
			}
			else
			{
				$row['post_text'] = "<div class=\"hidden_post\">{$f_lang['h_post']}</div>";
			}
		}
		
		if ($search_text)
		{
			$row['post_text'] = hilites($search_text, $row['post_text']);
		}

        //start Õàê ÒÑ by SaNcHeS

		if($row['post_author'] == $row_topic['author_topic'])
	    {
            $ts = "<b>Àâòîð òåìû</b><br><br>";
        }
        //end Õàê ÒÑ by SaNcHeS

// ********************************************************************************
// LOAD TEMPLATE
// ********************************************************************************	
		$tpl->load_template($tpl_dir.'post.tpl');
		
		if ($row['pid'] == $first_post){
			$tpl->set('{post_id}', "<a href=\"javascript:PostLink({$row['pid']});\" name=\"post-{$row['pid']}\">1</a>");
		} else {
			$tpl->set('{post_id}', "<a href=\"javascript:PostLink({$row['pid']});\" name=\"post-{$row['pid']}\">{$post_num_id}</a>");
		}
		
		if ($row['edit_time'] and $show_edit_info)
		$tpl->set('{edit-info}', "<br /><span class='edit-info'>{$f_lang['edit_info']}&nbsp;<b>{$row['edit_user']}</b> - ".show_date($row['edit_time'])."</span>");
		else $tpl->set('{edit-info}', "");
		
		$go_page = "onClick=\"return dropdownmenu(this, event, FUserMenu('".urlencode($row['name'])."', '".$row['user_id']."', '".$member_id['user_group']."', '$a_forum_url'), '170px')\" onMouseout=\"delayhidemenu()\"";

		if ($row['is_register'])
		$tpl->set('{author}', "<a {$go_page} href=\"#\">{$row['post_author']}</a>");
		else $tpl->set('{author}', "<a href=\"mailto:".$row['e_mail']."\">{$row['post_author']}</a>");
		
		$tpl->set( '{topic_url}', "");

        if( $row['foto'] and (file_exists( ROOT_DIR . "/uploads/fotos/" . $row['foto'] )) ) $tpl->set( '{foto}', $config['http_home_url'] . "uploads/fotos/" . $row['foto'] );
        else $tpl->set( '{foto}', "{THEME}/images/noavatar.png" );
		
		if ($row['icq']) $tpl->set('{icq}', stripslashes($row['icq']));
		else $tpl->set('{icq}', '--');

        //start Õàê ÒÑ by SaNcHeS
		if ($ts) $tpl->set('{ts}', '');
		if($row['post_author'] == $row_topic['author_topic']){
			if ($ts) $tpl->set('{ts}', $ts);
			else $tpl->set('{ts}');
		}
		//end Õàê ÒÑ by SaNcHeS
		
		if ($row['land']) $tpl->set('{land}', stripslashes($row['land']));
		else $tpl->set('{land}', '--');
		
		if ($row['fullname']) $tpl->set('{fullname}', stripslashes($row['fullname']));
		else $tpl->set('{fullname}', '--');
		
		if ($row['reg_date']) $tpl->set('{registration}', langdate("j.m.Y", $row['reg_date']));
		else $tpl->set('{registration}', '--');
		
		if ($row['is_register'] AND $row['signature'])
		{
			$tpl->set_block("'\\[signature\\](.*?)\\[/signature\\]'si","\\1");
			$tpl->set('{signature}', stripslashes($row['signature']));
		}
		else $tpl->set_block("'\\[signature\\](.*?)\\[/signature\\]'si","");

        if ($user_group[$row['user_group']]['colour']){
      			$group_span = $user_group[$row['user_group']]['colour'];
      			$group_name =  "<span style=\"color:{$group_span}\">".$user_group[$row['user_group']]['group_name']."</span>";
      		}else{
      			$group_name = $user_group[$row['user_group']]['group_name'];
      		}
		
		if ($row['banned']){$group_name = "BANNED";}		
		$tpl->set('{group-name}', $group_name);		
		$tpl->set('{post-num}', intval($row['forum_post']));
		$tpl->set('{news-num}', intval($row['news_num']));
		$tpl->set('{comm-num}', intval($row['comm_num']));

// ********************************************************************************
// POST SELECTED
// ********************************************************************************	
		if ($check_moderator AND $post_num_id != 1) $tpl->set('{selected}', "<input OnClick=\"select_id('{$row['pid']}');\" type='checkbox' name=\"sid[{$row['pid']}]\" value=\"{$row['pid']}\">");
		else $tpl->set('{selected}', "");

// ********************************************************************************
// POST DATE
// ********************************************************************************	
		$row['post_date'] = strtotime($row['post_date']);
		
		$tpl->set('{post-date}', show_date($row['post_date']));
		
		if (!$forum_config['mod_report'] and $is_logged){
			$tpl->set('[report]',"<a href=\"{$a_forum_url}act=_topic&code=report&tid={$tid}&pid={$post_num_id}\">");
			$tpl->set('[/report]',"</a>");
		} else {
			$tpl->set_block("'\\[report\\](.*?)\\[/report\\]'si","");
		}

// ********************************************************************************
// FAST
// ********************************************************************************
		if ($check_write AND !$row['hidden'])
		{
			$tpl->set('[fast]',"<a onmouseover=\"dle_copy_quote('".str_replace( array(" ", "&#039;"), array("&nbsp;", "&amp;#039;"), $row['post_author'] )."');\" href=\"#\" onClick=\"forum_ins('".str_replace( array(" ", "&#039;"), array("&nbsp;", "&amp;#039;"), $row['post_author'] )."'); ShowHide('sreply', 'open'); return false;\"\">");
			$tpl->set('[/fast]',"</a>");
		}
		else
		{
			$tpl->set_block("'\\[fast\\](.*?)\\[/fast\\]'si","");
		}

// ********************************************************************************
// REPUTATION
// ********************************************************************************	
        @include (SYSTEM_DIR.'/modules/reputation.php');
		
		if ($check_moderator)
		$tpl->set('{ip}', "IP: <a onClick=\"return dropdownmenu(this, event, IPMenu('".$row['post_ip']."', '".$lang['ip_info']."', '".$lang['ip_tools']."', '".$lang['ip_ban']."'), '190px')\" onMouseout=\"delayhidemenu()\" href=\"http://www.nic.ru/whois/?ip={$row['post_ip']}\" target=\"_blank\">{$row['post_ip']}</a>");
		else $tpl->set('{ip}', '');

// ********************************************************************************
// POST EDIT
// ********************************************************************************	
		if (($member_id['name'] == $row['post_author']) AND $group_post_edit AND !$row['hidden'] OR $deny_edit_post){
			$tpl->set('[post-edit]',"<a onClick=\"return dropdownmenu(this, event, PostEditMenu('$row[pid]', '$a_forum_url', '$page', '$post_num_id'), '170px')\" onMouseout=\"delayhidemenu()\" href=\"#\">");
			$tpl->set('[/post-edit]',"</a>");
		}else{
			$tpl->set_block("'\\[post-edit\\](.*?)\\[/post-edit\\]'si","");
		}

// ********************************************************************************
// POST DEL
// ********************************************************************************	
		if (($member_id['name'] == $row['post_author']) AND $group_post_del AND !$row['hidden'] OR $deny_del_post)
		{
			if ($post_num_id != 1)
			{
				$tpl->set('[post-del]',"<a href=\"javascript:postDelete('".$a_forum_url."act=post&code=04&selected_id=".$row['pid']."')\">");
				$tpl->set('[/post-del]',"</a>");
			}
			else
			{
				$tpl->set_block("'\\[post-del\\](.*?)\\[/post-del\\]'si","");
			}
		}
		else
		{
			$tpl->set_block("'\\[post-del\\](.*?)\\[/post-del\\]'si","");
		}
		
// ********************************************************************************
// POST TEXT
// ********************************************************************************			
		$tpl->set('{text}', "<div id='post-id-".$row['pid']."'>".stripslashes($row['post_text'])."</div>");
		
		$tpl->compile('posts');
		
		$tpl->clear();
		
		$posts_found = true;
	}
	
	if (stristr ($tpl->result['posts'], "[attachment="))
	{
		require_once SYSTEM_DIR.'/forum/sources/components/attachment.php';
	}
	
	$tpl->result['posts'] .= "\n<span id='ajax-post'></span>\n";
?>