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('visible', $id),
90 postRequestParameter('sort', $id),
92 ), __FILE__, __LINE__);
93 $TEXT = '{--ADMIN_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 = '{--ADMIN_CATEGORIES_DELETED--}';
106 $TEXT .= getMaskedMessage('ADMIN_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 row template and switch colors
119 $OUT .= loadTemplate('admin_del_cats_row', true, $id);
122 // Load main template
123 loadTemplate('admin_del_cats', false, $OUT);
124 } elseif ((isFormSent('edit')) && (ifPostContainsSelections())) {
127 foreach (postRequestParameter('sel') as $id => $value) {
128 // Load data from the category
129 $result = SQL_QUERY_ESC("SELECT `id`, `visible`, `sort` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `id`=%s LIMIT 1",
130 array(bigintval($id)), __FILE__, __LINE__);
131 $content = SQL_FETCHARRAY($result);
134 SQL_FREERESULT($result);
136 // Prepare data for the row template
137 $content['visible_selection'] = addSelectionBox('yn', $content['visible'], 'visible', $content['id']);
139 // Load row template and switch colors
140 $OUT .= loadTemplate('admin_edit_cats_row', true, $content);
143 // Load main template
144 loadTemplate('admin_edit_cats', false, $OUT);
146 // Init variable here
149 // Load all categories
150 $result = SQL_QUERY("SELECT `id`, `cat`, `visible`, `sort` FROM `{?_MYSQL_PREFIX?}_cats` ORDER BY `sort` ASC", __FILE__, __LINE__);
151 if (!SQL_HASZERONUMS($result)) {
155 // List already existing categories for editing
156 while ($content = SQL_FETCHARRAY($result)) {
157 // Put cat descriptions into variable for the selection box
158 $cat = $content['cat'];
159 if (strlen($cat) > 40) $cat = substr($cat, 0, 37) . '...';
160 $CATS .= '<option value="' . $content['sort'] . '">' . $cat . '</option>';
162 // Load row template and switch color
163 $OUT .= loadTemplate('admin_config_cats_row', true, $content);
167 SQL_FREERESULT($result);
169 // Load main template
170 loadTemplate('admin_config_cats', false, $OUT);
174 $content['cats'] = $CATS;
176 // Form to add a new category
177 loadTemplate('admin_add_cat', false, $content);