Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / calendar / preferences.php
blob98fd0912bbc3cc63e65cbeaf26e32999e8c7c641
1 <?PHP // $Id$
2 // preferences.php - user prefs for calendar
4 require_once('../config.php');
5 require_once($CFG->dirroot.'/calendar/lib.php');
7 if (isset($SESSION->cal_course_referer)) {
8 if (! $course = get_record('course', 'id', $SESSION->cal_course_referer)) {
9 $course = get_site();
13 if ($course->id != SITEID) {
14 require_login($course->id);
16 // Initialize the session variables
17 calendar_session_vars();
19 /// If data submitted, then process and store.
21 if ($form = data_submitted()) {
22 foreach ($form as $preference => $value) {
23 switch ($preference) {
24 case 'timeformat':
25 if ($value != CALENDAR_TF_12 and $value != CALENDAR_TF_24) {
26 $value = '';
28 set_user_preference('calendar_timeformat', $value);
29 break;
30 case 'startwday':
31 $value = intval($value);
32 if ($value < 0 or $value > 6) {
33 $value = abs($value % 7);
35 set_user_preference('calendar_startwday', $value);
36 break;
37 case 'maxevents':
38 if (intval($value) >= 1) {
39 set_user_preference('calendar_maxevents', $value);
41 break;
42 case 'lookahead':
43 if (intval($value) >= 1) {
44 set_user_preference('calendar_lookahead', $value);
46 break;
47 case 'persistflt':
48 set_user_preference('calendar_persistflt', intval($value));
49 break;
52 redirect('view.php?course='.$course->id, get_string('changessaved'), 1);
53 exit;
56 $site = get_site();
58 $strcalendar = get_string('calendar', 'calendar');
59 $strpreferences = get_string('preferences', 'calendar');
61 $navlinks = array();
62 if ($course->id != SITEID) {
63 $navlinks[] = array('name' => $course->shortname,
64 'link' => "$CFG->wwwroot/course/view.php?id=$course->id",
65 'type' => 'misc');
67 $navlinks[] = array('name' => $strpreferences, 'link' => 'view.php', 'type' => 'misc');
68 $navigation = build_navigation($navlinks);
70 print_header("$site->shortname: $strcalendar: $strpreferences", $strcalendar, $navigation,
71 '', '', true, '', user_login_string($site));
74 print_heading($strpreferences);
76 print_simple_box_start("center");
78 $prefs->timeformat = get_user_preferences('calendar_timeformat', '');
79 $prefs->startwday = get_user_preferences('calendar_startwday', CALENDAR_STARTING_WEEKDAY);
80 $prefs->maxevents = get_user_preferences('calendar_maxevents', CALENDAR_UPCOMING_MAXEVENTS);
81 $prefs->lookahead = get_user_preferences('calendar_lookahead', CALENDAR_UPCOMING_DAYS);
82 $prefs->persistflt = get_user_preferences('calendar_persistflt', 0);
84 include('./preferences.html');
85 print_simple_box_end();
87 print_footer($course);