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

$total = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_mail` WHERE `from_id`='$user_id' AND `sys`='1' AND `delete`!='$user_id';"), 0);
if($total) {
	$req = mysql_query("SELECT `cms_mail`.* FROM `cms_mail` WHERE `from_id`='$user_id' AND `sys`='1' AND `delete`!='$user_id' ORDER BY `time` DESC LIMIT " . $start . "," . $kmess);
	$mass_read = array();
	for ($i = 0; ($row = mysql_fetch_assoc($req)) !== false; ++$i) {
		$out .= $i % 2 ? '<div class="list1">' : '<div class="list2">';
		if($row['read'] == 0 && $row['from_id'] == $user_id)
			$mass_read[] = $row['id'];
		$vrp1 = date("d.m.Y / H:i", $row['time'] + $set_user['sdvig'] * 3600);
		$post = $row['text'];
		$post = checkout($post, 1, 1);
		if ($set_user['smileys'])
			$post = smileys($post);
		$out .= '<strong>'.checkout($row['them']).'</strong><br />';
		$out .= $post;
		$out .= '<div class="sub"><a href="index.php?act=delete&amp;id=' . $row['id'] . '">Удалить</a></div>';
		$out .= '</div>';
	}
	//Ставим метку о прочтении
	if($mass_read) {
		$result = implode(',', $mass_read);
		mysql_query("UPDATE `cms_mail` SET `read`='1' WHERE `from_id`='$user_id' AND `sys`='1' AND `id` IN (" . $result . ")");
	}
	$out .= '<div class="phdr">Всего: ' . $total . '</div>';
	//Навигация
	if ($total > $kmess) {
		$out .= '<p>' . pagenav('index.php?act=systems&amp;', $start, $total, $kmess) . '</p>';
		$out .= '<p><form action="index.php" method="get">
		<input type="hidden" name="act" value="systems"/>
		<input type="text" name="page" size="2"/>
		<input type="submit" value="К странице &gt;&gt;"/></form></p>';
	}

} else {
	$out .= '<div class="rmenu">Сообщений нет</div>';
}
$textl = 'Личная почта';
require_once('../incfiles/head.php');
echo '<div class="phdr"><h3>Системные сообщения</h3></div>';
echo $out;
echo '<div class="bmenu"><a href="../index.php?act=cab">Кабинет</a></div>';