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 - 2013 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 // Checks whether the current network id is set
54 function isCurrentNetworkIdSet () {
56 return isset($GLOBALS['current_network_id']);
59 // Getter for network_form_name
60 function getNetworkFormName () {
61 return $GLOBALS['network_form_name'];
64 // Setter for network_form_name
65 function setNetworkFormName ($networkFormName) {
66 $GLOBALS['network_form_name'] = (string) $networkFormName;
69 // Detects if a supported form has been sent
70 function detectNetworkProcessForm () {
71 // 'do' must be provided in URL
72 if (!isGetRequestElementSet('do')) {
74 reportBug(__FUNCTION__, __LINE__, 'No "do" has been provided. Please fix your templates.');
78 setNetworkFormName('invalid');
80 // Now search all valid
81 foreach (array('save_config', 'add', 'edit', 'delete', 'do_edit', 'do_delete') as $formName) {
83 if (isFormSent($formName)) {
85 setNetworkFormName($formName);
87 // Remove it generically here
88 unsetPostRequestElement($formName);
95 // Has the form being detected?
96 if (getNetworkFormName() == 'invalid') {
98 reportBug(__FUNCTION__, __LINE__, 'POST form could not be detected, postData=<pre>' . print_r(postRequestArray(), TRUE));
102 // Handle a (maybe) sent form here
103 function doNetworkHandleForm () {
104 // Is there a form sent?
105 if ((!isPostRequestElementSet('save_expert')) && (countRequestPost() > 0)) {
106 // Detect sent POST form
107 detectNetworkProcessForm();
108 } elseif (!isGetRequestElementSet('do')) {
109 // Skip any further requests
111 } elseif ((getHttpRequestMethod() != 'POST') && (getRequestElement('do') != 'export')) {
112 // Do not process non-POST requests that are not 'do=export'
116 // Process the request
117 doAdminNetworkProcessForm();
120 // Processes an admin form
121 function doAdminNetworkProcessForm () {
122 // Create function name
123 $functionName = sprintf('doAdminNetworkProcess%s', capitalizeUnderscoreString(getRequestElement('do')));
125 // Is the function valid?
126 if (!function_exists($functionName)) {
127 // Invalid function name
128 reportBug(__FUNCTION__, __LINE__, 'Invalid do ' . getRequestElement('do') . ', function ' . $functionName .' does not exist.', FALSE);
131 // Init global arrays
132 $GLOBALS['network_types_disabled'] = array();
134 // Call-back the method handling our request
135 call_user_func($functionName);
138 // Checks whether the (short) network name is already used (valid)
139 function isNetworkNameValid ($name) {
141 if (!isset($GLOBALS[__FUNCTION__][$name])) {
143 $GLOBALS[__FUNCTION__][$name] = (countSumTotalData($name, 'network_data', 'network_id', 'network_short_name', TRUE) == 1);
147 return $GLOBALS[__FUNCTION__][$name];
150 // Checks whether the (short) named network is activated
151 function isNetworkActiveByShortName ($name) {
153 if (!isset($GLOBALS[__FUNCTION__][$name])) {
155 $GLOBALS[__FUNCTION__][$name] = ((isNetworkNameValid($name)) && (countSumTotalData($name, 'network_data', 'network_id', 'network_short_name', TRUE, " AND `network_active`='Y'") == 1));
159 return $GLOBALS[__FUNCTION__][$name];
162 // Checks whether the network by given id is activated
163 function isNetworkActiveById ($networkId) {
165 if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
167 $GLOBALS[__FUNCTION__][$networkId] = (countSumTotalData(bigintval($networkId), 'network_data', 'network_id', 'network_id', TRUE, " AND `network_active`='Y'") == 1);
171 return $GLOBALS[__FUNCTION__][$networkId];
174 // "Getter" for 'network_activated' column depending on current administrator's expert setting
175 function getNetworkActivatedColumn ($whereAnd = 'WHERE', $table = '') {
177 if (!isset($GLOBALS[__FUNCTION__][$whereAnd][$table])) {
178 // Default is exclude deactivated networks
179 $GLOBALS[__FUNCTION__][$whereAnd][$table] = ' ' . $whereAnd . ' ' . $table . "`network_active`='Y'";
181 // Is the export setting on and debug mode enabled?
182 if ((isAdminsExpertSettingEnabled()) && (isDebugModeEnabled())) {
183 // Then allow all networks
184 $GLOBALS[__FUNCTION__][$whereAnd][$table] = '';
189 return $GLOBALS[__FUNCTION__][$whereAnd][$table];
192 // Checks whether the given network type is already used (valid)
193 function isNetworkTypeHandleValid ($type, $networkId) {
195 if (!isset($GLOBALS[__FUNCTION__][$networkId][$type])) {
197 $GLOBALS[__FUNCTION__][$networkId][$type] = (countSumTotalData(bigintval($networkId), 'network_types', 'network_type_id', 'network_id', TRUE, sprintf(" AND `network_type_handler`='%s'", sqlEscapeString($type))) == 1);
201 return $GLOBALS[__FUNCTION__][$networkId][$type];
204 // Checks whether the given network request parameter is already used (valid)
205 function isNetworkRequestElementValid ($key, $networkTypeId, $networkId) {
207 if (!isset($GLOBALS[__FUNCTION__][$networkId][$networkTypeId][$key])) {
209 $GLOBALS[__FUNCTION__][$networkId][$networkTypeId][$key] = (countSumTotalData(bigintval($networkId), 'network_request_params', 'network_request_param_id', 'network_id', TRUE, sprintf(" AND `network_type_id`=%s AND `network_request_param_key`='%s'", bigintval($networkTypeId), sqlEscapeString($key))) == 1);
213 return $GLOBALS[__FUNCTION__][$networkId][$networkTypeId][$key];
216 // Checks whether the given network API array translation
217 function isNetworkArrayTranslationValid ($key, $networkTypeId, $networkId) {
219 if (!isset($GLOBALS[__FUNCTION__][$networkId][$networkTypeId][$key])) {
221 $GLOBALS[__FUNCTION__][$networkId][$networkTypeId][$key] = (countSumTotalData(bigintval($networkId), 'network_array_translation', 'network_array_id', 'network_id', TRUE, sprintf(" AND `network_type_id`=%s AND `network_array_index`='%s'", bigintval($networkTypeId), sqlEscapeString($key))) == 1);
225 return $GLOBALS[__FUNCTION__][$networkId][$networkTypeId][$key];
228 // "Getter" for a network's data by provided id number
229 function getNetworkDataFromId ($networkId, $column = '') {
230 // Ids lower one are not accepted
231 if (!isValidId($networkId)) {
232 // Not good, should be fixed
233 reportBug(__FUNCTION__, __LINE__, 'Network id ' . $networkId . ' is smaller than 1.');
234 } elseif ((!isNetworkActiveById($networkId)) && (!isAdminsExpertSettingEnabled())) {
235 // Do not load inactive network data
236 reportBug(__FUNCTION__, __LINE__, 'Network id ' . $networkId . ' is not active.');
239 // Set current network id
240 setCurrentNetworkId($networkId);
243 if (!isset($GLOBALS['network_data'][$networkId])) {
244 // By default there is no data
245 $GLOBALS['network_data'][$networkId] = array();
247 // Query for the network data
248 $result = sqlQueryEscaped('SELECT
250 `network_short_name`,
253 `network_data_separator`,
254 `network_row_separator`,
255 `network_request_type`,
257 `network_require_id_card`,
258 `network_query_amount`
260 `{?_MYSQL_PREFIX?}_network_data`
264 array(bigintval($networkId)), __FUNCTION__, __LINE__);
266 // Is there an entry?
267 if (sqlNumRows($result) == 1) {
269 $GLOBALS['network_data'][$networkId] = sqlFetchArray($result);
273 sqlFreeResult($result);
277 if ((empty($column)) && (isset($GLOBALS['network_data'][$networkId]))) {
279 return $GLOBALS['network_data'][$networkId];
280 } elseif (isset($GLOBALS['network_data'][$networkId][$column])) {
282 return $GLOBALS['network_data'][$networkId][$column];
289 // "Getter" for a network's data by provided type id number
290 function getNetworkDataByTypeId ($networkTypeId, $column = '') {
291 // Ids lower one are not accepted
292 if (!isValidId($networkTypeId)) {
293 // Not good, should be fixed
294 reportBug(__FUNCTION__, __LINE__, 'Network type id ' . $networkTypeId . ' is smaller than 1.');
298 if (!isset($GLOBALS['network_type_data'][$networkTypeId])) {
299 // By default there is no data
300 $GLOBALS['network_type_data'][$networkTypeId] = array();
302 // Query for the network data
303 $result = sqlQueryEscaped('SELECT
305 `d`.`network_short_name`,
307 `d`.`network_reflink`,
308 `d`.`network_data_separator`,
309 `d`.`network_row_separator`,
310 `d`.`network_request_type`,
311 `d`.`network_charset`,
312 `d`.`network_require_id_card`,
313 `d`.`network_query_amount`,
314 `d`.`network_active`,
315 `t`.`network_type_id`,
316 `t`.`network_type_handler`,
317 `t`.`network_type_api_url`,
318 `t`.`network_type_click_url`,
319 `t`.`network_type_banner_url`,
320 `t`.`network_text_encoding`
322 `{?_MYSQL_PREFIX?}_network_data` AS `d`
324 `{?_MYSQL_PREFIX?}_network_types` AS `t`
326 `d`.`network_id`=`t`.`network_id`
328 `t`.`network_type_id`=%s
330 array(bigintval($networkTypeId)), __FUNCTION__, __LINE__);
332 // Is there an entry?
333 if (sqlNumRows($result) == 1) {
335 $GLOBALS['network_type_data'][$networkTypeId] = sqlFetchArray($result);
339 sqlFreeResult($result);
343 if (!isset($GLOBALS['network_type_data'][$networkTypeId])) {
346 } elseif (empty($column)) {
348 return $GLOBALS['network_type_data'][$networkTypeId];
351 return $GLOBALS['network_type_data'][$networkTypeId][$column];
355 // "Getter" for a network type data by provided id number
356 function getNetworkTypeDataByTypeId ($networkTypeId) {
357 // Ids lower one are not accepted
358 if (!isValidId($networkTypeId)) {
359 // Not good, should be fixed
360 reportBug(__FUNCTION__, __LINE__, 'Network type id ' . $networkTypeId . ' is smaller than 1.');
364 if (!isset($GLOBALS['network_type_data'][$networkTypeId])) {
365 // By default there is no data
366 $GLOBALS['network_type_data'][$networkTypeId] = array();
368 // Query for the network data
369 $result = sqlQueryEscaped('SELECT
372 `network_type_handler`,
373 `network_type_api_url`,
374 `network_type_click_url`,
375 `network_type_banner_url`
377 `{?_MYSQL_PREFIX?}_network_types`
381 array(bigintval($networkTypeId)), __FUNCTION__, __LINE__);
383 // Is there an entry?
384 if (sqlNumRows($result) == 1) {
386 $GLOBALS['network_type_data'][$networkTypeId] = sqlFetchArray($result);
390 sqlFreeResult($result);
394 return $GLOBALS['network_type_data'][$networkTypeId];
397 // "Getter" for all network type data by provided id number
398 function getNetworkTypeDataFromId ($networkId) {
399 // Ids lower one are not accepted
400 if (!isValidId($networkId)) {
401 // Not good, should be fixed
402 reportBug(__FUNCTION__, __LINE__, 'Network type id ' . $networkId . ' is smaller than 1.');
406 if (!isset($GLOBALS['network_types'][$networkId])) {
407 // By default there is no data
408 $GLOBALS['network_types'][$networkId] = array();
410 // Query for the network data
411 $result = sqlQueryEscaped('SELECT
414 `network_type_handler`,
415 `network_type_api_url`,
416 `network_type_click_url`,
417 `network_type_banner_url`
419 `{?_MYSQL_PREFIX?}_network_types`
423 `network_type_id` ASC',
424 array(bigintval($networkId)), __FUNCTION__, __LINE__);
426 // Is there an entry?
427 if (!ifSqlHasZeroNums($result)) {
429 while ($row = sqlFetchArray($result)) {
430 // Add it with new index as it is no longer required
431 $GLOBALS['network_types'][$networkId][] = $row;
436 sqlFreeResult($result);
440 return $GLOBALS['network_types'][$networkId];
443 // "Getter" for a network request parameter data by provided id number
444 function getNetworkRequestParamsDataFromId ($networkRequestId) {
445 // Ids lower one are not accepted
446 if (!isValidId($networkRequestId)) {
447 // Not good, should be fixed
448 reportBug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $networkRequestId . ' is smaller than 1.');
451 // By default there is no data
452 $networkRequestData = array();
454 // Query for the network data
455 $result = sqlQueryEscaped('SELECT
456 `network_request_param_id`,
459 `network_request_param_key`,
460 `network_request_param_value`,
461 `network_request_param_default`
463 `{?_MYSQL_PREFIX?}_network_request_params`
465 `network_request_param_id`=%s
467 array(bigintval($networkRequestId)), __FUNCTION__, __LINE__);
469 // Is there an entry?
470 if (sqlNumRows($result) == 1) {
472 $networkRequestData = sqlFetchArray($result);
476 sqlFreeResult($result);
479 return $networkRequestData;
482 // "Getter" for a network array translation data by provided id number
483 function getNetworkArrayTranslationsDataFromId ($networkTranslationId) {
484 // Ids lower one are not accepted
485 if (!isValidId($networkTranslationId)) {
486 // Not good, should be fixed
487 reportBug(__FUNCTION__, __LINE__, 'Network array translation id ' . $networkTranslationId . ' is smaller than 1.');
490 // By default there is no data
491 $networkTranslationData = array();
493 // Query for the network data
494 $result = sqlQueryEscaped('SELECT
498 `network_array_index`,
501 `{?_MYSQL_PREFIX?}_network_array_translation`
503 `network_array_id`=%s
505 array(bigintval($networkTranslationId)), __FUNCTION__, __LINE__);
507 // Is there an entry?
508 if (sqlNumRows($result) == 1) {
510 $networkTranslationData = sqlFetchArray($result);
514 sqlFreeResult($result);
517 return $networkTranslationData;
520 // "Getter" for network query request parameters
521 function getNetworkRequestParametersByTypeId ($networkTypeId) {
522 // Ids lower one are not accepted
523 if (!isValidId($networkTypeId)) {
524 // Not good, should be fixed
525 reportBug(__FUNCTION__, __LINE__, 'Network type id ' . $networkTypeId . ' is smaller than 1.');
529 if (!isset($GLOBALS['network_request_parameters'][$networkTypeId])) {
530 // By default there is no data
531 $GLOBALS['network_request_parameters'][$networkTypeId] = array();
534 $result = sqlQueryEscaped('SELECT
537 `network_request_param_key`,
538 `network_request_param_value`,
539 `network_request_param_default`
541 `{?_MYSQL_PREFIX?}_network_request_params`
545 `network_request_param_id` ASC',
547 bigintval($networkTypeId)
548 ), __FUNCTION__, __LINE__);
550 // Are there records?
551 if (!ifSqlHasZeroNums($result)) {
552 // Load all but make new indexes as the old are not required
553 while ($row = sqlFetchArray($result)) {
555 $GLOBALS['network_request_parameters'][$networkTypeId][] = $row;
560 sqlFreeResult($result);
563 // Return "cached" values
564 return $GLOBALS['network_request_parameters'][$networkTypeId];
567 // "Getter" for network configuration + handler config for given network type handler id
568 function getFullNetworkConfigurationByTypeId ($networkTypeId) {
569 // Ids lower one are not accepted
570 if (!isValidId($networkTypeId)) {
571 // Not good, should be fixed
572 reportBug(__FUNCTION__, __LINE__, 'Network type id ' . $networkTypeId . ' is smaller than 1.');
576 if (!isset($GLOBALS['network_full_config'][$networkTypeId])) {
577 // By default there is no data
578 $GLOBALS['network_full_config'][$networkTypeId] = array();
581 $result = sqlQueryEscaped('SELECT
583 `ntc`.`network_type_id`,
584 `nac`.`network_api_affiliate_id`,
585 `nac`.`network_api_password`,
586 `nac`.`network_api_site_id`,
587 `nac`.`network_api_active`,
588 `nac`.`network_api_referral_link`,
589 `nac`.`network_api_referral_button`,
590 `nac`.`network_api_remaining_requests`,
591 `nac`.`network_api_visual_pay_check`,
592 `nts`.`network_type_reload_time_unit`,
593 `ntc`.`network_max_reload_time`,
594 `ntc`.`network_min_waiting_time`,
595 `ntc`.`network_max_waiting_time`,
596 `ntc`.`network_min_remain_clicks`,
597 `ntc`.`network_min_remain_budget`,
598 `ntc`.`network_min_payment`,
599 `ntc`.`network_allow_erotic`,
600 `ntc`.`network_media_size`,
601 `ntc`.`network_media_output`
603 `{?_MYSQL_PREFIX?}_network_api_config` AS `nac`
605 `{?_MYSQL_PREFIX?}_network_handler_config` AS `ntc`
607 `nac`.`network_id`=`ntc`.`network_id`
609 `{?_MYSQL_PREFIX?}_network_types` AS `nts`
611 `ntc`.`network_type_id`=`nts`.`network_type_id`
613 `ntc`.`network_type_id`=%s
616 bigintval($networkTypeId)
617 ), __FUNCTION__, __LINE__);
619 // Is there one entry?
620 if (sqlNumRows($result) == 1) {
622 $GLOBALS['network_full_config'][$networkTypeId] = sqlFetchArray($result);
626 sqlFreeResult($result);
629 // Return "cached" values
630 return $GLOBALS['network_full_config'][$networkTypeId];
633 // Removes given network entry
634 function doAdminRemoveNetworkEntry ($table, $column, $id, $limit = 1) {
636 sqlQueryEscaped("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_network_%s` WHERE `%s`=%s LIMIT %s",
642 ), __FUNCTION__, __LINE__);
644 // Return affected rows
645 return sqlAffectedRows();
648 // Generates a list of networks for given script and returns it
649 function generateAdminNetworkList ($separated = FALSE, $includeConfigured = TRUE, $includeUnconfigured = TRUE, $extraName = '', $addSql = '') {
653 // Query for all networks
654 $result = sqlQuery('SELECT
656 `network_short_name`,
658 `network_request_type`,
660 `network_require_id_card`,
661 `network_query_amount`,
664 `{?_MYSQL_PREFIX?}_network_data`
665 ' . getNetworkActivatedColumn('WHERE') . '
667 `network_short_name` ASC', __FUNCTION__, __LINE__);
669 // Are there entries?
670 if (!ifSqlHasZeroNums($result)) {
673 while ($row = sqlFetchArray($result)) {
674 // Is this valid, then add it
675 if ((is_array($row)) && (isset($row['network_id']))) {
676 // Exclude configured and is it configured or same for unconfired but only if not separated lists?
677 if (((($includeConfigured === FALSE) && (isNetworkApiConfigured($row['network_id']))) || (($includeUnconfigured === FALSE) && (!isNetworkApiConfigured($row['network_id'])))) && ($separated === FALSE)) {
680 // @TODO Unfinished: } elseif ((!empty($addSql)) && (
684 $rows[$row['network_id']] = $row;
689 if (!isFilledArray($rows)) {
690 // Then return nothing ... ;-)
695 if ($separated === FALSE) {
696 // Exclude un-/configured?
697 if ($includeConfigured === FALSE) {
698 // Exclude configured, so only unconfigured
699 $extraName = '_unconfigured';
700 } elseif ($includeUnconfigured === FALSE) {
701 // Exclude unconfigured, so only configured
702 $extraName = '_configured';
705 // Generate the big selection box
706 $content = generateSelectionBoxFromArray($rows, 'network_id', 'network_id', '', $extraName, 'network');
708 // Generate two small, first configured
709 $content = generateAdminNetworkList(FALSE, TRUE, FALSE, '_configured', $addSql);
711 // Then add unconfigured
712 $content .= generateAdminNetworkList(FALSE, FALSE, TRUE, '_unconfigured', $addSql);
716 $content = displayErrorMessage('{--ADMIN_ENTRIES_404--}');
720 sqlFreeResult($result);
726 // Generator (somewhat getter) for a list of network types for given network id
727 function generateAdminNetworkTypeList ($networkId) {
731 // Query all types of this network
732 $result = sqlQueryEscaped('SELECT
734 `network_type_handler`
736 `{?_MYSQL_PREFIX?}_network_types`
739 ' . getNetworkActivatedColumn('AND') . '
741 `network_type_handler` ASC',
743 bigintval($networkId)
744 ), __FUNCTION__, __LINE__);
746 // Are there entries?
747 if (!ifSqlHasZeroNums($result)) {
750 while ($row = sqlFetchArray($result)) {
751 // Is this valid, then add it
752 if ((is_array($row)) && (isset($row['network_type_id']))) {
754 $rows[$row['network_type_id']] = $row;
758 // Generate the selection box
759 $content = generateSelectionBoxFromArray($rows, 'network_type', 'network_type_id');
762 $content = displayErrorMessage('{--ADMIN_ENTRIES_404--}');
766 sqlFreeResult($result);
772 // Generator (somewhat getter) for a list of network types for all types
773 function generateAdminDistinctNetworkTypeList () {
777 // Query all types of this network
778 $result = sqlQuery('SELECT
779 `t`.`network_type_id`,
780 `t`.`network_type_handler`,
783 `{?_MYSQL_PREFIX?}_network_types` AS `t`
785 `{?_MYSQL_PREFIX?}_network_data` AS `d`
787 `t`.`network_id`=`d`.`network_id`
788 ' . getNetworkActivatedColumn('WHERE', 'd') . '
790 `d`.`network_short_name` ASC,
791 `t`.`network_type_handler` ASC', __FUNCTION__, __LINE__);
793 // Are there entries?
794 if (!ifSqlHasZeroNums($result)) {
797 while ($row = sqlFetchArray($result)) {
798 // Is this valid, then add it
799 if ((is_array($row)) && (isset($row['network_type_id']))) {
801 $rows[$row['network_type_id']] = $row;
805 // Generate the selection box
806 $content = generateSelectionBoxFromArray($rows, 'network_type', 'network_type_id', '', '_title');
809 $content = displayErrorMessage('{--ADMIN_ENTRIES_404--}');
813 sqlFreeResult($result);
814 //* DEBUG: */ die('<pre>'.encodeEntities($content).'</pre>');
820 // Generator (somewhat getter) for network type options
821 function generateNetworkTypeOptions ($networkId) {
822 // Is this an array, then we just came back from edit/delete actions
823 if (is_array($networkId)) {
824 // Set it as empty string
829 if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
830 // Generate output and cache it
831 $GLOBALS[__FUNCTION__][$networkId] = generateOptions(
834 'network_type_handler',
838 "WHERE `network_id`=%s" . getNetworkActivatedColumn('AND'),
839 bigintval(getRequestElement('network_id'))
842 'translateNetworkTypeHandler'
847 return $GLOBALS[__FUNCTION__][$networkId];
850 // Generates an options list of all available (hard-coded) handlers
851 function generateNetworkTypesAvailableOptions ($defaultType = NULL) {
853 if (!isset($GLOBALS[__FUNCTION__][$defaultType])) {
855 $GLOBALS[__FUNCTION__][$defaultType] = generateOptions(
869 'forced_half_banner',
903 $GLOBALS['network_types_disabled'],
904 'translateNetworkTypeHandler'
909 return $GLOBALS[__FUNCTION__][$defaultType];
912 // Generates an options list of all available (hard-coded) text encoders
913 function generateNetworkTextEncodingAvailableOptions ($defaultEncoding = NULL) {
915 if (!isset($GLOBALS[__FUNCTION__][$defaultEncoding])) {
917 $GLOBALS[__FUNCTION__][$defaultEncoding] = generateOptions(
927 'translateNetworkTextEncoding'
932 return $GLOBALS[__FUNCTION__][$defaultEncoding];
935 // Generates an options list (somewhat getter) for request keys
936 function generateNetworkRequestKeyOptions () {
938 if (!isset($GLOBALS[__FUNCTION__])) {
939 // Generate and cache it
940 $GLOBALS[__FUNCTION__] = generateOptions(
963 $GLOBALS['network_request_params_disabled'],
964 'translateNetworkRequestParameterKey'
969 return $GLOBALS[__FUNCTION__];
972 // Generator (somewhat getter) for (return) array translation
973 function generateNetworkTranslationOptions ($default = '') {
975 if (!isset($GLOBALS[__FUNCTION__][$default])) {
976 // Generate and cache it
977 $GLOBALS[__FUNCTION__][$default] = generateOptions(
978 'network_translations',
979 'network_translation_id',
980 'network_translation_name',
984 $GLOBALS['network_array_translation_disabled'],
985 'translateNetworkTranslationName'
990 return $GLOBALS[__FUNCTION__][$default];
993 // Generates an option list of request types
994 function generateNetworkRequestTypeOptions ($default = '') {
996 if (!isset($GLOBALS[__FUNCTION__][$default])) {
998 $GLOBALS[__FUNCTION__][$default] = generateOptions(
1005 '{--ADMIN_NETWORK_REQUEST_TYPE_GET--}',
1006 '{--ADMIN_NETWORK_REQUEST_TYPE_POST--}'
1013 return $GLOBALS[__FUNCTION__][$default];
1016 // Generates an option list of network_api_active
1017 function generateNetworkApiActiveOptions ($default = '') {
1019 if (!isset($GLOBALS[__FUNCTION__][$default])) {
1020 // Generate the list
1021 $GLOBALS[__FUNCTION__][$default] = generateYesNoOptions($default);
1025 return $GLOBALS[__FUNCTION__][$default];
1028 // Generator (somewhat getter) for network type options
1029 function generateNetworkMediaOutputOptions ($mediaOutput) {
1030 // Is this an array, then we just came back from edit/delete actions
1031 if (is_array($mediaOutput)) {
1032 // Set it as empty string
1037 if (!isset($GLOBALS[__FUNCTION__][$mediaOutput])) {
1038 // Generate output and cache it
1039 $GLOBALS[__FUNCTION__][$mediaOutput] = generateOptions(
1053 '{--ADMIN_NETWORK_MEDIA_OUTPUT_NONE--}',
1054 '{--ADMIN_NETWORK_MEDIA_OUTPUT_BANNER--}',
1055 '{--ADMIN_NETWORK_MEDIA_OUTPUT_HTML_EMAIL--}',
1056 '{--ADMIN_NETWORK_MEDIA_OUTPUT_LAYER--}',
1057 '{--ADMIN_NETWORK_MEDIA_OUTPUT_PAGEPEEL--}',
1058 '{--ADMIN_NETWORK_MEDIA_OUTPUT_POPUP--}',
1059 '{--ADMIN_NETWORK_MEDIA_OUTPUT_POPDOWN--}',
1060 '{--ADMIN_NETWORK_MEDIA_OUTPUT_TEXT_EMAIL--}',
1061 '{--ADMIN_NETWORK_MEDIA_OUTPUT_TEXTLINK--}'
1064 'translateNetworkMediaOutputType'
1069 return $GLOBALS[__FUNCTION__][$mediaOutput];
1072 // Checks if the given network is configured by looking its API configuration entry up
1073 function isNetworkApiConfigured ($networkId, $addSql = '') {
1075 if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
1076 // Check for an entry in network_api_config
1077 $GLOBALS[__FUNCTION__][$networkId] = (countSumTotalData(
1078 bigintval($networkId),
1079 'network_api_config',
1087 return $GLOBALS[__FUNCTION__][$networkId];
1090 // Checks whether the given network type handler is configured
1091 function isNetworkTypeHandlerConfigured ($networkId, $networkTypeId) {
1093 if (!isset($GLOBALS[__FUNCTION__][$networkId][$networkTypeId])) {
1095 $GLOBALS[__FUNCTION__][$networkId][$networkTypeId] = (countSumTotalData(
1096 bigintval($networkTypeId),
1097 'network_handler_config',
1101 sprintf(' AND `network_id`=%s', bigintval($networkId))
1106 return $GLOBALS[__FUNCTION__][$networkId][$networkTypeId];
1109 // Handles the network-payment-check request
1110 function handleNetworkPaymentCheckRequest () {
1111 // @TODO Implement this function, don't forget to set HTTP status back to '200 OK' if everything went fine
1112 reportBug(__FUNCTION__, __LINE__, 'Not yet implemented.');
1115 // Handles the network-delete-url request
1116 function handleNetworkDeleteUrlRequest () {
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 // Handle a single request parameter key by given network type handler id and "internal" key
1122 function handleRequestParameterKey ($networkTypeId, $networkRequestKey) {
1123 // Construct call-back function name
1124 $callbackName = 'doHandleNetworkRequest' . capitalizeUnderscoreString($networkRequestKey) . 'Key';
1126 // Is the function there?
1127 if (!function_exists($callbackName)) {
1128 // Call-back function does not exist
1129 reportBug(__FUNCTION__, __LINE__, 'Call-back function ' . $callbackName . ' does not exist. networkTypeId=' . $networkTypeId . ',networkRequestKey=' . $networkRequestKey);
1132 // Call it with network type id
1133 return call_user_func_array($callbackName, array($networkTypeId));
1136 // Handle all keys given request parameter array loaded by getNetworkRequestParametersByTypeId()
1137 function handleNetworkRequestParameterKeys (&$requestParams) {
1138 // Simple check for validity
1139 assert(isset($requestParams[0]['network_request_param_key']));
1141 // "Walk" through all
1142 foreach ($requestParams as $key => $params) {
1143 // Is the default value not set?
1144 if (empty($params['network_request_param_default'])) {
1145 // This key needs to be handled, so call it
1146 $requestParams[$key]['network_request_param_default'] = handleRequestParameterKey($params['network_type_id'], $params['network_request_param_key']);
1152 * Logs given HTTP headers to database for debugging purposes.
1154 * @param $networkId Network's id number
1155 * @param $networkTypeId Network type handler's id number
1156 * @param $headers All HTTP headers
1157 * @param $type Can be only one of 'MANUAL' or 'CRON'
1160 function logNetworkResponseHeaders ($networkId, $networkTypeId, $headers, $type) {
1161 // Make sure type is valid
1162 assert(in_array($type, array('MANUAL', 'CRON')));
1164 // Is debug logging enabled or status code not 200 OK?
1165 if ((getConfig('network_logging_debug') == 'Y') || (!isHttpStatusOkay($headers[0]))) {
1167 sqlQueryEscaped("INSERT INTO `{?_MYSQL_PREFIX?}_network_header_logging` (`network_id`, `network_type_id`, `network_http_status_code`, `network_http_headers`, `network_logging_type`) VALUES(%s, %s, '%s', '%s', '%s')",
1169 bigintval($networkId),
1170 bigintval($networkTypeId),
1172 serialize($headers),
1174 ), __FUNCTION__, __LINE__);
1179 * Caches given reponse body from API into cache, updates existing cache if
1180 * found. This function does the charset-convertion, so you don't have to do it
1181 * again if you use this cached data.
1183 * @param $networkId Network's id number
1184 * @param $networkTypeId Network type handler's id number
1185 * @param $responseBody Response body (string)
1186 * @param $networkData Network + type handler data as array
1187 * @param $type Can be only one of 'MANUAL' or 'CRON'
1190 function saveNetworkResponseBodyInCache ($networkId, $networkTypeId, $responseBody, $networkData, $type) {
1191 // Make sure the body is not larger than this value
1192 assert(strlen($responseBody) <= 16777215);
1193 assert(in_array($type, array('MANUAL', 'CRON')));
1195 // So is there cache?
1196 if (countSumTotalData($networkId, 'network_cache', 'network_cache_id', 'network_id', TRUE, ' AND `network_type_id`=' . bigintval($networkTypeId)) == 1) {
1197 // Entry found, so update it
1198 sqlQueryEscaped("UPDATE
1199 `{?_MYSQL_PREFIX?}_network_cache`
1201 `network_cache_data`='%s',
1202 `network_cache_body`='%s',
1203 `network_cache_type`='%s',
1204 `network_cache_admin_id`=%s,
1205 `network_cache_updated`=NOW()
1208 `network_type_id`=%s
1211 serialize($networkData),
1212 compress(convertCharsetToUtf8($responseBody, $networkData['network_charset'])),
1214 convertZeroToNull(getCurrentAdminId()),
1215 bigintval($networkId),
1216 bigintval($networkTypeId)
1217 ), __FUNCTION__, __LINE__);
1220 sqlQueryEscaped("INSERT INTO `{?_MYSQL_PREFIX?}_network_cache` (`network_id`, `network_type_id`, `network_cache_data`, `network_cache_body`, `network_cache_type`, `network_cache_admin_id`) VALUES(%s, %s, '%s', '%s', '%s', %s)",
1222 bigintval($networkId),
1223 bigintval($networkTypeId),
1224 serialize($networkData),
1225 compress(convertCharsetToUtf8($responseBody, $networkData['network_charset'])),
1227 convertZeroToNull(getCurrentAdminId())
1228 ), __FUNCTION__, __LINE__);
1232 // Queries network API with given network data and request data
1233 function queryNetworkApi ($networkData, $requestData) {
1235 $response = sendHttpRequest($networkData['network_request_type'], $networkData['network_type_api_url'], $requestData, FALSE, FALSE);
1237 // Did all went fine? (also a 403 is considered as "okay" here)
1238 if (count($response) > 3) {
1239 // Save response body, remove last empty line if really empty
1240 $responseBody = (string) trim($response[count($response) - 1]);
1241 unset($response[count($response) - 1]);
1242 assert(empty($response[count($response)]));
1243 unset($response[count($response) - 1]);
1245 // Register all HTTP headers for debugging purposes
1246 logNetworkResponseHeaders($networkData['network_id'], postRequestElement('network_type_id'), $response, 'MANUAL');
1249 if (isHttpStatusOkay($response[0])) {
1250 // Count API request
1251 countNetworkApiRequest($networkData);
1253 // Save response in cache
1254 saveNetworkResponseBodyInCache($networkData['network_id'], postRequestElement('network_type_id'), $responseBody, $networkData, 'MANUAL');
1258 // Return the response
1263 * Counts API request from given network data generated by getNetworkDataByTypeId()
1265 * @param $networkData Array with network data
1266 * @return $affectedRows Affected rows (always one or FALSE if unlimited/depleted)
1268 function countNetworkApiRequest ($networkData) {
1270 $apiConfig = getFullNetworkConfigurationByTypeId($networkData['network_type_id']);
1272 // Is the daily or remaining free amount zero?
1273 if (($networkData['network_query_amount'] == 0) || ($apiConfig['network_api_remaining_requests'] == 0)) {
1278 // Okay, so update database
1279 $result = sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_network_api_config` SET `network_api_remaining_requests`=`network_api_remaining_requests`-1 WHERE `network_id`=%s LIMIT 1",
1281 bigintval($networkData['network_id'])
1282 ), __FUNCTION__, __LINE__);
1284 // Return affected rows
1285 return sqlAffectedRows();
1289 * Generates a referral link for given network id (including HTML)
1291 * @param $networkId Network id to generate link for
1292 * @return $output "Rendered" output
1294 function generateMetworkReferralLinkById ($networkId) {
1295 // Simple output (no need for template!)
1296 $output = '<a href="{%network,getNetworkDataFromId,network_reflink=' . $networkId . '%}" target="_blank" title="{%network,getNetworkDataFromId,network_title=' . $networkId . '%}">{%network,getNetworkDataFromId,network_title=' . $networkId . '%}</a>';
1302 //------------------------------------------------------------------------------
1303 // "Translation" functions (can be used in EL code)
1304 //------------------------------------------------------------------------------
1306 // Translates 'translate_name' for e.g. templates
1307 function translateNetworkTranslationName ($name) {
1308 // Return message id
1309 return translateGeneric('ADMIN_NETWORK_TRANSLATE', $name, '_NAME');
1312 // Translates the network type id to a handler
1313 function translateNetworkTypeHandlerByTypeId ($typeId) {
1315 $data = getNetworkDataByTypeId($typeId, 'network_type_handler');
1318 if (is_null($data)) {
1320 return translateNetworkTypeHandler('UNKNOWN');
1323 // Return actual translation
1324 return translateNetworkTypeHandler($data);
1327 // "Translates" give network media output (type)
1328 function translateNetworkMediaOutputType ($mediaOutput) {
1329 // Return message id
1330 return translateGeneric('ADMIN_NETWORK_MEDIA_OUTPUT', $mediaOutput);
1333 // Translates the network type handler (e.g. banner, paidmail) for templates
1334 function translateNetworkTypeHandler ($type) {
1336 $messageId = 'ADMIN_NETWORK_TYPE_HANDLER_' . strtoupper($type);
1338 // Is the message id there?
1339 if (!isMessageIdValid($messageId)) {
1341 reportBug(__FUNCTION__, __LINE__, 'type=' . $type . ' is invalid.');
1344 // Return message id
1345 return '{--' . $messageId . '--}';
1348 // Translates request type
1349 function translateNetworkRequestType ($type) {
1351 $messageId = 'ADMIN_NETWORK_REQUEST_TYPE_' . strtoupper($type) . '';
1353 // Is the message id there?
1354 if (!isMessageIdValid($messageId)) {
1356 reportBug(__FUNCTION__, __LINE__, 'type=' . $type . ' is invalid.');
1359 // Return message id
1360 return '{--' . $messageId . '--}';
1363 // Translates request parameter
1364 function translateNetworkRequestParameterKey ($param) {
1366 $messageId = 'ADMIN_NETWORK_REQUEST_PARAMETER_' . strtoupper($param) . '';
1368 // Is the message id there?
1369 if (!isMessageIdValid($messageId)) {
1371 reportBug(__FUNCTION__, __LINE__, 'param=' . $param . ' is invalid.');
1374 // Return message id
1375 return '{--' . $messageId . '--}';
1378 // Translate text-encoding
1379 function translateNetworkTextEncoding ($encoding) {
1381 $messageId = 'ADMIN_NETWORK_TYPE_TEXT_ENCODING_' . strtoupper($encoding) . '';
1383 // Is the message id there?
1384 if (!isMessageIdValid($messageId)) {
1385 // Not valid encoding
1386 reportBug(__FUNCTION__, __LINE__, 'encoding=' . $encoding . ' is invalid.');
1389 // Return message id
1390 return '{--' . $messageId . '--}';
1393 // Translates API index
1394 function translateNetworkApiIndex ($index) {
1396 if (!isset($GLOBALS['network_array_index'])) {
1397 // Get an array of all API array indexes
1398 $GLOBALS['network_array_index'] = array();
1401 $result = sqlQuery('SELECT
1403 `network_array_index`,
1404 `network_translation_name`
1406 `{?_MYSQL_PREFIX?}_network_array_translation`
1408 `{?_MYSQL_PREFIX?}_network_translations`
1410 `network_array_index`=`network_translation_id`
1412 `network_array_sort` ASC', __FUNCTION__, __LINE__);
1414 // Are there entries?
1415 if (!ifSqlHasZeroNums($result)) {
1417 while ($row = sqlFetchArray($result)) {
1418 // Add it to our global array
1419 $GLOBALS['network_array_index'][$row['network_array_index']] = $row;
1424 sqlFreeResult($result);
1427 // Default name is unknown
1430 // Is the entry there?
1431 if (isset($GLOBALS['network_array_index'][$index])) {
1432 // Then get the name
1433 $name = $GLOBALS['network_array_index'][$index]['network_translation_name'];
1436 // Return translation
1437 return translateNetworkTranslationName($name);
1440 // Translates network API configuration status (see function isNetworkApiConfigured()) by given id
1441 function translateNetworkApiConfiguredStatusById ($networkId) {
1443 if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
1444 // By default it is not configured
1445 $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_NOT_CONFIGURED--}';
1447 // So is it configured?
1448 if (!isNetworkActiveById($networkId)) {
1449 // Network is not active
1450 $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_NOT_ACTIVE--}';
1451 } elseif (isNetworkApiConfigured($networkId)) {
1453 $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_CONFIGURED--}';
1458 return $GLOBALS[__FUNCTION__][$networkId];
1462 * "Translates" given amount of queries; 0 = unlimited
1464 * @param $amount Amount of free queries
1465 * @return $translated "Translated" value; 0 = unlimited
1467 function translateNetworkQueryAmount ($amount) {
1468 // Default is unlimited (good! ;-) )
1469 $translated = '{--UNLIMITED--}';
1471 // Is the amount larger zero?
1473 // Then translate it
1474 $translated = translateComma($amount);
1477 // Return translated value
1482 * "Translates given status (Y/N) to "de-/activated" but only if expert and
1483 * debug mode are enabled.
1485 * @param $status Can be one of Y/N
1486 * @return $translated "Translated" status
1488 function translateNetworkActivationStatus ($status) {
1490 if (!isset($GLOBALS[__FUNCTION__][$status])) {
1491 // Default is not enabled
1492 $GLOBALS[__FUNCTION__][$status] = '';
1494 // Is expert + debug mode enabled?
1495 if ((isAdminsExpertSettingEnabled()) && (isDebugModeEnabled())) {
1496 // Then "translate" it
1497 $GLOBALS[__FUNCTION__][$status] = translateActivationStatus($status);
1501 // Return "translation"
1502 return $GLOBALS[__FUNCTION__][$status];
1505 //------------------------------------------------------------------------------
1506 // Wrapper functions to save data to network tables
1507 //------------------------------------------------------------------------------
1509 // Updates given network (id) with data from array
1510 function doNetworkUpdateDataByArray ($networkId, $networkData) {
1511 // Ids lower one are not accepted
1512 if (!isValidId($networkId)) {
1513 // Not good, should be fixed
1514 reportBug(__FUNCTION__, __LINE__, 'Network id ' . $networkId . ' is smaller than 1.');
1517 // Just call our inner method
1518 return adminSaveSettings($networkData, '_network_data', sprintf("`network_id`=%s", bigintval($networkId)), array(), FALSE, FALSE);
1521 // Updates given network type handler (id) with data from array
1522 function doNetworkUpdateTypeByArray ($networkTypeId, $networkTypeData) {
1523 // Ids lower one are not accepted
1524 if (!isValidId($networkTypeId)) {
1525 // Not good, should be fixed
1526 reportBug(__FUNCTION__, __LINE__, 'Network type handler id ' . $networkTypeId . ' is smaller than 1.');
1529 // Just call our inner method
1530 return adminSaveSettings($networkTypeData, '_network_types', sprintf("`network_type_id`=%s", bigintval($networkTypeId)), array(), FALSE, FALSE);
1533 // Updates given network request parameters (id) with data from array
1534 function doNetworkUpdateParamsByArray ($networkParamsId, $networkParamsData) {
1535 // Ids lower one are not accepted
1536 if (!isValidId($networkParamsId)) {
1537 // Not good, should be fixed
1538 reportBug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $networkParamsId . ' is smaller than 1.');
1541 // Just call our inner method
1542 return adminSaveSettings($networkParamsData, '_network_request_params', sprintf("`network_request_param_id`=%s", bigintval($networkParamsId)), array(), FALSE, FALSE);
1545 // Updates given network array translations (id) with data from array
1546 function doNetworkUpdateArrayTranslationsByArray ($networkTranslationsId, $networkTranslationsData) {
1547 // Ids lower one are not accepted
1548 if (!isValidId($networkTranslationsId)) {
1549 // Not good, should be fixed
1550 reportBug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $networkTranslationsId . ' is smaller than 1.');
1553 // Just call our inner method
1554 return adminSaveSettings($networkTranslationsData, '_network_array_translation', sprintf("`network_array_id`=%s", bigintval($networkTranslationsId)), array(), FALSE, FALSE);
1557 //------------------------------------------------------------------------------
1558 // Call-back functions for request parameter keys
1559 //------------------------------------------------------------------------------
1561 // ----------------------- Table: network_api_config -----------------------
1563 // Handles affiliate id
1564 function doHandleNetworkRequestAffiliateIdKey ($networkTypeId) {
1565 // It is assumed that the network + type handler are both configured
1566 // Load full config data (this will be "cached"!)
1567 $configData = getFullNetworkConfigurationByTypeId($networkTypeId);
1569 // Is the network activated?
1570 if (!isset($configData['network_api_active'])) {
1571 // Configuration could not be loaded
1572 reportBug(__FUNCTION__, __LINE__, 'Configuration for networkTypeId=' . $networkTypeId . ' could not be loaded.');
1573 } elseif (($configData['network_api_active'] == 'N') && (!isDebugModeEnabled())) {
1574 // Is not activated, so don't handle it in non-debug mode
1575 reportBug(__FUNCTION__, __LINE__, 'Configuration for network_id ' . $configData['network_id'] .',networkTypeId=' . $networkTypeId . ' is not activated.');
1576 } elseif (empty($configData['network_api_affiliate_id'])) {
1577 // Required element is not set
1578 reportBug(__FUNCTION__, __LINE__, 'network_api_affiliate_id for network_id=' . $configData['network_id'] . ',networkTypeId=' . $networkTypeId . ' is not set.');
1581 // Return configured value
1582 return $configData['network_api_affiliate_id'];
1586 function doHandleNetworkRequestSiteIdKey ($networkTypeId) {
1587 // It is assumed that the network + type handler are both configured
1588 // Load full config data (this will be "cached"!)
1589 $configData = getFullNetworkConfigurationByTypeId($networkTypeId);
1591 // Is the network activated?
1592 if (!isset($configData['network_api_active'])) {
1593 // Configuration could not be loaded
1594 reportBug(__FUNCTION__, __LINE__, 'Configuration for networkTypeId=' . $networkTypeId . ' could not be loaded.');
1595 } elseif (($configData['network_api_active'] == 'N') && (!isDebugModeEnabled())) {
1596 // Is not activated, so don't handle it in non-debug mode
1597 reportBug(__FUNCTION__, __LINE__, 'Configuration for network_id ' . $configData['network_id'] .',networkTypeId=' . $networkTypeId . ' is not activated.');
1598 } elseif (empty($configData['network_api_site_id'])) {
1599 // Required element is not set
1600 reportBug(__FUNCTION__, __LINE__, 'network_api_site_id for network_id=' . $configData['network_id'] . ',networkTypeId=' . $networkTypeId . ' is not set.');
1603 // Return configured value
1604 return $configData['network_api_site_id'];
1607 // Handles interface password
1608 function doHandleNetworkRequestPasswordKey ($networkTypeId) {
1609 // It is assumed that the network + type handler are both configured
1610 // Load full config data (this will be "cached"!)
1611 $configData = getFullNetworkConfigurationByTypeId($networkTypeId);
1613 // Is the network activated?
1614 if (!isset($configData['network_api_active'])) {
1615 // Configuration could not be loaded
1616 reportBug(__FUNCTION__, __LINE__, 'Configuration for networkTypeId=' . $networkTypeId . ' could not be loaded.');
1617 } elseif (($configData['network_api_active'] == 'N') && (!isDebugModeEnabled())) {
1618 // Is not activated, so don't handle it in non-debug mode
1619 reportBug(__FUNCTION__, __LINE__, 'Configuration for network_id ' . $configData['network_id'] .',networkTypeId=' . $networkTypeId . ' is not activated.');
1620 } elseif (empty($configData['network_api_password'])) {
1621 // Required element is not set
1622 reportBug(__FUNCTION__, __LINE__, 'network_api_password for network_id=' . $configData['network_id'] . ',networkTypeId=' . $networkTypeId . ' is not set.');
1625 // Return configured value
1626 return $configData['network_api_password'];
1629 // ----------------------- Table: network_handler_config -----------------------
1631 // Handles reload lock
1632 function doHandleNetworkRequestReloadKey ($networkTypeId) {
1633 // It is assumed that the network + type handler are both configured
1634 // Load full config data (this will be "cached"!)
1635 $configData = getFullNetworkConfigurationByTypeId($networkTypeId);
1637 // Is the network activated?
1638 if (!isset($configData['network_api_active'])) {
1639 // Configuration could not be loaded
1640 reportBug(__FUNCTION__, __LINE__, 'Configuration for networkTypeId=' . $networkTypeId . ' could not be loaded.');
1641 } elseif (($configData['network_api_active'] == 'N') && (!isDebugModeEnabled())) {
1642 // Is not activated, so don't handle it in non-debug mode
1643 reportBug(__FUNCTION__, __LINE__, 'Configuration for network_id ' . $configData['network_id'] .',networkTypeId=' . $networkTypeId . ' is not activated.');
1646 // Return configured value
1647 return caluculateTimeUnitValue($configData['network_max_reload_time'], $configData['network_type_reload_time_unit']);
1650 // Handles minimum stay
1651 function doHandleNetworkRequestMinimumStayKey ($networkTypeId) {
1652 // It is assumed that the network + type handler are both configured
1653 // Load full config data (this will be "cached"!)
1654 $configData = getFullNetworkConfigurationByTypeId($networkTypeId);
1656 // Is the network activated?
1657 if (!isset($configData['network_api_active'])) {
1658 // Configuration could not be loaded
1659 reportBug(__FUNCTION__, __LINE__, 'Configuration for networkTypeId=' . $networkTypeId . ' could not be loaded.');
1660 } elseif (($configData['network_api_active'] == 'N') && (!isDebugModeEnabled())) {
1661 // Is not activated, so don't handle it in non-debug mode
1662 reportBug(__FUNCTION__, __LINE__, 'Configuration for network_id ' . $configData['network_id'] .',networkTypeId=' . $networkTypeId . ' is not activated.');
1665 // Return configured value
1666 return $configData['network_min_waiting_time'];
1669 // Handles maximum stay
1670 function doHandleNetworkRequestMaximumStayKey ($networkTypeId) {
1671 // It is assumed that the network + type handler are both configured
1672 // Load full config data (this will be "cached"!)
1673 $configData = getFullNetworkConfigurationByTypeId($networkTypeId);
1675 // Is the network activated?
1676 if (!isset($configData['network_api_active'])) {
1677 // Configuration could not be loaded
1678 reportBug(__FUNCTION__, __LINE__, 'Configuration for networkTypeId=' . $networkTypeId . ' could not be loaded.');
1679 } elseif (($configData['network_api_active'] == 'N') && (!isDebugModeEnabled())) {
1680 // Is not activated, so don't handle it in non-debug mode
1681 reportBug(__FUNCTION__, __LINE__, 'Configuration for network_id ' . $configData['network_id'] .',networkTypeId=' . $networkTypeId . ' is not activated.');
1684 // Return configured value
1685 return $configData['network_max_waiting_time'];
1688 // Handles remaining clicks
1689 function doHandleNetworkRequestRemainClicksKey ($networkTypeId) {
1690 // It is assumed that the network + type handler are both configured
1691 // Load full config data (this will be "cached"!)
1692 $configData = getFullNetworkConfigurationByTypeId($networkTypeId);
1694 // Is the network activated?
1695 if (!isset($configData['network_api_active'])) {
1696 // Configuration could not be loaded
1697 reportBug(__FUNCTION__, __LINE__, 'Configuration for networkTypeId=' . $networkTypeId . ' could not be loaded.');
1698 } elseif (($configData['network_api_active'] == 'N') && (!isDebugModeEnabled())) {
1699 // Is not activated, so don't handle it in non-debug mode
1700 reportBug(__FUNCTION__, __LINE__, 'Configuration for network_id ' . $configData['network_id'] .',networkTypeId=' . $networkTypeId . ' is not activated.');
1703 // Return configured value
1704 return $configData['network_min_remain_clicks'];
1707 // Handles remaining budget
1708 function doHandleNetworkRequestRemainBudgetKey ($networkTypeId) {
1709 // It is assumed that the network + type handler are both configured
1710 // Load full config data (this will be "cached"!)
1711 $configData = getFullNetworkConfigurationByTypeId($networkTypeId);
1713 // Is the network activated?
1714 if (!isset($configData['network_api_active'])) {
1715 // Configuration could not be loaded
1716 reportBug(__FUNCTION__, __LINE__, 'Configuration for networkTypeId=' . $networkTypeId . ' could not be loaded.');
1717 } elseif (($configData['network_api_active'] == 'N') && (!isDebugModeEnabled())) {
1718 // Is not activated, so don't handle it in non-debug mode
1719 reportBug(__FUNCTION__, __LINE__, 'Configuration for network_id ' . $configData['network_id'] .',networkTypeId=' . $networkTypeId . ' is not activated.');
1722 // Return configured value
1723 return $configData['network_min_remain_budget'];
1726 // Handles reward (payment)
1727 function doHandleNetworkRequestRewardKey ($networkTypeId) {
1728 // It is assumed that the network + type handler are both configured
1729 // Load full config data (this will be "cached"!)
1730 $configData = getFullNetworkConfigurationByTypeId($networkTypeId);
1732 // Is the network activated?
1733 if (!isset($configData['network_api_active'])) {
1734 // Configuration could not be loaded
1735 reportBug(__FUNCTION__, __LINE__, 'Configuration for networkTypeId=' . $networkTypeId . ' could not be loaded.');
1736 } elseif (($configData['network_api_active'] == 'N') && (!isDebugModeEnabled())) {
1737 // Is not activated, so don't handle it in non-debug mode
1738 reportBug(__FUNCTION__, __LINE__, 'Configuration for network_id ' . $configData['network_id'] .',networkTypeId=' . $networkTypeId . ' is not activated.');
1739 } elseif (empty($configData['network_min_payment'])) {
1740 // Required element is not set
1741 reportBug(__FUNCTION__, __LINE__, 'network_min_payment for network_id=' . $configData['network_id'] . ',networkTypeId=' . $networkTypeId . ' is not set.');
1744 // Return configured value
1745 return $configData['network_min_payment'];
1748 // Handles media size
1749 function doHandleNetworkRequestSizeKey ($networkTypeId) {
1750 // It is assumed that the network + type handler are both configured
1751 // Load full config data (this will be "cached"!)
1752 $configData = getFullNetworkConfigurationByTypeId($networkTypeId);
1754 // Is the network activated?
1755 if (!isset($configData['network_api_active'])) {
1756 // Configuration could not be loaded
1757 reportBug(__FUNCTION__, __LINE__, 'Configuration for networkTypeId=' . $networkTypeId . ' could not be loaded.');
1758 } elseif (($configData['network_api_active'] == 'N') && (!isDebugModeEnabled())) {
1759 // Is not activated, so don't handle it in non-debug mode
1760 reportBug(__FUNCTION__, __LINE__, 'Configuration for network_id ' . $configData['network_id'] .',networkTypeId=' . $networkTypeId . ' is not activated.');
1761 } elseif (empty($configData['network_media_size'])) {
1762 // Required element is not set
1763 reportBug(__FUNCTION__, __LINE__, 'network_media_size for network_id=' . $configData['network_id'] . ',networkTypeId=' . $networkTypeId . ' is not set.');
1766 // Return configured value
1767 return $configData['network_media_size'];
1770 // Handles media output (type)
1771 function doHandleNetworkRequestTypeKey ($networkTypeId) {
1772 // It is assumed that the network + type handler are both configured
1773 // Load full config data (this will be "cached"!)
1774 $configData = getFullNetworkConfigurationByTypeId($networkTypeId);
1776 // Is the network activated?
1777 if (!isset($configData['network_api_active'])) {
1778 // Configuration could not be loaded
1779 reportBug(__FUNCTION__, __LINE__, 'Configuration for networkTypeId=' . $networkTypeId . ' could not be loaded.');
1780 } elseif (($configData['network_api_active'] == 'N') && (!isDebugModeEnabled())) {
1781 // Is not activated, so don't handle it in non-debug mode
1782 reportBug(__FUNCTION__, __LINE__, 'Configuration for network_id ' . $configData['network_id'] .',networkTypeId=' . $networkTypeId . ' is not activated.');
1785 // Return configured value
1786 return $configData['network_media_output'];
1790 function doHandleNetworkRequestEroticKey ($networkTypeId) {
1791 // It is assumed that the network + type handler are both configured
1792 // Load full config data (this will be "cached"!)
1793 $configData = getFullNetworkConfigurationByTypeId($networkTypeId);
1795 // Is the network activated?
1796 if (!isset($configData['network_api_active'])) {
1797 // Configuration could not be loaded
1798 reportBug(__FUNCTION__, __LINE__, 'Configuration for networkTypeId=' . $networkTypeId . ' could not be loaded.');
1799 } elseif (($configData['network_api_active'] == 'N') && (!isDebugModeEnabled())) {
1800 // Is not activated, so don't handle it in non-debug mode
1801 reportBug(__FUNCTION__, __LINE__, 'Configuration for network_id ' . $configData['network_id'] .',networkTypeId=' . $networkTypeId . ' is not activated.');
1802 } elseif (empty($configData['network_allow_erotic'])) {
1803 // Required element is not set
1804 reportBug(__FUNCTION__, __LINE__, 'network_allow_erotic for network_id=' . $configData['network_id'] . ',networkTypeId=' . $networkTypeId . ' is not set.');
1807 // Return configured value
1808 return $configData['network_allow_erotic'];
1811 // ----------------------- Table: network_request_params -----------------------
1813 //------------------------------------------------------------------------------
1814 // Call-back functions for admin area
1815 //------------------------------------------------------------------------------
1817 // Callback function to add new network
1818 function doAdminNetworkProcessAddNetwork () {
1819 // We can say here, the form is sent, so check if the network is already added
1820 if (isNetworkNameValid(postRequestElement('network_short_name'))) {
1822 displayErrorMessage('{%message,ADMIN_NETWORK_ALREADY_ADDED=' . postRequestElement('network_short_name') . '%}');
1826 // Add the whole request to database
1827 sqlQuery(getInsertSqlFromArray(postRequestArray(), 'network_data'), __FUNCTION__, __LINE__);
1829 // Add the id for output only
1830 setPostRequestElement('network_id', getSqlInsertId());
1833 if (!ifSqlHasZeroAffectedRows()) {
1834 // Successfully added
1835 loadTemplate('admin_network_added', FALSE, postRequestArray());
1838 displayErrorMessage('{%message,ADMIN_NETWORK_DATA_NOT_ADDED=' . postRequestElement('network_short_name') . '%}');
1842 // Displays selected networks for editing
1843 function doAdminNetworkProcessHandleNetworks () {
1844 // Is there selections?
1845 if (ifPostContainsSelections()) {
1846 // Something has been selected, so start displaying one by one
1848 foreach (postRequestElement('sel') as $networkId => $sel) {
1849 // Is this selected?
1851 // Load this network's data
1852 $networkData = getNetworkDataFromId($networkId);
1854 // Is there found the network?
1855 if (isFilledArray($networkData)) {
1856 // Add row template with given form name
1857 $OUT .= loadTemplate('admin_' . getNetworkFormName() . '_networks_row', TRUE, $networkData);
1862 // If there are no rows, we don't need to display the edit form
1864 // Init array with generic element
1869 // Output main template
1870 loadTemplate('admin_' . getNetworkFormName() . '_networks', FALSE, $content);
1872 // Don't display the list/add new form
1873 $GLOBALS['network_display'] = FALSE;
1875 // Nothing selected/found
1876 displayErrorMessage('{--ADMIN_NETWORK_NOTHING_FOUND--}');
1881 // Handle network type form
1882 function doAdminNetworkProcessHandleNetworkTypes () {
1883 // Is there selections?
1884 if (ifPostContainsSelections()) {
1885 // Load network data
1886 $networkData = getNetworkDataFromId(getRequestElement('network_id'));
1888 // Something has been selected, so start displaying one by one
1890 foreach (postRequestElement('sel') as $networkId => $sel) {
1891 // Is this selected?
1893 // Load this network's data
1894 $networkTypeData = getNetworkTypeDataByTypeId($networkId);
1896 // Is there found the network?
1897 if (isFilledArray($networkTypeData)) {
1898 if (getNetworkFormName() == 'edit') {
1899 // Add row template for deleting
1900 $OUT .= loadTemplate('admin_edit_network_types_row', TRUE, $networkTypeData);
1901 } elseif (getNetworkFormName() == 'delete') {
1902 // Add row template for deleting
1903 $OUT .= loadTemplate('admin_delete_network_types_row', TRUE, $networkTypeData);
1906 reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/delete. data=<pre>' . print_r(postRequestArray(), TRUE) . '</pre>');
1912 // If there are no rows, we don't need to display the edit form
1914 // Prepare array with generic elements
1917 'network_id' => bigintval(getRequestElement('network_id'))
1920 // Output main template
1921 if (getNetworkFormName() == 'edit') {
1922 loadTemplate('admin_edit_network_types', FALSE, $content);
1923 } elseif (getNetworkFormName() == 'delete') {
1924 loadTemplate('admin_delete_network_types', FALSE, $content);
1927 reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/delete. data=<pre>' . print_r(postRequestArray(), TRUE) . '</pre>');
1930 // Don't display the list/add new form
1931 $GLOBALS['network_display'] = FALSE;
1933 // Nothing selected/found
1934 displayErrorMessage('{--ADMIN_NETWORK_TYPE_HANDLER_NOTHING_FOUND--}');
1939 // Handle network request parameter form
1940 function doAdminNetworkProcessHandleRequestParams () {
1941 // Is there selections?
1942 if (ifPostContainsSelections()) {
1944 $GLOBALS['network_request_params_disabled'] = array();
1946 // Load network data
1947 $networkData = getNetworkDataFromId(getRequestElement('network_id'));
1949 // Something has been selected, so start displaying one by one
1951 foreach (postRequestElement('sel') as $networkId => $sel) {
1952 // Is this selected?
1954 // Load this network's data
1955 $networkRequestData = getNetworkRequestParamsDataFromId($networkId);
1957 // Is there found the network?
1958 if (isFilledArray($networkRequestData)) {
1959 if (getNetworkFormName() == 'edit') {
1960 // Add row template for deleting
1961 $OUT .= loadTemplate('admin_edit_network_request_params_row', TRUE, $networkRequestData);
1962 } elseif (getNetworkFormName() == 'delete') {
1964 $networkRequestData['network_type_data'] = getNetworkTypeDataByTypeId($networkRequestData['network_type_id']);
1966 // Add row template for deleting
1967 $OUT .= loadTemplate('admin_delete_network_request_params_row', TRUE, $networkRequestData);
1970 reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/delete. data=<pre>' . print_r(postRequestArray(), TRUE) . '</pre>');
1976 // If there are no rows, we don't need to display the edit form
1978 // Prepare array with generic elements
1981 'network_id' => bigintval(getRequestElement('network_id'))
1984 // Output main template
1985 if (getNetworkFormName() == 'edit') {
1986 loadTemplate('admin_edit_network_request_params', FALSE, $content);
1987 } elseif (getNetworkFormName() == 'delete') {
1988 loadTemplate('admin_delete_network_request_params', FALSE, $content);
1991 reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/delete. data=<pre>' . print_r(postRequestArray(), TRUE) . '</pre>');
1994 // Don't display the list/add new form
1995 $GLOBALS['network_display'] = FALSE;
1997 // Nothing selected/found
1998 displayErrorMessage('{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_FOUND--}');
2003 // Changes given networks
2004 function doAdminNetworkProcessChangeNetworks () {
2005 // Is there selections?
2006 if (ifPostContainsSelections()) {
2007 // By default nothing is updated
2010 // Something has been selected, so start updating them
2011 foreach (postRequestElement('sel') as $networkId => $sel) {
2012 // Update this entry?
2015 $networkData = array();
2017 // Transfer whole array, except 'sel'
2018 foreach (postRequestArray() as $key => $entry) {
2019 // Skip 'sel' and submit button
2020 if (in_array($key, array('sel', 'do_edit'))) {
2024 // Is there this enty?
2025 if (!isset($entry[$networkId])) {
2026 // Not found, needs fixing
2027 reportBug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
2031 $networkData[$key] = $entry[$networkId];
2034 // Update the network data
2035 $updated += doNetworkUpdateDataByArray($networkId, $networkData);
2039 // Is there updates?
2042 displayMessage('{%message,ADMIN_NETWORK_UPDATED=' . $updated . '%}');
2045 displayErrorMessage('{--ADMIN_NETWORK_NOTHING_CHANGED--}');
2050 // Removes given networks
2051 function doAdminNetworkProcessRemoveNetworks () {
2052 // Is there selections?
2053 if (ifPostContainsSelections()) {
2054 // By default nothing is removed
2057 // Something has been selected, so start updating them
2058 foreach (postRequestElement('sel') as $networkId => $sel) {
2059 // Update this entry?
2061 // Remove this entry
2062 $removed += doAdminRemoveNetworkEntry('data', 'network_id', $networkId);
2066 // Is there removes?
2069 displayMessage('{%message,ADMIN_NETWORK_REMOVED=' . $removed . '%}');
2072 displayErrorMessage('{--ADMIN_NETWORK_NOTHING_REMOVED--}');
2077 // Add a network type handler if not yet found
2078 function doAdminNetworkProcessAddNetworkType () {
2079 // Is the network type handle already used with given network?
2080 if (isNetworkTypeHandleValid(postRequestElement('network_type_handler'), getRequestElement('network_id'))) {
2082 displayErrorMessage('{%message,ADMIN_NETWORK_TYPE_HANDLER_ALREADY_ADDED=' . postRequestElement('network_type_handler') . '%}');
2084 // ... so abort here
2089 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
2091 // Is network_type_click_url set?
2092 if (!isPostRequestElementSet('network_type_click_url')) {
2093 // Remove empty value to get a NULL for an optional entry
2094 unsetPostRequestElement('network_type_click_url');
2097 // Is network_type_banner_url set?
2098 if (!isPostRequestElementSet('network_type_banner_url')) {
2099 // Remove empty value to get a NULL for an optional entry
2100 unsetPostRequestElement('network_type_banner_url');
2103 // Add the whole request to database
2104 sqlQuery(getInsertSqlFromArray(postRequestArray(), 'network_types'), __FUNCTION__, __LINE__);
2107 if (!ifSqlHasZeroAffectedRows()) {
2108 // Successfully added
2109 loadTemplate('admin_network_type_added', FALSE, postRequestArray());
2112 displayErrorMessage('{%message,ADMIN_NETWORK_TYPE_HANDLER_NOT_ADDED=' . postRequestElement('network_type_handler') . '%}');
2116 // Changes given network type handlers
2117 function doAdminNetworkProcessChangeHandlerTypes () {
2118 // Is there selections?
2119 if (ifPostContainsSelections()) {
2120 // By default nothing is updated
2123 // Something has been selected, so start updating them
2124 foreach (postRequestElement('sel') as $networkId => $sel) {
2125 // Update this entry?
2128 $networkTypeData = array();
2130 // Transfer whole array, except 'sel'
2131 foreach (postRequestArray() as $key => $entry) {
2132 // Skip 'sel' and submit button
2133 if (in_array($key, array('sel', 'do_edit'))) {
2137 // Is there this enty?
2138 if (!isset($entry[$networkId])) {
2139 // Not found, needs fixing
2140 reportBug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
2143 // Fix empty network_type_click/banner_url to NULL
2144 if ((in_array($key, array('network_type_click_url', 'network_type_banner_url'))) && (trim($entry[$networkId]) == '')) {
2146 $entry[$networkId] = NULL;
2150 $networkTypeData[$key] = $entry[$networkId];
2153 // Update the network data
2154 $updated += doNetworkUpdateTypeByArray($networkId, $networkTypeData);
2158 // Is there updates?
2161 displayMessage('{%message,ADMIN_NETWORK_TYPE_HANDLER_UPDATED=' . $updated . '%}');
2164 displayErrorMessage('{--ADMIN_NETWORK_TYPE_HANDLER_NOTHING_CHANGED--}');
2169 // Changes given network request parameters
2170 function doAdminNetworkProcessChangeRequestParams () {
2171 // Is there selections?
2172 if (ifPostContainsSelections()) {
2173 // By default nothing is updated
2176 // Something has been selected, so start updating them
2177 foreach (postRequestElement('sel') as $networkId => $sel) {
2178 // Update this entry?
2181 $networkParamsData = array();
2183 // Transfer whole array, except 'sel'
2184 foreach (postRequestArray() as $key => $entry) {
2185 // Skip 'sel' and submit button
2186 if (in_array($key, array('sel', 'do_edit'))) {
2190 // Is there this enty?
2191 if (!isset($entry[$networkId])) {
2192 // Not found, needs fixing
2193 reportBug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
2196 // Fix empty network_request_param_default to NULL
2197 if (($key == 'network_request_param_default') && (trim($entry[$networkId]) == '')) {
2199 $entry[$networkId] = NULL;
2203 $networkParamsData[$key] = $entry[$networkId];
2206 // Update the network data
2207 $updated += doNetworkUpdateParamsByArray($networkId, $networkParamsData);
2211 // Is there updates?
2214 displayMessage('{%message,ADMIN_NETWORK_REQUEST_PARAMETER_UPDATED=' . $updated . '%}');
2217 displayErrorMessage('{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_CHANGED--}');
2222 // Changes given network array translations
2223 function doAdminNetworkProcessChangeArrayTranslation () {
2224 // Is there selections?
2225 if (ifPostContainsSelections()) {
2226 // By default nothing is updated
2229 // Something has been selected, so start updating them
2230 foreach (postRequestElement('sel') as $networkId => $sel) {
2231 // Update this entry?
2234 $networkTranslationsData = array();
2236 // Transfer whole array, except 'sel'
2237 foreach (postRequestArray() as $key => $entry) {
2238 // Skip 'sel' and submit button
2239 if (in_array($key, array('sel', 'do_edit'))) {
2243 // Is there this enty?
2244 if (!isset($entry[$networkId])) {
2245 // Not found, needs fixing
2246 reportBug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
2249 // Fix empty network_request_param_default to NULL
2250 if (($key == 'network_request_param_default') && (trim($entry[$networkId]) == '')) {
2252 $entry[$networkId] = NULL;
2256 $networkTranslationsData[$key] = $entry[$networkId];
2259 // Update the network data
2260 $updated += doNetworkUpdateArrayTranslationsByArray($networkId, $networkTranslationsData);
2264 // Is there updates?
2267 displayMessage('{%message,ADMIN_NETWORK_ARRAY_TRANSLATION_UPDATED=' . $updated . '%}');
2270 displayErrorMessage('{--ADMIN_NETWORK_ARRAY_TRANSLATION_NOTHING_CHANGED--}');
2275 // Removes given network type handlers
2276 function doAdminNetworkProcessRemoveNetworkTypes () {
2277 // Is there selections?
2278 if (ifPostContainsSelections()) {
2279 // By default nothing is removed
2282 // Something has been selected, so start updating them
2283 foreach (postRequestElement('sel') as $networkId => $sel) {
2284 // Update this entry?
2286 // Remove this entry
2287 $removed += doAdminRemoveNetworkEntry('types', 'network_type_id', $networkId);
2291 // Is there removes?
2294 displayMessage('{%message,ADMIN_NETWORK_TYPE_HANDLER_REMOVED=' . $removed . '%}');
2297 displayErrorMessage('{--ADMIN_NETWORK_TYPE_HANDLER_NOTHING_REMOVED--}');
2302 // Removes given network request parameters
2303 function doAdminNetworkProcessRemoveNetworkRequestParams () {
2304 // Is there selections?
2305 if (ifPostContainsSelections()) {
2306 // By default nothing is removed
2309 // Something has been selected, so start updating them
2310 foreach (postRequestElement('sel') as $networkId => $sel) {
2311 // Update this entry?
2313 // Remove this entry
2314 $removed += doAdminRemoveNetworkEntry('request_params', 'network_request_param_id', $networkId);
2318 // Is there removes?
2321 displayMessage('{%message,ADMIN_NETWORK_REQUEST_PARAMETER_REMOVED=' . $removed . '%}');
2324 displayErrorMessage('{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_REMOVED--}');
2329 // Removes given network array translations
2330 function doAdminNetworkProcessRemoveNetworkArrayTranslation () {
2331 // Is there selections?
2332 if (ifPostContainsSelections()) {
2333 // By default nothing is removed
2336 // Something has been selected, so start updating them
2337 foreach (postRequestElement('sel') as $networkId => $sel) {
2338 // Update this entry?
2340 // Remove this entry
2341 $removed += doAdminRemoveNetworkEntry('array_translation', 'network_array_id', $networkId);
2345 // Is there removes?
2348 displayMessage('{%message,ADMIN_NETWORK_ARRAY_TRANSLATION_REMOVED=' . $removed . '%}');
2351 displayErrorMessage('{--ADMIN_NETWORK_ARRAY_TRANSLATION_NOTHING_REMOVED--}');
2356 // Adds a request parameter to given network and type
2357 function doAdminNetworkProcessAddRequestParam () {
2358 // Is the request parameter already used with given network?
2359 if (isNetworkRequestElementValid(postRequestElement('network_request_param_key'), postRequestElement('network_type_id'), getRequestElement('network_id'))) {
2361 displayErrorMessage('{%message,ADMIN_NETWORK_REQUEST_PARAMETER_ALREADY_ADDED=' . postRequestElement('network_request_param_key') . '%}');
2363 // ... so abort here
2368 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
2370 // Is network_request_param_default set?
2371 if (!isPostRequestElementSet('network_request_param_default')) {
2372 // Remove empty value to get a NULL for an optional entry
2373 unsetPostRequestElement('network_request_param_default');
2376 // Add the whole request to database
2377 sqlQuery(getInsertSqlFromArray(postRequestArray(), 'network_request_params'), __FUNCTION__, __LINE__);
2380 if (!ifSqlHasZeroAffectedRows()) {
2381 // Successfully added
2382 loadTemplate('admin_network_request_param_added', FALSE, postRequestArray());
2385 displayErrorMessage('{%message,ADMIN_NETWORK_REQUEST_PARAMETER_NOT_ADDED=' . postRequestElement('network_request_param_key') . '%}');
2389 // Adds a API response array entry
2390 function doAdminNetworkProcessAddNetworkArrayTranslation () {
2391 // Is the request parameter already used with given network?
2392 if (isNetworkArrayTranslationValid(postRequestElement('network_array_index'), postRequestElement('network_type_id'), getRequestElement('network_id'))) {
2394 displayErrorMessage('{%message,ADMIN_NETWORK_ARRAY_TRANSLATION_ALREADY_ADDED=' . postRequestElement('network_array_index') . '%}');
2396 // ... so abort here
2401 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
2404 setPostRequestElement('network_array_sort', (countSumTotalData(
2405 bigintval(postRequestElement('network_id')),
2406 'network_array_translation',
2410 sprintf(" AND `network_type_id`=%s", bigintval(postRequestElement('network_type_id')))
2413 // Add the whole request to database
2414 sqlQuery(getInsertSqlFromArray(postRequestArray(), 'network_array_translation'), __FUNCTION__, __LINE__);
2417 if (!ifSqlHasZeroAffectedRows()) {
2418 // Successfully added
2419 loadTemplate('admin_network_array_translation_added', FALSE, postRequestArray());
2422 displayErrorMessage('{%message,ADMIN_NETWORK_ARRAY_TRANSLATION_NOT_ADDED=' . postRequestElement('network_array_index') . '%}');
2426 // Handle network array translation form
2427 function doAdminNetworkProcessHandleArrayTranslations () {
2428 // Is there selections?
2429 if (ifPostContainsSelections()) {
2431 $GLOBALS['network_array_translation_disabled'] = array();
2433 // Load network data
2434 $networkData = getNetworkDataFromId(getRequestElement('network_id'));
2436 // Something has been selected, so start displaying one by one
2438 foreach (postRequestElement('sel') as $networkId => $sel) {
2439 // Is this selected?
2441 // Load this network's data
2442 $networkTranslationsData = getNetworkArrayTranslationsDataFromId($networkId);
2444 // Is there found the network?
2445 if (isFilledArray($networkTranslationsData)) {
2446 if (getNetworkFormName() == 'edit') {
2447 // Add row template for deleting
2448 $OUT .= loadTemplate('admin_edit_network_array_translation_row', TRUE, $networkTranslationsData);
2449 } elseif (getNetworkFormName() == 'delete') {
2451 $networkTranslationsData['network_type_data'] = getNetworkTypeDataByTypeId($networkTranslationsData['network_type_id']);
2453 // Add row template for deleting
2454 $OUT .= loadTemplate('admin_delete_network_array_translation_row', TRUE, $networkTranslationsData);
2457 reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/delete. data=<pre>' . print_r(postRequestArray(), TRUE) . '</pre>');
2463 // If there are no rows, we don't need to display the edit form
2465 // Prepare array with generic elements
2468 'network_id' => bigintval(getRequestElement('network_id'))
2471 // Output main template
2472 if (getNetworkFormName() == 'edit') {
2473 loadTemplate('admin_edit_network_array_translation', FALSE, $content);
2474 } elseif (getNetworkFormName() == 'delete') {
2475 loadTemplate('admin_delete_network_array_translation', FALSE, $content);
2478 reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/delete. data=<pre>' . print_r(postRequestArray(), TRUE) . '</pre>');
2481 // Don't display the list/add new form
2482 $GLOBALS['network_display'] = FALSE;
2484 // Nothing selected/found
2485 displayErrorMessage('{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_FOUND--}');
2490 // Adds/update network API configuration
2491 function doAdminNetworkProcessNetworkApiConfig () {
2493 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
2495 // NULL empty values
2496 foreach (array('network_api_site_id', 'network_api_referral_button', 'network_api_visual_pay_check') as $key) {
2498 if (!isPostRequestElementSet($key)) {
2499 // Remove empty value to get a NULL for an optional entry
2500 unsetPostRequestElement($key);
2504 // Is there already an entry?
2505 if (isNetworkApiConfigured(getRequestElement('network_id'))) {
2506 // Generate SQL query
2507 $SQL = getUpdateSqlFromArray(postRequestArray(), 'network_api_config', 'network_id', postRequestElement('network_id'), array('network_id'));
2510 $SQL = getInsertSqlFromArray(postRequestArray(), 'network_api_config');
2514 sqlQuery($SQL, __FUNCTION__, __LINE__);
2517 if (!ifSqlHasZeroAffectedRows()) {
2518 // Successfully added
2519 displayMessage('{--ADMIN_CONFIG_NETWORK_API_SAVED--}');
2522 displayErrorMessage('{--ADMIN_CONFIG_NETWORK_API_NOT_SAVED--}');
2526 // Only adds network type configuration if not yet present
2527 function doAdminNetworkProcessAddHandlerTypesConfig ($displayMessage = TRUE, $convertComma = TRUE) {
2529 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
2530 setPostRequestElement('network_type_id', bigintval(getRequestElement('network_type_id')));
2532 // Convert comma to dot?
2533 if ($convertComma === TRUE) {
2534 // Translate German comma to dot
2535 convertCommaToDotInPostData('network_min_payment');
2536 convertCommaToDotInPostData('network_min_remain_budget');
2537 convertCommaToDotInPostData('network_min_remain_clicks');
2541 * Some parameters are optional, at least one must be given so check a bunch
2544 foreach (array('network_min_waiting_time', 'network_max_waiting_time', 'network_min_remain_budget', 'network_min_remain_clicks', 'network_min_payment', 'network_allow_erotic', 'network_media_size', 'network_media_output') as $element) {
2545 // Is this element empty?
2546 if (!isPostRequestElementSet($element)) {
2547 // Then unset it to get a NULL for optional parameter
2548 unsetPostRequestElement($element);
2552 // Convert data in POST array
2553 convertSelectionsToEpocheTimeInPostData('network_max_reload_time_ye');
2555 // Is there already an entry?
2556 if (isNetworkTypeHandlerConfigured(getRequestElement('network_id'), getRequestElement('network_type_id'))) {
2557 // This network type handler is already configured
2558 displayMessage('{--ADMIN_NETWORK_HANDLER_TYPE_HANDLER_ALREADY_CONFIGURED--}');
2562 // Copy 'set all' and remove it from POST data
2563 $setAll = (postRequestElement('set_all') === 'Y');
2564 unsetPostRequestElement('set_all');
2566 // Shall we set for all?
2567 if ($setAll === TRUE) {
2569 $result = sqlQueryEscaped('SELECT `network_type_id` FROM `{?_MYSQL_PREFIX?}_network_types` WHERE `network_id`=%s ORDER BY `network_type_id` ASC',
2570 array(bigintval(getRequestElement('network_id'))), __FUNCTION__, __LINE__);
2572 // Are there entries?
2573 if (ifSqlHasZeroNums($result)) {
2574 // No, then abort here
2575 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_SET_ALL_404--}');
2579 // Init number of rows
2583 while (list($typeId) = sqlFetchRow($result)) {
2584 // Set it in GET data
2585 setGetRequestElement('network_type_id', $typeId);
2587 // Call this function again
2588 $numRows += doAdminNetworkProcessAddHandlerTypesConfig(FALSE, FALSE);
2592 sqlFreeResult($result);
2596 // Something has been updated
2597 displayMessage('{%message,ADMIN_CONFIG_NETWORK_HANDLER_TYPE_ALL_HANDLER_SAVED=' . bigintval($numRows) . '%}');
2599 // Nothing has been saved
2600 displayErrorMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}');
2603 // Get SQL query for new entry
2604 $SQL = getInsertSqlFromArray(postRequestArray(), 'network_handler_config');
2607 sqlQuery($SQL, __FUNCTION__, __LINE__);
2609 // Shall we display the message?
2610 if ($displayMessage === TRUE) {
2612 if (!ifSqlHasZeroAffectedRows()) {
2613 // Successfully added
2614 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_SAVED--}');
2617 displayErrorMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_SAVED--}');
2620 // Return amount of affected rows (1 or 2)
2621 return sqlAffectedRows();
2626 // Only changes network type configuration if not yet present
2627 function doAdminNetworkProcessEditHandlerTypesConfig ($displayMessage = TRUE, $convertComma = TRUE) {
2628 // Convert comma to dot?
2629 if ($convertComma === TRUE) {
2630 // Translate German comma to dot
2631 convertCommaToDotInPostData('network_min_payment');
2632 convertCommaToDotInPostData('network_min_remain_budget');
2633 convertCommaToDotInPostData('network_min_remain_clicks');
2637 * Some parameters are optional, at least one must be given so check a bunch
2640 foreach (array('network_min_waiting_time', 'network_max_waiting_time', 'network_min_remain_budget', 'network_min_remain_clicks', 'network_min_payment', 'network_allow_erotic', 'network_media_size', 'network_media_output') as $element) {
2641 // Is this element empty?
2642 if (!isPostRequestElementSet($element)) {
2643 // Then unset it to get a NULL for optional parameter
2644 unsetPostRequestElement($element);
2648 // Convert time selections in POST data
2649 convertSelectionsToEpocheTimeInPostData('network_max_reload_time_ye');
2651 // Is there already an entry?
2652 if (!isNetworkTypeHandlerConfigured(getRequestElement('network_id'), getRequestElement('network_type_id'))) {
2653 // This network type handler is not configured
2654 displayMessage('{--ADMIN_NETWORK_HANDLER_TYPE_HANDLER_NOT_CONFIGURED--}');
2658 // Copy 'set all' and remove it from POST data
2659 $setAll = (postRequestElement('set_all') === 'Y');
2660 unsetPostRequestElement('set_all');
2662 // Shall we set for all?
2663 if ($setAll === TRUE) {
2664 // Get all data entries
2665 $result = sqlQueryEscaped('SELECT `network_data_id` FROM `{?_MYSQL_PREFIX?}_network_handler_config` WHERE `network_id`=%s ORDER BY `network_type_id` ASC',
2666 array(bigintval(getRequestElement('network_id'))), __FUNCTION__, __LINE__);
2668 // Are there entries?
2669 if (ifSqlHasZeroNums($result)) {
2670 // No, then abort here
2671 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_SET_ALL_404--}');
2675 // Init number of rows
2679 while (list($dataId) = sqlFetchRow($result)) {
2680 // Set it in GET data
2681 setPostRequestElement('network_data_id', $dataId);
2683 // Call this function again
2684 $numRows += doAdminNetworkProcessEditHandlerTypesConfig(FALSE, FALSE);
2688 sqlFreeResult($result);
2692 // Something has been updated
2693 displayMessage('{%message,ADMIN_CONFIG_NETWORK_HANDLER_TYPE_ALL_HANDLER_SAVED=' . bigintval($numRows) . '%}');
2695 // Nothing has been saved
2696 displayErrorMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}');
2699 // Get SQL query for new entry
2700 $SQL = getUpdateSqlFromArray(postRequestArray(), 'network_handler_config', 'network_data_id', postRequestElement('network_data_id'), array('network_data_id'));
2703 sqlQuery($SQL, __FUNCTION__, __LINE__);
2705 // Shall we display the message?
2706 if ($displayMessage === TRUE) {
2708 if (!ifSqlHasZeroAffectedRows()) {
2709 // Successfully added
2710 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_SAVED--}');
2713 displayErrorMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}');
2716 // Return amount of affected rows (1 or 2)
2717 return sqlAffectedRows();
2722 // Do expression code for this extension
2723 function doExpressionNetwork ($data) {
2724 // Construct replacer
2725 $replacer = sprintf(
2726 "{DQUOTE} . %s(%s, '%s') . {DQUOTE}",
2728 $data['matches'][4][$data['key']],
2732 // Check matches[2] as it might contain more clues to look for
2733 $moreData = explode(',', $data['matches'][2][$data['key']]);
2735 // First must be 'network' so unshift it
2736 shift_array($moreData, 'network');
2738 // The second element must be a callable function
2739 if (!is_callable($moreData[0])) {
2741 reportBug(__FUNCTION__, __LINE__, 'Call-back function ' . $moreData[0] . ' cannot be called.');
2744 // Is the current network id set?
2745 if (isCurrentNetworkIdSet()) {
2746 // Replace %network_id% with the current network id
2747 $replacer = str_replace('%network_id%', getCurrentNetworkId(), $replacer);
2751 $code = replaceExpressionCode($data, $replacer);
2757 // ----------------------------------------------------------------------------
2758 // Call-back functions for exporting data
2759 // ----------------------------------------------------------------------------
2761 // Callback function to export network tables
2762 function doAdminNetworkProcessExport () {
2763 // Init table with all valid what->table entries
2764 $validExports = array(
2765 // General network data
2766 'list_network_data' => 'data',
2767 // Network type handler
2768 'list_network_types' => 'types',
2769 // Network request parameter
2770 'list_network_request_params' => 'request_params',
2771 // Network API response array index translation
2772 'list_network_array_translation' => 'array_translation',
2775 // Is the 'what' key valid?
2776 if (!isset($validExports[getWhat()])) {
2778 reportBug(__FUNCTION__, __LINE__, 'what=' . getWhat() . ' - not supported');
2781 // Generate call-back, some tables require to export not all columns
2782 $callbackName = 'doAdminNetworkExport' . capitalizeUnderscoreString($validExports[getWhat()]);
2784 // Is the call-back function there?
2785 if (!function_exists($callbackName)) {
2786 // No, this is really bad
2787 reportBug(__FUNCTION__, __LINE__, 'Invalid call-back function ' . $callbackName . ' detected.');
2788 } elseif (isset($GLOBALS[__FUNCTION__][$callbackName])) {
2790 reportBug(__FUNCTION__, __LINE__, 'Double-call of export function ' . $callbackName . ' detected.');
2793 // Call the function
2794 call_user_func($callbackName);
2796 // Mark it as called
2797 $GLOBALS[__FUNCTION__][$callbackName] = TRUE;
2799 // Don't display the list/add new form
2800 $GLOBALS['network_display'] = FALSE;
2803 // Exports (and displays) the table 'network_data'
2804 function doAdminNetworkExportData () {
2805 // Query for all networks
2806 $result = sqlQuery('SELECT
2807 `network_short_name`,
2810 `network_data_separator`,
2811 `network_row_separator`,
2812 `network_request_type`,
2814 `network_require_id_card`,
2815 `network_query_amount`,
2818 `{?_MYSQL_PREFIX?}_network_data`
2821 __FUNCTION__, __LINE__);
2823 // Start an empty SQL query
2824 $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' . PHP_EOL;
2827 while ($content = sqlFetchArray($result)) {
2830 $content['network_short_name'] . "', '" .
2831 $content['network_title'] . "', '" .
2832 $content['network_reflink'] . "', '" .
2833 $content['network_data_separator'] . "', '" .
2834 $content['network_row_separator'] . "', '" .
2835 $content['network_request_type'] . "', '" .
2836 $content['network_charset'] . "', '" .
2837 $content['network_require_id_card'] . "', " .
2838 $content['network_query_amount'] . ", '" .
2839 $content['network_active'] . "'),\n";
2842 // Remove last commata and close braces
2843 $SQL = substr($SQL, 0, -2);
2846 sqlFreeResult($result);
2848 // Output the SQL query
2849 loadTemplate('admin_export_network_data', FALSE, $SQL);
2852 // Exports (and displays) the table 'network_types'
2853 function doAdminNetworkExportTypes () {
2854 // 'network_id' must be set
2855 if (!isGetRequestElementSet('network_id')) {
2856 // Only network handlers of one network will be exported per time
2857 reportBug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
2860 // Get all network types of given network
2861 $result = sqlQueryEscaped('SELECT
2864 `network_type_handler`,
2865 `network_type_api_url`,
2866 `network_type_click_url`,
2867 `network_type_banner_url`,
2868 `network_type_reload_time_unit`,
2869 `network_text_encoding`
2871 `{?_MYSQL_PREFIX?}_network_types`
2875 `network_type_id` ASC',
2877 bigintval(getRequestElement('network_id'))
2878 ), __FUNCTION__, __LINE__);
2880 // Start an empty SQL query
2881 $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' . PHP_EOL;
2884 while ($content = sqlFetchArray($result)) {
2887 $content['network_type_id'] . ', ' .
2888 $content['network_id'] . ", '" .
2889 $content['network_type_handler'] . "', '" .
2890 $content['network_type_api_url'] . "', ";
2892 // Is the column NULL?
2893 if ((is_null($content['network_type_click_url'])) || (empty($content['network_type_click_url']))) {
2898 $SQL .= chr(39) . $content['network_type_click_url'] . chr(39) . ', ';
2901 // Is the column NULL?
2902 if ((is_null($content['network_type_banner_url'])) || (empty($content['network_type_banner_url']))) {
2907 $SQL .= chr(39) . $content['network_type_banner_url'] . chr(39) . ', ';
2911 $SQL .= chr(39) . $content['network_type_reload_time_unit'] . "','" . $content['network_text_encoding'] . "'),\n";
2914 // Remove last commata and close braces
2915 $SQL = substr($SQL, 0, -2);
2918 sqlFreeResult($result);
2920 // Output the SQL query
2921 loadTemplate('admin_export_network_types', FALSE, $SQL);
2924 // Exports (and displays) the table 'network_request_params'
2925 function doAdminNetworkExportRequestParams () {
2926 // 'network_id' must be set
2927 if (!isGetRequestElementSet('network_id')) {
2928 // Only network request parameters of one network will be exported per time
2929 reportBug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
2932 // Get all network types of given network
2933 $result = sqlQueryEscaped('SELECT
2936 `network_request_param_key`,
2937 `network_request_param_value`,
2938 `network_request_param_default`
2940 `{?_MYSQL_PREFIX?}_network_request_params`
2944 `network_type_id` ASC ,
2945 `network_request_param_id` ASC',
2947 bigintval(getRequestElement('network_id'))
2948 ), __FUNCTION__, __LINE__);
2950 // Start an empty SQL query
2951 $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' . PHP_EOL;
2954 while ($content = sqlFetchArray($result)) {
2957 $content['network_id'] . ', ' .
2958 $content['network_type_id'] . ", '" .
2959 $content['network_request_param_key'] . "', '" .
2960 $content['network_request_param_value'] . "', ";
2962 // Is the column NULL?
2963 if (is_null($content['network_request_param_default'])) {
2968 $SQL .= chr(39) . $content['network_request_param_default'] . "'),\n";
2972 // Remove last commata and close braces
2973 $SQL = substr($SQL, 0, -2);
2976 sqlFreeResult($result);
2978 // Output the SQL query
2979 loadTemplate('admin_export_network_request_params', FALSE, $SQL);
2982 // Exports (and displays) the table 'network_array_translation'
2983 function doAdminNetworkExportArrayTranslation () {
2984 // 'network_id' must be set
2985 if (!isGetRequestElementSet('network_id')) {
2986 // Only network API array index translations of one network will be exported per time
2987 reportBug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
2990 // Get all network types of given network
2991 $result = sqlQueryEscaped('SELECT
2994 `network_array_index`,
2995 `network_array_sort`
2997 `{?_MYSQL_PREFIX?}_network_array_translation`
3001 `network_type_id` ASC,
3002 `network_array_sort` ASC',
3004 bigintval(getRequestElement('network_id'))
3005 ), __FUNCTION__, __LINE__);
3007 // Start an empty SQL query
3008 $SQL = 'INSERT INTO `{?_MYSQL_PREFIX?}_network_array_translation` (`network_id`, `network_type_id`, `network_array_index`, `network_array_sort`) VALUES' . PHP_EOL;
3011 while ($content = sqlFetchArray($result)) {
3014 $content['network_id'] . ', ' .
3015 $content['network_type_id'] . ', ' .
3016 $content['network_array_index'] . ', ' .
3017 $content['network_array_sort'] . "),\n";
3020 // Remove last commata and close braces
3021 $SQL = substr($SQL, 0, -2);
3024 sqlFreeResult($result);
3026 // Output the SQL query
3027 loadTemplate('admin_export_network_array_translation', FALSE, $SQL);
3030 // ----------------------------------------------------------------------------
3031 // Call-back functions for AJAX requests
3032 // ----------------------------------------------------------------------------
3034 // AJAX call-back function for quering a single API
3035 function doAjaxAdminNetworkQuerySingleApi () {
3036 // This must be be done only by admins
3038 // Only allowed for admins
3039 reportBug(__FUNCTION__, __LINE__, 'Only allowed for admins.');
3040 } elseif (!isPostRequestElementSet('network_type_id')) {
3041 // Required POST field 'network_type_id' is not there
3042 reportBug(__FUNCTION__, __LINE__, 'Required POST field "network_type_id" is missing.');
3045 // Get network + type handler data
3046 $networkData = getNetworkDataByTypeId(postRequestElement('network_type_id'));
3049 if (is_null($networkData)) {
3050 // Provided type id is not found
3051 reportBug(__FUNCTION__, __LINE__, 'Requested network type id ' . postRequestElement('network_type_id') . ' does not exist.');
3052 } elseif ((!isDebugModeEnabled()) && ($networkData['network_active'] == 'N')) {
3053 // Network not active
3054 reportBug(__FUNCTION__, __LINE__, 'Network ' . $networkData['network_title'] . ' is not active. network_id=' . $networkData['network_id'] . ',network_type_id=' . postRequestElement('network_type_id'));
3055 } elseif (!isNetworkApiConfigured($networkData['network_id'])) {
3056 // Network not configured
3057 reportBug(__FUNCTION__, __LINE__, 'Network ' . $networkData['network_title'] . ' is not configured yet. network_id=' . $networkData['network_id'] . ',network_type_id=' . postRequestElement('network_type_id'));
3058 } elseif (!isNetworkTypeHandlerConfigured($networkData['network_id'], postRequestElement('network_type_id'))) {
3059 // Network type handler not configured
3060 reportBug(__FUNCTION__, __LINE__, 'Network type handler ' . $networkData['network_type_handler'] . ' for network ' . $networkData['network_title'] . ' is not configured yet. network_id=' . $networkData['network_id'] . ',network_type_id=' . postRequestElement('network_type_id'));
3063 // Now load request parameters
3064 $requestParams = getNetworkRequestParametersByTypeId(postRequestElement('network_type_id'));
3066 // Is there at least one entry?
3067 if (!isFilledArray($requestParams)) {
3068 // No entry found, please setup some first
3069 reportBug(__FUNCTION__, __LINE__, 'Network ' . $networkData['network_title'] . ' with id ' . $networkData['network_id'] . ' has no request parameters.');
3073 handleNetworkRequestParameterKeys($requestParams);
3076 * Array element network_request_param_value contains the request parameter
3077 * keys, network_request_param_default contains values. Now the request can
3080 $requestData = array();
3081 foreach ($requestParams as $key => $params) {
3083 $requestData[$params['network_request_param_value']] = $params['network_request_param_default'];
3086 // Everything is setup and ready to send out to the affiliate network's API
3087 $response = queryNetworkApi($networkData, $requestData);
3089 // Is the returned HTTP status '200 OK'?
3090 if (!isHttpStatusOkay($response[0])) {
3091 // Not HTTP/1.x 200 OK
3092 reportBug(__FUNCTION__, __LINE__, 'HTTP response code is not 200 OK, have: ' . $response[0]);
3095 // Load "success" message
3096 setAjaxReplyContent('{%message,ADMIN_NETWORK_QUERY_TYPE_OKAY=' . $networkData['network_title'] . '%}');
3099 setHttpStatus('200 OK');
3102 // AJAX call-back function to return a JSON with all network type handler ids
3103 function doAjaxAdminNetworkListById () {
3104 // This must be be done only by admins
3106 // Only allowed for admins
3107 reportBug(__FUNCTION__, __LINE__, 'Only allowed for admins.');
3108 } elseif (!isPostRequestElementSet('network_id')) {
3109 // Required POST field 'network_id' is not there
3110 reportBug(__FUNCTION__, __LINE__, 'Required POST field "network_id" is missing.');
3113 // Load all network type handlers by given network id and extract only network_type_id
3114 $networkTypes = getArrayFromArrayIndex(getNetworkTypeDataFromId(postRequestElement('network_id')), 'network_type_id');
3116 // Set generated array
3117 setAjaxReplyContent(encodeJson($networkTypes));
3120 setHttpStatus('200 OK');