<?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 |
// +----------------------------------------------------------------------+
// | sub_category.php |
// | Date Started: March 12, 2003 |
// | Last Modified: March 12, 2003 |
// +----------------------------------------------------------------------+
Class SubCategory {
//*************************************************/
// Just seing what we are doing
//*************************************************/
function SubCategory() {
global $tpl,$mysql,$ffdb,$CONFIG,$admin;
if ($_REQUEST['action']=="add_sub_category") {
$this->AddSubCategoryForm();
}elseif (isset($_REQUEST['add_sub_category'])) {
$this->AddSubCategory();
}elseif ($_REQUEST['action']=="edit_sub_category") {
$this->SubCategoryList();
}elseif ($_REQUEST['action']=="delete_sub_category_confirm") {
$this->ConfirmDeleteSubCategory();
}elseif ($_REQUEST['action']=="delete_sub_category") {
$this->DeleteSubCategory();
}elseif ($_REQUEST['action']=="edit_sub_category_form") {
$this->EditSubCategoryForm();
}elseif (isset($_REQUEST['edit_sub_category'])) {
$this->EditSubCategory();
}
}
//*************************************************/
// Add Sub Category Form
//*************************************************/
function AddSubCategoryForm() {
global $tpl,$mysql,$ffdb,$CONFIG,$admin_skin;
$tpl->LoadTemplate("add_sub_category_form","Admin/templates/$admin_skin/add_sub_category_form.tpl");
$mysql->Query("SELECT * FROM ffdb_categorys");
while ($show_category=mysql_fetch_array($mysql->result_id)) {
$category_list .="<option value=\"$show_category[category_id]\">$show_category[category_name]</option>";
}
$add_sub_category_form_array = array(
'category_list'=> $category_list
);
$tpl->ParseTemplate("add_sub_category_form",$add_sub_category_form_array,"No");
$tpl->PrintTemplate("add_sub_category_form");
}
//*************************************************/
// Actually Adds the Sub Category
//*************************************************/
function AddSubCategory() {
global $tpl,$mysql,$ffdb,$CONFIG,$admin_skin,$admin;
if (empty($_POST['sub_category_name'])) {
$error .="Missing SubCategory Name<br>";
}
if (empty($_POST['sub_category_description'])) {
$error .="Missing Sub Category Description<br>";
}
if (empty($_POST['category'])) {
$error .="Missing Category<br";
}
if ($error) {
$admin->Error($error);
}
$mysql->Query("SELECT display_order FROM ffdb_sub_categorys WHERE category_id=".$_POST['category']." 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(
'sub_category_name' => $_POST['sub_category_name'],
'sub_category_description'=>$_POST['sub_category_description'],
'display_order'=>$display_order,
'category_id'=>$_POST['category']
);
$mysql->MakeInsertString($add_category_array);
$mysql->Query("INSERT INTO ffdb_sub_categorys ($mysql->insert_fields) VALUES ($mysql->insert_values)");
$mysql->Query("UPDATE ffdb_categorys SET num_sub_categorys=num_sub_categorys+1 WHERE category_id=".$_REQUEST['category']."");
$admin->Success("Sub Category Added Successfully");
}
//*************************************************/
// Sub Category List for editing
//*************************************************/
function SubCategoryList() {
global $tpl,$mysql,$ffdb,$CONFIG,$admin_skin,$admin;
$mysql->Query("SELECT ffdb_sub_categorys.*,ffdb_categorys.* FROM ffdb_sub_categorys,ffdb_categorys WHERE ffdb_sub_categorys.category_id=ffdb_categorys.category_id ORDER BY ffdb_categorys.display_order AND ffdb_sub_categorys.display_order");
$tpl->LoadTemplate("sub_category_list","Admin/templates/$admin_skin/sub_category_list.tpl");
while ($show_sub_category=mysql_fetch_array($mysql->result_id)) {
$has_sub_category=1;
$sub_category_list_array = array(
'sub_category_name'=> $show_sub_category[sub_category_name],
'sub_category_description'=> $show_sub_category[sub_category_description],
'active'=> $show_sub_category[active],
'sub_category_id'=> $show_sub_category[sub_category_id],
'category_name'=>$show_sub_category[category_name]
);
$tpl->ParseTemplate("sub_category_list",$sub_category_list_array,"Yes");
}
if ($has_sub_category==1) {
$tpl->PrintTemplate("sub_category_list");
} else {
$admin->Error("There are currently no sub category's to edit");
}
}
//*************************************************/
// Confirms that they want to delete the Sub Category
//*************************************************/
function ConfirmDeleteSubCategory() {
global $tpl,$mysql,$ffdb,$CONFIG,$admin_skin,$admin;
$mysql->Query("SELECT * FROM ffdb_sub_categorys WHERE sub_category_id=".$_REQUEST['id']."");
$show_sub_category=mysql_fetch_array($mysql->result_id);
$admin->Confirm("Are you sure you want to delete $show_sub_category[sub_category_name]?<br>","admin.php?action=delete_sub_category&id=$show_sub_category[sub_category_id]");
}
//*************************************************/
// Deletes the Sub Category
//*************************************************/
function DeleteSubCategory() {
global $tpl,$mysql,$ffdb,$CONFIG,$admin_skin,$admin;
$mysql->Query("SELECT * FROM ffdb_sub_categorys WHERE sub_category_id=".$_REQUEST['id']."");
$show_sub_category=mysql_fetch_array($mysql->result_id);
$mysql->Query("DELETE FROM ffdb_sub_categorys WHERE sub_category_id=".$_REQUEST['id']."");
$mysql->Query("UPDATE ffdb_categorys SET num_sub_categorys=num_sub_categorys-1 WHERE category_id=$show_sub_category[category_id]");
$admin->Success("Sub Category Deleted successfully");
}
//*************************************************/
// Edit Sub Category form
//*************************************************/
function EditSubCategoryForm() {
global $tpl,$mysql,$ffdb,$CONFIG,$admin_skin,$admin;
$mysql->Query("SELECT * FROM ffdb_sub_categorys WHERE sub_category_id=".$_REQUEST['id']."");
$show_sub_category=mysql_fetch_array($mysql->result_id);
if ($show_sub_category[active]=="Yes") {
$active_list=" <option selected>Yes</option>
<option>No</option>";
} else {
$active_list="<option selected>No</option>
<option>Yes</option>";
}
$mysql->Query("SELECT * FROM ffdb_categorys");
while ($show_category=mysql_fetch_array($mysql->result_id)) {
if ($show_category[category_id]==$show_sub_category[category_id]) {
$category_list .="<option value=\"$show_category[category_id]\" selected>$show_category[category_name]</option>";
} else {
$category_list .="<option value=\"$show_category[category_id]\">$show_category[category_name]</option>";
}
}
$tpl->LoadTemplate("edit_sub_category_form","Admin/templates/$admin_skin/edit_sub_category_form.tpl");
$edit_sub_category_form_array = array(
'sub_category_name'=> $show_sub_category[sub_category_name],
'sub_category_description'=> $show_sub_category[sub_category_description],
'active_list'=> $active_list,
'sub_category_id'=> $show_sub_category[category_id],
'category_list'=>$category_list
);
$tpl->ParseTemplate("edit_sub_category_form",$edit_sub_category_form_array,"No");
$tpl->PrintTemplate("edit_sub_category_form");
}
//*************************************************/
// Actually edits the Sub Category
//*************************************************/
function EditSubCategory() {
global $tpl,$mysql,$ffdb,$CONFIG,$admin_skin,$admin;
if (empty($_POST['sub_category_name'])) {
$error .="Missing SubCategory Name<br>";
}
if (empty($_POST['sub_category_description'])) {
$error .="Missing Sub Category Description<br>";
}
if (empty($_POST['category'])) {
$error .="Missing Category<br";
}
if ($error) {
$admin->Error($error);
}
$mysql->Query("SELECT * FROM ffdb_sub_categorys WHERE sub_category_id=".$_REQUEST['id']."");
$show_sub_category=mysql_fetch_array($mysql->result_id);
$ffdb->slash_array($_POST);
if ($show_sub_category[category_id] !=$_POST['category']) {
$mysql->Query("UPDATE ffdb_categorys SET num_sub_categorys=num_sub_categorys-1 WHERE category_id=$show_sub_category[category_id]");
$mysql->Query("UPDATE ffdb_categorys SET num_sub_categorys=num_sub_categorys+1 WHERE category_id=".$_REQUEST['category']."");
}
$update_sub_category_array = array(
'sub_category_name' => $_POST['sub_category_name'],
'sub_category_description' => $_POST['sub_category_description'],
'active' => $_POST['active'],
'category_id'=>$_POST['category']
);
$mysql->MakeUpdateString($update_sub_category_array);
$mysql->Query("UPDATE ffdb_sub_categorys SET $mysql->update_string WHERE sub_category_id=".$_POST['id']."");
$admin->Success("Sub Category Updated successfully");
}
}
?>