199a7f4ab85c28e48e6f747f7f11af2d22ededc0
[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 // Is there 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_max_waiting_time`,
76         NULL AS `network_min_remain_budget`,
77         NULL AS `network_min_remain_clicks`,
78         NULL AS `network_min_payment`,
79         NULL AS `network_allow_erotic`,
80         NULL AS `network_media_size`,
81         NULL AS `network_media_output`
82 FROM
83         `{?_MYSQL_PREFIX?}_network_types` AS t
84 INNER JOIN
85         `{?_MYSQL_PREFIX?}_network_data` AS d
86 ON
87         d.network_id=t.network_id
88 WHERE
89         t.`network_id`=%s AND
90         t.`network_type_id`=%s
91 LIMIT 1',
92                         array(
93                                 bigintval(getRequestElement('network_id')),
94                                 bigintval(getRequestElement('network_type_id'))
95                         ), __FUNCTION__, __LINE__);
96
97                 // Is there a record?
98                 if (SQL_NUMROWS($result) == 1) {
99                         // Load it
100                         $content = SQL_FETCHARRAY($result);
101
102                         // Is the network active?
103                         if (($content['network_active'] == 'N') && (!isAdminsExpertWarningEnabled()) && (!isDebugModeEnabled())) {
104                                 // Not active
105                                 displayMessage('{--ADMIN_NETWORK_NOT_ACTIVE--}');
106                                 return;
107                         } // END - if
108
109                         // Check for network type configuration
110                         $result_config = SQL_QUERY_ESC('SELECT
111         `network_data_id`,
112         `network_max_reload_time`,
113         `network_min_waiting_time`,
114         `network_max_waiting_time`,
115         `network_min_remain_budget`,
116         `network_min_remain_clicks`,
117         `network_min_payment`,
118         `network_allow_erotic`,
119         `network_media_size`,
120         `network_media_output`
121 FROM
122         `{?_MYSQL_PREFIX?}_network_handler_config`
123 WHERE
124         `network_id`=%s AND
125         `network_type_id`=%s
126 LIMIT 1',
127                                 array(
128                                         bigintval(getRequestElement('network_id')),
129                                         bigintval($content['network_type_id'])
130                                 ), __FUNCTION__, __LINE__);
131
132                         // Use template for adding
133                         $templateName = 'admin_add_config_network_type_form';
134
135                         // Do we also have configuration?
136                         if (SQL_NUMROWS($result_config) == 1) {
137                                 // Load as well and merge it
138                                 $content = merge_array($content, SQL_FETCHARRAY($result_config));
139
140                                 // Use template for editing
141                                 $templateName = 'admin_edit_config_network_type_form';
142                         } // END - if
143
144                         // Free result
145                         SQL_FREERESULT($result_config);
146
147                         // "Translate" some values
148                         $content['network_max_reload_time']  = createTimeSelections($content['network_max_reload_time'], 'network_max_reload_time', 'WDhms');
149
150                         // Load template
151                         loadTemplate($templateName, FALSE, $content);
152
153                         // Abort here
154                         return;
155                 } else {
156                         // No entry found
157                         displayMessage('{%message,ADMIN_ADD_CONFIG_NETWORK_HANDLER_TYPE_404=' . bigintval(getRequestElement('network_id')) . '/' . bigintval(getRequestElement('network_type_id')) . '%}');
158                 } // END - if
159
160                 // Free result
161                 SQL_FREERESULT($result);
162         } // END - if
163
164         // Get all type handlers
165         $result = SQL_QUERY_ESC('SELECT
166         `network_id`,
167         `network_type_id`,
168         `network_type_handler`,
169         `network_type_reload_time_unit`
170 FROM
171         `{?_MYSQL_PREFIX?}_network_types`
172 WHERE
173         `network_id`=%s
174 ORDER BY
175         `network_type_handler` ASC',
176                 array(
177                         bigintval(getRequestElement('network_id'))
178                 ), __FUNCTION__, __LINE__);
179
180         // Are there entries left?
181         if (!SQL_HASZERONUMS($result)) {
182                 // Init row output
183                 $OUT = '';
184
185                 // List all entries
186                 while ($content = SQL_FETCHARRAY($result)) {
187                         // Check if config entry is there
188                         $result_config = SQL_QUERY_ESC('SELECT
189         `network_data_id`,
190         `network_max_reload_time`,
191         `network_min_waiting_time`,
192         `network_max_waiting_time`,
193         `network_min_remain_budget`,
194         `network_min_remain_clicks`,
195         `network_min_payment`,
196         `network_allow_erotic`,
197         `network_media_size`,
198         `network_media_output`
199 FROM
200         `{?_MYSQL_PREFIX?}_network_handler_config`
201 WHERE
202         `network_id`=%s AND
203         `network_type_id`=%s
204 LIMIT 1',
205                                 array(
206                                         bigintval(getRequestElement('network_id')),
207                                         bigintval($content['network_type_id'])
208                                 ), __FUNCTION__, __LINE__);
209
210                         // Is there an entry?
211                         if (SQL_NUMROWS($result_config) == 1) {
212                                 // Load this data as well
213                                 $content = merge_array($content, SQL_FETCHARRAY($result_config));
214
215                                 // Add it with extra template
216                                 $content['network_type_config_content'] = loadTemplate('admin_show_config_network_type', TRUE, $content);
217                         } else {
218                                 // No configuration found, so display form
219                                 $content['network_type_config_content'] = loadTemplate('admin_add_config_network_type', TRUE, $content);
220                         }
221
222                         // Free result
223                         SQL_FREERESULT($result_config);
224
225                         // Load row template
226                         $OUT .= loadTemplate('admin_config_network_types_row', TRUE, $content);
227                 } // END - while
228
229                 // Prepare array for main template
230                 $content = array(
231                         'network_id' => bigintval(getRequestElement('network_id')),
232                         'rows'       => $OUT
233                 );
234
235                 // Load main template
236                 loadTemplate('admin_config_network_types', FALSE, $content);
237         } else {
238                 // No entries found
239                 displayMessage('{%message,ADMIN_CONFIG_NETWORK_HANDLER_TYPES_404=' . bigintval(getRequestElement('network_id')) . '%}');
240         }
241
242         // Free result
243         SQL_FREERESULT($result);
244 } else {
245         // Generate network list for this script
246         $OUT = generateAdminNetworkList(FALSE, TRUE, FALSE);
247
248         // Is it not empty?
249         if (!empty($OUT)) {
250                 // Output it
251                 outputHtml($OUT);
252         } else {
253                 // Nothing configured yet
254                 displayMessage('{--ADMIN_NETWORK_QUERY_API_404--}');
255         }
256 }
257
258 // [EOF]
259 ?>