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');
62 if ($course->id
!= SITEID
) {
63 $navlinks[] = array('name' => $course->shortname
,
64 'link' => "$CFG->wwwroot/course/view.php?id=$course->id",
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);