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

raeburn raeburn@source.lon-capa.org
Wed, 23 Sep 2009 16:55:54 -0000


raeburn		Wed Sep 23 16:55:54 2009 EDT

  Modified files:              (Branch: GCI_1)
    /loncom/auth	lonroles.pm 
  Log:
  - lonroles.pm for GCI_1 updated to 2.8.X
  - Backport 1.215
  
  
Index: loncom/auth/lonroles.pm
diff -u loncom/auth/lonroles.pm:1.209 loncom/auth/lonroles.pm:1.209.4.1
--- loncom/auth/lonroles.pm:1.209	Mon Oct 20 03:25:48 2008
+++ loncom/auth/lonroles.pm	Wed Sep 23 16:55:53 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # User Roles Screen
 #
-# $Id: lonroles.pm,v 1.209 2008/10/20 03:25:48 raeburn Exp $
+# $Id: lonroles.pm,v 1.209.4.1 2009/09/23 16:55:53 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -548,6 +548,7 @@
     my $possiblerole='';
     my %futureroles;
     my %roles_nextlogin;
+    my %timezones;
     foreach $envkey (sort keys %env) {
         my $button = 1;
         my $switchserver='';
@@ -557,15 +558,16 @@
             my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend,$tfont);
             &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=' ';
             $tfont='#000000';
             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';
@@ -833,6 +835,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;