File size: 3.08Kb
<?php
$title = 'Сообщения';
require_once ('../system/fun.php');
require_once ('../system/head.php');
if(!isset($user['id'])) {
echo '<div class="menu">Вход в раздел запрещен так как вы не зарегистрированы </div>';
require_once '../system/foot.php';
exit();
}
$id = abs(intval($_GET['id']));
$mess = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '".$id."'"));
if(isset($mess['id']) and $user['id'] != $id)
{
echo '<div class="title"> Диалог с '.$mess['login'].'</div>';
if(isset($_REQUEST['ok']))
{
$text = text($_POST['text']);
if(empty($text) or mb_strlen($text) < 3)
{
echo '<div class="podmenu"><center><b>Ошибка ввода ,минимум 3 символа!</b></center></div>';
//-----Подключаем низ-----//
require_once ('../system/footer.php');
exit();
}
$messa = mysql_result(mysql_query("SELECT COUNT(id) FROM `message_list` WHERE `kogo` = '".$mess['id']."' and `kto` = '".$user['id']."' LIMIT 1"),0);
if($messa == 0) {
mysql_query("INSERT INTO `message_list` SET `kto` = '".$user['id']."', `kogo` = '".$mess['id']."', `time` = '".time()."'");
mysql_query("INSERT INTO `message_list` SET `kto` = '".$mess['id']."', `kogo` = '".$user['id']."', `time` = '".time()."'");
}
mysql_query("INSERT INTO `message` SET `text` = '".$text."', `kto` = '".$user['id']."', `komy` = '".$mess['id']."', `time` = '".time()."', `readlen` = '0'");
header('Location: '.$HOME.'/message/message.php?id='.$mess['id'].'');
exit();
}
echo '<div class="menu"><form action="" method="POST">
<textarea name="text" placeholder="" /></textarea><br />
<input type="submit" name="ok" value="Написать" />
</form></div>';
if (empty($user['max'])) $user['max']=10;
$max = $user['max'];
$k_post = mysql_result(mysql_query("SELECT COUNT(id) FROM `message` WHERE `kto` = '".$user['id']."' and `komy` = '".$mess['id']."' or `kto` = '".$mess['id']."' and `komy` = '".$user['id']."'"),0);
$k_page = k_page($k_post,$max);
$page = page($k_page);
$start = $max*$page-$max;
$msg = mysql_query("SELECT * FROM `message` WHERE `kto` = '".$user['id']."' and `komy` = '".$mess['id']."' or `kto` = '".$mess['id']."' and `komy` = '".$user['id']."' ORDER BY `time` DESC LIMIT $start, $max");
while($m = mysql_fetch_assoc($msg))
{
echo '<div class="menu">'.nick($m['kto']).'';
if($m['readlen'] == 0)
{
echo ' [<font color="red">Не прочитано</font>]';
}else{
echo ' [<font color="green">Прочитано</font>]';
}
echo '</div><div class="menu">'.smi($m['text']).'</div>';
if($user['id'] == $m['komy'])
{
mysql_query("UPDATE `message` SET `readlen` = '1' WHERE `id`='".$m['id']."' limit 1");
}
}
if($k_post < 1)
{
echo '<div class="menu"><center><b>Переписка пуста с данным пользователям !</b></center></div>';
}
if ($k_page > 1) {
echo str(''.$HOME.'/message/message.php?id='.$mess['id'].'/?',$k_page,$page); // Вывод страниц
}
}else{
echo '<div class="title"> Ошибка</div>';
echo '<div class="menu"><b>Ошибка</b></div>';
}
//-----Подключаем низ-----//
require_once ('../system/foot.php');
?>