File size: 12.86Kb
<?
/*
=============================================
Движок: SHCMS Engine
=============================================
Название файла: Почта
=============================================
Official website: http://shcms.ru
=============================================
*/
define('SHCMS', true);
include_once'../system/inc/basic_settings.php';
if($_GET['id']){$id = $_GET['id'];}
$users_mail = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = '$id'"));
registrat();
if($user_id == $users_mail['id']) {
$shcmsengine['title'] = Lang::get('Вы не можете писать себе');
include_once'../template/head.php';
errors(Lang::get("Вы не можете писать себе"));
header("Refresh: 1; url=?act=mail");
include_once '../template/foot.php';
exit;
}
switch($act):
default:
$shcmsengine['title'] = Lang::get('Почта');
include_once'../template/head.php';
$allmail = mysql_result(mysql_query("SELECT COUNT(DISTINCT(`posted`)) FROM `mails` WHERE `user_id` = '$user_id'"),0);
$newmail = new Navigation($allmail, 10, true);
$mail = mysql_query("SELECT DISTINCT(`posted`) FROM `mails` WHERE `user_id` = '$user_id' ORDER BY `id` DESC ". $newmail->limit()."");
echo '<div class="maintitle mainrazd">'.Lang::get('Все ваши контакты').'</div><div class="maintext">';
if(!mysql_num_rows($mail))
{
echo '<div class="posts">'.Lang::get('У вас нет контактов').'</div>';
}
else
{
while($mails = mysql_fetch_array($mail))
{
$profile_users = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = ".$mails['posted']." LIMIT 1"));
echo '<div class="posts"> ';
if($profile_users['pol'] == 1){
echo ' <img src="/template/icon/users/1.png"/>';
}
else{
echo ' <img src="/template/icon/users/2.png"/>';
}
//Вывод всех контактов
$kont_count = mysql_result(mysql_query("SELECT COUNT(*) FROM `mails` WHERE `posted` = '$profile_users[id]'"),0);
if($mails['posted'] == 0) {
echo '<a href="?act=message&id='.$mails['posted'].'">'.SHCMS_Core::system_nick(false).' </a>';
echo '<span class="maintime"><b>'.$kont_count.'</b></span>';
}else {
echo ' <a href="'.DIR_SHCMS.'change_view.php?id='.$profile_users['id'].'">'.$profile_users['login'].'</a> ('.$kont_count.')';
echo '<span class="maintime"><a href="mails.php?act=message&id='.$mails['posted'].'">'.Lang::get('Написать').'</a></span>';
}
echo '</div>';
}
echo '<div class="pages">';
echo $newmail->pagination();
echo '</div>';
}
echo '</div>';
$mail_proch = mysql_result(mysql_query("SELECT COUNT(*) FROM `mails` WHERE `user_id` = '$user_id' AND `read` = 'yes'"),0);
$mail_noproch = mysql_result(mysql_query("SELECT COUNT(*) FROM `mails` WHERE `user_id` = '$user_id' AND `read` = 'no'"),0);
$mail_read = mysql_result(mysql_query("SELECT COUNT(*) FROM `mails` WHERE `posted` = '$user_id'"),0);
echo '<div class="maintitle mainrazd">'.Lang::get('Действие').'</div><div class="maintext">';
echo '<div class="posts"><img src="../template/icon/mail/pr.png"> <a href="?act=written">'.Lang::get('Прочитанные письма').'</a><span class="maintime mainrazd">'.$mail_proch.'</span></div>';
echo '<div class="posts"><img src="../template/icon/mail/ne.png"> <a href="?act=mail">'.Lang::get('Непрочитанные письма').'</a><span class="maintime mainrazd">'.$mail_noproch.'</span></div>';
echo '<div class="posts"><img src="../template/icon/mail/ot.png"> <a href="?act=read">'.Lang::get('Отправленные письма').'</a><span class="maintime mainrazd">'.$mail_read.'</span></div>';
echo '</div>';
break;
case 'message':
if($id == 0) {
$shcmsengine['title'] = Lang::get('Сообщение от Системы');
}else {
$shcmsengine['title'] = Lang::get('Переписка с %s',$users_mail['login']);
}
include_once'../template/head.php';
if($_POST['submit'])
{
$submit = $_POST['submit'];
}
if(isset($submit))
{
if($_POST['text'])
{
$text = $_POST['text'];
}
if(empty($text))
{
errors(Lang::get('Введите пожалуйста текст сообщения'));
include_once'../template/foot.php';
exit;
}
if(strlen($text) < 4 or strlen($text) > 10000)
{
errors(Lang::get('Сообщение должно быть не меньше 4 и не больше 10 000'));
include_once'../template/foot.php';
exit;
}
if($settings_shcms['antimat'] == true) {
$text = $system_function->antimat($text);
}
$message = mysql_query("INSERT INTO `mails` (`user_id`,`read`,`text`,`posted`,`time`) VALUES ('".$users_mail['id']."','no','$text','$user_id','".time()."')");
if($message == true)
{
messag(Lang::get("Сообщение успешно отправлено"));
header("Refresh: 1; url=?act=message&id=$id");
include_once'../template/foot.php';
exit;
}
else
{
errors(Lang::get("Возникла ошибка при отправки письма"));
header("Refresh: 1; url=?");
include_once'../template/foot.php';
exit;
}
}
if($id == 0) {echo false; }else {
echo '<div class="maintext">';
$form = new form("?act=message&id=$id");
$form->textarea(Lang::get('<strong>Текст сообщения:</strong>'),'text','',true);
$form->submit(Lang::get('Отправить'),'submit');
$form->submit(Lang::get('Обновить'),'resfresh');
$form->finish();
echo '</div>';
}
$allfield = mysql_result(mysql_query("SELECT COUNT(*) FROM `mails` WHERE ((`mails`.`user_id`='$id' AND `mails`.`posted`='$user_id') OR (`mails`.`user_id`='$user_id' AND `mails`.`posted`='$id'))"),0);
$newlist = new Navigation($allfield, 10, true);
$mails = mysql_query("SELECT * FROM `mails` WHERE ((`mails`.`user_id`='$id' AND `mails`.`posted`='$user_id') OR (`mails`.`user_id`='$user_id' AND `mails`.`posted`='$id')) ORDER BY `id` DESC ". $newlist->limit()."");
if(mysql_num_rows($mails) != 0) {
while($mail = mysql_fetch_array($mails)) {
if($user_id == $mail['user_id']) {
mysql_query("UPDATE `mails` SET `read` = 'yes' WHERE `posted` = '$id'");
}
$mysql_users = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = '$mail[user_id]'"));
echo '<div class="maintitle">';
if($mail['posted'] == 0) {
SHCMS_core::system_nick(true);
}else {
if($mail['read'] == 'no') {
users_profile($mail['posted']);
echo '<font color="red"> <small>'.Lang::get('Не прочитано').'</small></font>';
}else {
users_profile($mail['posted']);
}
}
echo '<span class="mainforum">'.$timedate->times($mail['time']).'</span></div><div class="maintext">';
echo processing($mail['text']) ;
echo '<div style="text-align:right;"><a href="?act=delete&id_mail='.$mail['id'].'&id='.$id.'"><img src="../template/icon/delete.png"></a></div>';
echo '</div>';
}
}else {
echo '<div class="posts mail_ mainrazd">'.Lang::get('История сообщений пуста.').'</div>';
}
echo '<div class="pages">';
echo $newlist->pagination('act=message&id='.$id.'');
echo '</div>';
break;
case 'delete':
$shcmsengine['title'] = Lang::get('Удаление сообщений');
include_once'../template/head.php';
if($_GET['id_mail']){$id_mail = $_GET['id_mail'];}
if($id == false) {
errors(Lang::get('Выбранный вами пост не существует'));
header("Refresh: 1; url=?act=message&id=$id");
include_once'../template/foot.php';
}
$delete_mail = mysql_query("DELETE FROM `mails` WHERE `id` = '$id_mail'");
if($delete_mail == true) {
messag(Lang::get('Пост успешно удален'));
header("Refresh: 1; url=?act=message&id=$id");
include_once'../template/foot.php';
}else {
errors(Lang::get('Пост не удален'));
header("Refresh: 1; url=?act=message&id=$id");
include_once'../template/foot.php';
}
break;
case 'mail':
$countmail = mysql_result(mysql_query("SELECT COUNT(*) FROM `mails` WHERE `user_id` = '" .$user_id."' AND `read` = 'no'"), 0);
if($countmail == NULL){
$shcmsengine['title'] = Lang::get('Новых сообщений нет');
}
else{
$shcmsengine['title'] = Lang::get('Новых сообщений %s',$countmail);
}
include_once'../template/head.php';
$mail = mysql_query("SELECT DISTINCT(`posted`) FROM `mails` WHERE `user_id` = '$user_id' AND `read` = 'no' ORDER BY `id` DESC");
$mails = mysql_fetch_array($mail);
if($mails == NULL) {
echo '<div class="posts"> ';
echo '<div class="mail_ mainrazd">'.Lang::get('История сообщений пуста.').'</div></div>';
}
else
{
echo '<div class="maintitle mainrazd">'.Lang::get('Новых сообщений %s',$countmail).'</div>';
echo '<div class="maintext">';
do
{
$mail_users = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = '$mails[posted]'"));
echo '<div class="mysql_no">';
$user_pol = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `login` = '$mail_users[login]'"));
$count = mysql_result(mysql_query("SELECT COUNT(*) FROM `mails` WHERE `user_id` = '$user_id' AND `read` = 'no' AND `posted` = '$mails[posted]'"),0);
if($mails['posted'] == 0) {
echo '<a href="?act=message&id='.$mails['posted'].'">'.SHCMS_Core::system_nick(false).' </a>';
}else {
if($user_pol['pol'] == 1) {
echo '<img src="../template/icon/users/1.png"> ';
}
else{
echo '<img src="../template/icon/users/2.png"> ';
}
echo '<a href="?act=message&id='.$mails['posted'].'">'.$mail_users['login'].'<span style="color:green;" class="mainforum mainrazd">'.$count.'</span></a>';
}
echo '</div>';
}
while($mails = mysql_fetch_array($mail));
echo '</div>';
}
break;
case'prosm':
header("Location: mails.php?act=message&id=$id");
break;
case 'written':
$shcmsengine['title'] = Lang::get('Прочитанные письма');
include_once'../template/head.php';
$allmail = mysql_result(mysql_query("SELECT COUNT(DISTINCT(`posted`)) FROM `mails` WHERE `user_id` = '$user_id'"),0);
$newmail = new Navigation($allmail, 10, true);
$mail = mysql_query("SELECT DISTINCT(`posted`) FROM `mails` WHERE `user_id` = '$user_id' ORDER BY `id` DESC ". $newmail->limit()."");
if(!mysql_num_rows($mail))
{
echo '<div class="posts">'.Lang::get('У вас нет контактов').'</div>';
}
else
{
while($mails = mysql_fetch_array($mail))
{
$profile_users = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = ".$mails['posted']." LIMIT 1"));
echo '<div class="mysql_yes"> ';
$kont_count = mysql_result(mysql_query("SELECT COUNT(*) FROM `mails` WHERE `posted` = '$profile_users[id]'"),0);
if($mails['posted'] == 0) {
echo '<a href="mails.php?act=message&id='.$mails['posted'].'">'.SHCMS_core::system_nick(false).'</a>';
}else {
if($profile_users['pol'] == 1){
echo ' <img src="/template/icon/users/1.png"/>';
}
else {
echo ' <img src="/template/icon/users/2.png"/>';
}
echo ' <a href="mails.php?act=message&id='.$mails['posted'].'">'.$profile_users['login'].'</a>';
}
echo '<span class="mainforum">'.$kont_count.'</span>';
echo '</div>';
}
echo '<div class="pages">';
echo $newmail->pagination();
echo '</div>';
}
break;
case 'read':
$shcmsengine['title'] = Lang::get('Отправленные письма');
include_once'../template/head.php';
$mail = mysql_query("SELECT * FROM `mails` WHERE `posted` = '$user_id' ORDER BY `id` DESC");
while($mails = mysql_fetch_array($mail))
{
$mail_users = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = '$mails[user_id]'"));
if($mails['user_id'] == 0) {echo false;}else {
echo '<div class="mysql_yes"><a href="?act=prosm&id='.$mails['user_id'].'">'.$mail_users['login'].'</a>
<div class="maintime">'.$timedate->times($mails['time']).'</div></div>';
}
}
break;
endswitch;
include_once'../template/foot.php';
?>