<?php
// +----------------------------------------------------------------------+
// | Fantastic File Database |
// +----------------------------------------------------------------------+
// | By Tony Baird |
// | Copyright (c) 2003 Fantastic Scripts |
// | http://fscripts.com |
// +----------------------------------------------------------------------+
// | Fantastic File Database Can be modified freely as long as copyright |
// | is intact and this is left at the top of every source file |
// +----------------------------------------------------------------------+
// | category.php |
// | Date Started: March 11, 2003 |
// | Last Modified: March 13, 2003 |
// +----------------------------------------------------------------------+
Class Category {
//*************************************************/
// Just seing what we are doing
//*************************************************/
function Category() {
global $tpl,$mysql,$ffdb,$CONFIG,$admin;
if ($_REQUEST['action']=="add_category") {
$this->AddCategoryForm();
}elseif (isset($_REQUEST['add_category'])) {
$this->AddCategory();
}elseif ($_REQUEST['action']=="edit_category") {
$this->CategoryList();
}elseif ($_REQUEST['action']=="delete_category_confirm") {
$this->ConfirmDeleteCategory();
}elseif ($_REQUEST['action']=="delete_category") {
$this->DeleteCategory();
}elseif ($_REQUEST['action']=="edit_category_form") {
$this->EditCategoryForm();
}elseif (isset($_REQUEST['edit_category'])) {
$this->EditCategory();
}elseif ($_REQUEST['action']=="display_order") {
$this->EditDisplayOrderForm();
}elseif (isset($_REQUEST['update_display_order'])) {
$this->UpdateDisplayOrder();
}
}
//*************************************************/
// Add Category Form
//*************************************************/
function AddCategoryForm() {
global $tpl,$mysql,$ffdb,$CONFIG,$admin_skin;
$tpl->LoadTemplate("add_category_form","Admin/templates/$admin_skin/add_category_form.tpl");
$tpl->ParseTemplate("add_category_form",$add_category_form_array,"No");
$tpl->PrintTemplate("add_category_form");
}
//*************************************************/
// Actually Adds Category
//*************************************************/
function AddCategory() {
global $tpl,$mysql,$ffdb,$CONFIG,$admin_skin,$admin;
if (empty($_POST['category_name'])) {
$error .="Missing Category Name<br>";
}
if (empty($_POST['category_description'])) {
$error .="Missing Category Description<br>";
}
if ($error) {
$admin->Error($error);
}
$mysql->Query("SELECT display_order FROM ffdb_categorys ORDER BY display_order DESC LIMIT 1");
$show_category=mysql_fetch_array($mysql->result_id);
$display_order=$show_category[display_order]+1;
$ffdb->slash_array($_POST);
$add_category_array = array(
'category_name' => $_POST['category_name'],
'category_description'=>$_POST['category_description'],
'display_order'=>$display_order
);
$mysql->MakeInsertString($add_category_array);
$mysql->Query("INSERT INTO ffdb_categorys ($mysql->insert_fields) VALUES ($mysql->insert_values)");
$admin->Success("Category Added Successfully");
}
//*************************************************/
// Category List for editing
//*************************************************/
function CategoryList() {
global $tpl,$mysql,$ffdb,$CONFIG,$admin_skin,$admin;
$mysql->Query("SELECT * FROM ffdb_categorys ORDER BY display_order");
$tpl->LoadTemplate("category_list","Admin/templates/$admin_skin/category_list.tpl");
while ($show_category=mysql_fetch_array($mysql->result_id)) {
$has_category=1;
$category_list_array = array(
'category_name'=> $show_category[category_name],
'category_description'=> $show_category[category_description],
'active'=> $show_category[active],
'category_id'=> $show_category[category_id],
);
$tpl->ParseTemplate("category_list",$category_list_array,"Yes");
}
if ($has_category==1) {
$tpl->PrintTemplate("category_list");
} else {
$admin->Error("There are currently no categorys to edit");
}
}
//*************************************************/
// Confirms that the user wants to delete the
// category
//*************************************************/
function ConfirmDeleteCategory() {
global $tpl,$mysql,$ffdb,$CONFIG,$admin_skin,$admin;
$mysql->Query("SELECT * FROM ffdb_categorys WHERE category_id=".$_REQUEST['id']."");
$show_category=mysql_fetch_array($mysql->result_id);
$admin->Confirm("Are you sure you want to delete $show_category[category_name]?<br>","admin.php?action=delete_category&id=$show_category[category_id]");
}
//*************************************************/
// Deletes the category
//*************************************************/
function DeleteCategory() {
global $tpl,$mysql,$ffdb,$CONFIG,$admin_skin,$admin;
$mysql->Query("DELETE FROM ffdb_categorys WHERE category_id=".$_REQUEST['id']."");
$admin->Success("Category Deleted successfully");
}
//*************************************************/
// Edit Category form
//*************************************************/
function EditCategoryForm() {
global $tpl,$mysql,$ffdb,$CONFIG,$admin_skin,$admin;
$mysql->Query("SELECT * FROM ffdb_categorys WHERE category_id=".$_REQUEST['id']."");
$show_category=mysql_fetch_array($mysql->result_id);
if ($show_category[active]=="Yes") {
$active_list=" <option selected>Yes</option>
<option>No</option>";
} else {
$active_list="<option selected>No</option>
<option>Yes</option>";
}
$tpl->LoadTemplate("edit_category_form","Admin/templates/$admin_skin/edit_category_form.tpl");
$edit_category_form_array = array(
'category_name'=> $show_category[category_name],
'category_description'=> $show_category[category_description],
'active_list'=> $active_list,
'category_id'=> $show_category[category_id],
);
$tpl->ParseTemplate("edit_category_form",$edit_category_form_array,"No");
$tpl->PrintTemplate("edit_category_form");
}
//*************************************************/
// Actually edits the categorys
//*************************************************/
function EditCategory() {
global $tpl,$mysql,$ffdb,$CONFIG,$admin_skin,$admin;
if (empty($_POST['category_name'])) {
$error .="Missing Category Name<br>";
}
if (empty($_POST['category_description'])) {
$error .="Missing Category Description<br>";
}
if ($error) {
$admin->Error($error);
}
$ffdb->slash_array($_POST);
$update_category_array = array(
'category_name' => $_POST['category_name'],
'category_description' => $_POST['category_description'],
'active' => $_POST['active'],
);
$mysql->MakeUpdateString($update_category_array);
$mysql->Query("UPDATE ffdb_categorys SET $mysql->update_string WHERE category_id=".$_POST['id']."");
$admin->Success("Category Updated successfully");
}
//*************************************************/
// Edit Display Order Form
//*************************************************/
function EditDisplayOrderForm() {
global $tpl,$mysql,$ffdb,$CONFIG,$admin_skin,$admin;
$tpl->LoadTemplate("edit_display_order_form","Admin/templates/$admin_skin/edit_display_order_form.tpl");
$mysql->Query("SELECT * FROM ffdb_categorys ORDER BY display_order");
while ($show_category=mysql_fetch_array($mysql->result_id)) {
$category_list .="<tr>
<td BGCOLOR=\"#009999\"><font size=\"2\">$show_category[category_name]</font></td>
<td BGCOLOR=\"#009999\">
<p ALIGN=\"CENTER\">
<input NAME=\"c$show_category[category_id]\" TYPE=\"text\" SIZE=\"1\" VALUE=\"$show_category[display_order]\"></p>
</td>
</tr>";
}
// Fully Category List
$mysql->Query("SELECT ffdb_categorys.*, ffdb_sub_categorys.* FROM ffdb_categorys,ffdb_sub_categorys WHERE ffdb_categorys.category_id=ffdb_sub_categorys.category_id ORDER BY ffdb_sub_categorys.display_order ASC, ffdb_categorys.display_order ASC");
while ($show_category=mysql_fetch_array($mysql->result_id)) {
if ($show_category[category_id]==$oldcat_id) {
$full_category_list .="<tr>
<td BGCOLOR=\"#008080\"><font size=\"2\">$show_category[sub_category_name]</font></td>
<td BGCOLOR=\"#008080\">
<p ALIGN=\"CENTER\">
<input NAME=\"s$show_category[sub_category_id]\" TYPE=\"text\" SIZE=\"1\" VALUE=\"$show_category[display_order]\"></p>
</td>
</tr>";
} else {
$full_category_list .="<tr>
<td COLSPAN=\"2\" bgcolor=\"#009999\">
<p ALIGN=\"CENTER\"><font size=\"2\"><b>$show_category[category_name]</b></font></p>
</td>
</tr>
<tr>
<td bgcolor=\"#008080\"><font size=\"2\">$show_category[sub_category_name]</font></td>
<td BGCOLOR=\"#008080\">
<p ALIGN=\"CENTER\">
<input NAME=\"s$show_category[sub_category_id]\" TYPE=\"text\" SIZE=\"1\" VALUE=\"$show_category[display_order]\"></p>
</td>
</tr>";
}
$oldcat_id=$show_category[category_id];
}
$edit_display_order_form_array = array(
'full_category_list'=> $full_category_list,
'category_list'=> $category_list,
'active_list'=> $active_list,
'category_id'=> $show_category[category_id],
);
$tpl->ParseTemplate("edit_display_order_form",$edit_display_order_form_array,"No");
$tpl->PrintTemplate("edit_display_order_form");
}
//*************************************************/
// Updates Display Order of the Categorys and
// and Sub Categorys
//*************************************************/
function UpdateDisplayOrder() {
global $tpl,$mysql,$ffdb,$CONFIG,$admin_skin,$admin;
$mysql->Query("SELECT * FROM ffdb_categorys");
$update_display=new Mysql;
while($show_category = mysql_fetch_array($mysql->result_id)) {
$final = $_POST['c'.$show_category[category_id]];
$update_display->Query("UPDATE ffdb_categorys SET display_order='$final' WHERE category_id='$show_category[category_id]'");
}
$mysql->Query("SELECT * FROM ffdb_sub_categorys");
while($show_sub_category = mysql_fetch_array($mysql->result_id)) {
$final = $_POST['s'.$show_sub_category['sub_category_id']];
$update_display->Query("UPDATE ffdb_sub_categorys SET display_order='$final' WHERE sub_category_id='$show_sub_category[sub_category_id]'");
}
$admin->Success("Display order updated successfully");
}
}
?>