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 * Copyright (c) 2009, 2010 by Mailer Developer Team *
23 * For more information visit: http://www.mxchange.org *
25 * This program is free software; you can redistribute it and/or modify *
26 * it under the terms of the GNU General Public License as published by *
27 * the Free Software Foundation; either version 2 of the License, or *
28 * (at your option) any later version. *
30 * This program is distributed in the hope that it will be useful, *
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
33 * GNU General Public License for more details. *
35 * You should have received a copy of the GNU General Public License *
36 * along with this program; if not, write to the Free Software *
37 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
39 ************************************************************************/
41 // Some security stuff...
42 if ((!defined('__SECURITY')) || (!isAdmin())) {
46 // Add description as navigation point
47 addMenuDescription('admin', __FILE__);
49 // Init variable to avoid a notice
52 if (isFormSent('add')) {
54 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `cat`='%s' LIMIT 1",
55 array(postRequestParameter('catname')), __FILE__, __LINE__);
56 if (SQL_HASZERONUMS($result)) {
57 // Category does not exists, we simply add it...
58 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_cats` (`cat`, `visible`, `sort`) VALUES ('%s','%s','%s')",
60 postRequestParameter('catname'),
61 postRequestParameter('visible'),
62 bigintval(postRequestParameter('parent') + 1)
63 ), __FILE__, __LINE__);
64 $content = '{--CATEGORY_ADDED--}';
66 // Category does already exists
67 $content = '<span class="admin_failed">{--CATEGORY_ALREADY_EXISTS--}</span>';
71 SQL_FREERESULT($result);
74 loadTemplate('admin_settings_saved', false, $content);
75 } elseif ((isFormSent()) && (isPostRequestParameterSet('id')) && (is_array(postRequestParameter('id')))) {
76 // Change or delete categories...
78 foreach (postRequestParameter('id') as $id => $cat) {
84 switch (getRequestParameter('do')) {
85 case 'edit': // Change categories
86 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_cats` SET `cat`='%s', `visible`='%s', `sort`=%s WHERE `id`=%s LIMIT 1",
89 postRequestParameter('vis', $id),
90 postRequestParameter('sort', $id),
92 ), __FILE__, __LINE__);
93 $TEXT = '{--CATEGORIES_SAVED--}';
96 case 'del': // Delete categories
97 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_cats` WHERE `id`=%s LIMIT 1",
98 array($id), __FILE__, __LINE__);
99 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_cats` WHERE `cat_id`=%s",
100 array($id), __FILE__, __LINE__);
101 $TEXT = '{--CATEGORIES_DELETED--}';
106 $TEXT .= getMaskedMessage('CATEGORY_NOT_SAVED', $id);
112 loadTemplate('admin_settings_saved', false, $TEXT);
114 } elseif ((isFormSent('del')) && (ifPostContainsSelections())) {
117 foreach (postRequestParameter('sel') as $id => $value) {
118 // Load data of category
119 $result = SQL_QUERY_ESC("SELECT `cat` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `id`=%s LIMIT 1",
120 array(bigintval($id)), __FILE__, __LINE__);
121 list($cat) = SQL_FETCHROW($result);
124 SQL_FREERESULT($result);
126 // Prepare data for the row template
132 // Load row template and switch colors
133 $OUT .= loadTemplate('admin_del_cats_row', true, $content);
136 // Load main template
137 loadTemplate('admin_del_cats', false, $OUT);
138 } elseif ((isFormSent('edit')) && (ifPostContainsSelections())) {
141 foreach (postRequestParameter('sel') as $id => $value) {
142 // Load data from the category
143 $result = SQL_QUERY_ESC("SELECT cat, visible, sort FROM `{?_MYSQL_PREFIX?}_cats` WHERE `id`=%s LIMIT 1",
144 array(bigintval($id)), __FILE__, __LINE__);
145 list($cat, $vis, $sort) = SQL_FETCHROW($result);
146 SQL_FREERESULT($result);
148 // Prepare data for the row template
152 'vis' => addSelectionBox('yn', $vis, 'vis', $id),
156 // Load row template and switch colors
157 $OUT .= loadTemplate('admin_edit_cats_row', true, $content);
160 // Load main template
161 loadTemplate('admin_edit_cats', false, $OUT);
163 // Init variable here
166 // Load all categories
167 $result = SQL_QUERY("SELECT `id`, `cat`, `visible`, `sort` FROM `{?_MYSQL_PREFIX?}_cats` ORDER BY `sort` ASC", __FILE__, __LINE__);
168 if (!SQL_HASZERONUMS($result)) {
172 // List already existing categories for editing
173 while ($content = SQL_FETCHARRAY($result)) {
174 // Prepare data for the row template
175 $content['vis'] = translateYesNo($content['visible']);
177 // Put cat descriptions into variable for the selection box
178 $cat = $content['cat'];
179 if (strlen($cat) > 40) $cat = substr($cat, 0, 37) . '...';
180 $CATS .= '<option value="' . $content['sort'] . '">' . $cat . '</option>';
182 // Load row template and switch color
183 $OUT .= loadTemplate('admin_config_cats_row', true, $content);
187 SQL_FREERESULT($result);
189 // Load main template
190 loadTemplate('admin_config_cats', false, $OUT);
194 $content['cats'] = $CATS;
196 // Form to add a new category
197 loadTemplate('admin_add_cat', false, $content);