Annotation of loncom/interface/lonpickstudent.pm, revision 1.34
1.1 www 1: # The LearningOnline Network
2: # Pick a student from the classlist
3: #
1.34 ! raeburn 4: # $Id: lonpickstudent.pm,v 1.33 2020/02/12 16:25:47 raeburn 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',
1.34 ! raeburn 53: 'roles','courseadv','clicker','identelement']);
1.6 www 54: # Allowed?
1.10 albertel 55: my $allowed;
1.33 raeburn 56: if ($env{'request.course.id'}) {
57: if (!($allowed = &Apache::lonnet::allowed('srm',$env{'request.course.id'}))) {
58: if ($env{'request.course.sec'}) {
59: $allowed = &Apache::lonnet::allowed('srm',
60: "$env{'request.course.id'}/$env{'request.course.sec'}");
61: if ($allowed) { $allowed = 'section'; }
62: }
63: }
1.10 albertel 64: }
1.6 www 65:
1.33 raeburn 66: unless (($env{'form.roles'}) || ($allowed)) {
1.11 albertel 67: $r->print(&mt('No context.').
68: &Apache::loncommon::end_page());
1.1 www 69: return OK;
70: }
1.2 www 71:
1.6 www 72: # See if filter present
1.9 albertel 73: my $filter=$env{'form.filter'};
1.20 albertel 74: my $filtermsg;
1.22 albertel 75: my $encoded_filter = &HTML::Entities::encode($filter,'<>&"');
76: $filter = quotemeta($filter);
77: my $change = &mt('Change');
78: my $filterbutton =<<FILTER;
1.21 albertel 79: <input type="text" name="filter" value="$encoded_filter" />
80: <input type="submit" name="Change" value="$change" />
81: FILTER
1.34 ! raeburn 82: foreach my $name ('form','unameelement','udomelement','roles','courseadv','clicker','identelement') {
1.22 albertel 83: my $value = &HTML::Entities::encode($env{"form.$name"},'<>&"');
84: $filterbutton .= <<HIDDEN;
1.21 albertel 85: <input type="hidden" name="$name" value="$value" />
86: HIDDEN
1.22 albertel 87: }
1.33 raeburn 88: unless ($env{'form.courseadv'} eq 'only') {
89: if ($env{'request.course.id'}) {
90: my $crstype = &Apache::loncommon::course_type();
91: my $showrole = &Apache::lonnet::plaintext('st',$crstype);
92: $filtermsg = &mt("Showing users with role of '[_1]' with name starting: [_2]",
93: $showrole,$filterbutton);
94: } else {
95: $filtermsg =
96: &mt('Showing users with a name starting with [_1]',
97: $filterbutton);
98: }
1.27 raeburn 99: }
1.22 albertel 100: if ($filter eq '') {
101: $filter = '.'
1.20 albertel 102: }
1.1 www 103:
104: # --------------------------------------- There is such a user, get environment
105:
1.2 www 106: $r->print(<<ENDSCRIPT);
1.20 albertel 107: <script type="text/javascript">
1.2 www 108: function gochoose(uname,udom) {
1.34 ! raeburn 109: var form = opener.document.$env{'form.form'};
! 110: form.elements["$env{'form.unameelement'}"].value=uname;
! 111: var slct = form.elements['$env{"form.udomelement"}'];
! 112: if ((slct.tagName === 'INPUT') && ((slct.type === 'text') || (slct.type === 'hidden'))) {
! 113: slct.value=udom;
! 114: } else if (slct.tagName === 'SELECT') {
! 115: var i;
! 116: for (i=0;i<slct.length;i++) {
! 117: if (slct.options[i].value==udom) {
! 118: slct.selectedIndex=i;
! 119: break;
! 120: }
! 121: }
! 122: }
! 123: var identname = "$env{'form.identelement'}";
! 124: if ((identname != undefined) && (identname != '') && (identname != 'null')) {
! 125: ident = opener.document.getElementsByName("$env{'form.identelement'}");
! 126: if (ident.length > 0) {
! 127: var j;
! 128: for (j=0; j<ident.length; j++) {
! 129: if (ident[j].value == 'uname') {
! 130: if (ident[j].checked) {
! 131: break;
! 132: } else {
! 133: ident[j].checked = true;
! 134: window.opener.toggleIdentifier(form);
! 135: }
! 136: } else {
! 137: ident[j].checked = false;
! 138: }
! 139: }
! 140: }
1.2 www 141: }
142: self.close();
143: }
144: </script>
145: ENDSCRIPT
1.20 albertel 146:
1.32 bisitz 147: $r->print('<form action="">');
1.20 albertel 148: if ($allowed && (!$env{'form.roles'})) {
1.33 raeburn 149: unless ($env{'form.courseadv'} eq 'none') {
1.6 www 150: # -------------------------------------------------------- Get course personnel
1.33 raeburn 151: $r->print('<h3>'.$env{'course.'.$env{'request.course.id'}.'.description'}.
152: '</h3>');
153: my %coursepersonnel=
154: &Apache::lonnet::get_course_adv_roles();
155: $r->print(&Apache::loncommon::start_data_table());
156: foreach my $role (sort(keys(%coursepersonnel))) {
157: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
158: my ($puname,$pudom)=split(/\:/,$user);
159: $r->print(&Apache::loncommon::start_data_table_row().
160: '<td>'.
161: '<input type="button" value="'.&mt('Select').'" onclick="gochoose('.
162: "'".$puname."','".$pudom."')".'" /></td><td>'.$role.'</td><td>'.
163: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($puname,$pudom),$puname,$pudom).'</td>'.
164: &Apache::loncommon::end_data_table_row());
165: }
166: }
167: $r->print(&Apache::loncommon::end_data_table().'<br /><hr />');
168: }
1.20 albertel 169:
1.33 raeburn 170: if ($filtermsg ne '') {
171: $r->print('<p>'.$filtermsg.'</p>');
172: }
1.22 albertel 173:
1.30 www 174: $r->rflush();
175:
1.33 raeburn 176: unless ($env{'form.courseadv'} eq 'only') {
1.27 raeburn 177:
1.20 albertel 178: # ------------------------------------------------------------------ Students
1.29 www 179:
180: # Do we have a clicker?
181:
182: my $clicker=$env{'form.clicker'};
183: my @fragments=();
184: if ($clicker) {
185: $r->print('<h1>'.&mt('Clicker: [_1]',$clicker).'</h1>');
186: my $clicklength=length($clicker);
187: my $maxlength=$clicklength-1;
188: if ($maxlength>2) {
189: my $minlength=$maxlength-2;
190: if ($minlength<2) { $minlength=2; }
191: for (my $length=$maxlength;$length>=$minlength;$length--) {
192: for (my $startidx=0; $startidx<=$clicklength-$length; $startidx++) {
193: push(@fragments,substr($clicker,$startidx,$length));
194: }
195: }
196: }
197: }
198:
1.27 raeburn 199: my $result;
200: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
201: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
202: my $classlist=&Apache::loncoursedata::get_classlist();
203: my %grouplist=&Apache::lonnet::get_group_membership($cdom,$cnum);
204: my $now = time;
205: my %allgroups = &Apache::longroup::coursegroups($cdom,$cnum);
206:
207: foreach my $user (sort(keys(%$classlist))) {
208: # the following undefs are for 'domain', and 'username' respectively.
209: my (undef,undef,$end,$start,$id,$section,$fullname,$status)=
210: @{$classlist->{$user}};
211: if ($allowed eq 'section' && $section ne $env{'request.course.sec'}) {
212: next;
213: }
214: if ($user=~/^($LONCAPA::username_re)\:($LONCAPA::domain_re)$/) {
215: my ($uname,$udom)=($1,$2);
216: if (($uname=~/^$filter/) || ($fullname=~/^$filter/i)) {
217: my $grouplist = '';
218: foreach my $group (sort(keys(%allgroups))) {
219: if (exists($grouplist{$group.':'.$uname.':'.$udom})) {
220: my ($end,$start) = split(/:/,$grouplist{$group.':'.$uname.':'.$udom});
221: if (($end!=0) && ($end<$now)) { next; }
222: if (($start!=0) && ($start>$now)) {next; }
223: $grouplist .= " $group,";
224: }
225: }
226: $grouplist =~ s/,$//;
1.29 www 227: my $markedupclicker;
228: if ($clicker) {
229: $markedupclicker=(&Apache::lonnet::userenvironment($udom,$uname,'clickers'))[1];
230: if ($markedupclicker!~/\w/) {
231: $markedupclicker='-';
232: } else {
233: foreach my $frag (@fragments) {
234: if ($markedupclicker=~/\Q$frag\E/is) {
235: $markedupclicker=~s/(\Q$frag\E)/<font color=\"green\" size=\"\+1\"><b>$1<\/b><\/font>/gis;
236: last;
237: }
238: }
239: }
240: }
1.27 raeburn 241: $result .=&Apache::loncommon::start_data_table_row().
242: '<td>'.
1.31 bisitz 243: '<input type="button" value="'.&mt('Select').'" onclick="gochoose('.
1.27 raeburn 244: "'".$uname."','".$udom."')".'" /></td>'.
245: '<td><tt>'.$uname.'</tt></td><td> <tt>'.$udom.
246: '</tt></td><td>'.
247: &Apache::loncommon::aboutmewrapper($fullname,
248: $uname,$udom).
249: '</td><td>'.$id.'</td><td>'.$section.
250: '</td><td>'.$grouplist.'</td>'.
1.29 www 251: ($clicker?'<td>'.$markedupclicker.'</td>':'').
1.27 raeburn 252: &Apache::loncommon::end_data_table_row();
253: }
254: }
1.20 albertel 255: }
1.27 raeburn 256: if (!$result) {
257: $r->print('<p>'.&mt('No students found.').'</p>');
258: } else {
259: $r->print(&Apache::loncommon::start_data_table().
260: &Apache::loncommon::start_data_table_header_row().
261: &Apache::loncommon::end_data_table_header_row().
262: '<th> </th>'.
263: '<th>'.&mt('username').'</th>'.
264: '<th>'.&mt('domain').'</th>'.
265: '<th>'.&mt('Name').'</th>'.
266: '<th>'.&mt('ID').'</th>'.
267: '<th>'.&mt('section').'</th>'.
268: '<th>'.&mt('active group(s)').'</th>'.
1.29 www 269: ($clicker?'<th>'.&mt('clicker').'</th>':'').
1.27 raeburn 270: &Apache::loncommon::end_data_table_header_row().
271: $result.
272: &Apache::loncommon::end_data_table());
1.20 albertel 273: }
1.27 raeburn 274: }
1.20 albertel 275: } else {
276: $r->print('<h3>'.&mt('Users with Roles Assigned by').' '.
277: &Apache::loncommon::plainname($env{'user.name'},
278: $env{'user.domain'}).'</h3>');
279: $r->print($filtermsg);
1.30 www 280: $r->rflush();
1.20 albertel 281:
282: $r->print('<p>'.&Apache::loncommon::start_data_table());
1.23 albertel 283: my %user_role=&Apache::lonnet::get_my_roles();
284: my %users;
285: foreach my $user_role (keys(%user_role)) {
286: next if ($user_role !~
287: /^($LONCAPA::username_re):($LONCAPA::domain_re):(\w+)$/);
288: my ($uname,$udom,$urole)=($1,$2,$3);
289: my $fullname=&Apache::loncommon::plainname($uname,$udom);
1.24 raeburn 290: next if (($uname!~/^$filter/i) && ($fullname !~/^$filter/i));
1.23 albertel 291:
292: if (!exists($users{"$uname:$udom"})) {
293: $users{"$uname:$udom"} = {'fullname' => $fullname };
1.20 albertel 294: }
1.23 albertel 295: push(@{$users{"$uname:$udom"}{'roles'}},$urole);
296: }
297: foreach my $user (sort {lc($a) cmp lc($b)} (keys(%users))) {
298: my ($uname,$udom) = split(':',$user);
299: $r->print(&Apache::loncommon::start_data_table_row().
300: '<td>'.
1.31 bisitz 301: '<input type="button" value="'.&mt('Select').'" onclick="gochoose('.
1.23 albertel 302: "'".$uname."','".$udom."')".'" /></td>'.
303: '<td><tt>'.$uname.'</tt></td>'.
304: '<td><tt>'.$udom.'</tt></td><td>'.
305: &Apache::loncommon::aboutmewrapper($users{$user}{'fullname'},
306: $uname,$udom).'</td>'.
307: '<td>'.
308: join(', ',sort(map {&Apache::lonnet::plaintext($_)}
309: (@{$users{$user}{'roles'}}))).
310: '</td>'.
311: &Apache::loncommon::end_data_table_row());
1.10 albertel 312: }
1.20 albertel 313: $r->print(&Apache::loncommon::end_data_table().'</p>');
1.6 www 314: }
1.20 albertel 315: $r->print('</form>'.&Apache::loncommon::end_page());
316: return OK;
1.33 raeburn 317: }
1.1 www 318:
319: 1;
320: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>