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

raeburn raeburn@source.lon-capa.org
Thu, 02 Sep 2010 17:06:38 -0000


raeburn		Thu Sep  2 17:06:38 2010 EDT

  Modified files:              
    /loncom/auth	lonroles.pm 
  Log:
  - Reduce load time for users with lots of roles.
    - Only check course or domain timezone for active or future roles, or if display 'all" has been
      selected by an advanced user.
    - Get course timezone settings from %env where available.
  - Flush print buffer before compiling roles table. 
  - xhtml: don't emit <tr></tr> in recent roles part if role text is blank.  
  
  
Index: loncom/auth/lonroles.pm
diff -u loncom/auth/lonroles.pm:1.258 loncom/auth/lonroles.pm:1.259
--- loncom/auth/lonroles.pm:1.258	Tue Aug 24 13:18:26 2010
+++ loncom/auth/lonroles.pm	Thu Sep  2 17:06:38 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # User Roles Screen
 #
-# $Id: lonroles.pm,v 1.258 2010/08/24 13:18:26 raeburn Exp $
+# $Id: lonroles.pm,v 1.259 2010/09/02 17:06:38 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -730,6 +730,7 @@
         $r->print('<input type="hidden" name="selectrole" value="1" />');
         $r->print('<input type="hidden" name="newrole" value="" />');
     }
+    $r->rflush();
 
     my (%roletext,%sortrole,%roleclass,%futureroles,%timezones);
     my ($countactive,$countfuture,$inrole,$possiblerole) = 
@@ -845,12 +846,16 @@
 	    } elsif ($numdc > 0) {
                 unless ($role =~/^error\:/) {
                     my ($roletext,$role_text_end) = &display_cc_role('user.role.'.$role);
-                    $output.= &Apache::loncommon::start_data_table_row().
-                              $roletext.
-                              &Apache::loncommon::end_data_table_row().
-                              &Apache::loncommon::continue_data_table_row().
-                              $role_text_end.
-                              &Apache::loncommon::end_data_table_row();
+                    if ($roletext) {
+                        $output.= &Apache::loncommon::start_data_table_row().
+                                  $roletext.
+                                  &Apache::loncommon::end_data_table_row();
+                        if ($role_text_end) {
+                            $output .= &Apache::loncommon::continue_data_table_row().
+                                       $role_text_end.
+                                       &Apache::loncommon::end_data_table_row();
+                        }
+                    }
                 }
             }
 	}
@@ -931,16 +936,9 @@
             &Apache::lonnet::role_status($envkey,$then,$refresh,$now,\$role,\$where,
                                          \$trolecode,\$tstatus,\$tstart,\$tend);
             next if (!defined($role) || $role eq '' || $role =~ /^gr/);
-            my $timezone = &role_timezone($where,$timezones);
             $tremark='';
             $tpstart='&nbsp;';
             $tpend='&nbsp;';
-            if ($tstart) {
-                $tpstart=&Apache::lonlocal::locallocaltime($tstart,$timezone);
-            }
-            if ($tend) {
-                $tpend=&Apache::lonlocal::locallocaltime($tend,$timezone);
-            }
             if ($env{'request.role'} eq $trolecode) {
                 $tstatus='selected';
             }
@@ -949,6 +947,13 @@
                 || ($tstatus eq 'selected')
                 || ($tstatus eq 'future')
                 || ($env{'form.showall'})) {
+                my $timezone = &role_timezone($where,$timezones);
+                if ($tstart) {
+                    $tpstart=&Apache::lonlocal::locallocaltime($tstart,$timezone);
+                }
+                if ($tend) {
+                    $tpend=&Apache::lonlocal::locallocaltime($tend,$timezone);
+                }
                 if ($tstatus eq 'is') {
                     $tbg='LC_roles_is';
                     $possiblerole=$trolecode;
@@ -1032,10 +1037,12 @@
                                     '</span>';
                             unless ($home && grep(/^\Q$home\E$/,@ids) && $loncaparev eq '') {
                                 my $required = $env{'course.'.$tcourseid.'.internal.releaserequired'};
-                                ($switchserver,$switchwarning) = 
-                                    &check_release_required($loncaparev,$tcourseid,$trolecode,$required);
-                                if ($switchserver || $switchwarning) {
-                                    $button = 0;
+                                if ($required ne '') {
+                                    ($switchserver,$switchwarning) = 
+                                        &check_release_required($loncaparev,$tcourseid,$trolecode,$required);
+                                    if ($switchserver || $switchwarning) {
+                                        $button = 0;
+                                    }
                                 }
                             }
                         }
@@ -1053,10 +1060,12 @@
                             my $home = $newhash{'home'};
                             unless ($home && grep(/^\Q$home\E$/,@ids) && $loncaparev eq '') {
                                 my $required = $newhash{'internal.releaserequired'};
-                                ($switchserver,$switchwarning) =
-                                    &check_release_required($loncaparev,$tcourseid,$trolecode,$required);
-                                if ($switchserver || $switchwarning) {
-                                    $button = 0;
+                                if ($required ne '') {
+                                    ($switchserver,$switchwarning) =
+                                        &check_release_required($loncaparev,$tcourseid,$trolecode,$required);
+                                    if ($switchserver || $switchwarning) {
+                                        $button = 0;
+                                    }
                                 }
                             }
                         } else {
@@ -1102,9 +1111,15 @@
             my $cnum = $2;
             if ($cdom && $cnum) {
                 if (!exists($timezones->{$cdom.'_'.$cnum})) {
-                    my %timehash =
-                        &Apache::lonnet::get('environment',['timezone'],$cdom,$cnum);
-                    if ($timehash{'timezone'} eq '') {
+                    my $tz;
+                    if ($env{'course.'.$cdom.'_'.$cnum.'.description'}) {
+                        $tz = $env{'course.'.$cdom.'_'.$cnum.'.timezone'};
+                    } else {
+                        my %timehash =
+                            &Apache::lonnet::get('environment',['timezone'],$cdom,$cnum);
+                        $tz = $timehash{'timezone'};
+                    }
+                    if ($tz eq '') {
                         if (!exists($timezones->{$cdom})) {
                             my %domdefaults = 
                                 &Apache::lonnet::get_domain_defaults($cdom);
@@ -1117,7 +1132,7 @@
                         $timezones->{$cdom.'_'.$cnum} = $timezones->{$cdom};
                     } else {
                         $timezones->{$cdom.'_'.$cnum} = 
-                            &Apache::lonlocal::gettimezone($timehash{'timezone'});
+                            &Apache::lonlocal::gettimezone($tz);
                     }
                 }
                 $timezone = $timezones->{$cdom.'_'.$cnum};