<?php
if(!defined('DATALIFEENGINE')){die("Hacking attempt!");}

if (intval($row['user_id']) != 0)
{
	if ($row['repa_off'] == 0)
	{
        $repa_mod_mas = explode ("|", $row['repa_mod']);
     	$repa_type = "(<font color=green><b>".$repa_mod_mas[0]."</b></font><b>|</b><font color=red><b>".$repa_mod_mas[1]."</b></font>)";

        $repa_minus = "<a OnClick=\"Reputation('0', '$row[user_id]');\"><img src='{THEME}/images/repa_dn.gif' alt='-' border='0' /></a>&nbsp;";
        $repa_plus = "&nbsp;<a OnClick=\"Reputation('1', '$row[user_id]');\"><img src='{THEME}/images/repa_up.gif' alt='+' border='0' /></a>";

		$tpl->set('{repa}', "<span id='repa-".$row['user_id']."'>".$repa_plus." <a href=\"".$config['http_home_url']."user/reputation/".urlencode($row['name'])."/\">".$repa_type."</a> ".$repa_minus."</span>");
	} else {
		$tpl->set('{repa}', "Выкл.");
	}
}
else
{
	$tpl->set('{repa}', " 0");
}

if( $_REQUEST['action'] == "list" ) {
    $user = $db->safesql( htmlspecialchars( urldecode( $_REQUEST['user'] ) ) );

    include_once SYSTEM_DIR.'/data/repa.php';
   	include_once ROOT_DIR . '/language/' . $config['langs'] . '/website_repa.lng';

    if($repa_cf['status']=='no'){
    	msgbox ($lang['all_err_1'], $lang_repa['gen_status_off']);
    }else{
    	$sql_result = $db->query("SELECT * FROM " . USERPREFIX . "_users where name = '$user'");
    	while($row = $db->get_row($sql_result)){
    		$user_found = TRUE;
    		$repa_off = $row['repa_off'];
    	}

    	if ($repa_off == 0){
            $limit = intval($repa_cf['res_site']);
            $pass = $db->super_query("SELECT COUNT(*) as count FROM `" . USERPREFIX . "_reputation` where `komu` = '$user'");
            $posts = $pass['count'];

    	if($posts == 0)
    	{
    		if ($user_found == TRUE)
    		{
                $tpl->load_template('reputation.tpl');
                $tpl->set('{usertitle}',"<a href=\"".$config['http_home_url']."user/".urlencode($user)."/\">".$user."</a>");
                $tpl->set('{history_content}', 'Изменений небыло');
    		}
    	}else{
    		$page = intval( $_REQUEST['cstart'] );
            $total = intval( ( ( $posts - 1 ) / $limit ) + 1 );
        	if( $page <= 0 ) $page = 1;
        	if( $page > $total ) $page = $total;
            $start = $page * $limit - $limit;

            $i = $start;

            $result = $db->query("SELECT * FROM `" . USERPREFIX . "_reputation` WHERE `komu`='$user' ORDER BY `date` DESC LIMIT " . $start . "," . $limit);
            $repa_list = "<table width=100% class=userstop><tr bgcolor=#F2F2F2><td><div align=center><strong>Автор</strong></div></td><td><div align=center><strong>Комментарий</strong></div></td><td><div align=center><strong>Дата</strong></div></td><td></td></tr>";
    		while($row = $db->get_row($result))
    		{
                $i ++;

    			if ($repa_cf['robot'] == $row['author']) $auth_link = $row['author'];
    			else{$auth_link = "<a href=\"".$config['http_home_url']."user/".urlencode($row['author'])."/\">".$row['author']."</a>";}

    			switch($row['how'])
    			{
    			     	case($row['how'] > 0): $how = '<img src="{THEME}/images/repa_up.gif" alt="'.$lang_repa['repa_up'].'">'; break;
    	     			case($row['how'] < 0): $how = '<img src="{THEME}/images/repa_dn.gif" alt="'.$lang_repa['repa_down'].'">'; break;
    			     	case($row['how'] == "totalminus"): $how = '<img src="{THEME}/images/repa_adm.png" alt="'.$lang_repa['repa_adm'].'" title="Понижение на '.$repa_cf[adm_minus].' пунктов">'; break;
    			     	case($row['how'] == "totalplus"): $how = '<img src="{THEME}/images/repa_adm_p.png" alt="'.$lang_repa['repa_adm'].'" title="Повышение на '.$repa_cf[adm_plus].' пунктов">'; break;
    			}
    			$row['date'] = strtotime($row['date']);
                if( date( Ymd, $row['date'] ) == date( Ymd, $_TIME ) )$date = $lang['time_heute'] . langdate( ", H:i", $row['date'] );
               	elseif( date( Ymd, $row['date'] ) == date( Ymd, ($_TIME - 86400) )  )$date = $lang['time_gestern'] . langdate( ", H:i", $row['date'] );
               	else $date = langdate( $config['timestamp_active'], $row['date'] );

    			if ($repa_cf['comm_page'] == 1 AND $row['url_page']) $row['text'] .= "<br>Изменено на этой <a href=\"".$row['url_page']."\">странице</a>.";

                $repa_list .= "<tr><td width=18% align=center>".$auth_link."</td><td width=40% align=center>".$row['text']."</td><td width=15% align=center>".$date."</td><td width=2% align=center>".$how."</td></tr>";
    		}
            $repa_list .= "</table>";
    		$tpl->load_template('reputation.tpl');
         	$tpl->set('{usertitle}',"<a href=\"".$config['http_home_url']."user/".urlencode($user)."/\">".$user."</a>");
            $tpl->set('{history_content}', $repa_list);
            $tpl->compile('content');
            $tpl->clear();

            $nav = "/user/reputation/".$user."/page/{page}";
            CreateNavigation( $nav, $page, $total );
    	}
    	$tpl->compile('content');
    	$tpl->clear();
        $db->free();
    	}
    	else msgbox ($lang['all_err_1'], "Пользователь отключил репутацию в своих настройках. Вы не можете просмотреть историю его репутации.<br /><a href=\"javascript:history.go(-1)\">Вернуться назад.</a>");
    	if ($user_found == FALSE) { msgbox ($lang['all_err_1'], $lang['news_err_26']); }
    }
}
?>