[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm

albertel lon-capa-cvs@mail.lon-capa.org
Tue, 15 Nov 2005 15:52:52 -0000


albertel		Tue Nov 15 10:52:52 2005 EDT

  Modified files:              
    /loncom/interface	loncommon.pm 
  Log:
  - protecting vars regexps with \Q \E
  - style
  - eliminating unneccessary nesting
  
  
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.289 loncom/interface/loncommon.pm:1.290
--- loncom/interface/loncommon.pm:1.289	Tue Nov 15 10:40:58 2005
+++ loncom/interface/loncommon.pm	Tue Nov 15 10:52:51 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.289 2005/11/15 15:40:58 albertel Exp $
+# $Id: loncommon.pm,v 1.290 2005/11/15 15:52:51 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3123,17 +3123,16 @@
     $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
     $idx{status} = &Apache::loncoursedata::CL_STATUS();
 
-    if (grep/^st$/,@{$roles}) {
+    if (grep(/^st$/,@{$roles})) {
         my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
         my $now = time;
         foreach my $student (keys(%{$classlist})) {
             my $match = 0;
-            if (defined($sections) && (ref($sections) eq 'ARRAY')) {
-                if (@{$sections} > 0) {
-                    unless(grep/^$$classlist{$student}[$idx{section}]$/,@{$sections}) {
-                        next;
-                    }
-                }
+            if (ref($sections) eq 'ARRAY') && (@{$sections} > 0) {
+		unless(grep(/^\Q$$classlist{$student}[$idx{section}]\E$/,
+			    @{$sections})) {
+		    next;
+		}
             } 
             if (defined($$types{'active'})) {
                 if ($$classlist{$student}[$idx{status}] eq 'Active') {
@@ -3164,16 +3163,13 @@
             my $match = 0;
             my ($role,$user) = ($person =~ /^([^:]*):([^:]+:[^:]+)/);
             $user =~ s/:$//;
-            if (($role) && (grep(/^$role$/,@{$roles}))) {
+            if (($role) && (grep(/^\Q$role\E$/,@{$roles}))) {
                 my ($uname,$udom,$usec) = split(/:/,$user);
-                unless ($usec eq '') {
-                    if (defined($sections) && (ref($sections) eq 'ARRAY')) {
-                        if (@{$sections} > 0) {
-                            unless(grep/^$usec$/,@{$sections}) {
-                                next;
-                            }
-                        }
-                    }
+                if ($usec ne '' && (ref($sections) eq 'ARRAY') && 
+		    @{$sections} > 0) {
+		    unless(grep(/^\Q$usec\E$/,@{$sections})) {
+			next;
+		    }
                 }
                 if ($uname ne '' && $udom ne '') {
                     my $status = &check_user_status($udom,$uname,$cdom,$cnum,$role);
@@ -3183,25 +3179,23 @@
                             $match = 1;
                         }
                     }
-                    if ($match && defined($userdata)) {
-                        unless(exists($$userdata{$uname.':'.$udom})) {
-                            &get_user_info($udom,$uname,\%idx,$userdata);
-                        }
+                    if ($match && defined($userdata) &&
+                        !exists($$userdata{$uname.':'.$udom})) {
+			&get_user_info($udom,$uname,\%idx,$userdata);
                     }
                 }
             }
         }
-        if (grep/^ow$/,@{$roles}) {
+        if (grep(/^ow$/,@{$roles})) {
             if ((defined($cdom)) && (defined($cnum))) {
                 my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
                 if ( defined($csettings{'internal.courseowner'}) ) {
                     my $owner = $csettings{'internal.courseowner'};
                     @{$$users{'ow'}{$owner.':'.$cdom}} = 'any';
-                    if (defined($userdata)) {
-                        unless(exists($$userdata{$owner.':'.$cdom})) {
-                            &get_user_info($cdom,$owner,\%idx,$userdata);
-                        }
-                    }
+                    if (defined($userdata) && 
+			!exists($$userdata{$owner.':'.$cdom})) {
+			&get_user_info($cdom,$owner,\%idx,$userdata);
+		    }
                 }
             }
         }