Annotation of loncom/interface/lonpickstudent.pm, revision 1.22

1.1       www         1: # The LearningOnline Network
                      2: # Pick a student from the classlist
                      3: #
1.22    ! albertel    4: # $Id: lonpickstudent.pm,v 1.21 2007/07/21 00:48:55 albertel Exp $
1.1       www         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;
1.7       www        36: use Apache::lonlocal;
1.17      raeburn    37: use Apache::longroup;
1.20      albertel   38: use LONCAPA;
1.1       www        39: 
                     40: sub handler {
                     41:     my $r = shift;
1.7       www        42:     &Apache::loncommon::content_type($r,'text/html');
1.1       www        43:     $r->send_http_header;
                     44:     return OK if $r->header_only;
                     45: 
                     46: # ------------------------------------------------------------ Print the screen
1.13      albertel   47:     $r->print(&Apache::loncommon::start_page("Selecting a User",undef,
                     48: 					     {'no_nav_bar' => 1}));
1.6       www        49: 
                     50: 
                     51:     &Apache::loncommon::get_unprocessed_cgi
                     52:         ($ENV{'QUERY_STRING'},['filter','form','unameelement','udomelement',
                     53: 			       'roles']);
                     54: # Allowed?
1.10      albertel   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:     }
1.6       www        62: 
1.9       albertel   63:     unless (($env{'form.roles'}) ||
1.10      albertel   64:             (($env{'request.course.id'}) && ($allowed))) {
1.11      albertel   65: 	$r->print(&mt('No context.').
                     66: 		  &Apache::loncommon::end_page());
1.1       www        67:         return OK;
                     68:     }
1.2       www        69: 
1.6       www        70: # See if filter present
1.9       albertel   71:     my $filter=$env{'form.filter'};
1.20      albertel   72:     my $filtermsg;
1.22    ! albertel   73:     my $encoded_filter = &HTML::Entities::encode($filter,'<>&"');
        !            74:     $filter = quotemeta($filter);
        !            75:     my $change = &mt('Change');
        !            76:     my $filterbutton =<<FILTER;
1.21      albertel   77:   <input type="text" name="filter" value="$encoded_filter" />
                     78:   <input type="submit" name="Change" value="$change" />
                     79: FILTER
1.22    ! albertel   80:     foreach my $name ('form','unameelement','udomelement','roles') {
        !            81: 	my $value = &HTML::Entities::encode($env{"form.$name"},'<>&"');
        !            82: 	$filterbutton .= <<HIDDEN;
1.21      albertel   83:    <input type="hidden" name="$name" value="$value" />
                     84: HIDDEN
1.22    ! albertel   85:     }
        !            86:     $filtermsg = '<br />'.
        !            87: 	&mt('Showing users with a name starting with [_1]',
        !            88: 	    $filterbutton).'<br />';
        !            89:     if ($filter eq '') {
        !            90: 	$filter = '.'
1.20      albertel   91:     }
1.1       www        92: 
1.12      raeburn    93:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                     94:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.3       www        95:     my $classlist=&Apache::loncoursedata::get_classlist();
1.12      raeburn    96:     my %grouplist=&Apache::lonnet::get_group_membership($cdom,$cnum);
                     97:     my $now = time;
1.17      raeburn    98:     my %allgroups = &Apache::longroup::coursegroups($cdom,$cnum);
1.12      raeburn    99: 
1.1       www       100: # --------------------------------------- There is such a user, get environment
                    101: 
1.2       www       102:     $r->print(<<ENDSCRIPT);
1.20      albertel  103: <script type="text/javascript">
1.2       www       104: function gochoose(uname,udom) {
1.9       albertel  105:     opener.document.$env{'form.form'}.$env{'form.unameelement'}.value=uname;
                    106:     var slct=opener.document.$env{'form.form'}.$env{'form.udomelement'};
1.2       www       107:     var i;
                    108:     for (i=0;i<slct.length;i++) {
1.4       www       109:         if (slct.options[i].value==udom) { slct.selectedIndex=i; }
1.2       www       110:     }
                    111:     self.close();
                    112: }
                    113: </script>
                    114: ENDSCRIPT
1.20      albertel  115: 
                    116:     $r->print('<form>');
                    117:     if ($allowed && (!$env{'form.roles'})) {
1.6       www       118: # -------------------------------------------------------- Get course personnel
1.20      albertel  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 (split(/\,/,$coursepersonnel{$role})) {
                    126: 		my ($puname,$pudom)=split(/\:/,$_);
                    127: 		$role = &Apache::lonnet::plaintext($role,
                    128: 						   &Apache::loncommon::course_type());
                    129: 		$r->print(&Apache::loncommon::start_data_table_row().
                    130: 			  '<td>'.
                    131: 			  '<input type="button" value="Select" onClick="gochoose('.
                    132: 			  "'".$puname."','".$pudom."')".'" /></td><td>'.$role.'</td><td>'.
                    133: 			  &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($puname,$pudom),$puname,$pudom).'</td>'.
                    134: 			  &Apache::loncommon::end_data_table_row());
                    135: 	    }
                    136: 	}
                    137: 	$r->print(&Apache::loncommon::end_data_table().'<p>&nbsp;');
                    138: 
                    139: 	$r->print($filtermsg);
                    140: 
1.22    ! albertel  141: 	$r->print('</p>');
        !           142: 
1.20      albertel  143: # ------------------------------------------------------------------ Students
1.22    ! albertel  144: 	my $result;
1.20      albertel  145: 	foreach my $user (sort(keys(%$classlist))) {
                    146: 	    # the following undefs are for 'domain', and 'username' respectively.
                    147: 	    my (undef,undef,$end,$start,$id,$section,$fullname,$status)=
                    148: 		@{$classlist->{$user}};
                    149: 	    if ($allowed eq 'section' && $section ne $env{'request.course.sec'}) {
                    150: 		next;
                    151: 	    }
                    152: 	    if ($user=~/^($LONCAPA::username_re)\:($LONCAPA::domain_re)$/) {
                    153: 		my ($uname,$udom)=($1,$2);
                    154: 		if (($uname=~/^$filter/) || 
                    155: 		    ($fullname=~/^$filter/i)) {
                    156: 		    my $grouplist = '';
                    157: 		    foreach my $group (sort(keys(%allgroups))) {
                    158: 			if (exists($grouplist{$group.':'.$uname.':'.$udom})) {
                    159: 			    my ($end,$start) = split(/:/,$grouplist{$group.':'.$uname.':'.$udom});
                    160: 			    if (($end!=0) && ($end<$now)) { next; }
                    161: 			    if (($start!=0) && ($start>$now)) {next; }
                    162: 			    $grouplist .= " $group,"; 
                    163: 			}
                    164: 		    }
                    165: 		    $grouplist =~ s/,$//;
1.22    ! albertel  166: 		    $result .=&Apache::loncommon::start_data_table_row().
1.20      albertel  167: 			      '<td>'.
                    168: 			      '<input type="button" value="'.&mt('Select').'" onClick="gochoose('.
                    169: 			      "'".$uname."','".$udom."')".'" /></td>'.
                    170: 			      '<td><tt>'.$uname.'</tt></td><td> <tt>'.$udom.
                    171: 			      '</tt></td><td>'.
                    172: 			      &Apache::loncommon::aboutmewrapper($fullname,
                    173: 								 $uname,$udom).
                    174: 			      '</td><td>'.$id.'</td><td>'.$section.
                    175: 			      '</td><td>'.$grouplist.'</td>'.
1.22    ! albertel  176: 			      &Apache::loncommon::end_data_table_row();
1.20      albertel  177: 		}
                    178: 	    }
1.4       www       179: 	}
1.22    ! albertel  180: 	if (!$result) {
        !           181: 	    $r->print('<p>'.&mt('No students found.').'</p>');
        !           182: 	} else {
        !           183: 	    $r->print(&Apache::loncommon::start_data_table().
        !           184: 		      &Apache::loncommon::start_data_table_header_row().
        !           185: 		      &Apache::loncommon::end_data_table_header_row().
        !           186: 		      '<th>&nbsp;</th>'.
        !           187: 		      '<th>'.&mt('username').'</th>'.
        !           188: 		      '<th>'.&mt('domain').'</th>'.
        !           189: 		      '<th>'.&mt('Name').'</th>'.
        !           190: 		      '<th>'.&mt('ID').'</th>'.
        !           191: 		      '<th>'.&mt('section').'</th>'.
        !           192: 		      '<th>'.&mt('active group(s)').'</th>'.
        !           193: 		      &Apache::loncommon::end_data_table_header_row().
        !           194: 		      $result.
        !           195: 		      &Apache::loncommon::end_data_table());
        !           196: 	}
1.20      albertel  197:     } else {
                    198: 	$r->print('<h3>'.&mt('Users with Roles Assigned by').' '.
                    199: 		  &Apache::loncommon::plainname($env{'user.name'},
                    200: 						$env{'user.domain'}).'</h3>');
                    201: 	$r->print($filtermsg);
                    202: 
                    203: 	$r->print('<p>'.&Apache::loncommon::start_data_table());
                    204: 	my %users=&Apache::lonnet::get_my_roles();
                    205: 	foreach my $user (sort(keys(%users))) {
                    206: 	    if ($user =~
                    207: 		/^($LONCAPA::username_re)\:($LONCAPA::domain_re)\:(\w+)$/) {
                    208: 		my ($uname,$udom,$urole)=($1,$2,$3);
                    209: 		my $fullname=&Apache::loncommon::plainname($uname,$udom);
                    210: 		if (($uname=~/^$filter/) || 
                    211: 		    ($fullname=~/^$filter/i)) {
                    212: 		    $r->print(&Apache::loncommon::start_data_table_row().
                    213: 			      '<td>'.
                    214: 			      '<input type="button" value="Select" onClick="gochoose('.
                    215: 			      "'".$uname."','".$udom."')".'" /></td>'.
                    216: 			      '<td><tt>'.$uname.'</tt></td><td><tt>'.$udom.
                    217: 			      '</tt></td><td>'.
                    218: 			      &Apache::loncommon::aboutmewrapper(
                    219: 								 $fullname,
                    220: 								 $uname,$udom).'</td><td><td>'.
                    221: 			      &Apache::lonnet::plaintext($urole).
                    222: 			      '</td>'.
                    223: 			      &Apache::loncommon::end_data_table_row());
                    224: 		}
                    225: 	    }
1.10      albertel  226: 	}
1.20      albertel  227: 	$r->print(&Apache::loncommon::end_data_table().'</p>');
1.6       www       228:     }
1.20      albertel  229:     $r->print('</form>'.&Apache::loncommon::end_page());
                    230:     return OK;
1.1       www       231: } 
                    232: 
                    233: 1;
                    234: __END__

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