<?php
include_once '../sys/inc/start.php';
dpanel::check_access();
$doc = new document(2);
$doc -> title = 'Жалобы';



if (!empty($_GET['id_ank']) && !empty($_GET['code']))
{
$ank = new user($_GET['id_ank']);
$code=(string)$_GET['code'];

$codes = new menu_code('code');

if (!$ank->id)$doc->err('Не выбран пользователь');
elseif (!isset($codes->menu_arr[$code]))$doc->err('Не выбрано нарушение');
else
{
$doc->title='Жалобы на "'.$ank->login.'"';

if (isset($_GET['delete']))
{

mysql_query("UPDATE `complaints` SET `processed` = '1'  WHERE `id_ank` = '$ank->id' AND `code` = '".my_esc($code)."' LIMIT 1");

$doc->msg('Нарушение помечено как обработанное');

}

$posts = array();
$pages = new pages;
$pages->posts = mysql_result(mysql_query("SELECT COUNT(*) FROM `complaints` WHERE `processed` = '0' AND `id_ank` = '$ank->id' AND `code` = '".my_esc($code)."'"), 0);
$pages->this_page(); // получаем текущую страницу






$q = mysql_query("SELECT `comment`, `link`, COUNT(*) as `count`, MAX(`time`) as `time` FROM `complaints` WHERE `processed` = '0' AND `id_ank` = '$ank->id' AND `code` = '".my_esc($code)."' GROUP BY `link` ORDER BY `count` DESC LIMIT {$pages->my_start()}, {$pages->items_per_page}");
while ($c=mysql_fetch_assoc($q)) {
$t='<a href="user.ban.php?id_ank='.$ank->id.'&amp;code='.urlencode($code).'&amp;link='.urlencode($c['link']).'">'.$c['count'].' '.misc::number($c['count'],'жалоба','жалобы','жалоб').'</a> ('.vremja($c['time']).')';
$p='Нарушение: <a'.($dcms->browser_type=='web'?' target="_blank"':null).' href="'.for_value($c['link']).'">'.for_value($c['link']).'</a><br />';
$p.=output_text($c['comment']);

$act=array();
$act[]=array('delete','?id_ank='.$ank->id.'&amp;code='.urlencode($code).'&amp;link='.urlencode($c['link']).'&amp;delete');

$posts[]=array('title'=>$t,'post'=>$p,'act'=>$act);
}
if (!$posts)$posts[]=array('icon'=>array('size'=>'small','src'=>'/sys/images/icons/empty.png'),'title'=>'Жалобы отсутствуют');

$show = new design();
$show->assign('post',$posts);
$show->display('design.listing.tpl');

$pages->listing("?id_ank=$ank->id&amp;code=".urlencode($c['code']).'&amp;'); // вывод страниц



$doc->ret('Все жалобы','?');
$doc->ret('Админка','./');
exit;
}
}




$posts = array();
$pages = new pages;
$pages->posts = mysql_result(mysql_query("SELECT COUNT(DISTINCT `id_ank`, `code`) FROM `complaints` WHERE `processed` = '0'"), 0);
$pages->this_page(); // получаем текущую страницу



$q = mysql_query("SELECT *, COUNT(*) as `count` FROM `complaints` WHERE `processed` = '0' GROUP BY `id_ank`, `code` ORDER BY `count` LIMIT {$pages->my_start()}, {$pages->items_per_page}");
while ($c=mysql_fetch_assoc($q)) {
$ank=new user($c['id_ank']);
$t="<a href='?id_ank=$c[id_ank]&amp;code=".urlencode($c['code'])."'>".$ank->nick.'</a>'.($c['count']>1?' ('.$c['count'].')':null);

$p=output_text($c['code']);
$posts[]=array('title'=>$t,'post'=>$p);
}
if (!$posts)$posts[]=array('icon'=>array('size'=>'small','src'=>'/sys/images/icons/empty.png'),'title'=>'Жалобы отсутствуют');

$show = new design();
$show->assign('post',$posts);
$show->display('design.listing.tpl');

$pages->listing("?"); // вывод страниц




$doc->ret('Админка','./');

?>
