Security line in all includes changed
[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  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if ((!defined('__SECURITY')) || (!is_admin())) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 }
39
40 // Add description as navigation point
41 ADD_DESCR("admin", basename(__FILE__));
42
43 // Add new code?
44 if ((isset($_POST['add'])) && (!empty($_POST['code'])) && (!empty($_POST['descr'])))
45 {
46         // Check if country code does already exist
47         $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_countries WHERE code='%s' LIMIT 1",
48          array(strtoupper($_POST['code'])), __FILE__, __LINE__);
49         if (SQL_NUMROWS($result) == 0)
50         {
51                 // Save entry
52                 $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_countries (code, descr, is_active)
53  VALUES('%s', '%s', '%s')",
54  array(strtoupper(substr($_POST['code'], 0, 2)), $_POST['descr'], $_POST['is_active']), __FILE__, __LINE__);
55
56                 // Country added
57                 $MSG = ADMIN_COUNTRY_ADDED_1.strtoupper($_POST['descr']).ADMIN_COUNTRY_ADDED_2;
58         }
59          else
60         {
61                 // Free memory
62                 SQL_FREERESULT($result);
63
64                 // Does already exist
65                 $MSG = ADMIN_COUNTRY_ALREADY_1.strtoupper($_POST['code']).ADMIN_COUNTRY_ALREADY_2;
66         }
67
68         // Display message
69         LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
70         OUTPUT_HTML("<br />");
71 }
72 // Change status?
73  elseif ((isset($_POST['change'])) && (!empty($_POST['id'])))
74 {
75         // Change all status
76         ADMIN_CHANGE_ACTIVATION_STATUS($_POST['id'], "countries", "is_active");
77 }
78 // Edit / delete entries?
79  elseif (((isset($_POST['edit'])) || (isset($_POST['delete']))) && (!empty($_POST['id'])))
80 {
81         if (count($_POST['id']) > 0)
82         {
83                 if (isset($_POST['edit']))
84                 {
85                         // Edit template
86                         $row    = "admin_list_country_edit_row";
87                         $post   = "modify";
88                         $class  = "admin_submit";
89                         $submit = ADMIN_COUNTRY_EDIT_NOW;
90                         $title  = ADMIN_COUNTRY_EDIT_TITLE;
91                         $reset  = "<INPUT type=\"reset\" class=\"admin_reset\" value=\"".UNDO_SELECTIONS."\">&nbsp;*\n";
92                 }
93                  else
94                 {
95                         // Delete template
96                         $row    = "admin_list_country_del_row";
97                         $post   = "remove";
98                         $class  = "admin_delete";
99                         $submit = ADMIN_COUNTRY_DELETE_NOW;
100                         $title  = ADMIN_COUNTRY_DELETE_TITLE;
101                         $reset  = "";
102                 }
103
104                 // Edit all selected country codes
105                 $OUT = ""; $SW = 2;
106                 foreach ($_POST['id'] as $id => $status)
107                 {
108                         // Load data from DB
109                         $result = SQL_QUERY_ESC("SELECT code, descr FROM "._MYSQL_PREFIX."_countries WHERE id=%s LIMIT 1",
110                          array(bigintval($id)), __FILE__, __LINE__);
111                         if (SQL_NUMROWS($result) == 1)
112                         {
113                                 // Load data
114                                 list($code, $descr) = SQL_FETCHROW($result);
115                                 SQL_FREERESULT($result);
116
117                                 // Prepare data, load row template and switch colors
118                                 $content = array(
119                                         'id'    => $id,
120                                         'code'  => $code,
121                                         'descr' => $descr,
122                                         'sw'    => $SW,
123                                 );
124                                 if ($post == "modify")
125                                 {
126                                         // Generate default selection in edit-mode
127                                         $content['status'] = ADD_OPTION_LINES("/ARRAY/", array('Y', 'N'), array(YES, NO ), $status);
128                                 }
129                                  else
130                                 {
131                                         // Only display status when in delete-mode
132                                         $content['status'] = TRANSLATE_YESNO($status);
133                                 }
134                                 $OUT .= LOAD_TEMPLATE($row, true, $content);
135                                 $SW = 3 - $SW;
136                         }
137                 }
138                 define('__COUNTRY_ROWS'  , $OUT);
139                 define('__COUNTRY_MODE'  , $post);
140                 define('__COUNTRY_CLASS' , $class);
141                 define('__COUNTRY_SUBMIT', $submit);
142                 define('__COUNTRY_TITLE' , $title);
143                 define('__COUNTRY_RESET' , $reset);
144
145                 // Load main template
146                 LOAD_TEMPLATE("admin_list_country_form");
147         }
148 }
149  else
150 {
151         // Shall we modify / remove entries now?
152         $MSG = ""; $SQLs = array();
153         if ((isset($_POST['modify'])) && (!empty($_POST['id'])))
154         {
155                 // Modify
156                 foreach ($_POST['id'] as $id => $sel)
157                 {
158                         $SQLs[] = "UPDATE "._MYSQL_PREFIX."_countries SET code='".$_POST['code'][$id]."', descr='".$_POST['descr'][$id]."', is_active='".$_POST['is_active'][$id]."' WHERE id='".$id."' LIMIT 1";
159                 }
160
161                 // Create message
162                 $MSG = ADMIN_COUNTRIES_MODIFIED;
163         }
164          elseif ((isset($_POST['remove'])) && (!empty($_POST['id'])))
165         {
166                 // Remove
167                 $IDs = implode(", ", bigintval($_POST['id']));
168                 $SQLs[] = "DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_countries WHERE id IN (".$IDs.") LIMIT ".count($_POST['id'])."";
169
170                 // Create message
171                 $MSG = ADMIN_COUNTRIES_REMOVED;
172         }
173
174         if ((!empty($MSG)) && (count($SQLs) > 0))
175         {
176                 // Run SQL commands
177                 foreach ($SQLs as $sql)
178                 {
179                         $result = SQL_QUERY($sql, __FILE__, __LINE__);
180                 }
181
182                 // Display message
183                 LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
184                 OUTPUT_HTML("<br />");
185         }
186
187         // Load currenty setup country codes to list
188         $result = SQL_QUERY("SELECT id, code, descr, is_active FROM "._MYSQL_PREFIX."_countries ORDER BY code", __FILE__, __LINE__);
189         if (SQL_NUMROWS($result) > 0)
190         {
191                 // List all countries
192                 $OUT = ""; $SW = 2;
193                 while(list($id, $code, $descr, $active) = SQL_FETCHROW($result))
194                 {
195                         // Prepare array for the template
196                         $content = array(
197                                 'id'     => $id,
198                                 'code'   => $code,
199                                 'name'   => $descr,
200                                 'active' => TRANSLATE_YESNO($active),
201                                 'sw'     => $SW,
202                                 'status' => $active,
203                         );
204
205                         // Load row template and switch colors
206                         $OUT .= LOAD_TEMPLATE("admin_list_country_row", true, $content);
207                         $SW = 3 - $SW;
208                 }
209
210                 // Free memory
211                 SQL_FREERESULT($result);
212         }
213          else
214         {
215                 // No code setup so far (not possible by this software! 'DE' for 'Deutschland' is default
216                 $OUT = LOAD_TEMPLATE("admin_list_country_no_row", true);
217         }
218
219         // Add list to constant for the template
220         define('__COUNTRY_ROWS', $OUT);
221
222         // Include add template
223         define('__ADD_COUNTRY_FORM', LOAD_TEMPLATE("admin_add_country", true));
224
225         // Load main template
226         LOAD_TEMPLATE("admin_list_country");
227 }
228
229 //
230 ?>