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 ($networkTypeId) {
331 // Ids lower one are not accepted
332 if ($networkTypeId < 1) {
333 // Not good, should be fixed
334 reportBug(__FUNCTION__, __LINE__, 'Network type id ' . $networkTypeId . ' is smaller than 1.');
337 // By default we have no data
338 $GLOBALS['network_type_data'][$networkTypeId] = 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($networkTypeId)), __FUNCTION__, __LINE__);
355 // Is there an entry?
356 if (SQL_NUMROWS($result) == 1) {
358 $GLOBALS['network_type_data'][$networkTypeId] = SQL_FETCHARRAY($result);
362 SQL_FREERESULT($result);
365 return $GLOBALS['network_type_data'][$networkTypeId];
368 // "Getter" for a network request parameter data by provided id number
369 function getNetworkRequestParamsDataById ($networkRequestId) {
370 // Ids lower one are not accepted
371 if ($networkRequestId < 1) {
372 // Not good, should be fixed
373 reportBug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $networkRequestId . ' 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($networkRequestId)), __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 // "Getter" for a network array translation data by provided id number
408 function getNetworkArrayTranslationsDataById ($networkTranslationId) {
409 // Ids lower one are not accepted
410 if ($networkTranslationId < 1) {
411 // Not good, should be fixed
412 reportBug(__FUNCTION__, __LINE__, 'Network array translation id ' . $networkTranslationId . ' is smaller than 1.');
415 // By default we have no data
416 $networkTranslationData = array();
418 // Query for the network data
419 $result = SQL_QUERY_ESC('SELECT
423 `network_array_index`,
426 `{?_MYSQL_PREFIX?}_network_array_translation`
428 `network_array_id`=%s
430 array(bigintval($networkTranslationId)), __FUNCTION__, __LINE__);
432 // Is there an entry?
433 if (SQL_NUMROWS($result) == 1) {
435 $networkTranslationData = SQL_FETCHARRAY($result);
439 SQL_FREERESULT($result);
442 return $networkTranslationData;
445 // Updates given network (id) with data from array
446 function doNetworkUpdateDataByArray ($networkId, $networkData) {
447 // Ids lower one are not accepted
448 if ($networkId < 1) {
449 // Not good, should be fixed
450 reportBug(__FUNCTION__, __LINE__, 'Network id ' . $networkId . ' is smaller than 1.');
453 // Just call our inner method
454 return adminSaveSettings($networkData, '_network_data', sprintf("`network_id`=%s", bigintval($networkId)), array(), false, false);
457 // Updates given network type handler (id) with data from array
458 function doNetworkUpdateTypeByArray ($networkTypeId, $networkTypeData) {
459 // Ids lower one are not accepted
460 if ($networkTypeId < 1) {
461 // Not good, should be fixed
462 reportBug(__FUNCTION__, __LINE__, 'Network type handler id ' . $networkTypeId . ' is smaller than 1.');
465 // Just call our inner method
466 return adminSaveSettings($networkTypeData, '_network_types', sprintf("`network_type_id`=%s", bigintval($networkTypeId)), array(), false, false);
469 // Updates given network request parameters (id) with data from array
470 function doNetworkUpdateParamsByArray ($networkParamsId, $networkParamsData) {
471 // Ids lower one are not accepted
472 if ($networkParamsId < 1) {
473 // Not good, should be fixed
474 reportBug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $networkParamsId . ' is smaller than 1.');
477 // Just call our inner method
478 return adminSaveSettings($networkParamsData, '_network_request_params', sprintf("`network_request_param_id`=%s", bigintval($networkParamsId)), array(), false, false);
481 // Updates given network array translations (id) with data from array
482 function doNetworkUpdateArrayTranslationsByArray ($networkTranslationsId, $networkTranslationsData) {
483 // Ids lower one are not accepted
484 if ($networkTranslationsId < 1) {
485 // Not good, should be fixed
486 reportBug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $networkTranslationsId . ' is smaller than 1.');
489 // Just call our inner method
490 return adminSaveSettings($networkTranslationsData, '_network_array_translation', sprintf("`network_array_id`=%s", bigintval($networkTranslationsId)), array(), false, false);
493 // Removes given network entry
494 function doAdminRemoveNetworkEntry ($table, $column, $id, $limit = 1) {
496 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_network_%s` WHERE `%s`=%s LIMIT %s",
502 ), __FUNCTION__, __LINE__);
504 // Return affected rows
505 return SQL_AFFECTEDROWS();
508 // Generates a list of networks for given script and returns it
509 function generateAdminNetworkList () {
513 // Query for all networks
514 $result = SQL_QUERY("SELECT
516 `network_short_name`,
519 `{?_MYSQL_PREFIX?}_network_data`
523 `network_short_name` ASC", __FUNCTION__, __LINE__);
525 // Are there entries?
526 if (!SQL_HASZERONUMS($result)) {
529 while ($row = SQL_FETCHARRAY($result)) {
530 // Is this valid, then add it
531 if ((is_array($row)) && (isset($row['network_id']))) {
533 $rows[$row['network_id']] = $row;
537 // Generate the selection box
538 $content = generateSelectionBoxFromArray($rows, 'network_id', 'network_id', '', '', 'network');
541 $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}');
545 SQL_FREERESULT($result);
551 // Generator (somewhat getter) for a list of network types for given network id
552 function generateAdminNetworkTypeList ($networkId) {
556 // Query all types of this network
557 $result = SQL_QUERY_ESC('SELECT
559 `network_type_handler`
561 `{?_MYSQL_PREFIX?}_network_types`
565 `network_type_handler` ASC',
567 bigintval($networkId)
568 ), __FUNCTION__, __LINE__);
570 // Are there entries?
571 if (!SQL_HASZERONUMS($result)) {
574 while ($row = SQL_FETCHARRAY($result)) {
575 // Is this valid, then add it
576 if ((is_array($row)) && (isset($row['network_type_id']))) {
578 $rows[$row['network_type_id']] = $row;
582 // Generate the selection box
583 $content = generateSelectionBoxFromArray($rows, 'network_type', 'network_type_id');
586 $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}');
590 SQL_FREERESULT($result);
596 // Generator (somewhat getter) for a list of network types for all types
597 function generateAdminDistinctNetworkTypeList () {
601 // Query all types of this network
602 $result = SQL_QUERY("SELECT
604 t.`network_type_handler`,
607 `{?_MYSQL_PREFIX?}_network_types` AS t
609 `{?_MYSQL_PREFIX?}_network_data` AS d
611 t.`network_id`=d.`network_id`
613 d.`network_active`='Y'
615 d.`network_short_name` ASC,
616 t.`network_type_handler` ASC", __FUNCTION__, __LINE__);
618 // Are there entries?
619 if (!SQL_HASZERONUMS($result)) {
622 while ($row = SQL_FETCHARRAY($result)) {
623 // Is this valid, then add it
624 if ((is_array($row)) && (isset($row['network_type_id']))) {
626 $rows[$row['network_type_id']] = $row;
630 // Generate the selection box
631 $content = generateSelectionBoxFromArray($rows, 'network_type', 'network_type_id', '', '_title');
634 $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}');
638 SQL_FREERESULT($result);
639 //* DEBUG: */ die('<pre>'.encodeEntities($content).'</pre>');
645 // Generator (somewhat getter) for network type options
646 function generateNetworkTypeOptions ($networkId) {
647 // Is this an array, then we just came back from edit/delete actions
648 if (is_array($networkId)) {
653 if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
654 // Generate output and cache it
655 $GLOBALS[__FUNCTION__][$networkId] = generateOptions(
658 'network_type_handler',
662 "WHERE `network_id`=%s",
663 bigintval(getRequestElement('network_id'))
666 'translateNetworkTypeHandler'
671 return $GLOBALS[__FUNCTION__][$networkId];
674 // Generates an options list of all available (hard-coded) handlers
675 function generateNetworkTypesAvailableOptions ($defaultType = NULL) {
677 if (!isset($GLOBALS[__FUNCTION__][$defaultType])) {
679 $GLOBALS[__FUNCTION__][$defaultType] = generateOptions(
715 $GLOBALS['network_types_disabled'],
716 'translateNetworkTypeHandler'
721 return $GLOBALS[__FUNCTION__][$defaultType];
724 // Generates an options list of all available (hard-coded) text encoders
725 function generateNetworkTextEncodingAvailableOptions ($defaultEncoding = NULL) {
727 if (!isset($GLOBALS[__FUNCTION__][$defaultEncoding])) {
729 $GLOBALS[__FUNCTION__][$defaultEncoding] = generateOptions(
739 'translateNetworkTextEncoding'
744 return $GLOBALS[__FUNCTION__][$defaultEncoding];
747 // Generates an options list (somewhat getter) for request keys
748 function generateNetworkRequestKeyOptions () {
750 if (!isset($GLOBALS[__FUNCTION__])) {
751 // Generate and cache it
752 $GLOBALS[__FUNCTION__] = generateOptions(
774 $GLOBALS['network_request_params_disabled'],
775 'translateNetworkRequestParameterKey'
780 return $GLOBALS[__FUNCTION__];
783 // Generates an options list for vcheck request keys
784 function generateNetworkVcheckKeyOptions () {
786 if (!isset($GLOBALS[__FUNCTION__])) {
787 // Generate and cache it
788 $GLOBALS[__FUNCTION__] = generateOptions(
808 $GLOBALS['network_vcheck_params_disabled'],
809 'translateNetworkVcheckParameterKey'
814 return $GLOBALS[__FUNCTION__];
817 // Generator (somewhat getter) for (return) array translation
818 function generateNetworkTranslationOptions ($default = '') {
820 if (!isset($GLOBALS[__FUNCTION__][$default])) {
821 // Generate and cache it
822 $GLOBALS[__FUNCTION__][$default] = generateOptions(
823 'network_translations',
824 'network_translation_id',
825 'network_translation_name',
829 $GLOBALS['network_array_translation_disabled'],
830 'translateNetworkTranslationName'
835 return $GLOBALS[__FUNCTION__][$default];
838 // Generates an option list of request types
839 function generateNetworkRequestTypeOptions ($default = '') {
841 if (!isset($GLOBALS[__FUNCTION__][$default])) {
843 $GLOBALS[__FUNCTION__][$default] = generateOptions(
850 '{--ADMIN_NETWORK_REQUEST_TYPE_GET--}',
851 '{--ADMIN_NETWORK_REQUEST_TYPE_POST--}'
858 return $GLOBALS[__FUNCTION__][$default];
861 // Generates an option list of network_api_active
862 function generateNetworkApiActiveOptions ($default = '') {
864 if (!isset($GLOBALS[__FUNCTION__][$default])) {
866 $GLOBALS[__FUNCTION__][$default] = generateYesNoOptions($default);
870 return $GLOBALS[__FUNCTION__][$default];
873 // Translates 'translate_name' for e.g. templates
874 function translateNetworkTranslationName ($name) {
876 $messageId = 'ADMIN_NETWORK_TRANSLATE_' . strtoupper($name) . '_NAME';
878 // Is the message id there?
879 if (!isMessageIdValid($messageId)) {
881 reportBug(__FUNCTION__, __LINE__, 'name=' . $name . ' is invalid.');
885 return '{--' . $messageId . '--}';
888 // Translates the network type handler (e.g. banner, paidmail) for templates
889 function translateNetworkTypeHandler ($type) {
891 $messageId = 'ADMIN_NETWORK_TYPE_HANDLER_' . strtoupper($type);
893 // Is the message id there?
894 if (!isMessageIdValid($messageId)) {
896 reportBug(__FUNCTION__, __LINE__, 'type=' . $type . ' is invalid.');
900 return '{--' . $messageId . '--}';
903 // Translates request type
904 function translateNetworkRequestType ($type) {
906 $messageId = 'ADMIN_NETWORK_REQUEST_TYPE_' . strtoupper($type) . '';
908 // Is the message id there?
909 if (!isMessageIdValid($messageId)) {
911 reportBug(__FUNCTION__, __LINE__, 'type=' . $type . ' is invalid.');
915 return '{--' . $messageId . '--}';
918 // Translates request parameter
919 function translateNetworkRequestParameterKey ($param) {
921 $messageId = 'ADMIN_NETWORK_REQUEST_PARAMETER_' . strtoupper($param) . '';
923 // Is the message id there?
924 if (!isMessageIdValid($messageId)) {
926 reportBug(__FUNCTION__, __LINE__, 'param=' . $param . ' is invalid.');
930 return '{--' . $messageId . '--}';
933 // Translates vheck request parameter
934 function translateNetworkVcheckParameterKey ($param) {
936 $messageId = 'ADMIN_NETWORK_VCHECK_PARAMETER_' . strtoupper($param) . '';
938 // Is the message id there?
939 if (!isMessageIdValid($messageId)) {
941 reportBug(__FUNCTION__, __LINE__, 'param=' . $param . ' is invalid.');
945 return '{--' . $messageId . '--}';
948 // Translate text-encoding
949 function translateNetworkTextEncoding ($encoding) {
951 $messageId = 'ADMIN_NETWORK_TYPE_TEXT_ENCODING_' . strtoupper($encoding) . '';
953 // Is the message id there?
954 if (!isMessageIdValid($messageId)) {
955 // Not valid encoding
956 reportBug(__FUNCTION__, __LINE__, 'encoding=' . $encoding . ' is invalid.');
960 return '{--' . $messageId . '--}';
963 // Translates API index
964 function translateNetworkApiIndex ($index) {
966 if (!isset($GLOBALS['network_array_index'])) {
967 // Get an array of all API array indexes
968 $GLOBALS['network_array_index'] = array();
971 $result = SQL_QUERY('SELECT
973 `network_array_index`,
974 `network_translation_name`
976 `{?_MYSQL_PREFIX?}_network_array_translation`
978 `{?_MYSQL_PREFIX?}_network_translations`
980 `network_array_index`=`network_translation_id`
982 `network_array_sort` ASC', __FUNCTION__, __LINE__);
984 // Are there entries?
985 if (!SQL_HASZERONUMS($result)) {
987 while ($row = SQL_FETCHARRAY($result)) {
988 // Add it to our global array
989 $GLOBALS['network_array_index'][$row['network_array_index']] = $row;
994 SQL_FREERESULT($result);
997 // Default name is unknown
1000 // Is the entry there?
1001 if (isset($GLOBALS['network_array_index'][$index])) {
1002 // Then get the name
1003 $name = $GLOBALS['network_array_index'][$index]['network_translation_name'];
1006 // Return translation
1007 return translateNetworkTranslationName($name);
1010 // Translates network API configuration status (see function isNetworkApiConfigured()) by given id
1011 function translateNetworkApiConfiguredStatusById ($networkId) {
1013 if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
1014 // By default it is not configured
1015 $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_NOT_CONFIGURED--}';
1017 // So is it configured?
1018 if (isNetworkApiConfigured($networkId)) {
1020 $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_CONFIGURED--}';
1025 return $GLOBALS[__FUNCTION__][$networkId];
1028 // Checks if the given network is configured by looking its API configuration entry up
1029 function isNetworkApiConfigured ($networkId) {
1031 if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
1032 // Check for an entry in network_api_config
1033 $GLOBALS[__FUNCTION__][$networkId] = (countSumTotalData(
1034 bigintval($networkId),
1035 'network_api_config',
1043 return $GLOBALS[__FUNCTION__][$networkId];
1046 // Checks whether the given network type handler is configured
1047 function isNetworkTypeHandlerConfigured ($networkId, $networkTypeId) {
1049 if (!isset($GLOBALS[__FUNCTION__][$networkId][$networkTypeId])) {
1051 $GLOBALS[__FUNCTION__][$networkId][$networkTypeId] = (countSumTotalData(
1052 bigintval($networkTypeId),
1053 'network_types_config',
1057 sprintf(' AND `network_id`=%s', bigintval($networkId))
1062 return $GLOBALS[__FUNCTION__][$networkId][$networkTypeId];
1065 // Handles the network-payment-check request
1066 function handleNetworkPaymentCheckRequest () {
1067 // @TODO Implement this function, don't forget to set HTTP status back to '200 OK' if everything went fine
1068 reportBug(__FUNCTION__, __LINE__, 'Not yet implemented.');
1071 //------------------------------------------------------------------------------
1072 // Call-back functions
1073 //------------------------------------------------------------------------------
1075 // Callback function to add new network
1076 function doAdminNetworkProcessAddNetwork () {
1077 // We can say here, the form is sent, so check if the network is already added
1078 if (isNetworkNameValid(postRequestElement('network_short_name'))) {
1080 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_ALREADY_ADDED=' . postRequestElement('network_short_name') . '%}');
1084 // Remove the 'ok' part
1085 unsetPostRequestElement('ok');
1087 // Add the whole request to database
1088 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_data'), __FUNCTION__, __LINE__);
1090 // Add the id for output only
1091 setPostRequestElement('network_id', SQL_INSERTID());
1094 if (!SQL_HASZEROAFFECTED()) {
1095 // Successfully added
1096 loadTemplate('admin_network_added', false, postRequestArray());
1099 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_DATA_NOT_ADDED=' . postRequestElement('network_short_name') . '%}');
1103 // Displays selected networks for editing
1104 function doAdminNetworkProcessHandleNetworks () {
1105 // Is there selections?
1106 if (ifPostContainsSelections()) {
1107 // Something has been selected, so start displaying one by one
1109 foreach (postRequestElement('sel') as $networkId => $sel) {
1110 // Is this selected?
1112 // Load this network's data
1113 $networkData = getNetworkDataById($networkId);
1115 // Is there found the network?
1116 if (count($networkData) > 0) {
1117 // Add row template with given form name
1118 $OUT .= loadTemplate('admin_' . $GLOBALS['network_form_name'] . '_networks_row', true, $networkData);
1123 // If we have no rows, we don't need to display the edit form
1125 // Output main template
1126 loadTemplate('admin_' . $GLOBALS['network_form_name'] . '_networks', false, $OUT);
1128 // Don't display the list/add new form
1129 $GLOBALS['network_display'] = false;
1131 // Nothing selected/found
1132 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_FOUND--}');
1137 // Handle network type form
1138 function doAdminNetworkProcessHandleNetworkTypes () {
1139 // Is there selections?
1140 if (ifPostContainsSelections()) {
1141 // Load network data
1142 $networkData = getNetworkDataById(getRequestElement('network_id'));
1144 // Something has been selected, so start displaying one by one
1146 foreach (postRequestElement('sel') as $networkId => $sel) {
1147 // Is this selected?
1149 // Load this network's data
1150 $networkTypeData = getNetworkTypeDataById($networkId);
1152 // Is there found the network?
1153 if (count($networkTypeData) > 0) {
1154 if (isFormSent('edit')) {
1155 // Add row template for deleting
1156 $OUT .= loadTemplate('admin_edit_network_types_row', true, $networkTypeData);
1157 } elseif (isFormSent('delete')) {
1158 // Add row template for deleting
1159 $OUT .= loadTemplate('admin_delete_network_types_row', true, $networkTypeData);
1162 reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/delete.');
1168 // If we have no rows, we don't need to display the edit form
1170 // Output main template
1171 if (isFormSent('edit')) {
1172 loadTemplate('admin_edit_network_types', false, $OUT);
1173 } elseif (isFormSent('delete')) {
1174 loadTemplate('admin_delete_network_types', false, $OUT);
1177 reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/delete.');
1180 // Don't display the list/add new form
1181 $GLOBALS['network_display'] = false;
1183 // Nothing selected/found
1184 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPE_HANDLER_NOTHING_FOUND--}');
1189 // Handle network request parameter form
1190 function doAdminNetworkProcessHandleRequestParams () {
1191 // Is there selections?
1192 if (ifPostContainsSelections()) {
1194 $GLOBALS['network_request_params_disabled'] = array();
1196 // Load network data
1197 $networkData = getNetworkDataById(getRequestElement('network_id'));
1199 // Something has been selected, so start displaying one by one
1201 foreach (postRequestElement('sel') as $networkId => $sel) {
1202 // Is this selected?
1204 // Load this network's data
1205 $networkRequestData = getNetworkRequestParamsDataById($networkId);
1207 // Is there found the network?
1208 if (count($networkRequestData) > 0) {
1209 if (isFormSent('edit')) {
1210 // Add row template for deleting
1211 $OUT .= loadTemplate('admin_edit_network_request_params_row', true, $networkRequestData);
1212 } elseif (isFormSent('delete')) {
1214 $networkRequestData['network_type_data'] = getNetworkTypeDataById($networkRequestData['network_type_id']);
1216 // Add row template for deleting
1217 $OUT .= loadTemplate('admin_delete_network_request_params_row', true, $networkRequestData);
1220 reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/delete.');
1226 // If we have no rows, we don't need to display the edit form
1228 // Output main template
1229 if (isFormSent('edit')) {
1230 loadTemplate('admin_edit_network_request_params', false, $OUT);
1231 } elseif (isFormSent('delete')) {
1232 loadTemplate('admin_delete_network_request_params', false, $OUT);
1235 reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/delete.');
1238 // Don't display the list/add new form
1239 $GLOBALS['network_display'] = false;
1241 // Nothing selected/found
1242 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_FOUND--}');
1247 // Changes given networks
1248 function doAdminNetworkProcessChangeNetworks () {
1249 // Is there selections?
1250 if (ifPostContainsSelections()) {
1251 // By default nothing is updated
1254 // Something has been selected, so start updating them
1255 foreach (postRequestElement('sel') as $networkId => $sel) {
1256 // Update this entry?
1259 $networkData = array();
1261 // Transfer whole array, except 'sel'
1262 foreach (postRequestArray() as $key => $entry) {
1263 // Skip 'sel' and submit button
1264 if (in_array($key, array('sel', 'do_edit'))) {
1268 // Is there this enty?
1269 if (!isset($entry[$networkId])) {
1270 // Not found, needs fixing
1271 reportBug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1275 $networkData[$key] = $entry[$networkId];
1278 // Update the network data
1279 $updated += doNetworkUpdateDataByArray($networkId, $networkData);
1283 // Is there updates?
1286 displayMessage('{%message,ADMIN_NETWORK_UPDATED=' . $updated . '%}');
1289 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_CHANGED--}');
1294 // Removes given networks
1295 function doAdminNetworkProcessRemoveNetworks () {
1296 // Is there selections?
1297 if (ifPostContainsSelections()) {
1298 // By default nothing is removed
1301 // Something has been selected, so start updating them
1302 foreach (postRequestElement('sel') as $networkId => $sel) {
1303 // Update this entry?
1305 // Remove this entry
1306 $removed += doAdminRemoveNetworkEntry('data', 'network_id', $networkId);
1310 // Is there removes?
1313 displayMessage('{%message,ADMIN_NETWORK_REMOVED=' . $removed . '%}');
1316 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_REMOVED--}');
1321 // Add a network type handler if not yet found
1322 function doAdminNetworkProcessAddNetworkType () {
1323 // Is the network type handle already used with given network?
1324 if (isNetworkTypeHandleValid(postRequestElement('network_type_handler'), getRequestElement('network_id'))) {
1326 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_TYPE_HANDLER_ALREADY_ADDED=' . postRequestElement('network_type_handler') . '%}');
1328 // ... so abort here
1332 // Remove the 'ok' part
1333 unsetPostRequestElement('ok');
1336 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1338 // Is network_type_banner_url set?
1339 if (postRequestElement('network_type_banner_url') == '') {
1340 // Remove empty value to get a NULL for an optional entry
1341 unsetPostRequestElement('network_type_banner_url');
1344 // Add the whole request to database
1345 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_types'), __FUNCTION__, __LINE__);
1348 if (!SQL_HASZEROAFFECTED()) {
1349 // Successfully added
1350 loadTemplate('admin_network_type_added', false, postRequestArray());
1353 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_TYPE_HANDLER_NOT_ADDED=' . postRequestElement('network_type_handler') . '%}');
1357 // Changes given network type handlers
1358 function doAdminNetworkProcessChangeHandlerTypes () {
1359 // Is there selections?
1360 if (ifPostContainsSelections()) {
1361 // By default nothing is updated
1364 // Something has been selected, so start updating them
1365 foreach (postRequestElement('sel') as $networkId => $sel) {
1366 // Update this entry?
1369 $networkTypeData = array();
1371 // Transfer whole array, except 'sel'
1372 foreach (postRequestArray() as $key => $entry) {
1373 // Skip 'sel' and submit button
1374 if (in_array($key, array('sel', 'do_edit'))) {
1378 // Is there this enty?
1379 if (!isset($entry[$networkId])) {
1380 // Not found, needs fixing
1381 reportBug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1384 // Fix empty network_type_banner_url to NULL
1385 if (($key == 'network_type_banner_url') && (trim($entry[$networkId]) == '')) {
1387 $entry[$networkId] = NULL;
1391 $networkTypeData[$key] = $entry[$networkId];
1394 // Update the network data
1395 $updated += doNetworkUpdateTypeByArray($networkId, $networkTypeData);
1399 // Is there updates?
1402 displayMessage('{%message,ADMIN_NETWORK_TYPE_HANDLER_UPDATED=' . $updated . '%}');
1405 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPE_HANDLER_NOTHING_CHANGED--}');
1410 // Changes given network request parameters
1411 function doAdminNetworkProcessChangeRequestParams () {
1412 // Is there selections?
1413 if (ifPostContainsSelections()) {
1414 // By default nothing is updated
1417 // Something has been selected, so start updating them
1418 foreach (postRequestElement('sel') as $networkId => $sel) {
1419 // Update this entry?
1422 $networkParamsData = array();
1424 // Transfer whole array, except 'sel'
1425 foreach (postRequestArray() as $key => $entry) {
1426 // Skip 'sel' and submit button
1427 if (in_array($key, array('sel', 'do_edit'))) {
1431 // Is there this enty?
1432 if (!isset($entry[$networkId])) {
1433 // Not found, needs fixing
1434 reportBug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1437 // Fix empty network_request_param_default to NULL
1438 if (($key == 'network_request_param_default') && (trim($entry[$networkId]) == '')) {
1440 $entry[$networkId] = NULL;
1444 $networkParamsData[$key] = $entry[$networkId];
1447 // Update the network data
1448 $updated += doNetworkUpdateParamsByArray($networkId, $networkParamsData);
1452 // Is there updates?
1455 displayMessage('{%message,ADMIN_NETWORK_REQUEST_PARAMETER_UPDATED=' . $updated . '%}');
1458 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_CHANGED--}');
1463 // Changes given network array translations
1464 function doAdminNetworkProcessChangeArrayTranslations () {
1465 // Is there selections?
1466 if (ifPostContainsSelections()) {
1467 // By default nothing is updated
1470 // Something has been selected, so start updating them
1471 foreach (postRequestElement('sel') as $networkId => $sel) {
1472 // Update this entry?
1475 $networkTranslationsData = array();
1477 // Transfer whole array, except 'sel'
1478 foreach (postRequestArray() as $key => $entry) {
1479 // Skip 'sel' and submit button
1480 if (in_array($key, array('sel', 'do_edit'))) {
1484 // Is there this enty?
1485 if (!isset($entry[$networkId])) {
1486 // Not found, needs fixing
1487 reportBug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1490 // Fix empty network_request_param_default to NULL
1491 if (($key == 'network_request_param_default') && (trim($entry[$networkId]) == '')) {
1493 $entry[$networkId] = NULL;
1497 $networkTranslationsData[$key] = $entry[$networkId];
1500 // Update the network data
1501 $updated += doNetworkUpdateArrayTranslationsByArray($networkId, $networkTranslationsData);
1505 // Is there updates?
1508 displayMessage('{%message,ADMIN_NETWORK_ARRAY_TRANSLATION_UPDATED=' . $updated . '%}');
1511 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_ARRAY_TRANSLATION_NOTHING_CHANGED--}');
1516 // Removes given network type handlers
1517 function doAdminNetworkProcessRemoveNetworkTypes () {
1518 // Is there selections?
1519 if (ifPostContainsSelections()) {
1520 // By default nothing is removed
1523 // Something has been selected, so start updating them
1524 foreach (postRequestElement('sel') as $networkId => $sel) {
1525 // Update this entry?
1527 // Remove this entry
1528 $removed += doAdminRemoveNetworkEntry('types', 'network_type_id', $networkId);
1532 // Is there removes?
1535 displayMessage('{%message,ADMIN_NETWORK_TYPE_HANDLER_REMOVED=' . $removed . '%}');
1538 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPE_HANDLER_NOTHING_REMOVED--}');
1543 // Removes given network request parameters
1544 function doAdminNetworkProcessRemoveNetworkRequestParams () {
1545 // Is there selections?
1546 if (ifPostContainsSelections()) {
1547 // By default nothing is removed
1550 // Something has been selected, so start updating them
1551 foreach (postRequestElement('sel') as $networkId => $sel) {
1552 // Update this entry?
1554 // Remove this entry
1555 $removed += doAdminRemoveNetworkEntry('request_params', 'network_request_param_id', $networkId);
1559 // Is there removes?
1562 displayMessage('{%message,ADMIN_NETWORK_REQUEST_PARAMETER_REMOVED=' . $removed . '%}');
1565 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_REMOVED--}');
1570 // Removes given network array translations
1571 function doAdminNetworkProcessRemoveNetworkArrayTranslation () {
1572 // Is there selections?
1573 if (ifPostContainsSelections()) {
1574 // By default nothing is removed
1577 // Something has been selected, so start updating them
1578 foreach (postRequestElement('sel') as $networkId => $sel) {
1579 // Update this entry?
1581 // Remove this entry
1582 $removed += doAdminRemoveNetworkEntry('array_translation', 'network_array_id', $networkId);
1586 // Is there removes?
1589 displayMessage('{%message,ADMIN_NETWORK_ARRAY_TRANSLATION_REMOVED=' . $removed . '%}');
1592 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_ARRAY_TRANSLATION_NOTHING_REMOVED--}');
1597 // Adds a request parameter to given network and type
1598 function doAdminNetworkProcessAddRequestParam () {
1599 // Is the request parameter already used with given network?
1600 if (isNetworkRequestElementValid(postRequestElement('network_request_param_key'), postRequestElement('network_type_id'), getRequestElement('network_id'))) {
1602 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_REQUEST_PARAMETER_ALREADY_ADDED=' . postRequestElement('network_request_param_key') . '%}');
1604 // ... so abort here
1608 // Remove the 'ok' part
1609 unsetPostRequestElement('ok');
1612 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1614 // Is network_request_param_default set?
1615 if (postRequestElement('network_request_param_default') == '') {
1616 // Remove empty value to get a NULL for an optional entry
1617 unsetPostRequestElement('network_request_param_default');
1620 // Add the whole request to database
1621 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_request_params'), __FUNCTION__, __LINE__);
1624 if (!SQL_HASZEROAFFECTED()) {
1625 // Successfully added
1626 loadTemplate('admin_network_request_param_added', false, postRequestArray());
1629 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_REQUEST_PARAMETER_NOT_ADDED=' . postRequestElement('network_request_param_key') . '%}');
1633 // Adds a vheck request parameter to given network
1634 function doAdminNetworkProcessAddVcheckParam () {
1635 // Is the request parameter already used with given network?
1636 if (isNetworkVcheckElementValid(postRequestElement('network_vcheck_param_key'), getRequestElement('network_id'))) {
1638 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_VCHECK_PARAMETER_ALREADY_ADDED=' . postRequestElement('network_vcheck_param_key') . '%}');
1640 // ... so abort here
1644 // Remove the 'ok' part
1645 unsetPostRequestElement('ok');
1648 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1650 // Is network_vcheck_param_default set?
1651 if (postRequestElement('network_vcheck_param_default') == '') {
1652 // Remove empty value to get a NULL for an optional entry
1653 unsetPostRequestElement('network_vcheck_param_default');
1656 // Add the whole vcheck to database
1657 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_vcheck_params'), __FUNCTION__, __LINE__);
1660 if (!SQL_HASZEROAFFECTED()) {
1661 // Successfully added
1662 loadTemplate('admin_network_vcheck_param_added', false, postRequestArray());
1665 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_VCHECK_PARAMETER_NOT_ADDED=' . postRequestElement('network_vcheck_param_key') . '%}');
1669 // Adds a API response array entry
1670 function doAdminNetworkProcessAddNetworkArrayTranslation () {
1671 // Is the request parameter already used with given network?
1672 if (isNetworkArrayTranslationValid(postRequestElement('network_array_index'), postRequestElement('network_type_id'), getRequestElement('network_id'))) {
1674 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_ARRAY_TRANSLATION_ALREADY_ADDED=' . postRequestElement('network_array_index') . '%}');
1676 // ... so abort here
1680 // Remove the 'ok' part
1681 unsetPostRequestElement('ok');
1684 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1687 setPostRequestElement('network_array_sort', (countSumTotalData(
1688 bigintval(postRequestElement('network_id')),
1689 'network_array_translation',
1693 sprintf(" AND `network_type_id`=%s", bigintval(postRequestElement('network_type_id')))
1696 // Add the whole request to database
1697 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_array_translation'), __FUNCTION__, __LINE__);
1700 if (!SQL_HASZEROAFFECTED()) {
1701 // Successfully added
1702 loadTemplate('admin_network_array_translation_added', false, postRequestArray());
1705 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_ARRAY_TRANSLATION_NOT_ADDED=' . postRequestElement('network_array_index') . '%}');
1709 // Handle network array translation form
1710 function doAdminNetworkProcessHandleArrayTranslations () {
1711 // Is there selections?
1712 if (ifPostContainsSelections()) {
1714 $GLOBALS['network_array_translation_disabled'] = array();
1716 // Load network data
1717 $networkData = getNetworkDataById(getRequestElement('network_id'));
1719 // Something has been selected, so start displaying one by one
1721 foreach (postRequestElement('sel') as $networkId => $sel) {
1722 // Is this selected?
1724 // Load this network's data
1725 $networkTranslationsData = getNetworkArrayTranslationsDataById($networkId);
1727 // Is there found the network?
1728 if (count($networkTranslationsData) > 0) {
1729 if (isFormSent('edit')) {
1730 // Add row template for deleting
1731 $OUT .= loadTemplate('admin_edit_network_array_translation_row', true, $networkTranslationsData);
1732 } elseif (isFormSent('delete')) {
1734 $networkTranslationsData['network_type_data'] = getNetworkTypeDataById($networkTranslationsData['network_type_id']);
1736 // Add row template for deleting
1737 $OUT .= loadTemplate('admin_delete_network_array_translation_row', true, $networkTranslationsData);
1740 reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/delete.');
1746 // If we have no rows, we don't need to display the edit form
1748 // Output main template
1749 if (isFormSent('edit')) {
1750 loadTemplate('admin_edit_network_array_translation', false, $OUT);
1751 } elseif (isFormSent('delete')) {
1752 loadTemplate('admin_delete_network_array_translation', false, $OUT);
1755 reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/delete.');
1758 // Don't display the list/add new form
1759 $GLOBALS['network_display'] = false;
1761 // Nothing selected/found
1762 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_FOUND--}');
1767 // Adds/update network API configuration
1768 function doAdminNetworkProcessNetworkApiConfig () {
1769 // Remove the 'ok' part
1770 unsetPostRequestElement('ok');
1773 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1775 // Is network_api_referral_button set?
1776 if (postRequestElement('network_api_referral_button') == '') {
1777 // Remove empty value to get a NULL for an optional entry
1778 unsetPostRequestElement('network_api_referral_button');
1781 // Is there already an entry?
1782 if (isNetworkApiConfigured(getRequestElement('network_id'))) {
1783 // Generate SQL query
1784 $SQL = getUpdateSqlFromArray(postRequestArray(), 'network_api_config', 'network_id', postRequestElement('network_id'), array('network_id'));
1787 $SQL = getInsertSqlFromArray(postRequestArray(), 'network_api_config');
1791 SQL_QUERY($SQL, __FUNCTION__, __LINE__);
1794 if (!SQL_HASZEROAFFECTED()) {
1795 // Successfully added
1796 displayMessage('{--ADMIN_CONFIG_NETWORK_API_SAVED--}');
1799 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_API_NOT_SAVED--}');
1803 // Only adds network type configuration if not yet present
1804 function doAdminNetworkProcessAddHandlerTypesConfig ($displayMessage = true) {
1805 // Remove the 'ok' part
1806 unsetPostRequestElement('ok');
1809 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1810 setPostRequestElement('network_type_id', bigintval(getRequestElement('network_type_id')));
1813 * Some parameters are optional, at least one must be given so check a bunch
1816 foreach (array('network_min_waiting_time', 'network_min_remain_clicks', 'network_min_payment', 'network_allow_erotic') as $element) {
1817 // Is this element empty?
1818 if (postRequestElement($element) == '') {
1819 // Then unset it to get a NULL for optional parameter
1820 unsetPostRequestElement($element);
1824 // Convert data in POST array
1825 convertSelectionsToEpocheTimeInPostData($content, 'network_max_reload_time_ye', $skip);
1827 // Is there already an entry?
1828 if (isNetworkTypeHandlerConfigured(getRequestElement('network_id'), getRequestElement('network_type_id'))) {
1829 // This network type handler is already configured
1830 displayMessage('{--ADMIN_NETWORK_HANDLER_TYPE_HANDLER_ALREADY_CONFIGURED--}');
1834 // Copy 'set all' and remove it from POST data
1835 $setAll = (postRequestElement('set_all') === 'Y');
1836 unsetPostRequestElement('set_all');
1838 // Shall we set for all?
1839 if ($setAll === true) {
1841 $result = SQL_QUERY_ESC('SELECT `network_type_id` FROM `{?_MYSQL_PREFIX?}_network_types` WHERE `network_id`=%s ORDER BY `network_type_id` ASC',
1842 array(bigintval(getRequestElement('network_id'))), __FUNCTION__, __LINE__);
1844 // Are there entries?
1845 if (SQL_HASZERONUMS($result)) {
1846 // No, then abort here
1847 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_SET_ALL_404--}');
1851 // Init number of rows
1855 while (list($typeId) = SQL_FETCHROW($result)) {
1856 // Set it in GET data
1857 setGetRequestElement('network_type_id', $typeId);
1859 // Call this function again
1860 $numRows += doAdminNetworkProcessAddHandlerTypesConfig(false);
1864 SQL_FREERESULT($result);
1868 // Something has been updated
1869 displayMessage('{%message,ADMIN_CONFIG_NETWORK_HANDLER_TYPE_ALL_HANDLER_SAVED=' . bigintval($numRows) . '%}');
1871 // Nothing has been saved
1872 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}');
1875 // Get SQL query for new entry
1876 $SQL = getInsertSqlFromArray(postRequestArray(), 'network_types_config');
1879 SQL_QUERY($SQL, __FUNCTION__, __LINE__);
1881 // Shall we display the message?
1882 if ($displayMessage === true) {
1884 if (!SQL_HASZEROAFFECTED()) {
1885 // Successfully added
1886 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_SAVED--}');
1889 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_SAVED--}');
1892 // Return amount of affected rows (1 or 2)
1893 return SQL_AFFECTEDROWS();
1898 // Only changes network type configuration if not yet present
1899 function doAdminNetworkProcessEditHandlerTypesConfig ($displayMessage = true) {
1900 // Remove the 'ok' part
1901 unsetPostRequestElement('ok');
1904 * Some parameters are optional, at least one must be given so check a bunch
1907 foreach (array('network_min_waiting_time', 'network_min_remain_clicks', 'network_min_payment', 'network_allow_erotic') as $element) {
1908 // Is this element empty?
1909 if (postRequestElement($element) == '') {
1910 // Then unset it to get a NULL for optional parameter
1911 unsetPostRequestElement($element);
1915 // Convert time selections in POST data
1916 convertSelectionsToEpocheTimeInPostArray('network_max_reload_time_ye');
1918 // Is there already an entry?
1919 if (!isNetworkTypeHandlerConfigured(getRequestElement('network_id'), getRequestElement('network_type_id'))) {
1920 // This network type handler is not configured
1921 displayMessage('{--ADMIN_NETWORK_HANDLER_TYPE_HANDLER_NOT_CONFIGURED--}');
1925 // Copy 'set all' and remove it from POST data
1926 $setAll = (postRequestElement('set_all') === 'Y');
1927 unsetPostRequestElement('set_all');
1929 // Shall we set for all?
1930 if ($setAll === true) {
1931 // Get all data entries
1932 $result = SQL_QUERY_ESC('SELECT `network_data_id` FROM `{?_MYSQL_PREFIX?}_network_types_config` WHERE `network_id`=%s ORDER BY `network_type_id` ASC',
1933 array(bigintval(getRequestElement('network_id'))), __FUNCTION__, __LINE__);
1935 // Are there entries?
1936 if (SQL_HASZERONUMS($result)) {
1937 // No, then abort here
1938 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_SET_ALL_404--}');
1942 // Init number of rows
1946 while (list($dataId) = SQL_FETCHROW($result)) {
1947 // Set it in GET data
1948 setPostRequestElement('network_data_id', $dataId);
1950 // Call this function again
1951 $numRows += doAdminNetworkProcessEditHandlerTypesConfig(false);
1955 SQL_FREERESULT($result);
1959 // Something has been updated
1960 displayMessage('{%message,ADMIN_CONFIG_NETWORK_HANDLER_TYPE_ALL_HANDLER_SAVED=' . bigintval($numRows) . '%}');
1962 // Nothing has been saved
1963 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}');
1966 // Get SQL query for new entry
1967 $SQL = getUpdateSqlFromArray(postRequestArray(), 'network_types_config', 'network_data_id', postRequestElement('network_data_id'), array('network_data_id'));
1970 SQL_QUERY($SQL, __FUNCTION__, __LINE__);
1972 // Shall we display the message?
1973 if ($displayMessage === true) {
1975 if (!SQL_HASZEROAFFECTED()) {
1976 // Successfully added
1977 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_SAVED--}');
1980 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}');
1983 // Return amount of affected rows (1 or 2)
1984 return SQL_AFFECTEDROWS();
1989 // Do expression code for this extension
1990 function doExpressionNetwork ($data) {
1991 // Construct replacer
1992 $replacer = sprintf(
1993 "{DQUOTE} . %s(%s, '%s') . {DQUOTE}",
1995 $data['matches'][4][$data['key']],
1999 // Replace %network_id% with the current network id
2000 $replacer = str_replace('%network_id%', getCurrentNetworkId(), $replacer);
2003 $code = replaceExpressionCode($data, $replacer);
2009 // ----------------------------------------------------------------------------
2010 // Call-back functions for exporting data
2011 // ----------------------------------------------------------------------------
2013 // Callback function to export network tables
2014 function doAdminNetworkProcessExport () {
2015 // Init table with all valid what->table entries
2016 $validExports = array(
2017 // General network data
2018 'list_network_data' => 'data',
2019 // Network type handler
2020 'list_network_types' => 'types',
2021 // Network request parameter
2022 'list_network_request_params' => 'request_params',
2023 // Vcheck request parameter
2024 'list_network_vcheck_params' => 'vcheck_params',
2025 // Network API response array index translation
2026 'list_network_array_translation' => 'array_translation',
2029 // Is the 'what' key valid?
2030 if (!isset($validExports[getWhat()])) {
2032 reportBug(__FUNCTION__, __LINE__, 'what=' . getWhat() . ' - not supported');
2035 // Generate call-back, some tables require to export not all columns
2036 $callbackName = 'doAdminNetworkExport' . capitalizeUnderscoreString($validExports[getWhat()]);
2038 // Is the call-back function there?
2039 if (!function_exists($callbackName)) {
2040 // No, this is really bad
2041 reportBug(__FUNCTION__, __LINE__, 'Invalid call-back function ' . $callbackName . ' detected.');
2042 } elseif (isset($GLOBALS[__FUNCTION__][$callbackName])) {
2044 reportBug(__FUNCTION__, __LINE__, 'Double-call of export function ' . $callbackName . ' detected.');
2047 // Call the function
2048 call_user_func($callbackName);
2050 // Mark it as called
2051 $GLOBALS[__FUNCTION__][$callbackName] = true;
2053 // Don't display the list/add new form
2054 $GLOBALS['network_display'] = false;
2057 // Exports (and displays) the table 'network_data'
2058 function doAdminNetworkExportData () {
2059 // Query for all networks
2060 $result = SQL_QUERY('SELECT
2061 `network_short_name`,
2064 `network_data_separator`,
2065 `network_row_separator`,
2066 `network_request_type`,
2068 `network_require_id_card`,
2069 `network_query_amount`,
2072 `{?_MYSQL_PREFIX?}_network_data`
2075 __FUNCTION__, __LINE__);
2077 // Start an empty SQL query
2078 $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";
2081 while ($content = SQL_FETCHARRAY($result)) {
2084 $content['network_short_name'] . "', '" .
2085 $content['network_title'] . "', '" .
2086 $content['network_reflink'] . "', '" .
2087 $content['network_data_separator'] . "', '" .
2088 $content['network_row_separator'] . "', '" .
2089 $content['network_request_type'] . "', '" .
2090 $content['network_charset'] . "', '" .
2091 $content['network_require_id_card'] . "', " .
2092 $content['network_query_amount'] . ", '" .
2093 $content['network_active'] . "'),\n";
2096 // Remove last commata and close braces
2097 $SQL = substr($SQL, 0, -2);
2100 SQL_FREERESULT($result);
2102 // Output the SQL query
2103 loadTemplate('admin_export_network_data', false, $SQL);
2106 // Exports (and displays) the table 'network_types'
2107 function doAdminNetworkExportTypes () {
2108 // 'network_id' must be set
2109 if (!isGetRequestElementSet('network_id')) {
2110 // Only network handlers of one network will be exported per time
2111 reportBug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
2114 // Get all network types of given network
2115 $result = SQL_QUERY_ESC('SELECT
2118 `network_type_handler`,
2119 `network_type_api_url`,
2120 `network_type_click_url`,
2121 `network_type_banner_url`,
2122 `network_type_reload_time_unit`,
2123 `network_text_encoding`
2125 `{?_MYSQL_PREFIX?}_network_types`
2129 `network_type_id` ASC',
2131 bigintval(getRequestElement('network_id'))
2132 ), __FUNCTION__, __LINE__);
2134 // Start an empty SQL query
2135 $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";
2138 while ($content = SQL_FETCHARRAY($result)) {
2141 $content['network_type_id'] . ', ' .
2142 $content['network_id'] . ", '" .
2143 $content['network_type_handler'] . "', '" .
2144 $content['network_type_api_url'] . "', '" .
2145 $content['network_type_click_url'] . "', ";
2147 // Is the column NULL?
2148 if (is_null($content['network_type_banner_url'])) {
2153 $SQL .= chr(39) . $content['network_type_banner_url'] . chr(39);
2157 $SQL .= ",'" . $content['network_type_reload_time_unit'] . "','" . $content['network_text_encoding'] . "'),\n";
2160 // Remove last commata and close braces
2161 $SQL = substr($SQL, 0, -2);
2164 SQL_FREERESULT($result);
2166 // Output the SQL query
2167 loadTemplate('admin_export_network_types', false, $SQL);
2170 // Exports (and displays) the table 'network_request_params'
2171 function doAdminNetworkExportRequestParams () {
2172 // 'network_id' must be set
2173 if (!isGetRequestElementSet('network_id')) {
2174 // Only network request parameters of one network will be exported per time
2175 reportBug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
2178 // Get all network types of given network
2179 $result = SQL_QUERY_ESC('SELECT
2182 `network_request_param_key`,
2183 `network_request_param_value`,
2184 `network_request_param_default`
2186 `{?_MYSQL_PREFIX?}_network_request_params`
2190 `network_type_id` ASC ,
2191 `network_request_param_id` ASC',
2193 bigintval(getRequestElement('network_id'))
2194 ), __FUNCTION__, __LINE__);
2196 // Start an empty SQL query
2197 $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";
2200 while ($content = SQL_FETCHARRAY($result)) {
2203 $content['network_id'] . ', ' .
2204 $content['network_type_id'] . ", '" .
2205 $content['network_request_param_key'] . "', '" .
2206 $content['network_request_param_value'] . "', ";
2208 // Is the column NULL?
2209 if (is_null($content['network_request_param_default'])) {
2214 $SQL .= chr(39) . $content['network_request_param_default'] . "'),\n";
2218 // Remove last commata and close braces
2219 $SQL = substr($SQL, 0, -2);
2222 SQL_FREERESULT($result);
2224 // Output the SQL query
2225 loadTemplate('admin_export_network_request_params', false, $SQL);
2228 // Exports (and displays) the table 'network_vcheck_params'
2229 function doAdminNetworkExportVcheckParams () {
2230 // 'network_id' must be set
2231 if (!isGetRequestElementSet('network_id')) {
2232 // Only network vcheck parameters of one network will be exported per time
2233 reportBug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
2236 // Get all network types of given network
2237 $result = SQL_QUERY_ESC('SELECT
2239 `network_vcheck_param_key`,
2240 `network_vcheck_param_value`,
2241 `network_vcheck_param_default`
2243 `{?_MYSQL_PREFIX?}_network_vcheck_params`
2247 `network_vcheck_param_id` ASC',
2249 bigintval(getRequestElement('network_id'))
2250 ), __FUNCTION__, __LINE__);
2252 // Start an empty SQL query
2253 $SQL = "INSERT INTO `{?_MYSQL_PREFIX?}_network_vcheck_params` (`network_id`, `network_vcheck_param_key`, `network_vcheck_param_value`, `network_vcheck_param_default`) VALUES\n";
2256 while ($content = SQL_FETCHARRAY($result)) {
2259 $content['network_id'] . ", '" .
2260 $content['network_vcheck_param_key'] . "', '" .
2261 $content['network_vcheck_param_value'] . "', ";
2263 // Is the column NULL?
2264 if (is_null($content['network_vcheck_param_default'])) {
2269 $SQL .= chr(39) . $content['network_vcheck_param_default'] . "'),\n";
2273 // Remove last commata and close braces
2274 $SQL = substr($SQL, 0, -2);
2277 SQL_FREERESULT($result);
2279 // Output the SQL query
2280 loadTemplate('admin_export_network_vcheck_params', false, $SQL);
2283 // Exports (and displays) the table 'network_array_translation'
2284 function doAdminNetworkExportArrayTranslation () {
2285 // 'network_id' must be set
2286 if (!isGetRequestElementSet('network_id')) {
2287 // Only network API array index translations of one network will be exported per time
2288 reportBug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
2291 // Get all network types of given network
2292 $result = SQL_QUERY_ESC('SELECT
2295 `network_array_index`,
2296 `network_array_sort`
2298 `{?_MYSQL_PREFIX?}_network_array_translation`
2302 `network_type_id` ASC,
2303 `network_array_sort` ASC',
2305 bigintval(getRequestElement('network_id'))
2306 ), __FUNCTION__, __LINE__);
2308 // Start an empty SQL query
2309 $SQL = "INSERT INTO `{?_MYSQL_PREFIX?}_network_array_translation` (`network_id`, `network_type_id`, `network_array_index`, `network_array_sort`) VALUES\n";
2312 while ($content = SQL_FETCHARRAY($result)) {
2315 $content['network_id'] . ', ' .
2316 $content['network_type_id'] . ', ' .
2317 $content['network_array_index'] . ', ' .
2318 $content['network_array_sort'] . "),\n";
2321 // Remove last commata and close braces
2322 $SQL = substr($SQL, 0, -2);
2325 SQL_FREERESULT($result);
2327 // Output the SQL query
2328 loadTemplate('admin_export_network_array_translation', false, $SQL);