"copied"
[mailer.git] / 0.2.1-FINAL / 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", __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                 SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_countries (code, descr, is_active) VALUES ('%s','%s','%s')",
53  array(strtoupper(substr($_POST['code'], 0, 2)), $_POST['descr'], $_POST['is_active']), __FILE__, __LINE__);
54
55                 // Country added
56                 $MSG = ADMIN_COUNTRY_ADDED_1.strtoupper($_POST['descr']).ADMIN_COUNTRY_ADDED_2;
57         }
58          else
59         {
60                 // Free memory
61                 SQL_FREERESULT($result);
62
63                 // Does already exist
64                 $MSG = ADMIN_COUNTRY_ALREADY_1.strtoupper($_POST['code']).ADMIN_COUNTRY_ALREADY_2;
65         }
66
67         // Display message
68         LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
69         OUTPUT_HTML("<br />");
70 }
71 // Change status?
72  elseif ((isset($_POST['change'])) && (!empty($_POST['id'])))
73 {
74         // Change all status
75         ADMIN_CHANGE_ACTIVATION_STATUS($_POST['id'], "countries", "is_active");
76 }
77 // Edit / delete entries?
78  elseif (((isset($_POST['edit'])) || (isset($_POST['delete']))) && (!empty($_POST['id'])))
79 {
80         if (count($_POST['id']) > 0)
81         {
82                 if (isset($_POST['edit']))
83                 {
84                         // Edit template
85                         $row    = "admin_list_country_edit_row";
86                         $post   = "modify";
87                         $class  = "admin_submit";
88                         $submit = ADMIN_COUNTRY_EDIT_NOW;
89                         $title  = ADMIN_COUNTRY_EDIT_TITLE;
90                         $reset  = "<INPUT type=\"reset\" class=\"admin_reset\" value=\"".UNDO_SELECTIONS."\">&nbsp;*\n";
91                 }
92                  else
93                 {
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 ($_POST['id'] as $id => $status)
106                 {
107                         // Load data from DB
108                         $result = SQL_QUERY_ESC("SELECT code, descr FROM "._MYSQL_PREFIX."_countries WHERE id=%s LIMIT 1",
109                          array(bigintval($id)), __FILE__, __LINE__);
110                         if (SQL_NUMROWS($result) == 1)
111                         {
112                                 // Load data
113                                 list($code, $descr) = SQL_FETCHROW($result);
114                                 SQL_FREERESULT($result);
115
116                                 // Prepare data, load row template and switch colors
117                                 $content = array(
118                                         'id'    => $id,
119                                         'code'  => $code,
120                                         'descr' => $descr,
121                                         'sw'    => $SW,
122                                 );
123                                 if ($post == "modify")
124                                 {
125                                         // Generate default selection in edit-mode
126                                         $content['status'] = ADD_OPTION_LINES("/ARRAY/", array("Y","N"), array(YES, NO ), $status);
127                                 }
128                                  else
129                                 {
130                                         // Only display status when in delete-mode
131                                         $content['status'] = TRANSLATE_YESNO($status);
132                                 }
133                                 $OUT .= LOAD_TEMPLATE($row, true, $content);
134                                 $SW = 3 - $SW;
135                         }
136                 }
137                 define('__COUNTRY_ROWS'  , $OUT);
138                 define('__COUNTRY_MODE'  , $post);
139                 define('__COUNTRY_CLASS' , $class);
140                 define('__COUNTRY_SUBMIT', $submit);
141                 define('__COUNTRY_TITLE' , $title);
142                 define('__COUNTRY_RESET' , $reset);
143
144                 // Load main template
145                 LOAD_TEMPLATE("admin_list_country_form");
146         }
147 }
148  else
149 {
150         // Shall we modify / remove entries now?
151         $MSG = ""; $SQLs = array();
152         if ((isset($_POST['modify'])) && (!empty($_POST['id'])))
153         {
154                 // Modify
155                 foreach ($_POST['id'] as $id => $sel)
156                 {
157                         $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";
158                 }
159
160                 // Create message
161                 $MSG = ADMIN_COUNTRIES_MODIFIED;
162         }
163          elseif ((isset($_POST['remove'])) && (!empty($_POST['id'])))
164         {
165                 // Remove
166                 $IDs = implode(", ", bigintval($_POST['id']));
167                 $SQLs[] = "DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_countries WHERE id IN (".$IDs.") LIMIT ".count($_POST['id'])."";
168
169                 // Create message
170                 $MSG = ADMIN_COUNTRIES_REMOVED;
171         }
172
173         if ((!empty($MSG)) && (count($SQLs) > 0))
174         {
175                 // Run SQL commands
176                 foreach ($SQLs as $sql)
177                 {
178                         $result = SQL_QUERY($sql, __FILE__, __LINE__);
179                 }
180
181                 // Display message
182                 LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
183                 OUTPUT_HTML("<br />");
184         }
185
186         // Load currenty setup country codes to list
187         $result = SQL_QUERY("SELECT id, code, descr, is_active FROM "._MYSQL_PREFIX."_countries ORDER BY code", __FILE__, __LINE__);
188         if (SQL_NUMROWS($result) > 0)
189         {
190                 // List all countries
191                 $OUT = ""; $SW = 2;
192                 while(list($id, $code, $descr, $active) = SQL_FETCHROW($result))
193                 {
194                         // Prepare array for the template
195                         $content = array(
196                                 'id'     => $id,
197                                 'code'   => $code,
198                                 'name'   => $descr,
199                                 'active' => TRANSLATE_YESNO($active),
200                                 'sw'     => $SW,
201                                 'status' => $active,
202                         );
203
204                         // Load row template and switch colors
205                         $OUT .= LOAD_TEMPLATE("admin_list_country_row", true, $content);
206                         $SW = 3 - $SW;
207                 }
208
209                 // Free memory
210                 SQL_FREERESULT($result);
211         }
212          else
213         {
214                 // No code setup so far (not possible by this software! 'DE' for 'Deutschland' is default
215                 $OUT = LOAD_TEMPLATE("admin_list_country_no_row", true);
216         }
217
218         // Add list to constant for the template
219         define('__COUNTRY_ROWS', $OUT);
220
221         // Include add template
222         define('__ADD_COUNTRY_FORM', LOAD_TEMPLATE("admin_add_country", true));
223
224         // Load main template
225         LOAD_TEMPLATE("admin_list_country");
226 }
227
228 //
229 ?>