Annotation of loncom/interface/lonpickstudent.pm, revision 1.21
1.1 www 1: # The LearningOnline Network
2: # Pick a student from the classlist
3: #
1.21 ! albertel 4: # $Id: lonpickstudent.pm,v 1.20 2006/12/06 20:54:13 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.17 raeburn 37: use Apache::longroup;
1.20 albertel 38: use LONCAPA;
1.1 www 39:
40: sub handler {
41: my $r = shift;
1.7 www 42: &Apache::loncommon::content_type($r,'text/html');
1.1 www 43: $r->send_http_header;
44: return OK if $r->header_only;
45:
46: # ------------------------------------------------------------ Print the screen
1.13 albertel 47: $r->print(&Apache::loncommon::start_page("Selecting a User",undef,
48: {'no_nav_bar' => 1}));
1.6 www 49:
50:
51: &Apache::loncommon::get_unprocessed_cgi
52: ($ENV{'QUERY_STRING'},['filter','form','unameelement','udomelement',
53: 'roles']);
54: # Allowed?
1.10 albertel 55: my $allowed;
56: my $scope = $env{'request.course.id'};
57: if (!($allowed = &Apache::lonnet::allowed('srm',$scope))) {
58: $scope .= '/'.$env{'request.course.sec'};
59: $allowed = &Apache::lonnet::allowed('srm',$scope);
60: if ($allowed) { $allowed = 'section'; }
61: }
1.6 www 62:
1.9 albertel 63: unless (($env{'form.roles'}) ||
1.10 albertel 64: (($env{'request.course.id'}) && ($allowed))) {
1.11 albertel 65: $r->print(&mt('No context.').
66: &Apache::loncommon::end_page());
1.1 www 67: return OK;
68: }
1.2 www 69:
1.6 www 70: # See if filter present
1.9 albertel 71: my $filter=$env{'form.filter'};
1.20 albertel 72: my $filtermsg;
1.21 ! albertel 73: if ($filter eq '') {
! 74: $filter = '.'
! 75: } else {
! 76: my $encoded_filter = &HTML::Entities::encode($filter,'<>&"');
1.20 albertel 77: $filter = quotemeta($filter);
1.21 ! albertel 78: my $change = &mt('Change');
! 79: my $filterbutton =<<FILTER;
! 80: <input type="text" name="filter" value="$encoded_filter" />
! 81: <input type="submit" name="Change" value="$change" />
! 82: FILTER
! 83: foreach my $name ('form','unameelement','udomelement','roles') {
! 84: my $value = &HTML::Entities::encode($env{"form.$name"},'<>&"');
! 85: $filterbutton .= <<HIDDEN;
! 86: <input type="hidden" name="$name" value="$value" />
! 87: HIDDEN
! 88: }
! 89: $filtermsg = '<br />'.
! 90: &mt('Showing users with a name starting with [_1]',
! 91: $filterbutton).'<br />';
1.20 albertel 92: }
1.1 www 93:
1.12 raeburn 94: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
95: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.3 www 96: my $classlist=&Apache::loncoursedata::get_classlist();
1.12 raeburn 97: my %grouplist=&Apache::lonnet::get_group_membership($cdom,$cnum);
98: my $now = time;
1.17 raeburn 99: my %allgroups = &Apache::longroup::coursegroups($cdom,$cnum);
1.12 raeburn 100:
1.1 www 101: # --------------------------------------- There is such a user, get environment
102:
1.2 www 103: $r->print(<<ENDSCRIPT);
1.20 albertel 104: <script type="text/javascript">
1.2 www 105: function gochoose(uname,udom) {
1.9 albertel 106: opener.document.$env{'form.form'}.$env{'form.unameelement'}.value=uname;
107: var slct=opener.document.$env{'form.form'}.$env{'form.udomelement'};
1.2 www 108: var i;
109: for (i=0;i<slct.length;i++) {
1.4 www 110: if (slct.options[i].value==udom) { slct.selectedIndex=i; }
1.2 www 111: }
112: self.close();
113: }
114: </script>
115: ENDSCRIPT
1.20 albertel 116:
117: $r->print('<form>');
118: if ($allowed && (!$env{'form.roles'})) {
1.6 www 119: # -------------------------------------------------------- Get course personnel
1.20 albertel 120: $r->print('<h3>'.$env{'course.'.$env{'request.course.id'}.'.description'}.
121: '</h3>');
122: my %coursepersonnel=
123: &Apache::lonnet::get_course_adv_roles();
124: $r->print(&Apache::loncommon::start_data_table());
125: foreach my $role (sort(keys(%coursepersonnel))) {
126: foreach (split(/\,/,$coursepersonnel{$role})) {
127: my ($puname,$pudom)=split(/\:/,$_);
128: $role = &Apache::lonnet::plaintext($role,
129: &Apache::loncommon::course_type());
130: $r->print(&Apache::loncommon::start_data_table_row().
131: '<td>'.
132: '<input type="button" value="Select" onClick="gochoose('.
133: "'".$puname."','".$pudom."')".'" /></td><td>'.$role.'</td><td>'.
134: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($puname,$pudom),$puname,$pudom).'</td>'.
135: &Apache::loncommon::end_data_table_row());
136: }
137: }
138: $r->print(&Apache::loncommon::end_data_table().'<p> ');
139:
140: $r->print($filtermsg);
141:
142: $r->print('</p><p>'.
143: &Apache::loncommon::start_data_table().
144: &Apache::loncommon::start_data_table_header_row().
145: &Apache::loncommon::end_data_table_header_row().
146: '<th> </th>'.
147: '<th>'.&mt('username').'</th>'.
148: '<th>'.&mt('domain').'</th>'.
149: '<th>'.&mt('Name').'</th>'.
150: '<th>'.&mt('ID').'</th>'.
151: '<th>'.&mt('section').'</th>'.
152: '<th>'.&mt('active group(s)').'</th>'.
153: &Apache::loncommon::end_data_table_header_row());
154: # ------------------------------------------------------------------ Students
155: foreach my $user (sort(keys(%$classlist))) {
156: # the following undefs are for 'domain', and 'username' respectively.
157: my (undef,undef,$end,$start,$id,$section,$fullname,$status)=
158: @{$classlist->{$user}};
159: if ($allowed eq 'section' && $section ne $env{'request.course.sec'}) {
160: next;
161: }
162: if ($user=~/^($LONCAPA::username_re)\:($LONCAPA::domain_re)$/) {
163: my ($uname,$udom)=($1,$2);
164: if (($uname=~/^$filter/) ||
165: ($fullname=~/^$filter/i)) {
166: my $grouplist = '';
167: foreach my $group (sort(keys(%allgroups))) {
168: if (exists($grouplist{$group.':'.$uname.':'.$udom})) {
169: my ($end,$start) = split(/:/,$grouplist{$group.':'.$uname.':'.$udom});
170: if (($end!=0) && ($end<$now)) { next; }
171: if (($start!=0) && ($start>$now)) {next; }
172: $grouplist .= " $group,";
173: }
174: }
175: $grouplist =~ s/,$//;
176: $r->print(&Apache::loncommon::start_data_table_row().
177: '<td>'.
178: '<input type="button" value="'.&mt('Select').'" onClick="gochoose('.
179: "'".$uname."','".$udom."')".'" /></td>'.
180: '<td><tt>'.$uname.'</tt></td><td> <tt>'.$udom.
181: '</tt></td><td>'.
182: &Apache::loncommon::aboutmewrapper($fullname,
183: $uname,$udom).
184: '</td><td>'.$id.'</td><td>'.$section.
185: '</td><td>'.$grouplist.'</td>'.
186: &Apache::loncommon::end_data_table_row());
187: }
188: }
1.4 www 189: }
1.20 albertel 190:
191: $r->print(&Apache::loncommon::end_data_table().'</p>');
192: } else {
193: $r->print('<h3>'.&mt('Users with Roles Assigned by').' '.
194: &Apache::loncommon::plainname($env{'user.name'},
195: $env{'user.domain'}).'</h3>');
196: $r->print($filtermsg);
197:
198: $r->print('<p>'.&Apache::loncommon::start_data_table());
199: my %users=&Apache::lonnet::get_my_roles();
200: foreach my $user (sort(keys(%users))) {
201: if ($user =~
202: /^($LONCAPA::username_re)\:($LONCAPA::domain_re)\:(\w+)$/) {
203: my ($uname,$udom,$urole)=($1,$2,$3);
204: my $fullname=&Apache::loncommon::plainname($uname,$udom);
205: if (($uname=~/^$filter/) ||
206: ($fullname=~/^$filter/i)) {
207: $r->print(&Apache::loncommon::start_data_table_row().
208: '<td>'.
209: '<input type="button" value="Select" onClick="gochoose('.
210: "'".$uname."','".$udom."')".'" /></td>'.
211: '<td><tt>'.$uname.'</tt></td><td><tt>'.$udom.
212: '</tt></td><td>'.
213: &Apache::loncommon::aboutmewrapper(
214: $fullname,
215: $uname,$udom).'</td><td><td>'.
216: &Apache::lonnet::plaintext($urole).
217: '</td>'.
218: &Apache::loncommon::end_data_table_row());
219: }
220: }
1.10 albertel 221: }
1.20 albertel 222: $r->print(&Apache::loncommon::end_data_table().'</p>');
1.6 www 223: }
1.20 albertel 224: $r->print('</form>'.&Apache::loncommon::end_page());
225: return OK;
1.1 www 226: }
227:
228: 1;
229: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>