query("INSERT INTO `forums` SET $values, `lastpostid` = '0'"); if (mysql_error()) die(mysql_error()); $id = mysql_insert_id(); trigger_error("Created new forum \"$forumtitle\" with ID $id", E_USER_NOTICE); } else { $sql->query("UPDATE `forums` SET $values WHERE `id` = '". $_GET['id'] ."'"); if (mysql_error()) die(mysql_error()); $id = $_GET['id']; trigger_error("Edited forum ID $id", E_USER_NOTICE); } if ($_POST['edit']) header("Location: ?id=". $id . $prevtext); else header("Location: ?".substr($prevtext, 1)); die(); } elseif ($_POST['delete']) { if (!$isadmin) die("You aren't an admin!"); $id = intval($_GET['delete']); $mergeid = intval($_POST['mergeid']); if (!isset($_GET['delete']) || $id < 0) die("No forum selected to delete."); if (!isset($_POST['mergeid']) || $mergeid < 0) die("No forum selected to merge to."); $counts = $sql->fetchq("SELECT `numthreads`, `numposts` FROM `forums` WHERE `id`='$id'"); $sql->query("UPDATE `threads` SET `forum`='$mergeid' WHERE `forum`='$id'") or die(mysql_error()); $sql->query("UPDATE `announcements` SET `forum`='$mergeid' WHERE `forum`='$id'") or die(mysql_error()); $sql->query("DELETE FROM `forummods` WHERE `forum`='$id'") or die(mysql_error()); $sql->query("DELETE FROM `forums` WHERE `id`='$id'") or die(mysql_error()); $lastthread = $sql->fetchq("SELECT * FROM `threads` WHERE `forum`='$mergeid' ORDER BY `lastpostdate` DESC LIMIT 1"); $sql->query("UPDATE `forums` SET `numthreads`=`numthreads`+'{$counts['numthreads']}', `numposts`=`numposts`+'{$counts['numposts']}', `lastpostdate`='{$lastthread['lastpostdate']}', `lastpostuser`='{$lastthread['lastposter']}', `lastpostid`='{$lastthread['id']}' WHERE `id`='$mergeid'") or die(mysql_error()); if (isset($_GET['preview'])) $prevtext = "preview=" . $_GET['preview']; trigger_error("DELETED forum ID $id; merged into forum ID $mergeid", E_USER_NOTICE); header("Location: ?$prevtext"); die(); } $windowtitle = "Editing Forum List"; require_once('lib/layout.php'); print "$header
"; admincheck(); print adminlinkbar('admin-editforums.php'); foreach($pwlnames as $pwl=>$pwlname) { if ($pwl < 0) continue; $powers[] = $pwlname; } $powers[] = '[no access]'; $pollstyles = array(-2 => 'Disallowed', -1 => 'Normal', 0 => 'Force Regular', 1 => 'Force Influence'); if (isset($_GET['delete'])) { $forum = intval($_GET['delete']); $forums[-1] = "Choose a forum to merge into..."; $forumquery = $sql->query("SELECT id,title FROM forums ORDER BY catid,forder"); while ($f = $sql->fetch($forumquery, MYSQL_ASSOC)) $forums[$f['id']] = $f['title']; if (array_key_exists($forum, $forums)) { $fname = $forums[$forum]; unset($forums[$forum]); if (isset($_GET['preview'])) $prevtext = "&preview=" . $_GET['preview']; echo "
$tblstart $tccellh>Deleting $fname $tccellc>You are about to delete forum ID $forum.

All announcements and threads will be moved to the forum below.
". dropdownList($forums, -1, "mergeid") . " $tccellc> or Cancel

"; } } else if (isset($_GET['id'])) { $catquery = $sql->query("SELECT id,name FROM categories ORDER BY id"); while ($catres = $sql->fetch($catquery)) $categories[$catres['id']] = $catres['name']; $forum = $sql->fetchq("SELECT * FROM `forums` WHERE `id` = '". $_GET['id'] . "'", MYSQL_ASSOC); if (!$forum) $_GET['id'] = -1; if ($forum && !array_key_exists($forum['catid'], $categories)) $categories[$forum['catid']] = "Unknown category #" . $forum['catid']; if (isset($_GET['preview'])) $prevtext = "&preview=" . $_GET['preview']; echo "
$tblstart $tccellh colspan=6>Editing ". ($forum ? htmlspecialchars($forum['title']) : "a new forum") . " $tccellh>Forum Name $tccell1l colspan=4> $tccell1l width=10%> $tccellh rowspan=4>Description $tccell1l rowspan=4 colspan=3>$txta=description ROWS=4 style=\"width: 100%; resize:none;\">". htmlspecialchars($forum['description']) ." $tccellh colspan=2>Minimum power needed... $tccellh>...to view the forum $tccell1l>". dropdownList($powers, $forum['minpower'], "minpower") . " $tccellh>...to post a thread $tccell1l>". dropdownList($powers, $forum['minpowerthread'], "minpowerthread") . " $tccellh>...to reply $tccell1l>". dropdownList($powers, $forum['minpowerreply'], "minpowerreply") . " $tccellh width='10%'>Number of Threads $tccell1l width='24%'> $tccellh width='10%'>Forum order $tccell1l width='23%'> $tccellh width='10%'>Poll Style $tccell1l width='23%'>". dropdownList($pollstyles, $forum['pollstyle'], "pollstyle") . " $tccellh >Number of Posts $tccell1l> $tccellh >Special Scheme $tccell1l> $tccellh >Category $tccell1l>". dropdownList($categories, $forum['catid'], "catid") . " $tccellc colspan=6> 

"; } $forumlist=" $tccellh width=90px>Actions $tccellh>Forum $tccellh width=80>Threads $tccellh width=80>Posts $tccellh width=15%>Last post "; if (isset($_GET['preview'])) { $forumquery = $sql->query("SELECT f.*,u.id AS uid,name,sex,powerlevel FROM forums f LEFT JOIN users u ON f.lastpostuser=u.id WHERE (!minpower OR minpower<=$_GET[preview]) AND f.hidden = '0' ORDER BY catid,forder"); $catquery = $sql->query("SELECT id,name FROM categories WHERE (!minpower OR minpower<=$_GET[preview]) ORDER BY id"); $prevtext = "&preview=" . $_GET['preview']; } else { $forumquery = $sql->query("SELECT f.*,u.id AS uid,name,sex,powerlevel FROM forums f LEFT JOIN users u ON f.lastpostuser=u.id ORDER BY catid,forder"); $catquery = $sql->query("SELECT id,name FROM categories ORDER BY id"); } $modquery = $sql->query("SELECT u.id,name,sex,powerlevel,forum FROM users u INNER JOIN forummods m ON u.id=m.user ORDER BY name"); $categories = array(); $forums = array(); $mods = array(); while ($res = $sql->fetch($catquery)) $categories[] = $res; while ($res = $sql->fetch($forumquery)) $forums[] = $res; while ($res = $sql->fetch($modquery)) $mods[] = $res; $forumlist .= "< Create a new forum >"; foreach ($categories as $category) { $forumlist.="$category[name]"; foreach ($forums as $forumplace => $forum) { if ($forum['catid'] != $category['id']) continue; $m = 0; $modlist = ""; foreach ($mods as $modplace => $mod) { if ($mod['forum'] != $forum['id']) continue; $namecolor=getnamecolor($mod['sex'],$mod['powerlevel']); $modlist.=($m++?', ':'')."$mod[name]"; unset($mods[$modplace]); } if ($m) $modlist="$smallfont(moderated by: $modlist)"; $namecolor = getnamecolor($forum['sex'],$forum['powerlevel']); if($forum['numposts']){ $forumlastpost="". date($dateformat,$forum['lastpostdate']+$tzoff); $by="$smallfont
by $forum[name]". ($forum['lastpostid'] ? " ". $statusicons['getlast'] ."" : "") ."
"; } else { $forumlastpost=getblankdate(); $by=''; } if($forum['lastpostdate']>$category['lastpostdate']){ $category['lastpostdate']=$forum['lastpostdate']; $category['l']=$forumlastpost.$by; } if ($forum['hidden']) $hidden = " (hidden)"; else $hidden = ""; if ($_GET['id'] == $forum['id']) { $tc1 = $tccellh; $tc2 = $tccellh; $tc2l = $tccellhl; } else { $tc1 = $tccell1; $tc2 = $tccell2; $tc2l = $tccell2l; } $forumlist.=" $tc1>Edit / Delete $tc2l>$forum[title]$hidden
$smallfont$forum[description]
$modlist $tc1>$forum[numthreads] $tc1>$forum[numposts] $tc2>$forumlastpost$by$forumlastuser "; unset($forums[$forumplace]); } } // Leftover forums if (!isset($_GET['preview']) && count($forums)) { $forumlist.="These forums are not associated with a valid category ID"; foreach ($forums as $forum) { $m = 0; foreach ($mods as $modplace => $mod) { if ($mod['forum'] != $forum['id']) continue; $namecolor=getnamecolor($mod['sex'],$mod['powerlevel']); $modlist.=($m++?', ':'')."$mod[name]"; unset($mods[$modplace]); } if ($m) $modlist="$smallfont(moderated by: $modlist)"; $namecolor = getnamecolor($forum['sex'],$forum['powerlevel']); if($forum['numposts']){ $forumlastpost="". date($dateformat,$forum['lastpostdate']+$tzoff); $by="$smallfont
by $forum[name]". ($forum['lastpostid'] ? " ". $statusicons['getlast'] ."" : "") ."
"; } else { $forumlastpost=getblankdate(); $by=''; } if($forum['lastpostdate']>$category['lastpostdate']){ $category['lastpostdate']=$forum['lastpostdate']; $category['l']=$forumlastpost.$by; } if ($forum['hidden']) $hidden = " (hidden)"; else $hidden = ""; $forumlist.=" $tccell1>Edit / Delete $tccell2l>$forum[title]$hidden
$smallfont$forum[description]
$modlist $tccell1>$forum[numthreads] $tccell1>$forum[numposts] $tccell2>$forumlastpost$by$forumlastuser "; } } print "
Preview forums with powerlevel: ".previewbox()."
\n"; print "$tblstart$forumlist$tblend$footer"; printtimedif($startingtime); function dropdownList($links, $sel, $n) { global $tccell1, $tccellc; $r = ""; } function previewbox(){ if (isset($_GET['id'])) { $idtxt = "id=" . $_GET['id'] . "&"; $idtxt2 = "?id=" . $_GET['id']; } return "
"; } ?>