Annotation of loncom/interface/lonviewclasslist.pm, revision 1.3
1.1 matthew 1: # The LearningOnline Network with CAPA
2: # Handler to display the classlist
3: #
1.3 ! matthew 4: # $Id: lonviewclasslist.pm,v 1.2 2004/08/27 04:18:11 raeburn Exp $
1.1 matthew 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: ##############################################################
30:
31: package Apache::lonviewclasslist;
32:
33: use strict;
34: use Apache::loncoursedata();
35: use Apache::loncommon();
36: use Apache::lonhtmlcommon();
37: use Apache::Constants qw(:common :http REDIRECT);
38: use Apache::lonlocal;
39:
40:
41: ###################################################################
42: ###################################################################
43:
44: =pod
45:
46: =item &handler
47:
48: The typical handler you see in all these modules. Takes $r, the
49: http request, as an argument.
50:
51: =cut
52:
53: ###################################################################
54: ###################################################################
55: sub handler {
56: my $r=shift;
57: if ($r->header_only) {
58: &Apache::loncommon::content_type($r,'text/html');
59: $r->send_http_header;
60: return OK;
61: }
62: # &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
63: # ['action','state']);
64: &Apache::lonhtmlcommon::clear_breadcrumbs();
65: &Apache::lonhtmlcommon::add_breadcrumb
66: ({href=>"/adm/viewclasslist",
67: text=>"View Classlist",
68: faq=>9,bug=>'Instructor Interface',});
69: # Needs to be in a course
70: if (! ($ENV{'request.course.fn'})) {
71: $ENV{'user.error.msg'}=
72: "/adm/viewclasslist:not in course role";
73: return HTTP_NOT_ACCEPTABLE;
74: }
75: &Apache::loncommon::content_type($r,'text/html');
76: $r->send_http_header;
77: #
78: my $bodytag=&Apache::loncommon::bodytag('Classlist');
79: my $breadcrumbs=&Apache::lonhtmlcommon::breadcrumbs(undef,
80: 'Enrollment Manager');
81: $r->print(<<ENDHEADER);
82: <html>
83: <head>
84: <title>Classlist</title>
85: </head>
86: $bodytag
87: $breadcrumbs
88: ENDHEADER
89: #
90: # Print classlist
91: my $cid = $ENV{'request.course.id'};
92: my $viewpermission = 'course.'.$cid.'.student_classlist_view';
93: if (&allowed_to_view_classlist()) {
94: $r->print(&html_classlist());
95: } else {
96: $r->print('<h2>'.
97: &mt("You are not authorized to view the classlist for your course.").
98: '</h2>');
99: }
100: #
101: # Finish up
102: $r->print('</body></html>');
103: return OK;
104: }
105:
106: sub allowed_to_view_classlist {
107: return 0 if (! exists($ENV{'request.course.id'}));
108: my $cid = $ENV{'request.course.id'};
109: my $viewpermission = 'course.'.$cid.'.student_classlist_view';
110: if (exists($ENV{$viewpermission}) &&
111: $ENV{$viewpermission} =~ /^(all|section)$/) {
112: return $ENV{$viewpermission};
113: } else {
114: return 0;
115: }
116: }
117:
118: sub html_classlist {
119: my $limit_to_section = (&allowed_to_view_classlist()=~ /^section$/i);
120: my $Str;
121: if ($limit_to_section) {
122: if ($ENV{'request.course.sec'} eq '') {
123: $Str .= '<h2>'.
124: &mt('Students with no section').'</h2>';
125: } else {
126: $Str.='<h2>'.
127: &mt('Students in section "[_1]"',
128: $ENV{'request.course.sec'}).
129: '</h2>';
130: }
131: }
132: #
133: my $classlist = &Apache::loncoursedata::get_classlist();
134: #
135: # Set up a couple variables.
136: my $usernameidx = &Apache::loncoursedata::CL_SNAME();
137: my $domainidx = &Apache::loncoursedata::CL_SDOM();
138: my $fullnameidx = &Apache::loncoursedata::CL_FULLNAME();
139: my $sectionidx = &Apache::loncoursedata::CL_SECTION();
140: my $statusidx = &Apache::loncoursedata::CL_STATUS();
141: #
142: # Sort the students
143: my $sortby = $fullnameidx;
144: my @Sorted_Students = sort {
145: lc($classlist->{$a}->[$sortby]) cmp lc($classlist->{$b}->[$sortby])
146: } (keys(%$classlist));
147: $Str .= '<table>'.$/.
148: '<tr>'.
149: '<th></th>'. # for the count
150: '<th>'.&mt('Student').'</th>'.
151: '<th>'.&mt('Username').'</th>';
152: if (! $limit_to_section) {
153: $Str .= '<th>'.&mt('Section').'</th>';
154: }
155: $Str .='</tr>'.$/;
156: my $count ++;
157: foreach my $student (@Sorted_Students) {
158: my $username = $classlist->{$student}->[$usernameidx];
159: my $domain = $classlist->{$student}->[$domainidx];
160: my $fullname = $classlist->{$student}->[$fullnameidx];
161: if ($fullname =~ /^\s*$/) {
162: $fullname = &mt('Name not given');
163: }
164: my $section = $classlist->{$student}->[$sectionidx];
165: my $status = $classlist->{$student}->[$statusidx];
1.3 ! matthew 166: next if (lc($status) ne 'active');
1.1 matthew 167: if ($limit_to_section) {
168: if ($section ne $ENV{'request.course.sec'}) {
169: next;
170: }
171: }
172: $Str .= '<tr>'.
173: '<td>'.$count++.'</td>'.
174: '<td>'.&Apache::loncommon::aboutmewrapper($fullname,
175: $username,
176: $domain).'</td>'.
177: '<td>'.(' 'x2).
178: &Apache::loncommon::messagewrapper
1.2 raeburn 179: ('<img src="/adm/lonIcons/mailto.gif" border="0" /> '.
1.1 matthew 180: $username.'@'.$domain,$username,$domain).'</td>';
181: if (! $limit_to_section) {
182: $Str .= '<td>'.$section.'</td>';
183: }
184: $Str .= '</tr>'.$/;
185: }
186: $Str .= '</table>';
187: return $Str;
188: }
189:
190: ###################################################################
191: ###################################################################
192:
193: 1;
194: __END__
195:
196:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>