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