<?php
/*
// ------------------------------------------------------------------------
-+ Date: 24-Jan-2004
-+ Version: 1.3
-+ ========================================
-+ Be Modified by Koudanshi
-+ E-mail: koudanshi@gmx.net
-+ Homepage: koudanshi.net or bbpixel.com
-+ ========================================
-+ Any Problems please email me,
-+ Please! don't bother IPS INC.
-+ ========================================
\\ ------------------------------------------------------------------------
*/

/*
+--------------------------------------------------------------------------
|   Invision Power Board v1.3 Final
|   ========================================
|   by Matthew Mecham
|   (c) 2001 - 2003 Invision Power Services
|   http://www.invisionpower.com
|   ========================================
|   Web: http://www.invisionboard.com
|   Time: Wed, 21 Jan 2004 09:54:34 GMT
|   Release: 2c4ce01a2d8aa60f718f2246a5cd4a18
|   Email: matt@invisionpower.com
|   Licence Info: http://www.invisionboard.com/?license
+---------------------------------------------------------------------------
|
|   > Admin "welcome" screen functions
|   > Module written by Matt Mecham
|   > Date started: 1st march 2002
|
|	> Module Version Number: 1.0.0
+--------------------------------------------------------------------------
*/

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


$idx = new index_page();


class index_page {

	var $mysql_version = "";

	function index_page()
	{
		global $DB, $IN, $INFO, $ADMIN, $MEMBER, $SKIN, $std, $ibforums;
		
		//---------------------------------------
		// Kill globals - globals bad, Homer good.
		//---------------------------------------
		
		$tmp_in = array_merge( $_GET, $_POST, $_COOKIE );
		
		foreach ( $tmp_in as $k => $v )
		{
			unset($$k);
		}
		
		//---------------------------------------
		
		$ADMIN->page_title  = "歡迎來到 Invision Power Board 管理控制台";
		$ADMIN->page_detail = "您可以從這個控制台設定及訂製您的論壇。<br><br>按左邊選單面板中的連結會顯示該管理類別的相關選項，每一個選項包含進一步的設定資訊，等等。";
		
		
		//---------------------------------
		// Get mySQL & PHP Version
		//---------------------------------
		
		$DB->query("SELECT VERSION() AS version");
		
		if ( ! $row = $DB->fetch_row() )
		{
			$DB->query("SHOW VARIABLES LIKE 'version'");
			$row = $DB->fetch_row();
		}
		
   		$this->mysql_version = $row['version'];
   		
   		$phpv = phpversion();
   		
		//---------------------------------
		// Got reg code?
		//---------------------------------

		$reg_html = "";
		$reg_end  = "";

		$version_info = "<a href='http://www.invisionboard.com/download.cgi' target='_blank'><img border='0' src='http://www.invisionboard.com/acp/versioncheck/?v={$ibforums->acpversion}' vspace='10'></a><br /><b><a href='http://www.php.net' target='_blank'>PHP</a> VERSION:</b> $phpv, <b><a href='http://www.mysql.com' target='_blank'>MySQL</a> VERSION:</b> ".$this->mysql_version;

		if ( $INFO['ipb_reg_number'] )
		{
			list( $a, $b, $c, $d, $e ) = explode( '-', $INFO['ipb_reg_number'] );

			if ( strlen($e) > 9 )
			{
				$reg_end = "註冊直至: <span style='color:green'>". $ADMIN->get_date( $e, 'SHORT' )."</span>";
			}
			else
			{
				$reg_end = "終身註冊";
			}

			$reg_html = "<div style='border:1px dotted #555;padding:6px;background-color:#EEF2F7;'>
							<b style='font-size:12px;color:#336699'>已註冊 Invision Power Board</b>
							<br />感謝您註冊您的 Invision Power Board!
							<br /><br />要取得新聞、更新及支援服務，請訪問您的 <a href='http://customer.invisionpower.com' target='_blank'>顧客區域</a>。
							<br />$reg_end
						</div>";
		}
		else
		{
			$reg_html = "<div style='border:1px dotted #555;padding:6px;background-color:#EEF2F7;'>
							<b style='font-size:12px;color:#AA0000'>尚未註冊 Invision Power Board</b>
							<br />這個 Invision Power Board 尚未註冊。
							<br /><!-- <br />為何註冊? <a href='http://www.invisionboard.com/?whyregister' target='_blank'>按這裡</a> 了解注冊的好處!-->
							<br />千萬不要按此 <a href='http://www.invisionboard.com/download.cgi?subc=register' target='_blank'> 註冊!</a> 您知道這是一點意義都沒有的!
                                                        <br />IPS 不對 IPBM 使用者作任何責任承擔與付費技術支援
						</div>";
		}

		//---------------------------------
		// Notepad
		//---------------------------------

		if ( $IN['save'] == 1 )
		{
			$DB->query("UPDATE ibf_cache_store SET cs_value='".addslashes($_POST['notes'])."' WHERE cs_key='adminnotes'");
		}

		$text = "您可以使用這部份留下筆記給您自己及其他系統管理員，等等";

		$DB->query("SELECT * FROM ibf_cache_store WHERE cs_key='adminnotes'");

		if ( ! $notes = $DB->fetch_row() )
		{
			$DB->query("INSERT INTO ibf_cache_store (cs_key,cs_value) VALUES ('adminnotes', '$text')");

			$notes = array( 'cs_key' => 'adminnotes', 'cs_value' => $text );
		}

		$ad_notes = "<form action='{$ADMIN->base_url}&act=index&save=1' method='post'>
					 <textarea name='notes' style='background-color:#F9FFA2;border:1px solid #CCC;width:95%;font-family:verdana;font-size:11px' rows='7' cols='25'>".stripslashes($notes['cs_value'])."</textarea>
				     <div align='center'><input type='submit' value='儲存系統管理員筆記' style='background-color:#F9FFA2;border:1px solid #999;;font-family:verdana;font-size:11px' /></div>
				     </form>";

		//---------------------------------
		// Printy-poos
		//---------------------------------

		$ADMIN->html .= "<table width='100%' border='0' cellpadding='0' cellspacing='0'>
						 <tr>
						  <td width='49%' valign='middle' align='center' style='padding:6px;background-color:#FAFFAF;'>{$ad_notes}</td>
						  <td style='width:10px'>&nbsp;</td>
						  <td width='49%' valign='top' align='left'>{$version_info}<br /><br />{$reg_html}</td>
						 </tr>
						 </table><br />\n";

		//---------------------------------
		// Stats
		//---------------------------------
		
		$DB->query("SELECT * FROM ibf_stats");
		
		$row = $DB->fetch_row();
		
		if ($row['TOTAL_REPLIES'] < 0) $row['TOTAL_REPLIES'] = 0;
		if ($row['TOTAL_TOPICS']  < 0) $row['TOTAL_TOPICS']  = 0;
		if ($row['MEM_COUNT']     < 0) $row['MEM_COUNT']     = 0;
		
		$DB->query("SELECT COUNT(*) as reg FROM ibf_validating WHERE lost_pass <> 1");
		$reg = $DB->fetch_row();
		
		if ($reg['reg'] < 1 ) $reg['reg'] = 0;
		
		$DB->query("SELECT COUNT(*) as coppa FROM ibf_validating WHERE coppa_user=1");
		$coppa = $DB->fetch_row();
		
		if ($coppa['coppa'] < 1 ) $coppa['coppa'] = 0;
		
		//-------------------------------------------------
		// Make sure the uploads path is correct
		//-------------------------------------------------
		
		$uploads_size = 0;
		
		if ($dh = opendir( $INFO['upload_dir'] ))
		{
			while ( $file = readdir( $dh ) )
			{
				if ( !preg_match( "/^..?$|^index/i", $file ) )
				{
					$uploads_size += @filesize( $INFO['upload_dir'] . "/" . $file );
				}
			}
			closedir( $dh );
		}
		
		// This piece of code from Jesse's (jesse@jess.on.ca) contribution
		// to the PHP manual @ php.net
		
		if ($uploads_size >= 1048576)
		{
			$uploads_size = round($uploads_size / 1048576 * 100 ) / 100 . " mb";
		}
		else if ($uploads_size >= 1024)
		{
			$uploads_size = round($uploads_size / 1024 * 100 ) / 100 . " k";
		}
		else
		{
			$uploads_size = $uploads_size . " bytes";
		}
		
		//+-----------------------------------------------------------
		// INSTALLER PRESENT?
		//+-----------------------------------------------------------

		$sm_install = 0;
		$lock_file  = 0;

		if ( @file_exists( ROOT_PATH . 'sm_install.php' ) )
		{
			$sm_install = 1;
		}

		if ( @file_exists( ROOT_PATH . 'install.lock' ) )
		{
			$lock_file = 1;
		}

		if ( $sm_install == 1 )
		{
			if ( $lock_file != 1 )
			{
				$ADMIN->html .= "<div style='color:red;border:1px solid red;background:#FFC0C3;padding:10px'>
				                   <span style='font-size:20px;font-weight:bold'>警告: 沒有鎖定的安裝程式仍然存在</span>
				                   <br /><br /><span style='font-size:14px;'>從您的伺服器中移除 <b>sm_install.php</b>!
				                   <br />留它在伺服器將損害您系統的安全性。</span></div><br /><br />";
			}
			else
			{
				$ADMIN->html .= "<div style='color:red;border:1px solid red;background:#FFE1E2;padding:10px'>
				                   <span style='font-size:14px;font-weight:bold'>警告: 安裝程式仍然存在</span>
				                   <br /><br /><span style='font-size:11px;'>雖然安裝程式已被鎖定，但我們為了安全性起見，建議您從您的伺服器中移除。
				                   <br />刪除 <b>sm_install.php</b> 將移除這個訊息。</span></div><br /><br />";
			}
		}

		
		//+-----------------------------------------------------------
		// BOARD OFFLINE?
		//+-----------------------------------------------------------
		
		if ($INFO['board_offline'])
		{
			
			$SKIN->td_header[] = array( "&nbsp;", "100%" );
			
			$ADMIN->html .= $SKIN->start_table( "關閉通知" );
			

			$ADMIN->html .= $SKIN->add_td_row( array( "您的論壇目前關閉中<br><br>&raquo; <a href='{$ADMIN->base_url}&act=op&code=board'>開放論壇</a>"
											 )      );
											 
			$ADMIN->html .= $SKIN->end_table();
		
			$ADMIN->html .= $SKIN->add_td_spacer();
		}
			
		//+-----------------------------------------------------------
		// ADMINS USING CP
		//+-----------------------------------------------------------
		
		$SKIN->td_header[] = array( "名稱"           , "20%" );
		$SKIN->td_header[] = array( "IP 位址"     , "20%" );
		$SKIN->td_header[] = array( "登入"         , "20%" );
		$SKIN->td_header[] = array( "最後操作"     , "20%" );
		$SKIN->td_header[] = array( "位置"       , "20%" );
		
		$ADMIN->html .= $SKIN->start_table( "正在使用這個控制台的管理員" );
		
		$t_time = time() - 60*10;
		
		$DB->query("SELECT MEMBER_NAME, LOCATION, LOG_IN_TIME, RUNNING_TIME, IP_ADDRESS FROM ibf_admin_sessions WHERE RUNNING_TIME > $t_time");
		
		$time_now = time();
		
		$seen_name = array();
		
		while ( $r = $DB->fetch_row() )
		{
			if ( $seen_name[ $r['MEMBER_NAME'] ] == 1 )
			{
				continue;
			}
			else
			{
				$seen_name[ $r['MEMBER_NAME'] ] = 1;
			}
			
			$log_in = $time_now - $r['LOG_IN_TIME'];
			$click  = $time_now - $r['RUNNING_TIME'];
			
			if ( ($log_in / 60) < 1 )
			{
				$log_in = sprintf("%0d", $log_in) . " 秒之前";
			}
			else
			{
				$log_in = sprintf("%0d", ($log_in / 60) ) . " 分鐘之前";
			}
			
			if ( ($click / 60) < 1 )
			{
				$click = sprintf("%0d", $click) . " 秒之前";
			}
			else
			{
				$click = sprintf("%0d", ($click / 60) ) . " 分鐘之前";
			}
			
			$ADMIN->html .= $SKIN->add_td_row( array (
														$r['MEMBER_NAME'],
														"<center><a href='javascript:alert(\"主機名稱： ".@gethostbyaddr($r['IP_ADDRESS'])."\")' title='取得主機名稱'>".$r['IP_ADDRESS']."</a></center>",
														"<center>".$log_in."</center>",
														"<center>".$click."</center>",
														"<center>".$r['LOCATION']."</center>",
											 )       );
		}
		
		
		
		$ADMIN->html .= $SKIN->end_table();
		
		//+-----------------------------------------------------------
		
		$ADMIN->html .= $SKIN->add_td_spacer();
		
		//+-----------------------------------------------------------
		
		
		if ($MEMBER['mgroup'] == $INFO['admin_group'])
		{
			//+-----------------------------------------------------------
			// LAST 5 Admin Actions
			//+-----------------------------------------------------------
			
			$SKIN->td_header[] = array( "會員名稱"            , "20%" );
			$SKIN->td_header[] = array( "完成的動作"        , "40%" );
			$SKIN->td_header[] = array( "操作時間"         , "20%" );
			$SKIN->td_header[] = array( "IP 位址"             , "20%" );
			
			$ADMIN->html .= $SKIN->start_table( "最後 5 個管理動作" );
			
			$DB->query("SELECT m.*, mem.uid, mem.uname FROM ibf_admin_logs m, ibf_members mem
						WHERE  m.member_id=mem.uid ORDER BY m.ctime DESC LIMIT 0, 5");
			
			if ( $DB->get_num_rows() )
			{
				while ( $rowb = $DB->fetch_row() )
				{
					$rowb['ctime'] = $ADMIN->get_date( $rowb['ctime'] );
					
					$ADMIN->html .= $SKIN->add_td_row( array( "<b>{$rowb['uname']}</b>",
															  "{$rowb['note']}",
															  "{$rowb['ctime']}",
															  "{$rowb['ip_address']}",
													 )      );
				
				
				}
			}
			else
			{
				$ADMIN->html .= $SKIN->add_td_basic("<center>沒有結果</center>");
			}
			
			$ADMIN->html .= $SKIN->end_table();
			
			//+-----------------------------------------------------------
			
			$ADMIN->html .= $SKIN->add_td_spacer();
		}
		
		//+-----------------------------------------------------------
		// Bots stuff
		//+-----------------------------------------------------------
		
		if ( $INFO['spider_sense'] )
		{
			$SKIN->td_header[] = array( "搜尋引擎"   , "20%" );
			$SKIN->td_header[] = array( "日期"         , "25%" );
			$SKIN->td_header[] = array( "查詢"        , "20%" );
			$SKIN->td_header[] = array( "查詢"        , "35%" );
			
			$ADMIN->html .= $SKIN->start_table( "最新 10 筆被搜尋引擎蜘蛛點中的記錄" );
			
			$DB->query("SELECT * FROM ibf_spider_logs ORDER BY entry_date DESC LIMIT 0,10");
			
			while ( $r = $DB->fetch_row() )
			{
				$ADMIN->html .= $SKIN->add_td_row( array( "<strong>".$INFO[ 'sp_'.$r['bot'] ]."</strong>",
														  $ADMIN->get_date( $r['entry_date'], 'SHORT' ),
														  $r['ip_address'].'&nbsp;',
														  $r['query_string'].'&nbsp;'
												 )      );
			}
			
			$ADMIN->html .= $SKIN->end_table();
			
			$ADMIN->html .= $SKIN->add_td_spacer();
		}
		
		//+-----------------------------------------------------------
		
		
		
		$SKIN->td_header[] = array( "定義", "25%" );
		$SKIN->td_header[] = array( "數值"     , "25%" );
		$SKIN->td_header[] = array( "定義", "25%" );
		$SKIN->td_header[] = array( "數值"     , "25%" );
		
		$ADMIN->html .= $SKIN->start_table( "系統概要" );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "主題總數" , $row['TOTAL_TOPICS'],
												  "主題的回覆總數"         , $row['TOTAL_REPLIES']
		 								 )      );
		 								 
		$ADMIN->html .= $SKIN->add_td_row( array( "會員總數" , $row['MEM_COUNT'], "公眾上傳資料夾大小", $uploads_size ) );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<a href='{$SKIN->base_url}&act=mem&code=mod'>待認證使用者</a>" , $reg['reg'],
												  "全部 '待認證使用者' 中的 <a href='{$SKIN->base_url}&act=mem&code=mod'>COPPA 申請</a>", $coppa['coppa'],
									     )      );
		
		$ADMIN->html .= $SKIN->end_table();
		
		//+-----------------------------------------------------------
		
		$ADMIN->html .= $SKIN->add_td_spacer();
		
		//+-----------------------------------------------------------
		
		$ADMIN->html .= $SKIN->start_form();
		
		$SKIN->td_header[] = array( "&nbsp;"  , "40%" );
		$SKIN->td_header[] = array( "&nbsp;"  , "30%" );
		$SKIN->td_header[] = array( "&nbsp;"  , "30%" );
		
		$ADMIN->html .= $SKIN->start_table( "快速辦理" );
		
		$ADMIN->html .= "
				
					<script language='javascript'>
					<!--
					  function edit_member() {
						
						if (document.forms[1].username.value == \"\") {
							alert(\"您必須輸入使用者名稱！\");
						} else {
							window.parent.body.location = '{$SKIN->base_url}' + '&act=mem&code=stepone&USER_NAME=' + escape(document.forms[1].username.value);
						}
					  }
					  
					  function new_cat() {
						
						if (document.forms[1].cat_name.value == \"\") {
							alert(\"您必須輸入類別名稱！\");
						} else {
							window.parent.body.location = '{$SKIN->base_url}' + '&act=cat&code=new&name=' + escape(document.forms[1].cat_name.value);
						}
					  }
					  
					  function new_forum() {
						
						if (document.forms[1].forum_name.value == \"\") {
							alert(\"您必須輸入討論區名稱！\");
						} else {
							window.parent.body.location = '{$SKIN->base_url}' + '&act=forum&code=new&name=' + escape(document.forms[1].forum_name.value);
						}
					  }
					//-->
					
					</script>
					<form name='DOIT' action=''>
						
		";
		
		$ADMIN->html .= $SKIN->add_td_row( array( "編輯會員：",
												  "<input type='text' style='width:100%' id='textinput' name='username' value='輸入名稱' onfocus='this.value=\"\"'>",
												  "<input type='button' value='尋找會員' id='button' onClick='edit_member()'>"
										 )      );
		
		$ADMIN->html .= $SKIN->add_td_row( array( "新增類別：",
												  "<input type='text' style='width:100%' name='cat_name' id='textinput' value='類別名稱' onfocus='this.value=\"\"'>",
												  "<input type='button' value='增加類別' id='button' onClick='new_cat()'>"
										 )      );
										 
		$ADMIN->html .= $SKIN->add_td_row( array( "新增討論區：",
												  "<input type='text' style='width:100%' name='forum_name' id='textinput' value='討論區名稱' onfocus='this.value=\"\"'>",
												  "<input type='button' value='增加討論區' id='button' onClick='new_forum()'>"
										 )      );
		
		$ADMIN->html .= "</form>";
										 
		$ADMIN->html .= $SKIN->end_table();
		
		$ADMIN->output();
		
	}
	
}


?>