Admin Forum functions
| > Module written by Matt Mecham
| > Date started: 1st march 2002
|
| > Module Version Number: 1.0.0
| > DBA Checked: Mon 24th May 2004
+--------------------------------------------------------------------------
*/
if ( ! defined( 'IN_ACP' ) )
{
print "
Incorrect access
You cannot access this file directly. If you have recently upgraded, make sure you upgraded 'admin.php'.";
exit();
}
class ad_forums {
var $base_url;
function auto_run()
{
global $ibforums, $forums, $DB, $std;
//-----------------------------------------
// Kill globals - globals bad, Homer good.
//-----------------------------------------
$tmp_in = array_merge( $_GET, $_POST, $_COOKIE );
foreach ( $tmp_in as $k => $v )
{
unset($$k);
}
$forums->forums_init();
require ROOT_PATH.'sources/admin/admin_forum_functions.php';
$this->forumfunc = new admin_forum_functions();
//-----------------------------------------
switch($ibforums->input['code'])
{
case 'new':
$this->do_form('new');
break;
case 'donew':
$this->do_new();
break;
//-----------------------------------------
case 'edit':
$this->do_form('edit');
break;
case 'doedit':
$this->do_edit();
break;
//-----------------------------------------
case 'pedit':
$this->perm_edit_form();
break;
case 'pdoedit':
$this->perm_do_edit();
break;
//-----------------------------------------
case 'reorder':
$this->reorder_form();
break;
case 'doreorder':
$this->do_reorder();
break;
case 'doreordercat':
$this->do_reorder();
break;
//-----------------------------------------
case 'delete':
$this->delete_form();
break;
case 'dodelete':
$this->do_delete();
break;
//-----------------------------------------
case 'recount':
$this->recount();
break;
//-----------------------------------------
case 'empty':
$this->empty_form();
break;
case 'doempty':
$this->do_empty();
break;
//-----------------------------------------
case 'frules':
$this->show_rules();
break;
case 'dorules':
$this->do_rules();
break;
//-----------------------------------------
case 'skinedit':
$this->skin_edit();
break;
case 'doskinedit':
$this->do_skin_edit();
break;
//-----------------------------------------
default:
$this->show_forums();
break;
}
}
//-----------------------------------------
//
// Edit forum skins
//
//-----------------------------------------
function skin_edit()
{
global $ibforums, $DB, $std, $forums;
if ($ibforums->input['f'] == "")
{
$ibforums->admin->error("Could not determine the forum ID to empty.");
}
$forum = $forums->forum_by_id[ $ibforums->input['f'] ];
//-----------------------------------------
// Make sure we have a legal forum
//-----------------------------------------
if ( ! $forum['id'] )
{
$ibforums->admin->error("Could not resolve that forum ID");
}
if ( ! $forum['skin_id'] )
{
$forum['skin_id'] = -1;
}
//-----------------------------------------
// Get skins..
//-----------------------------------------
$tmp = $ibforums->skin['_setid'];
$ibforums->skin['_setid'] = $forum['skin_id'];
require_once( ROOT_PATH.'sources/classes/class_display.php' );
$display = new display();
$skin_list = $display->_build_skin_list();
$ibforums->skin['_setid'] = $tmp;
//-----------------------------------------
// Do form..
//-----------------------------------------
$ibforums->admin->page_title = "Forum Skin Options";
$ibforums->admin->page_detail = "You may choose to either add or remove a skin set to this forum. The skin choice will override the users choice.";
$ibforums->html .= $ibforums->adskin->start_form( array( 1 => array( 'code' , 'doskinedit'),
2 => array( 'act' , 'forum' ),
3 => array( 'f' , $ibforums->input['f'] ),
) );
$ibforums->adskin->td_header[] = array( " " , "40%" );
$ibforums->adskin->td_header[] = array( " " , "60%" );
$ibforums->html .= $ibforums->adskin->start_table( "Skin choices for forum: {$forum['name']}" );
$ibforums->html .= $ibforums->adskin->add_td_row( array( "Apply which skin to this forum?" ,
""
) );
$ibforums->html .= $ibforums->adskin->add_td_row( array( "Apply to all children of this forum (all sub-forums)" ,
$ibforums->adskin->form_yes_no( 'apply_to_children' )
) );
$ibforums->html .= $ibforums->adskin->end_form("Edit forum skin options");
$ibforums->html .= $ibforums->adskin->end_table();
$ibforums->admin->output();
}
/*-------------------------------------------------------------------------*/
// Complete forum skin edit
/*-------------------------------------------------------------------------*/
function do_skin_edit()
{
global $ibforums, $DB, $std, $forums;
if ($ibforums->input['f'] == "")
{
$ibforums->admin->error("Could not determine the forum ID to apply this skin to.");
}
$forum = $forums->forum_by_id[ $ibforums->input['f'] ];
//-----------------------------------------
// Make sure we have a legal forum
//-----------------------------------------
$DB->do_update( 'forums', array( 'skin_id' => $ibforums->input['fsid'] ), 'id='.$ibforums->input['f'] );
//-----------------------------------------
// Find children?
//-----------------------------------------
if ( $ibforums->input['apply_to_children'] )
{
//-----------------------------------------
// Get children!
//-----------------------------------------
$ids = $forums->forums_get_children( $ibforums->input['f'] );
if ( count( $ids ) )
{
$DB->do_update( 'forums', array( 'skin_id' => $ibforums->input['fsid'] ), 'id IN ('.implode(",",$ids).')' );
}
}
$ibforums->main_msg = "Forum skin updated";
$this->recache_forums();
$forums->forums_init();
$ibforums->input['f'] = "";
$this->show_forums();
}
//-----------------------------------------
//
// Show forum rules
//
//-----------------------------------------
function show_rules()
{
global $ibforums, $DB, $std;
if ($ibforums->input['f'] == "")
{
$ibforums->admin->error("Could not determine the forum ID to empty.");
}
$DB->simple_construct( array( 'select' => 'id, name, show_rules, rules_title, rules_text', 'from' => 'forums', 'where' => "id=".$ibforums->input['f'] ) );
$DB->simple_exec();
//-----------------------------------------
// Make sure we have a legal forum
//-----------------------------------------
if ( ! $DB->get_num_rows() )
{
$ibforums->admin->error("Could not resolve that forum ID");
}
$forum = $DB->fetch_row();
//-----------------------------------------
$ibforums->admin->page_title = "Forum Rules";
$ibforums->admin->page_detail = "You may edit, add, remove or change the state of the forum rules display";
$ibforums->html .= $ibforums->adskin->start_form( array( 1 => array( 'code' , 'dorules'),
2 => array( 'act' , 'forum' ),
3 => array( 'f' , $ibforums->input['f'] ),
) );
$ibforums->adskin->td_header[] = array( " " , "40%" );
$ibforums->adskin->td_header[] = array( " " , "60%" );
$ibforums->html .= $ibforums->adskin->start_table( "Forum Rules set up" );
$ibforums->html .= $ibforums->adskin->add_td_row( array( "Display method" ,
$ibforums->adskin->form_dropdown( "show_rules",
array(
0 => array( '0' , 'Don\'t Show' ),
1 => array( '1' , 'Show Link Only' ),
2 => array( '2' , 'Show full text' )
),
$forum['show_rules']
)
) );
$ibforums->html .= $ibforums->adskin->add_td_row( array( "Rules Title" ,
$ibforums->adskin->form_input("title", $std->txt_stripslashes(str_replace( "'", ''', $forum['rules_title'])))
) );
$ibforums->html .= $ibforums->adskin->add_td_row( array( "Rules Text (HTML Editing Mode)" ,
$ibforums->adskin->form_textarea( "body", $std->txt_stripslashes($forum['rules_text']), 65, 20 )
) );
$ibforums->html .= $ibforums->adskin->end_form("Edit forum rules");
$ibforums->html .= $ibforums->adskin->end_table();
$ibforums->admin->output();
}
function do_rules()
{
global $ibforums, $DB, $std, $HTTP_POST_VARS;
if ($ibforums->input['f'] == "")
{
$ibforums->admin->error("Could not determine the forum ID to empty.");
}
$rules = array(
'rules_title' => $ibforums->admin->make_safe($std->txt_stripslashes($HTTP_POST_VARS['title'])),
'rules_text' => $ibforums->admin->make_safe($std->txt_stripslashes($HTTP_POST_VARS['body'])),
'show_rules' => $ibforums->input['show_rules']
);
$DB->do_update( 'forums', $rules, 'id='.$ibforums->input['f'] );
$this->recache_forums();
$ibforums->admin->done_screen("Forum Rules Updated", "Forum Control", "act=forum" );
}
//-----------------------------------------
//
// RECOUNT FORUM: Recounts topics and posts
//
//-----------------------------------------
function recount($f_override="")
{
global $ibforums, $DB, $std, $forums;
if ($f_override != "")
{
// Internal call, remap
$ibforums->input['f'] = $f_override;
}
require_once( ROOT_PATH.'sources/lib/modfunctions.php' );
$modfunc = new modfunctions();
$modfunc->forum_recount($ibforums->input['f']);
$this->recache_forums();
$ibforums->admin->save_log("Recounted posts in forum '{$forums->forum_by_id[$ibforums->input['f']]['name']}'");
$ibforums->admin->done_screen("Forum Resynchronised", "Forum Control", "act=forum", 'redirect' );
}
//-----------------------------------------
//
// EMPTY FORUM: Removes all topics and posts, etc.
//
//-----------------------------------------
function empty_form()
{
global $ibforums, $DB, $std;
$form_array = array();
if ($ibforums->input['f'] == "")
{
$ibforums->admin->error("Could not determine the forum ID to empty.");
}
$DB->simple_construct( array( 'select' => 'id, name', 'from' => 'forums', 'where' => "id=".$ibforums->input['f'] ) );
$DB->simple_exec();
//-----------------------------------------
// Make sure we have a legal forum
//-----------------------------------------
if ( !$DB->get_num_rows() )
{
$ibforums->admin->error("Could not resolve that forum ID");
}
$forum = $DB->fetch_row();
//-----------------------------------------
$ibforums->admin->page_title = "Empty Forum '{$forum['name']}'";
$ibforums->admin->page_detail = "This WILL DELETE ALL TOPICS, POSTS AND POLLS. The forum itself will not be deleted - please ensure you wish to carry out this action before continuing.";
//-----------------------------------------
$ibforums->html .= $ibforums->adskin->start_form( array( 1 => array( 'code' , 'doempty'),
2 => array( 'act' , 'forum' ),
3 => array( 'f' , $ibforums->input['f'] ),
4 => array( 'name' , $forum['name'] ),
) );
//-----------------------------------------
$ibforums->adskin->td_header[] = array( " " , "40%" );
$ibforums->adskin->td_header[] = array( " " , "60%" );
//-----------------------------------------
$ibforums->html .= $ibforums->adskin->start_table( "Empty Forum '{$forum['name']}" );
$ibforums->html .= $ibforums->adskin->add_td_row( array( "Forum to empty: " , $forum['name'] ) );
$ibforums->html .= $ibforums->adskin->end_form("Empty this forum");
$ibforums->html .= $ibforums->adskin->end_table();
$ibforums->admin->output();
}
//-----------------------------------------
function do_empty()
{
global $ibforums, $DB, $std;
//-----------------------------------------
// Get module
//-----------------------------------------
require_once( ROOT_PATH.'sources/lib/modfunctions.php' );
$modfunc = new modfunctions();
if ($ibforums->input['f'] == "")
{
$ibforums->admin->error("Could not determine the source forum ID.");
}
//-----------------------------------------
// Check to make sure its a valid forum.
//-----------------------------------------
$DB->simple_construct( array( 'select' => 'id, posts, topics', 'from' => 'forums', 'where' => "id=".$ibforums->input['f'] ) );
$DB->simple_exec();
if ( ! $forum = $DB->fetch_row() )
{
$ibforums->admin->error("Could not get the forum details for the forum to empty");
}
$DB->simple_construct( array( 'select' => 'tid', 'from' => 'topics', 'where' => "forum_id=".$ibforums->input['f'] ) );
$outer = $DB->simple_exec();
//-----------------------------------------
// What to do..
//-----------------------------------------
while( $t = $DB->fetch_row($outer) )
{
$modfunc->topic_delete($t['tid']);
}
//-----------------------------------------
// Rebuild stats
//-----------------------------------------
$modfunc->forum_recount($ibforums->input['f']);
$modfunc->stats_recount();
//-----------------------------------------
// Rebuild forum cache
//-----------------------------------------
$this->recache_forums();
$ibforums->admin->save_log("Emptied forum '{$ibforums->input['name']}' of all posts");
$ibforums->admin->done_screen("Forum Emptied", "Forum Control", "act=forum", 'redirect' );
}
//-----------------------------------------
//
// REMOVE FORUM
//
//-----------------------------------------
function delete_form()
{
global $ibforums, $DB, $std, $forums;
$form_array = array();
$ibforums->input['f'] = intval($ibforums->input['f']);
if ( ! $ibforums->input['f'] )
{
$ibforums->admin->error("Could not determine the forum ID to delete.");
}
$DB->simple_construct( array( 'select' => 'id, name', 'from' => 'forums', 'order' => 'position' ) );
$DB->simple_exec();
//-----------------------------------------
// Make sure we have more than 1
// forum..
//-----------------------------------------
if ( $DB->get_num_rows() < 2 )
{
$ibforums->admin->error("Can not remove this forum, please create another before attempting to remove this one");
}
while ( $r = $DB->fetch_row() )
{
if ($r['id'] == $ibforums->input['f'])
{
$name = $r['name'];
continue;
}
}
$form_array = $this->forumfunc->ad_forums_forum_list(1);
//-----------------------------------------
// Count the number of topics
//-----------------------------------------
$posts = $DB->simple_exec_query( array( 'select' => 'count(*) as count', 'from' => 'topics', 'where' => 'forum_id='.$ibforums->input['f'] ) );
//-----------------------------------------
// Count the number of children
//-----------------------------------------
$children = $DB->simple_exec_query( array( 'select' => 'count(*) as count', 'from' => 'forums', 'where' => 'parent_id='.$ibforums->input['f'] ) );
//-----------------------------------------
// Start form
//-----------------------------------------
$ibforums->admin->page_title = "Removing forum '$name'";
$ibforums->admin->page_detail = "Before we remove this forum, if this forum is not empty, we need to determine what to do with any topics and posts you may have left in this forum.";
$ibforums->html .= $ibforums->adskin->start_form( array( 1 => array( 'code' , 'dodelete'),
2 => array( 'act' , 'forum' ),
3 => array( 'f' , $ibforums->input['f'] ),
) );
$ibforums->adskin->td_header[] = array( " " , "40%" );
$ibforums->adskin->td_header[] = array( " " , "60%" );
//-----------------------------------------
// Main form
//-----------------------------------------
$ibforums->html .= $ibforums->adskin->start_table( "Required" );
$ibforums->html .= $ibforums->adskin->add_td_row( array( "Forum to remove: " , $name ) );
if ( $posts['count'] )
{
$ibforums->html .= $ibforums->adskin->add_td_row( array( "Move all existing topics and posts in this forum to which forum?" ,
$ibforums->adskin->form_dropdown( "MOVE_ID", $form_array )
) );
}
if ( $children['count'] )
{
$ibforums->html .= $ibforums->adskin->add_td_row( array( "Move all children forums to which forum?" ,
$ibforums->adskin->form_dropdown( "new_parent_id", $form_array )
) );
}
$ibforums->html .= $ibforums->adskin->end_form( "Remove Forum" );
$ibforums->html .= $ibforums->adskin->end_table();
$ibforums->admin->output();
}
//-----------------------------------------
// PROCESS DELETE
//-----------------------------------------
function do_delete()
{
global $ibforums, $DB, $std;
$ibforums->input['f'] = intval($ibforums->input['f']);
$ibforums->input['MOVE_ID'] = intval($ibforums->input['MOVE_ID']);
$ibforums->input['new_parent_id'] = intval($ibforums->input['new_parent_id']);
$DB->simple_construct( array( 'select' => '*', 'from' => 'forums', 'where' => "id=".$ibforums->input['f'] ) );
$DB->simple_exec();
$forum = $DB->fetch_row();
if ( ! $ibforums->input['f'] )
{
$ibforums->admin->error("Could not determine the source forum ID.");
}
if ( ! $ibforums->input['new_parent_id'] )
{
$ibforums->input['new_parent_id'] = -1;
}
else
{
if ( $ibforums->input['new_parent_id'] == $ibforums->input['f'] )
{
$ibforums->main_msg = "You cannot move children forums to the forum you're removing!";
$this->delete_form();
}
}
require_once( ROOT_PATH.'sources/lib/modfunctions.php' );
$modfunc = new modfunctions();
//-----------------------------------------
// Move stuff
//-----------------------------------------
if ( $ibforums->input['MOVE_ID'] )
{
if ( $ibforums->input['MOVE_ID'] == $ibforums->input['f'] )
{
$ibforums->main_msg = "You cannot move topics into the forum you're removing!";
$this->delete_form();
}
//-----------------------------------------
// Move topics...
//-----------------------------------------
$DB->do_update( 'topics', array( 'forum_id' => $ibforums->input['MOVE_ID'] ), 'forum_id='.$ibforums->input['f'] );
//-----------------------------------------
// Move polls...
//-----------------------------------------
$DB->do_update( 'polls', array( 'forum_id' => $ibforums->input['MOVE_ID'] ), 'forum_id='.$ibforums->input['f'] );
//-----------------------------------------
// Move voters...
//-----------------------------------------
$DB->do_update( 'voters', array( 'forum_id' => $ibforums->input['MOVE_ID'] ), 'forum_id='.$ibforums->input['f'] );
$modfunc->forum_recount( $ibforums->input['MOVE_ID'] );
}
//-----------------------------------------
// Delete the forum
//-----------------------------------------
$DB->simple_exec_query( array( 'delete' => 'forums', 'where' => "id=".$ibforums->input['f'] ) );
//-----------------------------------------
// Delete any moderators, if any..
//-----------------------------------------
$DB->simple_exec_query( array( 'delete' => 'moderators', 'where' => "forum_id=".$ibforums->input['f'] ) );
//-----------------------------------------
// Delete forum subscriptions
//-----------------------------------------
$DB->simple_exec_query( array( 'delete' => 'forum_tracker', 'where' => "forum_id=".$ibforums->input['f'] ) );
//-----------------------------------------
// Update children
//-----------------------------------------
if ( ! $ibforums->input['new_parent_id'] )
{
$ibforums->input['new_parent_id'] = -1;
}
$DB->do_update( 'forums', array( 'parent_id' => $ibforums->input['new_parent_id'] ), "parent_id={$ibforums->input['f']}" );
//-----------------------------------------
// Rebuild forum cache
//-----------------------------------------
$this->recache_forums();
//-----------------------------------------
// Rebuild moderator cache
//-----------------------------------------
require_once( ROOT_PATH.'sources/admin/ad_moderator.php' );
$moderator = new ad_moderator();
$moderator->rebuild_moderator_cache();
$ibforums->admin->save_log("Removed forum '{$forum['name']}'");
$ibforums->admin->done_screen("Forum Removed", "Forum Control", "act=forum", 'redirect' );
}
//-----------------------------------------
// DO NEW FORUM
//-----------------------------------------
function do_new()
{
global $ibforums, $DB, $std;
$ibforums->input['name'] = trim($ibforums->input['name']);
if ($ibforums->input['name'] == "")
{
$ibforums->admin->error("You must enter a forum title");
}
// Get the new forum id. We could use auto_incrememnt, but we need the ID to use as the default
// forum position...
$DB->simple_construct( array( 'select' => 'MAX(id) as top_forum', 'from' => 'forums' ) );
$DB->simple_exec();
$row = $DB->fetch_row();
if ($row['top_forum'] < 1) $row['top_forum'] = 0;
$row['top_forum']++;
$perms = $ibforums->admin->compile_forum_perms();
$perm_array = addslashes(serialize(array(
'start_perms' => $perms['START'],
'reply_perms' => $perms['REPLY'],
'read_perms' => $perms['READ'],
'upload_perms' => $perms['UPLOAD'],
'show_perms' => $perms['SHOW']
) ) );
$DB->do_insert( 'forums', array (
'id' => $row['top_forum'],
'position' => $row['top_forum'],
'topics' => 0,
'posts' => 0,
'last_post' => "",
'last_poster_id' => "",
'last_poster_name' => "",
'name' => $ibforums->input['name'],
'description' => $std->my_nl2br( $std->txt_stripslashes($_POST['description']) ),
'use_ibc' => $ibforums->input['use_ibc'],
'use_html' => $ibforums->input['use_html'],
'status' => $ibforums->input['status'],
'password' => $ibforums->input['password'],
'last_id' => "",
'last_title' => "",
'sort_key' => $ibforums->input['sort_key'],
'sort_order' => $ibforums->input['sort_order'],
'prune' => $ibforums->input['prune'],
'show_rules' => 0,
'preview_posts' => $ibforums->input['preview_posts'],
'allow_poll' => $ibforums->input['allow_poll'],
'allow_pollbump' => $ibforums->input['allow_pollbump'],
'inc_postcount' => $ibforums->input['inc_postcount'],
'parent_id' => $ibforums->input['parent_id'],
'sub_can_post' => $ibforums->input['sub_can_post'],
'quick_reply' => $ibforums->input['quick_reply'],
'redirect_on' => $ibforums->input['redirect_on'],
'redirect_hits' => $ibforums->input['redirect_hits'],
'redirect_url' => $ibforums->input['redirect_url'],
'redirect_loc' => $ibforums->input['redirect_loc'],
'notify_modq_emails' => $ibforums->input['notify_modq_emails'],
'permission_array' => $perm_array,
'permission_showtopic' => $ibforums->input['permission_showtopic'],
'permission_custom_error' => $std->my_nl2br( $std->txt_stripslashes($_POST['permission_custom_error']) ),
) );
$this->recache_forums();
$ibforums->admin->save_log("Forum '{$ibforums->input['name']}' created");
$ibforums->admin->done_screen("Forum {$ibforums->input['name']} created", "Forum Control", "act=forum", 'redirect' );
}
//-----------------------------------------
//
// EDIT FORUM
//
//-----------------------------------------
function do_form($type='edit')
{
global $ibforums, $DB, $std, $forums;
$ibforums->admin->page_detail = "This section will allow you to add or edit an existing forum. If you wish to adjust the forum permissions (who has the ability to
start, reply and read topics) click on 'Edit Permissions on the Forums and Categories overview.";
if ( $type == 'edit' )
{
if ($ibforums->input['f'] == "")
{
$ibforums->admin->error("You didn't choose a forum to edit, duh!");
}
$this->forumfunc->exclude_from_list = $ibforums->input['f'];
$forum = $DB->simple_exec_query( array( 'select' => '*', 'from' => 'forums', 'where' => 'id='.$ibforums->input['f'] ) );
if ($forum['id'] == "")
{
$ibforums->admin->error("Could not retrieve the forum data based on ID {$ibforums->input['f']}");
}
$title = "Editing Forum: {$forum['name']}";
$button = "Edit Forum";
$code = "doedit";
$basic_title = "