File:
[LON-CAPA] /
loncom /
interface /
lonpickstudent.pm
Revision
1.20:
download - view:
text,
annotated -
select for diffs
Wed Dec 6 20:54:13 2006 UTC (17 years, 8 months ago) by
albertel
Branches:
MAIN
CVS tags:
version_2_4_X,
version_2_4_2,
version_2_4_1,
version_2_4_0,
version_2_3_X,
version_2_3_99_0,
version_2_3_2,
version_2_3_1,
version_2_3_0,
version_2_2_99_1,
version_2_2_99_0,
HEAD
- style
- re strign replacement
1: # The LearningOnline Network
2: # Pick a student from the classlist
3: #
4: # $Id: lonpickstudent.pm,v 1.20 2006/12/06 20:54:13 albertel 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']);
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: if ($filter ne '') {
74: $filtermsg = '<br />'.&mt('Name starting with').' "'.$filter.'"<br />';
75: $filter = quotemeta($filter);
76: } else {
77: $filter = '.'
78: }
79:
80: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
81: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
82: my $classlist=&Apache::loncoursedata::get_classlist();
83: my %grouplist=&Apache::lonnet::get_group_membership($cdom,$cnum);
84: my $now = time;
85: my %allgroups = &Apache::longroup::coursegroups($cdom,$cnum);
86:
87: # --------------------------------------- There is such a user, get environment
88:
89: $r->print(<<ENDSCRIPT);
90: <script type="text/javascript">
91: function gochoose(uname,udom) {
92: opener.document.$env{'form.form'}.$env{'form.unameelement'}.value=uname;
93: var slct=opener.document.$env{'form.form'}.$env{'form.udomelement'};
94: var i;
95: for (i=0;i<slct.length;i++) {
96: if (slct.options[i].value==udom) { slct.selectedIndex=i; }
97: }
98: self.close();
99: }
100: </script>
101: ENDSCRIPT
102:
103: $r->print('<form>');
104: if ($allowed && (!$env{'form.roles'})) {
105: # -------------------------------------------------------- Get course personnel
106: $r->print('<h3>'.$env{'course.'.$env{'request.course.id'}.'.description'}.
107: '</h3>');
108: my %coursepersonnel=
109: &Apache::lonnet::get_course_adv_roles();
110: $r->print(&Apache::loncommon::start_data_table());
111: foreach my $role (sort(keys(%coursepersonnel))) {
112: foreach (split(/\,/,$coursepersonnel{$role})) {
113: my ($puname,$pudom)=split(/\:/,$_);
114: $role = &Apache::lonnet::plaintext($role,
115: &Apache::loncommon::course_type());
116: $r->print(&Apache::loncommon::start_data_table_row().
117: '<td>'.
118: '<input type="button" value="Select" onClick="gochoose('.
119: "'".$puname."','".$pudom."')".'" /></td><td>'.$role.'</td><td>'.
120: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($puname,$pudom),$puname,$pudom).'</td>'.
121: &Apache::loncommon::end_data_table_row());
122: }
123: }
124: $r->print(&Apache::loncommon::end_data_table().'<p> ');
125:
126: $r->print($filtermsg);
127:
128: $r->print('</p><p>'.
129: &Apache::loncommon::start_data_table().
130: &Apache::loncommon::start_data_table_header_row().
131: &Apache::loncommon::end_data_table_header_row().
132: '<th> </th>'.
133: '<th>'.&mt('username').'</th>'.
134: '<th>'.&mt('domain').'</th>'.
135: '<th>'.&mt('Name').'</th>'.
136: '<th>'.&mt('ID').'</th>'.
137: '<th>'.&mt('section').'</th>'.
138: '<th>'.&mt('active group(s)').'</th>'.
139: &Apache::loncommon::end_data_table_header_row());
140: # ------------------------------------------------------------------ Students
141: foreach my $user (sort(keys(%$classlist))) {
142: # the following undefs are for 'domain', and 'username' respectively.
143: my (undef,undef,$end,$start,$id,$section,$fullname,$status)=
144: @{$classlist->{$user}};
145: if ($allowed eq 'section' && $section ne $env{'request.course.sec'}) {
146: next;
147: }
148: if ($user=~/^($LONCAPA::username_re)\:($LONCAPA::domain_re)$/) {
149: my ($uname,$udom)=($1,$2);
150: if (($uname=~/^$filter/) ||
151: ($fullname=~/^$filter/i)) {
152: my $grouplist = '';
153: foreach my $group (sort(keys(%allgroups))) {
154: if (exists($grouplist{$group.':'.$uname.':'.$udom})) {
155: my ($end,$start) = split(/:/,$grouplist{$group.':'.$uname.':'.$udom});
156: if (($end!=0) && ($end<$now)) { next; }
157: if (($start!=0) && ($start>$now)) {next; }
158: $grouplist .= " $group,";
159: }
160: }
161: $grouplist =~ s/,$//;
162: $r->print(&Apache::loncommon::start_data_table_row().
163: '<td>'.
164: '<input type="button" value="'.&mt('Select').'" onClick="gochoose('.
165: "'".$uname."','".$udom."')".'" /></td>'.
166: '<td><tt>'.$uname.'</tt></td><td> <tt>'.$udom.
167: '</tt></td><td>'.
168: &Apache::loncommon::aboutmewrapper($fullname,
169: $uname,$udom).
170: '</td><td>'.$id.'</td><td>'.$section.
171: '</td><td>'.$grouplist.'</td>'.
172: &Apache::loncommon::end_data_table_row());
173: }
174: }
175: }
176:
177: $r->print(&Apache::loncommon::end_data_table().'</p>');
178: } else {
179: $r->print('<h3>'.&mt('Users with Roles Assigned by').' '.
180: &Apache::loncommon::plainname($env{'user.name'},
181: $env{'user.domain'}).'</h3>');
182: $r->print($filtermsg);
183:
184: $r->print('<p>'.&Apache::loncommon::start_data_table());
185: my %users=&Apache::lonnet::get_my_roles();
186: foreach my $user (sort(keys(%users))) {
187: if ($user =~
188: /^($LONCAPA::username_re)\:($LONCAPA::domain_re)\:(\w+)$/) {
189: my ($uname,$udom,$urole)=($1,$2,$3);
190: my $fullname=&Apache::loncommon::plainname($uname,$udom);
191: if (($uname=~/^$filter/) ||
192: ($fullname=~/^$filter/i)) {
193: $r->print(&Apache::loncommon::start_data_table_row().
194: '<td>'.
195: '<input type="button" value="Select" onClick="gochoose('.
196: "'".$uname."','".$udom."')".'" /></td>'.
197: '<td><tt>'.$uname.'</tt></td><td><tt>'.$udom.
198: '</tt></td><td>'.
199: &Apache::loncommon::aboutmewrapper(
200: $fullname,
201: $uname,$udom).'</td><td><td>'.
202: &Apache::lonnet::plaintext($urole).
203: '</td>'.
204: &Apache::loncommon::end_data_table_row());
205: }
206: }
207: }
208: $r->print(&Apache::loncommon::end_data_table().'</p>');
209: }
210: $r->print('</form>'.&Apache::loncommon::end_page());
211: return OK;
212: }
213:
214: 1;
215: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>