authenticate("U_Groups, U_TimeOffset, U_FrontPage"); $Username = $user['U_Username']; // --------------- // send the header $html = new html; $html -> send_header($config['title'],$Cat,0,$user); // ------------------------------------------------------------------------ // If they are logged in then we check their groups, otherwise they // get set to the guest group $Groups = $user['U_Groups']; if (!$Groups) { $Groups = "-4-"; } // ------------------------------------ // Are we just looking at one category? $catsonly = $user['U_FrontPage']; $main = "ubbthreads"; if ($config['catsonly']) { $main = "categories"; } if (!$catsonly) { $catsonly = $main; } // ----------------------------------------------------------------- // If we have a Cat variable then we need to set it up for the query $Cat = preg_replace("/[^\d,]/","",$Cat); if ($Cat) { $pattern = "/,/"; $replace = " OR Cat_Number = "; $catonly = preg_replace($pattern,$replace,$Cat); $catonly = "AND Cat_Number = " . $catonly; } // ---------------------------------------------------------------------- // Lets see how many total registered users there are but only if we want // to display this information $sth = $dbh->do_query("SELECT COUNT(*) FROM {$config['tbprefix']}Users WHERE U_Approved='yes'"); list($registered) = $dbh -> fetch_array($sth); $dbh -> finish_sth($sth); // ------------------------------------------------------------------------- // let's grab the name of the most recently registered user $query = " SELECT U_Username,U_Number FROM {$config['tbprefix']}Users WHERE U_Approved='yes' ORDER BY U_Number DESC LIMIT 0,1 "; $sth = $dbh -> do_query($query); list($newusername,$newnumber) = $dbh -> fetch_array($sth); $dbh -> finish_sth($sth); // Must define welcome message here for the template since it is different // if the user isn't logged in. if ($user['U_Username']) { $welcomemessage = "{$ubbt_lang['INTRO_SUB']}, {$user['U_Username']}"; } else { $welcomemessage = $ubbt_lang['WEL_PRIV_NO']; } // -------------------------- // Get the list of categories $query = " SELECT DISTINCT Cat_Title,Cat_Number,Cat_Description FROM {$config['tbprefix']}Category WHERE Cat_Type='forum' $catonly ORDER BY Cat_Number "; $categories = $dbh -> do_query($query); $j = 0; // -------------------------------------------------------------- // We need to format a SQL query to see what boards this user can // view $Grouparray = split("-",$Groups); $gsize = sizeof($Grouparray); $groupquery = "AND ("; $g = 0; for ($i=0; $i<$gsize;$i++) { if (!preg_match("/[0-9]/",$Grouparray[$i])) { continue; }; $g++; if ($g > 1) { $groupquery .= " OR "; } $groupquery .= "Bo_Read_Perm LIKE '%-$Grouparray[$i]-%'"; } $groupquery .= ")"; // ---------------------------- // Cycle through the categories $forumtotal=0; $threadtotal=0; $posttotal=0; $shownew=0; $x = 0; while (list ($CatTitle,$CatNumber,$CatDescription) = $dbh -> fetch_array($categories)) { if (!$CatTitle) { continue; } // --------------------------------------- // Grab all of the boards in this category $query = " SELECT Bo_Keyword,Bo_Total,Bo_Last,Bo_Threads,Bo_Moderated FROM {$config['tbprefix']}Boards WHERE Bo_Cat = '$CatNumber' $groupquery "; $boards = $dbh -> do_query($query); $catcheck = $dbh -> total_rows($boards); if (!$catcheck) { continue; } // ----------------------------------------- // Grab all of the moderators for all forums $query = " SELECT t1.Mod_Board,t1.Mod_Uid,t2.U_Username FROM {$config['tbprefix']}Moderators AS t1, {$config['tbprefix']}Users AS t2 WHERE t1.Mod_Uid = t2.U_Number "; $sth = $dbh -> do_query($query); while (list($modboard,$modid,$modname) = $dbh -> fetch_array($sth)) { if (!isset($modarray[$modboard])) { $modarray[$modboard] = ",$modname,"; } else { $modarray[$modboard] .= "$modname,"; } } // ----------------------------------------- // Get this user's last visit to each forum if ($Username) { $Username_q = addslashes($Username); $query = " SELECT L_Board,L_Last FROM {$config['tbprefix']}Last WHERE L_Uid = '{$user['U_Number']}' "; $sth = $dbh -> do_query($query); while(list($Board,$Last) = $dbh -> fetch_array($sth)) { $Lastvisit[$Board] = $Last; } } // --------------------------------------------- // Now cycle through the boards in this category $firstpass = 0; $boardfolder = "nonewposts.gif"; while (list($Keyword,$Total,$Last,$Threads,$Moderated) = $dbh -> fetch_array($boards)) { $Board_q = addslashes($Keyword); // --------------------------------------------------------------- // If they are a normal user then they can only see approved posts $Viewable = "And B_Approved = 'yes'"; if ($user['U_Status'] == "Administrator") { $Viewable = ""; } if ($user['U_Status'] == "Moderator") { if (preg_match("/(,|$){$user['U_Username']}(,|^)/i",$modarray[$Keyword])) { $Viewable = ""; } } if (isset($Lastvisit[$Keyword])) { $checker = $Lastvisit[$Keyword]; } else { $checker = 0; } if ( ($checker < $Last) ) { $boardfolder = "newposts.gif"; } if ( ($config['newcounter'] == 2) && ($Username) && ($boardfolder == "newposts.gif") ) { // -------------------------------------------------------------- // Let's see how many new posts there are. We have to do some // tricky AND/OR operations because we don't want sticky posts to // be counted as new if they aren't. $newposts = ""; $newthreads = ""; $query = " SELECT COUNT(*), SUM(B_Topic) FROM {$config['tbprefix']}Posts WHERE (B_Posted > $checker AND B_Posted <> 4294967295) $Viewable AND B_Board = '$Board_q' "; $newp1 = $dbh -> do_query($query); $newposts1 = $dbh -> fetch_array($newp1); $dbh -> finish_sth($newposts1); $newthreads1 = $newposts1[1]; $newposts1 = $newposts1[0]; $query = " SELECT COUNT(*), SUM(B_Topic) FROM {$config['tbprefix']}Posts WHERE (B_Posted = 4294967295 AND B_Sticky > $checker) $Viewable AND B_Board = '$Board_q' "; $newp2 = $dbh -> do_query($query); $newposts2 = $dbh -> fetch_array($newp2); $newthreads2 = $newposts2[1]; $newposts2 = $newposts2[0]; // now add the results $newposts = $newposts1 + $newposts2; $newthreads = $newthreads1 + $newthreads2; if ( ($checker < $Last) && ($Username) ) { $shownew = $shownew + $newposts; $boardfolder = "newposts.gif"; } // ----------------------------------------------------------- // If we have new posts let's see how many new threads we have // merged with query above if ( ($checker < $Last) && ($Username) ) { $shownewt = $shownewt + $newthreads; $boardfolder = "newposts.gif"; } // -------------------------------------- // Let's see how many NA posts there are if ( ($Moderated == "yes") && ($Viewable == "") ) { $query = " SELECT COUNT(*) FROM {$config['tbprefix']}Posts WHERE B_Approved = 'no' AND B_Board = '$Board_q' "; $notapp = $dbh -> do_query($query); list($notapproved) = $dbh -> fetch_array($notapp); $dbh -> finish_sth($notapp); } $showna = $showna + $notapproved; } if (isset($catrow[$x]['threadtotal'])) { $catthreads = $catrow[$x]['threadtotal']; } else { $catthreads = "0"; } if (isset($catrow[$x]['posttotal'])) { $catposts = $catrow[$x]['posttotal']; } else { $catposts = "0"; } if (!isset($catrow[$x]['forumtotal'])) { $catrow[$x]['forumtotal'] = "0"; } $catrow[$x]['threadtotal'] = $catthreads + $Threads; $catrow[$x]['forumtotal']++; $catrow[$x]['posttotal'] = $catposts + $Total; $catrow[$x]['boardfolder'] = $boardfolder; } $dbh -> finish_sth($boards); if ($shownew) { $shownew = "
($shownew {$ubbt_lang['NEW_TEXT']})"; } else { $shownew = ""; } $catrow[$x]['shownew'] = $shownew; if ($shownewt) { $shownewt = "
($shownewt {$ubbt_lang['NEW_TEXT']})"; } else { $shownewt = ""; } $catrow[$x]['shownewt'] = $shownewt; if ($showna) { $showna = " ($showna {$ubbt_lang['NOT_APPROVED']})"; } else { $showna = ""; } $catrow[$x]['showna'] = $showna; if (isset($catrow[$x]['forumtotal'])) { $catrow[$x]['CatNumber'] = $CatNumber; $catrow[$x]['CatTitle'] = $CatTitle; $catrow[$x]['CatDescription'] = $CatDescription; $x++; } $forumtotal = 0; $threadtotal = 0; $posttotal = 0; $shownew = ""; $shownewt = ""; $showna = ""; } $dbh -> finish_sth($categories); // ----------------------- // Grab the total # online $query = " SELECT O_Type,COUNT(*) FROM {$config['tbprefix']}Online GROUP BY O_Type "; $sth = $dbh -> do_query($query); while(list ($type,$count) = $dbh -> fetch_array($sth)) { ${$type} = $count; } if (!isset($a)) {$a = "0"; } if (!isset($r)) {$r = "0"; } $catsize = sizeof($catrow); // --------------------- // Grab the tablewrapper list($tbopen,$tbclose) = $html -> table_wrapper(); if (!$debug) { include ("$thispath/templates/$tempstyle/categories.tmpl"); } $html -> send_footer(); ?>