More XHTML-fied and extended header added to templates
[mailer.git] / inc / modules / admin / what-list_country.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    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:: 856                                                    $ *
14  * $Date:: 2009-03-06 20:24:32 +0100 (Fr, 06. March 2009)             $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author:: stelzi                                                   $ *
17  * Needs to be in all Files and every File needs "svn propset           *
18  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
19  * -------------------------------------------------------------------- *
20  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
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')) || (!IS_ADMIN())) {
41         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
42         require($INC);
43 }
44
45 // Add description as navigation point
46 ADD_DESCR("admin", __FILE__);
47
48 // Add new code?
49 if ((REQUEST_ISSET_POST(('add'))) && (REQUEST_ISSET_POST(('code'))) && (REQUEST_ISSET_POST(('descr')))) {
50         // Check if country code does already exist
51         $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_countries` WHERE code='%s' LIMIT 1",
52          array(strtoupper(REQUEST_POST('code'))), __FILE__, __LINE__);
53         if (SQL_NUMROWS($result) == 0) {
54                 // Save entry
55                 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_countries` (code, descr, is_active) VALUES ('%s','%s','%s')",
56                         array(
57                                 strtoupper(substr(REQUEST_POST('code'), 0, 2)),
58                                 REQUEST_POST('descr'),
59                                 REQUEST_POST('is_active')
60                         ), __FILE__, __LINE__);
61
62                 // Country added
63                 $MSG = ADMIN_COUNTRY_ADDED_1.strtoupper(REQUEST_POST('descr')).ADMIN_COUNTRY_ADDED_2;
64         } else {
65                 // Free memory
66                 SQL_FREERESULT($result);
67
68                 // Does already exist
69                 $MSG = ADMIN_COUNTRY_ALREADY_1.strtoupper(REQUEST_POST('code')).ADMIN_COUNTRY_ALREADY_2;
70         }
71
72         // Display message
73         LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
74 } elseif ((REQUEST_ISSET_POST(('change'))) && (REQUEST_ISSET_POST(('id')))) {
75         // Change all status
76         ADMIN_CHANGE_ACTIVATION_STATUS(REQUEST_POST('id'), "countries", "is_active");
77
78         // Show next link
79         LOAD_TEMPLATE("admin_next_link", false, array(
80                 'url'   => "modules.php?module=admin&amp;what=list_country",
81                 'title' => getMessage('ADMIN_COUNTRY_ACTIVATION_NEXT_LINK')
82         ));
83 } elseif (((REQUEST_ISSET_POST('edit')) || (REQUEST_ISSET_POST(('delete')))) && (REQUEST_ISSET_POST(('id')))) {
84         if (count(REQUEST_POST('id')) > 0) {
85                 if (REQUEST_ISSET_POST('edit')) {
86                         // Edit template
87                         $row    = "admin_list_country_edit_row";
88                         $post   = "modify";
89                         $class  = "admin_submit";
90                         $submit = ADMIN_COUNTRY_EDIT_NOW;
91                         $title  = ADMIN_COUNTRY_EDIT_TITLE;
92                         $reset  = "<input type=\"reset\" class=\"admin_reset\" value=\"{!UNDO_SELECTIONS!}\" />&nbsp;*\n";
93                 } else {
94                         // Delete template
95                         $row    = "admin_list_country_del_row";
96                         $post   = "remove";
97                         $class  = "admin_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 = ""; $SW = 2;
105                 foreach (REQUEST_POST('id') as $id => $status) {
106                         // Load data from DB
107                         $result = SQL_QUERY_ESC("SELECT 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                                 list($code, $descr) = SQL_FETCHROW($result);
112                                 SQL_FREERESULT($result);
113
114                                 // Prepare data, load row template and switch colors
115                                 $content = array(
116                                         'id'    => $id,
117                                         'code'  => $code,
118                                         'descr' => $descr,
119                                         'sw'    => $SW,
120                                 );
121
122                                 if ($post == "modify") {
123                                         // Generate default selection in edit-mode
124                                         $content['status'] = ADD_OPTION_LINES("/ARRAY/", array("Y","N"), array(YES, NO ), $status);
125                                 } else {
126                                         // Only display status when in delete-mode
127                                         $content['status'] = TRANSLATE_YESNO($status);
128                                 }
129
130                                 // Insert row template and switch color
131                                 $OUT .= LOAD_TEMPLATE($row, true, $content);
132                                 $SW = 3 - $SW;
133                         }
134                 }
135                 define('__COUNTRY_ROWS'  , $OUT);
136                 define('__COUNTRY_MODE'  , $post);
137                 define('__COUNTRY_CLASS' , $class);
138                 define('__COUNTRY_SUBMIT', $submit);
139                 define('__COUNTRY_TITLE' , $title);
140                 define('__COUNTRY_RESET' , $reset);
141
142                 // Load main template
143                 LOAD_TEMPLATE("admin_list_country_form");
144         }
145 } else {
146         // Shall we modify / remove entries now?
147         $MSG = ""; INIT_SQLS();
148         if ((REQUEST_ISSET_POST(('modify'))) && (REQUEST_ISSET_POST(('id')))) {
149                 // Modify
150                 foreach (REQUEST_POST('id') as $id => $sel) {
151                         ADD_SQL("UPDATE `{!_MYSQL_PREFIX!}_countries` SET code='".REQUEST_POST('code', $id)."', descr='".REQUEST_POST('descr', $id)."', is_active='".REQUEST_POST('is_active', $id)."' WHERE id='".$id."' LIMIT 1");
152                 }
153
154                 // Create message
155                 $MSG = getMessage('ADMIN_COUNTRIES_MODIFIED');
156         } elseif ((REQUEST_ISSET_POST(('remove'))) && (REQUEST_ISSET_POST(('id')))) {
157                 // Remove
158                 $IDs = implode(",", array_keys(REQUEST_POST('id')));
159                 ADD_SQL("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_countries` WHERE id IN (".$IDs.") LIMIT ".count(REQUEST_POST('id'))."");
160
161                 // Create message
162                 $MSG = getMessage('ADMIN_COUNTRIES_REMOVED');
163         }
164
165         if ((!empty($MSG)) && (COUNT_SQLS() > 0)) {
166                 // Run SQL commands
167                 runFilterChain('run_sqls');
168
169                 // Display message
170                 LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
171         }
172
173         // Load currenty setup country codes to list
174         $result = SQL_QUERY("SELECT id, code, descr, is_active FROM `{!_MYSQL_PREFIX!}_countries` ORDER BY code", __FILE__, __LINE__);
175         if (SQL_NUMROWS($result) > 0) {
176                 // List all countries
177                 $OUT = ""; $SW = 2;
178                 while ($content = SQL_FETCHARRAY($result)) {
179                         // Prepare array for the template
180                         // @TODO Rewritings: name->descr,status->is_active in template
181                         $content = array(
182                                 'id'     => $content['id'],
183                                 'code'   => $content['code'],
184                                 'name'   => $content['descr'],
185                                 'active' => TRANSLATE_YESNO($content['is_active']),
186                                 'sw'     => $SW,
187                                 'status' => $content['is_active'],
188                         );
189
190                         // Load row template and switch colors
191                         $OUT .= LOAD_TEMPLATE("admin_list_country_row", true, $content);
192                         $SW = 3 - $SW;
193                 }
194
195                 // Free memory
196                 SQL_FREERESULT($result);
197         } else {
198                 // No code setup so far (not possible by this software! 'DE' for 'Deutschland' is default
199                 $OUT = LOAD_TEMPLATE("admin_list_country_no_row", true);
200         }
201
202         // Add list to constant for the template
203         define('__COUNTRY_ROWS', $OUT);
204
205         // Include add template
206         define('__ADD_COUNTRY_FORM', LOAD_TEMPLATE("admin_add_country", true));
207
208         // Load main template
209         LOAD_TEMPLATE("admin_list_country");
210 }
211
212 //
213 ?>