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 if (!isset($GLOBALS[__FUNCTION__][$name])) {
121 $GLOBALS[__FUNCTION__][$name] = (countSumTotalData($name, 'network_data', 'network_id', 'network_short_name', TRUE) == 1);
125 return $GLOBALS[__FUNCTION__][$name];
128 // Checks whether the (short) named network is activated
129 function isNetworkActiveByShortName ($name) {
131 if (!isset($GLOBALS[__FUNCTION__][$name])) {
133 $GLOBALS[__FUNCTION__][$name] = ((isNetworkNameValid($name)) && (countSumTotalData($name, 'network_data', 'network_id', 'network_short_name', TRUE, " AND `network_active`='Y'") == 1));
137 return $GLOBALS[__FUNCTION__][$name];
140 // Checks whether the network by given id is activated
141 function isNetworkActiveById ($networkId) {
143 if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
145 $GLOBALS[__FUNCTION__][$networkId] = (countSumTotalData(bigintval($networkId), 'network_data', 'network_id', 'network_id', TRUE, " AND `network_active`='Y'") == 1);
149 return $GLOBALS[__FUNCTION__][$networkId];
152 // "Getter" for 'network_activated' column depending on current administrator's expert setting
153 function getNetworkActivatedColumn ($whereAnd = 'WHERE', $table = '') {
155 if (!isset($GLOBALS[__FUNCTION__][$whereAnd][$table])) {
156 // Default is exclude deactivated networks
157 $GLOBALS[__FUNCTION__][$whereAnd][$table] = ' ' . $whereAnd . ' ' . $table . "`network_active`='Y'";
159 // Is the export setting on?
160 if (isAdminsExpertSettingEnabled()) {
161 // Then allow all networks
162 $GLOBALS[__FUNCTION__][$whereAnd][$table] = '';
167 return $GLOBALS[__FUNCTION__][$whereAnd][$table];
170 // Checks whether the given network type is already used (valid)
171 function isNetworkTypeHandleValid ($type, $networkId) {
173 $result = SQL_QUERY_ESC("SELECT `network_type_id` FROM `{?_MYSQL_PREFIX?}_network_types` WHERE `network_id`=%s AND `network_type_handler`='%s' LIMIT 1",
177 ), __FUNCTION__, __LINE__);
180 $isValid = (SQL_NUMROWS($result) == 1);
183 SQL_FREERESULT($result);
189 // Checks whether the given network request parameter is already used (valid)
190 function isNetworkRequestElementValid ($key, $type, $networkId) {
192 $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",
197 ), __FUNCTION__, __LINE__);
200 $isValid = (SQL_NUMROWS($result) == 1);
203 SQL_FREERESULT($result);
209 // Checks whether the given vcheck request parameter is already used (valid)
210 function isNetworkVcheckElementValid ($key, $networkId) {
212 $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",
216 ), __FUNCTION__, __LINE__);
219 $isValid = (SQL_NUMROWS($result) == 1);
222 SQL_FREERESULT($result);
228 // Checks whether the given network API array translation
229 function isNetworkArrayTranslationValid ($key, $type, $networkId) {
231 $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",
236 ), __FUNCTION__, __LINE__);
239 $isValid = (SQL_NUMROWS($result) == 1);
242 SQL_FREERESULT($result);
248 // "Getter" for a network's data by provided id number
249 function getNetworkDataById ($networkId, $column = '') {
250 // Ids lower one are not accepted
251 if ($networkId < 1) {
252 // Not good, should be fixed
253 reportBug(__FUNCTION__, __LINE__, 'Network id ' . $networkId . ' is smaller than 1.');
254 } elseif ((!isNetworkActiveById($networkId)) && (!isAdminsExpertSettingEnabled())) {
255 // Do not load inactive network data
256 reportBug(__FUNCTION__, __LINE__, 'Network id ' . $networkId . ' is not active.');
259 // Set current network id
260 setCurrentNetworkId($networkId);
263 if (!isset($GLOBALS['network_data'][$networkId])) {
264 // By default we have no data
265 $GLOBALS['network_data'][$networkId] = array();
267 // Query for the network data
268 $result = SQL_QUERY_ESC('SELECT
270 `network_short_name`,
273 `network_data_separator`,
274 `network_row_separator`,
275 `network_request_type`,
277 `network_require_id_card`,
278 `network_query_amount`
280 `{?_MYSQL_PREFIX?}_network_data`
284 array(bigintval($networkId)), __FUNCTION__, __LINE__);
286 // Is there an entry?
287 if (SQL_NUMROWS($result) == 1) {
289 $GLOBALS['network_data'][$networkId] = SQL_FETCHARRAY($result);
293 SQL_FREERESULT($result);
297 if ((empty($column)) && (isset($GLOBALS['network_data'][$networkId]))) {
299 return $GLOBALS['network_data'][$networkId];
300 } elseif (isset($GLOBALS['network_data'][$networkId][$column])) {
302 return $GLOBALS['network_data'][$networkId][$column];
309 // "Getter" for a network's data by provided type id number
310 function getNetworkDataByTypeId ($networkId, $column = '') {
311 // Ids lower one are not accepted
312 if ($networkId < 1) {
313 // Not good, should be fixed
314 reportBug(__FUNCTION__, __LINE__, 'Network type id ' . $networkId . ' is smaller than 1.');
315 } elseif ((!isNetworkActiveById($networkId)) && (!isAdminsExpertSettingEnabled())) {
316 // Do not load inactive network data
317 reportBug(__FUNCTION__, __LINE__, 'Network id ' . $networkId . ' is not active.');
320 // Set current network id
321 setCurrentNetworkId($networkId);
324 if (!isset($GLOBALS['network_data'][$networkId])) {
325 // By default we have no data
326 $GLOBALS['network_data'][$networkId] = array();
328 // Query for the network data
329 $result = SQL_QUERY_ESC('SELECT
331 d.`network_short_name`,
334 d.`network_data_separator`,
335 d.`network_row_separator`,
336 d.`network_request_type`,
338 d.`network_require_id_card`,
339 d.`network_query_amount`,
340 t.`network_type_handler`,
341 t.`network_type_api_url`,
342 t.`network_type_click_url`,
343 t.`network_type_banner_url`,
344 t.`network_text_encoding`
346 `{?_MYSQL_PREFIX?}_network_data` AS d
348 `{?_MYSQL_PREFIX?}_network_types` AS t
350 d.`network_id`=t.`network_id`
352 t.`network_type_id`=%s
354 array(bigintval($networkId)), __FUNCTION__, __LINE__);
356 // Is there an entry?
357 if (SQL_NUMROWS($result) == 1) {
359 $GLOBALS['network_data'][$networkId] = SQL_FETCHARRAY($result);
363 SQL_FREERESULT($result);
367 if (empty($column)) {
369 return $GLOBALS['network_data'][$networkId];
372 return $GLOBALS['network_data'][$networkId][$column];
376 // "Getter" for a network type data by provided id number
377 function getNetworkTypeDataById ($networkTypeId) {
378 // Ids lower one are not accepted
379 if ($networkTypeId < 1) {
380 // Not good, should be fixed
381 reportBug(__FUNCTION__, __LINE__, 'Network type id ' . $networkTypeId . ' is smaller than 1.');
384 // By default we have no data
385 $GLOBALS['network_type_data'][$networkTypeId] = array();
387 // Query for the network data
388 $result = SQL_QUERY_ESC('SELECT
391 `network_type_handler`,
392 `network_type_api_url`,
393 `network_type_click_url`,
394 `network_type_banner_url`
396 `{?_MYSQL_PREFIX?}_network_types`
400 array(bigintval($networkTypeId)), __FUNCTION__, __LINE__);
402 // Is there an entry?
403 if (SQL_NUMROWS($result) == 1) {
405 $GLOBALS['network_type_data'][$networkTypeId] = SQL_FETCHARRAY($result);
409 SQL_FREERESULT($result);
412 return $GLOBALS['network_type_data'][$networkTypeId];
415 // "Getter" for a network request parameter data by provided id number
416 function getNetworkRequestParamsDataById ($networkRequestId) {
417 // Ids lower one are not accepted
418 if ($networkRequestId < 1) {
419 // Not good, should be fixed
420 reportBug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $networkRequestId . ' is smaller than 1.');
423 // By default we have no data
424 $networkRequestData = array();
426 // Query for the network data
427 $result = SQL_QUERY_ESC('SELECT
428 `network_request_param_id`,
431 `network_request_param_key`,
432 `network_request_param_value`,
433 `network_request_param_default`
435 `{?_MYSQL_PREFIX?}_network_request_params`
437 `network_request_param_id`=%s
439 array(bigintval($networkRequestId)), __FUNCTION__, __LINE__);
441 // Is there an entry?
442 if (SQL_NUMROWS($result) == 1) {
444 $networkRequestData = SQL_FETCHARRAY($result);
448 SQL_FREERESULT($result);
451 return $networkRequestData;
454 // "Getter" for a network array translation data by provided id number
455 function getNetworkArrayTranslationsDataById ($networkTranslationId) {
456 // Ids lower one are not accepted
457 if ($networkTranslationId < 1) {
458 // Not good, should be fixed
459 reportBug(__FUNCTION__, __LINE__, 'Network array translation id ' . $networkTranslationId . ' is smaller than 1.');
462 // By default we have no data
463 $networkTranslationData = array();
465 // Query for the network data
466 $result = SQL_QUERY_ESC('SELECT
470 `network_array_index`,
473 `{?_MYSQL_PREFIX?}_network_array_translation`
475 `network_array_id`=%s
477 array(bigintval($networkTranslationId)), __FUNCTION__, __LINE__);
479 // Is there an entry?
480 if (SQL_NUMROWS($result) == 1) {
482 $networkTranslationData = SQL_FETCHARRAY($result);
486 SQL_FREERESULT($result);
489 return $networkTranslationData;
492 // Updates given network (id) with data from array
493 function doNetworkUpdateDataByArray ($networkId, $networkData) {
494 // Ids lower one are not accepted
495 if ($networkId < 1) {
496 // Not good, should be fixed
497 reportBug(__FUNCTION__, __LINE__, 'Network id ' . $networkId . ' is smaller than 1.');
500 // Just call our inner method
501 return adminSaveSettings($networkData, '_network_data', sprintf("`network_id`=%s", bigintval($networkId)), array(), FALSE, FALSE);
504 // Updates given network type handler (id) with data from array
505 function doNetworkUpdateTypeByArray ($networkTypeId, $networkTypeData) {
506 // Ids lower one are not accepted
507 if ($networkTypeId < 1) {
508 // Not good, should be fixed
509 reportBug(__FUNCTION__, __LINE__, 'Network type handler id ' . $networkTypeId . ' is smaller than 1.');
512 // Just call our inner method
513 return adminSaveSettings($networkTypeData, '_network_types', sprintf("`network_type_id`=%s", bigintval($networkTypeId)), array(), FALSE, FALSE);
516 // Updates given network request parameters (id) with data from array
517 function doNetworkUpdateParamsByArray ($networkParamsId, $networkParamsData) {
518 // Ids lower one are not accepted
519 if ($networkParamsId < 1) {
520 // Not good, should be fixed
521 reportBug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $networkParamsId . ' is smaller than 1.');
524 // Just call our inner method
525 return adminSaveSettings($networkParamsData, '_network_request_params', sprintf("`network_request_param_id`=%s", bigintval($networkParamsId)), array(), FALSE, FALSE);
528 // Updates given network array translations (id) with data from array
529 function doNetworkUpdateArrayTranslationsByArray ($networkTranslationsId, $networkTranslationsData) {
530 // Ids lower one are not accepted
531 if ($networkTranslationsId < 1) {
532 // Not good, should be fixed
533 reportBug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $networkTranslationsId . ' is smaller than 1.');
536 // Just call our inner method
537 return adminSaveSettings($networkTranslationsData, '_network_array_translation', sprintf("`network_array_id`=%s", bigintval($networkTranslationsId)), array(), FALSE, FALSE);
540 // Removes given network entry
541 function doAdminRemoveNetworkEntry ($table, $column, $id, $limit = 1) {
543 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_network_%s` WHERE `%s`=%s LIMIT %s",
549 ), __FUNCTION__, __LINE__);
551 // Return affected rows
552 return SQL_AFFECTEDROWS();
555 // Generates a list of networks for given script and returns it
556 function generateAdminNetworkList () {
560 // Query for all networks
561 $result = SQL_QUERY('SELECT
563 `network_short_name`,
566 `{?_MYSQL_PREFIX?}_network_data`
567 ' . getNetworkActivatedColumn() . '
569 `network_short_name` ASC', __FUNCTION__, __LINE__);
571 // Are there entries?
572 if (!SQL_HASZERONUMS($result)) {
575 while ($row = SQL_FETCHARRAY($result)) {
576 // Is this valid, then add it
577 if ((is_array($row)) && (isset($row['network_id']))) {
579 $rows[$row['network_id']] = $row;
583 // Generate the selection box
584 $content = generateSelectionBoxFromArray($rows, 'network_id', 'network_id', '', '', 'network');
587 $content = loadTemplate('admin_settings_unsaved', FALSE, '{--ADMIN_ENTRIES_404--}');
591 SQL_FREERESULT($result);
597 // Generator (somewhat getter) for a list of network types for given network id
598 function generateAdminNetworkTypeList ($networkId) {
602 // Query all types of this network
603 $result = SQL_QUERY_ESC('SELECT
605 `network_type_handler`
607 `{?_MYSQL_PREFIX?}_network_types`
610 ' . getNetworkActivatedColumn('AND') . '
612 `network_type_handler` ASC',
614 bigintval($networkId)
615 ), __FUNCTION__, __LINE__);
617 // Are there entries?
618 if (!SQL_HASZERONUMS($result)) {
621 while ($row = SQL_FETCHARRAY($result)) {
622 // Is this valid, then add it
623 if ((is_array($row)) && (isset($row['network_type_id']))) {
625 $rows[$row['network_type_id']] = $row;
629 // Generate the selection box
630 $content = generateSelectionBoxFromArray($rows, 'network_type', 'network_type_id');
633 $content = loadTemplate('admin_settings_unsaved', FALSE, '{--ADMIN_ENTRIES_404--}');
637 SQL_FREERESULT($result);
643 // Generator (somewhat getter) for a list of network types for all types
644 function generateAdminDistinctNetworkTypeList () {
648 // Query all types of this network
649 $result = SQL_QUERY('SELECT
651 t.`network_type_handler`,
654 `{?_MYSQL_PREFIX?}_network_types` AS t
656 `{?_MYSQL_PREFIX?}_network_data` AS d
658 t.`network_id`=d.`network_id`
659 ' . getNetworkActivatedColumn('WHERE', 'd') . '
661 d.`network_short_name` ASC,
662 t.`network_type_handler` ASC', __FUNCTION__, __LINE__);
664 // Are there entries?
665 if (!SQL_HASZERONUMS($result)) {
668 while ($row = SQL_FETCHARRAY($result)) {
669 // Is this valid, then add it
670 if ((is_array($row)) && (isset($row['network_type_id']))) {
672 $rows[$row['network_type_id']] = $row;
676 // Generate the selection box
677 $content = generateSelectionBoxFromArray($rows, 'network_type', 'network_type_id', '', '_title');
680 $content = loadTemplate('admin_settings_unsaved', FALSE, '{--ADMIN_ENTRIES_404--}');
684 SQL_FREERESULT($result);
685 //* DEBUG: */ die('<pre>'.encodeEntities($content).'</pre>');
691 // Generator (somewhat getter) for network type options
692 function generateNetworkTypeOptions ($networkId) {
693 // Is this an array, then we just came back from edit/delete actions
694 if (is_array($networkId)) {
695 // Set it as empty string
700 if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
701 // Generate output and cache it
702 $GLOBALS[__FUNCTION__][$networkId] = generateOptions(
705 'network_type_handler',
709 "WHERE `network_id`=%s" . getNetworkActivatedColumn('AND'),
710 bigintval(getRequestElement('network_id'))
713 'translateNetworkTypeHandler'
718 return $GLOBALS[__FUNCTION__][$networkId];
721 // Generates an options list of all available (hard-coded) handlers
722 function generateNetworkTypesAvailableOptions ($defaultType = NULL) {
724 if (!isset($GLOBALS[__FUNCTION__][$defaultType])) {
726 $GLOBALS[__FUNCTION__][$defaultType] = generateOptions(
769 $GLOBALS['network_types_disabled'],
770 'translateNetworkTypeHandler'
775 return $GLOBALS[__FUNCTION__][$defaultType];
778 // Generates an options list of all available (hard-coded) text encoders
779 function generateNetworkTextEncodingAvailableOptions ($defaultEncoding = NULL) {
781 if (!isset($GLOBALS[__FUNCTION__][$defaultEncoding])) {
783 $GLOBALS[__FUNCTION__][$defaultEncoding] = generateOptions(
793 'translateNetworkTextEncoding'
798 return $GLOBALS[__FUNCTION__][$defaultEncoding];
801 // Generates an options list (somewhat getter) for request keys
802 function generateNetworkRequestKeyOptions () {
804 if (!isset($GLOBALS[__FUNCTION__])) {
805 // Generate and cache it
806 $GLOBALS[__FUNCTION__] = generateOptions(
828 $GLOBALS['network_request_params_disabled'],
829 'translateNetworkRequestParameterKey'
834 return $GLOBALS[__FUNCTION__];
837 // Generates an options list for vcheck request keys
838 function generateNetworkVcheckKeyOptions () {
840 if (!isset($GLOBALS[__FUNCTION__])) {
841 // Generate and cache it
842 $GLOBALS[__FUNCTION__] = generateOptions(
862 $GLOBALS['network_vcheck_params_disabled'],
863 'translateNetworkVcheckParameterKey'
868 return $GLOBALS[__FUNCTION__];
871 // Generator (somewhat getter) for (return) array translation
872 function generateNetworkTranslationOptions ($default = '') {
874 if (!isset($GLOBALS[__FUNCTION__][$default])) {
875 // Generate and cache it
876 $GLOBALS[__FUNCTION__][$default] = generateOptions(
877 'network_translations',
878 'network_translation_id',
879 'network_translation_name',
883 $GLOBALS['network_array_translation_disabled'],
884 'translateNetworkTranslationName'
889 return $GLOBALS[__FUNCTION__][$default];
892 // Generates an option list of request types
893 function generateNetworkRequestTypeOptions ($default = '') {
895 if (!isset($GLOBALS[__FUNCTION__][$default])) {
897 $GLOBALS[__FUNCTION__][$default] = generateOptions(
904 '{--ADMIN_NETWORK_REQUEST_TYPE_GET--}',
905 '{--ADMIN_NETWORK_REQUEST_TYPE_POST--}'
912 return $GLOBALS[__FUNCTION__][$default];
915 // Generates an option list of network_api_active
916 function generateNetworkApiActiveOptions ($default = '') {
918 if (!isset($GLOBALS[__FUNCTION__][$default])) {
920 $GLOBALS[__FUNCTION__][$default] = generateYesNoOptions($default);
924 return $GLOBALS[__FUNCTION__][$default];
927 // Translates 'translate_name' for e.g. templates
928 function translateNetworkTranslationName ($name) {
930 $messageId = 'ADMIN_NETWORK_TRANSLATE_' . strtoupper($name) . '_NAME';
932 // Is the message id there?
933 if (!isMessageIdValid($messageId)) {
935 reportBug(__FUNCTION__, __LINE__, 'name=' . $name . ' is invalid.');
939 return '{--' . $messageId . '--}';
942 // Translates the network type handler (e.g. banner, paidmail) for templates
943 function translateNetworkTypeHandler ($type) {
945 $messageId = 'ADMIN_NETWORK_TYPE_HANDLER_' . strtoupper($type);
947 // Is the message id there?
948 if (!isMessageIdValid($messageId)) {
950 reportBug(__FUNCTION__, __LINE__, 'type=' . $type . ' is invalid.');
954 return '{--' . $messageId . '--}';
957 // Translates request type
958 function translateNetworkRequestType ($type) {
960 $messageId = 'ADMIN_NETWORK_REQUEST_TYPE_' . strtoupper($type) . '';
962 // Is the message id there?
963 if (!isMessageIdValid($messageId)) {
965 reportBug(__FUNCTION__, __LINE__, 'type=' . $type . ' is invalid.');
969 return '{--' . $messageId . '--}';
972 // Translates request parameter
973 function translateNetworkRequestParameterKey ($param) {
975 $messageId = 'ADMIN_NETWORK_REQUEST_PARAMETER_' . strtoupper($param) . '';
977 // Is the message id there?
978 if (!isMessageIdValid($messageId)) {
980 reportBug(__FUNCTION__, __LINE__, 'param=' . $param . ' is invalid.');
984 return '{--' . $messageId . '--}';
987 // Translates vheck request parameter
988 function translateNetworkVcheckParameterKey ($param) {
990 $messageId = 'ADMIN_NETWORK_VCHECK_PARAMETER_' . strtoupper($param) . '';
992 // Is the message id there?
993 if (!isMessageIdValid($messageId)) {
995 reportBug(__FUNCTION__, __LINE__, 'param=' . $param . ' is invalid.');
999 return '{--' . $messageId . '--}';
1002 // Translate text-encoding
1003 function translateNetworkTextEncoding ($encoding) {
1005 $messageId = 'ADMIN_NETWORK_TYPE_TEXT_ENCODING_' . strtoupper($encoding) . '';
1007 // Is the message id there?
1008 if (!isMessageIdValid($messageId)) {
1009 // Not valid encoding
1010 reportBug(__FUNCTION__, __LINE__, 'encoding=' . $encoding . ' is invalid.');
1013 // Return message id
1014 return '{--' . $messageId . '--}';
1017 // Translates API index
1018 function translateNetworkApiIndex ($index) {
1020 if (!isset($GLOBALS['network_array_index'])) {
1021 // Get an array of all API array indexes
1022 $GLOBALS['network_array_index'] = array();
1025 $result = SQL_QUERY('SELECT
1027 `network_array_index`,
1028 `network_translation_name`
1030 `{?_MYSQL_PREFIX?}_network_array_translation`
1032 `{?_MYSQL_PREFIX?}_network_translations`
1034 `network_array_index`=`network_translation_id`
1036 `network_array_sort` ASC', __FUNCTION__, __LINE__);
1038 // Are there entries?
1039 if (!SQL_HASZERONUMS($result)) {
1041 while ($row = SQL_FETCHARRAY($result)) {
1042 // Add it to our global array
1043 $GLOBALS['network_array_index'][$row['network_array_index']] = $row;
1048 SQL_FREERESULT($result);
1051 // Default name is unknown
1054 // Is the entry there?
1055 if (isset($GLOBALS['network_array_index'][$index])) {
1056 // Then get the name
1057 $name = $GLOBALS['network_array_index'][$index]['network_translation_name'];
1060 // Return translation
1061 return translateNetworkTranslationName($name);
1064 // Translates network API configuration status (see function isNetworkApiConfigured()) by given id
1065 function translateNetworkApiConfiguredStatusById ($networkId) {
1067 if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
1068 // By default it is not configured
1069 $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_NOT_CONFIGURED--}';
1071 // So is it configured?
1072 if (!isNetworkActiveById($networkId)) {
1073 // Network is not active
1074 $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_NOT_ACTIVE--}';
1075 } elseif (isNetworkApiConfigured($networkId)) {
1077 $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_CONFIGURED--}';
1082 return $GLOBALS[__FUNCTION__][$networkId];
1085 // Checks if the given network is configured by looking its API configuration entry up
1086 function isNetworkApiConfigured ($networkId) {
1088 if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
1089 // Check for an entry in network_api_config
1090 $GLOBALS[__FUNCTION__][$networkId] = (countSumTotalData(
1091 bigintval($networkId),
1092 'network_api_config',
1100 return $GLOBALS[__FUNCTION__][$networkId];
1103 // Checks whether the given network type handler is configured
1104 function isNetworkTypeHandlerConfigured ($networkId, $networkTypeId) {
1106 if (!isset($GLOBALS[__FUNCTION__][$networkId][$networkTypeId])) {
1108 $GLOBALS[__FUNCTION__][$networkId][$networkTypeId] = (countSumTotalData(
1109 bigintval($networkTypeId),
1110 'network_types_config',
1114 sprintf(' AND `network_id`=%s', bigintval($networkId))
1119 return $GLOBALS[__FUNCTION__][$networkId][$networkTypeId];
1122 // Handles the network-payment-check request
1123 function handleNetworkPaymentCheckRequest () {
1124 // @TODO Implement this function, don't forget to set HTTP status back to '200 OK' if everything went fine
1125 reportBug(__FUNCTION__, __LINE__, 'Not yet implemented.');
1128 //------------------------------------------------------------------------------
1129 // Call-back functions
1130 //------------------------------------------------------------------------------
1132 // Callback function to add new network
1133 function doAdminNetworkProcessAddNetwork () {
1134 // We can say here, the form is sent, so check if the network is already added
1135 if (isNetworkNameValid(postRequestElement('network_short_name'))) {
1137 loadTemplate('admin_settings_unsaved', FALSE, '{%message,ADMIN_NETWORK_ALREADY_ADDED=' . postRequestElement('network_short_name') . '%}');
1141 // Remove the 'ok' part
1142 unsetPostRequestElement('ok');
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
1406 // Remove the 'ok' part
1407 unsetPostRequestElement('ok');
1410 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1412 // Is network_type_banner_url set?
1413 if (postRequestElement('network_type_banner_url') == '') {
1414 // Remove empty value to get a NULL for an optional entry
1415 unsetPostRequestElement('network_type_banner_url');
1418 // Add the whole request to database
1419 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_types'), __FUNCTION__, __LINE__);
1422 if (!SQL_HASZEROAFFECTED()) {
1423 // Successfully added
1424 loadTemplate('admin_network_type_added', FALSE, postRequestArray());
1427 loadTemplate('admin_settings_unsaved', FALSE, '{%message,ADMIN_NETWORK_TYPE_HANDLER_NOT_ADDED=' . postRequestElement('network_type_handler') . '%}');
1431 // Changes given network type handlers
1432 function doAdminNetworkProcessChangeHandlerTypes () {
1433 // Is there selections?
1434 if (ifPostContainsSelections()) {
1435 // By default nothing is updated
1438 // Something has been selected, so start updating them
1439 foreach (postRequestElement('sel') as $networkId => $sel) {
1440 // Update this entry?
1443 $networkTypeData = array();
1445 // Transfer whole array, except 'sel'
1446 foreach (postRequestArray() as $key => $entry) {
1447 // Skip 'sel' and submit button
1448 if (in_array($key, array('sel', 'do_edit'))) {
1452 // Is there this enty?
1453 if (!isset($entry[$networkId])) {
1454 // Not found, needs fixing
1455 reportBug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1458 // Fix empty network_type_banner_url to NULL
1459 if (($key == 'network_type_banner_url') && (trim($entry[$networkId]) == '')) {
1461 $entry[$networkId] = NULL;
1465 $networkTypeData[$key] = $entry[$networkId];
1468 // Update the network data
1469 $updated += doNetworkUpdateTypeByArray($networkId, $networkTypeData);
1473 // Is there updates?
1476 displayMessage('{%message,ADMIN_NETWORK_TYPE_HANDLER_UPDATED=' . $updated . '%}');
1479 loadTemplate('admin_settings_unsaved', FALSE, '{--ADMIN_NETWORK_TYPE_HANDLER_NOTHING_CHANGED--}');
1484 // Changes given network request parameters
1485 function doAdminNetworkProcessChangeRequestParams () {
1486 // Is there selections?
1487 if (ifPostContainsSelections()) {
1488 // By default nothing is updated
1491 // Something has been selected, so start updating them
1492 foreach (postRequestElement('sel') as $networkId => $sel) {
1493 // Update this entry?
1496 $networkParamsData = array();
1498 // Transfer whole array, except 'sel'
1499 foreach (postRequestArray() as $key => $entry) {
1500 // Skip 'sel' and submit button
1501 if (in_array($key, array('sel', 'do_edit'))) {
1505 // Is there this enty?
1506 if (!isset($entry[$networkId])) {
1507 // Not found, needs fixing
1508 reportBug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1511 // Fix empty network_request_param_default to NULL
1512 if (($key == 'network_request_param_default') && (trim($entry[$networkId]) == '')) {
1514 $entry[$networkId] = NULL;
1518 $networkParamsData[$key] = $entry[$networkId];
1521 // Update the network data
1522 $updated += doNetworkUpdateParamsByArray($networkId, $networkParamsData);
1526 // Is there updates?
1529 displayMessage('{%message,ADMIN_NETWORK_REQUEST_PARAMETER_UPDATED=' . $updated . '%}');
1532 loadTemplate('admin_settings_unsaved', FALSE, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_CHANGED--}');
1537 // Changes given network array translations
1538 function doAdminNetworkProcessChangeArrayTranslations () {
1539 // Is there selections?
1540 if (ifPostContainsSelections()) {
1541 // By default nothing is updated
1544 // Something has been selected, so start updating them
1545 foreach (postRequestElement('sel') as $networkId => $sel) {
1546 // Update this entry?
1549 $networkTranslationsData = array();
1551 // Transfer whole array, except 'sel'
1552 foreach (postRequestArray() as $key => $entry) {
1553 // Skip 'sel' and submit button
1554 if (in_array($key, array('sel', 'do_edit'))) {
1558 // Is there this enty?
1559 if (!isset($entry[$networkId])) {
1560 // Not found, needs fixing
1561 reportBug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1564 // Fix empty network_request_param_default to NULL
1565 if (($key == 'network_request_param_default') && (trim($entry[$networkId]) == '')) {
1567 $entry[$networkId] = NULL;
1571 $networkTranslationsData[$key] = $entry[$networkId];
1574 // Update the network data
1575 $updated += doNetworkUpdateArrayTranslationsByArray($networkId, $networkTranslationsData);
1579 // Is there updates?
1582 displayMessage('{%message,ADMIN_NETWORK_ARRAY_TRANSLATION_UPDATED=' . $updated . '%}');
1585 loadTemplate('admin_settings_unsaved', FALSE, '{--ADMIN_NETWORK_ARRAY_TRANSLATION_NOTHING_CHANGED--}');
1590 // Removes given network type handlers
1591 function doAdminNetworkProcessRemoveNetworkTypes () {
1592 // Is there selections?
1593 if (ifPostContainsSelections()) {
1594 // By default nothing is removed
1597 // Something has been selected, so start updating them
1598 foreach (postRequestElement('sel') as $networkId => $sel) {
1599 // Update this entry?
1601 // Remove this entry
1602 $removed += doAdminRemoveNetworkEntry('types', 'network_type_id', $networkId);
1606 // Is there removes?
1609 displayMessage('{%message,ADMIN_NETWORK_TYPE_HANDLER_REMOVED=' . $removed . '%}');
1612 loadTemplate('admin_settings_unsaved', FALSE, '{--ADMIN_NETWORK_TYPE_HANDLER_NOTHING_REMOVED--}');
1617 // Removes given network request parameters
1618 function doAdminNetworkProcessRemoveNetworkRequestParams () {
1619 // Is there selections?
1620 if (ifPostContainsSelections()) {
1621 // By default nothing is removed
1624 // Something has been selected, so start updating them
1625 foreach (postRequestElement('sel') as $networkId => $sel) {
1626 // Update this entry?
1628 // Remove this entry
1629 $removed += doAdminRemoveNetworkEntry('request_params', 'network_request_param_id', $networkId);
1633 // Is there removes?
1636 displayMessage('{%message,ADMIN_NETWORK_REQUEST_PARAMETER_REMOVED=' . $removed . '%}');
1639 loadTemplate('admin_settings_unsaved', FALSE, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_REMOVED--}');
1644 // Removes given network array translations
1645 function doAdminNetworkProcessRemoveNetworkArrayTranslation () {
1646 // Is there selections?
1647 if (ifPostContainsSelections()) {
1648 // By default nothing is removed
1651 // Something has been selected, so start updating them
1652 foreach (postRequestElement('sel') as $networkId => $sel) {
1653 // Update this entry?
1655 // Remove this entry
1656 $removed += doAdminRemoveNetworkEntry('array_translation', 'network_array_id', $networkId);
1660 // Is there removes?
1663 displayMessage('{%message,ADMIN_NETWORK_ARRAY_TRANSLATION_REMOVED=' . $removed . '%}');
1666 loadTemplate('admin_settings_unsaved', FALSE, '{--ADMIN_NETWORK_ARRAY_TRANSLATION_NOTHING_REMOVED--}');
1671 // Adds a request parameter to given network and type
1672 function doAdminNetworkProcessAddRequestParam () {
1673 // Is the request parameter already used with given network?
1674 if (isNetworkRequestElementValid(postRequestElement('network_request_param_key'), postRequestElement('network_type_id'), getRequestElement('network_id'))) {
1676 loadTemplate('admin_settings_unsaved', FALSE, '{%message,ADMIN_NETWORK_REQUEST_PARAMETER_ALREADY_ADDED=' . postRequestElement('network_request_param_key') . '%}');
1678 // ... so abort here
1682 // Remove the 'ok' part
1683 unsetPostRequestElement('ok');
1686 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1688 // Is network_request_param_default set?
1689 if (postRequestElement('network_request_param_default') == '') {
1690 // Remove empty value to get a NULL for an optional entry
1691 unsetPostRequestElement('network_request_param_default');
1694 // Add the whole request to database
1695 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_request_params'), __FUNCTION__, __LINE__);
1698 if (!SQL_HASZEROAFFECTED()) {
1699 // Successfully added
1700 loadTemplate('admin_network_request_param_added', FALSE, postRequestArray());
1703 loadTemplate('admin_settings_unsaved', FALSE, '{%message,ADMIN_NETWORK_REQUEST_PARAMETER_NOT_ADDED=' . postRequestElement('network_request_param_key') . '%}');
1707 // Adds a vheck request parameter to given network
1708 function doAdminNetworkProcessAddVcheckParam () {
1709 // Is the request parameter already used with given network?
1710 if (isNetworkVcheckElementValid(postRequestElement('network_vcheck_param_key'), getRequestElement('network_id'))) {
1712 loadTemplate('admin_settings_unsaved', FALSE, '{%message,ADMIN_NETWORK_VCHECK_PARAMETER_ALREADY_ADDED=' . postRequestElement('network_vcheck_param_key') . '%}');
1714 // ... so abort here
1718 // Remove the 'ok' part
1719 unsetPostRequestElement('ok');
1722 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1724 // Is network_vcheck_param_default set?
1725 if (postRequestElement('network_vcheck_param_default') == '') {
1726 // Remove empty value to get a NULL for an optional entry
1727 unsetPostRequestElement('network_vcheck_param_default');
1730 // Add the whole vcheck to database
1731 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_vcheck_params'), __FUNCTION__, __LINE__);
1734 if (!SQL_HASZEROAFFECTED()) {
1735 // Successfully added
1736 loadTemplate('admin_network_vcheck_param_added', FALSE, postRequestArray());
1739 loadTemplate('admin_settings_unsaved', FALSE, '{%message,ADMIN_NETWORK_VCHECK_PARAMETER_NOT_ADDED=' . postRequestElement('network_vcheck_param_key') . '%}');
1743 // Adds a API response array entry
1744 function doAdminNetworkProcessAddNetworkArrayTranslation () {
1745 // Is the request parameter already used with given network?
1746 if (isNetworkArrayTranslationValid(postRequestElement('network_array_index'), postRequestElement('network_type_id'), getRequestElement('network_id'))) {
1748 loadTemplate('admin_settings_unsaved', FALSE, '{%message,ADMIN_NETWORK_ARRAY_TRANSLATION_ALREADY_ADDED=' . postRequestElement('network_array_index') . '%}');
1750 // ... so abort here
1754 // Remove the 'ok' part
1755 unsetPostRequestElement('ok');
1758 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1761 setPostRequestElement('network_array_sort', (countSumTotalData(
1762 bigintval(postRequestElement('network_id')),
1763 'network_array_translation',
1767 sprintf(" AND `network_type_id`=%s", bigintval(postRequestElement('network_type_id')))
1770 // Add the whole request to database
1771 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_array_translation'), __FUNCTION__, __LINE__);
1774 if (!SQL_HASZEROAFFECTED()) {
1775 // Successfully added
1776 loadTemplate('admin_network_array_translation_added', FALSE, postRequestArray());
1779 loadTemplate('admin_settings_unsaved', FALSE, '{%message,ADMIN_NETWORK_ARRAY_TRANSLATION_NOT_ADDED=' . postRequestElement('network_array_index') . '%}');
1783 // Handle network array translation form
1784 function doAdminNetworkProcessHandleArrayTranslations () {
1785 // Is there selections?
1786 if (ifPostContainsSelections()) {
1788 $GLOBALS['network_array_translation_disabled'] = array();
1790 // Load network data
1791 $networkData = getNetworkDataById(getRequestElement('network_id'));
1793 // Something has been selected, so start displaying one by one
1795 foreach (postRequestElement('sel') as $networkId => $sel) {
1796 // Is this selected?
1798 // Load this network's data
1799 $networkTranslationsData = getNetworkArrayTranslationsDataById($networkId);
1801 // Is there found the network?
1802 if (count($networkTranslationsData) > 0) {
1803 if (isFormSent('edit')) {
1804 // Add row template for deleting
1805 $OUT .= loadTemplate('admin_edit_network_array_translation_row', TRUE, $networkTranslationsData);
1806 } elseif (isFormSent('delete')) {
1808 $networkTranslationsData['network_type_data'] = getNetworkTypeDataById($networkTranslationsData['network_type_id']);
1810 // Add row template for deleting
1811 $OUT .= loadTemplate('admin_delete_network_array_translation_row', TRUE, $networkTranslationsData);
1814 reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/delete.');
1820 // If we have no rows, we don't need to display the edit form
1822 // Prepare array with generic elements
1825 'network_id' => bigintval(getRequestElement('network_id'))
1828 // Output main template
1829 if (isFormSent('edit')) {
1830 loadTemplate('admin_edit_network_array_translation', FALSE, $content);
1831 } elseif (isFormSent('delete')) {
1832 loadTemplate('admin_delete_network_array_translation', FALSE, $content);
1835 reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/delete.');
1838 // Don't display the list/add new form
1839 $GLOBALS['network_display'] = FALSE;
1841 // Nothing selected/found
1842 loadTemplate('admin_settings_unsaved', FALSE, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_FOUND--}');
1847 // Adds/update network API configuration
1848 function doAdminNetworkProcessNetworkApiConfig () {
1849 // Remove the 'ok' part
1850 unsetPostRequestElement('ok');
1853 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1855 // Is network_api_referral_button set?
1856 if (postRequestElement('network_api_referral_button') == '') {
1857 // Remove empty value to get a NULL for an optional entry
1858 unsetPostRequestElement('network_api_referral_button');
1861 // Is there already an entry?
1862 if (isNetworkApiConfigured(getRequestElement('network_id'))) {
1863 // Generate SQL query
1864 $SQL = getUpdateSqlFromArray(postRequestArray(), 'network_api_config', 'network_id', postRequestElement('network_id'), array('network_id'));
1867 $SQL = getInsertSqlFromArray(postRequestArray(), 'network_api_config');
1871 SQL_QUERY($SQL, __FUNCTION__, __LINE__);
1874 if (!SQL_HASZEROAFFECTED()) {
1875 // Successfully added
1876 displayMessage('{--ADMIN_CONFIG_NETWORK_API_SAVED--}');
1879 loadTemplate('admin_settings_unsaved', FALSE, '{--ADMIN_CONFIG_NETWORK_API_NOT_SAVED--}');
1883 // Only adds network type configuration if not yet present
1884 function doAdminNetworkProcessAddHandlerTypesConfig ($displayMessage = TRUE) {
1885 // Remove the 'ok' part
1886 unsetPostRequestElement('ok');
1889 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1890 setPostRequestElement('network_type_id', bigintval(getRequestElement('network_type_id')));
1893 * Some parameters are optional, at least one must be given so check a bunch
1896 foreach (array('network_min_waiting_time', 'network_min_remain_clicks', 'network_min_payment', 'network_allow_erotic') as $element) {
1897 // Is this element empty?
1898 if (postRequestElement($element) == '') {
1899 // Then unset it to get a NULL for optional parameter
1900 unsetPostRequestElement($element);
1904 // Convert data in POST array
1905 convertSelectionsToEpocheTimeInPostData($content, 'network_max_reload_time_ye', $skip);
1907 // Is there already an entry?
1908 if (isNetworkTypeHandlerConfigured(getRequestElement('network_id'), getRequestElement('network_type_id'))) {
1909 // This network type handler is already configured
1910 displayMessage('{--ADMIN_NETWORK_HANDLER_TYPE_HANDLER_ALREADY_CONFIGURED--}');
1914 // Copy 'set all' and remove it from POST data
1915 $setAll = (postRequestElement('set_all') === 'Y');
1916 unsetPostRequestElement('set_all');
1918 // Shall we set for all?
1919 if ($setAll === TRUE) {
1921 $result = SQL_QUERY_ESC('SELECT `network_type_id` FROM `{?_MYSQL_PREFIX?}_network_types` WHERE `network_id`=%s ORDER BY `network_type_id` ASC',
1922 array(bigintval(getRequestElement('network_id'))), __FUNCTION__, __LINE__);
1924 // Are there entries?
1925 if (SQL_HASZERONUMS($result)) {
1926 // No, then abort here
1927 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_SET_ALL_404--}');
1931 // Init number of rows
1935 while (list($typeId) = SQL_FETCHROW($result)) {
1936 // Set it in GET data
1937 setGetRequestElement('network_type_id', $typeId);
1939 // Call this function again
1940 $numRows += doAdminNetworkProcessAddHandlerTypesConfig(FALSE);
1944 SQL_FREERESULT($result);
1948 // Something has been updated
1949 displayMessage('{%message,ADMIN_CONFIG_NETWORK_HANDLER_TYPE_ALL_HANDLER_SAVED=' . bigintval($numRows) . '%}');
1951 // Nothing has been saved
1952 loadTemplate('admin_settings_unsaved', FALSE, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}');
1955 // Get SQL query for new entry
1956 $SQL = getInsertSqlFromArray(postRequestArray(), 'network_types_config');
1959 SQL_QUERY($SQL, __FUNCTION__, __LINE__);
1961 // Shall we display the message?
1962 if ($displayMessage === TRUE) {
1964 if (!SQL_HASZEROAFFECTED()) {
1965 // Successfully added
1966 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_SAVED--}');
1969 loadTemplate('admin_settings_unsaved', FALSE, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_SAVED--}');
1972 // Return amount of affected rows (1 or 2)
1973 return SQL_AFFECTEDROWS();
1978 // Only changes network type configuration if not yet present
1979 function doAdminNetworkProcessEditHandlerTypesConfig ($displayMessage = TRUE) {
1980 // Remove the 'ok' part
1981 unsetPostRequestElement('ok');
1984 * Some parameters are optional, at least one must be given so check a bunch
1987 foreach (array('network_min_waiting_time', 'network_min_remain_clicks', 'network_min_payment', 'network_allow_erotic') as $element) {
1988 // Is this element empty?
1989 if (postRequestElement($element) == '') {
1990 // Then unset it to get a NULL for optional parameter
1991 unsetPostRequestElement($element);
1995 // Convert time selections in POST data
1996 convertSelectionsToEpocheTimeInPostData('network_max_reload_time_ye');
1998 // Is there already an entry?
1999 if (!isNetworkTypeHandlerConfigured(getRequestElement('network_id'), getRequestElement('network_type_id'))) {
2000 // This network type handler is not configured
2001 displayMessage('{--ADMIN_NETWORK_HANDLER_TYPE_HANDLER_NOT_CONFIGURED--}');
2005 // Copy 'set all' and remove it from POST data
2006 $setAll = (postRequestElement('set_all') === 'Y');
2007 unsetPostRequestElement('set_all');
2009 // Shall we set for all?
2010 if ($setAll === TRUE) {
2011 // Get all data entries
2012 $result = SQL_QUERY_ESC('SELECT `network_data_id` FROM `{?_MYSQL_PREFIX?}_network_types_config` WHERE `network_id`=%s ORDER BY `network_type_id` ASC',
2013 array(bigintval(getRequestElement('network_id'))), __FUNCTION__, __LINE__);
2015 // Are there entries?
2016 if (SQL_HASZERONUMS($result)) {
2017 // No, then abort here
2018 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_SET_ALL_404--}');
2022 // Init number of rows
2026 while (list($dataId) = SQL_FETCHROW($result)) {
2027 // Set it in GET data
2028 setPostRequestElement('network_data_id', $dataId);
2030 // Call this function again
2031 $numRows += doAdminNetworkProcessEditHandlerTypesConfig(FALSE);
2035 SQL_FREERESULT($result);
2039 // Something has been updated
2040 displayMessage('{%message,ADMIN_CONFIG_NETWORK_HANDLER_TYPE_ALL_HANDLER_SAVED=' . bigintval($numRows) . '%}');
2042 // Nothing has been saved
2043 loadTemplate('admin_settings_unsaved', FALSE, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}');
2046 // Get SQL query for new entry
2047 $SQL = getUpdateSqlFromArray(postRequestArray(), 'network_types_config', 'network_data_id', postRequestElement('network_data_id'), array('network_data_id'));
2050 SQL_QUERY($SQL, __FUNCTION__, __LINE__);
2052 // Shall we display the message?
2053 if ($displayMessage === TRUE) {
2055 if (!SQL_HASZEROAFFECTED()) {
2056 // Successfully added
2057 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_SAVED--}');
2060 loadTemplate('admin_settings_unsaved', FALSE, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}');
2063 // Return amount of affected rows (1 or 2)
2064 return SQL_AFFECTEDROWS();
2069 // Do expression code for this extension
2070 function doExpressionNetwork ($data) {
2071 // Construct replacer
2072 $replacer = sprintf(
2073 "{DQUOTE} . %s(%s, '%s') . {DQUOTE}",
2075 $data['matches'][4][$data['key']],
2079 // Replace %network_id% with the current network id
2080 $replacer = str_replace('%network_id%', getCurrentNetworkId(), $replacer);
2083 $code = replaceExpressionCode($data, $replacer);
2089 // ----------------------------------------------------------------------------
2090 // Call-back functions for exporting data
2091 // ----------------------------------------------------------------------------
2093 // Callback function to export network tables
2094 function doAdminNetworkProcessExport () {
2095 // Init table with all valid what->table entries
2096 $validExports = array(
2097 // General network data
2098 'list_network_data' => 'data',
2099 // Network type handler
2100 'list_network_types' => 'types',
2101 // Network request parameter
2102 'list_network_request_params' => 'request_params',
2103 // Vcheck request parameter
2104 'list_network_vcheck_params' => 'vcheck_params',
2105 // Network API response array index translation
2106 'list_network_array_translation' => 'array_translation',
2109 // Is the 'what' key valid?
2110 if (!isset($validExports[getWhat()])) {
2112 reportBug(__FUNCTION__, __LINE__, 'what=' . getWhat() . ' - not supported');
2115 // Generate call-back, some tables require to export not all columns
2116 $callbackName = 'doAdminNetworkExport' . capitalizeUnderscoreString($validExports[getWhat()]);
2118 // Is the call-back function there?
2119 if (!function_exists($callbackName)) {
2120 // No, this is really bad
2121 reportBug(__FUNCTION__, __LINE__, 'Invalid call-back function ' . $callbackName . ' detected.');
2122 } elseif (isset($GLOBALS[__FUNCTION__][$callbackName])) {
2124 reportBug(__FUNCTION__, __LINE__, 'Double-call of export function ' . $callbackName . ' detected.');
2127 // Call the function
2128 call_user_func($callbackName);
2130 // Mark it as called
2131 $GLOBALS[__FUNCTION__][$callbackName] = TRUE;
2133 // Don't display the list/add new form
2134 $GLOBALS['network_display'] = FALSE;
2137 // Exports (and displays) the table 'network_data'
2138 function doAdminNetworkExportData () {
2139 // Query for all networks
2140 $result = SQL_QUERY('SELECT
2141 `network_short_name`,
2144 `network_data_separator`,
2145 `network_row_separator`,
2146 `network_request_type`,
2148 `network_require_id_card`,
2149 `network_query_amount`,
2152 `{?_MYSQL_PREFIX?}_network_data`
2155 __FUNCTION__, __LINE__);
2157 // Start an empty SQL query
2158 $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";
2161 while ($content = SQL_FETCHARRAY($result)) {
2164 $content['network_short_name'] . "', '" .
2165 $content['network_title'] . "', '" .
2166 $content['network_reflink'] . "', '" .
2167 $content['network_data_separator'] . "', '" .
2168 $content['network_row_separator'] . "', '" .
2169 $content['network_request_type'] . "', '" .
2170 $content['network_charset'] . "', '" .
2171 $content['network_require_id_card'] . "', " .
2172 $content['network_query_amount'] . ", '" .
2173 $content['network_active'] . "'),\n";
2176 // Remove last commata and close braces
2177 $SQL = substr($SQL, 0, -2);
2180 SQL_FREERESULT($result);
2182 // Output the SQL query
2183 loadTemplate('admin_export_network_data', FALSE, $SQL);
2186 // Exports (and displays) the table 'network_types'
2187 function doAdminNetworkExportTypes () {
2188 // 'network_id' must be set
2189 if (!isGetRequestElementSet('network_id')) {
2190 // Only network handlers of one network will be exported per time
2191 reportBug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
2194 // Get all network types of given network
2195 $result = SQL_QUERY_ESC('SELECT
2198 `network_type_handler`,
2199 `network_type_api_url`,
2200 `network_type_click_url`,
2201 `network_type_banner_url`,
2202 `network_type_reload_time_unit`,
2203 `network_text_encoding`
2205 `{?_MYSQL_PREFIX?}_network_types`
2209 `network_type_id` ASC',
2211 bigintval(getRequestElement('network_id'))
2212 ), __FUNCTION__, __LINE__);
2214 // Start an empty SQL query
2215 $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";
2218 while ($content = SQL_FETCHARRAY($result)) {
2221 $content['network_type_id'] . ', ' .
2222 $content['network_id'] . ", '" .
2223 $content['network_type_handler'] . "', '" .
2224 $content['network_type_api_url'] . "', '" .
2225 $content['network_type_click_url'] . "', ";
2227 // Is the column NULL?
2228 if (is_null($content['network_type_banner_url'])) {
2233 $SQL .= chr(39) . $content['network_type_banner_url'] . chr(39);
2237 $SQL .= ",'" . $content['network_type_reload_time_unit'] . "','" . $content['network_text_encoding'] . "'),\n";
2240 // Remove last commata and close braces
2241 $SQL = substr($SQL, 0, -2);
2244 SQL_FREERESULT($result);
2246 // Output the SQL query
2247 loadTemplate('admin_export_network_types', FALSE, $SQL);
2250 // Exports (and displays) the table 'network_request_params'
2251 function doAdminNetworkExportRequestParams () {
2252 // 'network_id' must be set
2253 if (!isGetRequestElementSet('network_id')) {
2254 // Only network request parameters of one network will be exported per time
2255 reportBug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
2258 // Get all network types of given network
2259 $result = SQL_QUERY_ESC('SELECT
2262 `network_request_param_key`,
2263 `network_request_param_value`,
2264 `network_request_param_default`
2266 `{?_MYSQL_PREFIX?}_network_request_params`
2270 `network_type_id` ASC ,
2271 `network_request_param_id` ASC',
2273 bigintval(getRequestElement('network_id'))
2274 ), __FUNCTION__, __LINE__);
2276 // Start an empty SQL query
2277 $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";
2280 while ($content = SQL_FETCHARRAY($result)) {
2283 $content['network_id'] . ', ' .
2284 $content['network_type_id'] . ", '" .
2285 $content['network_request_param_key'] . "', '" .
2286 $content['network_request_param_value'] . "', ";
2288 // Is the column NULL?
2289 if (is_null($content['network_request_param_default'])) {
2294 $SQL .= chr(39) . $content['network_request_param_default'] . "'),\n";
2298 // Remove last commata and close braces
2299 $SQL = substr($SQL, 0, -2);
2302 SQL_FREERESULT($result);
2304 // Output the SQL query
2305 loadTemplate('admin_export_network_request_params', FALSE, $SQL);
2308 // Exports (and displays) the table 'network_vcheck_params'
2309 function doAdminNetworkExportVcheckParams () {
2310 // 'network_id' must be set
2311 if (!isGetRequestElementSet('network_id')) {
2312 // Only network vcheck parameters of one network will be exported per time
2313 reportBug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
2316 // Get all network types of given network
2317 $result = SQL_QUERY_ESC('SELECT
2319 `network_vcheck_param_key`,
2320 `network_vcheck_param_value`,
2321 `network_vcheck_param_default`
2323 `{?_MYSQL_PREFIX?}_network_vcheck_params`
2327 `network_vcheck_param_id` ASC',
2329 bigintval(getRequestElement('network_id'))
2330 ), __FUNCTION__, __LINE__);
2332 // Start an empty SQL query
2333 $SQL = "INSERT INTO `{?_MYSQL_PREFIX?}_network_vcheck_params` (`network_id`, `network_vcheck_param_key`, `network_vcheck_param_value`, `network_vcheck_param_default`) VALUES\n";
2336 while ($content = SQL_FETCHARRAY($result)) {
2339 $content['network_id'] . ", '" .
2340 $content['network_vcheck_param_key'] . "', '" .
2341 $content['network_vcheck_param_value'] . "', ";
2343 // Is the column NULL?
2344 if (is_null($content['network_vcheck_param_default'])) {
2349 $SQL .= chr(39) . $content['network_vcheck_param_default'] . "'),\n";
2353 // Remove last commata and close braces
2354 $SQL = substr($SQL, 0, -2);
2357 SQL_FREERESULT($result);
2359 // Output the SQL query
2360 loadTemplate('admin_export_network_vcheck_params', FALSE, $SQL);
2363 // Exports (and displays) the table 'network_array_translation'
2364 function doAdminNetworkExportArrayTranslation () {
2365 // 'network_id' must be set
2366 if (!isGetRequestElementSet('network_id')) {
2367 // Only network API array index translations of one network will be exported per time
2368 reportBug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
2371 // Get all network types of given network
2372 $result = SQL_QUERY_ESC('SELECT
2375 `network_array_index`,
2376 `network_array_sort`
2378 `{?_MYSQL_PREFIX?}_network_array_translation`
2382 `network_type_id` ASC,
2383 `network_array_sort` ASC',
2385 bigintval(getRequestElement('network_id'))
2386 ), __FUNCTION__, __LINE__);
2388 // Start an empty SQL query
2389 $SQL = "INSERT INTO `{?_MYSQL_PREFIX?}_network_array_translation` (`network_id`, `network_type_id`, `network_array_index`, `network_array_sort`) VALUES\n";
2392 while ($content = SQL_FETCHARRAY($result)) {
2395 $content['network_id'] . ', ' .
2396 $content['network_type_id'] . ', ' .
2397 $content['network_array_index'] . ', ' .
2398 $content['network_array_sort'] . "),\n";
2401 // Remove last commata and close braces
2402 $SQL = substr($SQL, 0, -2);
2405 SQL_FREERESULT($result);
2407 // Output the SQL query
2408 loadTemplate('admin_export_network_array_translation', FALSE, $SQL);