File:  [LON-CAPA] / loncom / interface / lonpickstudent.pm
Revision 1.26: download - view: text, annotated - select for diffs
Sun Mar 1 01:17:20 2009 UTC (15 years, 3 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_8_X, version_2_8_2, version_2_8_1, HEAD, GCI_1
- Remove redundant call to lonnet::plaintext().
   - Keys in hash returned from lonnet::get_course_adv_roles() already passed
     through lonnet::plaintext().

    1: # The LearningOnline Network
    2: # Pick a student from the classlist
    3: #
    4: # $Id: lonpickstudent.pm,v 1.26 2009/03/01 01:17:20 raeburn Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: 
   29: package Apache::lonpickstudent;
   30: 
   31: use strict;
   32: use Apache::Constants qw(:common);
   33: use Apache::loncommon;
   34: use Apache::loncoursedata;
   35: use Apache::lonnet;
   36: use Apache::lonlocal;
   37: use Apache::longroup;
   38: use LONCAPA;
   39: 
   40: sub handler {
   41:     my $r = shift;
   42:     &Apache::loncommon::content_type($r,'text/html');
   43:     $r->send_http_header;
   44:     return OK if $r->header_only;
   45: 
   46: # ------------------------------------------------------------ Print the screen
   47:     $r->print(&Apache::loncommon::start_page("Selecting a User",undef,
   48: 					     {'no_nav_bar' => 1}));
   49: 
   50: 
   51:     &Apache::loncommon::get_unprocessed_cgi
   52:         ($ENV{'QUERY_STRING'},['filter','form','unameelement','udomelement',
   53: 			       'roles']);
   54: # Allowed?
   55:     my $allowed;
   56:     my $scope = $env{'request.course.id'};
   57:     if (!($allowed = &Apache::lonnet::allowed('srm',$scope))) {
   58: 	$scope .= '/'.$env{'request.course.sec'};
   59: 	$allowed = &Apache::lonnet::allowed('srm',$scope);
   60: 	if ($allowed) { $allowed = 'section';	}
   61:     }
   62: 
   63:     unless (($env{'form.roles'}) ||
   64:             (($env{'request.course.id'}) && ($allowed))) {
   65: 	$r->print(&mt('No context.').
   66: 		  &Apache::loncommon::end_page());
   67:         return OK;
   68:     }
   69: 
   70: # See if filter present
   71:     my $filter=$env{'form.filter'};
   72:     my $filtermsg;
   73:     my $encoded_filter = &HTML::Entities::encode($filter,'<>&"');
   74:     $filter = quotemeta($filter);
   75:     my $change = &mt('Change');
   76:     my $filterbutton =<<FILTER;
   77:   <input type="text" name="filter" value="$encoded_filter" />
   78:   <input type="submit" name="Change" value="$change" />
   79: FILTER
   80:     foreach my $name ('form','unameelement','udomelement','roles') {
   81: 	my $value = &HTML::Entities::encode($env{"form.$name"},'<>&"');
   82: 	$filterbutton .= <<HIDDEN;
   83:    <input type="hidden" name="$name" value="$value" />
   84: HIDDEN
   85:     }
   86:     $filtermsg = '<br />'.
   87: 	&mt('Showing users with a name starting with [_1]',
   88: 	    $filterbutton).'<br />';
   89:     if ($filter eq '') {
   90: 	$filter = '.'
   91:     }
   92: 
   93:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
   94:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
   95:     my $classlist=&Apache::loncoursedata::get_classlist();
   96:     my %grouplist=&Apache::lonnet::get_group_membership($cdom,$cnum);
   97:     my $now = time;
   98:     my %allgroups = &Apache::longroup::coursegroups($cdom,$cnum);
   99: 
  100: # --------------------------------------- There is such a user, get environment
  101: 
  102:     $r->print(<<ENDSCRIPT);
  103: <script type="text/javascript">
  104: function gochoose(uname,udom) {
  105:     opener.document.$env{'form.form'}.$env{'form.unameelement'}.value=uname;
  106:     var slct=opener.document.$env{'form.form'}.$env{'form.udomelement'};
  107:     var i;
  108:     for (i=0;i<slct.length;i++) {
  109:         if (slct.options[i].value==udom) { slct.selectedIndex=i; }
  110:     }
  111:     self.close();
  112: }
  113: </script>
  114: ENDSCRIPT
  115: 
  116:     $r->print('<form>');
  117:     if ($allowed && (!$env{'form.roles'})) {
  118: # -------------------------------------------------------- Get course personnel
  119: 	$r->print('<h3>'.$env{'course.'.$env{'request.course.id'}.'.description'}.
  120: 		  '</h3>');
  121: 	my %coursepersonnel=
  122: 	    &Apache::lonnet::get_course_adv_roles();
  123: 	$r->print(&Apache::loncommon::start_data_table());
  124: 	foreach my $role (sort(keys(%coursepersonnel))) {
  125: 	    foreach my $user (split(/\,/,$coursepersonnel{$role})) {
  126: 		my ($puname,$pudom)=split(/\:/,$user);
  127: 		$r->print(&Apache::loncommon::start_data_table_row().
  128: 			  '<td>'.
  129: 			  '<input type="button" value="'.&mt('Select').'" onClick="gochoose('.
  130: 			  "'".$puname."','".$pudom."')".'" /></td><td>'.$role.'</td><td>'.
  131: 			  &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($puname,$pudom),$puname,$pudom).'</td>'.
  132: 			  &Apache::loncommon::end_data_table_row());
  133: 	    }
  134: 	}
  135: 	$r->print(&Apache::loncommon::end_data_table().'<p>&nbsp;');
  136: 
  137: 	$r->print($filtermsg);
  138: 
  139: 	$r->print('</p>');
  140: 
  141: # ------------------------------------------------------------------ Students
  142: 	my $result;
  143: 	foreach my $user (sort(keys(%$classlist))) {
  144: 	    # the following undefs are for 'domain', and 'username' respectively.
  145: 	    my (undef,undef,$end,$start,$id,$section,$fullname,$status)=
  146: 		@{$classlist->{$user}};
  147: 	    if ($allowed eq 'section' && $section ne $env{'request.course.sec'}) {
  148: 		next;
  149: 	    }
  150: 	    if ($user=~/^($LONCAPA::username_re)\:($LONCAPA::domain_re)$/) {
  151: 		my ($uname,$udom)=($1,$2);
  152: 		if (($uname=~/^$filter/) || 
  153: 		    ($fullname=~/^$filter/i)) {
  154: 		    my $grouplist = '';
  155: 		    foreach my $group (sort(keys(%allgroups))) {
  156: 			if (exists($grouplist{$group.':'.$uname.':'.$udom})) {
  157: 			    my ($end,$start) = split(/:/,$grouplist{$group.':'.$uname.':'.$udom});
  158: 			    if (($end!=0) && ($end<$now)) { next; }
  159: 			    if (($start!=0) && ($start>$now)) {next; }
  160: 			    $grouplist .= " $group,"; 
  161: 			}
  162: 		    }
  163: 		    $grouplist =~ s/,$//;
  164: 		    $result .=&Apache::loncommon::start_data_table_row().
  165: 			      '<td>'.
  166: 			      '<input type="button" value="'.&mt('Select').'" onClick="gochoose('.
  167: 			      "'".$uname."','".$udom."')".'" /></td>'.
  168: 			      '<td><tt>'.$uname.'</tt></td><td> <tt>'.$udom.
  169: 			      '</tt></td><td>'.
  170: 			      &Apache::loncommon::aboutmewrapper($fullname,
  171: 								 $uname,$udom).
  172: 			      '</td><td>'.$id.'</td><td>'.$section.
  173: 			      '</td><td>'.$grouplist.'</td>'.
  174: 			      &Apache::loncommon::end_data_table_row();
  175: 		}
  176: 	    }
  177: 	}
  178: 	if (!$result) {
  179: 	    $r->print('<p>'.&mt('No students found.').'</p>');
  180: 	} else {
  181: 	    $r->print(&Apache::loncommon::start_data_table().
  182: 		      &Apache::loncommon::start_data_table_header_row().
  183: 		      &Apache::loncommon::end_data_table_header_row().
  184: 		      '<th>&nbsp;</th>'.
  185: 		      '<th>'.&mt('username').'</th>'.
  186: 		      '<th>'.&mt('domain').'</th>'.
  187: 		      '<th>'.&mt('Name').'</th>'.
  188: 		      '<th>'.&mt('ID').'</th>'.
  189: 		      '<th>'.&mt('section').'</th>'.
  190: 		      '<th>'.&mt('active group(s)').'</th>'.
  191: 		      &Apache::loncommon::end_data_table_header_row().
  192: 		      $result.
  193: 		      &Apache::loncommon::end_data_table());
  194: 	}
  195:     } else {
  196: 	$r->print('<h3>'.&mt('Users with Roles Assigned by').' '.
  197: 		  &Apache::loncommon::plainname($env{'user.name'},
  198: 						$env{'user.domain'}).'</h3>');
  199: 	$r->print($filtermsg);
  200: 
  201: 	$r->print('<p>'.&Apache::loncommon::start_data_table());
  202: 	my %user_role=&Apache::lonnet::get_my_roles();
  203: 	my %users;
  204: 	foreach my $user_role (keys(%user_role)) {
  205: 	    next if ($user_role !~
  206: 		     /^($LONCAPA::username_re):($LONCAPA::domain_re):(\w+)$/);
  207: 	    my ($uname,$udom,$urole)=($1,$2,$3);
  208: 	    my $fullname=&Apache::loncommon::plainname($uname,$udom);
  209: 	    next if (($uname!~/^$filter/i) && ($fullname !~/^$filter/i));
  210: 	    
  211: 	    if (!exists($users{"$uname:$udom"})) {
  212: 		$users{"$uname:$udom"} = {'fullname' => $fullname };
  213: 	    }
  214: 	    push(@{$users{"$uname:$udom"}{'roles'}},$urole);
  215: 	}
  216: 	foreach my $user (sort {lc($a) cmp lc($b)} (keys(%users))) {
  217: 	    my ($uname,$udom) = split(':',$user);
  218: 	    $r->print(&Apache::loncommon::start_data_table_row().
  219: 		      '<td>'.
  220: 		      '<input type="button" value="'.&mt('Select').'" onClick="gochoose('.
  221: 		      "'".$uname."','".$udom."')".'" /></td>'.
  222: 		      '<td><tt>'.$uname.'</tt></td>'.
  223: 		      '<td><tt>'.$udom.'</tt></td><td>'.
  224: 		      &Apache::loncommon::aboutmewrapper($users{$user}{'fullname'},
  225: 							 $uname,$udom).'</td>'.
  226: 		      '<td>'.
  227: 		      join(', ',sort(map {&Apache::lonnet::plaintext($_)}
  228: 				         (@{$users{$user}{'roles'}}))).
  229: 		      '</td>'.
  230: 		      &Apache::loncommon::end_data_table_row());
  231: 	}
  232: 	$r->print(&Apache::loncommon::end_data_table().'</p>');
  233:     }
  234:     $r->print('</form>'.&Apache::loncommon::end_page());
  235:     return OK;
  236: } 
  237: 
  238: 1;
  239: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>