1: # The LearningOnline Network
2: # Pick a student from the classlist
3: #
4: # $Id: lonpickstudent.pm,v 1.16 2006/05/09 14:38:10 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:
38: sub handler {
39: my $r = shift;
40: &Apache::loncommon::content_type($r,'text/html');
41: $r->send_http_header;
42: return OK if $r->header_only;
43:
44: # ------------------------------------------------------------ Print the screen
45: $r->print(&Apache::loncommon::start_page("Selecting a User",undef,
46: {'no_nav_bar' => 1}));
47:
48:
49: &Apache::loncommon::get_unprocessed_cgi
50: ($ENV{'QUERY_STRING'},['filter','form','unameelement','udomelement',
51: 'roles']);
52: # Allowed?
53: my $allowed;
54: my $scope = $env{'request.course.id'};
55: if (!($allowed = &Apache::lonnet::allowed('srm',$scope))) {
56: $scope .= '/'.$env{'request.course.sec'};
57: $allowed = &Apache::lonnet::allowed('srm',$scope);
58: if ($allowed) { $allowed = 'section'; }
59: }
60:
61: unless (($env{'form.roles'}) ||
62: (($env{'request.course.id'}) && ($allowed))) {
63: $r->print(&mt('No context.').
64: &Apache::loncommon::end_page());
65: return OK;
66: }
67:
68: # See if filter present
69:
70: my $filter=$env{'form.filter'};
71: $filter=~s/\W//g;
72: unless ($filter) { $filter='.'; }
73:
74: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
75: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
76: my $classlist=&Apache::loncoursedata::get_classlist();
77: my %grouplist=&Apache::lonnet::get_group_membership($cdom,$cnum);
78: my $now = time;
79: my %allgroups = &Apache::loncommon::coursegroups($cdom,$cnum);
80:
81: # --------------------------------------- There is such a user, get environment
82:
83: $r->print(<<ENDSCRIPT);
84: <script>
85: function gochoose(uname,udom) {
86: opener.document.$env{'form.form'}.$env{'form.unameelement'}.value=uname;
87: var slct=opener.document.$env{'form.form'}.$env{'form.udomelement'};
88: var i;
89: for (i=0;i<slct.length;i++) {
90: if (slct.options[i].value==udom) { slct.selectedIndex=i; }
91: }
92: self.close();
93: }
94: </script>
95: ENDSCRIPT
96:
97: $r->print('<form>');
98: if ($allowed && (!$env{'form.roles'})) {
99: # -------------------------------------------------------- Get course personnel
100: $r->print('<h3>'.$env{'course.'.$env{'request.course.id'}.'.description'}.
101: '</h3>');
102: my %coursepersonnel=
103: &Apache::lonnet::get_course_adv_roles();
104: $r->print('<table border="2">');
105: foreach my $role (sort keys %coursepersonnel) {
106: foreach (split(/\,/,$coursepersonnel{$role})) {
107: my ($puname,$pudom)=split(/\:/,$_);
108: $r->print('<tr><td>'.
109: '<input type="button" value="Select" onClick="gochoose('.
110: "'".$puname."','".$pudom."')".'" /></td><td>'.$role.'</td><td>'.
111: &Apache::loncommon::aboutmewrapper(
112: &Apache::loncommon::plainname($puname,
113: $pudom),$puname,$pudom).'</td></tr>');
114: }
115: }
116: $r->print('</table><p> ');
117: if ($filter ne '.') {
118: $r->print('<br/ >'.&mt('Name starting with').' "'.$filter.'"<br />');
119: }
120: $r->print('</p><p><table><tr><th> </th><th>username</th><th>domain</th><th>Name</th><th>ID</th><th>section</th><th>active group(s)</th></tr>');
121: # ------------------------------------------------------------------ Students
122: foreach (sort keys %$classlist) {
123: # the following undefs are for 'domain', and 'username' respectively.
124: my (undef,undef,$end,$start,$id,$section,$fullname,$status)=
125: @{$classlist->{$_}};
126: if ($allowed eq 'section' && $section ne $env{'request.course.sec'}) {
127: next;
128: }
129: if ($_=~/^(\w+)\:(\w+)$/) {
130: my ($uname,$udom)=($1,$2);
131: if (($uname=~/^$filter/) ||
132: ($fullname=~/^$filter/i)) {
133: my $grouplist = '';
134: foreach my $group (sort(keys(%allgroups))) {
135: if (exists($grouplist{$group.':'.$uname.':'.$udom})) {
136: my ($end,$start) = split(/:/,$grouplist{$group.':'.$uname.':'.$udom});
137: if (($end!=0) && ($end<$now)) { next; }
138: if (($start!=0) && ($start>$now)) {next; }
139: $grouplist .= " $group,";
140: }
141: }
142: $grouplist =~ s/,$//;
143: $r->print('<tr><td>'.
144: '<input type="button" value="'.&mt('Select').'" onClick="gochoose('.
145: "'".$uname."','".$udom."')".'" /></td>'.
146: '<td><tt>'.$uname.'</tt></td><td> <tt>'.$udom.
147: '</tt></td><td>'.
148: &Apache::loncommon::aboutmewrapper(
149: $fullname,
150: $uname,$udom).'</td><td>'.$id.'</td><td>'.$section.
151: '</td><td>'.$grouplist.'</td></tr>');
152: }
153: }
154: }
155:
156: $r->print('</table></p>');
157: } else {
158: $r->print('<h3>'.&mt('Users with Roles Assigned by').' '.
159: &Apache::loncommon::plainname($env{'user.name'},
160: $env{'user.domain'}).'</h3>');
161: if ($filter ne '.') {
162: $r->print('<br/ >'.&mt('Name starting with').' "'.$filter.'"<br />');
163: }
164: $r->print('<p><table>');
165: my %users=&Apache::lonnet::get_my_roles();
166: foreach (sort keys %users) {
167: if ($_=~/^(\w+)\:(\w+)\:(\w+)$/) {
168: my ($uname,$udom,$urole)=($1,$2,$3);
169: my $fullname=&Apache::loncommon::plainname($uname,$udom);
170: if (($uname=~/^$filter/) ||
171: ($fullname=~/^$filter/i)) {
172: $r->print('<tr><td>'.
173: '<input type="button" value="Select" onClick="gochoose('.
174: "'".$uname."','".$udom."')".'" /></td>'.
175: '<td><tt>'.$uname.'</tt></td><td><tt>'.$udom.
176: '</tt></td><td>'.
177: &Apache::loncommon::aboutmewrapper(
178: $fullname,
179: $uname,$udom).'</td><td><td>'.
180: &Apache::lonnet::plaintext($urole).
181: '</td></tr>');
182: }
183: }
184: }
185: $r->print('</table></p>');
186: }
187: $r->print('</form>'.&Apache::loncommon::end_page());
188: return OK;
189: }
190:
191: 1;
192: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>