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

if($id) {
	$req = mysql_query("SELECT * FROM `cms_mail` WHERE (`user_id`='$user_id' OR `from_id`='$user_id') AND `id` = '$id' AND `file_name` != '' AND `delete`!='$user_id' LIMIT 1");
    if (mysql_num_rows($req) == 0) {
		$textl = 'Личная почта';
		require_once('../incfiles/head.php');
		//Выводим ошибку
		echo display_error('Такого файла не существует!');
        require_once("../incfiles/end.php");
        exit;
    }
	$res = mysql_fetch_assoc($req);
	if(file_exists('../files/mail/' . $res['file_name'])) {
		mysql_query("UPDATE `cms_mail` SET `count` = `count`+1 WHERE `id` = '$id' LIMIT 1");
		Header('Location: ../files/mail/' . $res['file_name']);
		exit;
	} else {
		echo display_error('Такого файла не существует!');
	}
} else {
	echo display_error('Файл не выбран!');
}