View file admincp/manageforum.php

File size: 8.29Kb
<?php
// YANG HACK JANGAN HILANGKAN LISENSI INI
// HTTP://INDWAP.COM
// DAMAI SELALU TAK PERNAH JAIL KARENA TIDAK BISA APA-APA
// SCRIPT BY ULOKI.COM
// REMODIF BY ANTOQ 
// HTTP://FACEBOOK.COM/WWW.INDWAP.ORG

require("../include/init.php");

if($group[$user->groupid]['type'] < 3)
{
forward("index.php");
}

include "../include/header.php";
?>
<table class="maintable" cellspacing="1">

<table class="smalltable">
<tr style="background-color:#cccccc;"><td><a href="manageforum.php?do=new">Add Forum</a></td></tr>
</table>
<?php

if($group[$user->groupid]['type'] == 3)
{
err_msg("Admin CP","You dont have this right to perform this section.","</td></tr></table>");
}


if(isset($_GET['do']))
$do=$_GET['do'];
else
$do="";

if($do=="new")
{
if(isset($_POST['save']))
{
$fname=$_POST['forumname'];
$catid=$_POST['catid'];
$fsort=$_POST['fsort'];
$description=trim($_POST['description']);


if(strlen($fname) == 0)
{
err_msg("Admin CP","Forum name cannot be blank.","</td></tr></table>");
}

$forumid = $db->insert_data("INSERT INTO b_forums(parentid,name,description,numtopics,numposts,sort,lastpostuser,lastposttime,pforum) VALUES('$catid','$fname','$description','0','0','$fsort','0','0','0')");

foreach($group as $key => $val)
{
if($val['type']==0)
$db->insert_data("INSERT INTO b_permissions(forumid, groupid, view, newtopic, newpost, editpost, editotherpost, deletepost, deleteotherpost, movethread, lockthread, stickthread, upload, download) VALUES('$forumid','$key','1','0','0','0','0','0','0','0','0','0','0','0')");
else if($val['type']==1)
$db->insert_data("INSERT INTO b_permissions(forumid, groupid, view, newtopic, newpost, editpost, editotherpost, deletepost, deleteotherpost, movethread, lockthread, stickthread, upload, download) VALUES('$forumid','$key','1','1','1','1','0','0','0','0','0','0','1','1')");
else if($val['type']==2)
$db->insert_data("INSERT INTO b_permissions(forumid, groupid, view, newtopic, newpost, editpost, editotherpost, deletepost, deleteotherpost, movethread, lockthread, stickthread, upload, download) VALUES('$forumid','$key','1','1','1','1','1','1','1','1','1','0','1','1') ");
else if($val['type']==3)
$db->insert_data("INSERT INTO b_permissions(forumid, groupid, view, newtopic, newpost, editpost, editotherpost, deletepost, deleteotherpost, movethread, lockthread, stickthread, upload, download) VALUES('$forumid','$key','1','1','1','1','1','1','1','1','1','1','1','1') ");
else if($val['type']==4)
$db->insert_data("INSERT INTO b_permissions(forumid, groupid, view, newtopic, newpost, editpost, editotherpost, deletepost, deleteotherpost, movethread, lockthread, stickthread, upload, download) VALUES('$forumid','$key','1','1','1','1','1','1','1','1','1','1','1','1') ");

}

err_msg("Admin CP","Forum added. <a href=\"manageforum.php\">Click here</a>","</td></tr></table>");

}
else
{
$catlist=$db->select("SELECT * FROM b_categories ORDER BY catsort ASC");
if(!$catlist)
{
err_msg("Admin CP","You dont have categories. First add categories then you may add forum.");
}
?>
<form action="manageforum.php?do=new" method="POST">
<table class="smalltable" style="width:500;">
<tr><td>Forum Name:<br/><input type="text" name="forumname" value=""/> </td> </tr>
<tr><td>Description: <br/><textarea name="description"></textarea></td> </tr>
<tr><td>Category: <br/><select name="catid">
<?php
foreach($catlist as $cat)
print "<option value=\"".$cat->categoryid."\">".$cat->categoryname."</option>";
?>
</select></td> </tr>
<tr><td>Sort: <br/><input type="text" name="fsort" size="5" value=""/></td> </tr>

<tr><td> <input type="submit" name="save" value="Add"/> </td> </tr>
</table>
</form>
<?php
}
}
else if($do=="edit")
{
$fid=$_GET['fid'];
$forum=$db->get_row("SELECT * FROM b_forums WHERE forumid='$fid'");

$catlist=$db->select("SELECT * FROM b_categories ORDER BY catsort ASC");
if(!$catlist)
{
err_msg("Admin CP","You dont have categories. First add categories then you may edit forum.");
}

if(isset($_POST['save']))
{
$fname=trim($_POST['forumname']);
$catid=trim($_POST['catid']);
$fsort=trim($_POST['fsort']);
$description=trim($_POST['description']);

if(strlen($fname) == 0)
{
err_msg("Admin CP","Forum name cannot be blank.","</td></tr></table>");
}

$db->update_data("UPDATE b_forums SET parentid='$catid', name='$fname', description='$description', sort='$fsort' WHERE forumid='$fid'");
$db->update_data("UPDATE b_forums SET parentid='$catid' WHERE pforum='$fid'");
err_msg("Admin CP","Forum edited. <a href=\"manageforum.php\">Click here</a>","</td></tr></table>");

}
else
{

?>
<form action="manageforum.php?do=edit&fid=<?php echo $fid; ?>" method="POST">
<table class="smalltable" style="width:500;">
<tr><td>Forum Name: <br/><input type="text" name="forumname" value="<?php echo $forum->name;?>"/> </td></tr>
<tr><td>Description:<br/><textarea name="description"><?php echo $forum->description;?></textarea>
 </td> </tr>
<tr><td>Category:<br/><select name="catid">
<?php
foreach($catlist as $cat)
{
$sel=""; if($cat->categoryid == $forum->parentid){ $sel="selected=\"selected\""; }
print "<option value=\"".$cat->categoryid."\" ".$sel.">".$cat->categoryname."</option>";
}
?>
</select>  </td> </tr>
<tr><td>Sort: <br/><input type="text" name="fsort" size="5" value="<?php echo $forum->sort;?>"/> </td></tr>
<tr><td> <input type="submit" name="save" value="Save"/> </td> </tr>
</table>
</form>
<?php
}
}
else if($do=="delete")
{
$fid=$_GET['fid'];
$forum=$db->get_row("SELECT * FROM b_forums WHERE parentid='$fid'");


if(isset($_POST['yes']))
{

if($po=$db->select("SELECT id FROM b_posts WHERE postforum='$fid'"))
{
foreach($po as $post)
{
if($attach=$db->get_row("SELECT flocation FROM b_attachment WHERE postid='$post->id'"))
unlink(dirname(dirname(__FILE__))."/".$attach->flocation);
$db->delete_data("DELETE FROM b_attachment WHERE postid='$post->id'");
}
}
unset($po);
$db->delete_data("DELETE FROM b_forums WHERE forumid='$fid'");
$db->delete_data("DELETE FROM b_threads WHERE postforum='$fid'");
$db->delete_data("DELETE FROM b_posts WHERE postforum='$fid'");
$db->delete_data("DELETE FROM b_permissions WHERE forumid='$fid'");


if($fo=$db->select("SELECT * b_forums WHERE pforum='$fid'"))
{
foreach($fo as $foru)
{
if($po=$db->select("SELECT id FROM b_posts WHERE postforum='$foru->forumid'"))
{
foreach($po as $post)
{
if($attach=$db->get_row("SELECT flocation FROM b_attachment WHERE postid='$post->id'"))
unlink(dirname(dirname(__FILE__))."/".$attach->flocation);
$db->delete_data("DELETE FROM b_attachment WHERE postid='$post->id'");
}
}
unset($po);
$db->delete_data("DELETE FROM b_threads WHERE postforum='$forum->forumid'");
$db->delete_data("DELETE FROM b_posts WHERE postforum='$forum->forumid'");
$db->delete_data("DELETE FROM b_permissions WHERE forumid='$forum->forumid'");
}
}
unset($fo);
$db->delete_data("DELETE FROM b_forums WHERE pforum='$fid'");

err_msg("Admin CP","Forum deleted. <a href=\"manageforum.php\">Click here</a>","</td></tr></table>");

}
else
{

?>
<form action="manageforum.php?do=delete&fid=<?php echo $fid; ?>" method="POST">

This forum may contain some subforums or/and posts. So please what kind of action you want to perform ?<br/>
<br/> <input type="submit" name="yes" value="Delete all subforums, posts with this forum"/>

<b>OR</b> <a href="javascript:history.back();">Go Back</a><br/><br/>

</form>
<?php
}
}
else
{
?>
<table class="smalltable">
<?php
$catlist=$db->select("SELECT * FROM b_categories ORDER BY catsort ASC");

if($catlist)
{
foreach($catlist as $cat)
{
print "<tr style=\"background-color:#cccccc;\"><td>".$cat->categoryname."</td></tr>";
$forumlist=$db->select("SELECT * FROM b_forums WHERE parentid='$cat->categoryid' AND pforum='0' ORDER BY sort ASC");

if($forumlist)  // If forums under that category is fetched then show them
{
foreach($forumlist as $forum)
print "<tr style=\"background-color:#dddddd;\"><td>&nbsp;&nbsp;=>&nbsp;".$forum->name."</td><td width=\"60\"><a href=\"manageforum.php?do=edit&fid=".$forum->forumid."\">Edit</a></td><td width=\"60\"><a href=\"manageforum.php?do=delete&fid=".$forum->forumid."\">Delete</a></td></tr>";
}

}
}
?>
</table>
<?php
}
echo '<div class="phdr"><a href="index.php">Admin panel</a> | <a href="manageforum.php">Kembali</a></div>';
include "../include/footer.php"; 
?>