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(
762 $GLOBALS['network_types_disabled'],
763 'translateNetworkTypeHandler'
768 return $GLOBALS[__FUNCTION__][$defaultType];
771 // Generates an options list of all available (hard-coded) text encoders
772 function generateNetworkTextEncodingAvailableOptions ($defaultEncoding = NULL) {
774 if (!isset($GLOBALS[__FUNCTION__][$defaultEncoding])) {
776 $GLOBALS[__FUNCTION__][$defaultEncoding] = generateOptions(
786 'translateNetworkTextEncoding'
791 return $GLOBALS[__FUNCTION__][$defaultEncoding];
794 // Generates an options list (somewhat getter) for request keys
795 function generateNetworkRequestKeyOptions () {
797 if (!isset($GLOBALS[__FUNCTION__])) {
798 // Generate and cache it
799 $GLOBALS[__FUNCTION__] = generateOptions(
821 $GLOBALS['network_request_params_disabled'],
822 'translateNetworkRequestParameterKey'
827 return $GLOBALS[__FUNCTION__];
830 // Generates an options list for vcheck request keys
831 function generateNetworkVcheckKeyOptions () {
833 if (!isset($GLOBALS[__FUNCTION__])) {
834 // Generate and cache it
835 $GLOBALS[__FUNCTION__] = generateOptions(
855 $GLOBALS['network_vcheck_params_disabled'],
856 'translateNetworkVcheckParameterKey'
861 return $GLOBALS[__FUNCTION__];
864 // Generator (somewhat getter) for (return) array translation
865 function generateNetworkTranslationOptions ($default = '') {
867 if (!isset($GLOBALS[__FUNCTION__][$default])) {
868 // Generate and cache it
869 $GLOBALS[__FUNCTION__][$default] = generateOptions(
870 'network_translations',
871 'network_translation_id',
872 'network_translation_name',
876 $GLOBALS['network_array_translation_disabled'],
877 'translateNetworkTranslationName'
882 return $GLOBALS[__FUNCTION__][$default];
885 // Generates an option list of request types
886 function generateNetworkRequestTypeOptions ($default = '') {
888 if (!isset($GLOBALS[__FUNCTION__][$default])) {
890 $GLOBALS[__FUNCTION__][$default] = generateOptions(
897 '{--ADMIN_NETWORK_REQUEST_TYPE_GET--}',
898 '{--ADMIN_NETWORK_REQUEST_TYPE_POST--}'
905 return $GLOBALS[__FUNCTION__][$default];
908 // Generates an option list of network_api_active
909 function generateNetworkApiActiveOptions ($default = '') {
911 if (!isset($GLOBALS[__FUNCTION__][$default])) {
913 $GLOBALS[__FUNCTION__][$default] = generateYesNoOptions($default);
917 return $GLOBALS[__FUNCTION__][$default];
920 // Translates 'translate_name' for e.g. templates
921 function translateNetworkTranslationName ($name) {
923 $messageId = 'ADMIN_NETWORK_TRANSLATE_' . strtoupper($name) . '_NAME';
925 // Is the message id there?
926 if (!isMessageIdValid($messageId)) {
928 reportBug(__FUNCTION__, __LINE__, 'name=' . $name . ' is invalid.');
932 return '{--' . $messageId . '--}';
935 // Translates the network type handler (e.g. banner, paidmail) for templates
936 function translateNetworkTypeHandler ($type) {
938 $messageId = 'ADMIN_NETWORK_TYPE_HANDLER_' . strtoupper($type);
940 // Is the message id there?
941 if (!isMessageIdValid($messageId)) {
943 reportBug(__FUNCTION__, __LINE__, 'type=' . $type . ' is invalid.');
947 return '{--' . $messageId . '--}';
950 // Translates request type
951 function translateNetworkRequestType ($type) {
953 $messageId = 'ADMIN_NETWORK_REQUEST_TYPE_' . strtoupper($type) . '';
955 // Is the message id there?
956 if (!isMessageIdValid($messageId)) {
958 reportBug(__FUNCTION__, __LINE__, 'type=' . $type . ' is invalid.');
962 return '{--' . $messageId . '--}';
965 // Translates request parameter
966 function translateNetworkRequestParameterKey ($param) {
968 $messageId = 'ADMIN_NETWORK_REQUEST_PARAMETER_' . strtoupper($param) . '';
970 // Is the message id there?
971 if (!isMessageIdValid($messageId)) {
973 reportBug(__FUNCTION__, __LINE__, 'param=' . $param . ' is invalid.');
977 return '{--' . $messageId . '--}';
980 // Translates vheck request parameter
981 function translateNetworkVcheckParameterKey ($param) {
983 $messageId = 'ADMIN_NETWORK_VCHECK_PARAMETER_' . strtoupper($param) . '';
985 // Is the message id there?
986 if (!isMessageIdValid($messageId)) {
988 reportBug(__FUNCTION__, __LINE__, 'param=' . $param . ' is invalid.');
992 return '{--' . $messageId . '--}';
995 // Translate text-encoding
996 function translateNetworkTextEncoding ($encoding) {
998 $messageId = 'ADMIN_NETWORK_TYPE_TEXT_ENCODING_' . strtoupper($encoding) . '';
1000 // Is the message id there?
1001 if (!isMessageIdValid($messageId)) {
1002 // Not valid encoding
1003 reportBug(__FUNCTION__, __LINE__, 'encoding=' . $encoding . ' is invalid.');
1006 // Return message id
1007 return '{--' . $messageId . '--}';
1010 // Translates API index
1011 function translateNetworkApiIndex ($index) {
1013 if (!isset($GLOBALS['network_array_index'])) {
1014 // Get an array of all API array indexes
1015 $GLOBALS['network_array_index'] = array();
1018 $result = SQL_QUERY('SELECT
1020 `network_array_index`,
1021 `network_translation_name`
1023 `{?_MYSQL_PREFIX?}_network_array_translation`
1025 `{?_MYSQL_PREFIX?}_network_translations`
1027 `network_array_index`=`network_translation_id`
1029 `network_array_sort` ASC', __FUNCTION__, __LINE__);
1031 // Are there entries?
1032 if (!SQL_HASZERONUMS($result)) {
1034 while ($row = SQL_FETCHARRAY($result)) {
1035 // Add it to our global array
1036 $GLOBALS['network_array_index'][$row['network_array_index']] = $row;
1041 SQL_FREERESULT($result);
1044 // Default name is unknown
1047 // Is the entry there?
1048 if (isset($GLOBALS['network_array_index'][$index])) {
1049 // Then get the name
1050 $name = $GLOBALS['network_array_index'][$index]['network_translation_name'];
1053 // Return translation
1054 return translateNetworkTranslationName($name);
1057 // Translates network API configuration status (see function isNetworkApiConfigured()) by given id
1058 function translateNetworkApiConfiguredStatusById ($networkId) {
1060 if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
1061 // By default it is not configured
1062 $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_NOT_CONFIGURED--}';
1064 // So is it configured?
1065 if (!isNetworkActiveById($networkId)) {
1066 // Network is not active
1067 $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_NOT_ACTIVE--}';
1068 } elseif (isNetworkApiConfigured($networkId)) {
1070 $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_CONFIGURED--}';
1075 return $GLOBALS[__FUNCTION__][$networkId];
1078 // Checks if the given network is configured by looking its API configuration entry up
1079 function isNetworkApiConfigured ($networkId) {
1081 if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
1082 // Check for an entry in network_api_config
1083 $GLOBALS[__FUNCTION__][$networkId] = (countSumTotalData(
1084 bigintval($networkId),
1085 'network_api_config',
1093 return $GLOBALS[__FUNCTION__][$networkId];
1096 // Checks whether the given network type handler is configured
1097 function isNetworkTypeHandlerConfigured ($networkId, $networkTypeId) {
1099 if (!isset($GLOBALS[__FUNCTION__][$networkId][$networkTypeId])) {
1101 $GLOBALS[__FUNCTION__][$networkId][$networkTypeId] = (countSumTotalData(
1102 bigintval($networkTypeId),
1103 'network_types_config',
1107 sprintf(' AND `network_id`=%s', bigintval($networkId))
1112 return $GLOBALS[__FUNCTION__][$networkId][$networkTypeId];
1115 // Handles the network-payment-check request
1116 function handleNetworkPaymentCheckRequest () {
1117 // @TODO Implement this function, don't forget to set HTTP status back to '200 OK' if everything went fine
1118 reportBug(__FUNCTION__, __LINE__, 'Not yet implemented.');
1121 //------------------------------------------------------------------------------
1122 // Call-back functions
1123 //------------------------------------------------------------------------------
1125 // Callback function to add new network
1126 function doAdminNetworkProcessAddNetwork () {
1127 // We can say here, the form is sent, so check if the network is already added
1128 if (isNetworkNameValid(postRequestElement('network_short_name'))) {
1130 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_ALREADY_ADDED=' . postRequestElement('network_short_name') . '%}');
1132 } elseif (!isNetworkActiveByShortName(postRequestElement('network_short_name'))) {
1133 // Network is not active
1134 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_NOT_ACTIVE=' . postRequestElement('network_short_name') . '%}');
1138 // Remove the 'ok' part
1139 unsetPostRequestElement('ok');
1141 // Add the whole request to database
1142 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_data'), __FUNCTION__, __LINE__);
1144 // Add the id for output only
1145 setPostRequestElement('network_id', SQL_INSERTID());
1148 if (!SQL_HASZEROAFFECTED()) {
1149 // Successfully added
1150 loadTemplate('admin_network_added', false, postRequestArray());
1153 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_DATA_NOT_ADDED=' . postRequestElement('network_short_name') . '%}');
1157 // Displays selected networks for editing
1158 function doAdminNetworkProcessHandleNetworks () {
1159 // Is there selections?
1160 if (ifPostContainsSelections()) {
1161 // Something has been selected, so start displaying one by one
1163 foreach (postRequestElement('sel') as $networkId => $sel) {
1164 // Is this selected?
1166 // Load this network's data
1167 $networkData = getNetworkDataById($networkId);
1169 // Is there found the network?
1170 if (count($networkData) > 0) {
1171 // Add row template with given form name
1172 $OUT .= loadTemplate('admin_' . $GLOBALS['network_form_name'] . '_networks_row', true, $networkData);
1177 // If we have no rows, we don't need to display the edit form
1179 // Output main template
1180 loadTemplate('admin_' . $GLOBALS['network_form_name'] . '_networks', false, $OUT);
1182 // Don't display the list/add new form
1183 $GLOBALS['network_display'] = false;
1185 // Nothing selected/found
1186 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_FOUND--}');
1191 // Handle network type form
1192 function doAdminNetworkProcessHandleNetworkTypes () {
1193 // Is there selections?
1194 if (ifPostContainsSelections()) {
1195 // Load network data
1196 $networkData = getNetworkDataById(getRequestElement('network_id'));
1198 // Something has been selected, so start displaying one by one
1200 foreach (postRequestElement('sel') as $networkId => $sel) {
1201 // Is this selected?
1203 // Load this network's data
1204 $networkTypeData = getNetworkTypeDataById($networkId);
1206 // Is there found the network?
1207 if (count($networkTypeData) > 0) {
1208 if (isFormSent('edit')) {
1209 // Add row template for deleting
1210 $OUT .= loadTemplate('admin_edit_network_types_row', true, $networkTypeData);
1211 } elseif (isFormSent('delete')) {
1212 // Add row template for deleting
1213 $OUT .= loadTemplate('admin_delete_network_types_row', true, $networkTypeData);
1216 reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/delete.');
1222 // If we have no rows, we don't need to display the edit form
1224 // Output main template
1225 if (isFormSent('edit')) {
1226 loadTemplate('admin_edit_network_types', false, $OUT);
1227 } elseif (isFormSent('delete')) {
1228 loadTemplate('admin_delete_network_types', false, $OUT);
1231 reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/delete.');
1234 // Don't display the list/add new form
1235 $GLOBALS['network_display'] = false;
1237 // Nothing selected/found
1238 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPE_HANDLER_NOTHING_FOUND--}');
1243 // Handle network request parameter form
1244 function doAdminNetworkProcessHandleRequestParams () {
1245 // Is there selections?
1246 if (ifPostContainsSelections()) {
1248 $GLOBALS['network_request_params_disabled'] = array();
1250 // Load network data
1251 $networkData = getNetworkDataById(getRequestElement('network_id'));
1253 // Something has been selected, so start displaying one by one
1255 foreach (postRequestElement('sel') as $networkId => $sel) {
1256 // Is this selected?
1258 // Load this network's data
1259 $networkRequestData = getNetworkRequestParamsDataById($networkId);
1261 // Is there found the network?
1262 if (count($networkRequestData) > 0) {
1263 if (isFormSent('edit')) {
1264 // Add row template for deleting
1265 $OUT .= loadTemplate('admin_edit_network_request_params_row', true, $networkRequestData);
1266 } elseif (isFormSent('delete')) {
1268 $networkRequestData['network_type_data'] = getNetworkTypeDataById($networkRequestData['network_type_id']);
1270 // Add row template for deleting
1271 $OUT .= loadTemplate('admin_delete_network_request_params_row', true, $networkRequestData);
1274 reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/delete.');
1280 // If we have no rows, we don't need to display the edit form
1282 // Output main template
1283 if (isFormSent('edit')) {
1284 loadTemplate('admin_edit_network_request_params', false, $OUT);
1285 } elseif (isFormSent('delete')) {
1286 loadTemplate('admin_delete_network_request_params', false, $OUT);
1289 reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/delete.');
1292 // Don't display the list/add new form
1293 $GLOBALS['network_display'] = false;
1295 // Nothing selected/found
1296 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_FOUND--}');
1301 // Changes given networks
1302 function doAdminNetworkProcessChangeNetworks () {
1303 // Is there selections?
1304 if (ifPostContainsSelections()) {
1305 // By default nothing is updated
1308 // Something has been selected, so start updating them
1309 foreach (postRequestElement('sel') as $networkId => $sel) {
1310 // Update this entry?
1313 $networkData = array();
1315 // Transfer whole array, except 'sel'
1316 foreach (postRequestArray() as $key => $entry) {
1317 // Skip 'sel' and submit button
1318 if (in_array($key, array('sel', 'do_edit'))) {
1322 // Is there this enty?
1323 if (!isset($entry[$networkId])) {
1324 // Not found, needs fixing
1325 reportBug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1329 $networkData[$key] = $entry[$networkId];
1332 // Update the network data
1333 $updated += doNetworkUpdateDataByArray($networkId, $networkData);
1337 // Is there updates?
1340 displayMessage('{%message,ADMIN_NETWORK_UPDATED=' . $updated . '%}');
1343 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_CHANGED--}');
1348 // Removes given networks
1349 function doAdminNetworkProcessRemoveNetworks () {
1350 // Is there selections?
1351 if (ifPostContainsSelections()) {
1352 // By default nothing is removed
1355 // Something has been selected, so start updating them
1356 foreach (postRequestElement('sel') as $networkId => $sel) {
1357 // Update this entry?
1359 // Remove this entry
1360 $removed += doAdminRemoveNetworkEntry('data', 'network_id', $networkId);
1364 // Is there removes?
1367 displayMessage('{%message,ADMIN_NETWORK_REMOVED=' . $removed . '%}');
1370 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_REMOVED--}');
1375 // Add a network type handler if not yet found
1376 function doAdminNetworkProcessAddNetworkType () {
1377 // Is the network type handle already used with given network?
1378 if (isNetworkTypeHandleValid(postRequestElement('network_type_handler'), getRequestElement('network_id'))) {
1380 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_TYPE_HANDLER_ALREADY_ADDED=' . postRequestElement('network_type_handler') . '%}');
1382 // ... so abort here
1386 // Remove the 'ok' part
1387 unsetPostRequestElement('ok');
1390 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1392 // Is network_type_banner_url set?
1393 if (postRequestElement('network_type_banner_url') == '') {
1394 // Remove empty value to get a NULL for an optional entry
1395 unsetPostRequestElement('network_type_banner_url');
1398 // Add the whole request to database
1399 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_types'), __FUNCTION__, __LINE__);
1402 if (!SQL_HASZEROAFFECTED()) {
1403 // Successfully added
1404 loadTemplate('admin_network_type_added', false, postRequestArray());
1407 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_TYPE_HANDLER_NOT_ADDED=' . postRequestElement('network_type_handler') . '%}');
1411 // Changes given network type handlers
1412 function doAdminNetworkProcessChangeHandlerTypes () {
1413 // Is there selections?
1414 if (ifPostContainsSelections()) {
1415 // By default nothing is updated
1418 // Something has been selected, so start updating them
1419 foreach (postRequestElement('sel') as $networkId => $sel) {
1420 // Update this entry?
1423 $networkTypeData = array();
1425 // Transfer whole array, except 'sel'
1426 foreach (postRequestArray() as $key => $entry) {
1427 // Skip 'sel' and submit button
1428 if (in_array($key, array('sel', 'do_edit'))) {
1432 // Is there this enty?
1433 if (!isset($entry[$networkId])) {
1434 // Not found, needs fixing
1435 reportBug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1438 // Fix empty network_type_banner_url to NULL
1439 if (($key == 'network_type_banner_url') && (trim($entry[$networkId]) == '')) {
1441 $entry[$networkId] = NULL;
1445 $networkTypeData[$key] = $entry[$networkId];
1448 // Update the network data
1449 $updated += doNetworkUpdateTypeByArray($networkId, $networkTypeData);
1453 // Is there updates?
1456 displayMessage('{%message,ADMIN_NETWORK_TYPE_HANDLER_UPDATED=' . $updated . '%}');
1459 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPE_HANDLER_NOTHING_CHANGED--}');
1464 // Changes given network request parameters
1465 function doAdminNetworkProcessChangeRequestParams () {
1466 // Is there selections?
1467 if (ifPostContainsSelections()) {
1468 // By default nothing is updated
1471 // Something has been selected, so start updating them
1472 foreach (postRequestElement('sel') as $networkId => $sel) {
1473 // Update this entry?
1476 $networkParamsData = array();
1478 // Transfer whole array, except 'sel'
1479 foreach (postRequestArray() as $key => $entry) {
1480 // Skip 'sel' and submit button
1481 if (in_array($key, array('sel', 'do_edit'))) {
1485 // Is there this enty?
1486 if (!isset($entry[$networkId])) {
1487 // Not found, needs fixing
1488 reportBug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1491 // Fix empty network_request_param_default to NULL
1492 if (($key == 'network_request_param_default') && (trim($entry[$networkId]) == '')) {
1494 $entry[$networkId] = NULL;
1498 $networkParamsData[$key] = $entry[$networkId];
1501 // Update the network data
1502 $updated += doNetworkUpdateParamsByArray($networkId, $networkParamsData);
1506 // Is there updates?
1509 displayMessage('{%message,ADMIN_NETWORK_REQUEST_PARAMETER_UPDATED=' . $updated . '%}');
1512 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_CHANGED--}');
1517 // Changes given network array translations
1518 function doAdminNetworkProcessChangeArrayTranslations () {
1519 // Is there selections?
1520 if (ifPostContainsSelections()) {
1521 // By default nothing is updated
1524 // Something has been selected, so start updating them
1525 foreach (postRequestElement('sel') as $networkId => $sel) {
1526 // Update this entry?
1529 $networkTranslationsData = array();
1531 // Transfer whole array, except 'sel'
1532 foreach (postRequestArray() as $key => $entry) {
1533 // Skip 'sel' and submit button
1534 if (in_array($key, array('sel', 'do_edit'))) {
1538 // Is there this enty?
1539 if (!isset($entry[$networkId])) {
1540 // Not found, needs fixing
1541 reportBug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1544 // Fix empty network_request_param_default to NULL
1545 if (($key == 'network_request_param_default') && (trim($entry[$networkId]) == '')) {
1547 $entry[$networkId] = NULL;
1551 $networkTranslationsData[$key] = $entry[$networkId];
1554 // Update the network data
1555 $updated += doNetworkUpdateArrayTranslationsByArray($networkId, $networkTranslationsData);
1559 // Is there updates?
1562 displayMessage('{%message,ADMIN_NETWORK_ARRAY_TRANSLATION_UPDATED=' . $updated . '%}');
1565 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_ARRAY_TRANSLATION_NOTHING_CHANGED--}');
1570 // Removes given network type handlers
1571 function doAdminNetworkProcessRemoveNetworkTypes () {
1572 // Is there selections?
1573 if (ifPostContainsSelections()) {
1574 // By default nothing is removed
1577 // Something has been selected, so start updating them
1578 foreach (postRequestElement('sel') as $networkId => $sel) {
1579 // Update this entry?
1581 // Remove this entry
1582 $removed += doAdminRemoveNetworkEntry('types', 'network_type_id', $networkId);
1586 // Is there removes?
1589 displayMessage('{%message,ADMIN_NETWORK_TYPE_HANDLER_REMOVED=' . $removed . '%}');
1592 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPE_HANDLER_NOTHING_REMOVED--}');
1597 // Removes given network request parameters
1598 function doAdminNetworkProcessRemoveNetworkRequestParams () {
1599 // Is there selections?
1600 if (ifPostContainsSelections()) {
1601 // By default nothing is removed
1604 // Something has been selected, so start updating them
1605 foreach (postRequestElement('sel') as $networkId => $sel) {
1606 // Update this entry?
1608 // Remove this entry
1609 $removed += doAdminRemoveNetworkEntry('request_params', 'network_request_param_id', $networkId);
1613 // Is there removes?
1616 displayMessage('{%message,ADMIN_NETWORK_REQUEST_PARAMETER_REMOVED=' . $removed . '%}');
1619 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_REMOVED--}');
1624 // Removes given network array translations
1625 function doAdminNetworkProcessRemoveNetworkArrayTranslation () {
1626 // Is there selections?
1627 if (ifPostContainsSelections()) {
1628 // By default nothing is removed
1631 // Something has been selected, so start updating them
1632 foreach (postRequestElement('sel') as $networkId => $sel) {
1633 // Update this entry?
1635 // Remove this entry
1636 $removed += doAdminRemoveNetworkEntry('array_translation', 'network_array_id', $networkId);
1640 // Is there removes?
1643 displayMessage('{%message,ADMIN_NETWORK_ARRAY_TRANSLATION_REMOVED=' . $removed . '%}');
1646 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_ARRAY_TRANSLATION_NOTHING_REMOVED--}');
1651 // Adds a request parameter to given network and type
1652 function doAdminNetworkProcessAddRequestParam () {
1653 // Is the request parameter already used with given network?
1654 if (isNetworkRequestElementValid(postRequestElement('network_request_param_key'), postRequestElement('network_type_id'), getRequestElement('network_id'))) {
1656 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_REQUEST_PARAMETER_ALREADY_ADDED=' . postRequestElement('network_request_param_key') . '%}');
1658 // ... so abort here
1662 // Remove the 'ok' part
1663 unsetPostRequestElement('ok');
1666 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1668 // Is network_request_param_default set?
1669 if (postRequestElement('network_request_param_default') == '') {
1670 // Remove empty value to get a NULL for an optional entry
1671 unsetPostRequestElement('network_request_param_default');
1674 // Add the whole request to database
1675 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_request_params'), __FUNCTION__, __LINE__);
1678 if (!SQL_HASZEROAFFECTED()) {
1679 // Successfully added
1680 loadTemplate('admin_network_request_param_added', false, postRequestArray());
1683 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_REQUEST_PARAMETER_NOT_ADDED=' . postRequestElement('network_request_param_key') . '%}');
1687 // Adds a vheck request parameter to given network
1688 function doAdminNetworkProcessAddVcheckParam () {
1689 // Is the request parameter already used with given network?
1690 if (isNetworkVcheckElementValid(postRequestElement('network_vcheck_param_key'), getRequestElement('network_id'))) {
1692 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_VCHECK_PARAMETER_ALREADY_ADDED=' . postRequestElement('network_vcheck_param_key') . '%}');
1694 // ... so abort here
1698 // Remove the 'ok' part
1699 unsetPostRequestElement('ok');
1702 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1704 // Is network_vcheck_param_default set?
1705 if (postRequestElement('network_vcheck_param_default') == '') {
1706 // Remove empty value to get a NULL for an optional entry
1707 unsetPostRequestElement('network_vcheck_param_default');
1710 // Add the whole vcheck to database
1711 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_vcheck_params'), __FUNCTION__, __LINE__);
1714 if (!SQL_HASZEROAFFECTED()) {
1715 // Successfully added
1716 loadTemplate('admin_network_vcheck_param_added', false, postRequestArray());
1719 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_VCHECK_PARAMETER_NOT_ADDED=' . postRequestElement('network_vcheck_param_key') . '%}');
1723 // Adds a API response array entry
1724 function doAdminNetworkProcessAddNetworkArrayTranslation () {
1725 // Is the request parameter already used with given network?
1726 if (isNetworkArrayTranslationValid(postRequestElement('network_array_index'), postRequestElement('network_type_id'), getRequestElement('network_id'))) {
1728 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_ARRAY_TRANSLATION_ALREADY_ADDED=' . postRequestElement('network_array_index') . '%}');
1730 // ... so abort here
1734 // Remove the 'ok' part
1735 unsetPostRequestElement('ok');
1738 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1741 setPostRequestElement('network_array_sort', (countSumTotalData(
1742 bigintval(postRequestElement('network_id')),
1743 'network_array_translation',
1747 sprintf(" AND `network_type_id`=%s", bigintval(postRequestElement('network_type_id')))
1750 // Add the whole request to database
1751 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_array_translation'), __FUNCTION__, __LINE__);
1754 if (!SQL_HASZEROAFFECTED()) {
1755 // Successfully added
1756 loadTemplate('admin_network_array_translation_added', false, postRequestArray());
1759 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_ARRAY_TRANSLATION_NOT_ADDED=' . postRequestElement('network_array_index') . '%}');
1763 // Handle network array translation form
1764 function doAdminNetworkProcessHandleArrayTranslations () {
1765 // Is there selections?
1766 if (ifPostContainsSelections()) {
1768 $GLOBALS['network_array_translation_disabled'] = array();
1770 // Load network data
1771 $networkData = getNetworkDataById(getRequestElement('network_id'));
1773 // Something has been selected, so start displaying one by one
1775 foreach (postRequestElement('sel') as $networkId => $sel) {
1776 // Is this selected?
1778 // Load this network's data
1779 $networkTranslationsData = getNetworkArrayTranslationsDataById($networkId);
1781 // Is there found the network?
1782 if (count($networkTranslationsData) > 0) {
1783 if (isFormSent('edit')) {
1784 // Add row template for deleting
1785 $OUT .= loadTemplate('admin_edit_network_array_translation_row', true, $networkTranslationsData);
1786 } elseif (isFormSent('delete')) {
1788 $networkTranslationsData['network_type_data'] = getNetworkTypeDataById($networkTranslationsData['network_type_id']);
1790 // Add row template for deleting
1791 $OUT .= loadTemplate('admin_delete_network_array_translation_row', true, $networkTranslationsData);
1794 reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/delete.');
1800 // If we have no rows, we don't need to display the edit form
1802 // Output main template
1803 if (isFormSent('edit')) {
1804 loadTemplate('admin_edit_network_array_translation', false, $OUT);
1805 } elseif (isFormSent('delete')) {
1806 loadTemplate('admin_delete_network_array_translation', false, $OUT);
1809 reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/delete.');
1812 // Don't display the list/add new form
1813 $GLOBALS['network_display'] = false;
1815 // Nothing selected/found
1816 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_FOUND--}');
1821 // Adds/update network API configuration
1822 function doAdminNetworkProcessNetworkApiConfig () {
1823 // Remove the 'ok' part
1824 unsetPostRequestElement('ok');
1827 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1829 // Is network_api_referral_button set?
1830 if (postRequestElement('network_api_referral_button') == '') {
1831 // Remove empty value to get a NULL for an optional entry
1832 unsetPostRequestElement('network_api_referral_button');
1835 // Is there already an entry?
1836 if (isNetworkApiConfigured(getRequestElement('network_id'))) {
1837 // Generate SQL query
1838 $SQL = getUpdateSqlFromArray(postRequestArray(), 'network_api_config', 'network_id', postRequestElement('network_id'), array('network_id'));
1841 $SQL = getInsertSqlFromArray(postRequestArray(), 'network_api_config');
1845 SQL_QUERY($SQL, __FUNCTION__, __LINE__);
1848 if (!SQL_HASZEROAFFECTED()) {
1849 // Successfully added
1850 displayMessage('{--ADMIN_CONFIG_NETWORK_API_SAVED--}');
1853 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_API_NOT_SAVED--}');
1857 // Only adds network type configuration if not yet present
1858 function doAdminNetworkProcessAddHandlerTypesConfig ($displayMessage = true) {
1859 // Remove the 'ok' part
1860 unsetPostRequestElement('ok');
1863 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1864 setPostRequestElement('network_type_id', bigintval(getRequestElement('network_type_id')));
1867 * Some parameters are optional, at least one must be given so check a bunch
1870 foreach (array('network_min_waiting_time', 'network_min_remain_clicks', 'network_min_payment', 'network_allow_erotic') as $element) {
1871 // Is this element empty?
1872 if (postRequestElement($element) == '') {
1873 // Then unset it to get a NULL for optional parameter
1874 unsetPostRequestElement($element);
1878 // Convert data in POST array
1879 convertSelectionsToEpocheTimeInPostData($content, 'network_max_reload_time_ye', $skip);
1881 // Is there already an entry?
1882 if (isNetworkTypeHandlerConfigured(getRequestElement('network_id'), getRequestElement('network_type_id'))) {
1883 // This network type handler is already configured
1884 displayMessage('{--ADMIN_NETWORK_HANDLER_TYPE_HANDLER_ALREADY_CONFIGURED--}');
1888 // Copy 'set all' and remove it from POST data
1889 $setAll = (postRequestElement('set_all') === 'Y');
1890 unsetPostRequestElement('set_all');
1892 // Shall we set for all?
1893 if ($setAll === true) {
1895 $result = SQL_QUERY_ESC('SELECT `network_type_id` FROM `{?_MYSQL_PREFIX?}_network_types` WHERE `network_id`=%s ORDER BY `network_type_id` ASC',
1896 array(bigintval(getRequestElement('network_id'))), __FUNCTION__, __LINE__);
1898 // Are there entries?
1899 if (SQL_HASZERONUMS($result)) {
1900 // No, then abort here
1901 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_SET_ALL_404--}');
1905 // Init number of rows
1909 while (list($typeId) = SQL_FETCHROW($result)) {
1910 // Set it in GET data
1911 setGetRequestElement('network_type_id', $typeId);
1913 // Call this function again
1914 $numRows += doAdminNetworkProcessAddHandlerTypesConfig(false);
1918 SQL_FREERESULT($result);
1922 // Something has been updated
1923 displayMessage('{%message,ADMIN_CONFIG_NETWORK_HANDLER_TYPE_ALL_HANDLER_SAVED=' . bigintval($numRows) . '%}');
1925 // Nothing has been saved
1926 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}');
1929 // Get SQL query for new entry
1930 $SQL = getInsertSqlFromArray(postRequestArray(), 'network_types_config');
1933 SQL_QUERY($SQL, __FUNCTION__, __LINE__);
1935 // Shall we display the message?
1936 if ($displayMessage === true) {
1938 if (!SQL_HASZEROAFFECTED()) {
1939 // Successfully added
1940 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_SAVED--}');
1943 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_SAVED--}');
1946 // Return amount of affected rows (1 or 2)
1947 return SQL_AFFECTEDROWS();
1952 // Only changes network type configuration if not yet present
1953 function doAdminNetworkProcessEditHandlerTypesConfig ($displayMessage = true) {
1954 // Remove the 'ok' part
1955 unsetPostRequestElement('ok');
1958 * Some parameters are optional, at least one must be given so check a bunch
1961 foreach (array('network_min_waiting_time', 'network_min_remain_clicks', 'network_min_payment', 'network_allow_erotic') as $element) {
1962 // Is this element empty?
1963 if (postRequestElement($element) == '') {
1964 // Then unset it to get a NULL for optional parameter
1965 unsetPostRequestElement($element);
1969 // Convert time selections in POST data
1970 convertSelectionsToEpocheTimeInPostArray('network_max_reload_time_ye');
1972 // Is there already an entry?
1973 if (!isNetworkTypeHandlerConfigured(getRequestElement('network_id'), getRequestElement('network_type_id'))) {
1974 // This network type handler is not configured
1975 displayMessage('{--ADMIN_NETWORK_HANDLER_TYPE_HANDLER_NOT_CONFIGURED--}');
1979 // Copy 'set all' and remove it from POST data
1980 $setAll = (postRequestElement('set_all') === 'Y');
1981 unsetPostRequestElement('set_all');
1983 // Shall we set for all?
1984 if ($setAll === true) {
1985 // Get all data entries
1986 $result = SQL_QUERY_ESC('SELECT `network_data_id` FROM `{?_MYSQL_PREFIX?}_network_types_config` WHERE `network_id`=%s ORDER BY `network_type_id` ASC',
1987 array(bigintval(getRequestElement('network_id'))), __FUNCTION__, __LINE__);
1989 // Are there entries?
1990 if (SQL_HASZERONUMS($result)) {
1991 // No, then abort here
1992 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_SET_ALL_404--}');
1996 // Init number of rows
2000 while (list($dataId) = SQL_FETCHROW($result)) {
2001 // Set it in GET data
2002 setPostRequestElement('network_data_id', $dataId);
2004 // Call this function again
2005 $numRows += doAdminNetworkProcessEditHandlerTypesConfig(false);
2009 SQL_FREERESULT($result);
2013 // Something has been updated
2014 displayMessage('{%message,ADMIN_CONFIG_NETWORK_HANDLER_TYPE_ALL_HANDLER_SAVED=' . bigintval($numRows) . '%}');
2016 // Nothing has been saved
2017 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}');
2020 // Get SQL query for new entry
2021 $SQL = getUpdateSqlFromArray(postRequestArray(), 'network_types_config', 'network_data_id', postRequestElement('network_data_id'), array('network_data_id'));
2024 SQL_QUERY($SQL, __FUNCTION__, __LINE__);
2026 // Shall we display the message?
2027 if ($displayMessage === true) {
2029 if (!SQL_HASZEROAFFECTED()) {
2030 // Successfully added
2031 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_SAVED--}');
2034 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}');
2037 // Return amount of affected rows (1 or 2)
2038 return SQL_AFFECTEDROWS();
2043 // Do expression code for this extension
2044 function doExpressionNetwork ($data) {
2045 // Construct replacer
2046 $replacer = sprintf(
2047 "{DQUOTE} . %s(%s, '%s') . {DQUOTE}",
2049 $data['matches'][4][$data['key']],
2053 // Replace %network_id% with the current network id
2054 $replacer = str_replace('%network_id%', getCurrentNetworkId(), $replacer);
2057 $code = replaceExpressionCode($data, $replacer);
2063 // ----------------------------------------------------------------------------
2064 // Call-back functions for exporting data
2065 // ----------------------------------------------------------------------------
2067 // Callback function to export network tables
2068 function doAdminNetworkProcessExport () {
2069 // Init table with all valid what->table entries
2070 $validExports = array(
2071 // General network data
2072 'list_network_data' => 'data',
2073 // Network type handler
2074 'list_network_types' => 'types',
2075 // Network request parameter
2076 'list_network_request_params' => 'request_params',
2077 // Vcheck request parameter
2078 'list_network_vcheck_params' => 'vcheck_params',
2079 // Network API response array index translation
2080 'list_network_array_translation' => 'array_translation',
2083 // Is the 'what' key valid?
2084 if (!isset($validExports[getWhat()])) {
2086 reportBug(__FUNCTION__, __LINE__, 'what=' . getWhat() . ' - not supported');
2089 // Generate call-back, some tables require to export not all columns
2090 $callbackName = 'doAdminNetworkExport' . capitalizeUnderscoreString($validExports[getWhat()]);
2092 // Is the call-back function there?
2093 if (!function_exists($callbackName)) {
2094 // No, this is really bad
2095 reportBug(__FUNCTION__, __LINE__, 'Invalid call-back function ' . $callbackName . ' detected.');
2096 } elseif (isset($GLOBALS[__FUNCTION__][$callbackName])) {
2098 reportBug(__FUNCTION__, __LINE__, 'Double-call of export function ' . $callbackName . ' detected.');
2101 // Call the function
2102 call_user_func($callbackName);
2104 // Mark it as called
2105 $GLOBALS[__FUNCTION__][$callbackName] = true;
2107 // Don't display the list/add new form
2108 $GLOBALS['network_display'] = false;
2111 // Exports (and displays) the table 'network_data'
2112 function doAdminNetworkExportData () {
2113 // Query for all networks
2114 $result = SQL_QUERY('SELECT
2115 `network_short_name`,
2118 `network_data_separator`,
2119 `network_row_separator`,
2120 `network_request_type`,
2122 `network_require_id_card`,
2123 `network_query_amount`,
2126 `{?_MYSQL_PREFIX?}_network_data`
2129 __FUNCTION__, __LINE__);
2131 // Start an empty SQL query
2132 $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";
2135 while ($content = SQL_FETCHARRAY($result)) {
2138 $content['network_short_name'] . "', '" .
2139 $content['network_title'] . "', '" .
2140 $content['network_reflink'] . "', '" .
2141 $content['network_data_separator'] . "', '" .
2142 $content['network_row_separator'] . "', '" .
2143 $content['network_request_type'] . "', '" .
2144 $content['network_charset'] . "', '" .
2145 $content['network_require_id_card'] . "', " .
2146 $content['network_query_amount'] . ", '" .
2147 $content['network_active'] . "'),\n";
2150 // Remove last commata and close braces
2151 $SQL = substr($SQL, 0, -2);
2154 SQL_FREERESULT($result);
2156 // Output the SQL query
2157 loadTemplate('admin_export_network_data', false, $SQL);
2160 // Exports (and displays) the table 'network_types'
2161 function doAdminNetworkExportTypes () {
2162 // 'network_id' must be set
2163 if (!isGetRequestElementSet('network_id')) {
2164 // Only network handlers of one network will be exported per time
2165 reportBug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
2168 // Get all network types of given network
2169 $result = SQL_QUERY_ESC('SELECT
2172 `network_type_handler`,
2173 `network_type_api_url`,
2174 `network_type_click_url`,
2175 `network_type_banner_url`,
2176 `network_type_reload_time_unit`,
2177 `network_text_encoding`
2179 `{?_MYSQL_PREFIX?}_network_types`
2183 `network_type_id` ASC',
2185 bigintval(getRequestElement('network_id'))
2186 ), __FUNCTION__, __LINE__);
2188 // Start an empty SQL query
2189 $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";
2192 while ($content = SQL_FETCHARRAY($result)) {
2195 $content['network_type_id'] . ', ' .
2196 $content['network_id'] . ", '" .
2197 $content['network_type_handler'] . "', '" .
2198 $content['network_type_api_url'] . "', '" .
2199 $content['network_type_click_url'] . "', ";
2201 // Is the column NULL?
2202 if (is_null($content['network_type_banner_url'])) {
2207 $SQL .= chr(39) . $content['network_type_banner_url'] . chr(39);
2211 $SQL .= ",'" . $content['network_type_reload_time_unit'] . "','" . $content['network_text_encoding'] . "'),\n";
2214 // Remove last commata and close braces
2215 $SQL = substr($SQL, 0, -2);
2218 SQL_FREERESULT($result);
2220 // Output the SQL query
2221 loadTemplate('admin_export_network_types', false, $SQL);
2224 // Exports (and displays) the table 'network_request_params'
2225 function doAdminNetworkExportRequestParams () {
2226 // 'network_id' must be set
2227 if (!isGetRequestElementSet('network_id')) {
2228 // Only network request parameters of one network will be exported per time
2229 reportBug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
2232 // Get all network types of given network
2233 $result = SQL_QUERY_ESC('SELECT
2236 `network_request_param_key`,
2237 `network_request_param_value`,
2238 `network_request_param_default`
2240 `{?_MYSQL_PREFIX?}_network_request_params`
2244 `network_type_id` ASC ,
2245 `network_request_param_id` ASC',
2247 bigintval(getRequestElement('network_id'))
2248 ), __FUNCTION__, __LINE__);
2250 // Start an empty SQL query
2251 $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";
2254 while ($content = SQL_FETCHARRAY($result)) {
2257 $content['network_id'] . ', ' .
2258 $content['network_type_id'] . ", '" .
2259 $content['network_request_param_key'] . "', '" .
2260 $content['network_request_param_value'] . "', ";
2262 // Is the column NULL?
2263 if (is_null($content['network_request_param_default'])) {
2268 $SQL .= chr(39) . $content['network_request_param_default'] . "'),\n";
2272 // Remove last commata and close braces
2273 $SQL = substr($SQL, 0, -2);
2276 SQL_FREERESULT($result);
2278 // Output the SQL query
2279 loadTemplate('admin_export_network_request_params', false, $SQL);
2282 // Exports (and displays) the table 'network_vcheck_params'
2283 function doAdminNetworkExportVcheckParams () {
2284 // 'network_id' must be set
2285 if (!isGetRequestElementSet('network_id')) {
2286 // Only network vcheck parameters of one network will be exported per time
2287 reportBug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
2290 // Get all network types of given network
2291 $result = SQL_QUERY_ESC('SELECT
2293 `network_vcheck_param_key`,
2294 `network_vcheck_param_value`,
2295 `network_vcheck_param_default`
2297 `{?_MYSQL_PREFIX?}_network_vcheck_params`
2301 `network_vcheck_param_id` ASC',
2303 bigintval(getRequestElement('network_id'))
2304 ), __FUNCTION__, __LINE__);
2306 // Start an empty SQL query
2307 $SQL = "INSERT INTO `{?_MYSQL_PREFIX?}_network_vcheck_params` (`network_id`, `network_vcheck_param_key`, `network_vcheck_param_value`, `network_vcheck_param_default`) VALUES\n";
2310 while ($content = SQL_FETCHARRAY($result)) {
2313 $content['network_id'] . ", '" .
2314 $content['network_vcheck_param_key'] . "', '" .
2315 $content['network_vcheck_param_value'] . "', ";
2317 // Is the column NULL?
2318 if (is_null($content['network_vcheck_param_default'])) {
2323 $SQL .= chr(39) . $content['network_vcheck_param_default'] . "'),\n";
2327 // Remove last commata and close braces
2328 $SQL = substr($SQL, 0, -2);
2331 SQL_FREERESULT($result);
2333 // Output the SQL query
2334 loadTemplate('admin_export_network_vcheck_params', false, $SQL);
2337 // Exports (and displays) the table 'network_array_translation'
2338 function doAdminNetworkExportArrayTranslation () {
2339 // 'network_id' must be set
2340 if (!isGetRequestElementSet('network_id')) {
2341 // Only network API array index translations of one network will be exported per time
2342 reportBug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
2345 // Get all network types of given network
2346 $result = SQL_QUERY_ESC('SELECT
2349 `network_array_index`,
2350 `network_array_sort`
2352 `{?_MYSQL_PREFIX?}_network_array_translation`
2356 `network_type_id` ASC,
2357 `network_array_sort` ASC',
2359 bigintval(getRequestElement('network_id'))
2360 ), __FUNCTION__, __LINE__);
2362 // Start an empty SQL query
2363 $SQL = "INSERT INTO `{?_MYSQL_PREFIX?}_network_array_translation` (`network_id`, `network_type_id`, `network_array_index`, `network_array_sort`) VALUES\n";
2366 while ($content = SQL_FETCHARRAY($result)) {
2369 $content['network_id'] . ', ' .
2370 $content['network_type_id'] . ', ' .
2371 $content['network_array_index'] . ', ' .
2372 $content['network_array_sort'] . "),\n";
2375 // Remove last commata and close braces
2376 $SQL = substr($SQL, 0, -2);
2379 SQL_FREERESULT($result);
2381 // Output the SQL query
2382 loadTemplate('admin_export_network_array_translation', false, $SQL);