<?
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';


$set['title']='Рейтинг сообщения';
include_once '../sys/inc/thead.php';
title();


if (isset($_GET['id'])) {$id = $_GET['id'];}
if (isset($_GET['id_img'])) {$id_img = $_GET['id_img'];}
if (isset($_GET['rating'])) {$rating = $_GET['rating'];}

$result1 = mysql_query ("SELECT * FROM pricol_img_rating WHERE id_user='$user[id]' AND id_komm='$id'");
$row1 = mysql_fetch_array($result1);

if ($row1['id_user'] != $user['id'])
{
	if ($rating > 5)
	{
	$err[]="Ошибк, максимальная оценка 5";
	err();
	echo"<div class='foot'>";
	echo "<a href='/pricol_img/'>Обратно</a>";
	echo"</div>";
	}
	else
	{
mysql_query("INSERT INTO `pricol_img_rating` (`id_user`, `id_komm`, `id_img`, `rating`) values('$user[id]', '$id', '$id_img', '$rating')");
$sum = mysql_result(mysql_query("SELECT SUM(`rating`) FROM `pricol_img_rating` WHERE id_komm='$id'"),0);
mysql_query("UPDATE `pricol_img_komm` SET `rating` = '$sum' WHERE id='$id' LIMIT 1");
msg ('Ваша оценка принята');	
echo "<img src='/style/back.gif' alt='' class='icon'/>\n";
echo "<a href='/pricol_img/'>Обратно</a>";
	}
}
else
{
$err[]="Ошибк, вы уже голосовали";
err();	
echo "<img src='/style/back.gif' alt='' class='icon'/>\n";
echo "<a href='/pricol_img/'>Обратно</a>";
}


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