File:  [LON-CAPA] / loncom / interface / lonpickstudent.pm
Revision 1.18: download - view: text, annotated - select for diffs
Tue May 30 20:16:59 2006 UTC (18 years, 1 month ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Adding thin veneer to support ANGEL-style groups.

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

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