File:  [LON-CAPA] / loncom / interface / lonpickstudent.pm
Revision 1.10: download - view: text, annotated - select for diffs
Mon Jan 9 20:38:52 2006 UTC (18 years, 4 months ago) by albertel
Branches: MAIN
CVS tags: version_2_1_X, version_2_1_3, version_2_1_2, HEAD
-making section srm work a bit more universally

    1: # The LearningOnline Network
    2: # Pick a student from the classlist
    3: #
    4: # $Id: lonpickstudent.pm,v 1.10 2006/01/09 20:38:52 albertel Exp $
    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;
   36: use Apache::lonlocal;
   37: 
   38: sub handler {
   39:     my $r = shift;
   40:     &Apache::loncommon::content_type($r,'text/html');
   41:     $r->send_http_header;
   42:     return OK if $r->header_only;
   43: 
   44: # ------------------------------------------------------------ Print the screen
   45:     my $html=&Apache::lonxml::xmlbegin();
   46:     $r->print(<<ENDDOCUMENT);
   47: $html
   48: <head>
   49: <title>The LearningOnline Network with CAPA</title>
   50: </head>
   51: ENDDOCUMENT
   52: 
   53: 
   54: 
   55: 
   56:     &Apache::loncommon::get_unprocessed_cgi
   57:         ($ENV{'QUERY_STRING'},['filter','form','unameelement','udomelement',
   58: 			       'roles']);
   59: # Allowed?
   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:     }
   67: 
   68:     unless (($env{'form.roles'}) ||
   69:             (($env{'request.course.id'}) && ($allowed))) {
   70: 	$r->print('<body>No context.</body>');
   71:         return OK;
   72:     }
   73: 
   74: # See if filter present
   75: 
   76:     my $filter=$env{'form.filter'};
   77:     $filter=~s/\W//g;
   78:     unless ($filter) { $filter='.'; }
   79: 
   80:     my $classlist=&Apache::loncoursedata::get_classlist();
   81:        
   82: # --------------------------------------- There is such a user, get environment
   83: 
   84:     $r->print(&Apache::loncommon::bodytag("Selecting a User"));
   85:     $r->print(<<ENDSCRIPT);
   86: <script>
   87: function gochoose(uname,udom) {
   88:     opener.document.$env{'form.form'}.$env{'form.unameelement'}.value=uname;
   89:     var slct=opener.document.$env{'form.form'}.$env{'form.udomelement'};
   90:     var i;
   91:     for (i=0;i<slct.length;i++) {
   92:         if (slct.options[i].value==udom) { slct.selectedIndex=i; }
   93:     }
   94:     self.close();
   95: }
   96: </script>
   97: ENDSCRIPT
   98:     
   99:   $r->print('<form>');
  100:   if ($allowed && (!$env{'form.roles'})) {
  101: # -------------------------------------------------------- Get course personnel
  102:     $r->print('<h3>'.$env{'course.'.$env{'request.course.id'}.'.description'}.
  103:               '</h3>');
  104:     my %coursepersonnel=
  105:        &Apache::lonnet::get_course_adv_roles();
  106:     $r->print('<table border="2">');
  107:     foreach my $role (sort keys %coursepersonnel) {
  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;');
  119:     if ($filter ne '.') {
  120:        $r->print('<br/ >'.&mt('Name starting with').' "'.$filter.'"<br />');
  121:     }
  122:     $r->print('</p><p><table>');
  123:   # ------------------------------------------------------------------ Students
  124:     foreach (sort keys %$classlist) {
  125:         # the following undefs are for 'domain', and 'username' respectively.
  126: 	my (undef,undef,$end,$start,$id,$section,$fullname,$status)=
  127:             @{$classlist->{$_}};
  128: 	if ($allowed eq 'section' && $section ne $env{'request.course.sec'}) {
  129: 	    next;
  130: 	}
  131:         if ($_=~/^(\w+)\:(\w+)$/) {
  132: 	    my ($uname,$udom)=($1,$2);
  133: 	    if (($uname=~/^$filter/) || 
  134:                 ($fullname=~/^$filter/i)) {
  135: 	       $r->print('<tr><td>'.
  136:                       '<input type="button" value="'.&mt('Select').'" onClick="gochoose('.
  137:                       "'".$uname."','".$udom."')".'" /></td>'.
  138:                          '<td><tt>'.$uname.'</tt></td><td> <tt>'.$udom.
  139:                          '</tt></td><td>'.
  140:                          &Apache::loncommon::aboutmewrapper(
  141:                          $fullname,
  142:                          $uname,$udom).'</td><td>'.$id.'</td><td>'.$section.
  143:                                        '</td></tr>');
  144: 	   }
  145:         }
  146:     }
  147: 
  148:     $r->print('</table></p>');
  149:   } else {
  150:     $r->print('<h3>'.&mt('Users with Roles Assigned by').' '.
  151: 	      &Apache::loncommon::plainname($env{'user.name'},
  152: 					    $env{'user.domain'}).'</h3>');
  153:     if ($filter ne '.') {
  154:        $r->print('<br/ >'.&mt('Name starting with').' "'.$filter.'"<br />');
  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;
  181: } 
  182: 
  183: 1;
  184: __END__

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