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

albertel lon-capa-cvs@mail.lon-capa.org
Wed, 06 Dec 2006 20:54:14 -0000


This is a MIME encoded message

--albertel1165438454
Content-Type: text/plain

albertel		Wed Dec  6 15:54:14 2006 EDT

  Modified files:              
    /loncom/interface	lonpickstudent.pm 
  Log:
  - style 
  - re strign replacement
  
  
--albertel1165438454
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20061206155414.txt"

Index: loncom/interface/lonpickstudent.pm
diff -u loncom/interface/lonpickstudent.pm:1.19 loncom/interface/lonpickstudent.pm:1.20
--- loncom/interface/lonpickstudent.pm:1.19	Fri Jun  2 09:58:31 2006
+++ loncom/interface/lonpickstudent.pm	Wed Dec  6 15:54:13 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Pick a student from the classlist
 #
-# $Id: lonpickstudent.pm,v 1.19 2006/06/02 13:58:31 raeburn Exp $
+# $Id: lonpickstudent.pm,v 1.20 2006/12/06 20:54:13 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -35,6 +35,7 @@
 use Apache::lonnet;
 use Apache::lonlocal;
 use Apache::longroup;
+use LONCAPA;
 
 sub handler {
     my $r = shift;
@@ -67,10 +68,14 @@
     }
 
 # See if filter present
-
     my $filter=$env{'form.filter'};
-    $filter=~s/\W//g;
-    unless ($filter) { $filter='.'; }
+    my $filtermsg;
+    if ($filter ne '') {
+	$filtermsg = '<br />'.&mt('Name starting with').' "'.$filter.'"<br />';
+	$filter = quotemeta($filter);
+    } else {
+	$filter = '.'
+    }
 
     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
@@ -82,7 +87,7 @@
 # --------------------------------------- There is such a user, get environment
 
     $r->print(<<ENDSCRIPT);
-<script>
+<script type="text/javascript">
 function gochoose(uname,udom) {
     opener.document.$env{'form.form'}.$env{'form.unameelement'}.value=uname;
     var slct=opener.document.$env{'form.form'}.$env{'form.udomelement'};
@@ -94,101 +99,116 @@
 }
 </script>
 ENDSCRIPT
-    
-  $r->print('<form>');
-  if ($allowed && (!$env{'form.roles'})) {
+
+    $r->print('<form>');
+    if ($allowed && (!$env{'form.roles'})) {
 # -------------------------------------------------------- Get course personnel
-    $r->print('<h3>'.$env{'course.'.$env{'request.course.id'}.'.description'}.
-              '</h3>');
-    my %coursepersonnel=
-       &Apache::lonnet::get_course_adv_roles();
-    $r->print('<table border="2">');
-    foreach my $role (sort keys %coursepersonnel) {
-       foreach (split(/\,/,$coursepersonnel{$role})) {
-	   my ($puname,$pudom)=split(/\:/,$_);
-           $role = &Apache::lonnet::plaintext($role,
-                                            &Apache::loncommon::course_type());
-	   $r->print('<tr><td>'.
-             '<input type="button" value="Select" onClick="gochoose('.
-             "'".$puname."','".$pudom."')".'" /></td><td>'.$role.'</td><td>'.
-		     &Apache::loncommon::aboutmewrapper(
-                          &Apache::loncommon::plainname($puname,
-                          $pudom),$puname,$pudom).'</td></tr>');
-	}
-    }
-    $r->print('</table><p>&nbsp;');
-    if ($filter ne '.') {
-       $r->print('<br/ >'.&mt('Name starting with').' "'.$filter.'"<br />');
-    }
-    $r->print('</p><p><table><tr><th>&nbsp;</th><th>username</th><th>domain</th><th>Name</th><th>ID</th><th>section</th><th>active group(s)</th></tr>');
-  # ------------------------------------------------------------------ Students
-    foreach (sort keys %$classlist) {
-        # the following undefs are for 'domain', and 'username' respectively.
-	my (undef,undef,$end,$start,$id,$section,$fullname,$status)=
-            @{$classlist->{$_}};
-	if ($allowed eq 'section' && $section ne $env{'request.course.sec'}) {
-	    next;
+	$r->print('<h3>'.$env{'course.'.$env{'request.course.id'}.'.description'}.
+		  '</h3>');
+	my %coursepersonnel=
+	    &Apache::lonnet::get_course_adv_roles();
+	$r->print(&Apache::loncommon::start_data_table());
+	foreach my $role (sort(keys(%coursepersonnel))) {
+	    foreach (split(/\,/,$coursepersonnel{$role})) {
+		my ($puname,$pudom)=split(/\:/,$_);
+		$role = &Apache::lonnet::plaintext($role,
+						   &Apache::loncommon::course_type());
+		$r->print(&Apache::loncommon::start_data_table_row().
+			  '<td>'.
+			  '<input type="button" value="Select" onClick="gochoose('.
+			  "'".$puname."','".$pudom."')".'" /></td><td>'.$role.'</td><td>'.
+			  &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($puname,$pudom),$puname,$pudom).'</td>'.
+			  &Apache::loncommon::end_data_table_row());
+	    }
 	}
-        if ($_=~/^(\w+)\:(\w+)$/) {
-	    my ($uname,$udom)=($1,$2);
-	    if (($uname=~/^$filter/) || 
-                ($fullname=~/^$filter/i)) {
-               my $grouplist = '';
-               foreach my $group (sort(keys(%allgroups))) {
-                   if (exists($grouplist{$group.':'.$uname.':'.$udom})) {
-                       my ($end,$start) = split(/:/,$grouplist{$group.':'.$uname.':'.$udom});
-                       if (($end!=0) && ($end<$now)) { next; }
-                       if (($start!=0) && ($start>$now)) {next; }
-                       $grouplist .= " $group,"; 
-                   }
-               }
-               $grouplist =~ s/,$//;
-	       $r->print('<tr><td>'.
-                      '<input type="button" value="'.&mt('Select').'" onClick="gochoose('.
-                      "'".$uname."','".$udom."')".'" /></td>'.
-                         '<td><tt>'.$uname.'</tt></td><td> <tt>'.$udom.
-                         '</tt></td><td>'.
-                         &Apache::loncommon::aboutmewrapper(
-                         $fullname,
-                         $uname,$udom).'</td><td>'.$id.'</td><td>'.$section.
-                                       '</td><td>'.$grouplist.'</td></tr>');
-	   }
-        }
-    }
+	$r->print(&Apache::loncommon::end_data_table().'<p>&nbsp;');
 
-    $r->print('</table></p>');
-  } else {
-    $r->print('<h3>'.&mt('Users with Roles Assigned by').' '.
-	      &Apache::loncommon::plainname($env{'user.name'},
-					    $env{'user.domain'}).'</h3>');
-    if ($filter ne '.') {
-       $r->print('<br/ >'.&mt('Name starting with').' "'.$filter.'"<br />');
-    }
-    $r->print('<p><table>');
-    my %users=&Apache::lonnet::get_my_roles();
-    foreach (sort keys %users) {
-        if ($_=~/^(\w+)\:(\w+)\:(\w+)$/) {
-	    my ($uname,$udom,$urole)=($1,$2,$3);
-	    my $fullname=&Apache::loncommon::plainname($uname,$udom);
-	    if (($uname=~/^$filter/) || 
-                ($fullname=~/^$filter/i)) {
-	       $r->print('<tr><td>'.
-                      '<input type="button" value="Select" onClick="gochoose('.
-                      "'".$uname."','".$udom."')".'" /></td>'.
-                         '<td><tt>'.$uname.'</tt></td><td><tt>'.$udom.
-                         '</tt></td><td>'.
-                         &Apache::loncommon::aboutmewrapper(
-                         $fullname,
-                         $uname,$udom).'</td><td><td>'.
-			 &Apache::lonnet::plaintext($urole).
-                                       '</td></tr>');
-	   }
-        }
+	$r->print($filtermsg);
+
+	$r->print('</p><p>'.
+		  &Apache::loncommon::start_data_table().
+		  &Apache::loncommon::start_data_table_header_row().
+		  &Apache::loncommon::end_data_table_header_row().
+		  '<th>&nbsp;</th>'.
+		  '<th>'.&mt('username').'</th>'.
+		  '<th>'.&mt('domain').'</th>'.
+		  '<th>'.&mt('Name').'</th>'.
+		  '<th>'.&mt('ID').'</th>'.
+		  '<th>'.&mt('section').'</th>'.
+		  '<th>'.&mt('active group(s)').'</th>'.
+		  &Apache::loncommon::end_data_table_header_row());
+# ------------------------------------------------------------------ Students
+	foreach my $user (sort(keys(%$classlist))) {
+	    # the following undefs are for 'domain', and 'username' respectively.
+	    my (undef,undef,$end,$start,$id,$section,$fullname,$status)=
+		@{$classlist->{$user}};
+	    if ($allowed eq 'section' && $section ne $env{'request.course.sec'}) {
+		next;
+	    }
+	    if ($user=~/^($LONCAPA::username_re)\:($LONCAPA::domain_re)$/) {
+		my ($uname,$udom)=($1,$2);
+		if (($uname=~/^$filter/) || 
+		    ($fullname=~/^$filter/i)) {
+		    my $grouplist = '';
+		    foreach my $group (sort(keys(%allgroups))) {
+			if (exists($grouplist{$group.':'.$uname.':'.$udom})) {
+			    my ($end,$start) = split(/:/,$grouplist{$group.':'.$uname.':'.$udom});
+			    if (($end!=0) && ($end<$now)) { next; }
+			    if (($start!=0) && ($start>$now)) {next; }
+			    $grouplist .= " $group,"; 
+			}
+		    }
+		    $grouplist =~ s/,$//;
+		    $r->print(&Apache::loncommon::start_data_table_row().
+			      '<td>'.
+			      '<input type="button" value="'.&mt('Select').'" onClick="gochoose('.
+			      "'".$uname."','".$udom."')".'" /></td>'.
+			      '<td><tt>'.$uname.'</tt></td><td> <tt>'.$udom.
+			      '</tt></td><td>'.
+			      &Apache::loncommon::aboutmewrapper($fullname,
+								 $uname,$udom).
+			      '</td><td>'.$id.'</td><td>'.$section.
+			      '</td><td>'.$grouplist.'</td>'.
+			      &Apache::loncommon::end_data_table_row());
+		}
+	    }
+	}
+	
+	$r->print(&Apache::loncommon::end_data_table().'</p>');
+    } else {
+	$r->print('<h3>'.&mt('Users with Roles Assigned by').' '.
+		  &Apache::loncommon::plainname($env{'user.name'},
+						$env{'user.domain'}).'</h3>');
+	$r->print($filtermsg);
+
+	$r->print('<p>'.&Apache::loncommon::start_data_table());
+	my %users=&Apache::lonnet::get_my_roles();
+	foreach my $user (sort(keys(%users))) {
+	    if ($user =~
+		/^($LONCAPA::username_re)\:($LONCAPA::domain_re)\:(\w+)$/) {
+		my ($uname,$udom,$urole)=($1,$2,$3);
+		my $fullname=&Apache::loncommon::plainname($uname,$udom);
+		if (($uname=~/^$filter/) || 
+		    ($fullname=~/^$filter/i)) {
+		    $r->print(&Apache::loncommon::start_data_table_row().
+			      '<td>'.
+			      '<input type="button" value="Select" onClick="gochoose('.
+			      "'".$uname."','".$udom."')".'" /></td>'.
+			      '<td><tt>'.$uname.'</tt></td><td><tt>'.$udom.
+			      '</tt></td><td>'.
+			      &Apache::loncommon::aboutmewrapper(
+								 $fullname,
+								 $uname,$udom).'</td><td><td>'.
+			      &Apache::lonnet::plaintext($urole).
+			      '</td>'.
+			      &Apache::loncommon::end_data_table_row());
+		}
+	    }
+	}
+	$r->print(&Apache::loncommon::end_data_table().'</p>');
     }
-    $r->print('</table></p>');
-  }
-  $r->print('</form>'.&Apache::loncommon::end_page());
-  return OK;
+    $r->print('</form>'.&Apache::loncommon::end_page());
+    return OK;
 } 
 
 1;

--albertel1165438454--