Annotation of loncom/interface/lonpickstudent.pm, revision 1.33
1.1 www 1: # The LearningOnline Network
2: # Pick a student from the classlist
3: #
1.33 ! raeburn 4: # $Id: lonpickstudent.pm,v 1.32 2013/07/15 16:13:22 bisitz 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.33 ! raeburn 53: 'roles','courseadv','clicker']);
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.33 ! raeburn 82: foreach my $name ('form','unameelement','udomelement','roles','courseadv','clicker') {
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.28 raeburn 109: opener.document.$env{'form.form'}.elements['$env{'form.unameelement'}'].value=uname;
110: var slct=opener.document.$env{'form.form'}.elements['$env{'form.udomelement'}'];
1.2 www 111: var i;
112: for (i=0;i<slct.length;i++) {
1.4 www 113: if (slct.options[i].value==udom) { slct.selectedIndex=i; }
1.2 www 114: }
115: self.close();
116: }
117: </script>
118: ENDSCRIPT
1.20 albertel 119:
1.32 bisitz 120: $r->print('<form action="">');
1.20 albertel 121: if ($allowed && (!$env{'form.roles'})) {
1.33 ! raeburn 122: unless ($env{'form.courseadv'} eq 'none') {
1.6 www 123: # -------------------------------------------------------- Get course personnel
1.33 ! raeburn 124: $r->print('<h3>'.$env{'course.'.$env{'request.course.id'}.'.description'}.
! 125: '</h3>');
! 126: my %coursepersonnel=
! 127: &Apache::lonnet::get_course_adv_roles();
! 128: $r->print(&Apache::loncommon::start_data_table());
! 129: foreach my $role (sort(keys(%coursepersonnel))) {
! 130: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
! 131: my ($puname,$pudom)=split(/\:/,$user);
! 132: $r->print(&Apache::loncommon::start_data_table_row().
! 133: '<td>'.
! 134: '<input type="button" value="'.&mt('Select').'" onclick="gochoose('.
! 135: "'".$puname."','".$pudom."')".'" /></td><td>'.$role.'</td><td>'.
! 136: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($puname,$pudom),$puname,$pudom).'</td>'.
! 137: &Apache::loncommon::end_data_table_row());
! 138: }
! 139: }
! 140: $r->print(&Apache::loncommon::end_data_table().'<br /><hr />');
! 141: }
1.20 albertel 142:
1.33 ! raeburn 143: if ($filtermsg ne '') {
! 144: $r->print('<p>'.$filtermsg.'</p>');
! 145: }
1.22 albertel 146:
1.30 www 147: $r->rflush();
148:
1.33 ! raeburn 149: unless ($env{'form.courseadv'} eq 'only') {
1.27 raeburn 150:
1.20 albertel 151: # ------------------------------------------------------------------ Students
1.29 www 152:
153: # Do we have a clicker?
154:
155: my $clicker=$env{'form.clicker'};
156: my @fragments=();
157: if ($clicker) {
158: $r->print('<h1>'.&mt('Clicker: [_1]',$clicker).'</h1>');
159: my $clicklength=length($clicker);
160: my $maxlength=$clicklength-1;
161: if ($maxlength>2) {
162: my $minlength=$maxlength-2;
163: if ($minlength<2) { $minlength=2; }
164: for (my $length=$maxlength;$length>=$minlength;$length--) {
165: for (my $startidx=0; $startidx<=$clicklength-$length; $startidx++) {
166: push(@fragments,substr($clicker,$startidx,$length));
167: }
168: }
169: }
170: }
171:
1.27 raeburn 172: my $result;
173: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
174: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
175: my $classlist=&Apache::loncoursedata::get_classlist();
176: my %grouplist=&Apache::lonnet::get_group_membership($cdom,$cnum);
177: my $now = time;
178: my %allgroups = &Apache::longroup::coursegroups($cdom,$cnum);
179:
180: foreach my $user (sort(keys(%$classlist))) {
181: # the following undefs are for 'domain', and 'username' respectively.
182: my (undef,undef,$end,$start,$id,$section,$fullname,$status)=
183: @{$classlist->{$user}};
184: if ($allowed eq 'section' && $section ne $env{'request.course.sec'}) {
185: next;
186: }
187: if ($user=~/^($LONCAPA::username_re)\:($LONCAPA::domain_re)$/) {
188: my ($uname,$udom)=($1,$2);
189: if (($uname=~/^$filter/) || ($fullname=~/^$filter/i)) {
190: my $grouplist = '';
191: foreach my $group (sort(keys(%allgroups))) {
192: if (exists($grouplist{$group.':'.$uname.':'.$udom})) {
193: my ($end,$start) = split(/:/,$grouplist{$group.':'.$uname.':'.$udom});
194: if (($end!=0) && ($end<$now)) { next; }
195: if (($start!=0) && ($start>$now)) {next; }
196: $grouplist .= " $group,";
197: }
198: }
199: $grouplist =~ s/,$//;
1.29 www 200: my $markedupclicker;
201: if ($clicker) {
202: $markedupclicker=(&Apache::lonnet::userenvironment($udom,$uname,'clickers'))[1];
203: if ($markedupclicker!~/\w/) {
204: $markedupclicker='-';
205: } else {
206: foreach my $frag (@fragments) {
207: if ($markedupclicker=~/\Q$frag\E/is) {
208: $markedupclicker=~s/(\Q$frag\E)/<font color=\"green\" size=\"\+1\"><b>$1<\/b><\/font>/gis;
209: last;
210: }
211: }
212: }
213: }
1.27 raeburn 214: $result .=&Apache::loncommon::start_data_table_row().
215: '<td>'.
1.31 bisitz 216: '<input type="button" value="'.&mt('Select').'" onclick="gochoose('.
1.27 raeburn 217: "'".$uname."','".$udom."')".'" /></td>'.
218: '<td><tt>'.$uname.'</tt></td><td> <tt>'.$udom.
219: '</tt></td><td>'.
220: &Apache::loncommon::aboutmewrapper($fullname,
221: $uname,$udom).
222: '</td><td>'.$id.'</td><td>'.$section.
223: '</td><td>'.$grouplist.'</td>'.
1.29 www 224: ($clicker?'<td>'.$markedupclicker.'</td>':'').
1.27 raeburn 225: &Apache::loncommon::end_data_table_row();
226: }
227: }
1.20 albertel 228: }
1.27 raeburn 229: if (!$result) {
230: $r->print('<p>'.&mt('No students found.').'</p>');
231: } else {
232: $r->print(&Apache::loncommon::start_data_table().
233: &Apache::loncommon::start_data_table_header_row().
234: &Apache::loncommon::end_data_table_header_row().
235: '<th> </th>'.
236: '<th>'.&mt('username').'</th>'.
237: '<th>'.&mt('domain').'</th>'.
238: '<th>'.&mt('Name').'</th>'.
239: '<th>'.&mt('ID').'</th>'.
240: '<th>'.&mt('section').'</th>'.
241: '<th>'.&mt('active group(s)').'</th>'.
1.29 www 242: ($clicker?'<th>'.&mt('clicker').'</th>':'').
1.27 raeburn 243: &Apache::loncommon::end_data_table_header_row().
244: $result.
245: &Apache::loncommon::end_data_table());
1.20 albertel 246: }
1.27 raeburn 247: }
1.20 albertel 248: } else {
249: $r->print('<h3>'.&mt('Users with Roles Assigned by').' '.
250: &Apache::loncommon::plainname($env{'user.name'},
251: $env{'user.domain'}).'</h3>');
252: $r->print($filtermsg);
1.30 www 253: $r->rflush();
1.20 albertel 254:
255: $r->print('<p>'.&Apache::loncommon::start_data_table());
1.23 albertel 256: my %user_role=&Apache::lonnet::get_my_roles();
257: my %users;
258: foreach my $user_role (keys(%user_role)) {
259: next if ($user_role !~
260: /^($LONCAPA::username_re):($LONCAPA::domain_re):(\w+)$/);
261: my ($uname,$udom,$urole)=($1,$2,$3);
262: my $fullname=&Apache::loncommon::plainname($uname,$udom);
1.24 raeburn 263: next if (($uname!~/^$filter/i) && ($fullname !~/^$filter/i));
1.23 albertel 264:
265: if (!exists($users{"$uname:$udom"})) {
266: $users{"$uname:$udom"} = {'fullname' => $fullname };
1.20 albertel 267: }
1.23 albertel 268: push(@{$users{"$uname:$udom"}{'roles'}},$urole);
269: }
270: foreach my $user (sort {lc($a) cmp lc($b)} (keys(%users))) {
271: my ($uname,$udom) = split(':',$user);
272: $r->print(&Apache::loncommon::start_data_table_row().
273: '<td>'.
1.31 bisitz 274: '<input type="button" value="'.&mt('Select').'" onclick="gochoose('.
1.23 albertel 275: "'".$uname."','".$udom."')".'" /></td>'.
276: '<td><tt>'.$uname.'</tt></td>'.
277: '<td><tt>'.$udom.'</tt></td><td>'.
278: &Apache::loncommon::aboutmewrapper($users{$user}{'fullname'},
279: $uname,$udom).'</td>'.
280: '<td>'.
281: join(', ',sort(map {&Apache::lonnet::plaintext($_)}
282: (@{$users{$user}{'roles'}}))).
283: '</td>'.
284: &Apache::loncommon::end_data_table_row());
1.10 albertel 285: }
1.20 albertel 286: $r->print(&Apache::loncommon::end_data_table().'</p>');
1.6 www 287: }
1.20 albertel 288: $r->print('</form>'.&Apache::loncommon::end_page());
289: return OK;
1.33 ! raeburn 290: }
1.1 www 291:
292: 1;
293: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>