<?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');
	if(mysql_result(mysql_query('SELECT COUNT(*) FROM `users` WHERE `id` = ' . $id), 0)==0){
		echo '<div class="rmenu">Пользователя не существует!</div>';
	} else {
		if($id != $user_id) {
			if(mysql_result(mysql_query('SELECT COUNT(*) FROM `mail_konts` WHERE `id_user` = ' . $user_id . ' AND `id_kont`=' . $id . ''), 0)!=0){
				$total = mysql_result(mysql_query("SELECT COUNT(*) FROM `mail_msg` WHERE ((`id_user`='" . $user_id . "' AND `id_kont`='$id') OR (`id_user`='" . $id . "' AND `id_kont`='$user_id')) AND `sys`=1 AND `delete`!='" . $user_id . "' AND `file`!='' OR `id_kont`='" . $user_id . "' AND `sys`=1 AND `delete`!='" . $user_id . "' AND `file`!='' AND `id_kont`='$id';"), 0);
				if($total > 0) {
					$req = mysql_query("SELECT * FROM `mail_msg` WHERE ((`id_user`='" . $user_id . "' AND `id_kont`='$id') OR (`id_user`='" . $id . "' AND `id_kont`='$user_id')) AND `sys`=1 AND `delete`!='" . $user_id . "' AND `file`!='' OR `id_kont`='" . $user_id . "' AND `sys`=1 AND `delete`!='" . $user_id . "' AND `file`!='' AND `id_kont`='$id' LIMIT $start, $kmess;");
					while($row = mysql_fetch_assoc($req)) {
						echo '<div class="menu">Файл: <a href="'.$home.'/files/pochta/' . $row['file'] . '">' . $row['file'] . '</a> [' . formatsize(filesize('../files/pochta/'.$row['file'])) . ']</div>';
					}
					echo '<div class="phdr">Всего: ' . $total . '</div>';
					if ($total > $kmess) {
						echo '<div class="menu">' . pagenav($home.'/pochta/index.php?act=mfiles&amp;id='.$id.'&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>';
				}
			} else {
				echo '<div class="rmenu">Пользователя нет в Ваших контактах</div>';
			}
		} else {
			echo '<div class="rmenu">Ошибка при выборе контакта</div>';
		}
	}
?>