1: #
2: # $Id: lonwhatsnew.pm,v 1.97 2009/11/19 14:05:46 bisitz Exp $
3: #
4: # Copyright Michigan State University Board of Trustees
5: #
6: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
7: #
8: # LON-CAPA is free software; you can redistribute it and/or modify
9: # it under the terms of the GNU General Public License as published by
10: # the Free Software Foundation; either version 2 of the License, or
11: # (at your option) any later version.
12: #
13: # LON-CAPA is distributed in the hope that it will be useful,
14: # but WITHOUT ANY WARRANTY; without even the implied warranty of
15: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: # GNU General Public License for more details.
17: #
18: # You should have received a copy of the GNU General Public License
19: # along with LON-CAPA; if not, write to the Free Software
20: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21: #
22: # /home/httpd/html/adm/gpl.txt
23: #
24: # http://www.lon-capa.org/
25: #
26:
27:
28: package Apache::lonwhatsnew;
29:
30: use strict;
31: use lib qw(/home/httpd/lib/perl);
32: use Apache::lonnet;
33: use Apache::loncommon();
34: use Apache::lonhtmlcommon();
35: use Apache::lonlocal;
36: use Apache::loncoursedata();
37: use Apache::lonnavmaps();
38: use Apache::lonuserstate;
39: use Apache::lonuserutils;
40: use Apache::Constants qw(:common :http);
41: use Time::Local;
42: use GDBM_File;
43: use lib '/home/httpd/lib/perl/';
44: use LONCAPA;
45:
46: #----------------------------
47: # handler
48: #
49: #----------------------------
50:
51: sub handler {
52: my $r = shift;
53: if ($r->header_only) {
54: &Apache::loncommon::content_type($r,'text/html');
55: $r->send_http_header;
56: return OK;
57: }
58: &Apache::loncommon::get_unprocessed_cgi(
59: $ENV{'QUERY_STRING'},['command','refpage']);
60:
61: my $command = $env{'form.command'};
62: my $refpage = $env{'form.refpage'};
63:
64: my %checkallowed = ( coursenormalmail => 1,
65: coursecritmail => 1, );
66: foreach my $perm_check (['whn','whatsnew',1],
67: ['pch','coursediscussion',1],
68: ['mgr','handgrading',1],
69: ['vgr','abovethreshold',1],
70: ['opa','haserrors',1],
71: ['mdc','versionchanges',0],
72: ['vcl','newroles',1],
73: ['vcl','oldroles',1],
74: ) {
75: my ($perm,$key,$check_section) = @{ $perm_check };
76: my $scope = $env{'request.course.id'};
77: if (!($checkallowed{$key} = &Apache::lonnet::allowed($perm,$scope))) {
78: $scope .= '/'.$env{'request.course.sec'};
79: if ( $check_section ) {
80: $checkallowed{$key} = &Apache::lonnet::allowed($perm,$scope);
81: }
82: if ($checkallowed{$key}) {
83: $checkallowed{$key.'_section'} = $env{'request.course.sec'};
84: }
85: }
86: }
87:
88: if ( ! $env{'request.course.fn'} || ! $checkallowed{'whatsnew'}) {
89: # Not in a course, or no whn priv in course
90: $env{'user.error.msg'}="/adm/whatsnew::whn:0:0:Cannot display what's new page";
91: return HTTP_NOT_ACCEPTABLE;
92: }
93:
94: &Apache::loncommon::content_type($r,'text/html');
95: $r->send_http_header;
96:
97: $r->print(&display_header($command,\%checkallowed));
98:
99: &Apache::lonhtmlcommon::clear_breadcrumbs();
100: &Apache::lonhtmlcommon::add_breadcrumb
101: ({href=>'/adm/whatsnew',
102: text=>"What's New?"});
103: if (($command eq 'chgthreshold') && $checkallowed{'abovethreshold'}) {
104: &Apache::lonhtmlcommon::add_breadcrumb
105: ({href=>'/adm/whatsnew?command=chgthreshold&refpage='.$refpage,
106: text=>"Change thresholds"});
107: $r->print(&Apache::lonhtmlcommon::breadcrumbs
108: ("What's New?",#'Course_Action_Items_Thresholds'
109: ));
110: } elsif (($command eq 'chginterval') && $checkallowed{'versionchanges'} ) {
111: &Apache::lonhtmlcommon::add_breadcrumb
112: ({href=>'/adm/whatsnew?command=chginterval&refpage='.$refpage,
113: text=>"Change interval"});
114: $r->print(&Apache::lonhtmlcommon::breadcrumbs
115: ("What's New?",#'Course_Action_Items_Intervals'
116: ));
117: } elsif (($command eq 'chgdisc') && $checkallowed{'coursediscussion'}) {
118: &Apache::lonhtmlcommon::add_breadcrumb
119: ({href=>'/adm/whatsnew?command=chgdisc&refpage='.$refpage,
120: text=>"Change discussion display"});
121: $r->print(&Apache::lonhtmlcommon::breadcrumbs
122: ("What's New?",#'Course_Action_Items_Intervals'
123: ));
124: } elsif ($command eq 'courseinit') {
125: &Apache::lonhtmlcommon::add_breadcrumb
126: ({href=>'/adm/whatsnew?command=courseinit&refpage='.$refpage,
127: text=>"Course initialization preference"});
128: $r->print(&Apache::lonhtmlcommon::breadcrumbs
129: ("What's New?",#'Course_Action_Items_Initialization'
130: ));
131: } elsif ($command eq 'chgoldroleinterval' && $checkallowed{'oldroles'}) {
132: &Apache::lonhtmlcommon::add_breadcrumb
133: ({href=>'/adm/whatsnew?command=chgoldroleinterval&refpage='.$refpage,
134: text=>"Change interval"});
135: $r->print(&Apache::lonhtmlcommon::breadcrumbs
136: ("What's New?",#'Course_Action_Items_Intervals'
137: ));
138: } elsif ($command eq 'chgnewroleinterval' && $checkallowed{'newroles'}) {
139: &Apache::lonhtmlcommon::add_breadcrumb
140: ({href=>'/adm/whatsnew?command=chgnewroleinterval&refpage='.$refpage,
141: text=>"Change interval"});
142: $r->print(&Apache::lonhtmlcommon::breadcrumbs
143: ("What's New?",#'Course_Action_Items_Intervals'
144: ));
145: } else {
146: $r->print(&Apache::lonhtmlcommon::breadcrumbs
147: ("What's New?",#'Course_Action_Items_Display'
148: ));
149: }
150: &display_main_box($r,$command,$refpage,\%checkallowed);
151: return OK;
152: }
153:
154: #------------------------------
155: # display_main_box
156: #
157: # Display all the elements within the main box
158: #------------------------------
159:
160: sub display_main_box {
161: my ($r,$command,$refpage,$checkallowed) = @_;
162: my $domain=&Apache::loncommon::determinedomain();
163: my $function = &Apache::loncommon::get_users_function();
164: my $lctype = lc(&Apache::loncommon::course_type());
165: $r->print('<table width="100%" border="0" cellpadding="5" cellspacing="0"><tr><td width="100%">');
166:
167: my %threshold_titles = &Apache::lonlocal::texthash (
168: av_attempts => 'Average number of attempts',
169: degdiff => 'Degree of difficulty',
170: numstudents => 'Total number of students with submissions',
171: );
172: my %versions = (
173: -1 => "version changes since start of $lctype",
174: 2592000 => 'version changes since last month',
175: 604800 => 'version changes since last week',
176: 86400 => 'version changes since yesterday',
177: );
178: my %newroles = (
179: -1 => "roles which have become active since start of $lctype",
180: 2592000 => 'roles which have become active since last month',
181: 604800 => 'roles which have become active since last week',
182: 86400 => 'roles which have become active since yesterday',
183: );
184: my %oldroles = (
185: -1 => "roles which expired since start of $lctype",
186: 2592000 => 'roles which expired since last month',
187: 604800 => 'roles which expired since last week',
188: 86400 => 'roles which expired since yesterday',
189: );
190: my %interval_titles = (
191: versions => \%versions,
192: newroles => \%newroles,
193: oldroles => \%oldroles,
194: );
195: my %initpage = &Apache::lonlocal::texthash (
196: firstres => "first resource in the $lctype",
197: whatsnew => "What's New Page",
198: userpref => 'your general user preferences',
199: coursespecific => "specific setting for this $lctype",
200: );
201: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
202: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
203:
204: if (($command eq 'chgthreshold')
205: && $checkallowed->{'abovethreshold'}) {
206: &display_threshold_config($r,$refpage,\%threshold_titles,
207: $cdom,$crs);
208: } elsif (($command eq 'chginterval')
209: && $checkallowed->{'versionchanges'}) {
210: &display_interval_config($r,$refpage,\%interval_titles,'versions');
211: } elsif (($command eq 'chgdisc')
212: && $checkallowed->{'coursediscussion'}) {
213: &display_discussion_config($r,$refpage);
214: } elsif ($command eq 'courseinit') {
215: &courseinit_config($r,$refpage,\%initpage);
216: } elsif (($command eq 'chgnewroleinterval')
217: && $checkallowed->{'newroles'}) {
218: &display_interval_config($r,$refpage,\%interval_titles,'newroles');
219: } elsif (($command eq 'chgoldroleinterval')
220: && $checkallowed->{'oldroles'}) {
221: &display_interval_config($r,$refpage,\%interval_titles,'oldroles');
222: } else {
223: &display_actions_box($r,$command,$refpage,\%threshold_titles,
224: \%interval_titles,\%initpage,$cdom,$crs,$checkallowed);
225: }
226: my $end_page = &Apache::loncommon::end_page();
227: $r->print(<<END_OF_BLOCK);
228: </td>
229: </tr>
230: </table><br />
231: $end_page
232: END_OF_BLOCK
233: }
234:
235: #-------------------------------
236: # display_header
237: #
238: # Display the header information and set
239: # up the HTML
240: #-------------------------------
241:
242: sub display_header {
243: my ($command,$checkallowed) = @_;
244:
245: my $scripttag;
246: unless ($command eq 'chgthreshold' || $command eq 'chginterval' ||
247: $command eq 'chgoldroleinterval' || $command eq 'chgnewroleinterval') {
248: $scripttag = <<"END";
249: <script type="text/javascript">
250: function change_display(caller,change) {
251: caller.value = change;
252: document.visible.submit();
253: }
254:
255: function changeAll(change) {
256: END
257: foreach my $item (keys(%{$checkallowed})) {
258: if ($item =~ /_section$/) { next; }
259: if ($$checkallowed{$item}) {
260: $scripttag.='document.visible.display_'.$item.'.value=change'.
261: "\n";
262: }
263: }
264: $scripttag.='document.visible.submit();
265: }
266: </script>
267: ';
268: }
269: my $course_type=&Apache::loncommon::course_type();
270: return &Apache::loncommon::start_page("What's New?",
271: $scripttag);
272: }
273:
274: #-------------------------------
275: # display_actions_box
276: #
277: # Display the action items
278: #
279: #-------------------------------
280:
281: sub display_actions_box {
282: my ($r,$command,$refpage,$threshold_titles,$interval_titles,$initpage,
283: $cdom,$crs,$checkallowed) = @_;
284: my $udom = $env{'user.domain'};
285: my $uname = $env{'user.name'};
286: my $cid = $env{'request.course.id'};
287: my $crstype = &Apache::loncommon::course_type();
288: my $lctype = lc($crstype);
289: my %stulabel = (
290: 'Course' => 'students',
291: 'Community' => 'members',
292: );
293: my %lt = &Apache::lonlocal::texthash(
294: 'yacc' => 'You are accessing an invalid course',
295: 'gtfr' => 'Go to first resource',
296: 'hial' => 'Hide all',
297: 'shal' => 'Show all',
298: );
299:
300: my %unread = ();
301: my %ungraded = ();
302: my %bombed = ();
303: my %triggered = ();
304: my %changed = ();
305: my @newmsgs = ();
306: my @critmsgs = ();
307: my @newdiscussions = ();
308: my @tograde = ();
309: my @bombs = ();
310: my @warnings = ();
311: my $msgcount = 0;
312: my $critmsgcount = 0;
313: my $expirecount;
314: my %expired;
315: my $activecount;
316: my %activated;
317: my %res_title = ();
318: my %show = ();
319: my $needitems = 0;
320: my $boxcount = 0;
321:
322: my $result;
323: if ($command eq 'newcourseinit') {
324: $result = &store_courseinit_setting($uname,$udom,$cid,$initpage);
325: }
326:
327: my %threshold = ();
328: my %pagedesc = &Apache::lonlocal::texthash (
329: firstres => 'First resource',
330: whatsnew => "What's New Page",
331: userpref => 'user preference',
332: coursespecific => $lctype.' only',
333: default => 'default',
334: );
335:
336: my ($initcontrol,$initdisp) = &curr_courseinit();
337: my $currinit = $pagedesc{$initdisp}.' ('.$pagedesc{$initcontrol}.')';
338:
339: unless ($cid) {
340: $r->print('<p><span style="text-align: center; font-weight: bold;">'.$lt{'yacc'}.'</span></p>');
341: return;
342: }
343:
344: my $header = '';
345: if ($refpage eq 'start') {
346: if (tie(my %bighash,'GDBM_File',$env{'request.course.fn'}.'.db',
347: &GDBM_READER(),0640)) {
348: my $furl=$bighash{'first_url'};
349: untie(%bighash);
350: $header .= '<b><a href="'.$furl.'">'.$lt{'gtfr'}.
351: '</a></b><br />';
352: }
353: }
354: $header .= &mt('Page set to be displayed after you have selected a role in this '.$lctype).'.'
355: .' <span class="LC_nobreak">'
356: .&mt('Currently: [_1].','<i>'.$currinit.'</i>')
357: .' '
358: .&mt('[_1]Change[_2] for just [_3]this '.$lctype.'[_4] or for [_5]all your courses/communities[_6].'
359: ,'<b>'
360: ,'</b>'
361: ,'<a href="/adm/whatsnew?command=courseinit&refpage='.$refpage.'">'
362: ,'</a>'
363: ,'<a href="/adm/preferences?action=changecourseinit&refpage='.$refpage.'">'
364: ,'</a>')
365: .' </span>';
366:
367: $r->print(&Apache::loncommon::head_subbox($header));
368:
369: if ($command eq 'reset') {
370: $result = &process_reset($cdom,$crs);
371: } elsif ($command eq 'update') {
372: $result = &process_update($uname,$udom,$threshold_titles);
373: } elsif ($command eq 'newinterval') {
374: $result = &store_interval_setting($uname,$udom,$cid,$interval_titles);
375: } elsif ($command eq 'newdiscconf') {
376: $result = &store_discussion_setting($uname,$udom,$cid);
377: }
378:
379: my $store_result=&store_display_settings($uname,$udom,$cid,$checkallowed);
380:
381: unless ($store_result eq 'ok') {
382: &Apache::lonnet::logthis('Error saving whatsnew settings: '.
383: $store_result.' for '.'user '.$uname.':'.$udom.' in '.$lctype.' '.$cid);
384: $result .= '<span class="LC_error">'
385: .&mt('Unable to save visibility settings due to [_1]',
386: $store_result)
387: .'</span>';
388: }
389:
390: if ($result) {
391: $r->print($result.'<hr />');
392: }
393: $r->rflush();
394:
395: my (%timediff,%interval);
396: my %display_settings = &get_display_settings($uname,$udom,$cid);
397: $timediff{'versions'} = $display_settings{$cid.':interval'};
398: unless (defined($timediff{'versions'})) { $timediff{'versions'} = 604800; }
399: $interval{'versions'} = $interval_titles->{'versions'}->{$timediff{'versions'}};
400:
401: my %headings = &Apache::lonlocal::texthash(
402: coursediscussion => 'Unread '.$lctype.' discussion posts',
403: handgrading => 'Problems requiring handgrading',
404: haserrors => 'Problems with errors',
405: coursenormalmail => 'New '.$lctype.' messages',
406: coursecritmail => 'New critical messages in '.$lctype,
407: );
408:
409: if ($timediff{'versions'} == -1) {
410: $headings{'versionchanges'} = &mt('Resources in '.$lctype.' with version changes since start of '.$lctype);
411: } elsif ($timediff{'versions'} == 2592000) {
412: $headings{'versionchanges'} = &mt('Resources in '.$lctype.' with version changes since last month');
413: } elsif ($timediff{'versions'} == 604800) {
414: $headings{'versionchanges'} = &mt('Resources in '.$lctype.' with version changes since last week');
415: } elsif ($timediff{'versions'} == 86400) {
416: $headings{'versionchanges'} = &mt('Resources in '.$lctype.' with version changes since yesterday');
417: }
418:
419: $timediff{'oldroles'} = $display_settings{$cid.':oldroleinterval'};
420: unless (defined($timediff{'oldroles'})) { $timediff{'oldroles'} = 604800; }
421: $interval{'oldroles'} = $interval_titles->{'oldroles'}->{$timediff{'oldroles'}};
422:
423: if ($timediff{'oldroles'} == -1) {
424: $headings{'oldroles'} = &mt('Roles for which access to '.$lctype.' has expired since start of '.$lctype);
425: } elsif ($timediff{'oldroles'} == 2592000) {
426: $headings{'oldroles'} = &mt('Roles for which access to '.$lctype.' has expired since last month');
427: } elsif ($timediff{'oldroles'} == 604800) {
428: $headings{'oldroles'} = &mt('Roles for which access to '.$lctype.' has expired since last week');
429: } elsif ($timediff{'oldroles'} == 86400) {
430: $headings{'oldroles'} = &mt('Roles for which access to '.$lctype.' has expired since yesterday');
431: }
432:
433: $timediff{'newroles'} = $display_settings{$cid.':newroleinterval'};
434: unless (defined($timediff{'newroles'})) { $timediff{'newroles'} = 604800; }
435: $interval{'newroles'} = $interval_titles->{'newroles'}->{$timediff{'newroles'}};
436:
437: if ($timediff{'newroles'} == -1) {
438: $headings{'newroles'} = &mt('Roles for which access to '.$lctype.' has become available since start of '.$lctype);
439: } elsif ($timediff{'newroles'} == 2592000) {
440: $headings{'newroles'} = &mt('Roles for which access to '.$lctype.' has become available since last month');
441: } elsif ($timediff{'newroles'} == 604800) {
442: $headings{'newroles'} = &mt('Roles for which access to '.$lctype.' has become available since last week');
443: } elsif ($timediff{'newroles'} == 86400) {
444: $headings{'newroles'} = &mt('Roles for which access to '.$lctype.' has become available since yesterday');
445: }
446:
447: my $now = time;
448: if ($timediff{'versions'} == -1) {
449: $timediff{'versions'} = time;
450: }
451: my $starttime = $now - $timediff{'versions'};
452:
453: if ($timediff{'newroles'} == -1) {
454: $timediff{'newroles'} = time;
455: }
456: my $activatedstart = $now - $timediff{'newroles'};
457:
458: if ($timediff{'oldroles'} == -1) {
459: $timediff{'oldroles'} = time;
460: }
461: my $expiredstart = $now - $timediff{'oldroles'};
462:
463: my $countunread = $display_settings{$cid.':countunread'};
464: unless (defined($countunread)) {
465: $countunread = 'on';
466: }
467: if ($$checkallowed{'abovethreshold'}) {
468: &get_curr_thresholds(\%threshold,$uname,$udom,$cid,$cdom,$crs);
469: }
470:
471: $headings{'abovethreshold'} =
472: &mt('(Problems with av. attempts ≥ [_1] or deg. difficulty ≥ [_2]) [_3] and total number of '.$stulabel{$crstype}.' with submissions ≥ [_4]',
473: $threshold{'av_attempts'},$threshold{'degdiff'},
474: '<br />',$threshold{'numstudents'});
475:
476: my @actionorder = ('handgrading','haserrors','abovethreshold','versionchanges','coursediscussion','coursenormalmail','coursecritmail','newroles','oldroles');
477:
478: foreach my $key (keys(%{$checkallowed})) {
479: if ($key =~ /_section$/) { next; }
480: $show{$key} = 0;
481: if ($$checkallowed{$key}) {
482: unless ($display_settings{$cid.':'.$key} eq 'hide') {
483: $show{$key} = 1;
484: }
485: }
486: }
487:
488: foreach my $item (@actionorder) {
489: unless ($item eq 'coursenormalmail' || $item eq 'coursecritmail' ||
490: $item eq 'newroles' || $item eq 'oldroles') {
491: if ($show{$item}) {
492: $needitems = 1;
493: last;
494: }
495: }
496: }
497:
498: my $itemserror;
499: if ($needitems) {
500: $itemserror = &getitems(\%unread,\%ungraded,\%bombed,\%triggered,\%changed,\@newdiscussions,\@tograde,\@bombs,\@warnings,\%threshold,$cdom,$crs,\%res_title,\%show,$starttime,$countunread);
501: }
502: if ($show{'coursenormalmail'}) {
503: $msgcount = &getnormalmail(\@newmsgs);
504: }
505: if ($show{'coursecritmail'}) {
506: $critmsgcount = &getcritmail(\@critmsgs);
507: }
508: if ($show{'oldroles'}) {
509: $expirecount = &getexpired(\%expired,$expiredstart,'previous');
510: }
511: if ($show{'newroles'}) {
512: $activecount = &getactivated(\%activated,$activatedstart,'active');
513: }
514: $r->print(qq|<a href="javascript:changeAll('hide');">$lt{'hial'}</a>
515: <a href="javascript:changeAll('show');">$lt{'shal'}</a>
516: <form method="post" name="visible" action="/adm/whatsnew">\n|);
517: foreach my $item (keys(%{$checkallowed})) {
518: if ($item =~ /_section$/) { next; }
519: if ($$checkallowed{$item}) {
520: $r->print('<input type="hidden" name="display_'.$item.'" />'."\n");
521: }
522: }
523:
524: $r->print('<input type="hidden" name="refpage" value="'.$refpage.'" /></form><table class="LC_double_column"><tr><td class="LC_left_col">');
525:
526: my $displayed = 0;
527: my $totalboxes = 0;
528: foreach my $key (keys(%{$checkallowed})) {
529: if ($key =~ /_section$/) { next; }
530: if ($key eq 'whatsnew' ) { next; } # whatsnew check creates no box
531: if ($$checkallowed{$key}) {
532: $totalboxes ++;
533: }
534: }
535: my $halfway = 4;
536: # my $halfway = int($totalboxes/2) + $totalboxes%2;
537: foreach my $actionitem (@actionorder) {
538: if ($$checkallowed{$actionitem}) {
539: if ($displayed == $halfway) {
540: $r->print('</td><td> </td><td class="LC_right_col" >');
541: }
542: &display_launcher($r,$actionitem,$refpage,$checkallowed,\%show,\%headings,\%res_title,\@tograde,\%ungraded,\@bombs,\%bombed,\%changed,\@warnings,\%triggered,\@newdiscussions,\%unread,$msgcount,\@newmsgs,$critmsgcount,\@critmsgs,\%interval,$countunread,\%expired,$expirecount,\%activated,$activecount,$crstype,$itemserror);
543: $displayed ++;
544: }
545: }
546: $r->print('
547: </td>
548: </tr>
549: </table>
550: ');
551: }
552:
553: #-------------------------------
554: # display_threshold_config
555: #
556: # Display the threshold setting screen
557: #
558: #-------------------------------
559:
560: sub display_threshold_config {
561: my ($r,$refpage,$threshold_titles,$cdom,$crs) = @_;
562: my $uname = $env{'user.name'};
563: my $udom = $env{'user.dom'};
564: my $cid = $env{'request.course.id'};
565: my %threshold = ();
566: my $rowColor1 = "#ffffff";
567: my $rowColor2 = "#eeeeee";
568: my $rowColor;
569:
570: my @thresholditems = ("av_attempts","degdiff","numstudents");
571: my %threshold_titles = &Apache::lonlocal::texthash(
572: av_attempts => 'Average number of attempts',
573: degdiff => 'Degree of difficulty',
574: numstudents => 'Total number of students with submissions',
575: );
576: &get_curr_thresholds(\%threshold,$uname,$udom,$cid,$cdom,$crs);
577:
578: $r->print('<br /><form name="thresholdform" method="post" action="/adm/whatsnew">'.
579: &Apache::loncommon::start_data_table().
580: &Apache::loncommon::start_data_table_header_row().
581: '<th>'.&mt('Threshold Name').'</th>'."\n".
582: '<th>'.&mt('Current value').'</th>'."\n".
583: '<th>'.&mt('Change?').'</th>'."\n".
584: &Apache::loncommon::end_data_table_header_row());
585: foreach my $type (@thresholditems) {
586: my $parameter = $env{'request.course.id'}.':threshold_'.$type;
587: # onchange is javascript to automatically check the 'Set' button.
588: my $onchange = 'onFocus="javascript:window.document.forms'.
589: "['thresholdform'].elements['".$parameter."_setparmval']".
590: '.checked=true;"';
591: $r->print(&Apache::loncommon::start_data_table_row()."\n".
592: '<td>'.$threshold_titles{$type}.'</td>'."\n".
593: '<td>'.&Apache::lonhtmlcommon::textbox($parameter.'_value',
594: $threshold{$type},
595: 10,$onchange).'</td>'."\n".
596: '<td>'.
597: &Apache::lonhtmlcommon::checkbox($parameter.'_setparmval').
598: '</td>'."\n".
599: &Apache::loncommon::end_data_table_row());
600: }
601: $r->print(&Apache::loncommon::end_data_table()."\n".
602: '<br /><input type="submit" name="threshold" value="'.&mt('Save').'" />
603: <input type="hidden" name="command" value="update" />
604: <input type="hidden" name="refpage" value="'.$refpage.'" />
605: </form>');
606: }
607:
608: #-------------------------------
609: # display_interval_config
610: #
611: # Display the interval setting screen
612: #
613: #-------------------------------
614:
615: sub display_interval_config {
616: my ($r,$refpage,$interval_titles,$context) = @_;
617: my $setting = 'interval';
618: if ($context eq 'oldroles') {
619: $setting = 'oldroleinterval';
620: } elsif ($context eq 'newroles') {
621: $setting = 'newroleinterval';
622: }
623: my $lctype = lc(&Apache::loncommon::course_type());
624: my $current = &get_current($env{'user.name'},$env{'user.domain'},
625: $env{'request.course.id'},$setting);
626: if ($context eq 'oldroles') {
627: $r->print('<br />'.&mt('Choose the time window to use to display roles for which access to the '.$lctype.' expired.').'<br />');
628: } elsif ($context eq 'newroles') {
629: $r->print('<br />'.&mt('Choose the time window to use to display roles for which access to the '.$lctype.' became available.').'<br />');
630: } else {
631: $r->print('<br />'.&mt('Choose the time window to use to display resources in the '.$lctype.' with version changes.').'<br />');
632: }
633: unless ($current eq '') {
634: if (ref($interval_titles->{$context}) eq 'HASH') {
635: $r->print(' '.&mt('Current value is "[_1]".','<b>'.
636: $interval_titles->{$context}->{$current}.'</b>').'<br />');
637: }
638: }
639: $r->print('<br />
640: <form method="post" name="intervalswitch" action="/adm/whatsnew">
641: <input type="hidden" name="command" value="newinterval" />
642: <input type="hidden" name="intervaltype" value="'.$context.'" />
643: <input type="hidden" name="refpage" value="'.$refpage.'" />'.
644: &mt('Display:').'
645: <select name="interval">
646: <option value="" selected="selected">'.&mt('Select').'</option>
647: ');
648: if (ref($interval_titles) eq 'HASH') {
649: if (ref($interval_titles->{$context}) eq 'HASH') {
650: foreach my $key (reverse sort ({$a cmp $b} (keys(%{$interval_titles->{$context}})))) {
651: $r->print('<option value="'.$key.'">'.&mt($interval_titles->{$context}->{$key}).
652: '</option>'."\n");
653: }
654: }
655: }
656: $r->print('</select>
657: <input type="submit" name="display" value="'.
658: &mt('Save').'" /></form>');
659: return;
660: }
661:
662: #----------------------------------------------
663: # display_discussion_config
664: #
665: # Display the discussion display setting screen
666: #
667: #----------------------------------------------
668:
669: sub display_discussion_config {
670: my ($r,$refpage) = @_;
671: my $current = &get_current($env{'user.name'},$env{'user.domain'},
672: $env{'request.course.id'},'countunread');
673: if ($current eq '') {
674: $current = 'on';
675: }
676: my %opposite = (
677: 'on' => 'off',
678: 'off' => 'on',
679: );
680: $r->print('<script type="text/javascript">
681: function toggle_countunread(choice) {
682: if (choice == "unchanged") {
683: document.discussionswitch.command.value = "";
684: }
685: document.discussionswitch.submit();
686: }
687: </script>');
688: $r->print('<br />'
689: .&mt('Choose whether or not to display a count of the number of new posts for each resource or discussion board which has unread posts.')
690: .'<br />'
691: .&mt("This can increase the time taken to gather data for the [_1]What's New Page[_2] by a few seconds.",'<i>','</i>')
692: .' '
693: .&mt('Currently set to [_1].','<b>'.$current.'</b>.')
694: );
695: $r->print('<br /><br />
696: <form method="post" name="discussionswitch" action="/adm/whatsnew">
697: <input type="hidden" name="command" value="newdiscconf" />
698: <input type="hidden" name="refpage" value="'.$refpage.'" />
699: <input type="hidden" name="countunread" value="'.$opposite{$current}.'" />
700: ');
701: $r->print('<br/>
702: <input type="button" name="display" value="'.
703: &mt('Change to [_1]',&mt($opposite{$current})).'"
704: onclick="javascript:toggle_countunread('."'change'".')" />'.
705: (' ' x7).
706: '<input type="button" name="nochange" value="'.
707: &mt("No change").'"
708: onclick="javascript:toggle_countunread('."'unchanged'".')" />
709: </form>');
710: return;
711: }
712:
713: #---------------------------------------------------
714: # courseinit_config
715: #
716: # Set page displayed when course loads after
717: # selecting a role in the course from the roles page.
718: #
719: #---------------------------------------------------
720:
721: sub courseinit_config {
722: my ($r,$refpage,$initpage) = @_;
723: my ($control,$current) = &curr_courseinit();
724: my @chgstate = ('userpref','coursespecific');
725: my @chgentry = ('firstres','whatsnew');
726: my $lctype = lc(&Apache::loncommon::course_type());
727: my %lt = &Apache::lonlocal::texthash(
728: 'chwp' => "Choose which page will be displayed when you enter this $lctype after selecting a role.",
729: 'cuva' => 'Current value is determined by',
730: 'anis' => 'and is set to display',
731: 'padc' => 'Page display controlled by',
732: 'chce' => 'Choose '.$lctype.' entry',
733: 'moce' => 'Save',
734: );
735: $r->print(<<"END");
736: <br />$lt{'chwp'}
737: <br />$lt{'cuva'}: <b>
738: $$initpage{$control}</b> $lt{'anis'} <b>
739: $$initpage{$current}</b>.<br /><br />
740: <form method="post" name="courseinitswitch" action="/adm/whatsnew">
741: <input type="hidden" name="command" value="newcourseinit" />
742: <input type="hidden" name="refpage" value="$refpage" />
743: $lt{'padc'}:
744: END
745: foreach my $choice (@chgstate) {
746: my $chkstring;
747: if ($choice eq $control) {
748: $chkstring = ' checked="checked" ';
749: }
750: $r->print('<span class="LC_nobreak"><label><input type="radio" name="courseinit_control" value="'.
751: $choice.'"'.$chkstring.'/>'.$$initpage{$choice}.
752: ' </label></span>');
753: }
754: $r->print('<br /><br />'.&mt('If').' '.$$initpage{'coursespecific'}.
755: ' - <br />'.$lt{'chce'}.": \n");
756: foreach my $choice (@chgentry) {
757: my $chkstring;
758: if (($choice eq $current) && ($control eq 'coursespecific')) {
759: $chkstring = ' checked="checked" ';
760: }
761: $r->print('<span class="LC_nobreak"><label><input type="radio" name="courseinit_page" value="'.
762: $choice.'"'.$chkstring.'/>'.$$initpage{$choice}.
763: ' </label></span>');
764: }
765: $r->print('<br /><br /><input type="submit" name="display" value="'.
766: $lt{'moce'}.'" /></form>');
767: return;
768: }
769:
770: sub curr_courseinit {
771: my $current = &get_current($env{'user.name'},$env{'user.domain'},
772: $env{'request.course.id'},'courseinit');
773: my $control;
774: if ($current) {
775: $control = 'coursespecific';
776: } else {
777: $control = 'userpref';
778: my %userenv = &Apache::lonnet::get('environment',
779: ['course_init_display']);
780: if (exists($userenv{'course_init_display'})) {
781: $current = $userenv{'course_init_display'};
782: }
783: unless ($current) {
784: $current = 'whatsnew';
785: }
786: }
787: return ($control,$current);
788: }
789:
790: sub display_launcher {
791: my ($r,$action,$refpage,$checkallowed,$show,$headings,$res_title,
792: $tograde,$ungraded,$bombs,$bombed,$changed,$warnings,$triggered,
793: $newdiscussions,$unread,$msgcount,$newmsgs,$critmsgcount,$critmsgs,
794: $interval,$countunread,$expired,$expirecount,$activated,$activecount,
795: $crstype,$itemserror) = @_;
796:
797: if ($$checkallowed{$action}) {
798: &start_box($r,$show,$headings,$action,$refpage,$action);
799: if ($$show{$action}) {
800: if ($action eq 'handgrading') { # UNGRADED ITEMS
801: &display_handgrade($r,$tograde,$ungraded,$itemserror);
802: } elsif ($action eq 'haserrors') { # BOMBS
803: &display_haserrors($r,$bombs,$bombed,$res_title,$itemserror);
804: } elsif ($action eq 'versionchanges') { # VERSION CHANGES
805: &display_versionchanges($r,$changed,$res_title,$interval->{'versions'},$itemserror);
806: } elsif ($action eq 'abovethreshold') { # DEGDIFF/AV. TRIES TRIGGERS
807: &display_abovethreshold($r,$refpage,$warnings,$triggered,
808: $res_title,$itemserror);
809: } elsif ($action eq 'coursediscussion') { # UNREAD COURSE DISCUSSION
810: &display_coursediscussion($r,$newdiscussions,$unread,
811: $countunread,$res_title,$itemserror);
812: } elsif ($action eq 'coursenormalmail') { # NORMAL MESSAGES
813: &display_coursenormalmail($r,$msgcount,$newmsgs);
814: } elsif ($action eq 'coursecritmail') { # CRITICAL MESSAGES
815: &display_coursecritmail($r,$critmsgcount,$critmsgs);
816: } elsif ($action eq 'newroles') { # ACTIVATED ROLES
817: &display_rolechanges($r,$activecount,$activated,$interval->{'newroles'},
818: $crstype);
819: } elsif ($action eq 'oldroles') { # EXPIRED ROLES
820: &display_rolechanges($r,$expirecount,$expired,$interval->{'oldroles'},
821: $crstype);
822: }
823: }
824: &end_box($r);
825: }
826: return;
827: }
828:
829: sub getitems {
830: my ($unread,$ungraded,$bombed,$triggered,$changed,$newdiscussions,
831: $tograde,$bombs,$warnings,$threshold,$cdom,$crs,$res_title,$show,
832: $starttime,$countunread) = @_;
833: my $navmap = Apache::lonnavmaps::navmap->new();
834: if (!defined($navmap)) {
835: my $itemserror = '<span class="LC_warning">'.&mt('An error occurred retrieving information about the course.').'<br />'.&mt('It is recommended that you [_1]re-select the course[_2].','<a href="/adm/roles">','</a>').'</span>';
836: return $itemserror;
837: }
838: # force retrieve Resource to seed the part id cache we'll need it later
839: my @allres=$navmap->retrieveResources(undef,
840: sub {if ($_[0]->is_problem) { $_[0]->parts();} return 1;});
841: my %resourcetracker;
842: my $discussiontime;
843:
844: # Resource version changes
845: if ($$show{'versionchanges'}) {
846: &checkversions($cdom,$crs,$navmap,$changed,$starttime);
847: }
848:
849: if ($$show{'abovethreshold'}) {
850: %resourcetracker = &Apache::lonnet::dump('nohist_resourcetracker',
851: $cdom,$crs);
852: }
853:
854: foreach my $resource (@allres) {
855: my $result = '';
856: my $applies = 0;
857: my $symb = $resource->symb();
858: %{$$bombed{$symb}} = ();
859: %{$$ungraded{$symb}} = ();
860: %{$$triggered{$symb}} = ();
861: $$triggered{$symb}{numparts} = 0;
862: if ($resource->encrypted()) {
863: $$triggered{$symb}{'enclink'} = $resource->link();
864: $$triggered{$symb}{'encsymb'} = $resource->shown_symb();
865: }
866: my $title = $resource->compTitle();
867: $$res_title{$symb} = $title;
868: my $ressymb = $resource->wrap_symb();
869:
870: # Check if there are unread discussion postings
871: if ($$show{'coursediscussion'}) {
872: &check_discussions($resource,$symb,$ressymb,$title,
873: $newdiscussions,$unread,$countunread);
874: }
875:
876: # Check for ungraded problems
877: if ($resource->is_problem()) {
878: if ($$show{'handgrading'}) {
879: &check_handgraded($resource,$symb,$title,$cdom,$crs,$ungraded,
880: $tograde);
881: }
882: }
883:
884: # Check for bombs
885: if ($$show{'haserrors'}) {
886: &check_bombed($resource,$symb,$title,$bombs,$bombed);
887: }
888:
889: # Maxtries and degree of difficulty for problem parts, unless handgradeable
890: if ($$show{'abovethreshold'}) {
891: &check_thresholds($resource,$symb,\%resourcetracker,
892: $triggered,$threshold,$warnings);
893: }
894:
895: }
896: return;
897: }
898:
899: sub check_discussions {
900: my ($resource,$symb,$ressymb,$title,$newdiscussions,$unread,
901: $countunread) = @_;
902:
903: if (!$resource->hasDiscussion()) { return; }
904:
905: %{$$unread{$ressymb}} = ();
906: $$unread{$ressymb}{'title'} = $title;
907: $$unread{$ressymb}{'symb'} = $symb;
908: if ($resource->encrypted()) {
909: $$unread{$ressymb}{'enclink'} = $resource->link();
910: $$unread{$ressymb}{'encsymb'} = $resource->shown_symb();
911: }
912: push(@{$newdiscussions}, $ressymb);
913:
914: $$unread{$ressymb}{'lastpost'} = $resource->last_post_time();
915:
916: if ($countunread eq 'on') {
917: $$unread{$ressymb}{'unreadcount'} =
918: $resource->discussion_info('unread');
919: }
920: }
921:
922: sub check_handgraded {
923: my ($resource,$symb,$title,$cdom,$cnum,$ungraded,$tograde) = @_;
924: if ($resource->is_problem()) {
925: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
926: my $partlist=$resource->parts();
927: my $handgradeable;
928: foreach my $part (@$partlist) {
929: if ($resource->handgrade($part) eq 'yes') {
930: $handgradeable=1; last;
931: }
932: }
933: if ($handgradeable) {
934: my @ungraded = &Apache::bridgetask::get_queue_symb_status(
935: 'gradingqueue',$symb,$cdom,$cnum);
936: if (@ungraded > 0) {
937: $$ungraded{$symb}{count} = scalar(@ungraded);
938: $$ungraded{$symb}{title} = $title;
939: if ($resource->encrypted()) {
940: $$ungraded{$symb}{'enclink'} = $resource->link();
941: $$ungraded{$symb}{'encsymb'} = $resource->shown_symb();
942: }
943: push(@{$tograde},$symb);
944: }
945: }
946: }
947: }
948:
949: sub check_bombed {
950: my ($resource,$symb,$title,$bombs,$bombed) = @_;
951: if ($resource->getErrors()) {
952: my $errors = $resource->getErrors();
953: $errors =~ s/^,//;
954: my @bombs = split(/,/, $errors);
955: my $errorcount = scalar(@bombs);
956: my $errorlink = '<a href="/adm/email?display='.
957: &escape($bombs[0]).'">'.
958: $title.'</a>';
959: $$bombed{$symb}{errorcount} = $errorcount;
960: $$bombed{$symb}{errorlink} = $errorlink;
961: push(@{$bombs}, $symb);
962: }
963: }
964:
965: sub check_thresholds {
966: my ($resource,$symb,$resourcetracker,$triggered,$threshold,$warnings) = @_;
967: # Compile maxtries and degree of difficulty for problem parts, unless handgradeable
968: my @parts = @{$resource->parts()};
969: my %stats;
970: my %lastreset = ();
971: my $warning = 0;
972: foreach my $part (@parts) {
973: if ($resource->handgrade($part) eq 'yes') {
974: next;
975: }
976: if ($resource->is_survey($part)) {
977: next;
978: }
979: %{$stats{$part}} = ();
980: my ($attempts,$users,$corrects,$degdiff,$av_attempts);
981: if (exists($$resourcetracker{$symb."\0".$part."\0attempts"})) {
982: $attempts = $$resourcetracker{$symb."\0".$part."\0attempts"};
983: }
984: if (exists($$resourcetracker{$symb."\0".$part."\0users"})) {
985: $users = $$resourcetracker{$symb."\0".$part."\0users"};
986: }
987: if (exists($$resourcetracker{$symb."\0".$part."\0correct"})) {
988: $corrects = $$resourcetracker{$symb."\0".$part."\0correct"};
989: }
990: if ($attempts > 0) {
991: $degdiff = 1 - ($corrects/$attempts);
992: $degdiff = sprintf("%.2f",$degdiff);
993: }
994: if ($users > 0) {
995: $av_attempts = $attempts/$users;
996: $av_attempts = sprintf("%.2f",$av_attempts);
997: }
998: if ((($degdiff ne '' && $degdiff >= $$threshold{'degdiff'}) || ($av_attempts ne '' && $av_attempts >= $$threshold{'av_attempts'})) && ($users >= $$threshold{'numstudents'})) {
999: $stats{$part}{degdiff} = $degdiff;
1000: $stats{$part}{attempts} = $av_attempts;
1001: $stats{$part}{users} = $users;
1002: $lastreset{$part} = $$resourcetracker{$symb."\0".$part."\0resettime"};
1003: if ($lastreset{$part}) {
1004: $lastreset{$part} = &Apache::lonnavmaps::timeToHumanString($lastreset{$part});
1005: }
1006: $warning = 1;
1007: }
1008: }
1009: if ($warning) {
1010: $$triggered{$symb}{title} = $resource->title;
1011: my $partcount = 0;
1012: @{$$triggered{$symb}{text}} = ();
1013: foreach my $part (@parts) {
1014: if (exists($stats{$part}{users})) {
1015: my $resetname = 'reset_'.&escape($symb."\0".$part);
1016: my $resettitle = 'title_'.&escape($symb."\0".$part);
1017: if (@parts > 1) {
1018: $$triggered{$symb}{text}[$partcount] = '
1019: <td>'.&mt('part - ').$part.'</td>';
1020: } else {
1021: $$triggered{$symb}{text}[$partcount] = '
1022: <td>'.&mt('single part').'</td>';
1023: }
1024: $$triggered{$symb}{text}[$partcount] .= '
1025: <td>'.$stats{$part}{users}.'</td>
1026: <td>'.$stats{$part}{attempts}.'</td>
1027: <td>'.$stats{$part}{degdiff}.'</td>
1028: <td>'.$lastreset{$part}.'</td>
1029: <td><input type="checkbox" name="'.$resetname.'" /><input type="hidden" name="'.$resettitle.'" value="'.&escape($$triggered{$symb}{title}).'" /></td>';
1030: $partcount ++;
1031: }
1032: $$triggered{$symb}{numparts} = $partcount;
1033: }
1034: push(@{$warnings},$symb);
1035: }
1036: }
1037:
1038:
1039: sub get_curr_thresholds {
1040: my ($threshold,$uname,$udom,$cid,$cdom,$crs) = @_;
1041: # set default values
1042: %$threshold = (av_attempts => 2,
1043: degdiff => 0.5,
1044: numstudents => 2
1045: );
1046: my %thresholdsettings = &Apache::lonnet::dump('nohist_whatsnew',$udom,
1047: $uname,$cid.':threshold');
1048: my $thresholdcount = 0;
1049: my ($tmp) = %thresholdsettings;
1050: unless ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1051: foreach my $item (keys %{$threshold}) {
1052: if (exists($thresholdsettings{$cid.':threshold_'.$item})) {
1053: $$threshold{$item} =
1054: $thresholdsettings{$cid.':threshold_'.$item};
1055: $thresholdcount ++;
1056: }
1057: }
1058: }
1059: if ($thresholdcount == 3) {
1060: return;
1061: }
1062: my %coursesettings = &Apache::lonnet::dump('environment',
1063: $cdom,$crs,'internal.threshold');
1064: my ($temp) = %coursesettings;
1065: unless ($temp =~ /^(con_lost|error|no_such_host)/i) {
1066: foreach my $item (keys %{$threshold}) {
1067: unless (exists($thresholdsettings{$cid.':threshold_'.$item})) {
1068: if (exists($coursesettings{'internal.threshold_'.$item})) {
1069: $$threshold{$item} =
1070: $coursesettings{'internal.threshold_'.$item};
1071: }
1072: }
1073: }
1074: }
1075: return;
1076: }
1077:
1078: sub get_current {
1079: my ($uname,$udom,$cid,$caller) = @_;
1080: my $currvalue;
1081: my %settings = &Apache::lonnet::dump('nohist_whatsnew',$udom,$uname,$cid.
1082: ':'.$caller);
1083: my ($tmp) = %settings;
1084: unless ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1085: $currvalue = $settings{$cid.':'.$caller};
1086: }
1087: return $currvalue;
1088: }
1089:
1090: sub process_reset {
1091: my ($dom,$crs) = @_;
1092: my $result = '<b>'.&mt('Counters reset for following problems (and parts):').
1093: '</b><br />';
1094: my @agg_types = ('attempts','users','correct');
1095: my %agg_titles = &Apache::lonlocal::texthash (
1096: attempts => 'Number of submissions',
1097: users => 'Students with submissions',
1098: correct => 'Number of correct submissions',
1099: );
1100: my @resets = ();
1101: my %titles = ();
1102: foreach my $key (keys(%env)) {
1103: next if ($key !~ /^form\.reset_(.+)$/);
1104: my $title = &unescape($env{'form.title_'.$1});
1105: my $reset_item = &unescape($1);
1106: my %curr_aggregates = &Apache::lonnet::dump('nohist_resourcetracker',$dom,$crs,$reset_item);
1107: my %aggregates = ();
1108: my ($symb,$part) = split(/\0/,$reset_item);
1109: foreach my $type (@agg_types) {
1110: $aggregates{$reset_item."\0".$type} = 0;
1111: }
1112: $aggregates{$reset_item."\0".'resettime'} = time;
1113: my $putresult = &Apache::lonnet::put('nohist_resourcetracker',\%aggregates,
1114: $dom,$crs);
1115: if ($putresult eq 'ok') {
1116: $result .= $title.' -part '.$part.': ';
1117: my %new_aggregates = &Apache::lonnet::dump('nohist_resourcetracker',$dom,$crs,$reset_item);
1118: foreach my $type (@agg_types) {
1119: $result .= $agg_titles{$type}.' = '.$new_aggregates{$reset_item."\0".$type}.'; ';
1120: }
1121: $result =~ s/; $//;
1122: $result .= '<br />';
1123: } else {
1124: $result = $title.' -part '.$part.': '.&mt('Unable to reset counters to zero due to [_1]',$putresult).'.<br />'."\n";
1125: }
1126: }
1127: return $result;
1128: }
1129:
1130: sub process_update {
1131: my ($uname,$udom,$threshold_titles) = @_;
1132: my $setoutput = '<b>'.&mt('Changes to threshold(s) for problem tracking:').'</b><br />';
1133: foreach (keys %env) {
1134: next if ($_!~/^form\.(.+)\_setparmval$/);
1135: my $name = $1;
1136: my $value = $env{'form.'.$name.'_value'};
1137: if ($name && defined($value) && ($value ne '')) {
1138: my $put_result = &Apache::lonnet::put('nohist_whatsnew',
1139: {$name=>$value},$udom,$uname);
1140:
1141: my ($shortname) = ($name =~ /^\Q$env{'request.course.id'}\E:threshold_(.+)$/);
1142: if ($put_result eq 'ok') {
1143: $setoutput.=&mt('Set threshold for [_1] to [_2]',
1144: '<b>'.$$threshold_titles{$shortname}.'</b>',
1145: '<b>'.$value.'</b>').'<br />';
1146: } else {
1147: $setoutput.=&mt('Unable to set threshold for [_1] to [_2] due to [_3].',
1148: '<b>'.$name.'</b>','<b>'.$value.'</b>',
1149: '<tt>'.$put_result.'</tt>').'<br />';
1150: }
1151: }
1152: }
1153: return $setoutput;
1154: }
1155:
1156: sub getnormalmail {
1157: my ($newmsgs) = @_;
1158: # Check for unread mail in course
1159: my $msgcount = 0;
1160:
1161: my @messages = sort(&Apache::lonnet::getkeys('nohist_email'));
1162: foreach my $message (@messages) {
1163: my $msgid=&escape($message);
1164: my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
1165: &Apache::lonmsg::unpackmsgid($msgid);
1166: if (($fromcid) && ($fromcid eq $env{'request.course.id'})) {
1167: if (defined($sendtime) && $sendtime!~/error/) {
1168: my $numsendtime = $sendtime;
1169: if ($status eq 'new') {
1170: $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
1171: $msgcount ++;
1172: if ($shortsubj eq '') {
1173: $shortsubj = &mt('No subject');
1174: }
1175: push(@{$newmsgs}, {
1176: msgid => $msgid,
1177: sendtime => $sendtime,
1178: shortsub => $shortsubj,
1179: from => $fromname,
1180: fromdom => $fromdom
1181: });
1182: }
1183: }
1184: }
1185: }
1186: return $msgcount;
1187: }
1188:
1189: sub getcritmail {
1190: my ($critmsgs) = @_;
1191: # Check for critical messages in course
1192: my %what=&Apache::lonnet::dump('critical');
1193: my $result = '';
1194: my $critmsgcount = 0;
1195: foreach my $msgid (sort(keys(%what))) {
1196: my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
1197: &Apache::lonmsg::unpackmsgid($msgid);
1198: if (($fromcid) && ($fromcid eq $env{'request.course.id'})) {
1199: if (defined($sendtime) && $sendtime!~/error/) {
1200: my $numsendtime = $sendtime;
1201: $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
1202: $critmsgcount ++;
1203: if ($shortsubj eq '') {
1204: $shortsubj = &mt('No subject');
1205: }
1206: push(@{$critmsgs}, {
1207: msgid => $msgid,
1208: sendtime => $sendtime,
1209: shortsub => $shortsubj,
1210: from => $fromname,
1211: fromdom => $fromdom
1212: });
1213: }
1214: }
1215: }
1216: return $critmsgcount;
1217: }
1218:
1219: sub getexpired {
1220: my ($rolechgs,$rolechgtime,$status) = @_;
1221: my $expirecount = &getrolechanges($rolechgs,$rolechgtime,$status);
1222: return $expirecount;
1223: }
1224:
1225: sub getactivated {
1226: my ($rolechgs,$rolechgtime,$status) = @_;
1227: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1228: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1229: my $now = time();
1230: my $context = 'course';
1231: my ($permission,$allowed) =
1232: &Apache::lonuserutils::get_permission($context);
1233: my $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1234: my %changes=&Apache::lonnet::dump('nohist_rolelog',$cdom,$cnum);
1235: my (%stucounted,%advcounted);
1236: my $activatedcount = 0;
1237: if (keys(%changes) > 0) {
1238: foreach my $chg (sort { $b <=> $a } (keys(%changes))) {
1239: if (ref($changes{$chg}) eq 'HASH') {
1240: my $timestamp = $changes{$chg}{'exe_time'};
1241: if ($timestamp) {
1242: if ($rolechgtime > 0) {
1243: if ($timestamp < $rolechgtime) {
1244: last;
1245: }
1246: }
1247: if (ref($changes{$chg}{'logentry'}) eq 'HASH') {
1248: next if ($changes{$chg}{'delflag'});
1249: my $start = $changes{$chg}{'logentry'}{'start'};
1250: my $end = $changes{$chg}{'logentry'}{'end'};
1251: my $section = $changes{$chg}{'logentry'}{'section'};
1252: my $role = $changes{$chg}{'logentry'}{'role'};
1253: my $uname = $changes{$chg}{'uname'};
1254: my $udom = $changes{$chg}{'udom'};
1255: next if ($end && $end <= $now);
1256: if (($viewablesec ne '') && ($section ne '')) {
1257: next if ($viewablesec ne $section);
1258: }
1259: next if ($start >= $timestamp);
1260: if ($role eq 'st') {
1261: $stucounted{$uname.':'.$udom.':'.$section} = $start.':'.$end;
1262: } else {
1263: $advcounted{$uname.':'.$udom.':'.$role.':'.$section} = $start.':'.$end;
1264: }
1265: my %chginfo = (
1266: 'section' => $section,
1267: 'uname' => $uname,
1268: 'udom' => $udom,
1269: 'role' => $role,
1270: 'status' => $status,
1271: );
1272: $activatedcount ++;
1273: push (@{$rolechgs->{$timestamp}},\%chginfo);
1274: }
1275: }
1276: }
1277: }
1278: }
1279: $activatedcount += &getrolechanges($rolechgs,$rolechgtime,$status,\%stucounted,\%advcounted);
1280: return $activatedcount;
1281: }
1282:
1283: sub getrolechanges {
1284: my ($rolechgs,$rolechgtime,$status,$stucountref,$advcountref) = @_;
1285: my (%stucounted,%advcounted);
1286: if (ref($stucountref) eq 'HASH') {
1287: %stucounted = %{$stucountref};
1288: }
1289: if (ref($advcountref) eq 'HASH') {
1290: %advcounted = %{$advcountref};
1291: }
1292: my $withsec = 1;
1293: my $hidepriv = 1;
1294: my $context = 'course';
1295: my @statuses = ($status);
1296: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1297: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1298: my $now = time();
1299: my ($permission,$allowed) =
1300: &Apache::lonuserutils::get_permission($context);
1301: my $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1302: my $classlist = &Apache::loncoursedata::get_classlist();
1303: my $secidx = &Apache::loncoursedata::CL_SECTION();
1304: my $startidx = &Apache::loncoursedata::CL_START();
1305: my $endidx = &Apache::loncoursedata::CL_END();
1306: my $rolechgcount = 0;
1307: foreach my $key (keys(%{$classlist})) {
1308: my ($userstatus,$eventtime);
1309: my $student = $classlist->{$key};
1310: if (ref($student) eq 'ARRAY') {
1311: my $start = $student->[$startidx];
1312: my $end = $student->[$endidx];
1313: my $sec = $student->[$secidx];
1314: my ($stuname,$studom) = split(/:/,$key);
1315: if ($status eq 'active') {
1316: if (exists($stucounted{$key.':'.$sec})) {
1317: next;
1318: }
1319: }
1320: if (($end == 0) || ($end > $start)) {
1321: if ($start <= $now) {
1322: if ($end && $end < $now) {
1323: if ($rolechgtime > 0) {
1324: if ($end > $rolechgtime) {
1325: $userstatus = 'previous';
1326: }
1327: } else {
1328: $userstatus = 'previous';
1329: }
1330: } else {
1331: if ($rolechgtime > 0) {
1332: if ($start >= $rolechgtime) {
1333: $userstatus = 'active';
1334: }
1335: } else {
1336: $userstatus = 'active';
1337: }
1338: }
1339: }
1340: }
1341: next if ($userstatus ne $status);
1342: if ($status eq 'active') {
1343: $eventtime = $start;
1344: } else {
1345: $eventtime = $end;
1346: }
1347: if (($viewablesec ne '') && ($sec ne '')) {
1348: next if ($viewablesec ne $sec);
1349: }
1350: my %chginfo = (
1351: 'section' => $sec,
1352: 'uname' => $stuname,
1353: 'udom' => $studom,
1354: 'role' => 'st',
1355: 'status' => $userstatus,
1356: );
1357: $rolechgcount ++;
1358: push (@{$rolechgs->{$eventtime}},\%chginfo);
1359: }
1360: }
1361: my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
1362: \@statuses,undef,undef,$withsec,$hidepriv);
1363: foreach my $item (keys(%advrolehash)) {
1364: my ($userstatus,$eventtime);
1365: my ($uname,$udom,$role,$section) = split(/:/,$item,-1);
1366: my ($start,$end) = split(/:/,$advrolehash{$item});
1367: if ($start eq '-1' && $end eq '-1') {
1368: next;
1369: } else {
1370: if ($status eq 'active') {
1371: if (exists($advcounted{$item})) {
1372: next;
1373: }
1374: }
1375: if (($end == 0) || ($end > $start)) {
1376: if ($start <= $now) {
1377: if ($end && $end < $now) {
1378: if ($rolechgtime > 0) {
1379: if ($end > $rolechgtime) {
1380: $userstatus = 'previous';
1381: }
1382: } else {
1383: $userstatus = 'previous';
1384: }
1385: } else {
1386: if ($rolechgtime > 0) {
1387: if ($start >= $rolechgtime) {
1388: $userstatus = 'active';
1389: }
1390: } else {
1391: $userstatus = 'active';
1392: }
1393: }
1394: }
1395: }
1396: next if ($userstatus ne $status);
1397: if ($status eq 'active') {
1398: $eventtime = $start;
1399: } else {
1400: $eventtime = $end;
1401: }
1402: }
1403: if (($viewablesec ne '') && ($section ne '')) {
1404: next if ($viewablesec ne $section);
1405: }
1406: my %chginfo = (
1407: 'section' => $section,
1408: 'uname' => $uname,
1409: 'udom' => $udom,
1410: 'role' => $role,
1411: 'status' => $userstatus,
1412: );
1413: $rolechgcount ++;
1414: push (@{$rolechgs->{$eventtime}},\%chginfo);
1415: }
1416: return $rolechgcount;
1417: }
1418:
1419: sub checkversions {
1420: my ($cdom,$crs,$navmap,$changed,$starttime) = @_;
1421: my %changes=&Apache::lonnet::dump('versionupdate',$cdom,$crs);
1422: my ($tmp) = keys(%changes);
1423: unless ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1424: if (keys(%changes) > 0) {
1425: foreach my $key (sort(keys(%changes))) {
1426: if ($changes{$key} > $starttime) {
1427: my $version;
1428: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
1429: my $currentversion=&Apache::lonnet::getversion($key);
1430: my $revdate =
1431: &Apache::lonnet::metadata($root.'.'.$extension,
1432: 'lastrevisiondate');
1433: $revdate = &Apache::lonlocal::locallocaltime($revdate);
1434: my $linkurl=&Apache::lonnet::clutter($key);
1435: my $usedversion=$navmap->usedVersion('version_'.$linkurl);
1436: my @resources = $navmap->getResourceByUrl($linkurl,1);
1437: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1438: $version = $usedversion;
1439: } else {
1440: $version = $currentversion;
1441: }
1442: foreach my $res (@resources) {
1443: if (ref($res) eq 'Apache::lonnavmaps::resource') {
1444: my $symb = $res->symb();
1445: %{$$changed{$symb}} = (
1446: current => $currentversion,
1447: version => $version,
1448: revdate => $revdate,
1449: );
1450: }
1451: }
1452: }
1453: }
1454: }
1455: }
1456: return;
1457: }
1458:
1459: sub display_handgrade {
1460: my ($r,$tograde,$ungraded,$itemserror) = @_;
1461: my %lt = &Apache::lonlocal::texthash(
1462: 'prna' => 'Problem Name',
1463: 'nmun' => 'Number ungraded',
1464: 'nopr' => 'No problems require handgrading',
1465: );
1466: if (@{$tograde} > 0) {
1467: $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
1468: $lt{'prna'}.'</td><td class="LC_right_item">'.
1469: $lt{'nmun'}.'</td></tr>');
1470: my $rowNum = 0;
1471: foreach my $res (@{$tograde}) {
1472: $rowNum ++;
1473: my $css_class = $rowNum%2?' class="LC_odd_row"':'';
1474: my ($map,$id,$url)=&Apache::lonnet::decode_symb($res);
1475: my $linkurl=&Apache::lonnet::clutter($url);
1476: $linkurl .= '?symb='.&escape($res);
1477: if ($$ungraded{$res}{'enclink'}) {
1478: $linkurl =
1479: $$ungraded{$res}{'enclink'}.'?symb='.$$ungraded{$res}{'encsymb'};
1480: }
1481: $r->print('<tr'.$css_class.'><td><a href="'.$linkurl.'">'.$$ungraded{$res}{title}.'</a></td><td class="LC_right_item">'.$$ungraded{$res}{count}.'</td></tr>');
1482: }
1483: } elsif ($itemserror) {
1484: $r->print('<tr class="LC_empty_row"><td>'.$itemserror.'</td></tr>');
1485: } else {
1486: $r->print('<tr class="LC_empty_row"><td>'.$lt{'nopr'}.'</td></tr>');
1487: }
1488: }
1489:
1490: sub display_haserrors {
1491: my ($r,$bombs,$bombed,$res_title,$itemserror) = @_;
1492: my $bombnum = 0;
1493: my %lt = &Apache::lonlocal::texthash(
1494: reso => 'Resource',
1495: nmer => 'Number of errors',
1496: noer => 'No problems with errors',
1497: );
1498: if (@{$bombs} > 0) {
1499: $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
1500: $lt{'reso'}.'</td><td class="LC_right_item">'.
1501: $lt{'nmer'}.'</td></tr>');
1502: @{$bombs} = sort { &cmp_title($a,$b,$res_title) } @{$bombs};
1503: foreach my $bomb (@{$bombs}) {
1504: $bombnum ++;
1505: my $css_class = $bombnum%2?' class="LC_odd_row"':'';
1506: $r->print('<tr'.$css_class.'><td>'.$$bombed{$bomb}{errorlink}.
1507: '</td><td class="LC_right_item">'.
1508: $$bombed{$bomb}{errorcount}.'</td></tr>');
1509: }
1510: } elsif ($itemserror) {
1511: $r->print('<tr class="LC_empty_row"><td>'.$itemserror.'</td></tr>');
1512: } else {
1513: $r->print('<tr class="LC_empty_row"><td>'.$lt{'noer'}.'</td></tr>');
1514: }
1515: return;
1516: }
1517:
1518: sub display_abovethreshold {
1519: my ($r,$refpage,$warnings,$triggered,$res_title,$itemserror) = @_;
1520: my %lt = &Apache::lonlocal::texthash(
1521: reso => 'Resource',
1522: part => 'Part',
1523: nust => 'Num. students',
1524: avat => 'Av. Attempts',
1525: dedi => 'Deg. Diff',
1526: lare => 'Last Reset',
1527: reco => 'Reset Count?',
1528: rese => 'Reset counters to 0',
1529: nopr => 'No problems satisfy threshold criteria',
1530: );
1531: if (@{$warnings} > 0) {
1532: @{$warnings} = sort { &cmp_title($a,$b,$res_title) } @{$warnings};
1533: $r->print('<form name="reset_tracking" method="post" action="/adm/whatsnew">'.
1534: ' <input type="hidden" name="command" value="reset" />'."\n".
1535: ' <input type="hidden" name="refpage" value="'.$refpage.'" />'.
1536: "\n");
1537: $r->print('<tr class="LC_info_row">'.
1538: '<td class="LC_left_item">'.$lt{'reso'}.'</td>'.
1539: '<td>'.$lt{'part'}.'</td><td>'.$lt{'nust'}.'</td>'.
1540: '<td>'.$lt{'avat'}.'</td><td>'.$lt{'dedi'}.'</td>'.
1541: '<td>'.$lt{'lare'}.'</td><td class="LC_right_item">'.
1542: $lt{'reco'}.'</td></tr>');
1543: my $row;
1544: foreach my $res (@{$warnings}) {
1545: $row++;
1546: my ($map,$id,$url)=&Apache::lonnet::decode_symb($res);
1547: my $linkurl=&Apache::lonnet::clutter($url);
1548: my $rowspan;
1549: if ($$triggered{$res}{numparts} > 1) {
1550: $rowspan = 'rowspan="'.$$triggered{$res}{numparts}.'"';
1551: }
1552: $linkurl .= '?symb='.&escape($res);
1553: if ($$triggered{$res}{'enclink'}) {
1554: $linkurl =
1555: $$triggered{$res}{'enclink'}.'?symb='.$$triggered{$res}{'encsymb'};
1556: }
1557: my $css_class = $row%2?' class="LC_odd_row"':'';
1558: $r->print('<tr'.$css_class.'>'.
1559: '<td class="LC_first_item" '.$rowspan.'><a href="'.$linkurl.'">'.
1560: $$triggered{$res}{title}.'</a></td>');
1561: if (ref($$triggered{$res}{text}) eq 'ARRAY') {
1562: $r->print($$triggered{$res}{text}[0]);
1563: }
1564: $r->print('</tr>');
1565: if (ref($$triggered{$res}{text}) eq 'ARRAY') {
1566: if (@{$$triggered{$res}{text}} > 1) {
1567: for (my $i=1; $i<@{$$triggered{$res}{text}}; $i++) {
1568: $r->print('<tr class="'.$css_class.'">'.
1569: $$triggered{$res}{text}[$i].'</tr>');
1570: }
1571: }
1572: }
1573: }
1574: $r->print('<tr class="LC_info_row"><td colspan="7" class="LC_right_item"><br /><input type="submit" name="counters" value="'.$lt{'rese'}.'" /></td></tr></form>');
1575: } elsif ($itemserror) {
1576: $r->print('<tr class="LC_empty_row"><td>'.$itemserror.'</td></tr>');
1577: } else {
1578: $r->print('<tr class="LC_empty_row"><td>'.$lt{'nopr'}.'</td></tr>');
1579: }
1580: }
1581:
1582: sub display_versionchanges {
1583: my ($r,$changed,$res_title,$interval,$itemserror) = @_;
1584: my %lt = &Apache::lonlocal::texthash(
1585: 'reso' => 'Resource',
1586: 'revd' => 'Last revised',
1587: 'newv' => 'New version',
1588: 'veru' => 'Version used',
1589: );
1590: if (keys(%{$changed}) > 0) {
1591: $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
1592: $lt{'reso'}.'</td><td>'.$lt{'revd'}.'</td><td>'.
1593: $lt{'newv'}.'</td><td class="LC_right_item">'.
1594: $lt{'veru'}.'</td></tr>');
1595: my @changes = sort { &cmp_title($a,$b,$res_title) } keys(%{$changed});
1596: my $changenum = 0;
1597: foreach my $item (@changes) {
1598: $changenum ++;
1599: my $css_class = $changenum%2?' class="LC_odd_row"':'';
1600: my ($map,$id,$url)=&Apache::lonnet::decode_symb($item);
1601: my $linkurl=&Apache::lonnet::clutter($url);
1602: $linkurl .= '?symb='.&escape($item);
1603:
1604: $r->print('<tr'.$css_class.'><td><a href="'.$linkurl.'">'.
1605: $$res_title{$item}.'</a></td><td>'.
1606: $$changed{$item}{'revdate'}.'</td><td>'.
1607: $$changed{$item}{'current'}.'</td><td>'.
1608: $$changed{$item}{'version'}.'</td></tr>');
1609: }
1610: } elsif ($itemserror) {
1611: $r->print('<tr class="LC_empty_row"><td>'.$itemserror.'</td></tr>');
1612: } else {
1613: $r->print('<tr class="LC_empty_row"><td>'
1614: .&mt('No '.$interval).'</td></tr>');
1615: }
1616: return;
1617: }
1618:
1619: sub display_rolechanges {
1620: my ($r,$chgcount,$changed,$interval,$crstype) = @_;
1621: my $now = time();
1622: my %lt = &Apache::lonlocal::texthash(
1623: 'user' => 'User',
1624: 'tich' => 'Time of change',
1625: 'role' => 'Role',
1626: 'sec' => 'Section',
1627: 'status' => 'Status',
1628: );
1629: if ($chgcount) {
1630: $r->print('<tr class="LC_info_row">'.
1631: '<td class="LC_left_item">'.$lt{'tich'}.'</td>'.
1632: '<td class="LC_left_item">'.$lt{'user'}.'</td>'.
1633: '<td class="LC_left_item">'.$lt{'role'}.'</td>'.
1634: '<td class="LC_left_item">'.$lt{'sec'}.'</td>'.
1635: '<td class="LC_left_item">'.$lt{'status'}.'</td></tr>');
1636: if (ref($changed) eq 'HASH') {
1637: my @changes = sort { $b <=> $a } (keys(%{$changed}));
1638: my $changenum = 0;
1639: foreach my $item (@changes) {
1640: if (ref($changed->{$item}) eq 'ARRAY') {
1641: foreach my $chg (@{$changed->{$item}}) {
1642: if (ref($chg) eq 'HASH') {
1643: my $section;
1644: my $role =
1645: &Apache::lonnet::plaintext($chg->{'role'},$crstype);
1646: my $status = &mt($chg->{'status'});
1647: if ($chg->{'section'} eq '') {
1648: $section = &mt('none');
1649: } else {
1650: $section = $chg->{'section'};
1651: }
1652: my $uname = $chg->{'uname'};
1653: my $udom = $chg->{'udom'};
1654: $changenum ++;
1655: my $css_class = $changenum%2?' class="LC_odd_row"':'';
1656: my $link =
1657: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom);
1658: $r->print('<tr'.$css_class.'>'.
1659: '<td>'.&Apache::lonlocal::locallocaltime($item).'</td>'.
1660: '<td>'.$link.'</td>'.
1661: '<td>'.$role.'</td>'.
1662: '<td>'.$section.'</td>'.
1663: '<td>'.$status.'</td></tr>');
1664: }
1665: }
1666: }
1667: }
1668: }
1669: } else {
1670: $r->print('<tr class="LC_empty_row"><td>'
1671: .&mt('There are no '.$interval).'</td></tr>');
1672: }
1673: return;
1674: }
1675:
1676: sub display_coursediscussion {
1677: my ($r,$newdiscussions,$unread,$countunread,$res_title,$itemserror) = @_;
1678: my $lctype = lc(&Apache::loncommon::course_type());
1679: my %lt = &Apache::lonlocal::texthash(
1680: 'loca' => 'Location',
1681: 'type' => 'Type',
1682: 'numn' => 'Number of new posts',
1683: 'noun' => 'No unread posts in '.$lctype.' discussions',
1684: 'tmlp' => 'Time of last post',
1685: );
1686: if (@{$newdiscussions} > 0) {
1687: $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
1688: $lt{'loca'}.'</td><td>'.
1689: $lt{'type'}.'</td>');
1690: if ($countunread eq 'on') {
1691: $r->print('<td>'.$lt{'tmlp'}.'</td>'.
1692: '<td class="LC_right_item">'.$lt{'numn'}.'</td>');
1693: } else {
1694: $r->print('<td class="LC_right_item">'.$lt{'tmlp'}.'</td>');
1695: }
1696: $r->print("</tr>\n");
1697: @{$newdiscussions} = sort { &cmp_title($a,$b,$res_title) }
1698: @{$newdiscussions};
1699: my $rowNum = 0;
1700: foreach my $ressymb (@{$newdiscussions}) {
1701: $rowNum ++;
1702: my $forum_title = $$unread{$ressymb}{'title'};
1703: my $type = 'Resource';
1704: my $feedurl=&Apache::lonfeedback::get_feedurl($ressymb);
1705: my $disclink = $feedurl.'?symb='.$$unread{$ressymb}{symb};
1706: if ($feedurl =~ /bulletinboard/) {
1707: $type = 'Discussion Board';
1708: }
1709: if ($$unread{$ressymb}{'enclink'}) {
1710: $disclink = $$unread{$ressymb}{'enclink'}.'?symb='.$$unread{$ressymb}{'encsymb'};
1711: }
1712: my $css_class = $rowNum%2?' class="LC_odd_row"':'';
1713: my $lastpost = &Apache::lonnavmaps::timeToHumanString(
1714: $$unread{$ressymb}{'lastpost'});
1715: $r->print('<tr'.$css_class.'><td><a href="'.$disclink.'">'.$forum_title.'</a> </td><td>'.&mt($type).' </td>');
1716: if ($countunread eq 'on') {
1717: my $unreadnum = $$unread{$ressymb}{'unreadcount'};
1718: $r->print('<td>'.$lastpost.'</td><td class="LC_right_item">'.
1719: $unreadnum.' </td>');
1720: } else {
1721: $r->print('<td class="LC_right_item">'.$lastpost.'</td>');
1722: }
1723: $r->print("</tr>\n");
1724: }
1725: } elsif ($itemserror) {
1726: $r->print('<tr class="LC_empty_row"><td>'.$itemserror.'</td></tr>');
1727: } else {
1728: $r->print('<tr class="LC_empty_row"><td>'.$lt{'noun'}.'</td></tr>');
1729: }
1730: }
1731:
1732: sub display_coursenormalmail {
1733: my ($r,$msgcount,$newmsgs) = @_;
1734: my $lctype = lc(&Apache::loncommon::course_type());
1735: if ($msgcount > 0) {
1736: $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
1737: &mt('Number').'</td><td>'.&mt('Subject').'</td><td>'.
1738: &mt('Sender').'</td><td class="LC_right_item">'.
1739: &mt('Date/Time').'</td></tr>');
1740: my $mailcount = 0;
1741: foreach my $msg (@{$newmsgs}) {
1742: $mailcount ++;
1743: my $css_class = $mailcount%2?' class="LC_odd_row"':'';
1744: $r->print('<tr'.$css_class.'><td>'.$mailcount
1745: .'. </td><td><a href="/adm/email?display='
1746: .$msg->{'msgid'}.'">'
1747: .$msg->{'shortsub'}.'</a> </td><td> '
1748: .$msg->{'from'}.':'.$msg->{'fromdom'}.' </td><td>'
1749: .$msg->{'sendtime'}.'</td></tr>');
1750: }
1751: } else {
1752: $r->print('<tr class="LC_empty_row"><td>'.
1753: &mt('No new '.$lctype.' messages').'</td></tr>');
1754: }
1755: }
1756:
1757: sub display_coursecritmail {
1758: my ($r,$critmsgcount,$critmsgs) = @_;
1759: my $lctype = lc(&Apache::loncommon::course_type());
1760: if ($critmsgcount > 0) {
1761: $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
1762: &mt('Number').'</td><td>'.&mt('Subject').'</td><td>'.
1763: &mt('Sender').'</td><td class="LC_right_item">'.
1764: &mt('Date/Time').'</td></tr>');
1765: my $mailcount = 0;
1766: foreach my $msg (@{$critmsgs}) {
1767: $mailcount ++;
1768: my $css_class = $mailcount%2?' class="LC_odd_row"':'';
1769: $r->print('<tr'.$css_class.'><td>'.$mailcount.
1770: '. </td><td><a href="/adm/email?folder=critical">'.
1771: $msg->{'shortsub'}.'</a> </td><td> '.
1772: $msg->{'from'}.':'.$msg->{'fromdom'}.' </td><td>'.
1773: $msg->{'sendtime'}.'</td></tr>');
1774: }
1775: } else {
1776: $r->print('<tr class="LC_empty_row"><td>'.
1777: &mt('No unread critical messages in '.$lctype).
1778: '</td></tr>');
1779: }
1780: }
1781:
1782: sub cmp_title {
1783: my ($a,$b,$res_title) = @_;
1784: my ($atitle,$btitle) = (lc($$res_title{$a}),lc($$res_title{$b}));
1785: $atitle=~s/^\s*//;
1786: $btitle=~s/^\s*//;
1787: return $atitle cmp $btitle;
1788: }
1789:
1790: sub get_display_settings {
1791: my ($uname,$udom,$cid) = @_;
1792: my %settings = &Apache::lonnet::dump('nohist_whatsnew',$udom,$uname,$cid);
1793: my ($tmp) = keys(%settings);
1794: if ($tmp=~ /^(con_lost|error|no_such_host)/i) {
1795: %settings = ();
1796: unless ($tmp =~ /^error: 2 /) {
1797: my $lctype = lc(&Apache::loncommon::course_type());
1798: &Apache::lonnet::logthis('Error retrieving whatsnew settings: '.
1799: $tmp.' for '.$uname.':'.$udom.' for '.$lctype.': '.$cid);
1800: }
1801: }
1802: return %settings;
1803: }
1804:
1805: sub store_display_settings {
1806: my ($uname,$udom,$cid,$checkallowed) = @_;
1807: my %whatsnew_settings;
1808: my $result;
1809: foreach my $key (keys(%{$checkallowed})) {
1810: if ($key =~ /_section$/) { next; }
1811: if (exists($env{'form.display_'.$key})) {
1812: unless ($env{'form.display_'.$key} eq '') {
1813: $whatsnew_settings{$cid.':'.$key} = $env{'form.display_'.$key};
1814: }
1815: }
1816: }
1817: if (keys(%whatsnew_settings)) {
1818: $result = &Apache::lonnet::put('nohist_whatsnew',\%whatsnew_settings,
1819: $udom,$uname);
1820: } else {
1821: $result = 'ok';
1822: }
1823: return $result;
1824: }
1825:
1826: sub store_interval_setting {
1827: my ($uname,$udom,$cid,$interval_titles) = @_;
1828: my %interval_settings = ();
1829: my $result;
1830: my $context = $env{'form.intervaltype'};
1831: if ($env{'form.interval'} ne '') {
1832: if ($context eq 'oldroles') {
1833: $interval_settings{$cid.':oldroleinterval'} = $env{'form.interval'};
1834: } elsif ($context eq 'newroles') {
1835: $interval_settings{$cid.':newroleinterval'} = $env{'form.interval'};
1836: } else {
1837: $interval_settings{$cid.':interval'} = $env{'form.interval'};
1838: }
1839: my $outcome = &Apache::lonnet::put('nohist_whatsnew',
1840: \%interval_settings,$udom,$uname);
1841: if ($outcome eq 'ok') {
1842: if (ref($interval_titles->{$context}) eq 'HASH') {
1843: $result = &mt('New filter setting: [_1].','<b>'.
1844: $interval_titles->{$context}->{$env{'form.interval'}}.'</b>').'<br />';
1845: }
1846: } else {
1847: my $lctype = lc(&Apache::loncommon::course_type());
1848: &Apache::lonnet::logthis('Error saving whatsnew '.$context.' interval setting'.
1849: ' '.$outcome.' for '.$uname.':'.$udom.' in '.$lctype.' '.$cid);
1850: $result = &mt('Unable to set interval to [_1] due to [_2].',
1851: '<b>'.$interval_titles->{$context}->{$env{'form.interval'}}.'</b>',
1852: '<tt>'.$outcome.'</tt>.<br />');
1853: }
1854: }
1855: return $result;
1856: }
1857:
1858: sub store_discussion_setting {
1859: my ($uname,$udom,$cid) = @_;
1860: my %discussion_settings;
1861: my $result;
1862: if (defined($env{'form.countunread'})) {
1863: $discussion_settings{$cid.':countunread'} = $env{'form.countunread'};
1864: my $outcome = &Apache::lonnet::put('nohist_whatsnew',
1865: \%discussion_settings,$udom,$uname);
1866: if ($outcome eq 'ok') {
1867: $result = &mt('Count unread posts in discussions display set to [_1]',
1868: '<b>'.&mt($env{'form.countunread'}).'</b>').'<br />';
1869:
1870: } else {
1871: my $lctype = lc(&Apache::loncommon::course_type());
1872: &Apache::lonnet::logthis('Error saving whatsnew countunread setting'.
1873: ' '.$outcome.' for '.$uname.':'.$udom.' in '.$lctype.' '.$cid);
1874: $result = &mt('Unable to set "number unread posts display" to [_1]'.
1875: ' due to [_2].',
1876: '<b>'.&mt($env{'form.countunread'}).'</b>',
1877: '<tt>'.$outcome.'</tt>.<br />');
1878: }
1879: }
1880: return $result;
1881: }
1882:
1883: sub store_courseinit_setting {
1884: my ($uname,$udom,$cid,$initpage) = @_;
1885: my %courseinit_settings;
1886: my $page_control;
1887: my $result;
1888: if (defined($env{'form.courseinit_control'})) {
1889: if ($env{'form.courseinit_control'} eq 'userpref') {
1890: $courseinit_settings{$cid.':courseinit'} = '';
1891: $page_control = 'global preferences';
1892: } else {
1893: if (defined($env{'form.courseinit_page'})) {
1894: $courseinit_settings{$cid.':courseinit'} =
1895: $env{'form.courseinit_page'};
1896: $page_control = 'course specific setting';
1897: }
1898: }
1899: if ($page_control) {
1900: my $lctype = lc(&Apache::loncommon::course_type());
1901: my $outcome = &Apache::lonnet::put('nohist_whatsnew',
1902: \%courseinit_settings,$udom,$uname);
1903: if ($outcome eq 'ok') {
1904: if ($page_control eq 'global preferences') {
1905: $result = &mt("Page displayed after role selection in $lctype now set by [_1]user's global preferences[_2].",'<b>','</b>');
1906: } else {
1907: $result = &mt('Page displayed after role selection in this '.$lctype.' set to [_1].'
1908: ,'<b>'.$$initpage{$env{'form.courseinit_page'}}.'</b>');
1909: }
1910: } else {
1911: &Apache::lonnet::logthis('Error saving whatsnew courseinit '.
1912: 'setting: '.$outcome.' for '.$uname.
1913: ':'.$udom.' in '.$lctype.' '.$cid);
1914: if ($page_control eq 'global preferences') {
1915: $result = &mt('Unable to set control of page display to [_1]'.
1916: ' due to [_2].',
1917: '<b>'.$page_control.'</b>',
1918: '<tt>'.$outcome.'</tt>.<br />');
1919: } else {
1920: $result = &mt('Unable to set page display, after role selection, for this '.$lctype.' to [_1] due to [_2].'
1921: ,'<b>'.$$initpage{$env{'form.courseinit_page'}}.'</b>'
1922: ,'<tt>'.$outcome.'</tt>')
1923: .'<br />';
1924: }
1925: }
1926: }
1927: }
1928: return $result;
1929: }
1930:
1931: sub start_box {
1932: my ($r,$show,$heading,$caller,$refpage) = @_;
1933: my %lt = &Apache::lonlocal::texthash(
1934: chth => 'Change thresholds?',
1935: chin => 'Change interval?',
1936: chop => 'Change options?',
1937: );
1938: my $showhide;
1939: if ($$show{$caller}) {
1940: $showhide = '<b><a href="javascript:change_display(document.visible.'.
1941: 'display_'.$caller.",'hide'".');">'.
1942: &mt('Hide').'</a></b>';
1943:
1944: } else {
1945: $showhide = '<b><a href="javascript:change_display(document.visible.'.
1946: 'display_'.$caller.",'show'".');">'.
1947: &mt('Show').'</a></b>';
1948: }
1949:
1950: $r->print('
1951: <table class="LC_nested_outer">
1952: <tr>
1953: <th class="LC_left_item">'.$$heading{$caller}.'</th>
1954: <th class="LC_right_item">'.$showhide.'</th>
1955: </tr>');
1956: if (($caller eq 'abovethreshold') && ($$show{$caller})) {
1957: if ($$show{$caller}) {
1958: $r->print('
1959: <tr>
1960: <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgthreshold&refpage='.$refpage.'">'.$lt{'chth'}.'</a></td>
1961: </tr>');
1962: }
1963: } elsif (($caller eq 'versionchanges') && ($$show{$caller})) {
1964: if ($$show{$caller}) {
1965: $r->print('
1966: <tr>
1967: <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chginterval&refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
1968: </tr>');
1969: }
1970: } elsif ($caller eq 'coursediscussion') {
1971: if ($$show{$caller}) {
1972: $r->print('
1973: <tr>
1974: <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgdisc&refpage='.$refpage.'">'.$lt{'chop'}.'</a></td>
1975: </tr>');
1976: }
1977: } elsif (($caller eq 'newroles') && ($$show{$caller})) {
1978: if ($$show{$caller}) {
1979: $r->print('
1980: <tr>
1981: <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgnewroleinterval&refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
1982: </tr>');
1983: }
1984: } elsif (($caller eq 'oldroles') && ($$show{$caller})) {
1985: if ($$show{$caller}) {
1986: $r->print('
1987: <tr>
1988: <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgoldroleinterval&refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
1989: </tr>');
1990: }
1991: }
1992: $r->print('
1993: <tr>
1994: <td colspan="2">
1995: <table class="LC_nested">
1996: ');
1997: return;
1998: }
1999:
2000: sub end_box {
2001: my ($r) = shift;
2002: $r->print('
2003: </table>
2004: </td>
2005: </tr>
2006: </table><br />');
2007: return;
2008: }
2009:
2010: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>