Файл: Arhmobi_esdcms/betachat/room.php
Строк: 55
<?php
include_once '../sys/inc/start.php';
if (AJAX)
$doc = new document_json();
else
$doc = new document();
$pages = new pages($db->query("SELECT COUNT(*) FROM `roms_message`")->fetchColumn());
$room = (int)$_GET['id'];
$q = $db->prepare("SELECT * FROM `rooms` WHERE `id` = ? AND `group_show` <= ?");
$q->execute(Array($room, $user->group));
if (!$category = $q->fetch()) {
header('Refresh: 1; url=./');
$doc->err(__('Комната не доступна'));
exit;
}
$doc->title = $category['name'];
if (isset($_GET['id']))
$ank = new user($_GET['id']);
else
$ank = $user;
if (!$ank->group) {
$doc->access_denied(__('Нет данных'));
}
if ($user->group && isset($_POST['review'])) {
$rev = text::input_text($_POST['review']);
$user->balls++;
if ($rev) {
$res = $db->prepare("INSERT INTO `roms_message` (`id_user`, `id_rooms`, `time`, `text`) VALUES (?, ?, ?, ?)");
$res->execute(Array($user->id, $ank->id, TIME, $rev));
header('Refresh: 1; url=?id=' . $ank->id);
$doc->ret(__('Вернуться'), '?id=' . $ank->id);
$doc->msg(__('Успешно написано'));
} else {
$doc->err(__('Пустое сообщение'));
header('Refresh: 1; url=?id=' . $ank->id);
$doc->ret(__('Вернуться'), '?id=' . $ank->id);
}
}
if ($user->group ) {
$form = new form('?id=' . $ank->id . '&' . passgen());
$form->textarea('review', __('Написать в чат') . ':');
$form->button(__('Отправить'));
$form->display();
}
$q = $db->prepare("SELECT COUNT(*) AS `count`, MAX(`time`) AS `time` FROM `roms_message` WHERE `id_user` = ? AND `id_rooms` = ?");
$q->execute(Array($user->id, $ank->id));
if ($row = $q->fetch()) {
$count = $row['count'];
$time = $row['time'];
} else {
$count = 0;
$time = 0;
}
switch (@$_GET['from']) {
case 'users':
$from = 'users';
break;
case 'all':
$from = 'all';
break;
default:
$from = 'users';
break;
}
$pages = new pages;
$res = $db->prepare("SELECT COUNT(*) FROM `roms_message` WHERE `id_rooms` = ?" . ($from === 'users' ? ' AND `id_user` <> 0' : ''));
$res->execute(Array($ank->id));
$pages->posts = $res->fetchColumn();
$q = $db->prepare("SELECT * FROM `roms_message` WHERE `id_rooms` = ? " . ($from === 'users' ? ' AND `id_user` <> 0' : '') . " ORDER BY `id` DESC LIMIT $pages->limit");
$q->execute(Array($ank->id));
$listing = new listing();
if ($arr = $q->fetchAll()) {
foreach ($arr AS $rev) {
$post = $listing->post();
if ($rev['id_user']) {
$ank2 = new user($rev['id_user']);
} else {
$ank2 = new user(0);
}
// $post->icon($ank2->icon());
$post->title = $ank2->nick();
$post->content = text::toOutput($rev['text']);
$post->url = 'actions.php?id=' . $rev['id'];
}
}
$listing->display(__('Записи отсутствуют'));
$pages->display('?id=' . $ank->id . '&from=' . $from . '&'); // вывод страниц
if ($user->group >= 5) {
$doc->act(__('Параметры комнаты'), 'rooms.edit.php?id=' . $category['id']);
}
$doc->ret(__('Чат прихожая'), './');