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 * Needs to be in all Files and every File needs "svn propset *
18 * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
19 * -------------------------------------------------------------------- *
20 * Copyright (c) 2003 - 2009 by Roland Haeder *
21 * Copyright (c) 2009, 2010 by Mailer Developer Team *
22 * For more information visit: http://www.mxchange.org *
24 * This program is free software; you can redistribute it and/or modify *
25 * it under the terms of the GNU General Public License as published by *
26 * the Free Software Foundation; either version 2 of the License, or *
27 * (at your option) any later version. *
29 * This program is distributed in the hope that it will be useful, *
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
32 * GNU General Public License for more details. *
34 * You should have received a copy of the GNU General Public License *
35 * along with this program; if not, write to the Free Software *
36 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
38 ************************************************************************/
40 // Some security stuff...
41 if (!defined('__SECURITY')) {
45 // Private setter for current network id
46 function setCurrentNetworkId ($id) {
47 $GLOBALS['current_network_id'] = bigintval($id);
50 // Private getter for current network id
51 function getCurrentNetworkId () {
52 return $GLOBALS['current_network_id'];
55 // Handle a (maybe) sent form here
56 function doNetworkHandleForm () {
58 if ((isFormSent()) || (isFormSent('edit')) || (isFormSent('del')) || (isFormSent('change')) || (isFormSent('remove'))) {
60 if (isGetRequestParameterSet('do')) {
61 // Process the request
62 doAdminNetworkProcessForm();
65 loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_NETWORK_DO_404'));
70 // Processes an admin form
71 function doAdminNetworkProcessForm () {
73 if ((!isFormSent()) && (!isFormSent('edit')) && (!isFormSent('del')) && (!isFormSent('change')) && (!isFormSent('remove'))) {
75 loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_NETWORK_FORM_NOT_SENT'));
77 } elseif (!isGetRequestParameterSet('do')) {
79 loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_NETWORK_DO_404'));
83 // Create function name
84 $functionName = sprintf("doAdminNetworkProcess%sForm", ucfirst(strtolower(getRequestParameter('do'))));
86 // Is the function valid?
87 if (!function_exists($functionName)) {
88 // Invalid function name
89 debug_report_bug(__FUNCTION__, __LINE__, 'Invalid do ' . getRequestParameter('do') . ', function ' . $functionName .' does not exist.', false);
92 // Call-back the method handling our request
93 call_user_func($functionName);
96 // Checks wether the (short) network name is already used (valid)
97 function isNetworkNameValid ($name) {
99 $result = SQL_QUERY_ESC("SELECT `network_id` FROM `{?_MYSQL_PREFIX?}_network_data` WHERE `network_short_name`='%s' LIMIT 1",
100 array($name), __FUNCTION__, __LINE__);
103 $isValid = (SQL_NUMROWS($result) == 1);
106 SQL_FREERESULT($result);
112 // Checks wether the given network type is already used (valid)
113 function isNetworkTypeHandleValid ($type, $networkId) {
115 $result = SQL_QUERY_ESC("SELECT `network_type_id` FROM `{?_MYSQL_PREFIX?}_network_types` WHERE `network_id`=%s AND `network_type_handle`='%s' LIMIT 1",
116 array($networkId, $type), __FUNCTION__, __LINE__);
119 $isValid = (SQL_NUMROWS($result) == 1);
122 SQL_FREERESULT($result);
128 // Checks wether the given network request parameter is already used (valid)
129 function isNetworkRequestParameterValid ($key, $type, $networkId) {
131 $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",
132 array($networkId, $type, $key), __FUNCTION__, __LINE__);
135 $isValid = (SQL_NUMROWS($result) == 1);
138 SQL_FREERESULT($result);
144 // "Getter" for a network's data by provided id number
145 function getNetworkDataById ($id, $column = '') {
146 // Ids lower one are not accepted
148 // Not good, should be fixed
149 debug_report_bug(__FUNCTION__, __LINE__, 'Network id ' . $id . ' is smaller than 1.');
152 // Set current network id
153 setCurrentNetworkId($id);
156 if (!isset($GLOBALS['network_data'][$id])) {
157 // By default we have no data
158 $GLOBALS['network_data'][$id] = array();
160 // Query for the network data
161 $result = SQL_QUERY_ESC("SELECT
162 `network_id`, `network_short_name`, `network_title`, `network_reflink`, `network_data_seperator`, `network_row_seperator`, `network_request_type`, `network_charset`
164 `{?_MYSQL_PREFIX?}_network_data`
168 array(bigintval($id)), __FUNCTION__, __LINE__);
170 // Do we have an entry?
171 if (SQL_NUMROWS($result) == 1) {
173 $GLOBALS['network_data'][$id] = SQL_FETCHARRAY($result);
177 SQL_FREERESULT($result);
181 if (empty($column)) {
183 return $GLOBALS['network_data'][$id];
186 return $GLOBALS['network_data'][$id][$column];
190 // "Getter" for a network's data by provided type id number
191 function getNetworkDataByTypeId ($id, $column = '') {
192 // Ids lower one are not accepted
194 // Not good, should be fixed
195 debug_report_bug(__FUNCTION__, __LINE__, 'Network type id ' . $id . ' is smaller than 1.');
198 // Set current network id
199 setCurrentNetworkId($id);
202 if (!isset($GLOBALS['network_data'][$id])) {
203 // By default we have no data
204 $GLOBALS['network_data'][$id] = array();
206 // Query for the network data
207 $result = SQL_QUERY_ESC("SELECT
208 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`,
209 t.`network_type_handle`, t.`network_type_api_url`, t.`network_type_click_url`, t.`network_type_banner_url`
211 `{?_MYSQL_PREFIX?}_network_data` AS d
213 `{?_MYSQL_PREFIX?}_network_types` AS t
215 d.`network_id`=t.`network_id`
217 t.`network_type_id`=%s
219 array(bigintval($id)), __FUNCTION__, __LINE__);
221 // Do we have an entry?
222 if (SQL_NUMROWS($result) == 1) {
224 $GLOBALS['network_data'][$id] = SQL_FETCHARRAY($result);
228 SQL_FREERESULT($result);
232 if (empty($column)) {
234 return $GLOBALS['network_data'][$id];
237 return $GLOBALS['network_data'][$id][$column];
241 // "Getter" for a network type data by provided id number
242 function getNetworkTypeDataById ($id) {
243 // Ids lower one are not accepted
245 // Not good, should be fixed
246 debug_report_bug(__FUNCTION__, __LINE__, 'Network type id ' . $id . ' is smaller than 1.');
249 // By default we have no data
250 $GLOBALS['network_type_data'][$id] = array();
252 // Query for the network data
253 $result = SQL_QUERY_ESC("SELECT
254 `network_type_id`, `network_id`, `network_type_handle`, `network_type_api_url`, `network_type_click_url`, `network_type_banner_url`
256 `{?_MYSQL_PREFIX?}_network_types`
260 array(bigintval($id)), __FUNCTION__, __LINE__);
262 // Do we have an entry?
263 if (SQL_NUMROWS($result) == 1) {
265 $GLOBALS['network_type_data'][$id] = SQL_FETCHARRAY($result);
269 SQL_FREERESULT($result);
272 return $GLOBALS['network_type_data'][$id];
275 // "Getter" for a network request parameter data by provided id number
276 function getNetworkRequestParamsDataById ($id) {
277 // Ids lower one are not accepted
279 // Not good, should be fixed
280 debug_report_bug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $id . ' is smaller than 1.');
283 // By default we have no data
284 $networkRequestData = array();
286 // Query for the network data
287 $result = SQL_QUERY_ESC("SELECT
288 `network_param_id`, `network_id`, `network_type_id`, `request_param_key`, `request_param_value`, `request_param_default`
290 `{?_MYSQL_PREFIX?}_network_request_params`
292 `network_param_id`=%s
294 array(bigintval($id)), __FUNCTION__, __LINE__);
296 // Do we have an entry?
297 if (SQL_NUMROWS($result) == 1) {
299 $networkRequestData = SQL_FETCHARRAY($result);
303 SQL_FREERESULT($result);
306 return $networkRequestData;
309 // Updates given network (id) with data from array
310 function doNetworkUpdateDataByArray ($id, $networkData) {
311 // Ids lower one are not accepted
313 // Not good, should be fixed
314 debug_report_bug(__FUNCTION__, __LINE__, 'Network id ' . $id . ' is smaller than 1.');
317 // Just call our inner method
318 return adminSaveSettings($networkData, '_network_data', sprintf("`network_id`=%s", bigintval($id)), array(), false, false);
321 // Updates given network type handler (id) with data from array
322 function doNetworkUpdateTypeByArray ($id, $networkTypeData) {
323 // Ids lower one are not accepted
325 // Not good, should be fixed
326 debug_report_bug(__FUNCTION__, __LINE__, 'Network type handler id ' . $id . ' is smaller than 1.');
329 // Just call our inner method
330 return adminSaveSettings($networkTypeData, '_network_types', sprintf("`network_type_id`=%s", bigintval($id)), array(), false, false);
333 // Updates given network request parameters (id) with data from array
334 function doNetworkUpdateParamsByArray ($id, $networkParamData) {
335 // Ids lower one are not accepted
337 // Not good, should be fixed
338 debug_report_bug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $id . ' is smaller than 1.');
341 // Just call our inner method
342 return adminSaveSettings($networkParamData, '_network_request_params', sprintf("`network_param_id`=%s", bigintval($id)), array(), false, false);
345 // Removes given network entry
346 function doAdminRemoveNetworkEntry ($table, $column, $id, $limit = 1) {
348 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_network_%s` WHERE `%s`=%s LIMIT %s",
349 array($table, $column, $id, $limit), __FUNCTION__, __LINE__);
351 // Return affected rows
352 return SQL_AFFECTEDROWS();
355 // Generates a list of networks for given script and returns it
356 function generateAdminNetworkList () {
360 // Query for all networks
361 $result = SQL_QUERY("SELECT
362 `network_id`, `network_short_name`, `network_title`
364 `{?_MYSQL_PREFIX?}_network_data`
366 `network_short_name` ASC", __FUNCTION__, __LINE__);
368 // Do we have entries?
369 if (SQL_NUMROWS($result) > 0) {
372 while ($row = SQL_FETCHARRAY($result)) {
373 // Is this valid, then add it
374 if ((is_array($row)) && (isset($row['network_id']))) {
376 $rows[$row['network_id']] = $row;
380 // Generate the selection box
381 $content = generateSelectionBoxFromArray($rows, 'network', 'network_id');
384 $content = loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_ENTRIES_404'));
388 SQL_FREERESULT($result);
394 // Generator (somewhat getter) for a list of network types for given network id
395 function generateAdminNetworkTypeList ($networkId) {
399 // Query all types of this network
400 $result = SQL_QUERY_ESC("SELECT
401 `network_type_id`, `network_type_handle`
403 `{?_MYSQL_PREFIX?}_network_types`
407 `network_type_handle` ASC",
409 bigintval($networkId)
410 ), __FUNCTION__, __LINE__);
412 // Do we have entries?
413 if (SQL_NUMROWS($result) > 0) {
416 while ($row = SQL_FETCHARRAY($result)) {
417 // Is this valid, then add it
418 if ((is_array($row)) && (isset($row['network_type_id']))) {
420 $rows[$row['network_type_id']] = $row;
424 // Generate the selection box
425 $content = generateSelectionBoxFromArray($rows, 'network_type', 'network_type_id');
428 $content = loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_ENTRIES_404'));
432 SQL_FREERESULT($result);
438 // Generator (somewhat getter) for a list of network types for all types
439 function generateAdminDistinctNetworkTypeList () {
443 // Query all types of this network
444 $result = SQL_QUERY("SELECT
445 t.`network_type_id`, t.`network_type_handle`, d.`network_title`
447 `{?_MYSQL_PREFIX?}_network_types` AS t
449 `{?_MYSQL_PREFIX?}_network_data` AS d
451 t.`network_id`=d.`network_id`
453 d.`network_short_name` ASC,
454 t.`network_type_handle` ASC", __FUNCTION__, __LINE__);
456 // Do we have entries?
457 if (SQL_NUMROWS($result) > 0) {
460 while ($row = SQL_FETCHARRAY($result)) {
461 // Is this valid, then add it
462 if ((is_array($row)) && (isset($row['network_type_id']))) {
464 $rows[$row['network_type_id']] = $row;
468 // Generate the selection box
469 $content = generateSelectionBoxFromArray($rows, 'network_type', 'network_type_id', '', '_title');
472 $content = loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_ENTRIES_404'));
476 SQL_FREERESULT($result);
477 //* DEBUG: */ die('<pre>'.htmlentities($content).'</pre>');
483 // Generator (somewhat getter) for network type options
484 function generateNetworkTypeOptions ($id) {
485 // Is this an array, then we just came back from edit/delete actions
486 if (is_array($id)) $id = '';
489 if (!isset($GLOBALS['network_type_options'][$id])) {
490 // Generate output and cache it
491 $GLOBALS['network_type_options'][$id] = generateOptionList(
494 'network_type_handle',
498 "WHERE `network_id`=%s",
499 bigintval(getRequestParameter('network'))
505 return $GLOBALS['network_type_options'][$id];
508 // Generator (somewhat getter) for request key options
509 function generateNetworkRequestKeyOptions ($key) {
511 if (!isset($GLOBALS['network_request_param_key'][$key])) {
512 // Generate and cache it
513 $GLOBALS['network_request_param_key'][$key] = generateOptionList(
532 '{--ADMIN_NETWORK_REQUEST_PARAMETER_ID--}',
533 '{--ADMIN_NETWORK_REQUEST_PARAMETER_SID--}',
534 '{--ADMIN_NETWORK_REQUEST_PARAMETER_HASH--}',
535 '{--ADMIN_NETWORK_REQUEST_PARAMETER_PASSWORD--}',
536 '{--ADMIN_NETWORK_REQUEST_PARAMETER_RELOAD--}',
537 '{--ADMIN_NETWORK_REQUEST_PARAMETER_MAXIMUM_STAY--}',
538 '{--ADMIN_NETWORK_REQUEST_PARAMETER_MINIMUM_STAY--}',
539 '{--ADMIN_NETWORK_REQUEST_PARAMETER_CURRENCY--}',
540 '{--ADMIN_NETWORK_REQUEST_PARAMETER_TYPE--}',
541 '{--ADMIN_NETWORK_REQUEST_PARAMETER_REMAIN--}',
542 '{--ADMIN_NETWORK_REQUEST_PARAMETER_REWARD--}',
543 '{--ADMIN_NETWORK_REQUEST_PARAMETER_SIZE--}',
544 '{--ADMIN_NETWORK_REQUEST_PARAMETER_EROTIC--}',
545 '{--ADMIN_NETWORK_REQUEST_PARAMETER_EXTRA--}'
549 $GLOBALS['network_params_disabled']
554 return $GLOBALS['network_request_param_key'][$key];
557 // Generator (somewhat getter) for (return) array translation
558 function generateNetworkArrayTranslationOptions ($default) {
560 if (!isset($GLOBALS['network_array_translation'][$default])) {
561 // Generate and cache it
562 $GLOBALS['network_array_translation'][$default] = generateOptionList(
563 'network_translations',
564 'network_translation',
565 'network_translation',
568 sprintf("WHERE `network_type_id`=%s",
569 bigintval(getRequestParameter('network_type'))
571 $GLOBALS['network_array_translation_disabled'],
572 'ADMIN_NETWORK_ARRAY_TRANSLATION_'
577 return $GLOBALS['network_array_translation'][$default];
580 //------------------------------------------------------------------------------
581 // Call-back functions
582 //------------------------------------------------------------------------------
584 // Callback function to add new network
585 function doAdminNetworkProcessAddnetworkForm () {
586 // We can say here, the form is sent, so check if the network is already added
587 if (isNetworkNameValid(postRequestParameter('network_short_name'))) {
589 loadTemplate('admin_settings_unsaved', false, getMaskedMessage('ADMIN_NETWORK_ALREADY_ADDED', postRequestParameter('network_short_name')));
593 // Remove the 'ok' part
594 unsetPostRequestParameter('ok');
596 // Add the whole request to database
597 SQL_QUERY("INSERT INTO
598 `{?_MYSQL_PREFIX?}_network_data`
600 `" . implode('`,`', array_keys(postRequestArray())) . "`
602 '" . implode("','", array_values(postRequestArray())) . "'
603 )", __FUNCTION__, __LINE__);
605 // Add the id for output only
606 setPostRequestParameter('network_id', SQL_INSERTID());
609 if (SQL_AFFECTEDROWS() == 1) {
610 // Successfully added
611 loadTemplate('admin_network_added', false, postRequestArray());
614 loadTemplate('admin_settings_unsaved', false, getMaskedMessage('ADMIN_NETWORK_DATA_NOT_ADDED', postRequestParameter('network_short_name')));
618 // Displays selected networks for editing
619 function doAdminNetworkProcessHandlenetworkForm () {
620 // Do we have selections?
621 if (countPostSelection() > 0) {
622 // Something has been selected, so start displaying one by one
624 foreach (postRequestParameter('sel') as $id => $sel) {
627 // Load this network's data
628 $networkData = getNetworkDataById($id);
630 // Do we have found the network?
631 if (count($networkData) > 0) {
633 $networkData['sw'] = $SW;
635 if (isFormSent('edit')) {
636 // Make selection box for network_request_type
637 $networkData['network_request_type'] = generateOptionList(
644 getMessage('ADMIN_NETWORK_REQUEST_TYPE_GET'),
645 getMessage('ADMIN_NETWORK_REQUEST_TYPE_POST')
647 $networkData['network_request_type']
650 // Add row template for editing
651 $OUT .= loadTemplate('admin_edit_networks_row', true, $networkData);
652 } elseif (isFormSent('del')) {
653 // Translate the request type
654 $networkData['network_request_type'] = getMessage('ADMIN_NETWORK_REQUEST_TYPE_' . $networkData['network_request_type']);
656 // Add row template for deleting
657 $OUT .= loadTemplate('admin_del_networks_row', true, $networkData);
660 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
669 // If we have no rows, we don't need to display the edit form
671 // Output main template
672 if (isFormSent('edit')) {
673 loadTemplate('admin_edit_networks', false, $OUT);
674 } elseif (isFormSent('del')) {
675 loadTemplate('admin_del_networks', false, $OUT);
678 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
681 // Don't display the list/add new form
682 $GLOBALS['network_display'] = false;
684 // Nothing selected/found
685 loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_NETWORK_NOTHING_FOUND'));
690 // Handle network type form
691 function doAdminNetworkProcessHandlenetworktypeForm () {
692 // Do we have selections?
693 if (countPostSelection() > 0) {
695 $networkData = getNetworkDataById(getRequestParameter('network'));
697 // Something has been selected, so start displaying one by one
699 foreach (postRequestParameter('sel') as $id => $sel) {
702 // Load this network's data
703 $networkTypeData = getNetworkTypeDataById($id);
705 // Do we have found the network?
706 if (count($networkTypeData) > 0) {
708 $networkTypeData['sw'] = $SW;
710 if (isFormSent('edit')) {
711 // Add row template for deleting
712 $OUT .= loadTemplate('admin_edit_network_types_row', true, $networkTypeData);
713 } elseif (isFormSent('del')) {
714 // Fix empty banner URL
715 if (trim($networkTypeData['network_type_banner_url']) == '') $networkTypeData['network_type_banner_url'] = '---';
717 // Add row template for deleting
718 $OUT .= loadTemplate('admin_del_network_types_row', true, $networkTypeData);
721 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
730 // If we have no rows, we don't need to display the edit form
732 // Prepare content for template
735 'network_data' => getNetworkDataById(getRequestParameter('network'))
738 // Output main template
739 if (isFormSent('edit')) {
740 loadTemplate('admin_edit_network_types', false, $content);
741 } elseif (isFormSent('del')) {
742 loadTemplate('admin_del_network_types', false, $content);
745 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
748 // Don't display the list/add new form
749 $GLOBALS['network_display'] = false;
751 // Nothing selected/found
752 loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_NETWORK_TYPES_NOTHING_FOUND'));
757 // Handle network request parameter form
758 function doAdminNetworkProcessHandlerequestparamsForm () {
759 // Do we have selections?
760 if (countPostSelection() > 0) {
762 $GLOBALS['network_params_disabled'] = array();
765 $networkData = getNetworkDataById(getRequestParameter('network'));
767 // Something has been selected, so start displaying one by one
769 foreach (postRequestParameter('sel') as $id => $sel) {
772 // Load this network's data
773 $networkRequestData = getNetworkRequestParamsDataById($id);
775 // Do we have found the network?
776 if (count($networkRequestData) > 0) {
778 $networkRequestData['sw'] = $SW;
780 if (isFormSent('edit')) {
781 // Add options list for network type
782 $networkRequestData['type_options'] = generateNetworkTypeOptions($networkRequestData['network_type_id']);
784 // Add options list for request key
785 $networkRequestData['key_options'] = generateNetworkRequestKeyOptions($networkRequestData['request_param_key']);
787 // Add row template for deleting
788 $OUT .= loadTemplate('admin_edit_network_params_row', true, $networkRequestData);
789 } elseif (isFormSent('del')) {
790 // Fix empty banner URL
791 if (trim($networkRequestData['request_param_default']) == '') $networkRequestData['request_param_default'] = '---';
794 $networkRequestData['network_type_data'] = getNetworkTypeDataById($networkRequestData['network_type_id']);
796 // Add row template for deleting
797 $OUT .= loadTemplate('admin_del_network_params_row', true, $networkRequestData);
800 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
809 // If we have no rows, we don't need to display the edit form
811 // Prepare content for template
814 'network_data' => getNetworkDataById(getRequestParameter('network'))
817 // Output main template
818 if (isFormSent('edit')) {
819 loadTemplate('admin_edit_network_params', false, $content);
820 } elseif (isFormSent('del')) {
821 loadTemplate('admin_del_network_params', false, $content);
824 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
827 // Don't display the list/add new form
828 $GLOBALS['network_display'] = false;
830 // Nothing selected/found
831 loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_FOUND'));
836 // Changes given networks
837 function doAdminNetworkProcessChangenetworkForm () {
838 // Do we have selections?
839 if (countPostSelection() > 0) {
840 // By default nothing is updated
843 // Something has been selected, so start updating them
844 foreach (postRequestParameter('sel') as $id => $sel) {
845 // Update this entry?
848 $networkData = array();
850 // Transfer whole array, except 'sel'
851 foreach (postRequestArray() as $key => $entry) {
852 // Skip 'sel' and submit button
853 if (in_array($key, array('sel', 'change'))) continue;
855 // Do we have this enty?
856 if (!isset($entry[$id])) {
857 // Not found, needs fixing
858 debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $id . ' found.');
862 $networkData[$key] = $entry[$id];
865 // Update the network data
866 $updated += doNetworkUpdateDataByArray($id, $networkData);
870 // Do we have updates?
873 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_UPDATED', $updated));
876 loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_NETWORK_NOTHING_CHANGED'));
881 // Removes given networks
882 function doAdminNetworkProcessRemovenetworkForm () {
883 // Do we have selections?
884 if (countPostSelection() > 0) {
885 // By default nothing is removed
888 // Something has been selected, so start updating them
889 foreach (postRequestParameter('sel') as $id => $sel) {
890 // Update this entry?
893 $removed += doAdminRemoveNetworkEntry('data', 'network_id', $id);
897 // Do we have removes?
900 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_REMOVED', $removed));
903 loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_NETWORK_NOTHING_REMOVED'));
908 // Add a network type handler if not yet found
909 function doAdminNetworkProcessAddnetworktypeForm () {
910 // Is the network type handle already used with given network?
911 if (isNetworkTypeHandleValid(postRequestParameter('network_type_handle'), getRequestParameter('network'))) {
913 loadTemplate('admin_settings_unsaved', false, getMaskedMessage('ADMIN_NETWORK_TYPES_HANDLE_ALREADY_ADDED', postRequestParameter('network_type_handle')));
919 // Remove the 'ok' part
920 unsetPostRequestParameter('ok');
923 setPostRequestParameter('network_id', bigintval(getRequestParameter('network')));
925 // Is network_type_banner_url set?
926 if (postRequestParameter('network_type_banner_url') == '') {
927 // Remove empty value to get a NULL for an optional entry
928 unsetPostRequestParameter('network_type_banner_url');
931 // Add the whole request to database
932 SQL_QUERY("INSERT INTO
933 `{?_MYSQL_PREFIX?}_network_types`
935 `" . implode('`,`', array_keys(postRequestArray())) . "`
937 '" . implode("','", array_values(postRequestArray())) . "'
938 )", __FUNCTION__, __LINE__);
941 if (SQL_AFFECTEDROWS() == 1) {
942 // Successfully added
943 loadTemplate('admin_network_type_added', false, postRequestArray());
946 loadTemplate('admin_settings_unsaved', false, getMaskedMessage('ADMIN_NETWORK_TYPES_NOT_ADDED', postRequestParameter('network_type_handle')));
950 // Changes given network type handlers
951 function doAdminNetworkProcessChangenetworktypeForm () {
952 // Do we have selections?
953 if (countPostSelection() > 0) {
954 // By default nothing is updated
957 // Something has been selected, so start updating them
958 foreach (postRequestParameter('sel') as $id => $sel) {
959 // Update this entry?
962 $networkTypeData = array();
964 // Transfer whole array, except 'sel'
965 foreach (postRequestArray() as $key => $entry) {
966 // Skip 'sel' and submit button
967 if (in_array($key, array('sel', 'change'))) continue;
969 // Do we have this enty?
970 if (!isset($entry[$id])) {
971 // Not found, needs fixing
972 debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $id . ' found.');
975 // Fix empty network_type_banner_url to NULL
976 if (($key == 'network_type_banner_url') && (trim($entry[$id]) == '')) {
982 $networkTypeData[$key] = $entry[$id];
985 // Update the network data
986 $updated += doNetworkUpdateTypeByArray($id, $networkTypeData);
990 // Do we have updates?
993 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_TYPES_UPDATED', $updated));
996 loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_NETWORK_TYPES_NOTHING_CHANGED'));
1001 // Changes given network request parameters
1002 function doAdminNetworkProcessChangenetworkparamForm () {
1003 // Do we have selections?
1004 if (countPostSelection() > 0) {
1005 // By default nothing is updated
1008 // Something has been selected, so start updating them
1009 foreach (postRequestParameter('sel') as $id => $sel) {
1010 // Update this entry?
1013 $networkParamsData = array();
1015 // Transfer whole array, except 'sel'
1016 foreach (postRequestArray() as $key => $entry) {
1017 // Skip 'sel' and submit button
1018 if (in_array($key, array('sel', 'change'))) continue;
1020 // Do we have this enty?
1021 if (!isset($entry[$id])) {
1022 // Not found, needs fixing
1023 debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $id . ' found.');
1026 // Fix empty request_param_default to NULL
1027 if (($key == 'request_param_default') && (trim($entry[$id]) == '')) {
1033 $networkParamsData[$key] = $entry[$id];
1036 // Update the network data
1037 $updated += doNetworkUpdateParamsByArray($id, $networkParamsData);
1041 // Do we have updates?
1044 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_REQUEST_PARAMETER_UPDATED', $updated));
1047 loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_CHANGED'));
1052 // Removes given network type handlers
1053 function doAdminNetworkProcessRemovenetworktypeForm () {
1054 // Do we have selections?
1055 if (countPostSelection() > 0) {
1056 // By default nothing is removed
1059 // Something has been selected, so start updating them
1060 foreach (postRequestParameter('sel') as $id => $sel) {
1061 // Update this entry?
1063 // Remove this entry
1064 $removed += doAdminRemoveNetworkEntry('types', 'network_type_id', $id);
1068 // Do we have removes?
1071 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_TYPES_REMOVED', $removed));
1074 loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_NETWORK_TYPES_NOTHING_REMOVED'));
1079 // Removes given network request parameters
1080 function doAdminNetworkProcessRemovenetworkparamForm () {
1081 // Do we have selections?
1082 if (countPostSelection() > 0) {
1083 // By default nothing is removed
1086 // Something has been selected, so start updating them
1087 foreach (postRequestParameter('sel') as $id => $sel) {
1088 // Update this entry?
1090 // Remove this entry
1091 $removed += doAdminRemoveNetworkEntry('request_params', 'network_param_id', $id);
1095 // Do we have removes?
1098 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_REQUEST_PARAMETER_REMOVED', $removed));
1101 loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_REMOVED'));
1106 // Adds a request parameter to given network and type
1107 function doAdminNetworkProcessAddnetworkparamForm () {
1108 // Is the request parameter already used with given network?
1109 if (isNetworkRequestParameterValid(postRequestParameter('request_param_key'), postRequestParameter('network_type_id'), getRequestParameter('network'))) {
1111 loadTemplate('admin_settings_unsaved', false, getMaskedMessage('ADMIN_NETWORK_REQUEST_PARAMETER_ALREADY_ADDED', postRequestParameter('request_param_key')));
1113 // ... so abort here
1117 // Remove the 'ok' part
1118 unsetPostRequestParameter('ok');
1121 setPostRequestParameter('network_id', bigintval(getRequestParameter('network')));
1123 // Is request_param_default set?
1124 if (postRequestParameter('request_param_default') == '') {
1125 // Remove empty value to get a NULL for an optional entry
1126 unsetPostRequestParameter('request_param_default');
1129 // Add the whole request to database
1130 SQL_QUERY("INSERT INTO
1131 `{?_MYSQL_PREFIX?}_network_request_params`
1133 `" . implode('`,`', array_keys(postRequestArray())) . "`
1135 '" . implode("','", array_values(postRequestArray())) . "'
1136 )", __FUNCTION__, __LINE__);
1139 if (SQL_AFFECTEDROWS() == 1) {
1140 // Successfully added
1141 loadTemplate('admin_network_request_param_added', false, postRequestArray());
1144 loadTemplate('admin_settings_unsaved', false, getMaskedMessage('ADMIN_NETWORK_REQUEST_PARAMETER_NOT_ADDED', postRequestParameter('request_param_key')));
1148 // Do expression code for this extension
1149 function doExpressionNetwork ($data) {
1150 // Construct replacer
1151 $replacer = sprintf(
1152 "{DQUOTE} . %s(%s, '%s') . {DQUOTE}",
1154 $data['matches'][4][$data['key']],
1158 // Replace %network% with the current network id
1159 $replacer = str_replace('%network%', getCurrentNetworkId(), $replacer);
1162 $code = replaceExpressionCode($data, $replacer);