<?php

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;
}

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

$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);
$count_nbk = mysql_result(mysql_query("SELECT COUNT(*) FROM `notebook` WHERE `user_id` = '$user_id'"), 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">' . $lng_profile['my_actives'] . '</div>' .
    '<div class="list2"><p>'.
    '<div><a href="profile.php"><i class="fa fa-address-card-o"></i>&#160;&#160;' . $lng_profile['my_profile'] . '</a></div>' .
    '<div><a href="profile.php?act=stat"><i class="fa fa-bar-chart-o"></i>&#160;&#160;' . $lng['statistics'] . '</a></div>' .
    '<div><a href="album.php?act=list"><i class="fa fa-camera-retro"></i>&#160;&#160;&#160;' . $lng['photo_album'] . '</a>&#160;(' . $total_photo . ')</div>' .
    '<div><a href="profile.php?act=guestbook"><i class="fa fa-address-book-o"></i>&#160;&#160;&#160;' . $lng['guestbook'] . '</a>&#160;(' . $user['comm_count'] . ')</div>'.
'<div><a href="'.$home.'/users/notebook.php"><i class="fa fa-dot-circle-o"></i>&nbsp;&nbsp;&nbsp;'.$lng['diary'].'</a> (' . $count_nbk . ')</div>';
if ($rights >= 1) {
    $guest = counters::guestbook(2);
    echo '<div><a href="../guestbook/index.php?act=ga&amp;do=set"><i class="fa fa-ban"></i>&#160;&#160;&#160;' . $lng['admin_club'] . '</a> (<span class="red">' . $guest . '</span>)</div>';
}
echo '</p></div>';
/*
-----------------------------------------------------------------
Блок почты
-----------------------------------------------------------------
*/
echo '<div class="phdr">' . $lng_profile['my_mail'] . '</div><p>';
//Входящие сообщения
$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="list2">';
 echo '<div><a href="../mail/index.php?act=input"><i class="fa fa-external-link"></i>&#160;&#160;' . $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><a href="../mail/index.php?act=output"><i class="fa fa-external-link"></i>&#160;&#160;' . $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><a href="../mail/index.php?act=systems"><i class="fa fa-external-link"></i>&#160;&#160;' . $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><a href="../mail/index.php?act=files"><i class="fa fa-floppy-o"></i>&#160;&#160;&#160;' . $lng['files'] . '</a>&nbsp;(' . $count_file . ')</div>';
$fm_pradd = mysql_result(mysql_query("SELECT COUNT(*) FROM `privat` WHERE `user` = '$login' AND `type` = 'in'"), 0);
echo '<div><a href="../users/pradd.php?act=in"><i class="fa fa-futbol-o"></i>&#160;&#160;' . $lng['fm_offer'] . '</a>&nbsp;(' . $fm_pradd . ')</div>';
if (empty($ban['1']) && empty($ban['3'])) {
    echo '<p><form action="../mail/index.php?act=write" method="post"><input type="submit" class="write" value="' . $lng['write'] . '"/></form></p>';
}
// Блок контактов
echo '</p></div>';
echo'<div class="phdr">' . $lng['contacts'] . '</div><p>';
//Контакты
$count_contacts = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_contact`
WHERE `user_id`='" . $user_id . "' AND `ban`!='1';"), 0);
echo'<div class="list2">';
echo '<div><a href="../mail/"><i class="fa fa-address-card-o"></i>&#160;&#160;' . $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><a href="profile.php?act=friends"><i class="fa fa-address-card-o"></i>&#160;&#160;' . $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><a href="../mail/index.php?act=ignor"><i class="fa fa-address-card-o"></i>&#160;&#160;' . $lng_profile['banned'] . '</a>&nbsp;(' . $count_ignor . ')</div>';
echo '</p></div>';

// Блок настроек
echo '<div class="phdr">' . $lng['settings'] . '</div><div class="list2"><p>' .
    '<div><a href="profile.php?act=settings"><i class="fa fa-cog"></i>&#160;&#160;&#160;' . $lng['system_settings'] . '</a></div>' .
    '<div><a href="profile.php?act=edit"><i class="fa fa-pencil-square-o"></i>&#160;&#160;&#160;' . $lng_profile['profile_edit'] . '</a></div>' .
    '<div><a href="profile.php?act=password"><i class="fa fa-pencil-square-o"></i>&#160;&#160;&#160;' . $lng['change_password'] . '</a></div>';
if ($rights >= 1) {
    echo '<div><span class="red"><a href="../' . $set['admp'] . '/index.php"><i class="fa fa-ban"></i>&#160;&#160;&#160;<b>' . $lng['admin_panel'] . '</b></a></span></div>';
}
echo '</p></div>';

// Выход с сайта
echo '<div class="rmenu"><p><a href="' . $set['homeurl'] . '/exit.php"><i class="fa fa-times-circle-o"></i>&#160;&#160;&#160;'.$lng['exit'] . '</a></p></div>';