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 `network_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
177 `network_short_name`,
180 `network_data_separator`,
181 `network_row_separator`,
182 `network_request_type`,
184 `network_require_id_card`,
185 `network_query_amount`
187 `{?_MYSQL_PREFIX?}_network_data`
191 array(bigintval($networkId)), __FUNCTION__, __LINE__);
193 // Do we have an entry?
194 if (SQL_NUMROWS($result) == 1) {
196 $GLOBALS['network_data'][$networkId] = SQL_FETCHARRAY($result);
200 SQL_FREERESULT($result);
204 if (empty($column)) {
206 return $GLOBALS['network_data'][$networkId];
209 return $GLOBALS['network_data'][$networkId][$column];
213 // "Getter" for a network's data by provided type id number
214 function getNetworkDataByTypeId ($networkId, $column = '') {
215 // Ids lower one are not accepted
216 if ($networkId < 1) {
217 // Not good, should be fixed
218 debug_report_bug(__FUNCTION__, __LINE__, 'Network type id ' . $networkId . ' is smaller than 1.');
221 // Set current network id
222 setCurrentNetworkId($networkId);
225 if (!isset($GLOBALS['network_data'][$networkId])) {
226 // By default we have no data
227 $GLOBALS['network_data'][$networkId] = array();
229 // Query for the network data
230 $result = SQL_QUERY_ESC("SELECT
232 d.`network_short_name`,
235 d.`network_data_separator`,
236 d.`network_row_separator`,
237 d.`network_request_type`,
239 d.`network_require_id_card`,
240 d.`network_query_amount`,
241 t.`network_type_handle`,
242 t.`network_type_api_url`,
243 t.`network_type_click_url`,
244 t.`network_type_banner_url`
246 `{?_MYSQL_PREFIX?}_network_data` AS d
248 `{?_MYSQL_PREFIX?}_network_types` AS t
250 d.`network_id`=t.`network_id`
252 t.`network_type_id`=%s
254 array(bigintval($networkId)), __FUNCTION__, __LINE__);
256 // Do we have an entry?
257 if (SQL_NUMROWS($result) == 1) {
259 $GLOBALS['network_data'][$networkId] = SQL_FETCHARRAY($result);
263 SQL_FREERESULT($result);
267 if (empty($column)) {
269 return $GLOBALS['network_data'][$networkId];
272 return $GLOBALS['network_data'][$networkId][$column];
276 // "Getter" for a network type data by provided id number
277 function getNetworkTypeDataById ($networkId) {
278 // Ids lower one are not accepted
279 if ($networkId < 1) {
280 // Not good, should be fixed
281 debug_report_bug(__FUNCTION__, __LINE__, 'Network type id ' . $networkId . ' is smaller than 1.');
284 // By default we have no data
285 $GLOBALS['network_type_data'][$networkId] = array();
287 // Query for the network data
288 $result = SQL_QUERY_ESC("SELECT
291 `network_type_handle`,
292 `network_type_api_url`,
293 `network_type_click_url`,
294 `network_type_banner_url`
296 `{?_MYSQL_PREFIX?}_network_types`
300 array(bigintval($networkId)), __FUNCTION__, __LINE__);
302 // Do we have an entry?
303 if (SQL_NUMROWS($result) == 1) {
305 $GLOBALS['network_type_data'][$networkId] = SQL_FETCHARRAY($result);
309 SQL_FREERESULT($result);
312 return $GLOBALS['network_type_data'][$networkId];
315 // "Getter" for a network request parameter data by provided id number
316 function getNetworkRequestParamsDataById ($networkId) {
317 // Ids lower one are not accepted
318 if ($networkId < 1) {
319 // Not good, should be fixed
320 debug_report_bug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $networkId . ' is smaller than 1.');
323 // By default we have no data
324 $networkRequestData = array();
326 // Query for the network data
327 $result = SQL_QUERY_ESC("SELECT
331 `network_request_param_key`,
332 `network_request_param_value`,
333 `network_request_param_default`
335 `{?_MYSQL_PREFIX?}_network_request_params`
337 `network_param_id`=%s
339 array(bigintval($networkId)), __FUNCTION__, __LINE__);
341 // Do we have an entry?
342 if (SQL_NUMROWS($result) == 1) {
344 $networkRequestData = SQL_FETCHARRAY($result);
348 SQL_FREERESULT($result);
351 return $networkRequestData;
354 // Updates given network (id) with data from array
355 function doNetworkUpdateDataByArray ($networkId, $networkData) {
356 // Ids lower one are not accepted
357 if ($networkId < 1) {
358 // Not good, should be fixed
359 debug_report_bug(__FUNCTION__, __LINE__, 'Network id ' . $networkId . ' is smaller than 1.');
362 // Just call our inner method
363 return adminSaveSettings($networkData, '_network_data', sprintf("`network_id`=%s", bigintval($networkId)), array(), false, false);
366 // Updates given network type handler (id) with data from array
367 function doNetworkUpdateTypeByArray ($networkId, $networkTypeData) {
368 // Ids lower one are not accepted
369 if ($networkId < 1) {
370 // Not good, should be fixed
371 debug_report_bug(__FUNCTION__, __LINE__, 'Network type handler id ' . $networkId . ' is smaller than 1.');
374 // Just call our inner method
375 return adminSaveSettings($networkTypeData, '_network_types', sprintf("`network_type_id`=%s", bigintval($networkId)), array(), false, false);
378 // Updates given network request parameters (id) with data from array
379 function doNetworkUpdateParamsByArray ($networkId, $networkParamData) {
380 // Ids lower one are not accepted
381 if ($networkId < 1) {
382 // Not good, should be fixed
383 debug_report_bug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $networkId . ' is smaller than 1.');
386 // Just call our inner method
387 return adminSaveSettings($networkParamData, '_network_request_params', sprintf("`network_param_id`=%s", bigintval($networkId)), array(), false, false);
390 // Removes given network entry
391 function doAdminRemoveNetworkEntry ($table, $column, $networkId, $limit = 1) {
393 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_network_%s` WHERE `%s`=%s LIMIT %s",
394 array($table, $column, $networkId, $limit), __FUNCTION__, __LINE__);
396 // Return affected rows
397 return SQL_AFFECTEDROWS();
400 // Generates a list of networks for given script and returns it
401 function generateAdminNetworkList () {
405 // Query for all networks
406 $result = SQL_QUERY('SELECT
408 `network_short_name`,
411 `{?_MYSQL_PREFIX?}_network_data`
413 `network_short_name` ASC', __FUNCTION__, __LINE__);
415 // Do we have entries?
416 if (!SQL_HASZERONUMS($result)) {
419 while ($row = SQL_FETCHARRAY($result)) {
420 // Is this valid, then add it
421 if ((is_array($row)) && (isset($row['network_id']))) {
423 $rows[$row['network_id']] = $row;
427 // Generate the selection box
428 $content = generateSelectionBoxFromArray($rows, 'network_id', 'network_id', '', '', 'network');
431 $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}');
435 SQL_FREERESULT($result);
441 // Generator (somewhat getter) for a list of network types for given network id
442 function generateAdminNetworkTypeList ($networkId) {
446 // Query all types of this network
447 $result = SQL_QUERY_ESC("SELECT
448 `network_type_id`,`network_type_handle`
450 `{?_MYSQL_PREFIX?}_network_types`
454 `network_type_handle` ASC",
456 bigintval($networkId)
457 ), __FUNCTION__, __LINE__);
459 // Do we have entries?
460 if (!SQL_HASZERONUMS($result)) {
463 while ($row = SQL_FETCHARRAY($result)) {
464 // Is this valid, then add it
465 if ((is_array($row)) && (isset($row['network_type_id']))) {
467 $rows[$row['network_type_id']] = $row;
471 // Generate the selection box
472 $content = generateSelectionBoxFromArray($rows, 'network_type', 'network_type_id');
475 $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}');
479 SQL_FREERESULT($result);
485 // Generator (somewhat getter) for a list of network types for all types
486 function generateAdminDistinctNetworkTypeList () {
490 // Query all types of this network
491 $result = SQL_QUERY('SELECT
492 t.`network_type_id`, t.`network_type_handle`, d.`network_title`
494 `{?_MYSQL_PREFIX?}_network_types` AS t
496 `{?_MYSQL_PREFIX?}_network_data` AS d
498 t.`network_id`=d.`network_id`
500 d.`network_short_name` ASC,
501 t.`network_type_handle` ASC', __FUNCTION__, __LINE__);
503 // Do we have entries?
504 if (!SQL_HASZERONUMS($result)) {
507 while ($row = SQL_FETCHARRAY($result)) {
508 // Is this valid, then add it
509 if ((is_array($row)) && (isset($row['network_type_id']))) {
511 $rows[$row['network_type_id']] = $row;
515 // Generate the selection box
516 $content = generateSelectionBoxFromArray($rows, 'network_type', 'network_type_id', '', '_title');
519 $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}');
523 SQL_FREERESULT($result);
524 //* DEBUG: */ die('<pre>'.encodeEntities($content).'</pre>');
530 // Generator (somewhat getter) for network type options
531 function generateNetworkTypeOptions ($networkId) {
532 // Is this an array, then we just came back from edit/delete actions
533 if (is_array($networkId)) {
538 if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
539 // Generate output and cache it
540 $GLOBALS[__FUNCTION__][$networkId] = generateOptionList(
543 'network_type_handle',
547 "WHERE `network_id`=%s",
548 bigintval(getRequestElement('network_id'))
551 'translateNetworkTypeHandler'
556 return $GLOBALS[__FUNCTION__][$networkId];
559 // Generates an options list of all available (hard-coded) handlers
560 function generateNetworkTypesAvailableOptions () {
562 if (!isset($GLOBALS[__FUNCTION__])) {
564 $GLOBALS[__FUNCTION__] = generateOptionList(
600 $GLOBALS['network_types_disabled'],
601 'translateNetworkTypeHandler'
606 return $GLOBALS[__FUNCTION__];
609 // Generates an options list (somewhat getter) ofr request keys
610 function generateNetworkRequestKeyOptions () {
612 if (!isset($GLOBALS[__FUNCTION__])) {
613 // Generate and cache it
614 $GLOBALS[__FUNCTION__] = generateOptionList(
636 $GLOBALS['network_params_disabled'],
637 'translateNetworkRequestElement'
642 return $GLOBALS[__FUNCTION__];
645 // Generator (somewhat getter) for (return) array translation
646 function generateNetworkTranslationOptions ($default = '') {
648 if (!isset($GLOBALS[__FUNCTION__][$default])) {
649 // Generate and cache it
650 $GLOBALS[__FUNCTION__][$default] = generateOptionList(
651 'network_translations',
652 'network_translation_id',
653 'network_translation_name',
657 $GLOBALS['network_translation_disabled'],
658 'translateNetworkTranslationName'
663 return $GLOBALS[__FUNCTION__][$default];
666 // Generates an option list of request types
667 function generateNetworkRequestTypeOptions ($default = '') {
669 if (!isset($GLOBALS[__FUNCTION__][$default])) {
671 $GLOBALS[__FUNCTION__][$default] = generateOptionList(
678 '{--ADMIN_NETWORK_REQUEST_TYPE_GET--}',
679 '{--ADMIN_NETWORK_REQUEST_TYPE_POST--}'
686 return $GLOBALS[__FUNCTION__][$default];
689 // Generates an option list of network_api_active
690 function generateNetworkApiActiveOptions ($default = '') {
692 if (!isset($GLOBALS[__FUNCTION__][$default])) {
694 $GLOBALS[__FUNCTION__][$default] = generateYesNoOptionList($default);
698 return $GLOBALS[__FUNCTION__][$default];
701 // Translates 'translate_name' for e.g. templates
702 function translateNetworkTranslationName ($name) {
703 // Get the message id
704 return '{--ADMIN_NETWORK_TRANSLATE_' . strtoupper($name) . '_NAME--}';
707 // Translates the network type handler (e.g. banner, paidmail) for templates
708 function translateNetworkTypeHandler ($type) {
709 // Get the message id
710 return '{--ADMIN_NETWORK_TYPES_' . strtoupper($type) . '--}';
713 // Translates request type
714 function translateNetworkRequestType ($type) {
715 // Get the message id
716 return '{--ADMIN_NETWORK_REQUEST_TYPE_' . strtoupper($type) . '--}';
719 // Translates request parameter
720 function translateNetworkRequestElement ($param) {
721 // Get the message id
722 return '{--ADMIN_NETWORK_REQUEST_PARAMETER_' . strtoupper($param) . '--}';
725 // Translates API index
726 function translateNetworkApiIndex ($index) {
728 if (!isset($GLOBALS['network_api_index'])) {
729 // Get an array of all API array indexes
730 $GLOBALS['network_api_index'] = array();
733 $result = SQL_QUERY('SELECT
734 `network_api_id`,`network_api_index`,`network_translation_name`
736 `{?_MYSQL_PREFIX?}_network_api_translation`
738 `{?_MYSQL_PREFIX?}_network_translations`
740 `network_api_index`=`network_translation_id`
742 `sort` ASC', __FUNCTION__, __LINE__);
744 // Do we have entries?
745 if (!SQL_HASZERONUMS($result)) {
747 while ($row = SQL_FETCHARRAY($result)) {
748 // Add it to our global array
749 $GLOBALS['network_api_index'][$row['network_api_index']] = $row;
754 SQL_FREERESULT($result);
757 // Default name is unknown
760 // Is the entry there?
761 if (isset($GLOBALS['network_api_index'][$index])) {
763 $name = $GLOBALS['network_api_index'][$index]['network_translation_name'];
766 // Return translation
767 return translateNetworkTranslationName($name);
770 // Translates network API configuration status (see function isNetworkApiConfigured()) by given id
771 function translateNetworkApiConfiguredStatusById ($networkId) {
773 if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
774 // By default it is not configured
775 $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_NOT_CONFIGURED--}';
777 // So is it configured?
778 if (isNetworkApiConfigured($networkId)) {
780 $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_CONFIGURED--}';
785 return $GLOBALS[__FUNCTION__][$networkId];
788 // Checks if the given network is configured by looking its API configuration entry up
789 function isNetworkApiConfigured ($networkId) {
791 if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
792 // Check for an entry in network_api_config
793 $GLOBALS[__FUNCTION__][$networkId] = (countSumTotalData(
794 bigintval($networkId),
795 'network_api_config',
803 return $GLOBALS[__FUNCTION__][$networkId];
806 //------------------------------------------------------------------------------
807 // Call-back functions
808 //------------------------------------------------------------------------------
810 // Callback function to add new network
811 function doAdminNetworkProcessAddNetwork () {
812 // We can say here, the form is sent, so check if the network is already added
813 if (isNetworkNameValid(postRequestElement('network_short_name'))) {
815 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_ALREADY_ADDED=' . postRequestElement('network_short_name') . '%}');
819 // Remove the 'ok' part
820 unsetPostRequestElement('ok');
822 // Add the whole request to database
823 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_data'), __FUNCTION__, __LINE__);
825 // Add the id for output only
826 setPostRequestElement('network_id', SQL_INSERTID());
829 if (!SQL_HASZEROAFFECTED()) {
830 // Successfully added
831 loadTemplate('admin_network_added', false, postRequestArray());
834 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_DATA_NOT_ADDED=' . postRequestElement('network_short_name') . '%}');
838 // Displays selected networks for editing
839 function doAdminNetworkProcessHandleNetwork () {
840 // Do we have selections?
841 if (ifPostContainsSelections()) {
842 // Something has been selected, so start displaying one by one
844 foreach (postRequestElement('sel') as $networkId => $sel) {
847 // Load this network's data
848 $networkData = getNetworkDataById($networkId);
850 // Do we have found the network?
851 if (count($networkData) > 0) {
852 if (isFormSent('edit')) {
853 // Add row template for editing
854 $OUT .= loadTemplate('admin_edit_networks_row', true, $networkData);
855 } elseif (isFormSent('delete')) {
856 // Add row template for deleting
857 $OUT .= loadTemplate('admin_delete_networks_row', true, $networkData);
860 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
866 // If we have no rows, we don't need to display the edit form
868 // Output main template
869 if (isFormSent('edit')) {
870 loadTemplate('admin_edit_networks', false, $OUT);
871 } elseif (isFormSent('delete')) {
872 loadTemplate('admin_delete_networks', false, $OUT);
875 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
878 // Don't display the list/add new form
879 $GLOBALS['network_display'] = false;
881 // Nothing selected/found
882 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_FOUND--}');
887 // Handle network type form
888 function doAdminNetworkProcessHandleNetworkType () {
889 // Do we have selections?
890 if (ifPostContainsSelections()) {
892 $networkData = getNetworkDataById(getRequestElement('network_id'));
894 // Something has been selected, so start displaying one by one
896 foreach (postRequestElement('sel') as $networkId => $sel) {
899 // Load this network's data
900 $networkTypeData = getNetworkTypeDataById($networkId);
902 // Do we have found the network?
903 if (count($networkTypeData) > 0) {
904 if (isFormSent('edit')) {
905 // Add row template for deleting
906 $OUT .= loadTemplate('admin_edit_network_types_row', true, $networkTypeData);
907 } elseif (isFormSent('delete')) {
908 // Add row template for deleting
909 $OUT .= loadTemplate('admin_delete_network_types_row', true, $networkTypeData);
912 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
918 // If we have no rows, we don't need to display the edit form
920 // Output main template
921 if (isFormSent('edit')) {
922 loadTemplate('admin_edit_network_types', false, $OUT);
923 } elseif (isFormSent('delete')) {
924 loadTemplate('admin_delete_network_types', false, $OUT);
927 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
930 // Don't display the list/add new form
931 $GLOBALS['network_display'] = false;
933 // Nothing selected/found
934 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPES_NOTHING_FOUND--}');
939 // Handle network request parameter form
940 function doAdminNetworkProcessHandleRequestParams () {
941 // Do we have selections?
942 if (ifPostContainsSelections()) {
944 $GLOBALS['network_params_disabled'] = array();
947 $networkData = getNetworkDataById(getRequestElement('network_id'));
949 // Something has been selected, so start displaying one by one
951 foreach (postRequestElement('sel') as $networkId => $sel) {
954 // Load this network's data
955 $networkRequestData = getNetworkRequestParamsDataById($networkId);
957 // Do we have found the network?
958 if (count($networkRequestData) > 0) {
959 if (isFormSent('edit')) {
960 // Add row template for deleting
961 $OUT .= loadTemplate('admin_edit_network_params_row', true, $networkRequestData);
962 } elseif (isFormSent('delete')) {
964 $networkRequestData['network_type_data'] = getNetworkTypeDataById($networkRequestData['network_type_id']);
966 // Add row template for deleting
967 $OUT .= loadTemplate('admin_delete_network_params_row', true, $networkRequestData);
970 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
976 // If we have no rows, we don't need to display the edit form
978 // Output main template
979 if (isFormSent('edit')) {
980 loadTemplate('admin_edit_network_params', false, $OUT);
981 } elseif (isFormSent('delete')) {
982 loadTemplate('admin_delete_network_params', false, $OUT);
985 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
988 // Don't display the list/add new form
989 $GLOBALS['network_display'] = false;
991 // Nothing selected/found
992 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_FOUND--}');
997 // Changes given networks
998 function doAdminNetworkProcessChangeNetwork () {
999 // Do we have selections?
1000 if (ifPostContainsSelections()) {
1001 // By default nothing is updated
1004 // Something has been selected, so start updating them
1005 foreach (postRequestElement('sel') as $networkId => $sel) {
1006 // Update this entry?
1009 $networkData = array();
1011 // Transfer whole array, except 'sel'
1012 foreach (postRequestArray() as $key => $entry) {
1013 // Skip 'sel' and submit button
1014 if (in_array($key, array('sel', 'do_edit'))) {
1018 // Do we have this enty?
1019 if (!isset($entry[$networkId])) {
1020 // Not found, needs fixing
1021 debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1025 $networkData[$key] = $entry[$networkId];
1028 // Update the network data
1029 $updated += doNetworkUpdateDataByArray($networkId, $networkData);
1033 // Do we have updates?
1036 displayMessage('{%message,ADMIN_NETWORK_UPDATED=' . $updated . '%}');
1039 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_CHANGED--}');
1044 // Removes given networks
1045 function doAdminNetworkProcessRemoveNetwork () {
1046 // Do we have selections?
1047 if (ifPostContainsSelections()) {
1048 // By default nothing is removed
1051 // Something has been selected, so start updating them
1052 foreach (postRequestElement('sel') as $networkId => $sel) {
1053 // Update this entry?
1055 // Remove this entry
1056 $removed += doAdminRemoveNetworkEntry('data', 'network_id', $networkId);
1060 // Do we have removes?
1063 displayMessage('{%message,ADMIN_NETWORK_REMOVED=' . $removed . '%}');
1066 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_REMOVED--}');
1071 // Add a network type handler if not yet found
1072 function doAdminNetworkProcessAddNetworkType () {
1073 // Is the network type handle already used with given network?
1074 if (isNetworkTypeHandleValid(postRequestElement('network_type_handle'), getRequestElement('network_id'))) {
1076 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_TYPES_HANDLE_ALREADY_ADDED=' . postRequestElement('network_type_handle') . '%}');
1078 // ... so abort here
1082 // Remove the 'ok' part
1083 unsetPostRequestElement('ok');
1086 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1088 // Is network_type_banner_url set?
1089 if (postRequestElement('network_type_banner_url') == '') {
1090 // Remove empty value to get a NULL for an optional entry
1091 unsetPostRequestElement('network_type_banner_url');
1094 // Add the whole request to database
1095 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_types'), __FUNCTION__, __LINE__);
1098 if (!SQL_HASZEROAFFECTED()) {
1099 // Successfully added
1100 loadTemplate('admin_network_type_added', false, postRequestArray());
1103 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_TYPES_NOT_ADDED=' . postRequestElement('network_type_handle') . '%}');
1107 // Changes given network type handlers
1108 function doAdminNetworkProcessChangeNetworkType () {
1109 // Do we have selections?
1110 if (ifPostContainsSelections()) {
1111 // By default nothing is updated
1114 // Something has been selected, so start updating them
1115 foreach (postRequestElement('sel') as $networkId => $sel) {
1116 // Update this entry?
1119 $networkTypeData = array();
1121 // Transfer whole array, except 'sel'
1122 foreach (postRequestArray() as $key => $entry) {
1123 // Skip 'sel' and submit button
1124 if (in_array($key, array('sel', 'do_edit'))) {
1128 // Do we have this enty?
1129 if (!isset($entry[$networkId])) {
1130 // Not found, needs fixing
1131 debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1134 // Fix empty network_type_banner_url to NULL
1135 if (($key == 'network_type_banner_url') && (trim($entry[$networkId]) == '')) {
1137 $entry[$networkId] = NULL;
1141 $networkTypeData[$key] = $entry[$networkId];
1144 // Update the network data
1145 $updated += doNetworkUpdateTypeByArray($networkId, $networkTypeData);
1149 // Do we have updates?
1152 displayMessage('{%message,ADMIN_NETWORK_TYPES_UPDATED=' . $updated . '%}');
1155 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPES_NOTHING_CHANGED--}');
1160 // Changes given network request parameters
1161 function doAdminNetworkProcessChangeNetworkParam () {
1162 // Do we have selections?
1163 if (ifPostContainsSelections()) {
1164 // By default nothing is updated
1167 // Something has been selected, so start updating them
1168 foreach (postRequestElement('sel') as $networkId => $sel) {
1169 // Update this entry?
1172 $networkParamsData = array();
1174 // Transfer whole array, except 'sel'
1175 foreach (postRequestArray() as $key => $entry) {
1176 // Skip 'sel' and submit button
1177 if (in_array($key, array('sel', 'do_edit'))) {
1181 // Do we have this enty?
1182 if (!isset($entry[$networkId])) {
1183 // Not found, needs fixing
1184 debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1187 // Fix empty network_request_param_default to NULL
1188 if (($key == 'network_request_param_default') && (trim($entry[$networkId]) == '')) {
1190 $entry[$networkId] = NULL;
1194 $networkParamsData[$key] = $entry[$networkId];
1197 // Update the network data
1198 $updated += doNetworkUpdateParamsByArray($networkId, $networkParamsData);
1202 // Do we have updates?
1205 displayMessage('{%message,ADMIN_NETWORK_REQUEST_PARAMETER_UPDATED=' . $updated . '%}');
1208 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_CHANGED--}');
1213 // Removes given network type handlers
1214 function doAdminNetworkProcessRemoveNetworkType () {
1215 // Do we have selections?
1216 if (ifPostContainsSelections()) {
1217 // By default nothing is removed
1220 // Something has been selected, so start updating them
1221 foreach (postRequestElement('sel') as $networkId => $sel) {
1222 // Update this entry?
1224 // Remove this entry
1225 $removed += doAdminRemoveNetworkEntry('types', 'network_type_id', $networkId);
1229 // Do we have removes?
1232 displayMessage('{%message,ADMIN_NETWORK_TYPES_REMOVED=' . $removed . '%}');
1235 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPES_NOTHING_REMOVED--}');
1240 // Removes given network request parameters
1241 function doAdminNetworkProcessRemoveNetworkParam () {
1242 // Do we have selections?
1243 if (ifPostContainsSelections()) {
1244 // By default nothing is removed
1247 // Something has been selected, so start updating them
1248 foreach (postRequestElement('sel') as $networkId => $sel) {
1249 // Update this entry?
1251 // Remove this entry
1252 $removed += doAdminRemoveNetworkEntry('request_params', 'network_param_id', $networkId);
1256 // Do we have removes?
1259 displayMessage('{%message,ADMIN_NETWORK_REQUEST_PARAMETER_REMOVED=' . $removed . '%}');
1262 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_REMOVED--}');
1267 // Adds a request parameter to given network and type
1268 function doAdminNetworkProcessAddNetworkParam () {
1269 // Is the request parameter already used with given network?
1270 if (isNetworkRequestElementValid(postRequestElement('network_request_param_key'), postRequestElement('network_type_id'), getRequestElement('network_id'))) {
1272 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_REQUEST_PARAMETER_ALREADY_ADDED=' . postRequestElement('network_request_param_key') . '%}');
1274 // ... so abort here
1278 // Remove the 'ok' part
1279 unsetPostRequestElement('ok');
1282 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1284 // Is network_request_param_default set?
1285 if (postRequestElement('network_request_param_default') == '') {
1286 // Remove empty value to get a NULL for an optional entry
1287 unsetPostRequestElement('network_request_param_default');
1290 // Add the whole request to database
1291 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_request_params'), __FUNCTION__, __LINE__);
1294 if (!SQL_HASZEROAFFECTED()) {
1295 // Successfully added
1296 loadTemplate('admin_network_network_request_param_added', false, postRequestArray());
1299 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_REQUEST_PARAMETER_NOT_ADDED=' . postRequestElement('network_request_param_key') . '%}');
1303 // Adds a API response array entry
1304 function doAdminNetworkProcessAddNetworkApiTranslation () {
1305 // Is the request parameter already used with given network?
1306 if (isNetworkApiTranslationValid(postRequestElement('network_api_index'), postRequestElement('network_type_id'), getRequestElement('network_id'))) {
1308 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_API_TRANSLATION_ALREADY_ADDED=' . postRequestElement('network_api_index') . '%}');
1310 // ... so abort here
1314 // Remove the 'ok' part
1315 unsetPostRequestElement('ok');
1318 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1321 setPostRequestElement('sort', (countSumTotalData(
1322 bigintval(postRequestElement('network_id')),
1323 'network_api_translation',
1327 sprintf(" AND `network_type_id`=%s", bigintval(postRequestElement('network_type_id')))
1330 // Add the whole request to database
1331 SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_api_translation'), __FUNCTION__, __LINE__);
1334 if (!SQL_HASZEROAFFECTED()) {
1335 // Successfully added
1336 loadTemplate('admin_network_api_translation_added', false, postRequestArray());
1339 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_API_TRANSLATION_NOT_ADDED=' . postRequestElement('network_api_index') . '%}');
1343 // Adds/update network API configuration
1344 function doAdminNetworkProcessNetworkApiConfig () {
1345 // Remove the 'ok' part
1346 unsetPostRequestElement('ok');
1349 setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1351 // Is network_api_referral_button set?
1352 if (postRequestElement('network_api_referral_button') == '') {
1353 // Remove empty value to get a NULL for an optional entry
1354 unsetPostRequestElement('network_api_referral_button');
1357 // Is there already an entry?
1358 if (isNetworkApiConfigured(getRequestElement('network_id'))) {
1359 // Generate SQL query
1360 $SQL = getUpdateSqlFromArray(postRequestArray(), 'network_api_config', 'network_id', postRequestElement('network_id'), array('network_id'));
1363 $SQL = getInsertSqlFromArray(postRequestArray(), 'network_api_config');
1367 SQL_QUERY($SQL, __FUNCTION__, __LINE__);
1370 if (!SQL_HASZEROAFFECTED()) {
1371 // Successfully added
1372 displayMessage('{--ADMIN_CONFIG_NETWORK_API_SAVED--}');
1375 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_API_NOT_SAVED--}');
1379 // Do expression code for this extension
1380 function doExpressionNetwork ($data) {
1381 // Construct replacer
1382 $replacer = sprintf(
1383 "{DQUOTE} . %s(%s, '%s') . {DQUOTE}",
1385 $data['matches'][4][$data['key']],
1389 // Replace %network_id% with the current network id
1390 $replacer = str_replace('%network_id%', getCurrentNetworkId(), $replacer);
1393 $code = replaceExpressionCode($data, $replacer);