<?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 "welcome" screen functions
|   > Module written by Matt Mecham
|   > Date started: 1st march 2002
|
|	> Module Version Number: 1.0.0
+--------------------------------------------------------------------------
*/




$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();
   		
   		$ADMIN->page_detail .= "<br><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> 版本：</b> $phpv, <b><a href='http://www.mysql.com' target='_blank'>MySQL</a> 版本：</b> ".$this->mysql_version;
		
		//---------------------------------
		
		
		$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");	/*ipbm 1.23更新內容*/
		$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";
		}
		
		
		//+-----------------------------------------------------------
		// 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[0].username.value == \"\") {
							alert(\"您必須輸入使用者名稱！\");
						} else {
							window.parent.body.location = '{$SKIN->base_url}' + '&act=mem&code=stepone&USER_NAME=' + escape(document.forms[0].username.value);
						}
					  }
					  
					  function new_cat() {
						
						if (document.forms[0].cat_name.value == \"\") {
							alert(\"您必須輸入類別名稱！\");
						} else {
							window.parent.body.location = '{$SKIN->base_url}' + '&act=cat&code=new&name=' + escape(document.forms[0].cat_name.value);
						}
					  }
					  
					  function new_forum() {
						
						if (document.forms[0].forum_name.value == \"\") {
							alert(\"您必須輸入討論區名稱！\");
						} else {
							window.parent.body.location = '{$SKIN->base_url}' + '&act=forum&code=new&name=' + escape(document.forms[0].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();
		
	}
	
}


?>