Extension ext-network continued:
[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 - 2011 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         `network_id`,
68         `network_type_id`,
69         `network_type_handle`,
70         NULL AS `network_data_id`,
71         NULL AS `network_max_reload_time`,
72         NULL AS `network_min_waiting_time`,
73         NULL AS `network_min_remain_clicks`,
74         NULL AS `network_min_payment`,
75         NULL AS `network_allow_erotic`
76 FROM
77         `{?_MYSQL_PREFIX?}_network_types`
78 WHERE
79         `network_id`=%s AND
80         `network_type_id`=%s
81 LIMIT 1',
82                         array(
83                                 bigintval(getRequestElement('network_id')),
84                                 bigintval(getRequestElement('network_type_id'))
85                         ), __FUNCTION__, __LINE__);
86
87                 // Do we have a record?
88                 if (SQL_NUMROWS($result) == 1) {
89                         // Load it
90                         $content = SQL_FETCHARRAY($result);
91
92                         // Check for network type configuration
93                         $result_config = SQL_QUERY_ESC('SELECT
94         `network_data_id`,
95         `network_max_reload_time`,
96         `network_min_waiting_time`
97         `network_min_remain_clicks`,
98         `network_min_payment`,
99         `network_allow_erotic`
100 FROM
101         `{?_MYSQL_PREFIX?}_network_types_config`
102 WHERE
103         `network_id`=%s AND
104         `network_type_id`=%s
105 LIMIT 1',
106                                 array(
107                                         bigintval(getRequestElement('network_id')),
108                                         bigintval($content['network_type_id'])
109                                 ), __FUNCTION__, __LINE__);
110
111                         // Do we also have configuration?
112                         if (SQL_NUMROWS($result_config) == 1) {
113                                 // Load as well and merge it
114                                 $content = merge_array($content, SQL_FETCHARRAY($result_config));
115                         } // END - if
116
117                         // Free result
118                         SQL_FREERESULT($result_config);
119
120                         // "Translate" some values
121                         $content['network_max_reload_time'] = createTimeSelections($content['network_max_reload_time'], 'network_max_reload_time', 'WDhms');
122
123                         // Load template
124                         loadTemplate('admin_add_config_network_type_form', false, $content);
125
126                         // Abort here
127                         return;
128                 } else {
129                         // No entry found
130                         displayMessage('{%message,ADMIN_ADD_CONFIG_NETWORK_TYPE_404', bigintval(getRequestElement('network_id')) . '/' . bigintval(getRequestElement('network_type_id')));
131                 } // END - if
132
133                 // Free result
134                 SQL_FREERESULT($result);
135         } // END - if
136
137         // Get all type handlers
138         $result = SQL_QUERY_ESC('SELECT
139         `network_id`,
140         `network_type_id`,
141         `network_type_handle`
142 FROM
143         `{?_MYSQL_PREFIX?}_network_types`
144 WHERE
145         `network_id`=%s
146 ORDER BY
147         `network_type_handle` ASC',
148                 array(
149                         bigintval(getRequestElement('network_id'))
150                 ), __FUNCTION__, __LINE__);
151
152         // Do we have entries left?
153         if (!SQL_HASZERONUMS($result)) {
154                 // Init row output
155                 $OUT = '';
156
157                 // List all entries
158                 while ($content = SQL_FETCHARRAY($result)) {
159                         // Check if config entry is there
160                         $result_config = SQL_QUERY_ESC('SELECT
161         `network_data_id`,
162         `network_max_reload_time`,
163         `network_min_waiting_time`,
164         `network_min_remain_clicks`,
165         `network_min_payment`,
166         `network_allow_erotic`
167 FROM
168         `{?_MYSQL_PREFIX?}_network_types_config`
169 WHERE
170         `network_id`=%s AND
171         `network_type_id`=%s
172 LIMIT 1',
173                                 array(
174                                         bigintval(getRequestElement('network_id')),
175                                         bigintval($content['network_type_id'])
176                                 ), __FUNCTION__, __LINE__);
177
178                         // Do we have an entry?
179                         if (SQL_NUMROWS($result_config) == 1) {
180                                 // Load this data as well
181                                 $contentConfig = SQL_FETCHARRAY($result_config);
182
183                                 // Add it with extra template
184                                 $content['network_type_config_content'] = loadTemplate('admin_show_config_network_type', true, $contentConfig);
185                         } else {
186                                 // No configuration found, so display form
187                                 $content['network_type_config_content'] = loadTemplate('admin_add_config_network_type', true, $content);
188                         }
189
190                         // Free result
191                         SQL_FREERESULT($result_config);
192
193                         // Load row template
194                         $OUT .= loadTemplate('admin_config_network_types_row', true, $content);
195                 } // END - while
196
197                 // Prepare array for main template
198                 $content = array(
199                         'network_id' => bigintval(getRequestElement('network_id')),
200                         'rows'       => $OUT
201                 );
202
203                 // Load main template
204                 loadTemplate('admin_config_network_types', false, $content);
205         } else {
206                 // No entries found
207                 displayMessage('{%message,ADMIN_CONFIG_NETWORK_TYPES_404=' . bigintval(getRequestElement('network_id')) . '%}');
208         }
209
210         // Free result
211         SQL_FREERESULT($result);
212 } else {
213         // Generate network list for this script
214         outputHtml(generateAdminNetworkList());
215 }
216
217 // [EOF]
218 ?>