[TT 2.x] Forums
First add this to your database
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 '0',
`minclasswrite` tinyint(3) unsigned NOT NULL default '0',
`category` tinyint(2) NOT NULL default '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM 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', 0, 0, 1);
INSERT INTO `forum_forums` VALUES (0, 2, 'Test Forum 2', 'test2', 0, 0, 3);
INSERT INTO `forum_forums` VALUES (0, 3, 'Test Forum 3', 'test', 0, 0, 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 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 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 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 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);
Next add to functions.php:
PHP Code:
function autolink($al_url, $al_msg) // create autolink
{
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";
echo "</td>\n</tr>\n</table>\n</td>\n</tr>\n</table>\n</body>\n</html>\n";
stdfoot();
exit;
}
function classlist() {
$ret = array();
$res = mysql_query("SELECT * FROM groups ORDER BY group_id ASC");
while ($row = mysql_fetch_array($res))
$ret[] = $row;
return $ret;
}
Next add this to admincp.php:
PHP Code:
<td align="center"><a href=admincp.php?action=admin-forums><img src="images/admin/forums.gif" border=0 width=32 height=32><BR>Forum<BR>Configuration</a><BR></td>
Next add AFTER
PHP Code:
echo "<BR><center><b>Added OK</b></center><BR>";
end_frame();
stdfoot();
}
PHP Code:
#======================================================================#
# Forum Settings
#======================================================================#
if($action == "admin-forums"){
stdhead("Forums Management");
if($do == "add_this_forum"){
//add to db & create autolink
$error_ac == "";
if($new_forum_name == "") $error_ac .= "<li>Forum-name was empty\n";
if($new_desc == "") $error_ac .= "<li>Forum-description was empty\n";
if($new_forum_sort == "") $error_ac .= "<li>Forum sort order was empty\n";
if($new_forum_cat == "") $error_ac .= "<li>Forum category was empty\n";
if($error_ac == ""){
$sql = "INSERT INTO forum_forums (`name`, `description`, `sort`, `category`, `minclassread`, `minclasswrite`) VALUES
('$new_forum_name', '$new_desc', '$new_forum_sort', '$new_forum_cat', '$minclassread', '$minclasswrite')";
$ok = MYSQL_QUERY($sql);
if($ok)
autolink("admincp.php?action=admin-forums", "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"){
//add to db & create autolink
$error_ac == "";
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 == ""){
$sql = "INSERT INTO forumcats (`name`, `sort`) VALUES ('$new_forumcat_name', '$new_forumcat_sort')";
$ok = MYSQL_QUERY($sql) or die(mysql_error());
if($ok)
autolink("admincp.php?action=admin-forums", "Thank you, new forum cat added to db ...");
else
echo "<h4>Could not save to DB - check your connection & settings!</h4>";
}
}
//save edited data
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' WHERE id='$id'") or die(mysql_error());
echo "<br><br><center><b>Updated Completed</b></center>";
}
//save edited data cat
if($do == "save_editcat"){
mysql_query("UPDATE forumcats SET sort = '$changed_sortcat', name = '$changed_forumcat' WHERE id='$id'") or die(mysql_error());
echo "<br><br><center><b>Updated Completed</b></center>";
}
//finally delete forum
if($do == "delete_forum"){
if($delcat != ""){
$sql2 = "DELETE FROM forum_forums WHERE id = '$id'";
$ok2 = MYSQL_QUERY($sql2) or die(mysql_error());
if($ok2) autolink("admincp.php?action=admin-forums", "forum deleted ...");
}
}
//finally delete forumcat
if($do == "delete_forumcat"){
if($delcat != ""){
$sql2 = "DELETE FROM forumcats WHERE id = '$id'";
$ok2 = MYSQL_QUERY($sql2);
if($ok2) autolink("admincp.php?action=admin-forums", "forum cat deleted ...");
}
}
if($act == "forum" || $error_ac != ""){
//form to add forum
//adminonly();
//adminmenu();
begin_frame("<font color=2fdceb>Forums Management</font>");
$query = MYSQL_QUERY("SELECT * FROM forumcats ORDER BY sort, name");
$allcat = MYSQL_NUM_ROWS($query);
while($row =MYSQL_FETCH_ARRAY($query)) {
$forumcat[] = $row;
}
MYSQL_FREE_RESULT($query);
?>
<p>
<table align='center' width='80%' cellspacing='2' cellpadding='2'>
<form action='admincp.php?action=admin-forums' method='post'>
<input type='hidden' name='sid' value='<?=$sid?>'>
<input type='hidden' name='act' value='sql'>
<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>";
?>
</select></td></tr>
<td>Mininum Class Needed to Read:</td>
<td align='right'><select name='minclassread'>
<?
$group = classlist();
foreach ($group as $groups)
echo "<option value={$groups['group_id']}>{$groups['level']}</option>";
?>
</select></td></tr>
<td>Mininum Class Needed to Write:</td>
<td align='right'><select name='minclasswrite'>
<?
$group = classlist();
foreach ($group as $groups)
echo "<option value={$groups['group_id']}>{$groups['level']}</option>";
?>
</select></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";
?>
</table>
</form>
<p>
<table align='center' width='80%' cellspacing='2' cellpadding='2'>
<h5>Current Forums:</h5>
<?
// get forum from db
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=admin-forums&do=edit_forum&id=$row[id]'>[Edit]</a></td>\n";
echo "<td width='18'><a href='admincp.php?action=admin-forums&do=del_forum&id=$row[id]'><img src='images/delete.gif'
alt='Delete
Category' width='17' height='17' border='0'></a></td></tr>\n";
}
MYSQL_FREE_RESULT($query);
} //endif
echo "</table>\n";
?>
<BR><table align='center' width='80%' cellspacing='2' cellpadding='2'>
<h5>Current Forum Categories:</h5>
<?
// get forum from db
echo "<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=admin-forums&do=edit_forumcat&id=$row[id]'>[Edit]</a></td>\n";
echo "<td width='18'><a href='admincp.php?action=admin-forums&do=del_forumcat&id=$row[id]'><img src='images/delete.gif'
alt='Delete
Category' width='17' height='17' border='0'></a></td></tr>\n";
}
} //endif
echo "</table>\n";
?>
<BR><table align='center' width='80%' cellspacing='2' cellpadding='2'>
<form action='admincp.php?action=admin-forums' method='post'>
<input type='hidden' name='sid' value='<?=$sid?>'>
<input type='hidden' name='act' value='sql'>
<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();
}
//edit forum
if($do == "edit_forum"){
begin_frame("<font color=2fdceb>Edit Forum</font>");
$q = MYSQL_QUERY("SELECT * FROM forum_forums WHERE id = '$id'");
$r = MYSQL_FETCH_ARRAY($q);
MYSQL_FREE_RESULT($q);
?>
<table align='center' width='80%' cellspacing='2' cellpadding='2'>
<form action="admincp.php?action=admin-forums" method="post">
<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>";
MYSQL_FREE_RESULT($query);
?>
</select></td></tr>
<td>Mininum Class Needed to Read:</td>
<td align='right'><select name='minclassread'>
<?
$group = classlist();
foreach ($group as $groups)
echo "<option value={$groups['group_id']}>{$groups['level']}</option>";
?>
</select></td></tr>
<td>Mininum Class Needed to Write:</td>
<td align='right'><select name='minclasswrite'>
<?
$group = classlist();
foreach ($group as $groups)
echo "<option value={$groups['groups_id']}>{$groups['level']}</option>";
?>
</select></td></tr>
<tr><td><input type="submit" class="button" value="Change"></td></tr>
</form>
</table>
<?
end_frame();
}
//del Forum
if($do == "del_forum"){
begin_frame("<font color=2fdceb>Confirm</font>");
$t = MYSQL_QUERY("SELECT * FROM forum_forums WHERE id = '$id'");
$v = MYSQL_FETCH_ARRAY($t);
?>
<form action="admincp.php?action=admin-forums" method="post">
<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();
}
//del Forum
if($do == "del_forumcat"){
begin_frame("<font color=2fdceb>Confirm</font>");
$t = MYSQL_QUERY("SELECT * FROM forumcats WHERE id = '$id'");
$v = MYSQL_FETCH_ARRAY($t);
?>
<form action="admincp.php?action=admin-forums" method="post">
<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();
}
//edit forum
if($do == "edit_forumcat"){
begin_frame("<font color=2fdceb>Edit Category</font>");
$q = MYSQL_QUERY("SELECT * FROM forumcats WHERE id = '$id'");
$r = MYSQL_FETCH_ARRAY($q);
?>
<table align='center' width='80%' cellspacing='2' cellpadding='2'>
<form action="admincp.php?action=admin-forums" method="post">
<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>
<input type="submit" class="button" value="Change"></td></tr>
</form>
</table>
<?
end_frame();
}
begin_frame("<font color=2fdceb>Forums Management</font>");
echo "<b><font color=red>If something doesn't work, it probably shouldn't. Let me know and we'll see what happens...<br></b></font>";
$query = MYSQL_QUERY("SELECT * FROM forumcats ORDER BY sort, name");
$allcat = MYSQL_NUM_ROWS($query);
while($row =MYSQL_FETCH_ARRAY($query)) {
$forumcat[] = $row;
}
MYSQL_FREE_RESULT($query);
?>
<p>
<table align='center' width='80%' cellspacing='2' cellpadding='2'>
<form action='admincp.php?action=admin-forums' method='post'>
<input type='hidden' name='sid' value='<?=$sid?>'>
<input type='hidden' name='act' value='sql'>
<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>";
?>
</select></tr>
<td>Mininum Class Needed to Read:</td>
<td align='right'><select name='minclassread'>
<?
$group = classlist();
foreach ($group as $groups)
echo "<option value={$groups['group_id']}>{$groups['level']}</option>";
?>
</select></td></tr>
<td>Mininum Class Needed to Write:</td>
<td align='right'><select name='minclasswrite'>
<?
$group = classlist();
foreach ($group as $groups)
echo "<option value={$groups['group_id']}>{$groups['level']}</option>";
?>
</select></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";
?>
</table></form>
<p>
<table align='center' width='80%' cellspacing='2' cellpadding='2'>
<h5>Current Forums:</h5>
<?
// get forum from db
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=admin-forums&do=edit_forum&id=$row[id]'>[Edit]</a></td>\n";
echo "<td width='18'><a href='admincp.php?action=admin-forums&do=del_forum&id=$row[id]'><img src='images/delete.gif'
alt='Delete
Category' width='17' height='17' border='0'></a></td></tr>\n";
}
MYSQL_FREE_RESULT($query);
} //endif
echo "</table>\n";
?>
<BR><table align='center' width='80%' cellspacing='2' cellpadding='2'>
<h5>Current Forum Categories:</h5>
<?
// get forum from db
echo "<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=admin-forums&do=edit_forumcat&id=$row[id]'>[Edit]</a></td>\n";
echo "<td width='18'><a href='admincp.php?action=admin-forums&do=del_forumcat&id=$row[id]'><img src='images/delete.gif'
alt='Delete
Category' width='17' height='17' border='0'></a></td></tr>\n";
}
} //endif
echo "</table>\n";
?>
<BR><table align='center' width='80%' cellspacing='2' cellpadding='2'>
<form action='admincp.php?action=admin-forums' method='post'>
<input type='hidden' name='sid' value='<?=$sid?>'>
<input type='hidden' name='act' value='sql'>
<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();
navmenu();
stdfoot();
}
#======================================================================#
# End Forum Management
#======================================================================#
Then upload to root the following files
|