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 - 2012 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 reportBug(__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 reportBug(__FUNCTION__, __LINE__, 'POST form could not be detected.');
83 // Handle a (maybe) sent form here
84 function doNetworkHandleForm () {
85 // Is there 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 reportBug(__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 whether 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 whether 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 whether 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 whether 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 whether 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 reportBug(__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 // Is there 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 reportBug(__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`,
297 t.`network_text_encoding`
299 `{?_MYSQL_PREFIX?}_network_data` AS d
301 `{?_MYSQL_PREFIX?}_network_types` AS t
303 d.`network_id`=t.`network_id`
305 t.`network_type_id`=%s
307 array(bigintval($networkId)), __FUNCTION__, __LINE__);
309 // Is there an entry?
310 if (SQL_NUMROWS($result) == 1) {
312 $GLOBALS['network_data'][$networkId] = SQL_FETCHARRAY($result);
316 SQL_FREERESULT($result);
320 if (empty($column)) {
322 return $GLOBALS['network_data'][$networkId];
325 return $GLOBALS['network_data'][$networkId][$column];
329 // "Getter" for a network type data by provided id number
330 function getNetworkTypeDataById ($networkId) {
331 // Ids lower one are not accepted
332 if ($networkId < 1) {
333 // Not good, should be fixed
334 reportBug(__FUNCTION__, __LINE__, 'Network type id ' . $networkId . ' is smaller than 1.');
337 // By default we have no data
338 $GLOBALS['network_type_data'][$networkId] = array();
340 // Query for the network data
341 $result = SQL_QUERY_ESC('SELECT
344 `network_type_handler`,
345 `network_type_api_url`,
346 `network_type_click_url`,
347 `network_type_banner_url`
349 `{?_MYSQL_PREFIX?}_network_types`
353 array(bigintval($networkId)), __FUNCTION__, __LINE__);
355 // Is there an entry?
356 if (SQL_NUMROWS($result) == 1) {
358 $GLOBALS['network_type_data'][$networkId] = SQL_FETCHARRAY($result);
362 SQL_FREERESULT($result);
365 return $GLOBALS['network_type_data'][$networkId];
368 // "Getter" for a network request parameter data by provided id number
369 function getNetworkRequestParamsDataById ($networkId) {
370 // Ids lower one are not accepted
371 if ($networkId < 1) {
372 // Not good, should be fixed
373 reportBug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $networkId . ' is smaller than 1.');
376 // By default we have no data
377 $networkRequestData = array();
379 // Query for the network data
380 $result = SQL_QUERY_ESC('SELECT
381 `network_request_param_id`,
384 `network_request_param_key`,
385 `network_request_param_value`,
386 `network_request_param_default`
388 `{?_MYSQL_PREFIX?}_network_request_params`
390 `network_request_param_id`=%s
392 array(bigintval($networkId)), __FUNCTION__, __LINE__);
394 // Is there an entry?
395 if (SQL_NUMROWS($result) == 1) {
397 $networkRequestData = SQL_FETCHARRAY($result);
401 SQL_FREERESULT($result);
404 return $networkRequestData;
407 // Updates given network (id) with data from array
408 function doNetworkUpdateDataByArray ($networkId, $networkData) {
409 // Ids lower one are not accepted
410 if ($networkId < 1) {
411 // Not good, should be fixed
412 reportBug(__FUNCTION__, __LINE__, 'Network id ' . $networkId . ' is smaller than 1.');
415 // Just call our inner method
416 return adminSaveSettings($networkData, '_network_data', sprintf("`network_id`=%s", bigintval($networkId)), array(), false, false);
419 // Updates given network type handler (id) with data from array
420 function doNetworkUpdateTypeByArray ($networkId, $networkTypeData) {
421 // Ids lower one are not accepted
422 if ($networkId < 1) {
423 // Not good, should be fixed
424 reportBug(__FUNCTION__, __LINE__, 'Network type handler id ' . $networkId . ' is smaller than 1.');
427 // Just call our inner method
428 return adminSaveSettings($networkTypeData, '_network_types', sprintf("`network_type_id`=%s", bigintval($networkId)), array(), false, false);
431 // Updates given network request parameters (id) with data from array
432 function doNetworkUpdateParamsByArray ($networkId, $networkParamData) {
433 // Ids lower one are not accepted
434 if ($networkId < 1) {
435 // Not good, should be fixed
436 reportBug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $networkId . ' is smaller than 1.');
439 // Just call our inner method
440 return adminSaveSettings($networkParamData, '_network_request_params', sprintf("`network_request_param_id`=%s", bigintval($networkId)), array(), false, false);
443 // Removes given network entry
444 function doAdminRemoveNetworkEntry ($table, $column, $networkId, $limit = 1) {
446 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_network_%s` WHERE `%s`=%s LIMIT %s",
452 ), __FUNCTION__, __LINE__);
454 // Return affected rows
455 return SQL_AFFECTEDROWS();
458 // Generates a list of networks for given script and returns it
459 function generateAdminNetworkList () {
463 // Query for all networks
464 $result = SQL_QUERY("SELECT
466 `network_short_name`,
469 `{?_MYSQL_PREFIX?}_network_data`
473 `network_short_name` ASC", __FUNCTION__, __LINE__);
475 // Are there entries?
476 if (!SQL_HASZERONUMS($result)) {
479 while ($row = SQL_FETCHARRAY($result)) {
480 // Is this valid, then add it
481 if ((is_array($row)) && (isset($row['network_id']))) {
483 $rows[$row['network_id']] = $row;
487 // Generate the selection box
488 $content = generateSelectionBoxFromArray($rows, 'network_id', 'network_id', '', '', 'network');
491 $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}');
495 SQL_FREERESULT($result);
501 // Generator (somewhat getter) for a list of network types for given network id
502 function generateAdminNetworkTypeList ($networkId) {
506 // Query all types of this network
507 $result = SQL_QUERY_ESC('SELECT
509 `network_type_handler`
511 `{?_MYSQL_PREFIX?}_network_types`
515 `network_type_handler` ASC',
517 bigintval($networkId)
518 ), __FUNCTION__, __LINE__);
520 // Are there entries?
521 if (!SQL_HASZERONUMS($result)) {
524 while ($row = SQL_FETCHARRAY($result)) {
525 // Is this valid, then add it
526 if ((is_array($row)) && (isset($row['network_type_id']))) {
528 $rows[$row['network_type_id']] = $row;
532 // Generate the selection box
533 $content = generateSelectionBoxFromArray($rows, 'network_type', 'network_type_id');
536 $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}');
540 SQL_FREERESULT($result);
546 // Generator (somewhat getter) for a list of network types for all types
547 function generateAdminDistinctNetworkTypeList () {
551 // Query all types of this network
552 $result = SQL_QUERY("SELECT
554 t.`network_type_handler`,
557 `{?_MYSQL_PREFIX?}_network_types` AS t
559 `{?_MYSQL_PREFIX?}_network_data` AS d
561 t.`network_id`=d.`network_id`
563 d.`network_active`='Y'
565 d.`network_short_name` ASC,
566 t.`network_type_handler` ASC", __FUNCTION__, __LINE__);
568 // Are there entries?
569 if (!SQL_HASZERONUMS($result)) {
572 while ($row = SQL_FETCHARRAY($result)) {
573 // Is this valid, then add it
574 if ((is_array($row)) && (isset($row['network_type_id']))) {
576 $rows[$row['network_type_id']] = $row;
580 // Generate the selection box
581 $content = generateSelectionBoxFromArray($rows, 'network_type', 'network_type_id', '', '_title');
584 $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}');
588 SQL_FREERESULT($result);
589 //* DEBUG: */ die('<pre>'.encodeEntities($content).'</pre>');
595 // Generator (somewhat getter) for network type options
596 function generateNetworkTypeOptions ($networkId) {
597 // Is this an array, then we just came back from edit/delete actions
598 if (is_array($networkId)) {
603 if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
604 // Generate output and cache it
605 $GLOBALS[__FUNCTION__][$networkId] = generateOptions(
608 'network_type_handler',
612 "WHERE `network_id`=%s",
613 bigintval(getRequestElement('network_id'))
616 'translateNetworkTypeHandler'
621 return $GLOBALS[__FUNCTION__][$networkId];
624 // Generates an options list of all available (hard-coded) handlers
625 function generateNetworkTypesAvailableOptions ($defaultType = NULL) {
627 if (!isset($GLOBALS[__FUNCTION__][$defaultType])) {
629 $GLOBALS[__FUNCTION__][$defaultType] = generateOptions(
665 $GLOBALS['network_types_disabled'],
666 'translateNetworkTypeHandler'
671 return $GLOBALS[__FUNCTION__][$defaultType];
674 // Generates an options list of all available (hard-coded) text encoders
675 function generateNetworkTextEncodingAvailableOptions ($defaultEncoding = NULL) {
677 if (!isset($GLOBALS[__FUNCTION__][$defaultEncoding])) {
679 $GLOBALS[__FUNCTION__][$defaultEncoding] = generateOptions(
689 'translateNetworkTextEncoding'
694 return $GLOBALS[__FUNCTION__][$defaultEncoding];
697 // Generates an options list (somewhat getter) for request keys
698 function generateNetworkRequestKeyOptions () {
700 if (!isset($GLOBALS[__FUNCTION__])) {
701 // Generate and cache it
702 $GLOBALS[__FUNCTION__] = generateOptions(
724 $GLOBALS['network_request_params_disabled'],
725 'translateNetworkRequestParameterKey'
730 return $GLOBALS[__FUNCTION__];
733 // Generates an options list for vcheck request keys
734 function generateNetworkVcheckKeyOptions () {
736 if (!isset($GLOBALS[__FUNCTION__])) {
737 // Generate and cache it
738 $GLOBALS[__FUNCTION__] = generateOptions(
758 $GLOBALS['network_vcheck_params_disabled'],
759 'translateNetworkVcheckParameterKey'
764 return $GLOBALS[__FUNCTION__];
767 // Generator (somewhat getter) for (return) array translation
768 function generateNetworkTranslationOptions ($default = '') {
770 if (!isset($GLOBALS[__FUNCTION__][$default])) {
771 // Generate and cache it
772 $GLOBALS[__FUNCTION__][$default] = generateOptions(
773 'network_translations',
774 'network_translation_id',
775 'network_translation_name',
779 $GLOBALS['network_translation_disabled'],
780 'translateNetworkTranslationName'
785 return $GLOBALS[__FUNCTION__][$default];
788 // Generates an option list of request types
789 function generateNetworkRequestTypeOptions ($default = '') {
791 if (!isset($GLOBALS[__FUNCTION__][$default])) {
793 $GLOBALS[__FUNCTION__][$default] = generateOptions(
800 '{--ADMIN_NETWORK_REQUEST_TYPE_GET--}',
801 '{--ADMIN_NETWORK_REQUEST_TYPE_POST--}'
808 return $GLOBALS[__FUNCTION__][$default];
811 // Generates an option list of network_api_active
812 function generateNetworkApiActiveOptions ($default = '') {
814 if (!isset($GLOBALS[__FUNCTION__][$default])) {
816 $GLOBALS[__FUNCTION__][$default] = generateYesNoOptions($default);
820 return $GLOBALS[__FUNCTION__][$default];
823 // Translates 'translate_name' for e.g. templates
824 function translateNetworkTranslationName ($name) {
826 $messageId = 'ADMIN_NETWORK_TRANSLATE_' . strtoupper($name) . '_NAME';
828 // Is the message id there?
829 if (!isMessageIdValid($messageId)) {
831 reportBug(__FUNCTION__, __LINE__, 'name=' . $name . ' is invalid.');
835 return '{--' . $messageId . '--}';
838 // Translates the network type handler (e.g. banner, paidmail) for templates
839 function translateNetworkTypeHandler ($type) {
841 $messageId = 'ADMIN_NETWORK_TYPE_HANDLER_' . strtoupper($type);
843 // Is the message id there?
844 if (!isMessageIdValid($messageId)) {
846 reportBug(__FUNCTION__, __LINE__, 'type=' . $type . ' is invalid.');
850 return '{--' . $messageId . '--}';
853 // Translates request type
854 function translateNetworkRequestType ($type) {
856 $messageId = 'ADMIN_NETWORK_REQUEST_TYPE_' . strtoupper($type) . '';
858 // Is the message id there?
859 if (!isMessageIdValid($messageId)) {
861 reportBug(__FUNCTION__, __LINE__, 'type=' . $type . ' is invalid.');
865 return '{--' . $messageId . '--}';
868 // Translates request parameter
869 function translateNetworkRequestParameterKey ($param) {
871 $messageId = 'ADMIN_NETWORK_REQUEST_PARAMETER_' . strtoupper($param) . '';
873 // Is the message id there?
874 if (!isMessageIdValid($messageId)) {
876 reportBug(__FUNCTION__, __LINE__, 'param=' . $param . ' is invalid.');
880 return '{--' . $messageId . '--}';
883 // Translates vheck request parameter
884 function translateNetworkVcheckParameterKey ($param) {
886 $messageId = 'ADMIN_NETWORK_VCHECK_PARAMETER_' . strtoupper($param) . '';
888 // Is the message id there?
889 if (!isMessageIdValid($messageId)) {
891 reportBug(__FUNCTION__, __LINE__, 'param=' . $param . ' is invalid.');
895 return '{--' . $messageId . '--}';
898 // Translate text-encoding
899 function translateNetworkTextEncoding ($encoding) {
901 $messageId = 'ADMIN_NETWORK_TYPE_TEXT_ENCODING_' . strtoupper($encoding) . '';
903 // Is the message id there?
904 if (!isMessageIdValid($messageId)) {
905 // Not valid encoding
906 reportBug(__FUNCTION__, __LINE__, 'encoding=' . $encoding . ' is invalid.');
910 return '{--' . $messageId . '--}';
913 // Translates API index
914 function translateNetworkApiIndex ($index) {
916 if (!isset($GLOBALS['network_array_index'])) {
917 // Get an array of all API array indexes
918 $GLOBALS['network_array_index'] = array();
921 $result = SQL_QUERY('SELECT
923 `network_array_index`,
924 `network_translation_name`
926 `{?_MYSQL_PREFIX?}_network_array_translation`
928 `{?_MYSQL_PREFIX?}_network_translations`
930 `network_array_index`=`network_translation_id`
932 `sort` ASC', __FUNCTION__, __LINE__);
934 // Are there entries?
935 if (!SQL_HASZERONUMS($result)) {
937 while ($row = SQL_FETCHARRAY($result)) {
938 // Add it to our global array
939 $GLOBALS['network_array_index'][$row['network_array_index']] = $row;
944 SQL_FREERESULT($result);
947 // Default name is unknown
950 // Is the entry there?
951 if (isset($GLOBALS['network_array_index'][$index])) {
953 $name = $GLOBALS['network_array_index'][$index]['network_translation_name'];
956 // Return translation
957 return translateNetworkTranslationName($name);
960 // Translates network API configuration status (see function isNetworkApiConfigured()) by given id
961 function translateNetworkApiConfiguredStatusById ($networkId) {
963 if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
964 // By default it is not configured
965 $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_NOT_CONFIGURED--}';
967 // So is it configured?
968 if (isNetworkApiConfigured($networkId)) {
970 $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_CONFIGURED--}';
975 return $GLOBALS[__FUNCTION__][$networkId];
978 // Checks if the given network is configured by looking its API configuration entry up
979 function isNetworkApiConfigured ($networkId) {
981 if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
982 // Check for an entry in network_api_config
983 $GLOBALS[__FUNCTION__][$networkId] = (countSumTotalData(
984 bigintval($networkId),
985 'network_api_config',
993 return $GLOBALS[__FUNCTION__][$networkId];
996 // Checks whether the given network type handler is configured
997 function isNetworkTypeHandlerConfigured ($networkId, $networkTypeId) {
999 if (!isset($GLOBALS[__FUNCTION__][$networkId][$networkTypeId])) {
1001 $GLOBALS[__FUNCTION__][$networkId][$networkTypeId] = (countSumTotalData(
1002 bigintval($networkTypeId),
1003 'network_types_config',
1007 sprintf(' AND `network_id`=%s', bigintval($networkId))
1012 return $GLOBALS[__FUNCTION__][$networkId][$networkTypeId];
1015 // Handles the network-payment-check request
1016 function handleNetworkPaymentCheckRequest () {
1017 // @TODO Implement this function, don't forget to set HTTP status back to '200 OK' if everything went fine
1018 reportBug(__FUNCTION__, __LINE__, 'Not yet implemented.');
1021 //------------------------------------------------------------------------------
1022 // Call-back functions
1023 //------------------------------------------------------------------------------
1025 // Callback function to add new network
1026 function doAdminNetworkProcessAddNetwork () {
1027 // We can say here, the form is sent, so check if the network is already added
1028 if (isNetworkNameValid(postRequestElement('network_short_name'))) {
1030 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_ALREADY_ADDED=' . postRequestElement('network_short_name') . '%}');
1034 // Remove the 'ok' part
1035 unsetPostRequestElement('ok');
1037 // Add the whole request to database
1038 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_data'), __FUNCTION__, __LINE__);
1040 // Add the id for output only
1041 setPostRequestElement('network_id', SQL_INSERTID());
1044 if (!SQL_HASZEROAFFECTED()) {
1045 // Successfully added
1046 loadTemplate('admin_network_added', false, postRequestArray());
1049 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_DATA_NOT_ADDED=' . postRequestElement('network_short_name') . '%}');
1053 // Displays selected networks for editing
1054 function doAdminNetworkProcessHandleNetworks () {
1055 // Is there selections?
1056 if (ifPostContainsSelections()) {
1057 // Something has been selected, so start displaying one by one
1059 foreach (postRequestElement('sel') as $networkId => $sel) {
1060 // Is this selected?
1062 // Load this network's data
1063 $networkData = getNetworkDataById($networkId);
1065 // Is there found the network?
1066 if (count($networkData) > 0) {
1067 // Add row template with given form name
1068 $OUT .= loadTemplate('admin_' . $GLOBALS['network_form_name'] . '_networks_row', true, $networkData);
1073 // If we have no rows, we don't need to display the edit form
1075 // Output main template
1076 loadTemplate('admin_' . $GLOBALS['network_form_name'] . '_networks', false, $OUT);
1078 // Don't display the list/add new form
1079 $GLOBALS['network_display'] = false;
1081 // Nothing selected/found
1082 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_FOUND--}');
1087 // Handle network type form
1088 function doAdminNetworkProcessHandleNetworkTypes () {
1089 // Is there selections?
1090 if (ifPostContainsSelections()) {
1091 // Load network data
1092 $networkData = getNetworkDataById(getRequestElement('network_id'));
1094 // Something has been selected, so start displaying one by one
1096 foreach (postRequestElement('sel') as $networkId => $sel) {
1097 // Is this selected?
1099 // Load this network's data
1100 $networkTypeData = getNetworkTypeDataById($networkId);
1102 // Is there found the network?
1103 if (count($networkTypeData) > 0) {
1104 if (isFormSent('edit')) {
1105 // Add row template for deleting
1106 $OUT .= loadTemplate('admin_edit_network_types_row', true, $networkTypeData);
1107 } elseif (isFormSent('delete')) {
1108 // Add row template for deleting
1109 $OUT .= loadTemplate('admin_delete_network_types_row', true, $networkTypeData);
1112 reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
1118 // If we have no rows, we don't need to display the edit form
1120 // Output main template
1121 if (isFormSent('edit')) {
1122 loadTemplate('admin_edit_network_types', false, $OUT);
1123 } elseif (isFormSent('delete')) {
1124 loadTemplate('admin_delete_network_types', false, $OUT);
1127 reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
1130 // Don't display the list/add new form
1131 $GLOBALS['network_display'] = false;
1133 // Nothing selected/found
1134 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPE_HANDLER_NOTHING_FOUND--}');
1139 // Handle network request parameter form
1140 function doAdminNetworkProcessHandleRequestParams () {
1141 // Is there selections?
1142 if (ifPostContainsSelections()) {
1144 $GLOBALS['network_request_params_disabled'] = array();
1146 // Load network data
1147 $networkData = getNetworkDataById(getRequestElement('network_id'));
1149 // Something has been selected, so start displaying one by one
1151 foreach (postRequestElement('sel') as $networkId => $sel) {
1152 // Is this selected?
1154 // Load this network's data
1155 $networkRequestData = getNetworkRequestParamsDataById($networkId);
1157 // Is there found the network?
1158 if (count($networkRequestData) > 0) {
1159 if (isFormSent('edit')) {
1160 // Add row template for deleting
1161 $OUT .= loadTemplate('admin_edit_network_request_params_row', true, $networkRequestData);
1162 } elseif (isFormSent('delete')) {
1164 $networkRequestData['network_type_data'] = getNetworkTypeDataById($networkRequestData['network_type_id']);
1166 // Add row template for deleting
1167 $OUT .= loadTemplate('admin_delete_network_request_params_row', true, $networkRequestData);
1170 reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
1176 // If we have no rows, we don't need to display the edit form
1178 // Output main template
1179 if (isFormSent('edit')) {
1180 loadTemplate('admin_edit_network_request_params', false, $OUT);
1181 } elseif (isFormSent('delete')) {
1182 loadTemplate('admin_delete_network_request_params', false, $OUT);
1185 reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
1188 // Don't display the list/add new form
1189 $GLOBALS['network_display'] = false;
1191 // Nothing selected/found
1192 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_FOUND--}');
1197 // Changes given networks
1198 function doAdminNetworkProcessChangeNetworks () {
1199 // Is there selections?
1200 if (ifPostContainsSelections()) {
1201 // By default nothing is updated
1204 // Something has been selected, so start updating them
1205 foreach (postRequestElement('sel') as $networkId => $sel) {
1206 // Update this entry?
1209 $networkData = array();
1211 // Transfer whole array, except 'sel'
1212 foreach (postRequestArray() as $key => $entry) {
1213 // Skip 'sel' and submit button
1214 if (in_array($key, array('sel', 'do_edit'))) {
1218 // Is there this enty?
1219 if (!isset($entry[$networkId])) {
1220 // Not found, needs fixing
1221 reportBug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1225 $networkData[$key] = $entry[$networkId];
1228 // Update the network data
1229 $updated += doNetworkUpdateDataByArray($networkId, $networkData);
1233 // Is there updates?
1236 displayMessage('{%message,ADMIN_NETWORK_UPDATED=' . $updated . '%}');
1239 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_CHANGED--}');
1244 // Removes given networks
1245 function doAdminNetworkProcessRemoveNetworks () {
1246 // Is there selections?
1247 if (ifPostContainsSelections()) {
1248 // By default nothing is removed
1251 // Something has been selected, so start updating them
1252 foreach (postRequestElement('sel') as $networkId => $sel) {
1253 // Update this entry?
1255 // Remove this entry
1256 $removed += doAdminRemoveNetworkEntry('data', 'network_id', $networkId);
1260 // Is there removes?
1263 displayMessage('{%message,ADMIN_NETWORK_REMOVED=' . $removed . '%}');
1266 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_REMOVED--}');
1271 // Add a network type handler if not yet found
1272 function doAdminNetworkProcessAddNetworkType () {
1273 // Is the network type handle already used with given network?
1274 if (isNetworkTypeHandleValid(postRequestElement('network_type_handler'), getRequestElement('network_id'))) {
1276 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_TYPE_HANDLER_ALREADY_ADDED=' . postRequestElement('network_type_handler') . '%}');
1278 // ... so abort here
1282 // Remove the 'ok' part
1283 unsetPostRequestElement('ok');
1286 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1288 // Is network_type_banner_url set?
1289 if (postRequestElement('network_type_banner_url') == '') {
1290 // Remove empty value to get a NULL for an optional entry
1291 unsetPostRequestElement('network_type_banner_url');
1294 // Add the whole request to database
1295 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_types'), __FUNCTION__, __LINE__);
1298 if (!SQL_HASZEROAFFECTED()) {
1299 // Successfully added
1300 loadTemplate('admin_network_type_added', false, postRequestArray());
1303 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_TYPE_HANDLER_NOT_ADDED=' . postRequestElement('network_type_handler') . '%}');
1307 // Changes given network type handlers
1308 function doAdminNetworkProcessChangeHandlerTypes () {
1309 // Is there selections?
1310 if (ifPostContainsSelections()) {
1311 // By default nothing is updated
1314 // Something has been selected, so start updating them
1315 foreach (postRequestElement('sel') as $networkId => $sel) {
1316 // Update this entry?
1319 $networkTypeData = array();
1321 // Transfer whole array, except 'sel'
1322 foreach (postRequestArray() as $key => $entry) {
1323 // Skip 'sel' and submit button
1324 if (in_array($key, array('sel', 'do_edit'))) {
1328 // Is there this enty?
1329 if (!isset($entry[$networkId])) {
1330 // Not found, needs fixing
1331 reportBug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1334 // Fix empty network_type_banner_url to NULL
1335 if (($key == 'network_type_banner_url') && (trim($entry[$networkId]) == '')) {
1337 $entry[$networkId] = NULL;
1341 $networkTypeData[$key] = $entry[$networkId];
1344 // Update the network data
1345 $updated += doNetworkUpdateTypeByArray($networkId, $networkTypeData);
1349 // Is there updates?
1352 displayMessage('{%message,ADMIN_NETWORK_TYPE_HANDLER_UPDATED=' . $updated . '%}');
1355 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPE_HANDLER_NOTHING_CHANGED--}');
1360 // Changes given network request parameters
1361 function doAdminNetworkProcessChangeRequestParams () {
1362 // Is there selections?
1363 if (ifPostContainsSelections()) {
1364 // By default nothing is updated
1367 // Something has been selected, so start updating them
1368 foreach (postRequestElement('sel') as $networkId => $sel) {
1369 // Update this entry?
1372 $networkParamsData = array();
1374 // Transfer whole array, except 'sel'
1375 foreach (postRequestArray() as $key => $entry) {
1376 // Skip 'sel' and submit button
1377 if (in_array($key, array('sel', 'do_edit'))) {
1381 // Is there this enty?
1382 if (!isset($entry[$networkId])) {
1383 // Not found, needs fixing
1384 reportBug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1387 // Fix empty network_request_param_default to NULL
1388 if (($key == 'network_request_param_default') && (trim($entry[$networkId]) == '')) {
1390 $entry[$networkId] = NULL;
1394 $networkParamsData[$key] = $entry[$networkId];
1397 // Update the network data
1398 $updated += doNetworkUpdateParamsByArray($networkId, $networkParamsData);
1402 // Is there updates?
1405 displayMessage('{%message,ADMIN_NETWORK_REQUEST_PARAMETER_UPDATED=' . $updated . '%}');
1408 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_CHANGED--}');
1413 // Removes given network type handlers
1414 function doAdminNetworkProcessRemoveNetworkTypes () {
1415 // Is there selections?
1416 if (ifPostContainsSelections()) {
1417 // By default nothing is removed
1420 // Something has been selected, so start updating them
1421 foreach (postRequestElement('sel') as $networkId => $sel) {
1422 // Update this entry?
1424 // Remove this entry
1425 $removed += doAdminRemoveNetworkEntry('types', 'network_type_id', $networkId);
1429 // Is there removes?
1432 displayMessage('{%message,ADMIN_NETWORK_TYPE_HANDLER_REMOVED=' . $removed . '%}');
1435 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPE_HANDLER_NOTHING_REMOVED--}');
1440 // Removes given network request parameters
1441 function doAdminNetworkProcessRemoveNetworkRequestParams () {
1442 // Is there selections?
1443 if (ifPostContainsSelections()) {
1444 // By default nothing is removed
1447 // Something has been selected, so start updating them
1448 foreach (postRequestElement('sel') as $networkId => $sel) {
1449 // Update this entry?
1451 // Remove this entry
1452 $removed += doAdminRemoveNetworkEntry('request_params', 'network_request_param_id', $networkId);
1456 // Is there removes?
1459 displayMessage('{%message,ADMIN_NETWORK_REQUEST_PARAMETER_REMOVED=' . $removed . '%}');
1462 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_REMOVED--}');
1467 // Adds a request parameter to given network and type
1468 function doAdminNetworkProcessAddRequestParam () {
1469 // Is the request parameter already used with given network?
1470 if (isNetworkRequestElementValid(postRequestElement('network_request_param_key'), postRequestElement('network_type_id'), getRequestElement('network_id'))) {
1472 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_REQUEST_PARAMETER_ALREADY_ADDED=' . postRequestElement('network_request_param_key') . '%}');
1474 // ... so abort here
1478 // Remove the 'ok' part
1479 unsetPostRequestElement('ok');
1482 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1484 // Is network_request_param_default set?
1485 if (postRequestElement('network_request_param_default') == '') {
1486 // Remove empty value to get a NULL for an optional entry
1487 unsetPostRequestElement('network_request_param_default');
1490 // Add the whole request to database
1491 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_request_params'), __FUNCTION__, __LINE__);
1494 if (!SQL_HASZEROAFFECTED()) {
1495 // Successfully added
1496 loadTemplate('admin_network_request_param_added', false, postRequestArray());
1499 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_REQUEST_PARAMETER_NOT_ADDED=' . postRequestElement('network_request_param_key') . '%}');
1503 // Adds a vheck request parameter to given network
1504 function doAdminNetworkProcessAddVcheckParam () {
1505 // Is the request parameter already used with given network?
1506 if (isNetworkVcheckElementValid(postRequestElement('network_vcheck_param_key'), getRequestElement('network_id'))) {
1508 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_VCHECK_PARAMETER_ALREADY_ADDED=' . postRequestElement('network_vcheck_param_key') . '%}');
1510 // ... so abort here
1514 // Remove the 'ok' part
1515 unsetPostRequestElement('ok');
1518 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1520 // Is network_vcheck_param_default set?
1521 if (postRequestElement('network_vcheck_param_default') == '') {
1522 // Remove empty value to get a NULL for an optional entry
1523 unsetPostRequestElement('network_vcheck_param_default');
1526 // Add the whole vcheck to database
1527 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_vcheck_params'), __FUNCTION__, __LINE__);
1530 if (!SQL_HASZEROAFFECTED()) {
1531 // Successfully added
1532 loadTemplate('admin_network_vcheck_param_added', false, postRequestArray());
1535 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_VCHECK_PARAMETER_NOT_ADDED=' . postRequestElement('network_vcheck_param_key') . '%}');
1539 // Adds a API response array entry
1540 function doAdminNetworkProcessAddNetworkArrayTranslation () {
1541 // Is the request parameter already used with given network?
1542 if (isNetworkArrayTranslationValid(postRequestElement('network_array_index'), postRequestElement('network_type_id'), getRequestElement('network_id'))) {
1544 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_ARRAY_TRANSLATION_ALREADY_ADDED=' . postRequestElement('network_array_index') . '%}');
1546 // ... so abort here
1550 // Remove the 'ok' part
1551 unsetPostRequestElement('ok');
1554 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1557 setPostRequestElement('sort', (countSumTotalData(
1558 bigintval(postRequestElement('network_id')),
1559 'network_array_translation',
1563 sprintf(" AND `network_type_id`=%s", bigintval(postRequestElement('network_type_id')))
1566 // Add the whole request to database
1567 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_array_translation'), __FUNCTION__, __LINE__);
1570 if (!SQL_HASZEROAFFECTED()) {
1571 // Successfully added
1572 loadTemplate('admin_network_array_translation_added', false, postRequestArray());
1575 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_ARRAY_TRANSLATION_NOT_ADDED=' . postRequestElement('network_array_index') . '%}');
1579 // Adds/update network API configuration
1580 function doAdminNetworkProcessNetworkApiConfig () {
1581 // Remove the 'ok' part
1582 unsetPostRequestElement('ok');
1585 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1587 // Is network_api_referral_button set?
1588 if (postRequestElement('network_api_referral_button') == '') {
1589 // Remove empty value to get a NULL for an optional entry
1590 unsetPostRequestElement('network_api_referral_button');
1593 // Is there already an entry?
1594 if (isNetworkApiConfigured(getRequestElement('network_id'))) {
1595 // Generate SQL query
1596 $SQL = getUpdateSqlFromArray(postRequestArray(), 'network_api_config', 'network_id', postRequestElement('network_id'), array('network_id'));
1599 $SQL = getInsertSqlFromArray(postRequestArray(), 'network_api_config');
1603 SQL_QUERY($SQL, __FUNCTION__, __LINE__);
1606 if (!SQL_HASZEROAFFECTED()) {
1607 // Successfully added
1608 displayMessage('{--ADMIN_CONFIG_NETWORK_API_SAVED--}');
1611 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_API_NOT_SAVED--}');
1615 // Only adds network type configuration if not yet present
1616 function doAdminNetworkProcessAddHandlerTypesConfig ($displayMessage = true) {
1617 // Remove the 'ok' part
1618 unsetPostRequestElement('ok');
1621 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1622 setPostRequestElement('network_type_id', bigintval(getRequestElement('network_type_id')));
1625 * Some parameters are optional, at least one must be given so check a bunch
1628 foreach (array('network_min_waiting_time', 'network_min_remain_clicks', 'network_min_payment', 'network_allow_erotic') as $element) {
1629 // Is this element empty?
1630 if (postRequestElement($element) == '') {
1631 // Then unset it to get a NULL for optional parameter
1632 unsetPostRequestElement($element);
1636 // Convert data in POST array
1637 convertSelectionsToEpocheTimeInPostData($content, 'network_max_reload_time_ye', $skip);
1639 // Is there already an entry?
1640 if (isNetworkTypeHandlerConfigured(getRequestElement('network_id'), getRequestElement('network_type_id'))) {
1641 // This network type handler is already configured
1642 displayMessage('{--ADMIN_NETWORK_HANDLER_TYPE_HANDLER_ALREADY_CONFIGURED--}');
1646 // Copy 'set all' and remove it from POST data
1647 $setAll = (postRequestElement('set_all') === 'Y');
1648 unsetPostRequestElement('set_all');
1650 // Shall we set for all?
1651 if ($setAll === true) {
1653 $result = SQL_QUERY_ESC('SELECT `network_type_id` FROM `{?_MYSQL_PREFIX?}_network_types` WHERE `network_id`=%s ORDER BY `network_type_id` ASC',
1654 array(bigintval(getRequestElement('network_id'))), __FUNCTION__, __LINE__);
1656 // Are there entries?
1657 if (SQL_HASZERONUMS($result)) {
1658 // No, then abort here
1659 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_SET_ALL_404--}');
1663 // Init number of rows
1667 while (list($typeId) = SQL_FETCHROW($result)) {
1668 // Set it in GET data
1669 setGetRequestElement('network_type_id', $typeId);
1671 // Call this function again
1672 $numRows += doAdminNetworkProcessAddHandlerTypesConfig(false);
1676 SQL_FREERESULT($result);
1680 // Something has been updated
1681 displayMessage('{%message,ADMIN_CONFIG_NETWORK_HANDLER_TYPE_ALL_HANDLER_SAVED=' . bigintval($numRows) . '%}');
1683 // Nothing has been saved
1684 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}');
1687 // Get SQL query for new entry
1688 $SQL = getInsertSqlFromArray(postRequestArray(), 'network_types_config');
1691 SQL_QUERY($SQL, __FUNCTION__, __LINE__);
1693 // Shall we display the message?
1694 if ($displayMessage === true) {
1696 if (!SQL_HASZEROAFFECTED()) {
1697 // Successfully added
1698 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_SAVED--}');
1701 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_SAVED--}');
1704 // Return amount of affected rows (1 or 2)
1705 return SQL_AFFECTEDROWS();
1710 // Only changes network type configuration if not yet present
1711 function doAdminNetworkProcessEditHandlerTypesConfig ($displayMessage = true) {
1712 // Remove the 'ok' part
1713 unsetPostRequestElement('ok');
1716 * Some parameters are optional, at least one must be given so check a bunch
1719 foreach (array('network_min_waiting_time', 'network_min_remain_clicks', 'network_min_payment', 'network_allow_erotic') as $element) {
1720 // Is this element empty?
1721 if (postRequestElement($element) == '') {
1722 // Then unset it to get a NULL for optional parameter
1723 unsetPostRequestElement($element);
1727 // Convert time selections in POST data
1728 convertSelectionsToEpocheTimeInPostArray('network_max_reload_time_ye');
1730 // Is there already an entry?
1731 if (!isNetworkTypeHandlerConfigured(getRequestElement('network_id'), getRequestElement('network_type_id'))) {
1732 // This network type handler is not configured
1733 displayMessage('{--ADMIN_NETWORK_HANDLER_TYPE_HANDLER_NOT_CONFIGURED--}');
1737 // Copy 'set all' and remove it from POST data
1738 $setAll = (postRequestElement('set_all') === 'Y');
1739 unsetPostRequestElement('set_all');
1741 // Shall we set for all?
1742 if ($setAll === true) {
1743 // Get all data entries
1744 $result = SQL_QUERY_ESC('SELECT `network_data_id` FROM `{?_MYSQL_PREFIX?}_network_types_config` WHERE `network_id`=%s ORDER BY `network_type_id` ASC',
1745 array(bigintval(getRequestElement('network_id'))), __FUNCTION__, __LINE__);
1747 // Are there entries?
1748 if (SQL_HASZERONUMS($result)) {
1749 // No, then abort here
1750 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_SET_ALL_404--}');
1754 // Init number of rows
1758 while (list($dataId) = SQL_FETCHROW($result)) {
1759 // Set it in GET data
1760 setPostRequestElement('network_data_id', $dataId);
1762 // Call this function again
1763 $numRows += doAdminNetworkProcessEditHandlerTypesConfig(false);
1767 SQL_FREERESULT($result);
1771 // Something has been updated
1772 displayMessage('{%message,ADMIN_CONFIG_NETWORK_HANDLER_TYPE_ALL_HANDLER_SAVED=' . bigintval($numRows) . '%}');
1774 // Nothing has been saved
1775 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}');
1778 // Get SQL query for new entry
1779 $SQL = getUpdateSqlFromArray(postRequestArray(), 'network_types_config', 'network_data_id', postRequestElement('network_data_id'), array('network_data_id'));
1782 SQL_QUERY($SQL, __FUNCTION__, __LINE__);
1784 // Shall we display the message?
1785 if ($displayMessage === true) {
1787 if (!SQL_HASZEROAFFECTED()) {
1788 // Successfully added
1789 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_SAVED--}');
1792 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}');
1795 // Return amount of affected rows (1 or 2)
1796 return SQL_AFFECTEDROWS();
1801 // Do expression code for this extension
1802 function doExpressionNetwork ($data) {
1803 // Construct replacer
1804 $replacer = sprintf(
1805 "{DQUOTE} . %s(%s, '%s') . {DQUOTE}",
1807 $data['matches'][4][$data['key']],
1811 // Replace %network_id% with the current network id
1812 $replacer = str_replace('%network_id%', getCurrentNetworkId(), $replacer);
1815 $code = replaceExpressionCode($data, $replacer);
1821 // ----------------------------------------------------------------------------
1822 // Call-back functions for exporting data
1823 // ----------------------------------------------------------------------------
1825 // Callback function to export network tables
1826 function doAdminNetworkProcessExport () {
1827 // Init table with all valid what->table entries
1828 $validExports = array(
1829 // General network data
1830 'list_network_data' => 'data',
1831 // Network type handler
1832 'list_network_types' => 'types',
1833 // Network request parameter
1834 'list_network_request_params' => 'request_params',
1835 // Vcheck request parameter
1836 'list_network_vcheck_params' => 'vcheck_params',
1837 // Network API response array index translation
1838 'list_network_array_translation' => 'array_translation',
1841 // Is the 'what' key valid?
1842 if (!isset($validExports[getWhat()])) {
1844 reportBug(__FUNCTION__, __LINE__, 'what=' . getWhat() . ' - not supported');
1847 // Generate call-back, some tables require to export not all columns
1848 $callbackName = 'doAdminNetworkExport' . capitalizeUnderscoreString($validExports[getWhat()]);
1850 // Is the call-back function there?
1851 if (!function_exists($callbackName)) {
1852 // No, this is really bad
1853 reportBug(__FUNCTION__, __LINE__, 'Invalid call-back function ' . $callbackName . ' detected.');
1854 } elseif (isset($GLOBALS[__FUNCTION__][$callbackName])) {
1856 reportBug(__FUNCTION__, __LINE__, 'Double-call of export function ' . $callbackName . ' detected.');
1859 // Call the function
1860 call_user_func($callbackName);
1862 // Mark it as called
1863 $GLOBALS[__FUNCTION__][$callbackName] = true;
1865 // Don't display the list/add new form
1866 $GLOBALS['network_display'] = false;
1869 // Exports (and displays) the table 'network_data'
1870 function doAdminNetworkExportData () {
1871 // Query for all networks
1872 $result = SQL_QUERY('SELECT
1873 `network_short_name`,
1876 `network_data_separator`,
1877 `network_row_separator`,
1878 `network_request_type`,
1880 `network_require_id_card`,
1881 `network_query_amount`,
1884 `{?_MYSQL_PREFIX?}_network_data`
1887 __FUNCTION__, __LINE__);
1889 // Start an empty SQL query
1890 $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";
1893 while ($content = SQL_FETCHARRAY($result)) {
1896 $content['network_short_name'] . "', '" .
1897 $content['network_title'] . "', '" .
1898 $content['network_reflink'] . "', '" .
1899 $content['network_data_separator'] . "', '" .
1900 $content['network_row_separator'] . "', '" .
1901 $content['network_request_type'] . "', '" .
1902 $content['network_charset'] . "', '" .
1903 $content['network_require_id_card'] . "', " .
1904 $content['network_query_amount'] . ", '" .
1905 $content['network_active'] . "'),\n";
1908 // Remove last commata and close braces
1909 $SQL = substr($SQL, 0, -2);
1912 SQL_FREERESULT($result);
1914 // Output the SQL query
1915 loadTemplate('admin_export_network_data', false, $SQL);
1918 // Exports (and displays) the table 'network_types'
1919 function doAdminNetworkExportTypes () {
1920 // 'network_id' must be set
1921 if (!isGetRequestElementSet('network_id')) {
1922 // Only network handlers of one network will be exported per time
1923 reportBug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
1926 // Get all network types of given network
1927 $result = SQL_QUERY_ESC('SELECT
1930 `network_type_handler`,
1931 `network_type_api_url`,
1932 `network_type_click_url`,
1933 `network_type_banner_url`,
1934 `network_type_reload_time_unit`,
1935 `network_text_encoding`
1937 `{?_MYSQL_PREFIX?}_network_types`
1941 `network_type_id` ASC',
1943 bigintval(getRequestElement('network_id'))
1944 ), __FUNCTION__, __LINE__);
1946 // Start an empty SQL query
1947 $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`, `network_text_encoding`) VALUES\n";
1950 while ($content = SQL_FETCHARRAY($result)) {
1953 $content['network_type_id'] . ', ' .
1954 $content['network_id'] . ", '" .
1955 $content['network_type_handler'] . "', '" .
1956 $content['network_type_api_url'] . "', '" .
1957 $content['network_type_click_url'] . "', ";
1959 // Is the column NULL?
1960 if (is_null($content['network_type_banner_url'])) {
1965 $SQL .= chr(39) . $content['network_type_banner_url'] . chr(39);
1969 $SQL .= ",'" . $content['network_type_reload_time_unit'] . "','" . $content['network_text_encoding'] . "'),\n";
1972 // Remove last commata and close braces
1973 $SQL = substr($SQL, 0, -2);
1976 SQL_FREERESULT($result);
1978 // Output the SQL query
1979 loadTemplate('admin_export_network_types', false, $SQL);
1982 // Exports (and displays) the table 'network_request_params'
1983 function doAdminNetworkExportRequestParams () {
1984 // 'network_id' must be set
1985 if (!isGetRequestElementSet('network_id')) {
1986 // Only network request parameters of one network will be exported per time
1987 reportBug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
1990 // Get all network types of given network
1991 $result = SQL_QUERY_ESC('SELECT
1994 `network_request_param_key`,
1995 `network_request_param_value`,
1996 `network_request_param_default`
1998 `{?_MYSQL_PREFIX?}_network_request_params`
2002 `network_type_id` ASC ,
2003 `network_request_param_id` ASC',
2005 bigintval(getRequestElement('network_id'))
2006 ), __FUNCTION__, __LINE__);
2008 // Start an empty SQL query
2009 $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";
2012 while ($content = SQL_FETCHARRAY($result)) {
2015 $content['network_id'] . ', ' .
2016 $content['network_type_id'] . ", '" .
2017 $content['network_request_param_key'] . "', '" .
2018 $content['network_request_param_value'] . "', ";
2020 // Is the column NULL?
2021 if (is_null($content['network_request_param_default'])) {
2026 $SQL .= chr(39) . $content['network_request_param_default'] . "'),\n";
2030 // Remove last commata and close braces
2031 $SQL = substr($SQL, 0, -2);
2034 SQL_FREERESULT($result);
2036 // Output the SQL query
2037 loadTemplate('admin_export_network_request_params', false, $SQL);
2040 // Exports (and displays) the table 'network_vcheck_params'
2041 function doAdminNetworkExportVcheckParams () {
2042 // 'network_id' must be set
2043 if (!isGetRequestElementSet('network_id')) {
2044 // Only network vcheck parameters of one network will be exported per time
2045 reportBug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
2048 // Get all network types of given network
2049 $result = SQL_QUERY_ESC('SELECT
2051 `network_vcheck_param_key`,
2052 `network_vcheck_param_value`,
2053 `network_vcheck_param_default`
2055 `{?_MYSQL_PREFIX?}_network_vcheck_params`
2059 `network_vcheck_param_id` ASC',
2061 bigintval(getRequestElement('network_id'))
2062 ), __FUNCTION__, __LINE__);
2064 // Start an empty SQL query
2065 $SQL = "INSERT INTO `{?_MYSQL_PREFIX?}_network_vcheck_params` (`network_id`, `network_vcheck_param_key`, `network_vcheck_param_value`, `network_vcheck_param_default`) VALUES\n";
2068 while ($content = SQL_FETCHARRAY($result)) {
2071 $content['network_id'] . ", '" .
2072 $content['network_vcheck_param_key'] . "', '" .
2073 $content['network_vcheck_param_value'] . "', ";
2075 // Is the column NULL?
2076 if (is_null($content['network_vcheck_param_default'])) {
2081 $SQL .= chr(39) . $content['network_vcheck_param_default'] . "'),\n";
2085 // Remove last commata and close braces
2086 $SQL = substr($SQL, 0, -2);
2089 SQL_FREERESULT($result);
2091 // Output the SQL query
2092 loadTemplate('admin_export_network_vcheck_params', false, $SQL);
2095 // Exports (and displays) the table 'network_array_translation'
2096 function doAdminNetworkExportArrayTranslation () {
2097 // 'network_id' must be set
2098 if (!isGetRequestElementSet('network_id')) {
2099 // Only network API array index translations of one network will be exported per time
2100 reportBug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
2103 // Get all network types of given network
2104 $result = SQL_QUERY_ESC('SELECT
2107 `network_array_index`,
2110 `{?_MYSQL_PREFIX?}_network_array_translation`
2114 `network_type_id` ASC,
2117 bigintval(getRequestElement('network_id'))
2118 ), __FUNCTION__, __LINE__);
2120 // Start an empty SQL query
2121 $SQL = "INSERT INTO `{?_MYSQL_PREFIX?}_network_array_translation` (`network_id`, `network_type_id`, `network_array_index`, `sort`) VALUES\n";
2124 while ($content = SQL_FETCHARRAY($result)) {
2127 $content['network_id'] . ', ' .
2128 $content['network_type_id'] . ', ' .
2129 $content['network_array_index'] . ', ' .
2130 $content['sort'] . "),\n";
2133 // Remove last commata and close braces
2134 $SQL = substr($SQL, 0, -2);
2137 SQL_FREERESULT($result);
2139 // Output the SQL query
2140 loadTemplate('admin_export_network_array_translation', false, $SQL);