shortname: $strcalendardstpresets", "$site->fullname", "$stradministration -> ". "$strconfiguration -> ". "$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()) && confirm_sesskey()) { if(isset($form->result_cancel)) { $mode = ''; } else if(isset($form->mode_return)) { redirect('calendar.php'); 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 'Proceed'; die(); } else { print_simple_box_start('center', '70%', '#cc0000'); echo '
'.get_string('therewereerrors', 'admin').':
'; echo '
'; print_simple_box_end(); } } // Show the edit screen $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') ); print_heading(get_string('editingdstpreset', 'admin')); print_simple_box_start('center', '70%'); include('./dst_edit.html'); print_simple_box_end(); break; } // Default behavior here if(empty($mode)) { $presets = get_records('dst_preset', '', '', 'name'); if(!empty($presets)) { $presetdescriptions = array(); foreach($presets as $id => $preset) { $presetdescriptions[$id] = calendar_human_readable_dst($preset); } } print_heading($strcalendardstpresets); print_simple_box_start('center', '70%'); include('./dst.html'); print_simple_box_end(); } print_footer(); ?>