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