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

// =======================================================================
// Module name: Admin Modules
// File name: admin_modules.inc
// Version: 1.0
// Description: This script contains php code for the admin modules core.
// This is a script that controls core fuctions of the program. It is
// pre-installed with the program and can not be uninstalled. This script
// allows users with administrator rights to add,
// manage, search, and delete admin modules.
// 
// 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 - DC - Version 1.0
// =======================================================================

if ($request == "run_install" and $install_type == "express" and $admin_rights == "Admin") {

	$db_create_admin_modules = "CREATE TABLE admin_modules (" . 
		"id int not null auto_increment primary key, " . 
		"module_name text, " . 
		"file_path text, " . 
		"rights text, " . 
		"install_date text, " . 
		"install_time text" . 
		")";

		echo("<tr>");
		echo("<td>" . $font_body . "Create Modules</font></td>");
		echo("<td>" . $font_body);
		if (@mysql_query($db_create_admin_modules)) {
			echo("Successful");
		} else {
			echo("Error");
		}
		echo("</font></td>");
		echo("</tr>");
}

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

if ($page == "modules" and !$request and $admin_rights == "Admin") {
	echo("<b>Modules</b><p>");

	$order_by = $_GET['order_by'];
	$sort = $_GET['sort'];

	// ==================== START OF PAGE # HEADER ====================

	if ($_POST["results_per_page"]) {
		$results_per_page  = $_POST["results_per_page"];
		$_SESSION['results_per_page'] = $results_per_page;
	} else {
		if (!$_SESSION['results_per_page']) {
			$results_per_page=10;
		}
	}
	if ($_GET["start_page"]) {
		$start_page  = $_GET["start_page"];
	} else {
		$start_page=1;
	}
	$start_from = ($start_page-1) * $results_per_page; 

	echo("<p>");
	echo("<table border='0' cellpadding='0' cellspacing='0' bordercolor='#000000' width='100%'>");
	echo("<tr>");
	echo("<td align='left' width='50%'>" . $font_body);

	echo "<b>Pages:&nbsp;&nbsp;";

	$db_count_admin_modules = @mysql_query("SELECT COUNT(id) FROM admin_modules"); 
	$row = @mysql_fetch_row($db_count_admin_modules); 
	$total_records = $row[0]; 
	$total_start_pages = ceil($total_records / $results_per_page); 

	for ($page_number=1; $page_number<=$total_start_pages; $page_number++) {
		if ($page_number == $start_page) {
			echo "$page_number&nbsp;&nbsp;";
		} else {
			echo "<a href='" . $_SERVER['PHP_SELF'] . "?page=modules&results_per_page=$results_per_page&start_page=".$page_number."'>".$page_number."</a>&nbsp; ";
		}
	}
	echo "</b>";

	echo("</td>");
	echo("<td align='left' width='50%'>" . $font_body);

	echo("<table border='0' cellpadding='2' cellspacing='0'>");
	echo("<form action='" . $_SERVER['PHP_SELF'] . "?page=modules&start_page=".$start_page."' method='post'>");
	echo("<tr>");
	echo("<td>" . $font_body . "<b>Items per page:</b> </font></td>");
	echo("<td>" . $font_body . "");
	echo("<select size='1' name='results_per_page'>");
	if ($results_per_page == 10) {
		echo("<option value='10' selected>10</option>");
	} else {
		echo("<option value='10'>10</option>");
	}
	if ($results_per_page == 25) {
		echo("<option value='25' selected>25</option>");
	} else {
		echo("<option value='25'>25</option>");
	}
	if ($results_per_page == 50) {
		echo("<option value='50' selected>50</option>");
	} else {
		echo("<option value='50'>50</option>");
	}
	if ($results_per_page == 100) {
		echo("<option value='100' selected>100</option>");
	} else {
		echo("<option value='100'>100</option>");
	}
	if ($results_per_page == 99999) {
		echo("<option value='99999' selected>All</option>");
	} else {
		echo("<option value='99999'>All</option>");
	}
	echo("</select>");
	echo("</font></td>");
	echo("<td>" . $font_body . "<input type='submit' name ='submit' value ='Change'></font></td>");
	echo("</tr>");
	echo("</form>");
	echo("</table>");

	echo("</td>");
	echo("</tr>");
	echo("</table>");

	// ==================== END OF PAGE # HEADER ====================

	echo("<p>[<a href='" . $_SERVER['PHP_SELF'] . "?page=modules&request=add_module'>" . $link_color . "Add</font></a>]&nbsp;");
	echo("[<a href='" . $_SERVER['PHP_SELF'] . "?page=modules&request=search_modules'>" . $link_color . "Search</font></a>]<p>");

	echo("<table border='0' cellpadding='5' cellspacing='0'>");
	echo("<tr>");
	if (!$sort or $sort == "DESC") { 
		echo("<td>" . $font_body . "<b><a href='" . $_SERVER['PHP_SELF'] . "?page=modules&order_by=module_name&sort=ASC'>" . $link_color . "Module Name</font></a></b></td>");
		echo("<td>" . $font_body . "<b>Actions</b></td>");
	}
	if ($sort == "ASC") { 
		echo("<td>" . $font_body . "<b><a href='" . $_SERVER['PHP_SELF'] . "?page=modules&order_by=module_name&sort=DESC'>" . $link_color . "Module Name</font></a></b></td>");
		echo("<td>" . $font_body . "<b>Actions</b></td>");
	}
	echo("</tr>");

	if ($order_by) {
		if ($sort) {
			$db_lookup_admin_modules = @mysql_query("SELECT id, module_name FROM admin_modules ORDER BY $order_by $sort LIMIT $start_from, $results_per_page");
		} else {
			$db_lookup_admin_modules = @mysql_query("SELECT id, module_name FROM admin_modules ORDER BY $order_by LIMIT $start_from, $results_per_page");
		}
	} else {
		$db_lookup_admin_modules = @mysql_query("SELECT id, module_name FROM admin_modules ORDER BY id DESC LIMIT $start_from, $results_per_page");
	}
	
	while ($db_admin_modules = @mysql_fetch_array($db_lookup_admin_modules)) {
		$db_admin_modules_id = $db_admin_modules['id'];
		$db_admin_modules_module_name = $db_admin_modules['module_name'];

		$db_lookup_admin_menu = @mysql_query("SELECT page FROM admin_menu WHERE name='$db_admin_modules_module_name'");
		$db_admin_menu = @mysql_fetch_array($db_lookup_admin_menu);
		$db_admin_menu_page = $db_admin_menu['page'];
		
		echo("<tr>");
		echo("<td>" . $font_body . $db_admin_modules_module_name . "</font></td>");
		echo("<td>" . $font_body . "");
		echo("[<a href='" . $_SERVER['PHP_SELF'] . "?page=modules&request=view_module&module_id=$db_admin_modules_id'>" . $link_color . "View</font></a>]&nbsp;");
		if ($admin_rights == "Admin") {
			echo("[<a href='" . $_SERVER['PHP_SELF'] . "?page=" . $db_admin_menu_page . "&request=uninstall'>" . $link_color . "Uninstall</font></a>]");
		}
		echo("</font></td>");
		echo("</tr>");
	}
	echo("</table>");

	echo("<p>[<a href='" . $_SERVER['PHP_SELF'] . "?page=modules&request=add_module'>" . $link_color . "Add</font></a>]&nbsp;");
	echo("[<a href='" . $_SERVER['PHP_SELF'] . "?page=modules&request=search_modules'>" . $link_color . "Search</font></a>]");

	// ==================== START OF PAGE # FOOTER ====================

	echo("<p>");
	echo("<table border='0' cellpadding='0' cellspacing='0' bordercolor='#000000' width='100%'>");
	echo("<tr>");
	echo("<td align='left' width='50%'>" . $font_body);

	echo "<b>Pages:&nbsp;&nbsp;";

	$db_count_admin_modules = @mysql_query("SELECT COUNT(id) FROM admin_modules"); 
	$row = @mysql_fetch_row($db_count_admin_modules); 
	$total_records = $row[0]; 
	$total_start_pages = ceil($total_records / $results_per_page); 

	for ($page_number=1; $page_number<=$total_start_pages; $page_number++) {
		if ($page_number == $start_page) {
			echo "$page_number&nbsp;&nbsp;";
		} else {
			echo "<a href='" . $_SERVER['PHP_SELF'] . "?page=modules&results_per_page=$results_per_page&start_page=".$page_number."'>".$page_number."</a>&nbsp; ";
		}
	}
	echo "</b>";

	echo("</td>");
	echo("<td align='left' width='50%'>" . $font_body);

	echo("<table border='0' cellpadding='2' cellspacing='0'>");
	echo("<form action='" . $_SERVER['PHP_SELF'] . "?page=modules&start_page=".$start_page."' method='post'>");
	echo("<tr>");
	echo("<td>" . $font_body . "<b>Items per page:</b> </font></td>");
	echo("<td>" . $font_body . "");
	echo("<select size='1' name='results_per_page'>");
	if ($results_per_page == 10) {
		echo("<option value='10' selected>10</option>");
	} else {
		echo("<option value='10'>10</option>");
	}
	if ($results_per_page == 25) {
		echo("<option value='25' selected>25</option>");
	} else {
		echo("<option value='25'>25</option>");
	}
	if ($results_per_page == 50) {
		echo("<option value='50' selected>50</option>");
	} else {
		echo("<option value='50'>50</option>");
	}
	if ($results_per_page == 100) {
		echo("<option value='100' selected>100</option>");
	} else {
		echo("<option value='100'>100</option>");
	}
	if ($results_per_page == 99999) {
		echo("<option value='99999' selected>All</option>");
	} else {
		echo("<option value='99999'>All</option>");
	}
	echo("</select>");
	echo("</font></td>");
	echo("<td>" . $font_body . "<input type='submit' name ='submit' value ='Change'></font></td>");
	echo("</tr>");
	echo("</form>");
	echo("</table>");

	echo("</td>");
	echo("</tr>");
	echo("</table>");

	// ==================== END OF PAGE # FOOTER ====================

}

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

if ($page == "modules" and $request == "add_module" and $admin_rights == "Admin") {
	echo("<b>Modules - Add Module</b><p>");
	echo("<form action='" . $_SERVER['PHP_SELF'] . "?page=modules&request=add_module_submit' method='post'>");
	echo("<input type='hidden' name='product_id' value='" . $product_id . "'>");
	echo("<table border='0' cellpadding='5' cellspacing='0'>");
	echo("<tr>");
	echo("<td>" . $font_body . "File Name:</font></td>");
	echo("<td>" . $font_body . "<input type='text' name='file_name'><br><i>Example: file_name.inc</i></font></td>");
	echo("</tr>");
	echo("<tr>");
	echo("<td>" . $font_body . "&nbsp;</font></td>");
	echo("<td>" . $font_body . "<input type='submit' name ='submit' value ='Install'></font></td>");
	echo("</tr>");
	echo("</table>");
	echo("</form>");

	echo("<p>[<a href='" . $_SERVER['PHP_SELF'] . "?page=modules'>" . $link_color . "Modules</font></a>]<p>");
}

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

if ($page == "modules" and $request == "add_module_submit" and $admin_rights == "Admin") {
	
	$file_name = $_POST['file_name'];
	$request = "install";
	$install_type = "express";
	$include = $file_name;

	include($file_name);
}

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

if ($page == "modules" and $request == "view_module" and $admin_rights == "Admin") {
	echo("<b>Modules - View Module</b><p>");
	
	$module_id = $_GET['module_id'];

	$db_lookup_admin_modules = @mysql_query("SELECT module_name, menu_section, file_path, rights, install_date, install_time FROM admin_modules WHERE id='$module_id'");
	$db_admin_modules = @mysql_fetch_array($db_lookup_admin_modules);
	
	$db_admin_modules_module_name = $db_admin_modules['module_name'];
	$db_admin_modules_menu_section = $db_admin_modules['menu_section'];
	$db_admin_modules_file_path = $db_admin_modules['file_path'];
	$db_admin_modules_rights = $db_admin_modules['rights'];
	$db_admin_modules_install_date = $db_admin_modules['install_date'];
	$db_admin_modules_install_time = $db_admin_modules['install_time'];

	echo("<table border='0' cellpadding='5' cellspacing='0'>");
	echo("<tr>");
	echo("<td>" . $font_body . "Install Date:</font></td>");
	echo("<td>" . $font_body . $db_admin_modules_install_date . "</font></td>");
	echo("</tr>");
	echo("<tr>");
	echo("<td>" . $font_body . "Install Time:</font></td>");
	echo("<td>" . $font_body . $db_admin_modules_install_time . "</font></td>");
	echo("</tr>");
	echo("</table>");
	echo("<p>");
	
	echo("<table border='0' cellpadding='5' cellspacing='0'>");
	echo("<tr>");
	echo("<td>" . $font_body . "Module Name:</font></td>");
	echo("<td>" . $font_body . $db_admin_modules_module_name . "</font></td>");
	echo("</tr>");
	echo("<tr>");
	echo("<td>" . $font_body . "Menu Section:</font></td>");
	echo("<td>" . $font_body . $db_admin_modules_menu_section . "</font></td>");
	echo("</tr>");
	echo("<tr>");
	echo("<td>" . $font_body . "File Name:</font></td>");
	echo("<td>" . $font_body . $db_admin_modules_file_path . "</font></td>");
	echo("</tr>");
	echo("<tr>");
	echo("<td>" . $font_body . "Rights Required (if any):</font></td>");
	echo("<td>" . $font_body . $db_admin_modules_rights . "&nbsp;</font></td>");
	echo("</tr>");
	echo("</table>");

	echo("<p>[<a href='" . $_SERVER['PHP_SELF'] . "?page=modules'>" . $link_color . "Modules</font></a>]<p>");

}

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

if ($page == "modules" and $request == "search_modules" and $admin_rights == "Admin") {
	echo("<b>Modules - Search Modules</b><p>");

	echo("<form action='" . $_SERVER['PHP_SELF'] . "?page=modules&request=search_modules_submit' method='post'>");
	echo("<table border='0' cellpadding='5' cellspacing='0'");
	echo("<tr>");
	echo("<td valign='top' align='left'>" . $font_body . "Module name: </td></font>");
	echo("<td>" . $font_body . " ");
	echo("<input type='text' name='module_name'> ");
	echo("<input type='submit' name ='submit' value ='Search'>");
	echo("</form></td>");
	echo("</tr>");
	echo("</table>");
	echo($font_body . "<p>[<a href='" . $_SERVER['PHP_SELF'] . "?page=modules'>" . $link_color . "Modules</font></a>]<p>");
}

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

if ($page == "modules" and $request == "search_modules_submit" and $admin_rights == "Admin") {
	echo("<b>Modules - Search Modules</b><p><p>");

	$module_name = $_POST['module_name'];

	$db_lookup_admin_modules = @mysql_query("SELECT id, module_name FROM admin_modules WHERE module_name='$module_name' ORDER BY id DESC");
	$db_admin_modules = @mysql_fetch_array($db_lookup_admin_modules);
	$db_admin_modules_id = $db_admin_modules['id'];
	$db_admin_modules_name = $db_admin_modules['module_name'];

	if ($db_admin_modules_id) {
		echo("<table border='0' cellpadding='5' cellspacing='0'>");
		echo("<tr>");
		echo("<td>" . $font_body . "<b>Module Name</b></td>");
		echo("<td>" . $font_body . "<b>Actions</b></td>");
		echo("</tr>");

		$db_lookup_admin_modules = @mysql_query("SELECT id, module_name, page_name FROM admin_modules WHERE module_name='$module_name'");

		while ($db_admin_modules = @mysql_fetch_array($db_lookup_admin_modules)) {
			$db_admin_modules_id = $db_admin_modules['id'];
			$db_admin_modules_module_name = $db_admin_modules['module_name'];
			$db_admin_modules_page_name = $db_admin_modules['page_name'];

			echo("<tr>");
			echo("<td>" . $font_body . $db_admin_modules_module_name . "</td>");
			echo("<td>". $font_body . "&nbsp;[<a href='" . $_SERVER['PHP_SELF'] . "?page=modules&request=view_module&module_id=$db_admin_modules_id'>" . $link_color . "View</font></a>]&nbsp;[<a href='" . $_SERVER['PHP_SELF'] . "?page=" . $db_admin_modules_page_name . "&request=uninstall'>" . $link_color . "Uninstall</font></a>]&nbsp;</td>");
			echo("</tr>");
		}
		echo("</table>");
	} else {
		echo("Sorry, there were no results found matching \"$module_name\".");
	}
	echo("<p>[<a href='" . $_SERVER['PHP_SELF'] . "?page=modules&request=search_modules'>" . $link_color . "Search Modules</font></a>]<p>");
}

?>
Return current item: FreePHPShoppingCartSoftware