www is out-dated
[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 - 2011 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         if (count(postRequestElement('id')) > 0) {
83                 if (isFormSent('edit')) {
84                         // Edit template
85                         $row    = 'admin_edit_country_row';
86                         $post   = 'modify';
87                         $class  = 'form_submit';
88                         $submit = '{--ADMIN_COUNTRY_EDIT_NOW--}';
89                         $title  = '{--ADMIN_COUNTRY_EDIT_TITLE--}';
90                         $reset  = '<input type="reset" class="form_reset" value="{--UNDO_SELECTIONS--}" /> ';
91                 } else {
92                         // Delete template
93                         $row    = 'admin_delete_country_row';
94                         $post   = 'remove';
95                         $class  = 'form_delete';
96                         $submit = '{--ADMIN_COUNTRY_DELETE_NOW--}';
97                         $title  = '{--ADMIN_COUNTRY_DELETE_TITLE--}';
98                         $reset  = '';
99                 }
100
101                 // Edit all selected country codes
102                 $OUT = '';
103                 foreach (postRequestElement('id') as $id => $isActive) {
104                         // Load data from DB
105                         $result = SQL_QUERY_ESC("SELECT `id`,`code`,`descr` FROM `{?_MYSQL_PREFIX?}_countries` WHERE `id`=%s LIMIT 1",
106                                 array(bigintval($id)), __FILE__, __LINE__);
107                         if (SQL_NUMROWS($result) == 1) {
108                                 // Load data
109                                 $content = SQL_FETCHARRAY($result);
110
111                                 // Add $isActive
112                                 $content['is_active'] = $isActive;
113
114                                 // Insert row template and switch color
115                                 $OUT .= loadTemplate($row, true, $content);
116                         } // END - if
117
118                         // Free result
119                         SQL_FREERESULT($result);
120                 } // END - foreach
121
122                 // Prepare content for template
123                 $content = array(
124                         'rows'   => $OUT,
125                         'mode'   => $post,
126                         'class'  => $class,
127                         'title'  => $title,
128                         'submit' => $submit,
129                         'reset'  => $reset,
130                 );
131
132                 // Load main template
133                 loadTemplate('admin_list_country_form', false, $content);
134         } // END - if
135 } else {
136         // Shall we modify / remove entries now?
137         $message = '';
138         initSqls();
139         if ((isPostRequestElementSet('modify')) && (isPostRequestElementSet('id'))) {
140                 // Modify
141                 foreach (postRequestElement('id') as $id => $sel) {
142                         addSql("UPDATE `{?_MYSQL_PREFIX?}_countries` SET `code`='" . postRequestElement('code', $id) . "', `descr`='" . postRequestElement('descr', $id) . "', `is_active`='" . postRequestElement('is_active', $id) . "' WHERE `id`=" . bigintval($id) . " LIMIT 1");
143                 } // END - foreach
144
145                 // Create message
146                 $message = '{--ADMIN_COUNTRIES_MODIFIED--}';
147         } elseif ((isFormSent('do_delete')) && (isPostRequestElementSet('id'))) {
148                 // Remove
149                 $IDs = implode(',', array_keys(postRequestElement('id')));
150                 addSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_countries` WHERE `id` IN (".$IDs.") LIMIT ".count(postRequestElement('id'))."");
151
152                 // Create message
153                 $message = '{--ADMIN_COUNTRIES_REMOVED--}';
154         }
155
156         if ((!empty($message)) && (countSqls() > 0)) {
157                 // Run SQL commands
158                 runFilterChain('run_sqls');
159
160                 // Display message
161                 displayMessage($message);
162         } // END - if
163
164         // Load currenty setup country codes to list
165         $result = SQL_QUERY('SELECT `id`,`code`,`descr`,`is_active` FROM `{?_MYSQL_PREFIX?}_countries` ORDER BY `code` ASC',
166         __FILE__, __LINE__);
167
168         // Do we have entries?
169         if (!SQL_HASZERONUMS($result)) {
170                 // List all countries
171                 $OUT = '';
172                 while ($content = SQL_FETCHARRAY($result)) {
173                         // Load row template and switch colors
174                         $OUT .= loadTemplate('admin_list_country_row', true, $content);
175                 } // END - while
176
177                 // Free memory
178                 SQL_FREERESULT($result);
179         } else {
180                 // No code setup so far (not possible by this software! 'DE' for 'Deutschland' is default
181                 $OUT = loadTemplate('admin_list_country_no_row', true);
182         }
183
184         // Add list to constant for the template
185         $content['rows'] = $OUT;
186
187         // Include add template
188         $content['add_form'] = loadTemplate('admin_add_country', true);
189
190         // Load main template
191         loadTemplate('admin_list_country', false, $content);
192 }
193
194 // [EOF]
195 ?>