Location: PHPKode > projects > FreePHPShoppingCartSoftware > admin_log.inc
<?php

// =======================================================================
// Module name: Admin Log
// File name: admin_log.inc
// Version: 1.0
// Description: This script contains php code for the admin log module.
// This module allows users to view, search, and delete logged admin
// activity.
//
// Comments are included within this script to document changes made to
// the code with each new version of the script. Each comment also lists
// the author's initials to document who made the changes to the code.
//
// Copyright (C) 2006-2010 Dustin Cowell Enterprises
//
// License: GNU General Public License, Version 2
//
// Link: http://www.gnu.org/licenses/gpl-2.0.txt
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to:
//
// Free Software Foundation, Inc.
// 51 Franklin Street, Fifth Floor
// Boston, MA  02110-1301 USA
// =======================================================================

// =======================================================================
// Comment - Version 1.0 - DC
// =======================================================================

if ($request == "install" and $admin_rights == "Admin") {
	echo("<b>Log - Install Module</b><p>");

	$db_lookup_backup_log = @mysql_query("SELECT id FROM backup_log");

	if ($db_lookup_backup_log) {
		echo("A backup of the admin log module has been found from a ");
		echo("prior installation. If you would like to restore the ");
		echo("backup data and install the module, click <i>Install ");
		echo("and Restore Backup</i>. If you prefer to not restore ");
		echo("the backup data and you want to start fresh, click ");
		echo("<i>Install and DO NOT Restore Backup</i>.<p>");
		echo("[<a href='" . $_SERVER['PHP_SELF'] . "?include=$include&page=log&request=install_from_backup'>Install and Restore Backup</a>]&nbsp;&nbsp;|&nbsp;&nbsp;");
		echo("[<a href='" . $_SERVER['PHP_SELF'] . "?include=$include&page=log&request=install_not_from_backup'>Install and DO NOT Restore Backup</a>]");
	} else {
		echo("No backup from a prior installation of the admin log module ");
		echo("was found. A new installation will be created. Click ");
		echo("<i>Install Module</i> to proceed.<p>");
		echo("[<a href='" . $_SERVER['PHP_SELF'] . "?include=$include&page=log&request=install_not_from_backup'>Install Module</a>]");
	}
}

// =======================================================================
// Comment - Version 1.0 - DC
// =======================================================================

if ($page == "log" and $request == "install_from_backup" and $admin_rights == "Admin") {
	echo("<b>Log - Install Module</b><p>");
	
	$db_lookup_admin_modules = @mysql_query("SELECT id FROM admin_modules WHERE module_name='Log'");
	$db_admin_modules = @mysql_fetch_array($db_lookup_admin_modules);

	if ($db_admin_modules) {
		echo("The admin log module is already installed, please uninstall before installing again.");
	} else {
		echo("The admin log module will now be installed (from a backup)...<p>");

		$date = date('m/d/Y');
		$time = date('g:i A');
		
		$db_restore_log = "RENAME TABLE backup_admin_log TO admin_log";
		$db_restore_log_settings = "RENAME TABLE backup_admin_log_settings TO admin_log_settings";
		
		$db_insert_log = "INSERT INTO admin_modules SET " . 
			"module_name = 'Log', " . 
			"menu_section = 'Administration', " . 
			"file_path = 'admin_admin_log.inc', " . 
			"version = '$current_version', " . 
			"rights = 'Admin', " . 
			"page_name = 'log', " . 
			"install_date = '$date', " . 
			"install_time = '$time'";

		$db_insert_log_settings = "INSERT INTO admin_modules SET " . 
			"module_name = 'Log Settings', " . 
			"menu_section = 'Administration', " . 
			"file_path = 'admin_log.inc', " . 
			"version = '$current_version', " . 
			"rights = 'Admin', " . 
			"page_name = 'log_settings', " . 
			"install_date = '$date', " . 
			"install_time = '$time'";

		echo("Status:<p>");
		if (@mysql_query($db_restore_log)) {
			echo("db_restore_log (function name) successful. <p>");
		} else {
			echo("An error was encountered. <p>Software version: $current_version <br>Function name: db_restore_log<br>File name: admin_log.inc <p>Please report this error to OSModSoft Support, <a href='http://www.osmodsoft.com/index.php?page=support' target='_blank'>click here</a>. Please note your software version, the function name, and the file name. <p>");
		}
		if (@mysql_query($db_restore_log_settings)) {
			echo("db_restore_log_settings (function name) successful. <p>");
		} else {
			echo("An error was encountered. <p>Software version: $current_version <br>Function name: db_restore_log_settings<br>File name: admin_log.inc <p>Please report this error to OSModSoft Support, <a href='http://www.osmodsoft.com/index.php?page=support' target='_blank'>click here</a>. Please note your software version, the function name, and the file name. <p>");
		}
		if (@mysql_query($db_insert_log)) {
			echo("db_insert_log (function name) successful. <p>");
		} else {
			echo("An error was encountered. <p>Software version: $current_version <br>Function name: db_insert_log<br>File name: admin_log.inc <p>Please report this error to OSModSoft Support, <a href='http://www.osmodsoft.com/index.php?page=support' target='_blank'>click here</a>. Please note your software version, the function name, and the file name. <p>");
		}
		if (@mysql_query($db_insert_log_settings)) {
			echo("db_insert_log_settings (function name) successful. <p>");
		} else {
			echo("An error was encountered. <p>Software version: $current_version <br>Function name: db_insert_log_settings<br>File name: admin_log.inc <p>Please report this error to OSModSoft Support, <a href='http://www.osmodsoft.com/index.php?page=support' target='_blank'>click here</a>. Please note your software version, the function name, and the file name. <p>");
		}
	}
}

// =======================================================================
// Comment - Version 1.0 - DC
// =======================================================================

if ($page == "log" and $request == "install_not_from_backup" and $admin_rights == "Admin") {
	echo("<b>Log - Install Module</b><p>");
	
	$db_lookup_admin_modules = @mysql_query("SELECT id FROM admin_modules WHERE module_name='Admin Log'");
	$db_admin_modules = @mysql_fetch_array($db_lookup_admin_modules);

	if ($db_admin_modules) {
		echo("The admin log module is already installed, please uninstall before installing again.");
	} else {
		echo("The admin log module will now be installed (not from a backup)...<p>");

		$date = date('m/d/Y');
		$time = date('g:i A');
		
		$db_create_log = "CREATE TABLE admin_log (" . 
			"id int not null auto_increment primary key, " . 
			"date text, " . 
			"time text, " . 
			"user_id int, " . 
			"event_id int, " .
			"event_type text, " .
			"event text" . 
			")";

		$db_create_log_settings = "CREATE TABLE admin_log_settings (" . 
			"id int not null auto_increment primary key, " . 
			"event_type text, " . 
			"on_off text" . 
			")";
		
		$db_insert_log = "INSERT INTO admin_modules SET " . 
			"module_name = 'Log', " . 
			"menu_section = 'Administration', " . 
			"file_path = 'admin_log.inc', " . 
			"rights = 'Admin', " . 
			"page_name = 'log', " . 
			"install_date = '$date', " . 
			"install_time = '$time'";

		$db_insert_log_settings = "INSERT INTO admin_modules SET " . 
			"module_name = 'Log Settings', " . 
			"menu_section = 'Administration', " . 
			"file_path = 'admin_log.inc', " . 
			"rights = 'Admin', " . 
			"page_name = 'log_settings', " . 
			"install_date = '$date', " . 
			"install_time = '$time'";

		echo("Status:<p>");
		if (@mysql_query($db_create_log)) {
			echo("db_create_log (function name) successful. <p>");
		} else {
			echo("An error was encountered. <p>Software version: $current_version <br>Function name: db_create_log<br>File name: admin_log.inc <p>Please report this error to OSModSoft Support, <a href='http://www.osmodsoft.com/index.php?page=support' target='_blank'>click here</a>. Please note your software version, the function name, and the file name. <p>");
		}
		if (@mysql_query($db_create_log_settings)) {
			echo("db_create_log_settings (function name) successful. <p>");
		} else {
			echo("An error was encountered. <p>Software version: $current_version <br>Function name: db_create_log_settings<br>File name: admin_log.inc <p>Please report this error to OSModSoft Support, <a href='http://www.osmodsoft.com/index.php?page=support' target='_blank'>click here</a>. Please note your software version, the function name, and the file name. <p>");
		}
		if (@mysql_query($db_insert_log)) {
			echo("db_insert_log (function name) successful. <p>");
		} else {
			echo("An error was encountered. <p>Software version: $current_version <br>Function name: db_insert_log<br>File name: admin_log.inc <p>Please report this error to OSModSoft Support, <a href='http://www.osmodsoft.com/index.php?page=support' target='_blank'>click here</a>. Please note your software version, the function name, and the file name. <p>");
		}
		if (@mysql_query($db_insert_log_settings)) {
			echo("db_insert_log_settings (function name) successful. <p>");
		} else {
			echo("An error was encountered. <p>Software version: $current_version <br>Function name: db_insert_log_settings<br>File name: admin_log.inc <p>Please report this error to OSModSoft Support, <a href='http://www.osmodsoft.com/index.php?page=support' target='_blank'>click here</a>. Please note your software version, the function name, and the file name. <p>");
		}
	}
}

// =======================================================================
// Comment - Version 1.0 - DC
// =======================================================================

if ($page == "log" and $request == "uninstall" and $admin_rights == "Admin") {
	echo("<b>Log - Uninstall Module</b><p>");

	echo("To create a backup of the admin log module before the module is ");
	echo("uninstalled, click <i>Uninstall and Backup</i>. If you don't ");
	echo("want to backup the admin log module before it is uninstalled, ");
	echo("click <i>Uninstall and DO NOT Backup</i>.<p>");

	echo("[<a href='" . $_SERVER['PHP_SELF'] . "?page=log&request=uninstall_backup'>Uninstall and Backup</a>]&nbsp;&nbsp;|&nbsp;&nbsp;");
	echo("[<a href='" . $_SERVER['PHP_SELF'] . "?page=log&request=uninstall_no_backup'>Uninstall and DO NOT Backup</a>]");
}

// =======================================================================
// Comment - Version 1.0 - DC
// =======================================================================

if ($page == "log" and $request == "uninstall_backup" and $admin_rights == "Admin") {
	echo("<b>Log - Uninstall Module</b><p>");

	echo("The admin log module will now be backed up and then uninstalled... <p>");
	
	@mysql_query("DROP TABLE backup_admin_log");
	@mysql_query("DROP TABLE backup_admin_log_settings");
	$db_backup_log = @mysql_query("RENAME TABLE admin_log TO backup_admin_log");
	$db_backup_log_settings = @mysql_query("RENAME TABLE admin_log_settings TO backup_admin_log_settings");
	$db_delete_log = @mysql_query("DELETE FROM admin_modules WHERE module_name='Log'");
	$db_delete_log_settings = @mysql_query("DELETE FROM admin_modules WHERE module_name='Log Settings'");

	echo("Status:<p>");
	if ($db_backup_log) {
		echo("db_backup_log (function name) successful. <p>");
	} else {
		echo("An error was encountered. <p>Software version: $current_version <br>Function name: db_backup_log<br>File name: admin_log.inc <p>Please report this error to OSModSoft Support, <a href='http://www.osmodsoft.com/index.php?page=support' target='_blank'>click here</a>. Please note your software version, the function name, and the file name. <p>");
	}
	if ($db_backup_log_settings) {
		echo("db_backup_log_settings (function name) successful. <p>");
	} else {
		echo("An error was encountered. <p>Software version: $current_version <br>Function name: db_backup_log_settings<br>File name: admin_log.inc <p>Please report this error to OSModSoft Support, <a href='http://www.osmodsoft.com/index.php?page=support' target='_blank'>click here</a>. Please note your software version, the function name, and the file name. <p>");
	}
	if ($db_delete_log) {
		echo("db_delete_log (function name) successful. <p>");
	} else {
		echo("An error was encountered. <p>Software version: $current_version <br>Function name: db_delete_log<br>File name: admin_log.inc <p>Please report this error to OSModSoft Support, <a href='http://www.osmodsoft.com/index.php?page=support' target='_blank'>click here</a>. Please note your software version, the function name, and the file name. <p>");
	}
	if ($db_delete_log_settings) {
		echo("db_delete_log_settings (function name) successful. <p>");
	} else {
		echo("An error was encountered. <p>Software version: $current_version <br>Function name: db_delete_log_settings<br>File name: admin_log.inc <p>Please report this error to OSModSoft Support, <a href='http://www.osmodsoft.com/index.php?page=support' target='_blank'>click here</a>. Please note your software version, the function name, and the file name. <p>");
	}
}

// =======================================================================
// Comment - Version 1.0 - DC
// =======================================================================

if ($page == "log" and $request == "uninstall_no_backup" and $admin_rights == "Admin") {
	echo("<b>Log - Uninstall Module</b><p>");

	echo("The admin log module will now be uninstalled (no backup will be created, as requested)...<p>");
	
	$db_delete_table_log = @mysql_query("DROP TABLE admin_log");
	$db_delete_table_log_settings = @mysql_query("DROP TABLE admin_log_settings");
	$db_delete_module_log = @mysql_query("DELETE FROM admin_modules WHERE module_name='Log'");
	$db_delete_module_log_settings = @mysql_query("DELETE FROM admin_modules WHERE module_name='Log Settings'");

	echo("Status:<p>");
	if ($db_delete_table_log) {
		echo("db_delete_table_log (function name) successful. <p>");
	} else {
		echo("An error was encountered. <p>Software version: $current_version <br>Function name: db_delete_table_log<br>File name: admin_log.inc <p>Please report this error to OSModSoft Support, <a href='http://www.osmodsoft.com/index.php?page=support' target='_blank'>click here</a>. Please note your software version, the function name, and the file name. <p>");
	}
	if ($db_delete_table_log_settings) {
		echo("db_delete_table_log_settings (function name) successful. <p>");
	} else {
		echo("An error was encountered. <p>Software version: $current_version <br>Function name: db_delete_table_log_settings<br>File name: admin_log.inc <p>Please report this error to OSModSoft Support, <a href='http://www.osmodsoft.com/index.php?page=support' target='_blank'>click here</a>. Please note your software version, the function name, and the file name. <p>");
	}
	if ($db_delete_module_log) {
		echo("db_delete_module_log (function name) successful. <p>");
	} else {
		echo("An error was encountered. <p>Software version: $current_version <br>Function name: db_delete_module_log<br>File name: admin_log.inc <p>Please report this error to OSModSoft Support, <a href='http://www.osmodsoft.com/index.php?page=support' target='_blank'>click here</a>. Please note your software version, the function name, and the file name. <p>");
	}
	if ($db_delete_module_log_settings) {
		echo("db_delete_module_log_settings (function name) successful. <p>");
	} else {
		echo("An error was encountered. <p>Software version: $current_version <br>Function name: db_delete_module_log_settings<br>File name: admin_log.inc <p>Please report this error to OSModSoft Support, <a href='http://www.osmodsoft.com/index.php?page=support' target='_blank'>click here</a>. Please note your software version, the function name, and the file name. <p>");
	}
}

// =======================================================================
// Comment - Version 1.0 - DC
// =======================================================================

if ($page == "log" and !$request) {
	echo("<b>Log</b><p>");

	echo("[<a href='" . $_SERVER['PHP_SELF'] . "?page=log&request=view_log'>View Log Data</a>]<p>");
}

// =======================================================================
// Comment - Version 1.0 - DC
// =======================================================================

if ($page == "log" and $request == "view_log") {
	echo("<b>Log</b><p>");

	$db_lookup_log_settings = @mysql_query("SELECT event_type FROM admin_log_settings");

	echo("Select the type of event you would like to view log data for:<p>");

	echo("[<a href='" . $_SERVER['PHP_SELF'] . "?page=log&request=view_log_submit&event_type=all'>All Event Types</a>]<p>");

	while ($db_log_settings = @mysql_fetch_array($db_lookup_log_settings)) {

		$db_log_settings_event_type = $db_log_settings['event_type'];

		echo("[<a href='" . $_SERVER['PHP_SELF'] . "?page=log&request=view_log_submit&event_type=" . $db_log_settings_event_type . "'>$db_log_settings_event_type</a>]<p>");
	}
}

// =======================================================================
// Comment - Version 1.0 - DC
// =======================================================================

if ($page == "log" and $request == "view_log_submit") {
	echo("<b>Log</b><p>");

	$event_type = $_GET['event_type'];

	if ($event_type == "all") {
		$db_lookup_log = @mysql_query("SELECT date, time, user_id, event_id, event_type, event FROM admin_log");
	} else {
		$db_lookup_log = @mysql_query("SELECT date, time, user_id, event_id, event_type, event FROM admin_log WHERE event_type='$event_type'");
	}
	
	echo("<table border='0' cellpadding='5' cellspacing='0' width='100%'>");
	echo("<tr>");
	echo("<td>" . $font_body . "<b>Date</b></font></td>");
	echo("<td>" . $font_body . "<b>Time</b></font></td>");
	echo("<td>" . $font_body . "<b>User</b></font></td>");
	echo("<td>" . $font_body . "<b>Event Type</b></font></td>");
	echo("<td>" . $font_body . "<b>Event</b></font></td>");
	echo("</tr>");

	while ($db_log = @mysql_fetch_array($db_lookup_log)) {

		$db_log_date = $db_log['date'];
		$db_log_time = $db_log['time'];
		$db_log_user_id = $db_log['user_id'];
		$db_log_event_type = $db_log['event_type'];
		$db_log_event = $db_log['event'];

		$db_lookup_admin_users = @mysql_query("SELECT first_name, last_name FROM admin_users WHERE id='" . $db_log_user_id . "'");
		$db_admin_users = @mysql_fetch_array($db_lookup_admin_users);

		$db_admin_users_first_name = $db_admin_users['first_name'];
		$db_admin_users_last_name = $db_admin_users['last_name'];

		echo("<tr>");
		echo("<td>" . $font_body . $db_log_date . "</font></td>");
		echo("<td>" . $font_body . $db_log_time . "</font></td>");
		echo("<td>" . $font_body . $db_admin_users_first_name . "&nbsp;" . $db_admin_users_last_name . "</font></td>");
		echo("<td>" . $font_body . $db_log_event_type . "</font></td>");
		echo("<td>" . $font_body . $db_log_event . "</font></td>");
		echo("</tr>");
	}
	echo("</table><p>");
	echo("[<a href='" . $_SERVER['PHP_SELF'] . "?page=log'>Main Page</a>]");
}

?>
Return current item: FreePHPShoppingCartSoftware