<?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
+---------------------------------------------------------------------------
|
|   > Import functions
|   > Module written by Matt Mecham
|   > Date started: 22nd April 2002
|
|	> Module Version Number: 1.0.0
+--------------------------------------------------------------------------
*/


// Ensure we've not accessed this script directly:



$idx = new ad_modlogs();


class ad_modlogs {

	var $base_url;

	function ad_modlogs() {
		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 'view':
				$this->view();
				break;
				
			case 'remove':
				$this->remove();
				break;
				
				
			//-------------------------
			default:
				$this->list_current();
				break;
		}
		
	}
	
	//---------------------------------------------
	// Remove archived files
	//---------------------------------------------
	
	function view()
	{
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
		
		$start = $IN['st'] ? $IN['st'] : 0;
		
		$ADMIN->page_detail = "檢視板主的所有動作";
		$ADMIN->page_title  = "板主日誌管理";
	
		if ($IN['search_string'] == "")
		{
			$DB->query("SELECT COUNT(id) as count FROM ibf_moderator_logs WHERE member_id='".$IN['mid']."'");
			$row = $DB->fetch_row();
			
			$row_count = $row['count'];
			
			$query = "&act=modlog&mid={$IN['mid']}&code=view";
			
			$DB->query("SELECT m.*, f.id as forum_id, f.name FROM ibf_moderator_logs m
					     LEFT JOIN ibf_forums f ON(f.id=m.forum_id)
					    WHERE m.member_id='".$IN['mid']."' ORDER BY m.ctime DESC LIMIT $start, 20");
			
		}
		else
		{
			$IN['search_string'] = urldecode($IN['search_string']);
			
			if ( ($IN['search_type'] == 'topic_id') or ($IN['search_type'] == 'forum_id') )
			{
				$dbq = "m.".$IN['search_type']."='".$IN['search_string']."'";
			}
			else
			{
				$dbq = "m.".$IN['search_type']." LIKE '%".$IN['search_string']."%'";
			}
		
			$DB->query("SELECT COUNT(m.id) as count FROM ibf_moderator_logs m WHERE $dbq");
			$row = $DB->fetch_row();
			
			$row_count = $row['count'];
			
			$query = "&act=modlog&code=view&search_type={$IN['search_type']}&search_string=".urlencode($IN['search_string']);
			
			$DB->query("SELECT m.*, f.id as forum_id, f.name FROM ibf_moderator_logs m
					    LEFT JOIN ibf_forums f ON(f.id=m.forum_id)
					    WHERE $dbq ORDER BY m.ctime DESC LIMIT $start, 20");
		
		}
		
		$links = $std->build_pagelinks( array( 'TOTAL_POSS'  => $row_count,
											   'PER_PAGE'    => 20,
											   'CUR_ST_VAL'  => $start,
											   'L_SINGLE'    => "單頁",
											   'L_MULTI'     => "分頁： ",
											   'BASE_URL'    => $ADMIN->base_url.$query,
											 )
									  );
									  
		$ADMIN->page_detail = "您可以檢視及移除由您的板主所完成的動作";
		$ADMIN->page_title  = "板主日誌管理";
		
		//+-------------------------------
		
		$SKIN->td_header[] = array( "會員名稱"            , "15%" );
		$SKIN->td_header[] = array( "完成的動作"        , "15%" );
		$SKIN->td_header[] = array( "討論區"                  , "15%" );
		$SKIN->td_header[] = array( "主題標題"            , "25%" );
		$SKIN->td_header[] = array( "行動時間"         , "20%" );
		$SKIN->td_header[] = array( "IP 位址"             , "10%" );
		
		$ADMIN->html .= $SKIN->start_table( "儲存的板主日誌" );
		$ADMIN->html .= $SKIN->add_td_basic($links, 'center', 'catrow');
		
		if ( $DB->get_num_rows() )
		{
			while ( $row = $DB->fetch_row() )
			{
			
				$row['ctime'] = $ADMIN->get_date( $row['ctime'], 'LONG' );
				
				if ( $row['topic_id'] )
				{
					$topicid = "<br />主題 ID： ".$row['topic_id'];
				}
				
				$sess_id             = preg_replace( "/^.+?s=(\w{32}).+?$/" , "\\1", $row['http_referer'] );
				$row['http_referer'] = preg_replace( "/s=(\w){32}/" , ""  , $row['http_referer'] );
				
				$ADMIN->html .= $SKIN->add_td_row( array( "<b>{$row['member_name']}</b>",
														  "<span style='font-weight:bold;color:red'>{$row['action']}</span>",
														  "<b>{$row['name']}</b>",
														  "{$row['topic_title']}".$topicid,
														  "{$row['ctime']}",
														  "{$row['ip_address']}",
												 )      );
			
			
			}
		}
		else
		{
			$ADMIN->html .= $SKIN->add_td_basic("<center>沒有結果</center>");
		}
		
		$ADMIN->html .= $SKIN->add_td_basic($links, 'center', 'tdtop');
		
		$ADMIN->html .= $SKIN->end_table();
		
		
		//+-------------------------------
		//+-------------------------------
		
		$ADMIN->output();
		
	}
	
	//---------------------------------------------
	// Remove archived files
	//---------------------------------------------
	
	function remove()
	{
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
	
		if ($IN['mid'] == "")
		{
			$ADMIN->error("您沒有選擇要移除的會員 ID！");
		}
		
		$DB->query("DELETE FROM ibf_moderator_logs WHERE member_id='".$IN['mid']."'");
		
		$ADMIN->save_log("移除板主日誌");
		
		$std->boink_it($ADMIN->base_url."&act=modlog");
		exit();
	
	
	}
	
	

	
	
	//-------------------------------------------------------------
	// SHOW ALL LANGUAGE PACKS
	//-------------------------------------------------------------
	
	function list_current()
	{
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
		
		$form_array = array();
	
		$ADMIN->page_detail = "您可以檢視及移除由您的板主所完成的動作";
		$ADMIN->page_title  = "板主日誌管理";
		
		
		//+-------------------------------
		// VIEW LAST 5
		//+-------------------------------
		
		$DB->query("SELECT m.*, f.id as forum_id, f.name FROM ibf_moderator_logs m
		            LEFT JOIN ibf_forums f ON (f.id=m.forum_id)
		            ORDER BY m.ctime DESC LIMIT 0, 5");
		
		$SKIN->td_header[] = array( "會員名稱"            , "15%" );
		$SKIN->td_header[] = array( "完成的動作"        , "15%" );
		$SKIN->td_header[] = array( "討論區"                  , "15%" );
		$SKIN->td_header[] = array( "主題名稱"            , "25%" );
		$SKIN->td_header[] = array( "操作時間"         , "20%" );
		$SKIN->td_header[] = array( "IP 位址"             , "10%" );
		
		$ADMIN->html .= $SKIN->start_table( "最後 5 個管理動作" );

		if ( $DB->get_num_rows() )
		{
			while ( $row = $DB->fetch_row() )
			{
			
				$row['ctime'] = $ADMIN->get_date( $row['ctime'], 'LONG' );
				
				$topicid = "";
				
				if ( $row['topic_id'] )
				{
					$topicid = "<br />主題 ID： ".$row['topic_id'];
				}
				
				$sess_id             = preg_replace( "/^.+?s=(\w{32}).+?$/" , "\\1", $row['http_referer'] );
				$row['http_referer'] = preg_replace( "/s=(\w){32}/" , ""  , $row['http_referer'] );
				
				$ADMIN->html .= $SKIN->add_td_row( array( "<b>{$row['member_name']}</b>",
														  "<span style='font-weight:bold;color:red'>{$row['action']}</span>",
														  "<b>{$row['name']}</b>",
														  "{$row['topic_title']}".$topicid,
														  "{$row['ctime']}",
														  "{$row['ip_address']}",
												 )      );
			
			
			}
		}
		else
		{
			$ADMIN->html .= $SKIN->add_td_basic("<center>無結果</center>");
		}
		
		$ADMIN->html .= $SKIN->end_table();
		
		//+-------------------------------
		
		$SKIN->td_header[] = array( "會員名稱"            , "30%" );
		$SKIN->td_header[] = array( "完成的動作"       , "20%" );
		$SKIN->td_header[] = array( "檢視"     , "20%" );
		$SKIN->td_header[] = array( "移除"   , "30%" );
		
		$ADMIN->html .= $SKIN->start_table( "儲存的板主日誌" );
		
		$DB->query("SELECT m.*, count(m.id) as act_count from ibf_moderator_logs m GROUP BY m.member_id ORDER BY act_count DESC");
		
		while ( $r = $DB->fetch_row() )
		{
			
			$ADMIN->html .= $SKIN->add_td_row( array( "<b>{$r['member_name']}</b>",
													  "<center>{$r['act_count']}</center>",
													  "<center><a href='".$SKIN->base_url."&act=modlog&code=view&mid={$r['member_id']}'>檢視</a></center>",
													  "<center><a href='".$SKIN->base_url."&act=modlog&code=remove&mid={$r['member_id']}'>移除</a></center>",
											 )      );
		}
			
		
		
		$ADMIN->html .= $SKIN->end_table();
		
		
		//+-------------------------------
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'view'     ),
												  2 => array( 'act'   , 'modlog'       ),
									     )      );
		
		$SKIN->td_header[] = array( "&nbsp;"  , "40%" );
		$SKIN->td_header[] = array( "&nbsp;"  , "60%" );
		
		$ADMIN->html .= $SKIN->start_table( "搜尋板主日誌" );
		
		$form_array = array(
							  0 => array( 'topic_title', '主題標題' ),
							  1 => array( 'ip_address',  'IP 位址'  ),
							  2 => array( 'member_name', '會員名稱' ),
							  3 => array( 'topic_id'   , '主題 ID'    ),
							  4 => array( 'forum_id'   , '討論區 ID'    )
						   );
			
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>搜尋...</b>" ,
										  		  $SKIN->form_input( "search_string")
								 )      );
								 
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>搜尋於...</b>" ,
										  		  $SKIN->form_dropdown( "search_type", $form_array)
								 )      );
		
		$ADMIN->html .= $SKIN->end_form("搜尋");
										 
		$ADMIN->html .= $SKIN->end_table();
		
		//+-------------------------------
		//+-------------------------------
		
		$ADMIN->output();
	
	}
	
	
	
}


?>