<?php
// =======================================================================
// Module name: Links
// File name: links.inc
// Version: 1.0
// Description: This script contains php code for website links.
//
// 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 == "install" and $admin_rights == "Admin") {
echo("<b>Links - Install Module</b><p>");
$db_lookup_admin_settings = @mysql_query("SELECT id FROM links");
$db_pages = @mysql_fetch_array($db_lookup_pages);
if ($db_pages) {
echo("This module is already installed. The current installation must be uninstalled before a new installation can be created.");
} else {
echo("Click the link below to install this module.<p>");
echo("[<a href='" . $_SERVER['PHP_SELF'] . "?include=$include&request=run_install'>" . $link_color . "Install</font></a>]");
}
}
// =======================================================================
// Comment - DC - Version 1.0
// =======================================================================
if ($request == "run_install" and $admin_rights == "Admin") {
if ($install_type != "express") {
echo("<b>Pages - Install Module</b><p>");
}
$db_create_links = "CREATE TABLE links (" .
"id int not null auto_increment primary key, " .
"links_categories_id text, " .
"name text, " .
"url text" .
")";
$db_create_links_categories = "CREATE TABLE links_categories (" .
"id int not null auto_increment primary key, " .
"name text" .
")";
$db_insert_admin_modules_links = "INSERT INTO admin_modules SET " .
"module_name = 'Links', " .
"file_path = 'links.inc', " .
"rights = ' ', " .
"install_date = '$date', " .
"install_time = '$time'";
if ($install_type != "express") {
echo("Links Installation Status:<p>");
echo("<table border='0' cellpadding='5' cellspacing='0'>");
}
echo("<tr>");
echo("<td>" . $font_body . "Links Table Setup</td>");
echo("<td>" . $font_body . "");
if (@mysql_query($db_create_links)) {
echo("Successful");
} else {
echo("Error");
}
echo("</font></td>");
echo("</tr>");
echo("<tr>");
echo("<td>" . $font_body . "Links Categories Table Setup</td>");
echo("<td>" . $font_body . "");
if (@mysql_query($db_create_links_categories)) {
echo("Successful");
} else {
echo("Error");
}
echo("</font></td>");
echo("</tr>");
echo("<tr>");
echo("<td>" . $font_body . "Links Module Registration</td>");
echo("<td>" . $font_body . "");
if (@mysql_query($db_insert_admin_modules_links)) {
echo("Successful");
} else {
echo("Error");
}
echo("</font></td>");
echo("</tr>");
$db_lookup_admin_menu_categories = @mysql_query("SELECT id FROM admin_menu_categories WHERE name='Website'");
$db_admin_menu_categories = @mysql_fetch_array($db_lookup_admin_menu_categories);
$db_admin_menu_categories_id = $db_admin_menu_categories['id'];
if (!$db_admin_menu_categories_id) {
$db_insert_admin_menu_categories_website = "INSERT INTO admin_menu_categories SET " .
"name = 'Website'";
echo("<tr>");
echo("<td>" . $font_body . "Insert Admin Menu Categories Website</td>");
echo("<td>" . $font_body . "");
if (@mysql_query($db_insert_admin_menu_categories_website)) {
echo("Successful");
} else {
echo("Error");
}
echo("</font></td>");
echo("</tr>");
}
$db_lookup_admin_menu_categories = @mysql_query("SELECT id FROM admin_menu_categories WHERE name='Website'");
$db_admin_menu_categories = @mysql_fetch_array($db_lookup_admin_menu_categories);
$db_admin_menu_categories_id = $db_admin_menu_categories['id'];
$db_insert_admin_menu_links = "INSERT INTO admin_menu SET " .
"menu_categories_id = '$db_admin_menu_categories_id', " .
"name = 'Links', " .
"include_file = 'links.inc', " .
"page = 'links'";
echo("<tr>");
echo("<td>" . $font_body . "Links Admin Menu Insert</td>");
echo("<td>" . $font_body . "");
if (@mysql_query($db_insert_admin_menu_links)) {
echo("Successful");
} else {
echo("Error");
}
echo("</font></td>");
echo("</tr>");
$db_lookup_admin_menu_categories = @mysql_query("SELECT id FROM admin_menu_categories WHERE name='Website'");
$db_admin_menu_categories = @mysql_fetch_array($db_lookup_admin_menu_categories);
$db_admin_menu_categories_id = $db_admin_menu_categories['id'];
$db_insert_admin_menu_link_categories = "INSERT INTO admin_menu SET " .
"menu_categories_id = '$db_admin_menu_categories_id', " .
"name = 'Link Categories', " .
"include_file = 'links.inc', " .
"page = 'link_categories'";
echo("<tr>");
echo("<td>" . $font_body . "Link Categories Admin Menu Insert</td>");
echo("<td>" . $font_body . "");
if (@mysql_query($db_insert_admin_menu_link_categories)) {
echo("Successful");
} else {
echo("Error");
}
echo("</font></td>");
echo("</tr>");
$db_lookup_menu_categories = @mysql_query("SELECT id FROM menu_categories WHERE name='Links'");
$db_menu_categories = @mysql_fetch_array($db_lookup_menu_categories);
$db_menu_categories_id = $db_menu_categories['id'];
if (!$db_menu_categories_id) {
$db_insert_menu_categories = "INSERT INTO menu_categories SET " .
"name = 'Links', " .
"left_right = 'Left'";
echo("<tr>");
echo("<td>" . $font_body . "Links Menu Categories Insert</td>");
echo("<td>" . $font_body . "");
if (@mysql_query($db_insert_menu_categories)) {
echo("Successful");
} else {
echo("Error");
}
echo("</font></td>");
echo("</tr>");
}
if ($install_type != "express") {
echo("</table>");
echo("<p>");
}
}
// =======================================================================
// Comment - DC - Version 1.0
// =======================================================================
if ($page == "links" and $request == "uninstall" and $admin_rights == "Admin") {
echo("<b>Links - Uninstall Module</b><p>");
echo("Click the link below to uninstall this module.<p>");
echo("[<a href='" . $_SERVER['PHP_SELF'] . "?page=links&request=run_uninstall'>" . $link_color . "Uninstall</font></a>]");
}
// =======================================================================
// Comment - DC - Version 1.0
// =======================================================================
if ($page == "links" and $request == "run_uninstall" and $admin_rights == "Admin") {
echo("<b>Links - Uninstall Module</b><p>");
echo("The links module will now be uninstalled...<p>");
$db_delete_table_links = @mysql_query("DROP TABLE links");
$db_delete_table_links_categories = @mysql_query("DROP TABLE links_categories");
$db_delete_module = @mysql_query("DELETE FROM admin_modules WHERE module_name='Links'");
$db_delete_admin_menu_links = "DELETE FROM admin_menu WHERE name='Links'";
$db_delete_admin_menu_links_categories = "DELETE FROM admin_menu WHERE name='Link Categories'";
echo("<table border='0' cellpadding='5' cellspacing='0'>");
echo("<tr>");
echo("<td>" . $font_body . "Links Table Deletion</td>");
echo("<td>" . $font_body . "");
if ($db_delete_table_links) {
echo("Successful");
} else {
echo("Error");
}
echo("</font></td>");
echo("</tr>");
echo("<tr>");
echo("<td>" . $font_body . "Link Categories Table Deletion</td>");
echo("<td>" . $font_body . "");
if ($db_delete_table_links_categories) {
echo("Successful");
} else {
echo("Error");
}
echo("</font></td>");
echo("</tr>");
echo("<tr>");
echo("<td>" . $font_body . "Links Module Unregistered</td>");
echo("<td>" . $font_body . "");
if ($db_delete_module) {
echo("Successful");
} else {
echo("Error");
}
echo("</font></td>");
echo("</tr>");
echo("<tr>");
echo("<td>" . $font_body . "Links Admin Menu Deletion</td>");
echo("<td>" . $font_body . "");
if (@mysql_query($db_delete_admin_menu_links)) {
echo("Successful");
} else {
echo("Error");
}
echo("</font></td>");
echo("</tr>");
echo("<tr>");
echo("<td>" . $font_body . "Link Categories Admin Menu Deletion</td>");
echo("<td>" . $font_body . "");
if (@mysql_query($db_delete_admin_menu_links_categories)) {
echo("Successful");
} else {
echo("Error");
}
echo("</font></td>");
echo("</tr>");
echo("</table>");
}
// =======================================================================
// Comment - DC - Version 1.0
// =======================================================================
if ($page == "links" and !$request and $admin_rights) {
echo("<b>Links</b><p>");
$db_lookup_links = @mysql_query("SELECT id FROM links");
$db_links = @mysql_fetch_array($db_lookup_links);
$db_links_id = $db_links['id'];
if ($db_links_id) {
// ==================== 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: ";
$db_count_links = @mysql_query("SELECT COUNT(id) FROM links");
$row = @mysql_fetch_row($db_count_links);
$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 ";
} else {
echo "<a href='" . $_SERVER['PHP_SELF'] . "?page=links&results_per_page=$results_per_page&start_page=".$page_number."'>".$page_number."</a> ";
}
}
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=links&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=links&request=new_link'>" . $link_color . "New</font></a>] [<a href='" . $_SERVER['PHP_SELF'] . "?page=link_categories'>" . $link_color . "Categories</font></a>]");
echo("<p><table border='0' cellpadding='5' cellspacing='0'>");
echo("<tr>");
echo("<td>" . $font_body . "<b>Name</b></td>");
echo("<td>" . $font_body . "<b>Category</b></td>");
echo("<td>" . $font_body . "<b>Actions</b></td>");
echo("</tr>");
$db_lookup_links = @mysql_query("SELECT id, links_categories_id, name FROM links ORDER BY name ASC LIMIT $start_from, $results_per_page");
while ($db_links = @mysql_fetch_array($db_lookup_links)) {
$db_links_id = $db_links['id'];
$db_links_links_categories_id = $db_links['links_categories_id'];
$db_links_name = $db_links['name'];
$db_lookup_links_categories = @mysql_query("SELECT name FROM links_categories WHERE id='$db_links_links_categories_id'");
$db_links_categories = @mysql_fetch_array($db_lookup_links_categories);
$db_links_categories_name = $db_links_categories['name'];
echo("<tr>");
echo("<td>" . $font_body . $db_links_name . "</td>");
echo("<td>" . $font_body . $db_links_categories_name . "</td>");
echo("<td>". $font_body . "[<a href='" . $_SERVER['PHP_SELF'] . "?page=links&request=view_link&link_id=" . $db_links_id . "'>" . $link_color . "View</font></a>] [<a href='" . $_SERVER['PHP_SELF'] . "?page=links&request=edit_link&link_id=" . $db_links_id . "'>" . $link_color . "Edit</font></a>] [<a href='" . $_SERVER['PHP_SELF'] . "?page=links&request=delete_link&link_id=" . $db_links_id . "'>" . $link_color . "Delete</font></a>]</td>");
echo("</tr>");
}
echo("</table>");
echo("<p>[<a href='" . $_SERVER['PHP_SELF'] . "?page=links&request=new_link'>" . $link_color . "New</font></a>] [<a href='" . $_SERVER['PHP_SELF'] . "?page=link_categories'>" . $link_color . "Categories</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: ";
$db_count_links = @mysql_query("SELECT COUNT(id) FROM links");
$row = @mysql_fetch_row($db_count_links);
$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 ";
} else {
echo "<a href='" . $_SERVER['PHP_SELF'] . "?page=links&results_per_page=$results_per_page&start_page=".$page_number."'>".$page_number."</a> ";
}
}
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=links&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 ====================
} else {
echo("No links were found in the database.");
echo("<p>[<a href='" . $_SERVER['PHP_SELF'] . "?page=links&request=new_link'>" . $link_color . "New</font></a>] [<a href='" . $_SERVER['PHP_SELF'] . "?page=link_categories'>" . $link_color . "Categories</font></a>]");
}
}
// =======================================================================
// Comment - DC - Version 1.0
// =======================================================================
if ($page == "links" and $request == "new_link" and $admin_rights) {
echo("<b>Links - New Link</b><p>");
echo("<form enctype='multipart/form-data' action='" . $_SERVER['PHP_SELF'] . "?page=links&request=new_link_submit' method='post'>");
echo("<table border='0' cellpadding='5' cellspacing='0'>");
echo("<tr>");
echo("<td>" . $font_body . "Name:</font></td>");
echo("<td>" . $font_body . "<input type='text' name='name' size='20'></font></td>");
echo("</tr>");
echo("<tr>");
echo("<td>" . $font_body . "Category:</font></td>");
echo("<td>" . $font_body . "");
echo("<select size='1' name='links_categories_id'><option selected value='0'>None</option>");
$db_lookup_links_categories = @mysql_query("SELECT id, name FROM links_categories ORDER BY name ASC");
while ($db_links_categories = @mysql_fetch_array($db_lookup_links_categories)) {
$db_links_categories_id = $db_links_categories['id'];
$db_links_categories_name = $db_links_categories['name'];
echo("<option value='" . $db_links_categories_id . "'>" . $db_links_categories_name . "</option>");
}
echo("</select> or new: <input type='text' name='new_category' size='20'>");
echo("</font></td>");
echo("</tr>");
echo("<tr>");
echo("<td>" . $font_body . "Website address:</font></td>");
echo("<td>" . $font_body . "<input type='text' name='url' size='30'></font></td>");
echo("</tr>");
echo("</table>");
echo("<p>");
echo("<input type='submit' name ='submit' value ='Submit'><p>");
echo("</form>");
echo("[<a href='" . $_SERVER['PHP_SELF'] . "?page=links'>" . $link_color . "Links</font></a>]<p>");
}
// =======================================================================
// Comment - DC - Version 1.0
// =======================================================================
if ($page == "links" and $request == "new_link_submit" and $admin_rights) {
echo("<b>Links - New Link</b><p>");
$name = $_POST['name'];
$links_categories_id = $_POST['links_categories_id'];
$new_category = $_POST['new_category'];
$url = $_POST['url'];
$db_lookup_links = @mysql_query("SELECT id FROM links WHERE name='$name' and url='$url'");
$db_links = @mysql_fetch_array($db_lookup_links);
$db_links_id = $db_links['id'];
if ($db_links_id) {
echo("Link already exists in database, duplicates are not allowed.<p>");
} else {
if ($new_category) {
$db_lookup_links_categories = @mysql_query("SELECT id FROM links_categories WHERE name='$new_category'");
$db_links_categories = @mysql_fetch_array($db_lookup_links_categories);
$db_links_categories_id = $db_links_categories['id'];
if ($db_links_categories_id) {
echo("Link category already exists in database, duplicates are not allowed.<p>");
} else {
$db_insert_links_categories = "INSERT INTO links_categories SET " .
"name = '$new_category'";
if (@mysql_query($db_insert_links_categories)) {
echo("Link category creation successful.<p>");
} else {
echo("Link category creation error.<p>");
}
}
$db_lookup_links_categories = @mysql_query("SELECT id FROM links_categories WHERE name='$new_category'");
$db_links_categories = @mysql_fetch_array($db_lookup_links_categories);
$db_links_categories_id = $db_links_categories['id'];
}
if ($db_links_categories_id) {
$db_insert_links = "INSERT INTO links SET " .
"name = '$name', " .
"links_categories_id = '$db_links_categories_id', " .
"url = '$url'";
} else {
$db_insert_links = "INSERT INTO links SET " .
"name = '$name', " .
"links_categories_id = '$links_categories_id', " .
"url = '$url'";
}
if (@mysql_query($db_insert_links)) {
echo("Link creation successful.<p>");
} else {
echo("Link creation error.<p>");
}
}
echo("[<a href='" . $_SERVER['PHP_SELF'] . "?page=links'>" . $link_color . "Links</font></a>]");
}
// =======================================================================
// Comment - Version 1.0 - DC
// =======================================================================
if ($page == "links" and $request == "view_link" and $admin_rights) {
echo("<b>Links - View Link</b><p>");
$link_id = $_GET['link_id'];
$db_lookup_links = @mysql_query("SELECT links_categories_id, name, url FROM links WHERE id='$link_id'");
$db_links = @mysql_fetch_array($db_lookup_links);
$db_links_links_categories_id = $db_links['links_categories_id'];
$db_links_name = $db_links['name'];
$db_links_url = $db_links['url'];
$db_lookup_links_categories = @mysql_query("SELECT name FROM links_categories WHERE id='$db_links_links_categories_id'");
$db_links_categories = @mysql_fetch_array($db_lookup_links_categories);
$db_links_categories_name = $db_links_categories['name'];
echo("<table border='0' cellpadding='5' cellspacing='0'>");
echo("<tr>");
echo("<td>" . $font_body . "Name:</td>");
echo("<td>" . $font_body . $db_links_name . "</td>");
echo("</tr>");
echo("<tr>");
echo("<td>" . $font_body . "Category:</td>");
echo("<td>" . $font_body . $db_links_categories_name . "</td>");
echo("</tr>");
echo("<tr>");
echo("<td>" . $font_body . "Website address:</td>");
echo("<td>" . $font_body . $db_links_url . "</td>");
echo("</tr>");
echo("</table>");
echo("<p>[<a href='" . $_SERVER['PHP_SELF'] . "?page=links'>" . $link_color . "Links</font></a>]");
}
// =======================================================================
// Comment - Version 1.0 - DC
// =======================================================================
if ($page == "links" and $request == "edit_link" and $admin_rights) {
echo("<b>Links - Edit Link</b><p>");
$link_id = $_GET['link_id'];
$db_lookup_links = @mysql_query("SELECT links_categories_id, name, url FROM links WHERE id='$link_id'");
$db_links = @mysql_fetch_array($db_lookup_links);
$db_links_links_categories_id = $db_links['links_categories_id'];
$db_links_name = $db_links['name'];
$db_links_url = $db_links['url'];
$db_lookup_links_categories = @mysql_query("SELECT id, name FROM links_categories WHERE id='$db_links_links_categories_id'");
$db_links_categories = @mysql_fetch_array($db_lookup_links_categories);
$db_links_categories_id = $db_links_categories['id'];
$db_links_categories_name = $db_links_categories['name'];
$db_links_name = htmlspecialchars("$db_links_name", ENT_QUOTES);
echo("<form action='" . $_SERVER['PHP_SELF'] . "?page=links&request=edit_link_submit' method='post'>");
echo("<input type='hidden' name='link_id' value='$link_id'>");
echo("<table border='0' cellpadding='5' cellspacing='0'>");
echo("<tr>");
echo("<td>" . $font_body . "Name:</font></td>");
echo("<td>" . $font_body . "<input type='text' name='name' value='$db_links_name' size='30'></font></td>");
echo("</tr>");
echo("<tr>");
echo("<td>" . $font_body . "Category:</font></td>");
echo("<td>" . $font_body . "<select size='1' name='category'>");
if (!$db_links_categories_id) {
echo("<option selected value='0'>None</option>");
} else {
echo("<option value='0'>None</option>");
}
$db_lookup_links_categories = @mysql_query("SELECT id, name FROM links_categories WHERE id='$db_links_categories_id'");
while ($db_links_categories = @mysql_fetch_array($db_lookup_links_categories)) {
$db_links_categories_id = $db_links_categories['id'];
$db_links_categories_name = $db_links_categories['name'];
echo("<option selected value='" . $db_links_categories_id . "'>" . $db_links_categories_name . "</option>");
}
$db_lookup_links_categories = @mysql_query("SELECT id, name FROM links_categories WHERE id != '$db_links_categories_id' ORDER BY name ASC");
while ($db_links_categories = @mysql_fetch_array($db_lookup_links_categories)) {
$db_links_categories_id = $db_links_categories['id'];
$db_links_categories_name = $db_links_categories['name'];
echo("<option value='" . $db_links_categories_id . "'>" . $db_links_categories_name . "</option>");
}
echo("</select> or new: <input type='text' name='new_category' size='20'>");
echo("</font></td>");
echo("</tr>");
echo("<tr>");
echo("<td>" . $font_body . "Website address:</font></td>");
echo("<td>" . $font_body . "<input type='text' name='url' value='$db_links_url' size='30'></font></td>");
echo("</tr>");
echo("</table>");
echo("<p>");
echo("<input type='submit' name ='submit' value ='Update'><p>");
echo("</form>");
echo("<p>[<a href='" . $_SERVER['PHP_SELF'] . "?page=links'>" . $link_color . "Links</font></a>]");
}
// =======================================================================
// Comment - DC - Version 1.0
// =======================================================================
if ($page == "links" and $request == "edit_link_submit" and $admin_rights) {
echo("<b>Links - Edit Link</b><p>");
$link_id = $_POST['link_id'];
$name = $_POST['name'];
$category = $_POST['category'];
$new_category = $_POST['new_category'];
$url = $_POST['url'];
if ($new_category) {
$db_lookup_links_categories = @mysql_query("SELECT id FROM links_categories WHERE name='$new_category'");
$db_links_categories = @mysql_fetch_array($db_lookup_links_categories);
$db_links_categories_id = $db_links_categories['id'];
if ($db_links_categories_id) {
echo("Link category already exists in database, duplicates are not allowed.<p>");
} else {
$db_insert_links_categories = "INSERT INTO links_categories SET " .
"name = '$new_category'";
if (@mysql_query($db_insert_links_categories)) {
echo("Link category creation successful.<p>");
} else {
echo("Link category creation error.<p>");
}
}
$db_lookup_links_categories = @mysql_query("SELECT id FROM links_categories WHERE name='$new_category'");
$db_links_categories = @mysql_fetch_array($db_lookup_links_categories);
$db_links_categories_id = $db_links_categories['id'];
}
if ($db_links_categories_id) {
$db_update_links = "UPDATE links SET " .
"name = '$name', " .
"links_categories_id = '$db_links_categories_id', " .
"url = '$url'" .
"WHERE id = '$link_id'";
} else {
$db_update_links = "UPDATE links SET " .
"name = '$name', " .
"links_categories_id = '$category', " .
"url = '$url'" .
"WHERE id = '$link_id'";
}
if (@mysql_query($db_update_links)) {
echo("Link updated successfully.<p>");
} else {
echo("Link update error.<p>");
}
echo("<p>[<a href='" . $_SERVER['PHP_SELF'] . "?page=links'>" . $link_color . "Links</font></a>]");
}
// =======================================================================
// Comment - Version 1.0 - DC
// =======================================================================
if ($page == "links" and $request == "delete_link" and $admin_rights == "Admin") {
echo("<b>Links - Delete Link</b><p>");
$link_id = $_GET['link_id'];
$db_lookup_links = @mysql_query("SELECT name FROM links WHERE id='$link_id'");
$db_links = @mysql_fetch_array($db_lookup_links);
$db_links_name = $db_links['name'];
echo("Name: $db_links_name<p>");
echo("<p>Are you sure you want to delete this link?<p>");
echo("[<a href='" . $_SERVER['PHP_SELF'] . "?page=links&request=delete_link_submit&link_id=$link_id'>" . $link_color . "Yes</font></a>] ");
echo("[<a href='" . $_SERVER['PHP_SELF'] . "?page=links&request=delete_link_cancel&link_id=$link_id'>" . $link_color . "No</font></a>] ");
echo("<p>[<a href='" . $_SERVER['PHP_SELF'] . "?page=links'>" . $link_color . "Links</font></a>]<p>");
}
// =======================================================================
// Comment - Version 1.0 - DC
// =======================================================================
if ($page == "links" and $request == "delete_link_submit" and $admin_rights == "Admin") {
echo("<b>Links - Delete Link</b><p>");
$link_id = $_GET['link_id'];
$db_delete_links = @mysql_query("DELETE FROM links WHERE id='$link_id'");
if ($db_delete_links) {
echo("The link has been deleted.");
} else {
echo("Error deleting link.");
}
echo("<p>[<a href='" . $_SERVER['PHP_SELF'] . "?page=links'>" . $link_color . "Links</font></a>]<p>");
}
// =======================================================================
// Comment - Version 1.0 - DC
// =======================================================================
if ($page == "links" and $request == "delete_link_cancel" and $admin_rights == "Admin") {
echo("<b>Links - Delete Link</b><p>");
$link_id = $_GET['link_id'];
echo("The link has not been deleted.");
echo("<p>[<a href='" . $_SERVER['PHP_SELF'] . "?page=links'>" . $link_color . "Links</font></a>]<p>");
}
// =======================================================================
// Comment - DC - Version 1.0
// =======================================================================
if ($page == "link_categories" and !$request and $admin_rights) {
echo("<b>Link Categories</b><p>");
$db_lookup_links_categories = @mysql_query("SELECT id FROM links_categories");
$db_links_categories = @mysql_fetch_array($db_lookup_links_categories);
$db_links_categories_id = $db_links_categories['id'];
if ($db_links_categories_id) {
// ==================== 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: ";
$db_count_links_categories = @mysql_query("SELECT COUNT(id) FROM links_categories");
$row = @mysql_fetch_row($db_count_links_categories);
$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 ";
} else {
echo "<a href='" . $_SERVER['PHP_SELF'] . "?page=link_categories&results_per_page=$results_per_page&start_page=".$page_number."'>".$page_number."</a> ";
}
}
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=link_categories&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=link_categories&request=new_link_category'>" . $link_color . "New</font></a>] ");
echo("<p><table border='0' cellpadding='5' cellspacing='0'>");
echo("<tr>");
echo("<td>" . $font_body . "<b>Name</b></td>");
echo("<td>" . $font_body . "<b>Actions</b></td>");
echo("</tr>");
$db_lookup_links_categories = @mysql_query("SELECT id, name FROM links_categories ORDER BY name ASC LIMIT $start_from, $results_per_page");
while ($db_links_categories = @mysql_fetch_array($db_lookup_links_categories)) {
$db_links_categories_id = $db_links_categories['id'];
$db_links_categories_name = $db_links_categories['name'];
echo("<tr>");
echo("<td>" . $font_body . $db_links_categories_name . "</td>");
echo("<td>". $font_body . "[<a href='" . $_SERVER['PHP_SELF'] . "?page=link_categories&request=view_link_category&link_categories_id=" . $db_links_categories_id . "'>" . $link_color . "View</font></a>] [<a href='" . $_SERVER['PHP_SELF'] . "?page=link_categories&request=edit_link_category&link_categories_id=" . $db_links_categories_id . "'>" . $link_color . "Edit</font></a>] [<a href='" . $_SERVER['PHP_SELF'] . "?page=link_categories&request=delete_link_category&link_categories_id=" . $db_links_categories_id . "'>" . $link_color . "Delete</font></a>]</td>");
echo("</tr>");
}
echo("</table>");
echo("<p>[<a href='" . $_SERVER['PHP_SELF'] . "?page=link_categories&request=new_link_category'>" . $link_color . "New</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: ";
$db_count_links_categories = @mysql_query("SELECT COUNT(id) FROM links_categories");
$row = @mysql_fetch_row($db_count_links_categories);
$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 ";
} else {
echo "<a href='" . $_SERVER['PHP_SELF'] . "?page=link_categories&results_per_page=$results_per_page&start_page=".$page_number."'>".$page_number."</a> ";
}
}
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=link_categories&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 ====================
} else {
echo("No link categories were found in the database.");
echo("<p>[<a href='" . $_SERVER['PHP_SELF'] . "?page=link_categories&request=new_link_category'>" . $link_color . "New</font></a>]<p>");
}
}
// =======================================================================
// Comment - DC - Version 1.0
// =======================================================================
if ($page == "link_categories" and $request == "new_link_category" and $admin_rights) {
echo("<b>Link Categories - New Link Category</b><p>");
echo("<form enctype='multipart/form-data' action='" . $_SERVER['PHP_SELF'] . "?page=link_categories&request=new_link_category_submit' method='post'>");
echo("<table border='0' cellpadding='5' cellspacing='0'>");
echo("<tr>");
echo("<td>" . $font_body . "Name:</font></td>");
echo("<td>" . $font_body . "<input type='text' name='name' size='20'></font></td>");
echo("</tr>");
echo("</table>");
echo("<p>");
echo("<input type='submit' name ='submit' value ='Submit'><p>");
echo("</form>");
echo("[<a href='" . $_SERVER['PHP_SELF'] . "?page=link_categories'>" . $link_color . "Link Categories</font></a>]<p>");
}
// =======================================================================
// Comment - DC - Version 1.0
// =======================================================================
if ($page == "link_categories" and $request == "new_link_category_submit" and $admin_rights) {
echo("<b>Link Categories - New Link Category</b><p>");
$name = $_POST['name'];
$db_lookup_links_categories = @mysql_query("SELECT id FROM links_categories WHERE name='$name'");
$db_links_categories = @mysql_fetch_array($db_lookup_links_categories);
$db_links_categories_id = $db_links_categories['id'];
if ($db_links_categories_id) {
echo("Link category already exists in database, duplicates are not allowed.");
} else {
$db_insert_links_categories = "INSERT INTO links_categories SET " .
"name = '$name'";
if (@mysql_query($db_insert_links_categories)) {
echo("Link category creation successful.<p>");
} else {
echo("Link category creation error.<p>");
}
}
echo("[<a href='" . $_SERVER['PHP_SELF'] . "?page=link_categories'>" . $link_color . "Link Categories</font></a>]<p>");
}
// =======================================================================
// Comment - Version 1.0 - DC
// =======================================================================
if ($page == "link_categories" and $request == "view_link_category" and $admin_rights) {
echo("<b>Link Categories - View Link Category</b><p>");
$link_categories_id = $_GET['link_categories_id'];
$db_lookup_links_categories = @mysql_query("SELECT name FROM links_categories WHERE id='$link_categories_id'");
$db_links_categories = @mysql_fetch_array($db_lookup_links_categories);
$db_links_categories_name = $db_links_categories['name'];
echo("<table border='0' cellpadding='5' cellspacing='0'>");
echo("<tr>");
echo("<td>" . $font_body . "Name:</td>");
echo("<td>" . $font_body . $db_links_categories_name . "</td>");
echo("</tr>");
echo("</table>");
echo("<p>");
echo("[<a href='" . $_SERVER['PHP_SELF'] . "?page=link_categories'>" . $link_color . "Link Categories</font></a>]<p>");
}
// =======================================================================
// Comment - Version 1.0 - DC
// =======================================================================
if ($page == "link_categories" and $request == "edit_link_category" and $admin_rights) {
echo("<b>Link Categories - Edit Link Category</b><p>");
$link_categories_id = $_GET['link_categories_id'];
$db_lookup_links_categories = @mysql_query("SELECT name FROM links_categories WHERE id='$link_categories_id'");
$db_links_categories = @mysql_fetch_array($db_lookup_links_categories);
$db_links_categories_name = $db_links_categories['name'];
echo("<form action='" . $_SERVER['PHP_SELF'] . "?page=link_categories&request=edit_link_category_submit' method='post'>");
echo("<input type='hidden' name='link_categories_id' value='$link_categories_id'>");
echo("<table border='0' cellpadding='5' cellspacing='0'>");
echo("<tr>");
echo("<td>" . $font_body . "Name:</font></td>");
echo("<td>" . $font_body . "<input type='text' name='name' value='$db_links_categories_name' size='30'></font></td>");
echo("</tr>");
echo("</table>");
echo("<p>");
echo("<input type='submit' name ='submit' value ='Update'><p>");
echo("</form>");
echo("[<a href='" . $_SERVER['PHP_SELF'] . "?page=link_categories'>" . $link_color . "Link Categories</font></a>]<p>");
}
// =======================================================================
// Comment - DC - Version 1.0
// =======================================================================
if ($page == "link_categories" and $request == "edit_link_category_submit" and $admin_rights) {
echo("<b>Link Categories - Edit Link Category</b><p>");
$link_categories_id = $_POST['link_categories_id'];
$name = $_POST['name'];
$db_update_links_categories = "UPDATE links_categories SET " .
"name = '$name'" .
"WHERE id = '$link_categories_id'";
if (@mysql_query($db_update_links_categories)) {
echo("Link category updated successfully.<p>");
} else {
echo("Link cateogry update error.<p>");
}
echo("[<a href='" . $_SERVER['PHP_SELF'] . "?page=link_categories'>" . $link_color . "Link Categories</font></a>]<p>");
}
// =======================================================================
// Comment - Version 1.0 - DC
// =======================================================================
if ($page == "link_categories" and $request == "delete_link_category" and $admin_rights == "Admin") {
echo("<b>Link Categories - Delete Link Category</b><p>");
$link_categories_id = $_GET['link_categories_id'];
$db_lookup_links_categories = @mysql_query("SELECT name FROM links_categories WHERE id='$link_categories_id'");
$db_links_categories = @mysql_fetch_array($db_lookup_links_categories);
$db_links_categories_name = $db_links_categories['name'];
echo("Name: $db_links_categories_name<p>");
echo("<p>Are you sure you want to delete this link category?<p>");
echo("[<a href='" . $_SERVER['PHP_SELF'] . "?page=link_categories&request=delete_link_category_submit&link_categories_id=$link_categories_id'>" . $link_color . "Yes</font></a>] ");
echo("[<a href='" . $_SERVER['PHP_SELF'] . "?page=link_categories&request=delete_link_category_cancel&link_categories_id=$link_categories_id'>" . $link_color . "No</font></a>]<p>");
echo("[<a href='" . $_SERVER['PHP_SELF'] . "?page=link_categories'>" . $link_color . "Link Categories</font></a>]<p>");
}
// =======================================================================
// Comment - Version 1.0 - DC
// =======================================================================
if ($page == "link_categories" and $request == "delete_link_category_submit" and $admin_rights == "Admin") {
echo("<b>Link Categories - Delete Link Category</b><p>");
$link_categories_id = $_GET['link_categories_id'];
$db_delete_links_categories = @mysql_query("DELETE FROM links_categories WHERE id='$link_categories_id'");
if ($db_delete_links_categories) {
echo("The link category has been deleted.<p>");
} else {
echo("Error deleting link category.<p>");
}
echo("[<a href='" . $_SERVER['PHP_SELF'] . "?page=link_categories'>" . $link_color . "Link Categories</font></a>]<p>");
}
// =======================================================================
// Comment - Version 1.0 - DC
// =======================================================================
if ($page == "link_categories" and $request == "delete_link_category_cancel" and $admin_rights == "Admin") {
echo("<b>Links Categories - Delete Link Category</b><p>");
$link_categories_id = $_GET['link_categories_id'];
echo("The link category has not been deleted.<p>");
echo("[<a href='" . $_SERVER['PHP_SELF'] . "?page=link_categories'>" . $link_color . "Link Categories</font></a>]<p>");
}
?>