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