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

1.1       www         1: # The LearningOnline Network
                      2: # Pick a student from the classlist
                      3: #
1.13    ! albertel    4: # $Id: lonpickstudent.pm,v 1.12 2006/03/16 21:15:16 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.1       www        37: 
                     38: sub handler {
                     39:     my $r = shift;
1.7       www        40:     &Apache::loncommon::content_type($r,'text/html');
1.1       www        41:     $r->send_http_header;
                     42:     return OK if $r->header_only;
                     43: 
                     44: # ------------------------------------------------------------ Print the screen
1.13    ! albertel   45:     $r->print(&Apache::loncommon::start_page("Selecting a User",undef,
        !            46: 					     {'no_nav_bar' => 1}));
1.6       www        47: 
                     48: 
                     49:     &Apache::loncommon::get_unprocessed_cgi
                     50:         ($ENV{'QUERY_STRING'},['filter','form','unameelement','udomelement',
                     51: 			       'roles']);
                     52: # Allowed?
1.10      albertel   53:     my $allowed;
                     54:     my $scope = $env{'request.course.id'};
                     55:     if (!($allowed = &Apache::lonnet::allowed('srm',$scope))) {
                     56: 	$scope .= '/'.$env{'request.course.sec'};
                     57: 	$allowed = &Apache::lonnet::allowed('srm',$scope);
                     58: 	if ($allowed) { $allowed = 'section';	}
                     59:     }
1.6       www        60: 
1.9       albertel   61:     unless (($env{'form.roles'}) ||
1.10      albertel   62:             (($env{'request.course.id'}) && ($allowed))) {
1.11      albertel   63: 	$r->print(&mt('No context.').
                     64: 		  &Apache::loncommon::end_page());
1.1       www        65:         return OK;
                     66:     }
1.2       www        67: 
1.6       www        68: # See if filter present
1.1       www        69: 
1.9       albertel   70:     my $filter=$env{'form.filter'};
1.2       www        71:     $filter=~s/\W//g;
                     72:     unless ($filter) { $filter='.'; }
1.1       www        73: 
1.12      raeburn    74:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                     75:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.3       www        76:     my $classlist=&Apache::loncoursedata::get_classlist();
1.12      raeburn    77:     my %grouplist=&Apache::lonnet::get_group_membership($cdom,$cnum);
                     78:     my $now = time;
                     79:     my %allgroups;
                     80:     my @coursegroups = ();
                     81:     if (&Apache::loncommon::coursegroups(\%allgroups,$cdom,$cnum)) {
                     82:         @coursegroups = keys(%allgroups);
                     83:     }
                     84: 
1.1       www        85: # --------------------------------------- There is such a user, get environment
                     86: 
1.2       www        87:     $r->print(<<ENDSCRIPT);
                     88: <script>
                     89: function gochoose(uname,udom) {
1.9       albertel   90:     opener.document.$env{'form.form'}.$env{'form.unameelement'}.value=uname;
                     91:     var slct=opener.document.$env{'form.form'}.$env{'form.udomelement'};
1.2       www        92:     var i;
                     93:     for (i=0;i<slct.length;i++) {
1.4       www        94:         if (slct.options[i].value==udom) { slct.selectedIndex=i; }
1.2       www        95:     }
                     96:     self.close();
                     97: }
                     98: </script>
                     99: ENDSCRIPT
                    100:     
1.6       www       101:   $r->print('<form>');
1.10      albertel  102:   if ($allowed && (!$env{'form.roles'})) {
1.6       www       103: # -------------------------------------------------------- Get course personnel
1.9       albertel  104:     $r->print('<h3>'.$env{'course.'.$env{'request.course.id'}.'.description'}.
1.6       www       105:               '</h3>');
1.4       www       106:     my %coursepersonnel=
                    107:        &Apache::lonnet::get_course_adv_roles();
                    108:     $r->print('<table border="2">');
1.5       www       109:     foreach my $role (sort keys %coursepersonnel) {
1.4       www       110:        foreach (split(/\,/,$coursepersonnel{$role})) {
                    111: 	   my ($puname,$pudom)=split(/\:/,$_);
                    112: 	   $r->print('<tr><td>'.
                    113:              '<input type="button" value="Select" onClick="gochoose('.
                    114:              "'".$puname."','".$pudom."')".'" /></td><td>'.$role.'</td><td>'.
                    115: 		     &Apache::loncommon::aboutmewrapper(
                    116:                           &Apache::loncommon::plainname($puname,
                    117:                           $pudom),$puname,$pudom).'</td></tr>');
                    118: 	}
                    119:     }
                    120:     $r->print('</table><p>&nbsp;');
1.2       www       121:     if ($filter ne '.') {
1.7       www       122:        $r->print('<br/ >'.&mt('Name starting with').' "'.$filter.'"<br />');
1.2       www       123:     }
1.12      raeburn   124:     $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>');
1.4       www       125:   # ------------------------------------------------------------------ Students
1.1       www       126:     foreach (sort keys %$classlist) {
1.3       www       127:         # the following undefs are for 'domain', and 'username' respectively.
                    128: 	my (undef,undef,$end,$start,$id,$section,$fullname,$status)=
                    129:             @{$classlist->{$_}};
1.10      albertel  130: 	if ($allowed eq 'section' && $section ne $env{'request.course.sec'}) {
                    131: 	    next;
                    132: 	}
1.3       www       133:         if ($_=~/^(\w+)\:(\w+)$/) {
1.1       www       134: 	    my ($uname,$udom)=($1,$2);
1.2       www       135: 	    if (($uname=~/^$filter/) || 
1.3       www       136:                 ($fullname=~/^$filter/i)) {
1.12      raeburn   137:                my $grouplist = '';
                    138:                foreach my $group (@coursegroups) {
                    139:                    if (exists($grouplist{$group.':'.$uname.':'.$udom})) {
                    140:                        my ($end,$start) = split(/:/,$grouplist{$group.':'.$uname.':'.$udom});
                    141:                        if (($end!=0) && ($end<$now)) { next; }
                    142:                        if (($start!=0) && ($start>$now)) {next; }
                    143:                        $grouplist .= " $group,"; 
                    144:                    }
                    145:                }
                    146:                $grouplist =~ s/,$//;
1.2       www       147: 	       $r->print('<tr><td>'.
1.7       www       148:                       '<input type="button" value="'.&mt('Select').'" onClick="gochoose('.
1.2       www       149:                       "'".$uname."','".$udom."')".'" /></td>'.
1.6       www       150:                          '<td><tt>'.$uname.'</tt></td><td> <tt>'.$udom.
1.2       www       151:                          '</tt></td><td>'.
                    152:                          &Apache::loncommon::aboutmewrapper(
1.3       www       153:                          $fullname,
                    154:                          $uname,$udom).'</td><td>'.$id.'</td><td>'.$section.
1.12      raeburn   155:                                        '</td><td>'.$grouplist.'</td></tr>');
1.2       www       156: 	   }
1.1       www       157:         }
                    158:     }
                    159: 
1.6       www       160:     $r->print('</table></p>');
                    161:   } else {
1.7       www       162:     $r->print('<h3>'.&mt('Users with Roles Assigned by').' '.
1.9       albertel  163: 	      &Apache::loncommon::plainname($env{'user.name'},
                    164: 					    $env{'user.domain'}).'</h3>');
1.6       www       165:     if ($filter ne '.') {
1.7       www       166:        $r->print('<br/ >'.&mt('Name starting with').' "'.$filter.'"<br />');
1.6       www       167:     }
                    168:     $r->print('<p><table>');
                    169:     my %users=&Apache::lonnet::get_my_roles();
                    170:     foreach (sort keys %users) {
                    171:         if ($_=~/^(\w+)\:(\w+)\:(\w+)$/) {
                    172: 	    my ($uname,$udom,$urole)=($1,$2,$3);
                    173: 	    my $fullname=&Apache::loncommon::plainname($uname,$udom);
                    174: 	    if (($uname=~/^$filter/) || 
                    175:                 ($fullname=~/^$filter/i)) {
                    176: 	       $r->print('<tr><td>'.
                    177:                       '<input type="button" value="Select" onClick="gochoose('.
                    178:                       "'".$uname."','".$udom."')".'" /></td>'.
                    179:                          '<td><tt>'.$uname.'</tt></td><td><tt>'.$udom.
                    180:                          '</tt></td><td>'.
                    181:                          &Apache::loncommon::aboutmewrapper(
                    182:                          $fullname,
                    183:                          $uname,$udom).'</td><td><td>'.
                    184: 			 &Apache::lonnet::plaintext($urole).
                    185:                                        '</td></tr>');
                    186: 	   }
                    187:         }
                    188:     }
                    189:     $r->print('</table></p>');
                    190:   }
1.11      albertel  191:   $r->print('</form>'.&Apache::loncommon::end_page());
1.6       www       192:   return OK;
1.1       www       193: } 
                    194: 
                    195: 1;
                    196: __END__

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