<?
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();


$result = mysql_query ("SELECT * FROM pricol_img ORDER BY id DESC LIMIT 1");
$row = mysql_fetch_array($result);

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

$result11 = mysql_query ("SELECT * FROM pricol_img_rating WHERE id_user='$user[id]' AND id_img='$row[id]'");
$row11 = mysql_fetch_array($result11);

if ($row1['id_user'] != $user['id'])
{
if (isset($_POST['save']))
{
if (isset($_POST['msg']) && isset($user)){$msg=$_POST['msg'];}
$msg = stripcslashes(htmlspecialchars(trim($msg)));
if (strlen2($msg)>1024){$err='Сообщение слишком длинное';}
if (strlen2($msg)<2){$err='Короткое сообщение';}
if(!isset($err)){
mysql_query("INSERT INTO `pricol_img_komm` (`id_user`, `time`, `msg`, `id_img`) values('$user[id]', '$time', '".my_esc($msg)."', '$row[id]')");
mysql_query("UPDATE `user` SET `balls` = '".($user['balls'] + 10)."' WHERE id='$user[id]' LIMIT 1");
msg("Комментарий успешно добавлин + 10 LM");
}
}
}

err();

if (isset($_POST['save1']))
{
if (isset($_POST['go'])) {$go=intval($_POST['go']);}
if (isset($_POST['priz'])) {$priz=$_POST['priz'];}
mysql_query("UPDATE `pricol_img` SET `go` = '$go' WHERE `id` = '$row[id]' LIMIT 1");
mysql_query("UPDATE `pricol_img` SET `priz` = '$priz' WHERE `id` = '$row[id]' LIMIT 1");
msg("Настройка принята");	
}

	$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `pricol_img_komm` WHERE id_img='$row[id]'"),0);
	$k_page=k_page($k_post,$set['p_str']);
	$page=page($k_page);
	$start=$set['p_str']*$page-$set['p_str'];	

	$result2 = mysql_query ("SELECT * FROM pricol_img_komm WHERE id_img='$row[id]' ORDER BY id DESC LIMIT $start, $set[p_str]");
	$myrow2 = mysql_fetch_array($result2);

	
if (isset($user) && ($user['level']>$ank['level'] || $user['level']!=0 && $user['id']==$ank['id']))
{
if (isset($_GET['delete']))	
{
	if (isset($_GET['id'])) {$id = $_GET['id'];}
mysql_query("DELETE FROM `pricol_img_komm` WHERE `id` = '$id'");
msg ("Комментарий успешно удален");	
}
}


echo "<center><img src='files/$row[name].$row[ras]'></center><br /><br />";

if ($row['go'] == 0)
{
if ($row1['id_user'] != $user['id'])
{
if (isset($user))
{
echo "<div class='textmes'>";
echo "<form action='' method='post'>";
echo "Сообщение | <a href='/smiles/index.php'>Смайлы</a><br />\n<input name=\"msg\" type=\"text\" maxlength='600' value='' />\n";
echo "<input value=\"Отправить\" type=\"submit\" name=\"save\" />\n";
echo "</form>";
echo "</div>\n";
}
}
else
{
echo "<div class='gend'>";
echo "Вы уже оставили свой комментарий<br />";
echo "ждите начала голосования";
echo "</div>\n";	
}
}
else
{
echo "<div class='textmes'>";
echo "Началось голосование";
echo "</div>\n";		
}



if (mysql_num_rows ($result2) > 0)
{
do
{	
$ank=get_user($myrow2['id_user']);
echo "".online($ank['id'])."<a href='/info.php?id=$ank[id]'><span style=\"color:$ank[ncolor]\">$ank[nick]</span></a> \n";
if ($ank['obit']==0)
{
if ($ank['group_access']>1)echo "<img src='/img/tabor/admin_sign.gif'>\n";
}
echo "<br/> \n";
echo "<span style=\"color:$ank[mcolor]\">\n";
echo output_text($myrow2['msg'])."<br />\n";
echo "</span>\n";
echo "<div style='text-align: right;'><font color='#afb0a3'> ".vremja($myrow2['time'])." </font><img src='/img/microblog/eye.png'></img>\n";
if (isset($user) && ($user['level']>$ank['level'] || $user['level']!=0 && $user['id']==$ank['id']))
echo " <a href='?id=$myrow2[id]&amp;delete'><b><font color='red'><img src='/style/icons/bdel.png' alt='' class='icon'/></font></b></a>\n";


if ($row['go'] == 1)
{
if ($row11['id_user'] != $user['id'])
{
if ($myrow2['id_user'] != $user['id'])
{
echo "<br /><a href='rating.php?id=$myrow2[id]&amp;id_img=$row[id]&amp;rating=1'><img src='/style/ocenki/1.png' alt='' class='icon'/></a> ";
echo "<a href='rating.php?id=$myrow2[id]&amp;id_img=$row[id]&amp;rating=2'><img src='/style/ocenki/2.png' alt='' class='icon'/></a> ";
echo "<a href='rating.php?id=$myrow2[id]&amp;id_img=$row[id]&amp;rating=3'><img src='/style/ocenki/3.png' alt='' class='icon'/></a> ";
echo "<a href='rating.php?id=$myrow2[id]&∓id_img=$row[id]&amp;rating=4'><img src='/style/ocenki/4.png' alt='' class='icon'/></a> ";
echo "<a href='rating.php?id=$myrow2[id]&amp;id_img=$row[id]&amp;rating=5'><img src='/style/ocenki/5.png' alt='' class='icon'/></a><br />";
}
}
else
{
echo "<br />Рейтинг: $myrow2[rating]<br />";
}
}

echo "</div>\n";
echo "</div><br />\n";
}
while ($myrow2 = mysql_fetch_array($result2));
}
else
{
echo "Нет не одного комментария<br /><br />";
}

if ($k_page>1){str("?id=$user[id]&id=$row[id]&",$k_page,$page);} // Вывод страниц

if ($row['go'] == 1)
{
$result100 = mysql_query ("SELECT * FROM pricol_img_komm WHERE id_img = '$row[id]' ORDER BY rating DESC LIMIT 1");
$row100 = mysql_fetch_array($result100);

$ank1=get_user($row100['id_user']);

echo "<div class='tmn'>";
echo "Луччший комментарий";
echo "</div>\n";
	if (!$set['web'])
{
echo "<div class='menu_razd'>";
}
echo "Автор: <a href='/info.php?id=$ank1[id]'>$ank1[nick]</a><br />";
echo "Рейтинг: $row100[rating]";
echo "</div><br />\n";
}

echo "<img src='/1/status.gif' alt='' class='icon'/>\n";
echo "<a href='all_img.php'>прошлые картинки</a><br />\n";
echo "<img src='img/rules.png' alt='' class='icon'/>\n";
echo "<a href='rules.php'>Правила</a><br />\n";
echo "<img src='img/priz.png' alt='' class='icon'/>\n";
echo "<a href='priz.php?id=$row[id]'>Призы</a><br />\n";
if ($user['level'] > 3)
{
if (!isset($_GET['admin']))
{
echo "<br /><img src='img/admin.png' alt='' class='icon'/>\n";
echo "<a href='?admin'>Мини админка</a><br />\n";
}
else
{
echo "<br /><img src='/style/back.gif' alt='' class='icon'/>\n";
echo "<a href='index.php'>Закрыть админку</a><br /><br />\n";	
}
if (isset($_GET['admin']))
{
echo "<img src='img/load.png' alt='' class='icon'/>\n";
echo "<a href='upload.php'>Загрузить картинку</a><br />\n";
echo "<form action='' method='post'>";
echo "Голосование:<br />\n<select name='go'>\n";
echo "<option value='1'".($row['go']==1?" selected='selected'":null).">Да</option>\n";
echo "<option value='0'".($row['go']==0?" selected='selected'":null).">Нет</option>\n";
echo "</select><br />";
echo "Приз для этой картинки <br /><input name=\"priz\" type=\"text\" maxlength='600' value='$row[priz]' /><br />\n";
echo "<input value=\"Ok\" type=\"submit\" name=\"save1\" />\n";
echo "</form>";
}
}

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