f6af185807b7978fab4f46dca6912330c47205d5
[mailer.git] / inc / modules / admin / what-config_network_types.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 08/13/2011 *
4  * ===================                          Last change: 08/13/2011 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-config_network_types.php                    *
8  * -------------------------------------------------------------------- *
9  * Short description : Handler types configuration                      *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Werbe-Handler-Konfiguration                      *
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 - 2012 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 // By default we should display list/add new forms
47 $GLOBALS['network_display'] = true;
48
49 // Handle form here
50 doNetworkHandleForm();
51
52 // Display forms?
53 if ($GLOBALS['network_display'] === false) {
54         // Abort here
55         return;
56 } // END - if
57
58 // Do we have a network selected?
59 if (isGetRequestElementSet('network_id')) {
60         // Set current network id
61         setCurrentNetworkId(getRequestElement('network_id'));
62
63         // Is a network type handler selected?
64         if (isGetRequestElementSet('network_type_id')) {
65                 // Load data for given network
66                 $result = SQL_QUERY_ESC('SELECT
67         t.`network_id`,
68         t.`network_type_id`,
69         t.`network_type_handler`,
70         t.`network_type_reload_time_unit`,
71         d.`network_active`,
72         NULL AS `network_data_id`,
73         NULL AS `network_max_reload_time`,
74         NULL AS `network_min_waiting_time`,
75         NULL AS `network_min_remain_clicks`,
76         NULL AS `network_min_payment`,
77         NULL AS `network_allow_erotic`
78 FROM
79         `{?_MYSQL_PREFIX?}_network_types` AS t
80 INNER JOIN
81         `{?_MYSQL_PREFIX?}_network_data` AS d
82 ON
83         d.network_id=t.network_id
84 WHERE
85         t.`network_id`=%s AND
86         t.`network_type_id`=%s
87 LIMIT 1',
88                         array(
89                                 bigintval(getRequestElement('network_id')),
90                                 bigintval(getRequestElement('network_type_id'))
91                         ), __FUNCTION__, __LINE__);
92
93                 // Do we have a record?
94                 if (SQL_NUMROWS($result) == 1) {
95                         // Load it
96                         $content = SQL_FETCHARRAY($result);
97
98                         // Is the network active?
99                         if ($content['network_active'] == 'N') {
100                                 // Not active
101                                 displayMessage('{--ADMIN_NETWORK_NOT_ACTIVE--}');
102                                 return;
103                         } // END - if
104
105                         // Check for network type configuration
106                         $result_config = SQL_QUERY_ESC('SELECT
107         `network_data_id`,
108         `network_max_reload_time`,
109         `network_min_waiting_time`,
110         `network_min_remain_clicks`,
111         `network_min_payment`,
112         `network_allow_erotic`
113 FROM
114         `{?_MYSQL_PREFIX?}_network_types_config`
115 WHERE
116         `network_id`=%s AND
117         `network_type_id`=%s
118 LIMIT 1',
119                                 array(
120                                         bigintval(getRequestElement('network_id')),
121                                         bigintval($content['network_type_id'])
122                                 ), __FUNCTION__, __LINE__);
123
124                         // Use template for adding
125                         $templateName = 'admin_add_config_network_type_form';
126
127                         // Do we also have configuration?
128                         if (SQL_NUMROWS($result_config) == 1) {
129                                 // Load as well and merge it
130                                 $content = merge_array($content, SQL_FETCHARRAY($result_config));
131
132                                 // Use template for editing
133                                 $templateName = 'admin_edit_config_network_type_form';
134                         } // END - if
135
136                         // Free result
137                         SQL_FREERESULT($result_config);
138
139                         // "Translate" some values
140                         $content['network_max_reload_time']  = createTimeSelections($content['network_max_reload_time'], 'network_max_reload_time', 'WDhms');
141
142                         // Load template
143                         loadTemplate($templateName, false, $content);
144
145                         // Abort here
146                         return;
147                 } else {
148                         // No entry found
149                         displayMessage('{%message,ADMIN_ADD_CONFIG_NETWORK_HANDLER_TYPE_404=' . bigintval(getRequestElement('network_id')) . '/' . bigintval(getRequestElement('network_type_id')) . '%}');
150                 } // END - if
151
152                 // Free result
153                 SQL_FREERESULT($result);
154         } // END - if
155
156         // Get all type handlers
157         $result = SQL_QUERY_ESC('SELECT
158         `network_id`,
159         `network_type_id`,
160         `network_type_handler`,
161         `network_type_reload_time_unit`
162 FROM
163         `{?_MYSQL_PREFIX?}_network_types`
164 WHERE
165         `network_id`=%s
166 ORDER BY
167         `network_type_handler` ASC',
168                 array(
169                         bigintval(getRequestElement('network_id'))
170                 ), __FUNCTION__, __LINE__);
171
172         // Do we have entries left?
173         if (!SQL_HASZERONUMS($result)) {
174                 // Init row output
175                 $OUT = '';
176
177                 // List all entries
178                 while ($content = SQL_FETCHARRAY($result)) {
179                         // Check if config entry is there
180                         $result_config = SQL_QUERY_ESC('SELECT
181         `network_data_id`,
182         `network_max_reload_time`,
183         `network_min_waiting_time`,
184         `network_min_remain_clicks`,
185         `network_min_payment`,
186         `network_allow_erotic`
187 FROM
188         `{?_MYSQL_PREFIX?}_network_types_config`
189 WHERE
190         `network_id`=%s AND
191         `network_type_id`=%s
192 LIMIT 1',
193                                 array(
194                                         bigintval(getRequestElement('network_id')),
195                                         bigintval($content['network_type_id'])
196                                 ), __FUNCTION__, __LINE__);
197
198                         // Do we have an entry?
199                         if (SQL_NUMROWS($result_config) == 1) {
200                                 // Load this data as well
201                                 $content = merge_array($content, SQL_FETCHARRAY($result_config));
202
203                                 // Add it with extra template
204                                 $content['network_type_config_content'] = loadTemplate('admin_show_config_network_type', true, $content);
205                         } else {
206                                 // No configuration found, so display form
207                                 $content['network_type_config_content'] = loadTemplate('admin_add_config_network_type', true, $content);
208                         }
209
210                         // Free result
211                         SQL_FREERESULT($result_config);
212
213                         // Load row template
214                         $OUT .= loadTemplate('admin_config_network_types_row', true, $content);
215                 } // END - while
216
217                 // Prepare array for main template
218                 $content = array(
219                         'network_id' => bigintval(getRequestElement('network_id')),
220                         'rows'       => $OUT
221                 );
222
223                 // Load main template
224                 loadTemplate('admin_config_network_types', false, $content);
225         } else {
226                 // No entries found
227                 displayMessage('{%message,ADMIN_CONFIG_NETWORK_HANDLER_TYPES_404=' . bigintval(getRequestElement('network_id')) . '%}');
228         }
229
230         // Free result
231         SQL_FREERESULT($result);
232 } else {
233         // Generate network list for this script
234         outputHtml(generateAdminNetworkList());
235 }
236
237 // [EOF]
238 ?>