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

1.1       www         1: # The LearningOnline Network
                      2: # Pick a student from the classlist
                      3: #
1.20    ! albertel    4: # $Id: lonpickstudent.pm,v 1.19 2006/06/02 13:58:31 raeburn 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;
        !            73:     if ($filter ne '') {
        !            74: 	$filtermsg = '<br />'.&mt('Name starting with').' "'.$filter.'"<br />';
        !            75: 	$filter = quotemeta($filter);
        !            76:     } else {
        !            77: 	$filter = '.'
        !            78:     }
1.1       www        79: 
1.12      raeburn    80:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                     81:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.3       www        82:     my $classlist=&Apache::loncoursedata::get_classlist();
1.12      raeburn    83:     my %grouplist=&Apache::lonnet::get_group_membership($cdom,$cnum);
                     84:     my $now = time;
1.17      raeburn    85:     my %allgroups = &Apache::longroup::coursegroups($cdom,$cnum);
1.12      raeburn    86: 
1.1       www        87: # --------------------------------------- There is such a user, get environment
                     88: 
1.2       www        89:     $r->print(<<ENDSCRIPT);
1.20    ! albertel   90: <script type="text/javascript">
1.2       www        91: function gochoose(uname,udom) {
1.9       albertel   92:     opener.document.$env{'form.form'}.$env{'form.unameelement'}.value=uname;
                     93:     var slct=opener.document.$env{'form.form'}.$env{'form.udomelement'};
1.2       www        94:     var i;
                     95:     for (i=0;i<slct.length;i++) {
1.4       www        96:         if (slct.options[i].value==udom) { slct.selectedIndex=i; }
1.2       www        97:     }
                     98:     self.close();
                     99: }
                    100: </script>
                    101: ENDSCRIPT
1.20    ! albertel  102: 
        !           103:     $r->print('<form>');
        !           104:     if ($allowed && (!$env{'form.roles'})) {
1.6       www       105: # -------------------------------------------------------- Get course personnel
1.20    ! albertel  106: 	$r->print('<h3>'.$env{'course.'.$env{'request.course.id'}.'.description'}.
        !           107: 		  '</h3>');
        !           108: 	my %coursepersonnel=
        !           109: 	    &Apache::lonnet::get_course_adv_roles();
        !           110: 	$r->print(&Apache::loncommon::start_data_table());
        !           111: 	foreach my $role (sort(keys(%coursepersonnel))) {
        !           112: 	    foreach (split(/\,/,$coursepersonnel{$role})) {
        !           113: 		my ($puname,$pudom)=split(/\:/,$_);
        !           114: 		$role = &Apache::lonnet::plaintext($role,
        !           115: 						   &Apache::loncommon::course_type());
        !           116: 		$r->print(&Apache::loncommon::start_data_table_row().
        !           117: 			  '<td>'.
        !           118: 			  '<input type="button" value="Select" onClick="gochoose('.
        !           119: 			  "'".$puname."','".$pudom."')".'" /></td><td>'.$role.'</td><td>'.
        !           120: 			  &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($puname,$pudom),$puname,$pudom).'</td>'.
        !           121: 			  &Apache::loncommon::end_data_table_row());
        !           122: 	    }
        !           123: 	}
        !           124: 	$r->print(&Apache::loncommon::end_data_table().'<p>&nbsp;');
        !           125: 
        !           126: 	$r->print($filtermsg);
        !           127: 
        !           128: 	$r->print('</p><p>'.
        !           129: 		  &Apache::loncommon::start_data_table().
        !           130: 		  &Apache::loncommon::start_data_table_header_row().
        !           131: 		  &Apache::loncommon::end_data_table_header_row().
        !           132: 		  '<th>&nbsp;</th>'.
        !           133: 		  '<th>'.&mt('username').'</th>'.
        !           134: 		  '<th>'.&mt('domain').'</th>'.
        !           135: 		  '<th>'.&mt('Name').'</th>'.
        !           136: 		  '<th>'.&mt('ID').'</th>'.
        !           137: 		  '<th>'.&mt('section').'</th>'.
        !           138: 		  '<th>'.&mt('active group(s)').'</th>'.
        !           139: 		  &Apache::loncommon::end_data_table_header_row());
        !           140: # ------------------------------------------------------------------ Students
        !           141: 	foreach my $user (sort(keys(%$classlist))) {
        !           142: 	    # the following undefs are for 'domain', and 'username' respectively.
        !           143: 	    my (undef,undef,$end,$start,$id,$section,$fullname,$status)=
        !           144: 		@{$classlist->{$user}};
        !           145: 	    if ($allowed eq 'section' && $section ne $env{'request.course.sec'}) {
        !           146: 		next;
        !           147: 	    }
        !           148: 	    if ($user=~/^($LONCAPA::username_re)\:($LONCAPA::domain_re)$/) {
        !           149: 		my ($uname,$udom)=($1,$2);
        !           150: 		if (($uname=~/^$filter/) || 
        !           151: 		    ($fullname=~/^$filter/i)) {
        !           152: 		    my $grouplist = '';
        !           153: 		    foreach my $group (sort(keys(%allgroups))) {
        !           154: 			if (exists($grouplist{$group.':'.$uname.':'.$udom})) {
        !           155: 			    my ($end,$start) = split(/:/,$grouplist{$group.':'.$uname.':'.$udom});
        !           156: 			    if (($end!=0) && ($end<$now)) { next; }
        !           157: 			    if (($start!=0) && ($start>$now)) {next; }
        !           158: 			    $grouplist .= " $group,"; 
        !           159: 			}
        !           160: 		    }
        !           161: 		    $grouplist =~ s/,$//;
        !           162: 		    $r->print(&Apache::loncommon::start_data_table_row().
        !           163: 			      '<td>'.
        !           164: 			      '<input type="button" value="'.&mt('Select').'" onClick="gochoose('.
        !           165: 			      "'".$uname."','".$udom."')".'" /></td>'.
        !           166: 			      '<td><tt>'.$uname.'</tt></td><td> <tt>'.$udom.
        !           167: 			      '</tt></td><td>'.
        !           168: 			      &Apache::loncommon::aboutmewrapper($fullname,
        !           169: 								 $uname,$udom).
        !           170: 			      '</td><td>'.$id.'</td><td>'.$section.
        !           171: 			      '</td><td>'.$grouplist.'</td>'.
        !           172: 			      &Apache::loncommon::end_data_table_row());
        !           173: 		}
        !           174: 	    }
1.4       www       175: 	}
1.20    ! albertel  176: 	
        !           177: 	$r->print(&Apache::loncommon::end_data_table().'</p>');
        !           178:     } else {
        !           179: 	$r->print('<h3>'.&mt('Users with Roles Assigned by').' '.
        !           180: 		  &Apache::loncommon::plainname($env{'user.name'},
        !           181: 						$env{'user.domain'}).'</h3>');
        !           182: 	$r->print($filtermsg);
        !           183: 
        !           184: 	$r->print('<p>'.&Apache::loncommon::start_data_table());
        !           185: 	my %users=&Apache::lonnet::get_my_roles();
        !           186: 	foreach my $user (sort(keys(%users))) {
        !           187: 	    if ($user =~
        !           188: 		/^($LONCAPA::username_re)\:($LONCAPA::domain_re)\:(\w+)$/) {
        !           189: 		my ($uname,$udom,$urole)=($1,$2,$3);
        !           190: 		my $fullname=&Apache::loncommon::plainname($uname,$udom);
        !           191: 		if (($uname=~/^$filter/) || 
        !           192: 		    ($fullname=~/^$filter/i)) {
        !           193: 		    $r->print(&Apache::loncommon::start_data_table_row().
        !           194: 			      '<td>'.
        !           195: 			      '<input type="button" value="Select" onClick="gochoose('.
        !           196: 			      "'".$uname."','".$udom."')".'" /></td>'.
        !           197: 			      '<td><tt>'.$uname.'</tt></td><td><tt>'.$udom.
        !           198: 			      '</tt></td><td>'.
        !           199: 			      &Apache::loncommon::aboutmewrapper(
        !           200: 								 $fullname,
        !           201: 								 $uname,$udom).'</td><td><td>'.
        !           202: 			      &Apache::lonnet::plaintext($urole).
        !           203: 			      '</td>'.
        !           204: 			      &Apache::loncommon::end_data_table_row());
        !           205: 		}
        !           206: 	    }
1.10      albertel  207: 	}
1.20    ! albertel  208: 	$r->print(&Apache::loncommon::end_data_table().'</p>');
1.6       www       209:     }
1.20    ! albertel  210:     $r->print('</form>'.&Apache::loncommon::end_page());
        !           211:     return OK;
1.1       www       212: } 
                    213: 
                    214: 1;
                    215: __END__

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