diff --git a/admin/calendar.html b/admin/calendar.html new file mode 100644 index 00000000000..d1b83d651d8 --- /dev/null +++ b/admin/calendar.html @@ -0,0 +1,49 @@ + +
diff --git a/admin/calendar.php b/admin/calendar.php new file mode 100644 index 00000000000..69353561fa1 --- /dev/null +++ b/admin/calendar.php @@ -0,0 +1,69 @@ +shortname: $strcalendarsettings", "$site->fullname", + "$stradministration -> ". + "$strconfiguration -> $strcalendarsettings"); + + print_heading($strcalendarsettings); + + +/// If data submitted, process and store + + if(confirm_sesskey() && $form = data_submitted()) { + if(isset($form->mode_dst)) { + // Move to DST presets configuration + redirect('dst.php?sesskey='.$USER->sesskey); + die(); + } + // Normal configuration, just save the variables + if(isset($form->adminseesallcourses)) { + set_config('calendar_adminseesall', intval($form->adminseesallcourses) != 0); + unset($SESSION->cal_courses_shown); + } + if(isset($form->dstforusers)) { + if($form->dstforusers == 'force') { + $preset = optional_param('dstpreset', 0, PARAM_INT); + } + else { + $preset = 0; + } + set_config('calendar_dstforusers', $preset); + } + } + + $presets = get_records('dst_preset'); + if(!empty($presets)) { + foreach($presets as $id => $preset) { + $presets[$id] = $preset->name; + } + } + +/// Main display starts here + + print_simple_box_start('center', '100%', $THEME->cellheading); + include('./calendar.html'); + print_simple_box_end(); + + print_footer(); + +?> diff --git a/admin/configure.php b/admin/configure.php index 9c9011ee595..2f4f74ce6d3 100644 --- a/admin/configure.php +++ b/admin/configure.php @@ -43,6 +43,8 @@ $table->data[]= array("sesskey\">". get_string('editorsettings') ."", get_string('adminhelpeditorsettings')); + $table->data[]= array("sesskey\">". get_string('calendarsettings', 'admin') ."", + get_string('helpcalendarsettings', 'admin')); print_table($table); diff --git a/admin/dst.html b/admin/dst.html new file mode 100644 index 00000000000..db1d9dd4359 --- /dev/null +++ b/admin/dst.html @@ -0,0 +1,62 @@ + + diff --git a/admin/dst.php b/admin/dst.php new file mode 100644 index 00000000000..8e1b9de2ca1 --- /dev/null +++ b/admin/dst.php @@ -0,0 +1,243 @@ +shortname: $strcalendardstpresets", "$site->fullname", + "$stradministration -> ". + "$strconfiguration -> ". + "sesskey\">$strcalendarsettings -> $strcalendardstpresets"); + + $mode = ''; + $form = false; + + // $action may instruct us to do something first, then go on to display the preset list + $action = optional_param('action', ''); + + switch($action) { + case 'delete': + $presetid = optional_param('preset', 0, PARAM_INT); + $preset = get_record('dst_preset', 'id', $presetid); + if($preset !== false) { + // First delete the preset + delete_records('dst_preset', 'id', $presetid); + // And then disable DST for all users who had selected that preset + execute_sql('UPDATE '.$CFG->prefix.'user_preferences SET value = 0 WHERE name = \'calendar_dstpreset\' AND value = '.$presetid, false); + } + break; + } + + + // $mode, on the other hand, may make us do something INSTEAD of displaying the preset list + if($form = data_submitted()) { + if(isset($form->result_cancel)) { + $mode = ''; + } + else if(isset($form->mode_return)) { + redirect('calendar.php?sesskey='.$USER->sesskey); + die(); + } + else if(isset($form->mode_delete)) { + $mode = 'delete'; + } + else if(isset($form->mode_editform)) { + // Present add/edit form + $mode = 'edit'; + } + else if(isset($form->mode_edit)) { + // Fetch data for existing preset and display edit form + $presetid = optional_param('preset', 0, PARAM_INT); + $preset = get_record('dst_preset', 'id', $presetid); + if($preset !== false) { + // This variable used inside dst_edit.html + $weekdays = array( + -1 => get_string('day', 'calendar'), + 0 => get_string('sunday', 'calendar'), + 1 => get_string('monday', 'calendar'), + 2 => get_string('tuesday', 'calendar'), + 3 => get_string('wednesday', 'calendar'), + 4 => get_string('thursday', 'calendar'), + 5 => get_string('friday', 'calendar'), + 6 => get_string('saturday', 'calendar') + ); + + $preset->apply_offset_sign = ($preset->apply_offset >= 0 ? 1 : -1); + $preset->apply_offset = abs($preset->apply_offset); + list($preset->activate_hour, $preset->activate_minute) = explode(':', $preset->activate_time); + list($preset->deactivate_hour, $preset->deactivate_minute) = explode(':', $preset->deactivate_time); + $mode = 'continueedit'; + } + else { + $mode = ''; + } + } + else if(isset($form->mode_add)) { + // Move to adding a new dst + $preset = new stdClass; + $preset->id = 0; + $mode = 'add'; + } + // Normal configuration, just save the variables + else if(isset($form->adminseesallcourses)) { + set_config('calendar_adminseesall', intval($form->adminseesallcourses) != 0); + unset($SESSION->cal_courses_shown); + } + } + + switch($mode) { + case 'delete': + $presetid = optional_param('preset', 0, PARAM_INT); + $preset = get_record('dst_preset', 'id', $presetid); + if($preset !== false) { + print_heading(get_string('confirmation', 'admin')); + if(!empty($CFG->calendar_dstforusers) && $preset->id == $CFG->calendar_dstforusers) { + notice_yesno(get_string('confirmdeletedstdefault', 'admin', $preset->name), 'dst.php?action=delete&preset='.$presetid.'&sesskey='.$USER->sesskey, 'dst.php?sesskey='.$USER->sesskey); + } + else { + notice_yesno(get_string('confirmdeletedst', 'admin', $preset->name), 'dst.php?action=delete&preset='.$presetid.'&sesskey='.$USER->sesskey, 'dst.php?sesskey='.$USER->sesskey); + } + } + else { + $mode = ''; + } + break; + case 'edit': + // These variables are used inside dst_edit.html + $preset = new stdClass; + $preset->id = optional_param('preset', 0, PARAM_INT); + case 'add': + $preset->name = optional_param('name', get_string('dstdefaultpresetname', 'calendar')); + $preset->apply_offset = abs(optional_param('apply_offset', 60, PARAM_INT)); + $preset->apply_offset_sign = min(max(optional_param('apply_offset_sign', 1, PARAM_INT), -1), 1); + $preset->activate_index = min(max(optional_param('activate_index', 1, PARAM_INT), -1), 1); + $preset->activate_day = min(max(optional_param('activate_day', 0, PARAM_INT), -1), 6); + $preset->activate_month = min(max(optional_param('activate_month', 1, PARAM_INT), 1), 12); + $preset->activate_hour = min(max(optional_param('activate_hour', 3, PARAM_INT), 0), 23); + $preset->activate_minute = min(max(optional_param('activate_minute', 0, PARAM_INT), 0), 59); + $preset->deactivate_index = min(max(optional_param('deactivate_index', 1, PARAM_INT), -1), 1); + $preset->deactivate_day = min(max(optional_param('deactivate_day', 0, PARAM_INT), -1), 6); + $preset->deactivate_month = min(max(optional_param('deactivate_month', 2, PARAM_INT), 1), 12); + $preset->deactivate_hour = min(max(optional_param('deactivate_hour', 3, PARAM_INT), 0), 23); + $preset->deactivate_minute = min(max(optional_param('deactivate_minute', 0, PARAM_INT), 0), 59); + + $preset->apply_offset *= $preset->apply_offset_sign; + case 'continueedit': + if(!empty($form->result_ok)) { + // Complete the transaction + + // Validation here + $errors = array(); + if(empty($name)) { + $errors[] = get_string('errordstpresetnameempty', 'admin'); + } + else { + $other = get_record('dst_preset', 'name', $preset->name); + if($preset->id != $other->id) { + $errors[] = get_string('errordstpresetnameexists', 'admin'); + } + } + if($preset->activate_month >= $preset->deactivate_month) { + $errors[] = get_string('errordstpresetactivateearlier', 'admin'); + } + + // Are we error-free? + if(empty($errors)) { + // Calculate the last/next/current_offset variables + // WARNING: TODO: BUG: To calculate the timestamps, we are taking into account + // the admin's own DST setting. That means that if the admin changes his own DST + // setting and with this change his effective DST status changes, the timestamps + // will NOT be calculated correctly. Thus, the whole DST setting will be wrong + // for ALL USERS! + $preset = calendar_dst_update_preset($preset); + print_object("record is:"); + print_object($preset); + print_object('The last change time (DST) was: '.strftime('%A, %d %B %Y %H:%M', $preset->last_change)); + print_object('The last change time (user) was: '.userdate($preset->last_change)); + print_object('The next change time (DST) is : '.strftime('%A, %d %B %Y %H:%M', $preset->next_change)); + print_object('The next change time (user) is : '.userdate($preset->next_change)); + + // Write it! + if($preset->id) { + print_object("UPDATED!"); + update_record('dst_preset', $preset); + } + else { + print_object("INSERT!"); + insert_record('dst_preset', $preset); + } + echo '