<?php
include('header.php');
$hide_footer = -1;
$counter = 0;
$qqq = 1;
$pageTitle = "$l_view_new_posts";
$sort = "DESC";
$bys = "post_date";
$userid = -5;
if (isset($_SESSION['user_id']))
{$userid = $_SESSION['user_id'];}
if (isset($_GET['sort']))
{
if (safeEscape($_GET['sort']) == "desc") {
$sort = "DESC";
$bys = "post_date";
}
if (safeEscape($_GET['sort']) == "asc") {
$sort = "ASC";
$bys = "post_date";
}
if (safeEscape($_GET['sort']) == "sub") {
$sort = "ASC";
$bys = "post_subject";
}
}
?>
<!--<br />Sort by:
<select class="dropdown" name="sort" ONCHANGE="location = this.options[this.selectedIndex].value;">
<option value="view_new.php?sort=desc">-----</option>
<option value="view_new.php?sort=desc">Descending</option>
<option value="view_new.php?sort=asc" >Ascending</option>
<option value="view_new.php?sort=sub" >Post Subject</option>
</select><br />
-->
<?php
echo "<b>$l_view_new_posts</b><hr/>";
$check_approved = "AND " . $table_prefix . "topics.topic_status <= 1";
if (isset($_SESSION['user_level']) AND $_SESSION['user_level']>=1)
{$check_approved = "";}
$result = $db->query("SELECT COUNT(*)
FROM " . $table_prefix . "topics
WHERE
topic_date >= NOW() + INTERVAL $server_time MINUTE + INTERVAL $time_difference HOUR - INTERVAL 30 DAY
$check_approved
ORDER BY
topic_date DESC LIMIT 1");
if (!$result) {
echo "An error occured, please try again later.";
} else {
$r = $db->fetch_row($result);
$numrows = $r[0];
$rowsperpage = $max_search_results;
$totalpages = ceil($numrows / $rowsperpage);
if ($totalpages == 0) {
$totalpages = 1;
}
echo "<table><tr>";
if (isset($_GET['page']) && is_numeric($_GET['page'])) {
$currentpage = (int)$_GET['page'];
} else {
$currentpage = 1;
}
if ($currentpage > $totalpages) {
$currentpage = $totalpages;
}
if ($currentpage < 1) {
$currentpage = 1;
}
$offset = ($currentpage - 1) * $rowsperpage;
$current_page = $page;
if ($current_page == "") {
$current_page = 1;
}
$range = $max_pagination_link;
if ($range >= $totalpages) {
$range = $totalpages;
}
echo '<td align="right" class="pagination"> <b>' . $l_page . ' ' . $current_page . ' ' . $l_page_of . ' ' . $totalpages . '</b> [' . $numrows . ' ' . $l_maches . '] ';
if ($currentpage > 1) {
echo " <a title= '$l_first_page' href='{$_SERVER['PHP_SELF']}?page=1'><<</a> ";
$prevpage = $currentpage - 1;
echo " <a title='$l_prev_page' href='{$_SERVER['PHP_SELF']}?page=$prevpage'><</a> ";
}
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
if (($x > 0) && ($x <= $totalpages)) {
if ($x == $currentpage) {
echo " [<b>$x</b>] ";
} else {
echo " <a title='$l_goto_page " . $x . "' href='{$_SERVER['PHP_SELF']}?page=$x'>$x</a> ";
}
}
}
if ($currentpage != $totalpages) {
$nextpage = $currentpage + 1;
echo " <a title='$l_next_page' href='{$_SERVER['PHP_SELF']}?page=$nextpage'>></a> ";
echo " <a title='$l_goto_last_page' href='{$_SERVER['PHP_SELF']}?page=$totalpages'>>></a> ";
}
echo '</td></tr></table>';
if ($page <= 0 or $page > $totalpages) {
$page = 1;
}
$offset = $max_search_results * ($page - 1);
$qqq += 1;
$sql = "SELECT
" . $table_prefix . "topics.topic_id,
" . $table_prefix . "topics.topic_subject,
" . $table_prefix . "topics.topic_date,
" . $table_prefix . "topics.topic_cat,
" . $table_prefix . "topics.topic_by,
" . $table_prefix . "topics.topic_permission,
" . $table_prefix . "topics.view,
" . $table_prefix . "topics.reply,
" . $table_prefix . "topics.topic_starter,
" . $table_prefix . "topics.topic_last_poster_id,
" . $table_prefix . "topics.topic_last_poster,
" . $table_prefix . "topics.topic_last_post_date,
" . $table_prefix . "topics.topic_sort,
" . $table_prefix . "topics.topic_icon,
" . $table_prefix . "topics.topic_status,
" . $table_prefix . "categories.cat_id,
" . $table_prefix . "categories.cat_permission,
" . $table_prefix . "categories.cat_name
FROM
" . $table_prefix . "topics
LEFT JOIN
" . $table_prefix . "categories
ON
" . $table_prefix . "categories.cat_id = " . $table_prefix . "topics.topic_cat
WHERE
" . $table_prefix . "topics.topic_last_post_date >= NOW() - INTERVAL 30 DAY
$check_approved
ORDER BY
" . $table_prefix . "topics.topic_last_post_date $sort
LIMIT $offset, $max_search_results";
/*$result2 = $db->query("
SELECT * FROM " . $table_prefix . "topics
WHERE
topic_last_post_date >= NOW() - INTERVAL 30 DAY
$check_approved
ORDER BY
topic_last_post_date
DESC
LIMIT $offset, $max_search_results");*/
$result2 = $db->query($sql);
if (!$result2) {
echo "An error occured!";
die;
}
$qqq += 1;
$cat_icon = '*';
$tags = array('{ICON}', '{TOPIC}', '{REPLIES}', '{VIEWS}', '{CREATED}', );
$data = array($cat_icon, $l_topic, $l_replies, $l_views, $l_created);
echo str_replace($tags, $data, file_get_contents("./style/" . $default_style . "/topics.html"));
while ($list = $db->fetch_array($result2,'assoc')) {
/*$result44 = $db->query("
SELECT cat_id,
cat_permission,
cat_name
FROM " . $table_prefix . "categories
WHERE
cat_id = $list[topic_cat]
LIMIT 1");
$row44 = $db->fetch_array($result44,'assoc');*/
if ($list['cat_permission'] == 3 and isset($_SESSION['signed_in']) and $_SESSION['user_level'] >= 1) {
$hide_forum = 0;
}
if ($list['cat_permission'] == 3 and isset($_SESSION['signed_in']) and $_SESSION['user_level'] < 1) {
$hide_forum = 1;
}
if ($list['cat_permission'] == 3 and !isset($_SESSION['signed_in'])) {
$hide_forum = 1;
}
if ($list['cat_permission'] == 2 and !isset($_SESSION['signed_in'])) {
$hide_forum = 1;
}
if ($list['cat_permission'] == 2 and isset($_SESSION['signed_in'])) {
$hide_forum = 0;
}
if ($list['cat_permission'] <= 1) {
$hide_forum = 0;
}
$pages = ceil(($list['reply']) / $post_per_page);
if ($pages == 0) {
$pages = 1;
}
if ($hide_forum != 1) {
$last_poster = "<a class='last_poster' href = 'user.php?u=" . $list['topic_last_poster_id'] . "'>" . $list['topic_last_poster'] . "</a>";
if ($list['topic_last_poster_id'] <= 1) {
$last_poster = "<i>" . $list['topic_last_poster'] . "</i>";
}
//TOPIC ICONS
$topic_icon = "./style/" . $default_style . "/img/normal_post.gif";
$title_icon = "$l_tnormal";
if ($list['reply'] >= $hot_topics_post) {
$topic_icon = "./style/" . $default_style . "/img/topic_hot.gif";
$title_icon = "$l_thot";
}
if ($list['topic_by'] == $userid) {
$topic_icon = "./style/" . $default_style . "/img/my_topic.gif";
$title_icon = "$l_tyou";
}
if ($list['topic_by'] == $userid and $list['reply'] >= $hot_topics_post) {
$topic_icon = "./style/" . $default_style . "/img/my_hot_topic.gif";
$title_icon = "$l_thotyou";
}
if ($list['topic_status'] == 1) {
$topic_icon = "./style/" . $default_style . "/img/topic_locked.gif";
$title_icon = "$l_tlocked";
}
$latest = "./style/" . $default_style . "/img/";
if ($list['topic_sort'] == -1) {
$topic_icon = "./style/" . $default_style . "/img/quick_sticky.gif";
$title_icon = "$l_tsticky";
}
$latest = "./style/" . $default_style . "/img/";
if ($list['topic_sort'] == -1 and $list['topic_status'] == 1) {
$topic_icon = "./style/" . $default_style . "/img/normal_post_locked_sticky.gif";
$title_icon = "$l_tlockedsticky";
}
$latest = "./style/" . $default_style . "/img/";
$tpages = ceil(($list['reply'] + 1) / $post_per_page);
if ($tpages <= 1) {
$topic_pages = "";
} else {
$topic_pages = " (<img src = './style/$default_style/img/more_pages_view.gif'> <a class='underline' href = 'topic.php?t=$list[topic_id]&page=1'>1</a>";
$topic_pages .= " <a class='underline' href = 'topic.php?t=$list[topic_id]&page=2'>2</a>";
if ($tpages > 2) {
$topic_pages .= " <a class='underline' href = 'topic.php?t=$list[topic_id]&page=3'>3</a>";
}
if ($tpages > 3) {
$topic_pages .= " <a class='underline' href = 'topic.php?t=$list[topic_id]&page=4'>4</a>";
}
if ($tpages > 4) {
$topic_pages .= " <a class='underline' href = 'topic.php?t=$list[topic_id]&page=5'>5</a>";
}
if ($tpages > 5) {
$topic_pages .= " <a class='underline' href = 'topic.php?t=$list[topic_id]&page=6'>6</a>";
}
if ($tpages > 6) {
$topic_pages .= " <a class='underline' href = 'topic.php?t=$list[topic_id]&page=7'>7</a>";
}
if ($tpages > 7) {
$topic_pages .= " <a class='underline' href = 'topic.php?t=$list[topic_id]&page=8'>8</a>";
}
if ($tpages > 8) {
$topic_pages .= " ... <a class='underline' href = 'topic.php?t=$list[topic_id]&page=$pages'>last page</a>";
}
$topic_pages .= ")";
}
if ($list['topic_icon'] != "" and $list['topic_icon'] != "0") {
$t_icon = "<img style='vertical-align: middle;' src='./img/misc/" . $list['topic_icon'] . "' />";
} else {
$t_icon = "";
}
$pages = ceil(($list['reply']) / $post_per_page);
if ($pages == 0) {$pages += 1;}
$last_post = $list['reply'];
$last_post += 1;
$in_forum = "$l_in <i><a href='category.php?f=$list[cat_id]'>$list[cat_name]</a></i>";
$topic_author = "$l_started_by <a href='user.php?u=" . $list['topic_by'] . "'>" . $list['topic_starter'] . "</a>";
$tags = array('{F_ID}', '{T_ID}', '(TOPIC_SUBJECT)', '{TOPIC_AUTHOR}', '{REPLY}', '{VIEW}', '{T_DATE}', '{LAST_POSTER}', '{PAGE}', '{LAST_POST}', '{IMG_PATH}', '{TITLE}', '{SMALL_ICON}', '{PAGES}', '{TOPIC_ICON}','{VIEW_LATEST}','{BY}','{IN_FORUM}');
$data = array($fid, $list['topic_id'], trim($list['topic_subject']), $topic_author, $list['reply'], $list['view'], date($date_format, strtotime($list['topic_last_post_date']." $user_time hours")), $last_poster, $pages, $last_post, $topic_icon, $title_icon, $latest, $topic_pages, $t_icon,$l_view_latest,$l_by,$in_forum);
echo str_replace($tags, $data, file_get_contents("./style/" . $default_style . "/topics_row.html"));
$counter += 1;
}
}
echo "</tr></td></table>";
if ($db->num_rows($result2) > 0) {
// BOTTOM PAGINATION
echo "<table><tr><th></th></tr><tr>";
$range = $max_pagination_link;
if ($range >= $totalpages) {
$range = $totalpages;
}
echo '<td align="right" class="pagination"> <b>' . $l_page . ' ' . $current_page . ' ' . $l_page_of . ' ' . $totalpages . '</b> [' . $numrows . ' ' . $l_maches . '] ';
if ($currentpage > 1) {
echo " <a title= '$l_first_page' href='{$_SERVER['PHP_SELF']}?t=" . safeEscape($_GET['t']) . "&page=1'><<</a> ";
$prevpage = $currentpage - 1;
echo " <a title='$l_prev_page' href='{$_SERVER['PHP_SELF']}?t=" . safeEscape($_GET['t']) . "&page=$prevpage'><</a> ";
}
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
if (($x > 0) && ($x <= $totalpages)) {
if ($x == $currentpage) {
echo " [<b>$x</b>] ";
} else {
echo " <a title='$l_goto_page " . $x . "' href='{$_SERVER['PHP_SELF']}?t=$topicid&page=$x'>$x</a> ";
}
}
}
if ($currentpage != $totalpages) {
$nextpage = $currentpage + 1;
echo " <a title='$l_next_page' href='{$_SERVER['PHP_SELF']}?t=$topicid &page=$nextpage'>></a> ";
echo " <a title='$l_goto_last_page' href='{$_SERVER['PHP_SELF']}?t=$topicid &page=$totalpages'>>></a> ";
}
echo '</td></tr></table> ';
}
// BOTTOM PAGINATION END
echo '</table><br />' . $l_search_found . ' ' . $numrows . ' ' . $l_maches . '';
$counter = 0;
}
if ($hide_footer < 1) {
include 'footer.php';
}
$pageContents = ob_get_contents();
ob_end_clean();
echo str_replace('<!--TITLE-->', $pageTitle, $pageContents);
?>