<?php

/**
 * @package     JohnCMS
 * @link        http://johncms.com
 * @copyright   Copyright (C) 2008-2011 JohnCMS Community
 * @license     LICENSE.txt (see attached file)
 * @version     VERSION.txt (see attached file)
 * @author      http://johncms.com/about
 */

defined('_IN_JOHNCMS') or die('Error: restricted access');
$headmod = 'office';
$textl = $lng_profile['my_office'];
require('../incfiles/head.php');

/*
-----------------------------------------------------------------
Проверяем права доступа
-----------------------------------------------------------------
*/
if ($user['id'] != $user_id) {
    echo functions::display_error($lng['access_forbidden']);
    require('../incfiles/end.php');
    exit;
}

/*
-----------------------------------------------------------------
Личный кабинет пользователя
-----------------------------------------------------------------
*/


			/*
				   echo'<div class="gmenu"><h3>Баланс: ' . $user['balans'] . '</h3>';
				  echo'<a href="/worldkassa"><i class="fa fa-rub" aria-hidden="true"></i> Ввод</a><br/ >';           
				   echo '<a href="/ok.php"><i class="fa fa-rub" aria-hidden="true"></i> Вывод</a></div>';
			*/
$total_photo = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_album_files` WHERE `user_id` = '$user_id'"), 0);
$total_friends = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_contact` WHERE `user_id`='$user_id' AND `type`='2' AND `friends`='1'"), 0);
$new_friends = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_contact` WHERE `from_id`='$user_id' AND `type`='2' AND `friends`='0';"), 0);
$online_friends = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_contact` LEFT JOIN `users` ON `cms_contact`.`from_id`=`users`.`id` WHERE `cms_contact`.`user_id`='$user_id' AND `cms_contact`.`type`='2' AND `cms_contact`.`friends`='1' AND `lastdate` > " . (time() - 300) . ""), 0);

echo '<div class="phdr">Мои страницы</div>' .
    '<div class="menu"><i class="fa fa-address-card-o" aria-hidden="true"></i> <a href="/users/profile.php">Анкета</a></div>' .
    '<div class="menu"><i class="fa fa-bar-chart" aria-hidden="true"></i> <a href="?act=stat">Статистика</a></div>'.
	'<div class="menu"><i class="fa fa-picture-o" aria-hidden="true"></i> <a href="album.php?act=list">' . $lng['photo_album'] . '</a>&#160;(' . $total_photo . ')</div>' .
    '<div class="menu"><i class="fa fa-book" aria-hidden="true"></i> <a href="profile.php?act=guestbook">' . $lng['guestbook'] . '</a>&#160;(' . $user['comm_count'] . ')</div>';
if ($rights >= 1) {
    $guest = counters::guestbook(2);
    echo '<div class="menu"><i class="fa fa-user" aria-hidden="true"></i> <a href="../guestbook/index.php?act=ga&amp;do=set">' . $lng['admin_club'] . '</a> (<span class="red">' . $guest . '</span>)</div>';
}
echo '';
/*
-----------------------------------------------------------------
Блок почты
-----------------------------------------------------------------
*/
echo '<div class="phdr">Моя почта</div>';
//Входящие сообщения
$count_input = mysql_result(mysql_query("
	SELECT COUNT(*) 
	FROM `cms_mail` 
	LEFT JOIN `cms_contact` 
	ON `cms_mail`.`user_id`=`cms_contact`.`from_id` 
	AND `cms_contact`.`user_id`='$user_id' 
	WHERE `cms_mail`.`from_id`='$user_id' 
	AND `cms_mail`.`sys`='0' AND `cms_mail`.`delete`!='$user_id' 
	AND `cms_contact`.`ban`!='1' AND `spam`='0'"), 0);
echo '<div class="menu"> <i class="fa fa-envelope-o" aria-hidden="true" style="color:green"></i> <a href="../mail/index.php?act=input">' . $lng_profile['received'] . '</a>&nbsp;(' . $count_input . ($new_mail ? '/<span class="red">+' . $new_mail . '</span>' : '') . ')</div>';
//Исходящие сообщения
$count_output = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_mail` LEFT JOIN `cms_contact` ON `cms_mail`.`from_id`=`cms_contact`.`from_id` AND `cms_contact`.`user_id`='$user_id' 
WHERE `cms_mail`.`user_id`='$user_id' AND `cms_mail`.`delete`!='$user_id' AND `cms_mail`.`sys`='0' AND `cms_contact`.`ban`!='1'"), 0);
//Исходящие непрочитанные сообщения
$count_output_new = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_mail` LEFT JOIN `cms_contact` ON `cms_mail`.`from_id`=`cms_contact`.`from_id` AND `cms_contact`.`user_id`='$user_id' 
WHERE `cms_mail`.`user_id`='$user_id' AND `cms_mail`.`delete`!='$user_id' AND `cms_mail`.`read`='0' AND `cms_mail`.`sys`='0' AND `cms_contact`.`ban`!='1'"), 0);
echo '<div class="menu"><i class="fa fa-envelope-o" aria-hidden="true" style="color:orange"></i> <a href="../mail/index.php?act=output">' . $lng_profile['sent'] . '</a>&nbsp;(' . $count_output . ($count_output_new ? '/<span class="red">+' . $count_output_new . '</span>' : '') . ')</div>';
$count_systems = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_mail`
WHERE `from_id`='$user_id' AND `delete`!='$user_id' AND `sys`='1'"), 0);
//Системные сообщения
$count_systems_new = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_mail`
WHERE `from_id`='$user_id' AND `delete`!='$user_id' AND `sys`='1' AND `read`='0'"), 0);
echo '<div class="menu"><i class="fa fa-envelope-o" aria-hidden="true" style="color:blue"></i> <a href="../mail/index.php?act=systems">' . $lng_profile['systems'] . '</a>&nbsp;(' . $count_systems . ($count_systems_new ? '/<span class="red">+' . $count_systems_new . '</span>' : '') . ')</div>';
//Файлы
$count_file = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_mail`
WHERE (`user_id`='$user_id' OR `from_id`='$user_id') AND `delete`!='$user_id' AND `file_name`!='';"), 0);
echo '<div class="menu"> <i class="fa fa-file-archive-o" aria-hidden="true"></i> <a href="../mail/index.php?act=files">' . $lng['files'] . '</a>&nbsp;(' . $count_file . ')</div>';
//if (empty($ban['1']) && empty($ban['3'])) {
//    echo '<p><form action="../mail/index.php?act=write" method="post"><input type="submit" value="' . $lng['write'] . '"/></form></p>';
//}
// Блок контактов
echo '<div class="phdr">Контакты</div>';
//Контакты
$count_contacts = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_contact`
WHERE `user_id`='" . $user_id . "' AND `ban`!='1';"), 0);
echo '<div class="menu"> <i class="fa fa-address-book-o" aria-hidden="true"></i> <a href="../mail/">' . $lng['contacts'] . '</a>&nbsp;(' . $count_contacts . ')</div>';
//Заблокированные
$count_ignor = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_contact`
WHERE `user_id`='" . $user_id . "' AND `ban`='1';"), 0);
echo '<div class="menu"><i class="fa fa-users" aria-hidden="true"></i> <a href="profile.php?act=friends">' . $lng_profile['friends'] . '</a>&#160;(' . $total_friends . ($new_friends ? '/<span class="red">+' . $new_friends . '</span>' : '') . ')&#160;<a href="profile.php?act=friends&amp;do=online">' . $lng['online'] . '</a> (' . $online_friends . ')</div>';
echo '<div class="menu"><i class="fa fa-address-book-o" aria-hidden="true" style="color:red"></i><a href="../mail/index.php?act=ignor">' . $lng_profile['banned'] . '</a>&nbsp;(' . $count_ignor . ')</div>';


// Блок настроек
echo '<div class="phdr">Настройки </div>' .
    '<div class="menu"><i class="fa fa-cog" aria-hidden="true"></i> <a href="profile.php?act=settings">' . $lng['system_settings'] . '</a></div>' .
    '<div class="menu"><i class="fa fa-address-card" aria-hidden="true"></i> <a href="profile.php?act=edit">' . $lng_profile['profile_edit'] . '</a></div>' .
    '<div class="menu"><i class="fa fa-unlock-alt" aria-hidden="true"></i> <a href="profile.php?act=password">' . $lng['change_password'] . '</a></div>';
if ($rights >= 1) {
    echo '<div class="menu"><i class="fa fa-user-circle" aria-hidden="true"></i> <span class="red"><a href="../' . $set['admp'] . '/index.php"><b>' . $lng['admin_panel'] . '</b></a></span></div>';
}
echo '';

// Выход с сайта
echo '<div class="rmenu"><p><a href="' . $set['homeurl'] . '/exit.php">' . functions::image('del.png') . $lng['exit'] . '</a></p></div>';