Файл: DARK WARS/dark_war/mail.php
Строк: 55
<?php
include_once 'start.php';
$doc = new document();
if (isset($_GET['id'])) {
$id = (int)$_GET['id'];
$ank = new player($id);
if (!$ank->id || $ank->id == $player->id) {
$doc->err('Не выбран игрок');
exit;
}
$doc->title('Почта ' . $ank->nick);
$mail_new = mysql_result(mysql_query("SELECT COUNT(*) FROM `dark_war_mail`
WHERE `id_who` = '{$player->id}' AND `id_player` = '{$ank->id}' AND `read` = '0' "), 0);
if ($mail_new) {
mysql_query("UPDATE `dark_war_users` SET `mail_new_msg` = (`mail_new_msg` - '$mail_new') WHERE `id` = '{$player->id}'");
}
// Отметели как прочитаное письмо
mysql_query("UPDATE `dark_war_mail` SET `read` = '1' WHERE `id_player` = '{$ank->id}' AND `id_who` = '{$player->id}'");
$doc->assign('method', 'post');
$doc->assign('action', "save_mail.php?id=$id");
$dispatch = array();
$dispatch[] = array('type' => 'textarea', 'name' => 'msg', 'title' => 'Сообщение', 'br' => 1);
$dispatch[] = array('type' => 'submit', 'name' => 'save', 'value' => 'Отправить', 'br' => 0);
$doc->assign('dis', $dispatch);
$doc->display('form.tpl');
$pages = new pages;
$pages->posts = mysql_result(mysql_query("SELECT COUNT(*) FROM `dark_war_mail`
WHERE (`id_player` = '{$player->id}' AND `id_who` = '{$ank->id}')
OR (`id_player` = '{$ank->id}' AND `id_who` = '{$player->id}')"), 0);
$pages->this_page();
$dispatch = array();
$q=mysql_query("SELECT * FROM `dark_war_mail` WHERE (`id_player` = '{$player->id}' AND `id_who` = '{$ank->id}')
OR (`id_player` = '{$ank->id}' AND `id_who` = '{$player->id}')
ORDER BY `time` DESC LIMIT {$pages->my_start()}, {$pages->items_per_page}");
while ($post = mysql_fetch_array($q)) {
$ank = new player($post['id_player']);
$list = $ank->name . " " . $post['time'];
$link = "profil.php?id=$post[id_player]";
$descrip = ($post['read'] == '0'? 'Не прочитано<br />' : null) . text::lead_text($post['msg']);
$dispatch[] = array ('title' => $list, 'link' => $link, 'descrip' => $descrip);
}
if (!$dispatch) {
$dispatch[] = array ('title' => 'Нет сообщений');
}
$doc->assign('post', $dispatch);
$doc->display('view_list_plus_img.tpl');
$pages->listing("?id=$id&"); // вывод страниц
$doc->act("mail.php", "Все письма");
exit;
}
if (isset($_GET['not_read'])) {
$not_read = " AND `read` = '0'";
} else {
$not_read = '';
}
$pages = new pages;
$pages->posts = mysql_result(mysql_query("SELECT COUNT(DISTINCT `id_player`) FROM `dark_war_mail`
WHERE `id_who` = '{$player->id}'$not_read"), 0);
$pages->this_page();
$dispatch = array();
$q=mysql_query("SELECT * FROM `dark_war_mail` WHERE `id_who` = '{$player->id}'$not_read
GROUP BY `id_player`
ORDER BY `time` DESC LIMIT {$pages->my_start()}, {$pages->items_per_page}");
while ($post = mysql_fetch_array($q)) {
$ank = new player($post['id_player']);
$list = $ank->name;
$link = "?id=$post[id_player]";
$dispatch[] = array ('title' => $list, 'link' => $link);
}
if (!$dispatch) {
$dispatch[] = array ('title' => 'Нет новых сообщений');
}
$doc->assign('post', $dispatch);
$doc->display('view_list_plus_img.tpl');
$pages->listing("?"); // вывод страниц
?>