]> git.mxchange.org Git - mailer.git/blob - inc/libs/network_functions.php
Fixes and cleanups
[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 // Handle a (maybe) sent form here
54 function doNetworkHandleForm () {
55         // Was the form sent?
56         if ((isFormSent()) || (isFormSent('edit')) || (isFormSent('delete')) || (isFormSent('do_edit')) || (isFormSent('do_delete'))) {
57                 // Do we have a 'do'?
58                 if (isGetRequestElementSet('do')) {
59                         // Process the request
60                         doAdminNetworkProcessForm();
61                 } else {
62                         // No 'do' found
63                         loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_DO_404--}');
64                 }
65         } // END - if
66 }
67
68 // Processes an admin form
69 function doAdminNetworkProcessForm () {
70         // Form really sent?
71         if ((!isFormSent()) && (!isFormSent('edit')) && (!isFormSent('delete')) && (!isFormSent('do_edit')) && (!isFormSent('do_delete'))) {
72                 // Abort here
73                 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_FORM_NOT_SENT--}');
74                 return;
75         } elseif (!isGetRequestElementSet('do')) {
76                 // No 'do' found
77                 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_DO_404--}');
78                 return;
79         }
80
81         // Create function name
82         $functionName = sprintf("doAdminNetworkProcess%s", capitalizeUnderscoreString(getRequestElement('do')));
83
84         // Is the function valid?
85         if (!function_exists($functionName)) {
86                 // Invalid function name
87                 debug_report_bug(__FUNCTION__, __LINE__, 'Invalid do ' . getRequestElement('do') . ', function ' . $functionName .' does not exist.', false);
88         } // END - if
89
90         // Call-back the method handling our request
91         call_user_func($functionName);
92 }
93
94 // Checks wether the (short) network name is already used (valid)
95 function isNetworkNameValid ($name) {
96         // Query for it
97         $result = SQL_QUERY_ESC("SELECT `network_id` FROM `{?_MYSQL_PREFIX?}_network_data` WHERE `network_short_name`='%s' LIMIT 1",
98                 array($name), __FUNCTION__, __LINE__);
99
100         // Does it exist?
101         $isValid = (SQL_NUMROWS($result) == 1);
102
103         // Free result
104         SQL_FREERESULT($result);
105
106         // Return result
107         return $isValid;
108 }
109
110 // Checks wether the given network type is already used (valid)
111 function isNetworkTypeHandleValid ($type, $networkId) {
112         // Query for it
113         $result = SQL_QUERY_ESC("SELECT `network_type_id` FROM `{?_MYSQL_PREFIX?}_network_types` WHERE `network_id`=%s AND `network_type_handle`='%s' LIMIT 1",
114                 array($networkId, $type), __FUNCTION__, __LINE__);
115
116         // Does it exist?
117         $isValid = (SQL_NUMROWS($result) == 1);
118
119         // Free result
120         SQL_FREERESULT($result);
121
122         // Return result
123         return $isValid;
124 }
125
126 // Checks wether the given network request parameter is already used (valid)
127 function isNetworkRequestElementValid ($key, $type, $networkId) {
128         // Query for it
129         $result = SQL_QUERY_ESC("SELECT `network_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",
130                 array($networkId, $type, $key), __FUNCTION__, __LINE__);
131
132         // Does it exist?
133         $isValid = (SQL_NUMROWS($result) == 1);
134
135         // Free result
136         SQL_FREERESULT($result);
137
138         // Return result
139         return $isValid;
140 }
141
142 // Checks wether the given network API array translation
143 function isNetworkApiTranslationValid ($key, $type, $networkId) {
144         // Query for it
145         $result = SQL_QUERY_ESC("SELECT `network_api_id` FROM `{?_MYSQL_PREFIX?}_network_api_translation` WHERE `network_id`=%s AND `network_type_id`=%s AND `network_api_index`='%s' LIMIT 1",
146                 array($networkId, $type, $key), __FUNCTION__, __LINE__);
147
148         // Does it exist?
149         $isValid = (SQL_NUMROWS($result) == 1);
150
151         // Free result
152         SQL_FREERESULT($result);
153
154         // Return result
155         return $isValid;
156 }
157
158 // "Getter" for a network's data by provided id number
159 function getNetworkDataById ($networkId, $column = '') {
160         // Ids lower one are not accepted
161         if ($networkId < 1) {
162                 // Not good, should be fixed
163                 debug_report_bug(__FUNCTION__, __LINE__, 'Network id ' . $networkId . ' is smaller than 1.');
164         } // END - if
165
166         // Set current network id
167         setCurrentNetworkId($networkId);
168
169         // Is it cached?
170         if (!isset($GLOBALS['network_data'][$networkId])) {
171                 // By default we have no data
172                 $GLOBALS['network_data'][$networkId] = array();
173
174                 // Query for the network data
175                 $result = SQL_QUERY_ESC("SELECT
176         `network_id`,
177         `network_short_name`,
178         `network_title`,
179         `network_reflink`,
180         `network_data_separator`,
181         `network_row_separator`,
182         `network_request_type`,
183         `network_charset`,
184         `network_require_id_card`,
185         `network_query_amount`
186 FROM
187         `{?_MYSQL_PREFIX?}_network_data`
188 WHERE
189         `network_id`=%s
190 LIMIT 1",
191                         array(bigintval($networkId)), __FUNCTION__, __LINE__);
192
193                 // Do we have an entry?
194                 if (SQL_NUMROWS($result) == 1) {
195                         // Then get it
196                         $GLOBALS['network_data'][$networkId] = SQL_FETCHARRAY($result);
197                 } // END - if
198
199                 // Free result
200                 SQL_FREERESULT($result);
201         } // END - if
202
203         // Return result
204         if (empty($column)) {
205                 // Return array
206                 return $GLOBALS['network_data'][$networkId];
207         } else {
208                 // Return column
209                 return $GLOBALS['network_data'][$networkId][$column];
210         }
211 }
212
213 // "Getter" for a network's data by provided type id number
214 function getNetworkDataByTypeId ($networkId, $column = '') {
215         // Ids lower one are not accepted
216         if ($networkId < 1) {
217                 // Not good, should be fixed
218                 debug_report_bug(__FUNCTION__, __LINE__, 'Network type id ' . $networkId . ' is smaller than 1.');
219         } // END - if
220
221         // Set current network id
222         setCurrentNetworkId($networkId);
223
224         // Is it cached?
225         if (!isset($GLOBALS['network_data'][$networkId])) {
226                 // By default we have no data
227                 $GLOBALS['network_data'][$networkId] = array();
228
229                 // Query for the network data
230                 $result = SQL_QUERY_ESC("SELECT
231         d.`network_id`,
232         d.`network_short_name`,
233         d.`network_title`,
234         d.`network_reflink`,
235         d.`network_data_separator`,
236         d.`network_row_separator`,
237         d.`network_request_type`,
238         d.`network_charset`,
239         d.`network_require_id_card`,
240         d.`network_query_amount`,
241         t.`network_type_handle`,
242         t.`network_type_api_url`,
243         t.`network_type_click_url`,
244         t.`network_type_banner_url`
245 FROM
246         `{?_MYSQL_PREFIX?}_network_data` AS d
247 LEFT JOIN
248         `{?_MYSQL_PREFIX?}_network_types` AS t
249 ON
250         d.`network_id`=t.`network_id`
251 WHERE
252         t.`network_type_id`=%s
253 LIMIT 1",
254                         array(bigintval($networkId)), __FUNCTION__, __LINE__);
255
256                 // Do we have an entry?
257                 if (SQL_NUMROWS($result) == 1) {
258                         // Then get it
259                         $GLOBALS['network_data'][$networkId] = SQL_FETCHARRAY($result);
260                 } // END - if
261
262                 // Free result
263                 SQL_FREERESULT($result);
264         } // END - if
265
266         // Return result
267         if (empty($column)) {
268                 // Return array
269                 return $GLOBALS['network_data'][$networkId];
270         } else {
271                 // Return column
272                 return $GLOBALS['network_data'][$networkId][$column];
273         }
274 }
275
276 // "Getter" for a network type data by provided id number
277 function getNetworkTypeDataById ($networkId) {
278         // Ids lower one are not accepted
279         if ($networkId < 1) {
280                 // Not good, should be fixed
281                 debug_report_bug(__FUNCTION__, __LINE__, 'Network type id ' . $networkId . ' is smaller than 1.');
282         } // END - if
283
284         // By default we have no data
285         $GLOBALS['network_type_data'][$networkId] = array();
286
287         // Query for the network data
288         $result = SQL_QUERY_ESC("SELECT
289         `network_type_id`
290         `network_id`,
291         `network_type_handle`,
292         `network_type_api_url`,
293         `network_type_click_url`,
294         `network_type_banner_url`
295 FROM
296         `{?_MYSQL_PREFIX?}_network_types`
297 WHERE
298         `network_type_id`=%s
299 LIMIT 1",
300                 array(bigintval($networkId)), __FUNCTION__, __LINE__);
301
302         // Do we have an entry?
303         if (SQL_NUMROWS($result) == 1) {
304                 // Then get it
305                 $GLOBALS['network_type_data'][$networkId] = SQL_FETCHARRAY($result);
306         } // END - if
307
308         // Free result
309         SQL_FREERESULT($result);
310
311         // Return result
312         return $GLOBALS['network_type_data'][$networkId];
313 }
314
315 // "Getter" for a network request parameter data by provided id number
316 function getNetworkRequestParamsDataById ($networkId) {
317         // Ids lower one are not accepted
318         if ($networkId < 1) {
319                 // Not good, should be fixed
320                 debug_report_bug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $networkId . ' is smaller than 1.');
321         } // END - if
322
323         // By default we have no data
324         $networkRequestData = array();
325
326         // Query for the network data
327         $result = SQL_QUERY_ESC("SELECT
328         `network_param_id`,
329         `network_id`,
330         `network_type_id`,
331         `network_request_param_key`,
332         `network_request_param_value`,
333         `network_request_param_default`
334 FROM
335         `{?_MYSQL_PREFIX?}_network_request_params`
336 WHERE
337         `network_param_id`=%s
338 LIMIT 1",
339                 array(bigintval($networkId)), __FUNCTION__, __LINE__);
340
341         // Do we have an entry?
342         if (SQL_NUMROWS($result) == 1) {
343                 // Then get it
344                 $networkRequestData = SQL_FETCHARRAY($result);
345         } // END - if
346
347         // Free result
348         SQL_FREERESULT($result);
349
350         // Return result
351         return $networkRequestData;
352 }
353
354 // Updates given network (id) with data from array
355 function doNetworkUpdateDataByArray ($networkId, $networkData) {
356         // Ids lower one are not accepted
357         if ($networkId < 1) {
358                 // Not good, should be fixed
359                 debug_report_bug(__FUNCTION__, __LINE__, 'Network id ' . $networkId . ' is smaller than 1.');
360         } // END - if
361
362         // Just call our inner method
363         return adminSaveSettings($networkData, '_network_data', sprintf("`network_id`=%s", bigintval($networkId)), array(), false, false);
364 }
365
366 // Updates given network type handler (id) with data from array
367 function doNetworkUpdateTypeByArray ($networkId, $networkTypeData) {
368         // Ids lower one are not accepted
369         if ($networkId < 1) {
370                 // Not good, should be fixed
371                 debug_report_bug(__FUNCTION__, __LINE__, 'Network type handler id ' . $networkId . ' is smaller than 1.');
372         } // END - if
373
374         // Just call our inner method
375         return adminSaveSettings($networkTypeData, '_network_types', sprintf("`network_type_id`=%s", bigintval($networkId)), array(), false, false);
376 }
377
378 // Updates given network request parameters (id) with data from array
379 function doNetworkUpdateParamsByArray ($networkId, $networkParamData) {
380         // Ids lower one are not accepted
381         if ($networkId < 1) {
382                 // Not good, should be fixed
383                 debug_report_bug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $networkId . ' is smaller than 1.');
384         } // END - if
385
386         // Just call our inner method
387         return adminSaveSettings($networkParamData, '_network_request_params', sprintf("`network_param_id`=%s", bigintval($networkId)), array(), false, false);
388 }
389
390 // Removes given network entry
391 function doAdminRemoveNetworkEntry ($table, $column, $networkId, $limit = 1) {
392         // Remove the entry
393         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_network_%s` WHERE `%s`=%s LIMIT %s",
394                 array($table, $column, $networkId, $limit), __FUNCTION__, __LINE__);
395
396         // Return affected rows
397         return SQL_AFFECTEDROWS();
398 }
399
400 // Generates a list of networks for given script and returns it
401 function generateAdminNetworkList () {
402         // Init output
403         $content = '';
404
405         // Query for all networks
406         $result = SQL_QUERY('SELECT
407         `network_id`,`network_short_name`,`network_title`
408 FROM
409         `{?_MYSQL_PREFIX?}_network_data`
410 ORDER BY
411         `network_short_name` ASC', __FUNCTION__, __LINE__);
412
413         // Do we have entries?
414         if (!SQL_HASZERONUMS($result)) {
415                 // List all entries
416                 $rows = array();
417                 while ($row = SQL_FETCHARRAY($result)) {
418                         // Is this valid, then add it
419                         if ((is_array($row)) && (isset($row['network_id']))) {
420                                 // Add entry
421                                 $rows[$row['network_id']] = $row;
422                         } // END - if
423                 } // END - while
424
425                 // Generate the selection box
426                 $content = generateSelectionBoxFromArray($rows, 'network', 'network_id');
427         } else {
428                 // Nothing selected
429                 $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}');
430         }
431
432         // Free the result
433         SQL_FREERESULT($result);
434
435         // Return the list
436         return $content;
437 }
438
439 // Generator (somewhat getter) for a list of network types for given network id
440 function generateAdminNetworkTypeList ($networkId) {
441         // Init content
442         $content = '';
443
444         // Query all types of this network
445         $result = SQL_QUERY_ESC("SELECT
446         `network_type_id`,`network_type_handle`
447 FROM
448         `{?_MYSQL_PREFIX?}_network_types`
449 WHERE
450         `network_id`=%s
451 ORDER BY
452         `network_type_handle` ASC",
453                 array(
454                         bigintval($networkId)
455                 ), __FUNCTION__, __LINE__);
456
457         // Do we have entries?
458         if (!SQL_HASZERONUMS($result)) {
459                 // List all entries
460                 $rows = array();
461                 while ($row = SQL_FETCHARRAY($result)) {
462                         // Is this valid, then add it
463                         if ((is_array($row)) && (isset($row['network_type_id']))) {
464                                 // Add entry
465                                 $rows[$row['network_type_id']] = $row;
466                         } // END - if
467                 } // END - while
468
469                 // Generate the selection box
470                 $content = generateSelectionBoxFromArray($rows, 'network_type', 'network_type_id');
471         } else {
472                 // Nothing selected
473                 $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}');
474         }
475
476         // Free the result
477         SQL_FREERESULT($result);
478
479         // Return content
480         return $content;
481 }
482
483 // Generator (somewhat getter) for a list of network types for all types
484 function generateAdminDistinctNetworkTypeList () {
485         // Init content
486         $content = '';
487
488         // Query all types of this network
489         $result = SQL_QUERY('SELECT
490         t.`network_type_id`, t.`network_type_handle`, d.`network_title`
491 FROM
492         `{?_MYSQL_PREFIX?}_network_types` AS t
493 LEFT JOIN
494         `{?_MYSQL_PREFIX?}_network_data` AS d
495 ON
496         t.`network_id`=d.`network_id`
497 ORDER BY
498         d.`network_short_name` ASC,
499         t.`network_type_handle` ASC', __FUNCTION__, __LINE__);
500
501         // Do we have entries?
502         if (!SQL_HASZERONUMS($result)) {
503                 // List all entries
504                 $rows = array();
505                 while ($row = SQL_FETCHARRAY($result)) {
506                         // Is this valid, then add it
507                         if ((is_array($row)) && (isset($row['network_type_id']))) {
508                                 // Add entry
509                                 $rows[$row['network_type_id']] = $row;
510                         } // END - if
511                 } // END - while
512
513                 // Generate the selection box
514                 $content = generateSelectionBoxFromArray($rows, 'network_type', 'network_type_id', '', '_title');
515         } else {
516                 // Nothing selected
517                 $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}');
518         }
519
520         // Free the result
521         SQL_FREERESULT($result);
522         //* DEBUG: */ die('<pre>'.encodeEntities($content).'</pre>');
523
524         // Return content
525         return $content;
526 }
527
528 // Generator (somewhat getter) for network type options
529 function generateNetworkTypeOptions ($networkId) {
530         // Is this an array, then we just came back from edit/delete actions
531         if (is_array($networkId)) {
532                 $networkId = '';
533         } // END - if
534
535         // Is this cached?
536         if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
537                 // Generate output and cache it
538                 $GLOBALS[__FUNCTION__][$networkId] = generateOptionList(
539                         'network_types',
540                         'network_type_id',
541                         'network_type_handle',
542                         $networkId,
543                         '',
544                         sprintf(
545                                 "WHERE `network_id`=%s",
546                                 bigintval(getRequestElement('network'))
547                         ),
548                         '',
549                         'translateNetworkTypeHandler'
550                 );
551         } // END - if
552
553         // Return content
554         return $GLOBALS[__FUNCTION__][$networkId];
555 }
556
557 // Generates an options list of all available (hard-coded) handlers
558 function generateNetworkTypesAvailableOptions () {
559         // Is it cached?
560         if (!isset($GLOBALS[__FUNCTION__])) {
561                 // Generate list
562                 $GLOBALS[__FUNCTION__] = generateOptionList(
563                         '/ARRAY/',
564                         array(
565                                 'banner',
566                                 'banner_click',
567                                 'banner_view',
568                                 'button',
569                                 'button_click',
570                                 'button_view',
571                                 'surfbar',
572                                 'surfbar_click',
573                                 'surfbar_view',
574                                 'forcedbanner',
575                                 'forcedtextlink',
576                                 'textlink',
577                                 'textlink_click',
578                                 'textlink_view',
579                                 'skybanner',
580                                 'skybanner_click',
581                                 'skybanner_view',
582                                 'layer',
583                                 'layer_click',
584                                 'layer_view',
585                                 'popup',
586                                 'popdown',
587                                 'textmail',
588                                 'htmlmail',
589                                 'lead',
590                                 'sale',
591                                 'payperactive',
592                                 'pagepeel',
593                                 'traffic'
594                         ),
595                         array(),
596                         '',
597                         '', '',
598                         $GLOBALS['network_types_disabled'],
599                         'translateNetworkTypeHandler'
600                 );
601         } // END - if
602
603         // Return content
604         return $GLOBALS[__FUNCTION__];
605 }
606
607 // Generates an options list (somewhat getter) ofr request keys
608 function generateNetworkRequestKeyOptions () {
609         // Is it cached?
610         if (!isset($GLOBALS[__FUNCTION__])) {
611                 // Generate and cache it
612                 $GLOBALS[__FUNCTION__] = generateOptionList(
613                         '/ARRAY/',
614                         array(
615                                 'id',
616                                 'sid',
617                                 'hash',
618                                 'password',
619                                 'reload',
620                                 'maximum_stay',
621                                 'minimum_stay',
622                                 'currency',
623                                 'type',
624                                 'remain',
625                                 'reward',
626                                 'size',
627                                 'erotic',
628                                 'extra',
629                                 'country'
630                         ),
631                         array(),
632                         '',
633                         '', '',
634                         $GLOBALS['network_params_disabled'],
635                         'translateNetworkRequestElement'
636                 );
637         } // END - if
638
639         // Return content
640         return $GLOBALS[__FUNCTION__];
641 }
642
643 // Generator (somewhat getter) for (return) array translation
644 function generateNetworkTranslationOptions ($default = '') {
645         // Is it cached?
646         if (!isset($GLOBALS[__FUNCTION__][$default])) {
647                 // Generate and cache it
648                 $GLOBALS[__FUNCTION__][$default] = generateOptionList(
649                         'network_translations',
650                         'network_translation_id',
651                         'network_translation_name',
652                         $default,
653                         '',
654                         '',
655                         $GLOBALS['network_translation_disabled'],
656                         'translateNetworkTranslationName'
657                 );
658         } // END - if
659
660         // Return content
661         return $GLOBALS[__FUNCTION__][$default];
662 }
663
664 // Generates an option list of request types
665 function generateNetworkRequestTypeOptions ($default = '') {
666         // Do we have cache?
667         if (!isset($GLOBALS[__FUNCTION__][$default])) {
668                 // Generate the list
669                 $GLOBALS[__FUNCTION__][$default] = generateOptionList(
670                         '/ARRAY/',
671                         array(
672                                 'GET',
673                                 'POST'
674                         ),
675                         array(
676                                 '{--ADMIN_NETWORK_REQUEST_TYPE_GET--}',
677                                 '{--ADMIN_NETWORK_REQUEST_TYPE_POST--}'
678                         ),
679                         $default
680                 );
681         } // END - if
682
683         // Return cache
684         return $GLOBALS[__FUNCTION__][$default];
685 }
686
687 // Generates an option list of network_api_active
688 function generateNetworkApiActiveOptions ($default = '') {
689         // Do we have cache?
690         if (!isset($GLOBALS[__FUNCTION__][$default])) {
691                 // Generate the list
692                 $GLOBALS[__FUNCTION__][$default] = generateYesNoOptionList($default);
693         } // END - if
694
695         // Return cache
696         return $GLOBALS[__FUNCTION__][$default];
697 }
698
699 // Translates 'translate_name' for e.g. templates
700 function translateNetworkTranslationName ($name) {
701         // Get the message id
702         return '{--ADMIN_NETWORK_TRANSLATE_' . strtoupper($name) . '_NAME--}';
703 }
704
705 // Translates the network type handler (e.g. banner, paidmail) for templates
706 function translateNetworkTypeHandler ($type) {
707         // Get the message id
708         return '{--ADMIN_NETWORK_TYPES_' . strtoupper($type) . '--}';
709 }
710
711 // Translates request type
712 function translateNetworkRequestType ($type) {
713         // Get the message id
714         return '{--ADMIN_NETWORK_REQUEST_TYPE_' . strtoupper($type) . '--}';
715 }
716
717 // Translates request parameter
718 function translateNetworkRequestElement ($param) {
719         // Get the message id
720         return '{--ADMIN_NETWORK_REQUEST_PARAMETER_' . strtoupper($param) . '--}';
721 }
722
723 // Translates API index
724 function translateNetworkApiIndex ($index) {
725         // Do we have cache?
726         if (!isset($GLOBALS['network_api_index'])) {
727                 // Get an array of all API array indexes
728                 $GLOBALS['network_api_index'] = array();
729
730                 // Get all entries
731                 $result = SQL_QUERY('SELECT
732         `network_api_id`,`network_api_index`,`network_translation_name`
733 FROM
734         `{?_MYSQL_PREFIX?}_network_api_translation`
735 INNER JOIN
736         `{?_MYSQL_PREFIX?}_network_translations`
737 ON
738         `network_api_index`=`network_translation_id`
739 ORDER BY
740         `sort` ASC', __FUNCTION__, __LINE__);
741
742                 // Do we have entries?
743                 if (!SQL_HASZERONUMS($result)) {
744                         // Get all entries
745                         while ($row = SQL_FETCHARRAY($result)) {
746                                 // Add it to our global array
747                                 $GLOBALS['network_api_index'][$row['network_api_index']] = $row;
748                         } // END - while
749                 } // END - if
750
751                 // Free result
752                 SQL_FREERESULT($result);
753         } // END - if
754
755         // Default name is unknown
756         $name = 'unknown';
757
758         // Is the entry there?
759         if (isset($GLOBALS['network_api_index'][$index])) {
760                 // Then get the name
761                 $name = $GLOBALS['network_api_index'][$index]['network_translation_name'];
762         } // END - if
763
764         // Return translation
765         return translateNetworkTranslationName($name);
766 }
767
768 // Translates network API configuration status (see function isNetworkApiConfigured()) by given id
769 function translateNetworkApiConfiguredStatusById ($networkId) {
770         // Do we have cache?
771         if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
772                 // By default it is not configured
773                 $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_NOT_CONFIGURED--}';
774
775                 // So is it configured?
776                 if (isNetworkApiConfigured($networkId)) {
777                         // Yes, it is
778                         $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_CONFIGURED--}';
779                 } // END - if
780         } // END - if
781
782         // Return cache
783         return $GLOBALS[__FUNCTION__][$networkId];
784 }
785
786 // Checks if the given network is configured by looking its API configuration entry up
787 function isNetworkApiConfigured ($networkId) {
788         // Do we have cache?
789         if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
790                 // Check for an entry in network_api_config
791                 $GLOBALS[__FUNCTION__][$networkId] = (countSumTotalData(
792                         bigintval($networkId),
793                         'network_api_config',
794                         'network_id',
795                         'network_id',
796                         true
797                 ) == 1);
798         } // END - if
799
800         // Return cache
801         return $GLOBALS[__FUNCTION__][$networkId];
802 }
803
804 //------------------------------------------------------------------------------
805 //                             Call-back functions
806 //------------------------------------------------------------------------------
807
808 // Callback function to add new network
809 function doAdminNetworkProcessAddNetwork () {
810         // We can say here, the form is sent, so check if the network is already added
811         if (isNetworkNameValid(postRequestElement('network_short_name'))) {
812                 // Already there
813                 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_ALREADY_ADDED=' . postRequestElement('network_short_name') . '%}');
814                 return false;
815         } // END - if
816
817         // Remove the 'ok' part
818         unsetPostRequestElement('ok');
819
820         // Add the whole request to database
821         SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_data'), __FUNCTION__, __LINE__);
822
823         // Add the id for output only
824         setPostRequestElement('network_id', SQL_INSERTID());
825
826         // Output message
827         if (!SQL_HASZEROAFFECTED()) {
828                 // Successfully added
829                 loadTemplate('admin_network_added', false, postRequestArray());
830         } else {
831                 // Not added
832                 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_DATA_NOT_ADDED=' . postRequestElement('network_short_name') . '%}');
833         }
834 }
835
836 // Displays selected networks for editing
837 function doAdminNetworkProcessHandleNetwork () {
838         // Do we have selections?
839         if (ifPostContainsSelections()) {
840                 // Something has been selected, so start displaying one by one
841                 $OUT = '';
842                 foreach (postRequestElement('sel') as $networkId => $sel) {
843                         // Is this selected?
844                         if ($sel == 1) {
845                                 // Load this network's data
846                                 $networkData = getNetworkDataById($networkId);
847
848                                 // Do we have found the network?
849                                 if (count($networkData) > 0) {
850                                         if (isFormSent('edit')) {
851                                                 // Add row template for editing
852                                                 $OUT .= loadTemplate('admin_edit_networks_row', true, $networkData);
853                                         } elseif (isFormSent('delete')) {
854                                                 // Add row template for deleting
855                                                 $OUT .= loadTemplate('admin_delete_networks_row', true, $networkData);
856                                         } else {
857                                                 // Problem!
858                                                 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
859                                         }
860                                 } // END - if
861                         } // END - if
862                 } // END - foreach
863
864                 // If we have no rows, we don't need to display the edit form
865                 if (!empty($OUT)) {
866                         // Output main template
867                         if (isFormSent('edit')) {
868                                 loadTemplate('admin_edit_networks', false, $OUT);
869                         } elseif (isFormSent('delete')) {
870                                 loadTemplate('admin_delete_networks', false, $OUT);
871                         } else {
872                                 // Problem!
873                                 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
874                         }
875
876                         // Don't display the list/add new form
877                         $GLOBALS['network_display'] = false;
878                 } else {
879                         // Nothing selected/found
880                         loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_FOUND--}');
881                 }
882         } // END - if
883 }
884
885 // Handle network type form
886 function doAdminNetworkProcessHandleNetworkType () {
887         // Do we have selections?
888         if (ifPostContainsSelections()) {
889                 // Load network data
890                 $networkData = getNetworkDataById(getRequestElement('network'));
891
892                 // Something has been selected, so start displaying one by one
893                 $OUT = '';
894                 foreach (postRequestElement('sel') as $networkId => $sel) {
895                         // Is this selected?
896                         if ($sel == 1) {
897                                 // Load this network's data
898                                 $networkTypeData = getNetworkTypeDataById($networkId);
899
900                                 // Do we have found the network?
901                                 if (count($networkTypeData) > 0) {
902                                         if (isFormSent('edit')) {
903                                                 // Add row template for deleting
904                                                 $OUT .= loadTemplate('admin_edit_network_types_row', true, $networkTypeData);
905                                         } elseif (isFormSent('delete')) {
906                                                 // Add row template for deleting
907                                                 $OUT .= loadTemplate('admin_delete_network_types_row', true, $networkTypeData);
908                                         } else {
909                                                 // Problem!
910                                                 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
911                                         }
912                                 } // END - if
913                         } // END - if
914                 } // END - foreach
915
916                 // If we have no rows, we don't need to display the edit form
917                 if (!empty($OUT)) {
918                         // Output main template
919                         if (isFormSent('edit')) {
920                                 loadTemplate('admin_edit_network_types', false, $OUT);
921                         } elseif (isFormSent('delete')) {
922                                 loadTemplate('admin_delete_network_types', false, $OUT);
923                         } else {
924                                 // Problem!
925                                 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
926                         }
927
928                         // Don't display the list/add new form
929                         $GLOBALS['network_display'] = false;
930                 } else {
931                         // Nothing selected/found
932                         loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPES_NOTHING_FOUND--}');
933                 }
934         } // END - if
935 }
936
937 // Handle network request parameter form
938 function doAdminNetworkProcessHandleRequestParams () {
939         // Do we have selections?
940         if (ifPostContainsSelections()) {
941                 // Init cache array
942                 $GLOBALS['network_params_disabled'] = array();
943
944                 // Load network data
945                 $networkData = getNetworkDataById(getRequestElement('network'));
946
947                 // Something has been selected, so start displaying one by one
948                 $OUT = '';
949                 foreach (postRequestElement('sel') as $networkId => $sel) {
950                         // Is this selected?
951                         if ($sel == 1) {
952                                 // Load this network's data
953                                 $networkRequestData = getNetworkRequestParamsDataById($networkId);
954
955                                 // Do we have found the network?
956                                 if (count($networkRequestData) > 0) {
957                                         if (isFormSent('edit')) {
958                                                 // Add row template for deleting
959                                                 $OUT .= loadTemplate('admin_edit_network_params_row', true, $networkRequestData);
960                                         } elseif (isFormSent('delete')) {
961                                                 // Get type data
962                                                 $networkRequestData['network_type_data'] = getNetworkTypeDataById($networkRequestData['network_type_id']);
963
964                                                 // Add row template for deleting
965                                                 $OUT .= loadTemplate('admin_delete_network_params_row', true, $networkRequestData);
966                                         } else {
967                                                 // Problem!
968                                                 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
969                                         }
970                                 } // END - if
971                         } // END - if
972                 } // END - foreach
973
974                 // If we have no rows, we don't need to display the edit form
975                 if (!empty($OUT)) {
976                         // Output main template
977                         if (isFormSent('edit')) {
978                                 loadTemplate('admin_edit_network_params', false, $OUT);
979                         } elseif (isFormSent('delete')) {
980                                 loadTemplate('admin_delete_network_params', false, $OUT);
981                         } else {
982                                 // Problem!
983                                 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
984                         }
985
986                         // Don't display the list/add new form
987                         $GLOBALS['network_display'] = false;
988                 } else {
989                         // Nothing selected/found
990                         loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_FOUND--}');
991                 }
992         } // END - if
993 }
994
995 // Changes given networks
996 function doAdminNetworkProcessChangeNetwork () {
997         // Do we have selections?
998         if (ifPostContainsSelections()) {
999                 // By default nothing is updated
1000                 $updated = 0;
1001
1002                 // Something has been selected, so start updating them
1003                 foreach (postRequestElement('sel') as $networkId => $sel) {
1004                         // Update this entry?
1005                         if ($sel == 1) {
1006                                 // Init data array
1007                                 $networkData = array();
1008
1009                                 // Transfer whole array, except 'sel'
1010                                 foreach (postRequestArray() as $key => $entry) {
1011                                         // Skip 'sel' and submit button
1012                                         if (in_array($key, array('sel', 'do_edit'))) {
1013                                                 continue;
1014                                         } // END - if
1015
1016                                         // Do we have this enty?
1017                                         if (!isset($entry[$networkId])) {
1018                                                 // Not found, needs fixing
1019                                                 debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1020                                         } // END - if
1021
1022                                         // Add this entry
1023                                         $networkData[$key] = $entry[$networkId];
1024                                 } // END - foreach
1025
1026                                 // Update the network data
1027                                 $updated += doNetworkUpdateDataByArray($networkId, $networkData);
1028                         } // END - if
1029                 } // END - foreach
1030
1031                 // Do we have updates?
1032                 if ($updated > 0) {
1033                         // Updates done
1034                         displayMessage('{%message,ADMIN_NETWORK_UPDATED=' . $updated . '%}');
1035                 } else {
1036                         // Nothing changed
1037                         loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_CHANGED--}');
1038                 }
1039         } // END - if
1040 }
1041
1042 // Removes given networks
1043 function doAdminNetworkProcessRemoveNetwork () {
1044         // Do we have selections?
1045         if (ifPostContainsSelections()) {
1046                 // By default nothing is removed
1047                 $removed = 0;
1048
1049                 // Something has been selected, so start updating them
1050                 foreach (postRequestElement('sel') as $networkId => $sel) {
1051                         // Update this entry?
1052                         if ($sel == 1) {
1053                                 // Remove this entry
1054                                 $removed += doAdminRemoveNetworkEntry('data', 'network_id', $networkId);
1055                         } // END - if
1056                 } // END - foreach
1057
1058                 // Do we have removes?
1059                 if ($removed > 0) {
1060                         // Removals done
1061                         displayMessage('{%message,ADMIN_NETWORK_REMOVED=' . $removed . '%}');
1062                 } else {
1063                         // Nothing removed
1064                         loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_REMOVED--}');
1065                 }
1066         } // END - if
1067 }
1068
1069 // Add a network type handler if not yet found
1070 function doAdminNetworkProcessAddNetworkType () {
1071         // Is the network type handle already used with given network?
1072         if (isNetworkTypeHandleValid(postRequestElement('network_type_handle'), getRequestElement('network'))) {
1073                 // Already added
1074                 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_TYPES_HANDLE_ALREADY_ADDED=' . postRequestElement('network_type_handle') . '%}');
1075
1076                 // ... so abort here
1077                 return false;
1078         } // END - if
1079
1080         // Remove the 'ok' part
1081         unsetPostRequestElement('ok');
1082
1083         // Add id
1084         setPostRequestElement('network_id', bigintval(getRequestElement('network')));
1085
1086         // Is network_type_banner_url set?
1087         if (postRequestElement('network_type_banner_url') == '') {
1088                 // Remove empty value to get a NULL for an optional entry
1089                 unsetPostRequestElement('network_type_banner_url');
1090         } // END - if
1091
1092         // Add the whole request to database
1093         SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_types'), __FUNCTION__, __LINE__);
1094
1095         // Output message
1096         if (!SQL_HASZEROAFFECTED()) {
1097                 // Successfully added
1098                 loadTemplate('admin_network_type_added', false, postRequestArray());
1099         } else {
1100                 // Not added
1101                 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_TYPES_NOT_ADDED=' . postRequestElement('network_type_handle') . '%}');
1102         }
1103 }
1104
1105 // Changes given network type handlers
1106 function doAdminNetworkProcessChangeNetworkType () {
1107         // Do we have selections?
1108         if (ifPostContainsSelections()) {
1109                 // By default nothing is updated
1110                 $updated = 0;
1111
1112                 // Something has been selected, so start updating them
1113                 foreach (postRequestElement('sel') as $networkId => $sel) {
1114                         // Update this entry?
1115                         if ($sel == 1) {
1116                                 // Init data array
1117                                 $networkTypeData = array();
1118
1119                                 // Transfer whole array, except 'sel'
1120                                 foreach (postRequestArray() as $key => $entry) {
1121                                         // Skip 'sel' and submit button
1122                                         if (in_array($key, array('sel', 'do_edit'))) {
1123                                                 continue;
1124                                         } // END - if
1125
1126                                         // Do we have this enty?
1127                                         if (!isset($entry[$networkId])) {
1128                                                 // Not found, needs fixing
1129                                                 debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1130                                         } // END - if
1131
1132                                         // Fix empty network_type_banner_url to NULL
1133                                         if (($key == 'network_type_banner_url') && (trim($entry[$networkId]) == '')) {
1134                                                 // Set it to NULL
1135                                                 $entry[$networkId] = NULL;
1136                                         } // END - if
1137
1138                                         // Add this entry
1139                                         $networkTypeData[$key] = $entry[$networkId];
1140                                 } // END - foreach
1141
1142                                 // Update the network data
1143                                 $updated += doNetworkUpdateTypeByArray($networkId, $networkTypeData);
1144                         } // END - if
1145                 } // END - foreach
1146
1147                 // Do we have updates?
1148                 if ($updated > 0) {
1149                         // Updates done
1150                         displayMessage('{%message,ADMIN_NETWORK_TYPES_UPDATED=' . $updated . '%}');
1151                 } else {
1152                         // Nothing changed
1153                         loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPES_NOTHING_CHANGED--}');
1154                 }
1155         } // END - if
1156 }
1157
1158 // Changes given network request parameters
1159 function doAdminNetworkProcessChangeNetworkParam () {
1160         // Do we have selections?
1161         if (ifPostContainsSelections()) {
1162                 // By default nothing is updated
1163                 $updated = 0;
1164
1165                 // Something has been selected, so start updating them
1166                 foreach (postRequestElement('sel') as $networkId => $sel) {
1167                         // Update this entry?
1168                         if ($sel == 1) {
1169                                 // Init data array
1170                                 $networkParamsData = array();
1171
1172                                 // Transfer whole array, except 'sel'
1173                                 foreach (postRequestArray() as $key => $entry) {
1174                                         // Skip 'sel' and submit button
1175                                         if (in_array($key, array('sel', 'do_edit'))) {
1176                                                 continue;
1177                                         } // END - if
1178
1179                                         // Do we have this enty?
1180                                         if (!isset($entry[$networkId])) {
1181                                                 // Not found, needs fixing
1182                                                 debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1183                                         } // END - if
1184
1185                                         // Fix empty network_request_param_default to NULL
1186                                         if (($key == 'network_request_param_default') && (trim($entry[$networkId]) == '')) {
1187                                                 // Set it to NULL
1188                                                 $entry[$networkId] = NULL;
1189                                         } // END - if
1190
1191                                         // Add this entry
1192                                         $networkParamsData[$key] = $entry[$networkId];
1193                                 } // END - foreach
1194
1195                                 // Update the network data
1196                                 $updated += doNetworkUpdateParamsByArray($networkId, $networkParamsData);
1197                         } // END - if
1198                 } // END - foreach
1199
1200                 // Do we have updates?
1201                 if ($updated > 0) {
1202                         // Updates done
1203                         displayMessage('{%message,ADMIN_NETWORK_REQUEST_PARAMETER_UPDATED=' . $updated . '%}');
1204                 } else {
1205                         // Nothing changed
1206                         loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_CHANGED--}');
1207                 }
1208         } // END - if
1209 }
1210
1211 // Removes given network type handlers
1212 function doAdminNetworkProcessRemoveNetworkType () {
1213         // Do we have selections?
1214         if (ifPostContainsSelections()) {
1215                 // By default nothing is removed
1216                 $removed = 0;
1217
1218                 // Something has been selected, so start updating them
1219                 foreach (postRequestElement('sel') as $networkId => $sel) {
1220                         // Update this entry?
1221                         if ($sel == 1) {
1222                                 // Remove this entry
1223                                 $removed += doAdminRemoveNetworkEntry('types', 'network_type_id', $networkId);
1224                         } // END - if
1225                 } // END - foreach
1226
1227                 // Do we have removes?
1228                 if ($removed > 0) {
1229                         // Removals done
1230                         displayMessage('{%message,ADMIN_NETWORK_TYPES_REMOVED=' . $removed . '%}');
1231                 } else {
1232                         // Nothing removed
1233                         loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPES_NOTHING_REMOVED--}');
1234                 }
1235         } // END - if
1236 }
1237
1238 // Removes given network request parameters
1239 function doAdminNetworkProcessRemoveNetworkParam () {
1240         // Do we have selections?
1241         if (ifPostContainsSelections()) {
1242                 // By default nothing is removed
1243                 $removed = 0;
1244
1245                 // Something has been selected, so start updating them
1246                 foreach (postRequestElement('sel') as $networkId => $sel) {
1247                         // Update this entry?
1248                         if ($sel == 1) {
1249                                 // Remove this entry
1250                                 $removed += doAdminRemoveNetworkEntry('request_params', 'network_param_id', $networkId);
1251                         } // END - if
1252                 } // END - foreach
1253
1254                 // Do we have removes?
1255                 if ($removed > 0) {
1256                         // Removals done
1257                         displayMessage('{%message,ADMIN_NETWORK_REQUEST_PARAMETER_REMOVED=' . $removed . '%}');
1258                 } else {
1259                         // Nothing removed
1260                         loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_REMOVED--}');
1261                 }
1262         } // END - if
1263 }
1264
1265 // Adds a request parameter to given network and type
1266 function doAdminNetworkProcessAddNetworkParam () {
1267         // Is the request parameter already used with given network?
1268         if (isNetworkRequestElementValid(postRequestElement('network_request_param_key'), postRequestElement('network_type_id'), getRequestElement('network'))) {
1269                 // Already added
1270                 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_REQUEST_PARAMETER_ALREADY_ADDED=' . postRequestElement('network_request_param_key') . '%}');
1271
1272                 // ... so abort here
1273                 return false;
1274         } // END - if
1275
1276         // Remove the 'ok' part
1277         unsetPostRequestElement('ok');
1278
1279         // Add id
1280         setPostRequestElement('network_id', bigintval(getRequestElement('network')));
1281
1282         // Is network_request_param_default set?
1283         if (postRequestElement('network_request_param_default') == '') {
1284                 // Remove empty value to get a NULL for an optional entry
1285                 unsetPostRequestElement('network_request_param_default');
1286         } // END - if
1287
1288         // Add the whole request to database
1289         SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_request_params'), __FUNCTION__, __LINE__);
1290
1291         // Output message
1292         if (!SQL_HASZEROAFFECTED()) {
1293                 // Successfully added
1294                 loadTemplate('admin_network_network_request_param_added', false, postRequestArray());
1295         } else {
1296                 // Not added
1297                 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_REQUEST_PARAMETER_NOT_ADDED=' . postRequestElement('network_request_param_key') . '%}');
1298         }
1299 }
1300
1301 // Adds a API response array entry
1302 function doAdminNetworkProcessAddNetworkApiTranslation () {
1303         // Is the request parameter already used with given network?
1304         if (isNetworkApiTranslationValid(postRequestElement('network_api_index'), postRequestElement('network_type_id'), getRequestElement('network'))) {
1305                 // Already added
1306                 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_API_TRANSLATION_ALREADY_ADDED=' . postRequestElement('network_api_index') . '%}');
1307
1308                 // ... so abort here
1309                 return false;
1310         } // END - if
1311
1312         // Remove the 'ok' part
1313         unsetPostRequestElement('ok');
1314
1315         // Add id
1316         setPostRequestElement('network_id', bigintval(getRequestElement('network')));
1317
1318         // Add sorting
1319         setPostRequestElement('sort', (countSumTotalData(
1320                 bigintval(postRequestElement('network_id')),
1321                 'network_api_translation',
1322                 'network_api_id',
1323                 'network_id',
1324                 true,
1325                 sprintf(" AND `network_type_id`=%s", bigintval(postRequestElement('network_type_id')))
1326         ) + 1));
1327
1328         // Add the whole request to database
1329         SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_api_translation'), __FUNCTION__, __LINE__);
1330
1331         // Output message
1332         if (!SQL_HASZEROAFFECTED()) {
1333                 // Successfully added
1334                 loadTemplate('admin_network_api_translation_added', false, postRequestArray());
1335         } else {
1336                 // Not added
1337                 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_API_TRANSLATION_NOT_ADDED=' . postRequestElement('network_api_index') . '%}');
1338         }
1339 }
1340
1341 // Adds/update network API configuration
1342 function doAdminNetworkProcessNetworkApiConfig () {
1343         // Remove the 'ok' part
1344         unsetPostRequestElement('ok');
1345
1346         // Add id
1347         setPostRequestElement('network_id', bigintval(getRequestElement('network')));
1348
1349         // Is network_api_referral_button set?
1350         if (postRequestElement('network_api_referral_button') == '') {
1351                 // Remove empty value to get a NULL for an optional entry
1352                 unsetPostRequestElement('network_api_referral_button');
1353         } // END - if
1354
1355         // Is there already an entry?
1356         if (isNetworkApiConfigured(getRequestElement('network'))) {
1357                 // Generate SQL query
1358                 $SQL = getUpdateSqlFromArray(postRequestArray(), 'network_api_config', 'network_id', postRequestElement('network_id'), array('network_id'));
1359         } else {
1360                 // Insert new entry
1361                 $SQL = getInsertSqlFromArray(postRequestArray(), 'network_api_config');
1362         }
1363
1364         // Run the query
1365         SQL_QUERY($SQL, __FUNCTION__, __LINE__);
1366
1367         // Output message
1368         if (!SQL_HASZEROAFFECTED()) {
1369                 // Successfully added
1370                 displayMessage('{--ADMIN_CONFIG_NETWORK_API_SAVED--}');
1371         } else {
1372                 // Not added
1373                 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_API_NOT_SAVED--}');
1374         }
1375 }
1376
1377 // Do expression code for this extension
1378 function doExpressionNetwork ($data) {
1379         // Construct replacer
1380         $replacer = sprintf(
1381                 "{DQUOTE} . %s(%s, '%s') . {DQUOTE}",
1382                 $data['callback'],
1383                 $data['matches'][4][$data['key']],
1384                 $data['extra_func']
1385         );
1386
1387         // Replace %network% with the current network id
1388         $replacer = str_replace('%network%', getCurrentNetworkId(), $replacer);
1389
1390         // Replace the code
1391         $code = replaceExpressionCode($data, $replacer);
1392
1393         // Return it
1394         return $code;
1395 }
1396
1397 // [EOF]
1398 ?>