518ce7690bf1b9883d8a21c23b2de1e54c05b598
[mailer.git] / inc / modules / admin / what-list_country.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 04/30/2005 *
4  * ===================                          Last change: 04/30/2005 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-list_country.php                            *
8  * -------------------------------------------------------------------- *
9  * Short description : Manage country codes                             *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Country codes verwalten                          *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2012 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isAdmin())) {
40         die();
41 } // END - if
42
43 // Add description as navigation point
44 addYouAreHereLink('admin', __FILE__);
45
46 // Add new code?
47 if ((isFormSent('add')) && (isPostRequestElementSet('code')) && (isPostRequestElementSet('descr'))) {
48         // Check if country code does already exist
49         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_countries` WHERE `code`='%s' LIMIT 1",
50         array(strtoupper(postRequestElement('code'))), __FILE__, __LINE__);
51         if (SQL_HASZERONUMS($result)) {
52                 // Save entry
53                 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_countries` (`code`, `descr`, `is_active`) VALUES ('%s','%s','%s')",
54                 array(
55                         strtoupper(substr(postRequestElement('code'), 0, 2)),
56                         postRequestElement('descr'),
57                         postRequestElement('is_active')
58                 ), __FILE__, __LINE__);
59
60                 // Country added
61                 $message = '{%message,ADMIN_COUNTRY_ADDED=' . strtoupper(postRequestElement('descr')) . '%}';
62         } else {
63                 // Free memory
64                 SQL_FREERESULT($result);
65
66                 // Does already exist
67                 $message = '{%message,ADMIN_COUNTRY_ALREADY=' . strtoupper(postRequestElement('code')) . '%}';
68         }
69
70         // Display message
71         displayMessage($message);
72 } elseif ((isFormSent('do_edit')) && (isPostRequestElementSet('id'))) {
73         // Change all status
74         adminChangeActivationStatus(postRequestElement('id'), 'countries', 'is_active');
75
76         // Show next link
77         loadTemplate('admin_next_link', FALSE, array(
78                 'url'   => 'modules.php?module=admin&amp;what=list_country',
79                 'title' => '{--ADMIN_COUNTRY_ACTIVATION_NEXT_LINK--}'
80         ));
81 } elseif (((isFormSent('edit')) || (isPostRequestElementSet('delete'))) && (isPostRequestElementSet('id'))) {
82         // Are there entries?
83         if (ifPostContainsSelections('id')) {
84                 // Is the proper form sent?
85                 if (isFormSent('edit')) {
86                         // Edit template
87                         $row    = 'admin_edit_country_row';
88                         $do     = 'modify';
89                         $class  = 'form_submit';
90                         $submit = '{--ADMIN_COUNTRY_EDIT_NOW--}';
91                         $title  = '{--ADMIN_COUNTRY_EDIT_TITLE--}';
92                         $reset  = '<input type="reset" class="form_reset" value="{--UNDO_SELECTIONS--}" /> ';
93                 } else {
94                         // Delete template
95                         $row    = 'admin_delete_country_row';
96                         $do     = 'remove';
97                         $class  = 'form_delete';
98                         $submit = '{--ADMIN_COUNTRY_DELETE_NOW--}';
99                         $title  = '{--ADMIN_COUNTRY_DELETE_TITLE--}';
100                         $reset  = '';
101                 }
102
103                 // Edit all selected country codes
104                 $OUT = '';
105                 foreach (postRequestElement('id') as $id => $isActive) {
106                         // Load data from DB
107                         $result = SQL_QUERY_ESC("SELECT `id`, `code`, `descr` FROM `{?_MYSQL_PREFIX?}_countries` WHERE `id`=%s LIMIT 1",
108                                 array(bigintval($id)), __FILE__, __LINE__);
109                         if (SQL_NUMROWS($result) == 1) {
110                                 // Load data
111                                 $content = SQL_FETCHARRAY($result);
112
113                                 // Add $isActive
114                                 $content['is_active'] = $isActive;
115
116                                 // Insert row template and switch color
117                                 $OUT .= loadTemplate($row, TRUE, $content);
118                         } // END - if
119
120                         // Free result
121                         SQL_FREERESULT($result);
122                 } // END - foreach
123
124                 // Prepare content for template
125                 $content = array(
126                         'rows'   => $OUT,
127                         'do'     => $do,
128                         'class'  => $class,
129                         'title'  => $title,
130                         'submit' => $submit,
131                         'reset'  => $reset,
132                 );
133
134                 // Load main template
135                 loadTemplate('admin_list_country_form', FALSE, $content);
136         } // END - if
137 } else {
138         // Shall we modify / remove entries now?
139         $message = '';
140         initSqls();
141         if ((isPostRequestElementSet('modify')) && (isPostRequestElementSet('id'))) {
142                 // Modify
143                 foreach (postRequestElement('id') as $id => $sel) {
144                         addSql("UPDATE
145         `{?_MYSQL_PREFIX?}_countries`
146 SET
147         `code`='" . postRequestElement('code', $id) . "',
148         `descr`='" . postRequestElement('descr', $id) . "',
149         `is_active`='" . postRequestElement('is_active', $id) . "'
150 WHERE
151         `id`=" . bigintval($id) . "
152 LIMIT 1");
153                 } // END - foreach
154
155                 // Create message
156                 $message = '{--ADMIN_COUNTRIES_MODIFIED--}';
157         } elseif ((isFormSent('do_delete')) && (isPostRequestElementSet('id'))) {
158                 // Remove
159                 $IDs = implode(',', array_keys(postRequestElement('id')));
160                 addSql('DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_countries` WHERE `id` IN (' . $IDs . ') LIMIT ' . countPostSelection('id') . '');
161
162                 // Create message
163                 $message = '{--ADMIN_COUNTRIES_REMOVED--}';
164         }
165
166         if ((!empty($message)) && (countSqls() > 0)) {
167                 // Run SQL commands
168                 runFilterChain('run_sqls');
169
170                 // Display message
171                 displayMessage($message);
172         } // END - if
173
174         // Load currenty setup country codes to list
175         $result = SQL_QUERY('SELECT `id`, `code`, `descr`, `is_active` FROM `{?_MYSQL_PREFIX?}_countries` ORDER BY `code` ASC',
176         __FILE__, __LINE__);
177
178         // Are there entries?
179         if (!SQL_HASZERONUMS($result)) {
180                 // List all countries
181                 $OUT = '';
182                 while ($content = SQL_FETCHARRAY($result)) {
183                         // Load row template and switch colors
184                         $OUT .= loadTemplate('admin_list_country_row', TRUE, $content);
185                 } // END - while
186
187                 // Free memory
188                 SQL_FREERESULT($result);
189         } else {
190                 // No code setup so far (not possible by this software! 'DE' for 'Deutschland' is default
191                 $OUT = loadTemplate('admin_list_country_no_row', TRUE);
192         }
193
194         // Add list to constant for the template
195         $content['rows'] = $OUT;
196
197         // Include add template
198         $content['add_form'] = loadTemplate('admin_add_country', TRUE);
199
200         // Load main template
201         loadTemplate('admin_list_country', FALSE, $content);
202 }
203
204 // [EOF]
205 ?>