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