File:
[LON-CAPA] /
loncom /
interface /
lonpickstudent.pm
Revision
1.32:
download - view:
text,
annotated -
select for diffs
Mon Jul 15 16:13:22 2013 UTC (11 years, 1 month ago) by
bisitz
Branches:
MAIN
CVS tags:
version_2_11_2_uiuc,
version_2_11_2_msu,
version_2_11_2_educog,
version_2_11_2,
version_2_11_1,
version_2_11_0_RC3,
version_2_11_0_RC2,
version_2_11_0_RC1,
version_2_11_0,
HEAD
XHTML: action attribute in <form> tag required (dummy attribute added)
1: # The LearningOnline Network
2: # Pick a student from the classlist
3: #
4: # $Id: lonpickstudent.pm,v 1.32 2013/07/15 16:13:22 bisitz 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: use LONCAPA;
39:
40: sub handler {
41: my $r = shift;
42: &Apache::loncommon::content_type($r,'text/html');
43: $r->send_http_header;
44: return OK if $r->header_only;
45:
46: # ------------------------------------------------------------ Print the screen
47: $r->print(&Apache::loncommon::start_page("Selecting a User",undef,
48: {'no_nav_bar' => 1}));
49:
50:
51: &Apache::loncommon::get_unprocessed_cgi
52: ($ENV{'QUERY_STRING'},['filter','form','unameelement','udomelement',
53: 'roles','courseadvonly','clicker']);
54: # Allowed?
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: }
62:
63: unless (($env{'form.roles'}) ||
64: (($env{'request.course.id'}) && ($allowed))) {
65: $r->print(&mt('No context.').
66: &Apache::loncommon::end_page());
67: return OK;
68: }
69:
70: # See if filter present
71: my $filter=$env{'form.filter'};
72: my $filtermsg;
73: my $encoded_filter = &HTML::Entities::encode($filter,'<>&"');
74: $filter = quotemeta($filter);
75: my $change = &mt('Change');
76: my $filterbutton =<<FILTER;
77: <input type="text" name="filter" value="$encoded_filter" />
78: <input type="submit" name="Change" value="$change" />
79: FILTER
80: foreach my $name ('form','unameelement','udomelement','roles') {
81: my $value = &HTML::Entities::encode($env{"form.$name"},'<>&"');
82: $filterbutton .= <<HIDDEN;
83: <input type="hidden" name="$name" value="$value" />
84: HIDDEN
85: }
86: unless ($env{'form.courseadvonly'}) {
87: $filtermsg = '<br />'.
88: &mt('Showing users with a name starting with [_1]',
89: $filterbutton).'<br />';
90: }
91: if ($filter eq '') {
92: $filter = '.'
93: }
94:
95: # --------------------------------------- There is such a user, get environment
96:
97: $r->print(<<ENDSCRIPT);
98: <script type="text/javascript">
99: function gochoose(uname,udom) {
100: opener.document.$env{'form.form'}.elements['$env{'form.unameelement'}'].value=uname;
101: var slct=opener.document.$env{'form.form'}.elements['$env{'form.udomelement'}'];
102: var i;
103: for (i=0;i<slct.length;i++) {
104: if (slct.options[i].value==udom) { slct.selectedIndex=i; }
105: }
106: self.close();
107: }
108: </script>
109: ENDSCRIPT
110:
111: $r->print('<form action="">');
112: if ($allowed && (!$env{'form.roles'})) {
113: # -------------------------------------------------------- Get course personnel
114: $r->print('<h3>'.$env{'course.'.$env{'request.course.id'}.'.description'}.
115: '</h3>');
116: my %coursepersonnel=
117: &Apache::lonnet::get_course_adv_roles();
118: $r->print(&Apache::loncommon::start_data_table());
119: foreach my $role (sort(keys(%coursepersonnel))) {
120: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
121: my ($puname,$pudom)=split(/\:/,$user);
122: $r->print(&Apache::loncommon::start_data_table_row().
123: '<td>'.
124: '<input type="button" value="'.&mt('Select').'" onclick="gochoose('.
125: "'".$puname."','".$pudom."')".'" /></td><td>'.$role.'</td><td>'.
126: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($puname,$pudom),$puname,$pudom).'</td>'.
127: &Apache::loncommon::end_data_table_row());
128: }
129: }
130: $r->print(&Apache::loncommon::end_data_table().'<p> ');
131:
132: $r->print($filtermsg);
133:
134: $r->print('</p>');
135:
136: $r->rflush();
137:
138: unless ($env{'form.courseadvonly'}) {
139:
140: # ------------------------------------------------------------------ Students
141:
142: # Do we have a clicker?
143:
144: my $clicker=$env{'form.clicker'};
145: my @fragments=();
146: if ($clicker) {
147: $r->print('<h1>'.&mt('Clicker: [_1]',$clicker).'</h1>');
148: my $clicklength=length($clicker);
149: my $maxlength=$clicklength-1;
150: if ($maxlength>2) {
151: my $minlength=$maxlength-2;
152: if ($minlength<2) { $minlength=2; }
153: for (my $length=$maxlength;$length>=$minlength;$length--) {
154: for (my $startidx=0; $startidx<=$clicklength-$length; $startidx++) {
155: push(@fragments,substr($clicker,$startidx,$length));
156: }
157: }
158: }
159: }
160:
161: my $result;
162: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
163: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
164: my $classlist=&Apache::loncoursedata::get_classlist();
165: my %grouplist=&Apache::lonnet::get_group_membership($cdom,$cnum);
166: my $now = time;
167: my %allgroups = &Apache::longroup::coursegroups($cdom,$cnum);
168:
169: foreach my $user (sort(keys(%$classlist))) {
170: # the following undefs are for 'domain', and 'username' respectively.
171: my (undef,undef,$end,$start,$id,$section,$fullname,$status)=
172: @{$classlist->{$user}};
173: if ($allowed eq 'section' && $section ne $env{'request.course.sec'}) {
174: next;
175: }
176: if ($user=~/^($LONCAPA::username_re)\:($LONCAPA::domain_re)$/) {
177: my ($uname,$udom)=($1,$2);
178: if (($uname=~/^$filter/) || ($fullname=~/^$filter/i)) {
179: my $grouplist = '';
180: foreach my $group (sort(keys(%allgroups))) {
181: if (exists($grouplist{$group.':'.$uname.':'.$udom})) {
182: my ($end,$start) = split(/:/,$grouplist{$group.':'.$uname.':'.$udom});
183: if (($end!=0) && ($end<$now)) { next; }
184: if (($start!=0) && ($start>$now)) {next; }
185: $grouplist .= " $group,";
186: }
187: }
188: $grouplist =~ s/,$//;
189: my $markedupclicker;
190: if ($clicker) {
191: $markedupclicker=(&Apache::lonnet::userenvironment($udom,$uname,'clickers'))[1];
192: if ($markedupclicker!~/\w/) {
193: $markedupclicker='-';
194: } else {
195: foreach my $frag (@fragments) {
196: if ($markedupclicker=~/\Q$frag\E/is) {
197: $markedupclicker=~s/(\Q$frag\E)/<font color=\"green\" size=\"\+1\"><b>$1<\/b><\/font>/gis;
198: last;
199: }
200: }
201: }
202: }
203: $result .=&Apache::loncommon::start_data_table_row().
204: '<td>'.
205: '<input type="button" value="'.&mt('Select').'" onclick="gochoose('.
206: "'".$uname."','".$udom."')".'" /></td>'.
207: '<td><tt>'.$uname.'</tt></td><td> <tt>'.$udom.
208: '</tt></td><td>'.
209: &Apache::loncommon::aboutmewrapper($fullname,
210: $uname,$udom).
211: '</td><td>'.$id.'</td><td>'.$section.
212: '</td><td>'.$grouplist.'</td>'.
213: ($clicker?'<td>'.$markedupclicker.'</td>':'').
214: &Apache::loncommon::end_data_table_row();
215: }
216: }
217: }
218: if (!$result) {
219: $r->print('<p>'.&mt('No students found.').'</p>');
220: } else {
221: $r->print(&Apache::loncommon::start_data_table().
222: &Apache::loncommon::start_data_table_header_row().
223: &Apache::loncommon::end_data_table_header_row().
224: '<th> </th>'.
225: '<th>'.&mt('username').'</th>'.
226: '<th>'.&mt('domain').'</th>'.
227: '<th>'.&mt('Name').'</th>'.
228: '<th>'.&mt('ID').'</th>'.
229: '<th>'.&mt('section').'</th>'.
230: '<th>'.&mt('active group(s)').'</th>'.
231: ($clicker?'<th>'.&mt('clicker').'</th>':'').
232: &Apache::loncommon::end_data_table_header_row().
233: $result.
234: &Apache::loncommon::end_data_table());
235: }
236: }
237: } else {
238: $r->print('<h3>'.&mt('Users with Roles Assigned by').' '.
239: &Apache::loncommon::plainname($env{'user.name'},
240: $env{'user.domain'}).'</h3>');
241: $r->print($filtermsg);
242: $r->rflush();
243:
244: $r->print('<p>'.&Apache::loncommon::start_data_table());
245: my %user_role=&Apache::lonnet::get_my_roles();
246: my %users;
247: foreach my $user_role (keys(%user_role)) {
248: next if ($user_role !~
249: /^($LONCAPA::username_re):($LONCAPA::domain_re):(\w+)$/);
250: my ($uname,$udom,$urole)=($1,$2,$3);
251: my $fullname=&Apache::loncommon::plainname($uname,$udom);
252: next if (($uname!~/^$filter/i) && ($fullname !~/^$filter/i));
253:
254: if (!exists($users{"$uname:$udom"})) {
255: $users{"$uname:$udom"} = {'fullname' => $fullname };
256: }
257: push(@{$users{"$uname:$udom"}{'roles'}},$urole);
258: }
259: foreach my $user (sort {lc($a) cmp lc($b)} (keys(%users))) {
260: my ($uname,$udom) = split(':',$user);
261: $r->print(&Apache::loncommon::start_data_table_row().
262: '<td>'.
263: '<input type="button" value="'.&mt('Select').'" onclick="gochoose('.
264: "'".$uname."','".$udom."')".'" /></td>'.
265: '<td><tt>'.$uname.'</tt></td>'.
266: '<td><tt>'.$udom.'</tt></td><td>'.
267: &Apache::loncommon::aboutmewrapper($users{$user}{'fullname'},
268: $uname,$udom).'</td>'.
269: '<td>'.
270: join(', ',sort(map {&Apache::lonnet::plaintext($_)}
271: (@{$users{$user}{'roles'}}))).
272: '</td>'.
273: &Apache::loncommon::end_data_table_row());
274: }
275: $r->print(&Apache::loncommon::end_data_table().'</p>');
276: }
277: $r->print('</form>'.&Apache::loncommon::end_page());
278: return OK;
279: }
280:
281: 1;
282: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>