<?php
include_once '../../sys/fnc.php';

if (!isset($user)) {
    header('location: /');
    exit;
}
$title = 'Кабинет';
include_once '../../sys/head.php';

$hist_money = mysql_num_rows(mysql_query("SELECT * FROM `history_money` WHERE `user` = '$user->id'"));
$products_kol = mysql_num_rows(mysql_query("SELECT * FROM `my_orders` WHERE `id_user` = '$user->id'"));
// $s_notice = mysql_num_rows(mysql_query("SELECT * FROM `system_notice` WHERE `id_user` = '$user->id'"));
// $new_notice = mysql_num_rows(mysql_query("SELECT * FROM `system_notice` WHERE `id_user` = '$user->id' AND `chit` = '1'"));
$ref_kol = mysql_num_rows(mysql_query("SELECT * FROM `userref` WHERE `user_id` = '$user->id'"));
$ref_suma = mysql_result(mysql_query("SELECT sum(profit_suma) FROM `userref` WHERE `user_id` = '$user->id'"), 0);
$logs_user = mysql_result(mysql_query("SELECT COUNT(*) FROM `logs_user` WHERE `id_user` = '$user->id'"),0);

echo '<div class="razdel2">Профиль</div>
<a class="link2" href="/cabinet/profile/"><span class="arrow"><img src="/style/img/icon2.png" alt="icon" /> Профайл </span></a>

<a class="link2" href="/cabinet/logs/"><span class="arrow"><img src="/style/img/icon2.png" alt="icon" /> Логи входа </span></a>



<div class="razdel2">Биллинг</div>
<a class="link2" href="#"><span class="arrow"><img src="/style/img/icon2.png" alt="icon" /> Баланс ('.sprintf("%.02f", $user->wmr).' рублей) </span></a>
<a class="link2" href="/cabinet/balance/"><span class="arrow"><img src="/style/img/icon2.png" alt="icon" /> Пополнить Баланс </span></a>
<a class="link2" href="/cabinet/ref/"><span class="arrow"><img src="/style/img/icon2.png" alt="icon" /> Рефералы ['.$ref_kol.' |'.sprintf("%.02f", $ref_suma).' Руб.]</span></a>
<a class="link2" href="/cabinet/history/"><span class="arrow"><img src="/style/img/icon2.png" alt="icon" /> Движение средств ['.$hist_money.']</span></a>
<a class="link2" href="/cabinet/uslug/"><span class="arrow"><img src="/style/img/icon2.png" alt="icon" /> Заказаные услуги ['.$products_kol.']</span></a>
<a class="link2" href="/tafifs/"><span class="arrow"><img src="/style/img/icon2.png" alt="icon" /> Заказать услугу </span></a>

<div class="razdel2">Дополнительно</div>';
echo "<a class='link2' href='/tickets/'><span class='arrow'><img src='/style/img/icon2.png' alt='icon' /> Тикеты 
(".($t_new > 0 ? '<font color="#59983a">'.$t_new.'</font> /' : '')."</b> ".mysql_result(mysql_query("SELECT COUNT(*) FROM `tickets` WHERE `user` = '$user->id' AND `user_read` = '1' AND `closed` = '0'"), 0)." / <font color='red'>".mysql_result(mysql_query("SELECT COUNT(*) FROM `tickets` WHERE `closed` = '1'"), 0)."
</font>) </span></a>";
if ($user->position == 'admin'){
$t_new = mysql_result(mysql_query("SELECT COUNT(*) FROM `tickets` WHERE `closed` = '0' AND `read` = '0'"), 0);
echo $div->div_menu." <a class='link2' href='".$HOME."/scripts/tickets/admin_list.php?act=other'><span class='arrow'><img src='/style/img/icon2.png' alt='icon' />Тикеты [Управление] 
<span class='count'>
(<b>".($t_new > 0 ? '<font color="#59983a">'.$t_new.'</font> /' : '')."</b> ".mysql_result(mysql_query("SELECT COUNT(*) FROM `tickets` WHERE `user` = '$user->id' AND `user_read` = '1' AND `closed` = '0'"), 0)." / <font color='red'>".mysql_result(mysql_query("SELECT COUNT(*) FROM `tickets` WHERE `closed` = '1'"), 0)."</font>) 
</span></span></a>  </div>";

echo $div->div_menu."<a class='link2' href='".$HOME."/scripts/tickets/admin_list.php?act=peredany_adm'><span class='arrow'><img src='/style/img/icon2.png' alt='icon' />Переданы General (".mysql_result(mysql_query("SELECT COUNT(*) FROM `tickets` WHERE `adm_transferred` = '1' AND `closed` = '0'"), 0).")</span></a></div>";
}
if ($user->position == 'admin')echo $div->div_menu.'<a class="link2" href="/admin"><span class="arrow"><img src="/style/img/icon2.png" alt="icon" />Админ управление</span></a></div>';

echo '<a class="link2" href="/?exit"><span class="arrow"><img src="/style/img/icon2.png" alt="icon" /> Выход </span></a>';
include_once '../../sys/foot.php';
?>