[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/calendar/ -> preferences.php (source)

   1  <?php
   2  
   3  // preferences.php - user prefs for calendar
   4  
   5  require_once('../config.php');
   6  require_once($CFG->dirroot.'/calendar/lib.php');
   7  require_once($CFG->dirroot.'/calendar/preferences_form.php');
   8  
   9  $courseid = required_param('course', PARAM_INT);
  10  $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
  11  
  12  $PAGE->set_url(new moodle_url('/calendar/preferences.php', array('course' => $courseid)));
  13  $PAGE->set_pagelayout('standard');
  14  
  15  require_login($course);
  16  
  17  if ($courseid == SITEID) {
  18      $viewurl = new moodle_url('/calendar/view.php', array('view' => 'month'));
  19  } else {
  20      $viewurl = new moodle_url('/calendar/view.php', array('view' => 'month', 'course' => $courseid));
  21  }
  22  navigation_node::override_active_url($viewurl);
  23  
  24  $defaultlookahead = CALENDAR_DEFAULT_UPCOMING_LOOKAHEAD;
  25  if (isset($CFG->calendar_lookahead)) {
  26      $defaultlookahead = intval($CFG->calendar_lookahead);
  27  }
  28  $defaultmaxevents = CALENDAR_DEFAULT_UPCOMING_MAXEVENTS;
  29  if (isset($CFG->calendar_maxevents)) {
  30      $defaultmaxevents = intval($CFG->calendar_maxevents);
  31  }
  32  
  33  $prefs = new stdClass;
  34  $prefs->timeformat = get_user_preferences('calendar_timeformat', '');
  35  $prefs->startwday  = calendar_get_starting_weekday();
  36  $prefs->maxevents  = get_user_preferences('calendar_maxevents', $defaultmaxevents);
  37  $prefs->lookahead  = get_user_preferences('calendar_lookahead', $defaultlookahead);
  38  $prefs->persistflt = get_user_preferences('calendar_persistflt', 0);
  39  
  40  $form = new calendar_preferences_form($PAGE->url);
  41  $form->set_data($prefs);
  42  
  43  if ($form->is_cancelled()) {
  44      redirect($viewurl);
  45  } else if ($form->is_submitted() && $form->is_validated() && confirm_sesskey()) {
  46      $data = $form->get_data();
  47      if ($data->timeformat != CALENDAR_TF_12 && $data->timeformat != CALENDAR_TF_24) {
  48          $data->timeformat = '';
  49      }
  50      set_user_preference('calendar_timeformat', $data->timeformat);
  51  
  52      $data->startwday = intval($data->startwday);
  53      if ($data->startwday < 0 || $data->startwday > 6) {
  54          $data->startwday = abs($data->startwday % 7);
  55      }
  56      set_user_preference('calendar_startwday', $data->startwday);
  57  
  58      if (intval($data->maxevents) >= 1) {
  59          set_user_preference('calendar_maxevents', $data->maxevents);
  60      }
  61  
  62      if (intval($data->lookahead) >= 1) {
  63          set_user_preference('calendar_lookahead', $data->lookahead);
  64      }
  65  
  66      set_user_preference('calendar_persistflt', intval($data->persistflt));
  67      redirect($viewurl, get_string('changessaved'), 1);
  68      exit;
  69  }
  70  
  71  $strcalendar = get_string('calendar', 'calendar');
  72  $strpreferences = get_string('calendarpreferences', 'calendar');
  73  
  74  $PAGE->navbar->add($strpreferences);
  75  $PAGE->set_pagelayout('admin');
  76  $PAGE->set_title("$course->shortname: $strcalendar: $strpreferences");
  77  $PAGE->set_heading($course->fullname);
  78  
  79  echo $OUTPUT->header();
  80  echo $OUTPUT->heading($strpreferences);
  81  echo $OUTPUT->box_start('generalbox boxaligncenter');
  82  $form->display();
  83  echo $OUTPUT->box_end();
  84  echo $OUTPUT->footer();


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1