<?php

/*
+--------------------------------------------------------------------------
|   Invision Power Board v1.2 (Click Site)
|   ========================================
|   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 Setting
|   > Module written by Matt Mecham
|   > Date started: 1st July 03
|
|	> 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, $HTTP_POST_VARS;
		
		//---------------------------------------
		// 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 'settings':
				$this->settings();
				break;
			case 'dosettings':
				$this->save_config( array( 'csite_on','csite_article_forum','csite_article_max','csite_article_recent_on','csite_article_recent_max','csite_article_chars','csite_discuss_max','csite_discuss_on',
	 									   'csite_discuss_len', 'csite_article_len', 'csite_pm_show', 'csite_stats_show', 'csite_search_show', 'csite_poll_show', 'csite_poll_url', 'csite_online_show','csite_skinchange_show',
	 									   'csite_nav_show', 'csite_title', 'csite_article_date','csite_fav_show' ) );
				break;
				
			
			default:
				$this->settings();
				break;
		}
		
	}
	
	//-------------------------------------------------------------
	// SETTINGS: Do Settings for the clickywickydickytavi
	//-------------------------------------------------------------- 
	 
	
	function settings()
	{
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
	
		$this->common_header('dosettings', 'IPDynamic Lite 設定', '您可以在這個控制台調整設定');
		
		// Get links
		
		$def_nav = "{board_url} [論壇]\n{board_url}act=Search&amp;CODE=getactive [今天活動主題]\n{board_url}act=Stats [今天發表前十名]\n{board_url}act=Stats&amp;CODE=leaders [連絡站管]";
		
		$DB->query("SELECT * FROM ibf_cache_store WHERE cs_key IN ('csite_nav_contents', 'csite_fav_contents')");
		
		$links = array( 'csite_nav_contents' => $def_nav, 'csite_fav_contents' => "" );
		
		while ( $row = $DB->fetch_row() )
		{
			$links[ $row['cs_key'] ] = $row['cs_value'];
		}
		
		// Save default informidificationally?
		
		if ( $INFO['csite_configured'] != 1 )
		{
			$DB->query("REPLACE INTO ibf_cache_store SET cs_key='csite_nav_contents', cs_value=\"$def_nav\"");
			$DB->query("REPLACE INTO ibf_cache_store SET cs_key='csite_fav_contents', cs_value=''");
		}
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>啟用 IPDynamic Lite?</b>" ,
										  $SKIN->form_yes_no( "csite_on", $INFO['csite_on'] )
								 )      );
								 
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>頁面抬頭？</b><br />這會出現在頁面的 &lt;title&gt; 元素之間" ,
										  $SKIN->form_input( "csite_title", str_replace( "'", "&#39;", $INFO['csite_title'] ) )
								 )      );
									     
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>要匯出文章的討論區...</b><br>若有超過一個以上的討論區 ID 請以逗號分隔." ,
										  $SKIN->form_input( "csite_article_forum", $INFO['csite_article_forum'] )
								 )      );
 
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>顯示在主區段的文章數</b>" ,
										  $SKIN->form_simple_input( "csite_article_max", $INFO['csite_article_max'] ? $INFO['csite_article_max'] : 15)
								 )      );
								 
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>啟用近期文章？</b><br />允許將未顯示於主區塊的文章以列表單顯示.",
										          $SKIN->form_yes_no( "csite_article_recent_on", $INFO['csite_article_recent_on'] )
										          ."<br />要顯示的近期文章數: ".$SKIN->form_simple_input( "csite_article_recent_max", $INFO['csite_article_recent_max'] ? $INFO['csite_article_recent_max'] : 5)
								 				  ."<br />主題標題的長度上限: ".$SKIN->form_simple_input( "csite_article_len", $INFO['csite_article_len'] ? $INFO['csite_article_len'] : 30)
								 )      );
								 
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>文章日期格式？</b><br><a href='http://www.php.net/date'>與 PHP 的日期函式相同." ,
										  $SKIN->form_input( "csite_article_date", $INFO['csite_article_date'] ? $INFO['csite_article_date'] : 'm-j-y H:i' )
								 )      );
								 
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>每篇文章顯示的字元上限</b><br>留空或輸入 0 取消限制<br />如果有裁切的話，文章的 bbcode 可能會被移除." ,
										  $SKIN->form_input( "csite_article_chars", $INFO['csite_article_chars'] )
								 )      );
								 
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>啟用近期討論？</b><br />允許列出近期的回覆或主題",
										          $SKIN->form_yes_no( "csite_discuss_on", $INFO['csite_discuss_on'] )
										          ."<br />要顯示的近期討論數: ".$SKIN->form_simple_input( "csite_discuss_max", $INFO['csite_discuss_max'] ? $INFO['csite_discuss_max'] : 10)
										          ."<br />主題標題的長度上限: ".$SKIN->form_simple_input( "csite_discuss_len", $INFO['csite_discuss_len'] ? $INFO['csite_discuss_len'] : 30)
								 )      );
								 
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>顯示使用者 / 訪客資訊方塊?</b>" ,
										  $SKIN->form_yes_no( "csite_pm_show", $INFO['csite_pm_show'] )
								 )      );
								 
		/*$ADMIN->html .= $SKIN->add_td_row( array( "<b>Show forum stats?</b><br />No. posts, topics, members" ,
										  $SKIN->form_yes_no( "csite_stats_show", $INFO['csite_stats_show'] )
								 )      );*/
								 
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>顯示線上使用者?</b><br />" ,
										  $SKIN->form_yes_no( "csite_online_show", $INFO['csite_online_show'] )
								 )      );
								 
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>顯示搜尋方塊?</b>" ,
										  $SKIN->form_yes_no( "csite_search_show", $INFO['csite_search_show'] )
								 )      );
								 
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>啟用面板選擇下拉選單?</b><br />訪客可以變更面板" ,
										  $SKIN->form_yes_no( "csite_skinchange_show", $INFO['csite_skinchange_show'] )
								 )      );
								 
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>顯示投票?</b>" ,
										  $SKIN->form_yes_no( "csite_poll_show", $INFO['csite_poll_show'] )
										   ."<br />輸入要包含的投票主題 URL: ".$SKIN->form_input( "csite_poll_url", $INFO['csite_poll_url'] )
								 )      );
								 
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>顯示網站導覽選單?</b>" ,
										  $SKIN->form_yes_no( "csite_nav_show", $INFO['csite_nav_show'] )
								 )      );
								 
		$ADMIN->html .= $SKIN->add_td_row( array( "<span style='vertical-align:top'><b>網站導覽選單連結</b><br>以這樣的格式每列一個<br>http://www.apple.com [Apple's Website]<br><br>{board_url} 會轉到您的論壇</span>" ,
										  $SKIN->form_textarea( "csite_nav_contents", $links['csite_nav_contents'], 70, 20 )
								 )      );
								 
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>顯示友情 / 偏愛網站方塊?</b>" ,
										  $SKIN->form_yes_no( "csite_fav_show", $INFO['csite_fav_show'] ) 
								 )      );
								 
		$ADMIN->html .= $SKIN->add_td_row( array( "<span style='vertical-align:top'><b>顯示友情 / 偏愛網站方塊內容</b><br>可使用原生 HTML</span>" ,
										  $SKIN->form_textarea( "csite_fav_contents", str_replace( '&middot;', '&amp;middot;', $links['csite_fav_contents'] ), 70, 20 )
								 )      );
								 
		$this->common_footer();
	
	
	}
	
	
	
	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 )
				{
					$master[ $field ] = $std->txt_stripslashes($HTTP_POST_VARS[ $field ]);
				}
				
				$master['csite_title']        = str_replace( "'", "&#39;", stripslashes($master['csite_title']) ); /* 中文修正 */
				$master['csite_article_date'] = str_replace( "'", "&#39;", $master['csite_article_date'] );
				
				$master['csite_configured'] = 1;
				
				$ADMIN->rebuild_config($master);
			}
		}
		
		$nav_contents = $std->txt_stripslashes($HTTP_POST_VARS['csite_nav_contents']);
		$fav_contents = str_replace( '&amp;middot;', '&middot;', $std->txt_stripslashes($HTTP_POST_VARS['csite_fav_contents']) );
		
		$DB->query("UPDATE ibf_cache_store SET cs_value='".str_replace( "'", '&#39;', $nav_contents )."' WHERE cs_key='csite_nav_contents'");
		$DB->query("UPDATE ibf_cache_store SET cs_value='".str_replace( "'", '&#39;', $fav_contents )."' WHERE cs_key='csite_fav_contents'");
		
		$ADMIN->save_log("IPDynamic Lite 配置已更新，備份寫入");
		
		$ADMIN->done_screen("IPDynamic Lite 配置已更新", "IPDynamic Lite 設定", "act=csite" );
		
		
		
	}
	//-------------------------------------------------------------
	//
	// 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  = "Board Settings ($section)";
		
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , $formcode ),
												  2 => array( 'act'   , 'csite'      ),
									     )      );
		
		//+-------------------------------
		
		$SKIN->td_header[] = array( "{none}"  , "40%" );
		$SKIN->td_header[] = array( "{none}"  , "60%" );
		
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->start_table( "Settings" );
		
	}

	//-------------------------------------------------------------
	//
	// 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();
		
	}




}





?>
