2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 11/04/2009 *
4 * =================== Last change: 11/04/2009 *
6 * -------------------------------------------------------------------- *
7 * File : network_functions.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Functions for ext-network *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Funktionen fuer ext-network *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
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 *
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. *
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. *
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, *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
43 // Private setter for current network id
44 function setCurrentNetworkId ($networkId) {
45 $GLOBALS['current_network_id'] = bigintval($networkId);
48 // Private getter for current network id
49 function getCurrentNetworkId () {
50 return $GLOBALS['current_network_id'];
53 // Detects if a supported form has been sent
54 function detectNetworkProcessForm () {
55 // 'do' must be provided in URL
56 if (!isGetRequestElementSet('do')) {
58 debug_report_bug(__FUNCTION__, __LINE__, 'No "do" has been provided. Please fix your templates.');
62 $GLOBALS['network_form_name'] = 'invalid';
64 // Now search all valid
65 foreach (array('ok', 'edit', 'delete', 'do_edit', 'do_delete') as $form) {
67 if (isFormSent($form)) {
69 $GLOBALS['network_form_name'] = $form;
76 // Has the form being detected?
77 if ($GLOBALS['network_form_name'] == 'invalid') {
79 debug_report_bug(__FUNCTION__, __LINE__, 'POST form could not be detected.');
83 // Handle a (maybe) sent form here
84 function doNetworkHandleForm () {
85 // Do we have a form sent?
86 if (countRequestPost() > 0) {
87 // Detect sent POST form
88 detectNetworkProcessForm();
89 } elseif (!isGetRequestElementSet('do')) {
90 // Skip any further requests
94 // Process the request
95 doAdminNetworkProcessForm();
98 // Processes an admin form
99 function doAdminNetworkProcessForm () {
100 // Create function name
101 $functionName = sprintf("doAdminNetworkProcess%s", capitalizeUnderscoreString(getRequestElement('do')));
103 // Is the function valid?
104 if (!function_exists($functionName)) {
105 // Invalid function name
106 debug_report_bug(__FUNCTION__, __LINE__, 'Invalid do ' . getRequestElement('do') . ', function ' . $functionName .' does not exist.', false);
109 // Init global arrays
110 $GLOBALS['network_types_disabled'] = array();
112 // Call-back the method handling our request
113 call_user_func($functionName);
116 // Checks wether the (short) network name is already used (valid)
117 function isNetworkNameValid ($name) {
119 $result = SQL_QUERY_ESC("SELECT `network_id` FROM `{?_MYSQL_PREFIX?}_network_data` WHERE `network_short_name`='%s' LIMIT 1",
120 array($name), __FUNCTION__, __LINE__);
123 $isValid = (SQL_NUMROWS($result) == 1);
126 SQL_FREERESULT($result);
132 // Checks wether the given network type is already used (valid)
133 function isNetworkTypeHandleValid ($type, $networkId) {
135 $result = SQL_QUERY_ESC("SELECT `network_type_id` FROM `{?_MYSQL_PREFIX?}_network_types` WHERE `network_id`=%s AND `network_type_handler`='%s' LIMIT 1",
139 ), __FUNCTION__, __LINE__);
142 $isValid = (SQL_NUMROWS($result) == 1);
145 SQL_FREERESULT($result);
151 // Checks wether the given network request parameter is already used (valid)
152 function isNetworkRequestElementValid ($key, $type, $networkId) {
154 $result = SQL_QUERY_ESC("SELECT `network_request_param_id` FROM `{?_MYSQL_PREFIX?}_network_request_params` WHERE `network_id`=%s AND `network_type_id`=%s AND `network_request_param_key`='%s' LIMIT 1",
159 ), __FUNCTION__, __LINE__);
162 $isValid = (SQL_NUMROWS($result) == 1);
165 SQL_FREERESULT($result);
171 // Checks wether the given network API array translation
172 function isNetworkArrayTranslationValid ($key, $type, $networkId) {
174 $result = SQL_QUERY_ESC("SELECT `network_array_id` FROM `{?_MYSQL_PREFIX?}_network_array_translation` WHERE `network_id`=%s AND `network_type_id`=%s AND `network_array_index`='%s' LIMIT 1",
179 ), __FUNCTION__, __LINE__);
182 $isValid = (SQL_NUMROWS($result) == 1);
185 SQL_FREERESULT($result);
191 // "Getter" for a network's data by provided id number
192 function getNetworkDataById ($networkId, $column = '') {
193 // Ids lower one are not accepted
194 if ($networkId < 1) {
195 // Not good, should be fixed
196 debug_report_bug(__FUNCTION__, __LINE__, 'Network id ' . $networkId . ' is smaller than 1.');
199 // Set current network id
200 setCurrentNetworkId($networkId);
203 if (!isset($GLOBALS['network_data'][$networkId])) {
204 // By default we have no data
205 $GLOBALS['network_data'][$networkId] = array();
207 // Query for the network data
208 $result = SQL_QUERY_ESC("SELECT
210 `network_short_name`,
213 `network_data_separator`,
214 `network_row_separator`,
215 `network_request_type`,
217 `network_require_id_card`,
218 `network_query_amount`
220 `{?_MYSQL_PREFIX?}_network_data`
224 array(bigintval($networkId)), __FUNCTION__, __LINE__);
226 // Do we have an entry?
227 if (SQL_NUMROWS($result) == 1) {
229 $GLOBALS['network_data'][$networkId] = SQL_FETCHARRAY($result);
233 SQL_FREERESULT($result);
237 if (empty($column)) {
239 return $GLOBALS['network_data'][$networkId];
242 return $GLOBALS['network_data'][$networkId][$column];
246 // "Getter" for a network's data by provided type id number
247 function getNetworkDataByTypeId ($networkId, $column = '') {
248 // Ids lower one are not accepted
249 if ($networkId < 1) {
250 // Not good, should be fixed
251 debug_report_bug(__FUNCTION__, __LINE__, 'Network type id ' . $networkId . ' is smaller than 1.');
254 // Set current network id
255 setCurrentNetworkId($networkId);
258 if (!isset($GLOBALS['network_data'][$networkId])) {
259 // By default we have no data
260 $GLOBALS['network_data'][$networkId] = array();
262 // Query for the network data
263 $result = SQL_QUERY_ESC("SELECT
265 d.`network_short_name`,
268 d.`network_data_separator`,
269 d.`network_row_separator`,
270 d.`network_request_type`,
272 d.`network_require_id_card`,
273 d.`network_query_amount`,
274 t.`network_type_handler`,
275 t.`network_type_api_url`,
276 t.`network_type_click_url`,
277 t.`network_type_banner_url`
279 `{?_MYSQL_PREFIX?}_network_data` AS d
281 `{?_MYSQL_PREFIX?}_network_types` AS t
283 d.`network_id`=t.`network_id`
285 t.`network_type_id`=%s
287 array(bigintval($networkId)), __FUNCTION__, __LINE__);
289 // Do we have an entry?
290 if (SQL_NUMROWS($result) == 1) {
292 $GLOBALS['network_data'][$networkId] = SQL_FETCHARRAY($result);
296 SQL_FREERESULT($result);
300 if (empty($column)) {
302 return $GLOBALS['network_data'][$networkId];
305 return $GLOBALS['network_data'][$networkId][$column];
309 // "Getter" for a network type data by provided id number
310 function getNetworkTypeDataById ($networkId) {
311 // Ids lower one are not accepted
312 if ($networkId < 1) {
313 // Not good, should be fixed
314 debug_report_bug(__FUNCTION__, __LINE__, 'Network type id ' . $networkId . ' is smaller than 1.');
317 // By default we have no data
318 $GLOBALS['network_type_data'][$networkId] = array();
320 // Query for the network data
321 $result = SQL_QUERY_ESC('SELECT
324 `network_type_handler`,
325 `network_type_api_url`,
326 `network_type_click_url`,
327 `network_type_banner_url`
329 `{?_MYSQL_PREFIX?}_network_types`
333 array(bigintval($networkId)), __FUNCTION__, __LINE__);
335 // Do we have an entry?
336 if (SQL_NUMROWS($result) == 1) {
338 $GLOBALS['network_type_data'][$networkId] = SQL_FETCHARRAY($result);
342 SQL_FREERESULT($result);
345 return $GLOBALS['network_type_data'][$networkId];
348 // "Getter" for a network request parameter data by provided id number
349 function getNetworkRequestParamsDataById ($networkId) {
350 // Ids lower one are not accepted
351 if ($networkId < 1) {
352 // Not good, should be fixed
353 debug_report_bug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $networkId . ' is smaller than 1.');
356 // By default we have no data
357 $networkRequestData = array();
359 // Query for the network data
360 $result = SQL_QUERY_ESC('SELECT
361 `network_request_param_id`,
364 `network_request_param_key`,
365 `network_request_param_value`,
366 `network_request_param_default`
368 `{?_MYSQL_PREFIX?}_network_request_params`
370 `network_request_param_id`=%s
372 array(bigintval($networkId)), __FUNCTION__, __LINE__);
374 // Do we have an entry?
375 if (SQL_NUMROWS($result) == 1) {
377 $networkRequestData = SQL_FETCHARRAY($result);
381 SQL_FREERESULT($result);
384 return $networkRequestData;
387 // Updates given network (id) with data from array
388 function doNetworkUpdateDataByArray ($networkId, $networkData) {
389 // Ids lower one are not accepted
390 if ($networkId < 1) {
391 // Not good, should be fixed
392 debug_report_bug(__FUNCTION__, __LINE__, 'Network id ' . $networkId . ' is smaller than 1.');
395 // Just call our inner method
396 return adminSaveSettings($networkData, '_network_data', sprintf("`network_id`=%s", bigintval($networkId)), array(), false, false);
399 // Updates given network type handler (id) with data from array
400 function doNetworkUpdateTypeByArray ($networkId, $networkTypeData) {
401 // Ids lower one are not accepted
402 if ($networkId < 1) {
403 // Not good, should be fixed
404 debug_report_bug(__FUNCTION__, __LINE__, 'Network type handler id ' . $networkId . ' is smaller than 1.');
407 // Just call our inner method
408 return adminSaveSettings($networkTypeData, '_network_types', sprintf("`network_type_id`=%s", bigintval($networkId)), array(), false, false);
411 // Updates given network request parameters (id) with data from array
412 function doNetworkUpdateParamsByArray ($networkId, $networkParamData) {
413 // Ids lower one are not accepted
414 if ($networkId < 1) {
415 // Not good, should be fixed
416 debug_report_bug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $networkId . ' is smaller than 1.');
419 // Just call our inner method
420 return adminSaveSettings($networkParamData, '_network_request_params', sprintf("`network_request_param_id`=%s", bigintval($networkId)), array(), false, false);
423 // Removes given network entry
424 function doAdminRemoveNetworkEntry ($table, $column, $networkId, $limit = 1) {
426 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_network_%s` WHERE `%s`=%s LIMIT %s",
432 ), __FUNCTION__, __LINE__);
434 // Return affected rows
435 return SQL_AFFECTEDROWS();
438 // Generates a list of networks for given script and returns it
439 function generateAdminNetworkList () {
443 // Query for all networks
444 $result = SQL_QUERY("SELECT
446 `network_short_name`,
449 `{?_MYSQL_PREFIX?}_network_data`
453 `network_short_name` ASC", __FUNCTION__, __LINE__);
455 // Do we have entries?
456 if (!SQL_HASZERONUMS($result)) {
459 while ($row = SQL_FETCHARRAY($result)) {
460 // Is this valid, then add it
461 if ((is_array($row)) && (isset($row['network_id']))) {
463 $rows[$row['network_id']] = $row;
467 // Generate the selection box
468 $content = generateSelectionBoxFromArray($rows, 'network_id', 'network_id', '', '', 'network');
471 $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}');
475 SQL_FREERESULT($result);
481 // Generator (somewhat getter) for a list of network types for given network id
482 function generateAdminNetworkTypeList ($networkId) {
486 // Query all types of this network
487 $result = SQL_QUERY_ESC('SELECT
489 `network_type_handler`
491 `{?_MYSQL_PREFIX?}_network_types`
495 `network_type_handler` ASC',
497 bigintval($networkId)
498 ), __FUNCTION__, __LINE__);
500 // Do we have entries?
501 if (!SQL_HASZERONUMS($result)) {
504 while ($row = SQL_FETCHARRAY($result)) {
505 // Is this valid, then add it
506 if ((is_array($row)) && (isset($row['network_type_id']))) {
508 $rows[$row['network_type_id']] = $row;
512 // Generate the selection box
513 $content = generateSelectionBoxFromArray($rows, 'network_type', 'network_type_id');
516 $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}');
520 SQL_FREERESULT($result);
526 // Generator (somewhat getter) for a list of network types for all types
527 function generateAdminDistinctNetworkTypeList () {
531 // Query all types of this network
532 $result = SQL_QUERY("SELECT
534 t.`network_type_handler`,
537 `{?_MYSQL_PREFIX?}_network_types` AS t
539 `{?_MYSQL_PREFIX?}_network_data` AS d
541 t.`network_id`=d.`network_id`
543 d.`network_active`='Y'
545 d.`network_short_name` ASC,
546 t.`network_type_handler` ASC", __FUNCTION__, __LINE__);
548 // Do we have entries?
549 if (!SQL_HASZERONUMS($result)) {
552 while ($row = SQL_FETCHARRAY($result)) {
553 // Is this valid, then add it
554 if ((is_array($row)) && (isset($row['network_type_id']))) {
556 $rows[$row['network_type_id']] = $row;
560 // Generate the selection box
561 $content = generateSelectionBoxFromArray($rows, 'network_type', 'network_type_id', '', '_title');
564 $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}');
568 SQL_FREERESULT($result);
569 //* DEBUG: */ die('<pre>'.encodeEntities($content).'</pre>');
575 // Generator (somewhat getter) for network type options
576 function generateNetworkTypeOptions ($networkId) {
577 // Is this an array, then we just came back from edit/delete actions
578 if (is_array($networkId)) {
583 if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
584 // Generate output and cache it
585 $GLOBALS[__FUNCTION__][$networkId] = generateOptionList(
588 'network_type_handler',
592 "WHERE `network_id`=%s",
593 bigintval(getRequestElement('network_id'))
596 'translateNetworkTypeHandler'
601 return $GLOBALS[__FUNCTION__][$networkId];
604 // Generates an options list of all available (hard-coded) handlers
605 function generateNetworkTypesAvailableOptions ($defaultType = NULL) {
607 if (!isset($GLOBALS[__FUNCTION__][$defaultType])) {
609 $GLOBALS[__FUNCTION__][$defaultType] = generateOptionList(
645 $GLOBALS['network_types_disabled'],
646 'translateNetworkTypeHandler'
651 return $GLOBALS[__FUNCTION__][$defaultType];
654 // Generates an options list (somewhat getter) ofr request keys
655 function generateNetworkRequestKeyOptions () {
657 if (!isset($GLOBALS[__FUNCTION__])) {
658 // Generate and cache it
659 $GLOBALS[__FUNCTION__] = generateOptionList(
681 $GLOBALS['network_request_params_disabled'],
682 'translateNetworkRequestParamKey'
687 return $GLOBALS[__FUNCTION__];
690 // Generator (somewhat getter) for (return) array translation
691 function generateNetworkTranslationOptions ($default = '') {
693 if (!isset($GLOBALS[__FUNCTION__][$default])) {
694 // Generate and cache it
695 $GLOBALS[__FUNCTION__][$default] = generateOptionList(
696 'network_translations',
697 'network_translation_id',
698 'network_translation_name',
702 $GLOBALS['network_translation_disabled'],
703 'translateNetworkTranslationName'
708 return $GLOBALS[__FUNCTION__][$default];
711 // Generates an option list of request types
712 function generateNetworkRequestTypeOptions ($default = '') {
714 if (!isset($GLOBALS[__FUNCTION__][$default])) {
716 $GLOBALS[__FUNCTION__][$default] = generateOptionList(
723 '{--ADMIN_NETWORK_REQUEST_TYPE_GET--}',
724 '{--ADMIN_NETWORK_REQUEST_TYPE_POST--}'
731 return $GLOBALS[__FUNCTION__][$default];
734 // Generates an option list of network_api_active
735 function generateNetworkApiActiveOptions ($default = '') {
737 if (!isset($GLOBALS[__FUNCTION__][$default])) {
739 $GLOBALS[__FUNCTION__][$default] = generateYesNoOptionList($default);
743 return $GLOBALS[__FUNCTION__][$default];
746 // Translates 'translate_name' for e.g. templates
747 function translateNetworkTranslationName ($name) {
749 $messageId = 'ADMIN_NETWORK_TRANSLATE_' . strtoupper($name) . '_NAME';
751 // Is the message id there?
752 if (!isMessageIdValid($messageId)) {
754 debug_report_bug(__FUNCTION__, __LINE__, 'type=' . $type . ' is invalid.');
758 return '{--' . $messageId . '--}';
761 // Translates the network type handler (e.g. banner, paidmail) for templates
762 function translateNetworkTypeHandler ($type) {
764 $messageId = 'ADMIN_NETWORK_TYPE_HANDLER_' . strtoupper($type);
766 // Is the message id there?
767 if (!isMessageIdValid($messageId)) {
769 debug_report_bug(__FUNCTION__, __LINE__, 'type=' . $type . ' is invalid.');
773 return '{--' . $messageId . '--}';
776 // Translates request type
777 function translateNetworkRequestType ($type) {
779 $messageId = 'ADMIN_NETWORK_REQUEST_TYPE_' . strtoupper($type) . '';
781 // Is the message id there?
782 if (!isMessageIdValid($messageId)) {
784 debug_report_bug(__FUNCTION__, __LINE__, 'type=' . $type . ' is invalid.');
788 return '{--' . $messageId . '--}';
791 // Translates request parameter
792 function translateNetworkRequestParamKey ($param) {
794 $messageId = 'ADMIN_NETWORK_REQUEST_PARAMETER_' . strtoupper($param) . '';
796 // Is the message id there?
797 if (!isMessageIdValid($messageId)) {
799 debug_report_bug(__FUNCTION__, __LINE__, 'param=' . $param . ' is invalid.');
803 return '{--' . $messageId . '--}';
806 // Translates API index
807 function translateNetworkApiIndex ($index) {
809 if (!isset($GLOBALS['network_array_index'])) {
810 // Get an array of all API array indexes
811 $GLOBALS['network_array_index'] = array();
814 $result = SQL_QUERY('SELECT
816 `network_array_index`,
817 `network_translation_name`
819 `{?_MYSQL_PREFIX?}_network_array_translation`
821 `{?_MYSQL_PREFIX?}_network_translations`
823 `network_array_index`=`network_translation_id`
825 `sort` ASC', __FUNCTION__, __LINE__);
827 // Do we have entries?
828 if (!SQL_HASZERONUMS($result)) {
830 while ($row = SQL_FETCHARRAY($result)) {
831 // Add it to our global array
832 $GLOBALS['network_array_index'][$row['network_array_index']] = $row;
837 SQL_FREERESULT($result);
840 // Default name is unknown
843 // Is the entry there?
844 if (isset($GLOBALS['network_array_index'][$index])) {
846 $name = $GLOBALS['network_array_index'][$index]['network_translation_name'];
849 // Return translation
850 return translateNetworkTranslationName($name);
853 // Translates network API configuration status (see function isNetworkApiConfigured()) by given id
854 function translateNetworkApiConfiguredStatusById ($networkId) {
856 if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
857 // By default it is not configured
858 $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_NOT_CONFIGURED--}';
860 // So is it configured?
861 if (isNetworkApiConfigured($networkId)) {
863 $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_CONFIGURED--}';
868 return $GLOBALS[__FUNCTION__][$networkId];
871 // Checks if the given network is configured by looking its API configuration entry up
872 function isNetworkApiConfigured ($networkId) {
874 if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
875 // Check for an entry in network_api_config
876 $GLOBALS[__FUNCTION__][$networkId] = (countSumTotalData(
877 bigintval($networkId),
878 'network_api_config',
886 return $GLOBALS[__FUNCTION__][$networkId];
889 // Checks wether the given network type handler is configured
890 function isNetworkTypeHandlerConfigured ($networkId, $networkTypeId) {
892 if (!isset($GLOBALS[__FUNCTION__][$networkId][$networkTypeId])) {
894 $GLOBALS[__FUNCTION__][$networkId][$networkTypeId] = (countSumTotalData(
895 bigintval($networkTypeId),
896 'network_types_config',
900 sprintf(' AND `network_id`=%s', bigintval($networkId))
905 return $GLOBALS[__FUNCTION__][$networkId][$networkTypeId];
908 // Handles the network-payment-check request
909 function handleNetworkPaymentCheckRequest () {
910 // @TODO Implement this function
911 debug_report_bug(__FUNCTION__, __LINE__, 'Not yet implemented.');
914 //------------------------------------------------------------------------------
915 // Call-back functions
916 //------------------------------------------------------------------------------
918 // Callback function to add new network
919 function doAdminNetworkProcessAddNetwork () {
920 // We can say here, the form is sent, so check if the network is already added
921 if (isNetworkNameValid(postRequestElement('network_short_name'))) {
923 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_ALREADY_ADDED=' . postRequestElement('network_short_name') . '%}');
927 // Remove the 'ok' part
928 unsetPostRequestElement('ok');
930 // Add the whole request to database
931 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_data'), __FUNCTION__, __LINE__);
933 // Add the id for output only
934 setPostRequestElement('network_id', SQL_INSERTID());
937 if (!SQL_HASZEROAFFECTED()) {
938 // Successfully added
939 loadTemplate('admin_network_added', false, postRequestArray());
942 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_DATA_NOT_ADDED=' . postRequestElement('network_short_name') . '%}');
946 // Displays selected networks for editing
947 function doAdminNetworkProcessHandleNetworks () {
948 // Do we have selections?
949 if (ifPostContainsSelections()) {
950 // Something has been selected, so start displaying one by one
952 foreach (postRequestElement('sel') as $networkId => $sel) {
955 // Load this network's data
956 $networkData = getNetworkDataById($networkId);
958 // Do we have found the network?
959 if (count($networkData) > 0) {
960 // Add row template with given form name
961 $OUT .= loadTemplate('admin_' . $GLOBALS['network_form_name'] . '_networks_row', true, $networkData);
966 // If we have no rows, we don't need to display the edit form
968 // Output main template
969 loadTemplate('admin_' . $GLOBALS['network_form_name'] . '_networks', false, $OUT);
971 // Don't display the list/add new form
972 $GLOBALS['network_display'] = false;
974 // Nothing selected/found
975 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_FOUND--}');
980 // Handle network type form
981 function doAdminNetworkProcessHandleNetworkTypes () {
982 // Do we have selections?
983 if (ifPostContainsSelections()) {
985 $networkData = getNetworkDataById(getRequestElement('network_id'));
987 // Something has been selected, so start displaying one by one
989 foreach (postRequestElement('sel') as $networkId => $sel) {
992 // Load this network's data
993 $networkTypeData = getNetworkTypeDataById($networkId);
995 // Do we have found the network?
996 if (count($networkTypeData) > 0) {
997 if (isFormSent('edit')) {
998 // Add row template for deleting
999 $OUT .= loadTemplate('admin_edit_network_types_row', true, $networkTypeData);
1000 } elseif (isFormSent('delete')) {
1001 // Add row template for deleting
1002 $OUT .= loadTemplate('admin_delete_network_types_row', true, $networkTypeData);
1005 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
1011 // If we have no rows, we don't need to display the edit form
1013 // Output main template
1014 if (isFormSent('edit')) {
1015 loadTemplate('admin_edit_network_types', false, $OUT);
1016 } elseif (isFormSent('delete')) {
1017 loadTemplate('admin_delete_network_types', false, $OUT);
1020 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
1023 // Don't display the list/add new form
1024 $GLOBALS['network_display'] = false;
1026 // Nothing selected/found
1027 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPE_HANDLER_NOTHING_FOUND--}');
1032 // Handle network request parameter form
1033 function doAdminNetworkProcessHandleRequestParams () {
1034 // Do we have selections?
1035 if (ifPostContainsSelections()) {
1037 $GLOBALS['network_request_params_disabled'] = array();
1039 // Load network data
1040 $networkData = getNetworkDataById(getRequestElement('network_id'));
1042 // Something has been selected, so start displaying one by one
1044 foreach (postRequestElement('sel') as $networkId => $sel) {
1045 // Is this selected?
1047 // Load this network's data
1048 $networkRequestData = getNetworkRequestParamsDataById($networkId);
1050 // Do we have found the network?
1051 if (count($networkRequestData) > 0) {
1052 if (isFormSent('edit')) {
1053 // Add row template for deleting
1054 $OUT .= loadTemplate('admin_edit_network_request_params_row', true, $networkRequestData);
1055 } elseif (isFormSent('delete')) {
1057 $networkRequestData['network_type_data'] = getNetworkTypeDataById($networkRequestData['network_type_id']);
1059 // Add row template for deleting
1060 $OUT .= loadTemplate('admin_delete_network_request_params_row', true, $networkRequestData);
1063 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
1069 // If we have no rows, we don't need to display the edit form
1071 // Output main template
1072 if (isFormSent('edit')) {
1073 loadTemplate('admin_edit_network_request_params', false, $OUT);
1074 } elseif (isFormSent('delete')) {
1075 loadTemplate('admin_delete_network_request_params', false, $OUT);
1078 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
1081 // Don't display the list/add new form
1082 $GLOBALS['network_display'] = false;
1084 // Nothing selected/found
1085 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_FOUND--}');
1090 // Changes given networks
1091 function doAdminNetworkProcessChangeNetworks () {
1092 // Do we have selections?
1093 if (ifPostContainsSelections()) {
1094 // By default nothing is updated
1097 // Something has been selected, so start updating them
1098 foreach (postRequestElement('sel') as $networkId => $sel) {
1099 // Update this entry?
1102 $networkData = array();
1104 // Transfer whole array, except 'sel'
1105 foreach (postRequestArray() as $key => $entry) {
1106 // Skip 'sel' and submit button
1107 if (in_array($key, array('sel', 'do_edit'))) {
1111 // Do we have this enty?
1112 if (!isset($entry[$networkId])) {
1113 // Not found, needs fixing
1114 debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1118 $networkData[$key] = $entry[$networkId];
1121 // Update the network data
1122 $updated += doNetworkUpdateDataByArray($networkId, $networkData);
1126 // Do we have updates?
1129 displayMessage('{%message,ADMIN_NETWORK_UPDATED=' . $updated . '%}');
1132 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_CHANGED--}');
1137 // Removes given networks
1138 function doAdminNetworkProcessRemoveNetworks () {
1139 // Do we have selections?
1140 if (ifPostContainsSelections()) {
1141 // By default nothing is removed
1144 // Something has been selected, so start updating them
1145 foreach (postRequestElement('sel') as $networkId => $sel) {
1146 // Update this entry?
1148 // Remove this entry
1149 $removed += doAdminRemoveNetworkEntry('data', 'network_id', $networkId);
1153 // Do we have removes?
1156 displayMessage('{%message,ADMIN_NETWORK_REMOVED=' . $removed . '%}');
1159 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_REMOVED--}');
1164 // Add a network type handler if not yet found
1165 function doAdminNetworkProcessAddNetworkType () {
1166 // Is the network type handle already used with given network?
1167 if (isNetworkTypeHandleValid(postRequestElement('network_type_handler'), getRequestElement('network_id'))) {
1169 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_TYPE_HANDLER_ALREADY_ADDED=' . postRequestElement('network_type_handler') . '%}');
1171 // ... so abort here
1175 // Remove the 'ok' part
1176 unsetPostRequestElement('ok');
1179 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1181 // Is network_type_banner_url set?
1182 if (postRequestElement('network_type_banner_url') == '') {
1183 // Remove empty value to get a NULL for an optional entry
1184 unsetPostRequestElement('network_type_banner_url');
1187 // Add the whole request to database
1188 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_types'), __FUNCTION__, __LINE__);
1191 if (!SQL_HASZEROAFFECTED()) {
1192 // Successfully added
1193 loadTemplate('admin_network_type_added', false, postRequestArray());
1196 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_TYPE_HANDLER_NOT_ADDED=' . postRequestElement('network_type_handler') . '%}');
1200 // Changes given network type handlers
1201 function doAdminNetworkProcessChangeHandlerTypes () {
1202 // Do we have selections?
1203 if (ifPostContainsSelections()) {
1204 // By default nothing is updated
1207 // Something has been selected, so start updating them
1208 foreach (postRequestElement('sel') as $networkId => $sel) {
1209 // Update this entry?
1212 $networkTypeData = array();
1214 // Transfer whole array, except 'sel'
1215 foreach (postRequestArray() as $key => $entry) {
1216 // Skip 'sel' and submit button
1217 if (in_array($key, array('sel', 'do_edit'))) {
1221 // Do we have this enty?
1222 if (!isset($entry[$networkId])) {
1223 // Not found, needs fixing
1224 debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1227 // Fix empty network_type_banner_url to NULL
1228 if (($key == 'network_type_banner_url') && (trim($entry[$networkId]) == '')) {
1230 $entry[$networkId] = NULL;
1234 $networkTypeData[$key] = $entry[$networkId];
1237 // Update the network data
1238 $updated += doNetworkUpdateTypeByArray($networkId, $networkTypeData);
1242 // Do we have updates?
1245 displayMessage('{%message,ADMIN_NETWORK_TYPE_HANDLER_UPDATED=' . $updated . '%}');
1248 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPE_HANDLER_NOTHING_CHANGED--}');
1253 // Changes given network request parameters
1254 function doAdminNetworkProcessChangeRequestParams () {
1255 // Do we have selections?
1256 if (ifPostContainsSelections()) {
1257 // By default nothing is updated
1260 // Something has been selected, so start updating them
1261 foreach (postRequestElement('sel') as $networkId => $sel) {
1262 // Update this entry?
1265 $networkParamsData = array();
1267 // Transfer whole array, except 'sel'
1268 foreach (postRequestArray() as $key => $entry) {
1269 // Skip 'sel' and submit button
1270 if (in_array($key, array('sel', 'do_edit'))) {
1274 // Do we have this enty?
1275 if (!isset($entry[$networkId])) {
1276 // Not found, needs fixing
1277 debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1280 // Fix empty network_request_param_default to NULL
1281 if (($key == 'network_request_param_default') && (trim($entry[$networkId]) == '')) {
1283 $entry[$networkId] = NULL;
1287 $networkParamsData[$key] = $entry[$networkId];
1290 // Update the network data
1291 $updated += doNetworkUpdateParamsByArray($networkId, $networkParamsData);
1295 // Do we have updates?
1298 displayMessage('{%message,ADMIN_NETWORK_REQUEST_PARAMETER_UPDATED=' . $updated . '%}');
1301 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_CHANGED--}');
1306 // Removes given network type handlers
1307 function doAdminNetworkProcessRemoveNetworkTypes () {
1308 // Do we have selections?
1309 if (ifPostContainsSelections()) {
1310 // By default nothing is removed
1313 // Something has been selected, so start updating them
1314 foreach (postRequestElement('sel') as $networkId => $sel) {
1315 // Update this entry?
1317 // Remove this entry
1318 $removed += doAdminRemoveNetworkEntry('types', 'network_type_id', $networkId);
1322 // Do we have removes?
1325 displayMessage('{%message,ADMIN_NETWORK_TYPE_HANDLER_REMOVED=' . $removed . '%}');
1328 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPE_HANDLER_NOTHING_REMOVED--}');
1333 // Removes given network request parameters
1334 function doAdminNetworkProcessRemoveNetworkRequestParams () {
1335 // Do we have selections?
1336 if (ifPostContainsSelections()) {
1337 // By default nothing is removed
1340 // Something has been selected, so start updating them
1341 foreach (postRequestElement('sel') as $networkId => $sel) {
1342 // Update this entry?
1344 // Remove this entry
1345 $removed += doAdminRemoveNetworkEntry('request_params', 'network_request_param_id', $networkId);
1349 // Do we have removes?
1352 displayMessage('{%message,ADMIN_NETWORK_REQUEST_PARAMETER_REMOVED=' . $removed . '%}');
1355 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_REMOVED--}');
1360 // Adds a request parameter to given network and type
1361 function doAdminNetworkProcessAddRequestParam () {
1362 // Is the request parameter already used with given network?
1363 if (isNetworkRequestElementValid(postRequestElement('network_request_param_key'), postRequestElement('network_type_id'), getRequestElement('network_id'))) {
1365 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_REQUEST_PARAMETER_ALREADY_ADDED=' . postRequestElement('network_request_param_key') . '%}');
1367 // ... so abort here
1371 // Remove the 'ok' part
1372 unsetPostRequestElement('ok');
1375 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1377 // Is network_request_param_default set?
1378 if (postRequestElement('network_request_param_default') == '') {
1379 // Remove empty value to get a NULL for an optional entry
1380 unsetPostRequestElement('network_request_param_default');
1383 // Add the whole request to database
1384 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_request_params'), __FUNCTION__, __LINE__);
1387 if (!SQL_HASZEROAFFECTED()) {
1388 // Successfully added
1389 loadTemplate('admin_network_request_param_added', false, postRequestArray());
1392 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_REQUEST_PARAMETER_NOT_ADDED=' . postRequestElement('network_request_param_key') . '%}');
1396 // Adds a API response array entry
1397 function doAdminNetworkProcessAddNetworkArrayTranslation () {
1398 // Is the request parameter already used with given network?
1399 if (isNetworkArrayTranslationValid(postRequestElement('network_array_index'), postRequestElement('network_type_id'), getRequestElement('network_id'))) {
1401 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_ARRAY_TRANSLATION_ALREADY_ADDED=' . postRequestElement('network_array_index') . '%}');
1403 // ... so abort here
1407 // Remove the 'ok' part
1408 unsetPostRequestElement('ok');
1411 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1414 setPostRequestElement('sort', (countSumTotalData(
1415 bigintval(postRequestElement('network_id')),
1416 'network_array_translation',
1420 sprintf(" AND `network_type_id`=%s", bigintval(postRequestElement('network_type_id')))
1423 // Add the whole request to database
1424 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_array_translation'), __FUNCTION__, __LINE__);
1427 if (!SQL_HASZEROAFFECTED()) {
1428 // Successfully added
1429 loadTemplate('admin_network_array_translation_added', false, postRequestArray());
1432 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_ARRAY_TRANSLATION_NOT_ADDED=' . postRequestElement('network_array_index') . '%}');
1436 // Adds/update network API configuration
1437 function doAdminNetworkProcessNetworkApiConfig () {
1438 // Remove the 'ok' part
1439 unsetPostRequestElement('ok');
1442 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1444 // Is network_api_referral_button set?
1445 if (postRequestElement('network_api_referral_button') == '') {
1446 // Remove empty value to get a NULL for an optional entry
1447 unsetPostRequestElement('network_api_referral_button');
1450 // Is there already an entry?
1451 if (isNetworkApiConfigured(getRequestElement('network_id'))) {
1452 // Generate SQL query
1453 $SQL = getUpdateSqlFromArray(postRequestArray(), 'network_api_config', 'network_id', postRequestElement('network_id'), array('network_id'));
1456 $SQL = getInsertSqlFromArray(postRequestArray(), 'network_api_config');
1460 SQL_QUERY($SQL, __FUNCTION__, __LINE__);
1463 if (!SQL_HASZEROAFFECTED()) {
1464 // Successfully added
1465 displayMessage('{--ADMIN_CONFIG_NETWORK_API_SAVED--}');
1468 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_API_NOT_SAVED--}');
1472 // Only adds network type configuration if not yet present
1473 function doAdminNetworkProcessAddHandlerTypesConfig ($displayMessage = true) {
1474 // Remove the 'ok' part
1475 unsetPostRequestElement('ok');
1478 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1479 setPostRequestElement('network_type_id', bigintval(getRequestElement('network_type_id')));
1482 * Some parameters are optional, at least one must be given so check a bunch
1485 foreach (array('network_min_waiting_time', 'network_min_remain_clicks', 'network_min_payment', 'network_allow_erotic') as $element) {
1486 // Is this element empty?
1487 if (postRequestElement($element) == '') {
1488 // Then unset it to get a NULL for optional parameter
1489 unsetPostRequestElement($element);
1493 // Initialize variables
1495 $id = 'network_max_reload_time_ye';
1498 // Get all POST data
1499 $postData = postRequestArray();
1501 // Convert "reload time selections"
1502 convertSelectionsToEpocheTime($postData, $content, $id, $skip);
1504 // Set the POST array back
1505 setPostRequestArray($postData);
1507 // Is there already an entry?
1508 if (isNetworkTypeHandlerConfigured(getRequestElement('network_id'), getRequestElement('network_type_id'))) {
1509 // This network type handler is already configured
1510 displayMessage('{--ADMIN_NETWORK_HANDLER_TYPE_HANDLER_ALREADY_CONFIGURED--}');
1514 // Copy 'set all' and remove it from POST data
1515 $setAll = (postRequestElement('set_all') === 'Y');
1516 unsetPostRequestElement('set_all');
1518 // Shall we set for all?
1519 if ($setAll === true) {
1521 $result = SQL_QUERY_ESC('SELECT `network_type_id` FROM `{?_MYSQL_PREFIX?}_network_types` WHERE `network_id`=%s ORDER BY `network_type_id` ASC',
1522 array(bigintval(getRequestElement('network_id'))), __FUNCTION__, __LINE__);
1524 // Do we have entries?
1525 if (SQL_HASZERONUMS($result)) {
1526 // No, then abort here
1527 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_SET_ALL_404--}');
1531 // Init number of rows
1535 while (list($typeId) = SQL_FETCHROW($result)) {
1536 // Set it in GET data
1537 setGetRequestElement('network_type_id', $typeId);
1539 // Call this function again
1540 $numRows += doAdminNetworkProcessAddHandlerTypesConfig(false);
1544 SQL_FREERESULT($result);
1548 // Something has been updated
1549 displayMessage('{%message,ADMIN_CONFIG_NETWORK_HANDLER_TYPE_ALL_HANDLER_SAVED=' . bigintval($numRows) . '%}');
1551 // Nothing has been saved
1552 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}');
1555 // Get SQL query for new entry
1556 $SQL = getInsertSqlFromArray(postRequestArray(), 'network_types_config');
1559 SQL_QUERY($SQL, __FUNCTION__, __LINE__);
1561 // Shall we display the message?
1562 if ($displayMessage === true) {
1564 if (!SQL_HASZEROAFFECTED()) {
1565 // Successfully added
1566 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_SAVED--}');
1569 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_SAVED--}');
1572 // Return amount of affected rows (1 or 2)
1573 return SQL_AFFECTEDROWS();
1578 // Only changes network type configuration if not yet present
1579 function doAdminNetworkProcessEditHandlerTypesConfig ($displayMessage = true) {
1580 // Remove the 'ok' part
1581 unsetPostRequestElement('ok');
1584 * Some parameters are optional, at least one must be given so check a bunch
1587 foreach (array('network_min_waiting_time', 'network_min_remain_clicks', 'network_min_payment', 'network_allow_erotic') as $element) {
1588 // Is this element empty?
1589 if (postRequestElement($element) == '') {
1590 // Then unset it to get a NULL for optional parameter
1591 unsetPostRequestElement($element);
1595 // Initialize variables
1597 $id = 'network_max_reload_time_ye';
1599 $postData = postRequestArray();
1601 // Convert "reload time selections"
1602 convertSelectionsToEpocheTime($postData, $content, $id, $skip);
1604 // Set the POST array back
1605 setPostRequestArray($postData);
1607 // Is there already an entry?
1608 if (!isNetworkTypeHandlerConfigured(getRequestElement('network_id'), getRequestElement('network_type_id'))) {
1609 // This network type handler is not configured
1610 displayMessage('{--ADMIN_NETWORK_HANDLER_TYPE_HANDLER_NOT_CONFIGURED--}');
1614 // Copy 'set all' and remove it from POST data
1615 $setAll = (postRequestElement('set_all') === 'Y');
1616 unsetPostRequestElement('set_all');
1618 // Shall we set for all?
1619 if ($setAll === true) {
1620 // Get all data entries
1621 $result = SQL_QUERY_ESC('SELECT `network_data_id` FROM `{?_MYSQL_PREFIX?}_network_types_config` WHERE `network_id`=%s ORDER BY `network_type_id` ASC',
1622 array(bigintval(getRequestElement('network_id'))), __FUNCTION__, __LINE__);
1624 // Do we have entries?
1625 if (SQL_HASZERONUMS($result)) {
1626 // No, then abort here
1627 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_SET_ALL_404--}');
1631 // Init number of rows
1635 while (list($dataId) = SQL_FETCHROW($result)) {
1636 // Set it in GET data
1637 setPostRequestElement('network_data_id', $dataId);
1639 // Call this function again
1640 $numRows += doAdminNetworkProcessEditHandlerTypesConfig(false);
1644 SQL_FREERESULT($result);
1648 // Something has been updated
1649 displayMessage('{%message,ADMIN_CONFIG_NETWORK_HANDLER_TYPE_ALL_HANDLER_SAVED=' . bigintval($numRows) . '%}');
1651 // Nothing has been saved
1652 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}');
1655 // Get SQL query for new entry
1656 $SQL = getUpdateSqlFromArray(postRequestArray(), 'network_types_config', 'network_data_id', postRequestElement('network_data_id'), array('network_data_id'));
1659 SQL_QUERY($SQL, __FUNCTION__, __LINE__);
1661 // Shall we display the message?
1662 if ($displayMessage === true) {
1664 if (!SQL_HASZEROAFFECTED()) {
1665 // Successfully added
1666 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_SAVED--}');
1669 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}');
1672 // Return amount of affected rows (1 or 2)
1673 return SQL_AFFECTEDROWS();
1678 // Do expression code for this extension
1679 function doExpressionNetwork ($data) {
1680 // Construct replacer
1681 $replacer = sprintf(
1682 "{DQUOTE} . %s(%s, '%s') . {DQUOTE}",
1684 $data['matches'][4][$data['key']],
1688 // Replace %network_id% with the current network id
1689 $replacer = str_replace('%network_id%', getCurrentNetworkId(), $replacer);
1692 $code = replaceExpressionCode($data, $replacer);
1698 // ----------------------------------------------------------------------------
1699 // Call-back functions for exporting data
1700 // ----------------------------------------------------------------------------
1702 // Callback function to export network tables
1703 function doAdminNetworkProcessExport () {
1704 // Init table with all valid what->table entries
1705 $validExports = array(
1706 // General network data
1707 'list_networks' => 'network_data',
1708 // Network type handler
1709 'list_network_types' => 'network_types',
1710 // Network request parameter
1711 'list_network_request_params' => 'network_request_params',
1712 // Network API response array index translation
1713 'list_network_array_translation' => 'network_array_translation',
1716 // Is the 'what' key valid?
1717 if (!isset($validExports[getWhat()])) {
1719 debug_report_bug(__FUNCTION__, __LINE__, 'what=' . getWhat() . ' - not supported');
1722 // Generate call-back, some tables require to export not all columns
1723 $callbackName = 'doAdminNetworkExport' . capitalizeUnderscoreString($validExports[getWhat()]);
1725 // Is the call-back function there?
1726 if (!function_exists($callbackName)) {
1727 // No, this is really bad
1728 debug_report_bug(__FUNCTION__, __LINE__, 'Invalid call-back function ' . $callbackName . ' detected.');
1729 } elseif (isset($GLOBALS[__FUNCTION__][$callbackName])) {
1731 debug_report_bug(__FUNCTION__, __LINE__, 'Double-call of export function ' . $callbackName . ' detected.');
1734 // Call the function
1735 call_user_func($callbackName);
1737 // Mark it as called
1738 $GLOBALS[__FUNCTION__][$callbackName] = true;
1740 // Don't display the list/add new form
1741 $GLOBALS['network_display'] = false;
1744 // Exports (and displays) the table 'network_data'
1745 function doAdminNetworkExportNetworkData () {
1746 // Query for all networks
1747 $result = SQL_QUERY('SELECT
1748 `network_short_name`,
1751 `network_data_separator`,
1752 `network_row_separator`,
1753 `network_request_type`,
1755 `network_require_id_card`,
1756 `network_query_amount`,
1759 `{?_MYSQL_PREFIX?}_network_data`
1762 __FUNCTION__, __LINE__);
1764 // Start an empty SQL query
1765 $SQL = "INSERT INTO `{?_MYSQL_PREFIX?}_network_data` (`network_short_name`,`network_title`,`network_reflink`,`network_data_separator`,`network_row_separator`,`network_request_type`,`network_charset`,`network_require_id_card`,`network_query_amount`,`network_active`) VALUES\n";
1768 while ($content = SQL_FETCHARRAY($result)) {
1771 $content['network_short_name'] . "', '" .
1772 $content['network_title'] . "', '" .
1773 $content['network_reflink'] . "', '" .
1774 $content['network_data_separator'] . "', '" .
1775 $content['network_row_separator'] . "', '" .
1776 $content['network_request_type'] . "', '" .
1777 $content['network_charset'] . "', '" .
1778 $content['network_require_id_card'] . "', " .
1779 $content['network_query_amount'] . ", '" .
1780 $content['network_active'] . "'),\n";
1783 // Remove last commata and close braces
1784 $SQL = substr($SQL, 0, -2);
1787 SQL_FREERESULT($result);
1789 // Output the SQL query
1790 loadTemplate('admin_export_network_data', false, $SQL);
1793 // Exports (and displays) the table 'network_types'
1794 function doAdminNetworkExportNetworkTypes () {
1795 // 'network_id' must be set
1796 if (!isGetRequestElementSet('network_id')) {
1797 // Only network handlers of one network will be exported per time
1798 debug_report_bug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
1801 // Get all network types of given network
1802 $result = SQL_QUERY_ESC('SELECT
1805 `network_type_handler`,
1806 `network_type_api_url`,
1807 `network_type_click_url`,
1808 `network_type_banner_url`,
1809 `network_type_reload_time_unit`
1811 `{?_MYSQL_PREFIX?}_network_types`
1815 `network_type_id` ASC',
1817 bigintval(getRequestElement('network_id'))
1818 ), __FUNCTION__, __LINE__);
1820 // Start an empty SQL query
1821 $SQL = "INSERT INTO `{?_MYSQL_PREFIX?}_network_types` (`network_type_id`,`network_id`,`network_type_handler`,`network_type_api_url`,`network_type_click_url`,`network_type_banner_url`,`network_type_reload_time_unit`) VALUES\n";
1824 while ($content = SQL_FETCHARRAY($result)) {
1827 $content['network_type_id'] . ', ' .
1828 $content['network_id'] . ", '" .
1829 $content['network_type_handler'] . "', '" .
1830 $content['network_type_api_url'] . "', '" .
1831 $content['network_type_click_url'] . "', ";
1833 // Is the column NULL?
1834 if (is_null($content['network_type_banner_url'])) {
1839 $SQL .= "'" . $content['network_type_banner_url'] . "'";
1843 $SQL .= ",'" . $content['network_type_reload_time_unit'] . "'),\n";
1846 // Remove last commata and close braces
1847 $SQL = substr($SQL, 0, -2);
1850 SQL_FREERESULT($result);
1852 // Output the SQL query
1853 loadTemplate('admin_export_network_types', false, $SQL);
1856 // Exports (and displays) the table 'network_request_params'
1857 function doAdminNetworkExportNetworkRequestParams () {
1858 // 'network_id' must be set
1859 if (!isGetRequestElementSet('network_id')) {
1860 // Only network request parameters of one network will be exported per time
1861 debug_report_bug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
1864 // Get all network types of given network
1865 $result = SQL_QUERY_ESC('SELECT
1868 `network_request_param_key`,
1869 `network_request_param_value`,
1870 `network_request_param_default`
1872 `{?_MYSQL_PREFIX?}_network_request_params`
1876 `network_type_id` ASC ,
1877 `network_request_param_id` ASC',
1879 bigintval(getRequestElement('network_id'))
1880 ), __FUNCTION__, __LINE__);
1882 // Start an empty SQL query
1883 $SQL = "INSERT INTO `{?_MYSQL_PREFIX?}_network_request_params` (`network_id`,`network_type_id`,`network_request_param_key`,`network_request_param_value`,`network_request_param_default`) VALUES\n";
1886 while ($content = SQL_FETCHARRAY($result)) {
1889 $content['network_id'] . ', ' .
1890 $content['network_type_id'] . ", '" .
1891 $content['network_request_param_key'] . "', '" .
1892 $content['network_request_param_value'] . "', ";
1894 // Is the column NULL?
1895 if (is_null($content['network_request_param_default'])) {
1900 $SQL .= "'" . $content['network_request_param_default'] . "'),\n";
1904 // Remove last commata and close braces
1905 $SQL = substr($SQL, 0, -2);
1908 SQL_FREERESULT($result);
1910 // Output the SQL query
1911 loadTemplate('admin_export_network_request_params', false, $SQL);
1914 // Exports (and displays) the table 'network_array_translation'
1915 function doAdminNetworkExportNetworkArrayTranslation () {
1916 // 'network_id' must be set
1917 if (!isGetRequestElementSet('network_id')) {
1918 // Only network API array index translations of one network will be exported per time
1919 debug_report_bug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
1922 // Get all network types of given network
1923 $result = SQL_QUERY_ESC('SELECT
1926 `network_array_index`,
1929 `{?_MYSQL_PREFIX?}_network_array_translation`
1933 `network_type_id` ASC,
1936 bigintval(getRequestElement('network_id'))
1937 ), __FUNCTION__, __LINE__);
1939 // Start an empty SQL query
1940 $SQL = "INSERT INTO `{?_MYSQL_PREFIX?}_network_array_translation` (`network_id`,`network_type_id`,`network_array_index`,`sort`) VALUES\n";
1943 while ($content = SQL_FETCHARRAY($result)) {
1946 $content['network_id'] . ', ' .
1947 $content['network_type_id'] . ', ' .
1948 $content['network_array_index'] . ', ' .
1949 $content['sort'] . "),\n";
1952 // Remove last commata and close braces
1953 $SQL = substr($SQL, 0, -2);
1956 SQL_FREERESULT($result);
1958 // Output the SQL query
1959 loadTemplate('admin_export_network_array_translation', false, $SQL);