[TT v2.x] Forum
forums.php goes in root, smilies.php in backend/ (overwrite the existing one).
FORUM SQL
PHP Code:
CREATE TABLE `forum_forums` ( `sort` tinyint(3) unsigned NOT NULL default '0', `id` int(10) unsigned NOT NULL auto_increment, `name` varchar(60) NOT NULL default '', `description` varchar(200) default NULL, `minclassread` tinyint(3) unsigned NOT NULL default '1', `minclasswrite` tinyint(3) unsigned NOT NULL default '1', `guest_read` enum('yes', 'no') default 'yes', `category` tinyint(2) NOT NULL default '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
INSERT INTO `forum_forums` VALUES (1, 1, 'Example Forum', 'Here is a example forum, you can edit the forums via the control panel', 1, 1, 'yes', 1); INSERT INTO `forum_forums` VALUES (0, 2, 'Test Forum 2', 'test2', 1, 1, 'yes', 3); INSERT INTO `forum_forums` VALUES (0, 3, 'Test Forum 3', 'test', 1, 1, 'yes', 4);
CREATE TABLE `forum_posts` ( `id` int(10) unsigned NOT NULL auto_increment, `topicid` int(10) unsigned NOT NULL default '0', `userid` int(10) unsigned NOT NULL default '0', `added` datetime default NULL, `body` text, `editedby` int(10) unsigned NOT NULL default '0', `editedat` datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (`id`), KEY `topicid` (`topicid`), KEY `userid` (`userid`), FULLTEXT KEY `body` (`body`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
CREATE TABLE `forum_readposts` ( `id` int(10) unsigned NOT NULL auto_increment, `userid` int(10) unsigned NOT NULL default '0', `topicid` int(10) unsigned NOT NULL default '0', `lastpostread` int(10) unsigned NOT NULL default '0', PRIMARY KEY (`id`), KEY `userid` (`id`), KEY `topicid` (`topicid`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
INSERT INTO `forum_posts` VALUES (5, 3, 1, '2005-02-27 19:40:38', 'Here is a example post', 0, '0000-00-00 00:00:00'); INSERT INTO `forum_posts` VALUES (8, 3, 1, '2005-05-18 08:18:22', 'test 2', 1, '2005-11-11 14:40:44'); INSERT INTO `forum_posts` VALUES (9, 6, 1, '2005-07-11 18:49:27', 'test 3', 0, '0000-00-00 00:00:00');
CREATE TABLE `forum_topics` ( `id` int(10) unsigned NOT NULL auto_increment, `userid` int(10) unsigned NOT NULL default '0', `subject` varchar(40) default NULL, `locked` enum('yes','no') NOT NULL default 'no', `forumid` int(10) unsigned NOT NULL default '0', `lastpost` int(10) unsigned NOT NULL default '0', `moved` enum('yes','no') NOT NULL default 'no', `sticky` enum('yes','no') NOT NULL default 'no', `views` int(10) NOT NULL default '0', PRIMARY KEY (`id`), KEY `userid` (`userid`), KEY `subject` (`subject`), KEY `lastpost` (`lastpost`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
INSERT INTO `forum_topics` VALUES (3, 1, 'Test Topic', 'no', 2, 8, 'no', 'no', 15); INSERT INTO `forum_topics` VALUES (6, 1, 'Test Topic 2', 'no', 3, 9, 'no', 'no', 1);
CREATE TABLE `forumcats` ( `id` int(10) unsigned NOT NULL auto_increment, `name` varchar(60) NOT NULL default '', `sort` int(10) unsigned NOT NULL default '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
INSERT INTO `forumcats` VALUES (1, 'Test Cat 1', 1); INSERT INTO `forumcats` VALUES (3, 'Test Cat 2', 3); INSERT INTO `forumcats` VALUES (4, 'Test Cat 3', 4);
add to admincp.php:
PHP Code:
// Forum management if (!function_exists("autolink")) { function autolink($al_url, $al_msg) { stdhead(); begin_frame("", "center"); echo "\n<meta http-equiv=\"refresh\" content=\"3; URL=$al_url\">\n"; echo "<b>$al_msg</b>\n"; echo "<p>\n<b>Redirecting ...</b>\n"; echo "<p>\n[ <a href='$al_url'>link</a> ]\n"; end_frame(); stdfoot(); exit; } } if ($action == "forum") {
$error_ac == ""; if ($do == "add_this_forum") { if ($new_forum_name == "") $error_ac .= "<li>Forum-name was empty"; if ($new_desc == "") $error_ac .= "<li>Forum-description was empty"; if ($new_forum_sort == "") $error_ac .= "<li>Forum sort order was empty"; if ($new_forum_cat == "") $error_ac .= "<li>Forum category was empty";
if ($error_ac == "") { $res = mysql_query("INSERT INTO forum_forums (`name`, `description`, `sort`, `category`, `minclassread`, `minclasswrite`, `guest_read`) VALUES ('$new_forum_name', '$new_desc', '$new_forum_sort', '$new_forum_cat', '$minclassread', '$minclasswrite', '$guest_read')"); if ($res) autolink("admincp.php?action=forum", "Thank you, new forum added to db ..."); else echo "<h4>Could not save to DB - check your connection & settings!</h4>"; } }
if ($do == "add_this_forumcat") { if ($new_forumcat_name == "") $error_ac .= "<li>Forum cat name was empty\n"; if ($new_forumcat_sort == "") $error_ac .= "<li>Forum cat sort order was empty\n";
if ($error_ac == "") { $res = mysql_query("INSERT INTO forumcats (`name`, `sort`) VALUES ('$new_forumcat_name', '$new_forumcat_sort')"); if ($res) autolink("admincp.php?action=forum", "Thank you, new forum cat added to db ..."); else echo "<h4>Could not save to DB - check your connection & settings!</h4>"; } }
if ($do == "save_edit") { mysql_query("UPDATE forum_forums SET sort = '$changed_sort', name = '$changed_forum', description = '$changed_forum_desc', category = '$changed_forum_cat', minclassread='$minclassread', minclasswrite='$minclasswrite', guest_read='$guest_read' WHERE id='$id'"); autolink("admincp.php?action=forum", "<center><b>Update Completed</b></center>"); }
if ($do == "save_editcat") { mysql_query("UPDATE forumcats SET sort = '$changed_sortcat', name = '$changed_forumcat' WHERE id='$id'"); autolink("admincp.php?action=forum", "<center><b>Update Completed</b></center>"); }
if ($do == "delete_forum" && $delcat != "" && is_valid_id($id)) { mysql_query("DELETE FROM forum_forums WHERE id = $id"); autolink("admincp.php?action=forum", "forum deleted ..."); } if ($do == "delete_forumcat" && $delcat != "" && is_valid_id($id)) { mysql_query("DELETE FROM forumcats WHERE id = $id"); autolink("admincp.php?action=forum", "forum cat deleted ..."); } stdhead("Forum Management"); $groupsres = mysql_query("SELECT group_id, level FROM groups ORDER BY group_id ASC"); while ($groupsrow=mysql_fetch_row($groupsres)) $groups[$groupsrow[0]] = $groupsrow[1];
if ($do == "edit_forum") { begin_frame("Edit Forum"); $q = MYSQL_QUERY("SELECT * FROM forum_forums WHERE id = '$id'"); $r = MYSQL_FETCH_ARRAY($q); ?> <table align='center' width='80%' bgcolor='#cecece' cellspacing='2' cellpadding='2' style='border: 1px solid black'>
<form action="admincp.php" method="post"> <input type="hidden" name="action" value="forum"> <input type="hidden" name="do" value="save_edit"> <input type="hidden" name="id" value="<?=$id?>"> <tr><td>New Name for Forum:</td> <td align='right'><input type="text" name="changed_forum" class="option" size="35" value="<?=$r[name]?>"></td></tr> <tr><td>New Sort Order:</td> <td align='right'><input type="text" name="changed_sort" class="option" size="35" value="<?=$r[sort]?>"></td></tr> <tr><td>Description:</td> <td align='right'><textarea cols='50' rows='5' name='changed_forum_desc'><?=$r[description]?></textarea></td></tr> <tr><td>New Category:</td> <td align='right'><select name='changed_forum_cat'> <? $query = MYSQL_QUERY("SELECT * FROM forumcats ORDER BY sort, name"); while ($row=mysql_fetch_array($query)) echo "<option value={$row['id']}>{$row['name']}</option>";
echo "</select></td></tr> <tr><td>Mininum Class Needed to Read:</td> <td align='right'><select name='minclassread'>";
foreach ($groups as $id => $level) { $s = $r["minclassread"] == $id ? " selected" : ""; echo "<option value='$id' $s>$level</option>"; }
echo "<tr><td>Mininum Class Needed to Post:</td> <td align='right'><select name='minclasswrite'>";
foreach ($groups as $id => $level) { $s = $r["minclasswrite"] == $id ? " selected" : ""; echo "<option value='$id' $s>$level</option>"; } ?> </select></td></tr> <tr><td>Allow Guests to Read:</td><td align='right'><input type="radio" name="guest_read" value="yes" <?=$r["guest_read"] == "yes" ? "checked" : ""?>>Yes, <input type="radio" name="guest_read" value="no" <?=$r["guest_read"] != "yes" ? "checked" : ""?>>No</td></tr> <tr><td><input type="submit" class="button" value="Change"></td></tr> </form> </table> <? end_frame(); }
if ($do == "del_forum") { begin_frame("Confirm"); $t = MYSQL_QUERY("SELECT * FROM forum_forums WHERE id = '$id'"); $v = MYSQL_FETCH_ARRAY($t); ?> <form action="admincp.php" method="post"> <input type="hidden" name="action" value="forum"> <input type="hidden" name="do" value="delete_forum"> <input type="hidden" name="id" value="<?=$id?>"> Really delete the Forum <?="<b>$v[name] with ID$v[id] ???</b>"?> <input type="submit" name="delcat" class="button" value="Delete"> </form> <? end_frame(); }
if ($do == "del_forumcat") { begin_frame("Confirm"); $t = MYSQL_QUERY("SELECT * FROM forumcats WHERE id = '$id'"); $v = MYSQL_FETCH_ARRAY($t); ?> <form action="admincp.php" method="post"> <input type="hidden" name="action" value="forum"> <input type="hidden" name="do" value="delete_forumcat"> <input type="hidden" name="id" value="<?=$id?>"> Really delete the Forum category<?="<b>$v[name] with ID$v[id] ???</b> All Sub Forums will now be invisible"?> <input type="submit" name="delcat" class="button" value="Delete"> </form> <? end_frame(); }
if ($do == "edit_forumcat") { begin_frame("Edit Category"); $q = MYSQL_QUERY("SELECT * FROM forumcats WHERE id = '$id'"); $r = MYSQL_FETCH_ARRAY($q); ?> <table align='center' width='80%' bgcolor='#cecece' cellspacing='2' cellpadding='2' style='border: 1px solid black'> <form action="admincp.php" method="post"> <input type="hidden" name="action" value="forum"> <input type="hidden" name="do" value="save_editcat"> <input type="hidden" name="id" value="<?=$id?>"> <tr><td>New Name for Category:</td></tr> <tr><td><input type="text" name="changed_forumcat" class="option" size="35" value="<?=$r[name]?>"></td></tr> <tr><td>New Sort Order:</td></tr> <tr><td><input type="text" name="changed_sortcat" class="option" size="35" value="<?=$r[sort]?>"></td></tr> <tr><td><input type="submit" class="button" value="Change"></td></tr> </form> </table> <? end_frame(); stdfoot(); } if (!$do) { navmenu(); begin_frame("Forums Management"); $query = MYSQL_QUERY("SELECT * FROM forumcats ORDER BY sort, name"); $allcat = MYSQL_NUM_ROWS($query); while ($row = MYSQL_FETCH_ARRAY($query)) $forumcat[] = $row;
echo "<p> <table align='center' width='80%' bgcolor='#cecece' cellspacing='2' cellpadding='2' style='border: 1px solid black'> <form action='admincp.php' method='post'> <input type='hidden' name='sid' value='<?=$sid?>'> <input type='hidden' name='action' value='forum'> <input type='hidden' name='do' value='add_this_forum'> <tr> <td>Name of the new Forum:</td> <td align='right'><input type='text' name='new_forum_name' size='30' maxlength='30' value='$new_forum_name'></td> </tr> <tr> <td>Forum Sort Order:</td> <td align='right'><input type='text' name='new_forum_sort' size='10' maxlength='10' value='$new_forum_sort'></td> </tr> <tr> <td>Description of the new Forum:</td> <td align='right'><textarea cols='50' rows='5' name='new_desc'>$new_desc</textarea></td> </tr> <tr> <td>Forum Category:</td> <td align='right'><select name='new_forum_cat'>"; foreach ($forumcat as $row) echo "<option value={$row['id']}>{$row['name']}</option>";
echo "</select> </tr> <tr><td>Mininum Class Needed to Read:</td> <td align='right'><select name='minclassread'>";
foreach ($groups as $id => $level) { $s = $r["minclassread"] == $id ? " selected" : ""; echo "<option value='$id' $s>$level</option>"; }
echo "</select></td></tr> <tr><td>Mininum Class Needed to Post:</td> <td align='right'><select name='minclasswrite'>";
foreach ($groups as $id => $level) { $s = $r["minclasswrite"] == $id ? " selected" : ""; echo "<option value='$id' $s>$level</option>"; }
echo "</select></td></tr>". "<tr><td>Allow Guests to Read:</td><td align='right'><input type=\"radio\" name=\"guest_read\" value=\"yes\" checked>Yes, <input type=\"radio\" name=\"guest_read\" value=\"no\" >No</td></tr>". "<tr> <td colspan='2' align='center'> <input type='submit' value='Add new forum'> <input type='reset' value='Reset'> </td> </tr>";
if($error_ac != "") echo "<tr><td colspan='2' align='center' style='background:#eeeeee;border:2px red solid'><b>COULD NOT ADD NEW forum:</b><br />$error_ac</tr></td>\n";
echo "</table> </form> <p> <table align='center' width='80%' bgcolor='#cecece' cellspacing='2' cellpadding='2' style='border: 1px solid black'> <h5>Current Forums:</h5>";
echo "<tr><td width='60'><font size='2'><b>ID</b></td><td width='120'>NAME</td><td width='250'>DESC</td><td width='45'>SORT</td><td width='45'>CATEGORY</td><td width='18'>EDIT</td><td width='18'>DEL</td></font>\n"; $query = MYSQL_QUERY("SELECT * FROM forum_forums ORDER BY sort, name"); $allforums = MYSQL_NUM_ROWS($query); if ($allforums == 0) { echo "<h4>None</h4>\n"; } else { while($row = MYSQL_FETCH_ARRAY($query)) { foreach ($forumcat as $cat) if ($cat['id'] == $row['category']) $category = $cat['name']; echo "<tr><td width='60'><font size='2'><b>ID($row[id])</b></td><td width='120'> $row[name]</td><td width='250'>$row[description]</td><td width='45'>$row[sort]</td><td width='45'>$category</td></font>\n"; echo "<td width='18'><a href='admincp.php?action=forum&do=edit_forum&id=$row[id]'>[Edit]</a></td>\n"; echo "<td width='18'><a href='admincp.php?action=forum&do=del_forum&id=$row[id]'><img src='images/delete.gif' alt='Delete Category' width='17' height='17' border='0'></a></td></tr>\n"; } } echo "</table> <BR><table align='center' width='80%' bgcolor='#cecece' cellspacing='2' cellpadding='2' style='border: 1px solid black'> <h5>Current Forum Categories:</h5>
<tr><td width='60'><font size='2'><b>ID</b></td><td width='120'>NAME</td><td width='18'>SORT</td><td width='18'>EDIT</td><td width='18'>DEL</td></font>\n";
if ($allcat == 0) { echo "<h4>None set</h4>\n"; } else { foreach ($forumcat as $row) { echo "<tr><td width='60'><font size='2'><b>ID($row[id])</b></td><td width='120'> $row[name]</td><td width='18'>$row[sort]</td>\n"; echo "<td width='18'><a href='admincp.php?action=forum&do=edit_forumcat&id=$row[id]'>[Edit]</a></td>\n"; echo "<td width='18'><a href='admincp.php?action=forum&do=del_forumcat&id=$row[id]'><img src='images/delete.gif' alt='Delete Category' width='17' height='17' border='0'></a></td></tr>\n"; } } echo "</table>\n";
echo "<BR><table align='center' width='80%' bgcolor='#cecece' cellspacing='2' cellpadding='2' style='border: 1px solid black'> <form action='admincp.php' method='post'> <input type='hidden' name='action' value='forum'> <input type='hidden' name='do' value='add_this_forumcat'> <tr> <td>Name of the new Category:</td> <td align='right'><input type='text' name='new_forumcat_name' size='30' maxlength='30' value='$new_forumcat_name'></td> </tr> <tr> <td>Category Sort Order:</td> <td align='right'><input type='text' name='new_forumcat_sort' size='10' maxlength='10' value='$new_forumcat_sort'></td> </tr>
<tr> <td colspan='2' align='center'> <input type='submit' value='Add new category'> <input type='reset' value='Reset'> </td> </tr> </table> </form>"; end_frame(); } // End New Forum
} // End Forum management (TorrentialStorm)
Add in admincp.php link for navmenu():
PHP Code:
<td align="center"><a href='admincp.php?action=forum'><img src="http://bvlist.com/images/admin/forums.gif" border=0 width=32 height=32><br>Forum Management</a></td>
add to config.php:
PHP Code:
$site_config['FORUMS'] = true; // Enable / Disable Forums $site_config['FORUMS_GUESTREAD'] = true; // Allow / Disallow Guests To Read Forums
Get delete.gif from here and put it in images/.
SVN.
Code:
http://torrenttrader.svn.sourceforge.net/svnroot/torrenttrader/v2/branches/forums/
|