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
)) {
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) {
25 if ($value != CALENDAR_TF_12
and $value != CALENDAR_TF_24
) {
28 set_user_preference('calendar_timeformat', $value);
31 $value = intval($value);
32 if ($value < 0 or $value > 6) {
33 $value = abs($value %
7);
35 set_user_preference('calendar_startwday', $value);
38 if (intval($value) >= 1) {
39 set_user_preference('calendar_maxevents', $value);
43 if (intval($value) >= 1) {
44 set_user_preference('calendar_lookahead', $value);
48 set_user_preference('calendar_persistflt', intval($value));
52 redirect('view.php', get_string('changessaved'), 1);
58 $strcalendar = get_string('calendar', 'calendar');
59 $strpreferences = get_string('preferences', 'calendar');
61 if ($course->id
!= SITEID
) {
62 $navigation = "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> ->
63 <a href=\"view.php\">$strcalendar</a> -> $strpreferences";
65 $navigation = "<a href=\"view.php\">$strcalendar</a> -> $strpreferences";
69 print_header("$site->shortname: $strcalendar: $strpreferences", $strcalendar, $navigation,
70 '', '', true, '', user_login_string($site));
73 print_heading($strpreferences);
75 print_simple_box_start("center");
77 $prefs->timeformat
= get_user_preferences('calendar_timeformat', '');
78 $prefs->startwday
= get_user_preferences('calendar_startwday', CALENDAR_STARTING_WEEKDAY
);
79 $prefs->maxevents
= get_user_preferences('calendar_maxevents', CALENDAR_UPCOMING_MAXEVENTS
);
80 $prefs->lookahead
= get_user_preferences('calendar_lookahead', CALENDAR_UPCOMING_DAYS
);
81 $prefs->persistflt
= get_user_preferences('calendar_persistflt', 0);
83 include('./preferences.html');
84 print_simple_box_end();
86 print_footer($course);