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 //------------------------------------------------------------------------------
909 // Call-back functions
910 //------------------------------------------------------------------------------
912 // Callback function to add new network
913 function doAdminNetworkProcessAddNetwork () {
914 // We can say here, the form is sent, so check if the network is already added
915 if (isNetworkNameValid(postRequestElement('network_short_name'))) {
917 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_ALREADY_ADDED=' . postRequestElement('network_short_name') . '%}');
921 // Remove the 'ok' part
922 unsetPostRequestElement('ok');
924 // Add the whole request to database
925 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_data'), __FUNCTION__, __LINE__);
927 // Add the id for output only
928 setPostRequestElement('network_id', SQL_INSERTID());
931 if (!SQL_HASZEROAFFECTED()) {
932 // Successfully added
933 loadTemplate('admin_network_added', false, postRequestArray());
936 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_DATA_NOT_ADDED=' . postRequestElement('network_short_name') . '%}');
940 // Displays selected networks for editing
941 function doAdminNetworkProcessHandleNetworks () {
942 // Do we have selections?
943 if (ifPostContainsSelections()) {
944 // Something has been selected, so start displaying one by one
946 foreach (postRequestElement('sel') as $networkId => $sel) {
949 // Load this network's data
950 $networkData = getNetworkDataById($networkId);
952 // Do we have found the network?
953 if (count($networkData) > 0) {
954 // Add row template with given form name
955 $OUT .= loadTemplate('admin_' . $GLOBALS['network_form_name'] . '_networks_row', true, $networkData);
960 // If we have no rows, we don't need to display the edit form
962 // Output main template
963 loadTemplate('admin_' . $GLOBALS['network_form_name'] . '_networks', false, $OUT);
965 // Don't display the list/add new form
966 $GLOBALS['network_display'] = false;
968 // Nothing selected/found
969 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_FOUND--}');
974 // Handle network type form
975 function doAdminNetworkProcessHandleNetworkTypes () {
976 // Do we have selections?
977 if (ifPostContainsSelections()) {
979 $networkData = getNetworkDataById(getRequestElement('network_id'));
981 // Something has been selected, so start displaying one by one
983 foreach (postRequestElement('sel') as $networkId => $sel) {
986 // Load this network's data
987 $networkTypeData = getNetworkTypeDataById($networkId);
989 // Do we have found the network?
990 if (count($networkTypeData) > 0) {
991 if (isFormSent('edit')) {
992 // Add row template for deleting
993 $OUT .= loadTemplate('admin_edit_network_types_row', true, $networkTypeData);
994 } elseif (isFormSent('delete')) {
995 // Add row template for deleting
996 $OUT .= loadTemplate('admin_delete_network_types_row', true, $networkTypeData);
999 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
1005 // If we have no rows, we don't need to display the edit form
1007 // Output main template
1008 if (isFormSent('edit')) {
1009 loadTemplate('admin_edit_network_types', false, $OUT);
1010 } elseif (isFormSent('delete')) {
1011 loadTemplate('admin_delete_network_types', false, $OUT);
1014 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
1017 // Don't display the list/add new form
1018 $GLOBALS['network_display'] = false;
1020 // Nothing selected/found
1021 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPE_HANDLER_NOTHING_FOUND--}');
1026 // Handle network request parameter form
1027 function doAdminNetworkProcessHandleRequestParams () {
1028 // Do we have selections?
1029 if (ifPostContainsSelections()) {
1031 $GLOBALS['network_request_params_disabled'] = array();
1033 // Load network data
1034 $networkData = getNetworkDataById(getRequestElement('network_id'));
1036 // Something has been selected, so start displaying one by one
1038 foreach (postRequestElement('sel') as $networkId => $sel) {
1039 // Is this selected?
1041 // Load this network's data
1042 $networkRequestData = getNetworkRequestParamsDataById($networkId);
1044 // Do we have found the network?
1045 if (count($networkRequestData) > 0) {
1046 if (isFormSent('edit')) {
1047 // Add row template for deleting
1048 $OUT .= loadTemplate('admin_edit_network_request_params_row', true, $networkRequestData);
1049 } elseif (isFormSent('delete')) {
1051 $networkRequestData['network_type_data'] = getNetworkTypeDataById($networkRequestData['network_type_id']);
1053 // Add row template for deleting
1054 $OUT .= loadTemplate('admin_delete_network_request_params_row', true, $networkRequestData);
1057 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
1063 // If we have no rows, we don't need to display the edit form
1065 // Output main template
1066 if (isFormSent('edit')) {
1067 loadTemplate('admin_edit_network_request_params', false, $OUT);
1068 } elseif (isFormSent('delete')) {
1069 loadTemplate('admin_delete_network_request_params', false, $OUT);
1072 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
1075 // Don't display the list/add new form
1076 $GLOBALS['network_display'] = false;
1078 // Nothing selected/found
1079 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_FOUND--}');
1084 // Changes given networks
1085 function doAdminNetworkProcessChangeNetworks () {
1086 // Do we have selections?
1087 if (ifPostContainsSelections()) {
1088 // By default nothing is updated
1091 // Something has been selected, so start updating them
1092 foreach (postRequestElement('sel') as $networkId => $sel) {
1093 // Update this entry?
1096 $networkData = array();
1098 // Transfer whole array, except 'sel'
1099 foreach (postRequestArray() as $key => $entry) {
1100 // Skip 'sel' and submit button
1101 if (in_array($key, array('sel', 'do_edit'))) {
1105 // Do we have this enty?
1106 if (!isset($entry[$networkId])) {
1107 // Not found, needs fixing
1108 debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1112 $networkData[$key] = $entry[$networkId];
1115 // Update the network data
1116 $updated += doNetworkUpdateDataByArray($networkId, $networkData);
1120 // Do we have updates?
1123 displayMessage('{%message,ADMIN_NETWORK_UPDATED=' . $updated . '%}');
1126 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_CHANGED--}');
1131 // Removes given networks
1132 function doAdminNetworkProcessRemoveNetworks () {
1133 // Do we have selections?
1134 if (ifPostContainsSelections()) {
1135 // By default nothing is removed
1138 // Something has been selected, so start updating them
1139 foreach (postRequestElement('sel') as $networkId => $sel) {
1140 // Update this entry?
1142 // Remove this entry
1143 $removed += doAdminRemoveNetworkEntry('data', 'network_id', $networkId);
1147 // Do we have removes?
1150 displayMessage('{%message,ADMIN_NETWORK_REMOVED=' . $removed . '%}');
1153 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_REMOVED--}');
1158 // Add a network type handler if not yet found
1159 function doAdminNetworkProcessAddNetworkType () {
1160 // Is the network type handle already used with given network?
1161 if (isNetworkTypeHandleValid(postRequestElement('network_type_handler'), getRequestElement('network_id'))) {
1163 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_TYPE_HANDLER_ALREADY_ADDED=' . postRequestElement('network_type_handler') . '%}');
1165 // ... so abort here
1169 // Remove the 'ok' part
1170 unsetPostRequestElement('ok');
1173 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1175 // Is network_type_banner_url set?
1176 if (postRequestElement('network_type_banner_url') == '') {
1177 // Remove empty value to get a NULL for an optional entry
1178 unsetPostRequestElement('network_type_banner_url');
1181 // Add the whole request to database
1182 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_types'), __FUNCTION__, __LINE__);
1185 if (!SQL_HASZEROAFFECTED()) {
1186 // Successfully added
1187 loadTemplate('admin_network_type_added', false, postRequestArray());
1190 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_TYPE_HANDLER_NOT_ADDED=' . postRequestElement('network_type_handler') . '%}');
1194 // Changes given network type handlers
1195 function doAdminNetworkProcessChangeHandlerTypes () {
1196 // Do we have selections?
1197 if (ifPostContainsSelections()) {
1198 // By default nothing is updated
1201 // Something has been selected, so start updating them
1202 foreach (postRequestElement('sel') as $networkId => $sel) {
1203 // Update this entry?
1206 $networkTypeData = array();
1208 // Transfer whole array, except 'sel'
1209 foreach (postRequestArray() as $key => $entry) {
1210 // Skip 'sel' and submit button
1211 if (in_array($key, array('sel', 'do_edit'))) {
1215 // Do we have this enty?
1216 if (!isset($entry[$networkId])) {
1217 // Not found, needs fixing
1218 debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1221 // Fix empty network_type_banner_url to NULL
1222 if (($key == 'network_type_banner_url') && (trim($entry[$networkId]) == '')) {
1224 $entry[$networkId] = NULL;
1228 $networkTypeData[$key] = $entry[$networkId];
1231 // Update the network data
1232 $updated += doNetworkUpdateTypeByArray($networkId, $networkTypeData);
1236 // Do we have updates?
1239 displayMessage('{%message,ADMIN_NETWORK_TYPE_HANDLER_UPDATED=' . $updated . '%}');
1242 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPE_HANDLER_NOTHING_CHANGED--}');
1247 // Changes given network request parameters
1248 function doAdminNetworkProcessChangeRequestParams () {
1249 // Do we have selections?
1250 if (ifPostContainsSelections()) {
1251 // By default nothing is updated
1254 // Something has been selected, so start updating them
1255 foreach (postRequestElement('sel') as $networkId => $sel) {
1256 // Update this entry?
1259 $networkParamsData = array();
1261 // Transfer whole array, except 'sel'
1262 foreach (postRequestArray() as $key => $entry) {
1263 // Skip 'sel' and submit button
1264 if (in_array($key, array('sel', 'do_edit'))) {
1268 // Do we have this enty?
1269 if (!isset($entry[$networkId])) {
1270 // Not found, needs fixing
1271 debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1274 // Fix empty network_request_param_default to NULL
1275 if (($key == 'network_request_param_default') && (trim($entry[$networkId]) == '')) {
1277 $entry[$networkId] = NULL;
1281 $networkParamsData[$key] = $entry[$networkId];
1284 // Update the network data
1285 $updated += doNetworkUpdateParamsByArray($networkId, $networkParamsData);
1289 // Do we have updates?
1292 displayMessage('{%message,ADMIN_NETWORK_REQUEST_PARAMETER_UPDATED=' . $updated . '%}');
1295 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_CHANGED--}');
1300 // Removes given network type handlers
1301 function doAdminNetworkProcessRemoveNetworkTypes () {
1302 // Do we have selections?
1303 if (ifPostContainsSelections()) {
1304 // By default nothing is removed
1307 // Something has been selected, so start updating them
1308 foreach (postRequestElement('sel') as $networkId => $sel) {
1309 // Update this entry?
1311 // Remove this entry
1312 $removed += doAdminRemoveNetworkEntry('types', 'network_type_id', $networkId);
1316 // Do we have removes?
1319 displayMessage('{%message,ADMIN_NETWORK_TYPE_HANDLER_REMOVED=' . $removed . '%}');
1322 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPE_HANDLER_NOTHING_REMOVED--}');
1327 // Removes given network request parameters
1328 function doAdminNetworkProcessRemoveNetworkRequestParams () {
1329 // Do we have selections?
1330 if (ifPostContainsSelections()) {
1331 // By default nothing is removed
1334 // Something has been selected, so start updating them
1335 foreach (postRequestElement('sel') as $networkId => $sel) {
1336 // Update this entry?
1338 // Remove this entry
1339 $removed += doAdminRemoveNetworkEntry('request_params', 'network_request_param_id', $networkId);
1343 // Do we have removes?
1346 displayMessage('{%message,ADMIN_NETWORK_REQUEST_PARAMETER_REMOVED=' . $removed . '%}');
1349 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_REMOVED--}');
1354 // Adds a request parameter to given network and type
1355 function doAdminNetworkProcessAddRequestParam () {
1356 // Is the request parameter already used with given network?
1357 if (isNetworkRequestElementValid(postRequestElement('network_request_param_key'), postRequestElement('network_type_id'), getRequestElement('network_id'))) {
1359 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_REQUEST_PARAMETER_ALREADY_ADDED=' . postRequestElement('network_request_param_key') . '%}');
1361 // ... so abort here
1365 // Remove the 'ok' part
1366 unsetPostRequestElement('ok');
1369 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1371 // Is network_request_param_default set?
1372 if (postRequestElement('network_request_param_default') == '') {
1373 // Remove empty value to get a NULL for an optional entry
1374 unsetPostRequestElement('network_request_param_default');
1377 // Add the whole request to database
1378 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_request_params'), __FUNCTION__, __LINE__);
1381 if (!SQL_HASZEROAFFECTED()) {
1382 // Successfully added
1383 loadTemplate('admin_network_request_param_added', false, postRequestArray());
1386 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_REQUEST_PARAMETER_NOT_ADDED=' . postRequestElement('network_request_param_key') . '%}');
1390 // Adds a API response array entry
1391 function doAdminNetworkProcessAddNetworkArrayTranslation () {
1392 // Is the request parameter already used with given network?
1393 if (isNetworkArrayTranslationValid(postRequestElement('network_array_index'), postRequestElement('network_type_id'), getRequestElement('network_id'))) {
1395 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_ARRAY_TRANSLATION_ALREADY_ADDED=' . postRequestElement('network_array_index') . '%}');
1397 // ... so abort here
1401 // Remove the 'ok' part
1402 unsetPostRequestElement('ok');
1405 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1408 setPostRequestElement('sort', (countSumTotalData(
1409 bigintval(postRequestElement('network_id')),
1410 'network_array_translation',
1414 sprintf(" AND `network_type_id`=%s", bigintval(postRequestElement('network_type_id')))
1417 // Add the whole request to database
1418 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_array_translation'), __FUNCTION__, __LINE__);
1421 if (!SQL_HASZEROAFFECTED()) {
1422 // Successfully added
1423 loadTemplate('admin_network_array_translation_added', false, postRequestArray());
1426 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_ARRAY_TRANSLATION_NOT_ADDED=' . postRequestElement('network_array_index') . '%}');
1430 // Adds/update network API configuration
1431 function doAdminNetworkProcessNetworkApiConfig () {
1432 // Remove the 'ok' part
1433 unsetPostRequestElement('ok');
1436 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1438 // Is network_api_referral_button set?
1439 if (postRequestElement('network_api_referral_button') == '') {
1440 // Remove empty value to get a NULL for an optional entry
1441 unsetPostRequestElement('network_api_referral_button');
1444 // Is there already an entry?
1445 if (isNetworkApiConfigured(getRequestElement('network_id'))) {
1446 // Generate SQL query
1447 $SQL = getUpdateSqlFromArray(postRequestArray(), 'network_api_config', 'network_id', postRequestElement('network_id'), array('network_id'));
1450 $SQL = getInsertSqlFromArray(postRequestArray(), 'network_api_config');
1454 SQL_QUERY($SQL, __FUNCTION__, __LINE__);
1457 if (!SQL_HASZEROAFFECTED()) {
1458 // Successfully added
1459 displayMessage('{--ADMIN_CONFIG_NETWORK_API_SAVED--}');
1462 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_API_NOT_SAVED--}');
1466 // Only adds network type configuration if not yet present
1467 function doAdminNetworkProcessAddHandlerTypesConfig ($displayMessage = true) {
1468 // Remove the 'ok' part
1469 unsetPostRequestElement('ok');
1472 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1473 setPostRequestElement('network_type_id', bigintval(getRequestElement('network_type_id')));
1476 * Some parameters are optional, at least one must be given so check a bunch
1479 foreach (array('network_min_waiting_time', 'network_min_remain_clicks', 'network_min_payment', 'network_allow_erotic') as $element) {
1480 // Is this element empty?
1481 if (postRequestElement($element) == '') {
1482 // Then unset it to get a NULL for optional parameter
1483 unsetPostRequestElement($element);
1487 // Initialize variables
1489 $id = 'network_max_reload_time_ye';
1492 // Get all POST data
1493 $postData = postRequestArray();
1495 // Convert "reload time selections"
1496 convertSelectionsToEpocheTime($postData, $content, $id, $skip);
1498 // Set the POST array back
1499 setPostRequestArray($postData);
1501 // Is there already an entry?
1502 if (isNetworkTypeHandlerConfigured(getRequestElement('network_id'), getRequestElement('network_type_id'))) {
1503 // This network type handler is already configured
1504 displayMessage('{--ADMIN_NETWORK_HANDLER_TYPE_HANDLER_ALREADY_CONFIGURED--}');
1508 // Copy 'set all' and remove it from POST data
1509 $setAll = (postRequestElement('set_all') === 'Y');
1510 unsetPostRequestElement('set_all');
1512 // Shall we set for all?
1513 if ($setAll === true) {
1515 $result = SQL_QUERY_ESC('SELECT `network_type_id` FROM `{?_MYSQL_PREFIX?}_network_types` WHERE `network_id`=%s ORDER BY `network_type_id` ASC',
1516 array(bigintval(getRequestElement('network_id'))), __FUNCTION__, __LINE__);
1518 // Do we have entries?
1519 if (SQL_HASZERONUMS($result)) {
1520 // No, then abort here
1521 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_SET_ALL_404--}');
1525 // Init number of rows
1529 while (list($typeId) = SQL_FETCHROW($result)) {
1530 // Set it in GET data
1531 setGetRequestElement('network_type_id', $typeId);
1533 // Call this function again
1534 $numRows += doAdminNetworkProcessAddHandlerTypesConfig(false);
1538 SQL_FREERESULT($result);
1542 // Something has been updated
1543 displayMessage('{%message,ADMIN_CONFIG_NETWORK_HANDLER_TYPE_ALL_HANDLER_SAVED=' . bigintval($numRows) . '%}');
1545 // Nothing has been saved
1546 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}');
1549 // Get SQL query for new entry
1550 $SQL = getInsertSqlFromArray(postRequestArray(), 'network_types_config');
1553 SQL_QUERY($SQL, __FUNCTION__, __LINE__);
1555 // Shall we display the message?
1556 if ($displayMessage === true) {
1558 if (!SQL_HASZEROAFFECTED()) {
1559 // Successfully added
1560 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_SAVED--}');
1563 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_SAVED--}');
1566 // Return amount of affected rows (1 or 2)
1567 return SQL_AFFECTEDROWS();
1572 // Only changes network type configuration if not yet present
1573 function doAdminNetworkProcessEditHandlerTypesConfig ($displayMessage = true) {
1574 // Remove the 'ok' part
1575 unsetPostRequestElement('ok');
1578 * Some parameters are optional, at least one must be given so check a bunch
1581 foreach (array('network_min_waiting_time', 'network_min_remain_clicks', 'network_min_payment', 'network_allow_erotic') as $element) {
1582 // Is this element empty?
1583 if (postRequestElement($element) == '') {
1584 // Then unset it to get a NULL for optional parameter
1585 unsetPostRequestElement($element);
1589 // Initialize variables
1591 $id = 'network_max_reload_time_ye';
1593 $postData = postRequestArray();
1595 // Convert "reload time selections"
1596 convertSelectionsToEpocheTime($postData, $content, $id, $skip);
1598 // Set the POST array back
1599 setPostRequestArray($postData);
1601 // Is there already an entry?
1602 if (!isNetworkTypeHandlerConfigured(getRequestElement('network_id'), getRequestElement('network_type_id'))) {
1603 // This network type handler is not configured
1604 displayMessage('{--ADMIN_NETWORK_HANDLER_TYPE_HANDLER_NOT_CONFIGURED--}');
1608 // Copy 'set all' and remove it from POST data
1609 $setAll = (postRequestElement('set_all') === 'Y');
1610 unsetPostRequestElement('set_all');
1612 // Shall we set for all?
1613 if ($setAll === true) {
1614 // Get all data entries
1615 $result = SQL_QUERY_ESC('SELECT `network_data_id` FROM `{?_MYSQL_PREFIX?}_network_types_config` WHERE `network_id`=%s ORDER BY `network_type_id` ASC',
1616 array(bigintval(getRequestElement('network_id'))), __FUNCTION__, __LINE__);
1618 // Do we have entries?
1619 if (SQL_HASZERONUMS($result)) {
1620 // No, then abort here
1621 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_SET_ALL_404--}');
1625 // Init number of rows
1629 while (list($dataId) = SQL_FETCHROW($result)) {
1630 // Set it in GET data
1631 setPostRequestElement('network_data_id', $dataId);
1633 // Call this function again
1634 $numRows += doAdminNetworkProcessEditHandlerTypesConfig(false);
1638 SQL_FREERESULT($result);
1642 // Something has been updated
1643 displayMessage('{%message,ADMIN_CONFIG_NETWORK_HANDLER_TYPE_ALL_HANDLER_SAVED=' . bigintval($numRows) . '%}');
1645 // Nothing has been saved
1646 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}');
1649 // Get SQL query for new entry
1650 $SQL = getUpdateSqlFromArray(postRequestArray(), 'network_types_config', 'network_data_id', postRequestElement('network_data_id'), array('network_data_id'));
1653 SQL_QUERY($SQL, __FUNCTION__, __LINE__);
1655 // Shall we display the message?
1656 if ($displayMessage === true) {
1658 if (!SQL_HASZEROAFFECTED()) {
1659 // Successfully added
1660 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_SAVED--}');
1663 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}');
1666 // Return amount of affected rows (1 or 2)
1667 return SQL_AFFECTEDROWS();
1672 // Do expression code for this extension
1673 function doExpressionNetwork ($data) {
1674 // Construct replacer
1675 $replacer = sprintf(
1676 "{DQUOTE} . %s(%s, '%s') . {DQUOTE}",
1678 $data['matches'][4][$data['key']],
1682 // Replace %network_id% with the current network id
1683 $replacer = str_replace('%network_id%', getCurrentNetworkId(), $replacer);
1686 $code = replaceExpressionCode($data, $replacer);
1692 // ----------------------------------------------------------------------------
1693 // Call-back functions for exporting data
1694 // ----------------------------------------------------------------------------
1696 // Callback function to export network tables
1697 function doAdminNetworkProcessExport () {
1698 // Init table with all valid what->table entries
1699 $validExports = array(
1700 // General network data
1701 'list_networks' => 'network_data',
1702 // Network type handler
1703 'list_network_types' => 'network_types',
1704 // Network request parameter
1705 'list_network_request_params' => 'network_request_params',
1706 // Network API response array index translation
1707 'list_network_array_translation' => 'network_array_translation',
1710 // Is the 'what' key valid?
1711 if (!isset($validExports[getWhat()])) {
1713 debug_report_bug(__FUNCTION__, __LINE__, 'what=' . getWhat() . ' - not supported');
1716 // Generate call-back, some tables require to export not all columns
1717 $callbackName = 'doAdminNetworkExport' . capitalizeUnderscoreString($validExports[getWhat()]);
1719 // Is the call-back function there?
1720 if (!function_exists($callbackName)) {
1721 // No, this is really bad
1722 debug_report_bug(__FUNCTION__, __LINE__, 'Invalid call-back function ' . $callbackName . ' detected.');
1723 } elseif (isset($GLOBALS[__FUNCTION__][$callbackName])) {
1725 debug_report_bug(__FUNCTION__, __LINE__, 'Double-call of export function ' . $callbackName . ' detected.');
1728 // Call the function
1729 call_user_func($callbackName);
1731 // Mark it as called
1732 $GLOBALS[__FUNCTION__][$callbackName] = true;
1734 // Don't display the list/add new form
1735 $GLOBALS['network_display'] = false;
1738 // Exports (and displays) the table 'network_data'
1739 function doAdminNetworkExportNetworkData () {
1740 // Query for all networks
1741 $result = SQL_QUERY('SELECT
1742 `network_short_name`,
1745 `network_data_separator`,
1746 `network_row_separator`,
1747 `network_request_type`,
1749 `network_require_id_card`,
1750 `network_query_amount`,
1753 `{?_MYSQL_PREFIX?}_network_data`
1756 __FUNCTION__, __LINE__);
1758 // Start an empty SQL query
1759 $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";
1762 while ($content = SQL_FETCHARRAY($result)) {
1765 $content['network_short_name'] . "', '" .
1766 $content['network_title'] . "', '" .
1767 $content['network_reflink'] . "', '" .
1768 $content['network_data_separator'] . "', '" .
1769 $content['network_row_separator'] . "', '" .
1770 $content['network_request_type'] . "', '" .
1771 $content['network_charset'] . "', '" .
1772 $content['network_require_id_card'] . "', " .
1773 $content['network_query_amount'] . ", '" .
1774 $content['network_active'] . "'),\n";
1777 // Remove last commata and close braces
1778 $SQL = substr($SQL, 0, -2);
1781 SQL_FREERESULT($result);
1783 // Output the SQL query
1784 loadTemplate('admin_export_network_data', false, $SQL);
1787 // Exports (and displays) the table 'network_types'
1788 function doAdminNetworkExportNetworkTypes () {
1789 // 'network_id' must be set
1790 if (!isGetRequestElementSet('network_id')) {
1791 // Only network handlers of one network will be exported per time
1792 debug_report_bug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
1795 // Get all network types of given network
1796 $result = SQL_QUERY_ESC('SELECT
1799 `network_type_handler`,
1800 `network_type_api_url`,
1801 `network_type_click_url`,
1802 `network_type_banner_url`,
1803 `network_type_reload_time_unit`
1805 `{?_MYSQL_PREFIX?}_network_types`
1809 `network_type_id` ASC',
1811 bigintval(getRequestElement('network_id'))
1812 ), __FUNCTION__, __LINE__);
1814 // Start an empty SQL query
1815 $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`) VALUES\n";
1818 while ($content = SQL_FETCHARRAY($result)) {
1821 $content['network_type_id'] . ', ' .
1822 $content['network_id'] . ", '" .
1823 $content['network_type_handler'] . "', '" .
1824 $content['network_type_api_url'] . "', '" .
1825 $content['network_type_click_url'] . "', ";
1827 // Is the column NULL?
1828 if (is_null($content['network_type_banner_url'])) {
1833 $SQL .= "'" . $content['network_type_banner_url'] . "'";
1837 $SQL .= ",'" . $content['network_type_reload_time_unit'] . "'),\n";
1840 // Remove last commata and close braces
1841 $SQL = substr($SQL, 0, -2);
1844 SQL_FREERESULT($result);
1846 // Output the SQL query
1847 loadTemplate('admin_export_network_types', false, $SQL);
1850 // Exports (and displays) the table 'network_request_params'
1851 function doAdminNetworkExportNetworkRequestParams () {
1852 // 'network_id' must be set
1853 if (!isGetRequestElementSet('network_id')) {
1854 // Only network request parameters of one network will be exported per time
1855 debug_report_bug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
1858 // Get all network types of given network
1859 $result = SQL_QUERY_ESC('SELECT
1862 `network_request_param_key`,
1863 `network_request_param_value`,
1864 `network_request_param_default`
1866 `{?_MYSQL_PREFIX?}_network_request_params`
1870 `network_type_id` ASC ,
1871 `network_request_param_id` ASC',
1873 bigintval(getRequestElement('network_id'))
1874 ), __FUNCTION__, __LINE__);
1876 // Start an empty SQL query
1877 $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";
1880 while ($content = SQL_FETCHARRAY($result)) {
1883 $content['network_id'] . ', ' .
1884 $content['network_type_id'] . ", '" .
1885 $content['network_request_param_key'] . "', '" .
1886 $content['network_request_param_value'] . "', ";
1888 // Is the column NULL?
1889 if (is_null($content['network_request_param_default'])) {
1894 $SQL .= "'" . $content['network_request_param_default'] . "'),\n";
1898 // Remove last commata and close braces
1899 $SQL = substr($SQL, 0, -2);
1902 SQL_FREERESULT($result);
1904 // Output the SQL query
1905 loadTemplate('admin_export_network_request_params', false, $SQL);
1908 // Exports (and displays) the table 'network_array_translation'
1909 function doAdminNetworkExportNetworkArrayTranslation () {
1910 // 'network_id' must be set
1911 if (!isGetRequestElementSet('network_id')) {
1912 // Only network API array index translations of one network will be exported per time
1913 debug_report_bug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
1916 // Get all network types of given network
1917 $result = SQL_QUERY_ESC('SELECT
1920 `network_array_index`,
1923 `{?_MYSQL_PREFIX?}_network_array_translation`
1927 `network_type_id` ASC,
1930 bigintval(getRequestElement('network_id'))
1931 ), __FUNCTION__, __LINE__);
1933 // Start an empty SQL query
1934 $SQL = "INSERT INTO `{?_MYSQL_PREFIX?}_network_array_translation` (`network_id`,`network_type_id`,`network_array_index`,`sort`) VALUES\n";
1937 while ($content = SQL_FETCHARRAY($result)) {
1940 $content['network_id'] . ', ' .
1941 $content['network_type_id'] . ', ' .
1942 $content['network_array_index'] . ', ' .
1943 $content['sort'] . "),\n";
1946 // Remove last commata and close braces
1947 $SQL = substr($SQL, 0, -2);
1950 SQL_FREERESULT($result);
1952 // Output the SQL query
1953 loadTemplate('admin_export_network_array_translation', false, $SQL);