<?php
/*
// ------------------------------------------------------------------------
-+ Date: 27-May-2004
-+ Version: 1.4e
-+ ========================================
-+ Made by Koudanshi
-+ E-mail: koudanshi@gmx.net
-+ Homepage: bbpixel.com
-+ ========================================
-+ Any Problems please email me,
-+ ========================================
\\ ------------------------------------------------------------------------
*/

if ( ! defined( 'IN_ACP' ) )
{
	print "<h1>您沒有權限瀏覽此頁</h1>您不能夠直接瀏覽這個網頁內容。如果你最近進行升級，確定您已升級 'admin.php'。";
	exit();
}


$idx = new ad_xbb();

class ad_xbb {

	function ad_xbb() {
		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 'xset':
				$this->xset();
				break;
			case 'doxset':
				$this->save_config( array ( 'xbbc_ucp', 'xbbc_reg', 'xbbc_wrap', 'xbbc_redirect','xbbc_popup', 'xbbc_uname_len','xbbc_charset', 'xbbc_ag' ) );
				break;
			//-------------------------
			default:
				exit();
				break;
		}

	}

	function xset()
	{
		global $IN, $INFO, $SKIN, $ADMIN, $DB;
		$ADMIN->page_title = "XOOPS 整合設定";

		$ADMIN->page_detail = "在這個部分您可以選擇部分 XOOPS 與 IPBM 共同的設定應該交由何者指派,部分功能諸如註冊系統的選擇以及編輯/檢視會員資料連結...等都可在此設定.";
		//+-------------------------------

		$ADMIN->html .= $SKIN->start_form( 
		                array( 1 => array( 'code'  , 'doxset'),
											  	 2 => array( 'act'  , 'xbb'    )
											) );

		//+-------------------------------

		$SKIN->td_header[] = array( "&nbsp;"  , "50%" );
		$SKIN->td_header[] = array( "&nbsp;"  , "50%" );

		//+-------------------------------

		$ADMIN->html .= $SKIN->start_table( "整合設定項目" );
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>繼續使用 XOOPS 來觀看/編輯會員帳號?</b><br>觀看/編輯 帳號連結交由 XOOPS 請選是,使用 IPBM 連結請選否." ,
										  $SKIN->form_yes_no( "xbbc_ucp", $INFO['xbbc_ucp']  )
								 )      );

		$ADMIN->html .= $SKIN->add_td_row( array( "<b>繼續使用 XOOPS 會員註冊系統?</b><br>交由 XOOPS 選擇是,若交由 IPBM 請選否.</b>" ,
										  $SKIN->form_yes_no( "xbbc_reg", $INFO['xbbc_reg']  )
								 )      );

		$ADMIN->html .= $SKIN->add_td_row( array( "<b>套用 XOOPS 佈景?</b><br>選否將會在瀏覽討論區時不呈現 XOOPS 中的頭.尾及左右區塊</b>" ,
										  $SKIN->form_yes_no( "xbbc_wrap", $INFO['xbbc_wrap']  )
								 )      );

		$ADMIN->html .= $SKIN->add_td_row( array( "<b>顯示 IPB 頁面轉向提示訊息?</b><br>例如\"請稍後,正在為您轉換頁面\"的訊息畫面.</b>" ,
										  $SKIN->form_yes_no( "xbbc_redirect", $INFO['xbbc_redirect']  )
								 )      );
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>瀏覽 最新/熱門/人氣主題區塊聯結是否另開視窗?</b><br>當點選主題連結時會以新視窗開啟.</b>" ,
										  $SKIN->form_yes_no( "xbbc_popup", $INFO['xbbc_popup']  )
								 )      );
    if (empty($INFO['xbbc_uname_len'])) {
      $INFO['xbbc_uname_len'] = "15";
    }
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>會員名稱允許最大字元數?</b><br>一個中文字是兩個字元." ,
												  $SKIN->form_input("xbbc_uname_len", $INFO['xbbc_uname_len'])
									     )      );
    
    if (empty($INFO['xbbc_charset'])) {
      $INFO['xbbc_charset'] = "big5";
    }
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>使用語系編碼類型?</b><br>請填入您目前使用語系的編碼." ,
												  $SKIN->form_input("xbbc_charset", $INFO['xbbc_charset'])
									     )      );

    // Autologin with group's permission				
    // Koudanshi
    					        
    $gname = array();
		$group_q = $DB->query("SELECT g_title, g_id FROM ibf_groups");
		
		while ($group = $DB->fetch_row($group_q)){
		 $gname[]=array( $group['g_id'], $group['g_title'] );
		}
		
		$xbbc_ag_dft = explode( ",", $INFO['xbbc_ag']);
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>哪些群組無法使用自動登入功能?</b><br>您可以選擇多個群組,這些群組無法使自動登入您的網站." ,
												  $SKIN->form_multiselect("ag[]", $gname, $xbbc_ag_dft, 5)
									     )      );

		$ADMIN->html .= $SKIN->end_form("確定變更");

		$ADMIN->html .= $SKIN->end_table();
		//+-------------------------------

		$ADMIN->output();

		exit();
	}

	//-------------------------------------------------------------
	//
	// 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, $ipb_isactive, $ipb_mid;
    
    // Auto set permission for XOOPS's Guest if we use IPBM user system
    if (!$ipb_isactive and (!$HTTP_POST_VARS['xbbc_ucp'] or !$HTTP_POST_VARS['xbbc_reg']))
    {
     	$DB->query("INSERT INTO ".XOOPS_DB_PREFIX."_group_permission (gperm_id, gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES ('', 3, $ipb_mid, 1, 'module_read')");
    }

		$master = array();

		if ( is_array($new) )
		{
			if ( count($new) > 0 )
			{
				foreach( $new as $field )
				{

					// Handle special..

					if ($field == 'img_ext' or $field == 'avatar_ext' or $field == 'photo_ext')
					{
						$HTTP_POST_VARS[ $field ] = preg_replace( "/[\.\s]/", "" , $HTTP_POST_VARS[ $field ] );
						$HTTP_POST_VARS[ $field ] = str_replace('|', "&#124;", $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 ] );
					}

					if ( $field == 'gd_font' OR $field == 'html_dir' OR $field == 'upload_dir')
					{
						$HTTP_POST_VARS[ $field ] = preg_replace( "/'/", "&#39;", $HTTP_POST_VARS[ $field ] );
					}
					else
					{
					$HTTP_POST_VARS[ $field ] = preg_replace( "/'/", "&#39;", stripslashes($HTTP_POST_VARS[ $field ]) );
					}
          // Koudanshi hack autologin group permission
					if ($field == 'xbbc_ag')
					{
					  if ( is_array( $HTTP_POST_VARS['ag'] ) )
        		{
         			$ag = implode( ",", $HTTP_POST_VARS['ag'] );
        			$HTTP_POST_VARS[$field] = $ag;
        		}

					}
					// End hack
					$master[ $field ] = stripslashes($HTTP_POST_VARS[ $field ]);
				}

				$ADMIN->rebuild_config($master);
			}
		}

		$ADMIN->save_log("更新 XOOPS 整合設定");

		$ADMIN->done_screen("整合設定已更新", "XOOPS 整合設定", "act=xbb&code=xset" );
	}




}
?>