Файл: moduls/chat/index.php
Строк: 163
<?php
/**
* @package Prime Social
* @link http://primesocial.ru
* @copyright Copyright (C) 2016 Prime Social
* @author BoB | http://primesocial.ru/about
*/
require_once('../../core/start.php');
check_auth();
switch ($select) {
default:
head('Chat: Xonalar');
$all = DB::$dbs->querySingle("SELECT COUNT(`id`) FROM ".CHAT_ROOM."");
if (empty($all)) {
echo DIV_BLOCK . 'Xonalar yo`q' . CLOSE_DIV;
} else {
$sql = DB::$dbs->query("SELECT * FROM ".CHAT_ROOM." ORDER BY `id` DESC");
while($room = $sql -> fetch()) {
echo DIV_BLOCK;
echo ($room['icon'] ? '<img src="'.HOME.'/files/icons_chat/'.$room['icon'].'" alt="[icon]" /> ' : NULL) . '<a href="'.HOME.'/chat/'.$room['id'].'/">'.$room['name'].'</a> ';
$online = DB::$dbs->querySingle("SELECT COUNT(`user_id`) FROM ".USERS." WHERE `location` LIKE '%Xona: ".$room['name']."%' AND `last_time` > ?", array((time() - 300)));
echo '<span class="count"> ' . $online . '</span>';
echo CLOSE_DIV;
}
}
$array = array();
nav($array);
break;
case 'room':
$room = DB::$dbs->queryFetch("SELECT * FROM ".CHAT_ROOM." WHERE `id` = ? ",array(num($_GET['room'])));
if (empty($room)) {
header("Location: ".HOME."");
}
if ($room['type'] == 2) {
require_once('bots/shutnik.php');
}
if ($room['type'] == 1) {
require_once('bots/umnik/bot.php');
}
head('Xona: ' . $room['name']);
if (!empty($user['chat_restart'])) {
echo '<meta http-equiv="refresh" content="'.$user['chat_restart'].'">';
}
if (privilegy('chat_moder') && !empty($_POST['post_delete'])) {
foreach ($_POST as $name => $value) {
DB::$dbs->query("DELETE FROM ".CHAT_MSG." WHERE `id` = ?", array($name));
}
header("Location: ".HOME."/chat/".$room['id']."/");
}
if (privilegy('chat_moder') && !empty($_POST['clean'])) {
DB::$dbs->query("DELETE FROM ".CHAT_MSG." WHERE `room_id` = ?", array($room['id']));
header("Location: ".HOME."/chat/".$room['id']."/");
}
if (isset($_GET['restart'])) {
if ($_POST['restart_ok']) {
$restart = num($_POST['restart']);
DB::$dbs->query("UPDATE ".USERS." SET `chat_restart` = ? WHERE `user_id` = ? ", array($restart, $user['user_id']));
header("Location: ".HOME."/chat/".$room['id']."/");
}
echo DIV_AUT . '<b>Oraliqdagi vaqt:</b>';
echo '<form action="#" method="POST">';
echo '<select name="restart">';
echo '<option value="0">[O`chirish]</option>';
echo '<option value="5">5 soniya</option>';
echo '<option value="10">10 soniya</option>';
echo '<option value="20">20 soniya</option>';
echo '<option value="30">30 soniya</option>';
echo '<option value="45">45 soniya</option>';
echo '<option value="60">60 soniya</option>';
echo '</select>';
echo '<input type="submit" name="restart_ok" value="+" /></form>';
echo CLOSE_DIV;
}
if ($_POST['add']) {
$msg = html($_POST['msg']);
$privat = abs(num($_POST['privat']));
if (empty($msg)) {
$err = 'Bo`sh habar<br />';
}
if (!empty($_GET['otv']) && $_GET['otv'] != $user['user_id']) {
$ank = DB::$dbs->queryFetch("SELECT `user_id`, `nick` FROM ".USERS." WHERE `user_id` = ? ",array(abs(num($_GET['otv']))));
if (!empty($ank)) {
$msg = '[b]' . $ank['nick'] . '[/b], ' . $msg;
}
}
if (!empty($err)) {
echo DIV_ERROR . $err . CLOSE_DIV;
} else {
if ($room['type'] == 1) {
require_once('bots/umnik/bot.php');
require_once('bots/umnik/answer.php');
}
$kont_id = (!empty($ank) ? $ank['user_id'] : 0);
DB::$dbs->query("UPDATE ".USERS." SET `chat_post` = ? WHERE `user_id` = ?",array((++$user['chat_post']), $user['user_id']));
DB::$dbs->query("INSERT INTO ".CHAT_MSG." (`room_id`, `user_id`, `kont_id`, `privat`, `time`, `msg`) VALUES (?, ?, ?, ?, ?, ?)", array($room['id'], $user['user_id'], $kont_id, $privat, time(), $msg));
header("Location: ".HOME."/chat/".$room['id']."/");
}
}
echo DIV_AUT;
echo '<a href="'.HOME.'/chat/'.$room['id'].'/"><b>Yangilash</b></a> | '.(empty($user['chat_restart']) ? ' <a href="'.HOME.'/chat/'.$room['id'].'/?restart">Yangilashni sozlash</a>' : 'Har: <a href="'.HOME.'/chat/'.$room['id'].'/?restart"><b>'.$user['chat_restart'].'</b> soniyada</a> yangilash').' <br /><br />';
if (!empty($_GET['otv'])) {
$ank = DB::$dbs->queryFetch("SELECT `user_id`, `nick` FROM ".USERS." WHERE `user_id` = ? ",array(abs(num($_GET['otv']))));
if (!empty($ank) && $ank['user_id'] != $user['id']) {
echo '<form action="?otv='.$ank['user_id'].'&room='.$room['id'].'&select=room" method="POST">';
echo 'Foydalanuvchi <b>' . $ank['nick'] . '</b>ga habar<br />';
}
} else {
echo '<form action="?room='.$room['id'].'&select=room" method="POST">';
echo 'Habar:<br />';
}
echo '<textarea name="msg"></textarea><br />';
if (!empty($ank) && $ank['user_id'] != $user['id']) {
echo '<select name="privat">';
echo '<option value="0">Hammaga</option>';
echo '<option value="1">Shahsan</option>';
echo '</select>';
}
echo '<input type="submit" name="add" value="Gaplash" /></form>';
if ($room['type'] == 1) {
echo '<small><b>* javoblarni kichik harflar bilan hamda ortiqcha so`zlarsiz yozamiz</b></small>';
}
echo CLOSE_DIV;
bbsmile();
$all = DB::$dbs->querySingle("SELECT COUNT(`id`) FROM ".CHAT_MSG." WHERE `room_id` = ? ", array($room['id']));
if (empty($all)) {
echo DIV_BLOCK . 'Sharhlar yo`q' . CLOSE_DIV;
} else {
echo '<form action="#" method="POST">';
$n = new Navigator($all,$config['write']['room'],'select=room&room='.$room['id']);
$sql = DB::$dbs->query("SELECT * FROM ".CHAT_MSG." WHERE `room_id` = ? ORDER BY `id` DESC LIMIT {$n->start()}, ".$config['write']['room']."", array($room['id']));
while($post = $sql -> fetch()) {
echo DIV_BLOCK;
if (DB::$dbs->querySingle("SELECT COUNT(*) FROM ".BLACKUSERS." WHERE `user_id` = ? && `black_id` = ?", array($user['user_id'], $post['user_id'])) == FALSE) {
if ($post['privat'] == TRUE) {
if ($post['user_id'] == $user['user_id'] || $post['kont_id'] == $user['user_id']) {
$ank = DB::$dbs->queryFetch("SELECT `user_id`, `nick` FROM ".USERS." WHERE `user_id` = ?",array($post['user_id']));
echo (privilegy('chat_moder') ? '<input type="checkbox" name="'.$post['id'].'" /> ' : NULL);
echo '[' . vrem($post['time']) . '] [П!] ' . ($post['user_id'] != $user['user_id'] ? '<a href="?otv='.$post['user_id'].'&room='.$room['id'].'&select=room"><b>'.user_choice($post['user_id'], 'link').'</b></a>' : '<b>'.$ank['nick'].'</b>') . ' ' . userLink($post['user_id'], '[ank.]') . ': ' . '<font color="#FF0000">' . text($post['msg']) . '</font>';
}
} else {
$ank = DB::$dbs->queryFetch("SELECT `user_id`, `nick` FROM ".USERS." WHERE `user_id` = ?",array($post['user_id']));
echo (privilegy('chat_moder') ? '<input type="checkbox" name="'.$post['id'].'" /> ' : NULL);
echo '[' . vrem($post['time']) . '] ' . ($post['user_id'] != $user['user_id'] ? '<a href="?otv='.$post['user_id'].'&room='.$room['id'].'&select=room"><b>'.user_choice($post['user_id'], 'link').'</b></a>' : '<b>'.$ank['nick'].'</b>') . ' ' . userLink($post['user_id'], '[ank.]') . ': ' . text($post['msg']);
}
}
echo CLOSE_DIV;
}
echo $n->navi();
echo (privilegy('chat_moder') ? DIV_LI . '<input type="submit" name="post_delete" value="Belgilangan sharhlarni o`chirish"/> <input type="submit" name="clean" value="Xonani tozalash"/></form>' . CLOSE_DIV : NULL);
}
$online = DB::$dbs->querySingle("SELECT COUNT(`user_id`) FROM ".USERS." WHERE `location` LIKE '%Xona: ".$room['name']."%' AND `last_time` > ?", array((time()-300)));
echo DIV_LI . '<a href="'.HOME.'/chat/who/'.$room['id'].'/"><b>Xonada: '.$online.' kishi.</b></a> | <a href="'.HOME.'/chat/who/"><b>Kim qayerda</b></a>' . CLOSE_DIV;
$array = array('Chat');
nav($array);
break;
}
require_once('../../core/stop.php');
?>