Extension ext-network continued:
[mailer.git] / inc / libs / network_functions.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 11/04/2009 *
4  * ===================                          Last change: 11/04/2009 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : network_functions.php                            *
8  * -------------------------------------------------------------------- *
9  * Short description : Functions for ext-network                        *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Funktionen fuer ext-network                      *
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')) {
40         die();
41 } // END - if
42
43 // Private setter for current network id
44 function setCurrentNetworkId ($networkId) {
45         $GLOBALS['current_network_id'] = bigintval($networkId);
46 }
47
48 // Private getter for current network id
49 function getCurrentNetworkId () {
50         return $GLOBALS['current_network_id'];
51 }
52
53 // Detects if a supported form has been sent
54 function detectNetworkProcessForm () {
55         // 'do' must be provided in URL
56         if (!isGetRequestElementSet('do')) {
57                 // Not provided!
58                 debug_report_bug(__FUNCTION__, __LINE__, 'No "do" has been provided. Please fix your templates.');
59         } // END - if
60
61         // Default is invalid
62         $GLOBALS['network_form_name'] = 'invalid';
63
64         // Now search all valid
65         foreach (array('ok', 'edit', 'delete', 'do_edit', 'do_delete') as $form) {
66                 // Is it detected
67                 if (isFormSent($form)) {
68                         // Use this form name
69                         $GLOBALS['network_form_name'] = $form;
70
71                         // Abort loop
72                         break;
73                 } // END - if
74         } // END - foreach
75
76         // Has the form being detected?
77         if ($GLOBALS['network_form_name'] == 'invalid') {
78                 // Not supported
79                 debug_report_bug(__FUNCTION__, __LINE__, 'POST form could not be detected.');
80         } // END - if
81 }
82
83 // Handle a (maybe) sent form here
84 function doNetworkHandleForm () {
85         // Do we have a form sent?
86         if (countRequestPost() > 0) {
87                 // Detect sent POST form
88                 detectNetworkProcessForm();
89         } elseif (!isGetRequestElementSet('do')) {
90                 // Skip any further requests
91                 return;
92         }
93
94         // Process the request
95         doAdminNetworkProcessForm();
96 }
97
98 // Processes an admin form
99 function doAdminNetworkProcessForm () {
100         // Create function name
101         $functionName = sprintf("doAdminNetworkProcess%s", capitalizeUnderscoreString(getRequestElement('do')));
102
103         // Is the function valid?
104         if (!function_exists($functionName)) {
105                 // Invalid function name
106                 debug_report_bug(__FUNCTION__, __LINE__, 'Invalid do ' . getRequestElement('do') . ', function ' . $functionName .' does not exist.', false);
107         } // END - if
108
109         // Init global arrays
110         $GLOBALS['network_types_disabled'] = array();
111
112         // Call-back the method handling our request
113         call_user_func($functionName);
114 }
115
116 // Checks wether the (short) network name is already used (valid)
117 function isNetworkNameValid ($name) {
118         // Query for it
119         $result = SQL_QUERY_ESC("SELECT `network_id` FROM `{?_MYSQL_PREFIX?}_network_data` WHERE `network_short_name`='%s' LIMIT 1",
120                 array($name), __FUNCTION__, __LINE__);
121
122         // Does it exist?
123         $isValid = (SQL_NUMROWS($result) == 1);
124
125         // Free result
126         SQL_FREERESULT($result);
127
128         // Return result
129         return $isValid;
130 }
131
132 // Checks wether the given network type is already used (valid)
133 function isNetworkTypeHandleValid ($type, $networkId) {
134         // Query for it
135         $result = SQL_QUERY_ESC("SELECT `network_type_id` FROM `{?_MYSQL_PREFIX?}_network_types` WHERE `network_id`=%s AND `network_type_handler`='%s' LIMIT 1",
136                 array(
137                         $networkId,
138                         $type
139                 ), __FUNCTION__, __LINE__);
140
141         // Does it exist?
142         $isValid = (SQL_NUMROWS($result) == 1);
143
144         // Free result
145         SQL_FREERESULT($result);
146
147         // Return result
148         return $isValid;
149 }
150
151 // Checks wether the given network request parameter is already used (valid)
152 function isNetworkRequestElementValid ($key, $type, $networkId) {
153         // Query for it
154         $result = SQL_QUERY_ESC("SELECT `network_request_param_id` FROM `{?_MYSQL_PREFIX?}_network_request_params` WHERE `network_id`=%s AND `network_type_id`=%s AND `network_request_param_key`='%s' LIMIT 1",
155                 array(
156                         $networkId,
157                         $type,
158                         $key
159                 ), __FUNCTION__, __LINE__);
160
161         // Does it exist?
162         $isValid = (SQL_NUMROWS($result) == 1);
163
164         // Free result
165         SQL_FREERESULT($result);
166
167         // Return result
168         return $isValid;
169 }
170
171 // Checks wether the given network API array translation
172 function isNetworkArrayTranslationValid ($key, $type, $networkId) {
173         // Query for it
174         $result = SQL_QUERY_ESC("SELECT `network_array_id` FROM `{?_MYSQL_PREFIX?}_network_array_translation` WHERE `network_id`=%s AND `network_type_id`=%s AND `network_array_index`='%s' LIMIT 1",
175                 array(
176                         $networkId,
177                         $type,
178                         $key
179                 ), __FUNCTION__, __LINE__);
180
181         // Does it exist?
182         $isValid = (SQL_NUMROWS($result) == 1);
183
184         // Free result
185         SQL_FREERESULT($result);
186
187         // Return result
188         return $isValid;
189 }
190
191 // "Getter" for a network's data by provided id number
192 function getNetworkDataById ($networkId, $column = '') {
193         // Ids lower one are not accepted
194         if ($networkId < 1) {
195                 // Not good, should be fixed
196                 debug_report_bug(__FUNCTION__, __LINE__, 'Network id ' . $networkId . ' is smaller than 1.');
197         } // END - if
198
199         // Set current network id
200         setCurrentNetworkId($networkId);
201
202         // Is it cached?
203         if (!isset($GLOBALS['network_data'][$networkId])) {
204                 // By default we have no data
205                 $GLOBALS['network_data'][$networkId] = array();
206
207                 // Query for the network data
208                 $result = SQL_QUERY_ESC("SELECT
209         `network_id`,
210         `network_short_name`,
211         `network_title`,
212         `network_reflink`,
213         `network_data_separator`,
214         `network_row_separator`,
215         `network_request_type`,
216         `network_charset`,
217         `network_require_id_card`,
218         `network_query_amount`
219 FROM
220         `{?_MYSQL_PREFIX?}_network_data`
221 WHERE
222         `network_id`=%s
223 LIMIT 1",
224                         array(bigintval($networkId)), __FUNCTION__, __LINE__);
225
226                 // Do we have an entry?
227                 if (SQL_NUMROWS($result) == 1) {
228                         // Then get it
229                         $GLOBALS['network_data'][$networkId] = SQL_FETCHARRAY($result);
230                 } // END - if
231
232                 // Free result
233                 SQL_FREERESULT($result);
234         } // END - if
235
236         // Return result
237         if (empty($column)) {
238                 // Return array
239                 return $GLOBALS['network_data'][$networkId];
240         } else {
241                 // Return column
242                 return $GLOBALS['network_data'][$networkId][$column];
243         }
244 }
245
246 // "Getter" for a network's data by provided type id number
247 function getNetworkDataByTypeId ($networkId, $column = '') {
248         // Ids lower one are not accepted
249         if ($networkId < 1) {
250                 // Not good, should be fixed
251                 debug_report_bug(__FUNCTION__, __LINE__, 'Network type id ' . $networkId . ' is smaller than 1.');
252         } // END - if
253
254         // Set current network id
255         setCurrentNetworkId($networkId);
256
257         // Is it cached?
258         if (!isset($GLOBALS['network_data'][$networkId])) {
259                 // By default we have no data
260                 $GLOBALS['network_data'][$networkId] = array();
261
262                 // Query for the network data
263                 $result = SQL_QUERY_ESC("SELECT
264         d.`network_id`,
265         d.`network_short_name`,
266         d.`network_title`,
267         d.`network_reflink`,
268         d.`network_data_separator`,
269         d.`network_row_separator`,
270         d.`network_request_type`,
271         d.`network_charset`,
272         d.`network_require_id_card`,
273         d.`network_query_amount`,
274         t.`network_type_handler`,
275         t.`network_type_api_url`,
276         t.`network_type_click_url`,
277         t.`network_type_banner_url`
278 FROM
279         `{?_MYSQL_PREFIX?}_network_data` AS d
280 LEFT JOIN
281         `{?_MYSQL_PREFIX?}_network_types` AS t
282 ON
283         d.`network_id`=t.`network_id`
284 WHERE
285         t.`network_type_id`=%s
286 LIMIT 1",
287                         array(bigintval($networkId)), __FUNCTION__, __LINE__);
288
289                 // Do we have an entry?
290                 if (SQL_NUMROWS($result) == 1) {
291                         // Then get it
292                         $GLOBALS['network_data'][$networkId] = SQL_FETCHARRAY($result);
293                 } // END - if
294
295                 // Free result
296                 SQL_FREERESULT($result);
297         } // END - if
298
299         // Return result
300         if (empty($column)) {
301                 // Return array
302                 return $GLOBALS['network_data'][$networkId];
303         } else {
304                 // Return column
305                 return $GLOBALS['network_data'][$networkId][$column];
306         }
307 }
308
309 // "Getter" for a network type data by provided id number
310 function getNetworkTypeDataById ($networkId) {
311         // Ids lower one are not accepted
312         if ($networkId < 1) {
313                 // Not good, should be fixed
314                 debug_report_bug(__FUNCTION__, __LINE__, 'Network type id ' . $networkId . ' is smaller than 1.');
315         } // END - if
316
317         // By default we have no data
318         $GLOBALS['network_type_data'][$networkId] = array();
319
320         // Query for the network data
321         $result = SQL_QUERY_ESC('SELECT
322         `network_type_id`,
323         `network_id`,
324         `network_type_handler`,
325         `network_type_api_url`,
326         `network_type_click_url`,
327         `network_type_banner_url`
328 FROM
329         `{?_MYSQL_PREFIX?}_network_types`
330 WHERE
331         `network_type_id`=%s
332 LIMIT 1',
333                 array(bigintval($networkId)), __FUNCTION__, __LINE__);
334
335         // Do we have an entry?
336         if (SQL_NUMROWS($result) == 1) {
337                 // Then get it
338                 $GLOBALS['network_type_data'][$networkId] = SQL_FETCHARRAY($result);
339         } // END - if
340
341         // Free result
342         SQL_FREERESULT($result);
343
344         // Return result
345         return $GLOBALS['network_type_data'][$networkId];
346 }
347
348 // "Getter" for a network request parameter data by provided id number
349 function getNetworkRequestParamsDataById ($networkId) {
350         // Ids lower one are not accepted
351         if ($networkId < 1) {
352                 // Not good, should be fixed
353                 debug_report_bug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $networkId . ' is smaller than 1.');
354         } // END - if
355
356         // By default we have no data
357         $networkRequestData = array();
358
359         // Query for the network data
360         $result = SQL_QUERY_ESC('SELECT
361         `network_request_param_id`,
362         `network_id`,
363         `network_type_id`,
364         `network_request_param_key`,
365         `network_request_param_value`,
366         `network_request_param_default`
367 FROM
368         `{?_MYSQL_PREFIX?}_network_request_params`
369 WHERE
370         `network_request_param_id`=%s
371 LIMIT 1',
372                 array(bigintval($networkId)), __FUNCTION__, __LINE__);
373
374         // Do we have an entry?
375         if (SQL_NUMROWS($result) == 1) {
376                 // Then get it
377                 $networkRequestData = SQL_FETCHARRAY($result);
378         } // END - if
379
380         // Free result
381         SQL_FREERESULT($result);
382
383         // Return result
384         return $networkRequestData;
385 }
386
387 // Updates given network (id) with data from array
388 function doNetworkUpdateDataByArray ($networkId, $networkData) {
389         // Ids lower one are not accepted
390         if ($networkId < 1) {
391                 // Not good, should be fixed
392                 debug_report_bug(__FUNCTION__, __LINE__, 'Network id ' . $networkId . ' is smaller than 1.');
393         } // END - if
394
395         // Just call our inner method
396         return adminSaveSettings($networkData, '_network_data', sprintf("`network_id`=%s", bigintval($networkId)), array(), false, false);
397 }
398
399 // Updates given network type handler (id) with data from array
400 function doNetworkUpdateTypeByArray ($networkId, $networkTypeData) {
401         // Ids lower one are not accepted
402         if ($networkId < 1) {
403                 // Not good, should be fixed
404                 debug_report_bug(__FUNCTION__, __LINE__, 'Network type handler id ' . $networkId . ' is smaller than 1.');
405         } // END - if
406
407         // Just call our inner method
408         return adminSaveSettings($networkTypeData, '_network_types', sprintf("`network_type_id`=%s", bigintval($networkId)), array(), false, false);
409 }
410
411 // Updates given network request parameters (id) with data from array
412 function doNetworkUpdateParamsByArray ($networkId, $networkParamData) {
413         // Ids lower one are not accepted
414         if ($networkId < 1) {
415                 // Not good, should be fixed
416                 debug_report_bug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $networkId . ' is smaller than 1.');
417         } // END - if
418
419         // Just call our inner method
420         return adminSaveSettings($networkParamData, '_network_request_params', sprintf("`network_request_param_id`=%s", bigintval($networkId)), array(), false, false);
421 }
422
423 // Removes given network entry
424 function doAdminRemoveNetworkEntry ($table, $column, $networkId, $limit = 1) {
425         // Remove the entry
426         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_network_%s` WHERE `%s`=%s LIMIT %s",
427                 array(
428                         $table,
429                         $column,
430                         $networkId,
431                         $limit
432                 ), __FUNCTION__, __LINE__);
433
434         // Return affected rows
435         return SQL_AFFECTEDROWS();
436 }
437
438 // Generates a list of networks for given script and returns it
439 function generateAdminNetworkList () {
440         // Init output
441         $content = '';
442
443         // Query for all networks
444         $result = SQL_QUERY("SELECT
445         `network_id`,
446         `network_short_name`,
447         `network_title`
448 FROM
449         `{?_MYSQL_PREFIX?}_network_data`
450 WHERE
451         `network_active`='Y'
452 ORDER BY
453         `network_short_name` ASC", __FUNCTION__, __LINE__);
454
455         // Do we have entries?
456         if (!SQL_HASZERONUMS($result)) {
457                 // List all entries
458                 $rows = array();
459                 while ($row = SQL_FETCHARRAY($result)) {
460                         // Is this valid, then add it
461                         if ((is_array($row)) && (isset($row['network_id']))) {
462                                 // Add entry
463                                 $rows[$row['network_id']] = $row;
464                         } // END - if
465                 } // END - while
466
467                 // Generate the selection box
468                 $content = generateSelectionBoxFromArray($rows, 'network_id', 'network_id', '', '', 'network');
469         } else {
470                 // Nothing selected
471                 $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}');
472         }
473
474         // Free the result
475         SQL_FREERESULT($result);
476
477         // Return the list
478         return $content;
479 }
480
481 // Generator (somewhat getter) for a list of network types for given network id
482 function generateAdminNetworkTypeList ($networkId) {
483         // Init content
484         $content = '';
485
486         // Query all types of this network
487         $result = SQL_QUERY_ESC('SELECT
488         `network_type_id`,
489         `network_type_handler`
490 FROM
491         `{?_MYSQL_PREFIX?}_network_types`
492 WHERE
493         `network_id`=%s
494 ORDER BY
495         `network_type_handler` ASC',
496                 array(
497                         bigintval($networkId)
498                 ), __FUNCTION__, __LINE__);
499
500         // Do we have entries?
501         if (!SQL_HASZERONUMS($result)) {
502                 // List all entries
503                 $rows = array();
504                 while ($row = SQL_FETCHARRAY($result)) {
505                         // Is this valid, then add it
506                         if ((is_array($row)) && (isset($row['network_type_id']))) {
507                                 // Add entry
508                                 $rows[$row['network_type_id']] = $row;
509                         } // END - if
510                 } // END - while
511
512                 // Generate the selection box
513                 $content = generateSelectionBoxFromArray($rows, 'network_type', 'network_type_id');
514         } else {
515                 // Nothing selected
516                 $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}');
517         }
518
519         // Free the result
520         SQL_FREERESULT($result);
521
522         // Return content
523         return $content;
524 }
525
526 // Generator (somewhat getter) for a list of network types for all types
527 function generateAdminDistinctNetworkTypeList () {
528         // Init content
529         $content = '';
530
531         // Query all types of this network
532         $result = SQL_QUERY("SELECT
533         t.`network_type_id`,
534         t.`network_type_handler`,
535         d.`network_title`
536 FROM
537         `{?_MYSQL_PREFIX?}_network_types` AS t
538 LEFT JOIN
539         `{?_MYSQL_PREFIX?}_network_data` AS d
540 ON
541         t.`network_id`=d.`network_id`
542 WHERE
543         d.`network_active`='Y'
544 ORDER BY
545         d.`network_short_name` ASC,
546         t.`network_type_handler` ASC", __FUNCTION__, __LINE__);
547
548         // Do we have entries?
549         if (!SQL_HASZERONUMS($result)) {
550                 // List all entries
551                 $rows = array();
552                 while ($row = SQL_FETCHARRAY($result)) {
553                         // Is this valid, then add it
554                         if ((is_array($row)) && (isset($row['network_type_id']))) {
555                                 // Add entry
556                                 $rows[$row['network_type_id']] = $row;
557                         } // END - if
558                 } // END - while
559
560                 // Generate the selection box
561                 $content = generateSelectionBoxFromArray($rows, 'network_type', 'network_type_id', '', '_title');
562         } else {
563                 // Nothing selected
564                 $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}');
565         }
566
567         // Free the result
568         SQL_FREERESULT($result);
569         //* DEBUG: */ die('<pre>'.encodeEntities($content).'</pre>');
570
571         // Return content
572         return $content;
573 }
574
575 // Generator (somewhat getter) for network type options
576 function generateNetworkTypeOptions ($networkId) {
577         // Is this an array, then we just came back from edit/delete actions
578         if (is_array($networkId)) {
579                 $networkId = '';
580         } // END - if
581
582         // Is this cached?
583         if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
584                 // Generate output and cache it
585                 $GLOBALS[__FUNCTION__][$networkId] = generateOptionList(
586                         'network_types',
587                         'network_type_id',
588                         'network_type_handler',
589                         $networkId,
590                         '',
591                         sprintf(
592                                 "WHERE `network_id`=%s",
593                                 bigintval(getRequestElement('network_id'))
594                         ),
595                         '',
596                         'translateNetworkTypeHandler'
597                 );
598         } // END - if
599
600         // Return content
601         return $GLOBALS[__FUNCTION__][$networkId];
602 }
603
604 // Generates an options list of all available (hard-coded) handlers
605 function generateNetworkTypesAvailableOptions ($defaultType = NULL) {
606         // Is it cached?
607         if (!isset($GLOBALS[__FUNCTION__][$defaultType])) {
608                 // Generate list
609                 $GLOBALS[__FUNCTION__][$defaultType] = generateOptionList(
610                         '/ARRAY/',
611                         array(
612                                 'banner',
613                                 'banner_click',
614                                 'banner_view',
615                                 'button',
616                                 'button_click',
617                                 'button_view',
618                                 'surfbar',
619                                 'surfbar_click',
620                                 'surfbar_view',
621                                 'forcedbanner',
622                                 'forcedtextlink',
623                                 'textlink',
624                                 'textlink_click',
625                                 'textlink_view',
626                                 'skybanner',
627                                 'skybanner_click',
628                                 'skybanner_view',
629                                 'layer',
630                                 'layer_click',
631                                 'layer_view',
632                                 'popup',
633                                 'popdown',
634                                 'textmail',
635                                 'htmlmail',
636                                 'lead',
637                                 'sale',
638                                 'payperactive',
639                                 'pagepeel',
640                                 'traffic'
641                         ),
642                         array(),
643                         $defaultType,
644                         '', '',
645                         $GLOBALS['network_types_disabled'],
646                         'translateNetworkTypeHandler'
647                 );
648         } // END - if
649
650         // Return content
651         return $GLOBALS[__FUNCTION__][$defaultType];
652 }
653
654 // Generates an options list (somewhat getter) ofr request keys
655 function generateNetworkRequestKeyOptions () {
656         // Is it cached?
657         if (!isset($GLOBALS[__FUNCTION__])) {
658                 // Generate and cache it
659                 $GLOBALS[__FUNCTION__] = generateOptionList(
660                         '/ARRAY/',
661                         array(
662                                 'id',
663                                 'sid',
664                                 'hash',
665                                 'password',
666                                 'reload',
667                                 'maximum_stay',
668                                 'minimum_stay',
669                                 'currency',
670                                 'type',
671                                 'remain',
672                                 'reward',
673                                 'size',
674                                 'erotic',
675                                 'extra',
676                                 'country'
677                         ),
678                         array(),
679                         '',
680                         '', '',
681                         $GLOBALS['network_request_params_disabled'],
682                         'translateNetworkRequestParamKey'
683                 );
684         } // END - if
685
686         // Return content
687         return $GLOBALS[__FUNCTION__];
688 }
689
690 // Generator (somewhat getter) for (return) array translation
691 function generateNetworkTranslationOptions ($default = '') {
692         // Is it cached?
693         if (!isset($GLOBALS[__FUNCTION__][$default])) {
694                 // Generate and cache it
695                 $GLOBALS[__FUNCTION__][$default] = generateOptionList(
696                         'network_translations',
697                         'network_translation_id',
698                         'network_translation_name',
699                         $default,
700                         '',
701                         '',
702                         $GLOBALS['network_translation_disabled'],
703                         'translateNetworkTranslationName'
704                 );
705         } // END - if
706
707         // Return content
708         return $GLOBALS[__FUNCTION__][$default];
709 }
710
711 // Generates an option list of request types
712 function generateNetworkRequestTypeOptions ($default = '') {
713         // Do we have cache?
714         if (!isset($GLOBALS[__FUNCTION__][$default])) {
715                 // Generate the list
716                 $GLOBALS[__FUNCTION__][$default] = generateOptionList(
717                         '/ARRAY/',
718                         array(
719                                 'GET',
720                                 'POST'
721                         ),
722                         array(
723                                 '{--ADMIN_NETWORK_REQUEST_TYPE_GET--}',
724                                 '{--ADMIN_NETWORK_REQUEST_TYPE_POST--}'
725                         ),
726                         $default
727                 );
728         } // END - if
729
730         // Return cache
731         return $GLOBALS[__FUNCTION__][$default];
732 }
733
734 // Generates an option list of network_api_active
735 function generateNetworkApiActiveOptions ($default = '') {
736         // Do we have cache?
737         if (!isset($GLOBALS[__FUNCTION__][$default])) {
738                 // Generate the list
739                 $GLOBALS[__FUNCTION__][$default] = generateYesNoOptionList($default);
740         } // END - if
741
742         // Return cache
743         return $GLOBALS[__FUNCTION__][$default];
744 }
745
746 // Translates 'translate_name' for e.g. templates
747 function translateNetworkTranslationName ($name) {
748         // Generate id
749         $messageId = 'ADMIN_NETWORK_TRANSLATE_' . strtoupper($name) . '_NAME';
750
751         // Is the message id there?
752         if (!isMessageIdValid($messageId)) {
753                 // Not valid type
754                 debug_report_bug(__FUNCTION__, __LINE__, 'type=' . $type . ' is invalid.');
755         } // END - if
756
757         // Return message id
758         return '{--' . $messageId . '--}';
759 }
760
761 // Translates the network type handler (e.g. banner, paidmail) for templates
762 function translateNetworkTypeHandler ($type) {
763         // Generate id
764         $messageId = 'ADMIN_NETWORK_TYPE_HANDLER_' . strtoupper($type);
765
766         // Is the message id there?
767         if (!isMessageIdValid($messageId)) {
768                 // Not valid type
769                 debug_report_bug(__FUNCTION__, __LINE__, 'type=' . $type . ' is invalid.');
770         } // END - if
771
772         // Return message id
773         return '{--' . $messageId . '--}';
774 }
775
776 // Translates request type
777 function translateNetworkRequestType ($type) {
778         // Generate id
779         $messageId = 'ADMIN_NETWORK_REQUEST_TYPE_' . strtoupper($type) . '';
780
781         // Is the message id there?
782         if (!isMessageIdValid($messageId)) {
783                 // Not valid type
784                 debug_report_bug(__FUNCTION__, __LINE__, 'type=' . $type . ' is invalid.');
785         } // END - if
786
787         // Return message id
788         return '{--' . $messageId . '--}';
789 }
790
791 // Translates request parameter
792 function translateNetworkRequestParamKey ($param) {
793         // Generate id
794         $messageId = 'ADMIN_NETWORK_REQUEST_PARAMETER_' . strtoupper($param) . '';
795
796         // Is the message id there?
797         if (!isMessageIdValid($messageId)) {
798                 // Not valid param
799                 debug_report_bug(__FUNCTION__, __LINE__, 'param=' . $param . ' is invalid.');
800         } // END - if
801
802         // Return message id
803         return '{--' . $messageId . '--}';
804 }
805
806 // Translates API index
807 function translateNetworkApiIndex ($index) {
808         // Do we have cache?
809         if (!isset($GLOBALS['network_array_index'])) {
810                 // Get an array of all API array indexes
811                 $GLOBALS['network_array_index'] = array();
812
813                 // Get all entries
814                 $result = SQL_QUERY('SELECT
815         `network_array_id`,
816         `network_array_index`,
817         `network_translation_name`
818 FROM
819         `{?_MYSQL_PREFIX?}_network_array_translation`
820 INNER JOIN
821         `{?_MYSQL_PREFIX?}_network_translations`
822 ON
823         `network_array_index`=`network_translation_id`
824 ORDER BY
825         `sort` ASC', __FUNCTION__, __LINE__);
826
827                 // Do we have entries?
828                 if (!SQL_HASZERONUMS($result)) {
829                         // Get all entries
830                         while ($row = SQL_FETCHARRAY($result)) {
831                                 // Add it to our global array
832                                 $GLOBALS['network_array_index'][$row['network_array_index']] = $row;
833                         } // END - while
834                 } // END - if
835
836                 // Free result
837                 SQL_FREERESULT($result);
838         } // END - if
839
840         // Default name is unknown
841         $name = 'unknown';
842
843         // Is the entry there?
844         if (isset($GLOBALS['network_array_index'][$index])) {
845                 // Then get the name
846                 $name = $GLOBALS['network_array_index'][$index]['network_translation_name'];
847         } // END - if
848
849         // Return translation
850         return translateNetworkTranslationName($name);
851 }
852
853 // Translates network API configuration status (see function isNetworkApiConfigured()) by given id
854 function translateNetworkApiConfiguredStatusById ($networkId) {
855         // Do we have cache?
856         if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
857                 // By default it is not configured
858                 $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_NOT_CONFIGURED--}';
859
860                 // So is it configured?
861                 if (isNetworkApiConfigured($networkId)) {
862                         // Yes, it is
863                         $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_CONFIGURED--}';
864                 } // END - if
865         } // END - if
866
867         // Return cache
868         return $GLOBALS[__FUNCTION__][$networkId];
869 }
870
871 // Checks if the given network is configured by looking its API configuration entry up
872 function isNetworkApiConfigured ($networkId) {
873         // Do we have cache?
874         if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
875                 // Check for an entry in network_api_config
876                 $GLOBALS[__FUNCTION__][$networkId] = (countSumTotalData(
877                         bigintval($networkId),
878                         'network_api_config',
879                         'network_id',
880                         'network_id',
881                         true
882                 ) == 1);
883         } // END - if
884
885         // Return cache
886         return $GLOBALS[__FUNCTION__][$networkId];
887 }
888
889 // Checks wether the given network type handler is configured
890 function isNetworkTypeHandlerConfigured ($networkId, $networkTypeId) {
891         // Do we have cache?
892         if (!isset($GLOBALS[__FUNCTION__][$networkId][$networkTypeId])) {
893                 // Determine it
894                 $GLOBALS[__FUNCTION__][$networkId][$networkTypeId] = (countSumTotalData(
895                         bigintval($networkTypeId),
896                         'network_types_config',
897                         'network_data_id',
898                         'network_type_id',
899                         true,
900                         sprintf(' AND `network_id`=%s', bigintval($networkId))
901                 ) == 1);
902         } // END - if
903
904         // Return cache
905         return $GLOBALS[__FUNCTION__][$networkId][$networkTypeId];
906 }
907
908 //------------------------------------------------------------------------------
909 //                             Call-back functions
910 //------------------------------------------------------------------------------
911
912 // Callback function to add new network
913 function doAdminNetworkProcessAddNetwork () {
914         // We can say here, the form is sent, so check if the network is already added
915         if (isNetworkNameValid(postRequestElement('network_short_name'))) {
916                 // Already there
917                 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_ALREADY_ADDED=' . postRequestElement('network_short_name') . '%}');
918                 return false;
919         } // END - if
920
921         // Remove the 'ok' part
922         unsetPostRequestElement('ok');
923
924         // Add the whole request to database
925         SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_data'), __FUNCTION__, __LINE__);
926
927         // Add the id for output only
928         setPostRequestElement('network_id', SQL_INSERTID());
929
930         // Output message
931         if (!SQL_HASZEROAFFECTED()) {
932                 // Successfully added
933                 loadTemplate('admin_network_added', false, postRequestArray());
934         } else {
935                 // Not added
936                 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_DATA_NOT_ADDED=' . postRequestElement('network_short_name') . '%}');
937         }
938 }
939
940 // Displays selected networks for editing
941 function doAdminNetworkProcessHandleNetworks () {
942         // Do we have selections?
943         if (ifPostContainsSelections()) {
944                 // Something has been selected, so start displaying one by one
945                 $OUT = '';
946                 foreach (postRequestElement('sel') as $networkId => $sel) {
947                         // Is this selected?
948                         if ($sel == 1) {
949                                 // Load this network's data
950                                 $networkData = getNetworkDataById($networkId);
951
952                                 // Do we have found the network?
953                                 if (count($networkData) > 0) {
954                                         // Add row template with given form name
955                                         $OUT .= loadTemplate('admin_' . $GLOBALS['network_form_name'] . '_networks_row', true, $networkData);
956                                 } // END - if
957                         } // END - if
958                 } // END - foreach
959
960                 // If we have no rows, we don't need to display the edit form
961                 if (!empty($OUT)) {
962                         // Output main template
963                         loadTemplate('admin_' . $GLOBALS['network_form_name'] . '_networks', false, $OUT);
964
965                         // Don't display the list/add new form
966                         $GLOBALS['network_display'] = false;
967                 } else {
968                         // Nothing selected/found
969                         loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_FOUND--}');
970                 }
971         } // END - if
972 }
973
974 // Handle network type form
975 function doAdminNetworkProcessHandleNetworkTypes () {
976         // Do we have selections?
977         if (ifPostContainsSelections()) {
978                 // Load network data
979                 $networkData = getNetworkDataById(getRequestElement('network_id'));
980
981                 // Something has been selected, so start displaying one by one
982                 $OUT = '';
983                 foreach (postRequestElement('sel') as $networkId => $sel) {
984                         // Is this selected?
985                         if ($sel == 1) {
986                                 // Load this network's data
987                                 $networkTypeData = getNetworkTypeDataById($networkId);
988
989                                 // Do we have found the network?
990                                 if (count($networkTypeData) > 0) {
991                                         if (isFormSent('edit')) {
992                                                 // Add row template for deleting
993                                                 $OUT .= loadTemplate('admin_edit_network_types_row', true, $networkTypeData);
994                                         } elseif (isFormSent('delete')) {
995                                                 // Add row template for deleting
996                                                 $OUT .= loadTemplate('admin_delete_network_types_row', true, $networkTypeData);
997                                         } else {
998                                                 // Problem!
999                                                 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
1000                                         }
1001                                 } // END - if
1002                         } // END - if
1003                 } // END - foreach
1004
1005                 // If we have no rows, we don't need to display the edit form
1006                 if (!empty($OUT)) {
1007                         // Output main template
1008                         if (isFormSent('edit')) {
1009                                 loadTemplate('admin_edit_network_types', false, $OUT);
1010                         } elseif (isFormSent('delete')) {
1011                                 loadTemplate('admin_delete_network_types', false, $OUT);
1012                         } else {
1013                                 // Problem!
1014                                 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
1015                         }
1016
1017                         // Don't display the list/add new form
1018                         $GLOBALS['network_display'] = false;
1019                 } else {
1020                         // Nothing selected/found
1021                         loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPE_HANDLER_NOTHING_FOUND--}');
1022                 }
1023         } // END - if
1024 }
1025
1026 // Handle network request parameter form
1027 function doAdminNetworkProcessHandleRequestParams () {
1028         // Do we have selections?
1029         if (ifPostContainsSelections()) {
1030                 // Init cache array
1031                 $GLOBALS['network_request_params_disabled'] = array();
1032
1033                 // Load network data
1034                 $networkData = getNetworkDataById(getRequestElement('network_id'));
1035
1036                 // Something has been selected, so start displaying one by one
1037                 $OUT = '';
1038                 foreach (postRequestElement('sel') as $networkId => $sel) {
1039                         // Is this selected?
1040                         if ($sel == 1) {
1041                                 // Load this network's data
1042                                 $networkRequestData = getNetworkRequestParamsDataById($networkId);
1043
1044                                 // Do we have found the network?
1045                                 if (count($networkRequestData) > 0) {
1046                                         if (isFormSent('edit')) {
1047                                                 // Add row template for deleting
1048                                                 $OUT .= loadTemplate('admin_edit_network_request_params_row', true, $networkRequestData);
1049                                         } elseif (isFormSent('delete')) {
1050                                                 // Get type data
1051                                                 $networkRequestData['network_type_data'] = getNetworkTypeDataById($networkRequestData['network_type_id']);
1052
1053                                                 // Add row template for deleting
1054                                                 $OUT .= loadTemplate('admin_delete_network_request_params_row', true, $networkRequestData);
1055                                         } else {
1056                                                 // Problem!
1057                                                 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
1058                                         }
1059                                 } // END - if
1060                         } // END - if
1061                 } // END - foreach
1062
1063                 // If we have no rows, we don't need to display the edit form
1064                 if (!empty($OUT)) {
1065                         // Output main template
1066                         if (isFormSent('edit')) {
1067                                 loadTemplate('admin_edit_network_request_params', false, $OUT);
1068                         } elseif (isFormSent('delete')) {
1069                                 loadTemplate('admin_delete_network_request_params', false, $OUT);
1070                         } else {
1071                                 // Problem!
1072                                 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
1073                         }
1074
1075                         // Don't display the list/add new form
1076                         $GLOBALS['network_display'] = false;
1077                 } else {
1078                         // Nothing selected/found
1079                         loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_FOUND--}');
1080                 }
1081         } // END - if
1082 }
1083
1084 // Changes given networks
1085 function doAdminNetworkProcessChangeNetworks () {
1086         // Do we have selections?
1087         if (ifPostContainsSelections()) {
1088                 // By default nothing is updated
1089                 $updated = 0;
1090
1091                 // Something has been selected, so start updating them
1092                 foreach (postRequestElement('sel') as $networkId => $sel) {
1093                         // Update this entry?
1094                         if ($sel == 1) {
1095                                 // Init data array
1096                                 $networkData = array();
1097
1098                                 // Transfer whole array, except 'sel'
1099                                 foreach (postRequestArray() as $key => $entry) {
1100                                         // Skip 'sel' and submit button
1101                                         if (in_array($key, array('sel', 'do_edit'))) {
1102                                                 continue;
1103                                         } // END - if
1104
1105                                         // Do we have this enty?
1106                                         if (!isset($entry[$networkId])) {
1107                                                 // Not found, needs fixing
1108                                                 debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1109                                         } // END - if
1110
1111                                         // Add this entry
1112                                         $networkData[$key] = $entry[$networkId];
1113                                 } // END - foreach
1114
1115                                 // Update the network data
1116                                 $updated += doNetworkUpdateDataByArray($networkId, $networkData);
1117                         } // END - if
1118                 } // END - foreach
1119
1120                 // Do we have updates?
1121                 if ($updated > 0) {
1122                         // Updates done
1123                         displayMessage('{%message,ADMIN_NETWORK_UPDATED=' . $updated . '%}');
1124                 } else {
1125                         // Nothing changed
1126                         loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_CHANGED--}');
1127                 }
1128         } // END - if
1129 }
1130
1131 // Removes given networks
1132 function doAdminNetworkProcessRemoveNetworks () {
1133         // Do we have selections?
1134         if (ifPostContainsSelections()) {
1135                 // By default nothing is removed
1136                 $removed = 0;
1137
1138                 // Something has been selected, so start updating them
1139                 foreach (postRequestElement('sel') as $networkId => $sel) {
1140                         // Update this entry?
1141                         if ($sel == 1) {
1142                                 // Remove this entry
1143                                 $removed += doAdminRemoveNetworkEntry('data', 'network_id', $networkId);
1144                         } // END - if
1145                 } // END - foreach
1146
1147                 // Do we have removes?
1148                 if ($removed > 0) {
1149                         // Removals done
1150                         displayMessage('{%message,ADMIN_NETWORK_REMOVED=' . $removed . '%}');
1151                 } else {
1152                         // Nothing removed
1153                         loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_REMOVED--}');
1154                 }
1155         } // END - if
1156 }
1157
1158 // Add a network type handler if not yet found
1159 function doAdminNetworkProcessAddNetworkType () {
1160         // Is the network type handle already used with given network?
1161         if (isNetworkTypeHandleValid(postRequestElement('network_type_handler'), getRequestElement('network_id'))) {
1162                 // Already added
1163                 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_TYPE_HANDLER_ALREADY_ADDED=' . postRequestElement('network_type_handler') . '%}');
1164
1165                 // ... so abort here
1166                 return false;
1167         } // END - if
1168
1169         // Remove the 'ok' part
1170         unsetPostRequestElement('ok');
1171
1172         // Add id
1173         setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1174
1175         // Is network_type_banner_url set?
1176         if (postRequestElement('network_type_banner_url') == '') {
1177                 // Remove empty value to get a NULL for an optional entry
1178                 unsetPostRequestElement('network_type_banner_url');
1179         } // END - if
1180
1181         // Add the whole request to database
1182         SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_types'), __FUNCTION__, __LINE__);
1183
1184         // Output message
1185         if (!SQL_HASZEROAFFECTED()) {
1186                 // Successfully added
1187                 loadTemplate('admin_network_type_added', false, postRequestArray());
1188         } else {
1189                 // Not added
1190                 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_TYPE_HANDLER_NOT_ADDED=' . postRequestElement('network_type_handler') . '%}');
1191         }
1192 }
1193
1194 // Changes given network type handlers
1195 function doAdminNetworkProcessChangeHandlerTypes () {
1196         // Do we have selections?
1197         if (ifPostContainsSelections()) {
1198                 // By default nothing is updated
1199                 $updated = 0;
1200
1201                 // Something has been selected, so start updating them
1202                 foreach (postRequestElement('sel') as $networkId => $sel) {
1203                         // Update this entry?
1204                         if ($sel == 1) {
1205                                 // Init data array
1206                                 $networkTypeData = array();
1207
1208                                 // Transfer whole array, except 'sel'
1209                                 foreach (postRequestArray() as $key => $entry) {
1210                                         // Skip 'sel' and submit button
1211                                         if (in_array($key, array('sel', 'do_edit'))) {
1212                                                 continue;
1213                                         } // END - if
1214
1215                                         // Do we have this enty?
1216                                         if (!isset($entry[$networkId])) {
1217                                                 // Not found, needs fixing
1218                                                 debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1219                                         } // END - if
1220
1221                                         // Fix empty network_type_banner_url to NULL
1222                                         if (($key == 'network_type_banner_url') && (trim($entry[$networkId]) == '')) {
1223                                                 // Set it to NULL
1224                                                 $entry[$networkId] = NULL;
1225                                         } // END - if
1226
1227                                         // Add this entry
1228                                         $networkTypeData[$key] = $entry[$networkId];
1229                                 } // END - foreach
1230
1231                                 // Update the network data
1232                                 $updated += doNetworkUpdateTypeByArray($networkId, $networkTypeData);
1233                         } // END - if
1234                 } // END - foreach
1235
1236                 // Do we have updates?
1237                 if ($updated > 0) {
1238                         // Updates done
1239                         displayMessage('{%message,ADMIN_NETWORK_TYPE_HANDLER_UPDATED=' . $updated . '%}');
1240                 } else {
1241                         // Nothing changed
1242                         loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPE_HANDLER_NOTHING_CHANGED--}');
1243                 }
1244         } // END - if
1245 }
1246
1247 // Changes given network request parameters
1248 function doAdminNetworkProcessChangeRequestParams () {
1249         // Do we have selections?
1250         if (ifPostContainsSelections()) {
1251                 // By default nothing is updated
1252                 $updated = 0;
1253
1254                 // Something has been selected, so start updating them
1255                 foreach (postRequestElement('sel') as $networkId => $sel) {
1256                         // Update this entry?
1257                         if ($sel == 1) {
1258                                 // Init data array
1259                                 $networkParamsData = array();
1260
1261                                 // Transfer whole array, except 'sel'
1262                                 foreach (postRequestArray() as $key => $entry) {
1263                                         // Skip 'sel' and submit button
1264                                         if (in_array($key, array('sel', 'do_edit'))) {
1265                                                 continue;
1266                                         } // END - if
1267
1268                                         // Do we have this enty?
1269                                         if (!isset($entry[$networkId])) {
1270                                                 // Not found, needs fixing
1271                                                 debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1272                                         } // END - if
1273
1274                                         // Fix empty network_request_param_default to NULL
1275                                         if (($key == 'network_request_param_default') && (trim($entry[$networkId]) == '')) {
1276                                                 // Set it to NULL
1277                                                 $entry[$networkId] = NULL;
1278                                         } // END - if
1279
1280                                         // Add this entry
1281                                         $networkParamsData[$key] = $entry[$networkId];
1282                                 } // END - foreach
1283
1284                                 // Update the network data
1285                                 $updated += doNetworkUpdateParamsByArray($networkId, $networkParamsData);
1286                         } // END - if
1287                 } // END - foreach
1288
1289                 // Do we have updates?
1290                 if ($updated > 0) {
1291                         // Updates done
1292                         displayMessage('{%message,ADMIN_NETWORK_REQUEST_PARAMETER_UPDATED=' . $updated . '%}');
1293                 } else {
1294                         // Nothing changed
1295                         loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_CHANGED--}');
1296                 }
1297         } // END - if
1298 }
1299
1300 // Removes given network type handlers
1301 function doAdminNetworkProcessRemoveNetworkTypes () {
1302         // Do we have selections?
1303         if (ifPostContainsSelections()) {
1304                 // By default nothing is removed
1305                 $removed = 0;
1306
1307                 // Something has been selected, so start updating them
1308                 foreach (postRequestElement('sel') as $networkId => $sel) {
1309                         // Update this entry?
1310                         if ($sel == 1) {
1311                                 // Remove this entry
1312                                 $removed += doAdminRemoveNetworkEntry('types', 'network_type_id', $networkId);
1313                         } // END - if
1314                 } // END - foreach
1315
1316                 // Do we have removes?
1317                 if ($removed > 0) {
1318                         // Removals done
1319                         displayMessage('{%message,ADMIN_NETWORK_TYPE_HANDLER_REMOVED=' . $removed . '%}');
1320                 } else {
1321                         // Nothing removed
1322                         loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPE_HANDLER_NOTHING_REMOVED--}');
1323                 }
1324         } // END - if
1325 }
1326
1327 // Removes given network request parameters
1328 function doAdminNetworkProcessRemoveNetworkRequestParams () {
1329         // Do we have selections?
1330         if (ifPostContainsSelections()) {
1331                 // By default nothing is removed
1332                 $removed = 0;
1333
1334                 // Something has been selected, so start updating them
1335                 foreach (postRequestElement('sel') as $networkId => $sel) {
1336                         // Update this entry?
1337                         if ($sel == 1) {
1338                                 // Remove this entry
1339                                 $removed += doAdminRemoveNetworkEntry('request_params', 'network_request_param_id', $networkId);
1340                         } // END - if
1341                 } // END - foreach
1342
1343                 // Do we have removes?
1344                 if ($removed > 0) {
1345                         // Removals done
1346                         displayMessage('{%message,ADMIN_NETWORK_REQUEST_PARAMETER_REMOVED=' . $removed . '%}');
1347                 } else {
1348                         // Nothing removed
1349                         loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_REMOVED--}');
1350                 }
1351         } // END - if
1352 }
1353
1354 // Adds a request parameter to given network and type
1355 function doAdminNetworkProcessAddRequestParam () {
1356         // Is the request parameter already used with given network?
1357         if (isNetworkRequestElementValid(postRequestElement('network_request_param_key'), postRequestElement('network_type_id'), getRequestElement('network_id'))) {
1358                 // Already added
1359                 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_REQUEST_PARAMETER_ALREADY_ADDED=' . postRequestElement('network_request_param_key') . '%}');
1360
1361                 // ... so abort here
1362                 return false;
1363         } // END - if
1364
1365         // Remove the 'ok' part
1366         unsetPostRequestElement('ok');
1367
1368         // Add id
1369         setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1370
1371         // Is network_request_param_default set?
1372         if (postRequestElement('network_request_param_default') == '') {
1373                 // Remove empty value to get a NULL for an optional entry
1374                 unsetPostRequestElement('network_request_param_default');
1375         } // END - if
1376
1377         // Add the whole request to database
1378         SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_request_params'), __FUNCTION__, __LINE__);
1379
1380         // Output message
1381         if (!SQL_HASZEROAFFECTED()) {
1382                 // Successfully added
1383                 loadTemplate('admin_network_request_param_added', false, postRequestArray());
1384         } else {
1385                 // Not added
1386                 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_REQUEST_PARAMETER_NOT_ADDED=' . postRequestElement('network_request_param_key') . '%}');
1387         }
1388 }
1389
1390 // Adds a API response array entry
1391 function doAdminNetworkProcessAddNetworkArrayTranslation () {
1392         // Is the request parameter already used with given network?
1393         if (isNetworkArrayTranslationValid(postRequestElement('network_array_index'), postRequestElement('network_type_id'), getRequestElement('network_id'))) {
1394                 // Already added
1395                 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_ARRAY_TRANSLATION_ALREADY_ADDED=' . postRequestElement('network_array_index') . '%}');
1396
1397                 // ... so abort here
1398                 return false;
1399         } // END - if
1400
1401         // Remove the 'ok' part
1402         unsetPostRequestElement('ok');
1403
1404         // Add id
1405         setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1406
1407         // Add sorting
1408         setPostRequestElement('sort', (countSumTotalData(
1409                 bigintval(postRequestElement('network_id')),
1410                 'network_array_translation',
1411                 'network_array_id',
1412                 'network_id',
1413                 true,
1414                 sprintf(" AND `network_type_id`=%s", bigintval(postRequestElement('network_type_id')))
1415         ) + 1));
1416
1417         // Add the whole request to database
1418         SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_array_translation'), __FUNCTION__, __LINE__);
1419
1420         // Output message
1421         if (!SQL_HASZEROAFFECTED()) {
1422                 // Successfully added
1423                 loadTemplate('admin_network_array_translation_added', false, postRequestArray());
1424         } else {
1425                 // Not added
1426                 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_ARRAY_TRANSLATION_NOT_ADDED=' . postRequestElement('network_array_index') . '%}');
1427         }
1428 }
1429
1430 // Adds/update network API configuration
1431 function doAdminNetworkProcessNetworkApiConfig () {
1432         // Remove the 'ok' part
1433         unsetPostRequestElement('ok');
1434
1435         // Add id
1436         setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1437
1438         // Is network_api_referral_button set?
1439         if (postRequestElement('network_api_referral_button') == '') {
1440                 // Remove empty value to get a NULL for an optional entry
1441                 unsetPostRequestElement('network_api_referral_button');
1442         } // END - if
1443
1444         // Is there already an entry?
1445         if (isNetworkApiConfigured(getRequestElement('network_id'))) {
1446                 // Generate SQL query
1447                 $SQL = getUpdateSqlFromArray(postRequestArray(), 'network_api_config', 'network_id', postRequestElement('network_id'), array('network_id'));
1448         } else {
1449                 // Insert new entry
1450                 $SQL = getInsertSqlFromArray(postRequestArray(), 'network_api_config');
1451         }
1452
1453         // Run the query
1454         SQL_QUERY($SQL, __FUNCTION__, __LINE__);
1455
1456         // Output message
1457         if (!SQL_HASZEROAFFECTED()) {
1458                 // Successfully added
1459                 displayMessage('{--ADMIN_CONFIG_NETWORK_API_SAVED--}');
1460         } else {
1461                 // Not added
1462                 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_API_NOT_SAVED--}');
1463         }
1464 }
1465
1466 // Only adds network type configuration if not yet present
1467 function doAdminNetworkProcessAddHandlerTypesConfig ($displayMessage = true) {
1468         // Remove the 'ok' part
1469         unsetPostRequestElement('ok');
1470
1471         // Add both ids
1472         setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1473         setPostRequestElement('network_type_id', bigintval(getRequestElement('network_type_id')));
1474
1475         /*
1476          * Some parameters are optional, at least one must be given so check a bunch
1477          * of parameters.
1478          */
1479         foreach (array('network_min_waiting_time', 'network_min_remain_clicks', 'network_min_payment', 'network_allow_erotic') as $element) {
1480                 // Is this element empty?
1481                 if (postRequestElement($element) == '') {
1482                         // Then unset it to get a NULL for optional parameter
1483                         unsetPostRequestElement($element);
1484                 } // END - if
1485         } // END - foreach
1486
1487         // Initialize variables
1488         $content = array();
1489         $id = 'network_max_reload_time_ye';
1490         $skip = false;
1491
1492         // Get all POST data
1493         $postData = postRequestArray();
1494
1495         // Convert "reload time selections"
1496         convertSelectionsToEpocheTime($postData, $content, $id, $skip);
1497
1498         // Set the POST array back
1499         setPostRequestArray($postData);
1500
1501         // Is there already an entry?
1502         if (isNetworkTypeHandlerConfigured(getRequestElement('network_id'), getRequestElement('network_type_id'))) {
1503                 // This network type handler is already configured
1504                 displayMessage('{--ADMIN_NETWORK_HANDLER_TYPE_HANDLER_ALREADY_CONFIGURED--}');
1505                 return;
1506         } // END - if
1507
1508         // Copy 'set all' and remove it from POST data
1509         $setAll = (postRequestElement('set_all') === 'Y');
1510         unsetPostRequestElement('set_all');
1511
1512         // Shall we set for all?
1513         if ($setAll === true) {
1514                 // Get all handlers
1515                 $result = SQL_QUERY_ESC('SELECT `network_type_id` FROM `{?_MYSQL_PREFIX?}_network_types` WHERE `network_id`=%s ORDER BY `network_type_id` ASC',
1516                         array(bigintval(getRequestElement('network_id'))), __FUNCTION__, __LINE__);
1517
1518                 // Do we have entries?
1519                 if (SQL_HASZERONUMS($result)) {
1520                         // No, then abort here
1521                         displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_SET_ALL_404--}');
1522                         return;
1523                 } // END - if
1524
1525                 // Init number of rows
1526                 $numRows = 0;
1527
1528                 // Fetch all ids
1529                 while (list($typeId) = SQL_FETCHROW($result)) {
1530                         // Set it in GET data
1531                         setGetRequestElement('network_type_id', $typeId);
1532
1533                         // Call this function again
1534                         $numRows += doAdminNetworkProcessAddHandlerTypesConfig(false);
1535                 } // END - while
1536
1537                 // Free result
1538                 SQL_FREERESULT($result);
1539
1540                 // Output message
1541                 if ($numRows > 0) {
1542                         // Something has been updated
1543                         displayMessage('{%message,ADMIN_CONFIG_NETWORK_HANDLER_TYPE_ALL_HANDLER_SAVED=' . bigintval($numRows) . '%}');
1544                 } else {
1545                         // Nothing has been saved
1546                         loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}');
1547                 }
1548         } else {
1549                 // Get SQL query for new entry
1550                 $SQL = getInsertSqlFromArray(postRequestArray(), 'network_types_config');
1551
1552                 // Run the query
1553                 SQL_QUERY($SQL, __FUNCTION__, __LINE__);
1554
1555                 // Shall we display the message?
1556                 if ($displayMessage === true) {
1557                         // Output message
1558                         if (!SQL_HASZEROAFFECTED()) {
1559                                 // Successfully added
1560                                 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_SAVED--}');
1561                         } else {
1562                                 // Not added
1563                                 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_SAVED--}');
1564                         }
1565                 } else {
1566                         // Return amount of affected rows (1 or 2)
1567                         return SQL_AFFECTEDROWS();
1568                 }
1569         }
1570 }
1571
1572 // Only changes network type configuration if not yet present
1573 function doAdminNetworkProcessEditHandlerTypesConfig ($displayMessage = true) {
1574         // Remove the 'ok' part
1575         unsetPostRequestElement('ok');
1576
1577         /*
1578          * Some parameters are optional, at least one must be given so check a bunch
1579          * of parameters.
1580          */
1581         foreach (array('network_min_waiting_time', 'network_min_remain_clicks', 'network_min_payment', 'network_allow_erotic') as $element) {
1582                 // Is this element empty?
1583                 if (postRequestElement($element) == '') {
1584                         // Then unset it to get a NULL for optional parameter
1585                         unsetPostRequestElement($element);
1586                 } // END - if
1587         } // END - foreach
1588
1589         // Initialize variables
1590         $content = array();
1591         $id = 'network_max_reload_time_ye';
1592         $skip = false;
1593         $postData = postRequestArray();
1594
1595         // Convert "reload time selections"
1596         convertSelectionsToEpocheTime($postData, $content, $id, $skip);
1597
1598         // Set the POST array back
1599         setPostRequestArray($postData);
1600
1601         // Is there already an entry?
1602         if (!isNetworkTypeHandlerConfigured(getRequestElement('network_id'), getRequestElement('network_type_id'))) {
1603                 // This network type handler is not configured
1604                 displayMessage('{--ADMIN_NETWORK_HANDLER_TYPE_HANDLER_NOT_CONFIGURED--}');
1605                 return;
1606         } // END - if
1607
1608         // Copy 'set all' and remove it from POST data
1609         $setAll = (postRequestElement('set_all') === 'Y');
1610         unsetPostRequestElement('set_all');
1611
1612         // Shall we set for all?
1613         if ($setAll === true) {
1614                 // Get all data entries
1615                 $result = SQL_QUERY_ESC('SELECT `network_data_id` FROM `{?_MYSQL_PREFIX?}_network_types_config` WHERE `network_id`=%s ORDER BY `network_type_id` ASC',
1616                         array(bigintval(getRequestElement('network_id'))), __FUNCTION__, __LINE__);
1617
1618                 // Do we have entries?
1619                 if (SQL_HASZERONUMS($result)) {
1620                         // No, then abort here
1621                         displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_SET_ALL_404--}');
1622                         return;
1623                 } // END - if
1624
1625                 // Init number of rows
1626                 $numRows = 0;
1627
1628                 // Fetch all ids
1629                 while (list($dataId) = SQL_FETCHROW($result)) {
1630                         // Set it in GET data
1631                         setPostRequestElement('network_data_id', $dataId);
1632
1633                         // Call this function again
1634                         $numRows += doAdminNetworkProcessEditHandlerTypesConfig(false);
1635                 } // END - while
1636
1637                 // Free result
1638                 SQL_FREERESULT($result);
1639
1640                 // Output message
1641                 if ($numRows > 0) {
1642                         // Something has been updated
1643                         displayMessage('{%message,ADMIN_CONFIG_NETWORK_HANDLER_TYPE_ALL_HANDLER_SAVED=' . bigintval($numRows) . '%}');
1644                 } else {
1645                         // Nothing has been saved
1646                         loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}');
1647                 }
1648         } else {
1649                 // Get SQL query for new entry
1650                 $SQL = getUpdateSqlFromArray(postRequestArray(), 'network_types_config', 'network_data_id', postRequestElement('network_data_id'), array('network_data_id'));
1651
1652                 // Run the query
1653                 SQL_QUERY($SQL, __FUNCTION__, __LINE__);
1654
1655                 // Shall we display the message?
1656                 if ($displayMessage === true) {
1657                         // Output message
1658                         if (!SQL_HASZEROAFFECTED()) {
1659                                 // Successfully added
1660                                 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_SAVED--}');
1661                         } else {
1662                                 // Not added
1663                                 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}');
1664                         }
1665                 } else {
1666                         // Return amount of affected rows (1 or 2)
1667                         return SQL_AFFECTEDROWS();
1668                 }
1669         }
1670 }
1671
1672 // Do expression code for this extension
1673 function doExpressionNetwork ($data) {
1674         // Construct replacer
1675         $replacer = sprintf(
1676                 "{DQUOTE} . %s(%s, '%s') . {DQUOTE}",
1677                 $data['callback'],
1678                 $data['matches'][4][$data['key']],
1679                 $data['extra_func']
1680         );
1681
1682         // Replace %network_id% with the current network id
1683         $replacer = str_replace('%network_id%', getCurrentNetworkId(), $replacer);
1684
1685         // Replace the code
1686         $code = replaceExpressionCode($data, $replacer);
1687
1688         // Return it
1689         return $code;
1690 }
1691
1692 // ----------------------------------------------------------------------------
1693 //                     Call-back functions for exporting data
1694 // ----------------------------------------------------------------------------
1695
1696 // Callback function to export network tables
1697 function doAdminNetworkProcessExport () {
1698         // Init table with all valid what->table entries
1699         $validExports = array(
1700                 // General network data
1701                 'list_networks'                  => 'network_data',
1702                 // Network type handler
1703                 'list_network_types'             => 'network_types',
1704                 // Network request parameter
1705                 'list_network_request_params'    => 'network_request_params',
1706                 // Network API response array index translation
1707                 'list_network_array_translation' => 'network_array_translation',
1708         );
1709
1710         // Is the 'what' key valid?
1711         if (!isset($validExports[getWhat()])) {
1712                 // Not valid
1713                 debug_report_bug(__FUNCTION__, __LINE__, 'what=' . getWhat() . ' - not supported');
1714         } // END - if
1715
1716         // Generate call-back, some tables require to export not all columns
1717         $callbackName = 'doAdminNetworkExport' . capitalizeUnderscoreString($validExports[getWhat()]);
1718
1719         // Is the call-back function there?
1720         if (!function_exists($callbackName)) {
1721                 // No, this is really bad
1722                 debug_report_bug(__FUNCTION__, __LINE__, 'Invalid call-back function ' . $callbackName . ' detected.');
1723         } elseif (isset($GLOBALS[__FUNCTION__][$callbackName])) {
1724                 // Already called!
1725                 debug_report_bug(__FUNCTION__, __LINE__, 'Double-call of export function ' . $callbackName . ' detected.');
1726         }
1727
1728         // Call the function
1729         call_user_func($callbackName);
1730
1731         // Mark it as called
1732         $GLOBALS[__FUNCTION__][$callbackName] = true;
1733
1734         // Don't display the list/add new form
1735         $GLOBALS['network_display'] = false;
1736 }
1737
1738 // Exports (and displays) the table 'network_data'
1739 function doAdminNetworkExportNetworkData () {
1740         // Query for all networks
1741         $result = SQL_QUERY('SELECT
1742         `network_short_name`,
1743         `network_title`,
1744         `network_reflink`,
1745         `network_data_separator`,
1746         `network_row_separator`,
1747         `network_request_type`,
1748         `network_charset`,
1749         `network_require_id_card`,
1750         `network_query_amount`,
1751         `network_active`
1752 FROM
1753         `{?_MYSQL_PREFIX?}_network_data`
1754 ORDER BY
1755         `network_id` ASC',
1756                 __FUNCTION__, __LINE__);
1757
1758         // Start an empty SQL query
1759         $SQL = "INSERT INTO `&#123;&#63;_MYSQL_PREFIX&#63;&#125;_network_data` (`network_short_name`,`network_title`,`network_reflink`,`network_data_separator`,`network_row_separator`,`network_request_type`,`network_charset`,`network_require_id_card`,`network_query_amount`,`network_active`) VALUES\n";
1760
1761         // Load all entries
1762         while ($content = SQL_FETCHARRAY($result)) {
1763                 // Add row
1764                 $SQL .= "('" .
1765                         $content['network_short_name'] . "', '" .
1766                         $content['network_title'] . "', '" .
1767                         $content['network_reflink'] . "', '" .
1768                         $content['network_data_separator'] . "', '" .
1769                         $content['network_row_separator'] . "', '" .
1770                         $content['network_request_type'] . "', '" .
1771                         $content['network_charset'] . "', '" .
1772                         $content['network_require_id_card'] . "', " .
1773                         $content['network_query_amount'] . ", '" .
1774                         $content['network_active'] . "'),\n";
1775         } // END - while
1776
1777         // Remove last commata and close braces
1778         $SQL = substr($SQL, 0, -2);
1779
1780         // Free result
1781         SQL_FREERESULT($result);
1782
1783         // Output the SQL query
1784         loadTemplate('admin_export_network_data', false, $SQL);
1785 }
1786
1787 // Exports (and displays) the table 'network_types'
1788 function doAdminNetworkExportNetworkTypes () {
1789         // 'network_id' must be set
1790         if (!isGetRequestElementSet('network_id')) {
1791                 // Only network handlers of one network will be exported per time
1792                 debug_report_bug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
1793         } // END - if
1794
1795         // Get all network types of given network
1796         $result = SQL_QUERY_ESC('SELECT
1797         `network_type_id`,
1798         `network_id`,
1799         `network_type_handler`,
1800         `network_type_api_url`,
1801         `network_type_click_url`,
1802         `network_type_banner_url`,
1803         `network_type_reload_time_unit`
1804 FROM
1805         `{?_MYSQL_PREFIX?}_network_types`
1806 WHERE
1807         `network_id`=%s
1808 ORDER BY
1809         `network_type_id` ASC',
1810                 array(
1811                         bigintval(getRequestElement('network_id'))
1812                 ), __FUNCTION__, __LINE__);
1813
1814         // Start an empty SQL query
1815         $SQL = "INSERT INTO `&#123;&#63;_MYSQL_PREFIX&#63;&#125;_network_types` (`network_type_id`,`network_id`,`network_type_handler`,`network_type_api_url`,`network_type_click_url`,`network_type_banner_url`) VALUES\n";
1816
1817         // Load all entries
1818         while ($content = SQL_FETCHARRAY($result)) {
1819                 // Add row
1820                 $SQL .= '(' .
1821                         $content['network_type_id'] . ', ' .
1822                         $content['network_id'] . ", '" .
1823                         $content['network_type_handler'] . "', '" .
1824                         $content['network_type_api_url'] . "', '" .
1825                         $content['network_type_click_url'] . "', ";
1826                 
1827                 // Is the column NULL?
1828                 if (is_null($content['network_type_banner_url'])) {
1829                         // Column is NULL
1830                         $SQL .= 'NULL';
1831                 } else {
1832                         // Column is set
1833                         $SQL .= "'" . $content['network_type_banner_url'] . "'";
1834                 }
1835
1836                 // Add more
1837                 $SQL .= ",'" . $content['network_type_reload_time_unit'] . "'),\n";
1838         } // END - while
1839
1840         // Remove last commata and close braces
1841         $SQL = substr($SQL, 0, -2);
1842
1843         // Free result
1844         SQL_FREERESULT($result);
1845
1846         // Output the SQL query
1847         loadTemplate('admin_export_network_types', false, $SQL);
1848 }
1849
1850 // Exports (and displays) the table 'network_request_params'
1851 function doAdminNetworkExportNetworkRequestParams () {
1852         // 'network_id' must be set
1853         if (!isGetRequestElementSet('network_id')) {
1854                 // Only network request parameters of one network will be exported per time
1855                 debug_report_bug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
1856         } // END - if
1857
1858         // Get all network types of given network
1859         $result = SQL_QUERY_ESC('SELECT
1860         `network_id`,
1861         `network_type_id`,
1862         `network_request_param_key`,
1863         `network_request_param_value`,
1864         `network_request_param_default`
1865 FROM
1866         `{?_MYSQL_PREFIX?}_network_request_params`
1867 WHERE
1868         `network_id`=%s
1869 ORDER BY
1870         `network_type_id` ASC ,
1871         `network_request_param_id` ASC',
1872                 array(
1873                         bigintval(getRequestElement('network_id'))
1874                 ), __FUNCTION__, __LINE__);
1875
1876         // Start an empty SQL query
1877         $SQL = "INSERT INTO `&#123;&#63;_MYSQL_PREFIX&#63;&#125;_network_request_params` (`network_id`,`network_type_id`,`network_request_param_key`,`network_request_param_value`,`network_request_param_default`) VALUES\n";
1878
1879         // Load all entries
1880         while ($content = SQL_FETCHARRAY($result)) {
1881                 // Add row
1882                 $SQL .= '(' .
1883                         $content['network_id'] . ', ' .
1884                         $content['network_type_id'] . ", '" .
1885                         $content['network_request_param_key'] . "', '" .
1886                         $content['network_request_param_value'] . "', ";
1887                 
1888                 // Is the column NULL?
1889                 if (is_null($content['network_request_param_default'])) {
1890                         // Column is NULL
1891                         $SQL .= "NULL),\n";
1892                 } else {
1893                         // Column is set
1894                         $SQL .= "'" . $content['network_request_param_default'] . "'),\n";
1895                 }
1896         } // END - while
1897
1898         // Remove last commata and close braces
1899         $SQL = substr($SQL, 0, -2);
1900
1901         // Free result
1902         SQL_FREERESULT($result);
1903
1904         // Output the SQL query
1905         loadTemplate('admin_export_network_request_params', false, $SQL);
1906 }
1907
1908 // Exports (and displays) the table 'network_array_translation'
1909 function doAdminNetworkExportNetworkArrayTranslation () {
1910         // 'network_id' must be set
1911         if (!isGetRequestElementSet('network_id')) {
1912                 // Only network API array index translations of one network will be exported per time
1913                 debug_report_bug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
1914         } // END - if
1915
1916         // Get all network types of given network
1917         $result = SQL_QUERY_ESC('SELECT
1918         `network_id`,
1919         `network_type_id`,
1920         `network_array_index`,
1921         `sort`
1922 FROM
1923         `{?_MYSQL_PREFIX?}_network_array_translation`
1924 WHERE
1925         `network_id`=%s
1926 ORDER BY
1927         `network_type_id` ASC,
1928         `sort` ASC',
1929                 array(
1930                         bigintval(getRequestElement('network_id'))
1931                 ), __FUNCTION__, __LINE__);
1932
1933         // Start an empty SQL query
1934         $SQL = "INSERT INTO `&#123;&#63;_MYSQL_PREFIX&#63;&#125;_network_array_translation` (`network_id`,`network_type_id`,`network_array_index`,`sort`) VALUES\n";
1935
1936         // Load all entries
1937         while ($content = SQL_FETCHARRAY($result)) {
1938                 // Add row
1939                 $SQL .= '(' .
1940                         $content['network_id'] . ', ' .
1941                         $content['network_type_id'] . ', ' .
1942                         $content['network_array_index'] . ', ' .
1943                         $content['sort'] . "),\n";
1944         } // END - while
1945
1946         // Remove last commata and close braces
1947         $SQL = substr($SQL, 0, -2);
1948
1949         // Free result
1950         SQL_FREERESULT($result);
1951
1952         // Output the SQL query
1953         loadTemplate('admin_export_network_array_translation', false, $SQL);
1954 }
1955
1956 // [EOF]
1957 ?>