2009-09-29 02:51:00 +00:00
|
|
|
<?php
|
2004-03-29 15:28:15 +00:00
|
|
|
|
2009-09-29 02:51:00 +00:00
|
|
|
// preferences.php - user prefs for calendar
|
2004-03-29 15:28:15 +00:00
|
|
|
|
2009-09-29 02:51:00 +00:00
|
|
|
require_once('../config.php');
|
|
|
|
require_once($CFG->dirroot.'/calendar/lib.php');
|
2010-06-22 04:03:44 +00:00
|
|
|
require_once($CFG->dirroot.'/calendar/preferences_form.php');
|
2004-03-29 15:28:15 +00:00
|
|
|
|
2010-06-22 04:03:44 +00:00
|
|
|
$course = $site = get_site();
|
2010-07-16 08:57:44 +00:00
|
|
|
if (!empty($SESSION->cal_course_referer)) {
|
2010-06-22 04:03:44 +00:00
|
|
|
$course = $DB->get_record('course', array('id'=>$SESSION->cal_course_referer), '*', MUST_EXIST);
|
2009-09-29 02:51:00 +00:00
|
|
|
}
|
|
|
|
|
2010-01-16 15:39:56 +00:00
|
|
|
$PAGE->set_url('/calendar/preferences.php');
|
2009-09-29 02:51:00 +00:00
|
|
|
|
|
|
|
if ($course->id != SITEID) {
|
2010-06-22 04:03:44 +00:00
|
|
|
require_login($course);
|
|
|
|
} else {
|
|
|
|
require_login();
|
2010-08-04 07:37:02 +00:00
|
|
|
$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); //TODO: wrong
|
2009-09-29 02:51:00 +00:00
|
|
|
}
|
|
|
|
// Initialize the session variables
|
|
|
|
calendar_session_vars();
|
2007-08-16 15:01:25 +00:00
|
|
|
|
2010-06-22 04:03:44 +00:00
|
|
|
|
|
|
|
$prefs = new stdClass;
|
|
|
|
$prefs->timeformat = get_user_preferences('calendar_timeformat', '');
|
|
|
|
$prefs->startwday = get_user_preferences('calendar_startwday', calendar_get_starting_weekday());
|
|
|
|
$prefs->maxevents = get_user_preferences('calendar_maxevents', CALENDAR_UPCOMING_MAXEVENTS);
|
|
|
|
$prefs->lookahead = get_user_preferences('calendar_lookahead', CALENDAR_UPCOMING_DAYS);
|
|
|
|
$prefs->persistflt = get_user_preferences('calendar_persistflt', 0);
|
|
|
|
|
|
|
|
$form = new calendar_preferences_form();
|
|
|
|
$form->set_data($prefs);
|
|
|
|
|
|
|
|
if ($data = $form->get_data() && confirm_sesskey()) {
|
|
|
|
if ($data->timeformat != CALENDAR_TF_12 && $data->timeformat != CALENDAR_TF_24) {
|
|
|
|
$data->timeformat = '';
|
|
|
|
}
|
|
|
|
set_user_preference('calendar_timeformat', $data->timeformat);
|
|
|
|
|
|
|
|
$data->startwday = intval($data->startwday);
|
|
|
|
if ($data->startwday < 0 || $data->startwday > 6) {
|
|
|
|
$data->startwday = abs($data->startwday % 7);
|
|
|
|
}
|
|
|
|
set_user_preference('calendar_startwday', $data->startwday);
|
|
|
|
|
|
|
|
if (intval($data->maxevents) >= 1) {
|
|
|
|
set_user_preference('calendar_maxevents', $data->maxevents);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (intval($data->lookahead) >= 1) {
|
|
|
|
set_user_preference('calendar_lookahead', $data->lookahead);
|
2004-03-29 15:28:15 +00:00
|
|
|
}
|
2010-06-22 04:03:44 +00:00
|
|
|
|
|
|
|
set_user_preference('calendar_persistflt', intval($data->persistflt));
|
|
|
|
redirect(new moodle_url('/calendar/view.php', array('course'=>$course->id)), get_string('changessaved'), 1);
|
2009-09-29 02:51:00 +00:00
|
|
|
exit;
|
|
|
|
}
|
2004-03-29 15:28:15 +00:00
|
|
|
|
2009-09-29 02:51:00 +00:00
|
|
|
$strcalendar = get_string('calendar', 'calendar');
|
2010-06-22 04:03:44 +00:00
|
|
|
$strpreferences = get_string('calendarpreferences', 'calendar');
|
2004-03-29 15:28:15 +00:00
|
|
|
|
2010-01-16 15:39:56 +00:00
|
|
|
$PAGE->navbar->add($strpreferences, new moodle_url('/calendar/view.php'));
|
2010-06-22 04:03:44 +00:00
|
|
|
$PAGE->set_pagelayout('admin');
|
2009-09-29 02:51:00 +00:00
|
|
|
$PAGE->set_title("$site->shortname: $strcalendar: $strpreferences");
|
2010-05-27 09:33:46 +00:00
|
|
|
$PAGE->set_heading($COURSE->fullname);
|
2004-03-29 15:28:15 +00:00
|
|
|
|
2009-09-29 02:51:00 +00:00
|
|
|
echo $OUTPUT->header();
|
|
|
|
echo $OUTPUT->heading($strpreferences);
|
|
|
|
echo $OUTPUT->box_start('generalbox boxaligncenter');
|
2010-06-22 04:03:44 +00:00
|
|
|
$form->display();
|
2009-09-29 02:51:00 +00:00
|
|
|
echo $OUTPUT->box_end();
|
|
|
|
echo $OUTPUT->footer();
|