2 /************************************************************************
\r
3 * MXChange v0.2.1 Start: 10/10/2003 *
\r
4 * =============== Last change: 07/04/2004 *
\r
6 * -------------------------------------------------------------------- *
\r
7 * File : what-config_cats.php *
\r
8 * -------------------------------------------------------------------- *
\r
9 * Short description : Add new categories and edit / delete existing *
\r
10 * -------------------------------------------------------------------- *
\r
11 * Kurzbeschreibung : Neue Kategorien hinzuf�gen und bestehende *
\r
12 * editieren / l�schen *
\r
13 * -------------------------------------------------------------------- *
\r
15 * -------------------------------------------------------------------- *
\r
16 * Copyright (c) 2003 - 2008 by Roland Haeder *
\r
17 * For more information visit: http://www.mxchange.org *
\r
19 * This program is free software; you can redistribute it and/or modify *
\r
20 * it under the terms of the GNU General Public License as published by *
\r
21 * the Free Software Foundation; either version 2 of the License, or *
\r
22 * (at your option) any later version. *
\r
24 * This program is distributed in the hope that it will be useful, *
\r
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
\r
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
\r
27 * GNU General Public License for more details. *
\r
29 * You should have received a copy of the GNU General Public License *
\r
30 * along with this program; if not, write to the Free Software *
\r
31 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
\r
32 * MA 02110-1301 USA *
\r
33 ************************************************************************/
\r
35 // Some security stuff...
\r
36 if ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!IS_ADMIN())) {
\r
37 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
\r
41 // Add description as navigation point
\r
42 ADD_DESCR("admin", basename(__FILE__));
\r
44 // Init variable to avoid a notice
47 OPEN_TABLE("100%", "admin_content admin_content_align", "");
\r
48 if (isset($_POST['add'])) {
\r
49 // Add a new category
\r
50 $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_cats WHERE cat='%s' LIMIT 1",
\r
51 array(addslashes($_POST['catname'])), __FILE__, __LINE__);
\r
52 if (SQL_NUMROWS($result) == 0) {
\r
53 // Category does not exists, we simply add it...
\r
54 $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_cats (cat, visible, sort) VALUES ('%s', '%s', '%s')",
\r
55 array(addslashes($_POST['catname']), $_POST['visible'], bigintval($_POST['parent'] + 1)), __FILE__, __LINE__);
\r
56 $content = "<SPAN class=\"admin_done\">".CATEGORY_ADDED."</SPAN>";
\r
58 // Category does already exists
\r
59 $content = "<SPAN class=\"admin_failed\">".CATEGORY_ALREADY_EXISTS."</SPAN>";
\r
63 SQL_FREERESULT($result);
66 LOAD_TEMPLATE("admin_settings_saved", false, $content);
\r
67 } elseif ((isset($_POST['ok'])) && (isset($_POST['id'])) && (is_array($_POST['id']))) {
\r
68 // Change or delete categories...
\r
70 foreach ($_POST['id'] as $id=>$cat) {
\r
72 $id = bigintval($id);
\r
76 switch ($_GET['do'])
\r
78 case "edit": // Change categories
\r
79 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_cats SET cat='%s', visible='%s', sort=%d WHERE id=%d LIMIT 1",
\r
80 array($cat, $_POST['vis'][$id], $_POST['sort'][$id], $id), __FILE__, __LINE__);
\r
81 $TEXT = CATEGORIES_SAVED;
\r
84 case "del": // Delete categories
\r
85 $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_cats WHERE id=%d LIMIT 1",
\r
86 array($id), __FILE__, __LINE__);
\r
87 $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_cats WHERE cat_id=%d",
\r
88 array($id), __FILE__, __LINE__);
\r
89 $TEXT = CATEGORIES_DELETED;
\r
94 $TEXT .= sprintf(CATEGORY_NOT_SAVED, $id);
100 LOAD_TEMPLATE("admin_settings_saved", false, $TEXT);
\r
103 elseif ((isset($_POST['del'])) && ((SELECTION_COUNT($_POST['sel']) > 0) || (isset($_POST['sel'][0]))))
\r
105 // Delete categories
\r
106 $SW = 2; $OUT = "";
\r
107 foreach ($_POST['sel'] as $id=>$value)
\r
109 // Load data of category
\r
110 $result = SQL_QUERY_ESC("SELECT cat FROM "._MYSQL_PREFIX."_cats WHERE id=%d LIMIT 1",
\r
111 array(bigintval($id)), __FILE__, __LINE__);
\r
112 list($cat) = SQL_FETCHROW($result);
\r
113 SQL_FREERESULT($result);
\r
115 // Prepare data for the row template
\r
122 // Load row template and switch colors
\r
123 $OUT .= LOAD_TEMPLATE("admin_del_cats_row", true, $content);
\r
126 define('__CAT_ROWS', $OUT);
\r
128 // Load main template
\r
129 LOAD_TEMPLATE("admin_del_cats");
\r
130 } elseif ((isset($_POST['edit'])) && ((SELECTION_COUNT($_POST['sel']) > 0) || (isset($_POST['sel'][0])))) {
\r
132 $SW = 2; $OUT = "";
\r
133 foreach ($_POST['sel'] as $id=>$value)
\r
135 // Load data from the category
\r
136 $result = SQL_QUERY_ESC("SELECT cat, visible, sort FROM "._MYSQL_PREFIX."_cats WHERE id=%d LIMIT 1",
\r
137 array(bigintval($id)), __FILE__, __LINE__);
\r
138 list($cat, $vis, $sort) = SQL_FETCHROW($result);
\r
139 SQL_FREERESULT($result);
\r
141 // Prepare data for the row template
\r
146 'vis' => ADD_SELECTION("yn", $vis, "vis", $id),
\r
150 // Load row template and switch colors
\r
151 $OUT .= LOAD_TEMPLATE("admin_edit_cats_row", true, $content);
\r
154 define('__CAT_ROWS', $OUT);
\r
156 // Load main template
\r
157 LOAD_TEMPLATE("admin_edit_cats");
\r
161 // Load all categories
\r
162 $result = SQL_QUERY("SELECT id, cat, visible, sort FROM "._MYSQL_PREFIX."_cats ORDER BY sort", __FILE__, __LINE__);
\r
163 if (SQL_NUMROWS($result) > 0)
\r
165 // List already existing categories for editing
\r
166 $SW = 2; $OUT = ""; $CATS = "";
\r
167 while (list($id, $cat, $visible, $sort) = SQL_FETCHROW($result))
\r
169 // Prepare data for the row template
\r
174 'vis' => TRANSLATE_YESNO($visible),
\r
178 // Put cat descriptions into variable for the selection box
\r
179 if (strlen($cat) > 20) $cat = substr($cat, 0, 17)."...";
\r
180 $CATS .= " <OPTION value=\"".$sort."\">".$cat."</OPTION>\n";
\r
182 // Load row template and switch color
\r
183 $OUT .= LOAD_TEMPLATE("admin_config_cats_row", true, $content);
\r
188 SQL_FREERESULT($result);
\r
189 define('__CAT_ROWS', $OUT);
\r
191 // Load main template
\r
192 LOAD_TEMPLATE("admin_config_cats");
\r
195 define('CATS', $CATS);
\r
197 // Form to add a new category
\r
198 LOAD_TEMPLATE("admin_add_cat");
\r