<?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
+---------------------------------------------------------------------------
|
|   > Help Control functions
|   > Module written by Matt Mecham
|   > Date started: 2nd April 2002
|
|	> Module Version Number: 1.0.0
+--------------------------------------------------------------------------
*/




$idx = new ad_settings();


class ad_settings {

	var $base_url;

	function ad_settings() {
		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 'edit':
				$this->show_form('edit');
				break;
			case 'new':
				$this->show_form('new');
				break;
			
			case 'doedit':
				$this->doedit();
				break;
				
			case 'donew':
				$this->doadd();
				break;
				
			case 'remove':
				$this->remove();
				break;
			
			//-------------------------
			default:
				$this->list_files();
				break;
		}
		
	}
	
	//-------------------------------------------------------------
	// HELP FILE FUNCTIONS
	//-------------------------------------------------------------
	
	function doedit()
	{
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_POST_VARS;
		
		if ($IN['id'] == "")
		{
			$ADMIN->error("你必须提供有效的表情符号ID！");
		}
		
		$text  = preg_replace( "/\n/", "<br>", stripslashes($HTTP_POST_VARS['text'] ) );
		$title = preg_replace( "/\n/", "<br>", stripslashes($HTTP_POST_VARS['title'] ) );
		$desc  = preg_replace( "/\n/", "<br>", stripslashes($HTTP_POST_VARS['description'] ) );
		
		$db_string = $DB->compile_db_update_string( array( 'title'       => $title,
														   'text'        => $text,
														   'description' => $desc,
												  )      );
												  
		$DB->query("UPDATE ibf_faq SET $db_string WHERE id='".$IN['id']."'");
		
		$ADMIN->save_log("编辑帮助文件");
		
		$std->boink_it($SKIN->base_url."&act=help");
		exit();
			
		
	}
	
	//=====================================================
	
	
	function show_form($type='new')
	{
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
	
		$ADMIN->page_detail = "你可以在下面 添加/编辑/删除 帮助文件。";
		$ADMIN->page_title  = "帮助文件管理";
		
		//+-------------------------------
		
		if ($type != 'new')
		{
		
			if ($IN['id'] == "")
			{
				$ADMIN->error("你必须提供有效的帮助文件！");
			}
		
			//+-------------------------------
		
			$DB->query("SELECT * FROM ibf_faq WHERE id='".$IN['id']."'");
		
			if ( ! $r = $DB->fetch_row() )
			{
				$ADMIN->error("法在数据库中找到相关帮助信息文件");
			}
		
			//+-------------------------------
			
			$button = '编辑帮助文件';
			$code   = 'doedit';
		}
		else
		{
			$r = array();
			$button = '添加帮助文件';
			$code   = 'donew';
		}
		
		$ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , $code ),
												  2 => array( 'act'   , 'help'     ),
												  3 => array( 'id'    , $IN['id'] ),
									     )      );
		
		
		
		$SKIN->td_header[] = array( "&nbsp;"  , "20%" );
		$SKIN->td_header[] = array( "&nbsp;"  , "80%" );
		
		$r['text'] = preg_replace( "/<br>/i", "\n", stripslashes($r['text']) );
 		
 		//+-------------------------------
		
		$ADMIN->html .= $SKIN->start_table( $button );
		
		
		$ADMIN->html .= $SKIN->add_td_row( array( "帮助文件名称：",
												  $SKIN->form_input('title'  , stripslashes($r['title']) ),
										 )      );
										 
		$ADMIN->html .= $SKIN->add_td_row( array( "帮助文件叙述：",
												  $SKIN->form_textarea('description', stripslashes($r['description']) ),
										 )      );
										 
		$ADMIN->html .= $SKIN->add_td_row( array( "帮助文件内容：",
												  $SKIN->form_textarea('text', $r['text'], "60", "10" ),
										 )      );
										 
		$ADMIN->html .= $SKIN->end_form($button);
										 
		$ADMIN->html .= $SKIN->end_table();
		
		$ADMIN->output();
	
	}
	
	//=====================================================
	
	function remove()
	{
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
		
		if ($IN['id'] == "")
		{
			$ADMIN->error("你必须提供有效的帮助文件！");
		}
		
		$DB->query("DELETE FROM ibf_faq WHERE id='".$IN['id']."'");
		
		$ADMIN->save_log("删除帮助文件");
		
		$std->boink_it($SKIN->base_url."&act=help");
		exit();
			
		
	}
	
	//=====================================================
	
	function doadd()
	{
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_POST_VARS;
		
		if ($IN['title'] == "")
		{
			$ADMIN->error("你必须输入帮助文件名称！");
		}
		
		
		
		$text  = preg_replace( "/\n/", "<br>", stripslashes($HTTP_POST_VARS['text'] ) );
		$title = preg_replace( "/\n/", "<br>", stripslashes($HTTP_POST_VARS['title'] ) );
		$desc  = preg_replace( "/\n/", "<br>", stripslashes($HTTP_POST_VARS['description'] ) );
		
		$db_string = $DB->compile_db_insert_string( array( 'title'       => $title,
														   'text'        => $text,
														   'description' => $desc,
												  )      );
												  
		$DB->query("INSERT INTO ibf_faq (".$db_string['FIELD_NAMES'].") VALUES(".$db_string['FIELD_VALUES'].")");
		
		$ADMIN->save_log("添加帮助文件");
		
		$std->boink_it($SKIN->base_url."&act=help");
		exit();
			
		
	}
	
	//=====================================================
	
	function list_files()
	{
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
	
		$ADMIN->page_detail = "你可以在下面 添加/编辑/删除 帮助文件。";
		$ADMIN->page_title  = "帮助文件管理";
		
		//+-------------------------------
		
		$SKIN->td_header[] = array( "帮助文件名称"  , "50%" );
		$SKIN->td_header[] = array( "编辑"   , "30%" );
		$SKIN->td_header[] = array( "删除" , "20%" );
		
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->start_table( "当前使用的帮助文件" );
		
		$DB->query("SELECT * from ibf_faq ORDER BY id ASC");
		
		if ( $DB->get_num_rows() )
		{
			while ( $r = $DB->fetch_row() )
			{
				
				$ADMIN->html .= $SKIN->add_td_row( array( "<b>".stripslashes($r['title'])."</b><br>".stripslashes($r['description']),
														  "<center><a href='".$SKIN->base_url."&act=help&code=edit&id={$r['id']}'>编辑</a></center>",
														  "<center><a href='".$SKIN->base_url."&act=help&code=remove&id={$r['id']}'>删除</a></center>",
												 )      );
												   
			
				
			}
		}
		
		$ADMIN->html .= $SKIN->add_td_basic("<a href='".$SKIN->base_url."&act=help&code=new'>添加帮助文件</a>", "center", "title" );
		
		$ADMIN->html .= $SKIN->end_table();
		
		//+-------------------------------
		
		$ADMIN->output();
	
	}
	
	
}


?>