<?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
+---------------------------------------------------------------------------
|
|   > Spider (MAN) Logs
|   > Module written by Matt Mecham
|   > Date started: 28th May 2003
|
|	> Module Version Number: 1.0.0
+--------------------------------------------------------------------------
*/


$idx = new ad_spiderlogs();


class ad_spiderlogs {

	var $base_url;

	function ad_spiderlogs() {
		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);
		}
		
		$ADMIN->nav[] = array( 'act=spiderlog', '搜尋引擎蜘蛛日誌' );
		
		//---------------------------------------

		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  = "搜尋引擎日誌經理";
		
		$botty = urldecode($IN['bid']);
	
		if ($IN['search_string'] == "")
		{
			$DB->query("SELECT COUNT(sid) as count FROM ibf_spider_logs WHERE bot='$botty'");
			
			$row = $DB->fetch_row();
			
			$row_count = $row['count'];
			
			$query = "&act=spiderlog&bid={$IN['bid']}&code=view";
			
			$DB->query("SELECT * FROM ibf_spider_logs WHERE bot='$botty' ORDER BY entry_date DESC LIMIT $start, 20");
			
		}
		else
		{
			$IN['search_string'] = urldecode($IN['search_string']);
		
			$DB->query("SELECT COUNT(sid) as count FROM ibf_spider_logs WHERE query_string LIKE '%{$IN['search_string']}%'");
			
			$row = $DB->fetch_row();
			
			$row_count = $row['count'];
			
			$query = "&act=spiderlog&code=view&search_string=".urlencode($IN['search_string']);
			
			$DB->query("SELECT * FROM ibf_spider_logs WHERE query_string LIKE '%{$IN['search_string']}%' ORDER BY entry_date 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( "行為時間"      , "20%" );
		$SKIN->td_header[] = array( "IP 位址"          , "10%" );
		
		$ADMIN->html .= $SKIN->start_table( "儲存的搜尋引擎日誌" );
		$ADMIN->html .= $SKIN->add_td_basic($links, 'right', 'pformstrip');
		
		if ( $DB->get_num_rows() )
		{
			while ( $row = $DB->fetch_row() )
			{
			
				$ADMIN->html .= $SKIN->add_td_row( array( "<b>".$INFO[ 'sp_'.$row['bot'] ]."</b>",
														  "<a href='{$INFO['board_url']}/index.{$INFO['php_ext']}?{$row['query_string']}' target='_blank'>{$row['query_string']}</a>",
														  $ADMIN->get_date( $row['entry_date'], 'LONG' ),
														  "{$row['ip_address']}",
												 )      );
			
			}
		}
		else
		{
			$ADMIN->html .= $SKIN->add_td_basic("<center>無結果</center>");
		}
		
		$ADMIN->html .= $SKIN->add_td_basic($links, 'right', 'pformstrip');
		
		$ADMIN->html .= $SKIN->end_table();
		
		
		//+-------------------------------
		//+-------------------------------
		
		$ADMIN->output();
		
	}
	
	//---------------------------------------------
	// Remove archived files
	//---------------------------------------------
	
	function remove()
	{
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
	
		if ($IN['bid'] == "")
		{
			$ADMIN->error("您沒有選擇要移除的機器人！");
		}
		
		$botty = urldecode($IN['bid']);
		
		$DB->query("DELETE FROM ibf_spider_logs WHERE bot='$botty'");
		
		$ADMIN->save_log("移除的搜尋引擎日誌");
		
		$std->boink_it($ADMIN->base_url."&act=spiderlog");
		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  = "搜尋引擎日誌經理";

		//+-------------------------------
		
		$SKIN->td_header[] = array( "機器人名稱"            , "20%" );
		$SKIN->td_header[] = array( "點中"                , "20%" );
		$SKIN->td_header[] = array( "開始"             , "20%" );
		$SKIN->td_header[] = array( "根據機器人全部檢視"     , "20%" );
		$SKIN->td_header[] = array( "根據機器人全部移除"   , "20%" );
		
		$ADMIN->html .= $SKIN->start_table( "儲存的搜尋引擎蜘蛛日誌" );
		
		$DB->query("SELECT count(*) as cnt, bot, entry_date, query_string FROM `ibf_spider_logs` group by bot order by entry_date DESC");
		
		while ( $r = $DB->fetch_row() )
		{
		
			$url_butt = urlencode($r['bot']);
			
			$ADMIN->html .= $SKIN->add_td_row( array( $INFO[ 'sp_'.$r['bot'] ],
													  "<center>{$r['cnt']}</center>",
													   $ADMIN->get_date( $r['entry_date'], 'SHORT' ),
													  "<center><a href='".$SKIN->base_url."&act=spiderlog&code=view&bid={$url_butt}'>檢視</a></center>",
													  "<center><a href='".$SKIN->base_url."&act=spiderlog&code=remove&bid={$url_butt}'>移除</a></center>",
											 )      );
		}
			
		
		
		$ADMIN->html .= $SKIN->end_table();
		
		
		//+-------------------------------
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'view'     ),
												  2 => array( 'act'   , 'spiderlog'       ),
									     )      );
		
		$SKIN->td_header[] = array( "&nbsp;"  , "40%" );
		$SKIN->td_header[] = array( "&nbsp;"  , "60%" );
		
		$ADMIN->html .= $SKIN->start_table( "檢索搜尋引擎日誌" );
			
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>搜尋...</b>" ,
										  		  $SKIN->form_input( "search_string").'... 於查詢字串中'
								 )      );
		
		$ADMIN->html .= $SKIN->end_form("Search");
										 
		$ADMIN->html .= $SKIN->end_table();
		
		//+-------------------------------
		//+-------------------------------
		
		$ADMIN->output();
	
	}
	
	
	
}


?>