[LON-CAPA-cvs] cvs: loncom /auth lonroles.pm

raeburn raeburn@source.lon-capa.org
Sat, 03 Jan 2009 00:16:10 -0000


raeburn		Sat Jan  3 00:16:10 2009 EDT

  Modified files:              
    /loncom/auth	lonroles.pm 
  Log:
  - Bug 5792.
  - Timezones used in start and end dates on roles screen are specific to the role (appropriate course time zone for course roles, otherwise domain default for other roles based on role's domain).
  
  
Index: loncom/auth/lonroles.pm
diff -u loncom/auth/lonroles.pm:1.214 loncom/auth/lonroles.pm:1.215
--- loncom/auth/lonroles.pm:1.214	Mon Dec 15 16:37:53 2008
+++ loncom/auth/lonroles.pm	Sat Jan  3 00:16:10 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # User Roles Screen
 #
-# $Id: lonroles.pm,v 1.214 2008/12/15 16:37:53 raeburn Exp $
+# $Id: lonroles.pm,v 1.215 2009/01/03 00:16:10 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -646,6 +646,7 @@
     my $possiblerole='';
     my %futureroles;
     my %roles_nextlogin;
+    my %timezones;
     foreach $envkey (sort keys %env) {
         my $button = 1;
         my $switchserver='';
@@ -655,14 +656,15 @@
             my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend);
             &role_status($envkey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend);
             next if (!defined($role) || $role eq '' || $role =~ /^gr/);
+            my $timezone = &role_timezone($where,\%timezones);
             $tremark='';
             $tpstart=' ';
             $tpend=' ';
             if ($tstart) {
-                $tpstart=&Apache::lonlocal::locallocaltime($tstart);
+                $tpstart=&Apache::lonlocal::locallocaltime($tstart,$timezone);
             }
             if ($tend) {
-                $tpend=&Apache::lonlocal::locallocaltime($tend);
+                $tpend=&Apache::lonlocal::locallocaltime($tend,$timezone);
             }
             if ($env{'request.role'} eq $trolecode) {
 		$tstatus='selected';
@@ -938,6 +940,56 @@
     return OK;
 }
 
+sub role_timezone {
+    my ($where,$timezones) = @_;
+    my $timezone;
+    if (ref($timezones) eq 'HASH') { 
+        if ($where =~ m{^/($match_domain)/($match_courseid)}) {
+            my $cdom = $1;
+            my $cnum = $2;
+            if ($cdom && $cnum) {
+                if (!exists($timezones->{$cdom.'_'.$cnum})) {
+                    my %timehash =
+                        &Apache::lonnet::get('environment',['timezone'],$cdom,$cnum);
+                    if ($timehash{'timezone'} eq '') {
+                        if (!exists($timezones->{$cdom})) {
+                            my %domdefaults = 
+                                &Apache::lonnet::get_domain_defaults($cdom);
+                            if ($domdefaults{'timezone_def'} eq '') {
+                                $timezones->{$cdom} = 'local';
+                            } else {
+                                $timezones->{$cdom} = $domdefaults{'timezone_def'};
+                            }
+                        }
+                        $timezones->{$cdom.'_'.$cnum} = $timezones->{$cdom};
+                    } else {
+                        $timezones->{$cdom.'_'.$cnum} = 
+                            &Apache::lonlocal::gettimezone($timehash{'timezone'});
+                    }
+                }
+                $timezone = $timezones->{$cdom.'_'.$cnum};
+            }
+        } else {
+            my ($tdom) = ($where =~ m{^/($match_domain)});
+            if ($tdom) {
+                if (!exists($timezones->{$tdom})) {
+                    my %domdefaults = &Apache::lonnet::get_domain_defaults($tdom);
+                    if ($domdefaults{'timezone_def'} eq '') {
+                        $timezones->{$tdom} = 'local';
+                    } else {
+                        $timezones->{$tdom} = $domdefaults{'timezone_def'};
+                    }
+                }
+                $timezone = $timezones->{$tdom};
+            }
+        }
+        if ($timezone eq 'local') {
+            $timezone = undef;
+        }
+    }
+    return $timezone;
+}
+
 sub roletable_headers {
     my ($r,$roleclass,$sortrole,$nochoose) = @_;
     my $doheaders;