<?

	// Dcms-Fiera

	// http://dcms-help.ru

	// ShaMan



include_once '../../sys/inc/start.php';

include_once '../../sys/inc/compress.php';

include_once '../../sys/inc/sess.php';

include_once '../../sys/inc/home.php';

include_once '../../sys/inc/settings.php';

include_once '../../sys/inc/db_connect.php';

include_once '../../sys/inc/ipua.php';

include_once '../../sys/inc/fnc.php';

include_once '../../sys/inc/user.php';





if (isset($user))$ank['id']=$user['id'];

if (isset($_GET['id']))$ank['id']=intval($_GET['id']);





$ank=get_user($ank['id']);

if(!$ank){header("Location: /index.php?".SID);exit;}





$set['title']=$ank['nick'].' - отзывы '; // заголовок страницы

include_once '../../sys/inc/thead.php';

title();

aut();





if ((!isset($_SESSION['refer']) || $_SESSION['refer']==NULL)

&& isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER']!=NULL &&

!preg_match('#info\.php#',$_SERVER['HTTP_REFERER']))

$_SESSION['refer']=str_replace('&','&amp;',preg_replace('#^http://[^/]*/#','/', $_SERVER['HTTP_REFERER']));





if (isset($_POST['rating']) && isset($user) && isset($_POST['msg']) && $user['id']!=$ank['id'] && $user['rating']>=2 && mysql_result(mysql_query("SELECT SUM(`rating`) FROM `user_voice2` WHERE `id_kont` = '$user[id]'"),0)>=0)

{



$msg=mysql_real_escape_string($_POST['msg']);



if (strlen($msg)<3)$err='Короткий Отзыв';

if (strlen($msg)>1024)$err='Длиный Отзыв';



elseif (mysql_result(mysql_query("SELECT COUNT(*) FROM `user_voice2` WHERE `id_user` = '$user[id]' AND `msg` = '".my_esc($msg)."' LIMIT 1"),0)!=0){$err='Ваш отзыв повторяется';}



if (!isset($err))

{





$new_r=min(max(@intval($_POST['rating']),-2),2);

mysql_query("DELETE FROM `user_voice2` WHERE `id_user` = '$user[id]' AND `id_kont` = '$ank[id]' LIMIT 1");



if ($new_r) 

mysql_query("INSERT INTO `user_voice2` (`rating`, `id_user`, `id_kont`, `msg`, `time`) VALUES ('$new_r','$user[id]','$ank[id]', '$msg', '$time')");



$ank['rating']=intval(mysql_result(mysql_query("SELECT SUM(`rating`) FROM `user_voice2` WHERE `id_kont` = '$ank[id]'"),0));

mysql_query("UPDATE `user` SET `rating` = '$ank[rating]' WHERE `id` = '$ank[id]' LIMIT 1");



if ($new_r>0)

mysql_query("INSERT INTO `mail` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$ank[id]', '$user[nick] оставил о Вас [url=/user/info/who_rating.php]положительный отзыв[/url]', '$time')");

if ($new_r<0)

mysql_query("INSERT INTO `mail` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$ank[id]', '$user[nick] оставил о Вас [url=/user/info/who_rating.php]негативный отзыв[/url]', '$time')");

if ($new_r==0)

mysql_query("INSERT INTO `mail` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$ank[id]', '$user[nick] оставил о Вас [url=/user/info/who_rating.php]нейтральный отзыв[/url]', '$time')");



mysql_query("UPDATE `user` SET `rating_tmp` = '".($user['rating_tmp']+1)."' WHERE `id` = '$user[id]' LIMIT 1");



msg('Ваше мнение о пользователе успешно изменено');

}

}

err();



if (isset($user))$ank['id']=$user['id'];

if (isset($_GET['id']))$ank['id']=intval($_GET['id']);



if (isset($user) && $user['id']!=$ank['id'] && $user['rating']>=2 && mysql_result(mysql_query("SELECT SUM(`rating`) FROM `user_voice2` WHERE `id_kont` = '$user[id]'"),0)>=0)

{

echo "<b>Ваше отношение:</b><br />\n";

// мое отношение к пользователю





$my_r=intval(@mysql_result(mysql_query("SELECT `rating` FROM `user_voice2` WHERE `id_user` = '$user[id]' AND `id_kont` = '$ank[id]'"),0));

echo "<form method='post' action='?id=$ank[id]&amp;$passgen'>\n";

echo "<select name='rating'>\n";

echo "<option value='2' ".($my_r==2?'selected="selected"':null).">Замечательное</option>\n";

echo "<option value='1' ".($my_r==1?'selected="selected"':null).">Положительное</option>\n";

echo "<option value='0' ".($my_r==0?'selected="selected"':null).">Нейтральное</option>\n";

echo "<option value='-1' ".($my_r==-1?'selected="selected"':null).">Не очень...</option>\n";

echo "<option value='-2' ".($my_r==-2?'selected="selected"':null).">Негативное</option>\n";

echo "</select><br />\n";

echo "Текст: <br />";

echo "<textarea name=\"msg\"></textarea><br />";

echo "<input type='submit' value='GO' />\n";

echo "</form>\n";

//echo "<br />\n";

}elseif (isset($user)){

echo "<div class='mess'>";

echo 'Чтобы оставить отзыв, вам необходимо набрать 2 или более % рейтинга.';

echo "</div>";

}



$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `user_voice2` WHERE `id_kont` = '".$ank['id']."'"),0);

$k_page=k_page($k_post,$set['p_str']);

$page=page($k_page);

$start=$set['p_str']*$page-$set['p_str'];

echo "<table class='post'>\n";

if ($k_post==0)

{

echo "   <tr>\n";

echo "  <td class='p_t'>\n";

echo "Нет положительных отзывов\n";

echo "  </td>\n";

echo "   </tr>\n";



}



$q=mysql_query("SELECT * FROM `user_voice2` WHERE `id_kont` = '$ank[id]' ORDER BY `time` DESC LIMIT $start, $set[p_str]");

while ($post = mysql_fetch_assoc($q))

{

$ank=get_user($post['id_user']);

echo "   <tr>\n";

if ($set['set_show_icon']==2){

echo "  <td class='icon48' rowspan='2'>\n";

avatar($ank['id']);

echo "  </td>\n";

}

elseif ($set['set_show_icon']==1)

{

echo "  <td class='icon14'>\n";

echo "".status($ank['id'])."";

echo "  </td>\n";

}

echo "  <td class='p_t'>\n";

echo " ".group($ank['id'])." <a href='/info.php?id=$ank[id]'>$ank[nick]</a> \n";

echo "".medal($ank['id'])." ".online($ank['id'])." (".vremja($post['time']).")";

echo "  </td>\n";

echo "   </tr>\n";

echo "   <tr>\n";

if ($set['set_show_icon']==1)echo "  <td class='p_m' colspan='2'>\n"; else echo "  <td class='p_m'>\n";

echo "Отзыв:<br />\n";

switch ($post['rating'])

{

case 2:echo "Замечательный<br />\n";	break;

case 1:echo "Положительный<br />\n";	break;

case 0:echo "Нейтральный<br />\n";	break;

case -1:echo "Не очень...<br />\n";	break;

case -2:echo "Негативный<br />\n";	break;

}

$msg=stripcslashes(htmlspecialchars($post['msg']));

echo "$msg<br />\n";

echo "  </td>\n";

echo "   </tr>\n";



}

echo "</table>\n";





if ($k_page>1)str('who_rating.php?id='.$user_id.'&amp;',$k_page,$page); // Вывод страниц



include_once '../../sys/inc/tfoot.php';

?>