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, '{--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, '{--ADMIN_NETWORK_FORM_NOT_SENT--}');
77 } elseif (!isGetRequestParameterSet('do')) {
79 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_DO_404--}');
83 // Create function name
84 $functionName = sprintf("doAdminNetworkProcess%s", capitalizeUnderscoreString(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 // Checks wether the given network API array translation
145 function isNetworkApiTranslationValid ($key, $type, $networkId) {
147 $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",
148 array($networkId, $type, $key), __FUNCTION__, __LINE__);
151 $isValid = (SQL_NUMROWS($result) == 1);
154 SQL_FREERESULT($result);
160 // "Getter" for a network's data by provided id number
161 function getNetworkDataById ($id, $column = '') {
162 // Ids lower one are not accepted
164 // Not good, should be fixed
165 debug_report_bug(__FUNCTION__, __LINE__, 'Network id ' . $id . ' is smaller than 1.');
168 // Set current network id
169 setCurrentNetworkId($id);
172 if (!isset($GLOBALS['network_data'][$id])) {
173 // By default we have no data
174 $GLOBALS['network_data'][$id] = array();
176 // Query for the network data
177 $result = SQL_QUERY_ESC("SELECT
178 `network_id`, `network_short_name`, `network_title`, `network_reflink`, `network_data_seperator`, `network_row_seperator`, `network_request_type`, `network_charset`
180 `{?_MYSQL_PREFIX?}_network_data`
184 array(bigintval($id)), __FUNCTION__, __LINE__);
186 // Do we have an entry?
187 if (SQL_NUMROWS($result) == 1) {
189 $GLOBALS['network_data'][$id] = SQL_FETCHARRAY($result);
193 SQL_FREERESULT($result);
197 if (empty($column)) {
199 return $GLOBALS['network_data'][$id];
202 return $GLOBALS['network_data'][$id][$column];
206 // "Getter" for a network's data by provided type id number
207 function getNetworkDataByTypeId ($id, $column = '') {
208 // Ids lower one are not accepted
210 // Not good, should be fixed
211 debug_report_bug(__FUNCTION__, __LINE__, 'Network type id ' . $id . ' is smaller than 1.');
214 // Set current network id
215 setCurrentNetworkId($id);
218 if (!isset($GLOBALS['network_data'][$id])) {
219 // By default we have no data
220 $GLOBALS['network_data'][$id] = array();
222 // Query for the network data
223 $result = SQL_QUERY_ESC("SELECT
224 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`,
225 t.`network_type_handle`, t.`network_type_api_url`, t.`network_type_click_url`, t.`network_type_banner_url`
227 `{?_MYSQL_PREFIX?}_network_data` AS d
229 `{?_MYSQL_PREFIX?}_network_types` AS t
231 d.`network_id`=t.`network_id`
233 t.`network_type_id`=%s
235 array(bigintval($id)), __FUNCTION__, __LINE__);
237 // Do we have an entry?
238 if (SQL_NUMROWS($result) == 1) {
240 $GLOBALS['network_data'][$id] = SQL_FETCHARRAY($result);
244 SQL_FREERESULT($result);
248 if (empty($column)) {
250 return $GLOBALS['network_data'][$id];
253 return $GLOBALS['network_data'][$id][$column];
257 // "Getter" for a network type data by provided id number
258 function getNetworkTypeDataById ($id) {
259 // Ids lower one are not accepted
261 // Not good, should be fixed
262 debug_report_bug(__FUNCTION__, __LINE__, 'Network type id ' . $id . ' is smaller than 1.');
265 // By default we have no data
266 $GLOBALS['network_type_data'][$id] = array();
268 // Query for the network data
269 $result = SQL_QUERY_ESC("SELECT
270 `network_type_id`, `network_id`, `network_type_handle`, `network_type_api_url`, `network_type_click_url`, `network_type_banner_url`
272 `{?_MYSQL_PREFIX?}_network_types`
276 array(bigintval($id)), __FUNCTION__, __LINE__);
278 // Do we have an entry?
279 if (SQL_NUMROWS($result) == 1) {
281 $GLOBALS['network_type_data'][$id] = SQL_FETCHARRAY($result);
285 SQL_FREERESULT($result);
288 return $GLOBALS['network_type_data'][$id];
291 // "Getter" for a network request parameter data by provided id number
292 function getNetworkRequestParamsDataById ($id) {
293 // Ids lower one are not accepted
295 // Not good, should be fixed
296 debug_report_bug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $id . ' is smaller than 1.');
299 // By default we have no data
300 $networkRequestData = array();
302 // Query for the network data
303 $result = SQL_QUERY_ESC("SELECT
304 `network_param_id`, `network_id`, `network_type_id`, `request_param_key`, `request_param_value`, `request_param_default`
306 `{?_MYSQL_PREFIX?}_network_request_params`
308 `network_param_id`=%s
310 array(bigintval($id)), __FUNCTION__, __LINE__);
312 // Do we have an entry?
313 if (SQL_NUMROWS($result) == 1) {
315 $networkRequestData = SQL_FETCHARRAY($result);
319 SQL_FREERESULT($result);
322 return $networkRequestData;
325 // Updates given network (id) with data from array
326 function doNetworkUpdateDataByArray ($id, $networkData) {
327 // Ids lower one are not accepted
329 // Not good, should be fixed
330 debug_report_bug(__FUNCTION__, __LINE__, 'Network id ' . $id . ' is smaller than 1.');
333 // Just call our inner method
334 return adminSaveSettings($networkData, '_network_data', sprintf("`network_id`=%s", bigintval($id)), array(), false, false);
337 // Updates given network type handler (id) with data from array
338 function doNetworkUpdateTypeByArray ($id, $networkTypeData) {
339 // Ids lower one are not accepted
341 // Not good, should be fixed
342 debug_report_bug(__FUNCTION__, __LINE__, 'Network type handler id ' . $id . ' is smaller than 1.');
345 // Just call our inner method
346 return adminSaveSettings($networkTypeData, '_network_types', sprintf("`network_type_id`=%s", bigintval($id)), array(), false, false);
349 // Updates given network request parameters (id) with data from array
350 function doNetworkUpdateParamsByArray ($id, $networkParamData) {
351 // Ids lower one are not accepted
353 // Not good, should be fixed
354 debug_report_bug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $id . ' is smaller than 1.');
357 // Just call our inner method
358 return adminSaveSettings($networkParamData, '_network_request_params', sprintf("`network_param_id`=%s", bigintval($id)), array(), false, false);
361 // Removes given network entry
362 function doAdminRemoveNetworkEntry ($table, $column, $id, $limit = 1) {
364 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_network_%s` WHERE `%s`=%s LIMIT %s",
365 array($table, $column, $id, $limit), __FUNCTION__, __LINE__);
367 // Return affected rows
368 return SQL_AFFECTEDROWS();
371 // Generates a list of networks for given script and returns it
372 function generateAdminNetworkList () {
376 // Query for all networks
377 $result = SQL_QUERY('SELECT
378 `network_id`, `network_short_name`, `network_title`
380 `{?_MYSQL_PREFIX?}_network_data`
382 `network_short_name` ASC', __FUNCTION__, __LINE__);
384 // Do we have entries?
385 if (!SQL_HASZERONUMS($result)) {
388 while ($row = SQL_FETCHARRAY($result)) {
389 // Is this valid, then add it
390 if ((is_array($row)) && (isset($row['network_id']))) {
392 $rows[$row['network_id']] = $row;
396 // Generate the selection box
397 $content = generateSelectionBoxFromArray($rows, 'network', 'network_id');
400 $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}');
404 SQL_FREERESULT($result);
410 // Generator (somewhat getter) for a list of network types for given network id
411 function generateAdminNetworkTypeList ($networkId) {
415 // Query all types of this network
416 $result = SQL_QUERY_ESC("SELECT
417 `network_type_id`, `network_type_handle`
419 `{?_MYSQL_PREFIX?}_network_types`
423 `network_type_handle` ASC",
425 bigintval($networkId)
426 ), __FUNCTION__, __LINE__);
428 // Do we have entries?
429 if (!SQL_HASZERONUMS($result)) {
432 while ($row = SQL_FETCHARRAY($result)) {
433 // Is this valid, then add it
434 if ((is_array($row)) && (isset($row['network_type_id']))) {
436 $rows[$row['network_type_id']] = $row;
440 // Generate the selection box
441 $content = generateSelectionBoxFromArray($rows, 'network_type', 'network_type_id');
444 $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}');
448 SQL_FREERESULT($result);
454 // Generator (somewhat getter) for a list of network types for all types
455 function generateAdminDistinctNetworkTypeList () {
459 // Query all types of this network
460 $result = SQL_QUERY('SELECT
461 t.`network_type_id`, t.`network_type_handle`, d.`network_title`
463 `{?_MYSQL_PREFIX?}_network_types` AS t
465 `{?_MYSQL_PREFIX?}_network_data` AS d
467 t.`network_id`=d.`network_id`
469 d.`network_short_name` ASC,
470 t.`network_type_handle` ASC', __FUNCTION__, __LINE__);
472 // Do we have entries?
473 if (!SQL_HASZERONUMS($result)) {
476 while ($row = SQL_FETCHARRAY($result)) {
477 // Is this valid, then add it
478 if ((is_array($row)) && (isset($row['network_type_id']))) {
480 $rows[$row['network_type_id']] = $row;
484 // Generate the selection box
485 $content = generateSelectionBoxFromArray($rows, 'network_type', 'network_type_id', '', '_title');
488 $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}');
492 SQL_FREERESULT($result);
493 //* DEBUG: */ die('<pre>'.encodeEntities($content).'</pre>');
499 // Generator (somewhat getter) for network type options
500 function generateNetworkTypeOptions ($id) {
501 // Is this an array, then we just came back from edit/delete actions
502 if (is_array($id)) $id = '';
505 if (!isset($GLOBALS['network_type_options'][$id])) {
506 // Generate output and cache it
507 $GLOBALS['network_type_options'][$id] = generateOptionList(
510 'network_type_handle',
514 "WHERE `network_id`=%s",
515 bigintval(getRequestParameter('network'))
518 'translateNetworkTypeHandler'
523 return $GLOBALS['network_type_options'][$id];
526 // Generator (somewhat getter) for request key options
527 function generateNetworkRequestKeyOptions ($key) {
529 if (!isset($GLOBALS['network_request_param_key'][$key])) {
530 // Generate and cache it
531 $GLOBALS['network_request_param_key'][$key] = generateOptionList(
550 '{--ADMIN_NETWORK_REQUEST_PARAMETER_ID--}',
551 '{--ADMIN_NETWORK_REQUEST_PARAMETER_SID--}',
552 '{--ADMIN_NETWORK_REQUEST_PARAMETER_HASH--}',
553 '{--ADMIN_NETWORK_REQUEST_PARAMETER_PASSWORD--}',
554 '{--ADMIN_NETWORK_REQUEST_PARAMETER_RELOAD--}',
555 '{--ADMIN_NETWORK_REQUEST_PARAMETER_MAXIMUM_STAY--}',
556 '{--ADMIN_NETWORK_REQUEST_PARAMETER_MINIMUM_STAY--}',
557 '{--ADMIN_NETWORK_REQUEST_PARAMETER_CURRENCY--}',
558 '{--ADMIN_NETWORK_REQUEST_PARAMETER_TYPE--}',
559 '{--ADMIN_NETWORK_REQUEST_PARAMETER_REMAIN--}',
560 '{--ADMIN_NETWORK_REQUEST_PARAMETER_REWARD--}',
561 '{--ADMIN_NETWORK_REQUEST_PARAMETER_SIZE--}',
562 '{--ADMIN_NETWORK_REQUEST_PARAMETER_EROTIC--}',
563 '{--ADMIN_NETWORK_REQUEST_PARAMETER_EXTRA--}'
567 $GLOBALS['network_params_disabled']
572 return $GLOBALS['network_request_param_key'][$key];
575 // Generator (somewhat getter) for (return) array translation
576 function generateNetworkTranslationOptions ($default = '') {
578 if (!isset($GLOBALS['network_translation'][$default])) {
579 // Generate and cache it
580 $GLOBALS['network_translation'][$default] = generateOptionList(
581 'network_translations',
582 'network_translation_id',
583 'network_translation_name',
587 $GLOBALS['network_translation_disabled'],
588 'translateNetworkTranslationName'
593 return $GLOBALS['network_translation'][$default];
596 // Generates an option list of request types
597 function generateNetworkRequestTypeOptions ($default = '') {
599 if (!isset($GLOBALS['network_request_type'][$default])) {
601 $GLOBALS['network_request_type'][$default] = generateOptionList(
608 '{--ADMIN_NETWORK_REQUEST_TYPE_GET--}',
609 '{--ADMIN_NETWORK_REQUEST_TYPE_POST--}'
616 return $GLOBALS['network_request_type'][$default];
619 // Translates 'translate_name' for e.g. templates
620 function translateNetworkTranslationName ($name) {
621 // Get the message id
622 return getMessage('ADMIN_NETWORK_TRANSLATE_' . strtoupper($name) . '_NAME');
625 // Translates the network type handler (e.g. banner, paidmail) for templates
626 function translateNetworkTypeHandler ($type) {
627 // Get the message id
628 return getMessage('ADMIN_NETWORK_TYPES_' . strtoupper($type) . '');
631 // Translates request type
632 function translateNetworkRequestType ($name) {
633 // Get the message id
634 return getMessage('ADMIN_NETWORK_REQUEST_TYPE_' . strtoupper($name) . '');
637 //------------------------------------------------------------------------------
638 // Call-back functions
639 //------------------------------------------------------------------------------
641 // Callback function to add new network
642 function doAdminNetworkProcessAddNetwork () {
643 // We can say here, the form is sent, so check if the network is already added
644 if (isNetworkNameValid(postRequestParameter('network_short_name'))) {
646 loadTemplate('admin_settings_unsaved', false, getMaskedMessage('ADMIN_NETWORK_ALREADY_ADDED', postRequestParameter('network_short_name')));
650 // Remove the 'ok' part
651 unsetPostRequestParameter('ok');
653 // Add the whole request to database
654 SQL_QUERY('INSERT INTO
655 `{?_MYSQL_PREFIX?}_network_data`
657 `' . implode('`,`', array_keys(postRequestArray())) . "`
659 '" . implode("','", array_values(postRequestArray())) . "'
660 )", __FUNCTION__, __LINE__);
662 // Add the id for output only
663 setPostRequestParameter('network_id', SQL_INSERTID());
666 if (SQL_AFFECTEDROWS() == 1) {
667 // Successfully added
668 loadTemplate('admin_network_added', false, postRequestArray());
671 loadTemplate('admin_settings_unsaved', false, getMaskedMessage('ADMIN_NETWORK_DATA_NOT_ADDED', postRequestParameter('network_short_name')));
675 // Displays selected networks for editing
676 function doAdminNetworkProcessHandleNetwork () {
677 // Do we have selections?
678 if (ifPostContainsSelections()) {
679 // Something has been selected, so start displaying one by one
681 foreach (postRequestParameter('sel') as $id => $sel) {
684 // Load this network's data
685 $networkData = getNetworkDataById($id);
687 // Do we have found the network?
688 if (count($networkData) > 0) {
689 if (isFormSent('edit')) {
690 // Add row template for editing
691 $OUT .= loadTemplate('admin_edit_networks_row', true, $networkData);
692 } elseif (isFormSent('del')) {
693 // Add row template for deleting
694 $OUT .= loadTemplate('admin_del_networks_row', true, $networkData);
697 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
703 // If we have no rows, we don't need to display the edit form
705 // Output main template
706 if (isFormSent('edit')) {
707 loadTemplate('admin_edit_networks', false, $OUT);
708 } elseif (isFormSent('del')) {
709 loadTemplate('admin_del_networks', false, $OUT);
712 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
715 // Don't display the list/add new form
716 $GLOBALS['network_display'] = false;
718 // Nothing selected/found
719 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_FOUND--}');
724 // Handle network type form
725 function doAdminNetworkProcessHandleNetworkType () {
726 // Do we have selections?
727 if (ifPostContainsSelections()) {
729 $networkData = getNetworkDataById(getRequestParameter('network'));
731 // Something has been selected, so start displaying one by one
733 foreach (postRequestParameter('sel') as $id => $sel) {
736 // Load this network's data
737 $networkTypeData = getNetworkTypeDataById($id);
739 // Do we have found the network?
740 if (count($networkTypeData) > 0) {
741 if (isFormSent('edit')) {
742 // Add row template for deleting
743 $OUT .= loadTemplate('admin_edit_network_types_row', true, $networkTypeData);
744 } elseif (isFormSent('del')) {
745 // Add row template for deleting
746 $OUT .= loadTemplate('admin_del_network_types_row', true, $networkTypeData);
749 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
755 // If we have no rows, we don't need to display the edit form
757 // Output main template
758 if (isFormSent('edit')) {
759 loadTemplate('admin_edit_network_types', false, $OUT);
760 } elseif (isFormSent('del')) {
761 loadTemplate('admin_del_network_types', false, $OUT);
764 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
767 // Don't display the list/add new form
768 $GLOBALS['network_display'] = false;
770 // Nothing selected/found
771 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPES_NOTHING_FOUND--}');
776 // Handle network request parameter form
777 function doAdminNetworkProcessHandleRequestParams () {
778 // Do we have selections?
779 if (ifPostContainsSelections()) {
781 $GLOBALS['network_params_disabled'] = array();
784 $networkData = getNetworkDataById(getRequestParameter('network'));
786 // Something has been selected, so start displaying one by one
788 foreach (postRequestParameter('sel') as $id => $sel) {
791 // Load this network's data
792 $networkRequestData = getNetworkRequestParamsDataById($id);
794 // Do we have found the network?
795 if (count($networkRequestData) > 0) {
796 if (isFormSent('edit')) {
797 // Add row template for deleting
798 $OUT .= loadTemplate('admin_edit_network_params_row', true, $networkRequestData);
799 } elseif (isFormSent('del')) {
801 $networkRequestData['network_type_data'] = getNetworkTypeDataById($networkRequestData['network_type_id']);
803 // Add row template for deleting
804 $OUT .= loadTemplate('admin_del_network_params_row', true, $networkRequestData);
807 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
813 // If we have no rows, we don't need to display the edit form
815 // Output main template
816 if (isFormSent('edit')) {
817 loadTemplate('admin_edit_network_params', false, $OUT);
818 } elseif (isFormSent('del')) {
819 loadTemplate('admin_del_network_params', false, $OUT);
822 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
825 // Don't display the list/add new form
826 $GLOBALS['network_display'] = false;
828 // Nothing selected/found
829 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_FOUND--}');
834 // Changes given networks
835 function doAdminNetworkProcessChangeNetwork () {
836 // Do we have selections?
837 if (ifPostContainsSelections()) {
838 // By default nothing is updated
841 // Something has been selected, so start updating them
842 foreach (postRequestParameter('sel') as $id => $sel) {
843 // Update this entry?
846 $networkData = array();
848 // Transfer whole array, except 'sel'
849 foreach (postRequestArray() as $key => $entry) {
850 // Skip 'sel' and submit button
851 if (in_array($key, array('sel', 'change'))) continue;
853 // Do we have this enty?
854 if (!isset($entry[$id])) {
855 // Not found, needs fixing
856 debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $id . ' found.');
860 $networkData[$key] = $entry[$id];
863 // Update the network data
864 $updated += doNetworkUpdateDataByArray($id, $networkData);
868 // Do we have updates?
871 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_UPDATED', $updated));
874 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_CHANGED--}');
879 // Removes given networks
880 function doAdminNetworkProcessRemoveNetwork () {
881 // Do we have selections?
882 if (ifPostContainsSelections()) {
883 // By default nothing is removed
886 // Something has been selected, so start updating them
887 foreach (postRequestParameter('sel') as $id => $sel) {
888 // Update this entry?
891 $removed += doAdminRemoveNetworkEntry('data', 'network_id', $id);
895 // Do we have removes?
898 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_REMOVED', $removed));
901 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_REMOVED--}');
906 // Add a network type handler if not yet found
907 function doAdminNetworkProcessAddNetworkType () {
908 // Is the network type handle already used with given network?
909 if (isNetworkTypeHandleValid(postRequestParameter('network_type_handle'), getRequestParameter('network'))) {
911 loadTemplate('admin_settings_unsaved', false, getMaskedMessage('ADMIN_NETWORK_TYPES_HANDLE_ALREADY_ADDED', postRequestParameter('network_type_handle')));
917 // Remove the 'ok' part
918 unsetPostRequestParameter('ok');
921 setPostRequestParameter('network_id', bigintval(getRequestParameter('network')));
923 // Is network_type_banner_url set?
924 if (postRequestParameter('network_type_banner_url') == '') {
925 // Remove empty value to get a NULL for an optional entry
926 unsetPostRequestParameter('network_type_banner_url');
929 // Add the whole request to database
930 SQL_QUERY('INSERT INTO
931 `{?_MYSQL_PREFIX?}_network_types`
933 `' . implode('`,`', array_keys(postRequestArray())) . "`
935 '" . implode("','", array_values(postRequestArray())) . "'
936 )", __FUNCTION__, __LINE__);
939 if (SQL_AFFECTEDROWS() == 1) {
940 // Successfully added
941 loadTemplate('admin_network_type_added', false, postRequestArray());
944 loadTemplate('admin_settings_unsaved', false, getMaskedMessage('ADMIN_NETWORK_TYPES_NOT_ADDED', postRequestParameter('network_type_handle')));
948 // Changes given network type handlers
949 function doAdminNetworkProcessChangeNetworkType () {
950 // Do we have selections?
951 if (ifPostContainsSelections()) {
952 // By default nothing is updated
955 // Something has been selected, so start updating them
956 foreach (postRequestParameter('sel') as $id => $sel) {
957 // Update this entry?
960 $networkTypeData = array();
962 // Transfer whole array, except 'sel'
963 foreach (postRequestArray() as $key => $entry) {
964 // Skip 'sel' and submit button
965 if (in_array($key, array('sel', 'change'))) continue;
967 // Do we have this enty?
968 if (!isset($entry[$id])) {
969 // Not found, needs fixing
970 debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $id . ' found.');
973 // Fix empty network_type_banner_url to NULL
974 if (($key == 'network_type_banner_url') && (trim($entry[$id]) == '')) {
980 $networkTypeData[$key] = $entry[$id];
983 // Update the network data
984 $updated += doNetworkUpdateTypeByArray($id, $networkTypeData);
988 // Do we have updates?
991 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_TYPES_UPDATED', $updated));
994 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPES_NOTHING_CHANGED--}');
999 // Changes given network request parameters
1000 function doAdminNetworkProcessChangeNetworkParam () {
1001 // Do we have selections?
1002 if (ifPostContainsSelections()) {
1003 // By default nothing is updated
1006 // Something has been selected, so start updating them
1007 foreach (postRequestParameter('sel') as $id => $sel) {
1008 // Update this entry?
1011 $networkParamsData = array();
1013 // Transfer whole array, except 'sel'
1014 foreach (postRequestArray() as $key => $entry) {
1015 // Skip 'sel' and submit button
1016 if (in_array($key, array('sel', 'change'))) continue;
1018 // Do we have this enty?
1019 if (!isset($entry[$id])) {
1020 // Not found, needs fixing
1021 debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $id . ' found.');
1024 // Fix empty request_param_default to NULL
1025 if (($key == 'request_param_default') && (trim($entry[$id]) == '')) {
1031 $networkParamsData[$key] = $entry[$id];
1034 // Update the network data
1035 $updated += doNetworkUpdateParamsByArray($id, $networkParamsData);
1039 // Do we have updates?
1042 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_REQUEST_PARAMETER_UPDATED', $updated));
1045 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_CHANGED--}');
1050 // Removes given network type handlers
1051 function doAdminNetworkProcessRemoveNetworkType () {
1052 // Do we have selections?
1053 if (ifPostContainsSelections()) {
1054 // By default nothing is removed
1057 // Something has been selected, so start updating them
1058 foreach (postRequestParameter('sel') as $id => $sel) {
1059 // Update this entry?
1061 // Remove this entry
1062 $removed += doAdminRemoveNetworkEntry('types', 'network_type_id', $id);
1066 // Do we have removes?
1069 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_TYPES_REMOVED', $removed));
1072 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPES_NOTHING_REMOVED--}');
1077 // Removes given network request parameters
1078 function doAdminNetworkProcessRemoveNetworkParam () {
1079 // Do we have selections?
1080 if (ifPostContainsSelections()) {
1081 // By default nothing is removed
1084 // Something has been selected, so start updating them
1085 foreach (postRequestParameter('sel') as $id => $sel) {
1086 // Update this entry?
1088 // Remove this entry
1089 $removed += doAdminRemoveNetworkEntry('request_params', 'network_param_id', $id);
1093 // Do we have removes?
1096 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_REQUEST_PARAMETER_REMOVED', $removed));
1099 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_REMOVED--}');
1104 // Adds a request parameter to given network and type
1105 function doAdminNetworkProcessAddNetworkParam () {
1106 // Is the request parameter already used with given network?
1107 if (isNetworkRequestParameterValid(postRequestParameter('request_param_key'), postRequestParameter('network_type_id'), getRequestParameter('network'))) {
1109 loadTemplate('admin_settings_unsaved', false, getMaskedMessage('ADMIN_NETWORK_REQUEST_PARAMETER_ALREADY_ADDED', postRequestParameter('request_param_key')));
1111 // ... so abort here
1115 // Remove the 'ok' part
1116 unsetPostRequestParameter('ok');
1119 setPostRequestParameter('network_id', bigintval(getRequestParameter('network')));
1121 // Is request_param_default set?
1122 if (postRequestParameter('request_param_default') == '') {
1123 // Remove empty value to get a NULL for an optional entry
1124 unsetPostRequestParameter('request_param_default');
1127 // Add the whole request to database
1128 SQL_QUERY('INSERT INTO
1129 `{?_MYSQL_PREFIX?}_network_request_params`
1131 `' . implode('`,`', array_keys(postRequestArray())) . "`
1133 '" . implode("','", array_values(postRequestArray())) . "'
1134 )", __FUNCTION__, __LINE__);
1137 if (SQL_AFFECTEDROWS() == 1) {
1138 // Successfully added
1139 loadTemplate('admin_network_request_param_added', false, postRequestArray());
1142 loadTemplate('admin_settings_unsaved', false, getMaskedMessage('ADMIN_NETWORK_REQUEST_PARAMETER_NOT_ADDED', postRequestParameter('request_param_key')));
1146 // Adds a API response array entry
1147 function doAdminNetworkProcessAddNetworkApiTranslation () {
1148 // Is the request parameter already used with given network?
1149 if (isNetworkApiTranslationValid(postRequestParameter('network_api_index'), postRequestParameter('network_type_id'), getRequestParameter('network'))) {
1151 loadTemplate('admin_settings_unsaved', false, getMaskedMessage('ADMIN_NETWORK_API_TRANSLATION_ALREADY_ADDED', postRequestParameter('request_param_key')));
1153 // ... so abort here
1157 // Remove the 'ok' part
1158 unsetPostRequestParameter('ok');
1161 setPostRequestParameter('network_id', bigintval(getRequestParameter('network')));
1163 // Add the whole request to database
1164 SQL_QUERY('INSERT INTO
1165 `{?_MYSQL_PREFIX?}_network_api_translation`
1167 `' . implode('`,`', array_keys(postRequestArray())) . "`
1169 '" . implode("','", array_values(postRequestArray())) . "'
1170 )", __FUNCTION__, __LINE__);
1173 if (SQL_AFFECTEDROWS() == 1) {
1174 // Successfully added
1175 loadTemplate('admin_network_api_translation_added', false, postRequestArray());
1178 loadTemplate('admin_settings_unsaved', false, getMaskedMessage('ADMIN_NETWORK_API_TRANSLATION_NOT_ADDED', postRequestParameter('network_api_index')));
1182 // Do expression code for this extension
1183 function doExpressionNetwork ($data) {
1184 // Construct replacer
1185 $replacer = sprintf(
1186 "{DQUOTE} . %s(%s, '%s') . {DQUOTE}",
1188 $data['matches'][4][$data['key']],
1192 // Replace %network% with the current network id
1193 $replacer = str_replace('%network%', getCurrentNetworkId(), $replacer);
1196 $code = replaceExpressionCode($data, $replacer);