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

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

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