2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 10/10/2003 *
4 * =================== Last change: 07/04/2004 *
6 * -------------------------------------------------------------------- *
7 * File : what-config_cats.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Add new categories and edit / delete existing *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Neue Kategorien hinzufuegen und bestehende *
12 * editieren / loeschen *
13 * -------------------------------------------------------------------- *
16 * $Tag:: 0.2.1-FINAL $ *
18 * Needs to be in all Files and every File needs "svn propset *
19 * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
20 * -------------------------------------------------------------------- *
21 * Copyright (c) 2003 - 2009 by Roland Haeder *
22 * For more information visit: http://www.mxchange.org *
24 * This program is free software; you can redistribute it and/or modify *
25 * it under the terms of the GNU General Public License as published by *
26 * the Free Software Foundation; either version 2 of the License, or *
27 * (at your option) any later version. *
29 * This program is distributed in the hope that it will be useful, *
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
32 * GNU General Public License for more details. *
34 * You should have received a copy of the GNU General Public License *
35 * along with this program; if not, write to the Free Software *
36 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
38 ************************************************************************/
40 // Some security stuff...
41 if ((!defined('__SECURITY')) || (!isAdmin())) {
45 // Add description as navigation point
46 addMenuDescription('admin', __FILE__);
48 // Init variable to avoid a notice
51 if (isPostRequestElementSet('add')) {
53 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `cat`='%s' LIMIT 1",
54 array(postRequestElement('catname')), __FILE__, __LINE__);
55 if (SQL_NUMROWS($result) == '0') {
56 // Category does not exists, we simply add it...
57 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_cats` (`cat`, `visible`, `sort`) VALUES ('%s','%s','%s')",
59 postRequestElement('catname'),
60 postRequestElement('visible'),
61 bigintval(postRequestElement('parent') + 1)
62 ), __FILE__, __LINE__);
63 $content = getMessage('CATEGORY_ADDED');
65 // Category does already exists
66 $content = '<span class="admin_failed">{--CATEGORY_ALREADY_EXISTS--}</span>';
70 SQL_FREERESULT($result);
73 loadTemplate('admin_settings_saved', false, $content);
74 } elseif ((isFormSent()) && (isPostRequestElementSet('id')) && (is_array(postRequestElement('id')))) {
75 // Change or delete categories...
77 foreach (postRequestElement('id') as $id => $cat) {
83 switch (getRequestElement('do')) {
84 case 'edit': // Change categories
85 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_cats` SET `cat`='%s', `visible`='%s', `sort`=%s WHERE `id`=%s LIMIT 1",
88 postRequestElement('vis', $id),
89 postRequestElement('sort', $id),
91 ), __FILE__, __LINE__);
92 $TEXT = getMessage('CATEGORIES_SAVED');
95 case 'del': // Delete categories
96 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_cats` WHERE `id`=%s LIMIT 1",
97 array($id), __FILE__, __LINE__);
98 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_cats` WHERE `cat_id`=%s",
99 array($id), __FILE__, __LINE__);
100 $TEXT = getMessage('CATEGORIES_DELETED');
105 $TEXT .= sprintf(getMessage('CATEGORY_NOT_SAVED'), $id);
111 loadTemplate('admin_settings_saved', false, $TEXT);
113 } elseif ((isPostRequestElementSet('del')) && (countPostSelection() > 0)) {
116 foreach (postRequestElement('sel') as $id => $value) {
117 // Load data of category
118 $result = SQL_QUERY_ESC("SELECT `cat` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `id`=%s LIMIT 1",
119 array(bigintval($id)), __FILE__, __LINE__);
120 list($cat) = SQL_FETCHROW($result);
123 SQL_FREERESULT($result);
125 // Prepare data for the row template
132 // Load row template and switch colors
133 $OUT .= loadTemplate('admin_del_cats_row', true, $content);
137 // Load main template
138 loadTemplate('admin_del_cats', false, $OUT);
139 } elseif ((isPostRequestElementSet('edit')) && (countPostSelection() > 0)) {
142 foreach (postRequestElement('sel') as $id => $value) {
143 // Load data from the category
144 $result = SQL_QUERY_ESC("SELECT cat, visible, sort FROM `{?_MYSQL_PREFIX?}_cats` WHERE `id`=%s LIMIT 1",
145 array(bigintval($id)), __FILE__, __LINE__);
146 list($cat, $vis, $sort) = SQL_FETCHROW($result);
147 SQL_FREERESULT($result);
149 // Prepare data for the row template
154 'vis' => addSelectionBox('yn', $vis, 'vis', $id),
158 // Load row template and switch colors
159 $OUT .= loadTemplate('admin_edit_cats_row', true, $content);
163 // Load main template
164 loadTemplate('admin_edit_cats', false, $OUT);
166 // Init variable here
169 // Load all categories
170 $result = SQL_QUERY("SELECT `id`, `cat`, `visible`, `sort` FROM `{?_MYSQL_PREFIX?}_cats` ORDER BY `sort` ASC", __FILE__, __LINE__);
171 if (SQL_NUMROWS($result) > 0) {
175 // List already existing categories for editing
176 while ($content = SQL_FETCHARRAY($result)) {
177 // Prepare data for the row template
178 $content['sw'] = $SW;
179 $content['vis'] = translateYesNo($content['visible']);
181 // Put cat descriptions into variable for the selection box
182 $cat = $content['cat'];
183 if (strlen($cat) > 40) $cat = substr($cat, 0, 37) . '...';
184 $CATS .= '<option value="' . $content['sort'] . '">' . $cat . '</option>';
186 // Load row template and switch color
187 $OUT .= loadTemplate('admin_config_cats_row', true, $content);
192 SQL_FREERESULT($result);
194 // Load main template
195 loadTemplate('admin_config_cats', false, $OUT);
199 $content['cats'] = $CATS;
201 // Form to add a new category
202 loadTemplate('admin_add_cat', false, $content);