Файл: vsime.com/mail/inc/act_index.php
Строк: 277
<?
$q = mysqli_query($dbi, "SELECT * FROM `mail` WHERE `id_user` = '$user[id]' AND `favorite` = '1'");
$array = array();
while ($post = mysqli_fetch_array($q)) {
$cont = mysqli_fetch_array(mysqli_query($dbi, "SELECT * FROM `mail_conts` WHERE `id` = '$post[id_cont]'"));
$ankc = profile($cont['id_ank']);
foreach($array AS $key => $value) {
if ($key!=NULL && $key==$ankc['id'])$trim=1;
}
if (!isset($trim))$array[$ankc['id']]=0;
}
foreach ($array AS $key => $value) {
$ankv = profile($key);
if (mysqli_num_rows(mysqli_query($dbi, "SELECT * FROM `mail_conts` WHERE `id_user` = '$user[id]' AND `id_ank` = '$ankv[id]' AND `type` = 'favorite'"))==0)mysqli_query($dbi, "INSERT INTO `mail_conts` (`id_user`, `id_ank`, `time`, `nick`, `type`) VALUES ('$user[id]', '$ankv[id]', '$time', '$ankv[nick]', 'favorite')");
}
$q = mysqli_query($dbi, "SELECT * FROM `mail_conts` WHERE `id_user` = '$user[id]' AND `type` != 'all'");
while ($post = mysqli_fetch_array($q))
{
if ($post['type']=='favorite') {
$cont=mysqli_fetch_array(mysqli_query($dbi, "SELECT * FROM `mail_conts` WHERE `id_user` = '$user[id]' AND `id_ank` = '$post[id_ank]' AND `type` = 'all'"));
$count=mysqli_num_rows(mysqli_query($dbi, "SELECT * FROM `mail_conts` INNER JOIN `mail` ON `mail`.`id_cont`=`mail_conts`.`id` WHERE `mail`.`favorite` = '1' AND `mail`.`id_user` = '$user[id]' AND (`mail_conts`.`type` = 'all' OR `mail_conts`.`type` = 'arhive') AND `mail`.`id_cont` = '$cont[id]'"));
} else {
$count=mysqli_num_rows(mysqli_query($dbi, "SELECT * FROM `mail` WHERE `id_cont` = '$post[id]'"));
}
if ($count==0)mysqli_query($dbi, "DELETE FROM `mail_conts` WHERE `id` = '$post[id]'");
}
$sort='all';
if (isset($_GET['favorite']))$sort='favorite';
if (isset($_GET['arhive']))$sort='arhive';
if (isset($_GET['trash']))$sort='trash';
if ($sort!='favorite') {
if (isset($_POST['contact_archive']) && hsc(@$_POST['mdp'])==$mdp) {
$count=0;
foreach ($_POST as $key => $value) {
if (preg_match('#^cd_([0-9]*)$#',$key,$kid) && $value == 1) {
$cont=mysqli_fetch_array(mysqli_query($dbi, "SELECT * FROM `mail_conts` WHERE `id` = '$kid[1]' AND `id_user` = '$user[id]' AND `type` = 'all' LIMIT 1"));
$ank=profile($cont['id_ank']);
if ($cont) {
$count++;
if (mysqli_num_rows(mysqli_query($dbi, "SELECT * FROM `mail_conts` WHERE `id_user` = '$user[id]' AND `id_ank` = '$ank[id]' AND `type` = 'arhive'"))==0)mysqli_query($dbi, "UPDATE `mail_conts` SET `type` = 'arhive', `time_last` = '$time' WHERE `id` = '$cont[id]'");
else {
$tcont=mysqli_fetch_array(mysqli_query($dbi, "SELECT * FROM `mail_conts` WHERE `id_user` = '$user[id]' AND `id_ank` = '$ank[id]' AND `type` = 'arhive'"));
mysqli_query($dbi, "UPDATE `mail` SET `id_cont` = '$tcont[id]' WHERE `id_cont` = '$cont[id]'");
mysqli_query($dbi, "DELETE FROM `mail_conts` WHERE `id` = '$cont[id]'");
}
msg_sess("Контакты успешно перенесены в архив");
}
}
}
} elseif (isset($_POST['contact_delete']) && hsc(@$_POST['mdp'])==$mdp) {
$count=0;
foreach ($_POST as $key => $value) {
if (preg_match('#^cd_([0-9]*)$#',$key,$kid) && $value == 1) {
$cont=mysqli_fetch_array(mysqli_query($dbi, "SELECT * FROM `mail_conts` WHERE `id` = '$kid[1]' AND `id_user` = '$user[id]' LIMIT 1"));
$ank=profile($cont['id_ank']);
if ($cont) {
$count++;
if ($cont['type']=='trash') {
mysqli_query($dbi, "DELETE FROM `mail_conts` WHERE `id` = '$cont[id]'");
mysqli_query($dbi, "DELETE FROM `mail` WHERE `id_cont` = '$cont[id]'");
msg_sess("Контакты успешно удалены");
} else {
if (mysqli_num_rows(mysqli_query($dbi, "SELECT * FROM `mail_conts` WHERE `id_user` = '$user[id]' AND `id_ank` = '$ank[id]' AND `type` = 'trash'"))==0)mysqli_query($dbi, "UPDATE `mail_conts` SET `type` = 'trash', `time_last` = '$time' WHERE `id` = '$cont[id]'");
else {
$tcont=mysqli_fetch_array(mysqli_query($dbi, "SELECT * FROM `mail_conts` WHERE `id_user` = '$user[id]' AND `id_ank` = '$ank[id]' AND `type` = 'trash'"));
mysqli_query($dbi, "UPDATE `mail` SET `id_cont` = '$tcont[id]' WHERE `id_cont` = '$cont[id]'");
mysqli_query($dbi, "DELETE FROM `mail_conts` WHERE `id` = '$cont[id]'");
}
msg_sess("Контакты успешно перенесены в корзину");
}
}
}
}
} elseif (isset($_POST['contact_reset']) && hsc(@$_POST['mdp'])==$mdp && $sort=='trash') {
$count=0;
foreach ($_POST as $key => $value) {
if (preg_match('#^cd_([0-9]*)$#',$key,$kid) && $value == 1) {
$cont=mysqli_fetch_array(mysqli_query($dbi, "SELECT * FROM `mail_conts` WHERE `id` = '$kid[1]' AND `id_user` = '$user[id]' LIMIT 1"));
$ank=profile($cont['id_ank']);
if ($cont) {
$count++;
if ($cont['type']=='trash') {
if (mysqli_num_rows(mysqli_query($dbi, "SELECT * FROM `mail_conts` WHERE `id_user` = '$user[id]' AND `id_ank` = '$ank[id]' AND `type` = 'all'"))==0)mysqli_query($dbi, "UPDATE `mail_conts` SET `type` = 'all', `time_last` = '$time' WHERE `id` = '$cont[id]'");
else {
$tcont=mysqli_fetch_array(mysqli_query($dbi, "SELECT * FROM `mail_conts` WHERE `id_user` = '$user[id]' AND `id_ank` = '$ank[id]' AND `type` = 'all'"));
mysqli_query($dbi, "UPDATE `mail` SET `id_cont` = '$tcont[id]' WHERE `id_cont` = '$cont[id]'");
mysqli_query($dbi, "DELETE FROM `mail_conts` WHERE `id` = '$cont[id]'");
}
msg_sess("Контакты успешно восстановлены");
}
}
}
}
}
elseif (isset($_POST['contact_delete_all']) && $_POST['mdp']==$mdp && $sort=='trash')
{
$q=mysqli_query($dbi, "SELECT * FROM `mail_conts` WHERE `id_user` = '$user[id]' AND `type` = 'trash'");
while($cont=mysqli_fetch_array($q))
{
mysqli_query($dbi, "DELETE FROM `mail_conts` WHERE `id` = '$cont[id]'");
mysqli_query($dbi, "DELETE FROM `mail` WHERE `id_cont` = '$cont[id]'");
msg_sess("Контакты успешно удалены");
}
}
}
$title .= ' - Список контактов';
ex_head();
if ($sort=='arhive')echo "<div class='list'>Архив</div>n";
elseif ($sort=='favorite')echo "<div class='list'>Избранное</div>n";
elseif ($sort=='trash')echo "<div class='list'>Корзина</div>n";
else echo "<div class='menu'><img src='/i/site/new_mail.png' /> <a href='/mail/?act=new_message'>Новое сообщение</a><br />n";
echo "</div>n";
$csearch=NULL;
if (isset($_SESSION['csearch']))$csearch = $_SESSION['csearch'];
if (isset($_POST['csearch']))$csearch = $_POST['csearch'];
if ($csearch==NULL)unset($_SESSION['csearch']);
else $_SESSION['csearch']=$csearch;
$csearch= @preg_replace("#( ){1,}#","",$csearch);
if ($sort!='all')unset($csearch);
echo "<form method='POST' class='multi'>n";
echo "<input type='hidden' name='mdp' value='".$mdp."'/>n";
$count_results = mysqli_num_rows(mysqli_query($dbi, "SELECT * FROM `mail_conts` WHERE `id_user` = '$user[id]' AND `type` = '$sort'".(isset($_GET['go']) && $csearch!=NULL?" AND `nick` like '%".my_esc($csearch)."%'":NULL).""));
$count_pages = navi :: count_pages($count_results);
$page = navi :: page();
$start = navi :: start_pages();
if ($count_results == 0)
{
echo "<div class='list'>n";
if (isset($_GET['go']) && $csearch!=NULL) {
echo "Поиск не дал результатовn";
} else {
echo "Список контактов пустn";
}
echo "</div>n";
}
$query = mysqli_query($dbi, "SELECT * FROM `mail_conts` WHERE `id_user` = '$user[id]' AND `type` = '$sort'".(isset($_GET['go']) && $csearch!=NULL?" AND `nick` like '%".my_esc($csearch)."%' ORDER BY `nick` ASC":" ORDER BY `time_last` DESC, `count` DESC")." LIMIT $start, $config[rop]");
while ($post = mysqli_fetch_array($query))
{
$post['count_in'] = mysqli_num_rows(mysqli_query($dbi, "SELECT * FROM `mail` WHERE `id_cont` = '$post[id]' AND `type` = 'to'"));
$post['count_out'] = mysqli_num_rows(mysqli_query($dbi, "SELECT * FROM `mail` WHERE `id_cont` = '$post[id]' AND `type` = 'at'"));
$ank = profile($post['id_ank']);
echo "<div class='list'>n";
if ($sort != 'favorite')echo "<input type='checkbox' name='cd_$post[id]' value='1'/> n";
echo ($post['count']!=0?'<b class="none">':null);
echo profile_icon($ank['id'])."<a href='?act=cont&id=$post[id]'>$ank[nick]</a>".profile_medal($ank['id'])." n";
echo ($post['count']!=0?'</b>':null);
if ($sort == 'favorite')
{
$cont2 = mysqli_fetch_array(mysqli_query($dbi, "SELECT * FROM `mail_conts` WHERE `id_user` = '$user[id]' AND `id_ank` = '$post[id_ank]' AND `type` = 'all'"));
echo "<span style='color: green; font-size: small;'>(".mysqli_num_rows(mysqli_query($dbi, "SELECT * FROM `mail_conts` INNER JOIN `mail` ON `mail`.`id_cont`=`mail_conts`.`id` WHERE `mail`.`favorite` = '1' AND `mail`.`id_user` = '$user[id]' AND (`mail_conts`.`type` = 'all' OR `mail_conts`.`type` = 'arhive') AND `mail`.`id_cont` = '$cont2[id]'")).")</span>n";
} else echo " <span style='color: green; font-size: small;'>".($post['count']!=0?"<b class='none'>":null)."($post[count_in]/$post[count_out])".($post['count']!=0?"</b>":null)."</span>";
if ($post['count']!=0)echo " <span style='color: red; font-size: small;'>(+$post[count])</span>";
echo "</div>n";
}
navi :: pages_show("?");
if ($sort!='favorite')
{
echo "<div class='mod_grad'>n";
echo "<span style='font-size:small'>Отмеченные контакты:</span><br/>";
if ($sort=='all')echo "<input type='submit' name='contact_archive' value='в архив'/> ";
if ($sort=='trash')echo "<input type='submit' name='contact_reset' value='восстановить'/> ";
echo "<input type='submit' name='contact_delete' value='удалить'/>";
if ($sort=='trash')echo " <input type='submit' name='contact_delete_all' value='очистить корзину'/> ";
echo "</div>n";
}
echo "</form>";
if ($sort=='all')
{
echo "<div class='foot'>n";
echo "<form method='post' action='?go'>n";
echo "<span style='font-size:small'>Поиск контакта:</span><br />n";
echo "<input type='text' name='csearch' size='12' value=''/>n";
echo "<input type='submit' value='Go!'/>n";
echo "</form>n";
echo "</div>";
} else echo '<div class="foot">'.image_back().' <a href="/mail">Почта</a></div>';
echo "<div class='mod_grad'>";
echo "<img src='/i/site/favourite.png' /> <a href='?favorite'>Избранное</a> (".mysqli_num_rows(mysqli_query($dbi, "SELECT * FROM `mail_conts` WHERE `id_user` = '$user[id]' AND `type` = 'favorite'")).")<br/>n";
echo "<img src='/i/site/archive.png' /> <a href='?arhive'>Архив</a> (".mysqli_num_rows(mysqli_query($dbi, "SELECT * FROM `mail_conts` WHERE `id_user` = '$user[id]' AND `type` = 'arhive'")).")<br/>n";
echo "<img src='/i/site/trash.png' /> <a href='?trash'>Корзина</a> (".mysqli_num_rows(mysqli_query($dbi, "SELECT * FROM `mail_conts` WHERE `id_user` = '$user[id]' AND `type` = 'trash'")).")<br />n";
echo "</div>";
echo "<div class='foot'>";
echo "Принимать почту: <a href='/settings/?act=mail'>".($user['set_mail']==2?"<span style='color:blue'><b>Только от друзей":"<span style='color:green'><b>От всех")."</b></span></a>";
echo "</div>";
ex_foot();
?>