<?php
	/*
	* Модуль почты для JohnCMS 3.2.2 v2.6
	* Copyright © 2010-2011 UPcoder.RU Group All Rights Reserved.
	* Coding by Krite 2010-2011
	*/
	defined('_IN_JOHNCMS') or die('Error: restricted access');
	$textl = 'Контакт лист';
	$headmod = 'pochta';
	require_once('../incfiles/head.php');
	
	echo '<div class="phdr"><h3>Контакт-лист</h3></div>';
		$total = mysql_result(mysql_query("SELECT COUNT(*) FROM `mail_konts` WHERE `id_user`='" . $user_id . "' AND `type`='1'"), 0);
		if($total > 0) {
			$req = mysql_query("SELECT * FROM `mail_konts` WHERE `id_user`='" . $user_id . "' AND `type`='1' ORDER BY `time` DESC LIMIT $start, $kmess");
			while($row = mysql_fetch_assoc($req)) {
				$result = mysql_query('SELECT * FROM `users` WHERE `id` = ' . $row['id_kont']);
				if(mysql_num_rows($result))
					$res = mysql_fetch_assoc($result);
				else {
					$res['name'] = $row['from_out'];
					$res['id'] = $row['id_kont'];
					$res['ip'] = $row['ip'];
					$res['browser'] = $row['ua'];
				}
				echo ($i % 2) ? '<div class="list2">':'<div class="list1">';
				$subtext = '<a href="'.$home.'/pochta/index.php?act=add&amp;id='.$res['id'].'">Написать</a> | <a href="'.$home.'/pochta/index.php?act=delete&amp;id='.$row['id'].'">Удалить</a> | <a href="index.php?act=history&amp;id='.$res['id'].'">История</a>';
				echo show_user($res, 1, ($rights >= 6 && $rights >= $res['rights'] ? 1 : 0), NULL, NULL, $subtext);
				$file_count = mysql_result(mysql_query("SELECT COUNT(*) FROM `mail_msg` WHERE ((`id_user`='" . $user_id . "' AND `id_kont`='".$res['id']."') OR (`id_user`='" . $res['id'] . "' AND `id_kont`='" . $user_id . "')) AND `file`!='' AND `delete`!='".$user_id."';"), 0);
				echo '<a href="index.php?act=mfiles&amp;id='.$res['id'].'">Файлы</a> ['.$file_count.']';
				echo '</div>';
				++$i;
			}
			echo '<div class="phdr">Всего: ' . $total . '</div>';
			if ($total > $kmess) {
				echo '<div class="menu">' . pagenav($home.'/pochta/index.php?act=contacts&amp;', $start, $total, $kmess);
				echo '<form action="" method="post"><p><input type="text" name="page" size="2"/><input type="submit" value="Перейти"/></p></form></div>';
			}

		}
		else {
			echo '<div class="rmenu">Контакт лист пуст!</div>';
		}
		echo '<div class="bmenu"><a href="'.$home .'/index.php?act=cab">Кабинет</a></div>';
?>