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('save_config', 'add', 'edit', 'delete', 'do_edit', 'do_delete') as $formName) {
67 if (isFormSent($formName)) {
69 $GLOBALS['network_form_name'] = $formName;
71 // Remove it generically here
72 unsetPostRequestElement($formName);
79 // Has the form being detected?
80 if ($GLOBALS['network_form_name'] == 'invalid') {
82 reportBug(__FUNCTION__, __LINE__, 'POST form could not be detected, postData=<pre>' . print_r(postRequestArray(), TRUE));
86 // Handle a (maybe) sent form here
87 function doNetworkHandleForm () {
88 // Is there a form sent?
89 if (countRequestPost() > 0) {
90 // Detect sent POST form
91 detectNetworkProcessForm();
92 } elseif (!isGetRequestElementSet('do')) {
93 // Skip any further requests
97 // Process the request
98 doAdminNetworkProcessForm();
101 // Processes an admin form
102 function doAdminNetworkProcessForm () {
103 // Create function name
104 $functionName = sprintf("doAdminNetworkProcess%s", capitalizeUnderscoreString(getRequestElement('do')));
106 // Is the function valid?
107 if (!function_exists($functionName)) {
108 // Invalid function name
109 reportBug(__FUNCTION__, __LINE__, 'Invalid do ' . getRequestElement('do') . ', function ' . $functionName .' does not exist.', FALSE);
112 // Init global arrays
113 $GLOBALS['network_types_disabled'] = array();
115 // Call-back the method handling our request
116 call_user_func($functionName);
119 // Checks whether the (short) network name is already used (valid)
120 function isNetworkNameValid ($name) {
122 if (!isset($GLOBALS[__FUNCTION__][$name])) {
124 $GLOBALS[__FUNCTION__][$name] = (countSumTotalData($name, 'network_data', 'network_id', 'network_short_name', TRUE) == 1);
128 return $GLOBALS[__FUNCTION__][$name];
131 // Checks whether the (short) named network is activated
132 function isNetworkActiveByShortName ($name) {
134 if (!isset($GLOBALS[__FUNCTION__][$name])) {
136 $GLOBALS[__FUNCTION__][$name] = ((isNetworkNameValid($name)) && (countSumTotalData($name, 'network_data', 'network_id', 'network_short_name', TRUE, " AND `network_active`='Y'") == 1));
140 return $GLOBALS[__FUNCTION__][$name];
143 // Checks whether the network by given id is activated
144 function isNetworkActiveById ($networkId) {
146 if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
148 $GLOBALS[__FUNCTION__][$networkId] = (countSumTotalData(bigintval($networkId), 'network_data', 'network_id', 'network_id', TRUE, " AND `network_active`='Y'") == 1);
152 return $GLOBALS[__FUNCTION__][$networkId];
155 // "Getter" for 'network_activated' column depending on current administrator's expert setting
156 function getNetworkActivatedColumn ($whereAnd = 'WHERE', $table = '') {
158 if (!isset($GLOBALS[__FUNCTION__][$whereAnd][$table])) {
159 // Default is exclude deactivated networks
160 $GLOBALS[__FUNCTION__][$whereAnd][$table] = ' ' . $whereAnd . ' ' . $table . "`network_active`='Y'";
162 // Is the export setting on?
163 if (isAdminsExpertSettingEnabled()) {
164 // Then allow all networks
165 $GLOBALS[__FUNCTION__][$whereAnd][$table] = '';
170 return $GLOBALS[__FUNCTION__][$whereAnd][$table];
173 // Checks whether the given network type is already used (valid)
174 function isNetworkTypeHandleValid ($type, $networkId) {
176 $result = SQL_QUERY_ESC("SELECT `network_type_id` FROM `{?_MYSQL_PREFIX?}_network_types` WHERE `network_id`=%s AND `network_type_handler`='%s' LIMIT 1",
180 ), __FUNCTION__, __LINE__);
183 $isValid = (SQL_NUMROWS($result) == 1);
186 SQL_FREERESULT($result);
192 // Checks whether the given network request parameter is already used (valid)
193 function isNetworkRequestElementValid ($key, $type, $networkId) {
195 $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",
200 ), __FUNCTION__, __LINE__);
203 $isValid = (SQL_NUMROWS($result) == 1);
206 SQL_FREERESULT($result);
212 // Checks whether the given vcheck request parameter is already used (valid)
213 function isNetworkVcheckElementValid ($key, $networkId) {
215 $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",
219 ), __FUNCTION__, __LINE__);
222 $isValid = (SQL_NUMROWS($result) == 1);
225 SQL_FREERESULT($result);
231 // Checks whether the given network API array translation
232 function isNetworkArrayTranslationValid ($key, $type, $networkId) {
234 $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",
239 ), __FUNCTION__, __LINE__);
242 $isValid = (SQL_NUMROWS($result) == 1);
245 SQL_FREERESULT($result);
251 // "Getter" for a network's data by provided id number
252 function getNetworkDataById ($networkId, $column = '') {
253 // Ids lower one are not accepted
254 if ($networkId < 1) {
255 // Not good, should be fixed
256 reportBug(__FUNCTION__, __LINE__, 'Network id ' . $networkId . ' is smaller than 1.');
257 } elseif ((!isNetworkActiveById($networkId)) && (!isAdminsExpertSettingEnabled())) {
258 // Do not load inactive network data
259 reportBug(__FUNCTION__, __LINE__, 'Network id ' . $networkId . ' is not active.');
262 // Set current network id
263 setCurrentNetworkId($networkId);
266 if (!isset($GLOBALS['network_data'][$networkId])) {
267 // By default we have no data
268 $GLOBALS['network_data'][$networkId] = array();
270 // Query for the network data
271 $result = SQL_QUERY_ESC('SELECT
273 `network_short_name`,
276 `network_data_separator`,
277 `network_row_separator`,
278 `network_request_type`,
280 `network_require_id_card`,
281 `network_query_amount`
283 `{?_MYSQL_PREFIX?}_network_data`
287 array(bigintval($networkId)), __FUNCTION__, __LINE__);
289 // Is there an entry?
290 if (SQL_NUMROWS($result) == 1) {
292 $GLOBALS['network_data'][$networkId] = SQL_FETCHARRAY($result);
296 SQL_FREERESULT($result);
300 if ((empty($column)) && (isset($GLOBALS['network_data'][$networkId]))) {
302 return $GLOBALS['network_data'][$networkId];
303 } elseif (isset($GLOBALS['network_data'][$networkId][$column])) {
305 return $GLOBALS['network_data'][$networkId][$column];
312 // "Getter" for a network's data by provided type id number
313 function getNetworkDataByTypeId ($networkId, $column = '') {
314 // Ids lower one are not accepted
315 if ($networkId < 1) {
316 // Not good, should be fixed
317 reportBug(__FUNCTION__, __LINE__, 'Network type id ' . $networkId . ' is smaller than 1.');
318 } elseif ((!isNetworkActiveById($networkId)) && (!isAdminsExpertSettingEnabled())) {
319 // Do not load inactive network data
320 reportBug(__FUNCTION__, __LINE__, 'Network id ' . $networkId . ' is not active.');
323 // Set current network id
324 setCurrentNetworkId($networkId);
327 if (!isset($GLOBALS['network_data'][$networkId])) {
328 // By default we have no data
329 $GLOBALS['network_data'][$networkId] = array();
331 // Query for the network data
332 $result = SQL_QUERY_ESC('SELECT
334 d.`network_short_name`,
337 d.`network_data_separator`,
338 d.`network_row_separator`,
339 d.`network_request_type`,
341 d.`network_require_id_card`,
342 d.`network_query_amount`,
343 t.`network_type_handler`,
344 t.`network_type_api_url`,
345 t.`network_type_click_url`,
346 t.`network_type_banner_url`,
347 t.`network_text_encoding`
349 `{?_MYSQL_PREFIX?}_network_data` AS d
351 `{?_MYSQL_PREFIX?}_network_types` AS t
353 d.`network_id`=t.`network_id`
355 t.`network_type_id`=%s
357 array(bigintval($networkId)), __FUNCTION__, __LINE__);
359 // Is there an entry?
360 if (SQL_NUMROWS($result) == 1) {
362 $GLOBALS['network_data'][$networkId] = SQL_FETCHARRAY($result);
366 SQL_FREERESULT($result);
370 if (empty($column)) {
372 return $GLOBALS['network_data'][$networkId];
375 return $GLOBALS['network_data'][$networkId][$column];
379 // "Getter" for a network type data by provided id number
380 function getNetworkTypeDataById ($networkTypeId) {
381 // Ids lower one are not accepted
382 if ($networkTypeId < 1) {
383 // Not good, should be fixed
384 reportBug(__FUNCTION__, __LINE__, 'Network type id ' . $networkTypeId . ' is smaller than 1.');
387 // By default we have no data
388 $GLOBALS['network_type_data'][$networkTypeId] = array();
390 // Query for the network data
391 $result = SQL_QUERY_ESC('SELECT
394 `network_type_handler`,
395 `network_type_api_url`,
396 `network_type_click_url`,
397 `network_type_banner_url`
399 `{?_MYSQL_PREFIX?}_network_types`
403 array(bigintval($networkTypeId)), __FUNCTION__, __LINE__);
405 // Is there an entry?
406 if (SQL_NUMROWS($result) == 1) {
408 $GLOBALS['network_type_data'][$networkTypeId] = SQL_FETCHARRAY($result);
412 SQL_FREERESULT($result);
415 return $GLOBALS['network_type_data'][$networkTypeId];
418 // "Getter" for a network request parameter data by provided id number
419 function getNetworkRequestParamsDataById ($networkRequestId) {
420 // Ids lower one are not accepted
421 if ($networkRequestId < 1) {
422 // Not good, should be fixed
423 reportBug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $networkRequestId . ' is smaller than 1.');
426 // By default we have no data
427 $networkRequestData = array();
429 // Query for the network data
430 $result = SQL_QUERY_ESC('SELECT
431 `network_request_param_id`,
434 `network_request_param_key`,
435 `network_request_param_value`,
436 `network_request_param_default`
438 `{?_MYSQL_PREFIX?}_network_request_params`
440 `network_request_param_id`=%s
442 array(bigintval($networkRequestId)), __FUNCTION__, __LINE__);
444 // Is there an entry?
445 if (SQL_NUMROWS($result) == 1) {
447 $networkRequestData = SQL_FETCHARRAY($result);
451 SQL_FREERESULT($result);
454 return $networkRequestData;
457 // "Getter" for a network array translation data by provided id number
458 function getNetworkArrayTranslationsDataById ($networkTranslationId) {
459 // Ids lower one are not accepted
460 if ($networkTranslationId < 1) {
461 // Not good, should be fixed
462 reportBug(__FUNCTION__, __LINE__, 'Network array translation id ' . $networkTranslationId . ' is smaller than 1.');
465 // By default we have no data
466 $networkTranslationData = array();
468 // Query for the network data
469 $result = SQL_QUERY_ESC('SELECT
473 `network_array_index`,
476 `{?_MYSQL_PREFIX?}_network_array_translation`
478 `network_array_id`=%s
480 array(bigintval($networkTranslationId)), __FUNCTION__, __LINE__);
482 // Is there an entry?
483 if (SQL_NUMROWS($result) == 1) {
485 $networkTranslationData = SQL_FETCHARRAY($result);
489 SQL_FREERESULT($result);
492 return $networkTranslationData;
495 // Updates given network (id) with data from array
496 function doNetworkUpdateDataByArray ($networkId, $networkData) {
497 // Ids lower one are not accepted
498 if ($networkId < 1) {
499 // Not good, should be fixed
500 reportBug(__FUNCTION__, __LINE__, 'Network id ' . $networkId . ' is smaller than 1.');
503 // Just call our inner method
504 return adminSaveSettings($networkData, '_network_data', sprintf("`network_id`=%s", bigintval($networkId)), array(), FALSE, FALSE);
507 // Updates given network type handler (id) with data from array
508 function doNetworkUpdateTypeByArray ($networkTypeId, $networkTypeData) {
509 // Ids lower one are not accepted
510 if ($networkTypeId < 1) {
511 // Not good, should be fixed
512 reportBug(__FUNCTION__, __LINE__, 'Network type handler id ' . $networkTypeId . ' is smaller than 1.');
515 // Just call our inner method
516 return adminSaveSettings($networkTypeData, '_network_types', sprintf("`network_type_id`=%s", bigintval($networkTypeId)), array(), FALSE, FALSE);
519 // Updates given network request parameters (id) with data from array
520 function doNetworkUpdateParamsByArray ($networkParamsId, $networkParamsData) {
521 // Ids lower one are not accepted
522 if ($networkParamsId < 1) {
523 // Not good, should be fixed
524 reportBug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $networkParamsId . ' is smaller than 1.');
527 // Just call our inner method
528 return adminSaveSettings($networkParamsData, '_network_request_params', sprintf("`network_request_param_id`=%s", bigintval($networkParamsId)), array(), FALSE, FALSE);
531 // Updates given network array translations (id) with data from array
532 function doNetworkUpdateArrayTranslationsByArray ($networkTranslationsId, $networkTranslationsData) {
533 // Ids lower one are not accepted
534 if ($networkTranslationsId < 1) {
535 // Not good, should be fixed
536 reportBug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $networkTranslationsId . ' is smaller than 1.');
539 // Just call our inner method
540 return adminSaveSettings($networkTranslationsData, '_network_array_translation', sprintf("`network_array_id`=%s", bigintval($networkTranslationsId)), array(), FALSE, FALSE);
543 // Removes given network entry
544 function doAdminRemoveNetworkEntry ($table, $column, $id, $limit = 1) {
546 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_network_%s` WHERE `%s`=%s LIMIT %s",
552 ), __FUNCTION__, __LINE__);
554 // Return affected rows
555 return SQL_AFFECTEDROWS();
558 // Generates a list of networks for given script and returns it
559 function generateAdminNetworkList () {
563 // Query for all networks
564 $result = SQL_QUERY('SELECT
566 `network_short_name`,
569 `{?_MYSQL_PREFIX?}_network_data`
570 ' . getNetworkActivatedColumn() . '
572 `network_short_name` ASC', __FUNCTION__, __LINE__);
574 // Are there entries?
575 if (!SQL_HASZERONUMS($result)) {
578 while ($row = SQL_FETCHARRAY($result)) {
579 // Is this valid, then add it
580 if ((is_array($row)) && (isset($row['network_id']))) {
582 $rows[$row['network_id']] = $row;
586 // Generate the selection box
587 $content = generateSelectionBoxFromArray($rows, 'network_id', 'network_id', '', '', 'network');
590 $content = loadTemplate('admin_settings_unsaved', FALSE, '{--ADMIN_ENTRIES_404--}');
594 SQL_FREERESULT($result);
600 // Generator (somewhat getter) for a list of network types for given network id
601 function generateAdminNetworkTypeList ($networkId) {
605 // Query all types of this network
606 $result = SQL_QUERY_ESC('SELECT
608 `network_type_handler`
610 `{?_MYSQL_PREFIX?}_network_types`
613 ' . getNetworkActivatedColumn('AND') . '
615 `network_type_handler` ASC',
617 bigintval($networkId)
618 ), __FUNCTION__, __LINE__);
620 // Are there entries?
621 if (!SQL_HASZERONUMS($result)) {
624 while ($row = SQL_FETCHARRAY($result)) {
625 // Is this valid, then add it
626 if ((is_array($row)) && (isset($row['network_type_id']))) {
628 $rows[$row['network_type_id']] = $row;
632 // Generate the selection box
633 $content = generateSelectionBoxFromArray($rows, 'network_type', 'network_type_id');
636 $content = loadTemplate('admin_settings_unsaved', FALSE, '{--ADMIN_ENTRIES_404--}');
640 SQL_FREERESULT($result);
646 // Generator (somewhat getter) for a list of network types for all types
647 function generateAdminDistinctNetworkTypeList () {
651 // Query all types of this network
652 $result = SQL_QUERY('SELECT
654 t.`network_type_handler`,
657 `{?_MYSQL_PREFIX?}_network_types` AS t
659 `{?_MYSQL_PREFIX?}_network_data` AS d
661 t.`network_id`=d.`network_id`
662 ' . getNetworkActivatedColumn('WHERE', 'd') . '
664 d.`network_short_name` ASC,
665 t.`network_type_handler` ASC', __FUNCTION__, __LINE__);
667 // Are there entries?
668 if (!SQL_HASZERONUMS($result)) {
671 while ($row = SQL_FETCHARRAY($result)) {
672 // Is this valid, then add it
673 if ((is_array($row)) && (isset($row['network_type_id']))) {
675 $rows[$row['network_type_id']] = $row;
679 // Generate the selection box
680 $content = generateSelectionBoxFromArray($rows, 'network_type', 'network_type_id', '', '_title');
683 $content = loadTemplate('admin_settings_unsaved', FALSE, '{--ADMIN_ENTRIES_404--}');
687 SQL_FREERESULT($result);
688 //* DEBUG: */ die('<pre>'.encodeEntities($content).'</pre>');
694 // Generator (somewhat getter) for network type options
695 function generateNetworkTypeOptions ($networkId) {
696 // Is this an array, then we just came back from edit/delete actions
697 if (is_array($networkId)) {
698 // Set it as empty string
703 if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
704 // Generate output and cache it
705 $GLOBALS[__FUNCTION__][$networkId] = generateOptions(
708 'network_type_handler',
712 "WHERE `network_id`=%s" . getNetworkActivatedColumn('AND'),
713 bigintval(getRequestElement('network_id'))
716 'translateNetworkTypeHandler'
721 return $GLOBALS[__FUNCTION__][$networkId];
724 // Generates an options list of all available (hard-coded) handlers
725 function generateNetworkTypesAvailableOptions ($defaultType = NULL) {
727 if (!isset($GLOBALS[__FUNCTION__][$defaultType])) {
729 $GLOBALS[__FUNCTION__][$defaultType] = generateOptions(
772 $GLOBALS['network_types_disabled'],
773 'translateNetworkTypeHandler'
778 return $GLOBALS[__FUNCTION__][$defaultType];
781 // Generates an options list of all available (hard-coded) text encoders
782 function generateNetworkTextEncodingAvailableOptions ($defaultEncoding = NULL) {
784 if (!isset($GLOBALS[__FUNCTION__][$defaultEncoding])) {
786 $GLOBALS[__FUNCTION__][$defaultEncoding] = generateOptions(
796 'translateNetworkTextEncoding'
801 return $GLOBALS[__FUNCTION__][$defaultEncoding];
804 // Generates an options list (somewhat getter) for request keys
805 function generateNetworkRequestKeyOptions () {
807 if (!isset($GLOBALS[__FUNCTION__])) {
808 // Generate and cache it
809 $GLOBALS[__FUNCTION__] = generateOptions(
831 $GLOBALS['network_request_params_disabled'],
832 'translateNetworkRequestParameterKey'
837 return $GLOBALS[__FUNCTION__];
840 // Generates an options list for vcheck request keys
841 function generateNetworkVcheckKeyOptions () {
843 if (!isset($GLOBALS[__FUNCTION__])) {
844 // Generate and cache it
845 $GLOBALS[__FUNCTION__] = generateOptions(
865 $GLOBALS['network_vcheck_params_disabled'],
866 'translateNetworkVcheckParameterKey'
871 return $GLOBALS[__FUNCTION__];
874 // Generator (somewhat getter) for (return) array translation
875 function generateNetworkTranslationOptions ($default = '') {
877 if (!isset($GLOBALS[__FUNCTION__][$default])) {
878 // Generate and cache it
879 $GLOBALS[__FUNCTION__][$default] = generateOptions(
880 'network_translations',
881 'network_translation_id',
882 'network_translation_name',
886 $GLOBALS['network_array_translation_disabled'],
887 'translateNetworkTranslationName'
892 return $GLOBALS[__FUNCTION__][$default];
895 // Generates an option list of request types
896 function generateNetworkRequestTypeOptions ($default = '') {
898 if (!isset($GLOBALS[__FUNCTION__][$default])) {
900 $GLOBALS[__FUNCTION__][$default] = generateOptions(
907 '{--ADMIN_NETWORK_REQUEST_TYPE_GET--}',
908 '{--ADMIN_NETWORK_REQUEST_TYPE_POST--}'
915 return $GLOBALS[__FUNCTION__][$default];
918 // Generates an option list of network_api_active
919 function generateNetworkApiActiveOptions ($default = '') {
921 if (!isset($GLOBALS[__FUNCTION__][$default])) {
923 $GLOBALS[__FUNCTION__][$default] = generateYesNoOptions($default);
927 return $GLOBALS[__FUNCTION__][$default];
930 // Translates 'translate_name' for e.g. templates
931 function translateNetworkTranslationName ($name) {
933 $messageId = 'ADMIN_NETWORK_TRANSLATE_' . strtoupper($name) . '_NAME';
935 // Is the message id there?
936 if (!isMessageIdValid($messageId)) {
938 reportBug(__FUNCTION__, __LINE__, 'name=' . $name . ' is invalid.');
942 return '{--' . $messageId . '--}';
945 // Translates the network type handler (e.g. banner, paidmail) for templates
946 function translateNetworkTypeHandler ($type) {
948 $messageId = 'ADMIN_NETWORK_TYPE_HANDLER_' . strtoupper($type);
950 // Is the message id there?
951 if (!isMessageIdValid($messageId)) {
953 reportBug(__FUNCTION__, __LINE__, 'type=' . $type . ' is invalid.');
957 return '{--' . $messageId . '--}';
960 // Translates request type
961 function translateNetworkRequestType ($type) {
963 $messageId = 'ADMIN_NETWORK_REQUEST_TYPE_' . strtoupper($type) . '';
965 // Is the message id there?
966 if (!isMessageIdValid($messageId)) {
968 reportBug(__FUNCTION__, __LINE__, 'type=' . $type . ' is invalid.');
972 return '{--' . $messageId . '--}';
975 // Translates request parameter
976 function translateNetworkRequestParameterKey ($param) {
978 $messageId = 'ADMIN_NETWORK_REQUEST_PARAMETER_' . strtoupper($param) . '';
980 // Is the message id there?
981 if (!isMessageIdValid($messageId)) {
983 reportBug(__FUNCTION__, __LINE__, 'param=' . $param . ' is invalid.');
987 return '{--' . $messageId . '--}';
990 // Translates vheck request parameter
991 function translateNetworkVcheckParameterKey ($param) {
993 $messageId = 'ADMIN_NETWORK_VCHECK_PARAMETER_' . strtoupper($param) . '';
995 // Is the message id there?
996 if (!isMessageIdValid($messageId)) {
998 reportBug(__FUNCTION__, __LINE__, 'param=' . $param . ' is invalid.');
1001 // Return message id
1002 return '{--' . $messageId . '--}';
1005 // Translate text-encoding
1006 function translateNetworkTextEncoding ($encoding) {
1008 $messageId = 'ADMIN_NETWORK_TYPE_TEXT_ENCODING_' . strtoupper($encoding) . '';
1010 // Is the message id there?
1011 if (!isMessageIdValid($messageId)) {
1012 // Not valid encoding
1013 reportBug(__FUNCTION__, __LINE__, 'encoding=' . $encoding . ' is invalid.');
1016 // Return message id
1017 return '{--' . $messageId . '--}';
1020 // Translates API index
1021 function translateNetworkApiIndex ($index) {
1023 if (!isset($GLOBALS['network_array_index'])) {
1024 // Get an array of all API array indexes
1025 $GLOBALS['network_array_index'] = array();
1028 $result = SQL_QUERY('SELECT
1030 `network_array_index`,
1031 `network_translation_name`
1033 `{?_MYSQL_PREFIX?}_network_array_translation`
1035 `{?_MYSQL_PREFIX?}_network_translations`
1037 `network_array_index`=`network_translation_id`
1039 `network_array_sort` ASC', __FUNCTION__, __LINE__);
1041 // Are there entries?
1042 if (!SQL_HASZERONUMS($result)) {
1044 while ($row = SQL_FETCHARRAY($result)) {
1045 // Add it to our global array
1046 $GLOBALS['network_array_index'][$row['network_array_index']] = $row;
1051 SQL_FREERESULT($result);
1054 // Default name is unknown
1057 // Is the entry there?
1058 if (isset($GLOBALS['network_array_index'][$index])) {
1059 // Then get the name
1060 $name = $GLOBALS['network_array_index'][$index]['network_translation_name'];
1063 // Return translation
1064 return translateNetworkTranslationName($name);
1067 // Translates network API configuration status (see function isNetworkApiConfigured()) by given id
1068 function translateNetworkApiConfiguredStatusById ($networkId) {
1070 if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
1071 // By default it is not configured
1072 $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_NOT_CONFIGURED--}';
1074 // So is it configured?
1075 if (!isNetworkActiveById($networkId)) {
1076 // Network is not active
1077 $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_NOT_ACTIVE--}';
1078 } elseif (isNetworkApiConfigured($networkId)) {
1080 $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_CONFIGURED--}';
1085 return $GLOBALS[__FUNCTION__][$networkId];
1088 // Checks if the given network is configured by looking its API configuration entry up
1089 function isNetworkApiConfigured ($networkId) {
1091 if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
1092 // Check for an entry in network_api_config
1093 $GLOBALS[__FUNCTION__][$networkId] = (countSumTotalData(
1094 bigintval($networkId),
1095 'network_api_config',
1103 return $GLOBALS[__FUNCTION__][$networkId];
1106 // Checks whether the given network type handler is configured
1107 function isNetworkTypeHandlerConfigured ($networkId, $networkTypeId) {
1109 if (!isset($GLOBALS[__FUNCTION__][$networkId][$networkTypeId])) {
1111 $GLOBALS[__FUNCTION__][$networkId][$networkTypeId] = (countSumTotalData(
1112 bigintval($networkTypeId),
1113 'network_types_config',
1117 sprintf(' AND `network_id`=%s', bigintval($networkId))
1122 return $GLOBALS[__FUNCTION__][$networkId][$networkTypeId];
1125 // Handles the network-payment-check request
1126 function handleNetworkPaymentCheckRequest () {
1127 // @TODO Implement this function, don't forget to set HTTP status back to '200 OK' if everything went fine
1128 reportBug(__FUNCTION__, __LINE__, 'Not yet implemented.');
1131 //------------------------------------------------------------------------------
1132 // Call-back functions
1133 //------------------------------------------------------------------------------
1135 // Callback function to add new network
1136 function doAdminNetworkProcessAddNetwork () {
1137 // We can say here, the form is sent, so check if the network is already added
1138 if (isNetworkNameValid(postRequestElement('network_short_name'))) {
1140 loadTemplate('admin_settings_unsaved', FALSE, '{%message,ADMIN_NETWORK_ALREADY_ADDED=' . postRequestElement('network_short_name') . '%}');
1144 // Add the whole request to database
1145 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_data'), __FUNCTION__, __LINE__);
1147 // Add the id for output only
1148 setPostRequestElement('network_id', SQL_INSERTID());
1151 if (!SQL_HASZEROAFFECTED()) {
1152 // Successfully added
1153 loadTemplate('admin_network_added', FALSE, postRequestArray());
1156 loadTemplate('admin_settings_unsaved', FALSE, '{%message,ADMIN_NETWORK_DATA_NOT_ADDED=' . postRequestElement('network_short_name') . '%}');
1160 // Displays selected networks for editing
1161 function doAdminNetworkProcessHandleNetworks () {
1162 // Is there selections?
1163 if (ifPostContainsSelections()) {
1164 // Something has been selected, so start displaying one by one
1166 foreach (postRequestElement('sel') as $networkId => $sel) {
1167 // Is this selected?
1169 // Load this network's data
1170 $networkData = getNetworkDataById($networkId);
1172 // Is there found the network?
1173 if (count($networkData) > 0) {
1174 // Add row template with given form name
1175 $OUT .= loadTemplate('admin_' . $GLOBALS['network_form_name'] . '_networks_row', TRUE, $networkData);
1180 // If we have no rows, we don't need to display the edit form
1182 // Init array with generic element
1187 // Output main template
1188 loadTemplate('admin_' . $GLOBALS['network_form_name'] . '_networks', FALSE, $content);
1190 // Don't display the list/add new form
1191 $GLOBALS['network_display'] = FALSE;
1193 // Nothing selected/found
1194 loadTemplate('admin_settings_unsaved', FALSE, '{--ADMIN_NETWORK_NOTHING_FOUND--}');
1199 // Handle network type form
1200 function doAdminNetworkProcessHandleNetworkTypes () {
1201 // Is there selections?
1202 if (ifPostContainsSelections()) {
1203 // Load network data
1204 $networkData = getNetworkDataById(getRequestElement('network_id'));
1206 // Something has been selected, so start displaying one by one
1208 foreach (postRequestElement('sel') as $networkId => $sel) {
1209 // Is this selected?
1211 // Load this network's data
1212 $networkTypeData = getNetworkTypeDataById($networkId);
1214 // Is there found the network?
1215 if (count($networkTypeData) > 0) {
1216 if (isFormSent('edit')) {
1217 // Add row template for deleting
1218 $OUT .= loadTemplate('admin_edit_network_types_row', TRUE, $networkTypeData);
1219 } elseif (isFormSent('delete')) {
1220 // Add row template for deleting
1221 $OUT .= loadTemplate('admin_delete_network_types_row', TRUE, $networkTypeData);
1224 reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/delete.');
1230 // If we have no rows, we don't need to display the edit form
1232 // Prepare array with generic elements
1235 'network_id' => bigintval(getRequestElement('network_id'))
1238 // Output main template
1239 if (isFormSent('edit')) {
1240 loadTemplate('admin_edit_network_types', FALSE, $content);
1241 } elseif (isFormSent('delete')) {
1242 loadTemplate('admin_delete_network_types', FALSE, $content);
1245 reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/delete.');
1248 // Don't display the list/add new form
1249 $GLOBALS['network_display'] = FALSE;
1251 // Nothing selected/found
1252 loadTemplate('admin_settings_unsaved', FALSE, '{--ADMIN_NETWORK_TYPE_HANDLER_NOTHING_FOUND--}');
1257 // Handle network request parameter form
1258 function doAdminNetworkProcessHandleRequestParams () {
1259 // Is there selections?
1260 if (ifPostContainsSelections()) {
1262 $GLOBALS['network_request_params_disabled'] = array();
1264 // Load network data
1265 $networkData = getNetworkDataById(getRequestElement('network_id'));
1267 // Something has been selected, so start displaying one by one
1269 foreach (postRequestElement('sel') as $networkId => $sel) {
1270 // Is this selected?
1272 // Load this network's data
1273 $networkRequestData = getNetworkRequestParamsDataById($networkId);
1275 // Is there found the network?
1276 if (count($networkRequestData) > 0) {
1277 if (isFormSent('edit')) {
1278 // Add row template for deleting
1279 $OUT .= loadTemplate('admin_edit_network_request_params_row', TRUE, $networkRequestData);
1280 } elseif (isFormSent('delete')) {
1282 $networkRequestData['network_type_data'] = getNetworkTypeDataById($networkRequestData['network_type_id']);
1284 // Add row template for deleting
1285 $OUT .= loadTemplate('admin_delete_network_request_params_row', TRUE, $networkRequestData);
1288 reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/delete.');
1294 // If we have no rows, we don't need to display the edit form
1296 // Prepare array with generic elements
1299 'network_id' => bigintval(getRequestElement('network_id'))
1302 // Output main template
1303 if (isFormSent('edit')) {
1304 loadTemplate('admin_edit_network_request_params', FALSE, $content);
1305 } elseif (isFormSent('delete')) {
1306 loadTemplate('admin_delete_network_request_params', FALSE, $content);
1309 reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/delete.');
1312 // Don't display the list/add new form
1313 $GLOBALS['network_display'] = FALSE;
1315 // Nothing selected/found
1316 loadTemplate('admin_settings_unsaved', FALSE, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_FOUND--}');
1321 // Changes given networks
1322 function doAdminNetworkProcessChangeNetworks () {
1323 // Is there selections?
1324 if (ifPostContainsSelections()) {
1325 // By default nothing is updated
1328 // Something has been selected, so start updating them
1329 foreach (postRequestElement('sel') as $networkId => $sel) {
1330 // Update this entry?
1333 $networkData = array();
1335 // Transfer whole array, except 'sel'
1336 foreach (postRequestArray() as $key => $entry) {
1337 // Skip 'sel' and submit button
1338 if (in_array($key, array('sel', 'do_edit'))) {
1342 // Is there this enty?
1343 if (!isset($entry[$networkId])) {
1344 // Not found, needs fixing
1345 reportBug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1349 $networkData[$key] = $entry[$networkId];
1352 // Update the network data
1353 $updated += doNetworkUpdateDataByArray($networkId, $networkData);
1357 // Is there updates?
1360 displayMessage('{%message,ADMIN_NETWORK_UPDATED=' . $updated . '%}');
1363 loadTemplate('admin_settings_unsaved', FALSE, '{--ADMIN_NETWORK_NOTHING_CHANGED--}');
1368 // Removes given networks
1369 function doAdminNetworkProcessRemoveNetworks () {
1370 // Is there selections?
1371 if (ifPostContainsSelections()) {
1372 // By default nothing is removed
1375 // Something has been selected, so start updating them
1376 foreach (postRequestElement('sel') as $networkId => $sel) {
1377 // Update this entry?
1379 // Remove this entry
1380 $removed += doAdminRemoveNetworkEntry('data', 'network_id', $networkId);
1384 // Is there removes?
1387 displayMessage('{%message,ADMIN_NETWORK_REMOVED=' . $removed . '%}');
1390 loadTemplate('admin_settings_unsaved', FALSE, '{--ADMIN_NETWORK_NOTHING_REMOVED--}');
1395 // Add a network type handler if not yet found
1396 function doAdminNetworkProcessAddNetworkType () {
1397 // Is the network type handle already used with given network?
1398 if (isNetworkTypeHandleValid(postRequestElement('network_type_handler'), getRequestElement('network_id'))) {
1400 loadTemplate('admin_settings_unsaved', FALSE, '{%message,ADMIN_NETWORK_TYPE_HANDLER_ALREADY_ADDED=' . postRequestElement('network_type_handler') . '%}');
1402 // ... so abort here
1407 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1409 // Is network_type_banner_url set?
1410 if (!isPostRequestElementSet('network_type_banner_url')) {
1411 // Remove empty value to get a NULL for an optional entry
1412 unsetPostRequestElement('network_type_banner_url');
1415 // Add the whole request to database
1416 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_types'), __FUNCTION__, __LINE__);
1419 if (!SQL_HASZEROAFFECTED()) {
1420 // Successfully added
1421 loadTemplate('admin_network_type_added', FALSE, postRequestArray());
1424 loadTemplate('admin_settings_unsaved', FALSE, '{%message,ADMIN_NETWORK_TYPE_HANDLER_NOT_ADDED=' . postRequestElement('network_type_handler') . '%}');
1428 // Changes given network type handlers
1429 function doAdminNetworkProcessChangeHandlerTypes () {
1430 // Is there selections?
1431 if (ifPostContainsSelections()) {
1432 // By default nothing is updated
1435 // Something has been selected, so start updating them
1436 foreach (postRequestElement('sel') as $networkId => $sel) {
1437 // Update this entry?
1440 $networkTypeData = array();
1442 // Transfer whole array, except 'sel'
1443 foreach (postRequestArray() as $key => $entry) {
1444 // Skip 'sel' and submit button
1445 if (in_array($key, array('sel', 'do_edit'))) {
1449 // Is there this enty?
1450 if (!isset($entry[$networkId])) {
1451 // Not found, needs fixing
1452 reportBug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1455 // Fix empty network_type_banner_url to NULL
1456 if (($key == 'network_type_banner_url') && (trim($entry[$networkId]) == '')) {
1458 $entry[$networkId] = NULL;
1462 $networkTypeData[$key] = $entry[$networkId];
1465 // Update the network data
1466 $updated += doNetworkUpdateTypeByArray($networkId, $networkTypeData);
1470 // Is there updates?
1473 displayMessage('{%message,ADMIN_NETWORK_TYPE_HANDLER_UPDATED=' . $updated . '%}');
1476 loadTemplate('admin_settings_unsaved', FALSE, '{--ADMIN_NETWORK_TYPE_HANDLER_NOTHING_CHANGED--}');
1481 // Changes given network request parameters
1482 function doAdminNetworkProcessChangeRequestParams () {
1483 // Is there selections?
1484 if (ifPostContainsSelections()) {
1485 // By default nothing is updated
1488 // Something has been selected, so start updating them
1489 foreach (postRequestElement('sel') as $networkId => $sel) {
1490 // Update this entry?
1493 $networkParamsData = array();
1495 // Transfer whole array, except 'sel'
1496 foreach (postRequestArray() as $key => $entry) {
1497 // Skip 'sel' and submit button
1498 if (in_array($key, array('sel', 'do_edit'))) {
1502 // Is there this enty?
1503 if (!isset($entry[$networkId])) {
1504 // Not found, needs fixing
1505 reportBug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1508 // Fix empty network_request_param_default to NULL
1509 if (($key == 'network_request_param_default') && (trim($entry[$networkId]) == '')) {
1511 $entry[$networkId] = NULL;
1515 $networkParamsData[$key] = $entry[$networkId];
1518 // Update the network data
1519 $updated += doNetworkUpdateParamsByArray($networkId, $networkParamsData);
1523 // Is there updates?
1526 displayMessage('{%message,ADMIN_NETWORK_REQUEST_PARAMETER_UPDATED=' . $updated . '%}');
1529 loadTemplate('admin_settings_unsaved', FALSE, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_CHANGED--}');
1534 // Changes given network array translations
1535 function doAdminNetworkProcessChangeArrayTranslations () {
1536 // Is there selections?
1537 if (ifPostContainsSelections()) {
1538 // By default nothing is updated
1541 // Something has been selected, so start updating them
1542 foreach (postRequestElement('sel') as $networkId => $sel) {
1543 // Update this entry?
1546 $networkTranslationsData = array();
1548 // Transfer whole array, except 'sel'
1549 foreach (postRequestArray() as $key => $entry) {
1550 // Skip 'sel' and submit button
1551 if (in_array($key, array('sel', 'do_edit'))) {
1555 // Is there this enty?
1556 if (!isset($entry[$networkId])) {
1557 // Not found, needs fixing
1558 reportBug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1561 // Fix empty network_request_param_default to NULL
1562 if (($key == 'network_request_param_default') && (trim($entry[$networkId]) == '')) {
1564 $entry[$networkId] = NULL;
1568 $networkTranslationsData[$key] = $entry[$networkId];
1571 // Update the network data
1572 $updated += doNetworkUpdateArrayTranslationsByArray($networkId, $networkTranslationsData);
1576 // Is there updates?
1579 displayMessage('{%message,ADMIN_NETWORK_ARRAY_TRANSLATION_UPDATED=' . $updated . '%}');
1582 loadTemplate('admin_settings_unsaved', FALSE, '{--ADMIN_NETWORK_ARRAY_TRANSLATION_NOTHING_CHANGED--}');
1587 // Removes given network type handlers
1588 function doAdminNetworkProcessRemoveNetworkTypes () {
1589 // Is there selections?
1590 if (ifPostContainsSelections()) {
1591 // By default nothing is removed
1594 // Something has been selected, so start updating them
1595 foreach (postRequestElement('sel') as $networkId => $sel) {
1596 // Update this entry?
1598 // Remove this entry
1599 $removed += doAdminRemoveNetworkEntry('types', 'network_type_id', $networkId);
1603 // Is there removes?
1606 displayMessage('{%message,ADMIN_NETWORK_TYPE_HANDLER_REMOVED=' . $removed . '%}');
1609 loadTemplate('admin_settings_unsaved', FALSE, '{--ADMIN_NETWORK_TYPE_HANDLER_NOTHING_REMOVED--}');
1614 // Removes given network request parameters
1615 function doAdminNetworkProcessRemoveNetworkRequestParams () {
1616 // Is there selections?
1617 if (ifPostContainsSelections()) {
1618 // By default nothing is removed
1621 // Something has been selected, so start updating them
1622 foreach (postRequestElement('sel') as $networkId => $sel) {
1623 // Update this entry?
1625 // Remove this entry
1626 $removed += doAdminRemoveNetworkEntry('request_params', 'network_request_param_id', $networkId);
1630 // Is there removes?
1633 displayMessage('{%message,ADMIN_NETWORK_REQUEST_PARAMETER_REMOVED=' . $removed . '%}');
1636 loadTemplate('admin_settings_unsaved', FALSE, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_REMOVED--}');
1641 // Removes given network array translations
1642 function doAdminNetworkProcessRemoveNetworkArrayTranslation () {
1643 // Is there selections?
1644 if (ifPostContainsSelections()) {
1645 // By default nothing is removed
1648 // Something has been selected, so start updating them
1649 foreach (postRequestElement('sel') as $networkId => $sel) {
1650 // Update this entry?
1652 // Remove this entry
1653 $removed += doAdminRemoveNetworkEntry('array_translation', 'network_array_id', $networkId);
1657 // Is there removes?
1660 displayMessage('{%message,ADMIN_NETWORK_ARRAY_TRANSLATION_REMOVED=' . $removed . '%}');
1663 loadTemplate('admin_settings_unsaved', FALSE, '{--ADMIN_NETWORK_ARRAY_TRANSLATION_NOTHING_REMOVED--}');
1668 // Adds a request parameter to given network and type
1669 function doAdminNetworkProcessAddRequestParam () {
1670 // Is the request parameter already used with given network?
1671 if (isNetworkRequestElementValid(postRequestElement('network_request_param_key'), postRequestElement('network_type_id'), getRequestElement('network_id'))) {
1673 loadTemplate('admin_settings_unsaved', FALSE, '{%message,ADMIN_NETWORK_REQUEST_PARAMETER_ALREADY_ADDED=' . postRequestElement('network_request_param_key') . '%}');
1675 // ... so abort here
1680 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1682 // Is network_request_param_default set?
1683 if (!isPostRequestElementSet('network_request_param_default')) {
1684 // Remove empty value to get a NULL for an optional entry
1685 unsetPostRequestElement('network_request_param_default');
1688 // Add the whole request to database
1689 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_request_params'), __FUNCTION__, __LINE__);
1692 if (!SQL_HASZEROAFFECTED()) {
1693 // Successfully added
1694 loadTemplate('admin_network_request_param_added', FALSE, postRequestArray());
1697 loadTemplate('admin_settings_unsaved', FALSE, '{%message,ADMIN_NETWORK_REQUEST_PARAMETER_NOT_ADDED=' . postRequestElement('network_request_param_key') . '%}');
1701 // Adds a vheck request parameter to given network
1702 function doAdminNetworkProcessAddVcheckParam () {
1703 // Is the request parameter already used with given network?
1704 if (isNetworkVcheckElementValid(postRequestElement('network_vcheck_param_key'), getRequestElement('network_id'))) {
1706 loadTemplate('admin_settings_unsaved', FALSE, '{%message,ADMIN_NETWORK_VCHECK_PARAMETER_ALREADY_ADDED=' . postRequestElement('network_vcheck_param_key') . '%}');
1708 // ... so abort here
1713 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1715 // Is network_vcheck_param_default set?
1716 if (!isPostRequestElementSet('network_vcheck_param_default')) {
1717 // Remove empty value to get a NULL for an optional entry
1718 unsetPostRequestElement('network_vcheck_param_default');
1721 // Add the whole vcheck to database
1722 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_vcheck_params'), __FUNCTION__, __LINE__);
1725 if (!SQL_HASZEROAFFECTED()) {
1726 // Successfully added
1727 loadTemplate('admin_network_vcheck_param_added', FALSE, postRequestArray());
1730 loadTemplate('admin_settings_unsaved', FALSE, '{%message,ADMIN_NETWORK_VCHECK_PARAMETER_NOT_ADDED=' . postRequestElement('network_vcheck_param_key') . '%}');
1734 // Adds a API response array entry
1735 function doAdminNetworkProcessAddNetworkArrayTranslation () {
1736 // Is the request parameter already used with given network?
1737 if (isNetworkArrayTranslationValid(postRequestElement('network_array_index'), postRequestElement('network_type_id'), getRequestElement('network_id'))) {
1739 loadTemplate('admin_settings_unsaved', FALSE, '{%message,ADMIN_NETWORK_ARRAY_TRANSLATION_ALREADY_ADDED=' . postRequestElement('network_array_index') . '%}');
1741 // ... so abort here
1746 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1749 setPostRequestElement('network_array_sort', (countSumTotalData(
1750 bigintval(postRequestElement('network_id')),
1751 'network_array_translation',
1755 sprintf(" AND `network_type_id`=%s", bigintval(postRequestElement('network_type_id')))
1758 // Add the whole request to database
1759 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_array_translation'), __FUNCTION__, __LINE__);
1762 if (!SQL_HASZEROAFFECTED()) {
1763 // Successfully added
1764 loadTemplate('admin_network_array_translation_added', FALSE, postRequestArray());
1767 loadTemplate('admin_settings_unsaved', FALSE, '{%message,ADMIN_NETWORK_ARRAY_TRANSLATION_NOT_ADDED=' . postRequestElement('network_array_index') . '%}');
1771 // Handle network array translation form
1772 function doAdminNetworkProcessHandleArrayTranslations () {
1773 // Is there selections?
1774 if (ifPostContainsSelections()) {
1776 $GLOBALS['network_array_translation_disabled'] = array();
1778 // Load network data
1779 $networkData = getNetworkDataById(getRequestElement('network_id'));
1781 // Something has been selected, so start displaying one by one
1783 foreach (postRequestElement('sel') as $networkId => $sel) {
1784 // Is this selected?
1786 // Load this network's data
1787 $networkTranslationsData = getNetworkArrayTranslationsDataById($networkId);
1789 // Is there found the network?
1790 if (count($networkTranslationsData) > 0) {
1791 if (isFormSent('edit')) {
1792 // Add row template for deleting
1793 $OUT .= loadTemplate('admin_edit_network_array_translation_row', TRUE, $networkTranslationsData);
1794 } elseif (isFormSent('delete')) {
1796 $networkTranslationsData['network_type_data'] = getNetworkTypeDataById($networkTranslationsData['network_type_id']);
1798 // Add row template for deleting
1799 $OUT .= loadTemplate('admin_delete_network_array_translation_row', TRUE, $networkTranslationsData);
1802 reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/delete.');
1808 // If we have no rows, we don't need to display the edit form
1810 // Prepare array with generic elements
1813 'network_id' => bigintval(getRequestElement('network_id'))
1816 // Output main template
1817 if (isFormSent('edit')) {
1818 loadTemplate('admin_edit_network_array_translation', FALSE, $content);
1819 } elseif (isFormSent('delete')) {
1820 loadTemplate('admin_delete_network_array_translation', FALSE, $content);
1823 reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/delete.');
1826 // Don't display the list/add new form
1827 $GLOBALS['network_display'] = FALSE;
1829 // Nothing selected/found
1830 loadTemplate('admin_settings_unsaved', FALSE, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_FOUND--}');
1835 // Adds/update network API configuration
1836 function doAdminNetworkProcessNetworkApiConfig () {
1838 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1840 // Is network_api_referral_button set?
1841 if (!isPostRequestElementSet('network_api_referral_button')) {
1842 // Remove empty value to get a NULL for an optional entry
1843 unsetPostRequestElement('network_api_referral_button');
1846 // Is there already an entry?
1847 if (isNetworkApiConfigured(getRequestElement('network_id'))) {
1848 // Generate SQL query
1849 $SQL = getUpdateSqlFromArray(postRequestArray(), 'network_api_config', 'network_id', postRequestElement('network_id'), array('network_id'));
1852 $SQL = getInsertSqlFromArray(postRequestArray(), 'network_api_config');
1856 SQL_QUERY($SQL, __FUNCTION__, __LINE__);
1859 if (!SQL_HASZEROAFFECTED()) {
1860 // Successfully added
1861 displayMessage('{--ADMIN_CONFIG_NETWORK_API_SAVED--}');
1864 loadTemplate('admin_settings_unsaved', FALSE, '{--ADMIN_CONFIG_NETWORK_API_NOT_SAVED--}');
1868 // Only adds network type configuration if not yet present
1869 function doAdminNetworkProcessAddHandlerTypesConfig ($displayMessage = TRUE) {
1871 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1872 setPostRequestElement('network_type_id', bigintval(getRequestElement('network_type_id')));
1874 // Translate German comma to dot
1875 setPostRequestElement('network_min_payment', convertCommaToDot(postRequestElement('network_min_payment')));
1878 * Some parameters are optional, at least one must be given so check a bunch
1881 foreach (array('network_min_waiting_time', 'network_min_remain_clicks', 'network_min_payment', 'network_allow_erotic') as $element) {
1882 // Is this element empty?
1883 if (!isPostRequestElementSet($element)) {
1884 // Then unset it to get a NULL for optional parameter
1885 unsetPostRequestElement($element);
1889 // Convert data in POST array
1890 convertSelectionsToEpocheTimeInPostData('network_max_reload_time_ye');
1892 // Is there already an entry?
1893 if (isNetworkTypeHandlerConfigured(getRequestElement('network_id'), getRequestElement('network_type_id'))) {
1894 // This network type handler is already configured
1895 displayMessage('{--ADMIN_NETWORK_HANDLER_TYPE_HANDLER_ALREADY_CONFIGURED--}');
1899 // Copy 'set all' and remove it from POST data
1900 $setAll = (postRequestElement('set_all') === 'Y');
1901 unsetPostRequestElement('set_all');
1903 // Shall we set for all?
1904 if ($setAll === TRUE) {
1906 $result = SQL_QUERY_ESC('SELECT `network_type_id` FROM `{?_MYSQL_PREFIX?}_network_types` WHERE `network_id`=%s ORDER BY `network_type_id` ASC',
1907 array(bigintval(getRequestElement('network_id'))), __FUNCTION__, __LINE__);
1909 // Are there entries?
1910 if (SQL_HASZERONUMS($result)) {
1911 // No, then abort here
1912 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_SET_ALL_404--}');
1916 // Init number of rows
1920 while (list($typeId) = SQL_FETCHROW($result)) {
1921 // Set it in GET data
1922 setGetRequestElement('network_type_id', $typeId);
1924 // Call this function again
1925 $numRows += doAdminNetworkProcessAddHandlerTypesConfig(FALSE);
1929 SQL_FREERESULT($result);
1933 // Something has been updated
1934 displayMessage('{%message,ADMIN_CONFIG_NETWORK_HANDLER_TYPE_ALL_HANDLER_SAVED=' . bigintval($numRows) . '%}');
1936 // Nothing has been saved
1937 loadTemplate('admin_settings_unsaved', FALSE, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}');
1940 // Get SQL query for new entry
1941 $SQL = getInsertSqlFromArray(postRequestArray(), 'network_types_config');
1944 SQL_QUERY($SQL, __FUNCTION__, __LINE__);
1946 // Shall we display the message?
1947 if ($displayMessage === TRUE) {
1949 if (!SQL_HASZEROAFFECTED()) {
1950 // Successfully added
1951 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_SAVED--}');
1954 loadTemplate('admin_settings_unsaved', FALSE, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_SAVED--}');
1957 // Return amount of affected rows (1 or 2)
1958 return SQL_AFFECTEDROWS();
1963 // Only changes network type configuration if not yet present
1964 function doAdminNetworkProcessEditHandlerTypesConfig ($displayMessage = TRUE) {
1966 * Some parameters are optional, at least one must be given so check a bunch
1969 foreach (array('network_min_waiting_time', 'network_min_remain_clicks', 'network_min_payment', 'network_allow_erotic') as $element) {
1970 // Is this element empty?
1971 if (!isPostRequestElementSet($element)) {
1972 // Then unset it to get a NULL for optional parameter
1973 unsetPostRequestElement($element);
1977 // Convert time selections in POST data
1978 convertSelectionsToEpocheTimeInPostData('network_max_reload_time_ye');
1980 // Is there already an entry?
1981 if (!isNetworkTypeHandlerConfigured(getRequestElement('network_id'), getRequestElement('network_type_id'))) {
1982 // This network type handler is not configured
1983 displayMessage('{--ADMIN_NETWORK_HANDLER_TYPE_HANDLER_NOT_CONFIGURED--}');
1987 // Copy 'set all' and remove it from POST data
1988 $setAll = (postRequestElement('set_all') === 'Y');
1989 unsetPostRequestElement('set_all');
1991 // Shall we set for all?
1992 if ($setAll === TRUE) {
1993 // Get all data entries
1994 $result = SQL_QUERY_ESC('SELECT `network_data_id` FROM `{?_MYSQL_PREFIX?}_network_types_config` WHERE `network_id`=%s ORDER BY `network_type_id` ASC',
1995 array(bigintval(getRequestElement('network_id'))), __FUNCTION__, __LINE__);
1997 // Are there entries?
1998 if (SQL_HASZERONUMS($result)) {
1999 // No, then abort here
2000 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_SET_ALL_404--}');
2004 // Init number of rows
2008 while (list($dataId) = SQL_FETCHROW($result)) {
2009 // Set it in GET data
2010 setPostRequestElement('network_data_id', $dataId);
2012 // Call this function again
2013 $numRows += doAdminNetworkProcessEditHandlerTypesConfig(FALSE);
2017 SQL_FREERESULT($result);
2021 // Something has been updated
2022 displayMessage('{%message,ADMIN_CONFIG_NETWORK_HANDLER_TYPE_ALL_HANDLER_SAVED=' . bigintval($numRows) . '%}');
2024 // Nothing has been saved
2025 loadTemplate('admin_settings_unsaved', FALSE, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}');
2028 // Get SQL query for new entry
2029 $SQL = getUpdateSqlFromArray(postRequestArray(), 'network_types_config', 'network_data_id', postRequestElement('network_data_id'), array('network_data_id'));
2032 SQL_QUERY($SQL, __FUNCTION__, __LINE__);
2034 // Shall we display the message?
2035 if ($displayMessage === TRUE) {
2037 if (!SQL_HASZEROAFFECTED()) {
2038 // Successfully added
2039 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_SAVED--}');
2042 loadTemplate('admin_settings_unsaved', FALSE, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}');
2045 // Return amount of affected rows (1 or 2)
2046 return SQL_AFFECTEDROWS();
2051 // Do expression code for this extension
2052 function doExpressionNetwork ($data) {
2053 // Construct replacer
2054 $replacer = sprintf(
2055 "{DQUOTE} . %s(%s, '%s') . {DQUOTE}",
2057 $data['matches'][4][$data['key']],
2061 // Replace %network_id% with the current network id
2062 $replacer = str_replace('%network_id%', getCurrentNetworkId(), $replacer);
2065 $code = replaceExpressionCode($data, $replacer);
2071 // ----------------------------------------------------------------------------
2072 // Call-back functions for exporting data
2073 // ----------------------------------------------------------------------------
2075 // Callback function to export network tables
2076 function doAdminNetworkProcessExport () {
2077 // Init table with all valid what->table entries
2078 $validExports = array(
2079 // General network data
2080 'list_network_data' => 'data',
2081 // Network type handler
2082 'list_network_types' => 'types',
2083 // Network request parameter
2084 'list_network_request_params' => 'request_params',
2085 // Vcheck request parameter
2086 'list_network_vcheck_params' => 'vcheck_params',
2087 // Network API response array index translation
2088 'list_network_array_translation' => 'array_translation',
2091 // Is the 'what' key valid?
2092 if (!isset($validExports[getWhat()])) {
2094 reportBug(__FUNCTION__, __LINE__, 'what=' . getWhat() . ' - not supported');
2097 // Generate call-back, some tables require to export not all columns
2098 $callbackName = 'doAdminNetworkExport' . capitalizeUnderscoreString($validExports[getWhat()]);
2100 // Is the call-back function there?
2101 if (!function_exists($callbackName)) {
2102 // No, this is really bad
2103 reportBug(__FUNCTION__, __LINE__, 'Invalid call-back function ' . $callbackName . ' detected.');
2104 } elseif (isset($GLOBALS[__FUNCTION__][$callbackName])) {
2106 reportBug(__FUNCTION__, __LINE__, 'Double-call of export function ' . $callbackName . ' detected.');
2109 // Call the function
2110 call_user_func($callbackName);
2112 // Mark it as called
2113 $GLOBALS[__FUNCTION__][$callbackName] = TRUE;
2115 // Don't display the list/add new form
2116 $GLOBALS['network_display'] = FALSE;
2119 // Exports (and displays) the table 'network_data'
2120 function doAdminNetworkExportData () {
2121 // Query for all networks
2122 $result = SQL_QUERY('SELECT
2123 `network_short_name`,
2126 `network_data_separator`,
2127 `network_row_separator`,
2128 `network_request_type`,
2130 `network_require_id_card`,
2131 `network_query_amount`,
2134 `{?_MYSQL_PREFIX?}_network_data`
2137 __FUNCTION__, __LINE__);
2139 // Start an empty SQL query
2140 $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";
2143 while ($content = SQL_FETCHARRAY($result)) {
2146 $content['network_short_name'] . "', '" .
2147 $content['network_title'] . "', '" .
2148 $content['network_reflink'] . "', '" .
2149 $content['network_data_separator'] . "', '" .
2150 $content['network_row_separator'] . "', '" .
2151 $content['network_request_type'] . "', '" .
2152 $content['network_charset'] . "', '" .
2153 $content['network_require_id_card'] . "', " .
2154 $content['network_query_amount'] . ", '" .
2155 $content['network_active'] . "'),\n";
2158 // Remove last commata and close braces
2159 $SQL = substr($SQL, 0, -2);
2162 SQL_FREERESULT($result);
2164 // Output the SQL query
2165 loadTemplate('admin_export_network_data', FALSE, $SQL);
2168 // Exports (and displays) the table 'network_types'
2169 function doAdminNetworkExportTypes () {
2170 // 'network_id' must be set
2171 if (!isGetRequestElementSet('network_id')) {
2172 // Only network handlers of one network will be exported per time
2173 reportBug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
2176 // Get all network types of given network
2177 $result = SQL_QUERY_ESC('SELECT
2180 `network_type_handler`,
2181 `network_type_api_url`,
2182 `network_type_click_url`,
2183 `network_type_banner_url`,
2184 `network_type_reload_time_unit`,
2185 `network_text_encoding`
2187 `{?_MYSQL_PREFIX?}_network_types`
2191 `network_type_id` ASC',
2193 bigintval(getRequestElement('network_id'))
2194 ), __FUNCTION__, __LINE__);
2196 // Start an empty SQL query
2197 $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";
2200 while ($content = SQL_FETCHARRAY($result)) {
2203 $content['network_type_id'] . ', ' .
2204 $content['network_id'] . ", '" .
2205 $content['network_type_handler'] . "', '" .
2206 $content['network_type_api_url'] . "', '" .
2207 $content['network_type_click_url'] . "', ";
2209 // Is the column NULL?
2210 if (is_null($content['network_type_banner_url'])) {
2215 $SQL .= chr(39) . $content['network_type_banner_url'] . chr(39);
2219 $SQL .= ",'" . $content['network_type_reload_time_unit'] . "','" . $content['network_text_encoding'] . "'),\n";
2222 // Remove last commata and close braces
2223 $SQL = substr($SQL, 0, -2);
2226 SQL_FREERESULT($result);
2228 // Output the SQL query
2229 loadTemplate('admin_export_network_types', FALSE, $SQL);
2232 // Exports (and displays) the table 'network_request_params'
2233 function doAdminNetworkExportRequestParams () {
2234 // 'network_id' must be set
2235 if (!isGetRequestElementSet('network_id')) {
2236 // Only network request parameters of one network will be exported per time
2237 reportBug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
2240 // Get all network types of given network
2241 $result = SQL_QUERY_ESC('SELECT
2244 `network_request_param_key`,
2245 `network_request_param_value`,
2246 `network_request_param_default`
2248 `{?_MYSQL_PREFIX?}_network_request_params`
2252 `network_type_id` ASC ,
2253 `network_request_param_id` ASC',
2255 bigintval(getRequestElement('network_id'))
2256 ), __FUNCTION__, __LINE__);
2258 // Start an empty SQL query
2259 $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";
2262 while ($content = SQL_FETCHARRAY($result)) {
2265 $content['network_id'] . ', ' .
2266 $content['network_type_id'] . ", '" .
2267 $content['network_request_param_key'] . "', '" .
2268 $content['network_request_param_value'] . "', ";
2270 // Is the column NULL?
2271 if (is_null($content['network_request_param_default'])) {
2276 $SQL .= chr(39) . $content['network_request_param_default'] . "'),\n";
2280 // Remove last commata and close braces
2281 $SQL = substr($SQL, 0, -2);
2284 SQL_FREERESULT($result);
2286 // Output the SQL query
2287 loadTemplate('admin_export_network_request_params', FALSE, $SQL);
2290 // Exports (and displays) the table 'network_vcheck_params'
2291 function doAdminNetworkExportVcheckParams () {
2292 // 'network_id' must be set
2293 if (!isGetRequestElementSet('network_id')) {
2294 // Only network vcheck parameters of one network will be exported per time
2295 reportBug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
2298 // Get all network types of given network
2299 $result = SQL_QUERY_ESC('SELECT
2301 `network_vcheck_param_key`,
2302 `network_vcheck_param_value`,
2303 `network_vcheck_param_default`
2305 `{?_MYSQL_PREFIX?}_network_vcheck_params`
2309 `network_vcheck_param_id` ASC',
2311 bigintval(getRequestElement('network_id'))
2312 ), __FUNCTION__, __LINE__);
2314 // Start an empty SQL query
2315 $SQL = "INSERT INTO `{?_MYSQL_PREFIX?}_network_vcheck_params` (`network_id`, `network_vcheck_param_key`, `network_vcheck_param_value`, `network_vcheck_param_default`) VALUES\n";
2318 while ($content = SQL_FETCHARRAY($result)) {
2321 $content['network_id'] . ", '" .
2322 $content['network_vcheck_param_key'] . "', '" .
2323 $content['network_vcheck_param_value'] . "', ";
2325 // Is the column NULL?
2326 if (is_null($content['network_vcheck_param_default'])) {
2331 $SQL .= chr(39) . $content['network_vcheck_param_default'] . "'),\n";
2335 // Remove last commata and close braces
2336 $SQL = substr($SQL, 0, -2);
2339 SQL_FREERESULT($result);
2341 // Output the SQL query
2342 loadTemplate('admin_export_network_vcheck_params', FALSE, $SQL);
2345 // Exports (and displays) the table 'network_array_translation'
2346 function doAdminNetworkExportArrayTranslation () {
2347 // 'network_id' must be set
2348 if (!isGetRequestElementSet('network_id')) {
2349 // Only network API array index translations of one network will be exported per time
2350 reportBug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
2353 // Get all network types of given network
2354 $result = SQL_QUERY_ESC('SELECT
2357 `network_array_index`,
2358 `network_array_sort`
2360 `{?_MYSQL_PREFIX?}_network_array_translation`
2364 `network_type_id` ASC,
2365 `network_array_sort` ASC',
2367 bigintval(getRequestElement('network_id'))
2368 ), __FUNCTION__, __LINE__);
2370 // Start an empty SQL query
2371 $SQL = "INSERT INTO `{?_MYSQL_PREFIX?}_network_array_translation` (`network_id`, `network_type_id`, `network_array_index`, `network_array_sort`) VALUES\n";
2374 while ($content = SQL_FETCHARRAY($result)) {
2377 $content['network_id'] . ', ' .
2378 $content['network_type_id'] . ', ' .
2379 $content['network_array_index'] . ', ' .
2380 $content['network_array_sort'] . "),\n";
2383 // Remove last commata and close braces
2384 $SQL = substr($SQL, 0, -2);
2387 SQL_FREERESULT($result);
2389 // Output the SQL query
2390 loadTemplate('admin_export_network_array_translation', FALSE, $SQL);