<?php

/*
+--------------------------------------------------------------------------
|   Invision Power Board v1.1
|   ========================================
|   by Matthew Mecham
|   (c) 2001,2002 Invision Power Services
|   http://www.ibforums.com
|   ========================================
|   Web: http://www.ibforums.com
|   Email: phpboards@ibforums.com
|   Licence Info: phpib-licence@ibforums.com
+---------------------------------------------------------------------------
|
|   > 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;
		
		//---------------------------------------
		// Kill globals - globals bad, Homer good.
		//---------------------------------------
		
		$tmp_in = array_merge( $_GET, $_POST, $_COOKIE );
		
		foreach ( $tmp_in as $k => $v )
		{
			unset($$k);
		}
		
		$ADMIN->page_title  = "欢迎访问论坛管理中心";
		$ADMIN->page_detail = "你可以在论坛管理中心对你的论坛进行各项参数设置。通过点击左侧的管理选项菜单来显示相关的管理选项。在每个管理选项里都包含了详细的帮助和提示信息，以帮助你方便快速的管理论坛。<br><br><b>如果你在使用中遇到问题，请访问我们的官方技术支持论坛：</b><br><li><a href='http://www.ibfchina.com' target='_blank'>华酷论坛技术支持 - http://www.ibfchina.com</a></li><li><a href='http://service.ibfchina.com' target='_blank'>华酷论坛相关服务 - http://service.ibfchina.com</a></li><li><a href='http://download.ibfchina.com' target='_blank'>华酷论坛最新下载 - http://download.ibfchina.com</a></li>";
		
		
		//---------------------------------
		// 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><br><b>PHP 版本：</b> $phpv, <b>MySQL 版本：</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_members WHERE mgroup='".$INFO['auth_group']."' AND (new_pass='' or new_pass IS NULL)");
		$reg = $DB->fetch_row();
		
		if ($reg['reg'] < 1 ) $reg['reg'] = 0;
		
		$DB->query("SELECT COUNT(*) as coppa FROM ibf_members WHERE mgroup='".$INFO['auth_group']."' AND 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 . " KB";
		}
		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.id, mem.name FROM ibf_admin_logs m, ibf_members mem
						WHERE  m.member_id=mem.id 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->time_offset, 'LONG' );
					
					$ADMIN->html .= $SKIN->add_td_row( array( "<b>{$rowb['name']}</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();
		}
		
		//+-----------------------------------------------------------
		
		$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();
		
	}
	
}


?>