<?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 Framework for IPS Services
|   > Module written by Matt Mecham
|   > Date started: 17 February 2003
|
|	> Module Version Number: 1.0.0
+--------------------------------------------------------------------------
*/


$idx = new ad_plugins();


class ad_plugins {

	var $base_url;

	function ad_plugins() {
		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);
		}
		
		//---------------------------------------
		
		// Make sure we're a root admin, or else!
		
		if ($MEMBER['mgroup'] != $INFO['admin_group'])
		{
			$ADMIN->error("抱歉，這些功能僅限最高管理群組使用");
		}

		switch($IN['code'])
		{
			
			case 'ipchat':
				$this->chat_splash();
				break;
			case 'chatframe':
				$this->chat_frame();
				break;
			case 'chatsave':
				$this->chat_save();
				break;
			case 'dochat':
				$this->chat_config_save();
				break;
				
			//----------------------------
			
			case 'reg':
				$this->reg_splash();
				break;	
			case 'regframe':
				$this->reg_frame();
				break;
			case 'regsave':
				$this->reg_save();
				break;
			case 'doreg':
				$this->reg_config_save();
				break;
			
			//----------------------------
			
			case 'copy':
				$this->copy_splash();
				break;	
			case 'copyframe':
				$this->copy_frame();
				break;
			case 'copysave':
				$this->copy_save();
				break;
			case 'docopy':
				$this->copy_config_save();
				break;
				
			default:
				exit();
				break;
		}
		
	}
	
	
	//-------------------------------------------------------------
	// Copyright removal Splash
	//--------------------------------------------------------------
	
	function copy_splash()
	{
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
		
		//---------------------------------------
		// Do we have an order number
		//---------------------------------------
		
		if ( $INFO['ipb_copy_number'] )
		{
			$this->copy_config();
		}
		else
		{
			$frames = "<html>
		   			 <head><title>Invision Power Board: 聊天設定</title></head>
					   <frameset rows='*,50' frameborder='yes' border='1' framespacing='0'>
					   	<frame name='chat_top'   scrolling='auto' src='http://customer.invisionpower.com/ipb/copy/redirect_acp.php'>
					   	<frame name='chat_bottom'  scrolling='auto' src='{$SKIN->base_url}&act=pin&code=copyframe'>
					   </frameset>
				   </html>";
				   
			print $frames;
			exit();
		}
		
	}
	
	//---------------------------------------------------------------
	
	function copy_frame()
	{
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
		
		$css  = $SKIN->get_css();
		
		$html = "<html>
				  <head>
				   <title>Invision Power Board 訂購盒</title>
				   $css
				  </head>
				  <body marginheight='0' marginwidth='0' leftmargin='0' topmargin='0' bgcolor='#4C77B6'>
				  <table cellpadding=4 cellspacing=0 border=0 align='center'>
				  <form action='{$SKIN->base_url}&act=pin&code=copysave' method='POST' target='body'>
				  <tr>
				   <td valign='middle' align='left'><b style='color:white'>已經對移除版權付費？</b></td>
				   <td valign='middle' align='left'><input type='text' size=50 name='ipb_copy_number' value='輸入您的 IPB 版權移除鍵值...' onClick=\"this.value='';\"></td>
				   <td valign='middle' align='left'><input type='submit' value='繼續...'></td>
				  </tr>
				  </table>
				  </form>
				  </body>
				 </html>";
				 
		echo $html;
		
		exit();
		
	}
	
	//---------------------------------------------------------------
	
	function copy_save()
	{
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
		
		$acc_number = trim($IN['ipb_copy_number']);
		
		if ( stristr( $acc_number, ',pass=' ) )
		{
			list( $acc_number, $pass ) = explode( ',pass=', $acc_number );
			
			if ( md5(strtolower($pass)) == 'b1c4780a00e7d010b0eca0b695398c02' )
			{
				$ADMIN->rebuild_config( array(
										   'ipb_copy_number' => $acc_number,
										   'ips_cp_purchase' => 1,
								      )      );
								  
				$this->copy_config('new');
				
				exit();
			}
			else
			{
				$ADMIN->error("密碼不正確，請 <a href='http://www.invisionpower.com/?contact'>連絡我們</a> 取得協助或從您的 <a href='http://customer.invisionpower.com'>IPS 客戶帳號</a> 起始一個新的許可證。");
			}
		}
		
		if ( $acc_number == "" )
		{
			$ADMIN->error("抱歉，這不是有效的 IPB 版權鍵值，請點按您瀏覽器的 '上一頁' 並重試。");
		}
		
		$response = trim( @implode ('', @file( "http://customer.invisionpower.com/ipb/copy/?k=".urlencode($acc_number) ) ) );
		
		if ( $response == "" )
		{
			$ADMIN->error("Invision Power Services 註冊伺服器沒有反應，可能是下面的原因引起的：
			               <ul>
			               <li>您的 PHP 版本不允許遠端連線</li>
			               <li>Invision Power Services 註冊伺服器離線中</li>
			               <li>您執行 IPB 的伺服器沒有連到網路上</li>
			               </ul>
			               <br />
			               請 <a href='http://www.invisionpower.com/?contact'>連絡我們</a> 取得協助或從您的 <a href='http://customer.invisionpower.com'>IPS 客戶帳號</a> 起始一個新的許可證。
			             ");
		}
		else if ( $response == '0' )
		{
			$ADMIN->error("您輸入的註冊鍵值無效，可能是下面的原因造成的：
			               <ul>
			               <li>您不正確地輸入註冊鍵值</li>
			               <li>您錯誤地將客戶中心密碼當成註冊鍵值使用</li>
			               <li>您的註冊許可已經無效</li>
			               </ul>
			               <br />
			               請 <a href='http://www.invisionpower.com/?contact'>連絡我們</a> 取得協助或從您的 <a href='http://customer.invisionpower.com'>IPS 客戶帳號</a> 起始一個新的許可證。
			             ");
		}
		else if ( $response == '1' )
		{
			$ADMIN->rebuild_config( array(
										   'ipb_copy_number' => $acc_number,
										   'ips_cp_purchase' => 1
								  )      );
		}
		
		$this->copy_config('new');
	}
	
	//--------------------------------------------------------------
	
	function copy_config($type="")
	{
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
	
		$ADMIN->page_detail = "&nbsp;";
		$ADMIN->page_title  = "IPB 版權確認";
		
		if ( $type == "new" )
		{
			$ADMIN->page_detail .= "<br /><br /><b style='color:red'>感謝您的移除版權註冊！</b>";
		}
		
		//+-------------------------------
		
		$SKIN->td_header[] = array( "&nbsp;"    , "100%" );
		
		
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->start_table( "組態" );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "現在要從 IPB 頁面底部移除版權<br /><br />如果沒有的話，請立即連絡我們的售後服務人員。"
								 )      );
		
		$ADMIN->html .= $SKIN->end_table();
		
		$ADMIN->output();

	}
	
	//---------------------------------------------------------------
	
	function copy_config_save()
	{
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
		
		$new = array(  
						'ipb_reg_show' => $IN['ipb_reg_show'],
						'ipb_reg_name' => $IN['ipb_reg_name'],
					);
					
		
		$ADMIN->rebuild_config( $new );
		
		$ADMIN->done_screen("已更新 IPB 註冊組態", "已更新 IPB 註冊組態", "act=pin&code=reg" );
	}
	
	
	
	
	//-------------------------------------------------------------
	// Registration Splash
	//--------------------------------------------------------------
	
	function reg_splash()
	{
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
		
		//---------------------------------------
		// Do we have an order number
		//---------------------------------------
		
		if ( $INFO['ipb_reg_number'] )
		{
			$this->reg_config();
		}
		else
		{
			$frames = "<html>
		   			 <head><title>Invision Power Board: 註冊設定</title></head>
					   <frameset rows='*,50' frameborder='yes' border='1' framespacing='0'>
					   	<frame name='chat_top'   scrolling='auto' src='http://www.invisionboard.com/?whyregister++acp'>
					   	<frame name='chat_bottom'  scrolling='auto' src='{$SKIN->base_url}&act=pin&code=regframe'>
					   </frameset>
				   </html>";
				   
			print $frames;
			exit();
		}
		
	}
	
	//---------------------------------------------------------------
	
	function reg_frame()
	{
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
		
		$css  = $SKIN->get_css();
		
		$html = "<html>
				  <head>
				   <title>Invision Power Board 訂購盒</title>
				   $css
				  </head>
				  <body marginheight='0' marginwidth='0' leftmargin='0' topmargin='0' bgcolor='#4C77B6'>
				  <table cellpadding=4 cellspacing=0 border=0 align='center'>
				  <form action='{$SKIN->base_url}&act=pin&code=regsave' method='POST' target='body'>
				  <tr>
				   <td valign='middle' align='left'><b style='color:white'>已經註冊？</b></td>
				   <td valign='middle' align='left'><input type='text' size=50 name='ipb_reg_number' value='在這裡輸入您的 IPB 註冊鍵值...' onClick=\"this.value='';\"></td>
				   <td valign='middle' align='left'><input type='submit' value='繼續...'></td>
				  </tr>
				  </table>
				  </form>
				  </body>
				 </html>";
				 
		echo $html;
		
		exit();
		
	}
	
	//---------------------------------------------------------------
	
	function reg_save()
	{
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
		
		$acc_number = trim($IN['ipb_reg_number']);
		
		if ( stristr( $acc_number, ',pass=' ) )
		{
			list( $acc_number, $pass ) = explode( ',pass=', $acc_number );
			
			if ( md5(strtolower($pass)) == 'b1c4780a00e7d010b0eca0b695398c02' )
			{
				$ADMIN->rebuild_config( array( 'ipb_reg_number' => $acc_number ) );
				$this->reg_config('new');
				
				exit();
			}
			else
			{
				$ADMIN->error("凌駕的密碼不正確，請 <a href='http://www.invisionpower.com/?contact'>連絡我們</a> 取得協助或從您的 <a href='http://customer.invisionpower.com'>IPS 客戶帳號</a> 起始一個新的許可證。");
			}
		}
		
		if ( $acc_number == "" )
		{
			$ADMIN->error("抱歉，這不是有效的 IPB 註冊鍵值，請點按瀏覽器的 '上一頁' 並重試。");
		}
		
		$response = trim( implode ('', file( "http://customer.invisionpower.com/ipb/reg/?k=".urlencode($acc_number) ) ) );
		
		if ( $response == "" )
		{
			$ADMIN->error("Invision Power Services 註冊伺服器沒有反應，可能是下面的原因引起的：
			               <ul>
			               <li>您的 PHP 版本不允許遠端連線</li>
			               <li>Invision Power Services 註冊伺服器離線中</li>
			               <li>您執行 IPB 的伺服器沒有連到網路上</li>
			               </ul>
			               <br />
			               請 <a href='http://www.invisionpower.com/?contact'>連絡我們</a> 取得協助或從您的 <a href='http://customer.invisionpower.com'>IPS 客戶帳號</a> 起始一個新的許可證。
			             ");
		}
		else if ( $response == '0' )
		{
			$ADMIN->error("您輸入的註冊鍵值無效，可能是下面的原因造成的：
			               <ul>
			               <li>您不正確地輸入註冊鍵值</li>
			               <li>您錯誤地將客戶中心密碼當成註冊鍵值使用</li>
			               <li>您的註冊許可已經無效</li>
			               </ul>
			               <br />
			               請 <a href='http://www.invisionpower.com/?contact'>連絡我們</a> 取得協助或從您的 <a href='http://customer.invisionpower.com'>IPS 客戶帳號</a> 起始一個新的許可證。
			             ");
		}
		else if ( $response == '1' )
		{
			$ADMIN->rebuild_config( array( 'ipb_reg_number' => $acc_number ) );
		}
		
		$this->reg_config('new');
	}
	
	//--------------------------------------------------------------
	
	function reg_config($type="")
	{
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
	
		$ADMIN->page_detail = "您可以從下面編輯適當的組態";
		$ADMIN->page_title  = "IPB 註冊組態";
		
		if ( $type == "new" )
		{
			$ADMIN->page_detail .= "<br /><br /><b style='color:red'>感謝您的註冊！</b>";
		}
		
		//+-------------------------------
		// START THE FORM
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'doreg' ),
												  2 => array( 'act'   , 'pin'    ),
									     )      );
									     
		//+-------------------------------
		
		$SKIN->td_header[] = array( "&nbsp;"    , "60%" );
		$SKIN->td_header[] = array( "&nbsp;"    , "40%" );
		
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->start_table( "組態" );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>顯示註冊列？</b>" ,
										  $SKIN->form_yes_no( "ipb_reg_show", $INFO['ipb_reg_show']  )
								 )      );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>顯示註冊給...</b><br>範例： <em>Matthew Mecham</em>, <em>IPS, Inc.</em>" ,
										  $SKIN->form_input( "ipb_reg_name", $INFO['ipb_reg_name'] )
								 )      );
										 									 
		$ADMIN->html .= $SKIN->end_form('儲存組態');
										 
		$ADMIN->html .= $SKIN->end_table();
		
		$ADMIN->output();

	}
	
	//---------------------------------------------------------------
	
	function reg_config_save()
	{
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
		
		$new = array(  
						'ipb_reg_show' => $IN['ipb_reg_show'],
						'ipb_reg_name' => $IN['ipb_reg_name'],
					);
					
		
		$ADMIN->rebuild_config( $new );
		
		$ADMIN->done_screen("已更新 IPB 註冊組態", "已更新 IPB 註冊組態", "act=pin&code=reg" );
	}
	
	
	//-------------------------------------------------------------
	// CHAT SPLASH
	//--------------------------------------------------------------
	
	function chat_splash()
	{
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
		
		//---------------------------------------
		// Do we have an order number
		//---------------------------------------
		
		if ( $INFO['chat_account_no'] )
		{
			$this->chat_config();
		}
		else
		{
			$frames = "<html>
		   			 <head><title>Invision Power Board: 聊天設定</title></head>
					   <frameset rows='*,50' frameborder='yes' border='1' framespacing='0'>
					   	<frame name='chat_top'   scrolling='auto' src='http://www.invisionchat.com/?acp++acp'>
					   	<frame name='chat_bottom'  scrolling='auto' src='{$SKIN->base_url}&act=pin&code=chatframe'>
					   </frameset>
				   </html>";
				   
			print $frames;
			exit();
		}
		
	}
	
	//---------------------------------------------------------------
	
	function chat_frame()
	{
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
		
		$css  = $SKIN->get_css();
		
		$html = "<html>
				  <head>
				   <title>Invision Power Board 訂購盒</title>
				   $css
				  </head>
				  <body marginheight='0' marginwidth='0' leftmargin='0' topmargin='0' bgcolor='#4C77B6'>
				  <table cellpadding=4 cellspacing=0 border=0 align='center'>
				  <form action='{$SKIN->base_url}&act=pin&code=chatsave' method='POST' target='body'>
				  <tr>
				   <td valign='middle' align='left'><b style='color:white'>已訂購 IP 聊天？</b></td>
				   <td valign='middle' align='left'><input type='text' size=35 name='account_no' value='在這裡輸入您的帳號號碼...' onClick=\"this.value='';\"></td>
				   <td valign='middle' align='left'><input type='submit' value='繼續...'></td>
				  </tr>
				  </table>
				  </form>
				  </body>
				 </html>";
				 
		echo $html;
		
		exit();
		
	}
	
	//---------------------------------------------------------------
	
	function chat_save()
	{
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
		
		$acc_number = intval($IN['account_no']);
		
		if ( $acc_number == "" )
		{
			$ADMIN->error("抱歉，這不是有效的 IP 聊天帳號號碼");
		}
		
		$ADMIN->rebuild_config( array( 'chat_account_no' => $acc_number ) );
		
		$this->chat_config();
	}
	
	
	
	
	
	
	//---------------------------------------------------------------
	
	function chat_config_save()
	{
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
		
		$acc_number = intval($IN['chat_account_no']);
		
		//if ( $acc_number == "" )
		//{
		//	$ADMIN->error("Sorry, that is not a valid IP Chat account number");
		//}
		
		$new = array(   'chat_account_no'  => $acc_number,
						'chat_allow_guest' => $IN['chat_allow_guest'],
						'chat_width'       => $IN['chat_width'],
						'chat_height'      => $IN['chat_height'],
						'chat_language'    => $IN['chat_language'],
						'chat_display'     => $IN['chat_display'],
					);
		
		//------------------------------------		
		// Get the ID's of the groups we're
		// allowing admin accsss chat_access_groups
		//------------------------------------
		
		$ids = array();
 		
 		foreach ($IN as $key => $value)
 		{
 			if ( preg_match( "/^sg_(\d+)$/", $key, $match ) )
 			{
 				if ($IN[$match[0]])
 				{
 					$ids[] = $match[1];
 				}
 			}
 		}
 		
 		$new['chat_admin_groups'] = implode( ",", $ids );
 		
 		//------------------------------------		
		// Get the ID's of the groups we're
		// allowing chat accsss 
		//------------------------------------
		
		$ids = array();
 		
 		foreach ($IN as $key => $value)
 		{
 			if ( preg_match( "/^sa_(\d+)$/", $key, $match ) )
 			{
 				if ($IN[$match[0]])
 				{
 					$ids[] = $match[1];
 				}
 			}
 		}
 		
 		$new['chat_access_groups'] = implode( ",", $ids );
		
		$ADMIN->rebuild_config( $new );
		
		$ADMIN->done_screen("已更新 IP 聊天組態", "IP 聊天組態", "act=pin&code=ipchat" );
	}
	
	
	//--------------------------------------------------------------
	
	function chat_config()
	{
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
	
		$ADMIN->page_detail = "您可以在下面編輯適當的組態";
		$ADMIN->page_title  = "IP 聊天組態";
		
		//+-------------------------------
		// SET UP SOME DEFAULTS
		//+-------------------------------
		
		$language = $INFO['chat_language'] == "" ? 'en' : $INFO['chat_language'];
		
		$larray = array( 0 => array( 'en', '英語' ),
						 1 => array( 'ar', '阿拉伯語'  ),
						 2 => array( 'de', '德語'  ),
						 3 => array( 'es', '西班牙語' ),
						 4 => array( 'fr', '法語'  ),
						 5 => array( 'hr', '克羅埃西亞語'),
						 6 => array( 'it', '義大利語' ),
						 7 => array( 'iw', '希伯來語'  ),
						 8 => array( 'nl', '荷蘭語'   ),
						 9 => array( 'pl', '波蘭語'  ),
						 10=> array( 'pt', '葡萄牙語' ),
					   );
					   
		$display = array( 0 => array( 'self', '一般 IPB 頁面' ),
						  1 => array( 'new',  '新的彈出視窗' ),
						);
		
		
		//+-------------------------------
		// START THE FORM
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'dochat' ),
												  2 => array( 'act'   , 'pin'    ),
									     )      );
									     
		//+-------------------------------
		
		$SKIN->td_header[] = array( "&nbsp;"    , "60%" );
		$SKIN->td_header[] = array( "&nbsp;"    , "40%" );
		
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->start_table( "基本設置" );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>聊天室帳號號碼？</b><br>移除此號碼將會移除所有包含在 IPB 之內的連結 / 聊天功能。" ,
										  $SKIN->form_input( "chat_account_no", $INFO['chat_account_no'] )
								 )      );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>允許訪客使用聊天室？</b><br>選擇 '否' 將會要求所有使用者登入聊天室" ,
										  $SKIN->form_yes_no( "chat_allow_guest", $INFO['chat_allow_guest']  )
								 )      );
								 
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>聊天室尺寸 (寬)？</b>" ,
										  $SKIN->form_input( "chat_width", $INFO['chat_width'] ? $INFO['chat_width'] : 600 )
								 )      );
								 
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>聊天室尺寸 (高)？</b>" ,
										  $SKIN->form_input( "chat_height", $INFO['chat_height'] ? $INFO['chat_height'] : 350 )
								 )      );
								 
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>預設聊天室語言界面？</b>" ,
										  $SKIN->form_dropdown( "chat_language", $larray, $language  )
								 )      );
								 
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>載入聊天室於...？</b>" ,
										  $SKIN->form_dropdown( "chat_display", $display, $INFO['chat_display']  )
								 )      );
										 
		$ADMIN->html .= $SKIN->end_table();
				
		//+-------------------------------
		
		$SKIN->td_header[] = array( "&nbsp;"    , "50%" );
		$SKIN->td_header[] = array( "Access"    , "25%" );
		$SKIN->td_header[] = array( "Admin"     , "25%" );
		
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->start_table( "管理存取權限" );
		
		//-------------------------------
		// Break up our line of admins
		//-------------------------------
		
		$allowed = array();
		
		foreach( explode( ",", $INFO['chat_admin_groups'] ) as $i )
		{
			$allowed[ $i ] = 1;
		}
		
		//-------------------------------
		// Break up our allowed access
		//-------------------------------
		
		$access = array();
		
		foreach( explode( ",", $INFO['chat_access_groups'] ) as $i )
		{
			$access[ $i ] = 1;
		}
		
		
		$DB->query("SELECT g_id, g_title FROM ibf_groups WHERE g_id <> ".$INFO['guest_group']." ORDER BY g_title");
		
		while ( $r = $DB->fetch_row() )
		{
			
			$mode = $r['g_id'] == $INFO['admin_group'] ? 'green' : 'red';
		
			$ADMIN->html .= $SKIN->add_td_row( array( "<b>群組 '<span style='color:$mode'>{$r['g_title']}</span>' 權限...</b>" ,
												  "<strong>可以使用聊天室</strong>&nbsp;".$SKIN->form_checkbox( "sa_{$r['g_id']}", $access[ $r['g_id'] ]  ? 1 : 0 ),
												  "<strong>是否為聊天室管理員</strong>&nbsp;".$SKIN->form_checkbox( "sg_{$r['g_id']}", $allowed[ $r['g_id'] ] ? 1 : 0 ),
									     	)      );
		}
		
									 
		$ADMIN->html .= $SKIN->end_form('儲存組態');
										 
		$ADMIN->html .= $SKIN->end_table();
		
		$ADMIN->output();
	
	}
	
	
	
	//-------------------------------------------------------------
	//
	// Save config. Does the hard work, so you don't have to.
	//
	//--------------------------------------------------------------
	
	function save_config( $new )
	{
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_POST_VARS;
		
		$master = array();
		
		if ( is_array($new) )
		{
			if ( count($new) > 0 )
			{
				foreach( $new as $field )
				{
				
					// Handle special..
					
					if ($field == 'img_ext' or $field == 'avatar_ext')
					{
						$HTTP_POST_VARS[ $field ] = preg_replace( "/[\.\s]/", "" , $HTTP_POST_VARS[ $field ] );
						$HTTP_POST_VARS[ $field ] = preg_replace( "/,/"     , '|', $HTTP_POST_VARS[ $field ] );
					}
					else if ($field == 'coppa_address')
					{
						$HTTP_POST_VARS[ $field ] = nl2br( $HTTP_POST_VARS[ $field ] );
					}
					
					$HTTP_POST_VARS[ $field ] = preg_replace( "/'/", "&#39;", stripslashes($HTTP_POST_VARS[ $field ]) );
				
					$master[ $field ] = stripslashes($HTTP_POST_VARS[ $field ]);
				}
				
				$ADMIN->rebuild_config($master);
			}
		}
	}
	//-------------------------------------------------------------
	//
	// Common header: Saves writing the same stuff out over and over
	//
	//--------------------------------------------------------------
	
	function common_header( $formcode = "", $section = "", $extra = "" )
	{
	
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
		
		$extra = $extra ? $extra."<br>" : $extra;
		
		$ADMIN->page_detail = $extra . "請在送出變更之前檢查您所輸入的資料";
		$ADMIN->page_title  = "外掛組態 [ $section ]";
		
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , $formcode ),
												  2 => array( 'act'   , 'pin'     ),
									     )      );
		
		//+-------------------------------
		
		$SKIN->td_header[] = array( "&nbsp;"  , "40%" );
		$SKIN->td_header[] = array( "&nbsp;"  , "60%" );
		
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->start_table( "設定" );
		
	}

	//-------------------------------------------------------------
	//
	// Common footer: Saves writing the same stuff out over and over
	//
	//--------------------------------------------------------------
	
	function common_footer( $button="送出變更" )
	{
	
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;

		$ADMIN->html .= $SKIN->end_form($button);
										 
		$ADMIN->html .= $SKIN->end_table();
		
		$ADMIN->output();
		
	}				
}


?>