Merge branch 'MDL-43749' of git://github.com/timhunt/moodle
[moodle.git] / calendar / preferences.php
blobaeb502dadd97f9c9484f788e5635e3a0d336323d
1 <?php
3 // preferences.php - user prefs for calendar
5 require_once('../config.php');
6 require_once($CFG->dirroot.'/calendar/lib.php');
7 require_once($CFG->dirroot.'/calendar/preferences_form.php');
9 $courseid = required_param('course', PARAM_INT);
10 $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
12 $PAGE->set_url(new moodle_url('/calendar/preferences.php', array('course' => $courseid)));
13 $PAGE->set_pagelayout('standard');
15 require_login($course);
17 if ($courseid == SITEID) {
18 $viewurl = new moodle_url('/calendar/view.php', array('view' => 'month'));
19 } else {
20 $viewurl = new moodle_url('/calendar/view.php', array('view' => 'month', 'course' => $courseid));
22 navigation_node::override_active_url($viewurl);
24 $defaultlookahead = CALENDAR_DEFAULT_UPCOMING_LOOKAHEAD;
25 if (isset($CFG->calendar_lookahead)) {
26 $defaultlookahead = intval($CFG->calendar_lookahead);
28 $defaultmaxevents = CALENDAR_DEFAULT_UPCOMING_MAXEVENTS;
29 if (isset($CFG->calendar_maxevents)) {
30 $defaultmaxevents = intval($CFG->calendar_maxevents);
33 $prefs = new stdClass;
34 $prefs->timeformat = get_user_preferences('calendar_timeformat', '');
35 $prefs->startwday = calendar_get_starting_weekday();
36 $prefs->maxevents = get_user_preferences('calendar_maxevents', $defaultmaxevents);
37 $prefs->lookahead = get_user_preferences('calendar_lookahead', $defaultlookahead);
38 $prefs->persistflt = get_user_preferences('calendar_persistflt', 0);
40 $form = new calendar_preferences_form($PAGE->url);
41 $form->set_data($prefs);
43 if ($form->is_cancelled()) {
44 redirect($viewurl);
45 } else if ($form->is_submitted() && $form->is_validated() && confirm_sesskey()) {
46 $data = $form->get_data();
47 if ($data->timeformat != CALENDAR_TF_12 && $data->timeformat != CALENDAR_TF_24) {
48 $data->timeformat = '';
50 set_user_preference('calendar_timeformat', $data->timeformat);
52 $data->startwday = intval($data->startwday);
53 if ($data->startwday < 0 || $data->startwday > 6) {
54 $data->startwday = abs($data->startwday % 7);
56 set_user_preference('calendar_startwday', $data->startwday);
58 if (intval($data->maxevents) >= 1) {
59 set_user_preference('calendar_maxevents', $data->maxevents);
62 if (intval($data->lookahead) >= 1) {
63 set_user_preference('calendar_lookahead', $data->lookahead);
66 set_user_preference('calendar_persistflt', intval($data->persistflt));
67 redirect($viewurl, get_string('changessaved'), 1);
68 exit;
71 $strcalendar = get_string('calendar', 'calendar');
72 $strpreferences = get_string('calendarpreferences', 'calendar');
74 $PAGE->navbar->add($strpreferences);
75 $PAGE->set_pagelayout('admin');
76 $PAGE->set_title("$course->shortname: $strcalendar: $strpreferences");
77 $PAGE->set_heading($course->fullname);
79 echo $OUTPUT->header();
80 echo $OUTPUT->heading($strpreferences);
81 echo $OUTPUT->box_start('generalbox boxaligncenter');
82 $form->display();
83 echo $OUTPUT->box_end();
84 echo $OUTPUT->footer();