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