function RUN_Forums() { global $logged; if (is_numeric($_GET['id'])) { $id = intval(htmlspecialchars($_GET['id'])); //finish checking } else { pageerror("Forum Error", "", "Sorry, but there wasn't a forum id present."); } //Show Subforums here $SubForums = mysql_query("SELECT * FROM `forums` WHERE `sid` = '" . $id . "'"); if (mysql_num_rows($SubForums) > 0) { $Temp = new Template(); $Temp->dir = $logged['dskin']; $Temp->file = "category_header.tpl"; $Temp->tp(); $Temp->tr(array("CAT_NAME" => "SubForums")); echo $Temp->html; while ($SubForum = mysql_fetch_array($SubForums)) { //select the total replies for each forum $total_replies = mysql_query("SELECT topics.id,replies.tid FROM `topics`,`replies` WHERE `fid` = '" . $SubForum['id'] . "' AND topics.id = replies.tid") or die(mysql_error()); $total_replies_ = mysql_num_rows($total_replies); //select topic data from the database from these forums $nlastpost = mysql_query("SELECT `id`,`title`,`username` FROM `topics` WHERE `fid` ='" . $SubForum['id'] . "' ORDER BY timestamp DESC") or die(mysql_error()); $nlastpost1 = mysql_fetch_array($nlastpost); $topicid = $nlastpost1['id']; $topicuser = $nlastpost1['username']; $topicnumber = mysql_num_rows($nlastpost); //get latest replies from current forum $allreplies = mysql_query("SELECT * FROM `replies` WHERE `tid` = '" . $topicid . "' ORDER BY `id` DESC ") or die(mysql_error()); $all_replies = mysql_fetch_array($allreplies); if ($f['lastvisited'] == "") { $no_new_post = $total_topics_f_2 != 0 ? "<img src='styles/default/New.png' alt='New' />" : "<img src='styles/default/No%20New.png' alt='No-New' />"; } else { $lID = $logged['id']; $last_vdata = unserialize($f['lastvisited']); $no_new_post = $last_vdata[$lID] < $total_topics_f_2 ? "<img src='styles/default/New.png' alt='New' />" : "<img src='styles/default/No%20New.png' alt='No-New' />"; } //check if there we're any replies if (empty($nlastpost1['title'])) { $IN = "No Topics Here."; } else { $IN = "<a href=\"index.php?act=topicshow&id=" . $nlastpost1['id'] . "\">" . $nlastpost1['title'] . "</a>"; } if ($all_replies['username'] == "") { $BY = $topicuser; } else { $BY = $all_replies['username']; } if (getFP($SubForum['id'])) { $Temp = new Template(); $Temp->dir = $logged['dskin']; $Temp->file = "idxforum.tpl"; $Temp->tp(); $Temp->tr(array('NEWPOST' => $no_new_post, 'FORUM_ID' => $SubForum['id'], 'FORUM_NAME' => $SubForum['title'], 'FORUM_DESC' => $SubForum['description'], 'TOPICS' => $topicnumber, 'REPLIES' => $total_replies_, 'LASTPOSTER' => $BY, 'TOPIC_LINK' => $IN, 'SUBFORUMS' => '')); echo $Temp->html; } } echo "</table><br /><br /><br />"; } //End Subforums here. //total replies pagination limit $ppt = mysql_query("SELECT `topicsperforum` FROM `boardstatus` LIMIT 1;"); $p_p_t = mysql_fetch_array($ppt); $total_limit = intval($p_p_t['topicsperforum']); if (!isset($_GET['p']) || empty($_GET['p']) || $_GET['p'] == 0) { $page = 1; } else { if (!is_numeric($_GET['p'])) { pageerror("Page Error", "", "Didn't specify a correct page id."); } else { $page = intval(mysql_real_escape_string($_GET['p'])); } } $limit_start = $page * $total_limit - $total_limit; //do topic stuff with pagination $topics = mysql_query("SELECT * FROM `topics` WHERE `fid` = '" . $id . "' AND `sticky` = '1' ORDER BY `timestamp` DESC LIMIT {$limit_start},{$total_limit}") or die(mysql_error()); $TTtopics = mysql_query("SELECT * FROM `topics` WHERE `fid` = '" . $id . "' "); $has_topics = mysql_num_rows($TTtopics); $forum_title = mysql_query("SELECT `locked`,`title`,`lastvisited` FROM `forums` WHERE `id` = '" . $id . "' ") or die("Couldn't fetch forum info"); $forum = mysql_fetch_array($forum_title); if (!getFP($id, 0)) { pageerror("Permission Error", "", "Sorry, but you don't have permissions viewing this forum."); } topic_pagination($id, $total_limit, 0); echo "<br /><br />"; if ($forum['locked'] == 't') { echo "\n\t\t\t\t\t\t\t<img src='styles/" . $logged['dskin'] . "/Lockd.png' /><br />\n\t\t\t\t\t\t"; } else { echo "\n\t\t\t\t\t\t\t<a href=\"index.php?act=newtopic&id=" . $id . "\"><img src=\"styles/" . $logged['dskin'] . "/New%20topic.png\" alt='New Topic' style='border:1px solid black;margin-bottom:1px;' /></a>\n\t\t\t\t\t\t"; } if ($has_topics == 0) { $Temp = new Template(); $Temp->dir = $logged['dskin']; $Temp->file = "forums_none.tpl"; $Temp->tp(); $Temp->tr(array('FORUM_NAME' => $forum['title'])); echo $Temp->html; } else { $Temp = new Template(); $Temp->dir = $logged['dskin']; $Temp->file = "forums_header.tpl"; $Temp->tp(); $Temp->tr(array('FORUM_NAME' => $forum['title'])); echo $Temp->html; //do a check to see if topics are stickied $pinned_t = mysql_query("SELECT * FROM `topics` WHERE `fid` = '" . $id . "' AND `sticky` = '0' ORDER BY `timestamp` DESC"); $totalpins = mysql_num_rows($pinned_t); //show pinned topics if ($totalpins != 0) { echo ' <tr> <td width="100%" class="small_title" colspan="4"><span>Pinned Topics</span></td> </tr> '; $totalrepliesever = 0; while ($pinned = mysql_fetch_array($pinned_t)) { $replizS = mysql_query("SELECT * FROM `replies` WHERE `tid` = '" . $pinned['id'] . "' "); $replizS = mysql_num_rows($replizS); $lastS = mysql_query("SELECT `username`,`date` FROM `replies` WHERE tid='" . $topic_info['id'] . "' ORDER BY `id` DESC"); $lastpS = mysql_fetch_array($lastS); ($lastposterS = mysql_num_rows($lastS)) != 0 ? $ltpS = $lastpS['username'] and $ltpdS = date("m-d-y", $lastpS['date']) : ($ltpS = $pinned['username']) and $ltpdS = date("m-d-y", $pinned['timestamp']); $totalrepliesever += $replizS; //Output pinned topics $Temp = new Template(); $Temp->dir = $logged['dskin']; $Temp->file = "forums_content.tpl"; $Temp->tp(); $Temp->tr(array('VIEWS' => $pinned['views'], 'REPLIES' => $replizS, 'TID' => $pinned['id'], 'TNAME' => $pinned['title'], 'AUTHOR' => $pinned['username'], 'UID' => getid($pinned['username']), 'DESC' => $pinned['description'], 'LASTP' => $ltpS, 'UID_2' => getid($ltpS), 'DATE' => $ltpdS)); echo $Temp->html; } if (mysql_num_rows($topics) > 0) { echo ' <tr> <td width="100%" class="small_title" colspan="4"><span>Normal Topics</span></td> </tr> '; } } while ($topic_info = mysql_fetch_array($topics)) { $repliz = mysql_query("SELECT * FROM `replies` WHERE `tid` = '" . $topic_info['id'] . "' "); $repliz = mysql_num_rows($repliz); $totalrepliesever = $totalrepliesever + $repliz; $last = mysql_query("SELECT `username`,`date` FROM `replies` WHERE `tid` = '" . $topic_info['id'] . "' ORDER BY `id` DESC"); $lastp = mysql_fetch_array($last); ($lastposter = mysql_num_rows($last)) != 0 ? $ltp = $lastp['username'] and $ltpd = date("m-d-y", $lastp['date']) : ($ltp = $topic_info['username']) and $ltpd = date("m-d-y", $topic_info['timestamp']); //output normal topics $Temp = new Template(); $Temp->dir = $logged['dskin']; $Temp->file = "forums_content.tpl"; $Temp->tp(); $Temp->tr(array('VIEWS' => $topic_info['views'], 'REPLIES' => $repliz, 'TID' => $topic_info['id'], 'TNAME' => $topic_info['title'], 'AUTHOR' => $topic_info['username'], 'UID' => getid($topic_info['username']), 'DESC' => $topic_info['description'], 'LASTP' => $ltp, 'UID_2' => getid($ltp), 'DATE' => $ltpd)); echo $Temp->html; } $lfvisit = $forum['lastvisited']; $lID = $logged['id']; if ($lfvisit == "") { $user_lv = serialize(array($logged['id'] => $totalrepliesever)); $up_lfv = mysql_query("UPDATE `forums` SET `lastvisited` ='" . $user_lv . "' WHERE `id` = '" . $id . "' ") or die("error updating last visited"); } else { $lfvi = unserialize($lfvisit); if ($lfvi[$lID] < $totalrepliesever || $lfvi[$lID] == "") { $lfvi[$lID] = $totalrepliesever; $up_lfv = mysql_query("UPDATE `forums` SET `lastvisited` ='" . serialize($lfvi) . "' WHERE `id` = '" . $id . "' ") or die("error updating last visited"); } } echo ' </table> '; } }
function RUN_Topic() { global $logged, $permissions; if (is_numeric($_GET['id']) and !empty($_GET['id'])) { $id = intval(htmlspecialchars($_GET['id'])); } else { pageerror("Topic Error", "", "Sorry, but there wasn't a topic id present."); } if (!getFP(topic_parent_($id), 1)) { pageerror("Permission Error", "", "Sorry, but you don't have permissions viewing this topic."); } //do some post stuff //total replies pagination limit $ppt = mysql_query("SELECT `postpertopic` FROM `boardstatus` LIMIT 1"); $p_p_t = mysql_fetch_array($ppt); $total_limit = $p_p_t['postpertopic']; topic_pagination($id, $total_limit); $main = mysql_query("SELECT * FROM `topics` WHERE `id` = '" . $id . "' "); $tmain = mysql_fetch_array($main); $umain = mysql_query("SELECT * FROM `users` WHERE `username` = '" . $tmain['username'] . "'"); $fuser = mysql_fetch_array($umain); $isSticked = $tmain['sticky'] == 1 ? "<a href='mode.php?type=sticktopic&tid=" . $id . "'>Sticky</a>" : "<a href='mode.php?type=unsticktopic&tid=" . $id . "'>Un-Sticky</a>"; $isLocked = $tmain['closed'] == 1 ? "<a href='mode.php?type=closetopic&tid=" . $id . "'>Lock</a>" : "<a href='mode.php?type=opentopic&tid=" . $id . "'>Un-Lock</a>"; //check if user has permissions if ($permissions['admin'] == 't' || $permissions['e_topic'] == 't') { $modet = "<a href='mode.php?type=edit&post=topic&id=" . $id . "'>Edit</a> | <a href='mode.php?type=move&post=topic&id=" . $id . "'>Move Topic</a> | " . $isSticked . " | " . $isLocked; } elseif ($logged['username'] == $tmain['username'] && $permissions['e_topic'] == 't') { $modet = "<a href='mode.php?type=edit&post=topic&id=" . $id . "'>Edit</a>"; } else { $modet = ""; } echo "<br />" . run_buttons($id); $Temp = new Template(); $Temp->dir = $logged['dskin']; $Temp->file = "topic_title.tpl"; $Temp->tp(); $Temp->tr(array('TITLE' => $tmain['title'])); echo $Temp->html; //if($_GET['p'] == 1 || !isset($_GET['p']) ) // { echo ' <tr> <td colspan="2" class="small_title"><span style="float:left;"><b>Posted On:</b> ' . timezone_stamp($tmain['timestamp'], $logged['timezone']) . '</span><span style="float:right" class="small_title_link">' . $modet . '</span></td> </tr> '; //} if (!isset($_GET['p']) || empty($_GET['p']) || $_GET['p'] == 0) { $page = 1; } else { if (!is_numeric($_GET['p'])) { pageerror("Page Error", "", "Didn't specify a correct page id."); } else { $page = intval(mysql_real_escape_string($_GET['p'])); } } $limit_start = $page * $total_limit - $total_limit; //get replies $replies = mysql_query("SELECT * FROM `replies` WHERE `tid` = '" . $id . "' ORDER BY `id` LIMIT {$limit_start},{$total_limit}") or die(mysql_error(__FILE__, __LINE__)); $has_replys = mysql_num_rows($replies); if ($has_replys != 0) { //check to see if there are any replies :D while ($replys = mysql_fetch_array($replies)) { //check if user has permissions if ($permissions['admin'] == 't' || $permissions['d_post'] == 't') { $modep = "<a href='mode.php?type=edit&post=reply&id=" . $replys['id'] . "&tid=" . $id . "'>Edit</a> | <a href='mode.php?type=delete&post=reply&id=" . $replys['id'] . "&tid=" . $id . "'>Delete</a>"; } elseif ($logged['username'] == $replys['username']) { $modep = "<a href='mode.php?type=edit&post=reply&id=" . $replys['id'] . "&tid=" . $id . "'>Edit</a>"; } else { $modep = ""; } $usez = mysql_query("SELECT * FROM `users` WHERE `username` = '" . $replys['username'] . "'"); $useri = mysql_fetch_array($usez); //show replies $Temp = new Template(); $Temp->dir = $logged['dskin']; $Temp->file = "topic_post.tpl"; $Temp->tp(); $Temp->tr(array('OPTIONS' => $modep, 'POSTER' => $replys['username'], 'AVY' => !empty($useri['avatar']) ? '<img width="100" height="100" src="' . $useri['avatar'] . '" alt="" /><br />' : '', 'DATE' => timezone_stamp($replys['date'], $logged['timezone']), 'GROUP' => group($useri['level']), 'UID' => $useri['id'], 'UPOST' => $useri['post'], 'POST' => nl2br(bbcode_format($replys['post'])) . "<br />__________________<br />" . ($useri['signature'] == '' ? ' ' : nl2br(bbcode_format($useri['signature']))))); echo $Temp->html; } } else { echo "\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td width='100%' class='rows' align='center'><em>There isn't any posts in this topic</em></td>\n\t\t\t\t\t</tr>\n\t\t\t\t"; } echo ' </table> ' . run_buttons($id) . '<br />'; topic_pagination($id, $total_limit); add_views($id); }