File size: 2.22Kb
<?php
require '../inc/func.php';
bk_head('Gởi thư');
require '../inc/head.php';
if(!$user){
header('Location: /index.php');
}
$id_cont = intval($_GET['id_cont']);
$q = mysql_query("SELECT id FROM users WHERE id = '$id_cont'");
if(!mysql_num_rows($q)){
err (''.$send_mail['no_user'].'<br /><a href="javascript:history.go(-1)">Quay Lại</a>');
bk_foot();
exit;
}
if(!$id_cont){
err (''.$send_mail['err_cont'].'<br /><a href="javascript:history.go(-1)">Quay Lại</a>');
bk_foot();
exit;
}
if($id_cont == $userid){
err (''.$send_mail['isend'].'<br /><a href="javascript:history.go(-1)">Quay Lại</a>');
bk_foot();
exit;
}
echo '<div class="list1"><div class="tt">'.$send_mail['title'].'</div>';
echo '<div class="notic">'.$send_mail['to'].' ';
user($id_cont);
echo '</div>';
if(isset($_POST['send'])){
$mess = bk_check($_POST['messages']);
if (strlen($mess) < 2) {
$err = '<div class="left_bot">'.$send_mail['strlen'].'</div>';
}
if (empty($mess)) {
$err = '<div class="left_bot">'.$send_mail['empt'].'</div>';
}
if(!isset($err)){
$sql = mysql_query("SELECT * FROM cont WHERE (id_ser = '$userid' AND id_ger = '$id_cont') OR (id_ser = '$id_cont' AND id_ger = '$userid')");
$num = mysql_fetch_assoc($sql);
if(!mysql_num_rows($sql)){
###chua tung nt thi insert moi vao db
mysql_query("INSERT INTO `cont` SET `time` = '".time()."', `id_ser` = '$userid', `id_ger` = '$id_cont'");
$mid = mysql_insert_id();
mysql_query("INSERT INTO `messages` SET `time` = '".time()."', `id_ser` = '$userid', `id_ger` = '$id_cont', `msg` = '$mess', `cont` = '$mid'");
header("Location: /mail/write$mid");
} else {
####da tung nt thi update
mysql_query("UPDATE `cont` SET `time` = '".time()."' WHERE `id` = '$num[id]'");
mysql_query("INSERT INTO `messages` SET `time` = '".time()."', `id_ser` = '$userid', `id_ger` = '$id_cont', `msg` = '$mess', `cont` = '$num[id]'");
header("Location: /mail/write$num[id]");
}
} else {
echo $err;
echo '<a href="javascript:history.go(-1)">Quay Lại</a></div>';
bk_foot();
exit;
}
}
?>
<form method="post">
<textarea name="messages"></textarea><br />
<input type="submit" class="submit" name="send" value="<?php echo $send_mail['send'];?>" />
</form></div>
<?php
bk_foot();