Файл: forum/read.php
Строк: 290
<?
session_start();
include ("header.php");
$data=date("YmdHi");
$data4=date("Ymd");
$ref=rand(100000,1000000);
if (empty($mod)) $mod="index";
echo $div["header"];
if (!$autorize) { echo "[<a href="login.php?">Вход</a>][<a href="reg.php">Регистрация</a>]<br/>";
echo "-<br/>";
}
switch ($mod) {
case "index":
echo "Сообщения<br/>";
echo $div["end"];
echo $div["div"];
$qi = mysql_query("select * from `letters` where ((`read`='0')and(`komu`='$login')and(`inout`='in'));");
$i=mysql_num_rows($qi);
$qir = mysql_query("select * from `letters` where ((`komu`='$login')and(`inout`='in'));");
$ir=mysql_num_rows($qir);
echo "<a href="read.php?mod=input&".session_name()."=".session_id()."">Входящие</a>($ir)[$i]<br/>";
$qir = mysql_query("select * from `letters` where ((`komu`='$login')and(`inout`='out'));");
$ir=mysql_num_rows($qir);
echo "<a href="read.php?mod=output&".session_name()."=".session_id()."">Отправленные</a>($ir)<br/>";
echo "-<br/>";
echo "<a href="read.php?mod=sent&".session_name()."=".session_id()."">Написать</a><br/>";
echo "-<br/>";
echo "<a href="read.php?mod=delall&".session_name()."=".session_id()."">Удалить все сообщения</a><br/>";
break;
case "input":
$page=@$_GET['page'];
if (!isset($page) || $page=='' || $page<1 ) {
$page=1;}
$max_lines_on_page=$autorize['letmsg'];
$maxpages=5;
$t=2;
$limit=($page-1)* $max_lines_on_page;
$q=mysql_query("select * from `letters` where ((`komu`='$login')and(`inout`='in'));");
$all=mysql_num_rows($q);
$query = mysql_query("select * from `letters` where ((`komu`='$login')and(`inout`='in')) order by `id` desc LIMIT $limit, $max_lines_on_page;");
echo "<b>Входящие</b><br/>";
echo $div["end"];
echo $div["div"];
if ($_SESSION['wap']!="xml") {echo "-<br/>";}
if (mysql_affected_rows()==0)
{
echo "Сообщений нет!<br/>";
}
else
{
echo $div["end"];
echo $div["ten"];
while ($field=mysql_fetch_array($query))
{
$id=$field['id'];
$who=$field['who'];
$data_msg=$field['data'];
$read=$field['read'];
echo "<a href="read.php?mod=read&msgid=$id&".session_name()."=".session_id()."">$who</a>[$data_msg]";if ($read==0){ echo "<b>[NEW]</b>"; }
echo "<br/>";
}
echo $div["end"];
echo $div["div"];
}
//функция навигации
function PRINT_NUM_PAGE(){
global $page,$all, $max_lines_on_page, $max_pages_on_page, $maxpages, $t, $p;
$maxpage=ceil($all/$max_lines_on_page);
if ($maxpage>0&&$maxpage!=1){
echo "-<br/>";
if ($page>1) echo "<a href="".$PHP_SELF."?mod=input&page=".($page-1)."&".session_name()."=".session_id()."">«-</a>";
else echo "«-";
echo " | </small><input name="page" maxlength="3" value="1" size="3"/><small>";
echo "<a href="".$PHP_SELF."?mod=input&page=$(page)&".session_name()."=".session_id()."">»</a> | ";
if ($page<$maxpage) echo " <a href="".$PHP_SELF."?mod=input&page=".($page+1)."&".session_name()."=".session_id()."">-»</a> <br/>";
else echo " -» <br/>";
if ($page>4) {echo "<a href="".$PHP_SELF."?mod=input&page=1">1</a> ... "; }
if ($t=='2'){
$l=$page - floor($maxpages/2);
$r=$page + floor($maxpages/2);
if ($l<1){$l='1'; $r=$maxpages;}
if ($r>$maxpage){$r=$r+$r/2;}
if (($page-1)>$maxpages-3/2){ $ll=$l+1; echo "<a href="".$PHP_SELF."?mod=input&page=$ll&".session_name()."=".session_id()."">«</a> ";
}
}else{
$l = ceil($page/$maxpages)*$maxpages+1- $maxpages;
$r = ceil($page/$maxpages)*$maxpages;
}
$l=$l;
for ($l; $l<=$r; $l++){
if ($l>$maxpage)break;
if ($l == $page){
print " <b>$page</b> ";
}else{
echo " <a href="".$PHP_SELF."?mod=input&page=$l&".session_name()."=".session_id()."">$l</a> ";}
}
if ($maxpage>$r) { $ll=$r+1;
echo "<a href="".$PHP_SELF."?mod=input&page=$ll&".session_name()."=".session_id()."">»</a> ";}
if ($page<$maxpage-2) {echo "... <a href="".$PHP_SELF."?mod=input&page=$maxpage&".session_name()."=".session_id()."">$maxpage</a> ";}
echo "<br/>";
}
echo "-<br/>";
echo "[<a href="read.php?mod=index&".session_name()."=".session_id()."">Сообщения</a>]<br/>";
}
PRINT_NUM_PAGE();
break;
case "output":
$page=@$_GET['page'];
if (!isset($page) || $page=='' || $page<1 ) {
$page=1;}
$max_lines_on_page=$autorize['letmsg'];
$maxpages=5;
$t=2;
$limit=($page-1)* $max_lines_on_page;
$q= mysql_query("select * from `letters` where ((`komu`='$login')and(`inout`='out'));");
$all=mysql_num_rows($q);
$query = mysql_query("select * from `letters` where ((`komu`='$login')and(`inout`='out')) order by `id` desc LIMIT $limit, $max_lines_on_page;");
echo "<b>Отправленные:</b><br/>";
echo $div["end"];
echo $div["div"];
if ($_SESSION['wap']!="xml") {echo "-<br/>";}
if (mysql_affected_rows()==0)
{
echo "Сообщений нет!<br/>";
}
else
{
echo $div["end"];
echo $div["ten"];
while ($field=mysql_fetch_array($query))
{
$id=$field['id'];
$who=$field['who'];
$data_msg=$field['data'];
$read=$field['read'];
echo "<a href="read.php?mod=readout&msgid=$id&".session_name()."=".session_id()."">$who</a>[$data_msg]";
echo "<br/>";
}
echo $div["end"];
echo $div["div"];
}
//функция навигации
function PRINT_NUM_PAGE(){
global $page,$all, $max_lines_on_page, $max_pages_on_page, $maxpages, $t, $p;
$maxpage=ceil($all/$max_lines_on_page);
if ($maxpage>0&&$maxpage!=1){
echo "-<br/>";
if ($page>1) echo "<a href="".$PHP_SELF."?mod=output&?page=".($page-1)."&".session_name()."=".session_id()."">«-</a>";
else echo "«-";
echo " | </small><input name="page" maxlength="3" value="1" size="3"/><small>";
echo "<a href="".$PHP_SELF."?mod=output&page=$(page)&".session_name()."=".session_id()."">»</a> | ";
if ($page<$maxpage) echo " <a href="".$PHP_SELF."?mod=output&page=".($page+1)."&".session_name()."=".session_id()."">-»</a> <br/>";
else echo " -» <br/>";
if ($page>4) {echo "<a href="".$PHP_SELF."?mod=output&page=1">1</a> ... "; }
if ($t=='2'){
$l=$page - floor($maxpages/2);
$r=$page + floor($maxpages/2);
if ($l<1){$l='1'; $r=$maxpages;}
if ($r>$maxpage){$r=$r+$r/2;}
if (($page-1)>$maxpages-3/2){ $ll=$l+1; echo "<a href="".$PHP_SELF."?mod=output&page=$ll&".session_name()."=".session_id()."">«</a> ";
}
}else{
$l = ceil($page/$maxpages)*$maxpages+1- $maxpages;
$r = ceil($page/$maxpages)*$maxpages;
}
$l=$l;
for ($l; $l<=$r; $l++){
if ($l>$maxpage)break;
if ($l == $page){
print " <b>$page</b> ";
}else{
echo " <a href="".$PHP_SELF."?mod=output&page=$l&".session_name()."=".session_id()."">$l</a> ";}
}
if ($maxpage>$r) { $ll=$r+1;
echo "<a href="".$PHP_SELF."?mod=output&page=$ll&".session_name()."=".session_id()."">»</a> ";}
if ($page<$maxpage-2) {echo "... <a href="".$PHP_SELF."?mod=output&page=$maxpage&".session_name()."=".session_id()."">$maxpage</a> ";}
echo "<br/>";
}
echo "-<br/>";
echo "[<a href="read.php?mod=index&".session_name()."=".session_id()."">Сообщения</a>]<br/>";
}
PRINT_NUM_PAGE();
break;
case "read":
$q_msg = mysql_query("select * from `letters` where ((`komu`='$login')and(`id`='$msgid')and(`inout`='in'));");
if (mysql_affected_rows()==0)
{
echo "Нет такого сообщения!<br/>";
echo $div["end"];
echo $div["div"];
}
else
{
$row_msg=mysql_fetch_array($q_msg);
$who=$row_msg['who'];
$db_data=$row_msg['data'];
$msg=$row_msg['msg'];
echo "<b>Сообщение от:</b>[<a href="anketa.php?user=$who&".session_name()."=".session_id()."">$who</a>]<br/>";
echo $div["end"];
echo $div["div"];
echo "Дата: <b>$db_data</b><br/>";
if ($autorize['sml']==1) {$msg=smile($msg);}
echo "Сообщение: <b>$msg</b><br/>";
@mysql_query("UPDATE `letters` SET `read`='1' WHERE `id`='$msgid';");
}
echo "-<br/>";
echo "[<a href="read.php?mod=sent&user=$who&".session_name()."=".session_id()."">Ответить</a>]<br/>";
echo "-<br/>";
echo "[<a href="read.php?mod=delin&delid=$msgid&".session_name()."=".session_id()."">Удалить</a>]<br/>";
echo "-<br/>";
echo "[<a href="read.php?mod=input&".session_name()."=".session_id()."">Входящие</a>]<br/>";
break;
case "readout":
$q_msg = mysql_query("select * from `letters` where ((`komu`='$login')and(`id`='$msgid')and(`inout`='out'));");
if (mysql_affected_rows()==0)
{
echo "Нет такого сообщения!<br/>";
echo $div["end"];
echo $div["div"];
}
else
{
$row_msg=mysql_fetch_array($q_msg);
$who=$row_msg['who'];
$db_data=$row_msg['data'];
$msg=$row_msg['msg'];
echo "<b>Сообщение от:</b>[<a href="anketa.php?user=$who&".session_name()."=".session_id()."">$who</a>]<br/>";
echo $div["end"];
echo $div["div"];
echo "Дата: <b>$db_data</b><br/>";
if ($autorize['sml']==1) {$msg=smile($msg);}
echo "Сообщение: <b>$msg</b><br/>";
@mysql_query("UPDATE `letters` SET `read`='1' WHERE `id`='$msgid';");
}
//echo "-<br/>";
//echo "[<a href="read.php?mod=sent&user=$who&".session_name()."=".session_id()."">Ответить</a>]<br/>";
echo "-<br/>";
echo "[<a href="read.php?mod=delout&delid=$msgid&".session_name()."=".session_id()."">Удалить</a>]<br/>";
echo "-<br/>";
echo "[<a href="read.php?mod=output&".session_name()."=".session_id()."">Отправленные</a>]<br/>";
break;
case "sent":
if (empty($go)){
echo "Написать: <br/>";
echo $div["end"];
if ($_SESSION['wap']=="xml")
{
echo "<form action="read.php?mod=sent&go=add&".session_name()."=".session_id()."" method="post">";
echo "<div>";
echo "Кому: <br/>";
echo "<input name="komu" value="$user" title="Text"/><br/>";
echo "Сообщение: <br/>";
echo "<input name="msg" title="Text"/><br/>";
echo "<input class="ibutton" type="submit" value="Отправить"/>";
echo "</div>";
echo "</form>";
}
else
{
echo "Кому: <br/>";
echo "</small><input name="komu".$ref."" maxlength="20" value="$user" title="Text"/><br/><small>";
echo "Сообщение: <br/>";
echo "</small><input name="msg".$ref."" maxlength="200" title="Text"/><br/><small>";
echo "<anchor title="send">Отправить<go href="read.php?mod=sent&go=add&".session_name()."=".session_id()."" method="post">";
echo "<postfield name="komu" value="$(komu".$ref.")"/>";
echo "<postfield name="msg" value="$(msg".$ref.")"/>";
echo "</go></anchor><br/>";
}
echo $div["div"];
echo "-<br/>";
echo "[<a href="read.php?mod=index&".session_name()."=".session_id()."">Сообщения</a>]<br/>";
}
else
{
$q = mysql_query("select * from `users` where `login`='$komu';");
if (mysql_affected_rows()==0)
{
echo "Нет такого!<br/>";
echo $div["end"];
echo $div["div"];
echo "-<br/>";
echo "[<a href="read.php?mod=index&".session_name()."=".session_id()."">Сообщения</a>]<br/>";
}
else
{
if (!empty($msg))
{
$datamsg=date("d.m.Y H:i");
$k=$autorize['login'];
@mysql_query("insert into `letters` values(0,'$k','$komu','$msg','$datamsg','0','in');")or die ("FUCK");
@mysql_query("insert into `letters` values(0,'$komu','$k','$msg','$datamsg','0','out');")or die ("FUCK");
echo "Сообщение отправленно!<br/>";
echo $div["end"];
}
else
{
echo "Сообщение не может быть пустым!<br/>";
echo $div["end"];
}
echo $div["div"];
echo "-<br/>";
echo "[<a href="read.php?mod=index&".session_name()."=".session_id()."">Сообщения</a>]<br/>";
}
}
break;
case "delall":
mysql_query("delete from `letters` where ((`komu`='$login')and(`inout`='in'))");
mysql_query("delete from `letters` where ((`who`='$login')and(`inout`='out'))");
echo "Сообщения удалены!<br/>";
echo $div["end"];
echo $div["div"];
echo "-<br/>";
echo "[<a href="read.php?mod=index&".session_name()."=".session_id()."">Сообщения</a>]<br/>";
break;
case "delin":
mysql_query("delete from `letters` where ((`komu`='$login')and(`inout`='in')and(`id`='$delid'))");
echo "Сообщение удалено!<br/>";
echo $div["end"];
echo $div["div"];
echo "-<br/>";
echo "[<a href="read.php?mod=input&".session_name()."=".session_id()."">Входящие</a>]<br/>";
break;
case "delout":
mysql_query("delete from `letters` where ((`who`='$login')and(`inout`='out')and(`id`='$delid'))");
echo "Сообщение удалено!<br/>";
echo $div["end"];
echo $div["div"];
echo "-<br/>";
echo "[<a href="read.php?mod=output&".session_name()."=".session_id()."">Отправленные</a>]<br/>";
break;
}
echo "-<br/>";
echo "[<a href="index.php?".session_name()."=".session_id()."">Назад в форум</a>]<br/>";
if ($_SESSION['wap']!="xml") {echo "-<br/>";}
echo $div["end"];
include ("footer.php");
?>