File size: 2.56Kb
<?php
include '../system/inc/connect.php';
include '../system/inc/core.php';
$title = $send_mail['title'];
include '../system/inc/header.php';
if(!$user){
header('Location: /index.php');
}
$id_kont = intval($_GET['id_kont']);
##Проверяем на существование юзера##
$q = mysql_query("SELECT id FROM user WHERE id = '$id_kont'");
if(!mysql_num_rows($q)){
err($send_mail['no_user']);
include '../system/inc/footer.php';
exit;
}
######
if(!$id_kont){
err($send_mail['err_kont']);
echo '<div class="menu"><a href="/mail/">'.$send_mail['back'].'</a></div>';
include '../system/inc/footer.php';
exit;
}
#####Себе писать низя######
if($id_kont == $user['id']){
err($send_mail['isend']);
echo '<div class="menu"><a href="/mail/">'.$send_mail['back'].'</a></div>';
include '../system/inc/footer.php';
exit;
}
#######
echo '<div class="menu">  <span class="left">';
user($id_kont);
echo '</span></div>';
###Система отправки почты###
if(isset($_POST['send'])){
$mess = txt($_POST['messages']);
if (mb_strlen($mess, "utf-8") < 2) {
$err = $send_mail['strlen'];
}
/*---------*/
if(!isset($err)){
$sql = mysql_query("SELECT * FROM kont WHERE (id_user = '$user[id]' AND kont_user = '$id_kont') OR (id_user = '$id_kont' AND kont_user = '$user[id]')");
$num = mysql_fetch_assoc($sql);
if(!mysql_num_rows($sql)){
### Если диалога не существует,
### Создаем новый
mysql_query("INSERT INTO `kont` SET `time` = '".time()."', `id_user` = '$user[id]', `kont_user` = '$id_kont'");
$id = mysql_insert_id();
mysql_query("INSERT INTO `messages` SET `time` = '".time()."', `id_user` = '$user[id]', `mess_user` = '$id_kont', `msg` = '$mess', `cont` = '$id'");
header("Location: /mail/write$id");
} else {
#### Если диалог существует,
#### поднимаем его в списке диалогов
mysql_query("UPDATE `kont` SET `time` = '".time()."' WHERE `id` = '$num[id]'");
mysql_query("INSERT INTO `messages` SET `time` = '".time()."', `id_user` = '$user[id]', `mess_user` = '$id_kont', `msg` = '$mess', `cont` = '$num[id]'");
header("Location: /mail/write$num[id]");
}
####
} else {
err($err);
}
}
###Форма отправки####
?>
<div class="orange"><form method="post">
<textarea name="messages"></textarea><br />
<input type="submit" name="send" value="<?=$send_mail['send']?>" />
</form></div>
<?php
err($send_mail['warning']);
include '../system/inc/footer.php';