Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/calendar/preferences.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // preferences.php - user prefs for calendar
00004 
00005 require_once('../config.php');
00006 require_once($CFG->dirroot.'/calendar/lib.php');
00007 require_once($CFG->dirroot.'/calendar/preferences_form.php');
00008 
00009 $courseid = required_param('course', PARAM_INT);
00010 $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
00011 
00012 $PAGE->set_url(new moodle_url('/calendar/preferences.php', array('course' => $courseid)));
00013 $PAGE->set_pagelayout('standard');
00014 
00015 require_login($course);
00016 
00017 if ($courseid == SITEID) {
00018     $viewurl = new moodle_url('/calendar/view.php', array('view' => 'month'));
00019 } else {
00020     $viewurl = new moodle_url('/calendar/view.php', array('view' => 'month', 'course' => $courseid));
00021 }
00022 navigation_node::override_active_url($viewurl);
00023 
00024 $defaultlookahead = CALENDAR_DEFAULT_UPCOMING_LOOKAHEAD;
00025 if (isset($CFG->calendar_lookahead)) {
00026     $defaultlookahead = intval($CFG->calendar_lookahead);
00027 }
00028 $defaultmaxevents = CALENDAR_DEFAULT_UPCOMING_MAXEVENTS;
00029 if (isset($CFG->calendar_maxevents)) {
00030     $defaultmaxevents = intval($CFG->calendar_maxevents);
00031 }
00032 
00033 $prefs = new stdClass;
00034 $prefs->timeformat = get_user_preferences('calendar_timeformat', '');
00035 $prefs->startwday  = get_user_preferences('calendar_startwday', calendar_get_starting_weekday());
00036 $prefs->maxevents  = get_user_preferences('calendar_maxevents', $defaultmaxevents);
00037 $prefs->lookahead  = get_user_preferences('calendar_lookahead', $defaultlookahead);
00038 $prefs->persistflt = get_user_preferences('calendar_persistflt', 0);
00039 
00040 $form = new calendar_preferences_form($PAGE->url);
00041 $form->set_data($prefs);
00042 
00043 if ($form->is_cancelled()) {
00044     redirect($viewurl);
00045 } else if ($form->is_submitted() && $form->is_validated() && confirm_sesskey()) {
00046     $data = $form->get_data();
00047     if ($data->timeformat != CALENDAR_TF_12 && $data->timeformat != CALENDAR_TF_24) {
00048         $data->timeformat = '';
00049     }
00050     set_user_preference('calendar_timeformat', $data->timeformat);
00051 
00052     $data->startwday = intval($data->startwday);
00053     if ($data->startwday < 0 || $data->startwday > 6) {
00054         $data->startwday = abs($data->startwday % 7);
00055     }
00056     set_user_preference('calendar_startwday', $data->startwday);
00057 
00058     if (intval($data->maxevents) >= 1) {
00059         set_user_preference('calendar_maxevents', $data->maxevents);
00060     }
00061 
00062     if (intval($data->lookahead) >= 1) {
00063         set_user_preference('calendar_lookahead', $data->lookahead);
00064     }
00065 
00066     set_user_preference('calendar_persistflt', intval($data->persistflt));
00067     redirect($viewurl, get_string('changessaved'), 1);
00068     exit;
00069 }
00070 
00071 $strcalendar = get_string('calendar', 'calendar');
00072 $strpreferences = get_string('calendarpreferences', 'calendar');
00073 
00074 $PAGE->navbar->add($strpreferences);
00075 $PAGE->set_pagelayout('admin');
00076 $PAGE->set_title("$course->shortname: $strcalendar: $strpreferences");
00077 $PAGE->set_heading($course->fullname);
00078 
00079 echo $OUTPUT->header();
00080 echo $OUTPUT->heading($strpreferences);
00081 echo $OUTPUT->box_start('generalbox boxaligncenter');
00082 $form->display();
00083 echo $OUTPUT->box_end();
00084 echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations