Файл: Source/pages/pm.php
Строк: 204
<?php
/*
* Script name: Points4Prize
* Author: Soft Projects
* Date created: 15/07/2015
*/
require_once 'inc/header.php';
if (!isset($_SESSION['logged_in'])) {
$_SESSION['location'] = "/pm";
header('Location: /login');
exit();
}
?>
<body class="no-slider">
<!-- <body class="has-top-menu"> -->
<!-- BEGIN #slider-imgs -->
<div id="slider-imgs">
<div class="featured-img-box">
<div id="featured-img-1" class="featured-img"></div>
<div id="featured-img-2" class="featured-img invisible"></div>
<div id="featured-img-3" class="featured-img invisible"></div>
<div id="featured-img-4" class="featured-img invisible"></div>
</div>
<!-- END #slider-imgs -->
</div>
<!-- BEGIN #top-layer -->
<div id="top-layer">
<div id="header-top">
<?php
require_once 'inc/header_top.php';
?>
</div>
<section id="content">
<header id="header">
<div id="menu-bottom">
<?php
require_once 'inc/menu_bottom.php';
?>
</div>
<div class="wrapper">
<div class="header-breadcrumbs">
<?php
require_once 'inc/stats.php';
?>
<ul>
<li><a href="index.php">Home</a></li>
<li>Messages</li>
</ul>
</div>
</div>
</header>
<div id="main-box" class="full-width">
<?php
if (isset($_POST['mark'])) {
if (!isset($_SESSION['logged_in'])) {
$_SESSION['location'] = "/pm";
header('Location: /login');
exit();
} else {
if (isset($_SESSION['user'], $_SESSION['pass'])) {
$user = str_replace(" ", "", $_SESSION['user']);
$user = sprintf("%s", mysql_real_escape_string($user));
} else {
$user = str_replace(" ", "", $_COOKIE['user']);
$user = sprintf("%s", mysql_real_escape_string($user));
}
$count = 0;
$result = mysql_query("SELECT * FROM vn_messages WHERE forw='{$user}'") or die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
if ($_POST["remember" . $row['id']] == "on") {
$count = $count + 1;
mysql_query("UPDATE vn_messages SET readed='1' WHERE id='{$row[id]}' and forw='{$user}'") or die(mysql_error());
}
}
if ($count == 0) {
echo "<div class='info-message' style='background-color: #a24026;'> You have not selected message/s.</div>";
} elseif ($count > 1) {
echo "<div class='info-message' style='background-color: #75a226;'>The messages are marked as read.</div>";
} else {
echo "<div class='info-message' style='background-color: #75a226;'>The message is marked as read.</div>";
}
}
} elseif (isset($_POST['delete'])) {
if (!isset($_SESSION['logged_in'])) {
$_SESSION['location'] = "/pm";
header('Location: /login');
exit();
} else {
if (isset($_SESSION['user'], $_SESSION['pass'])) {
$user = str_replace(" ", "", $_SESSION['user']);
$user = sprintf("%s", mysql_real_escape_string($user));
} else {
$user = str_replace(" ", "", $_COOKIE['user']);
$user = sprintf("%s", mysql_real_escape_string($user));
}
$count = 0;
$result = mysql_query("SELECT * FROM vn_messages WHERE forw='{$user}'") or die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
if ($_POST["remember" . $row[id]] == "on") {
$count = 1;
mysql_query("DELETE FROM vn_messages WHERE id='{$row[id]}' and forw='{$user}'") or die(mysql_error());
}
}
if ($count == 0) {
echo "<div class='info-message' style='background-color: #a24026;'>You have not selected a message/s.</div>";
} else {
echo "<div class='info-message' style='background-color: #75a226;'>Messages deleted successfully.</div>";
}
}
} elseif (isset($_POST['write'])) {
header('Location: /sendpm');
exit();
}
if (isset($_SESSION['user'], $_SESSION['pass'])) {
$user = str_replace(" ", "", $_SESSION['user']);
$user = sprintf("%s", mysql_real_escape_string($user));
} else {
$user = str_replace(" ", "", $_COOKIE['user']);
$user = sprintf("%s", mysql_real_escape_string($user));
}
$checkalln = mysql_query("SELECT id,forw FROM vn_messages WHERE forw='{$user}'") or die(mysql_error());
$broi = mysql_num_rows($checkalln);
$pp = 15;
?>
<div id="main">
<h2><span>Messages(<?php echo $broi;?>)</span></h2>
<div class="content-padding">
<div class="messages-control">
<a href="/sendpm"
class="newdefbutton margin-right"><i class="fa fa-comments"></i>
New messages</a>
</div>
</div>
<div class="messages-container">
<?php
if ($broi > 0) {
$pages = ceil($broi / $pp);
$page = (int) $_GET['p'];
$page = sprintf("%s", mysql_real_escape_string($page));
if ($page == 0 || $page < 0 || $page == NULL) {
$page = 1;
}
if ($page > $pages) {
$page = $pages;
}
$begin = ($page * $pp) - $pp;
$result = mysql_query("SELECT * FROM vn_messages WHERE forw='{$user}' ORDER by time DESC LIMIT {$begin},{$pp}") or die(mysql_error());
for ($i = 0; $i < mysql_num_rows($result); ++$i) {
$row = mysql_fetch_array($result);
$date = date("d.m.Y H:i", $row['time']);
if ($row['readed'] == 0) {
$read = "unread";
} else {
$read = "read";
}
if (strlen($row['title']) > 26) {
$row['title'] = substr($row['title'], 0, 26) . '...';
}
$message = htmlspecialchars($row['message']);
$message = str_replace("[br]", "", $message);
$message = str_replace("[b]", "<b>", $message);
$message = str_replace("[/b]", "</b>", $message);
$message = str_replace("[quote]", "<i>", $message);
$message = nl2br(str_replace("[/quote]", "</i>", $message));
$result2 = mysql_query("SELECT user,avatar,vip FROM vn_users WHERE user='".$row['fromw']."'") or die (mysql_error());
$row2 = mysql_fetch_assoc($result2);
if(empty($row2['avatar'])) {
$avatar = "/uploads/avatars/noavatar.png";
} else {
$avatar = $row2['avatar'];
}
?>
<div class="message-block <?php echo $read;?>">
<a href="/u:<?php echo $row2['user'];?>" class="avatar">
<span class="wrapimg" style="display:inline-block;position:relative;border-radius:inherit;-moz-border-radius:inherit;overflow:hidden;"><img src="<?php echo $avatar;?>" class="setborder" title="" alt=""></span>
<strong>
<?php echo $row2['user']; ?>
</strong>
<i><?php echo $date;?></i>
</a>
<a href="/readpm-<?php echo $row['id'];?>" class="message-link">
<span class="msg-content"><?php echo $message; ?></span>
</a>
<a href="/deletepm-<?php echo $row['id'];?>"
class="messages-delete-conv strike-tooltip"><i class="fa fa-times"></i></a>
</div>
<?php
}
$next = $page + 1;
$next2 = $page + 2;
$prev = $page - 1;
$prev2 = $page - 2;
if ($pages >= $next) {
$nexts = "<button type='button' class='page' onClick="jump('/pm-$next');">></button>";
$pageup1 = "<button type='button' class='page' onClick="jump('/pm-$next');">$next</button>";
} else {
$nexts = "<button type='button' class='npage' disabled='disabled'>></button>";
}
if ($pages >= $next2) {
$pageup2 = "<button type='button' class='page' onClick="jump('/pm-$next2');">$next2</button>";
$last = "<button type='button' class='page' onClick="jump('/pm-$pages');">>></button>";
} else {
$last = "<button type='button' class='npage' disabled='disabled'>>></button>";
}
if ($page > 1) {
$prevs = "<button type='button' class='page' onClick="jump('/pm-$prev');"><</button>";
$pagedw1 = "<button type='button' class='page' onClick="jump('/pm-$prev');">$prev</button>";
} else {
$prevs = "<button type='button' class='npage' disabled='disabled'><</button>";
}
if ($page > 2) {
$pagedw2 = "<button type='button' class='page' onClick="jump('/pm-$prev2');">$prev2</button>";
$first = "<button type='button' class='page' onClick="jump('/pm-1');"><<</button>";
} else {
$first = "<button type='button' class='npage' disabled='disabled'><<</button>";
}
if ($page == 1 and $pages > 3) {
$pageup3 = "<button type='button' class='page' onClick="jump('/pm-4');">4</button>";
}
if ($page == $pages and $pages > 3) {
$pagedw3 = "<button type='button' class='page' onClick="jump('/pm-1');">1</button>";
}
if ($broi > $pp) {
echo "
<div style='text-align:left; margin:27px 20px 3px 10px; float:left;'>
$first $prevs $pagedw3 $pagedw2 $pagedw1 <button class='npage' disabled='disabled'>$page</button> $pageup1 $pageup2 $pageup3 $nexts $last
</div>
<div style='clear:both;'></div>";
}
}else{
?>
<br />
<br />
<center>Mail is empty.</center>
<?php
}
?>
</div>
<!-- END #main -->
</div>
</div>
</div>
</div>
<?php
require_once 'inc/footer.php';
?>