Made moving/deleting cats/forums possible

git-svn-id: file:///svn/phpbb/trunk@930 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Bart van Bragt 2001-08-23 22:31:44 +00:00
parent 4d04c8bad5
commit 8723edc8c8
4 changed files with 273 additions and 54 deletions

View file

@ -39,12 +39,87 @@ function check_forum_name($forumname)
{ {
message_die(GENERAL_ERROR, "Couldn't get list of Categories", "", __LINE__, __FILE__, $sql); message_die(GENERAL_ERROR, "Couldn't get list of Categories", "", __LINE__, __FILE__, $sql);
} }
if ($db->sql_num_rows($result) > 0) if ($db->sql_numrows($result) > 0)
{ {
message_die(GENERAL_ERROR, "A forum with that name already exists", "", __LINE__, __FILE__, $sql); message_die(GENERAL_ERROR, "A forum with that name already exists", "", __LINE__, __FILE__, $sql);
} }
} }
function get_info($mode, $id)
{
global $db;
switch($mode)
{
case 'category':
$table = CATEGORIES_TABLE;
$idfield = 'cat_id';
$namefield = 'cat_title';
break;
case 'forum':
$table = FORUMS_TABLE;
$idfield = 'forum_id';
$namefield = 'forum_name';
break;
default:
message_die(GENERAL_ERROR, "Wrong mode for generating select list", "", __LINE__, __FILE__);
}
$sql = " SELECT *
FROM $table
WHERE $idfield = $id";
if( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Couldn't get Forum/Category information", "", __LINE__, __FILE__, $sql);
}
if( $db->sql_numrows($result) != 1 )
{
message_die(GENERAL_ERROR, "Forum/Category doesn't exist or multiple forums/categories with ID $id", "", __LINE__, __FILE__);
}
return $db->sql_fetchrow($result);
}
function get_list($mode, $id, $select)
{
global $db;
switch($mode)
{
case 'category':
$table = CATEGORIES_TABLE;
$idfield = 'cat_id';
$namefield = 'cat_title';
break;
case 'forum':
$table = FORUMS_TABLE;
$idfield = 'forum_id';
$namefield = 'forum_name';
break;
default:
message_die(GENERAL_ERROR, "Wrong mode for generating select list", "", __LINE__, __FILE__);
}
$sql = "SELECT * FROM $table";
if( $select == FALSE)
{
$sql .= " WHERE $idfield != '$id'";
}
if( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Couldn't get list of Categories/Forums", "", __LINE__, __FILE__, $sql);
}
$cat_list = "";
while( $row = $db->sql_fetchrow($result) )
{
$s = "";
if ($row[$idfield] == $id)
{
$s = " SELECTED";
}
$catlist .= "<OPTION VALUE=\"$row[$idfield]\"$s>$row[$namefield]</OPTION>\n";
}
return($catlist);
}
// //
// Include required files, get $phpEx and check permissions // Include required files, get $phpEx and check permissions
// //
@ -67,6 +142,10 @@ if(isset($mode)) // Are we supposed to do something?
{ {
switch($mode) switch($mode)
{ {
case 'forum_sync':
sync('forum', $HTTP_GET_VARS['forum_id']);
$show_index = TRUE;
break;
case 'createforum': // Create a forum in the DB case 'createforum': // Create a forum in the DB
$sql = "SELECT $sql = "SELECT
max(forum_order) as max_order max(forum_order) as max_order
@ -147,22 +226,8 @@ if(isset($mode)) // Are we supposed to do something?
$buttonvalue = 'Change'; $buttonvalue = 'Change';
$forum_id = $HTTP_GET_VARS['forum_id']; $forum_id = $HTTP_GET_VARS['forum_id'];
$sql = " SELECT
forum_name, $row = get_info('forum', $forum_id);
cat_id,
forum_desc,
forum_status
FROM " . FORUMS_TABLE . "
WHERE forum_id = $forum_id";
if( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Couldn't get Forum information", "", __LINE__, __FILE__, $sql);
}
if( $db->sql_numrows($result) != 1 )
{
message_die(GENERAL_ERROR, "Forum doesn't exist or multiple forums with ID $forum_id", "", __LINE__, __FILE__);
}
$row = $db->sql_fetchrow($result);
$forumname = $row['forum_name']; $forumname = $row['forum_name'];
$cat_id = $row['cat_id']; $cat_id = $row['cat_id'];
$forumdesc = $row['forum_desc']; $forumdesc = $row['forum_desc'];
@ -180,22 +245,8 @@ if(isset($mode)) // Are we supposed to do something?
$forum_id = ''; $forum_id = '';
} }
$catlist = get_list('category', $cat_id, TRUE);
$sql = "SELECT * FROM " . CATEGORIES_TABLE;
if( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Couldn't get list of Categories", "", __LINE__, __FILE__, $sql);
}
$cat_list = "";
while( $row = $db->sql_fetchrow($result) )
{
$s = "";
if ($row['cat_id'] == $cat_id)
{
$s = " SELECTED";
}
$catlist .= "<OPTION VALUE=\"$row[cat_id]\"$s>$row[cat_title]</OPTION>\n";
}
$forumstatus == FORUM_LOCKED ? $forumlocked = "selected" : $forumunlocked = "selected"; $forumstatus == FORUM_LOCKED ? $forumlocked = "selected" : $forumunlocked = "selected";
$statuslist = "<OPTION VALUE=\"".FORUM_UNLOCKED."\" $forumunlocked>Unlocked</OPTION>\n"; $statuslist = "<OPTION VALUE=\"".FORUM_UNLOCKED."\" $forumunlocked>Unlocked</OPTION>\n";
$statuslist .= "<OPTION VALUE=\"".FORUM_LOCKED."\" $forumlocked>Locked</OPTION>\n"; $statuslist .= "<OPTION VALUE=\"".FORUM_LOCKED."\" $forumlocked>Locked</OPTION>\n";
@ -221,18 +272,7 @@ if(isset($mode)) // Are we supposed to do something?
$buttonvalue = 'Change'; $buttonvalue = 'Change';
$cat_id = $HTTP_GET_VARS['cat_id']; $cat_id = $HTTP_GET_VARS['cat_id'];
$sql = " SELECT * $row = get_info('category', $catid);
FROM " . CATEGORIES_TABLE . "
WHERE cat_id = $cat_id";
if( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Couldn't get Category information", "", __LINE__, __FILE__, $sql);
}
if( $db->sql_numrows($result) != 1 )
{
message_die(GENERAL_ERROR, "Category doesn't exist or multiple categories with ID $cat_id", "", __LINE__, __FILE__);
}
$row = $db->sql_fetchrow($result);
$cat_title = $row['cat_title']; $cat_title = $row['cat_title'];
$template->set_filenames(array( $template->set_filenames(array(
@ -258,6 +298,133 @@ if(isset($mode)) // Are we supposed to do something?
print "Modforum: ". $HTTP_POST_VARS['forumname']." sql= <pre>$sql</pre>"; print "Modforum: ". $HTTP_POST_VARS['forumname']." sql= <pre>$sql</pre>";
$show_index = TRUE; $show_index = TRUE;
break; break;
case 'movedelforum':
$from_id = $HTTP_POST_VARS['from_id'];
$to_id = $HTTP_POST_VARS['to_id'];
$delete_old = $HTTP_POST_VARS['delete_old'];
print "move '$from_id' to '$to_id'";
$sql = "SELECT * FROM ".FORUMS_TABLE." WHERE forum_id IN ($from_id, $to_id)";
if( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Couldn't verify existence of forums", "", __LINE__, __FILE__, $sql);
}
if($db->sql_numrows($result) != 2)
{
message_die(GENERAL_ERROR, "Ambiguous forum ID's", "", __LINE__, __FILE__);
}
// Either delete or move all posts in a forum
if($delete_old == 1)
{
include($phpbb_root_path . "/include/prune.$phpEx");
prune($from_id, FALSE); // Delete everything from forum
}
else
{
$sql = "UPDATE ".TOPICS_TABLE." SET
forum_id = '$to_id'
WHERE forum_id = '$from_id'";
if( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Couldn't move topics to other forum", "", __LINE__, __FILE__, $sql);
}
$sql = "UPDATE ".POSTS_TABLE." SET
forum_id = '$to_id'
WHERE forum_id = '$from_id'";
if( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Couldn't move posts to other forum", "", __LINE__, __FILE__, $sql);
}
sync('forum', $to_id);
}
$sql = "DELETE FROM ".FORUMS_TABLE."
WHERE forum_id = '$from_id'";
if( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Couldn't delete forum", "", __LINE__, __FILE__, $sql);
}
$show_index = TRUE;
break;
case 'movedelcat':
$from_id = $HTTP_POST_VARS['from_id'];
$to_id = $HTTP_POST_VARS['to_id'];
print "move '$from_id' to '$to_id'";
$sql = "SELECT * FROM ".CATEGORIES_TABLE." WHERE cat_id IN ($from_id, $to_id)";
if( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Couldn't verify existence of categories", "", __LINE__, __FILE__, $sql);
}
if($db->sql_numrows($result) != 2)
{
message_die(GENERAL_ERROR, "Ambiguous category ID's", "", __LINE__, __FILE__);
}
$sql = "UPDATE ".FORUMS_TABLE." SET
cat_id = '$to_id'
WHERE cat_id = '$from_id'";
if( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Couldn't move forums to other category", "", __LINE__, __FILE__, $sql);
}
$sql = "DELETE FROM ".CATEGORIES_TABLE."
WHERE cat_id = '$from_id'";
if( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Couldn't delete category", "", __LINE__, __FILE__, $sql);
}
$show_index = TRUE;
break;
case 'deletecat':
print "Deletecat";
$cat_id = $HTTP_GET_VARS['cat_id'];
$to_ids = get_list('category', $cat_id, FALSE);
$buttonvalue = "Move&Delete";
$newmode = 'movedelcat';
$catinfo = get_info('category', $cat_id);
$name = $catinfo['cat_title'];
$template->set_filenames(array(
"body" => "admin/forum_delete_body.tpl")
);
$template->assign_vars(array(
'NAME' => $name,
'S_FORUM_ACTION' => $PHP_SELF,
'S_FROM_ID' => $cat_id,
'S_TO_IDS' => $to_ids,
'S_NEWMODE' => $newmode,
'BUTTONVALUE' => $buttonvalue)
);
$template->pparse("body");
break;
case 'deleteforum':
print 'Deleteforum';
$forum_id = $HTTP_GET_VARS['forum_id'];
$to_ids = get_list('forum', $forum_id, FALSE);
$buttonvalue = "Move&Delete";
$newmode = 'movedelforum';
$foruminfo = get_info('forum', $forum_id);
$name = $foruminfo['forum_name'];
$template->set_filenames(array(
"body" => "admin/forum_delete_body.tpl")
);
$template->assign_vars(array(
'NAME' => $name,
'S_FORUM_ACTION' => $PHP_SELF,
'S_FROM_ID' => $forum_id,
'S_TO_IDS' => $to_ids,
'S_NEWMODE' => $newmode,
'BUTTONVALUE' => $buttonvalue)
);
$template->pparse("body");
break;
case 'cat_order': case 'cat_order':
case 'forum_order': case 'forum_order':
message_die(GENERAL_ERROR, "Sorry, not implemented yet"); message_die(GENERAL_ERROR, "Sorry, not implemented yet");
@ -325,7 +492,8 @@ if($total_categories = $db->sql_numrows($q_categories))
$template->assign_block_vars("catrow", array( $template->assign_block_vars("catrow", array(
"CAT_ID" => $cat_id, "CAT_ID" => $cat_id,
"CAT_DESC" => stripslashes($category_rows[$i]['cat_title']), "CAT_DESC" => stripslashes($category_rows[$i]['cat_title']),
"CAT_EDIT" => "<a href='$PHPSELF?mode=editcat&cat_id=$cat_id'>Edit/Delete</a>", "CAT_EDIT" => "<a href='$PHPSELF?mode=editcat&cat_id=$cat_id'>Edit</a>",
"CAT_DELETE" => "<a href='$PHPSELF?mode=deletecat&cat_id=$cat_id'>Delete</a>",
"CAT_UP" => "<a href='$PHPSELF?mode=cat_order&pos=1&cat_id=$cat_id'>Move up</a>", "CAT_UP" => "<a href='$PHPSELF?mode=cat_order&pos=1&cat_id=$cat_id'>Move up</a>",
"CAT_DOWN" => "<a href='$PHPSELF?mode=cat_order&pos=-1&forum_id=$cat_id'>Move down</a>", "CAT_DOWN" => "<a href='$PHPSELF?mode=cat_order&pos=-1&forum_id=$cat_id'>Move down</a>",
"U_VIEWCAT" => append_sid("index.$phpEx?viewcat=$cat_id"), "U_VIEWCAT" => append_sid("index.$phpEx?viewcat=$cat_id"),
@ -348,10 +516,14 @@ if($total_categories = $db->sql_numrows($q_categories))
"FORUM_NAME" => stripslashes($forum_rows[$j]['forum_name']), "FORUM_NAME" => stripslashes($forum_rows[$j]['forum_name']),
"FORUM_DESC" => stripslashes($forum_rows[$j]['forum_desc']), "FORUM_DESC" => stripslashes($forum_rows[$j]['forum_desc']),
"ROW_COLOR" => $row_color, "ROW_COLOR" => $row_color,
"U_VIEWFORUM" => append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id&" . $forum_rows[$j]['forum_posts']), "NUM_TOPICS" => $forum_rows[$j]['forum_topics'],
"FORUM_EDIT" => "<a href='$PHPSELF?mode=editforum&forum_id=$forum_id'>Edit/Delete</a>", "NUM_POSTS" => $forum_rows[$j]['forum_posts'],
"FORUM_UP" => "<a href='$PHPSELF?forum_mode=order&pos=1&forum_id=$forum_id'>Move up</a>", "U_VIEWFORUM" => append_sid($phpbb_root_path."viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id&" . $forum_rows[$j]['forum_posts']),
"FORUM_DOWN" => "<a href='$PHPSELF?mode=forum_order&pos=-1&forum_id=$forum_id'>Move down</a>") "FORUM_EDIT" => "<a href='".append_sid("$PHPSELF?mode=editforum&forum_id=$forum_id")."'>Edit</a>",
"FORUM_DELETE" => "<a href='".append_sid("$PHPSELF?mode=deleteforum&forum_id=$forum_id")."'>Delete</a>",
"FORUM_UP" => "<a href='".append_sid("$PHPSELF?forum_mode=order&pos=1&forum_id=$forum_id")."'>Move up</a>",
"FORUM_DOWN" => "<a href='".append_sid("$PHPSELF?mode=forum_order&pos=-1&forum_id=$forum_id")."'>Move down</a>",
"FORUM_SYNC" => "<a href='".append_sid("$PHPSELF?mode=forum_sync&forum_id=$forum_id")."'>Sync</a>")
); );
} // for ... forums } // for ... forums
$template->assign_block_vars("catrow.forumrow", array( $template->assign_block_vars("catrow.forumrow", array(

View file

@ -0,0 +1,40 @@
<br clear="all" />
<h1>Delete</h1>
<p>The form below will allow you to delete a forum/category and decide where you want to put all topics/forums inside that forum/category.</p>
<form action="{S_FORUM_ACTION}" method="POST">
<table width="99%" cellpadding="1" cellspacing="0" border="0" align="center">
<tr>
<td class="tablebg" width="100%"><table width="100%" cellpadding="4" cellspacing="1" border="0">
<tr>
<td class="cat" colspan="2"><span class="cattitle">Delete</span></td>
</tr>
<tr>
<td class="row1">Name:</td>
<td class="row2"><span class="row1">{NAME}</span></td>
</tr>
<tr>
<td class="row1">Move everything to:</td>
<td class="row2">
<select name="to_id">
{S_TO_IDS}
</select>
</td>
</tr>
<tr>
<td class="row2" colspan="2" align="center">
<input type="hidden" name="mode" value="{S_NEWMODE}">
<input type="hidden" name="from_id" value="{S_FROM_ID}">
<input type="submit" name="submit" value="{BUTTONVALUE}">
</td>
</tr>
</table></td>
</tr>
</table>
</form>
<br clear="all">

View file

@ -18,7 +18,7 @@
</tr> </tr>
<tr> <tr>
<td class="row1">Description:</td> <td class="row1">Description:</td>
<td class="row2"><textarea ROWS="15" COLS="45" WRAP="VIRTUAL" name="forumdesc">{DESCRIPTION}</TEXTAREA></td> <td class="row2"><textarea ROWS="5" COLS="45" WRAP="VIRTUAL" name="forumdesc">{DESCRIPTION}</TEXTAREA></td>
</tr> </tr>
<tr> <tr>
<td class="row1">Category:</td> <td class="row1">Category:</td>

View file

@ -7,17 +7,24 @@
<td class="tablebg"><table width="100%" cellpadding="3" cellspacing="1" border="0"> <td class="tablebg"><table width="100%" cellpadding="3" cellspacing="1" border="0">
<!-- BEGIN catrow --> <!-- BEGIN catrow -->
<tr> <tr>
<td class="cat" colspan="6"><span class="cattitle"><b><a href="{catrow.U_VIEWCAT}">{catrow.CAT_DESC}</a></b></span>{catrow.S_ADDCAT}</span></td> <td class="cat" colspan="4"><span class="cattitle"><b><a href="{catrow.U_VIEWCAT}">{catrow.CAT_DESC}</a></b></span>{catrow.S_ADDCAT}</span></td>
<td class="cat" align="center" valign="middle"><span class="gen">{catrow.CAT_EDIT}</span></td>
<td class="cat" align="center" valign="middle"><span class="gen">{catrow.CAT_DELETE}</span></td>
<td class="cat" align="center" valign="middle"><span class="gen">{catrow.CAT_UP} {catrow.CAT_DOWN}</span></td>
<td class="cat" align="center" valign="middle"><span class="gen">&nbsp</span></td>
</tr>{catrow.S_ADDCAT_ENDFORM} </tr>{catrow.S_ADDCAT_ENDFORM}
<!-- BEGIN forumrow --> <!-- BEGIN forumrow -->
<tr> <tr>
<td class="row1" align="center" valign="middle">{catrow.forumrow.FOLDER}</td> <td class="row1" align="center" valign="middle">{catrow.forumrow.FOLDER}</td>
<td class="row2"><span class="gen">{catrow.forumrow.S_ADDFORUM}{catrow.forumrow.S_NEWFORUM}<a href="{catrow.forumrow.U_VIEWFORUM}" target="_new">{catrow.forumrow.FORUM_NAME}</a></span><br><span class="gensmall">{catrow.forumrow.FORUM_DESC}</span></td> <td class="row2"><span class="gen">{catrow.forumrow.S_ADDFORUM}{catrow.forumrow.S_NEWFORUM}<a href="{catrow.forumrow.U_VIEWFORUM}" target="_new">{catrow.forumrow.FORUM_NAME}</a></span><br><span class="gensmall">{catrow.forumrow.FORUM_DESC}</span></td>
{catrow.forumrow.S_ADDFORUM_ENDFORM} {catrow.forumrow.S_ADDFORUM_ENDFORM}
<td class="row1" align="center" valign="middle"><span class="gen">{catrow.forumrow.NUM_TOPICS}</span></td>
<td class="row2" align="center" valign="middle"><span class="gen">{catrow.forumrow.NUM_POSTS}</span></td>
<td class="row1" align="center" valign="middle"><span class="gen">{catrow.forumrow.FORUM_EDIT}</span></td> <td class="row1" align="center" valign="middle"><span class="gen">{catrow.forumrow.FORUM_EDIT}</span></td>
<td class="row2" align="center" valign="middle"><span class="gen">{catrow.forumrow.FORUM_UP} {catrow.forumrow.FORUM_DOWN}</span></td> <td class="row2" align="center" valign="middle"><span class="gen">{catrow.forumrow.FORUM_DELETE}</span></td>
<td class="row1" align="center" valign="middle"><span class="gensmall">{catrow.forumrow.LAST_POST}</span></td> <td class="row1" align="center" valign="middle"><span class="gen">{catrow.forumrow.FORUM_UP} {catrow.forumrow.FORUM_DOWN}</span></td>
<td class="row2" align="center" valign="middle"><span class="gensmall">{catrow.forumrow.MODERATORS}</span></td></tr> <td class="row2" align="center" valign="middle"><span class="gen">{catrow.forumrow.FORUM_SYNC}</span></td>
</tr> </tr>
<!-- END forumrow --> <!-- END forumrow -->
<!-- END catrow --> <!-- END catrow -->