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 - 2011 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 // Handle a (maybe) sent form here
54 function doNetworkHandleForm () {
56 if ((isFormSent()) || (isFormSent('edit')) || (isFormSent('delete')) || (isFormSent('do_edit')) || (isFormSent('do_delete'))) {
58 if (isGetRequestElementSet('do')) {
59 // Process the request
60 doAdminNetworkProcessForm();
63 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_DO_404--}');
68 // Processes an admin form
69 function doAdminNetworkProcessForm () {
71 if ((!isFormSent()) && (!isFormSent('edit')) && (!isFormSent('delete')) && (!isFormSent('do_edit')) && (!isFormSent('do_delete'))) {
73 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_FORM_NOT_SENT--}');
75 } elseif (!isGetRequestElementSet('do')) {
77 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_DO_404--}');
81 // Create function name
82 $functionName = sprintf("doAdminNetworkProcess%s", capitalizeUnderscoreString(getRequestElement('do')));
84 // Is the function valid?
85 if (!function_exists($functionName)) {
86 // Invalid function name
87 debug_report_bug(__FUNCTION__, __LINE__, 'Invalid do ' . getRequestElement('do') . ', function ' . $functionName .' does not exist.', false);
90 // Call-back the method handling our request
91 call_user_func($functionName);
94 // Checks wether the (short) network name is already used (valid)
95 function isNetworkNameValid ($name) {
97 $result = SQL_QUERY_ESC("SELECT `network_id` FROM `{?_MYSQL_PREFIX?}_network_data` WHERE `network_short_name`='%s' LIMIT 1",
98 array($name), __FUNCTION__, __LINE__);
101 $isValid = (SQL_NUMROWS($result) == 1);
104 SQL_FREERESULT($result);
110 // Checks wether the given network type is already used (valid)
111 function isNetworkTypeHandleValid ($type, $networkId) {
113 $result = SQL_QUERY_ESC("SELECT `network_type_id` FROM `{?_MYSQL_PREFIX?}_network_types` WHERE `network_id`=%s AND `network_type_handle`='%s' LIMIT 1",
114 array($networkId, $type), __FUNCTION__, __LINE__);
117 $isValid = (SQL_NUMROWS($result) == 1);
120 SQL_FREERESULT($result);
126 // Checks wether the given network request parameter is already used (valid)
127 function isNetworkRequestElementValid ($key, $type, $networkId) {
129 $result = SQL_QUERY_ESC("SELECT `network_param_id` FROM `{?_MYSQL_PREFIX?}_network_request_params` WHERE `network_id`=%s AND `network_type_id`=%s AND `request_param_key`='%s' LIMIT 1",
130 array($networkId, $type, $key), __FUNCTION__, __LINE__);
133 $isValid = (SQL_NUMROWS($result) == 1);
136 SQL_FREERESULT($result);
142 // Checks wether the given network API array translation
143 function isNetworkApiTranslationValid ($key, $type, $networkId) {
145 $result = SQL_QUERY_ESC("SELECT `network_api_id` FROM `{?_MYSQL_PREFIX?}_network_api_translation` WHERE `network_id`=%s AND `network_type_id`=%s AND `network_api_index`='%s' LIMIT 1",
146 array($networkId, $type, $key), __FUNCTION__, __LINE__);
149 $isValid = (SQL_NUMROWS($result) == 1);
152 SQL_FREERESULT($result);
158 // "Getter" for a network's data by provided id number
159 function getNetworkDataById ($networkId, $column = '') {
160 // Ids lower one are not accepted
161 if ($networkId < 1) {
162 // Not good, should be fixed
163 debug_report_bug(__FUNCTION__, __LINE__, 'Network id ' . $networkId . ' is smaller than 1.');
166 // Set current network id
167 setCurrentNetworkId($networkId);
170 if (!isset($GLOBALS['network_data'][$networkId])) {
171 // By default we have no data
172 $GLOBALS['network_data'][$networkId] = array();
174 // Query for the network data
175 $result = SQL_QUERY_ESC("SELECT
176 `network_id`,`network_short_name`,`network_title`,`network_reflink`,`network_data_seperator`,`network_row_seperator`,`network_request_type`,`network_charset`
178 `{?_MYSQL_PREFIX?}_network_data`
182 array(bigintval($networkId)), __FUNCTION__, __LINE__);
184 // Do we have an entry?
185 if (SQL_NUMROWS($result) == 1) {
187 $GLOBALS['network_data'][$networkId] = SQL_FETCHARRAY($result);
191 SQL_FREERESULT($result);
195 if (empty($column)) {
197 return $GLOBALS['network_data'][$networkId];
200 return $GLOBALS['network_data'][$networkId][$column];
204 // "Getter" for a network's data by provided type id number
205 function getNetworkDataByTypeId ($networkId, $column = '') {
206 // Ids lower one are not accepted
207 if ($networkId < 1) {
208 // Not good, should be fixed
209 debug_report_bug(__FUNCTION__, __LINE__, 'Network type id ' . $networkId . ' is smaller than 1.');
212 // Set current network id
213 setCurrentNetworkId($networkId);
216 if (!isset($GLOBALS['network_data'][$networkId])) {
217 // By default we have no data
218 $GLOBALS['network_data'][$networkId] = array();
220 // Query for the network data
221 $result = SQL_QUERY_ESC("SELECT
222 d.`network_id`, d.`network_short_name`, d.`network_title`, d.`network_reflink`, d.`network_data_seperator`, d.`network_row_seperator`, d.`network_request_type`, d.`network_charset`,
223 t.`network_type_handle`, t.`network_type_api_url`, t.`network_type_click_url`, t.`network_type_banner_url`
225 `{?_MYSQL_PREFIX?}_network_data` AS d
227 `{?_MYSQL_PREFIX?}_network_types` AS t
229 d.`network_id`=t.`network_id`
231 t.`network_type_id`=%s
233 array(bigintval($networkId)), __FUNCTION__, __LINE__);
235 // Do we have an entry?
236 if (SQL_NUMROWS($result) == 1) {
238 $GLOBALS['network_data'][$networkId] = SQL_FETCHARRAY($result);
242 SQL_FREERESULT($result);
246 if (empty($column)) {
248 return $GLOBALS['network_data'][$networkId];
251 return $GLOBALS['network_data'][$networkId][$column];
255 // "Getter" for a network type data by provided id number
256 function getNetworkTypeDataById ($networkId) {
257 // Ids lower one are not accepted
258 if ($networkId < 1) {
259 // Not good, should be fixed
260 debug_report_bug(__FUNCTION__, __LINE__, 'Network type id ' . $networkId . ' is smaller than 1.');
263 // By default we have no data
264 $GLOBALS['network_type_data'][$networkId] = array();
266 // Query for the network data
267 $result = SQL_QUERY_ESC("SELECT
268 `network_type_id`,`network_id`,`network_type_handle`,`network_type_api_url`,`network_type_click_url`,`network_type_banner_url`
270 `{?_MYSQL_PREFIX?}_network_types`
274 array(bigintval($networkId)), __FUNCTION__, __LINE__);
276 // Do we have an entry?
277 if (SQL_NUMROWS($result) == 1) {
279 $GLOBALS['network_type_data'][$networkId] = SQL_FETCHARRAY($result);
283 SQL_FREERESULT($result);
286 return $GLOBALS['network_type_data'][$networkId];
289 // "Getter" for a network request parameter data by provided id number
290 function getNetworkRequestParamsDataById ($networkId) {
291 // Ids lower one are not accepted
292 if ($networkId < 1) {
293 // Not good, should be fixed
294 debug_report_bug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $networkId . ' is smaller than 1.');
297 // By default we have no data
298 $networkRequestData = array();
300 // Query for the network data
301 $result = SQL_QUERY_ESC("SELECT
302 `network_param_id`,`network_id`,`network_type_id`,`request_param_key`,`request_param_value`,`request_param_default`
304 `{?_MYSQL_PREFIX?}_network_request_params`
306 `network_param_id`=%s
308 array(bigintval($networkId)), __FUNCTION__, __LINE__);
310 // Do we have an entry?
311 if (SQL_NUMROWS($result) == 1) {
313 $networkRequestData = SQL_FETCHARRAY($result);
317 SQL_FREERESULT($result);
320 return $networkRequestData;
323 // Updates given network (id) with data from array
324 function doNetworkUpdateDataByArray ($networkId, $networkData) {
325 // Ids lower one are not accepted
326 if ($networkId < 1) {
327 // Not good, should be fixed
328 debug_report_bug(__FUNCTION__, __LINE__, 'Network id ' . $networkId . ' is smaller than 1.');
331 // Just call our inner method
332 return adminSaveSettings($networkData, '_network_data', sprintf("`network_id`=%s", bigintval($networkId)), array(), false, false);
335 // Updates given network type handler (id) with data from array
336 function doNetworkUpdateTypeByArray ($networkId, $networkTypeData) {
337 // Ids lower one are not accepted
338 if ($networkId < 1) {
339 // Not good, should be fixed
340 debug_report_bug(__FUNCTION__, __LINE__, 'Network type handler id ' . $networkId . ' is smaller than 1.');
343 // Just call our inner method
344 return adminSaveSettings($networkTypeData, '_network_types', sprintf("`network_type_id`=%s", bigintval($networkId)), array(), false, false);
347 // Updates given network request parameters (id) with data from array
348 function doNetworkUpdateParamsByArray ($networkId, $networkParamData) {
349 // Ids lower one are not accepted
350 if ($networkId < 1) {
351 // Not good, should be fixed
352 debug_report_bug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $networkId . ' is smaller than 1.');
355 // Just call our inner method
356 return adminSaveSettings($networkParamData, '_network_request_params', sprintf("`network_param_id`=%s", bigintval($networkId)), array(), false, false);
359 // Removes given network entry
360 function doAdminRemoveNetworkEntry ($table, $column, $networkId, $limit = 1) {
362 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_network_%s` WHERE `%s`=%s LIMIT %s",
363 array($table, $column, $networkId, $limit), __FUNCTION__, __LINE__);
365 // Return affected rows
366 return SQL_AFFECTEDROWS();
369 // Generates a list of networks for given script and returns it
370 function generateAdminNetworkList () {
374 // Query for all networks
375 $result = SQL_QUERY('SELECT
376 `network_id`,`network_short_name`,`network_title`
378 `{?_MYSQL_PREFIX?}_network_data`
380 `network_short_name` ASC', __FUNCTION__, __LINE__);
382 // Do we have entries?
383 if (!SQL_HASZERONUMS($result)) {
386 while ($row = SQL_FETCHARRAY($result)) {
387 // Is this valid, then add it
388 if ((is_array($row)) && (isset($row['network_id']))) {
390 $rows[$row['network_id']] = $row;
394 // Generate the selection box
395 $content = generateSelectionBoxFromArray($rows, 'network', 'network_id');
398 $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}');
402 SQL_FREERESULT($result);
408 // Generator (somewhat getter) for a list of network types for given network id
409 function generateAdminNetworkTypeList ($networkId) {
413 // Query all types of this network
414 $result = SQL_QUERY_ESC("SELECT
415 `network_type_id`,`network_type_handle`
417 `{?_MYSQL_PREFIX?}_network_types`
421 `network_type_handle` ASC",
423 bigintval($networkId)
424 ), __FUNCTION__, __LINE__);
426 // Do we have entries?
427 if (!SQL_HASZERONUMS($result)) {
430 while ($row = SQL_FETCHARRAY($result)) {
431 // Is this valid, then add it
432 if ((is_array($row)) && (isset($row['network_type_id']))) {
434 $rows[$row['network_type_id']] = $row;
438 // Generate the selection box
439 $content = generateSelectionBoxFromArray($rows, 'network_type', 'network_type_id');
442 $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}');
446 SQL_FREERESULT($result);
452 // Generator (somewhat getter) for a list of network types for all types
453 function generateAdminDistinctNetworkTypeList () {
457 // Query all types of this network
458 $result = SQL_QUERY('SELECT
459 t.`network_type_id`, t.`network_type_handle`, d.`network_title`
461 `{?_MYSQL_PREFIX?}_network_types` AS t
463 `{?_MYSQL_PREFIX?}_network_data` AS d
465 t.`network_id`=d.`network_id`
467 d.`network_short_name` ASC,
468 t.`network_type_handle` ASC', __FUNCTION__, __LINE__);
470 // Do we have entries?
471 if (!SQL_HASZERONUMS($result)) {
474 while ($row = SQL_FETCHARRAY($result)) {
475 // Is this valid, then add it
476 if ((is_array($row)) && (isset($row['network_type_id']))) {
478 $rows[$row['network_type_id']] = $row;
482 // Generate the selection box
483 $content = generateSelectionBoxFromArray($rows, 'network_type', 'network_type_id', '', '_title');
486 $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}');
490 SQL_FREERESULT($result);
491 //* DEBUG: */ die('<pre>'.encodeEntities($content).'</pre>');
497 // Generator (somewhat getter) for network type options
498 function generateNetworkTypeOptions ($networkId) {
499 // Is this an array, then we just came back from edit/delete actions
500 if (is_array($networkId)) {
505 if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
506 // Generate output and cache it
507 $GLOBALS[__FUNCTION__][$networkId] = generateOptionList(
510 'network_type_handle',
514 "WHERE `network_id`=%s",
515 bigintval(getRequestElement('network'))
518 'translateNetworkTypeHandler'
523 return $GLOBALS[__FUNCTION__][$networkId];
526 // Generates an options list of all available (hard-coded) handlers
527 function generateNetworkTypesAvailableOptions () {
529 if (!isset($GLOBALS[__FUNCTION__])) {
531 $GLOBALS[__FUNCTION__] = generateOptionList(
567 $GLOBALS['network_types_disabled'],
568 'translateNetworkTypeHandler'
573 return $GLOBALS[__FUNCTION__];
576 // Generates an options list (somewhat getter) ofr request keys
577 function generateNetworkRequestKeyOptions () {
579 if (!isset($GLOBALS[__FUNCTION__])) {
580 // Generate and cache it
581 $GLOBALS[__FUNCTION__] = generateOptionList(
603 $GLOBALS['network_params_disabled'],
604 'translateNetworkRequestElement'
609 return $GLOBALS[__FUNCTION__];
612 // Generator (somewhat getter) for (return) array translation
613 function generateNetworkTranslationOptions ($default = '') {
615 if (!isset($GLOBALS[__FUNCTION__][$default])) {
616 // Generate and cache it
617 $GLOBALS[__FUNCTION__][$default] = generateOptionList(
618 'network_translations',
619 'network_translation_id',
620 'network_translation_name',
624 $GLOBALS['network_translation_disabled'],
625 'translateNetworkTranslationName'
630 return $GLOBALS[__FUNCTION__][$default];
633 // Generates an option list of request types
634 function generateNetworkRequestTypeOptions ($default = '') {
636 if (!isset($GLOBALS[__FUNCTION__][$default])) {
638 $GLOBALS[__FUNCTION__][$default] = generateOptionList(
645 '{--ADMIN_NETWORK_REQUEST_TYPE_GET--}',
646 '{--ADMIN_NETWORK_REQUEST_TYPE_POST--}'
653 return $GLOBALS[__FUNCTION__][$default];
656 // Generates an option list of network_api_active
657 function generateNetworkApiActiveOptions ($default = '') {
659 if (!isset($GLOBALS[__FUNCTION__][$default])) {
661 $GLOBALS[__FUNCTION__][$default] = generateYesNoOptionList($default);
665 return $GLOBALS[__FUNCTION__][$default];
668 // Translates 'translate_name' for e.g. templates
669 function translateNetworkTranslationName ($name) {
670 // Get the message id
671 return '{--ADMIN_NETWORK_TRANSLATE_' . strtoupper($name) . '_NAME--}';
674 // Translates the network type handler (e.g. banner, paidmail) for templates
675 function translateNetworkTypeHandler ($type) {
676 // Get the message id
677 return '{--ADMIN_NETWORK_TYPES_' . strtoupper($type) . '--}';
680 // Translates request type
681 function translateNetworkRequestType ($type) {
682 // Get the message id
683 return '{--ADMIN_NETWORK_REQUEST_TYPE_' . strtoupper($type) . '--}';
686 // Translates request parameter
687 function translateNetworkRequestElement ($param) {
688 // Get the message id
689 return '{--ADMIN_NETWORK_REQUEST_PARAMETER_' . strtoupper($param) . '--}';
692 // Translates API index
693 function translateNetworkApiIndex ($index) {
695 if (!isset($GLOBALS['network_api_index'])) {
696 // Get an array of all API array indexes
697 $GLOBALS['network_api_index'] = array();
700 $result = SQL_QUERY('SELECT
701 `network_api_id`,`network_api_index`,`network_translation_name`
703 `{?_MYSQL_PREFIX?}_network_api_translation`
705 `{?_MYSQL_PREFIX?}_network_translations`
707 `network_api_index`=`network_translation_id`
709 `sort` ASC', __FUNCTION__, __LINE__);
711 // Do we have entries?
712 if (!SQL_HASZERONUMS($result)) {
714 while ($row = SQL_FETCHARRAY($result)) {
715 // Add it to our global array
716 $GLOBALS['network_api_index'][$row['network_api_index']] = $row;
721 SQL_FREERESULT($result);
724 // Default name is unknown
727 // Is the entry there?
728 if (isset($GLOBALS['network_api_index'][$index])) {
730 $name = $GLOBALS['network_api_index'][$index]['network_translation_name'];
733 // Return translation
734 return translateNetworkTranslationName($name);
737 // Translates network API configuration status (see function isNetworkApiConfigured()) by given id
738 function translateNetworkApiConfiguredStatusById ($networkId) {
740 if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
741 // By default it is not configured
742 $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_NOT_CONFIGURED--}';
744 // So is it configured?
745 if (isNetworkApiConfigured($networkId)) {
747 $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_CONFIGURED--}';
752 return $GLOBALS[__FUNCTION__][$networkId];
755 // Checks if the given network is configured by looking its API configuration entry up
756 function isNetworkApiConfigured ($networkId) {
758 if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
759 // Check for an entry in network_api_config
760 $GLOBALS[__FUNCTION__][$networkId] = (countSumTotalData(
761 bigintval($networkId),
762 'network_api_config',
770 return $GLOBALS[__FUNCTION__][$networkId];
773 //------------------------------------------------------------------------------
774 // Call-back functions
775 //------------------------------------------------------------------------------
777 // Callback function to add new network
778 function doAdminNetworkProcessAddNetwork () {
779 // We can say here, the form is sent, so check if the network is already added
780 if (isNetworkNameValid(postRequestElement('network_short_name'))) {
782 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_ALREADY_ADDED=' . postRequestElement('network_short_name') . '%}');
786 // Remove the 'ok' part
787 unsetPostRequestElement('ok');
789 // Add the whole request to database
790 SQL_QUERY('INSERT INTO
791 `{?_MYSQL_PREFIX?}_network_data`
793 `' . implode('`,`', array_keys(postRequestArray())) . "`
795 '" . implode("','", array_values(postRequestArray())) . "'
796 )", __FUNCTION__, __LINE__);
798 // Add the id for output only
799 setPostRequestElement('network_id', SQL_INSERTID());
802 if (!SQL_HASZEROAFFECTED()) {
803 // Successfully added
804 loadTemplate('admin_network_added', false, postRequestArray());
807 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_DATA_NOT_ADDED=' . postRequestElement('network_short_name') . '%}');
811 // Displays selected networks for editing
812 function doAdminNetworkProcessHandleNetwork () {
813 // Do we have selections?
814 if (ifPostContainsSelections()) {
815 // Something has been selected, so start displaying one by one
817 foreach (postRequestElement('sel') as $networkId => $sel) {
820 // Load this network's data
821 $networkData = getNetworkDataById($networkId);
823 // Do we have found the network?
824 if (count($networkData) > 0) {
825 if (isFormSent('edit')) {
826 // Add row template for editing
827 $OUT .= loadTemplate('admin_edit_networks_row', true, $networkData);
828 } elseif (isFormSent('delete')) {
829 // Add row template for deleting
830 $OUT .= loadTemplate('admin_delete_networks_row', true, $networkData);
833 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
839 // If we have no rows, we don't need to display the edit form
841 // Output main template
842 if (isFormSent('edit')) {
843 loadTemplate('admin_edit_networks', false, $OUT);
844 } elseif (isFormSent('delete')) {
845 loadTemplate('admin_delete_networks', false, $OUT);
848 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
851 // Don't display the list/add new form
852 $GLOBALS['network_display'] = false;
854 // Nothing selected/found
855 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_FOUND--}');
860 // Handle network type form
861 function doAdminNetworkProcessHandleNetworkType () {
862 // Do we have selections?
863 if (ifPostContainsSelections()) {
865 $networkData = getNetworkDataById(getRequestElement('network'));
867 // Something has been selected, so start displaying one by one
869 foreach (postRequestElement('sel') as $networkId => $sel) {
872 // Load this network's data
873 $networkTypeData = getNetworkTypeDataById($networkId);
875 // Do we have found the network?
876 if (count($networkTypeData) > 0) {
877 if (isFormSent('edit')) {
878 // Add row template for deleting
879 $OUT .= loadTemplate('admin_edit_network_types_row', true, $networkTypeData);
880 } elseif (isFormSent('delete')) {
881 // Add row template for deleting
882 $OUT .= loadTemplate('admin_delete_network_types_row', true, $networkTypeData);
885 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
891 // If we have no rows, we don't need to display the edit form
893 // Output main template
894 if (isFormSent('edit')) {
895 loadTemplate('admin_edit_network_types', false, $OUT);
896 } elseif (isFormSent('delete')) {
897 loadTemplate('admin_delete_network_types', false, $OUT);
900 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
903 // Don't display the list/add new form
904 $GLOBALS['network_display'] = false;
906 // Nothing selected/found
907 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPES_NOTHING_FOUND--}');
912 // Handle network request parameter form
913 function doAdminNetworkProcessHandleRequestParams () {
914 // Do we have selections?
915 if (ifPostContainsSelections()) {
917 $GLOBALS['network_params_disabled'] = array();
920 $networkData = getNetworkDataById(getRequestElement('network'));
922 // Something has been selected, so start displaying one by one
924 foreach (postRequestElement('sel') as $networkId => $sel) {
927 // Load this network's data
928 $networkRequestData = getNetworkRequestParamsDataById($networkId);
930 // Do we have found the network?
931 if (count($networkRequestData) > 0) {
932 if (isFormSent('edit')) {
933 // Add row template for deleting
934 $OUT .= loadTemplate('admin_edit_network_params_row', true, $networkRequestData);
935 } elseif (isFormSent('delete')) {
937 $networkRequestData['network_type_data'] = getNetworkTypeDataById($networkRequestData['network_type_id']);
939 // Add row template for deleting
940 $OUT .= loadTemplate('admin_delete_network_params_row', true, $networkRequestData);
943 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
949 // If we have no rows, we don't need to display the edit form
951 // Output main template
952 if (isFormSent('edit')) {
953 loadTemplate('admin_edit_network_params', false, $OUT);
954 } elseif (isFormSent('delete')) {
955 loadTemplate('admin_delete_network_params', false, $OUT);
958 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
961 // Don't display the list/add new form
962 $GLOBALS['network_display'] = false;
964 // Nothing selected/found
965 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_FOUND--}');
970 // Changes given networks
971 function doAdminNetworkProcessChangeNetwork () {
972 // Do we have selections?
973 if (ifPostContainsSelections()) {
974 // By default nothing is updated
977 // Something has been selected, so start updating them
978 foreach (postRequestElement('sel') as $networkId => $sel) {
979 // Update this entry?
982 $networkData = array();
984 // Transfer whole array, except 'sel'
985 foreach (postRequestArray() as $key => $entry) {
986 // Skip 'sel' and submit button
987 if (in_array($key, array('sel', 'do_edit'))) {
991 // Do we have this enty?
992 if (!isset($entry[$networkId])) {
993 // Not found, needs fixing
994 debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
998 $networkData[$key] = $entry[$networkId];
1001 // Update the network data
1002 $updated += doNetworkUpdateDataByArray($networkId, $networkData);
1006 // Do we have updates?
1009 displayMessage('{%message,ADMIN_NETWORK_UPDATED=' . $updated . '%}');
1012 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_CHANGED--}');
1017 // Removes given networks
1018 function doAdminNetworkProcessRemoveNetwork () {
1019 // Do we have selections?
1020 if (ifPostContainsSelections()) {
1021 // By default nothing is removed
1024 // Something has been selected, so start updating them
1025 foreach (postRequestElement('sel') as $networkId => $sel) {
1026 // Update this entry?
1028 // Remove this entry
1029 $removed += doAdminRemoveNetworkEntry('data', 'network_id', $networkId);
1033 // Do we have removes?
1036 displayMessage('{%message,ADMIN_NETWORK_REMOVED=' . $removed . '%}');
1039 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_REMOVED--}');
1044 // Add a network type handler if not yet found
1045 function doAdminNetworkProcessAddNetworkType () {
1046 // Is the network type handle already used with given network?
1047 if (isNetworkTypeHandleValid(postRequestElement('network_type_handle'), getRequestElement('network'))) {
1049 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_TYPES_HANDLE_ALREADY_ADDED=' . postRequestElement('network_type_handle') . '%}');
1051 // ... so abort here
1055 // Remove the 'ok' part
1056 unsetPostRequestElement('ok');
1059 setPostRequestElement('network_id', bigintval(getRequestElement('network')));
1061 // Is network_type_banner_url set?
1062 if (postRequestElement('network_type_banner_url') == '') {
1063 // Remove empty value to get a NULL for an optional entry
1064 unsetPostRequestElement('network_type_banner_url');
1067 // Add the whole request to database
1068 SQL_QUERY('INSERT INTO
1069 `{?_MYSQL_PREFIX?}_network_types`
1071 `' . implode('`,`', array_keys(postRequestArray())) . "`
1073 '" . implode("','", array_values(postRequestArray())) . "'
1074 )", __FUNCTION__, __LINE__);
1077 if (!SQL_HASZEROAFFECTED()) {
1078 // Successfully added
1079 loadTemplate('admin_network_type_added', false, postRequestArray());
1082 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_TYPES_NOT_ADDED=' . postRequestElement('network_type_handle') . '%}');
1086 // Changes given network type handlers
1087 function doAdminNetworkProcessChangeNetworkType () {
1088 // Do we have selections?
1089 if (ifPostContainsSelections()) {
1090 // By default nothing is updated
1093 // Something has been selected, so start updating them
1094 foreach (postRequestElement('sel') as $networkId => $sel) {
1095 // Update this entry?
1098 $networkTypeData = array();
1100 // Transfer whole array, except 'sel'
1101 foreach (postRequestArray() as $key => $entry) {
1102 // Skip 'sel' and submit button
1103 if (in_array($key, array('sel', 'do_edit'))) {
1107 // Do we have this enty?
1108 if (!isset($entry[$networkId])) {
1109 // Not found, needs fixing
1110 debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1113 // Fix empty network_type_banner_url to NULL
1114 if (($key == 'network_type_banner_url') && (trim($entry[$networkId]) == '')) {
1116 $entry[$networkId] = NULL;
1120 $networkTypeData[$key] = $entry[$networkId];
1123 // Update the network data
1124 $updated += doNetworkUpdateTypeByArray($networkId, $networkTypeData);
1128 // Do we have updates?
1131 displayMessage('{%message,ADMIN_NETWORK_TYPES_UPDATED=' . $updated . '%}');
1134 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPES_NOTHING_CHANGED--}');
1139 // Changes given network request parameters
1140 function doAdminNetworkProcessChangeNetworkParam () {
1141 // Do we have selections?
1142 if (ifPostContainsSelections()) {
1143 // By default nothing is updated
1146 // Something has been selected, so start updating them
1147 foreach (postRequestElement('sel') as $networkId => $sel) {
1148 // Update this entry?
1151 $networkParamsData = array();
1153 // Transfer whole array, except 'sel'
1154 foreach (postRequestArray() as $key => $entry) {
1155 // Skip 'sel' and submit button
1156 if (in_array($key, array('sel', 'do_edit'))) {
1160 // Do we have this enty?
1161 if (!isset($entry[$networkId])) {
1162 // Not found, needs fixing
1163 debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1166 // Fix empty request_param_default to NULL
1167 if (($key == 'request_param_default') && (trim($entry[$networkId]) == '')) {
1169 $entry[$networkId] = NULL;
1173 $networkParamsData[$key] = $entry[$networkId];
1176 // Update the network data
1177 $updated += doNetworkUpdateParamsByArray($networkId, $networkParamsData);
1181 // Do we have updates?
1184 displayMessage('{%message,ADMIN_NETWORK_REQUEST_PARAMETER_UPDATED=' . $updated . '%}');
1187 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_CHANGED--}');
1192 // Removes given network type handlers
1193 function doAdminNetworkProcessRemoveNetworkType () {
1194 // Do we have selections?
1195 if (ifPostContainsSelections()) {
1196 // By default nothing is removed
1199 // Something has been selected, so start updating them
1200 foreach (postRequestElement('sel') as $networkId => $sel) {
1201 // Update this entry?
1203 // Remove this entry
1204 $removed += doAdminRemoveNetworkEntry('types', 'network_type_id', $networkId);
1208 // Do we have removes?
1211 displayMessage('{%message,ADMIN_NETWORK_TYPES_REMOVED=' . $removed . '%}');
1214 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPES_NOTHING_REMOVED--}');
1219 // Removes given network request parameters
1220 function doAdminNetworkProcessRemoveNetworkParam () {
1221 // Do we have selections?
1222 if (ifPostContainsSelections()) {
1223 // By default nothing is removed
1226 // Something has been selected, so start updating them
1227 foreach (postRequestElement('sel') as $networkId => $sel) {
1228 // Update this entry?
1230 // Remove this entry
1231 $removed += doAdminRemoveNetworkEntry('request_params', 'network_param_id', $networkId);
1235 // Do we have removes?
1238 displayMessage('{%message,ADMIN_NETWORK_REQUEST_PARAMETER_REMOVED=' . $removed . '%}');
1241 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_REMOVED--}');
1246 // Adds a request parameter to given network and type
1247 function doAdminNetworkProcessAddNetworkParam () {
1248 // Is the request parameter already used with given network?
1249 if (isNetworkRequestElementValid(postRequestElement('request_param_key'), postRequestElement('network_type_id'), getRequestElement('network'))) {
1251 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_REQUEST_PARAMETER_ALREADY_ADDED=' . postRequestElement('request_param_key') . '%}');
1253 // ... so abort here
1257 // Remove the 'ok' part
1258 unsetPostRequestElement('ok');
1261 setPostRequestElement('network_id', bigintval(getRequestElement('network')));
1263 // Is request_param_default set?
1264 if (postRequestElement('request_param_default') == '') {
1265 // Remove empty value to get a NULL for an optional entry
1266 unsetPostRequestElement('request_param_default');
1269 // Add the whole request to database
1270 SQL_QUERY('INSERT INTO
1271 `{?_MYSQL_PREFIX?}_network_request_params`
1273 `' . implode('`,`', array_keys(postRequestArray())) . "`
1275 '" . implode("','", array_values(postRequestArray())) . "'
1276 )", __FUNCTION__, __LINE__);
1279 if (!SQL_HASZEROAFFECTED()) {
1280 // Successfully added
1281 loadTemplate('admin_network_request_param_added', false, postRequestArray());
1284 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_REQUEST_PARAMETER_NOT_ADDED=' . postRequestElement('request_param_key') . '%}');
1288 // Adds a API response array entry
1289 function doAdminNetworkProcessAddNetworkApiTranslation () {
1290 // Is the request parameter already used with given network?
1291 if (isNetworkApiTranslationValid(postRequestElement('network_api_index'), postRequestElement('network_type_id'), getRequestElement('network'))) {
1293 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_API_TRANSLATION_ALREADY_ADDED=' . postRequestElement('network_api_index') . '%}');
1295 // ... so abort here
1299 // Remove the 'ok' part
1300 unsetPostRequestElement('ok');
1303 setPostRequestElement('network_id', bigintval(getRequestElement('network')));
1306 setPostRequestElement('sort', (countSumTotalData(
1307 bigintval(postRequestElement('network_id')),
1308 'network_api_translation',
1312 sprintf(" AND `network_type_id`=%s", bigintval(postRequestElement('network_type_id')))
1315 // Add the whole request to database
1316 SQL_QUERY('INSERT INTO
1317 `{?_MYSQL_PREFIX?}_network_api_translation`
1319 `' . implode('`,`', array_keys(postRequestArray())) . "`
1321 '" . implode("','", array_values(postRequestArray())) . "'
1322 )", __FUNCTION__, __LINE__);
1325 if (!SQL_HASZEROAFFECTED()) {
1326 // Successfully added
1327 loadTemplate('admin_network_api_translation_added', false, postRequestArray());
1330 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_API_TRANSLATION_NOT_ADDED=' . postRequestElement('network_api_index') . '%}');
1334 // Adds/update network API configuration
1335 function doAdminNetworkProcessNetworkApiConfig () {
1336 // Remove the 'ok' part
1337 unsetPostRequestElement('ok');
1340 setPostRequestElement('network_id', bigintval(getRequestElement('network')));
1342 // Is there already an entry?
1343 if (isNetworkApiConfigured(getRequestElement('network'))) {
1344 // Generate SQL query
1345 $SQL = getUpdateSqlFromArray(postRequestArray(), 'network_api_config', 'network_id', postRequestElement('network_id'), array('network_id'));
1349 `{?_MYSQL_PREFIX?}_network_api_config`
1351 `' . implode('`,`', array_keys(postRequestArray())) . "`
1353 '" . implode("','", array_values(postRequestArray())) . "'
1358 SQL_QUERY($SQL, __FUNCTION__, __LINE__);
1361 if (!SQL_HASZEROAFFECTED()) {
1362 // Successfully added
1363 displayMessage('{--ADMIN_CONFIG_NETWORK_API_SAVED--}');
1366 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_API_NOT_SAVED--}');
1370 // Do expression code for this extension
1371 function doExpressionNetwork ($data) {
1372 // Construct replacer
1373 $replacer = sprintf(
1374 "{DQUOTE} . %s(%s, '%s') . {DQUOTE}",
1376 $data['matches'][4][$data['key']],
1380 // Replace %network% with the current network id
1381 $replacer = str_replace('%network%', getCurrentNetworkId(), $replacer);
1384 $code = replaceExpressionCode($data, $replacer);