]> git.mxchange.org Git - mailer.git/blob - inc/modules/admin/what-config_cats.php
b9683ab51f3124b7fac1180cbf6251f356d2ce54
[mailer.git] / inc / modules / admin / what-config_cats.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 10/10/2003 *
4  * ===================                          Last change: 07/04/2004 *
5  *                                                                      *
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  * -------------------------------------------------------------------- *
14  * $Revision::                                                        $ *
15  * $Date::                                                            $ *
16  * $Tag:: 0.2.1-FINAL                                                 $ *
17  * $Author::                                                          $ *
18  * -------------------------------------------------------------------- *
19  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
20  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!isAdmin())) {
41         die();
42 } // END - if
43
44 // Add description as navigation point
45 addMenuDescription('admin', __FILE__);
46
47 // Init variable to avoid a notice
48 $CATS = '';
49
50 if (isFormSent('add')) {
51         // Add a new category
52         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `cat`='%s' LIMIT 1",
53                 array(postRequestParameter('catname')), __FILE__, __LINE__);
54         if (SQL_HASZERONUMS($result)) {
55                 // Category does not exists, we simply add it...
56                 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_cats` (`cat`, `visible`, `sort`) VALUES ('%s','%s','%s')",
57                         array(
58                                 postRequestParameter('catname'),
59                                 postRequestParameter('visible'),
60                                 bigintval(postRequestParameter('parent') + 1)
61                         ), __FILE__, __LINE__);
62                 $content = '{--CATEGORY_ADDED--}';
63         } else {
64                 // Category does already exists
65                 $content = '<span class="notice">{--CATEGORY_ALREADY_EXISTS--}</span>';
66         }
67
68         // Free memory
69         SQL_FREERESULT($result);
70
71         // Display message
72         loadTemplate('admin_settings_saved', false, $content);
73 } elseif ((isFormSent()) && (isPostRequestParameterSet('id')) && (is_array(postRequestParameter('id')))) {
74         // Change or delete categories...
75         $TEXT = '';
76         foreach (postRequestParameter('id') as $id => $cat) {
77                 // Secure id
78                 $id = bigintval($id);
79
80                 // Is the entry set?
81                 if (!empty($cat)) {
82                         switch (getRequestParameter('do')) {
83                                 case 'edit': // Change categories
84                                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_cats` SET `cat`='%s', `visible`='%s', `sort`=%s WHERE `id`=%s LIMIT 1",
85                                                 array(
86                                                         $cat,
87                                                         postRequestParameter('visible', $id),
88                                                         postRequestParameter('sort', $id),
89                                                         $id
90                                                 ), __FILE__, __LINE__);
91                                         $TEXT = '{--ADMIN_CATEGORIES_SAVED--}';
92                                         break;
93
94                                 case 'delete': // Delete categories
95                                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_cats` WHERE `id`=%s LIMIT 1",
96                                                 array($id), __FILE__, __LINE__);
97                                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_cats` WHERE `cat_id`=%s",
98                                                 array($id), __FILE__, __LINE__);
99                                         $TEXT = '{--ADMIN_CATEGORIES_DELETED--}';
100                                         break;
101                         } // END - switch
102                 } else {
103                         // Entry not saved
104                         $TEXT .= getMaskedMessage('ADMIN_CATEGORY_NOT_SAVED', $id);
105                 }
106         } // END - foreach
107
108         if (isset($TEXT)) {
109                 // Display message
110                 loadTemplate('admin_settings_saved', false, $TEXT);
111         } // END - if
112 } elseif ((isFormSent('delete')) && (ifPostContainsSelections())) {
113         // Delete categories
114         $OUT = '';
115         foreach (postRequestParameter('sel') as $id => $value) {
116                 // Load row template and switch colors
117                 $OUT .= loadTemplate('admin_delete_cats_row', true, $id);
118         } // END - foreach
119
120         // Load main template
121         loadTemplate('admin_delete_cats', false, $OUT);
122 } elseif ((isFormSent('edit')) && (ifPostContainsSelections())) {
123         // Edit categories
124         $OUT = '';
125         foreach (postRequestParameter('sel') as $id => $value) {
126                 // Load data from the category
127                 $result = SQL_QUERY_ESC("SELECT `id`, `visible`, `sort` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `id`=%s LIMIT 1",
128                         array(bigintval($id)), __FILE__, __LINE__);
129                 $content = SQL_FETCHARRAY($result);
130
131                 // Free result
132                 SQL_FREERESULT($result);
133
134                 // Prepare data for the row template
135                 $content['visible_selection'] = addSelectionBox('yn', $content['visible'], 'visible', $content['id']);
136
137                 // Load row template and switch colors
138                 $OUT .= loadTemplate('admin_edit_cats_row', true, $content);
139         } // END - foreach
140
141         // Load main template
142         loadTemplate('admin_edit_cats', false, $OUT);
143 } else {
144         // Init variable here
145         $CATS = '';
146
147         // Load all categories
148         $result = SQL_QUERY("SELECT `id`, `cat`, `visible`, `sort` FROM `{?_MYSQL_PREFIX?}_cats` ORDER BY `sort` ASC", __FILE__, __LINE__);
149         if (!SQL_HASZERONUMS($result)) {
150                 // Init variables
151                 $OUT = '';
152
153                 // List already existing categories for editing
154                 while ($content = SQL_FETCHARRAY($result)) {
155                         // Put cat descriptions into variable for the selection box
156                         $cat = $content['cat'];
157                         if (strlen($cat) > 40) $cat = substr($cat, 0, 37) . '...';
158                         $CATS .= '<option value="' . $content['sort'] . '">' . $cat . '</option>';
159
160                         // Load row template and switch color
161                         $OUT .= loadTemplate('admin_config_cats_row', true, $content);
162                 } // END - while
163
164                 // Free memory
165                 SQL_FREERESULT($result);
166
167                 // Load main template
168                 loadTemplate('admin_config_cats', false, $OUT);
169         } // END - if
170
171         // Remember in array
172         $content['cats'] = $CATS;
173
174         // Form to add a new category
175         loadTemplate('admin_add_cat', false, $content);
176 }
177
178 // [EOF]
179 ?>