category.php
上传用户:gzy2002
上传日期:2010-02-11
资源大小:1785k
文件大小:11k
- <?php
- // +-------------------------------------------------------------+
- // | DeskPRO v [2.0.1 Production]
- // | Copyright (C) 2001 - 2004 Headstart Solutions Limited
- // | Supplied by WTN-WDYL
- // | Nullified by WTN-WDYL
- // | Distribution via WebForum, ForumRU and associated file dumps
- // +-------------------------------------------------------------+
- // | DESKPRO IS NOT FREE SOFTWARE
- // +-------------------------------------------------------------+
- // | License ID : Full Enterprise License =) ...
- // | License Owner : WTN-WDYL Team
- // +-------------------------------------------------------------+
- // | $RCSfile: category.php,v $
- // | $Date: 2004/02/10 01:34:25 $
- // | $Revision: 1.30 $
- // +-------------------------------------------------------------+
- // | File Details:
- // | - Categories maintenance (administration interface)
- // +-------------------------------------------------------------+
- error_reporting(E_ALL & ~E_NOTICE);
- require_once('./global.php');
- //Nullify WTN-WDYL Team
- // default do
- $_REQUEST['do'] = trim($_REQUEST['do']);
- if (!isset($_REQUEST['do']) or $_REQUEST['do'] == "") {
- $_REQUEST['do'] = "view";
- }
- // globalise variables
- $global = array (
- array('id', 'number')
- );
- rg($global);
- language_check();
- ############################### CATEGORY SETTINGS ###############################
- if ($_REQUEST['do'] == "settings") {
- admin_header('Categories', 'Category Settings');
- include('./settings_include.php');
- show_settings('category.php', 'Category settings');
- }
- ############################### UPDATE CATEGORY SETTINGS ###############################
- if ($_REQUEST['do'] == "update") {
- include('./settings_include.php');
- update_settings();
- jump("category.php?do=settings", 'Settings updated');
- }
- ############################### ORDER CATEGORIES ###############################
- if ($_REQUEST['do'] == "cat_orders") {
- while (list ($key, $val) = each ($_REQUEST['order'])) {
- $key = mysql_escape_string($key);
- $val = mysql_escape_string($val);
- $db->query("UPDATE ticket_cat SET cat_order = '$val' WHERE id = '$key'");
- }
-
- jump("category.php?do=view", 'Orders updated');
- }
- ############################### DELETE CATEGORY ###############################
- if ($_REQUEST['do'] == "delete") {
- admin_header('Categories', 'Delete Category');
-
- $db->query("SELECT * from ticket_cat WHERE id != '$id'");
- while ($cat = $db->row_array()) {
- $category[$cat[id]] = $cat[name];
- }
-
- $db->query("SELECT * from ticket_cat WHERE id = '$id'");
- $result = $db->row_array();
- $name = $result[name];
- $bit = form_select('category', $category);
- $table = array('<b>Choose a new category</b><br />You must select a category to move the tickets with their current category set as "' . $name . '"', $bit);
- table_header("Delete category $name", 'category.php', array('do' => 'delete2', 'id' => $id));
- table_content('', $table);
- table_footer('Delete Category');
- }
- ############################### DELETE (2) CATEGORY ###############################
- // update tickets to new category and add entry into the ticketlog
- if ($_REQUEST['do'] == "delete2") {
- $db->query("SELECT id FROM ticket WHERE category = " . intval($id) . "");
- while ($result = $db->row_array()) {
- $ticket_log[] = array($result[id], 'category', intval($id), $_REQUEST[category]);
- }
- ticketlog_array($ticket_log);
-
- $db->query("UPDATE ticket SET category = '" . mysql_escape_string($_REQUEST[category]) . "' WHERE category = " . intval($id));
- // delete the category
- $db->query("DELETE from ticket_cat WHERE id = '$id'");
- // delete langauage bits
- $category_languages = unserialize(get_data('category_languages'));
- if (is_array($category_languages)) {
- foreach ($category_languages AS $key => $var) {
- unset($category_languages[$key][$id]);
- }
- }
- update_data('category_languages', serialize($category_languages));
-
- jump('category.php?do=view', 'Category deleted');
- }
- ############################### EDIT / CREATE CATEGORY ###############################
- if (($_REQUEST['do'] == "edit") OR ($_REQUEST['do'] == "add")) {
-
- if ($_REQUEST['do'] == 'add') {
- admin_header('Categories', 'Add Category');
- // lets give some sensible defaults
- $category[user_view] = 1;
- $category[user_select] = 1;
- } else {
- admin_header('Categories', 'Edit Category');
- }
-
- $db->query("SELECT * from ticket_cat WHERE id != '$id' AND user_view = 1");
- while ($cat = $db->row_array()) {
- $category2[$cat[id]] = $cat[name];
- }
- if ($_REQUEST['do'] == "edit") {
- $db->query("SELECT * from ticket_cat WHERE id = '$id'");
- $category = $db->row_array();
- }
- $db->query("SELECT id, username FROM tech ORDER BY username");
- $techs[0] = 'Leave Unassigned';
- while ($tech = $db->row_array()) {
- $techs[$tech[id]] = $tech[username];
- }
- $bit = form_input('category', $category[name]);
- $table[] = array('<b>Category name</b><br />The name for your category.', $bit);
- $bit = form_input('cat_order', $category[cat_order], 5);
- $table[] = array('<b>Category order</b><br />The display order of your category (1 = high).', $bit);
- // there need to be other categories to enable this
- if (is_array($category2)) {
- $bit = form_radio_yn('user_view', '', $category[user_view]);
- $table[] = array('<b>User viewable</b><br />Can the user view the category? If not, you must select a category to be displayed to the user instead.', $bit);
- $bit = form_select('show_category', $category2, '', $category[show_category]);
- $table[] = array('<b>User display category</b><br />If you are hiding the real category choice from the user you should select a category to display to the user instead.', $bit);
- } else {
- $extra = form_hidden('user_view', 1);
- }
- $bit = form_radio_yn('user_select', '', $category[user_select]);
- $table[] = array('<b>User selectable</b><br />Can the user select this category when creating or editing tickets? This is different from user viewable because you may wish to have a category that only techs can assign to tickets but when they do assign that category to a ticket, the user can see this assignment.', $bit . $extra);
- unset($extra);
- $bit = form_radio_yn('require_registration', '', $category[require_registration]);
- $table[] = array('<b>Require registration</b><br />Will this category only accept tickets from registered users?', $bit);
- $bit = form_select('auto_assign_tech', $techs, '', $category[auto_assign_tech]);
- $table[] = array('<b>Assign to tech</b><br />If you select a tech here, new tickets in this category will automatically be assigned to that tech.', $bit);
- // languages for categories
- if ($settings['language_on']) {
- $category_languages = unserialize(get_data('category_languages'));
- $table[] = table_midheader('Language Options');
-
- $name = "<table cellpadding="2" cellspacing="0">";
- $db->query(" SELECT * FROM languages
- WHERE id != '$settings[default_language]'
- ");
- while ($lang = $db->row_array()) {
- $name .= "<tr><td><b>$lang[name]</b>:</td><td>" . form_input($lang[id], $category_languages[$lang[id]][$id]['name'], 30, 'language_name') . "</td></tr>";
- }
- $name .= "</table>";
- $table[] = array('<b>Category name</b><br />The name for the category in other languages.', $name);
- }
- $width = array('60%', '40%');
- if ($_REQUEST['do'] == "edit") {
- table_header('Edit Category ' . $category[name],'category.php', array('do' => 'edit2', 'id' => $id));
- table_content('', $table, '', '', '', '', $width);
- table_footer('Edit Category');
- } else {
- table_header('Create Category', 'category.php', array('do' => 'add2'));
- table_content('', $table, '', '', '', '', $width);
- table_footer('Create Category');
- }
- }
- ############################### EDIT (2) CATEGORY ###############################
- if ($_REQUEST['do'] == "edit2") {
- $db->query("UPDATE ticket_cat SET
- name = '".mysql_escape_string($_REQUEST[category])."',
- show_category = " . intval($_REQUEST[show_category]) . ",
- cat_order = '$_REQUEST[cat_order]',
- user_view = '$_REQUEST[user_view]',
- user_select = '$_REQUEST[user_select]',
- require_registration = '$_REQUEST[require_registration]',
- auto_assign_tech = '$_REQUEST[auto_assign_tech]'
- WHERE id='$id'
- ");
- // language options for category
- if ($settings[language_on]) {
- $category_languages = unserialize(get_data('category_languages'));
- if (is_array($_REQUEST['language_name'])) {
- foreach ($_REQUEST[language_name] AS $key => $var) {
- $category_languages[$key][$id] = array('name' => $var);
- }
- }
- update_data('category_languages', serialize($category_languages));
- }
- jump('category.php?do=view', 'Category updated');
- }
- ############################### ADD (2) CATEGORY ###############################
- if ($_REQUEST['do'] == "add2") {
- $db->query("INSERT into ticket_cat SET
- name = '" . mysql_escape_string($_REQUEST[category]) . "',
- show_category = " . intval($_REQUEST[show_category]) . ",
- cat_order = '$_REQUEST[cat_order]',
- user_view = '$_REQUEST[user_view]',
- user_select = '$_REQUEST[user_select]',
- require_registration = '$_REQUEST[require_registration]',
- auto_assign_tech = '$_REQUEST[auto_assign_tech]'
- ");
- $id = $db->last_id();
- // language options for category
- if ($settings['language_on']) {
- $category_languages = unserialize(get_data('category_languages'));
-
- if (is_array($_REQUEST['language_name'])) {
- foreach ($_REQUEST['language_name'] AS $key => $var) {
- $category_languages[$key][$id] = array('name' => $var);
- }
- }
- update_data('category_languages', serialize($category_languages));
- }
- jump('category.php?do=view', 'New category created');
- }
- ############################### VIEW CATEGORIES ###############################
- if ($_REQUEST['do'] == "view") {
- admin_header('Categories', 'View Categories');
- $db->query("SELECT id, username FROM tech ORDER BY username");
- $techs[0] = 'Leave Unassigned';
- while ($tech = $db->row_array()) {
- $techs[$tech[id]] = $tech[username];
- }
-
- $db->query("SELECT * from ticket_cat ORDER by cat_order");
- while ($category = $db->row_array()) {
- $table[] = array(
- form_input($category[id], $category[cat_order], '4', 'order'),
- "<B>$category[name]</b>",
- ifynb($category[user_view]),
- ifynb($category[user_select]),
- ifynb($category[require_registration]),
- $techs[$category[auto_assign_tech]],
- "<a href="category.php?do=delete&id=$category[id]">delete</a>",
- "<a href="category.php?do=edit&id=$category[id]">edit</a>"
- );
- }
- $cols = array('Order', 'Name', 'User Viewable', 'User Selectable', 'Registration Required', 'Assign to Technician', 'Delete', 'Edit');
- table_header('Your Categories', 'category.php', array('do' => 'cat_orders'));
- table_content($cols, $table);
- table_footer('Update Category Orders');
- unset($table);
-
- echo "<P><font face="verdana, arial, helvetica" size="2"><center><a href="category.php?do=add">Add New Category</a></center></font>";
- }
- ##############################################################
- admin_footer();
- ?>