File:
[LON-CAPA] /
loncom /
interface /
lonviewclasslist.pm
Revision
1.10:
download - view:
text,
annotated -
select for diffs
Wed Mar 12 02:45:07 2008 UTC (16 years, 5 months ago) by
raeburn
Branches:
MAIN
CVS tags:
version_2_8_X,
version_2_8_2,
version_2_8_1,
version_2_8_0,
version_2_7_X,
version_2_7_99_1,
version_2_7_99_0,
version_2_7_1,
version_2_7_0,
version_2_6_99_1,
version_2_6_99_0,
HEAD,
GCI_1
Change arguments accepted by lonnet::appenv() to:
1. reference to hash
2. (optional) reference to array.
Change all instances where lonnet::appenv() is called to replace first argument passed (originally a hash) to a reference to the hash.
- Modify lonnet.pm rev 1.35 code intended to prevent "dangerous" modifications of the environment, so it will actually do this.
- Allow these modifications to be made in certain instances:
DC switching to adhoc role
CC switching to a different course role in the current course.
user self-enrolling as a student
1: # The LearningOnline Network with CAPA
2: # Handler to display the classlist
3: #
4: # $Id: lonviewclasslist.pm,v 1.10 2008/03/12 02:45:07 raeburn 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: ##############################################################
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: use Apache::lonnet;
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
71: if (! ($env{'request.course.fn'})) {
72: $env{'user.error.msg'}=
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 $start_page = &Apache::loncommon::start_page('Classlist');
80: my $breadcrumbs= &Apache::lonhtmlcommon::breadcrumbs(undef,
81: 'Enrollment Manager');
82: $r->print(<<ENDHEADER);
83: $start_page
84: $breadcrumbs
85: ENDHEADER
86:
87: # Get classlist view settings
88: my %viewsettings = &retrieve_view_settings();
89:
90: # Print classlist
91: if (keys(%viewsettings) > 0) {
92: $r->print(&html_classlist($r,\%viewsettings));
93: } else {
94: $r->print('<h3>'.
95: &mt("Display of a student-viewable course roster is not currently enabled.").
96: '</h3>');
97: }
98: #
99: # Finish up
100: $r->print(&Apache::loncommon::end_page());
101: return OK;
102: }
103:
104: sub retrieve_view_settings {
105: my %viewsettings;
106: if (exists($env{'request.course.id'})) {
107: my $cid = $env{'request.course.id'};
108: my $viewpermission = 'course.'.$cid.'.student_classlist_view';
109: my $student_opt_in = 'course.'.$cid.'.student_classlist_opt_in';
110: my $portfiles_link = 'course.'.$cid.'.student_classlist_portfiles';
111: if (exists($env{$viewpermission}) &&
112: $env{$viewpermission} =~ /^(all|section)$/) {
113: $viewsettings{'permission'} = $env{$viewpermission};
114: if ($viewsettings{'permission'} =~ /^section$/i) {
115: $viewsettings{'limit_to_section'} = 1;
116: } else {
117: $viewsettings{'limit_to_section'} = 0;
118: }
119: $viewsettings{'student_opt_in'} = $env{$student_opt_in};
120: $viewsettings{'portfiles_link'} = $env{$portfiles_link};
121: }
122: }
123: return %viewsettings;
124: }
125:
126: sub html_classlist {
127: my ($r,$viewsettings) = @_;
128: my ($Str,$title,$secdisplay,$cid,$cdom,$cnum,$listtype,%publicroster);
129: my $fullroster = &Apache::loncoursedata::get_classlist();
130: my $classlist;
131:
132: if ($env{'form.action'} eq 'setenv') {
133: $Str .= &process_student_prefs();
134: }
135: $Str .= '<h3>'.&mt('Student-viewable course roster').'</h3>';
136:
137: $cid = $env{'request.course.id'};
138: $cdom = $env{'course.'.$cid.'.domain'};
139: $cnum = $env{'course.'.$cid.'.num'};
140:
141: if ($viewsettings->{'limit_to_section'}) {
142: if ($env{'request.course.sec'} eq '') {
143: $title = '<h4>'.&mt('Students with no section').'</h4>';
144: $listtype = 'without a section';
145: } else {
146: $title ='<h4>'.&mt('Students in section "[_1]"',
147: $env{'request.course.sec'}).'</h4>';
148: $listtype = 'in the section';
149: $secdisplay = " ($env{'request.course.sec'}) ";
150: }
151: } else {
152: $title .= '<h4>'.&mt('Students in any section').'</h4>';
153: $listtype = 'in the course';
154: }
155:
156: if ($viewsettings->{'student_opt_in'}) {
157: if ($env{'request.role'} =~ /^st/) {
158: $Str .= &print_roster_form();
159: }
160: %publicroster = &Apache::lonnet::dump('publicroster',$cdom,$cnum);
161: }
162:
163: $Str .= $title;
164:
165: my $fullcount = 0;
166: my $publiccount = 0;
167: my $displaycount = 0;
168: my $sectionidx = &Apache::loncoursedata::CL_SECTION();
169: my $statusidx = &Apache::loncoursedata::CL_STATUS();
170:
171: foreach my $student (keys(%{$fullroster})) {
172: my $section = $fullroster->{$student}->[$sectionidx];
173: my $status = $fullroster->{$student}->[$statusidx];
174: next if (lc($status) ne 'active');
175: if ($viewsettings->{'limit_to_section'}) {
176: next if ($section ne $env{'request.course.sec'});
177: }
178: $fullcount ++;
179: if ($viewsettings->{'student_opt_in'}) {
180: if ($publicroster{$student}) {
181: $classlist->{$student} = $fullroster->{$student};
182: $publiccount ++;
183: }
184: } else {
185: $classlist->{$student} = $fullroster->{$student};
186: }
187: }
188: if ($viewsettings->{'student_opt_in'}) {
189: $displaycount = $publiccount;
190: if ($fullcount > $publiccount) {
191: if ($publiccount) {
192: $Str .= &mt('Only students who have opted to be listed in the roster ([_1] out of [_2] students) are shown.',$publiccount,$fullcount).'<br />';
193: } else {
194: if ($fullcount == 1) {
195: $Str .= &mt('The single student '.$listtype.'[_1] has opted not to be listed in the roster.',$secdisplay);
196: } else {
197: $Str .= &mt('None of the [_1] students '.$listtype.'[_2] have opted to be listed in the roster.',$fullcount,$secdisplay);
198: }
199: return $Str;
200: }
201: } else {
202: if ($fullcount > 1) {
203: $Str .= &mt('All [_1] students '.$listtype.'[_2] have opted to be listed in the roster.',$fullcount,$secdisplay);
204: } elsif ($fullcount == 1) {
205: $Str .= &mt('The single student '.$listtype.'[_1] has opted to be listed in the roster.',$secdisplay);
206: }
207: }
208: } else {
209: $displaycount = $fullcount;
210: if ($fullcount > 1) {
211: $Str .= &mt('All [_1] students '.$listtype.'[_2] are listed in the roster.',$fullcount,$secdisplay);
212: } elsif ($fullcount == 1) {
213: $Str .= &mt('There is only a single student '.$listtype.'[_1]',$secdisplay);
214: }
215: }
216: undef($fullroster);
217:
218: if (!$displaycount) {
219: $Str .= &mt('There are currently no students to display.');
220: return $Str;
221: }
222:
223: # Set up a couple variables.
224: my $usernameidx = &Apache::loncoursedata::CL_SNAME();
225: my $domainidx = &Apache::loncoursedata::CL_SDOM();
226: my $fullnameidx = &Apache::loncoursedata::CL_FULLNAME();
227:
228: # Sort the students
229: my $sortby = $fullnameidx;
230: my @Sorted_Students = sort {
231: lc($classlist->{$a}->[$sortby]) cmp lc($classlist->{$b}->[$sortby])
232: } (keys(%$classlist));
233: $Str .= '<br />'.&Apache::loncommon::start_data_table()."\n".
234: &Apache::loncommon::start_data_table_header_row()."\n".
235: '<th></th>'. # for the count
236: '<th>'.&mt('Student').'</th>'.
237: '<th>'.&mt('Username').'</th>';
238: if (! $viewsettings->{'limit_to_section'}) {
239: $Str .= '<th>'.&mt('Section').'</th>';
240: }
241: if ($viewsettings->{'portfiles_link'}) {
242: $Str .= '<th>'.&mt('Available Portfolio files').'</th>';
243: }
244: $Str .= &Apache::loncommon::end_data_table_header_row();
245: my $count ++;
246: foreach my $student (@Sorted_Students) {
247: my $username = $classlist->{$student}->[$usernameidx];
248: my $domain = $classlist->{$student}->[$domainidx];
249: my $fullname = $classlist->{$student}->[$fullnameidx];
250: if ($fullname =~ /^\s*$/) {
251: $fullname = &mt('Name not given');
252: }
253: my $section = $classlist->{$student}->[$sectionidx];
254: if ($section eq '') {
255: $section = &mt('none');
256: }
257: $Str .= &Apache::loncommon::start_data_table_row()."\n".
258: '<td>'.$count++.'</td>'.
259: '<td>'.&Apache::loncommon::aboutmewrapper($fullname,
260: $username,
261: $domain).'</td>'.
262: '<td>'.(' 'x2).
263: &Apache::loncommon::messagewrapper
264: ('<img src="/adm/lonIcons/mailto.gif" border="0" /> '.
265: $username.'@'.$domain,$username,$domain).'</td>';
266: if (! $viewsettings->{'limit_to_section'}) {
267: $Str .= '<td>'.$section.'</td>';
268: }
269: if ($viewsettings->{'portfiles_link'}) {
270: my $filecounts = &Apache::lonaboutme::portfolio_files($r,'showlink',undef,undef,$domain,$username,$fullname);
271: my $link;
272: if (ref($filecounts) eq 'HASH') {
273: $link = &mt('[quant,_1,file,files,No files]',$filecounts->{'both'});
274: if ($filecounts->{'both'} > 0) {
275: $link = '<a href="/adm/'.$domain.'/'.$username.'/aboutme/portfolio?classlist">'.$link.'</a>';
276: }
277: } else {
278: $link = '<span class="LC_error">'.&mt("Error retrieving file information.").'</span>';
279: }
280: $Str .= '<td>'.$link.'</td>';
281: }
282: $Str .= &Apache::loncommon::end_data_table_row()."\n";
283: }
284: $Str .= &Apache::loncommon::end_data_table();
285: return $Str;
286: }
287:
288: sub print_roster_form {
289: my $cid = $env{'request.course.id'};
290: my $showinroster = $env{'environment.internal.'.$cid.'.showinroster'};
291: my ($showoff,$showon);
292: if ($showinroster) {
293: $showon = ' checked="checked" ';
294: $showoff = ' ';
295: } else {
296: $showoff = ' checked="checked" ';
297: $showon = ' ';
298: }
299: my $output = '<hr /><h4>'.&mt('Your roster setting').'</h4>';
300: if ($showinroster) {
301: $output .= &mt('You are currently listed in the student-viewable roster.');
302: } else {
303: $output .= &mt('You are currently <b>not</b> listed in the student-viewable roster.');
304: }
305: $output .= '<br />'.&mt('Include yourself in the roster?').' '.
306: '<form name="studentparm" method="post">'.
307: '<span class="LC_nobreak"><label><input type="radio" name="showinroster" value="1"'.$showon.'/>'.&mt('Yes').'</label> <label>'.
308: '<input type="radio" name="showinroster" value="0"'.$showoff.'/>'.&mt('No').
309: '</label></span><br /><br />'.
310: '<input type="hidden" name="action" value="setenv" />'.
311: '<input type="submit" name="studentsubmit" value="'.&mt('Save').'" /></form><hr />';
312: return $output;
313: }
314:
315: sub process_student_prefs {
316: my $cid = $env{'request.course.id'};
317: my $cdom = $env{'course.'.$cid.'.domain'};
318: my $cnum = $env{'course.'.$cid.'.num'};
319: my $uname = $env{'user.name'};
320: my $udom = $env{'user.domain'};
321: my $student = $uname.':'.$udom;
322: my %pubroster = &Apache::lonnet::get('publicroster',[$student],$cdom,$cnum);
323: my $visibility = &mt('off');
324: my $showinroster = $env{'form.showinroster'};
325: if ($showinroster) {
326: $visibility = &mt('on');
327: }
328: my $sturoster = 0;
329: if ($pubroster{$student}) {
330: $sturoster = 1;
331: }
332: my $output;
333: if ($sturoster ne $showinroster) {
334: my %changeHash = (
335: 'environment.internal.'.$cid.'.showinroster' => $showinroster,
336: );
337: my $putresult = &Apache::lonnet::put('environment',
338: \%changeHash,$udom,$uname);
339: if ($putresult eq 'ok') {
340: &Apache::lonnet::appenv(\%changeHash);
341: my $result = &Apache::lonnet::put('publicroster',{$student => $showinroster,},$cdom,$cnum);
342: if ($result eq 'ok') {
343: $output .= &mt('Display of your name in the student-viewable roster set to <b>[_1]</b>.',$visibility);
344: } else {
345: $output .= '<span class="LC_error">'.&mt('Error occurred saving display setting.').'</span>';
346: }
347: } else {
348: $output .= '<span class="LC_error">'.&mt('Error occurred saving display setting.').'</span>';
349: }
350: } else {
351: $output .= &mt('Display of your name in the student-viewable roster unchanged (set to <b>[_1]</b>).',$visibility);
352: }
353: return $output;
354: }
355:
356:
357:
358:
359: ###################################################################
360: ###################################################################
361:
362: 1;
363: __END__
364:
365:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>