]> git.mjollnir.org Git - moodle.git/commitdiff
New features implemented:
authordefacer <defacer>
Thu, 16 Dec 2004 18:49:57 +0000 (18:49 +0000)
committerdefacer <defacer>
Thu, 16 Dec 2004 18:49:57 +0000 (18:49 +0000)
 * Configurable defaults for the calendar upcoming events lookahead and
   maximum upcoming events displayed (bug #1623)

 * Configurable setting for which days of the week are treated as weekend
   (bug #1919)

 * Configurable setting for which day starts the week (the admin can now set
   this as the default for new users and guests without messing with language
   packs) (no butracker issue)

admin/calendar.html
admin/calendar.php
calendar/lib.php
calendar/preferences.html
calendar/view.php
lang/en/admin.php
theme/standard/styles.php

index d1b83d651d8dda94650187ff850685c25bcf25ee..841ee00452d68886e2a4f73440bfac0597b5dfb8 100644 (file)
@@ -3,7 +3,7 @@
 <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">
+<table style="margin: auto;" class="formtable">
   <tbody>
     <tr>
       <th>adminseesall:</th>
       </td>
       <td><?php print_string('helpadminseesall', 'admin'); ?></td>
     </tr>
+    <tr>
+      <th>startwday:</th>
+      <td>
+        <?php choose_from_menu($weekdays, 'startwday', empty($CFG->calendar_startwday) ? 0 : $CFG->calendar_startwday, ''); ?>
+      </td>
+      <td><?php print_string('helpstartofweek', 'admin'); ?></td>
+    </tr>
+    <tr>
+      <th>weekenddays:</th>
+      <td>
+        <nobr><input type="checkbox" name="weekend[]" value="1" id="weekend1" <?php if(CALENDAR_WEEKEND &  2) echo 'checked="checked"'; ?> /> <label for="weekend1"><?php print_string('monday', 'calendar'); ?></label></nobr>
+        <nobr><input type="checkbox" name="weekend[]" value="2" id="weekend2" <?php if(CALENDAR_WEEKEND &  4) echo 'checked="checked"'; ?> /> <label for="weekend2"><?php print_string('tuesday', 'calendar'); ?></label></nobr>
+        <nobr><input type="checkbox" name="weekend[]" value="3" id="weekend3" <?php if(CALENDAR_WEEKEND &  8) echo 'checked="checked"'; ?> /> <label for="weekend3"><?php print_string('wednesday', 'calendar'); ?></label></nobr>
+        <nobr><input type="checkbox" name="weekend[]" value="4" id="weekend4" <?php if(CALENDAR_WEEKEND & 16) echo 'checked="checked"'; ?> /> <label for="weekend4"><?php print_string('thursday', 'calendar'); ?></label></nobr>
+        <nobr><input type="checkbox" name="weekend[]" value="5" id="weekend5" <?php if(CALENDAR_WEEKEND & 32) echo 'checked="checked"'; ?> /> <label for="weekend5"><?php print_string('friday', 'calendar'); ?></label></nobr>
+        <nobr><input type="checkbox" name="weekend[]" value="6" id="weekend6" <?php if(CALENDAR_WEEKEND & 64) echo 'checked="checked"'; ?> /> <label for="weekend6"><?php print_string('saturday', 'calendar'); ?></label></nobr>
+        <nobr><input type="checkbox" name="weekend[]" value="0" id="weekend0" <?php if(CALENDAR_WEEKEND &  1) echo 'checked="checked"'; ?> /> <label for="weekend0"><?php print_string('sunday', 'calendar'); ?></label></nobr>
+      </td>
+      <td><?php print_string('helpweekenddays', 'admin'); ?></td>
+    </tr>
+    <tr>
+      <th>upcoming_lookahead:</th>
+      <td>
+        <input type="text" name="lookahead" size="3" value="<?php echo CALENDAR_UPCOMING_DAYS; ?>" />
+      </td>
+      <td><?php print_string('helpupcominglookahead', 'admin'); ?></td>
+    </tr>
+    <tr>
+      <th>upcoming_maxevents:</th>
+      <td>
+        <input type="text" name="maxevents" size="3" value="<?php echo CALENDAR_UPCOMING_MAXEVENTS; ?>" />
+      </td>
+      <td><?php print_string('helpupcomingmaxevents', 'admin'); ?></td>
+    </tr>
     <tr>
       <th>dstforusers:</th>
       <td>
index 69353561fa16ba7566f3ec3678b59812640552ea..9fbd5caae7b98e7157fc742fc4b6d44fcb263fbe 100644 (file)
@@ -26,7 +26,6 @@
 
     print_heading($strcalendarsettings);
 
-
 /// If data submitted, process and store
 
     if(confirm_sesskey() && $form = data_submitted()) {
             }
             set_config('calendar_dstforusers', $preset);
         }
+        if(isset($form->startwday)) {
+            $startwday = intval($form->startwday);
+            if($startwday >= 0 && $startwday <= 6) {
+                set_config('calendar_startwday', $startwday);
+            }
+        }
+        if(isset($form->weekend)) {
+            if(is_array($form->weekend)) {
+                // Creating a packed bitfield; look at /calendar/lib.php if you can't figure it out
+                $bitfield = 0;
+                foreach($form->weekend as $day) {
+                    $bitfield |= (1 << (intval($day) % 7));
+                }
+                if($bitfield > 0) {
+                    set_config('calendar_weekend', $bitfield);
+                }
+            }
+        }
+        if(isset($form->lookahead)) {
+            $lookahead = intval($form->lookahead);
+            if($lookahead > 0) {
+                set_config('calendar_lookahead', $lookahead);
+            }
+        }
+        if(isset($form->maxevents)) {
+            $maxevents = intval($form->maxevents);
+            if($maxevents > 0) {
+                set_config('calendar_maxevents', $maxevents);
+            }
+        }
     }
 
+    // Include the calendar library AFTER modifying the data, so we read the latest values
+    require_once('../calendar/lib.php');
+
+    // Populate some variables we 're going to need in calendar.html
+
     $presets = get_records('dst_preset');
     if(!empty($presets)) {
         foreach($presets as $id => $preset) {
         }
     }
 
-/// Main display starts here
+    $weekdays = array(
+        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')
+    );
+
+    // Main display starts here
 
     print_simple_box_start('center', '100%', $THEME->cellheading);
     include('./calendar.html');
index c74a5e701515e6def8e8783732b152f147d395bf..d2aeee4a8743933810b8e56d2038ed8ebb2e1b7c 100644 (file)
 //                                                                         //
 /////////////////////////////////////////////////////////////////////////////
 
-$firstday = get_string('firstdayofweek');
-if(!is_numeric($firstday)) {
-    define ('CALENDAR_STARTING_WEEKDAY', 1);
+// These are read by the administration component to provide default values
+define('CALENDAR_DEFAULT_UPCOMING_LOOKAHEAD', 21);
+define('CALENDAR_DEFAULT_UPCOMING_MAXEVENTS', 10);
+define('CALENDAR_DEFAULT_STARTING_WEEKDAY',   1);
+// This is a packed bitfield: day X is "weekend" if $field & (1 << X) is true
+// Default value = 65 = 64 + 1 = 2^6 + 2^0 = Saturday & Sunday
+define('CALENDAR_DEFAULT_WEEKEND',            65);
+
+// Fetch the correct values from admin settings/lang pack
+// If no such settings found, use the above defaults
+$firstday = isset($CFG->calendar_startwday) ? $CFG->calendar_startwday : get_string('firstdayofweek');
+if(!is_numeric($firstday)) {    
+    define ('CALENDAR_STARTING_WEEKDAY', CALENDAR_DEFAULT_STARTING_WEEKDAY);
 }
 else {
     define ('CALENDAR_STARTING_WEEKDAY', intval($firstday) % 7);
 }
-
-define ('CALENDAR_UPCOMING_DAYS', 21);
-define ('CALENDAR_UPCOMING_MAXEVENTS', 10);
+define ('CALENDAR_UPCOMING_DAYS', isset($CFG->calendar_lookahead) ? intval($CFG->calendar_lookahead) : CALENDAR_DEFAULT_UPCOMING_LOOKAHEAD);
+define ('CALENDAR_UPCOMING_MAXEVENTS', isset($CFG->calendar_maxevents) ? intval($CFG->calendar_maxevents) : CALENDAR_DEFAULT_UPCOMING_MAXEVENTS);
+define ('CALENDAR_WEEKEND', isset($CFG->calendar_weekend) ? intval($CFG->calendar_weekend) : CALENDAR_DEFAULT_WEEKEND);
 define ('CALENDAR_URL', $CFG->wwwroot.'/calendar/');
 define ('CALENDAR_TF_24', '%H:%M');
 define ('CALENDAR_TF_12', '%I:%M %p');
@@ -165,7 +175,7 @@ function calendar_get_mini($courses, $groups, $users, $cal_month = false, $cal_y
 
         // Reset vars
         $cell = '';
-        if($dayweek % 7 == 0 || $dayweek % 7 == 6) {
+        if(CALENDAR_WEEKEND & (1 << ($dayweek % 7))) {
             // Weekend. This is true no matter what the exact range is.
             $class = 'cal_weekend';
         }
index f0bb8e4fc647b3e7e2da65697d7dfba734f9a497..540d9c82d1c964877cdafa9956ff3ba5bae6fdb4 100644 (file)
@@ -37,7 +37,7 @@
        <td nowrap="nowrap" align="right"><?php print_string('pref_timeformat', 'calendar')?>:</td>
        <td>
     <?php
-        $options = NULL;
+        $options = array();
         $options['0']  = get_string('default', 'calendar');
         $options[CALENDAR_TF_12] = get_string('timeformat_12', 'calendar');
         $options[CALENDAR_TF_24] = get_string('timeformat_24', 'calendar');
@@ -53,7 +53,7 @@
        <td nowrap="nowrap" align="right"><?php print_string('pref_startwday', 'calendar')?>:</td>
        <td>
     <?php
-        $options = NULL;
+        $options = array();
         $options[0] = get_string('sunday', 'calendar');
         $options[1] = get_string('monday', 'calendar');
         $options[2] = get_string('tuesday', 'calendar');
index 64a42647bc3803b7ca6774c52f45bc146e56a71c..6db6fa41ad91ffb5d488ee9b98db1de0d9a59bf6 100644 (file)
@@ -368,7 +368,7 @@ function calendar_show_month_detailed($m, $y, $courses, $groups, $users) {
         $cell = '';
         $dayhref = calendar_get_link_href(CALENDAR_URL.'view.php?view=day&amp;', $day, $m, $y);
 
-        if($dayweek % 7 == 0 || $dayweek % 7 == 6) {
+        if(CALENDAR_WEEKEND & (1 << ($dayweek % 7))) {
             // Weekend. This is true no matter what the exact range is.
             $class = 'cal_weekend';
         }
index 6f672f5a7629487f01175442c1e053ea84a95cad..e81850df867a8241a6eb44e4aa4c63f9024af036 100755 (executable)
@@ -24,6 +24,10 @@ $string['helpadminseesall'] = 'Do admins see all calendar events or just those t
 $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['helpstartofweek'] = 'Which day starts the week in the calendar?';
+$string['helpupcominglookahead'] = 'How many days in the future does the calendar look for upcoming events by default?';
+$string['helpupcomingmaxevents'] = 'How many (maximum) upcoming events are shown to users by default?';
+$string['helpweekenddays'] = 'Which days of the week are treated as \"weekend\" and shown with a different colour?';
 $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';
index 2552baeb37d3be5d3ffb1ad2c4b46b411b81f779..ad3ca8d2c1b7c77d6e08c344c73bc77ead31aed4 100644 (file)
@@ -695,7 +695,7 @@ A IMG {
 }
 
 table.formtable td, table.formtable th {
-    padding: 8px;
+    padding: 6px;
 }
 
 table.formtable tbody tr {