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

raeburn lon-capa-cvs@mail.lon-capa.org
Tue, 09 Nov 2004 15:52:29 -0000


raeburn		Tue Nov  9 10:52:29 2004 EDT

  Modified files:              
    /loncom/auth	lonroles.pm 
  Log:
  Consolidating repeated code into subroutine.
  
  
Index: loncom/auth/lonroles.pm
diff -u loncom/auth/lonroles.pm:1.101 loncom/auth/lonroles.pm:1.102
--- loncom/auth/lonroles.pm:1.101	Tue Nov  2 18:22:46 2004
+++ loncom/auth/lonroles.pm	Tue Nov  9 10:52:29 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # User Roles Screen
 #
-# $Id: lonroles.pm,v 1.101 2004/11/02 23:22:46 albertel Exp $
+# $Id: lonroles.pm,v 1.102 2004/11/09 15:52:29 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -99,21 +99,9 @@
 				"request.role.domain" => $ENV{'user.domain'});
         foreach $envkey (keys %ENV) {
             next if ($envkey!~/^user\.role\./);
-	    my (undef,undef,$role,@pwhere)=split(/\./,$envkey);
-            my $where=join('.',@pwhere);
-            my $trolecode=$role.'.'.$where;
+            my ($where,$trolecode,$role,$tstatus,$tend,$tstart);
+            &role_status($envkey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend);
             if ($ENV{'form.'.$trolecode}) {
-		my ($tstart,$tend)=split(/\./,$ENV{$envkey});
-		my $tstatus='is';
-		if ($tstart) {
-		    if ($tstart>$then) { 
-			$tstatus='future';
-		    }
-		}
-		if ($tend) {
-		    if ($tend<$then) { $tstatus='expired'; }
-		    if ($tend<$now) { $tstatus='will_not'; }
-		}
 		if ($tstatus eq 'is') {
 		    $where=~s/^\///;
 		    my ($cdom,$cnum,$csec)=split(/\//,$where);
@@ -380,16 +368,13 @@
 	my $roletext;
 	my $sortkey;
         if ($envkey=~/^user\.role\./) {
-	    my (undef,undef,$role,@pwhere)=split(/\./,$envkey);
+            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 '');
-            my $where=join('.',@pwhere);
-            my $trolecode=$role.'.'.$where;
-            my ($tstart,$tend)=split(/\./,$ENV{$envkey});
-            my $tremark='';
-            my $tstatus='is';
-            my $tpstart='&nbsp;';
-            my $tpend='&nbsp;';
-            my $tfont='#000000';
+            $tremark='';
+            $tpstart='&nbsp;';
+            $tpend='&nbsp;';
+            $tfont='#000000';
             if ($tstart) {
 		if ($tstart>$then) { 
                     $tstatus='future';
@@ -719,7 +704,33 @@
     }
     $r->print("</body></html>\n");
     return OK;
-} 
+}
+
+sub role_status {
+    my ($rolekey,$then,$now,$role,$where,$trolecode,$tstatus,$tstart,$tend) = @_;
+    my @pwhere = ();
+    if (exists($ENV{$rolekey}) && $ENV{$rolekey} ne '') {
+        (undef,undef,$$role,@pwhere)=split(/\./,$rolekey);
+        unless (!defined($$role) || $$role eq '') {
+            $$where=join('.',@pwhere);
+            $$trolecode=$$role.'.'.$$where;
+            ($$tstart,$$tend)=split(/\./,$ENV{$rolekey});
+            $$tstatus='is';
+            if ($$tstart) {
+                if ($$tstart>$then) {
+                    $$tstatus='future';
+                    if ($$tstart<$now) { $$tstatus='will'; }
+                }
+            }
+            if ($$tend) {
+                if ($$tend<$then) {
+                    $$tstatus='expired';
+                    if ($$tend<$now) { $$tstatus='will_not'; }
+                }
+            }
+        }
+    }
+}
 
 1;
 __END__