<?php

defined('_IN_JOHNCMS') or die('Error: restricted access');

$set_mail = unserialize($user['set_mail']);
$out = '';
$total = 0;
$ch = 0;
$mod = isset($_REQUEST['mod']) ? $_REQUEST['mod'] : '';

if ($id) {
    $req = mysql_query("SELECT * FROM `users` WHERE `id` = '$id' LIMIT 1");
    if (mysql_num_rows($req) == 0) {
        $textl = $lng['mail'];
        require_once('../incfiles/head.php');
        echo functions::display_error($lng['error_user_not_exist']);
        require_once("../incfiles/end.php");
        exit;
    }
    $qs = mysql_fetch_assoc($req);
    if ($mod == 'clear') {
        $textl = $lng['mail'];
        require_once('../incfiles/head.php');
echo '<div class="phdr"><b>' . $lng_mail['clear_messages'] . '</b></div>';
        if (isset($_POST['clear'])) {
            $count_message = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_mail` WHERE ((`user_id`='$id' AND `from_id`='$user_id') OR (`user_id`='$user_id' AND `from_id`='$id')) AND `delete`!='$user_id'"), 0);
            if ($count_message) {
                $req = mysql_query("SELECT `cms_mail`.* FROM `cms_mail` WHERE ((`cms_mail`.`user_id`='$id' AND `cms_mail`.`from_id`='$user_id') OR (`cms_mail`.`user_id`='$user_id' AND `cms_mail`.`from_id`='$id')) AND `cms_mail`.`delete`!='$user_id' LIMIT " . $count_message);
                while (($row = mysql_fetch_assoc($req)) !== FALSE) {
                    if ($row['delete']) {
                        if ($row['file_name']) {
                            if (file_exists('../files/mail/' . $row['file_name']) !== FALSE)
                                @unlink('../files/mail/' . $row['file_name']);
                        }
                        mysql_query("DELETE FROM `cms_mail` WHERE `id`='{$row['id']}' LIMIT 1");
                    } else {
                        if ($row['read'] == 0 && $row['user_id'] == $user_id) {
                            if ($row['file_name']) {
                                if (file_exists('../files/mail/' . $row['file_name']) !== FALSE)
                                    @unlink('../files/mail/' . $row['file_name']);
                            }
                            mysql_query("DELETE FROM `cms_mail` WHERE `id`='{$row['id']}' LIMIT 1");
                        } else {
                            mysql_query("UPDATE `cms_mail` SET `delete` = '" . $user_id . "' WHERE `id` = '" . $row['id'] . "' LIMIT 1");
                        }
                    }
                }
            }
            echo '<div class="gmenu"><p>' . $lng_mail['messages_are_removed'] . '</p></div>';
        } else {
            echo '<div class="rmenu">
			<form action="index.php?act=write&amp;mod=clear&amp;id=' . $id . '" method="post">
			<p>' . $lng_mail['really_messages_removed'] . '</p>
			<p><input type="submit" name="clear" value="' . $lng['delete'] . '"/></p>
			</form>
			</div>';
        }
        echo '<div class="phdr"><a href="index.php?act=write&amp;id=' . $id . '">' . $lng['back'] . '</a></div>';
        echo '<p><a href="../users/profile.php?act=office">' . $lng['personal'] . '</a></p>';
        require_once('../incfiles/end.php');
        exit;
    }
}

if (empty($_SESSION['error'])) {
    $_SESSION['error'] = '';
}
$out .= '<div class="phdr"><b>Shaxsiy xabar</b></div>';


if (isset($_POST['submit']) && empty($ban['1']) && empty($ban['3']) && !functions::is_ignor($id)) {
    if (!$id) {
        $name = isset($_POST['nick']) ? functions::rus_lat(mb_strtolower(trim($_POST['nick']))) : '';
    }
    $text = isset($_POST['text']) ? trim($_POST['text']) : '';
    if ($set_user['translit'] && isset($_POST['msgtrans']))
        $text = functions::trans($text);
    $newfile = '';
    $sizefile = 0;
    $do_file = FALSE;
    $do_file_mini = FALSE;

$error = array();

include ('../incfiles/bantotal.php');

    if (!$id && empty($name))
        $error[] = $lng_mail['indicate_login_grantee'];
    if (empty($text))
        $error[] = $lng_mail['message_not_empty'];
    elseif (mb_strlen($text) < 2 || mb_strlen($text) > 5000)
        $error[] = $lng_mail['error_long_message'];
    if (($id && $id == $user_id) || !$id && $datauser['name_lat'] == $name)
        $error[] = $lng_mail['impossible_add_message'];
    $flood = functions::antiflood();
    if ($flood)
        $error[] = $lng['error_flood'] . ' ' . $flood . $lng['sec'];
    if (empty($error)) {
        if (!$id) {
            $query = mysql_query("SELECT * FROM `users` WHERE `name_lat`='" . mysql_real_escape_string($name) . "' LIMIT 1");
            if (mysql_num_rows($query) == 0) {
                $error[] = $lng['error_user_not_exist'];
            } else {
                $user = mysql_fetch_assoc($query);
                $id = $user['id'];
                $set_mail = unserialize($user['set_mail']);
            }
        } else {
            $set_mail = unserialize($qs['set_mail']);
        }

        if (empty($error)) {
            if ($set_mail) {
                if ($rights < 1) {
                    if ($set_mail['access']) {
                        if ($set_mail['access'] == 1) {
                            $query = mysql_query("SELECT * FROM `cms_contact` WHERE `user_id`='" . $id . "' AND `from_id`='" . $user_id . "' LIMIT 1");
                            if (mysql_num_rows($query) == 0) {
                                $error[] = $lng_mail['write_contacts'];
                            }
                        } else if ($set_mail['access'] == 2) {
                            $query = mysql_query("SELECT * FROM `cms_contact` WHERE `user_id`='" . $id . "' AND `from_id`='" . $user_id . "' AND `friends`='1' LIMIT 1");
                            if (mysql_num_rows($query) == 0) {
                                $error[] = $lng_mail['write_friends'];
                            }
                        }
                    }
                }
            }
        }
    }

    function parseFileName($var = '')
    {
        if (empty($var))
            return FALSE;
        $file_ext = pathinfo($var, PATHINFO_EXTENSION);
        $file_body = mb_substr($var, 0, mb_strripos($var, '.'));
        $info['filename'] = mb_strtolower(mb_substr(str_replace('.', '_', $file_body), 0, 38));
        $info['fileext'] = mb_strtolower($file_ext);

        return $info;
    }

    $info = array();
    if (isset($_FILES['fail']['size']) && $_FILES['fail']['size'] > 0) {
        $do_file = TRUE;
        $fname = $_FILES['fail']['name'];
        $fsize = $_FILES['fail']['size'];
        if (!empty($_FILES['fail']['error']))
            $error[] = $lng['error_load_file'];

    } else if (isset($_POST['fail']) && mb_strlen($_POST['fail']) > 0) {
        $do_file_mini = TRUE;
        $array = explode('file=', $_POST['fail']);
        $fname = mb_strtolower($array[0]);
        $filebase64 = $array[1];
        $fsize = strlen(base64_decode($filebase64));
        if (empty($fsize))
            $error[] = $lng['error_load_file'];
    }

    if (empty($error) && ($do_file || $do_file_mini)) {
        // Файлы Windows
        $ext_win = array(
            'exe',
            'msi'
        );
        // Файлы Java
        $ext_java = array(
            'jar',
            'jad'
        );
        // Файлы SIS
        $ext_sis = array(
            'sis',
            'sisx',
            'apk'
        );
        // Файлы документов и тексты
        $ext_doc = array(
            'txt',
            'pdf',
            'doc',
            'docx',
            'rtf',
            'djvu',
            'xls',
            'xlsx'
        );
        // Файлы картинок
        $ext_pic = array(
            'jpg',
            'jpeg',
            'gif',
            'png',
            'bmp',
            'wmf'
        );
        // Файлы архивов
        $ext_zip = array(
            'zip',
            'rar',
            '7z',
            'tar',
            'gz'
        );
        // Файлы видео
        $ext_video = array(
            '3gp',
            'avi',
            'flv',
            'mpeg',
            'mp4'
        );
        // Звуковые файлы
        $ext_audio = array(
            'mp3',
            'amr'
        );
        $ext = array_merge($ext_win, $ext_java, $ext_sis, $ext_doc, $ext_pic, $ext_zip, $ext_video, $ext_audio);
        $info = parseFileName($fname);
        if (empty($info['filename']))
            $error[] = $lng_mail['error_empty_name_file'];
        if (empty($info['fileext']))
            $error[] = $lng_mail['error_empty_ext_file'];
        if ($fsize > (1024 * $set['flsz']))
            $error[] = $lng_mail['error_max_file_size'];
        if (preg_match("/[^a-z0-9.()+_-]/", $info['filename']))
            $error[] = $lng_mail['error_simbol'];
        if (!in_array($info['fileext'], $ext))
            $error[] = $lng_mail['error_ext_type'] . ': ' . implode(', ', $ext);
        $newfile = $info['filename'] . '.' . $info['fileext'];
        $sizefile = $fsize;
    }

    if (empty($error)) {
        $ignor = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_contact`
		WHERE `user_id`='" . $user_id . "'
		AND `from_id`='" . $id . "'
		AND `ban`='1';"), 0);
        if ($ignor)
            $error[] = $lng_mail['error_user_ignor_in'];
        if (empty($error)) {
            $ignor_m = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_contact`
			WHERE `user_id`='" . $id . "'
			AND `from_id`='" . $user_id . "'
			AND `ban`='1';"), 0);
            if ($ignor_m)
                $error[] = $lng_mail['error_user_ignor_out'];
        }
    }

    if (empty($error)) {
        $q = mysql_query("SELECT * FROM `cms_contact`
		WHERE `user_id`='" . $user_id . "' AND `from_id`='" . $id . "';");
        if (mysql_num_rows($q) == 0) {
            mysql_query("INSERT INTO `cms_contact` SET
			`user_id` = '" . $user_id . "',
			`from_id` = '" . $id . "',
			`time` = '" . time() . "'");
            $ch = 1;
        }
        $q1 = mysql_query("SELECT * FROM `cms_contact`
		WHERE `user_id`='" . $id . "' AND `from_id`='" . $user_id . "';");
        if (mysql_num_rows($q1) == 0) {
            mysql_query("INSERT INTO `cms_contact` SET
			`user_id` = '" . $id . "',
			`from_id` = '" . $user_id . "',
			`time` = '" . time() . "'");
            $ch = 1;
        }

    }

    // Проверка наличия файла с таким же именем
    if (!empty($newfile) && file_exists('../files/mail/' . $newfile) !== FALSE) {
        $newfile = time() . '_' . $newfile;
    }

    if (empty($error) && $do_file) {
        if ((move_uploaded_file($_FILES['fail']['tmp_name'], '../files/mail/' . $newfile)) === TRUE) {
            @ chmod('../files/mail/' . $newfile, 0666);
            @unlink($_FILES['fail']['tmp_name']);
        } else {
            $error[] = $lng['error_load_file'];
        }
    }

    if (empty($error) && $do_file_mini) {
        if (strlen($filebase64) > 0) {
            $FileName = '../files/mail/' . $newfile;
            $filedata = base64_decode($filebase64);
            $fid = @fopen($FileName, "wb");
            if ($fid) {
                if (flock($fid, LOCK_EX)) {
                    fwrite($fid, $filedata);
                    flock($fid, LOCK_UN);
                }
                fclose($fid);
            }
            if (file_exists($FileName) && filesize($FileName) == strlen($filedata)) {
                @ chmod($FileName, 0666);
                unset($FileName);
            } else {
                $error[] = $lng['error_load_file'];
            }
        } else {
            $error[] = $lng['error_load_file'];
        }
    }

    // Проверяем на повтор сообщения
    if (empty($error)) {
        $rq = mysql_query("SELECT * FROM `cms_mail`
        WHERE `user_id` = $user_id
        AND `from_id` = $id
        ORDER BY `id` DESC
        LIMIT 1
        ") or die(mysql_error());
        $rres = mysql_fetch_assoc($rq);
        if ($rres['text'] == $text) {
            $error[] = $lng['error_message_exists'];
        }
    }


    if (empty($error)) {
        mysql_query("INSERT INTO `cms_mail` SET
		`user_id` = '" . $user_id . "',
		`from_id` = '" . $id . "',
		`text` = '" . mysql_real_escape_string($text) . "',
		`time` = '" . time() . "',
		`file_name` = '" . mysql_real_escape_string($newfile) . "',
		`size` = '" . $sizefile . "'") or die(mysql_error());

        mysql_query("UPDATE `users` SET `lastpost` = '" . time() . "' WHERE `id` = '$user_id';");
        if ($ch == 0) {
            mysql_query("UPDATE `cms_contact` SET `time` = '" . time() . "' WHERE `user_id` = '" . $user_id . "' AND
			`from_id` = '" . $id . "';");
            mysql_query("UPDATE `cms_contact` SET `time` = '" . time() . "' WHERE `user_id` = '" . $id . "' AND
			`from_id` = '" . $user_id . "';");
        }
        Header('Location: index.php?act=write' . ($id ? '&id=' . $id : ''));
        exit;
    } else {
        $out .= '<div class="rmenu">' . implode('<br />', $error) . '</div>';
    }
}


    $req = mysql_query("SELECT * FROM `users` WHERE `id` = '$id' LIMIT 1");

if ($res = mysql_fetch_assoc($req)) {
$out .= '<div class="menu"><table cellpadding="0" cellspacing="0"><tr><td>';
				if (file_exists('../files/users/photo/' . $res['id'] . '_small.jpg'))
$out .= '<a href="'.$home.'/files/users/photo/' . $res['id'] . '.jpg"><img src="'.$home.'/files/users/photo/' . $res['id'] . '_small.jpg" width="42" height="42" alt="#" /></a>&#160;';
else if ($res['sex']) {
$out .= ''; }
$out .= '</td><td>';
		        if ($res['dayb'] == date('j', time()) && $res['monthb'] == date('n', time()))
                $out .= functions::image('birthday.png');
if ($res['rights']>=1){$yaxa='mod_';}else{$yaxa='';}            
if ($res['sex']){            
$out .= '<img src="/theme/yoqimliuz/images/' . $yaxa . ($res['sex'] == 'm' ? 'm' : 'w') . ($res['lastdate'] > time() - 3600 ? '_on' : '_off')
. '.gif" />&nbsp;';
         } else {
                $out .= functions::image('user-delete.png');
         }
$out .= '<a href="' . $home . '/users/profile.php?user=' . $res['id'] . '"><b>' . $res['name'] . '</b></a>&#160;';
$sek = time() - $res['lastdate']; if ($sek == 0) { $bbb = '<font color="green">[on]</font> '; } elseif ($sek < 60) {  $bbb = '<font color="green">['.$sek.'s]</font>'; } elseif ($sek > 60 && $sek < 120) { $bbb = '<font color="green">[1m]</font>'; } elseif ($sek > 120 && $sek < 180) { $bbb = '<font color="green">[2m]</font>'; } elseif ($sek > 180 && $sek < 240) { $bbb = '<font color="green">[3m]</font>'; } elseif ($sek > 240 && $sek < 300) { $bbb = '<font color="green">[4m]</font>'; } elseif($sek > 300 && $sek < 360) { $bbb = '<font color="green">[5m]</font>'; } elseif ($sek > 360 && $sek < 420) { $bbb = '<font color="green">[6m]</font>'; } elseif ($sek > 420 && $sek < 480) { $bbb = '<font color="green">[7m]</font>'; } elseif ($sek > 480 && $sek < 540) { $bbb = '<font color="green">[8m]</font>'; } elseif ($sek > 540 && $sek < 600) { $bbb = '<font color="green">[9m]</font>'; } elseif ($sek > 600 && $sek < 660) { $bbb = '<font color="green">[10m]</font>'; } elseif ($sek > 660 && $sek < 720) { $bbb = '<font color="green">[11m]</font>'; } elseif ($sek > 720 && $sek < 780) { $bbb = '<font color="green">[12m]</font>'; } elseif ($sek > 780 && $sek < 840) { $bbb = '<font color="green">[13m]</font>'; } elseif ($sek > 840 && $sek < 900) { $bbb = '<font color="green">[14m]</font>'; } elseif ($sek > 900 && $sek < 960) { $bbb = '<font color="green">[15m]</font>'; } elseif ($sek > 960 && $sek < 1020) { $bbb = '<font color="green">[16m]</font>'; } elseif ($sek > 1020 && $sek < 1080) { $bbb = '<font color="green">[17m]</font>'; } elseif ($sek > 1080 && $sek < 1140) { $bbb = '<font color="green">[18m]</font>'; } elseif ($sek > 1140 && $sek < 1200) { $bbb = '<font color="green">[19m]</font>'; } elseif ($sek > 1200 && $sek < 1260) { $bbb = '<font color="green">[20m]</font>'; } elseif ($sek > 1260 && $sek < 1320) { $bbb = '<font color="green">[21m]</font>'; } elseif ($sek > 1320 && $sek < 1380) { $bbb = '<font color="green">[22m]</font>'; } elseif ($sek > 1380 && $sek < 1440) { $bbb = '<font color="green">[22m]</font>'; } elseif ($sek > 1440 && $sek < 1500) { $bbb = '<font color="green">[23m]</font>'; } elseif ($sek > 1500 && $sek < 1560) { $bbb = '<font color="green">[24m]</font>'; } elseif ($sek > 1560 && $sek < 1620) { $bbb = '<font color="green">[25m]</font>'; } elseif ($sek > 1620 && $sek < 1680) { $bbb = '<font color="green">[26m]</font>'; } elseif ($sek > 1680 && $sek < 1740) { $bbb = '<font color="green">[27m]</font>'; } elseif ($sek > 1740 && $sek < 1800) { $bbb = '<font color="green">[28m]</font>'; } elseif ($sek > 1800 && $sek < 1860) { $bbb = '<font color="green">[29m]</font>'; } elseif ($sek > 1860 && $sek < 1920) { $bbb = '<font color="green">[30m]</font>'; } elseif ($sek > 1920 && $sek < 1980) { $bbb = '<font color="green">[31m]</font>'; } elseif ($sek > 1980 && $sek < 2040) { $bbb = '<font color="green">[32m]</font>'; } elseif ($sek > 2040 && $sek < 2100) { $bbb = '<font color="green">[33m]</font>'; } elseif ($sek > 2100 && $sek < 2160) { $bbb = '<font color="green">[34m]</font>'; } elseif ($sek > 2160 && $sek < 2220) { $bbb = '<font color="green">[35m]</font>'; } elseif ($sek > 2220 && $sek < 2280) { $bbb = '<font color="green">[36m]</font>'; } elseif ($sek > 2280 && $sek < 2340) { $bbb = '<font color="green">[37m]</font>'; } elseif ($sek > 2340 && $sek < 2400) { $bbb = '<font color="green">[38m]</font>'; } elseif ($sek > 2400 && $sek < 2460) { $bbb = '<font color="green">[39m]</font>'; } elseif ($sek > 2460 && $sek < 2520) { $bbb = '<font color="green">[40m]</font>'; } elseif ($sek > 2520 && $sek < 2580) { $bbb = '<font color="green">[41m]</font>'; } elseif ($sek > 2580 && $sek < 2640) { $bbb = '<font color="green">[42m]</font>'; } elseif ($sek > 2640 && $sek < 2700) { $bbb = '<font color="green">[43m]</font>'; } elseif ($sek > 2700 && $sek < 2760) { $bbb = '<font color="green">[44m]</font>'; } elseif ($sek > 2760 && $sek < 2820) { $bbb = '<font color="green">[45m]</font>'; } elseif ($sek > 2820 && $sek < 2880) { $bbb = '<font color="green">[46m]</font>'; } elseif ($sek > 2880 && $sek < 2940) { $bbb = '<font color="green">[47m]</font>'; } elseif ($sek > 2940 && $sek < 3000) { $bbb = '<font color="green">[48m]</font>'; } elseif ($sek > 3000 && $sek < 3060) { $bbb = '<font color="green">[49m]</font>'; } elseif ($sek > 3060 && $sek < 3120) { $bbb = '<font color="green">[50m]</font>'; } elseif ($sek > 3120 && $sek < 3180) { $bbb = '<font color="green">[51m]</font>'; } elseif ($sek > 3180 && $sek < 3240) { $bbb = '<font color="green">[52m]</font>'; } elseif ($sek > 3240 && $sek < 3300) { $bbb = '<font color="green">[53m]</font>'; } elseif ($sek > 3300 && $sek < 3360) { $bbb = '<font color="green">[54m]</font>'; } elseif ($sek > 3360 && $sek < 3420) { $bbb = '<font color="green">[55m]</font>'; } elseif ($sek > 3420 && $sek < 3480) { $bbb = '<font color="green">[56m]</font>'; } elseif ($sek > 3480 && $sek < 3540) { $bbb = '<font color="green">[57m]</font>'; } elseif ($sek > 3540 && $sek < 3600) { $bbb = '<font color="green">[58m]</font>'; } elseif ($sek > 3600 && $sek < 3660) { $bbb = '<font color="green">[59m]</font>'; } else { $bbb = '<font color="red">[off]</font>'; }
$out .= '' . $bbb . '';




$out .= '<br />' . functions::display_date($res['lastdate']) . '</td></tr></table></div>';
		}

if (!functions::is_ignor($id) && empty($ban['1']) && empty($ban['3'])) {

    $out .= isset($_SESSION['error']) ? $_SESSION['error'] : '';
$out .= '<div class="menu">' .
        '<form name="form" action="index.php?act=write' . ($id ? '&amp;id=' . $id : '') . '" method="post"  enctype="multipart/form-data">' .
($id ? '' : '<p><input type="text" name="nick" maxlength="15" value="' . (!empty($_POST['nick']) ? functions::check($_POST['nick']) : '') . '" placeholder="' . $lng_mail['to_whom'] . '?"/></p>');
$out .= bbcode::auto_bb('form', 'text');
    $out .= '<p><textarea rows="' . $set_user['field_h'] . '" name="text"></textarea></p>';
    if ($set_user['translit'])
        $out .= '<input type="checkbox" name="msgtrans" value="1" ' . (isset($_POST['msgtrans']) ? 'checked="checked" ' : '') . '/> ' . $lng['translit'] . '<br />';
    $out .= '<p><input type="file" name="fail" style="width: 100%; max-width: 160px"/></p>';
    $out .= '<input type="submit" name="submit" value="' . $lng['sent'] . '"/></form></div>' .
'<div class="phdr"><b>Xabarlar:</b></div>';
}

if ($id) {

    $total = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_mail` WHERE ((`user_id`='$id' AND `from_id`='$user_id') OR (`user_id`='$user_id' AND `from_id`='$id')) AND `sys`!='1' AND `delete`!='$user_id' AND `spam`='0'"), 0);

    if ($total) {
$out .= '<div class="menu">';
        $req = mysql_query("SELECT `cms_mail`.*, `cms_mail`.`id` as `mid`, `cms_mail`.`time` as `mtime`, `users`.*
            FROM `cms_mail`
            LEFT JOIN `users` ON `cms_mail`.`user_id`=`users`.`id`
            WHERE ((`cms_mail`.`user_id`='$id' AND `cms_mail`.`from_id`='$user_id') OR (`cms_mail`.`user_id`='$user_id' AND `cms_mail`.`from_id`='$id'))
            AND `cms_mail`.`delete`!='$user_id'
            AND `cms_mail`.`sys`!='1'
            AND `cms_mail`.`spam`='0'
            ORDER BY `cms_mail`.`time` DESC
            LIMIT " . $start . "," . $kmess);
        $i = 1;
        $mass_read = array();
        while (($row = mysql_fetch_assoc($req)) !== FALSE) {
            if (!$row['read']) {
                if ($row['from_id'] == $user_id) {
$out .= '<div class="men2">';
                } else {
$out .= '<div class="men">';
                }
				} else {
                if ($row['from_id'] == $user_id) {
$out .= '<div class="men2">';
                } else {
$out .= '<div class="men">';
                }
				}
            
				if ($row['read'] == 1) {
				$read = '<img src="../images/readed.png" alt="read"/>';
				} else {
				if ($row['mtime']) {
				$read = '<img src="../images/sended.png" alt="send"/>';
				}
				}
            if ($row['read'] == 0 && $row['from_id'] == $user_id)
                $mass_read[] = $row['mid'];
            $post = $row['text'];
            $post = functions::checkout($post, 1, 1);
            if ($set_user['smileys'])
                $post = functions::smileys($post, $row['rights'] >= 1 ? 1 : 0);
            if ($row['file_name'])
                $post .= '<div class="func"><p>' . $lng_mail['file'] . ': <a href="index.php?act=load&amp;id=' . $row['mid'] . '">' . $row['file_name'] . '</a> (' . formatsize($row['size']) . ')  [' . $row['count'] . ']</p></div>';
            if ($row['from_id'] == $user_id) {
                    $post .= '<p><span style="margin-right: 12px; font-size: 12px; color: #999999; float: left;">' . functions::display_date($row['mtime']) . '</span></p>';
                } else {
                    $post .= '<p><span style="margin-right: 12px; font-size: 12px; color: #999999; float: left;">' . functions::display_date($row['mtime']) . '</span> <span style="margin-left: 12px; float: right;">'.$read.'</span></p>';
                }
				$out .= $post;
            $out .= '</div><div style="clear: both;"></div>';
            ++$i;
        }
        //Ставим метку о прочтении
        if ($mass_read) {
            $result = implode(',', $mass_read);
            mysql_query("UPDATE `cms_mail` SET `read`='1' WHERE `from_id`='$user_id' AND `id` IN (" . $result . ")");
        }
		$out .= '</div>';
    } else {
        $out .= '<div class="menu"><p>' . $lng['list_empty'] . '</p></div>';
    }

    $out .= '<div class="phdr">' . $lng['total'] . ': ' . $total . '</div>';
    if ($total > $kmess) {
$out .= '<div class="menu"><p><center>' . functions::display_pagination('index.php?act=write&amp;id=' . $id . '&amp;', $start, $total, $kmess) . '</p></center></div>';
        $out .= '<div class="topmenu"><p><form action="index.php" method="get"><input type="hidden" name="act" value="write"/><input type="hidden" name="id" value="' . $id . '"/>
			<input type="text" name="page" size="2"/><input type="submit" value="' . $lng['to_page'] . ' &gt;&gt;"/></form></p></div>';
    }
}

$textl = $lng['mail'];
require_once('../incfiles/head.php');
echo $out;

if ($total) {
echo '<div class="menu">' . functions::image('del.png') . ' <a href="index.php?act=write&amp;mod=clear&amp;id=' . $id . '">Yozishmalarni tozalash</a></div>';
}

unset($_SESSION['error']);
