Forgot Password / Register
Site Statistics
Total Members: 520
Total Tutorials: 242
Newsest User: 8884244477
Todays Unique Hits: 20
0 Users 5 Guests Online

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.
SkillMaster
Views:
3262
Rating:
Posted on Monday 24th September 2007 at 02:31 PM
fryser
fryser
@ SkillMaster I mean a sarch function on RMB :) lol
Posted on Friday 29th June 2007 at 02:29 PM
new2old
new2old
When i tested it i got normal members to sign up and they could see it
and post in it
Posted on Thursday 21st June 2007 at 08:49 PM
SkillMaster
SkillMaster
Really?
Posted on Thursday 21st June 2007 at 01:56 PM
new2old
new2old
Everyone can see the admin threads ;]

Just to let you no
Posted on Wednesday 20th June 2007 at 09:25 PM
SkillMaster
SkillMaster
Yeah well you dont need one. click php - user system its there? :S
Posted on Tuesday 19th June 2007 at 04:52 PM
fryser
fryser
Oh i'm sorry i've just saw the other tutorials great thanks :) tough a search functions would be nice :p lol
Posted on Tuesday 19th June 2007 at 04:49 PM
fryser
fryser
Im sorry to be so newbies but that file "forum_admin.php" where i am suposing to get the tutorials for its? :s
Posted on Monday 18th June 2007 at 08:52 PM
SkillMaster
SkillMaster
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;

It should be that sorry xD my bad
Posted on Monday 18th June 2007 at 08:37 PM
cyruswu
cyruswu
The if else. When it shows the category it does an if else to see if it's an admin then it views it.
Posted on Monday 18th June 2007 at 02:49 PM
new2old
new2old
By looking through i can't see how this displays the threads in the Admin section.

I'll test it later