Admin only forum add on.
To make a certain topic where only admins and mods can post in it.
Code
ALTER TABLE `forum_topic` ADD `adminonly` VARCHAR( 225 ) NOT NULL default 'No';
In forum_admin.php find:
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
case 'addtopic':
echo ("
<form method='POST' action='?page=inserttopic'>
<table width='100%'>
<tr>
<td align='right' width='25%'>New Topic Name</td>
<td align='left'>
<input size='25' name='topic'></td>
</tr>
<tr>
<td align='right' width='25%'>Description</td>
<td align='left'>
<input size='25' name='description'></td>
</tr>
<tr>
<td align='right' width='25%'>Under Category</td>
<td align='left'>
<select name='cid'>
");
$fetch = mysql_query("SELECT * FROM `forum_category`");
while ($category = mysql_fetch_array($fetch))
{
echo ("<option value='$category[id]'>$category[name]</option>");
}
echo ("
</select>
</td>
</tr>
<tr>
<td align='center'></td>
<td align='left'>
<input type='submit' name='submit' value='Update'></td>
</tr>
</table>
</form>
");
break;
case 'inserttopic':
$description = strip_tags(htmlspecialchars($_POST[description]));
$topic = strip_tags(htmlspecialchars($_POST[topic]));
$cid = (int) htmlspecialchars($_POST[cid]);
$insert = mysql_query("INSERT INTO `forum_topic` (`name`, `cat_id`, `description`) VALUES ('$topic', '$cid', '$description')");
echo ("New Category Created. Redirecting you...<meta http-equiv='refresh' content='2;url=forum_admin.php'>");
break;
Replace with
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
case 'addtopic':
echo ("
<form method='POST' action='?page=inserttopic'>
<table width='100%'>
<tr>
<td align='right' width='25%'>New Topic Name</td>
<td align='left'>
<input size='25' name='topic'></td>
</tr>
<tr>
<td align='right' width='25%'>Description</td>
<td align='left'>
<input size='25' name='description'></td>
</tr>
<tr>
<td align='right' width='25%'>Admin Threads Only?</td>
<td align='left'>
<select name='adminonly'>
<option value='No'>No</option>
<option value='Yes'>Yes</option>
</select></td>
</tr>
<tr>
<td align='right' width='25%'>Under Category</td>
<td align='left'>
<select name='cid'>
");
$fetch = mysql_query("SELECT * FROM `forum_category`");
while ($category = mysql_fetch_array($fetch))
{
echo ("<option value='$category[id]'>$category[name]</option>");
}
echo ("
</select>
</td>
</tr>
<tr>
<td align='center'></td>
<td align='left'>
<input type='submit' name='submit' value='Update'></td>
</tr>
</table>
</form>
");
break;
case 'inserttopic':
$description = strip_tags(htmlspecialchars($_POST[description]));
$topic = strip_tags(htmlspecialchars($_POST[topic]));
$adminonly = strip_tags(htmlspecialchars($_POST[adminonly]));
$cid = (int) htmlspecialchars($_POST[cid]);
$insert = mysql_query("INSERT INTO `forum_topic` (`name`, `cat_id`, `description`, `adminonly`) VALUES ('$topic', '$cid', '$description', '$adminonly')");
echo ("New Category Created. Redirecting you...<meta http-equiv='refresh' content='2;url=forum_admin.php'>");
break;
In forum.php find:
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
case 'forum':
echo ("<table width='100%' cellpadding='0'>");
$fetch1 = mysql_query("SELECT * FROM `forum_topic` WHERE `id` = '$_GET[id]'");
$topic = mysql_fetch_array($fetch1);
echo ("<tr><td id='mains'><b>$topic[name]</b> - <a href='?page=newthread&id=$_GET[id]'>New Thread</a></td><td id='mains'><b>Thread starter</b></td></tr>");
$fetch2 = mysql_query("SELECT * FROM `forum_thread` WHERE `id` = '$_GET[id]' ORDER BY `sticky` DESC");
while ($thread = mysql_fetch_array($fetch2))
{
$threadtitle = "$thread[title]";
$bbctt1 = BBCODE($threadtitle);
if($thread[sticky] == Yes)
{
echo ("<tr><td id='fields'><a href='?page=forumdisplay&id=$thread[id]'><b>Sticky:</b> $bbctt1</a></td><td id='fields'>$thread[poster]</td></tr>");
}
else
{
echo ("<tr><td id='fields'><a href='?page=forumdisplay&id=$thread[id]'>$bbctt1</a></td><td id='fields'>$thread[poster]</td></tr>");
}
}
echo ("</table>");
break;
Replace with
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
case 'forum':
echo ("<table width='100%' cellpadding='0'>");
$fetch1 = mysql_query("SELECT * FROM `forum_topic` WHERE `id` = '$_GET[id]'");
$topic = mysql_fetch_array($fetch1);
if ($logged[userlevel] == 4 || $logged[userlevel] == 6 && $topic[adminonly] == Yes)
{
echo ("<tr><td id='mains' width='50%'><b>$topic[name]</b> - <a href='?page=newthread&id=$_GET[id]'>New Thread</a></td><td id='mains'><b>Thread starter</b></td></tr>");
}
elseif ($logged[userlevel] == 2 && $topic[adminonly] == Yes)
{
echo ("<tr><td id='mains' width='50%'><b>$topic[name]</b></td><td id='mains'><b>Thread starter</b></td></tr>");
}
else
{
echo ("<tr><td id='mains' width='50%'><b>$topic[name]</b> - <a href='?page=newthread&id=$_GET[id]'>New Thread</a></td><td id='mains'><b>Thread starter</b></td></tr>");
}
$fetch2 = mysql_query("SELECT * FROM `forum_thread` WHERE `id` = '$_GET[id]' ORDER BY `sticky` DESC");
while ($thread = mysql_fetch_array($fetch2))
{
$threadtitle = "$thread[title]";
$bbctt1 = BBCODE($threadtitle);
if($thread[sticky] == Yes)
{
echo ("<tr><td id='fields'><a href='?page=forumdisplay&id=$thread[id]'><b>Sticky:</b> $bbctt1</a></td><td id='fields'>$thread[poster]</td></tr>");
}
else
{
echo ("<tr><td id='fields'><a href='?page=forumdisplay&id=$thread[id]'>$bbctt1</a></td><td id='fields'>$thread[poster]</td></tr>");
}
}
echo ("</table>");
break;
Basically we added a new row into the database. in forum_admin.php we let the admin choose whether the topic will be adminonly or not.
In forum.php we used a basic if and else command to see whether the topic adminonly is yes if it is we only show the title if no we show add thread as well
It works it has been tested. If there are any errors please post and we will troubleshoot.
Thats it for my tutorial.