|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00026 require_once(dirname(__FILE__) . '/../config.php'); 00027 require_once($CFG->dirroot . '/message/lib.php'); 00028 00029 $userid = optional_param('id', $USER->id, PARAM_INT); // user id 00030 $course = optional_param('course', SITEID, PARAM_INT); // course id (defaults to Site) 00031 $disableall = optional_param('disableall', 0, PARAM_BOOL); //disable all of this user's notifications 00032 00033 $url = new moodle_url('/message/edit.php'); 00034 if ($userid !== $USER->id) { 00035 $url->param('id', $userid); 00036 } 00037 if ($course != SITEID) { 00038 $url->param('course', $course); 00039 } 00040 $PAGE->set_url($url); 00041 00042 if (!$course = $DB->get_record('course', array('id' => $course))) { 00043 print_error('invalidcourseid'); 00044 } 00045 00046 if ($course->id != SITEID) { 00047 require_login($course); 00048 00049 } else { 00050 if (!isloggedin()) { 00051 if (empty($SESSION->wantsurl)) { 00052 $SESSION->wantsurl = $CFG->httpswwwroot.'/message/edit.php'; 00053 } 00054 redirect(get_login_url()); 00055 } 00056 } 00057 00058 if (isguestuser()) { 00059 print_error('guestnoeditmessage', 'message'); 00060 } 00061 00062 if (!$user = $DB->get_record('user', array('id' => $userid))) { 00063 print_error('invaliduserid'); 00064 } 00065 00066 $systemcontext = get_context_instance(CONTEXT_SYSTEM); 00067 $personalcontext = get_context_instance(CONTEXT_USER, $user->id); 00068 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); 00069 00070 $PAGE->set_context($personalcontext); 00071 $PAGE->set_pagelayout('course'); 00072 $PAGE->requires->js_init_call('M.core_message.init_editsettings'); 00073 00074 // check access control 00075 if ($user->id == $USER->id) { 00076 //editing own message profile 00077 require_capability('moodle/user:editownmessageprofile', $systemcontext); 00078 if ($course->id != SITEID && $node = $PAGE->navigation->find($course->id, navigation_node::TYPE_COURSE)) { 00079 $node->make_active(); 00080 $PAGE->navbar->includesettingsbase = true; 00081 } 00082 } else { 00083 // teachers, parents, etc. 00084 require_capability('moodle/user:editmessageprofile', $personalcontext); 00085 // no editing of guest user account 00086 if (isguestuser($user->id)) { 00087 print_error('guestnoeditmessageother', 'message'); 00088 } 00089 // no editing of admins by non admins! 00090 if (is_siteadmin($user) and !is_siteadmin($USER)) { 00091 print_error('useradmineditadmin'); 00092 } 00093 $PAGE->navigation->extend_for_user($user); 00094 } 00095 00096 // Fetch message providers 00097 $providers = message_get_providers_for_user($user->id); 00098 00100 00101 if (($form = data_submitted()) && confirm_sesskey()) { 00102 $preferences = array(); 00103 00104 //only update the user's "emailstop" if its actually changed 00105 if ( $user->emailstop != $disableall ) { 00106 $user->emailstop = $disableall; 00107 $DB->set_field('user', 'emailstop', $user->emailstop, array("id"=>$user->id)); 00108 } 00109 00110 // Turning on emailstop disables the preference checkboxes in the browser. 00111 // Disabled checkboxes may not be submitted with the form making them look (incorrectly) like they've been unchecked. 00112 // Only alter the messaging preferences if emailstop is turned off 00113 if (!$user->emailstop) { 00114 foreach ($providers as $provider) { 00115 $componentproviderbase = $provider->component.'_'.$provider->name; 00116 foreach (array('loggedin', 'loggedoff') as $state) { 00117 $linepref = ''; 00118 $componentproviderstate = $componentproviderbase.'_'.$state; 00119 if (array_key_exists($componentproviderstate, $form)) { 00120 foreach (array_keys($form->{$componentproviderstate}) as $process) { 00121 if ($linepref == ''){ 00122 $linepref = $process; 00123 } else { 00124 $linepref .= ','.$process; 00125 } 00126 } 00127 } 00128 if (empty($linepref)) { 00129 $linepref = 'none'; 00130 } 00131 $preferences['message_provider_'.$provider->component.'_'.$provider->name.'_'.$state] = $linepref; 00132 } 00133 } 00134 } 00135 00137 $processors = get_message_processors(true); 00138 foreach ($processors as $processor) { 00139 $processor->object->process_form($form, $preferences); 00140 } 00141 00142 //process general messaging preferences 00143 $preferences['message_blocknoncontacts'] = !empty($form->blocknoncontacts)?1:0; 00144 //$preferences['message_beepnewmessage'] = !empty($form->beepnewmessage)?1:0; 00145 00146 // Save all the new preferences to the database 00147 if (!set_user_preferences($preferences, $user->id)) { 00148 print_error('cannotupdateusermsgpref'); 00149 } 00150 00151 redirect("$CFG->wwwroot/message/edit.php?id=$user->id&course=$course->id"); 00152 } 00153 00155 $preferences = new stdClass(); 00156 $preferences->userdefaultemail = $user->email;//may be displayed by the email processor 00157 00159 foreach ($providers as $provider) { 00160 foreach (array('loggedin', 'loggedoff') as $state) { 00161 $linepref = get_user_preferences('message_provider_'.$provider->component.'_'.$provider->name.'_'.$state, '', $user->id); 00162 if ($linepref == ''){ 00163 continue; 00164 } 00165 $lineprefarray = explode(',', $linepref); 00166 $preferences->{$provider->component.'_'.$provider->name.'_'.$state} = array(); 00167 foreach ($lineprefarray as $pref) { 00168 $preferences->{$provider->component.'_'.$provider->name.'_'.$state}[$pref] = 1; 00169 } 00170 } 00171 } 00172 00173 // Load all processors 00174 $processors = get_message_processors(); 00176 foreach ($processors as $processor) { 00177 $processor->object->load_data($preferences, $user->id); 00178 } 00179 00180 //load general messaging preferences 00181 $preferences->blocknoncontacts = get_user_preferences( 'message_blocknoncontacts', '', $user->id); 00182 //$preferences->beepnewmessage = get_user_preferences( 'message_beepnewmessage', '', $user->id); 00183 00185 $streditmymessage = get_string('editmymessage', 'message'); 00186 $strparticipants = get_string('participants'); 00187 $userfullname = fullname($user, true); 00188 00189 $PAGE->set_title("$course->shortname: $streditmymessage"); 00190 if ($course->id != SITEID) { 00191 $PAGE->set_heading("$course->fullname: $streditmymessage"); 00192 } else { 00193 $PAGE->set_heading($course->fullname); 00194 } 00195 00196 // Grab the renderer 00197 $renderer = $PAGE->get_renderer('core', 'message'); 00198 // Fetch default (site) preferences 00199 $defaultpreferences = get_message_output_default_preferences(); 00200 00201 $messagingoptions = $renderer->manage_messagingoptions($processors, $providers, $preferences, $defaultpreferences, $user->emailstop); 00202 00203 echo $OUTPUT->header(); 00204 echo $messagingoptions; 00205 echo $OUTPUT->footer(); 00206