D'oh - counting $totalcount wrongly (duplicate courses are ignored)
[moodle-linuxchix.git] / calendar / preferences.php
blobe168acf839353214ff1fd30b7c6467744ced7994
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);
17 /// If data submitted, then process and store.
19 if ($form = data_submitted()) {
20 foreach ($form as $preference => $value) {
21 switch ($preference) {
22 case 'timeformat':
23 if ($value != CALENDAR_TF_12 and $value != CALENDAR_TF_24) {
24 $value = '';
26 set_user_preference('calendar_timeformat', $value);
27 break;
28 case 'startwday':
29 $value = intval($value);
30 if ($value < 0 or $value > 6) {
31 $value = abs($value % 7);
33 set_user_preference('calendar_startwday', $value);
34 break;
35 case 'maxevents':
36 if (intval($value) >= 1) {
37 set_user_preference('calendar_maxevents', $value);
39 break;
40 case 'lookahead':
41 if (intval($value) >= 1) {
42 set_user_preference('calendar_lookahead', $value);
44 break;
45 case 'persistflt':
46 set_user_preference('calendar_persistflt', intval($value));
47 break;
50 redirect('view.php', get_string('changessaved'), 1);
51 exit;
54 $site = get_site();
56 $strcalendar = get_string('calendar', 'calendar');
57 $strpreferences = get_string('preferences', 'calendar');
59 if ($course->id != SITEID) {
60 $navigation = "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> ->
61 <a href=\"view.php\">$strcalendar</a> -> $strpreferences";
62 } else {
63 $navigation = "<a href=\"view.php\">$strcalendar</a> -> $strpreferences";
67 print_header("$site->shortname: $strcalendar: $strpreferences", $strcalendar, $navigation,
68 '', '', true, '', user_login_string($site));
71 print_heading($strpreferences);
73 print_simple_box_start("center");
75 $prefs->timeformat = get_user_preferences('calendar_timeformat', '');
76 $prefs->startwday = get_user_preferences('calendar_startwday', CALENDAR_STARTING_WEEKDAY);
77 $prefs->maxevents = get_user_preferences('calendar_maxevents', CALENDAR_UPCOMING_MAXEVENTS);
78 $prefs->lookahead = get_user_preferences('calendar_lookahead', CALENDAR_UPCOMING_DAYS);
79 $prefs->persistflt = get_user_preferences('calendar_persistflt', 0);
81 include('./preferences.html');
82 print_simple_box_end();
84 print_footer($course);