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