From bb4a2e85c035a0d9edaee453eaa87f954b161776 Mon Sep 17 00:00:00 2001 From: defacer Date: Thu, 16 Dec 2004 18:49:57 +0000 Subject: [PATCH] New features implemented: * 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 | 36 ++++++++++++++++++++++++++++- admin/calendar.php | 48 +++++++++++++++++++++++++++++++++++++-- calendar/lib.php | 24 ++++++++++++++------ calendar/preferences.html | 4 ++-- calendar/view.php | 2 +- lang/en/admin.php | 4 ++++ theme/standard/styles.php | 2 +- 7 files changed, 106 insertions(+), 14 deletions(-) diff --git a/admin/calendar.html b/admin/calendar.html index d1b83d651d..841ee00452 100644 --- a/admin/calendar.html +++ b/admin/calendar.html @@ -3,7 +3,7 @@

- +
@@ -15,6 +15,40 @@ + + + + + + + + + + + + + + + + + + + +
adminseesall:
startwday: + calendar_startwday) ? 0 : $CFG->calendar_startwday, ''); ?> +
weekenddays: + /> + /> + /> + /> + /> + /> + /> +
upcoming_lookahead: + +
upcoming_maxevents: + +
dstforusers: diff --git a/admin/calendar.php b/admin/calendar.php index 69353561fa..9fbd5caae7 100644 --- a/admin/calendar.php +++ b/admin/calendar.php @@ -26,7 +26,6 @@ print_heading($strcalendarsettings); - /// If data submitted, process and store if(confirm_sesskey() && $form = data_submitted()) { @@ -49,8 +48,43 @@ } 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) { @@ -58,7 +92,17 @@ } } -/// 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'); diff --git a/calendar/lib.php b/calendar/lib.php index c74a5e7015..d2aeee4a87 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -38,16 +38,26 @@ // // ///////////////////////////////////////////////////////////////////////////// -$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'; } diff --git a/calendar/preferences.html b/calendar/preferences.html index f0bb8e4fc6..540d9c82d1 100644 --- a/calendar/preferences.html +++ b/calendar/preferences.html @@ -37,7 +37,7 @@ : :