Файл: _modules/mail/message/index.php
Строк: 148
<?php
# mark core v1.0
# author Drk in
# date 24.10.19
# core
require_once ( $_SERVER['DOCUMENT_ROOT']."/_core/system.php" );
# user
system::access(true);
# get
$id = isset( $_GET['id'] ) ? system::abs($_GET['id']): 0;
# check
if (cache_user::ch($id) == false)system::header('/mail');
$data = cache_user::get($id);
if ($id == $user['id'])system::header('/mail');
$adm = ($user['admin'] == 1 || $user['admin'] == 2 || $user['admin'] == 3 ? true:false);
# update user cn_mail
if($user['cn_mail'] > 0):
DB :: $dbh -> query("UPDATE user SET cn_mail = ? WHERE id = ? LIMIT 1;",array(0,$user['id']));
cache_user::save($user['id']);
endif;
# update user cn_new
$upn = DB :: $dbh -> queryFetch("SELECT id,cn_new FROM mail_con WHERE user = ? AND data = ?;", array($user['id'],$id));
if ($upn['cn_new'] > 0):
DB :: $dbh -> query("UPDATE mail_con SET cn_new = ? WHERE id = ? LIMIT 1;",array(0,$upn['id']));
cache_mail_con::save($upn['id']);
endif;
# meta
$title = 'Диалог c '.system::check($data['login']).' :: '.domain;
# post
if (isset($_POST['CFMS'])):
$mess = system::check($_POST['mess']);
$mess_cut = system::num($mess,40);
$CK = system::check($_POST['CK']);
$antiflood = DB :: $dbh -> querySingle("SELECT count(id) FROM mail WHERE user = ? AND time > ?;", array($user['id'],time()-10));
$ch_mess = DB :: $dbh -> querySingle("SELECT count(id) FROM mail WHERE user = ? AND mess = ? AND time > ?;", array($user['id'],$mess,time()-10));
$friends = DB :: $dbh -> querySingle("SELECT count(id) FROM friends WHERE user = ? AND data = ?;", array($user['id'], $id));
if (system::utf_strlen($mess) >= 2 && system::utf_strlen($mess) < 321):
if ($adm == true || $user['exp'] >= $config['mail_exp']):
if (empty($antiflood)): if (empty($ch_mess)):
if ($CK == $user['CK']):
if ($id > 0):
if ($id != $user['id']):
if ($data['mail'] > 0 && $adm == true || $data['mail'] == 0 || $data['mail'] == 1 && !empty($friends)):
# contact
$contact_user = DB :: $dbh -> queryFetch("SELECT id FROM mail_con WHERE user = ? AND data = ?;", array($id,$user['id']));
$contact_data = DB :: $dbh -> queryFetch("SELECT id FROM mail_con WHERE user = ? AND data = ?;", array($user['id'],$id));
# contact user
if (empty($contact_user)):
DB :: $dbh -> query("INSERT INTO mail_con SET user = ?,data = ?",array($id,$user['id']));
$my_contact = DB :: $dbh -> lastInsertId();
else:
$my_contact = $contact_user['id'];
endif;
# contact date
if (empty($contact_data)):
DB :: $dbh -> query("INSERT INTO mail_con SET user = ?, data = ?",array($user['id'],$id));
$data_contact = DB :: $dbh -> lastInsertId();
else:
$data_contact = $contact_data['id'];
endif;
# update
DB :: $dbh -> query("UPDATE mail_con SET cn = cn + 1, cn_new = cn_new + 1, time = ?, mess = ? WHERE id = ?",array(time(),$mess_cut,$my_contact));
cache_mail_con::save($my_contact);
DB :: $dbh -> query("UPDATE mail_con SET cn = cn + 1, time = ?, mess = ? WHERE id = ?",array(time(),$mess_cut,$data_contact));
cache_mail_con::save($data_contact);
# send message
DB :: $dbh -> query("INSERT INTO mail (user,data,mess,time,`read`) VALUES (?, ?, ?, ?, ?);",array($user['id'],$id,$mess,time(),1));
$id_db = DB :: $dbh -> lastInsertId();
cache_mail::save($id_db);
# user
DB :: $dbh -> query("UPDATE user SET cn_mail = ? WHERE id = ?",array(1,$id));
cache_user::save($id);
system::header('?');
# error
else: system::header('?', 'Ошибка, пользователь закрыл почту'); endif;
else: system::header('?', 'Ошибка, нельзя писать себе'); endif;
else: system::header('?', 'Ошибка, нельзя писать системе'); endif;
else: system::header('?', 'Ошибка, возможно вам подкинули эту ссылку'); endif;
else: system::header('?', 'Ошибка, ваше сообщение повторяет предыдущее'); endif;
else: system::header('?', 'Не так быстро, подожди не много'); endif;
else: system::header('?', 'Сначала заработай '.$config['mail_exp'].' опыта, чтобы общаться тут'); endif;
else: system::header('?', 'Cообщение может быть от 2 до 320 символов'); endif;
endif;
# head
require_once ( head );
echo '
'.($id > 0 ? '
<script language="javascript" type="text/javascript" src="'.js.'emoji.js"></script>
'.system::dis().'
<div class="dialog">
<h1 class="human">Вы</h1><form method="post">
<input type="hidden" name="CK" value="'.$user['CK'].'">
Введите сообщение<small>[Мин.:2/Макс.:320]</small>:<br>
<textarea name="mess" id="em" placeholder="Введите текст..." style="width: 96%;"></textarea>
<input type="submit" name="CFMS" value="Отправить сообщение">
<a onclick="emoji();"><img src="'.ico.'emoji/1.png" width="20" height="20"></a>
<a href="" class ="pull-right"><img src="'.ico.'update.png"></a>
</form></div>':null).'<div id="emoji" style="display: none;">
<div class="dialog">'; system::emoji(null,1); echo '</div></div>';
$cn = DB :: $dbh -> querySingle("SELECT count(id) FROM mail WHERE data = ? AND user = ? OR data =? AND user =?;", array($id, $user['id'], $user['id'], $id));
if ($cn == 0)echo '<div class="dialog"><h1 class="pda">КПК</h1><p>› Cписок сообщений пуст<br></p></div>';
$page = new page($cn);
$limit = $cn > $page -> elements ? $page -> limit : null;
$query = DB :: $dbh -> query("SELECT id FROM mail WHERE data = ? AND user = ? OR data =? AND user =? ORDER BY time DESC {$limit}", array($id, $user['id'], $user['id'], $id));
while ($act = $query -> fetch()):
$act = cache_mail::get($act['id']);
$data = cache_user::get($act['user']);
$color = ($data['id'] == 0 ? '#ffffff':($data['admin'] == 0 ? '#747987':null).($data['admin'] == 1 ? 'red':null).($data['admin'] == 2 ? 'green':null).($data['admin'] == 3 ? '#d25518':null));
if ($act['user'] != $user['id'] && $act['read'] == 1):
DB :: $dbh -> query("UPDATE mail SET `read` = ? WHERE user = ? AND data = ? AND id = ?; LIMIT 1", array(0, $id, $user['id'], $act['id']));
cache_mail::save($act['id']);
endif;
echo '
<div class="dialog">
<div style="padding-right: 7px;float: left;margin-top: 5px;">
'.user::min_ava($data['ava']).'
</div><div style="overflow: hidden;">
<h1 class="chat">'.user::chat($act['user']).' '.($act['user'] == $user['id'] && $act['read'] == 1? '<small><font color="red">(не прочитано)</font></small>':null).'</h1></div>
<div style="padding-top: 34px;text-align: left;">
<div style="color: #747987;margin: 2px 3px;word-wrap: break-word;">› <font color="'.$color.'">'.system::text($act['mess']).'</font></div> </div>
<div style="padding-top: 4px;text-align: left;">
<div class ="small" style="margin: 2px 3px;word-wrap: break-word;">› '.system::time($act['time']).'</div>
</div>
</div>
';
endwhile;
$page -> get('?');
echo '
<div class="fights-link" style="margin: 2px 5px"><a href="/mail">Назад в диалоги</a></div>
<div class="line"></div>
';
# foot
require_once ( foot );
?>