A *lot* more code-cleanups, errors in CSS fixed (missing brackets) and frameset suppo...
[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 ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!is_admin()))
36 {
37         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
38         require($INC);
39 }
40
41 // Add description as navigation point
42 ADD_DESCR("admin", basename(__FILE__));
43
44 // Add new code?
45 if ((isset($_POST['add'])) && (!empty($_POST['code'])) && (!empty($_POST['descr'])))
46 {
47         // Check if country code does already exist
48         $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_countries WHERE code='%s' LIMIT 1",
49          array(strtoupper($_POST['code'])), __FILE__, __LINE__);
50         if (SQL_NUMROWS($result) == 0)
51         {
52                 // Save entry
53                 $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_countries (code, descr, is_active)
54  VALUES('%s', '%s', '%s')",
55  array(strtoupper(substr($_POST['code'], 0, 2)), $_POST['descr'], $_POST['is_active']), __FILE__, __LINE__);
56
57                 // Country added
58                 $MSG = ADMIN_COUNTRY_ADDED_1.strtoupper($_POST['descr']).ADMIN_COUNTRY_ADDED_2;
59         }
60          else
61         {
62                 // Free memory
63                 SQL_FREERESULT($result);
64
65                 // Does already exist
66                 $MSG = ADMIN_COUNTRY_ALREADY_1.strtoupper($_POST['code']).ADMIN_COUNTRY_ALREADY_2;
67         }
68
69         // Display message
70         LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
71         OUTPUT_HTML("<br />");
72 }
73 // Change status?
74  elseif ((isset($_POST['change'])) && (!empty($_POST['id'])))
75 {
76         // Change all status
77         ADMIN_CHANGE_ACTIVATION_STATUS($_POST['id'], "countries", "is_active");
78 }
79 // Edit / delete entries?
80  elseif (((isset($_POST['edit'])) || (isset($_POST['delete']))) && (!empty($_POST['id'])))
81 {
82         if (count($_POST['id']) > 0)
83         {
84                 if (isset($_POST['edit']))
85                 {
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                 }
94                  else
95                 {
96                         // Delete template
97                         $row    = "admin_list_country_del_row";
98                         $post   = "remove";
99                         $class  = "admin_delete";
100                         $submit = ADMIN_COUNTRY_DELETE_NOW;
101                         $title  = ADMIN_COUNTRY_DELETE_TITLE;
102                         $reset  = "";
103                 }
104
105                 // Edit all selected country codes
106                 $OUT = ""; $SW = 2;
107                 foreach ($_POST['id'] as $id=>$status)
108                 {
109                         // Load data from DB
110                         $result = SQL_QUERY_ESC("SELECT code, descr FROM "._MYSQL_PREFIX."_countries WHERE id=%d LIMIT 1",
111                          array(bigintval($id)), __FILE__, __LINE__);
112                         if (SQL_NUMROWS($result) == 1)
113                         {
114                                 // Load data
115                                 list($code, $descr) = SQL_FETCHROW($result);
116                                 SQL_FREERESULT($result);
117
118                                 // Prepare data, load row template and switch colors
119                                 $content = array(
120                                         'id'    => $id,
121                                         'code'  => $code,
122                                         'descr' => $descr,
123                                         'sw'    => $SW,
124                                 );
125                                 if ($post == "modify")
126                                 {
127                                         // Generate default selection in edit-mode
128                                         $content['status'] = ADD_OPTION_LINES("/ARRAY/", array('Y', 'N'), array(YES, NO ), $status);
129                                 }
130                                  else
131                                 {
132                                         // Only display status when in delete-mode
133                                         $content['status'] = TRANSLATE_YESNO($status);
134                                 }
135                                 $OUT .= LOAD_TEMPLATE($row, true, $content);
136                                 $SW = 3 - $SW;
137                         }
138                 }
139                 define('__COUNTRY_ROWS'  , $OUT);
140                 define('__COUNTRY_MODE'  , $post);
141                 define('__COUNTRY_CLASS' , $class);
142                 define('__COUNTRY_SUBMIT', $submit);
143                 define('__COUNTRY_TITLE' , $title);
144                 define('__COUNTRY_RESET' , $reset);
145
146                 // Load main template
147                 LOAD_TEMPLATE("admin_list_country_form");
148         }
149 }
150  else
151 {
152         // Shall we modify / remove entries now?
153         $MSG = ""; $SQLs = array();
154         if ((isset($_POST['modify'])) && (!empty($_POST['id'])))
155         {
156                 // Modify
157                 foreach ($_POST['id'] as $id=>$sel)
158                 {
159                         $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";
160                 }
161
162                 // Create message
163                 $MSG = ADMIN_COUNTRIES_MODIFIED;
164         }
165          elseif ((isset($_POST['remove'])) && (!empty($_POST['id'])))
166         {
167                 // Remove
168                 $IDs = implode(", ", bigintval($_POST['id']));
169                 $SQLs[] = "DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_countries WHERE id IN (".$IDs.") LIMIT ".count($_POST['id'])."";
170
171                 // Create message
172                 $MSG = ADMIN_COUNTRIES_REMOVED;
173         }
174
175         if ((!empty($MSG)) && (count($SQLs) > 0))
176         {
177                 // Run SQL commands
178                 foreach ($SQLs as $sql)
179                 {
180                         $result = SQL_QUERY($sql, __FILE__, __LINE__);
181                 }
182
183                 // Display message
184                 LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
185                 OUTPUT_HTML("<br />");
186         }
187
188         // Load currenty setup country codes to list
189         $result = SQL_QUERY("SELECT id, code, descr, is_active FROM "._MYSQL_PREFIX."_countries ORDER BY code", __FILE__, __LINE__);
190         if (SQL_NUMROWS($result) > 0)
191         {
192                 // List all countries
193                 $OUT = ""; $SW = 2;
194                 while(list($id, $code, $descr, $active) = SQL_FETCHROW($result))
195                 {
196                         // Prepare array for the template
197                         $content = array(
198                                 'id'     => $id,
199                                 'code'   => $code,
200                                 'name'   => $descr,
201                                 'active' => TRANSLATE_YESNO($active),
202                                 'sw'     => $SW,
203                                 'status' => $active,
204                         );
205
206                         // Load row template and switch colors
207                         $OUT .= LOAD_TEMPLATE("admin_list_country_row", true, $content);
208                         $SW = 3 - $SW;
209                 }
210
211                 // Free memory
212                 SQL_FREERESULT($result);
213         }
214          else
215         {
216                 // No code setup so far (not possible by this software! 'DE' for 'Deutschland' is default
217                 $OUT = LOAD_TEMPLATE("admin_list_country_no_row", true);
218         }
219
220         // Add list to constant for the template
221         define('__COUNTRY_ROWS', $OUT);
222
223         // Include add template
224         define('__ADD_COUNTRY_FORM', LOAD_TEMPLATE("admin_add_country", true));
225
226         // Load main template
227         LOAD_TEMPLATE("admin_list_country");
228 }
229
230 //
231 ?>