<?php

/*
+--------------------------------------------------------------------------
|   Invision Power Board v1.2
|   ========================================
|   by Matthew Mecham
|   (c) 2001 - 2003 Invision Power Services
|   http://www.invisionpower.com
|   ========================================
|   Web: http://www.invisionboard.com
|   Email: matt@invisionpower.com
|   Licence Info: http://www.invisionboard.com/?license
+---------------------------------------------------------------------------
|
|   > 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', '-- NONE --' );
		
		$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>搬移所有 <i>存在的讨论区</i> 到哪一个父系？</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" );
		
	}
	
	
	
	//+---------------------------------------------------------------------------------
	//
	// 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, rules_title, rules_text 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 = "讨论区规则";
		$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_dropdown( "show_rules",
																		array( 
																				0 => array( '0' , '不要显示' ),
																				1 => array( '1' , '只显示连结' ),
																				2 => array( '2' , '显示完整内容' )
																			 ),
												  						$forum['show_rules']
												  					  )
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>规则标题</b>" ,
												  $SKIN->form_input("title", $std->txt_stripslashes(str_replace( "'", '&#039;', $forum['rules_title'])))       /*讨论区规则中文修正*/ 
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>规则内容</b><br>(HTML 编辑模式)" ,
												  $SKIN->form_textarea( "body", $std->txt_stripslashes(str_replace( "'", '&#039;',$forum['rules_text'])), 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( 
						'rules_title'    => $ADMIN->make_safe($std->txt_stripslashes($HTTP_POST_VARS['title'])),
						'rules_text'     => $ADMIN->make_safe($std->txt_stripslashes($HTTP_POST_VARS['body'])),
						'show_rules'     => $IN['show_rules']
					  );
					  
		$dbs = $DB->compile_db_update_string($rules);
		
		$DB->query("UPDATE ibf_forums SET $dbs WHERE id='".$IN['f']."'");
		
		$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' => addslashes($last_post['last_poster_name']), /* 中文修正 */
															 'last_post'        => $last_post['last_post'],
															 'last_title'       => addslashes($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']}' 的所有文章");
		
		$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;',
											 ), 'pformstrip'     );
			$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>",
																   $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>",
																	   $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>搬移所有 <i>存在于这个讨论区的主题与文章</i> 到哪一个讨论区？</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 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']}'");
			}
		}
		$forum['name'] = addslashes($forum['name']); /* 中文修正 */
		$ADMIN->save_log("已移除的讨论区 '{$forum['name']}'");
		
		$ADMIN->done_screen("已移除讨论区", "讨论区控制", "act=cat" );
		
	}
	
	
	//+---------------------------------------------------------------------------------
	//
	// NEW FORUM
	//
	//+---------------------------------------------------------------------------------
	
	
	function new_form() {
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_GET_VARS;
		
		$f_name = "";
		
		if ($HTTP_GET_VARS['name'] != "")
		{
			$f_name = $std->txt_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'] , "类别： ".$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>如果是，任何子讨论区将会显示在一般的主题列表上面，如果没有子讨论区可显示，会如常地显示主题列表。<br><b>如果 '否' 您可以略过这个表单剩下的部份，因为设定不会生效并且这个讨论区的作用将如同类别一般。</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>此讨论区要转至的 URL</b>" ,
												  $SKIN->form_input("redirect_url")
										 )      );
										 
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>要转至的目标？</b><br>留空或使用 '_self' 在同一个浏览视窗载入" ,
												  $SKIN->form_input("redirect_loc")
										 )      );
										 
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>启用 URL 转向？</b><br>如果 '是' 您可以略过讨论区权限，因为设定不会生效并且此讨论区的运作将会如同转向连结一般。启用之后目前所有的文章将无法被存取" ,
												  $SKIN->form_yes_no("redirect_on", 0)
										 )      );
										 
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>转向点按次数</b>" ,
												  $SKIN->form_input("redirect_hits", 0)
										 )      );
										 
		$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>允许使用 [doHTML] 标签？</b><br />可以使用 HTML 语法发表并执行" ,
												  $SKIN->form_yes_no("FORUM_HTML", 0 )
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>允许使用 IBF CODE 发表？</b>" ,
												  $SKIN->form_yes_no("FORUM_IBC", 1 )
									     )      );
									     
		//-----------
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>启用快速回复框？</b>" ,
												  $SKIN->form_yes_no("quick_reply", 0 )
									     )      );
									     
		$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 )
									     )      );
		//金钱hack
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>论坛金钱设定数据</b>" ,
												  $SKIN->form_input("coef_money", 1 )
									     )      );
									     
		//-----------
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>管制发表？</b><br>(需要板主手动将文章/主题加入讨论区)" ,
												  $SKIN->form_dropdown("MODERATE", array(
												  									 0 => array( 0, '否' ),
												  									 1 => array( 1, '管制所有新主题及所有回复' ),
												  									 2 => array( 2, '管制新主题但不要管制回复' ),
												  									 3 => array( 3, '管制回复但不要管制新主题' ),
												  									   ),
												  							    0 )
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>需要密码进入？<br>在这里输入密码</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( "名称"  , "40%" );
		$SKIN->td_header[] = array( "读取"  , "15%" );
		$SKIN->td_header[] = array( "回复" , "15%" );
		$SKIN->td_header[] = array( "发起" , "15%" );
		$SKIN->td_header[] = array( "上传", "15%" );
		
		$ADMIN->html .= $SKIN->start_table("存取权限等级");
		
		$ADMIN->html .= $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 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'      => $std->my_nl2br( $std->txt_stripslashes(str_replace( "'", "'", $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'],
															'coef_money'       => $IN['coef_money'], /*金钱hack*/ 
															'parent_id'        => $parent,
															'sub_can_post'     => $IN['sub_can_post'],
															'quick_reply'      => $IN['quick_reply'],
															'redirect_on'       => $IN['redirect_on'],
															'redirect_hits'     => $IN['redirect_hits'],
															'redirect_url'      => $IN['redirect_url'],
															'redirect_loc'		=> $IN['redirect_loc'],
															
												  )       );
												  
		$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" );
		
		
		
	}
	
	//------------------------------------------------------------------------------------------------
	//------------------------------------------------------------------------------------------------
	
	

	//+---------------------------------------------------------------------------------
	//
	// 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'] , "Category: ".$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("无法取得基于 ID {$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( "{none}"  , "40%" );
		$SKIN->td_header[] = array( "{none}"  , "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( "{none}"  , "40%" );
		$SKIN->td_header[] = array( "{none}"  , "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", $std->my_br2nl( $forum['description']) )
									     )      );
		
		$ADMIN->html .= $SKIN->end_table();
		
		//+-------------------------------
		
		$SKIN->td_header[] = array( "{none}"  , "40%" );
		$SKIN->td_header[] = array( "{none}"  , "60%" );
		
		$ADMIN->html .= $SKIN->start_table( "讨论区转向选项" );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>此讨论区要转至的 URL</b>" ,
												  $SKIN->form_input("redirect_url", $forum['redirect_url'])
										 )      );
										 
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>要转至的目标？</b><br>留空或使用 '_self' 在同一个浏览视窗载入" ,
												  $SKIN->form_input("redirect_loc", $forum['redirect_loc'])
										 )      );
										 
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>启用 URL 转向？</b><br>如果 '是' 您可以略过此表单剩余的部份，因为设定不会生效并且此讨论区的运作将会如同转向连结一般。启用之后目前所有的文章将无法被存取" ,
												  $SKIN->form_yes_no("redirect_on",
												 					 $forum['redirect_on'],
												  					  array(
												  					  		  '是' => " onclick=\"ShowHide('canpost', 'canpostoff');\" ",
												  					  		  '否'  => " onclick=\"ShowHide('canpost', 'canpostoff');\" "
												  					  	   )
												  					 )
										 )      );
										 
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>转向点按次数</b>" ,
												  $SKIN->form_input("redirect_hits", $forum['redirect_hits'])
										 )      );
										 
		$ADMIN->html .= $SKIN->end_table();
		
		//+-------------------------------
		
		
		if ($forum['parent_id'] > 0)
		{
			$extra = "<span id='normal' style='color:red'><br><b>注意</b>：这个讨论区并<b>不是</b>一个根讨论区，所以此选项将不会生效，除非您变更其父系到一个类别。</span>";
		}
		
		//+-------------------------------
		
		$SKIN->td_header[] = array( "{none}"  , "40%" );
		$SKIN->td_header[] = array( "{none}"  , "60%" );
		
		$cp2_show = $forum['redirect_on'] == 1 ? 'show' : 'none';
		$cp_show  = $forum['redirect_on'] == 1 ? 'none' : 'show';
		
		$ADMIN->html .= "\n<div id='canpost' style='display:$cp_show'>\n";
		
		$ADMIN->html .= $SKIN->start_table( "根讨论区选项：允许在此讨论区发表？" );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>允许在这个讨论区发表新主题与文章？</b><br>如果是，任何子讨论区将会显示在一般的主题列表上面，如果没有子讨论区可显示，会如常地显示主题列表。<br><b>如果 '否' 您可以略过这个表单剩下的部份，因为设定不会生效并且这个讨论区的作用将如同类别一般。</b>" ,
												  $SKIN->form_yes_no(
												  					  "sub_can_post",
												  					  $forum['sub_can_post'],
												  					  array(
												  					  		  '是' => " onclick=\"ShowHide('main_div', 'maindivoff');\" ",
												  					  		  '否'  => " onclick=\"ShowHide('main_div', 'maindivoff');\" "
												  					  	   )
												  					) . $extra
										 )      );
										 
		$ADMIN->html .= $SKIN->end_table();
		
		
		//+-------------------------------
		
		$md_show  = $forum['sub_can_post'] == 1 ? 'show' : 'none';
		$md2_show = $forum['sub_can_post'] == 1 ? 'none' : 'show';
		
		$SKIN->td_header[] = array( "{none}"  , "40%" );
		$SKIN->td_header[] = array( "{none}"  , "60%" );
		
		$ADMIN->html .= "\n<div id='main_div' style='display:$md_show'>\n";
		
		$ADMIN->html .= $SKIN->start_table( "可发表的讨论区设定" );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>允许使用 [doHTML] 标签？</b><br />可以使用 HTML 语法发表并执行" ,
												  $SKIN->form_yes_no("FORUM_HTML", $forum['use_html'] )
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>允许使用 IBF CODE 发表？</b>" ,
												  $SKIN->form_yes_no("FORUM_IBC", $forum['use_ibc'] )
									     )      );
									     
		//-----------
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>启用快速回复框？</b>" ,
												  $SKIN->form_yes_no("quick_reply", $forum['quick_reply'] )
									     )      );
									     
		$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'] )
									     )      );
		//金钱hack
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>此讨论区金钱设定数据</b>" ,
												  $SKIN->form_input("coef_money", $forum['coef_money'] )
									     )      );
									     
		//-----------
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>管制发表？</b><br>(需要板主手动将文章/主题加入讨论区)" ,
												  $SKIN->form_dropdown("MODERATE", array(
												  									 0 => array( 0, '否' ),
												  									 1 => array( 1, '管制所有新主题及所有回复' ),
												  									 2 => array( 2, '管制新主题但不要管制回复' ),
												  									 3 => array( 3, '管制回复但不要管制新主题' ),
												  									   ),
												  							    $forum['preview_posts'] )
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>需要密码进入？<br>在这里输入密码</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_table();
		
		$ADMIN->html .= "\n<!--END MAIN DIV--></div>\n
		                   <div id='maindivoff' class='offdiv' style='display:$md2_show'>
		                     <div class='tableborder'>
						       <div class='maintitle'><a href=\"javascript:ShowHide('main_div', 'maindivoff');\"><img src='{$SKIN->img_url}/plus.gif'></a>&nbsp;<a href=\"javascript:ShowHide('main_div', 'maindivoff');\">可发表的讨论区设定</a></div>
						     </div>
		                 </div><br />\n";
		                 
		                
		$ADMIN->html .= "\n<!--END CAN POST DIV--></div>\n
		                   <div id='canpostoff' style='display:$cp2_show'>
		                     <div class='tableborder'>
						       <div class='maintitle'><a href=\"javascript:ShowHide('canpost', 'canpostoff');\"><img src='{$SKIN->img_url}/plus.gif'></a>&nbsp;<a href=\"javascript:ShowHide('main_div', 'maindivoff');\">可发表的讨论区设定</a></div>
						     </div>
		                 </div><br />\n";
		
		$ADMIN->html .= $SKIN->end_form_standalone("编辑此讨论区");
		
		$ADMIN->nav[] = array( 'act=cat', '管理讨论区' );
		
		$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'       => $std->my_nl2br( $std->txt_stripslashes(str_replace( "'", "'", $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'],
															'coef_money'        => $IN['coef_money'], /*金钱hack*/ 
															'parent_id'         => $parent,
															'sub_can_post'      => $IN['sub_can_post'],
															'quick_reply'       => $IN['quick_reply'],
															'redirect_on'       => $IN['redirect_on'],
															'redirect_hits'     => $IN['redirect_hits'],
															'redirect_url'      => $IN['redirect_url'],
															'redirect_loc'		=> $IN['redirect_loc'],
															
												  )       );
												  
		$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" );
		
		
		
	}
	
	//+---------------------------------------------------------------------------------
	//
	// 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( "{none}"  , "40%" );
		$SKIN->td_header[] = array( "{none}"  , "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( "{none}"  , "40%" );
		$SKIN->td_header[] = array( "{none}"  , "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( "{none}"  , "40%" );
		$SKIN->td_header[] = array( "{none}"  , "60%" );
		
		$ADMIN->html .= $SKIN->start_table( "讨论区转向选项" );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>此讨论区要转至的 URL</b>" ,
												  $SKIN->form_input("redirect_url", $forum['redirect_url'])
										 )      );
										 
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>要转至的目标？</b><br>留空或使用 '_self' 在同一个浏览视窗载入" ,
												  $SKIN->form_input("redirect_loc", $forum['redirect_loc'])
										 )      );
										 
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>启用 URL 转向？</b><br>如果 '是' 您可以略过此表单剩余的部份，因为设定不会生效并且此讨论区的运作将会如同转向连结一般。启用之后目前所有的文章将无法被存取" ,
												  $SKIN->form_yes_no("redirect_on",
												 					 $forum['redirect_on'],
												  					  array(
												  					  		  '是' => " onclick=\"ShowHide('canpost', 'canpostoff');\" ",
												  					  		  '否'  => " onclick=\"ShowHide('canpost', 'canpostoff');\" "
												  					  	   )
												  					 )
										 )      );
										 
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>转向点按次数</b>" ,
												  $SKIN->form_input("redirect_hits", $forum['redirect_hits'])
										 )      );
										 
		$ADMIN->html .= $SKIN->end_table();
		
		//+-------------------------------
		
		$SKIN->td_header[] = array( "{none}"  , "40%" );
		$SKIN->td_header[] = array( "{none}"  , "60%" );
		
		$cp2_show = $forum['redirect_on'] == 1 ? 'show' : 'none';
		$cp_show  = $forum['redirect_on'] == 1 ? 'none' : 'show';
		
		$ADMIN->html .= "\n<div id='canpost' style='display:$cp_show'>\n";
		
		$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'],
												  					  array(
												  					  		  'yes' => " onclick=\"ShowHide('main_div', 'maindivoff');\" ",
												  					  		  'no'  => " onclick=\"ShowHide('main_div', 'maindivoff');\" "
												  					  	   )
												  					) . $extra
										 )      );
										 
		$ADMIN->html .= $SKIN->end_table();
		
		
		//+-------------------------------
		
		$md_show  = $forum['sub_can_post'] == 1 ? 'show' : 'none';
		$md2_show = $forum['sub_can_post'] == 1 ? 'none' : 'show';
		
		$SKIN->td_header[] = array( "{none}"  , "40%" );
		$SKIN->td_header[] = array( "{none}"  , "60%" );
		
		$ADMIN->html .= "\n<div id='main_div' style='display:$md_show'>\n";
		
		$ADMIN->html .= $SKIN->start_table( "可发表的讨论区设定" );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>允许使用 [doHTML] 标签？</b><br />可以使用 HTML 语法发表并执行" ,
												  $SKIN->form_yes_no("FORUM_HTML", $forum['use_html'] )
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>允许使用 IBF CODE 发表？</b>" ,
												  $SKIN->form_yes_no("FORUM_IBC", $forum['use_ibc'] )
									     )      );
									     
		//-----------
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>启用快速回复框？</b>" ,
												  $SKIN->form_yes_no("quick_reply", $forum['quick_reply'] )
									     )      );
									     
		$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'] )
									     )      );
		//金钱hack
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>此讨论区金钱设定数据</b>" ,
												  $SKIN->form_input("coef_money", $forum['coef_money'] )
									     )      );
									     
		//-----------
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>管制发表？</b><br>(需要板主手动将文章/主题加入讨论区)" ,
												  $SKIN->form_dropdown("MODERATE", array(
												  									 0 => array( 0, '否' ),
												  									 1 => array( 1, '管制所有新主题及所有回复' ),
												  									 2 => array( 2, '管制新主题但不要管制回复' ),
												  									 3 => array( 3, '管制回复但不要管制新主题' ),
												  									   ),
												  							    $forum['preview_posts'] )
									     )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>需要密码进入？<br>在这里输入密码</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_table();
		
		$ADMIN->html .= "\n<!--END MAIN DIV--></div>\n
		                   <div id='maindivoff' class='offdiv' style='display:$md2_show'>
		                     <div class='tableborder'>
						       <div class='maintitle'><a href=\"javascript:ShowHide('main_div', 'maindivoff');\"><img src='{$SKIN->img_url}/plus.gif'></a>&nbsp;<a href=\"javascript:ShowHide('main_div', 'maindivoff');\">可发表的讨论区设定</a></div>
						     </div>
						 <br />
		                 </div>\n";
		                 
		                
		$ADMIN->html .= "\n<!--END CAN POST DIV--></div>\n
		                   <div id='canpostoff' style='display:$cp2_show'>
		                     <div class='tableborder'>
						       <div class='maintitle'><a href=\"javascript:ShowHide('canpost', 'canpostoff');\"><img src='{$SKIN->img_url}/plus.gif'></a>&nbsp;<a href=\"javascript:ShowHide('main_div', 'maindivoff');\">可发表的讨论区设定</a></div>
						     </div>
		                 </div><br />\n";
		
		$ADMIN->html .= $SKIN->end_form_standalone("编辑此讨论区");
		
		$ADMIN->nav[] = array( 'act=cat', '管理讨论区' );
		
		$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'      => $std->my_nl2br( $std->txt_stripslashes(str_replace( "'", "'", $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'],
															'coef_money'        => $IN['coef_money'], /*金钱hack*/
															'quick_reply'       => $IN['quick_reply'],
															'redirect_on'       => $IN['redirect_on'],
															'redirect_hits'     => $IN['redirect_hits'],
															'redirect_url'      => $IN['redirect_url'],
															'redirect_loc'		=> $IN['redirect_loc'],
															
												  )       );
												  
		$DB->query("UPDATE ibf_forums SET $db_string WHERE id='".$IN['f']."'");
		
		$ADMIN->save_log("已编辑子讨论区 '{$IN['FORUM_NAME']}'");
		
		$ADMIN->done_screen("讨论区已编辑", "讨论区控制", "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 = "<b>讨论区存取权限</b><br>(勾选方块核准权限，取消勾选撤销权限)<br>如果您拒绝一个群组的读取权限，他们将无法看见该讨论区。";
		
		//+-------------------------------
		
		$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( "名称"  , "40%" );
		$SKIN->td_header[] = array( "读取"  , "15%" );
		$SKIN->td_header[] = array( "回复" , "15%" );
		$SKIN->td_header[] = array( "发起" , "15%" );
		$SKIN->td_header[] = array( "上传", "15%" );
		
		$ADMIN->html .= $SKIN->start_table("存取权限等级");
		
		$ADMIN->html .= $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" );
		
		
		
	}
	
		
}


?>
