]> git.mjollnir.org Git - moodle.git/commitdiff
Merging fix for reopened bug 1384 from STABLE.
authordefacer <defacer>
Wed, 12 Jan 2005 11:55:01 +0000 (11:55 +0000)
committerdefacer <defacer>
Wed, 12 Jan 2005 11:55:01 +0000 (11:55 +0000)
Fix for bug 2252:
You can now choose to have the calendar "remember" your filter settings
between logins.

Some extra code in calendar/lib.php for DST. It doesn't currently affect
how Moodle works.

calendar/lib.php
calendar/preferences.html
calendar/preferences.php
calendar/set.php
login/index.php

index 5d206e6876d00aba96150629411e6d7962c093a2..e0f49136008ea42595fa76200f3f8e0f91caa9c1 100644 (file)
@@ -885,12 +885,18 @@ function calendar_session_vars() {
         unset($SESSION->cal_users_shown);
         unset($SESSION->cal_courses_shown);
         $SESSION->cal_loggedinas = true;
+        if(intval(get_user_preferences('calendar_persistflt', 0))) {
+            calendar_set_filters_status(get_user_preferences('calendar_savedflt', 0xff));
+        }
     }
     else if(!empty($USER->id) && !isset($USER->realuser) && isset($SESSION->cal_loggedinas)) {
         // We just logged back to our real self, update again
         unset($SESSION->cal_users_shown);
         unset($SESSION->cal_courses_shown);
         unset($SESSION->cal_loggedinas);
+        if(intval(get_user_preferences('calendar_persistflt', 0))) {
+            calendar_set_filters_status(get_user_preferences('calendar_savedflt', 0xff));
+        }
     }
 
     if(!isset($SESSION->cal_course_referer)) {
@@ -996,14 +1002,9 @@ function calendar_set_filters(&$courses, &$group, &$user, $courseeventsfrom = NU
         foreach($groupcourses as $courseid) {
             // If the user is an editing teacher in there,
             if(!empty($USER->id) && isteacheredit($courseid, $USER->id)) {
-                if (isset($courses[$courseid])) {
-                    $checkcourse = $courses[$courseid];
-                    if (!empty($checkcourse->groupmode)) {
-                        // Show events from all groups
-                        if(($grouprecords = get_groups($courseid)) !== false) {
-                            $grouparray = array_merge($grouparray, array_keys($grouprecords));
-                        }
-                    }
+                // Show events from all groups
+                if(($grouprecords = get_groups($courseid)) !== false) {
+                    $grouparray = array_merge($grouparray, array_keys($grouprecords));
                 }
             }
             // Otherwise show events from the group he is a member of
@@ -1081,16 +1082,6 @@ function calendar_get_default_courses($ignoreref = false) {
     return $courses;
 }
 
-function calendar_preferences_array() {
-    return array(
-        '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'),
-    );
-}
-
 function calendar_preferences_button() {
     global $CFG, $USER;
 
@@ -1231,46 +1222,57 @@ function calendar_find_day_in_month($index, $weekday, $month, $year) {
 }
 
 function calendar_dst_update_preset($dstpreset) {
-    $now  = time();
 
     // What's the date according to our user right now?
+    $now  = time();
     $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);
+    $changes = calendar_dst_changes_for_year($date['year'], $dstpreset);
 
     // Great... let's see where exactly we are now.
-    if($now < $timeactivate) {
+    if($now < $changes['activate']) {
         print_object("<<");
         // DST has not been turned on this year
-        $dstpreset->next_change = $timeactivate;
+        $dstpreset->next_change = $changes['activate'];
         // 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;
+        $prevchanges = calendar_dst_changes_for_year($date['year'] - 1, $dstpreset);
+        $dstpreset->last_change = $prevchanges['deactivate'];
+        $dstpreset->current_offset = 0;
     }
-    else if($now < $timedeactivate) {
+    else if($now < $changes['deactivate']) {
         print_object("<>");
         // DST is on for this year right now
-        $dstpreset->last_change = $timeactivate;
-        $dstpreset->next_change = $timedeactivate;
+        $dstpreset->last_change = $changes['activate'];
+        $dstpreset->next_change = $changes['deactivate'];
+        $dstpreset->current_offset = $dstpreset->apply_offset;
     }
     else {
         print_object(">>");
         // DST has already been turned off; we are nearing the end of the year
-        $dstpreset->last_change = $timedeactivate;
+        $dstpreset->last_change = $changes['deactivate'];
         // 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;
+        $nextchanges = calendar_dst_changes_for_year($date['year'] + 1, $dstpreset);
+        $dstpreset->next_change = $nextchanges['activate'];
+        $dstpreset->current_offset = 0;
     }
 
     return $dstpreset;
 }
 
+function calendar_dst_changes_for_year($year, $dstpreset) {
+    $monthdayactivate   = calendar_find_day_in_month($dstpreset->activate_index,   $dstpreset->activate_day,   $dstpreset->activate_month,   $year);
+    $monthdaydeactivate = calendar_find_day_in_month($dstpreset->deactivate_index, $dstpreset->deactivate_day, $dstpreset->deactivate_month, $year);
+
+    list($activate_hour, $activate_minute)     = explode(':', $dstpreset->activate_time);
+    list($deactivate_hour, $deactivate_minute) = explode(':', $dstpreset->deactivate_time);
+    
+    $timezone       = get_user_timezone(99);
+    $timeactivate   = make_timestamp($year, $dstpreset->activate_month,   $monthdayactivate,   $activate_hour,   $activate_minute,   0, $timezone, false);
+    $timedeactivate = make_timestamp($year, $dstpreset->deactivate_month, $monthdaydeactivate, $deactivate_hour, $deactivate_minute, 0, $timezone, false);
+
+    return array('activate' => $timeactivate, 0 => $timeactivate, 'deactivate' => $timedeactivate, 1 => $timedeactivate);
+}
+
 function calendar_print_month_selector($name, $selected) {
     
     $months = array();
@@ -1282,4 +1284,38 @@ function calendar_print_month_selector($name, $selected) {
     choose_from_menu($months, $name, $selected, '');
 }
 
+function calendar_get_filters_status() {
+    global $SESSION;
+
+    $status = 0;
+    if($SESSION->cal_show_global) {
+        $status += 1;
+    }
+    if($SESSION->cal_show_course) {
+        $status += 2;
+    }
+    if($SESSION->cal_show_groups) {
+        $status += 4;
+    }
+    if($SESSION->cal_show_user) {
+        $status += 8;
+    }
+    return $status;
+}
+
+function calendar_set_filters_status($packed_bitfield) {
+    global $SESSION, $USER;
+
+    if(!isset($USER) || empty($USER->id)) {
+        return false;
+    }
+
+    $SESSION->cal_show_global = ($packed_bitfield & 1);
+    $SESSION->cal_show_course = ($packed_bitfield & 2);
+    $SESSION->cal_show_groups = ($packed_bitfield & 4);    
+    $SESSION->cal_show_user   = ($packed_bitfield & 8);
+
+    return true;
+}
+
 ?>
index 540d9c82d1c964877cdafa9956ff3ba5bae6fdb4..5bb15c93ded2c9adc6305c6f55b45af638c89145 100644 (file)
     </td>
 </tr>
 
+<tr valign="top">
+       <td nowrap="nowrap" align="right"><?php print_string('pref_persistflt', 'calendar')?>:</td>
+       <td>
+    <?php choose_from_menu (array(0 => get_string('no'), 1 => get_string('yes')), 'persistflt', $prefs->persistflt, '', '', ''); ?>
+    </td>
+    <td>
+    <?php print_string('explain_persistflt', 'calendar'); ?>
+    </td>
+</tr>
+
 <tr>
     <td colspan="3" align="center">
        <input type="submit" value="<?php print_string("savechanges") ?>" /></td>
index a44a1e9ebac78f23be50511c0dd00ccaded5afa5..5bd5d769f1b7fbae955f1eaa4b293213ec0412b7 100644 (file)
@@ -49,6 +49,9 @@
                         set_user_preference('calendar_lookahead', $value);
                     }
                 break;
+                case 'persistflt':
+                    set_user_preference('calendar_persistflt', intval($value));
+                break;
             }
         }
         redirect('view.php', get_string('changessaved'), 1);
@@ -81,6 +84,7 @@
     $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->persistflt = get_user_preferences('calendar_persistflt', 0);
 
        include('./preferences.html');
     print_simple_box_end();
index 18b30b76bee12fa2a42eaca540ba0f4c4a0b1d97..86e3c4d3d9f0396cd9f7fedc43d9d2929e6b148c 100644 (file)
         break;
         case 'showgroups':
             $SESSION->cal_show_groups = !$SESSION->cal_show_groups;
+            set_user_preference('calendar_savedflt', calendar_get_filters_status());
         break;
         case 'showcourses':
             $SESSION->cal_show_course = !$SESSION->cal_show_course;
+            set_user_preference('calendar_savedflt', calendar_get_filters_status());
         break;
         case 'showglobal':
             $SESSION->cal_show_global = !$SESSION->cal_show_global;
+            set_user_preference('calendar_savedflt', calendar_get_filters_status());
         break;
         case 'showuser':
             $SESSION->cal_show_user = !$SESSION->cal_show_user;
+            set_user_preference('calendar_savedflt', calendar_get_filters_status());
         break;
     }
 
index b35ba4e79237c95e9ad8efeda7f3a65b1addc490..2bb37450723b90bf33ad0863ea842b51ffd401d3 100644 (file)
             unset($SESSION->lang);
             $SESSION->justloggedin = true;
 
+            // Restore the calendar filters, if saved
+            if(intval(get_user_preferences('calendar_persistflt', 0))) {
+                include_once($CFG->dirroot.'/calendar/lib.php');
+                calendar_set_filters_status(get_user_preferences('calendar_savedflt', 0xff));
+            }
+
             //Select password change url
             if (is_internal_auth() || $CFG->{'auth_'.$USER->auth.'_stdchangepassword'}){
                 $passwordchangeurl=$CFG->wwwroot.'/login/change_password.php';