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 vcheck request parameter is already used (valid)
172 function isNetworkVcheckElementValid ($key, $networkId) {
174 $result = SQL_QUERY_ESC("SELECT `network_vcheck_param_id` FROM `{?_MYSQL_PREFIX?}_network_vcheck_params` WHERE `network_id`=%s AND `network_vcheck_param_key`='%s' LIMIT 1",
178 ), __FUNCTION__, __LINE__);
181 $isValid = (SQL_NUMROWS($result) == 1);
184 SQL_FREERESULT($result);
190 // Checks wether the given network API array translation
191 function isNetworkArrayTranslationValid ($key, $type, $networkId) {
193 $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",
198 ), __FUNCTION__, __LINE__);
201 $isValid = (SQL_NUMROWS($result) == 1);
204 SQL_FREERESULT($result);
210 // "Getter" for a network's data by provided id number
211 function getNetworkDataById ($networkId, $column = '') {
212 // Ids lower one are not accepted
213 if ($networkId < 1) {
214 // Not good, should be fixed
215 debug_report_bug(__FUNCTION__, __LINE__, 'Network id ' . $networkId . ' is smaller than 1.');
218 // Set current network id
219 setCurrentNetworkId($networkId);
222 if (!isset($GLOBALS['network_data'][$networkId])) {
223 // By default we have no data
224 $GLOBALS['network_data'][$networkId] = array();
226 // Query for the network data
227 $result = SQL_QUERY_ESC("SELECT
229 `network_short_name`,
232 `network_data_separator`,
233 `network_row_separator`,
234 `network_request_type`,
236 `network_require_id_card`,
237 `network_query_amount`
239 `{?_MYSQL_PREFIX?}_network_data`
243 array(bigintval($networkId)), __FUNCTION__, __LINE__);
245 // Do we have an entry?
246 if (SQL_NUMROWS($result) == 1) {
248 $GLOBALS['network_data'][$networkId] = SQL_FETCHARRAY($result);
252 SQL_FREERESULT($result);
256 if (empty($column)) {
258 return $GLOBALS['network_data'][$networkId];
261 return $GLOBALS['network_data'][$networkId][$column];
265 // "Getter" for a network's data by provided type id number
266 function getNetworkDataByTypeId ($networkId, $column = '') {
267 // Ids lower one are not accepted
268 if ($networkId < 1) {
269 // Not good, should be fixed
270 debug_report_bug(__FUNCTION__, __LINE__, 'Network type id ' . $networkId . ' is smaller than 1.');
273 // Set current network id
274 setCurrentNetworkId($networkId);
277 if (!isset($GLOBALS['network_data'][$networkId])) {
278 // By default we have no data
279 $GLOBALS['network_data'][$networkId] = array();
281 // Query for the network data
282 $result = SQL_QUERY_ESC("SELECT
284 d.`network_short_name`,
287 d.`network_data_separator`,
288 d.`network_row_separator`,
289 d.`network_request_type`,
291 d.`network_require_id_card`,
292 d.`network_query_amount`,
293 t.`network_type_handler`,
294 t.`network_type_api_url`,
295 t.`network_type_click_url`,
296 t.`network_type_banner_url`
298 `{?_MYSQL_PREFIX?}_network_data` AS d
300 `{?_MYSQL_PREFIX?}_network_types` AS t
302 d.`network_id`=t.`network_id`
304 t.`network_type_id`=%s
306 array(bigintval($networkId)), __FUNCTION__, __LINE__);
308 // Do we have an entry?
309 if (SQL_NUMROWS($result) == 1) {
311 $GLOBALS['network_data'][$networkId] = SQL_FETCHARRAY($result);
315 SQL_FREERESULT($result);
319 if (empty($column)) {
321 return $GLOBALS['network_data'][$networkId];
324 return $GLOBALS['network_data'][$networkId][$column];
328 // "Getter" for a network type data by provided id number
329 function getNetworkTypeDataById ($networkId) {
330 // Ids lower one are not accepted
331 if ($networkId < 1) {
332 // Not good, should be fixed
333 debug_report_bug(__FUNCTION__, __LINE__, 'Network type id ' . $networkId . ' is smaller than 1.');
336 // By default we have no data
337 $GLOBALS['network_type_data'][$networkId] = array();
339 // Query for the network data
340 $result = SQL_QUERY_ESC('SELECT
343 `network_type_handler`,
344 `network_type_api_url`,
345 `network_type_click_url`,
346 `network_type_banner_url`
348 `{?_MYSQL_PREFIX?}_network_types`
352 array(bigintval($networkId)), __FUNCTION__, __LINE__);
354 // Do we have an entry?
355 if (SQL_NUMROWS($result) == 1) {
357 $GLOBALS['network_type_data'][$networkId] = SQL_FETCHARRAY($result);
361 SQL_FREERESULT($result);
364 return $GLOBALS['network_type_data'][$networkId];
367 // "Getter" for a network request parameter data by provided id number
368 function getNetworkRequestParamsDataById ($networkId) {
369 // Ids lower one are not accepted
370 if ($networkId < 1) {
371 // Not good, should be fixed
372 debug_report_bug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $networkId . ' is smaller than 1.');
375 // By default we have no data
376 $networkRequestData = array();
378 // Query for the network data
379 $result = SQL_QUERY_ESC('SELECT
380 `network_request_param_id`,
383 `network_request_param_key`,
384 `network_request_param_value`,
385 `network_request_param_default`
387 `{?_MYSQL_PREFIX?}_network_request_params`
389 `network_request_param_id`=%s
391 array(bigintval($networkId)), __FUNCTION__, __LINE__);
393 // Do we have an entry?
394 if (SQL_NUMROWS($result) == 1) {
396 $networkRequestData = SQL_FETCHARRAY($result);
400 SQL_FREERESULT($result);
403 return $networkRequestData;
406 // Updates given network (id) with data from array
407 function doNetworkUpdateDataByArray ($networkId, $networkData) {
408 // Ids lower one are not accepted
409 if ($networkId < 1) {
410 // Not good, should be fixed
411 debug_report_bug(__FUNCTION__, __LINE__, 'Network id ' . $networkId . ' is smaller than 1.');
414 // Just call our inner method
415 return adminSaveSettings($networkData, '_network_data', sprintf("`network_id`=%s", bigintval($networkId)), array(), false, false);
418 // Updates given network type handler (id) with data from array
419 function doNetworkUpdateTypeByArray ($networkId, $networkTypeData) {
420 // Ids lower one are not accepted
421 if ($networkId < 1) {
422 // Not good, should be fixed
423 debug_report_bug(__FUNCTION__, __LINE__, 'Network type handler id ' . $networkId . ' is smaller than 1.');
426 // Just call our inner method
427 return adminSaveSettings($networkTypeData, '_network_types', sprintf("`network_type_id`=%s", bigintval($networkId)), array(), false, false);
430 // Updates given network request parameters (id) with data from array
431 function doNetworkUpdateParamsByArray ($networkId, $networkParamData) {
432 // Ids lower one are not accepted
433 if ($networkId < 1) {
434 // Not good, should be fixed
435 debug_report_bug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $networkId . ' is smaller than 1.');
438 // Just call our inner method
439 return adminSaveSettings($networkParamData, '_network_request_params', sprintf("`network_request_param_id`=%s", bigintval($networkId)), array(), false, false);
442 // Removes given network entry
443 function doAdminRemoveNetworkEntry ($table, $column, $networkId, $limit = 1) {
445 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_network_%s` WHERE `%s`=%s LIMIT %s",
451 ), __FUNCTION__, __LINE__);
453 // Return affected rows
454 return SQL_AFFECTEDROWS();
457 // Generates a list of networks for given script and returns it
458 function generateAdminNetworkList () {
462 // Query for all networks
463 $result = SQL_QUERY("SELECT
465 `network_short_name`,
468 `{?_MYSQL_PREFIX?}_network_data`
472 `network_short_name` ASC", __FUNCTION__, __LINE__);
474 // Do we have entries?
475 if (!SQL_HASZERONUMS($result)) {
478 while ($row = SQL_FETCHARRAY($result)) {
479 // Is this valid, then add it
480 if ((is_array($row)) && (isset($row['network_id']))) {
482 $rows[$row['network_id']] = $row;
486 // Generate the selection box
487 $content = generateSelectionBoxFromArray($rows, 'network_id', 'network_id', '', '', 'network');
490 $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}');
494 SQL_FREERESULT($result);
500 // Generator (somewhat getter) for a list of network types for given network id
501 function generateAdminNetworkTypeList ($networkId) {
505 // Query all types of this network
506 $result = SQL_QUERY_ESC('SELECT
508 `network_type_handler`
510 `{?_MYSQL_PREFIX?}_network_types`
514 `network_type_handler` ASC',
516 bigintval($networkId)
517 ), __FUNCTION__, __LINE__);
519 // Do we have entries?
520 if (!SQL_HASZERONUMS($result)) {
523 while ($row = SQL_FETCHARRAY($result)) {
524 // Is this valid, then add it
525 if ((is_array($row)) && (isset($row['network_type_id']))) {
527 $rows[$row['network_type_id']] = $row;
531 // Generate the selection box
532 $content = generateSelectionBoxFromArray($rows, 'network_type', 'network_type_id');
535 $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}');
539 SQL_FREERESULT($result);
545 // Generator (somewhat getter) for a list of network types for all types
546 function generateAdminDistinctNetworkTypeList () {
550 // Query all types of this network
551 $result = SQL_QUERY("SELECT
553 t.`network_type_handler`,
556 `{?_MYSQL_PREFIX?}_network_types` AS t
558 `{?_MYSQL_PREFIX?}_network_data` AS d
560 t.`network_id`=d.`network_id`
562 d.`network_active`='Y'
564 d.`network_short_name` ASC,
565 t.`network_type_handler` ASC", __FUNCTION__, __LINE__);
567 // Do we have entries?
568 if (!SQL_HASZERONUMS($result)) {
571 while ($row = SQL_FETCHARRAY($result)) {
572 // Is this valid, then add it
573 if ((is_array($row)) && (isset($row['network_type_id']))) {
575 $rows[$row['network_type_id']] = $row;
579 // Generate the selection box
580 $content = generateSelectionBoxFromArray($rows, 'network_type', 'network_type_id', '', '_title');
583 $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}');
587 SQL_FREERESULT($result);
588 //* DEBUG: */ die('<pre>'.encodeEntities($content).'</pre>');
594 // Generator (somewhat getter) for network type options
595 function generateNetworkTypeOptions ($networkId) {
596 // Is this an array, then we just came back from edit/delete actions
597 if (is_array($networkId)) {
602 if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
603 // Generate output and cache it
604 $GLOBALS[__FUNCTION__][$networkId] = generateOptionList(
607 'network_type_handler',
611 "WHERE `network_id`=%s",
612 bigintval(getRequestElement('network_id'))
615 'translateNetworkTypeHandler'
620 return $GLOBALS[__FUNCTION__][$networkId];
623 // Generates an options list of all available (hard-coded) handlers
624 function generateNetworkTypesAvailableOptions ($defaultType = NULL) {
626 if (!isset($GLOBALS[__FUNCTION__][$defaultType])) {
628 $GLOBALS[__FUNCTION__][$defaultType] = generateOptionList(
664 $GLOBALS['network_types_disabled'],
665 'translateNetworkTypeHandler'
670 return $GLOBALS[__FUNCTION__][$defaultType];
673 // Generates an options list (somewhat getter) for request keys
674 function generateNetworkRequestKeyOptions () {
676 if (!isset($GLOBALS[__FUNCTION__])) {
677 // Generate and cache it
678 $GLOBALS[__FUNCTION__] = generateOptionList(
700 $GLOBALS['network_request_params_disabled'],
701 'translateNetworkRequestParameterKey'
706 return $GLOBALS[__FUNCTION__];
709 // Generates an options list for vcheck request keys
710 function generateNetworkVcheckKeyOptions () {
712 if (!isset($GLOBALS[__FUNCTION__])) {
713 // Generate and cache it
714 $GLOBALS[__FUNCTION__] = generateOptionList(
734 $GLOBALS['network_vcheck_params_disabled'],
735 'translateNetworkVcheckParameterKey'
740 return $GLOBALS[__FUNCTION__];
743 // Generator (somewhat getter) for (return) array translation
744 function generateNetworkTranslationOptions ($default = '') {
746 if (!isset($GLOBALS[__FUNCTION__][$default])) {
747 // Generate and cache it
748 $GLOBALS[__FUNCTION__][$default] = generateOptionList(
749 'network_translations',
750 'network_translation_id',
751 'network_translation_name',
755 $GLOBALS['network_translation_disabled'],
756 'translateNetworkTranslationName'
761 return $GLOBALS[__FUNCTION__][$default];
764 // Generates an option list of request types
765 function generateNetworkRequestTypeOptions ($default = '') {
767 if (!isset($GLOBALS[__FUNCTION__][$default])) {
769 $GLOBALS[__FUNCTION__][$default] = generateOptionList(
776 '{--ADMIN_NETWORK_REQUEST_TYPE_GET--}',
777 '{--ADMIN_NETWORK_REQUEST_TYPE_POST--}'
784 return $GLOBALS[__FUNCTION__][$default];
787 // Generates an option list of network_api_active
788 function generateNetworkApiActiveOptions ($default = '') {
790 if (!isset($GLOBALS[__FUNCTION__][$default])) {
792 $GLOBALS[__FUNCTION__][$default] = generateYesNoOptionList($default);
796 return $GLOBALS[__FUNCTION__][$default];
799 // Translates 'translate_name' for e.g. templates
800 function translateNetworkTranslationName ($name) {
802 $messageId = 'ADMIN_NETWORK_TRANSLATE_' . strtoupper($name) . '_NAME';
804 // Is the message id there?
805 if (!isMessageIdValid($messageId)) {
807 debug_report_bug(__FUNCTION__, __LINE__, 'type=' . $type . ' is invalid.');
811 return '{--' . $messageId . '--}';
814 // Translates the network type handler (e.g. banner, paidmail) for templates
815 function translateNetworkTypeHandler ($type) {
817 $messageId = 'ADMIN_NETWORK_TYPE_HANDLER_' . strtoupper($type);
819 // Is the message id there?
820 if (!isMessageIdValid($messageId)) {
822 debug_report_bug(__FUNCTION__, __LINE__, 'type=' . $type . ' is invalid.');
826 return '{--' . $messageId . '--}';
829 // Translates request type
830 function translateNetworkRequestType ($type) {
832 $messageId = 'ADMIN_NETWORK_REQUEST_TYPE_' . strtoupper($type) . '';
834 // Is the message id there?
835 if (!isMessageIdValid($messageId)) {
837 debug_report_bug(__FUNCTION__, __LINE__, 'type=' . $type . ' is invalid.');
841 return '{--' . $messageId . '--}';
844 // Translates request parameter
845 function translateNetworkRequestParameterKey ($param) {
847 $messageId = 'ADMIN_NETWORK_REQUEST_PARAMETER_' . strtoupper($param) . '';
849 // Is the message id there?
850 if (!isMessageIdValid($messageId)) {
852 debug_report_bug(__FUNCTION__, __LINE__, 'param=' . $param . ' is invalid.');
856 return '{--' . $messageId . '--}';
859 // Translates vheck request parameter
860 function translateNetworkVcheckParameterKey ($param) {
862 $messageId = 'ADMIN_NETWORK_VCHECK_PARAMETER_' . strtoupper($param) . '';
864 // Is the message id there?
865 if (!isMessageIdValid($messageId)) {
867 debug_report_bug(__FUNCTION__, __LINE__, 'param=' . $param . ' is invalid.');
871 return '{--' . $messageId . '--}';
874 // Translates API index
875 function translateNetworkApiIndex ($index) {
877 if (!isset($GLOBALS['network_array_index'])) {
878 // Get an array of all API array indexes
879 $GLOBALS['network_array_index'] = array();
882 $result = SQL_QUERY('SELECT
884 `network_array_index`,
885 `network_translation_name`
887 `{?_MYSQL_PREFIX?}_network_array_translation`
889 `{?_MYSQL_PREFIX?}_network_translations`
891 `network_array_index`=`network_translation_id`
893 `sort` ASC', __FUNCTION__, __LINE__);
895 // Do we have entries?
896 if (!SQL_HASZERONUMS($result)) {
898 while ($row = SQL_FETCHARRAY($result)) {
899 // Add it to our global array
900 $GLOBALS['network_array_index'][$row['network_array_index']] = $row;
905 SQL_FREERESULT($result);
908 // Default name is unknown
911 // Is the entry there?
912 if (isset($GLOBALS['network_array_index'][$index])) {
914 $name = $GLOBALS['network_array_index'][$index]['network_translation_name'];
917 // Return translation
918 return translateNetworkTranslationName($name);
921 // Translates network API configuration status (see function isNetworkApiConfigured()) by given id
922 function translateNetworkApiConfiguredStatusById ($networkId) {
924 if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
925 // By default it is not configured
926 $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_NOT_CONFIGURED--}';
928 // So is it configured?
929 if (isNetworkApiConfigured($networkId)) {
931 $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_CONFIGURED--}';
936 return $GLOBALS[__FUNCTION__][$networkId];
939 // Checks if the given network is configured by looking its API configuration entry up
940 function isNetworkApiConfigured ($networkId) {
942 if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
943 // Check for an entry in network_api_config
944 $GLOBALS[__FUNCTION__][$networkId] = (countSumTotalData(
945 bigintval($networkId),
946 'network_api_config',
954 return $GLOBALS[__FUNCTION__][$networkId];
957 // Checks wether the given network type handler is configured
958 function isNetworkTypeHandlerConfigured ($networkId, $networkTypeId) {
960 if (!isset($GLOBALS[__FUNCTION__][$networkId][$networkTypeId])) {
962 $GLOBALS[__FUNCTION__][$networkId][$networkTypeId] = (countSumTotalData(
963 bigintval($networkTypeId),
964 'network_types_config',
968 sprintf(' AND `network_id`=%s', bigintval($networkId))
973 return $GLOBALS[__FUNCTION__][$networkId][$networkTypeId];
976 // Handles the network-payment-check request
977 function handleNetworkPaymentCheckRequest () {
978 // @TODO Implement this function
979 debug_report_bug(__FUNCTION__, __LINE__, 'Not yet implemented.');
982 //------------------------------------------------------------------------------
983 // Call-back functions
984 //------------------------------------------------------------------------------
986 // Callback function to add new network
987 function doAdminNetworkProcessAddNetwork () {
988 // We can say here, the form is sent, so check if the network is already added
989 if (isNetworkNameValid(postRequestElement('network_short_name'))) {
991 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_ALREADY_ADDED=' . postRequestElement('network_short_name') . '%}');
995 // Remove the 'ok' part
996 unsetPostRequestElement('ok');
998 // Add the whole request to database
999 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_data'), __FUNCTION__, __LINE__);
1001 // Add the id for output only
1002 setPostRequestElement('network_id', SQL_INSERTID());
1005 if (!SQL_HASZEROAFFECTED()) {
1006 // Successfully added
1007 loadTemplate('admin_network_added', false, postRequestArray());
1010 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_DATA_NOT_ADDED=' . postRequestElement('network_short_name') . '%}');
1014 // Displays selected networks for editing
1015 function doAdminNetworkProcessHandleNetworks () {
1016 // Do we have selections?
1017 if (ifPostContainsSelections()) {
1018 // Something has been selected, so start displaying one by one
1020 foreach (postRequestElement('sel') as $networkId => $sel) {
1021 // Is this selected?
1023 // Load this network's data
1024 $networkData = getNetworkDataById($networkId);
1026 // Do we have found the network?
1027 if (count($networkData) > 0) {
1028 // Add row template with given form name
1029 $OUT .= loadTemplate('admin_' . $GLOBALS['network_form_name'] . '_networks_row', true, $networkData);
1034 // If we have no rows, we don't need to display the edit form
1036 // Output main template
1037 loadTemplate('admin_' . $GLOBALS['network_form_name'] . '_networks', false, $OUT);
1039 // Don't display the list/add new form
1040 $GLOBALS['network_display'] = false;
1042 // Nothing selected/found
1043 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_FOUND--}');
1048 // Handle network type form
1049 function doAdminNetworkProcessHandleNetworkTypes () {
1050 // Do we have selections?
1051 if (ifPostContainsSelections()) {
1052 // Load network data
1053 $networkData = getNetworkDataById(getRequestElement('network_id'));
1055 // Something has been selected, so start displaying one by one
1057 foreach (postRequestElement('sel') as $networkId => $sel) {
1058 // Is this selected?
1060 // Load this network's data
1061 $networkTypeData = getNetworkTypeDataById($networkId);
1063 // Do we have found the network?
1064 if (count($networkTypeData) > 0) {
1065 if (isFormSent('edit')) {
1066 // Add row template for deleting
1067 $OUT .= loadTemplate('admin_edit_network_types_row', true, $networkTypeData);
1068 } elseif (isFormSent('delete')) {
1069 // Add row template for deleting
1070 $OUT .= loadTemplate('admin_delete_network_types_row', true, $networkTypeData);
1073 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
1079 // If we have no rows, we don't need to display the edit form
1081 // Output main template
1082 if (isFormSent('edit')) {
1083 loadTemplate('admin_edit_network_types', false, $OUT);
1084 } elseif (isFormSent('delete')) {
1085 loadTemplate('admin_delete_network_types', false, $OUT);
1088 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
1091 // Don't display the list/add new form
1092 $GLOBALS['network_display'] = false;
1094 // Nothing selected/found
1095 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPE_HANDLER_NOTHING_FOUND--}');
1100 // Handle network request parameter form
1101 function doAdminNetworkProcessHandleRequestParams () {
1102 // Do we have selections?
1103 if (ifPostContainsSelections()) {
1105 $GLOBALS['network_request_params_disabled'] = array();
1107 // Load network data
1108 $networkData = getNetworkDataById(getRequestElement('network_id'));
1110 // Something has been selected, so start displaying one by one
1112 foreach (postRequestElement('sel') as $networkId => $sel) {
1113 // Is this selected?
1115 // Load this network's data
1116 $networkRequestData = getNetworkRequestParamsDataById($networkId);
1118 // Do we have found the network?
1119 if (count($networkRequestData) > 0) {
1120 if (isFormSent('edit')) {
1121 // Add row template for deleting
1122 $OUT .= loadTemplate('admin_edit_network_request_params_row', true, $networkRequestData);
1123 } elseif (isFormSent('delete')) {
1125 $networkRequestData['network_type_data'] = getNetworkTypeDataById($networkRequestData['network_type_id']);
1127 // Add row template for deleting
1128 $OUT .= loadTemplate('admin_delete_network_request_params_row', true, $networkRequestData);
1131 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
1137 // If we have no rows, we don't need to display the edit form
1139 // Output main template
1140 if (isFormSent('edit')) {
1141 loadTemplate('admin_edit_network_request_params', false, $OUT);
1142 } elseif (isFormSent('delete')) {
1143 loadTemplate('admin_delete_network_request_params', false, $OUT);
1146 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
1149 // Don't display the list/add new form
1150 $GLOBALS['network_display'] = false;
1152 // Nothing selected/found
1153 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_FOUND--}');
1158 // Changes given networks
1159 function doAdminNetworkProcessChangeNetworks () {
1160 // Do we have selections?
1161 if (ifPostContainsSelections()) {
1162 // By default nothing is updated
1165 // Something has been selected, so start updating them
1166 foreach (postRequestElement('sel') as $networkId => $sel) {
1167 // Update this entry?
1170 $networkData = array();
1172 // Transfer whole array, except 'sel'
1173 foreach (postRequestArray() as $key => $entry) {
1174 // Skip 'sel' and submit button
1175 if (in_array($key, array('sel', 'do_edit'))) {
1179 // Do we have this enty?
1180 if (!isset($entry[$networkId])) {
1181 // Not found, needs fixing
1182 debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1186 $networkData[$key] = $entry[$networkId];
1189 // Update the network data
1190 $updated += doNetworkUpdateDataByArray($networkId, $networkData);
1194 // Do we have updates?
1197 displayMessage('{%message,ADMIN_NETWORK_UPDATED=' . $updated . '%}');
1200 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_CHANGED--}');
1205 // Removes given networks
1206 function doAdminNetworkProcessRemoveNetworks () {
1207 // Do we have selections?
1208 if (ifPostContainsSelections()) {
1209 // By default nothing is removed
1212 // Something has been selected, so start updating them
1213 foreach (postRequestElement('sel') as $networkId => $sel) {
1214 // Update this entry?
1216 // Remove this entry
1217 $removed += doAdminRemoveNetworkEntry('data', 'network_id', $networkId);
1221 // Do we have removes?
1224 displayMessage('{%message,ADMIN_NETWORK_REMOVED=' . $removed . '%}');
1227 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_REMOVED--}');
1232 // Add a network type handler if not yet found
1233 function doAdminNetworkProcessAddNetworkType () {
1234 // Is the network type handle already used with given network?
1235 if (isNetworkTypeHandleValid(postRequestElement('network_type_handler'), getRequestElement('network_id'))) {
1237 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_TYPE_HANDLER_ALREADY_ADDED=' . postRequestElement('network_type_handler') . '%}');
1239 // ... so abort here
1243 // Remove the 'ok' part
1244 unsetPostRequestElement('ok');
1247 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1249 // Is network_type_banner_url set?
1250 if (postRequestElement('network_type_banner_url') == '') {
1251 // Remove empty value to get a NULL for an optional entry
1252 unsetPostRequestElement('network_type_banner_url');
1255 // Add the whole request to database
1256 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_types'), __FUNCTION__, __LINE__);
1259 if (!SQL_HASZEROAFFECTED()) {
1260 // Successfully added
1261 loadTemplate('admin_network_type_added', false, postRequestArray());
1264 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_TYPE_HANDLER_NOT_ADDED=' . postRequestElement('network_type_handler') . '%}');
1268 // Changes given network type handlers
1269 function doAdminNetworkProcessChangeHandlerTypes () {
1270 // Do we have selections?
1271 if (ifPostContainsSelections()) {
1272 // By default nothing is updated
1275 // Something has been selected, so start updating them
1276 foreach (postRequestElement('sel') as $networkId => $sel) {
1277 // Update this entry?
1280 $networkTypeData = array();
1282 // Transfer whole array, except 'sel'
1283 foreach (postRequestArray() as $key => $entry) {
1284 // Skip 'sel' and submit button
1285 if (in_array($key, array('sel', 'do_edit'))) {
1289 // Do we have this enty?
1290 if (!isset($entry[$networkId])) {
1291 // Not found, needs fixing
1292 debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1295 // Fix empty network_type_banner_url to NULL
1296 if (($key == 'network_type_banner_url') && (trim($entry[$networkId]) == '')) {
1298 $entry[$networkId] = NULL;
1302 $networkTypeData[$key] = $entry[$networkId];
1305 // Update the network data
1306 $updated += doNetworkUpdateTypeByArray($networkId, $networkTypeData);
1310 // Do we have updates?
1313 displayMessage('{%message,ADMIN_NETWORK_TYPE_HANDLER_UPDATED=' . $updated . '%}');
1316 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPE_HANDLER_NOTHING_CHANGED--}');
1321 // Changes given network request parameters
1322 function doAdminNetworkProcessChangeRequestParams () {
1323 // Do we have selections?
1324 if (ifPostContainsSelections()) {
1325 // By default nothing is updated
1328 // Something has been selected, so start updating them
1329 foreach (postRequestElement('sel') as $networkId => $sel) {
1330 // Update this entry?
1333 $networkParamsData = array();
1335 // Transfer whole array, except 'sel'
1336 foreach (postRequestArray() as $key => $entry) {
1337 // Skip 'sel' and submit button
1338 if (in_array($key, array('sel', 'do_edit'))) {
1342 // Do we have this enty?
1343 if (!isset($entry[$networkId])) {
1344 // Not found, needs fixing
1345 debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1348 // Fix empty network_request_param_default to NULL
1349 if (($key == 'network_request_param_default') && (trim($entry[$networkId]) == '')) {
1351 $entry[$networkId] = NULL;
1355 $networkParamsData[$key] = $entry[$networkId];
1358 // Update the network data
1359 $updated += doNetworkUpdateParamsByArray($networkId, $networkParamsData);
1363 // Do we have updates?
1366 displayMessage('{%message,ADMIN_NETWORK_REQUEST_PARAMETER_UPDATED=' . $updated . '%}');
1369 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_CHANGED--}');
1374 // Removes given network type handlers
1375 function doAdminNetworkProcessRemoveNetworkTypes () {
1376 // Do we have selections?
1377 if (ifPostContainsSelections()) {
1378 // By default nothing is removed
1381 // Something has been selected, so start updating them
1382 foreach (postRequestElement('sel') as $networkId => $sel) {
1383 // Update this entry?
1385 // Remove this entry
1386 $removed += doAdminRemoveNetworkEntry('types', 'network_type_id', $networkId);
1390 // Do we have removes?
1393 displayMessage('{%message,ADMIN_NETWORK_TYPE_HANDLER_REMOVED=' . $removed . '%}');
1396 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPE_HANDLER_NOTHING_REMOVED--}');
1401 // Removes given network request parameters
1402 function doAdminNetworkProcessRemoveNetworkRequestParams () {
1403 // Do we have selections?
1404 if (ifPostContainsSelections()) {
1405 // By default nothing is removed
1408 // Something has been selected, so start updating them
1409 foreach (postRequestElement('sel') as $networkId => $sel) {
1410 // Update this entry?
1412 // Remove this entry
1413 $removed += doAdminRemoveNetworkEntry('request_params', 'network_request_param_id', $networkId);
1417 // Do we have removes?
1420 displayMessage('{%message,ADMIN_NETWORK_REQUEST_PARAMETER_REMOVED=' . $removed . '%}');
1423 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_REMOVED--}');
1428 // Adds a request parameter to given network and type
1429 function doAdminNetworkProcessAddRequestParam () {
1430 // Is the request parameter already used with given network?
1431 if (isNetworkRequestElementValid(postRequestElement('network_request_param_key'), postRequestElement('network_type_id'), getRequestElement('network_id'))) {
1433 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_REQUEST_PARAMETER_ALREADY_ADDED=' . postRequestElement('network_request_param_key') . '%}');
1435 // ... so abort here
1439 // Remove the 'ok' part
1440 unsetPostRequestElement('ok');
1443 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1445 // Is network_request_param_default set?
1446 if (postRequestElement('network_request_param_default') == '') {
1447 // Remove empty value to get a NULL for an optional entry
1448 unsetPostRequestElement('network_request_param_default');
1451 // Add the whole request to database
1452 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_request_params'), __FUNCTION__, __LINE__);
1455 if (!SQL_HASZEROAFFECTED()) {
1456 // Successfully added
1457 loadTemplate('admin_network_request_param_added', false, postRequestArray());
1460 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_REQUEST_PARAMETER_NOT_ADDED=' . postRequestElement('network_request_param_key') . '%}');
1464 // Adds a vheck request parameter to given network
1465 function doAdminNetworkProcessAddVcheckParam () {
1466 // Is the request parameter already used with given network?
1467 if (isNetworkVcheckElementValid(postRequestElement('network_vcheck_param_key'), getRequestElement('network_id'))) {
1469 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_VCHECK_PARAMETER_ALREADY_ADDED=' . postRequestElement('network_vcheck_param_key') . '%}');
1471 // ... so abort here
1475 // Remove the 'ok' part
1476 unsetPostRequestElement('ok');
1479 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1481 // Is network_vcheck_param_default set?
1482 if (postRequestElement('network_vcheck_param_default') == '') {
1483 // Remove empty value to get a NULL for an optional entry
1484 unsetPostRequestElement('network_vcheck_param_default');
1487 // Add the whole vcheck to database
1488 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_vcheck_params'), __FUNCTION__, __LINE__);
1491 if (!SQL_HASZEROAFFECTED()) {
1492 // Successfully added
1493 loadTemplate('admin_network_vcheck_param_added', false, postRequestArray());
1496 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_VCHECK_PARAMETER_NOT_ADDED=' . postRequestElement('network_vcheck_param_key') . '%}');
1500 // Adds a API response array entry
1501 function doAdminNetworkProcessAddNetworkArrayTranslation () {
1502 // Is the request parameter already used with given network?
1503 if (isNetworkArrayTranslationValid(postRequestElement('network_array_index'), postRequestElement('network_type_id'), getRequestElement('network_id'))) {
1505 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_ARRAY_TRANSLATION_ALREADY_ADDED=' . postRequestElement('network_array_index') . '%}');
1507 // ... so abort here
1511 // Remove the 'ok' part
1512 unsetPostRequestElement('ok');
1515 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1518 setPostRequestElement('sort', (countSumTotalData(
1519 bigintval(postRequestElement('network_id')),
1520 'network_array_translation',
1524 sprintf(" AND `network_type_id`=%s", bigintval(postRequestElement('network_type_id')))
1527 // Add the whole request to database
1528 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_array_translation'), __FUNCTION__, __LINE__);
1531 if (!SQL_HASZEROAFFECTED()) {
1532 // Successfully added
1533 loadTemplate('admin_network_array_translation_added', false, postRequestArray());
1536 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_ARRAY_TRANSLATION_NOT_ADDED=' . postRequestElement('network_array_index') . '%}');
1540 // Adds/update network API configuration
1541 function doAdminNetworkProcessNetworkApiConfig () {
1542 // Remove the 'ok' part
1543 unsetPostRequestElement('ok');
1546 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1548 // Is network_api_referral_button set?
1549 if (postRequestElement('network_api_referral_button') == '') {
1550 // Remove empty value to get a NULL for an optional entry
1551 unsetPostRequestElement('network_api_referral_button');
1554 // Is there already an entry?
1555 if (isNetworkApiConfigured(getRequestElement('network_id'))) {
1556 // Generate SQL query
1557 $SQL = getUpdateSqlFromArray(postRequestArray(), 'network_api_config', 'network_id', postRequestElement('network_id'), array('network_id'));
1560 $SQL = getInsertSqlFromArray(postRequestArray(), 'network_api_config');
1564 SQL_QUERY($SQL, __FUNCTION__, __LINE__);
1567 if (!SQL_HASZEROAFFECTED()) {
1568 // Successfully added
1569 displayMessage('{--ADMIN_CONFIG_NETWORK_API_SAVED--}');
1572 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_API_NOT_SAVED--}');
1576 // Only adds network type configuration if not yet present
1577 function doAdminNetworkProcessAddHandlerTypesConfig ($displayMessage = true) {
1578 // Remove the 'ok' part
1579 unsetPostRequestElement('ok');
1582 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1583 setPostRequestElement('network_type_id', bigintval(getRequestElement('network_type_id')));
1586 * Some parameters are optional, at least one must be given so check a bunch
1589 foreach (array('network_min_waiting_time', 'network_min_remain_clicks', 'network_min_payment', 'network_allow_erotic') as $element) {
1590 // Is this element empty?
1591 if (postRequestElement($element) == '') {
1592 // Then unset it to get a NULL for optional parameter
1593 unsetPostRequestElement($element);
1597 // Initialize variables
1599 $id = 'network_max_reload_time_ye';
1602 // Get all POST data
1603 $postData = postRequestArray();
1605 // Convert "reload time selections"
1606 convertSelectionsToEpocheTime($postData, $content, $id, $skip);
1608 // Set the POST array back
1609 setPostRequestArray($postData);
1611 // Is there already an entry?
1612 if (isNetworkTypeHandlerConfigured(getRequestElement('network_id'), getRequestElement('network_type_id'))) {
1613 // This network type handler is already configured
1614 displayMessage('{--ADMIN_NETWORK_HANDLER_TYPE_HANDLER_ALREADY_CONFIGURED--}');
1618 // Copy 'set all' and remove it from POST data
1619 $setAll = (postRequestElement('set_all') === 'Y');
1620 unsetPostRequestElement('set_all');
1622 // Shall we set for all?
1623 if ($setAll === true) {
1625 $result = SQL_QUERY_ESC('SELECT `network_type_id` FROM `{?_MYSQL_PREFIX?}_network_types` WHERE `network_id`=%s ORDER BY `network_type_id` ASC',
1626 array(bigintval(getRequestElement('network_id'))), __FUNCTION__, __LINE__);
1628 // Do we have entries?
1629 if (SQL_HASZERONUMS($result)) {
1630 // No, then abort here
1631 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_SET_ALL_404--}');
1635 // Init number of rows
1639 while (list($typeId) = SQL_FETCHROW($result)) {
1640 // Set it in GET data
1641 setGetRequestElement('network_type_id', $typeId);
1643 // Call this function again
1644 $numRows += doAdminNetworkProcessAddHandlerTypesConfig(false);
1648 SQL_FREERESULT($result);
1652 // Something has been updated
1653 displayMessage('{%message,ADMIN_CONFIG_NETWORK_HANDLER_TYPE_ALL_HANDLER_SAVED=' . bigintval($numRows) . '%}');
1655 // Nothing has been saved
1656 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}');
1659 // Get SQL query for new entry
1660 $SQL = getInsertSqlFromArray(postRequestArray(), 'network_types_config');
1663 SQL_QUERY($SQL, __FUNCTION__, __LINE__);
1665 // Shall we display the message?
1666 if ($displayMessage === true) {
1668 if (!SQL_HASZEROAFFECTED()) {
1669 // Successfully added
1670 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_SAVED--}');
1673 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_SAVED--}');
1676 // Return amount of affected rows (1 or 2)
1677 return SQL_AFFECTEDROWS();
1682 // Only changes network type configuration if not yet present
1683 function doAdminNetworkProcessEditHandlerTypesConfig ($displayMessage = true) {
1684 // Remove the 'ok' part
1685 unsetPostRequestElement('ok');
1688 * Some parameters are optional, at least one must be given so check a bunch
1691 foreach (array('network_min_waiting_time', 'network_min_remain_clicks', 'network_min_payment', 'network_allow_erotic') as $element) {
1692 // Is this element empty?
1693 if (postRequestElement($element) == '') {
1694 // Then unset it to get a NULL for optional parameter
1695 unsetPostRequestElement($element);
1699 // Initialize variables
1701 $id = 'network_max_reload_time_ye';
1703 $postData = postRequestArray();
1705 // Convert "reload time selections"
1706 convertSelectionsToEpocheTime($postData, $content, $id, $skip);
1708 // Set the POST array back
1709 setPostRequestArray($postData);
1711 // Is there already an entry?
1712 if (!isNetworkTypeHandlerConfigured(getRequestElement('network_id'), getRequestElement('network_type_id'))) {
1713 // This network type handler is not configured
1714 displayMessage('{--ADMIN_NETWORK_HANDLER_TYPE_HANDLER_NOT_CONFIGURED--}');
1718 // Copy 'set all' and remove it from POST data
1719 $setAll = (postRequestElement('set_all') === 'Y');
1720 unsetPostRequestElement('set_all');
1722 // Shall we set for all?
1723 if ($setAll === true) {
1724 // Get all data entries
1725 $result = SQL_QUERY_ESC('SELECT `network_data_id` FROM `{?_MYSQL_PREFIX?}_network_types_config` WHERE `network_id`=%s ORDER BY `network_type_id` ASC',
1726 array(bigintval(getRequestElement('network_id'))), __FUNCTION__, __LINE__);
1728 // Do we have entries?
1729 if (SQL_HASZERONUMS($result)) {
1730 // No, then abort here
1731 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_SET_ALL_404--}');
1735 // Init number of rows
1739 while (list($dataId) = SQL_FETCHROW($result)) {
1740 // Set it in GET data
1741 setPostRequestElement('network_data_id', $dataId);
1743 // Call this function again
1744 $numRows += doAdminNetworkProcessEditHandlerTypesConfig(false);
1748 SQL_FREERESULT($result);
1752 // Something has been updated
1753 displayMessage('{%message,ADMIN_CONFIG_NETWORK_HANDLER_TYPE_ALL_HANDLER_SAVED=' . bigintval($numRows) . '%}');
1755 // Nothing has been saved
1756 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}');
1759 // Get SQL query for new entry
1760 $SQL = getUpdateSqlFromArray(postRequestArray(), 'network_types_config', 'network_data_id', postRequestElement('network_data_id'), array('network_data_id'));
1763 SQL_QUERY($SQL, __FUNCTION__, __LINE__);
1765 // Shall we display the message?
1766 if ($displayMessage === true) {
1768 if (!SQL_HASZEROAFFECTED()) {
1769 // Successfully added
1770 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_SAVED--}');
1773 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}');
1776 // Return amount of affected rows (1 or 2)
1777 return SQL_AFFECTEDROWS();
1782 // Do expression code for this extension
1783 function doExpressionNetwork ($data) {
1784 // Construct replacer
1785 $replacer = sprintf(
1786 "{DQUOTE} . %s(%s, '%s') . {DQUOTE}",
1788 $data['matches'][4][$data['key']],
1792 // Replace %network_id% with the current network id
1793 $replacer = str_replace('%network_id%', getCurrentNetworkId(), $replacer);
1796 $code = replaceExpressionCode($data, $replacer);
1802 // ----------------------------------------------------------------------------
1803 // Call-back functions for exporting data
1804 // ----------------------------------------------------------------------------
1806 // Callback function to export network tables
1807 function doAdminNetworkProcessExport () {
1808 // Init table with all valid what->table entries
1809 $validExports = array(
1810 // General network data
1811 'list_networks' => 'data',
1812 // Network type handler
1813 'list_network_types' => 'types',
1814 // Network request parameter
1815 'list_network_request_params' => 'request_params',
1816 // Vcheck request parameter
1817 'list_network_vcheck_params' => 'vcheck_params',
1818 // Network API response array index translation
1819 'list_network_array_translation' => 'array_translation',
1822 // Is the 'what' key valid?
1823 if (!isset($validExports[getWhat()])) {
1825 debug_report_bug(__FUNCTION__, __LINE__, 'what=' . getWhat() . ' - not supported');
1828 // Generate call-back, some tables require to export not all columns
1829 $callbackName = 'doAdminNetworkExport' . capitalizeUnderscoreString($validExports[getWhat()]);
1831 // Is the call-back function there?
1832 if (!function_exists($callbackName)) {
1833 // No, this is really bad
1834 debug_report_bug(__FUNCTION__, __LINE__, 'Invalid call-back function ' . $callbackName . ' detected.');
1835 } elseif (isset($GLOBALS[__FUNCTION__][$callbackName])) {
1837 debug_report_bug(__FUNCTION__, __LINE__, 'Double-call of export function ' . $callbackName . ' detected.');
1840 // Call the function
1841 call_user_func($callbackName);
1843 // Mark it as called
1844 $GLOBALS[__FUNCTION__][$callbackName] = true;
1846 // Don't display the list/add new form
1847 $GLOBALS['network_display'] = false;
1850 // Exports (and displays) the table 'network_data'
1851 function doAdminNetworkExportData () {
1852 // Query for all networks
1853 $result = SQL_QUERY('SELECT
1854 `network_short_name`,
1857 `network_data_separator`,
1858 `network_row_separator`,
1859 `network_request_type`,
1861 `network_require_id_card`,
1862 `network_query_amount`,
1865 `{?_MYSQL_PREFIX?}_network_data`
1868 __FUNCTION__, __LINE__);
1870 // Start an empty SQL query
1871 $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";
1874 while ($content = SQL_FETCHARRAY($result)) {
1877 $content['network_short_name'] . "', '" .
1878 $content['network_title'] . "', '" .
1879 $content['network_reflink'] . "', '" .
1880 $content['network_data_separator'] . "', '" .
1881 $content['network_row_separator'] . "', '" .
1882 $content['network_request_type'] . "', '" .
1883 $content['network_charset'] . "', '" .
1884 $content['network_require_id_card'] . "', " .
1885 $content['network_query_amount'] . ", '" .
1886 $content['network_active'] . "'),\n";
1889 // Remove last commata and close braces
1890 $SQL = substr($SQL, 0, -2);
1893 SQL_FREERESULT($result);
1895 // Output the SQL query
1896 loadTemplate('admin_export_network_data', false, $SQL);
1899 // Exports (and displays) the table 'network_types'
1900 function doAdminNetworkExportTypes () {
1901 // 'network_id' must be set
1902 if (!isGetRequestElementSet('network_id')) {
1903 // Only network handlers of one network will be exported per time
1904 debug_report_bug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
1907 // Get all network types of given network
1908 $result = SQL_QUERY_ESC('SELECT
1911 `network_type_handler`,
1912 `network_type_api_url`,
1913 `network_type_click_url`,
1914 `network_type_banner_url`,
1915 `network_type_reload_time_unit`
1917 `{?_MYSQL_PREFIX?}_network_types`
1921 `network_type_id` ASC',
1923 bigintval(getRequestElement('network_id'))
1924 ), __FUNCTION__, __LINE__);
1926 // Start an empty SQL query
1927 $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";
1930 while ($content = SQL_FETCHARRAY($result)) {
1933 $content['network_type_id'] . ', ' .
1934 $content['network_id'] . ", '" .
1935 $content['network_type_handler'] . "', '" .
1936 $content['network_type_api_url'] . "', '" .
1937 $content['network_type_click_url'] . "', ";
1939 // Is the column NULL?
1940 if (is_null($content['network_type_banner_url'])) {
1945 $SQL .= "'" . $content['network_type_banner_url'] . "'";
1949 $SQL .= ",'" . $content['network_type_reload_time_unit'] . "'),\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_types', false, $SQL);
1962 // Exports (and displays) the table 'network_request_params'
1963 function doAdminNetworkExportRequestParams () {
1964 // 'network_id' must be set
1965 if (!isGetRequestElementSet('network_id')) {
1966 // Only network request parameters of one network will be exported per time
1967 debug_report_bug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
1970 // Get all network types of given network
1971 $result = SQL_QUERY_ESC('SELECT
1974 `network_request_param_key`,
1975 `network_request_param_value`,
1976 `network_request_param_default`
1978 `{?_MYSQL_PREFIX?}_network_request_params`
1982 `network_type_id` ASC ,
1983 `network_request_param_id` ASC',
1985 bigintval(getRequestElement('network_id'))
1986 ), __FUNCTION__, __LINE__);
1988 // Start an empty SQL query
1989 $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";
1992 while ($content = SQL_FETCHARRAY($result)) {
1995 $content['network_id'] . ', ' .
1996 $content['network_type_id'] . ", '" .
1997 $content['network_request_param_key'] . "', '" .
1998 $content['network_request_param_value'] . "', ";
2000 // Is the column NULL?
2001 if (is_null($content['network_request_param_default'])) {
2006 $SQL .= "'" . $content['network_request_param_default'] . "'),\n";
2010 // Remove last commata and close braces
2011 $SQL = substr($SQL, 0, -2);
2014 SQL_FREERESULT($result);
2016 // Output the SQL query
2017 loadTemplate('admin_export_network_request_params', false, $SQL);
2020 // Exports (and displays) the table 'network_vcheck_params'
2021 function doAdminNetworkExportVcheckParams () {
2022 // 'network_id' must be set
2023 if (!isGetRequestElementSet('network_id')) {
2024 // Only network vcheck parameters of one network will be exported per time
2025 debug_report_bug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
2028 // Get all network types of given network
2029 $result = SQL_QUERY_ESC('SELECT
2031 `network_vcheck_param_key`,
2032 `network_vcheck_param_value`,
2033 `network_vcheck_param_default`
2035 `{?_MYSQL_PREFIX?}_network_vcheck_params`
2039 `network_vcheck_param_id` ASC',
2041 bigintval(getRequestElement('network_id'))
2042 ), __FUNCTION__, __LINE__);
2044 // Start an empty SQL query
2045 $SQL = "INSERT INTO `{?_MYSQL_PREFIX?}_network_vcheck_params` (`network_id`,`network_vcheck_param_key`,`network_vcheck_param_value`,`network_vcheck_param_default`) VALUES\n";
2048 while ($content = SQL_FETCHARRAY($result)) {
2051 $content['network_id'] . ", '" .
2052 $content['network_vcheck_param_key'] . "', '" .
2053 $content['network_vcheck_param_value'] . "', ";
2055 // Is the column NULL?
2056 if (is_null($content['network_vcheck_param_default'])) {
2061 $SQL .= "'" . $content['network_vcheck_param_default'] . "'),\n";
2065 // Remove last commata and close braces
2066 $SQL = substr($SQL, 0, -2);
2069 SQL_FREERESULT($result);
2071 // Output the SQL query
2072 loadTemplate('admin_export_network_vcheck_params', false, $SQL);
2075 // Exports (and displays) the table 'network_array_translation'
2076 function doAdminNetworkExportArrayTranslation () {
2077 // 'network_id' must be set
2078 if (!isGetRequestElementSet('network_id')) {
2079 // Only network API array index translations of one network will be exported per time
2080 debug_report_bug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
2083 // Get all network types of given network
2084 $result = SQL_QUERY_ESC('SELECT
2087 `network_array_index`,
2090 `{?_MYSQL_PREFIX?}_network_array_translation`
2094 `network_type_id` ASC,
2097 bigintval(getRequestElement('network_id'))
2098 ), __FUNCTION__, __LINE__);
2100 // Start an empty SQL query
2101 $SQL = "INSERT INTO `{?_MYSQL_PREFIX?}_network_array_translation` (`network_id`,`network_type_id`,`network_array_index`,`sort`) VALUES\n";
2104 while ($content = SQL_FETCHARRAY($result)) {
2107 $content['network_id'] . ', ' .
2108 $content['network_type_id'] . ', ' .
2109 $content['network_array_index'] . ', ' .
2110 $content['sort'] . "),\n";
2113 // Remove last commata and close braces
2114 $SQL = substr($SQL, 0, -2);
2117 SQL_FREERESULT($result);
2119 // Output the SQL query
2120 loadTemplate('admin_export_network_array_translation', false, $SQL);