Differences Between: [Versions 310 and 402] [Versions 39 and 402]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Allows you to edit a users profile 19 * 20 * @copyright 2015 Shamim Rezaie http://foodle.org 21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 * @package core_user 23 */ 24 25 require_once('../config.php'); 26 require_once($CFG->dirroot.'/calendar/lib.php'); 27 require_once($CFG->dirroot.'/user/editlib.php'); 28 require_once($CFG->dirroot.'/user/lib.php'); 29 30 $userid = optional_param('id', $USER->id, PARAM_INT); // User id. 31 32 $PAGE->set_url('/user/calendar.php', array('id' => $userid)); 33 34 list($user, $course) = useredit_setup_preference_page($userid, SITEID); 35 36 $defaultlookahead = CALENDAR_DEFAULT_UPCOMING_LOOKAHEAD; 37 if (isset($CFG->calendar_lookahead)) { 38 $defaultlookahead = intval($CFG->calendar_lookahead); 39 } 40 $defaultmaxevents = CALENDAR_DEFAULT_UPCOMING_MAXEVENTS; 41 if (isset($CFG->calendar_maxevents)) { 42 $defaultmaxevents = intval($CFG->calendar_maxevents); 43 } 44 45 // Create form. 46 $calendarform = new core_user\form\calendar_form(null, array('userid' => $user->id)); 47 48 $user->timeformat = get_user_preferences('calendar_timeformat', ''); 49 $user->startwday = calendar_get_starting_weekday(); 50 $user->maxevents = get_user_preferences('calendar_maxevents', $defaultmaxevents); 51 $user->lookahead = get_user_preferences('calendar_lookahead', $defaultlookahead); 52 $user->persistflt = get_user_preferences('calendar_persistflt', 0); 53 $calendarform->set_data($user); 54 55 $redirect = new moodle_url("/user/preferences.php", array('userid' => $user->id)); 56 if ($calendarform->is_cancelled()) { 57 redirect($redirect); 58 } else if ($calendarform->is_submitted() && $calendarform->is_validated() && confirm_sesskey()) { 59 $data = $calendarform->get_data(); 60 61 $usernew = ['id' => $USER->id, 62 'preference_calendar_timeformat' => $data->timeformat, 63 'preference_calendar_startwday' => $data->startwday, 64 'preference_calendar_maxevents' => $data->maxevents, 65 'preference_calendar_lookahead' => $data->lookahead, 66 'preference_calendar_persistflt' => $data->persistflt 67 ]; 68 useredit_update_user_preference($usernew); 69 70 // Calendar type. 71 $calendartype = $data->calendartype; 72 // If the specified calendar type does not exist, use the site default. 73 if (!array_key_exists($calendartype, \core_calendar\type_factory::get_list_of_calendar_types())) { 74 $calendartype = $CFG->calendartype; 75 } 76 77 $user->calendartype = $calendartype; 78 // Update user with new calendar type. 79 user_update_user($user, false, false); 80 81 // Trigger event. 82 \core\event\user_updated::create_from_userid($user->id)->trigger(); 83 84 if ($USER->id == $user->id) { 85 $USER->calendartype = $calendartype; 86 } 87 88 redirect($redirect, get_string('changessaved'), null, \core\output\notification::NOTIFY_SUCCESS); 89 } 90 91 // Display page header. 92 $streditmycalendar = get_string('calendarpreferences', 'calendar'); 93 $userfullname = fullname($user, true); 94 95 $PAGE->navbar->includesettingsbase = true; 96 97 $PAGE->set_title("$course->shortname: $streditmycalendar"); 98 $PAGE->set_heading($userfullname); 99 100 echo $OUTPUT->header(); 101 echo $OUTPUT->heading($streditmycalendar); 102 103 // Finally display THE form. 104 $calendarform->display(); 105 106 // And proper footer. 107 echo $OUTPUT->footer();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body