<?php
/****************************
Arcanebase
http://ab.electronicembassy.com/
(C) 2003 Mike Kober
hide@address.com
released under the GNU Lesser Public License
---------------
kbmain.php - The Main Menu for the KB System
Displays available menu items and
available topics.
******************************/
require ("inc/conf.inc");
require ("checklogin.php");
require ("inc/DB.php");
require ("patTemplate/include/patTemplate.php");
require ("html/$Config_Site_Theme/theme.conf");
$dbh = DB::connect("$Config_DB_String");
if (DB::isError($dbh)) {
die ($dbh->getMessage());
}
$template = new patTemplate();
$template->setBasedir("html/$Config_Site_Theme/");
$template->readTemplatesFromFile("kb-index.tmpl");
//display and setup the header info
$template->addVar("mainpage", "SITE_NAME", $Config_Site_Name);
$template->addVar("mainpage", "USERNAME", $username);
$template->addVar("mainpage", "MYSECURITY", $mysecurity);
$template->addVar("mainpage", "LASTLOGIN", $lastlogin);
$template->addVar("mainpage", "FOOTER", $Config_Site_Footer);
$mymenu[0] = $Theme_Links_Logout;
if ($mysecurity == "3") {
$mymenu[1] = $Theme_Links_Admin;
}
for ($x=0; $x<sizeof($mymenu); $x++) {
$template->AddVar("menu_list", "MENUITEM", $mymenu[$x]);
$template->parseTemplate("menu_list", "a");
}
if ($page == ""){ //if no $page variable then
$page = 1; //start on page 1
}
$limitvalue = $page * $Config_Site_LimitTopics - ($Config_Site_LimitTopics);
$topicquery = "SELECT ab_topic.ab_topicid, ab_topic.ab_topic_name, ab_topic.ab_topic_desc, ab_topic.ab_topic_view,
ab_topic.ab_topic_post, ab_users.ab_username as moderator FROM ab_topic INNER JOIN ab_users ON
ab_topic.ab_userid = ab_users.ab_userid WHERE ab_topic_view <= $mysecurity ORDER BY ab_topicid
LIMIT $limitvalue, $Config_Site_LimitTopics";
$results = $dbh->query($topicquery);
if (DB::isError($results)) {
die ($results->getMessage());
}
$countquery = "SELECT ab_topic.ab_topicid, ab_topic.ab_topic_name, ab_topic.ab_topic_desc, ab_topic.ab_topic_view,
ab_topic.ab_topic_post,ab_users.ab_username as moderator FROM ab_topic INNER JOIN ab_users ON
ab_topic.ab_userid = ab_users.ab_userid WHERE ab_topic_view <= $mysecurity ORDER BY ab_topicid";
$results2 = $dbh->query($countquery);
if (DB::isError($results2)) {
die ($results2->getMessage());
}
$totalrows = $results2->numRows();
$rowcount = $results->numRows();
if ($rowcount == 0) {
$template->addVar("mainpage", "NOTOPIC", "No Topics Available");
}else{
$dbh->disconnect();
for ($count = 0; $row = $results->fetchRow(DB_FETCHMODE_ASSOC); ++$count) {
$thistopic = $row['ab_topicid'];
$dbh2 = DB::connect("$Config_DB_String");
$query = "SELECT COUNT(*) FROM ab_article WHERE ab_topicid ='$thistopic'";
$res = $dbh2->query($query);
if (DB::isError($res)) {
die ($res->getMessage());
}
$art_count = $res->fetchRow();
$dbh2->disconnect();
$template->AddVar("topic_list", "TOPIC_ID", $row['ab_topicid']);
$template->AddVar("topic_list", "TOPIC_NAME", $row['ab_topic_name']);
$template->AddVar("topic_list", "TOPIC_DESC", $row['ab_topic_desc']);
$template->AddVar("topic_list", "TOPIC_MOD", $row['moderator']);
$template->AddVar("topic_list", "ARTICLE_COUNT", $art_count);
$template->parseTemplate("topic_list", "a");
}
}
if($page != 1){
$pageprev = $page - 1;
$pagelisting = ("<a href=\"$PHP_SELF?page=$pageprev\">Previous".$limit."</a> ");
}else
$pagelisting = ("Previous".$limit." ");
$numofpages = $totalrows / $Config_Site_LimitTopics ;
for($i = 1; $i <= $numofpages; $i++){
if($i == $page){
$pagelisting = $pagelisting . ($i." ");
}else{
$pagelisting = $pagelisting . ("<a href=\"$PHP_SELF?page=$i\">$i</a> ");
}
}
// If we're on page 1, PREV is not a link
if(($totalrows % $Config_Site_LimitTopics) != 0){
if($i == $page){
$pagelisting = $pagelisting . ($i." ");
}else{
$pagelisting = $pagelisting . ("<a href=\"$PHP_SELF?page=$i\">$i</a> ");
}
}
if(($totalrows - ($Config_Site_LimitTopics * $page)) > 0){
/* This statement checks to see if there are more rows remaining, meaning there
are pages in front of the current one. */
$pagenext = $page + 1;
$pagelisting = $pagelisting . ("<a href=\"$PHP_SELF?page=$pagenext\">Next".$limit."</a>");
/* Since there are pages remaining, this outputs NEXT in link form. */
}else{
$pagelisting = $pagelisting . ("Next".$limit);
/* If we're on the last page possible, NEXT will NOT be displayed. */
}
$template->AddVar("mainpage", "PAGELISTING", $pagelisting);
$template->displayParsedTemplate("mainpage");
?>