From 95ad45c8f5597dc0273ec1b1a28036cee5f4c20e Mon Sep 17 00:00:00 2001
From: Cameron <cameron@e107coders.org>
Date: Wed, 1 Jan 2014 17:39:14 -0800
Subject: [PATCH] System-Log page updated to use admin-ui.

---
 e107_admin/admin_log.php | 727 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 713 insertions(+), 14 deletions(-)

diff --git a/e107_admin/admin_log.php b/e107_admin/admin_log.php
index fac4594ad..1e9202689 100644
--- a/e107_admin/admin_log.php
+++ b/e107_admin/admin_log.php
@@ -41,12 +41,723 @@ if(! getperms('S'))
 }
 
 include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_'.e_PAGE);
-
 // Main language file should automatically be loaded
 // Load language files for log messages
 include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_log_messages.php'); //... for core functions
 
 
+if(is_array($pref['lan_log_list'])) //... and for any plugins which support it
+{
+	foreach($pref['lan_log_list'] as $path => $file)
+	{
+		$file = str_replace('--LAN--', e_LANGUAGE, $file);
+		
+	//	echo "orig = ".$file."     ";
+		//e107::lan($path,'log',true);
+		include_lan(e_PLUGIN.$path.'/languages/'.$file);
+	}
+}
+
+define('AL_DATE_TIME_FORMAT', 'y-m-d  H:i:s');
+
+
+
+class adminlog_admin extends e_admin_dispatcher
+{
+
+	protected $modes = array(	
+	
+		'main'	=> array(
+			'controller' 	=> 'admin_log_ui',
+			'path' 			=> null,
+			'ui' 			=> 'admin_log_form_ui',
+			'uipath' 		=> null
+		),
+		
+
+		'audit'	=> array(
+			'controller' 	=> 'audit_log_ui',
+			'path' 			=> null,
+			'ui' 			=> 'admin_log_form_ui',
+			'uipath' 		=> null
+		),
+		
+
+		'rolling'	=> array(
+			'controller' 	=> 'dblog_ui',
+			'path' 			=> null,
+			'ui' 			=> 'admin_log_form_ui',
+			'uipath' 		=> null
+		),
+		
+
+	);	
+	
+	//$page_title = array('adminlog' => RL_LAN_030, 'auditlog' => RL_LAN_062, 'rolllog' => RL_LAN_002, 'downlog' => RL_LAN_067, 'detailed' => RL_LAN_094, 'online' => RL_LAN_120);
+	
+	
+	protected $adminMenu = array(
+
+		'main/list'			=> array('caption'=> RL_LAN_030, 'perm' => '5'),
+		'audit/list'		=> array('caption'=> RL_LAN_062, 'perm' => '5'),
+		'rolling/list'		=> array('caption'=> RL_LAN_002, 'perm' => '5'),
+	
+		'main/prefs' 		=> array('caption'=> LAN_PREFS, 'perm' => '5'),	
+		'main/maintenance'	=> array('caption'=> LAN_OPTIONS, 'perm' => '5')
+
+		// 'main/custom'		=> array('caption'=> 'Custom Page', 'perm' => 'P')
+	);
+
+	protected $adminMenuAliases = array(
+		'main/edit'	=> 'main/list'				
+	);	
+	
+	protected $menuTitle = ADLAN_155;
+}
+
+
+
+
+				
+class admin_log_ui extends e_admin_ui
+{
+			
+		protected $pluginTitle		= ADLAN_155;
+		protected $pluginName		= 'adminlog';
+		protected $table			= 'admin_log';
+		protected $pid				= 'dblog_id';
+		protected $perPage 			= 10; 
+		
+		protected $listQry			= "SELECT  f.*, u.* FROM #admin_log AS f LEFT JOIN #user AS u ON f.dblog_user_id = u.user_id "; // Should not be necessary.
+		protected $listOrder		= 'f.dblog_id DESC';
+		
+		protected $batchDelete		= false;
+			
+		protected $fields 		= array (  
+	//	'checkboxes' =>   array ( 'title' => '', 'type' => null, 'data' => null, 'nolist'=>true, 'width' => '5%', 'thclass' => 'center', 'forced' => '1', 'class' => 'center', 'toggle' => 'e-multiselect',  ),
+		  'dblog_id' 			=>   array ( 'title' => LAN_ID, 'data' => 'int', 'width' => '5%', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left',  ),
+		  'dblog_datestamp' 	=>   array ( 'title' => LAN_DATESTAMP, 'type' => 'datestamp', 'data' => 'int', 'width' => '15%', 'filter' => true, 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left',  ),
+		//  'dblog_microtime'		=>   array ( 'title' => 'Microtime', 'type' => 'method', 'data' => 'int', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'center', 'thclass' => 'center',  ),
+		  'dblog_type' 			=>   array ( 'title' => RL_LAN_032, 'type' => 'method', 'data' => 'int', 'width' => '1%', 'filter' => true,  'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left',  ),
+		  'dblog_ip' 			=>   array ( 'title' => LAN_IP, 'type' => 'ip', 'data' => 'str', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'center', 'thclass' => 'center',  ),
+		
+		  'dblog_user_id' 		=>   array ( 'title' => LAN_USER, 'type' => 'user', 'data' => 'int', 'width' => 'auto', 'filter' => true,  'help' => '', 'readParms'=>'link=1', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left',  ),
+		  'dblog_eventcode' 	=>   array ( 'title' => RL_LAN_023, 'type' => 'method', 'data' => 'str', 'width' => 'auto', 'filter' => true, 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left',  ),
+		
+		  'dblog_title' 		=>   array ( 'title' => RL_LAN_025, 'type' => 'method', 'data' => 'str', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left',  ),
+		  'dblog_remarks'		=>   array ( 'title' => RL_LAN_033, 'type' => 'method', 'data' => 'str', 'width' => '35%', 'filter'=>true, 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left',  ),
+		  'options' 			=>   array ( 'title' => 'Options', 'type' => null, 'nolist'=>true, 'data' => null, 'width' => '10%', 'thclass' => 'center last', 'class' => 'center last', 'forced' => '1',  ),
+		);		
+		
+		protected $fieldpref = array( 'dblog_datestamp',  'dblog_type', 'dblog_eventcode', 'dblog_user_id', 'dblog_ip', 'dblog_title', 'dblog_remarks');
+		
+		//'adminlog' => array(RL_LAN_019, RL_LAN_032, RL_LAN_020, RL_LAN_104, LAN_USER, RL_LAN_023, RL_LAN_025, RL_LAN_033), 
+		
+	
+		protected $prefs = array(	
+			'sys_log_perpage'			=> array('title'=> RL_LAN_044, 'type'=>'dropdown', 'data' => 'int','help'=> RL_LAN_064,'writeParms'=>''),
+			'user_audit_class'			=> array('title'=> RL_LAN_123, 'type'=>'userclass', 'data' => 'int','help'=>''),
+			'user_audit_opts'			=> array('title'=> RL_LAN_031, 'type'=>'method', 'data' => 'array','help'=>''),
+			'roll_log_active'			=> array('title'=> RL_LAN_008, 'type'=>'boolean', 'data' => 'int','help'=>''),
+			'roll_log_days'				=> array('title'=> RL_LAN_009, 'type'=>'text', 'data' => 'string','help'=>''),
+		//	'Delete admin log events older than '		=> array('title'=> RL_LAN_045, 'type'=>'method', 'data' => 'string','help'=>'Help Text goes here'),
+		//	'Delete user audit trail log events older'		=> array('title'=> 'Delete user audit trail log events older', 'type'=>'method', 'data' => 'string','help'=>'Help Text goes here'),
+		); 
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+		var $eventTypes = array();
+		
+		var $eventUsers = array();
+
+		// optional
+		public function init()
+		{
+			$this->prefs['sys_log_perpage']['writeParms'] = array(10, 20, 30, 40, 50);
+			
+			
+			$sql = e107::getDb();
+			$row = $sql->retrieve("SELECT dblog_eventcode,dblog_title FROM #admin_log WHERE dblog_eventcode !='' AND dblog_title !='' GROUP BY dblog_eventcode",true);
+			foreach($row as $val)
+			{
+				$id = $val['dblog_eventcode'];
+				$this->eventTypes[$id] = deftrue($val['dblog_title'],$id);
+			}
+
+			asort($this->eventTypes);
+			
+			$row = $sql->retrieve("SELECT  f.dblog_user_id, u.user_name FROM #admin_log AS f LEFT JOIN #user AS u ON f.dblog_user_id = u.user_id WHERE f.dblog_user_id != 0 GROUP BY dblog_user_id ORDER BY u.user_name",true);
+			foreach($row as $val)
+			{
+				$id = $val['dblog_user_id'];
+				$this->eventUsers[$id] = $val['user_name'];
+			}
+			
+	
+		}
+		
+		
+
+	
+		
+		function maintenancePage()
+		{
+			$frm = e107::getForm();
+			// Admin log maintenance
+			//==================
+			$text .= "
+			<form method='post' action='".e_SELF."?config'>
+				<fieldset id='core-admin-log-maintenance'>
+					<legend>".RL_LAN_125."</legend>
+					<table class='table adminform'>
+						<colgroup>
+							<col class='col-label' />
+							<col class='col-control' />
+						</colgroup>
+						<tbody>
+							<tr>
+								<td>".RL_LAN_045." </td>
+								<td>".gen_log_delete('rolllog_clearadmin')." ".RL_LAN_046.$frm->admin_button('deleteoldadmin', 'no-value', 'delete', RL_LAN_049)."</td>
+							</tr>
+			";
+		
+			// User log maintenance
+			//====================
+			$text .= "
+							<tr>
+								<td>".RL_LAN_066." </td>
+								<td>".gen_log_delete('rolllog_clearaudit')." ".RL_LAN_046.$frm->admin_button('deleteoldaudit', 'no-value', 'delete', RL_LAN_049)."</td>
+							</tr>
+						</tbody>
+					</table>
+				</fieldset>
+			</form>
+		
+			</fieldset>
+			";
+	 		return $text;
+			
+		}		
+		
+		
+		function maintenanceProcess()
+		{
+			$mes = e107::getMessage();
+			$ns = e107::getRender();
+			$log = e107::getAdminLog();
+			
+			if(isset($_POST['deleteoldadmin']) && isset($_POST['rolllog_clearadmin']))
+			{
+				$back_count = intval($_POST['rolllog_clearadmin']);
+				$next_action = 'confdel';
+			}
+			elseif(isset($_POST['deleteoldaudit']) && isset($_POST['rolllog_clearaudit']))
+			{
+				$back_count = intval($_POST['rolllog_clearaudit']);
+				$next_action = 'auditdel';
+			}
+			
+			if(isset($back_count) && isset($next_action))
+			{
+				if(($back_count >= 1) && ($back_count <= 90))
+				{
+					$temp_date = getdate();
+					$old_date = intval(mktime(0, 0, 0, $temp_date['mon'], $temp_date['mday'] - $back_count, $temp_date['year']));
+					$old_string = strftime("%d %B %Y", $old_date);
+					//	$message = "Back delete ".$back_count." days. Oldest date = ".$old_string;
+					$action = $next_action;
+					$qs[1] = $old_date;
+					$qs[2] = $back_count;
+				}
+				else 
+				{
+					$mes->addWarning(RL_LAN_050);
+				}
+			}
+			
+			if(!isset($admin_log))
+			{
+				$mes->addWarning("Admin Log not valid");
+			}
+			
+			
+			// Actually delete back events - admin or user audit log
+			if(($action == "backdel") && isset($_POST['backdeltype']))
+			{
+				if(isset($_POST['confirmdeleteold']))
+				{
+					$old_date = intval($qs[1]);
+					$old_string = strftime("%d %B %Y", $old_date);
+					$qry = "dblog_datestamp < ".$old_date; // Same field for both logs
+					switch($_POST['backdeltype'])
+					{
+						case 'confdel':
+							$db_table = 'admin_log';
+							$db_name = RL_LAN_052;
+							$db_msg = "ADLOG_02";
+							break;
+						case 'auditdel':
+							$db_table = 'audit_log';
+							$db_name = RL_LAN_053;
+							$db_msg = "ADLOG_03";
+							break;
+						default:
+							exit(); // Someone fooling around!
+					}
+					//	$message = "Back delete, oldest date = {$old_string}  Query = {$qry}";
+					if($del_count = $sql->db_Delete($db_table, $qry))
+					{
+						// Add in a log event
+						$message = $db_name.str_replace(array('--OLD--', '--NUM--'), array($old_string, $del_count), RL_LAN_057);
+						$mes->addSuccess($message);
+						$log->log_event($db_msg, "db_Delete - earlier than {$old_string} (past {$qs[2]} days)[!br!]".$message.'[!br!]'.$db_table.' '.$qry, E_LOG_INFORMATIVE, '');
+					}
+					else
+					{
+						$mes->addWarning(RL_LAN_054." : ".$sql->mySQLresult);
+					}
+				} 
+				else
+				{
+					$mes->addInfo(LAN_NO_CHANGE);
+				}
+			
+				$action = "config";
+				unset($qs[1]);
+				unset($qs[2]);
+			}
+			
+			// Prompt to delete back events
+			if(($action == "confdel") || ($action == "auditdel"))
+			{
+				$old_string = strftime("%d %B %Y", $qs[1]);
+				$text = "
+					<form method='post' action='".e_SELF."?backdel.{$qs[1]}.{$qs[2]}'>
+						<fieldset id='core-admin-log-confirm-delete'>
+							<legend class='e-hideme'>".LAN_CONFDELETE."</legend>
+							<table class='table adminform'>
+								<tr>
+									<td class='center'>
+										<strong>".(($action == "confdel") ? RL_LAN_047 : RL_LAN_065).$old_string."</strong>
+									</td>
+								</tr>
+							</table>
+							<div class='buttons-bar center'>
+								<input type='hidden' name='backdeltype' value='{$action}' />
+								".$frm->admin_button('confirmdeleteold', 'no-value', 'delete', RL_LAN_049)."
+								".$frm->admin_button('confirmcancelold', 'no-value', 'delete', LAN_CANCEL)."				
+							</div>
+						</fieldset>
+					</form>
+			
+				";
+			
+				$ns->tablerender(LAN_CONFDELETE, $text);
+			}	
+			
+			
+			
+		}
+		
+
+			
+}	
+
+
+class admin_log_form_ui extends e_admin_form_ui
+{
+
+	function sys_log_perpage($curVal,$mode)
+	{
+		$frm = e107::getForm();
+		switch($mode)
+		{
+			case 'write': // Edit Page
+				return $frm->text('sys_log_perpage',$curVal);		
+			break;	
+		}
+	}
+	
+	function user_audit_opts($curVal,$mode)
+	{
+		$pref = e107::getPref();
+		$frm = e107::getForm();
+		
+		// User Audit log options (for info)
+		//=======================
+		//	define('USER_AUDIT_SIGNUP',11);				// User signed up
+		//	define('USER_AUDIT_EMAILACK',12);			// User responded to registration email
+		//	define('USER_AUDIT_LOGIN',13);				// User logged in
+		//	define('USER_AUDIT_LOGOUT',14);				// User logged out
+		//	define('USER_AUDIT_NEW_DN',15);				// User changed display name
+		//	define('USER_AUDIT_NEW_PW',16);				// User changed password
+		//	define('USER_AUDIT_NEW_EML',17);			// User changed email
+		//	define('USER_AUDIT_NEW_SET',19);			// User changed other settings (intentional gap in numbering)
+		//	define('USER_AUDIT_ADD_ADMIN', 20); 		// User added by admin
+		//	define('USER_AUDIT_MAIL_BOUNCE', 21); 		// User mail bounce
+		//	define('USER_AUDIT_BANNED', 22); 			// User banned
+		//	define('USER_AUDIT_BOUNCE_RESET', 23); 		// User bounce reset
+		//	define('USER_AUDIT_TEMP_ACCOUNT', 24); 		// User temporary account
+		
+		
+		$audit_checkboxes = array(USER_AUDIT_SIGNUP => RL_LAN_071, USER_AUDIT_EMAILACK => RL_LAN_072, USER_AUDIT_LOGIN => RL_LAN_073, //	USER_AUDIT_LOGOUT 	=> RL_LAN_074,			// Logout is lumped in with login
+		USER_AUDIT_NEW_DN => RL_LAN_075, USER_AUDIT_NEW_PW => RL_LAN_076, USER_AUDIT_PW_RES => RL_LAN_078, USER_AUDIT_NEW_EML => RL_LAN_077, USER_AUDIT_NEW_SET => RL_LAN_079, 
+		USER_AUDIT_ADD_ADMIN => RL_LAN_080, USER_AUDIT_MAIL_BOUNCE => RL_LAN_081, USER_AUDIT_BANNED => RL_LAN_082, USER_AUDIT_BOUNCE_RESET => RL_LAN_083,
+		USER_AUDIT_TEMP_ACCOUNT => RL_LAN_084);
+	
+	
+		$user_signup_opts = array_flip(explode(',', varset($pref['user_audit_opts'], '')));
+
+		$text = "";
+		
+		foreach($audit_checkboxes as $k => $t)
+		{
+			$checked = isset($user_signup_opts[$k]) ? true : false;
+			$text .= $frm->checkbox('user_audit_opts[]',$k, $checked, array('label'=>$t));	
+		}
+		
+		$text .= $frm->admin_button('check_all', 'jstarget:user_audit_opts', 'checkall', LAN_CHECKALL).$frm->admin_button('uncheck_all', 'jstarget:user_audit_opts', 'checkall', LAN_UNCHECKALL);
+	
+	
+		return $text;
+	}
+	
+	
+	
+	
+	// Custom Method/Function 
+	/*
+	function dblog_datestamp($curVal,$mode)
+	{
+		$frm = e107::getForm();		
+		 		
+		switch($mode)
+		{
+			case 'read': // List Page
+				return date(AL_DATE_TIME_FORMAT, $curVal);
+			break;
+			
+			case 'write': // Edit Page
+				return $frm->text('dblog_datestamp',$curVal);		
+			break;
+			
+			case 'filter':
+			case 'batch':
+				return  $array; 
+			break;
+		}
+	}
+	*/
+	
+	// Custom Method/Function 
+	function dblog_microtime($curVal,$mode)
+	{
+		$frm = e107::getForm();		
+		 		
+		switch($mode)
+		{
+			case 'read': // List Page
+				return date("H:i:s", intval($curVal) % 86400).'.'.str_pad(100000 * round($curVal - floor($curVal), 6), 6, '0');
+			break;
+			
+			case 'write': // Edit Page
+				return $frm->text('dblog_microtime',$curVal);		
+			break;
+			
+			case 'filter':
+			case 'batch':
+				return  $array; 
+			break;
+		}
+	}
+
+	
+	// Custom Method/Function 
+	function dblog_type($curVal,$mode)
+	{
+		
+		switch($mode)
+		{
+			case 'read': // List Page
+				return $curVal;
+			break;
+			
+			case 'filter':
+			case 'batch':
+				return $array; 
+			break;
+		}
+	}
+
+
+	
+	// Custom Method/Function 
+	function dblog_title($curVal,$mode)
+	{
+		
+		
+		switch($mode)
+		{
+			case 'read': // List Page
+				$val = trim($curVal);
+				if(defined($val))
+				{
+					$val = constant($val);
+				}
+				return $val;
+			break;
+			
+			case 'filter':
+			case 'batch':
+				return  $array; 
+			break;
+		}
+	}
+
+	
+	function dblog_eventcode($curVal,$mode)
+	{
+		$array = $this->getController()->eventTypes;
+		 		
+		switch($mode)
+		{
+			case 'read': // List Page
+				return $curVal;
+			break;
+			
+			case 'filter':
+			case 'batch':
+				return  $array; 
+			break;
+		}
+	}
+
+
+	// Custom Method/Function 
+	function dblog_remarks($curVal,$mode)
+	{
+		$frm = e107::getForm();		
+		 		
+		switch($mode)
+		{
+			case 'read': // List Page
+				return preg_replace_callback("#\[!(\w+?)(=.+?){0,1}!]#", 'log_process', $curVal);
+			break;
+
+			
+			case 'filter':
+			case 'batch':
+				return  $array; 
+			break;
+		}
+	}
+
+// Custom Method/Function 
+	function dblog_caller($curVal,$mode)
+	{
+		 		
+		switch($mode)
+		{
+			case 'read': // List Page
+				$val =$curVal;
+				if((strpos($val, '|') !== FALSE) && (strpos($val, '@') !== FALSE))
+				{
+					list($file, $rest) = explode('|', $val);
+					list($routine, $rest) = explode('@', $rest);
+					$val = $file.'<br />Function: '.$routine.'<br />Line: '.$rest;
+				}
+				return $val;
+			break;
+
+			
+			case 'filter':
+			case 'batch':
+				return  $array; 
+			break;
+		}
+	}
+
+}		
+		
+
+				
+class audit_log_ui extends e_admin_ui
+{
+			
+		protected $pluginTitle		= 'adminlog';
+		protected $pluginName		= 'adminlog';
+		protected $table			= 'audit_log';
+		protected $pid				= 'dblog_id';
+		protected $perPage 			= 10; 
+			
+		protected $fields 		= array (  
+	//	'checkboxes' =>   array ( 'title' => '', 'type' => null, 'data' => null, 'width' => '5%', 'thclass' => 'center', 'forced' => '1', 'class' => 'center', 'toggle' => 'e-multiselect',  ),
+		  'dblog_id' 			=>   array ( 'title' => LAN_ID, 'data' => 'int', 'width' => '5%', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left',  ),
+		  'dblog_datestamp' 	=>   array ( 'title' => LAN_DATESTAMP, 'type' => 'method', 'data' => 'int', 'width' => 'auto', 'filter' => true, 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left',  ),
+		  'dblog_microtime' 	=>   array ( 'title' => 'Microtime', 'type' => 'method', 'data' => 'int', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'center', 'thclass' => 'center',  ),
+		  'dblog_eventcode' 	=>   array ( 'title' => 'Eventcode', 'type' => 'method', 'data' => 'str', 'width' => 'auto', 'filter' => true, 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'center', 'thclass' => 'center',  ),
+		  'dblog_user_id' 		=>   array ( 'title' => LAN_USER, 'type' => 'user', 'data' => 'int', 'width' => '5%', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left',  ),
+		  'dblog_user_name' 	=>   array ( 'title' => LAN_USER, 'type' => 'text', 'data' => 'str', 'width' => 'auto', 'filter' => true, 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left',  ),
+		  'dblog_ip' 			=>   array ( 'title' => LAN_IP, 'type' => 'text', 'data' => 'str', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'center', 'thclass' => 'center',  ),
+		  'dblog_title' 		=>   array ( 'title' => LAN_TITLE, 'type' => 'text', 'data' => 'str', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left',  ),
+		  'dblog_remarks' 		=>   array ( 'title' => 'Remarks', 'type' => 'method', 'data' => 'str', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'center', 'thclass' => 'center',  ),
+		  'options' 			=>   array ( 'title' => 'Options', 'type' => null,  'nolist'=>true, 'data' => null, 'width' => '10%', 'thclass' => 'center last', 'class' => 'center last', 'forced' => '1',  ),
+		);		
+		
+		protected $fieldpref = array('dblog_id', 'dblog_datestamp', 'dblog_microtime', 'dblog_eventcode', 'dblog_user_id', 'dblog_user_name', 'dblog_ip', 'dblog_title');
+		
+	
+	/*	
+		// optional
+		public function init()
+		{
+			
+		}
+	
+		
+		public function customPage()
+		{
+			$ns = e107::getRender();
+			$text = 'Hello World!';
+			$ns->tablerender('Hello',$text);	
+			
+		}
+	*/
+			
+}
+				
+
+
+	
+		
+
+				
+class dblog_ui extends e_admin_ui
+{
+			
+		protected $pluginTitle		= 'adminlog';
+		protected $pluginName		= 'adminlog';
+		protected $table			= 'dblog';
+		protected $pid				= 'dblog_id';
+		protected $perPage 			= 10; 
+			
+		protected $fields 		= array (  
+	//	  'checkboxes' 			=>   array ( 'title' => '', 'type' => null, 'data' => null, 'width' => '5%', 'thclass' => 'center', 'forced' => '1', 'class' => 'center', 'toggle' => 'e-multiselect',  ),
+		  'dblog_id' 			=>   array ( 'title' => LAN_ID, 'data' => 'int', 'width' => '5%', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left',  ),
+		  'dblog_datestamp' 	=>   array ( 'title' => LAN_DATESTAMP, 'type' => 'method', 'data' => 'int', 'width' => 'auto', 'filter' => true, 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left',  ),
+		  'dblog_microtime' 	=>   array ( 'title' => 'Microtime', 'type' => 'method', 'data' => 'int', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'center', 'thclass' => 'center',  ),
+		  'dblog_type' 			=>   array ( 'title' => LAN_TYPE, 'type' => 'method', 'data' => 'int', 'width' => 'auto', 'batch' => true, 'filter' => true, 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left',  ),
+		  'dblog_eventcode' 	=>   array ( 'title' => 'Eventcode', 'type' => 'method', 'data' => 'str', 'width' => 'auto', 'filter' => true, 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'center', 'thclass' => 'center',  ),
+		  'dblog_user_id' 		=>   array ( 'title' => LAN_ID, 'type' => 'user', 'data' => 'int', 'width' => '5%', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left',  ),
+		  'dblog_user_name' 	=>   array ( 'title' => LAN_USER, 'type' => 'text', 'data' => 'str', 'width' => 'auto', 'filter' => true, 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left',  ),
+		  'dblog_ip' 			=>   array ( 'title' => LAN_IP, 'type' => 'text', 'data' => 'str', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'center', 'thclass' => 'center',  ),
+		  'dblog_caller' 		=>   array ( 'title' => 'Caller', 'type' => 'method', 'data' => 'str', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'center', 'thclass' => 'center',  ),
+		  'dblog_title' 		=>   array ( 'title' => LAN_TITLE, 'type' => 'method', 'data' => 'str', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left',  ),
+		  'dblog_remarks' 		=>   array ( 'title' => 'Remarks', 'type' => 'method', 'data' => 'str', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'center', 'thclass' => 'center',  ),
+		  'options' 			=>   array ( 'title' => 'Options', 'type' => null,  'nolist'=>true,  'data' => null, 'width' => '10%', 'thclass' => 'center last', 'class' => 'center last', 'forced' => '1',  ),
+		);		
+		
+		protected $fieldpref = array('dblog_id', 'dblog_datestamp', 'dblog_microtime', 'dblog_type', 'dblog_eventcode', 'dblog_user_id', 'dblog_user_name', 'dblog_ip', 'dblog_caller', 'dblog_title', 'dblog_remarks');
+			
+}
+				
+
+	
+
+// Routine to handle the simple bbcode-like codes for log body text
+
+		function log_process($matches)
+		{
+			switch($matches[1])
+			{
+				case 'br':
+					return '<br />';
+				case 'link':
+					$temp = substr($matches[2], 1);
+					return "<a href='{$temp}'>{$temp}</a>";
+				case 'test':
+					return '----TEST----';
+				default:
+					return $matches[0]; // No change
+			}
+		}		
+
+
+		function gen_log_delete($selectname)
+		{
+			$values = array(90, 60, 30, 21, 20, 14, 10, 7, 6, 5, 4, 3, 2, 1);
+			$ret = "<select name='{$selectname}' class='tbox select'>";
+			$selected = " selected='selected'"; // Always select the first (highest) value
+			foreach($values as $v)
+			{
+				$ret .= "<option value='{$v}'{$selected}>{$v}</option>";
+				$selected = '';
+			}
+			$ret .= "</select>";
+			return $ret;
+		}
+
+
+		
+new adminlog_admin();
+
+require_once(e_ADMIN."auth.php");
+e107::getAdminUI()->runPage();
+
+require_once(e_ADMIN."footer.php");
+exit;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+// Everything below this point is currently unused, but left for reference in case of bugs. 
+// ----------------------------------------------------------------------------------------------------------
+
+
+
+
+
+
+
+
 if(is_array($pref['lan_log_list'])) //... and for any plugins which support it
 {
 	foreach($pref['lan_log_list'] as $path => $file)
@@ -1054,19 +1765,7 @@ function admin_log_adminmenu()
 
 require_once (e_ADMIN."footer.php");
 
-function gen_log_delete($selectname)
-{
-	$values = array(90, 60, 30, 21, 20, 14, 10, 7, 6, 5, 4, 3, 2, 1);
-	$ret = "<select name='{$selectname}' class='tbox select'>";
-	$selected = " selected='selected'"; // Always select the first (highest) value
-	foreach($values as $v)
-	{
-		$ret .= "<option value='{$v}'{$selected}>{$v}</option>";
-		$selected = '';
-	}
-	$ret .= "</select>";
-	return $ret;
-}
+
 
 /**
  * Handle page DOM within the page header