Category Management'; require('../data/config.php'); require('includes/functions.php'); require('includes/header.php'); function isValidMove($cat_id, $parentid) { $result = dbQuery("SELECT id, title FROM categories WHERE parentid=$cat_id"); while ($row = mysql_fetch_object($result)) { if ($row->id == $parentid) return false; else return isValidMove($row->id, $parentid); } return true; } ?>

'; echo ''.$errmsg.'

'; echo 'Click here to return.'; tableClose(); } else { dbQuery("INSERT INTO categories(parentid, title, description) VALUES($parent_id, '$title', '$description')"); tableHeader('Operation Successful'); echo 'The new category has been created successfully!

'; echo 'Click here to continue.'; tableClose(); } } if ($_GET['action'] == 'new' && hasAccess('categories', 'create')) { $parentid = ($_GET['parent'] != '') ? $_GET['parent'] : 0; echo '
'; tableHeader('Create New Category'); echo '
Parent category
Under what category should this new category appear? Select [no parent category] to have it at the top level.
Category name
Description
This is the description of the category. Description cannot be longer than 255 characters.

You do not need to enter a description.
'; tableClose(); echo '
'; echo '
'; } elseif ($_POST['action'] == 'edit' && hasAccess('articles', 'edit') && notDemoAccess(true)) { $old_parentid = $_POST['old_parentid']; $cat_id = $_POST['cat_id']; $parentid = $_POST['parent_id']; $title = $_POST['title']; $description = $_POST['description']; $canmove = isValidMove($cat_id, $parentid); $result = dbQuery("SELECT id FROM categories WHERE parentid=0 AND id!=$cat_id"); if (mysql_num_rows($result) == 0) $errmsg = 'You do not have any other root-level cateogies. You must have another root-level category before rearranging the current one.'; elseif ($canmove == false) $errmsg = 'You cannot move a category into one of its subcategories.'; elseif ($cat_id == $parentid) $errmsg = 'You cannot make the category a subcategory of itself.'; if ($errmsg) { tableHeader('Oops!'); echo 'The category could not be updated for the following reason:

'; echo ''.$errmsg.'

'; echo 'Click here to return.'; tableClose(); } else { dbQuery("UPDATE categories SET parentid='$parentid', title='$title', description='$description' WHERE id=$cat_id"); tableHeader('Operation Successful'); echo 'Your changes to the category have been saved successfully!

'; echo 'Click here to refresh the category list and close this window.'; tableClose(); } } elseif ($_GET['action'] == 'edit' && hasAccess('categories', 'edit')) { $cat_id = $_GET['id']; $result = dbQuery("SELECT * FROM categories WHERE id=$cat_id"); while ($row = mysql_fetch_object($result)) { echo '
'; tableHeader('Edit Category'); echo '
Parent category
Under what category should this new category appear? Select [no parent category] to have it at the top level.
Category name
Description
This is the description of the category. Description cannot be longer than 255 characters.

You do not need to enter a description.
'; tableClose(); echo '
'; echo '
'; } } elseif ($_GET['action'] == 'manage' && hasAccess('categories', 'view')) { $order = getOrderDetails('title', 'ASC'); $nav = getNavInfo("SELECT id FROM categories"); tableHeader('Manage Categories'); if ($nav['total'] > 0) { $page_nav = getPageNav($nav, 'categories', 'manage'); echo '
'.$nav['total'].' '.isPlural($nav['total'], 'categories', 'category').' found. Displaying page 1 of 1
'.createGetFields(array('orderby', 'order')).' Sort results by in order:
'; getCategories(0, 0); echo '
Category Description (50 character preview) Article Count Options
Important!

If you delete a category, all subcategories and articles in the category and its subcategories will be deleted! If you do not want them to be deleted, you will need to edit them and move them into a different category.

With selected categories:
'; } else { echo 'No categories have been created yet.

Click here if you would like to create one now.'; } tableClose(); } elseif ($_POST['action'] == 'bulk_action' && notDemoAccess()) { $return_action = $_POST['return_action']; $bulk_action = $_POST['bulk_action']; $errmsg = ''; if (!$_POST['mark']) { tableHeader('Oops!'); echo 'Your action could not be performed for the following reason:

'; echo 'You did not select any categories. You must select at least one category.

'; echo 'Click here to return.'; tableClose(); } else { if ($bulk_action == 'delete' && hasAccess('categories', 'delete')) { foreach($_POST['mark'] as $cat_id) { deleteCategory($cat_id); } } tableHeader('Operation Successful'); echo 'Your action has been performed successfully!

'; echo 'Please click here to continue.'; tableClose(); } } if (($_GET['action'] == 'edit' || $_GET['action'] == 'new') && $cfg['use_wysiwyg'] == 1) { ?>