function BoardSelect($board = 0) { global $config, $my, $tpl, $db, $gpc, $lang; $found = FALSE; $sub_cache = array(); $sub_cache_last = array(); $cat_cache = array(); $mod_cache = array(); $forum_cache = array(); $cat_cache = cache_categories(); if (!isset($GLOBALS['memberdata']) || !is_array($GLOBALS['memberdata'])) { $memberdata = cache_memberdata(); } else { $memberdata = $GLOBALS['memberdata']; } $scache = new scache('index-moderators'); if ($scache->existsdata() == TRUE) { $mod_cache = $scache->importdata(); } else { $result = $db->query('SELECT mid, bid FROM ' . $db->pre . 'moderators WHERE time > ' . time() . ' OR time IS NULL', __LINE__, __FILE__); $mod_cache = array(); while ($row = $db->fetch_assoc($result)) { if (isset($memberdata[$row['mid']])) { $row['name'] = $memberdata[$row['mid']]; $mod_cache[$row['bid']][] = $row; } } $scache->exportdata($mod_cache); } // Fetch Forums $sql = "SELECT \n c.id, c.name, c.desc, c.opt, c.optvalue, c.bid, c.topics, c.replys, c.cid, c.last_topic, \n t.topic as btopic, t.id as btopic_id, t.last as bdate, u.name AS uname, t.last_name AS bname\n FROM {$db->pre}cat AS c\n LEFT JOIN {$db->pre}topics AS t ON c.last_topic=t.id \n LEFT JOIN {$db->pre}user AS u ON t.last_name=u.id \n ORDER BY c.cid, c.c_order, c.id"; $result = $db->query($sql, __LINE__, __FILE__); if ($db->num_rows($result) == 0) { $errormsg = array('There are currently no boards to show. Pleas visit the <a href="admin.php' . SID2URL_1 . '">Admin Control Panel</a> and create some forums.'); $errorurl = ''; $tpl->globalvars(compact("errorurl", "errormsg")); echo $tpl->parse('main/error'); return $found; } while ($row = $db->fetch_assoc($result)) { $gpc->prepare($row['name']); $gpc->prepare($row['btopic']); $gpc->prepare($row['uname']); $gpc->prepare($row['bname']); // Caching for Subforums if ($row['bid'] > 0) { $sub_cache[$row['bid']][] = $row; $sub_cache_last[$row['id']] = $row; } // Caching the Forums if ($row['bid'] == $board) { $forum_cache[$row['cid']][] = $row; } } // Work with the chached data! foreach ($cat_cache as $cat) { $forums = array(); if (isset($forum_cache[$cat['id']]) == false) { continue; } foreach ($forum_cache[$cat['id']] as $forum) { $found = TRUE; $forum['new'] = false; $forum['mbdate'] = $forum['bdate']; // Subforendaten vererben (Letzter Beitrag, Markierung) if (isset($sub_cache[$forum['id']])) { $substats = SubStats($forum['topics'], $forum['replys'], $forum['id'], $sub_cache); $forum['topics'] = $substats[0]; $forum['replys'] = $substats[1]; $bids = $substats[2]; } $last = $forum['last_topic']; $last_date = $forum['bdate']; if (isset($sub_cache[$forum['id']])) { foreach ($bids as $bidf) { $sub = $sub_cache_last[$bidf]; if ($last_date < $sub['bdate']) { $last = $sub['id']; $last_date = $sub['bdate']; } } } $forum['lname'] = is_id($forum['bname']) ? $forum['uname'] : $forum['bname']; if ($last != $forum['last_topic']) { $forum['id2'] = $last; $forum['last_topic'] = $sub_cache_last[$forum['id2']]['last_topic']; $forum['btopic_id'] = $sub_cache_last[$forum['id2']]['btopic_id']; $forum['btopic'] = $sub_cache_last[$forum['id2']]['btopic']; $forum['bdate'] = $sub_cache_last[$forum['id2']]['bdate']; if (!isset($sub_cache_last[$forum['id2']]['lname'])) { $forum['lname'] = is_id($sub_cache_last[$forum['id2']]['bname']) ? $sub_cache_last[$forum['id2']]['uname'] : $sub_cache_last[$forum['id2']]['bname']; } else { $forum['lname'] = $sub_cache_last[$forum['id2']]['lname']; } } else { $forum['id2'] = $forum['id']; } $id = array_search(trim($forum['lname']), $memberdata); if (is_id($id)) { $forum['lname'] = array($forum['lname'], $id); } else { $forum['lname'] = array($forum['lname'], 0); } if ($forum['btopic_id']) { $forum['tid'] = $forum['btopic_id']; } else { $forum['tid'] = $forum['last_topic']; } // Rechte und Gelesensystem if ($forum['opt'] != 're') { if (!check_forumperm($forum)) { $forum['foldimg'] = $tpl->img('cat_locked'); $forum['topics'] = '-'; $forum['replys'] = '-'; $forum['btopic'] = FALSE; } else { if (isset($my->mark['f'][$forum['id']]) && $my->mark['f'][$forum['id']] > $forum['bdate'] || $forum['bdate'] < $my->clv || $forum['topics'] < 1) { $forum['foldimg'] = $tpl->img('cat_open'); } else { $forum['foldimg'] = $tpl->img('cat_red'); $forum['new'] = true; } if ($forum['btopic']) { if (strxlen($forum['btopic']) >= 40) { $forum['btopic'] = substr($forum['btopic'], 0, 40); $forum['btopic'] .= "..."; } $forum['bdate'] = str_date($lang->phrase('dformat1'), times($forum['bdate'])); } } } $forum['topics'] = numbers($forum['topics']); $forum['replys'] = numbers($forum['replys']); // Moderatoren $forum['mod'] = array(); if (isset($mod_cache[$forum['id']])) { $anz2 = count($mod_cache[$forum['id']]); for ($i = 0; $i < $anz2; $i++) { if ($anz2 != $i + 1) { $mod_cache[$forum['id']][$i]['sep'] = ', '; } else { $mod_cache[$forum['id']][$i]['sep'] = ''; } $forum['mod'][] = $mod_cache[$forum['id']][$i]; } } // Unterforen $forum['sub'] = array(); if ($config['showsubfs']) { if (isset($sub_cache[$forum['id']])) { $anz2 = count($sub_cache[$forum['id']]); $sub = array(); for ($i = 0; $i < $anz2; $i++) { $sub_cache[$forum['id']][$i]['new'] = false; if ($sub_cache[$forum['id']][$i]['opt'] != 're') { if (!check_forumperm($sub_cache[$forum['id']][$i])) { $sub_cache[$forum['id']][$i]['foldimg'] = $tpl->img('subcat_locked'); } else { if (isset($my->mark['f'][$sub_cache[$forum['id']][$i]['id']]) && $my->mark['f'][$sub_cache[$forum['id']][$i]['id']] > $sub_cache[$forum['id']][$i]['bdate'] || $sub_cache[$forum['id']][$i]['bdate'] < $my->clv || $sub_cache[$forum['id']][$i]['topics'] < 1) { $sub_cache[$forum['id']][$i]['foldimg'] = $tpl->img('subcat_open'); } else { $sub_cache[$forum['id']][$i]['foldimg'] = $tpl->img('subcat_red'); $sub_cache[$forum['id']][$i]['new'] = true; } } } else { $sub_cache[$forum['id']][$i]['foldimg'] = $tpl->img('subcat_redirect'); } $forum['sub'][] = $sub_cache[$forum['id']][$i]; } } } $forums[] = $forum; } $tpl->globalvars(compact("cat", "forums")); echo $tpl->parse("categories"); } return $found; }
} elseif ($actiong == "delete") { $catid = isset($_GET["cid"]) ? 0 + $_GET["cid"] : ""; $res = mysql_query("SELECT id, name FROM categories WHERE id=" . sqlesc($catid) . "") or sqlerr(__FILE__, __LINE__); $arr = mysql_fetch_assoc($res); $count = mysql_num_rows($res); if ($count == 1) { $delete = mysql_query("DELETE FROM categories where id=" . sqlesc($catid) . "") or sqlerr(__FILE__, __LINE__); if ($delete) { write_log("" . $CURUSER["username"] . " deleted category " . $arr["name"] . ""); stderr("Succes", "Category successfully deleted! Go <a href=\"" . $BASEUL . "/categorie.php\">back</a>"); } } else { stderr("Err", "No category with that id!"); } } elseif ($actiong == "cache") { cache_categories(); header("Refresh: 2; url=categorie.php"); stderr("Succes", "Categories saved to the cache file "); } else { stdhead("Categories"); begin_main_frame(); // add categories form begin_frame("Add category"); print "<form action=\"categorie.php\" method=\"post\">"; print "<table class=\"main\" border=\"1\" cellspacing=\"0\" align=\"center\" cellpadding=\"5\">\n"; print "<tr><td class=\"colhead\">Cat Name</td><td align=\"left\"><input type=\"text\" size=\"50\" name=\"cname\" /></td></tr>"; print "<tr><td class=\"colhead\">Cat image</td><td align=\"left\"><input type=\"text\" size=\"50\" name=\"cimage\" /></td></tr>"; print "<tr><td align=\"center\" colspan=\"2\"><input type=\"submit\" name=\"submit\" value=\"Add category\"/><input type=\"hidden\" name=\"action\" value=\"add\" />"; print "</table></form>"; end_frame(); // print existing catergories