category.php
上传用户:gzy2002
上传日期:2010-02-11
资源大小:1785k
文件大小:9k
- <?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:26 $
- // | $Revision: 1.22 $
- // +-------------------------------------------------------------+
- // | File Details:
- // | - FAQ category maintenance
- // +-------------------------------------------------------------+
- error_reporting(E_ALL ^ E_NOTICE);
- include "./../global.php";
- tech_nav('faq');
- // default do
- $_REQUEST['do'] = trim($_REQUEST['do']);
- if (!isset($_REQUEST['do']) or $_REQUEST['do'] == "") {
- $_REQUEST['do'] = "edit";
- }
- // globalise variables
- $global = array (
- array('catid')
- );
- rg($global);
- include ("./faq_include.php");
- ############################### SQL: ADD CATEGORY ###############################
- if ($_REQUEST['do'] == "add2") {
- if ($_REQUEST['parent'] != "0") {
- $result = $db->query_return("SELECT parentlist,id FROM faq_cats WHERE id = '" . intval($_REQUEST['parent']) . "'");
- $parentlist = iff($result['parentlist'], ", $result[parentlist]") . $result['id'];
- }
- $db->query("INSERT INTO faq_cats SET
- name = '".mysql_escape_string($_REQUEST['name'])."',
- parent = '".mysql_escape_string($_REQUEST['parent'])."',
- description = '".mysql_escape_string($_REQUEST['description'])."',
- parentlist = '$parentlist',
- show_order = '".mysql_escape_string($_REQUEST['order'])."'
- ");
- $catid = $db->last_id();
- // update permissions; need to give permissions to parents as well to prevent orphan cats.
- if (is_array($_REQUEST['permission'])) {
- foreach ($_REQUEST['permission'] AS $key => $var) {
- if ($var == 1) {
- $data[] = array($catid, $key);
- // also add for parentlist
- $parents = explode(',', $parentlist);
- foreach ($parents AS $key2 => $var2) {
- $data[] = array($var2, $key);
- }
- }
- }
- }
- // permissions
- if (is_array($data)) {
- $db->query("REPLACE INTO faq_permissions
- (catid, groupid)
- VALUES " . insertsql($data) . "
- ");
- }
- unset($data);
- // related categories
- $related = explode(',', $_REQUEST['related']);
- foreach ($related AS $key => $var) {
- if ($var) {
- $data[] = array($catid, $var);
- }
- }
- if (is_array($data)) {
- $db->query("INSERT INTO faq_cats_related
- (show_cat, related_cat)
- VALUES " . insertsql($data) . "
- ");
- }
- jump('category.php?do=add', 'New Category Created');
- }
- ############################### EDIT CATEGORY ###############################
- if ($_REQUEST['do'] == "update") {
- $checks = xss_check(array($_REQUEST['name'], $_REQUEST['description']), 'user');
- $db->query("UPDATE faq_cats SET
- name = '" . mysql_escape_string($checks[0]) . "',
- description = '" . mysql_escape_string($checks[1]) . "'
- WHERE id = '$_REQUEST[catid]'
- ");
- $db->query("DELETE FROM faq_permissions WHERE catid = '$_REQUEST[catid]'");
- $category = $db->query_return("SELECT * FROM faq_cats WHERE id = '$_REQUEST[catid]'");
- // update permissions; need to give permissions to parents as well to prevent orphan cats.
- if (is_array($_REQUEST['permission'])) {
- foreach ($_REQUEST['permission'] AS $key => $var) {
- if ($var == 1) {
- $data[] = array($catid, $key);
- // also add for parentlist
- $parents = explode(',', $category['parentlist']);
- foreach ($parents AS $key2 => $var2) {
- $data[] = array($var2, $key);
- }
- }
- }
- }
- if (is_array($data)) {
- $db->query("REPLACE INTO faq_permissions
- (catid, groupid)
- VALUES " . insertsql($data) . "
- ");
- }
- unset($data);
- // related categories
- $db->query("DELETE FROM faq_cats_related WHERE show_cat = '$_REQUEST[catid]'");
- $related = explode(',', $_REQUEST['related']);
- foreach ($related AS $key => $var) {
- if ($var) {
- $data[] = array($_REQUEST['catid'], $var);
- }
- }
- if (is_array($data)) {
- $db->query("INSERT INTO faq_cats_related
- (show_cat, related_cat)
- VALUES " . insertsql($data) . "
- ");
- }
- jump('index.php?catid=' . $categorycache[$_REQUEST['catid']]['parent'], 'Category Updated');
- }
- ############################### VIEW CATEGORY ###############################
- if ($_REQUEST['do'] == "edit" OR $_REQUEST['do'] == "add") {
- echo "<form method="post" action="category.php">";
- if ($_REQUEST['do'] == "edit") {
- echo form_hidden('do', 'update');
- echo form_hidden('catid', $_REQUEST['catid']);
- } else {
- echo form_hidden('do', 'add2');
- }
- $catarray = faq_categoryjump();
- if ($_REQUEST['do'] == "edit") {
- if (!$catid) {
- $catid = 0;
- }
- $parent = $categorycache[$catid]['parent'];
- while ($parent > 0) {
- $nav = " >> <a href="index.php?catid=" . $parent . "">" . $categorycache[$parent]['name'] . "</a>" . $nav;
- $parent = $categorycache[$parent]['parent'];
- }
- $nav = "<a href="index.php">Top</a>" . $nav;
- if ($catid != "0") {
- $nav .= " >> <a href="index.php?catid=$catid">" . $categorycache[$catid]['name'] . "</a>";
- }
- echo "<BR><B>$nav</b><br /><br />";
- }
- $db->query("SELECT groupid FROM faq_permissions WHERE catid = '$_REQUEST[catid]'");
- while ($result = $db->row_array()) {
- $perms[] = $result['groupid'];
- }
- $db->query("SELECT * FROM user_groups");
- while ($result = $db->row_array()) {
- // make all permissions selected by default for new cats
- if ($_REQUEST['do'] == 'add') {
- $perms[] = $result['id'];
- }
- $html .= form_checkbox_single($result['id'], 1, @in_array($result['id'], $perms), 'permission') . " $result[name]<br />";
- }
- $result = $db->query_return("SELECT * FROM faq_cats WHERE id = '$_REQUEST[catid]'");
- $table[] = array(table_thelp('<b>Name</b>', 'FAQ', 'Name'), form_input('name', $result['name']));
- if ($_REQUEST['do'] == "add") {
- $table[] = array(table_thelp('<b>Parent</b>', 'FAQ', 'Parent'), form_select('parent', $catarray));
- }
-
- $table[] = array(table_thelp('<b>Description</b>', 'FAQ', 'Description'), form_textarea('description', 60, 10, $result['description']));
- $table[] = array(table_thelp('<b>Permissions</b>', 'FAQ', 'Permissions'), $html);
- if ($_REQUEST['do'] == "edit") {
- table_header('Edit FAQ Category');
- } else {
- table_header('Create FAQ Category');
- }
- table_content($columns, $table, $extra);
- table_footer();
- unset($columns, $table, $extra, $html, $html2);
- ///////////////////////// RELATED CATEGORIES ///////////////
- echo get_javascript('selectBox.js');
- $db->query("SELECT faq_cats.id, faq_cats.name
- FROM faq_cats_related
- LEFT JOIN faq_cats ON (faq_cats.id = faq_cats_related.related_cat)
- WHERE show_cat = '$catid'
- ORDER BY faq_cats.parent
- ");
-
- while ($result = $db->row_array()) {
- $resultarray[] = $result['id'];
- if ($catarray[$result['id']]) {
- $html2 .= "<option value="$result[id]">" . $catarray[$result['id']] . "</option>";
- }
- }
- $db->query("SELECT id, name FROM faq_cats ORDER BY parent, show_order");
- while ($result = $db->row_array()) {
- if ($catarray[$result['id']] AND (!@in_array($result['id'], $resultarray))) {
- $html .= "<option value="$result[id]"> " . $catarray[$result['id']] . "</option>";
- }
- }
- $table[] = array(table_thelp("<b>Related Categories</b>", 'FAQ', 'Related Categories'), "
- <TABLE BORDER=0>
- <TR>
- <TD VALIGN=MIDDLE ALIGN=CENTER>
- <b>Available Categories</b><br />
- <SELECT style="width:250px" NAME="list11" MULTIPLE SIZE=10 onDblClick="moveSelectedOptions(this.form.list11,this.form.list21,true)">
- $html
- </SELECT>
- </TD>
- <TD VALIGN=MIDDLE ALIGN=CENTER>
- <INPUT TYPE="button" NAME="right" VALUE=">>" onClick="moveSelectedOptions(this.form.list11,this.form.list21,true); return true;"><BR><BR>
- <INPUT TYPE="button" NAME="right" VALUE="All >>" onClick="moveAllOptions(this.form.list11,this.form.list21,true); return true;"><BR><BR>
- <INPUT TYPE="button" NAME="left" VALUE="<<" onClick="moveSelectedOptions(this.form.list21,this.form.list11,true); return true;"><BR><BR>
- <INPUT TYPE="button" NAME="left" VALUE="All <<" onClick="moveAllOptions(this.form.list21,this.form.list11,true); return true;">
- </TD>
- <TD VALIGN=MIDDLE ALIGN=CENTER>
- <b>Selected Categories</b><br />
- <SELECT style="width:250px" NAME="list21" MULTIPLE SIZE=10 onDblClick="moveSelectedOptions(this.form.list21,this.form.list11,true)">
- $html2
- </SELECT>
- <input type="hidden" name="related" value="">
- </TD>
- </TR>
- </TABLE>");
- table_header('Related Categories');
- table_content($columns, $table, $extra);
- table_footer();
- if ($_REQUEST['do'] == 'edit') {
- $name = 'Update FAQ Category';
- } else {
- $name = 'Create FAQ Category';
- }
- echo "<p align="center"><input type="submit" name="submit" value="$name" onclick="submitAllOptions(this.form.list21,this.form.related)"></form>
- <SCRIPT LANGUAGE="javascript">
- sortSelect(document.forms[0].list11);
- sortSelect(document.forms[0].list21);
- </SCRIPT>";
- }
- tech_footer();
- ?>