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

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

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