Файл: modules/dialogs/dialogs.php
Строк: 78
<?php
define('R', $_SERVER['DOCUMENT_ROOT']);
define('S', R.'/system');
require_once(R.'/system/kernel.php');
$tmp->header('dialogs');
$tmp->title('title', Language::config('dialogs'));
User::panel();
if(!User::aut()){
header('location: /');
exit();
}
$id=my_int($db->guard($_GET['id']));
$p=$db->fass("select * from `users` where `id` = '".$id."'");
if(!$p){
$tmp->div('error', Language::config('error'));
$tmp->footer();
exit();
}
$proverka=$db->fass("SELECT * FROM `dialogs` where `kto`= '".User::ID()."' and `komy`= '".$id."'");
if(User::ID()==$id)
{
$tmp->div('error', Language::config('no_add_dialogs').'!');
$tmp->footer();
exit();
}
if($proverka['komy'] != $id && $proverka['kto'] != User::ID()) {
$db->query("INSERT INTO `dialogs` set `kto` = '".User::ID()."', `komy` = '".$id."'");
$db->query("INSERT INTO `dialogs` set `kto` = '".$id."', `komy` = '".User::ID()."'");
}
$posts=$db->fass_c("SELECT COUNT(*) as count FROM `dialogs_message` where `kto` = '".User::ID()."' and `komy` = '".$id."' or `kto` = '".$id."' and `komy` = '".User::ID()."'");
$total = intval((($posts-1)/$num)+1);
if(empty($page) or $page<0) $page=1;
if($page>$total) $page=$total;
$start=$page*$num-$num;
$d=$db->query("select * from `dialogs_message` where `kto` = '".User::ID()."' and `komy` = '".$id."' or `kto` = '".$id."' and `komy` = '".User::ID()."' ORDER BY time DESC LIMIT ".$start.", ".$num." ");
if(User::aut()){
if(isset($_REQUEST['submit'])) {
$text = $db->guard($_POST['text']);
if(empty($_POST['text']) || mb_strlen($_POST['text'], 'UTF-8')<2) {
$error .= Language::config('error_strlen').'! '.Language::config('message_min').'<br>';
}
if(!isset($error)) {
$db->query("INSERT INTO `dialogs_message` SET `kto` = '".User::ID()."', `komy` = '".$id."', `message` = '".$text."', `time` = '".time()."', `readln` = '0' ");
$db->query("UPDATE `dialogs` set `time_last` = '".time()."' where `kto` = '".User::ID()."' and `komy` = '".$id."' or `kto` = '".$id."' and `komy` = '".User::ID()."'");
header('location: /dialogs/dialogs'.$id);
}
}
error($error);
$tmp->div('menu', '<a href="/dialogs/dialogs'.$id.'?'.rand(101, 999).' ">'.img('refresh.png').' '.Language::config('refresh').'</a><hr>');
$tmp->div('main', '<form method="POST" action="/dialogs/dialogs'.$id.'?'.rand(101, 999).' ">'.Language::config('message').':<br/><textarea name="text"></textarea><br /><input type="submit" name="submit" value="'.Language::config('send').'" /></form>');
}
$b=$db->fass("SELECT * FROM `users` where `id` = '".$id."' LIMIT 1 ");
$date_last_entry = $db->guard($b['date_last_entry']);
echo (empty($date_last_entry) ? NULL : $date_last_entry > (time() - 360) ? NULL : '<hr><div class="main">'.Language::config('date_last_entry').': '.times($date_last_entry).'</div>');
if($posts==0){
$tmp->div('main', Language::config('no_messages').'');
$tmp->footer();
exit();
}
if(User::aut()){
echo '<div class="messages">';
while($di=$d->fetch_assoc()) {
if (User::ID() == $di['komy'])
$db->query("UPDATE `dialogs_message` set `readln` = '1' where `id` = '".$di['id']."' ");
echo '<hr><div'.(($di['readln'] == 0) ? ' class="no_read"' : NULL).'>'.nick_new($di['kto']).' <span class="times">'.times($di['time']).'</span><br>'.bb(smile($di['message'])).'</div>';
}
echo '</div>';
}
page('?');
$tmp->div('menu', '<hr><a href="/dialogs">'.img('link.png').' '.Language::config('dialogs').'</a>');
$tmp->footer();
?>