<?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="smalltable">
<tr style="background-color:#cccccc;"><td><a href="managesubforum.php?do=new">Add Sub-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'];
$pid=$_POST['pid'];
$fsort=$_POST['fsort'];
$description=trim($_POST['description']);
if(strlen($fname) == 0)
{
err_msg("Admin CP","Sub Forum name cannot be blank.","</td></tr></table>");
}
$f=$db->get_row("SELECT parentid FROM b_forums WHERE forumid='$pid'");
$forumid=$db->insert_data("INSERT INTO b_forums(parentid,name,description,numtopics,numposts,sort,lastpostuser,lastposttime,pforum) VALUES('$f->parentid','$fname','$description','0','0','$fsort','0','0','$pid')");
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","Sub-Forum added. <a href=\"managesubforum.php\">Click here</a>","</td></tr></table>");
}
else
{
$forumlist=$db->select("SELECT * FROM b_forums WHERE pforum='0' ORDER BY sort ASC");
if(!$forumlist)
{
err_msg("Admin CP","You dont have forums. First add forums then you may add sub forum.");
}
?>
<form action="managesubforum.php?do=new" method="POST">
<table class="smalltable" style="width:500;">
<tr><td>Sub-Forum Name: <br/><input type="text" name="forumname" value=""/></td></tr>
<tr><td>Parent Forum: <br/><select name="pid">
<?php
foreach($forumlist as $forum)
print "<option value=\"".$forum->forumid."\">".$forum->name."</option>";
?>
</select></td></tr>
<tr><td>Description: <br/><textarea name="description"></textarea></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 f WHERE f.forumid='$fid'");
$forumlist=$db->select("SELECT * FROM b_forums WHERE pforum='0' ORDER BY sort ASC");
if(!$forumlist)
{
err_msg("Admin CP","You dont have forums. First add forums then you may add sub forum.");
}
if(isset($_POST['save']))
{
$fname=trim($_POST['forumname']);
$pid=$_POST['pid'];
$fsort=$_POST['fsort'];
$description=trim($_POST['description']);
if(strlen($fname) == 0)
{
err_msg("Admin CP","Sub Forum name cannot be blank.","</td></tr></table>");
}
$f=$db->get_row("SELECT parentid FROM b_forums WHERE forumid='$pid'");
$db->update_data("UPDATE b_forums SET name='$fname', parentid='$f->parentid', pforum='$pid' , description='$description', sort='$fsort' WHERE forumid='$fid'");
err_msg("Admin CP","Sub-Forum edited. <a href=\"managesubforum.php\">Click here</a> <br/>","</td></tr></table>");
}
else
{
?>
<form action="managesubforum.php?do=edit&fid=<?php echo $fid; ?>" method="POST">
<table class="smalltable" style="width:500;">
<tr><td>Sub-Forum Name:<br/><input type="text" name="forumname" value="<?php echo $forum->name;?>"/> </td> </tr>
<tr><td>Parent Forum Name: <br/><select name="pid">
<?php
foreach($forumlist as $pforum)
{
$sel=""; if($pforum->forumid == $forum->parentid){ $sel="selected=\"selected\""; }
print "<option value=\"".$pforum->forumid."\" ".$sel.">".$pforum->name."</option>";
}
?>
</select> </td> </tr>
<tr><td>Description: <br/><textarea name="description"><?php echo $forum->description;?></textarea></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']))
{
$po=$db->select("SELECT id FROM b_posts WHERE postforum='$fid'");
if($po)
{
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'");
err_msg("Admin CP","Sub-Forum deleted. <a href=\"managesubforum.php\">Click here</a>","</td></tr></table>");
}
else
{
?>
<form action="managesubforum.php?do=delete&fid=<?php echo $fid; ?>" method="POST">
This forum may contain some posts. So please what kind of action you want to perform ?
<br/> <input type="submit" name="yes" value="Delete all with this sub forum"/>
<b>OR</b> <a href="javascript:history.back();">Go Back</a><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> ".$forum->name."</td></tr>";
$subforumlist=$db->select("SELECT * FROM b_forums WHERE parentid='$cat->categoryid' AND pforum='$forum->forumid' ORDER BY sort ASC");
if($subforumlist)
{
foreach($subforumlist as $subforum)
print "<tr style=\"background-color:#dddddd;\"><td> => ".$subforum->name."</td><td width=\"60\"><a href=\"managesubforum.php?do=edit&fid=".$subforum->forumid."\">Edit</a></td><td width=\"60\"><a href=\"managesubforum.php?do=delete&fid=".$subforum->forumid."\">Delete</a></td></tr>";
}
}
}
}
}
?>
</table>
<?php
}
echo '<div class="phdr"><a href="index.php">Admin panel</a> | <a href="managesubforum.php">Kembali</a></div>';
include "../include/footer.php";
?>