]> git.mjollnir.org Git - moodle.git/commitdiff
New "Calendar" section in Admin -> Configuration.
authordefacer <defacer>
Wed, 15 Dec 2004 07:14:41 +0000 (07:14 +0000)
committerdefacer <defacer>
Wed, 15 Dec 2004 07:14:41 +0000 (07:14 +0000)
Includes preliminary support for DST!
Includes "admin sees all events or only own?" setting (bug 1972)

WARNING: Modified moodlelib.php to explicitly specify NOT-DST when
calling mktime() and gmmktime(). This is essential since we don't want
PHP to second-guess us for the DST matters, but... it may affect existing
code?

16 files changed:
admin/calendar.html [new file with mode: 0644]
admin/calendar.php [new file with mode: 0644]
admin/configure.php
admin/dst.html [new file with mode: 0644]
admin/dst.php [new file with mode: 0644]
admin/dst_edit.html [new file with mode: 0644]
admin/index.php
calendar/lib.php
calendar/preferences.html
calendar/preferences.php
lang/en/admin.php
lang/en/calendar.php
lib/db/mysql.php
lib/moodlelib.php
theme/standard/styles.php
version.php

diff --git a/admin/calendar.html b/admin/calendar.html
new file mode 100644 (file)
index 0000000..d1b83d6
--- /dev/null
@@ -0,0 +1,49 @@
+
+<form method="post" action="calendar.php">
+<p><input type="hidden" name="sesskey" value="<?php echo $USER->sesskey ?>"></p>
+
+<div style="text-align: center;">
+<table style="margin: auto; border: none; width: 90%;" class="formtable">
+  <tbody>
+    <tr>
+      <th>adminseesall:</th>
+      <td>
+        <select name="adminseesallcourses">
+          <option value="0" <?php if(empty($CFG->calendar_adminseesall)) echo "selected='selected'"; ?>><?php print_string('adminseesownevents', 'admin'); ?></option>
+          <option value="1" <?php if(!empty($CFG->calendar_adminseesall)) echo "selected='selected'"; ?>><?php print_string('adminseesallevents', 'admin'); ?></option>
+        </select>
+      </td>
+      <td><?php print_string('helpadminseesall', 'admin'); ?></td>
+    </tr>
+    <tr>
+      <th>dstforusers:</th>
+      <td>
+        <?php if(empty($presets)) { print_string('nodstpresetsexist', 'admin'); } else { ?>
+        <div>
+          <nobr>
+          <input type="radio" id="dstradio1" name="dstforusers" value="preference" <?php if(empty($CFG->calendar_dstforusers)) echo 'checked="checked"';?> /> <label for="dstradio1"><?php print_string('dstisapreference', 'admin'); ?></label>
+          </nobr>
+        </div>
+        <div>
+          <nobr><input type="radio" id="dstradio2" name="dstforusers" value="force" <?php if(!empty($CFG->calendar_dstforusers)) echo 'checked="checked"';?> /> <label for="dstradio2"><?php print_string('dstisforcedto', 'admin'); ?></label>
+          <?php choose_from_menu($presets, 'dstpreset', (empty($CFG->calendar_dstforusers) ? 0 : $CFG->calendar_dstforusers), get_string('choose').'...', 'form.dstradio2.checked=\'checked\''); ?>
+          </nobr>
+        </div>
+        <?php } ?>
+      </td>
+      <td><?php print_string('helpdstforusers', 'admin'); ?></td>
+    </tr>
+    <tr>
+      <th>managedstpresets:</th>
+      <td>
+        <input type="submit" name="mode_dst" value="<?php print_string('managedstpresets', 'admin'); ?>..." />
+      </td>
+      <td><?php print_string('helpmanagedstpresets', 'admin'); ?></td>
+    </tr>
+  </tbody>
+</table>
+
+  <input type="submit" value="<?php print_string('savechanges'); ?>" />
+</div>
+
+</form>
diff --git a/admin/calendar.php b/admin/calendar.php
new file mode 100644 (file)
index 0000000..6935356
--- /dev/null
@@ -0,0 +1,69 @@
+<?PHP // $Id$
+
+    // Allows the admin to configure calendar and date/time stuff
+
+    require_once('../config.php');
+
+    require_login();
+
+    if (!isadmin()) {
+        error('Only administrators can use this page!');
+    }
+
+    if (!$site = get_site()) {
+        error('Site isn\'t defined!');
+    }
+
+/// Print headings
+
+    $stradministration = get_string('administration');
+    $strconfiguration = get_string('configuration');
+    $strcalendarsettings = get_string('calendarsettings', 'admin');
+
+    print_header("$site->shortname: $strcalendarsettings", "$site->fullname",
+                 "<a href=\"index.php\">$stradministration</a> -> ".
+                 "<a href=\"configure.php\">$strconfiguration</a> -> $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();
+
+?>
index 9c9011ee595b3633dc298acab5332ca80723dc73..2f4f74ce6d35ded716aa5e2700cfad7be069cda6 100644 (file)
@@ -43,6 +43,8 @@
 
     $table->data[]= array("<strong><a href=\"editor.php?sesskey=$USER->sesskey\">". get_string('editorsettings') ."</a></strong>",
                     get_string('adminhelpeditorsettings'));
+    $table->data[]= array("<strong><a href=\"calendar.php?sesskey=$USER->sesskey\">". get_string('calendarsettings', 'admin') ."</a></strong>",
+                    get_string('helpcalendarsettings', 'admin'));
 
     print_table($table);
     
diff --git a/admin/dst.html b/admin/dst.html
new file mode 100644 (file)
index 0000000..db1d9dd
--- /dev/null
@@ -0,0 +1,62 @@
+<form method="post" action="dst.php">
+<p><input type="hidden" name="sesskey" value="<?php echo $USER->sesskey ?>"></p>
+
+<div style="text-align: center;">
+<table style="margin: auto; width: 100%;" cellpadding="5" cellspacing="0">
+  <tbody>
+    <tr>
+      <td style="vertical-align: top; width: 40%;">
+        <div style="text-align: center;">
+        <?php if (!empty($presets)) {
+            echo '<select style="width: 100%;" id="dstselectmenu" size="10" name="preset" onclick="showdstinfo();">';
+            foreach($presets as $id => $preset) {
+                echo '<option value="'.$id.'">'.$preset->name.'</option>';
+            }
+            echo '</select>';
+         }
+         else {
+            echo get_string('emptydstlist', 'admin');
+         }
+        ?>
+        </div>
+      </td>
+      <td style="vertical-align: middle;">
+        <div id="dstdisplayboard" style="display: none; margin: 1em; padding: 5px; border: 1px black solid; text-align: center; background-color: <?php echo $THEME->cellcontent; ?>; -moz-border-radius: 4px;"> </div>
+        <div style="text-align: center; margin: 1em;">
+          <input type="submit" name="mode_add" value="<?php print_string('add'); ?>..." />
+          <input type="submit" name="mode_edit" value="<?php print_string('edit'); ?>" <?php if(empty($presets)) echo 'disabled="disabled"';?> />
+          <input type="submit" name="mode_delete" value="<?php print_string('delete'); ?>" <?php if(empty($presets)) echo 'disabled="disabled"';?> />
+        </div>
+      </td>
+    </tr>
+  </tbody>
+</table>
+</div>
+
+</form>
+<script type="text/javascript">
+<!--
+    var DSTPresetInfo = new Array();
+    <?php
+        foreach($presetdescriptions as $id => $desc) {
+            echo 'DSTPresetInfo['.$id.'] = "'.$desc.'";';
+        }
+    ?>
+
+    function showdstinfo() {
+        var board  = document.getElementById('dstdisplayboard');
+        var select = document.getElementById('dstselectmenu');
+        if(board && select) {
+            var index = select.selectedIndex;
+            if(index == -1 && select.options.length >= 1) {
+                select.selectedIndex = index = 0;
+            }
+            board.firstChild.nodeValue = window.DSTPresetInfo[select.options[index].value];
+            board.style.display = 'block';
+        }
+        return true;
+    }
+
+    showdstinfo();
+-->
+</script>
diff --git a/admin/dst.php b/admin/dst.php
new file mode 100644 (file)
index 0000000..8e1b9de
--- /dev/null
@@ -0,0 +1,243 @@
+<?PHP // $Id$
+
+    // Allows the admin to configure DST presets
+
+    require_once('../config.php');
+
+    require_login();
+
+    if (!isadmin()) {
+        error('Only administrators can use this page!');
+    }
+
+    if (!$site = get_site()) {
+        error('Site isn\'t defined!');
+    }
+
+    confirm_sesskey();
+
+    include_once('../calendar/lib.php');
+
+/// Print headings
+
+    $stradministration = get_string('administration');
+    $strconfiguration = get_string('configuration');
+    $strcalendarsettings = get_string('calendarsettings', 'admin');
+    $strcalendardstpresets = get_string('dstpresets', 'admin');
+
+    print_header("$site->shortname: $strcalendardstpresets", "$site->fullname",
+                 "<a href=\"index.php\">$stradministration</a> -> ".
+                 "<a href=\"configure.php\">$strconfiguration</a> -> ".
+                 "<a href=\"calendar.php?sesskey=$USER->sesskey\">$strcalendarsettings</a> -> $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&amp;preset='.$presetid.'&amp;sesskey='.$USER->sesskey, 'dst.php?sesskey='.$USER->sesskey);
+                }
+                else {
+                    notice_yesno(get_string('confirmdeletedst', 'admin', $preset->name), 'dst.php?action=delete&amp;preset='.$presetid.'&amp;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 '<a href="dst.php?sesskey='.$USER->sesskey.'>Proceed</a>';
+                    die();
+                }
+                else {
+                    print_simple_box_start('center', '70%', '#cc0000');
+                    echo '<div style="color: #fff;"><div style="font-weight: bold; text-align: center;">'.get_string('therewereerrors', 'admin').':</div>';
+                    echo '<ul>';
+                    foreach($errors as $error) {
+                        echo '<li>'.$error.'</li>';
+                    }
+                    echo '</ul></div>';
+                    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%', $THEME->cellheading);
+            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%', $THEME->cellheading);
+        include('./dst.html');
+        print_simple_box_end();
+    }
+
+    print_footer();
+
+?>
diff --git a/admin/dst_edit.html b/admin/dst_edit.html
new file mode 100644 (file)
index 0000000..1ec12d5
--- /dev/null
@@ -0,0 +1,66 @@
+<form method="post" action="dst.php">
+<p>
+  <input type="hidden" name="sesskey" value="<?php echo $USER->sesskey ?>" />
+  <input type="hidden" name="mode_editform" value="mode_editform" />
+  <input type="hidden" name="preset" value="<?php echo $preset->id ?>" />
+</p>
+
+<div style="text-align: center;">
+<table style="margin: auto;" class="formtable">
+  <tbody>
+    <tr>
+      <th>
+        <?php print_string('dstpresetname', 'calendar'); ?>
+      </th>
+      <td style="vertical-align: top;">
+        <input type="text" name="name" value="<?php print $preset->name; ?>" size="50" />
+      </td>
+    </tr>
+    <tr>
+      <th>
+        <?php print_string('dstpresetactivated', 'calendar'); ?>
+      </th>
+      <td style="vertical-align: top;">
+        <?php print_string('dstonthe', 'calendar'); ?>
+        <?php choose_from_menu(array('1' => get_string('first', 'calendar'), '-1' => get_string('last', 'calendar')), 'activate_index', $preset->activate_index, ''); ?>
+        <?php choose_from_menu($weekdays, 'activate_day', $preset->activate_day, ''); ?>
+        <?php print_string('dstof', 'calendar'); echo ' '; calendar_print_month_selector('activate_month', $preset->activate_month); ?>
+        <?php print_string('dstat', 'calendar'); echo ' '; print_time_selector('activate_hour', 'activate_minute', make_timestamp(2000, 1, 1, $preset->activate_hour, $preset->activate_minute), 30); ?>
+        <?php $preset->activate_hour; ?>
+      </td>
+    </tr>
+    <tr>
+      <th>
+        <?php print_string('dstpresetadjusttime', 'calendar'); ?>
+      </th>
+      <td style="vertical-align: top;">
+        <?php print_string('dstadjusttime', 'calendar'); ?>
+        <?php choose_from_menu(array('1' => get_string('timeforward', 'calendar'), '-1' => get_string('timerewind', 'calendar')), 'apply_offset_sign', $preset->apply_offset_sign, ''); ?>
+        <?php print_string('dstby', 'calendar'); ?>
+        <input type="text" name="apply_offset" value="<?php echo $preset->apply_offset; ?>" size="3" />
+        <?php print_string('mins'); ?>
+      </td>
+    </tr>
+    <tr>
+      <th>
+        <?php print_string('dstpresetdeactivated', 'calendar'); ?>
+      </th>
+      <td style="vertical-align: top;">
+        <?php print_string('dstonthe', 'calendar'); ?>
+        <?php choose_from_menu(array('1' => get_string('first', 'calendar'), '-1' => get_string('last', 'calendar')), 'deactivate_index', $preset->deactivate_index, ''); ?>
+        <?php choose_from_menu($weekdays, 'deactivate_day', $preset->deactivate_day, ''); ?>
+        <?php print_string('dstof', 'calendar'); echo ' '; calendar_print_month_selector('deactivate_month', $preset->deactivate_month); ?>
+        <?php print_string('dstat', 'calendar'); echo ' '; print_time_selector('deactivate_hour', 'deactivate_minute', make_timestamp(2000, 1, 1, $preset->deactivate_hour, $preset->deactivate_minute), 30); ?>
+      </td>
+    </tr>
+  </tbody>
+</table>
+
+<div style="margin: 1em;">
+  <input type="submit" name="result_ok" value="<?php print_string('ok'); ?>" />
+  <input type="submit" name="result_cancel" value="<?php print_string('cancel'); ?>" />
+</div>
+
+</div>
+
+</form>
index 25d618c7852b9a3442e9ad4b884b55decb3b4191..46a9f67fb8ee6f931ec31628df311d2d8b391332 100644 (file)
     }
     $configdata .= "<font size=+1>&nbsp;</font><a href=\"editor.php?sesskey=$USER->sesskey\">". get_string("editorsettings") ."</a> - <font size=\"1\">".
                     get_string("adminhelpeditorsettings")."</font><br />";
+    $configdata .= "<font size=+1>&nbsp;</font><a href=\"calendar.php?sesskey=$USER->sesskey\">". get_string('calendarsettings', 'admin') ."</a> - <font size=\"1\">".
+                    get_string('helpcalendarsettings', 'admin')."</font><br />";
 
     $table->data[] = array("<font size=+1><b><a href=\"configure.php\">".get_string("configuration")."</a></b>", 
                             $configdata);
index 3813f675178332c7b1348b3d7e2134f6e20d90b5..c74a5e701515e6def8e8783732b152f147d395bf 100644 (file)
@@ -1059,8 +1059,10 @@ function calendar_get_default_courses($ignoreref = false) {
 
     $courses = array();
     if(!empty($USER->id) && isadmin($USER->id)) {
-        $courses = get_records_sql('SELECT id, 1 FROM '.$CFG->prefix.'course');
-        return $courses;
+        if(!empty($CFG->calendar_adminseesall)) {
+            $courses = get_records_sql('SELECT id, 1 FROM '.$CFG->prefix.'course');
+            return $courses;
+        }
     }
     if(isset($USER->student) && is_array($USER->student)) {
         $courses = $USER->student;
@@ -1073,9 +1075,10 @@ function calendar_get_default_courses($ignoreref = false) {
 
 function calendar_preferences_array() {
     return array(
-        'startwday' => get_string('pref_startwday', 'calendar'),
-        'maxevents' => get_string('pref_maxevents', 'calendar'),
-        'lookahead' => get_string('pref_lookahead', 'calendar'),
+        'dstpreset'  => get_string('pref_dstpreset', 'calendar'),
+        'startwday'  => get_string('pref_startwday', 'calendar'),
+        'maxevents'  => get_string('pref_maxevents', 'calendar'),
+        'lookahead'  => get_string('pref_lookahead', 'calendar'),
         'timeformat' => get_string('pref_timeformat', 'calendar'),
     );
 }
@@ -1155,4 +1158,120 @@ function calendar_format_event_time($event, $now, $morehref, $usecommonwords = t
     return $eventtime;
 }
 
+function calendar_human_readable_dst($preset) {
+    $weekdays = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday');
+
+    $options = new stdClass;
+    $options->activate_index     = ($preset->activate_index == -1) ? get_string('last', 'calendar') : get_string('nth', 'calendar', $preset->activate_index);
+    $options->activate_weekday   = ($preset->activate_day < 0) ? get_string('day', 'calendar') : get_string($weekdays[$preset->activate_day], 'calendar');
+    $options->activate_month     = date('F', mktime(0, 0, 0, $preset->activate_month, 1, 2000));
+    $options->offset             = abs($preset->apply_offset);
+    $options->direction          = $preset->apply_offset > 0 ? get_string('timeforward', 'calendar') : get_string('timerewind', 'calendar');
+    $options->deactivate_index   = ($preset->deactivate_index == -1) ? get_string('last', 'calendar') : get_string('nth', 'calendar', $preset->deactivate_index);
+    $options->deactivate_weekday = ($preset->deactivate_day < 0) ? get_string('day', 'calendar') : get_string($weekdays[$preset->deactivate_day], 'calendar');
+    $options->deactivate_month   = date('F', mktime(0, 0, 0, $preset->deactivate_month, 1, 2000));
+
+    return get_string('dsthumanreadable', 'calendar', $options);
+    //print_string('dstonthe', 'calendar')
+    //return 'ID '.$preset->id.': DST is activated on the X of X.';
+}
+
+// "Find the ($index as int, 1st, 2nd, etc, -1 = last) ($weekday as int, sunday = 0) in ($month) of ($year)"
+function calendar_find_day_in_month($index, $weekday, $month, $year) {
+    if($weekday == -1) {
+        // Any day of the week will do
+        if($index == -1) {
+            // Last day of that month
+            $targetday = calendar_days_in_month($month, $year);
+        }
+        else {
+            // Not last day; a straight index value
+            $targetday = $index;
+        }
+    }
+    else {
+        // We need to calculate when exactly that weekday is
+        // Fist of all, what day of the week is the first of that month?
+
+        // Convert to timestamp and back to readable representation using the server's timezone;
+        // this should be correct regardless of what the user's timezone is.
+        $firstmonthweekday = strftime('%w', mktime(0, 0, 0, $month, 1, $year));
+//PJ        print_object('The first of '.$month.'/'.$year.' is '.$firstmonthweekday);
+        $daysinmonth       = calendar_days_in_month($month, $year);
+
+        // This is the first such-named weekday of the month
+        $targetday = 1 + $weekday - $firstmonthweekday;
+        if($targetday <= 0) {
+            $targetday += 7;
+        }
+//PJ        print_object('The FIRST SPECIFIC '.$weekday.' of '.$month.'/'.$year.' is on '.$targetday);
+
+        if($index == -1) {
+            // To find the LAST such weekday, just keep adding 7 days at a time
+            while($targetday + 7 <= $daysinmonth) {
+                $targetday += 7;
+            }
+//PJ            print_object('The LAST SPECIFIC '.$weekday.' of '.$month.'/'.$year.' is on '.$targetday);
+        }
+        else {
+            // For a specific week, add as many weeks as required
+            $targetday += $index > 1 ? ($index - 1) * 7 : 0;
+        }
+    }
+
+    return $targetday;
+}
+
+function calendar_dst_update_preset($dstpreset) {
+    $now  = time();
+
+    // What's the date according to our user right now?
+    $date = usergetdate($now);
+
+    $monthdayactivate   = calendar_find_day_in_month($dstpreset->activate_index, $dstpreset->activate_day, $dstpreset->activate_month, $date['year']);
+    $monthdaydeactivate = calendar_find_day_in_month($dstpreset->deactivate_index, $dstpreset->deactivate_day, $dstpreset->deactivate_month, $date['year']);
+
+    $timeactivate   = make_timestamp($date['year'], $dstpreset->activate_month, $monthdayactivate, $dstpreset->activate_hour, $dstpreset->activate_minute);
+    $timedeactivate = make_timestamp($date['year'], $dstpreset->deactivate_month, $monthdaydeactivate, $dstpreset->deactivate_hour, $dstpreset->deactivate_minute);
+
+    // Great... let's see where exactly we are now.
+    if($now < $timeactivate) {
+        print_object("<<");
+        // DST has not been turned on this year
+        $dstpreset->next_change = $timeactivate;
+        // For the last change, we need to fetch the previous year's DST deactivation timestamp
+        $monthdaydeactivate  = calendar_find_day_in_month($dstpreset->deactivate_index, $dstpreset->deactivate_day, $dstpreset->deactivate_month, $date['year'] - 1);
+        $timedeactivate      = make_timestamp($date['year'] - 1, $dstpreset->deactivate_month, $monthdaydeactivate, $dstpreset->deactivate_hour, $dstpreset->deactivate_minute);
+        $dstpreset->last_change = $timedeactivate;
+    }
+    else if($now < $timedeactivate) {
+        print_object("<>");
+        // DST is on for this year right now
+        $dstpreset->last_change = $timeactivate;
+        $dstpreset->next_change = $timedeactivate;
+    }
+    else {
+        print_object(">>");
+        // DST has already been turned off; we are nearing the end of the year
+        $dstpreset->last_change = $timedeactivate;
+        // For the next change, we need to fetch next year's DST activation timestamp
+        $monthdayactivate    = calendar_find_day_in_month($dstpreset->activate_index, $dstpreset->activate_day, $dstpreset->activate_month, $date['year'] + 1);
+        $timeactivate        = make_timestamp($date['year'] + 1, $dstpreset->activate_month, $monthdayactivate, $dstpreset->activate_hour, $dstpreset->activate_minute);
+        $dstpreset->next_change = $timeactivate;
+    }
+
+    return $dstpreset;
+}
+
+function calendar_print_month_selector($name, $selected) {
+    
+    $months = array();
+
+    for ($i=1; $i<=12; $i++) {
+        $months[$i] = userdate(gmmktime(12, 0, 0, $i, 1, 2000), '%B');
+    }
+
+    choose_from_menu($months, $name, $selected, '');
+}
+
 ?>
index 1dfc6c038972f4456d8aa08313316a47a58ff8a4..f0bb8e4fc647b3e7e2da65697d7dfba734f9a497 100644 (file)
@@ -1,6 +1,38 @@
 <form method="post" action="preferences.php" name="form">
 
 <table cellpadding="9" cellspacing="0">
+<tr valign="top">
+       <td nowrap="nowrap" align="right"><?php print_string('pref_dstpreset', 'calendar')?>:</td>
+       <td>
+    <?php
+        if(empty($CFG->calendar_dstforusers)) {
+            $presets = get_records('dst_preset');
+            $presetarray = array('0' => get_string('notusingdst', 'calendar'));
+            if(!empty($presets)) {
+                foreach($presets as $preset) {
+                    $presetarray[$preset->id] = $preset->name;
+                }
+            }
+            choose_from_menu ($presetarray, 'dstpreset', $prefs->dstpreset, '');
+        }
+        else {
+            $preset = get_record('dst_preset', 'id', $CFG->calendar_dstforusers);
+            echo '<strong>'.$preset->name.'</strong>';
+        }
+    ?>
+    </td>
+    <td>
+    <?php
+        if(empty($CFG->calendar_dstforusers)) {
+            print_string('explain_dstpreset', 'calendar');
+        }
+        else {
+            print_string('explain_dstpresetforced', 'calendar');
+        }
+    ?>
+    </td>
+</tr>
+
 <tr valign="top">
        <td nowrap="nowrap" align="right"><?php print_string('pref_timeformat', 'calendar')?>:</td>
        <td>
index dc082ce54e8b775b9fbc2569e90d16c1677ad8dd..a44a1e9ebac78f23be50511c0dd00ccaded5afa5 100644 (file)
         print_header();
         foreach ($form as $preference => $value) {
             switch ($preference) {
+                case 'dstpreset':
+                    $value = intval($value);
+                    if($value == 0 || get_record('dst_preset', 'id', $value)) {
+                        set_user_preference('calendar_dstpreset', $value);
+                    }
+                break;
                 case 'timeformat':
                     if ($value != CALENDAR_TF_12 and $value != CALENDAR_TF_24) {
                         $value = '';
 
     print_simple_box_start("center", "", "$THEME->cellheading");
 
+    $prefs->dstpreset  = get_user_preferences('calendar_dstpreset', 0);
     $prefs->timeformat = get_user_preferences('calendar_timeformat', '');
-    $prefs->startwday = get_user_preferences('calendar_startwday', CALENDAR_STARTING_WEEKDAY);
-    $prefs->maxevents = get_user_preferences('calendar_maxevents', CALENDAR_UPCOMING_MAXEVENTS);
-    $prefs->lookahead = get_user_preferences('calendar_lookahead', CALENDAR_UPCOMING_DAYS);
+    $prefs->startwday  = get_user_preferences('calendar_startwday', CALENDAR_STARTING_WEEKDAY);
+    $prefs->maxevents  = get_user_preferences('calendar_maxevents', CALENDAR_UPCOMING_MAXEVENTS);
+    $prefs->lookahead  = get_user_preferences('calendar_lookahead', CALENDAR_UPCOMING_DAYS);
 
-       include("preferences.html");
+       include('./preferences.html');
     print_simple_box_end();
 
     print_footer($course);
index e53937efbfb2031d80e4963d36d8f60acfe6c874..6f672f5a7629487f01175442c1e053ea84a95cad 100755 (executable)
@@ -1,12 +1,32 @@
 <?php // $Id$
       // admin.php - created with Moodle 1.2 development (2003111400)
 
-
+$string['adminseesallevents'] = 'Administrators see all events';
+$string['adminseesownevents'] = 'Administrators are just like other users';
 $string['blockinstances'] = 'Instances';
 $string['blockmultiple'] = 'Multiple';
 $string['change'] = 'change';
 $string['cachetext'] = 'Text cache lifetime';
+$string['calendarsettings'] = 'Calendar';
+$string['confirmation'] = 'Confirmation';
+$string['confirmdeletedst'] = 'Deleting the preset named <strong>$a</strong> will immediately disable DST for all users of that preset. This could possibly change their perception of time without warning. Are you sure you want to continue?';
+$string['confirmdeletedstdefault'] = '<strong>The preset named $a is being used for all users of this site!</strong> Deleting it will change their perception of time without warning. Are you sure you want to continue?';
+$string['dstisapreference'] = 'Each user can choose which preset to use';
+$string['dstisforcedto'] = 'Force all users to use';
+$string['dstpresets'] = 'DST Presets';
+$string['emptydstlist'] = 'There are currently no DST presets defined. You can add one by clicking on the Add button.';
+$string['editingdstpreset'] = 'Editing a DST preset';
+$string['errordstpresetactivateearlier'] = 'The month of activation must be earlier than the month of deactivation';
+$string['errordstpresetnameempty'] = 'The preset name cannot be empty';
+$string['errordstpresetnameexists'] = 'Another preset with that name already exists';
 $string['filteruploadedfiles'] = 'Filter uploaded files';
+$string['helpadminseesall'] = 'Do admins see all calendar events or just those that apply to themselves?';
+$string['helpcalendarsettings'] = 'Configure various calendar and date/time-related aspects of Moodle';
+$string['helpdstforusers'] = 'Can each user choose his own DST settings?';
+$string['helpmanagedstpresets'] = 'Click this button to add, edit and delete the DST presets available for this site.';
+$string['managedstpresets'] = 'Manage DST Presets';
+$string['nodstpresetsexist'] = 'DST support is disabled for all users because there are no DST presets defined. You can define some presets using the button below.';
+$string['therewereerrors'] = 'There were errors in your data';
 $string['upgradelogs'] = 'For full functionality, your old logs need to be upgraded.  <a href=\"$a\">More information</a>';
 $string['upgradelogsinfo'] = 'Some changes have recently been made in the way logs are stored.  To be able to view all of your old logs on a per-activity basis, your old logs need to be upgraded.  Depending on your site this can take a long time (eg several hours) and can be quite taxing on the database for large sites.  Once you start this process you should let it finish (by keeping the browser window open).  Don\'t worry - your site will work fine for other people while the logs are being upgraded.<br /><br />Do you want to upgrade your logs now?';
 
index cc4f3a25622c6ad17211fa773709f9f7a1b9d542..1d3076a0eaa1ada9cfac76e14ce4e28add1eef00 100644 (file)
@@ -95,4 +95,26 @@ $string['thursday'] = 'Thursday';
 $string['friday'] = 'Friday';
 $string['saturday'] = 'Saturday';
 
+$string['pref_dstpreset'] = 'Daylight Savings Time';
+$string['notusingdst'] = 'Not using DST';
+$string['dstpresetname'] = 'Preset name';
+$string['dstpresetactivated'] = 'Activation';
+$string['dstpresetdeactivated'] = 'Dectivation';
+$string['dstpresetadjusttime'] = 'Time adjustment';
+
+$string['explain_dstpresetforced'] = 'The site administrator does not allow users to modify this option.';
+$string['explain_dstpreset'] = 'You can select which area to use DST settings for, if any, from the drop-down menu.';
+$string['dstdefaultpresetname'] = 'New DST Preset';
+$string['nth'] = '{$a}st';
+$string['dsthumanreadable'] = 'On the $a->activate_index $a->activate_weekday of each $a->activate_month, move the time $a->offset minutes $a->direction. This change lasts until the $a->deactivate_index $a->deactivate_weekday of $a->deactivate_month.';
+$string['dstadjusttime'] = 'Move time';
+$string['dstof'] = 'of';
+$string['dstat'] = 'at';
+$string['dstonthe'] = 'On the';
+$string['dstby'] = 'by';
+$string['day'] = 'day';
+$string['timeforward'] = 'forward';
+$string['timerewind'] = 'backwards';
+$string['first'] = 'first';
+$string['last'] = 'last';
 ?>
index 7b9cd8481445b866cd3586a5722b4587104adab4..39571da3b45113f79bdab20b862dd9eea2a6bbf1 100644 (file)
@@ -1012,6 +1012,30 @@ function main_upgrade($oldversion=0) {
     if ($oldversion < 2004121400) {
         table_column('groups', '', 'password', 'varchar', '50', '', '', 'not null', 'description');
     }
+
+    if ($oldversion < 2004121500) {
+        modify_database('',"CREATE TABLE prefix_dst_preset (
+            id int(10) NOT NULL auto_increment,
+            name char(48) default '' NOT NULL,
+            
+            apply_offset tinyint(3) default '0' NOT NULL,
+            
+            activate_index tinyint(1) default '1' NOT NULL,
+            activate_day tinyint(1) default '1' NOT NULL,
+            activate_month tinyint(2) default '1' NOT NULL,
+            activate_time char(5) default '03:00' NOT NULL,
+            
+            deactivate_index tinyint(1) default '1' NOT NULL,
+            deactivate_day tinyint(1) default '1' NOT NULL,
+            deactivate_month tinyint(2) default '2' NOT NULL,
+            deactivate_time char(5) default '03:00' NOT NULL,
+            
+            last_change int(10) default '0' NOT NULL,
+            next_change int(10) default '0' NOT NULL,
+            current_offset tinyint(3) default '0' NOT NULL,
+            
+            PRIMARY KEY (id))");
+    }       
        
     return $result;
 
index 21378475c67940dd393817aa10b49cecc7f0145e..57d609b6a7feca6bc0e1e5bc09edb356101a86f7 100644 (file)
@@ -496,9 +496,9 @@ function make_timestamp($year, $month=1, $day=1, $hour=0, $minute=0, $second=0,
     $timezone = get_user_timezone($timezone);
 
     if (abs($timezone) > 13) {
-        return mktime((int)$hour,(int)$minute,(int)$second,(int)$month,(int)$day,(int)$year);
+        return mktime((int)$hour,(int)$minute,(int)$second,(int)$month,(int)$day,(int)$year, 0);
     } else {
-        $time = gmmktime((int)$hour,(int)$minute,(int)$second,(int)$month,(int)$day,(int)$year);
+        $time = gmmktime((int)$hour,(int)$minute,(int)$second,(int)$month,(int)$day,(int)$year, 0);
         return usertime($time, $timezone);  // This is GMT
     }
 }
index 26d1384ee4c3c06438f59415503c48837859127d..2552baeb37d3be5d3ffb1ad2c4b46b411b81f779 100644 (file)
@@ -694,8 +694,18 @@ A IMG {
     border: none;
 }
 
-TABLE.formtable TD {
-    padding: 9px;
+table.formtable td, table.formtable th {
+    padding: 8px;
+}
+
+table.formtable tbody tr {
+    vertical-align: top;
+}
+
+table.formtable tbody th {
+    text-align: right;
+    font-weight: bold;
+    background: none;
 }
 
 .eventfull {
index 5db01046e7e7392d7fc6534b381d5e83ea2e5628..2bffd8dcf9043e302f3108ec6453a0f1b8cb4fc9 100644 (file)
@@ -6,7 +6,7 @@
 // This is compared against the values stored in the database to determine 
 // whether upgrades should be performed (see lib/db/*.php)
 
-   $version = 2004121400;  // YYYYMMDD = date of first major branch release 1.4
+   $version = 2004121500;  // YYYYMMDD = date of first major branch release 1.4
                            //       XY = increments within a single day
 
    $release = '1.5 UNSTABLE DEVELOPMENT';    // Human-friendly version name