Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/message/defaultoutputs.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00024 require_once(dirname(__FILE__) . '/../config.php');
00025 require_once($CFG->dirroot . '/message/lib.php');
00026 require_once($CFG->libdir.'/adminlib.php');
00027 
00028 // This is an admin page
00029 admin_externalpage_setup('defaultmessageoutputs');
00030 
00031 // Require site configuration capability
00032 require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
00033 
00034 // Fetch processors
00035 $processors = get_message_processors(true);
00036 // Fetch message providers
00037 $providers = $DB->get_records('message_providers', null, 'name');
00038 
00039 if (($form = data_submitted()) && confirm_sesskey()) {
00040     $preferences = array();
00041     // Prepare default message outputs settings
00042     foreach ( $providers as $provider) {
00043         $componentproviderbase = $provider->component.'_'.$provider->name;
00044         foreach (array('permitted', 'loggedin', 'loggedoff') as $setting){
00045             $value = null;
00046             $componentprovidersetting = $componentproviderbase.'_'.$setting;
00047             if ($setting == 'permitted') {
00048                 // if we deal with permitted select element, we need to create individual
00049                 // setting for each possible processor. Note that this block will
00050                 // always be processed first after entring parental foreach iteration
00051                 // so we can change form values on this stage.
00052                 foreach($processors as $processor) {
00053                     $value = '';
00054                     if (isset($form->{$componentprovidersetting}[$processor->name])) {
00055                         $value = $form->{$componentprovidersetting}[$processor->name];
00056                     }
00057                     // Ensure that loggedin loggedoff options are set correctly
00058                     // for this permission
00059                     if ($value == 'forced') {
00060                         $form->{$componentproviderbase.'_loggedin'}[$processor->name] = 1;
00061                         $form->{$componentproviderbase.'_loggedoff'}[$processor->name] = 1;
00062                     } else if ($value == 'disallowed') {
00063                         // It might be better to unset them, but I can't figure out why that cause error
00064                         $form->{$componentproviderbase.'_loggedin'}[$processor->name] = 0;
00065                         $form->{$componentproviderbase.'_loggedoff'}[$processor->name] = 0;
00066                     }
00067                     // record the site preference
00068                     $preferences[$processor->name.'_provider_'.$componentprovidersetting] = $value;
00069                 }
00070             } else if (array_key_exists($componentprovidersetting, $form)) {
00071                 // we must be processing loggedin or loggedoff checkboxes. Store
00072                 // defained comma-separated processors as setting value.
00073                 // Using array_filter eliminates elements set to 0 above
00074                 $value = join(',', array_keys(array_filter($form->{$componentprovidersetting})));
00075                 if (empty($value)) {
00076                     $value = null;
00077                 }
00078             }
00079             if ($setting != 'permitted') {
00080                 // we have already recoded site preferences for 'permitted' type
00081                 $preferences['message_provider_'.$componentprovidersetting] = $value;
00082             }
00083         }
00084     }
00085 
00086     // Update database
00087     $transaction = $DB->start_delegated_transaction();
00088     foreach ($preferences as $name => $value) {
00089         set_config($name, $value, 'message');
00090     }
00091     $transaction->allow_commit();
00092 
00093     // Redirect
00094     $url = new moodle_url('defaultoutputs.php');
00095     redirect($url);
00096 }
00097 
00098 
00099 
00100 // Page settings
00101 $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
00102 $PAGE->requires->js_init_call('M.core_message.init_defaultoutputs');
00103 
00104 // Grab the renderer
00105 $renderer = $PAGE->get_renderer('core', 'message');
00106 
00107 // Display the manage message outputs interface
00108 $preferences = get_message_output_default_preferences();
00109 $messageoutputs = $renderer->manage_defaultmessageoutputs($processors, $providers, $preferences);
00110 
00111 // Display the page
00112 echo $OUTPUT->header();
00113 echo $OUTPUT->heading(get_string('defaultmessageoutputs', 'message'));
00114 echo $messageoutputs;
00115 echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations