2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * Allows you to edit a users profile
20 * @copyright 2015 Shamim Rezaie http://foodle.org
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
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');
30 $userid = optional_param('id', $USER->id
, PARAM_INT
); // User id.
32 $PAGE->set_url('/user/calendar.php', array('id' => $userid));
34 list($user, $course) = useredit_setup_preference_page($userid, SITEID
);
36 $defaultlookahead = CALENDAR_DEFAULT_UPCOMING_LOOKAHEAD
;
37 if (isset($CFG->calendar_lookahead
)) {
38 $defaultlookahead = intval($CFG->calendar_lookahead
);
40 $defaultmaxevents = CALENDAR_DEFAULT_UPCOMING_MAXEVENTS
;
41 if (isset($CFG->calendar_maxevents
)) {
42 $defaultmaxevents = intval($CFG->calendar_maxevents
);
46 $calendarform = new core_user\form\
calendar_form(null, array('userid' => $user->id
));
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);
55 $redirect = new moodle_url("/user/preferences.php", array('userid' => $user->id
));
56 if ($calendarform->is_cancelled()) {
58 } else if ($calendarform->is_submitted() && $calendarform->is_validated() && confirm_sesskey()) {
59 $data = $calendarform->get_data();
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
68 useredit_update_user_preference($usernew);
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
;
77 $user->calendartype
= $calendartype;
78 // Update user with new calendar type.
79 user_update_user($user, false, false);
82 \core\event\user_updated
::create_from_userid($user->id
)->trigger();
84 if ($USER->id
== $user->id
) {
85 $USER->calendartype
= $calendartype;
88 redirect($redirect, get_string('changessaved'), null, \core\output\notification
::NOTIFY_SUCCESS
);
91 // Display page header.
92 $streditmycalendar = get_string('calendarpreferences', 'calendar');
93 $userfullname = fullname($user, true);
95 $PAGE->navbar
->includesettingsbase
= true;
97 $PAGE->set_title("$course->shortname: $streditmycalendar");
98 $PAGE->set_heading($userfullname);
100 echo $OUTPUT->header();
101 echo $OUTPUT->heading($streditmycalendar);
103 // Finally display THE form.
104 $calendarform->display();
106 // And proper footer.
107 echo $OUTPUT->footer();