]> git.mxchange.org Git - mailer.git/blob - inc/modules/admin/what-list_cats.php
Renamed ifSqlHasZeroNums() to ifSqlHasZeroNumRows() and improved some queries.
[mailer.git] / inc / modules / admin / what-list_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-list_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 - 2015 by Mailer Developer Team                   *
21  * For more information visit: http://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 addYouAreHereLink('admin', __FILE__);
46
47 // Init variable to avoid a notice
48 $CATS = '';
49
50 if (isFormSent('add')) {
51         // Default message
52         $content = '<span class="bad">{--CATEGORY_ALREADY_EXISTS--}</span>';
53
54         // Add a new category
55         $result = sqlQueryEscaped("SELECT `id` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `cat`='%s' LIMIT 1",
56                 array(postRequestElement('catname')), __FILE__, __LINE__);
57
58         if (ifSqlHasZeroNumRows($result)) {
59                 // Category does not exists, we simply add it...
60                 sqlQueryEscaped("INSERT INTO `{?_MYSQL_PREFIX?}_cats` (`cat`, `visible`, `sort`) VALUES ('%s','%s','%s')",
61                         array(
62                                 postRequestElement('catname'),
63                                 postRequestElement('visible'),
64                                 bigintval(postRequestElement('parent') + 1)
65                         ), __FILE__, __LINE__);
66
67                 // Category has been added
68                 $content = '{--CATEGORY_ADDED--}';
69         } // END - if
70
71         // Free memory
72         sqlFreeResult($result);
73
74         // Display message
75         displayMessage($content);
76 } elseif ((isFormSent()) && (ifPostContainsSelections('id'))) {
77         // Change or delete categories...
78         $TEXT = '';
79         foreach (postRequestElement('id') as $id => $cat) {
80                 // Secure id
81                 $id = bigintval($id);
82
83                 // Is the entry set?
84                 if (!empty($cat)) {
85                         switch (getRequestElement('do')) {
86                                 case 'edit': // Change categories
87                                         sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_cats` SET `cat`='%s',`visible`='%s',`sort`=%s WHERE `id`=%s LIMIT 1",
88                                                 array(
89                                                         $cat,
90                                                         postRequestElement('visible', $id),
91                                                         postRequestElement('sort', $id),
92                                                         $id
93                                                 ), __FILE__, __LINE__);
94                                         $TEXT = '{--ADMIN_CATEGORIES_SAVED--}';
95                                         break;
96
97                                 case 'delete': // Delete categories
98                                         sqlQueryEscaped("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_cats` WHERE `id`=%s LIMIT 1",
99                                                 array($id), __FILE__, __LINE__);
100                                         sqlQueryEscaped("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_cats` WHERE `cat_id`=%s",
101                                                 array($id), __FILE__, __LINE__);
102                                         $TEXT = '{--ADMIN_CATEGORIES_DELETED--}';
103                                         break;
104                         } // END - switch
105                 } else {
106                         // Entry not saved
107                         $TEXT .= '{%message,ADMIN_CATEGORY_NOT_SAVED=' . $id . '%}';
108                 }
109         } // END - foreach
110
111         if (isset($TEXT)) {
112                 // Display message
113                 displayMessage($TEXT);
114         } // END - if
115 } elseif ((isFormSent('delete')) && (ifPostContainsSelections())) {
116         // Delete categories
117         $OUT = '';
118         foreach (postRequestElement('sel') as $id => $value) {
119                 // Load row template and switch colors
120                 $OUT .= loadTemplate('admin_delete_cats_row', TRUE, $id);
121         } // END - foreach
122
123         // Load main template
124         loadTemplate('admin_delete_cats', FALSE, $OUT);
125 } elseif ((isFormSent('edit')) && (ifPostContainsSelections())) {
126         // Edit categories
127         $OUT = '';
128         foreach (postRequestElement('sel') as $id => $value) {
129                 // Load data from the category
130                 $result = sqlQueryEscaped("SELECT `id`, `visible`, `sort` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `id`=%s LIMIT 1",
131                         array(bigintval($id)), __FILE__, __LINE__);
132                 $content = sqlFetchArray($result);
133
134                 // Free result
135                 sqlFreeResult($result);
136
137                 // Prepare data for the row template
138                 $content['visible_selection'] = addSelectionBox('yn', $content['visible'], 'visible', $content['id']);
139
140                 // Load row template and switch colors
141                 $OUT .= loadTemplate('admin_edit_cats_row', TRUE, $content);
142         } // END - foreach
143
144         // Load main template
145         loadTemplate('admin_edit_cats', FALSE, $OUT);
146 } else {
147         // Init variable here
148         $CATS = '';
149
150         // Load all categories
151         $result = sqlQuery("SELECT
152         `id`,
153         `cat`,
154         `visible`,
155         `sort`
156 FROM
157         `{?_MYSQL_PREFIX?}_cats`
158 ORDER BY
159         `sort` ASC", __FILE__, __LINE__);
160
161         if (!ifSqlHasZeroNumRows($result)) {
162                 // Init variables
163                 $OUT = '';
164
165                 // List already existing categories for editing
166                 while ($content = sqlFetchArray($result)) {
167                         // Put cat descriptions into variable for the selection box
168                         if (strlen($content['cat']) > 40) $content['cat'] = substr($content['cat'], 0, 37) . '...';
169                         $CATS .= '<option value="' . $content['sort'] . '">' . $content['cat'] . '</option>';
170
171                         // Load row template and switch color
172                         $OUT .= loadTemplate('admin_list_cats_row', TRUE, $content);
173                 } // END - while
174
175                 // Free memory
176                 sqlFreeResult($result);
177
178                 // Load main template
179                 loadTemplate('admin_list_cats', FALSE, $OUT);
180         } // END - if
181
182         // Remember in array
183         $content['cats'] = $CATS;
184
185         // Form to add a new category
186         loadTemplate('admin_add_cat', FALSE, $content);
187 }
188
189 // [EOF]
190 ?>