<?php

/*
+--------------------------------------------------------------------------
|   Invision Power Board v1.1
|   ========================================
|   by Matthew Mecham
|   (c) 2001,2002 Invision Power Services
|   http://www.ibforums.com
|   ========================================
|   Web: http://www.ibforums.com
|   Email: phpboards@ibforums.com
|   Licence Info: phpib-licence@ibforums.com
+---------------------------------------------------------------------------
|
|   > Admin Forum functions
|   > Module written by Matt Mecham
|   > Date started: 1st march 2002
|
|	> Module Version Number: 1.0.0
+--------------------------------------------------------------------------
*/





$idx = new ad_forums();


class ad_forums {

	var $base_url;

	function ad_forums() {
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
		
		//---------------------------------------
		// Kill globals - globals bad, Homer good.
		//---------------------------------------
		
		$tmp_in = array_merge( $_GET, $_POST, $_COOKIE );
		
		foreach ( $tmp_in as $k => $v )
		{
			unset($$k);
		}

		switch($IN['code'])
		{
			case 'new':
				$this->new_form();
				break;
			case 'donew':
				$this->do_new();
				break;
			//+-------------------------
			case 'edit':
				$this->edit_form();
				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 '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 'newsp':
				$this->new_form();
				break;
			case 'donewsplash':
				$this->donew_splash();
				break;
			case 'donewsub':
				$this->add_sub();
				break;
			//+-------------------------
			case 'subedit':
				$this->subedit();
				break;
			case 'doeditsub':
				$this->doeditsub();
				break;
				
			case 'subdelete':
				$this->subdeleteform();
				break;
			case 'dosubdelete':
				$this->dosubdelete();
				break;
			//+-------------------------
			case 'skinedit':
				$this->skin_edit();
				break;
			case 'doskinedit':
				$this->do_skin_edit();
				break;
			//+-------------------------	
			default:
				$this->new_form();
				break;
		}
		
	}
	
	
	//+---------------------------------------------------------------------------------
	//
	// Edit forum skins
	//
	//+---------------------------------------------------------------------------------
	
	function skin_edit() {
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
		
		if ($IN['f'] == "")
		{
			$ADMIN->error("没有找到需要清空的论坛栏目ID。");
		}
		
		$DB->query("SELECT id, name, skin_id FROM ibf_forums WHERE id='".$IN['f']."'");
		
		//+-------------------------------
		// Make sure we have a legal forum
		//+-------------------------------
		
		if ( !$DB->get_num_rows() )
		{
			$ADMIN->error("没有找到论坛栏目ID。");
		}
		
		$forum = $DB->fetch_row();
		
		if ( ($forum['skin_id'] == "") or ($forum['skin_id'] == -1) )
		{
			$forum['skin_id'] = 'n';
		}
		
		$form_array = array();
		
		$form_array[] = array( 'n', '-- 系统默认设置 --' );
		
		$DB->query("SELECT sid, sname FROM ibf_skins");
		
		while ($r = $DB->fetch_row())
		{
			$form_array[] = array( $r['sid'], $r['sname'] );
		}
		
		
		//+-------------------------------
		
		$ADMIN->page_title = "主题界面选项";
		$ADMIN->page_detail  = "你可以从下面选择一种你喜欢的论坛主题界面，所有论坛用户将统一使用你设置的主题界面。";
		
		$ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'doskinedit'),
												  2 => array( 'act'   , 'forum'  ),
												  3 => array( 'f'     , $IN['f'] ),
											) );
		
		
		$SKIN->td_header[] = array( "&nbsp;"   , "40%" );
		$SKIN->td_header[] = array( "&nbsp;"   , "60%" );
		
		$ADMIN->html .= $SKIN->start_table( "主题界面选项：{$forum['name']}" );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>选择主题界面：</b>" ,
												  $SKIN->form_dropdown("fsid", $form_array, $forum['skin_id'] )
									     )      );
									     
		$ADMIN->html .= $SKIN->end_form("编辑论坛主题界面选项");
										 
		$ADMIN->html .= $SKIN->end_table();
		
		$ADMIN->output();
		
	}
	
	function do_skin_edit() {
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
		
		if ($IN['f'] == "")
		{
			$ADMIN->error("没有找到需要清空的论坛栏目ID。");
		}
		
		$DB->query("SELECT id, name, skin_id FROM ibf_forums WHERE id='".$IN['f']."'");
		
		$forum = $DB->fetch_row();
		
		//+-------------------------------
		// Make sure we have a legal forum
		//+-------------------------------
		
		if ( !$DB->get_num_rows() )
		{
			$ADMIN->error("没有找到论坛栏目ID。");
		}
		
		if ($IN['fsid'] == 'n')
		{
			$DB->query("UPDATE ibf_forums SET skin_id='-1' WHERE id='".$IN['f']."'");
			$ADMIN->rebuild_config( array( 'forum_skin_'.$IN['f'] => "" ) );
		}
		else
		{
			$DB->query("UPDATE ibf_forums SET skin_id='".$IN['fsid']."' WHERE id='".$IN['f']."'");
			$ADMIN->rebuild_config( array( 'forum_skin_'.$IN['f'] => $IN['fsid'] ) );
		}
		
		$ADMIN->save_log("编辑论坛主题界面设置：'{$forum['name']}'");
		
		$std->boink_it($ADMIN->base_url."&act=cat" );
		exit();
		
	}
	
	//+---------------------------------------------------------------------------------
	//
	// Sub Cat Delete Form
	//
	//+---------------------------------------------------------------------------------
	
	function subdeleteform() {
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
		
		$form_array = array();
		
		if ($IN['f'] == "")
		{
			$ADMIN->error("没有找到需要删除的论坛栏目ID。");
		}
		
		$cats = array();
		
		$name = "";
		
		$last_cat_id = -1;
		
		$DB->query("SELECT c.id, c.name, f.id as forum_id, f.subwrap, f.name as forum_name, f.parent_id, f.category FROM ibf_categories c, ibf_forums f WHERE c.id > 0 ORDER BY c.position, f.position");
		
		while ( $r = $DB->fetch_row() )
		{
		
			if ($last_cat_id != $r['id'])
			{
				$cats[] = array( "c_".$r['id'] , "论坛分类：".$r['name'] );
				
				$last_cat_id = $r['id'];
			}
			
			if ($r['parent_id'] > 0)
			{
				continue;
			}
			
			if ($r['forum_id'] == $IN['f'])
			{
				$name = $r['forum_name'];
				continue;
			}
			
			if ($r['subwrap'] != 1)
			{
				continue;
			}
			
			if ($r['category'] == $r['id'])
			{
			
				$cats[] = array( "f_".$r['forum_id'], "论坛子分类：".$r['forum_name'] );
			}
			
		}
		
		//+-------------------------------
		// Make sure we have more than 1
		// forum..
		//+-------------------------------
		
		if ($DB->get_num_rows() < 2)
		{
			$ADMIN->error("无法删除这个论坛栏目，请尝试建立其它论坛栏目或论坛子分类");
		}
		
		//+-------------------------------
		
		$ADMIN->page_title = "删除论坛子分类：'$name'";
		
		$ADMIN->page_detail = "删除论坛栏目前，我们需要决定如何处理论坛栏目下的论坛子分类。";
		
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'dosubdelete'),
												  2 => array( 'act'   , 'forum'     ),
												  3 => array( 'f'     , $IN['f']  ),
												  4 => array( 'name'  , $name ),
											) );
		
		//+-------------------------------
		
		$SKIN->td_header[] = array( "&nbsp;"  , "40%" );
		$SKIN->td_header[] = array( "&nbsp;"  , "60%" );
		
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->start_table( "必须进行选择或填写" );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>删除论坛栏目：</b>" , $name )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>将此论坛栏目下存在的所有论坛子分类移动到：</b>" ,
												  $SKIN->form_dropdown( "MOVE_ID", $cats )
									     )      );
									     
		$ADMIN->html .= $SKIN->end_form("移动论坛子分类并删除论坛栏目");
										 
		$ADMIN->html .= $SKIN->end_table();
		
		$ADMIN->output();
		
		
	}
	
	
	function dosubdelete() {
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
		
		if ($IN['f'] == "")
		{
			$ADMIN->error("没有找到论坛栏目ID信息。");
		}
		
		if ($IN['MOVE_ID'] == "")
		{
			$ADMIN->error("没有找到论坛栏目ID文件。");
		}
		
		$cat    = -1;
		$parent = -1;
		
		if ( preg_match( "/^c_(\d+)$/", $IN['MOVE_ID'], $match ) )
		{
			$cat = $match[1];
		}
		else
		{
			$parent = preg_replace( "/^f_/", "", $IN['MOVE_ID'] );
		}
		
		// Move sub forums...
		
		$DB->query("UPDATE ibf_forums SET category='$cat', parent_id='$parent' WHERE parent_id='".$IN['f']."'");
		
		$DB->query("DELETE FROM ibf_forums WHERE id='".$IN['f']."'");
		
		// Delete any moderators, if any..
		
		$DB->query("DELETE FROM ibf_moderators WHERE forum_id='".$IN['f']."'");
		
		$ADMIN->save_log("删除论坛子分类：'{$IN['name']}'");
		
		$ADMIN->done_screen("论坛栏目已经删除", "论坛栏目控制面板", "act=cat" );
		
	}
	
	//+---------------------------------------------------------------------------------
	//
	// Sub Cat Edit Form
	//
	//+---------------------------------------------------------------------------------
	
	
	function subedit() {
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_GET_VARS;
		
		
		$cats = array();
		
		$last_cat_id = -1;
		
		$DB->query("SELECT * from ibf_categories WHERE id > 0 ORDER BY position");
		
		while ( $r = $DB->fetch_row() )
		{
			$cats[] = array( $r['id'] , "论坛分类：".$r['name'] );
		}
		
		$DB->query("SELECT * from ibf_forums WHERE subwrap='1' AND id='".$IN['f']."'");
		
		if (! $forum = $DB->fetch_row() )
		{
			$ADMIN->error("没有找到论坛子分类数据");
		}
		
		if ($forum['password'] == '-1')
		{
			$forum['password'] = "";
		}
		
		$ADMIN->page_title = "编辑论坛子分类";
		
		$ADMIN->page_detail = "请在下面编辑你的论坛子分类信息。";
		
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'doeditsub'  ),
												  2 => array( 'act'   , 'forum'  ),
												  3 => array( 'f'     , $IN['f'] ),
											) );
		
		//+-------------------------------
		
		$SKIN->td_header[] = array( "&nbsp;"  , "40%" );
		$SKIN->td_header[] = array( "&nbsp;"  , "60%" );
		
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->start_table( "论坛栏目设置" );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>添加到哪个论坛分类？</b><br>" ,
												  $SKIN->form_dropdown("CATEGORY", $cats, $forum['category'])
									     )      );
									     
		$ADMIN->html .= $SKIN->end_table();
		
		//+-------------------------------
		
		$SKIN->td_header[] = array( "&nbsp;"  , "40%" );
		$SKIN->td_header[] = array( "&nbsp;"  , "60%" );
		
		$ADMIN->html .= $SKIN->start_table( "添加论坛栏目信息" );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>论坛栏目名称：</b>" ,
												  $SKIN->form_input("name", $forum['name'])
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>论坛栏目叙述：</b>" ,
												  $SKIN->form_textarea("desc", $forum['description'])
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>论坛栏目状态：</b>" ,
												  $SKIN->form_dropdown( "FORUM_STATUS",
																			array( 
																					0 => array( 1, '立即启用' ),
																					1 => array( 0, '只读文档'  ),
																				 ),
												  						$forum['status']
												  					  )
									     )      );
									     
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->end_table();
		
		//+-------------------------------
		
		$SKIN->td_header[] = array( "&nbsp;"  , "40%" );
		$SKIN->td_header[] = array( "&nbsp;"  , "60%" );
		
		$ADMIN->html .= $SKIN->start_table( "是否允许用户在此论坛进行回复？" );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>是否允许用户在子论坛发表新主题和回复？</b><br>如果选择'是'，那么子论坛栏目将根据默认参数显示帖子。<b>如果选择'否'，那么任何设置将无效，你可以忽略这个选项的设置。</b>" ,
												  $SKIN->form_yes_no("sub_can_post", $forum['sub_can_post'])
									     )      );
									     
		$ADMIN->html .= $SKIN->end_table();
		
		//+-------------------------------
		
		$SKIN->td_header[] = array( "&nbsp;"  , "40%" );
		$SKIN->td_header[] = array( "&nbsp;"  , "60%" );
		
		$ADMIN->html .= $SKIN->start_table( "论坛帖子发表参数设置" );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>是否允许在帖子中使用 HTML 语言？</b>" ,
												  $SKIN->form_yes_no("FORUM_HTML", $forum['use_html'] )
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>是否允许在帖子中使用 IBF 代码？</b>" ,
												  $SKIN->form_yes_no("FORUM_IBC", $forum['use_ibc'] )
									     )      );
									     
		//-----------
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>是否允许在论坛中发表投票主题？</b>" ,
												  $SKIN->form_yes_no("allow_poll", $forum['allow_poll'] )
									     )      );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>是否将用户的投票计算为回复帖子？</b>" ,
												  $SKIN->form_yes_no("allow_pollbump", $forum['allow_pollbump'] )
									     )      );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>是否自动增加用户发表帖子的计数值？</b>" ,
												  $SKIN->form_yes_no("inc_postcount", $forum['inc_postcount'] )
									     )      );
									     
		//-----------
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>是否在帖子发表前进行帖子发表审核？</b><br>（必须由版主通过审核后，才能正式发表帖子到论坛）" ,
												  $SKIN->form_yes_no("MODERATE", $forum['preview_posts'] )
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>是否使用登录密码才能访问论坛？</b><br>（不填写表示禁止使用此功能，你也可以在表单中输入一个用户登录论坛的密码。）" ,
												  $SKIN->form_input("FORUM_PROTECT", $forum['password'])
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>论坛默认显示主题的天数：</b>" ,
												  $SKIN->form_dropdown( "PRUNE_DAYS",
																			array( 
																					0 => array( 1, '显示今天主题' ),
																					1 => array( 5, '显示5天前'  ),
																					2 => array( 7, '显示7天前'  ),
																					3 => array( 10, '显示10天前' ),
																					4 => array( 15, '显示15天前' ),
																					5 => array( 20, '显示20天前' ),
																					6 => array( 25, '显示25天前' ),
																					7 => array( 30, '显示30天前' ),
																					8 => array( 60, '显示60天前' ),
																					9 => array( 90, '显示90天前' ),
																					10=> array( 100,'显示所有主题'     ),
																				 ),
												  						$forum['prune']
												  					  )
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>默认的帖子显示方式：</b>" ,
												  $SKIN->form_dropdown( "SORT_KEY",
																			array( 
																					0 => array( 'last_post', '最后回复日期' ),
																					1 => array( 'title'    , '主题标题名称' ),
																					2 => array( 'starter_name', '发表作者名字' ),
																					3 => array( 'posts'    , '主题回复数量' ),
																					4 => array( 'views'    , '主题查看数量' ),
																					5 => array( 'start_date', '主题发表日期' ),
																					6 => array( 'last_poster_name'   , '最后发表作者' ),
																				 ),
												  						$forum['sort_key']
												  					  )
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>默认的帖子排列方式：</b>" ,
												  $SKIN->form_dropdown( "SORT_ORDER",
																			array( 
																					0 => array( 'Z-A', '降序排列（Z - A，0 - 10）' ),
																					1 => array( 'A-Z', '升序排列（A - Z，10 - 0）' ),
																				 ),
												  						$forum['sort_order']
												  					  )
									     )      );
									
		
		$ADMIN->html .= $SKIN->end_form("编辑论坛栏目");
										 
		$ADMIN->html .= $SKIN->end_table();
		
		$ADMIN->output();
			
			
	}
	
	function doeditsub() {
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_POST_VARS;
		
		$IN['FORUM_NAME'] = trim($IN['name']);
		
		if ($IN['FORUM_NAME'] == "")
		{
			$ADMIN->error("你必须输入论坛栏目名称");
		}
		
		if ($IN['f'] == "")
		{
			$ADMIN->error("没有选择论坛栏目ID，请返回重试！");
		}
		
		// Get the new forum id. We could use auto_incrememnt, but we need the ID to use as the default
		// forum position...
		
		$db_string = $DB->compile_db_update_string( array (
															'name'             => $IN['FORUM_NAME'],
															'description'      => str_replace( "\n", "<br>", stripslashes($HTTP_POST_VARS['desc']) ),
															'category'         => $IN['CATEGORY'],
															'subwrap'          => 1,
															'sub_can_post'     => $IN['sub_can_post'],
															'use_ibc'           => $IN['FORUM_IBC'],
															'use_html'          => $IN['FORUM_HTML'],
															'status'            => $IN['FORUM_STATUS'],
															'password'          => $IN['FORUM_PROTECT'],
															'sort_key'          => $IN['SORT_KEY'],
															'sort_order'        => $IN['SORT_ORDER'],
															'prune'             => $IN['PRUNE_DAYS'],
															'preview_posts'     => $IN['MODERATE'],
															'allow_poll'        => $IN['allow_poll'],
															'allow_pollbump'    => $IN['allow_pollbump'],
															'inc_postcount'     => $IN['inc_postcount'],
															
												  )       );
												  
		$DB->query("UPDATE ibf_forums SET $db_string WHERE id='".$IN['f']."'");
		
		$ADMIN->save_log("编辑论坛子分类：'{$IN['FORUM_NAME']}'");
		
		$ADMIN->done_screen("论坛栏目编辑完成", "论坛栏目控制面板", "act=cat" );
		
	}
	
	//+---------------------------------------------------------------------------------
	//
	// Show forum rules
	//
	//+---------------------------------------------------------------------------------
	
	function show_rules() {
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
		
		if ($IN['f'] == "")
		{
			$ADMIN->error("没有找到需要清空的论坛栏目ID。");
		}
		
		$DB->query("SELECT id, name, show_rules FROM ibf_forums WHERE id='".$IN['f']."'");
		
		//+-------------------------------
		// Make sure we have a legal forum
		//+-------------------------------
		
		if ( !$DB->get_num_rows() )
		{
			$ADMIN->error("无法找到论坛栏目ID");
		}
		
		$forum = $DB->fetch_row();
		
		//+-------------------------------
		
		$DB->query("SELECT * FROM ibf_rules WHERE fid='".$forum['id']."'");
		
		$rules = $DB->fetch_row();
		
		//+-------------------------------
		
		$ADMIN->page_title = "论坛规则设置";
		$ADMIN->page_detail  = "你可以 编辑/添加/删除/修改 论坛规则的显示。";
		
		$ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'dorules'),
												  2 => array( 'act'   , 'forum'  ),
												  3 => array( 'f'     , $IN['f'] ),
											) );
		
		
		$SKIN->td_header[] = array( "&nbsp;"   , "40%" );
		$SKIN->td_header[] = array( "&nbsp;"   , "60%" );
		
		$ADMIN->html .= $SKIN->start_table( "论坛规则参数设置" );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>是否显示论坛规则？</b>" ,
												  $SKIN->form_yes_no("show_rules", $forum['show_rules'] )
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>显示论坛规则的方式：</b>" ,
												  $SKIN->form_dropdown( "show_all",
																		array( 
																				0 => array( '0' , '只显示链接' ),
																				1 => array( '1' , '显示全部内容' )
																			 ),
												  						$rules['show_all']
												  					  )
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>论坛规则名称：</b>" ,
												  $SKIN->form_input("title", stripslashes($rules['title']))
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>论坛规则内容：</b><br>(允许使用 HTML 语言)" ,
												  $SKIN->form_textarea( "body", stripslashes($rules['body']), 65, 20 )
									     )      );
									     
		$ADMIN->html .= $SKIN->end_form("编辑论坛规则");
										 
		$ADMIN->html .= $SKIN->end_table();
		
		$ADMIN->output();
		
	}
	
	
	function do_rules() {
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_POST_VARS;
		
		if ($IN['f'] == "")
		{
			$ADMIN->error("没有找到需要清空的论坛栏目ID。");
		}
		
		$rules = array( 
						'title'    => $ADMIN->make_safe($HTTP_POST_VARS['title']),
						'body'     => $ADMIN->make_safe($HTTP_POST_VARS['body']),
						'updated'  => time(),
						'show_all' => $IN['show_all']
					  );
					  
		// Update the forum first..
		
		$DB->query("UPDATE ibf_forums SET show_rules='".$IN['show_rules']."' WHERE id='".$IN['f']."'");
		
		// Check for existing rules..
		
		$DB->query("SELECT fid FROM ibf_rules WHERE fid='".$IN['f']."'");
		
		if ( $DB->get_num_rows() )
		{
			$string = $DB->compile_db_update_string( $rules );
			
			$DB->query("UPDATE ibf_rules SET $string WHERE fid='".$IN['f']."'");
			
		}
		else
		{
			$rules['fid'] = $IN['f'];
			
			$string = $DB->compile_db_insert_string( $rules );
			
			$DB->query("INSERT INTO ibf_rules (" .$string['FIELD_NAMES']. ") VALUES (". $string['FIELD_VALUES'] .")");
			
		}
		
		$ADMIN->save_log("更新论坛规则");
		
		$ADMIN->done_screen("论坛规则更新完成", "论坛设置控制面板", "act=cat" );
		
	}
	
	//+---------------------------------------------------------------------------------
	//
	// RECOUNT FORUM: Recounts topics and posts
	//
	//+---------------------------------------------------------------------------------
	
	function recount($f_override="") {
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
		
		if ($f_override != "")
		{
			// Internal call, remap
			
			$IN['f'] = $f_override;
		}
		
		$DB->query("SELECT name FROM ibf_forums WHERE id='".$IN['f']."'");
		$forum = $DB->fetch_row();
		
		if ($IN['f'] == "")
		{
			$ADMIN->error("没有找到需要重新计算的论坛栏目ID。");
		}
		
		// Get the topics..
		
		$DB->query("SELECT COUNT(tid) as count FROM ibf_topics WHERE approved=1 and forum_id='".$IN['f']."'");
		$topics = $DB->fetch_row();
		
		// Get the posts..
		
		$DB->query("SELECT COUNT(pid) as count FROM ibf_posts WHERE queued <> 1 and forum_id='".$IN['f']."'");
		$posts = $DB->fetch_row();
		
		// Get the forum last poster..
		
		$DB->query("SELECT tid, title, last_poster_id, last_poster_name, last_post FROM ibf_topics WHERE approved=1 and forum_id='".$IN['f']."' ORDER BY last_post DESC LIMIT 0,1");
		$last_post = $DB->fetch_row();
		
		// Reset this forums stats
		
		$postc = $posts['count'] - $topics['count'];
		
		if ($postc < 0)
		{
			$postc = 0;
		}
		
		$db_string = $DB->compile_db_update_string( array (
															 'last_poster_id'   => $last_post['last_poster_id'],
															 'last_poster_name' => $last_post['last_poster_name'],
															 'last_post'        => $last_post['last_post'],
															 'last_title'       => $last_post['title'],
															 'last_id'          => $last_post['tid'],
															 'topics'           => $topics['count'],
															 'posts'            => $postc
												 )        );
												 
		$DB->query("UPDATE ibf_forums SET $db_string WHERE id='".$IN['f']."'");
		
		// Override? then return..
		
		if ($f_override != "")
		{
			return TRUE;
		}
		
		$ADMIN->save_log("重新计算帖子发表数量：'{$forum['name']}'");
		
		$ADMIN->done_screen("论坛重新计算已经完成", "论坛设置控制面板", "act=cat" );
		
	}
	
	//+---------------------------------------------------------------------------------
	//
	// EMPTY FORUM: Removes all topics and posts, etc.
	//
	//+---------------------------------------------------------------------------------
	
	function empty_form() {
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
		
		$form_array = array();
		
		if ($IN['f'] == "")
		{
			$ADMIN->error("没有找到需要清空的论坛栏目ID。");
		}
		
		$DB->query("SELECT id, name FROM ibf_forums WHERE id='".$IN['f']."'");
		
		//+-------------------------------
		// Make sure we have a legal forum
		//+-------------------------------
		
		if ( !$DB->get_num_rows() )
		{
			$ADMIN->error("没有找到论坛栏目ID。");
		}
		
		$forum = $DB->fetch_row();
		
		//+-------------------------------
		
		$ADMIN->page_title = "清空论坛栏目：'{$forum['name']}'";
		
		$ADMIN->page_detail = "此操作将删除所有的主题、回复、投票内容。<br>论坛栏目本身不会被删除 - 请在执行此操作前仔细进行核查。";
		
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'doempty'),
												  2 => array( 'act'   , 'forum'     ),
												  3 => array( 'f'     , $IN['f']  ),
												  4 => array( 'name' , $forum['name'] ),
											) );
		
		//+-------------------------------
		
		$SKIN->td_header[] = array( "&nbsp;"  , "40%" );
		$SKIN->td_header[] = array( "&nbsp;"  , "60%" );
		
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->start_table( "清空论坛栏目：'{$forum['name']}" );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>需要清空的论坛栏目：</b>" , $forum['name'] )      );
									     
		$ADMIN->html .= $SKIN->end_form("清空这个论坛栏目");
										 
		$ADMIN->html .= $SKIN->end_table();
		
		$ADMIN->output();
		
		
	}
	
	//+---------------------------------------------------------------------------------
	
	function do_empty() {
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
		
		if ($IN['f'] == "")
		{
			$ADMIN->error("无法找到论坛栏目ID文件。");
		}
		
		// Check to make sure its a valid forum.
		
		$DB->query("SELECT id, posts, topics FROM ibf_forums WHERE id='".$IN['f']."'");
		
		if ( ! $forum = $DB->fetch_row() )
		{
			$ADMIN->error("没有找到需要清空论坛栏目的详细信息");
		}
		
		// Delete topics...
		
		$DB->query("DELETE FROM ibf_topics WHERE forum_id='".$IN['f']."'");
		
		// Move posts...
		
		$DB->query("DELETE FROM ibf_posts WHERE forum_id='".$IN['f']."'");
		
		// Move polls...
		
		$DB->query("DELETE FROM ibf_polls WHERE forum_id='".$IN['f']."'");
		
		// Move voters...
		
		$DB->query("DELETE FROM ibf_voters WHERE forum_id='".$IN['f']."'");
		
		// Clean up the stats
		
		$DB->query("UPDATE ibf_forums SET posts='0', topics='0', last_post='', last_poster_id='', last_poster_name='', last_title='', last_id='' WHERE id='".$IN['f']."'");
		
		$DB->query("UPDATE ibf_stats SET TOTAL_TOPICS=TOTAL_TOPICS-".$forum['topics'].", TOTAL_REPLIES=TOTAL_REPLIES-".$forum['posts']);
		
		$ADMIN->save_log("清空论坛栏目：'{$IN['name']}' of all posts");
		
		$ADMIN->done_screen("论坛栏目已经清空", "论坛设置控制面板", "act=cat" );
		
	}
	
	
	//+---------------------------------------------------------------------------------
	//
	// RE-ORDER CATEGORY
	//
	//+---------------------------------------------------------------------------------
	
	function reorder_form() {
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
		
		$ADMIN->page_title = "论坛栏目排序";
		$ADMIN->page_detail  = "如果需要对论坛栏目进行重新排序，那么只要从下拉菜单中选择你满意的排列序号，然后确认就可以了。";
		
		$ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'doreorder'),
												  2 => array( 'act'   , 'forum'     ),
											) );
		
		
		$SKIN->td_header[] = array( "&nbsp;"       , "10%" );
		$SKIN->td_header[] = array( "论坛分类和栏目名称"   , "60%" );
		$SKIN->td_header[] = array( "主题回复"        , "15%" );
		$SKIN->td_header[] = array( "主题发表"       , "15%" );
		
		$ADMIN->html .= $SKIN->start_table( "你的论坛分类和栏目" );
		
		$cats        = array();
		$forums       = array();
		$forum_in_cat = array();
		$children = array();
		
		$DB->query("SELECT * from ibf_categories WHERE id > 0 ORDER BY position ASC");
		while ($r = $DB->fetch_row())
		{
			$cats[$r['id']] = $r;
		}
		
		$DB->query("SELECT * from ibf_forums ORDER BY position ASC");
		while ($r = $DB->fetch_row())
		{
			
			if ($r['parent_id'] > 0)
			{
				$children[ $r['parent_id'] ][] = $r;
			}
			else
			{
				$forums[] = $r;
				$forum_in_cat[ $r['category'] ]++;
			}
			
		}
		
		$i = 1;
		
		$last_cat_id = -1;
		
		foreach ($cats as $c)
		{
			
			$ADMIN->html .= $SKIN->add_td_row( array(  '&nbsp;',
													   $c['name'],
													   '&nbsp;',
													   '&nbsp;',
											 ), 'catrow'     );
			$last_cat_id = $c['id'];
			
			
			foreach($forums as $r)
			{	
			
				if ($r['category'] == $last_cat_id)
				{
				
					
					$form_array = array();
				
					for ($c = 1 ; $c <= $forum_in_cat[ $r['category'] ] ; $c++ )
					{
						$i++;
						
						$form_array[] = array( $c, $c );
					}
					
					if ($r['subwrap'] == 1)
					{
					
						$ADMIN->html .= $SKIN->add_td_row( array(  $SKIN->form_dropdown( 'POS_'.$r['id'], $form_array, $r['position'] ),
																   $r['name'],
																   '&nbsp;',
																   '&nbsp;',
														 ), 'catrow2'     );
					}
					else
					{
					
				
						$ADMIN->html .= $SKIN->add_td_row( array(
																   $SKIN->form_dropdown( 'POS_'.$r['id'], $form_array, $r['position'] ),
																   "<b>".$r['name']."</b><br>".$r['description'],
																   $r['posts'],
																   $r['topics'],
														 )      );
					}
					
													 
					if ( ( isset($children[ $r['id'] ]) ) and ( count ($children[ $r['id'] ]) > 0 ) )
					{
						foreach($children[ $r['id'] ] as $idx => $rd)
						{
							$form_array = array();
					
							for ($c = 1 ; $c <= count($children[ $r['id'] ]) ; $c++ )
							{
								$i++;
								
								$form_array[] = array( $c, $c );
							}
							
						
							$ADMIN->html .= $SKIN->add_td_row( array(
																	   $SKIN->form_dropdown( 'POS_'.$rd['id'], $form_array, $rd['position'] ),
																	   "<b>".$rd['name']."</b><br>".$rd['description'],
																	   $rd['posts'],
																	   $rd['topics'],
															 ), 'subforum'      );
						}
					}					 
				}
			}
		}
		
		$ADMIN->html .= $SKIN->end_form("调整论坛栏目排序");
		
		$ADMIN->html .= $SKIN->end_table();
		
		$ADMIN->output();
		
	}
	
	//+---------------------------------------------------------------------------------
	
	function do_reorder() {
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
		
		$cat_query = $DB->query("SELECT id from ibf_forums");
		
		while ( $r = $DB->fetch_row($cat_query) )
		{
			$order_query = $DB->query("UPDATE ibf_forums SET position='".$IN[ 'POS_' . $r['id'] ]."' WHERE id='".$r['id']."'");
		}
		
		$ADMIN->save_log("调整论坛栏目排序");
		
		$ADMIN->done_screen("论坛栏目排序已经调整", "论坛栏目排序", "act=cat" );
		
	}
	
	
	//+---------------------------------------------------------------------------------
	//
	// REMOVE FORUM
	//
	//+---------------------------------------------------------------------------------
	
	function delete_form() {
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
		
		$form_array = array();
		
		if ($IN['f'] == "")
		{
			$ADMIN->error("无法找到需要删除的论坛栏目ID。");
		}
		
		$DB->query("SELECT id, name FROM ibf_forums ORDER BY position");
		
		//+-------------------------------
		// Make sure we have more than 1
		// forum..
		//+-------------------------------
		
		if ($DB->get_num_rows() < 2)
		{
			$ADMIN->error("无法删除这个论坛栏目，请尝试建立其它论坛栏目");
		}
		
		while ( $r = $DB->fetch_row() )
		{
			if ($r['id'] == $IN['f'])
			{
				$name = $r['name'];
				continue;
			}
			
			$form_array[] = array( $r['id'] , $r['name'] );
		}
		
		//+-------------------------------
		
		$ADMIN->page_title = "删除论坛栏目：'$name'";
		
		$ADMIN->page_detail = "删除论坛栏目前，我们需要决定如何处理论坛栏目下的帖子。";
		
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'dodelete'),
												  2 => array( 'act'   , 'forum'     ),
												  3 => array( 'f'     , $IN['f']  ),
											) );
		
		//+-------------------------------
		
		$SKIN->td_header[] = array( "&nbsp;"  , "40%" );
		$SKIN->td_header[] = array( "&nbsp;"  , "60%" );
		
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->start_table( "必须进行选择或填写" );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>删除论坛栏目：</b>" , $name )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>将此论坛栏目下存在的所有帖子移动到：</b>" ,
												  $SKIN->form_dropdown( "MOVE_ID", $form_array )
									     )      );
									     
		$ADMIN->html .= $SKIN->end_form("移动帖子并删除论坛栏目");
										 
		$ADMIN->html .= $SKIN->end_table();
		
		$ADMIN->output();
		
		
	}
	
	//+---------------------------------------------------------------------------------
	
	function do_delete() {
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
		
		$DB->query("SELECT * FROM ibf_forums WHERE id='".$IN['f']."'");
		$forum = $DB->fetch_row();
		
		if ($IN['f'] == "")
		{
			$ADMIN->error("没有找到论坛栏目ID文件。");
		}
		
		if ($IN['MOVE_ID'] == "")
		{
			$ADMIN->error("没有找到论坛分类ID。");
		}
		
		// Move topics...
		
		$DB->query("UPDATE ibf_topics SET forum_id='".$IN['MOVE_ID']."' WHERE forum_id='".$IN['f']."'");
		
		// Move posts...
		
		$DB->query("UPDATE ibf_posts SET forum_id='".$IN['MOVE_ID']."' WHERE forum_id='".$IN['f']."'");
		
		// Move polls...
		
		$DB->query("UPDATE ibf_polls SET forum_id='".$IN['MOVE_ID']."' WHERE forum_id='".$IN['f']."'");
		
		// Move voters...
		
		$DB->query("UPDATE ibf_voters SET forum_id='".$IN['MOVE_ID']."' WHERE forum_id='".$IN['f']."'");
		
		// Delete the forum
		
		$DB->query("DELETE FROM ibf_forums WHERE id='".$IN['f']."'");
		
		// Delete forum rules, if any..
		
		$DB->query("DELETE FROM ibf_rules WHERE fid='".$IN['f']."'");
		
		// Delete any moderators, if any..
		
		$DB->query("DELETE FROM ibf_moderators WHERE forum_id='".$IN['f']."'");
		
		
		$this->recount($IN['MOVE_ID']);
		
		// Have we moved this forum from a sub cat forum?
		// If so, are there any forums left in this sub cat forum?
		
		if ($forum['parent_id'] > 0)
		{
			$DB->query("SELECT id FROM ibf_forums WHERE parent_id='{$forum['parent_id']}'");
			
			if ( ! $DB->get_num_rows() )
			{
				// No, there are no more forums that have a parent id the same as the one we've just moved it from
				// So, make that forum a normal forum then!
				
				$DB->query("UPDATE ibf_forums SET subwrap=0 WHERE id='{$forum['parent_id']}'");
			}
		}
		
		$ADMIN->save_log("删除论坛栏目：'{$forum['name']}'");
		
		$ADMIN->done_screen("论坛栏目已经删除", "论坛设置控制面板", "act=cat" );
		
	}
	
	
	//+---------------------------------------------------------------------------------
	//
	// NEW FORUM
	//
	//+---------------------------------------------------------------------------------
	
	function new_splash() {
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_GET_VARS;
		
		$f_name = "";
		
		
		$ADMIN->page_title = "添加论坛栏目";
		
		$ADMIN->page_detail = "请选择添加什么论坛栏目？<br><b>论坛子分类</b>- 允许你继续添加论坛栏目到这个分类中（注意：在论坛栏目链接被点击前，添加的论坛将自动隐藏。<br><b>论坛栏目</b> 将显示在论坛分类下。";
		
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'donewsplash'  ),
												  2 => array( 'act'   , 'forum'        ),
											) );
		
		//+-------------------------------
		
		$SKIN->td_header[] = array( "&nbsp;"  , "40%" );
		$SKIN->td_header[] = array( "&nbsp;"  , "60%" );
		
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->start_table( "论坛栏目类别" );
		
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>将这个论坛栏目设置为：</b>" ,
												  $SKIN->form_dropdown( "forum_type",
																			array( 
																					0 => array( 'n', '论坛栏目'        ),
																					1 => array( 's', '论坛子分类'  ),
																				 ),
												  						"1"
												  					  )
									     )      );
									     
		$ADMIN->html .= $SKIN->end_form("添加这个论坛栏目");
										 
		$ADMIN->html .= $SKIN->end_table();
		
		$ADMIN->output();
			
			
	}
	
	function donew_splash() {
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_GET_VARS;
		
		if ($IN['forum_type'] == 'n')
		{
			$this->new_form();
		}
		else
		{
			$this->newsub_form();
		}
		
		
	}
	
	//------------------------------------------------------------------------------------------------
	//------------------------------------------------------------------------------------------------
	
	function newsub_form() {
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_GET_VARS;
		
		$f_name = "";
		
		if ($HTTP_GET_VARS['name'] != "")
		{
			$f_name = stripslashes(urldecode($HTTP_GET_VARS['name']));
		}
		
		$cats = array();
		
		$last_cat_id = -1;
		
		$DB->query("SELECT * from ibf_categories WHERE id > 0 ORDER BY position");
		
		while ( $r = $DB->fetch_row() )
		{
			$cats[] = array( $r['id'] , "论坛分类：".$r['name'] );
		}
			
			
		
		$ADMIN->page_title = "添加论坛子分类";
		
		$ADMIN->page_detail = "你可以在论坛分类下添加一个论坛子分类。";
		
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'donewsub'  ),
												  2 => array( 'act'   , 'forum'  ),
											) );
		
		//+-------------------------------
		
		$SKIN->td_header[] = array( "&nbsp;"  , "40%" );
		$SKIN->td_header[] = array( "&nbsp;"  , "60%" );
		
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->start_table( "论坛参数设置" );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>添加到哪个论坛分类？</b><br>" ,
												  $SKIN->form_dropdown("CATEGORY", $cats)
									     )      );
									     
		$ADMIN->html .= $SKIN->end_table();
		
		//+-------------------------------
		
		$SKIN->td_header[] = array( "&nbsp;"  , "40%" );
		$SKIN->td_header[] = array( "&nbsp;"  , "60%" );
		
		$ADMIN->html .= $SKIN->start_table( "论坛栏目设置" );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>论坛栏目名称：</b>" ,
												  $SKIN->form_input("name", $f_name)
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>论坛栏目叙述：</b>你可以使用 HTML 语言" ,
												  $SKIN->form_textarea("desc")
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>论坛栏目状态：</b>" ,
												  $SKIN->form_dropdown( "FORUM_STATUS",
																			array( 
																					0 => array( 1, '立即启用' ),
																					1 => array( 0, '只读文档'  ),
																				 ),
												  						"1"
												  					  )
									     )      );
		
		$ADMIN->html .= $SKIN->end_table();
		
		//+-------------------------------
		
		$SKIN->td_header[] = array( "&nbsp;"  , "40%" );
		$SKIN->td_header[] = array( "&nbsp;"  , "60%" );
		
		$ADMIN->html .= $SKIN->start_table( "是否允许在此论坛栏目发表帖子？" );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>是否允许在论坛子分类中发表新主题和帖子？</b><br>如果选择'是'，论坛子分类中的论坛分类将显示在论坛主题的上面。<b>如果选择'否'，那么这个选项无效，你可以省略不添。</b>" ,
												  $SKIN->form_yes_no("sub_can_post")
									     )      );
									     
		$ADMIN->html .= $SKIN->end_table();
		
		//+-------------------------------
		
		$SKIN->td_header[] = array( "&nbsp;"  , "40%" );
		$SKIN->td_header[] = array( "&nbsp;"  , "60%" );
		
		$ADMIN->html .= $SKIN->start_table( "论坛帖子发表参数设置" );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>是否允许在帖子中使用 HTML 语言？</b>" ,
												  $SKIN->form_yes_no("FORUM_HTML", 0 )
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>是否允许在帖子中使用 IBF 代码？</b>" ,
												  $SKIN->form_yes_no("FORUM_IBC", 1 )
									     )      );
									     
		//-----------
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>是否允许在论坛中发表投票主题？</b>" ,
												  $SKIN->form_yes_no("allow_poll", 1 )
									     )      );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>是否将用户的投票计算为回复帖子？</b>" ,
												  $SKIN->form_yes_no("allow_pollbump", 0 )
									     )      );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>是否自动增加用户发表帖子的计数值？</b>" ,
												  $SKIN->form_yes_no("inc_postcount", 1 )
									     )      );
									     
		//-----------
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>是否在帖子发表前进行帖子发表审核？</b><br>（必须由版主通过审核后，才能正式发表帖子到论坛）" ,
												  $SKIN->form_yes_no("MODERATE", 0 )
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>是否使用登录密码才能访问论坛？<br>（不填写表示禁止使用此功能，你也可以在表单中输入一个用户登录论坛的密码。）" ,
												  $SKIN->form_input("FORUM_PROTECT")
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>论坛默认显示主题的天数：</b>" ,
												  $SKIN->form_dropdown( "PRUNE_DAYS",
																			array( 
																					0 => array( 1, '显示今天主题' ),
																					1 => array( 5, '显示5天前'  ),
																					2 => array( 7, '显示7天前'  ),
																					3 => array( 10, '显示10天前' ),
																					4 => array( 15, '显示15天前' ),
																					5 => array( 20, '显示20天前' ),
																					6 => array( 25, '显示257天前' ),
																					7 => array( 30, '显示30天前' ),
																					8 => array( 60, '显示60天前' ),
																					9 => array( 90, '显示90天前' ),
																					10=> array( 100,'显示所有主题'     ),
																				 ),
												  						"30"
												  					  )
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>默认的帖子显示方式：</b>" ,
												  $SKIN->form_dropdown( "SORT_KEY",
																			array( 
																					0 => array( 'last_post', '最后回复日期' ),
																					1 => array( 'title'    , '主题标题名称' ),
																					2 => array( 'starter_name', '发表作者名字' ),
																					3 => array( 'posts'    , '主题回复数量' ),
																					4 => array( 'views'    , '主题查看数量' ),
																					5 => array( 'start_date', '主题发表日期' ),
																					6 => array( 'last_poster_name'   , '最后发表作者' ),
																				 ),
												  						"last_post"
												  					  )
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>默认的帖子排列方式：</b>" ,
												  $SKIN->form_dropdown( "SORT_ORDER",
																			array( 
																					0 => array( 'Z-A', '降序排列（Z - A，0 - 10）' ),
																					1 => array( 'A-Z', '升序排列（A - Z，10 - 0）' ),
																				 ),
												  						"Z-A"
												  					  )
									     )      );
									     
		$ADMIN->html .= $SKIN->end_table();
		
		//+-------------------------------
		
		$SKIN->td_header[] = array( "&nbsp;"  , "40%" );
		$SKIN->td_header[] = array( "&nbsp;"  , "60%" );
		
		$ADMIN->html .= $SKIN->start_table( "论坛栏目访问权限设置" );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>论坛栏目访问权限设置</b><br>(请在下面进行选择，如果对某个用户团队禁止查看权限，那么这个用户团队将不能查看论坛栏目)" ,
												  $SKIN->build_group_perms()
									     )      );
		
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->end_form("添加此论坛栏目");
										 
		$ADMIN->html .= $SKIN->end_table();
		
		$ADMIN->output();
			
			
	}

	//------------------------------------------------------------------------------------------------
	//------------------------------------------------------------------------------------------------
	
	function new_form() {
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_GET_VARS;
		
		$f_name = "";
		
		if ($HTTP_GET_VARS['name'] != "")
		{
			$f_name = stripslashes(urldecode($HTTP_GET_VARS['name']));
		}
		
		$cats = array();
		$seen = array();
		
		$last_cat_id = -1;
		
		$DB->query("SELECT c.id, c.name, f.id as forum_id, f.subwrap, f.name as forum_name, f.subwrap, f.parent_id, f.category FROM ibf_categories c, ibf_forums f WHERE c.id > 0 ORDER BY c.position, f.position");
		
		if ( $DB->get_num_rows() )
		{
		
			while ( $r = $DB->fetch_row() )
			{
			
				if ($r['parent_id'] > 0)
				{
					continue;
				}
					
				if ($last_cat_id != $r['id'])
				{
					$cats[] = array( "c_".$r['id'] , "论坛分类：".$r['name'] );
					
					$seen[$r['id']] = 1;
					
					$last_cat_id = $r['id'];
				}
				
				if ($r['category'] == $r['id'])
				{
					if ($r['forum_id'] != $IN['f'])
					{
						$cats[] = array( "f_".$r['forum_id'], "论坛栏目：".$r['forum_name'] );
					}
				}
				
			}
		
		}
		else
		{
			// No forums, get cats only..
			
			$DB->query("SELECT * from ibf_categories WHERE id > 0");
			
			while ($r = $DB->fetch_row())
			{
				$cats[] = array( "c_".$r['id'] , "Category: ".$r['name'] );
			}
			
		}
		
		$ADMIN->page_title = "添加论坛栏目";
		
		$ADMIN->page_detail = "你可以在下面添加一个新论坛栏目到已经存在的论坛分类下，请确认选择的论坛分类正确并填写论坛分类叙述。如果建立论坛栏目后发现填写了错误信息，那么你可以同点击[编辑设置]功能来进行修改。";
		
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'donew'  ),
												  2 => array( 'act'   , 'forum'  ),
											) );
		
		//+-------------------------------
		
		$SKIN->td_header[] = array( "&nbsp;"  , "40%" );
		$SKIN->td_header[] = array( "&nbsp;"  , "60%" );
		
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->start_table( "论坛参数设置" );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>添加到哪个论坛分类下？</b><br>" ,
												  $SKIN->form_dropdown("CATEGORY", $cats)
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>论坛栏目状态：</b>" ,
												  $SKIN->form_dropdown( "FORUM_STATUS",
																			array( 
																					0 => array( 1, '立即启用' ),
																					1 => array( 0, '只读文档'  ),
																				 ),
												  						"1"
												  					  )
									     )      );
									     
		$ADMIN->html .= $SKIN->end_table();
		
		//+-------------------------------
		
		$SKIN->td_header[] = array( "&nbsp;"  , "40%" );
		$SKIN->td_header[] = array( "&nbsp;"  , "60%" );
		
		$ADMIN->html .= $SKIN->start_table( "论坛栏目设置" );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>论坛栏目名称：</b>" ,
												  $SKIN->form_input("FORUM_NAME", $f_name)
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>论坛栏目叙述：</b><br>你可以使用 HTML 语言 - 断行将自动被转换" ,
												  $SKIN->form_textarea("FORUM_DESC")
									     )      );
									     
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->end_table();
		
		//+-------------------------------
		
		$SKIN->td_header[] = array( "&nbsp;"  , "40%" );
		$SKIN->td_header[] = array( "&nbsp;"  , "60%" );
		
		$ADMIN->html .= $SKIN->start_table( "论坛全局参数设置：是否允许用户在此论坛栏目发表帖子？" );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>是否允许用户在此论坛栏目发表主题和回复？</b><br>选择'是'，所有的论坛子分类将显示在帖子的上面。选择'否'，此功能将失效，你可以省略不添。</b>" ,
												  $SKIN->form_yes_no("sub_can_post", 1)."<br><b>注意：</b>如果你使用了其它栏目作为论坛子分类，那么这个选项将失效，你可以省略不添。",
									     )      );
									     
		$ADMIN->html .= $SKIN->end_table();
		
		$SKIN->td_header[] = array( "&nbsp;"  , "40%" );
		$SKIN->td_header[] = array( "&nbsp;"  , "60%" );
		
		$ADMIN->html .= $SKIN->start_table( "论坛帖子发表参数设置" );
		
		//+-------------------------------
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>是否允许在帖子中使用 HTML 语言？</b>" ,
												  $SKIN->form_yes_no("FORUM_HTML", 0 )
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>是否允许在帖子中使用 IBF 代码？</b>" ,
												  $SKIN->form_yes_no("FORUM_IBC", 1 )
									     )      );
									     
		//-----------
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>是否允许在论坛中发表投票主题？</b>" ,
												  $SKIN->form_yes_no("allow_poll", 1 )
									     )      );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>是否将用户的投票计算为回复帖子？</b>" ,
												  $SKIN->form_yes_no("allow_pollbump", 0 )
									     )      );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>是否自动增加用户发表帖子的计数值？</b>" ,
												  $SKIN->form_yes_no("inc_postcount", 1 )
									     )      );
									     
		//-----------
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>是否在帖子发表前进行帖子发表审核？</b><br>（必须由版主通过审核后，才能正式发表帖子到论坛）" ,
												  $SKIN->form_yes_no("MODERATE", 0 )
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>是否使用登录密码才能访问论坛？</b><br>（不填写表示禁止使用此功能，你也可以在表单中输入一个用户登录论坛的密码。）" ,
												  $SKIN->form_input("FORUM_PROTECT")
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>论坛默认显示主题的天数：</b>" ,
												  $SKIN->form_dropdown( "PRUNE_DAYS",
																			array( 
																					0 => array( 1, '显示今天主题' ),
																					1 => array( 5, '显示5天前'  ),
																					2 => array( 7, '显示7天前'  ),
																					3 => array( 10, '显示10天前' ),
																					4 => array( 15, '显示15天前' ),
																					5 => array( 20, '显示20天前' ),
																					6 => array( 25, '显示25天前' ),
																					7 => array( 30, '显示30天前' ),
																					8 => array( 60, '显示60天前' ),
																					9 => array( 90, '显示90天前' ),
																					10=> array( 100,'显示所有主题'     ),
																				 ),
												  						"30"
												  					  )
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>默认的帖子显示方式：</b>" ,
												  $SKIN->form_dropdown( "SORT_KEY",
																			array( 
																					0 => array( 'last_post', '最后回复日期' ),
																					1 => array( 'title'    , '主题标题名称' ),
																					2 => array( 'starter_name', '发表作者名字' ),
																					3 => array( 'posts'    , '主题回复数量' ),
																					4 => array( 'views'    , '主题查看数量' ),
																					5 => array( 'start_date', '主题发表日期' ),
																					6 => array( 'last_poster_name'   , '最后发表作者' ),
																				 ),
												  						"last_post"
												  					  )
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>默认的帖子排列方式：</b>" ,
												  $SKIN->form_dropdown( "SORT_ORDER",
																			array( 
																					0 => array( 'Z-A', '降序排列（Z - A，0 - 10）' ),
																					1 => array( 'A-Z', '升序排列（A - Z，10 - 0）' ),
																				 ),
												  						"Z-A"
												  					  )
									     )      );
									     
		$ADMIN->html .= $SKIN->end_table();
		
		//+-------------------------------
		
		$SKIN->td_header[] = array( "&nbsp;"  , "40%" );
		$SKIN->td_header[] = array( "&nbsp;"  , "60%" );
		
		$ADMIN->html .= $SKIN->start_table( "论坛栏目访问权限设置" );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>论坛栏目访问权限设置</b><br>(请在下面进行选择，如果对某个用户团队禁止查看权限，那么这个用户团队将不能查看论坛栏目)" ,
												  $SKIN->build_group_perms()
									     )      );
		
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->end_form("添加此论坛栏目");
										 
		$ADMIN->html .= $SKIN->end_table();
		
		$ADMIN->output();
			
			
	}


	//------------------------------------------------------------------------------------------------
	//------------------------------------------------------------------------------------------------
	
	function do_new() {
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_POST_VARS;
		
		$IN['FORUM_NAME'] = trim($IN['FORUM_NAME']);
		
		if ($IN['FORUM_NAME'] == "")
		{
			$ADMIN->error("你必须输入论坛栏目名称");
		}
		
		// Get the new forum id. We could use auto_incrememnt, but we need the ID to use as the default
		// forum position...
		
		$DB->query("SELECT MAX(id) as top_forum FROM ibf_forums");
		$row = $DB->fetch_row();
		
		if ($row['top_forum'] < 1) $row['top_forum'] = 0;
		
		$row['top_forum']++;
		
		$perms = $ADMIN->compile_forum_perms();
		
		$cat    = -1;
		$parent = -1;
		
		if ( preg_match( "/^c_(\d+)$/", $IN['CATEGORY'], $match ) )
		{
			$cat = $match[1];
		}
		else
		{
			$parent = preg_replace( "/^f_/", "", $IN['CATEGORY'] );
			
			$DB->query("SELECT category FROM ibf_forums WHERE id='$parent'");
			
			if ($forum_result = $DB->fetch_row())
			{
				$cat = $forum_result['category'];
			}
		}
		
		$db_string = $DB->compile_db_insert_string( array (
															'id'               => $row['top_forum'],
															'position'         => $row['top_forum'],
															'topics'           => 0,
															'posts'            => 0,
															'last_post'        => "",
															'last_poster_id'   => "",
															'last_poster_name' => "",
															'name'             => $IN['FORUM_NAME'],
															'description'      => str_replace( "\n", "<br>", stripslashes($HTTP_POST_VARS['FORUM_DESC']) ),
															'use_ibc'          => $IN['FORUM_IBC'],
															'use_html'         => $IN['FORUM_HTML'],
															'status'           => $IN['FORUM_STATUS'],
															'start_perms'      => $perms['START'],
															'reply_perms'      => $perms['REPLY'],
															'read_perms'       => $perms['READ'],
															'upload_perms'     => $perms['UPLOAD'],
															'password'         => $IN['FORUM_PROTECT'],
															'category'         => $cat,
															'last_id'          => "",
															'last_title'       => "",
															'sort_key'         => $IN['SORT_KEY'],
															'sort_order'       => $IN['SORT_ORDER'],
															'prune'            => $IN['PRUNE_DAYS'],
															'show_rules'       => 0,
															'preview_posts'    => $IN['MODERATE'],
															'allow_poll'       => $IN['allow_poll'],
															'allow_pollbump'   => $IN['allow_pollbump'],
															'inc_postcount'    => $IN['inc_postcount'],
															'parent_id'        => $parent,
															'sub_can_post'     => $IN['sub_can_post'],
															
												  )       );
												  
		$DB->query("INSERT INTO ibf_forums (".$db_string['FIELD_NAMES'].") VALUES (".$db_string['FIELD_VALUES'].")");
		
		if ($parent != -1)
		{
			$DB->query("UPDATE ibf_forums SET subwrap=1 WHERE id='$parent'");
		}
		
		$ADMIN->save_log("添加论坛栏目：'{$IN['FORUM_NAME']}' ");
		
		$ADMIN->done_screen("论坛栏目 {$IN['FORUM_NAME']} 已经建立", "论坛设置控制面板", "act=cat" );
		
		
		
	}
	
	//------------------------------------------------------------------------------------------------
	//------------------------------------------------------------------------------------------------
	
	function add_sub() {
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_POST_VARS;
		
		$IN['FORUM_NAME'] = trim($IN['name']);
		
		if ($IN['FORUM_NAME'] == "")
		{
			$ADMIN->error("你必须输入论坛栏目名称");
		}
		
		// Get the new forum id. We could use auto_incrememnt, but we need the ID to use as the default
		// forum position...
		
		$DB->query("SELECT MAX(id) as top_forum FROM ibf_forums");
		$row = $DB->fetch_row();
		
		if ($row['top_forum'] < 1) $row['top_forum'] = 0;
		
		$row['top_forum']++;
		
		$perms = $ADMIN->compile_forum_perms();
		
		$db_string = $DB->compile_db_insert_string( array (
															'id'               => $row['top_forum'],
															'position'         => $row['top_forum'],
															'topics'           => 0,
															'posts'            => 0,
															'last_post'        => "",
															'last_poster_id'   => "",
															'last_poster_name' => "",
															'name'             => $IN['FORUM_NAME'],
															'description'      => str_replace( "\n", "<br>", stripslashes($HTTP_POST_VARS['desc']) ),
															'use_ibc'          => $IN['FORUM_IBC'],
															'use_html'         => $IN['FORUM_HTML'],
															'status'           => $IN['FORUM_STATUS'],
															'start_perms'      => $perms['START'],
															'reply_perms'      => $perms['REPLY'],
															'read_perms'       => $perms['READ'],
															'upload_perms'     => $perms['UPLOAD'],
															'password'         => $IN['FORUM_PROTECT'],
															'category'         => $IN['CATEGORY'],
															'last_id'          => "",
															'last_title'       => "",
															'sort_key'         => $IN['SORT_KEY'],
															'sort_order'       => $IN['SORT_ORDER'],
															'prune'            => $IN['PRUNE_DAYS'],
															'show_rules'       => 0,
															'preview_posts'    => $IN['MODERATE'],
															'allow_poll'       => $IN['allow_poll'],
															'allow_pollbump'   => $IN['allow_pollbump'],
															'inc_postcount'    => -1,
															'sub_can_post'     => $IN['sub_can_post'],
															'subwrap'          => 1,
																														
												  )       );
												  
												  
		$DB->query("INSERT INTO ibf_forums (".$db_string['FIELD_NAMES'].") VALUES (".$db_string['FIELD_VALUES'].")");
		
		$ADMIN->save_log("建立论坛栏目：'{$IN['FORUM_NAME']}' ");
		
		$ADMIN->done_screen("论坛栏目 {$IN['FORUM_NAME']} 已经建立", "论坛设置控制面板", "act=cat" );
		
		
		
	}



	//+---------------------------------------------------------------------------------
	//
	// EDIT FORUM
	//
	//+---------------------------------------------------------------------------------
	
	function edit_form() {
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
		
		if ($IN['f'] == "")
		{
			$ADMIN->error("没有选择要进行编辑的论坛栏目！");
		}
		
		$cats = array();
		$seen = array();
		
		$last_cat_id = -1;
		
		$DB->query("SELECT c.id, c.name, f.subwrap, f.id as forum_id, f.name as forum_name, f.subwrap, f.parent_id, f.category FROM ibf_categories c, ibf_forums f WHERE c.id > 0 ORDER BY c.position, f.position");
		
		while ( $r = $DB->fetch_row() )
		{
			
			if ($r['parent_id'] > 0)
			{
				continue;
			}
				
			if ($last_cat_id != $r['id'])
			{
				$cats[] = array( "c_".$r['id'] , "论坛分类：".$r['name'] );
				
				$seen[$r['id']] = 1;
				
				$last_cat_id = $r['id'];
			}
			
			if ($r['category'] == $r['id'])
			{
				if ($r['forum_id'] != $IN['f'])
				{
					$cats[] = array( "f_".$r['forum_id'], "论坛栏目：".$r['forum_name'] );
				}
			}
			
		}
		
		$DB->query("SELECT * FROM ibf_forums WHERE id='".$IN['f']."'");
		$forum = $DB->fetch_row();
		
		if ($forum['id'] == "")
		{
			$ADMIN->error("无法找到相关论坛栏目数据 {$IN['f']}");
		}
		
		//-------------------------------------
		
		$real_parent = "";
		
		if ($forum['parent_id'] < 1)
		{
			$real_parent = 'c_'.$forum['category'];
		}
		else
		{
			$real_parent = 'f_'.$forum['parent_id'];
		}
		
		//-------------------------------------
		
		$ADMIN->page_title = "编辑论坛栏目";
		
		$ADMIN->page_detail = "你可以在下面编辑一个已经存在的论坛栏目，如果你想编辑论坛栏目访问权限设置，请点击[编辑权限]选项。";
		
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'doedit'  ),
												  2 => array( 'act'   , 'forum'   ),
												  3 => array( 'f'     , $IN['f']  ),
												  4 => array( 'name'  , $forum['name'] ),
											) );
		
		//+-------------------------------
		
		$SKIN->td_header[] = array( "&nbsp;"  , "40%" );
		$SKIN->td_header[] = array( "&nbsp;"  , "60%" );
		
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->start_table( "论坛参数设置" );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>添加到哪个论坛分类下？</b><br>" ,
												  $SKIN->form_dropdown("CATEGORY", $cats, $real_parent)
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>论坛栏目状态：</b>" ,
												  $SKIN->form_dropdown( "FORUM_STATUS",
																			array( 
																					0 => array( 1, '立即启用' ),
																					1 => array( 0, '只读文档'  ),
																				 ),
												  						$forum['status']
												  					  )
									     )      );
									     
		$ADMIN->html .= $SKIN->end_table();
		
		//+-------------------------------
		
		$SKIN->td_header[] = array( "&nbsp;"  , "40%" );
		$SKIN->td_header[] = array( "&nbsp;"  , "60%" );
		
		$ADMIN->html .= $SKIN->start_table( "论坛栏目设置" );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>论坛栏目名称：</b>" ,
												  $SKIN->form_input("FORUM_NAME", $forum['name'])
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>论坛栏目叙述：</b><br>你可以使用 HTML 语言 - 断行将自动被转换为 &lt;br&gt;" ,
												  $SKIN->form_textarea("FORUM_DESC", str_replace("<br>", "\n", $forum['description']) )
									     )      );
									     
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->end_table();
		
		
		if ($forum['parent_id'] > 0)
		{
			$st = "<span style='color:#AAAAAA'>";
			$end = "</span>";
			$extra = "<span id='normal' style='color:red'><br><b>注意：</b>此论坛栏目不是一个论坛子分类，这个选项将无效。</span>";
		}
		
		//+-------------------------------
		
		$SKIN->td_header[] = array( "&nbsp;"  , "40%" );
		$SKIN->td_header[] = array( "&nbsp;"  , "60%" );
		
		$ADMIN->html .= $SKIN->start_table( $st."论坛全局参数设置：是否允许用户在此论坛栏目发表帖子？".$end );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>是否允许用户在此论坛栏目发表主题和回复？</b><br>选择'是'，所有的论坛子分类将显示在帖子的上面。选择'否'，此功能将失效，你可以省略不添。" ,
												  $SKIN->form_yes_no("sub_can_post", $forum['sub_can_post']) .$extra
										 )      );
										 
		$ADMIN->html .= $SKIN->end_table();
		
		
		
		
		//+-------------------------------
		
		$SKIN->td_header[] = array( "&nbsp;"  , "40%" );
		$SKIN->td_header[] = array( "&nbsp;"  , "60%" );
		
		$ADMIN->html .= $SKIN->start_table( "论坛帖子发表参数设置" );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>是否允许在帖子中使用 HTML 语言？</b>" ,
												  $SKIN->form_yes_no("FORUM_HTML", $forum['use_html'] )
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>是否允许在帖子中使用 IBF 代码？</b>" ,
												  $SKIN->form_yes_no("FORUM_IBC", $forum['use_ibc'] )
									     )      );
									     
		//-----------
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>是否允许在论坛中发表投票主题？</b>" ,
												  $SKIN->form_yes_no("allow_poll", $forum['allow_poll'] )
									     )      );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>是否将用户的投票计算为回复帖子？</b>" ,
												  $SKIN->form_yes_no("allow_pollbump", $forum['allow_pollbump'] )
									     )      );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>是否自动增加用户发表帖子的计数值？</b>" ,
												  $SKIN->form_yes_no("inc_postcount", $forum['inc_postcount'] )
									     )      );
									     
		//-----------
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>是否在帖子发表前进行帖子发表审核？</b><br>（必须由版主通过审核后，才能正式发表帖子到论坛）" ,
												  $SKIN->form_yes_no("MODERATE", $forum['preview_posts'] )
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>是否使用登录密码才能访问论坛？</b><br>（不填写表示禁止使用此功能，你也可以在表单中输入一个用户登录论坛的密码。）" ,
												  $SKIN->form_input("FORUM_PROTECT", $forum['password'])
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>论坛默认显示主题的天数：</b>" ,
												  $SKIN->form_dropdown( "PRUNE_DAYS",
																			array( 
																					0 => array( 1, '显示今天主题' ),
																					1 => array( 5, '显示5天前'  ),
																					2 => array( 7, '显示7天前'  ),
																					3 => array( 10, '显示10天前' ),
																					4 => array( 15, '显示15天前' ),
																					5 => array( 20, '显示20天前' ),
																					6 => array( 25, '显示25天前' ),
																					7 => array( 30, '显示30天前' ),
																					8 => array( 60, '显示60天前' ),
																					9 => array( 90, '显示90天前' ),
																					10=> array( 100,'显示所有主题'     ),
																				 ),
												  						$forum['prune']
												  					  )
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>默认的帖子显示方式：</b>" ,
												  $SKIN->form_dropdown( "SORT_KEY",
																			array( 
																					0 => array( 'last_post', '最后回复日期' ),
																					1 => array( 'title'    , '主题标题名称' ),
																					2 => array( 'starter_name', '发表作者名字' ),
																					3 => array( 'posts'    , '主题回复数量' ),
																					4 => array( 'views'    , '主题查看数量' ),
																					5 => array( 'start_date', '主题发表日期' ),
																					6 => array( 'last_poster_name'   , '最后发表作者' ),
																				 ),
												  						$forum['sort_key']
												  					  )
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>默认的帖子排列方式：</b>" ,
												  $SKIN->form_dropdown( "SORT_ORDER",
																			array( 
																					0 => array( 'Z-A', '降序排列（Z - A，0 - 10）' ),
																					1 => array( 'A-Z', '升序排列（A - Z，10 - 0）' ),
																				 ),
												  						$forum['sort_order']
												  					  )
									     )      );
									     

		$ADMIN->html .= $SKIN->end_form("编辑此论坛栏目");
										 
		$ADMIN->html .= $SKIN->end_table();
		
		$ADMIN->output();
			
			
	}


	//+---------------------------------------------------------------------------------
	
	function do_edit() {
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_POST_VARS;
		
		$IN['FORUM_NAME'] = trim($IN['FORUM_NAME']);
		
		if ($IN['FORUM_NAME'] == "")
		{
			$ADMIN->error("你必须输入论坛栏目名称");
		}
		
		$DB->query("SELECT * from ibf_forums WHERE id='".$IN['f']."'");
		
		$old_details = $DB->fetch_row();
		
		$cat    = -1;
		$parent = -1;
		
		if ( preg_match( "/^c_(\d+)$/", $IN['CATEGORY'], $match ) )
		{
			$cat = $match[1];
		}
		else
		{
			$parent = preg_replace( "/^f_/", "", $IN['CATEGORY'] );
			
			$DB->query("SELECT category FROM ibf_forums WHERE id='$parent'");
			
			if ($forum_result = $DB->fetch_row())
			{
				$cat = $forum_result['category'];
			}
		}
		
		$db_string = $DB->compile_db_update_string( array (
															
															'name'              => $IN['FORUM_NAME'],
															'description'       => str_replace( "\n", "<br>", stripslashes($HTTP_POST_VARS['FORUM_DESC']) ),
															'use_ibc'           => $IN['FORUM_IBC'],
															'use_html'          => $IN['FORUM_HTML'],
															'status'            => $IN['FORUM_STATUS'],
															'password'          => $IN['FORUM_PROTECT'],
															'category'          => $cat,
															'sort_key'          => $IN['SORT_KEY'],
															'sort_order'        => $IN['SORT_ORDER'],
															'prune'             => $IN['PRUNE_DAYS'],
															'preview_posts'     => $IN['MODERATE'],
															'allow_poll'        => $IN['allow_poll'],
															'allow_pollbump'    => $IN['allow_pollbump'],
															'inc_postcount'     => $IN['inc_postcount'],
															'parent_id'         => $parent,
															'sub_can_post'      => $IN['sub_can_post'],
															
												  )       );
												  
		$DB->query("UPDATE ibf_forums SET $db_string WHERE id='".$IN['f']."'");
		
		// Update the parent if need be
		
		if ($parent != -1)
		{
			$DB->query("UPDATE ibf_forums SET subwrap=1 WHERE id='$parent'");
		}
		
		// Have we moved this forum from a sub cat forum?
		// If so, are there any forums left in this sub cat forum?
		
		if (($old_details['parent_id'] > 0) and ($old_details['parent_id'] != $parent))
		{
			$DB->query("SELECT id FROM ibf_forums WHERE parent_id='{$old_details['parent_id']}'");
			
			if ( ! $DB->get_num_rows() )
			{
				// No, there are no more forums that have a parent id the same as the one we've just moved it from
				// So, make that forum a normal forum then!
				
				$DB->query("UPDATE ibf_forums SET subwrap=0 WHERE id='{$old_details['parent_id']}'");
			}
		}
		
		$ADMIN->save_log("编辑论坛栏目：'{$IN['name']}' ");
		
		$ADMIN->done_screen("论坛栏目 {$IN['name']} 编辑完成", "论坛设置控制面板", "act=cat" );
		
		
		
	}
	
	
	
	//+---------------------------------------------------------------------------------
	//
	// EDIT FORUM
	//
	//+---------------------------------------------------------------------------------
	
	function perm_edit_form() {
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
		
		if ($IN['f'] == "")
		{
			$ADMIN->error("你没有选择需要编辑的论坛栏目！");
		}
		
		$cats = array();
		
		$DB->query("SELECT id,name FROM ibf_categories ORDER BY position");
		
		while ( $r = $DB->fetch_row() )
		{
			$cats[] = array( $r['CAT_ID'] , $r['CAT_NAME'] );
		}
		
		$DB->query("SELECT * FROM ibf_forums WHERE id='".$IN['f']."'");
		$forum = $DB->fetch_row();
		
		if ($forum['id'] == "")
		{
			$ADMIN->error("无法找到相关论坛栏目ID数据 {$IN['f']}");
		}
		
		
		
		
		$ADMIN->page_title = "编辑论坛栏目访问权限：".$forum['name'];
		
		$ADMIN->page_detail = "你可以在下面编辑一个已经存在的论坛栏目，如果你想编辑论坛栏目访问权限设置，请点击[编辑权限]选项。";
		
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'pdoedit'  ),
												  2 => array( 'act'   , 'forum'   ),
												  3 => array( 'f'     , $IN['f']  ),
												  4 => array( 'name'  , $forum['name'] ),
											) );
		
		$SKIN->td_header[] = array( "&nbsp;"  , "20%" );
		$SKIN->td_header[] = array( "&nbsp;"  , "80%" );
		
		$ADMIN->html .= $SKIN->start_table( "论坛栏目访问权限设置" );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>论坛栏目访问权限设置</b><br>(请在下面进行选择，如果对某个用户团队禁止查看权限，那么这个用户团队将不能查看论坛栏目)" ,
												  $SKIN->build_group_perms($forum['read_perms'], $forum['start_perms'], $forum['reply_perms'], $forum['upload_perms'])
									     )      );
									     

		$ADMIN->html .= $SKIN->end_form("编辑此论坛栏目");
										 
		$ADMIN->html .= $SKIN->end_table();
		
		$ADMIN->output();
			
			
	}


	function perm_do_edit() {
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
		
		$perms = $ADMIN->compile_forum_perms();
		
		
		$db_string = $DB->compile_db_update_string( array (
															
															'start_perms' => $perms['START'],
															'reply_perms' => $perms['REPLY'],
															'read_perms'  => $perms['READ'],
															'upload_perms' => $perms['UPLOAD'],
															
												  )       );
												  
		$DB->query("UPDATE ibf_forums SET $db_string WHERE id='".$IN['f']."'");
		
		$ADMIN->save_log("编辑论坛栏目访问权限：'{$IN['name']}'");
		
		$ADMIN->done_screen("编辑论坛栏目访问权限编辑完成", "论坛设置控制面板", "act=cat" );
		
		
		
	}
	
		
}


?>