1: #
2: # $Id: lonwhatsnew.pm,v 1.36 2005/12/06 16:37:28 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::Constants qw(:common :http);
40: use Time::Local;
41: use GDBM_File;
42:
43: #----------------------------
44: # handler
45: #
46: #----------------------------
47:
48: sub handler {
49: my $r = shift;
50: if ($r->header_only) {
51: &Apache::loncommon::content_type($r,'text/html');
52: $r->send_http_header;
53: return OK;
54: }
55: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['command']);
56:
57: my $command = $env{'form.command'};
58:
59: &Apache::loncommon::content_type($r,'text/html');
60: $r->send_http_header;
61: if (! (($env{'request.course.fn'}) && (&Apache::lonnet::allowed('bre',$env{'request.course.id'})))) {
62: # Not in a course, or not allowed to view action items
63: $env{'user.error.msg'}="/adm/whatsnew:bre:0:0:Cannot display what's new screen";
64: return HTTP_NOT_ACCEPTABLE;
65: }
66:
67: my %checkallowed = (
68: coursediscussion => &Apache::lonnet::allowed('pch',$env{'request.course.id'}),
69: handgrading => &Apache::lonnet::allowed('mgr',$env{'request.course.id'}),
70: abovethreshold => &Apache::lonnet::allowed('vgr',$env{'request.course.id'}),
71: haserrors => &Apache::lonnet::allowed('opa',$env{'request.course.id'}),
72: versionchanges => &Apache::lonnet::allowed('opa',$env{'request.course.id'}),
73: coursenormalmail => 1,
74: coursecritmail => 1,
75: );
76:
77: $r->print(&display_header($command,\%checkallowed));
78:
79: &Apache::lonhtmlcommon::clear_breadcrumbs();
80: &Apache::lonhtmlcommon::add_breadcrumb
81: ({href=>'/adm/whatsnew',
82: text=>"Display Action Items"});
83: if (($command eq 'chgthreshold') && (&Apache::lonnet::allowed('vgr',$env{'request.course.id'}))) {
84: &Apache::lonhtmlcommon::add_breadcrumb
85: ({href=>'/adm/whatsnew?command=chgthreshold',
86: text=>"Change thresholds"});
87: $r->print(&Apache::lonhtmlcommon::breadcrumbs
88: (undef,'Course Action Items','Course_Action_Items_Thresholds'));
89: } elsif (($command eq 'chginterval') && (&Apache::lonnet::allowed('vgr',$env{'request.course.id'}))) {
90: &Apache::lonhtmlcommon::add_breadcrumb
91: ({href=>'/adm/whatsnew?command=chginterval',
92: text=>"Change interval"});
93: $r->print(&Apache::lonhtmlcommon::breadcrumbs
94: (undef,'Course Action Items','Course_Action_Items_Intervals'));
95: } else {
96: $r->print(&Apache::lonhtmlcommon::breadcrumbs
97: (undef,'Course Action Items','Course_Action_Items_Display'));
98: }
99: &display_main_box($r,$command,\%checkallowed);
100: return OK;
101: }
102:
103: #------------------------------
104: # display_main_box
105: #
106: # Display all the elements within the main box
107: #------------------------------
108:
109: sub display_main_box {
110: my ($r,$command,$checkallowed) = @_;
111: my $domain=&Apache::loncommon::determinedomain();
112: my $tabbg=&Apache::loncommon::designparm('coordinator.tabbg',$domain);
113: $r->print('<table width="100%" border="0" cellpadding="5" cellspacing="0"><tr><td width="100%">');
114:
115: my %threshold_titles = (
116: av_attempts => 'Average number of attempts',
117: degdiff => 'Degree of difficulty',
118: numstudents => 'Total number of students with submissions',
119: );
120:
121: my %interval_titles = (
122: -1 => 'since start of course',
123: 2592000 => 'since last month',
124: 604800 => 'since last week',
125: 86400 => 'since yesterday',
126: );
127:
128: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
129: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
130:
131: if (($command eq 'chgthreshold') &&
132: (&Apache::lonnet::allowed('vgr',$env{'request.course.id'}))) {
133: &display_threshold_config($r,$command,$tabbg,\%threshold_titles,
134: $cdom,$crs);
135: } elsif (($command eq 'chginterval') &&
136: (&Apache::lonnet::allowed('opa',$env{'request.course.id'}))) {
137: &display_interval_config($r,\%interval_titles);
138: } else {
139: &display_actions_box($r,$command,\%threshold_titles,\%interval_titles,
140: $cdom,$crs,$checkallowed);
141: }
142: $r->print(<<END_OF_BLOCK);
143: </td>
144: </tr>
145: </table><br />
146: </body>
147: </html>
148: END_OF_BLOCK
149: }
150:
151: #-------------------------------
152: # display_header
153: #
154: # Display the header information and set
155: # up the HTML
156: #-------------------------------
157:
158: sub display_header{
159: my ($command,$checkallowed) = @_;
160: my $html=&Apache::lonxml::xmlbegin();
161: my $bodytag=&Apache::loncommon::bodytag('Course Action Items');
162: my $scripttag;
163: unless ($command eq 'chgthreshold' || $command eq 'chginterval') {
164: $scripttag = <<"END";
165: <script type="text/javascript">
166: function change_display(caller,change) {
167: caller.value = change;
168: document.visible.submit();
169: }
170:
171: function changeAll(change) {
172: END
173: foreach my $item (keys(%{$checkallowed})) {
174: $scripttag.='document.visible.display_'.$item.'.value=change'."\n";
175: }
176: $scripttag.='document.visible.submit();
177: }
178: </script>
179: ';
180: }
181: return(<<ENDHEAD);
182: $html
183: <head>
184: <title>Course Action Items</title>
185: $scripttag
186: </head>
187: $bodytag
188: ENDHEAD
189: }
190:
191: #-------------------------------
192: # display_actions_box
193: #
194: # Display the action items
195: #
196: #-------------------------------
197:
198: sub display_actions_box() {
199: my ($r,$command,$threshold_titles,$interval_titles,$cdom,$crs,
200: $checkallowed) = @_;
201: my $rowColor1 = "#ffffff";
202: my $rowColor2 = "#eeeeee";
203:
204: my $udom = $env{'user.domain'};
205: my $uname = $env{'user.name'};
206: my $cid = $env{'request.course.id'};
207:
208: my %lt = &Apache::lonlocal::texthash(
209: 'yacc' => 'You are accessing an invalid course.',
210: 'gtfr' => 'Go to first resource',
211: 'chyp' => 'Change your preferences',
212: 'tsup' => 'to suppress display of this screen when accessing'.
213: ' this course in the future.',
214: 'hial' => 'Hide all',
215: 'shal' => 'Show all',
216: );
217:
218: my %unread = ();
219: my %ungraded = ();
220: my %bombed = ();
221: my %triggered = ();
222: my %changed = ();
223: my @newmsgs = ();
224: my @critmsgs = ();
225: my @newdiscussions = ();
226: my @tograde = ();
227: my @bombs = ();
228: my @warnings = ();
229: my $msgcount = 0;
230: my $critmsgcount = 0;
231:
232: my %res_title = ();
233: my %show = ();
234: my $needitems = 0;
235: my $boxcount = 0;
236:
237: my $domain=&Apache::loncommon::determinedomain();
238: my $function;
239: if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
240: $function='coordinator';
241: }
242: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
243: $function='admin';
244: }
245:
246: my %threshold = (
247: av_attempts => 2,
248: degdiff => 0.5,
249: numstudents => 2,
250: );
251:
252: my $pgbg=&Apache::loncommon::designparm($function.'.pgbg',$domain);
253: my $tabbg=&Apache::loncommon::designparm($function.'.tabbg',$domain);
254:
255: unless ($cid) {
256: $r->print('<br /><b><center>'.$lt{'yacc'}.'</center></b><br /><br />');
257: return;
258: }
259:
260: if (tie(my %bighash,'GDBM_File',$env{'request.course.fn'}.'.db',
261: &GDBM_READER(),0640)) {
262: my $furl=$bighash{'first_url'};
263: $r->print('<font size="+1"><a href="'.$furl.'">'.$lt{'gtfr'}.
264: '</a></font><a href="/adm/preferences?action=changecourseinit">'.
265: '</font><br />'.$lt{'chyp'}.'</a> '.$lt{'tsup'}.'<br /><hr />');
266: untie(%bighash);
267: }
268:
269: my $result;
270:
271: if ($command eq 'reset') {
272: $result = &process_reset($cdom,$crs);
273: } elsif ($command eq 'update') {
274: $result = &process_update($cdom,$crs,$threshold_titles);
275: } elsif ($command eq 'newinterval') {
276: $result = &store_interval_setting($uname,$udom,$cid,$interval_titles);
277: }
278:
279: my $store_result=&store_display_settings($uname,$udom,$cid,$checkallowed);
280:
281: unless ($store_result eq 'ok') {
282: &Apache::lonnet::logthis('Error storing whatsnew settings: '.
283: $store_result.' for '.'user '.$uname.':'.$udom.' in course '.$cid);
284: $result .= &mt('Unable to store visibility settings due to [_1]',
285: $store_result);
286: }
287:
288: if ($result) {
289: $r->print($result.'<hr width="100%" />');
290: }
291: $r->rflush();
292:
293:
294: my %display_settings = &get_display_settings($uname,$udom,$cid);
295: my $timediff = $display_settings{$cid.':interval'};
296: unless (defined($timediff)) { $timediff = 604800; }
297: my $now = time;
298: my $interval = $$interval_titles{$timediff};
299: if ($timediff == -1) {
300: $timediff = time;
301: }
302: my $starttime = $now - $timediff;
303:
304: my %headings = &Apache::lonlocal::texthash(
305: coursediscussion => 'Unread course discussion posts',
306: handgrading => 'Problems requiring handgrading',
307: haserrors => 'Problems with errors',
308: versionchanges => 'Resources in course with version changes '.$interval,
309: coursenormalmail => 'New course message',
310: coursecritmail => 'New critical messages in course',
311: );
312:
313: if ($$checkallowed{'abovethreshold'}) {
314: &get_curr_thresholds(\%threshold,$cdom,$crs);
315: }
316:
317: $headings{'abovethreshold'} = &mt('Problems with av. attempts').' ≥ '.$threshold{'av_attempts'}.' '.&mt('or deg. difficulty').' ≥ '.$threshold{'degdiff'}.'<br /> '.&mt('and total number of students with submissions').' ≥ '.$threshold{'numstudents'};
318:
319: my @actionorder = ('handgrading','haserrors','abovethreshold','versionchanges','coursediscussion','coursenormalmail','coursecritmail');
320:
321: foreach my $key (keys(%{$checkallowed})) {
322: $show{$key} = 0;
323: if ($$checkallowed{$key}) {
324: unless ($display_settings{$cid.':'.$key} eq 'hide') {
325: $show{$key} = 1;
326: }
327: }
328: }
329:
330: foreach my $item (@actionorder) {
331: unless ($item eq 'coursenormalmail' || $item eq 'coursecritmail') {
332: if ($show{$item}) {
333: $needitems = 1;
334: last;
335: }
336: }
337: }
338:
339: if ($needitems) {
340: &getitems(\%unread,\%ungraded,\%bombed,\%triggered,\%changed,\@newdiscussions,\@tograde,\@bombs,\@warnings,$rowColor1,$rowColor2,\%threshold,$cdom,$crs,\%res_title,\%show,$starttime);
341: }
342: if ($show{'coursenormalmail'}) {
343: &getnormalmail(\@newmsgs);
344: }
345: if ($show{'coursecritmail'}) {
346: &getcritmail(\@critmsgs);
347: }
348:
349: $r->print(qq|<a href="javascript:changeAll('hide');">$lt{'hial'}</a>
350: <a href="javascript:changeAll('show');">$lt{'shal'}</a>
351: <form method="post" name="visible" action="/adm/whatsnew">\n|);
352: foreach my $item (keys(%{$checkallowed})) {
353: if ($$checkallowed{$item}) {
354: $r->print('<input type="hidden" name="display_'.$item.'" />'."\n");
355: }
356: }
357:
358: $r->print('</form><br /><table border="0" width="100%" cellpadding="2" cellspacing="4"><tr><td align="left" valign="top" width="45%">');
359:
360: my $displayed = 0;
361: my $totalboxes = keys(%{$checkallowed});
362: my $halfway = int($totalboxes/2) + $totalboxes%2;
363: foreach my $actionitem (@actionorder) {
364: if ($$checkallowed{$actionitem}) {
365: if ($displayed == $halfway) {
366: $r->print('</td><td width="5%"> </td><td align="left" valign="top" width-"50%">');
367: }
368: &display_launcher($r,$actionitem,$checkallowed,$tabbg,$rowColor1,$rowColor2,\%show,\%headings,\%res_title,\@tograde,\%ungraded,\@bombs,\%bombed,\%changed,\@warnings,\%triggered,\@newdiscussions,\%unread,$msgcount,\@newmsgs,$critmsgcount,\@critmsgs,$interval);
369: $displayed ++;
370: }
371: }
372: $r->print('
373: </table>
374: </td>
375: </tr>
376: </table>
377: </td>
378: </tr>
379: </table>');
380: }
381:
382: #-------------------------------
383: # display_threshold_config
384: #
385: # Display the threshold setting screen
386: #
387: #-------------------------------
388:
389: sub display_threshold_config {
390: my ($r,$command,$tabbg,$threshold_titles,$cdom,$crs) = @_;
391: my %threshold = ();
392: my $rowColor1 = "#ffffff";
393: my $rowColor2 = "#eeeeee";
394: my $rowColor;
395:
396: my @thresholditems = ("av_attempts","degdiff","numstudents");
397: my %threshold_titles = (
398: av_attempts => 'Average number of attempts',
399: degdiff => 'Degree of difficulty',
400: numstudents => 'Total number of students with submissions',
401: );
402: &get_curr_thresholds(\%threshold,$cdom,$crs);
403:
404: $r->print('<br /><form name="thresholdform" method="post" action="/adm/whatsnew">
405: <table border="0" cellpadding="2" cellspacing="4">
406: <tr>
407: <td align="left" valign="top" width="45%">
408: <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
409: <tr>
410: <td>
411: <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000">
412: <tr>
413: <td bgcolor="#ffffff">
414: <table cellspacing="0" cellpadding="4" border="0">
415: <tr bgcolor="'.$tabbg.'">
416: <th>Threshold Name</th>
417: <th>Current value</th>
418: <th>Change?</th>
419: </tr>');
420: my $rowNum =0;
421: foreach my $type (@thresholditems) {
422: my $parameter = 'internal.threshold_'.$type;
423: # onchange is javascript to automatically check the 'Set' button.
424: my $onchange = 'onFocus="javascript:window.document.forms'.
425: "['thresholdform'].elements['".$parameter."_setparmval']".
426: '.checked=true;"';
427: if ($rowNum %2 == 1) {
428: $rowColor = $rowColor1;
429: } else {
430: $rowColor = $rowColor2;
431: }
432: $r->print('
433: <tr bgcolor="'.$rowColor.'">
434: <td>'.$threshold_titles{$type}.'</td>
435: <td>'.&Apache::lonhtmlcommon::textbox($parameter.'_value',
436: $threshold{$type},
437: 10,$onchange).'</td>
438: <td>'
439: .&Apache::lonhtmlcommon::checkbox($parameter.'_setparmval').
440: '</td>
441: </tr>');
442: $rowNum ++;
443: }
444: $r->print('</table></td></tr></table></td></tr></table>
445: <br /><input type="submit" name="threshold" value="Make changes" />
446: <input type="hidden" name="command" value="update" />
447: </form>');
448: }
449:
450: #-------------------------------
451: # display_interval_config
452: #
453: # Display the interval setting screen
454: #
455: #-------------------------------
456:
457: sub display_interval_config {
458: my ($r,$interval_titles) = @_;
459: my $current = &get_curr_interval($env{'user.name'},
460: $env{'user.domain'},$env{'request.course.id'});
461: $r->print('<br />'.&mt('Choose the time window to use for display of version changes for resources in the course.'));
462: unless ($current eq '') {
463: $r->print(' '.&mt('Current value is ').$$interval_titles{$current}.'<br /><br />');
464: }
465: $r->print('<br /><br />
466: <form method="post" name="intervalswitch" action="/adm/whatsnew">
467: <input type="hidden" name="command" value="newinterval" />
468: <select name="interval">
469: ');
470: foreach my $key (reverse sort ({$a cmp $b} (keys(%{$interval_titles})))) {
471: $r->print('<option value="'.$key.'">Version changes '.$$interval_titles{$key}.
472: '</option>'."\n");
473: }
474: $r->print('</select>
475: <input type="submit" name="display" value="'.
476: &mt('Change interval').'" /></form>');
477: return;
478: }
479:
480: sub display_launcher {
481: my ($r,$action,$checkallowed,$tabbg,$rowColor1,$rowColor2,$show,
482: $headings,$res_title,$tograde,$ungraded,$bombs,$bombed,$changed,
483: $warnings,$triggered,$newdiscussions,$unread,$msgcount,$newmsgs,
484: $critmsgcount,$critmsgs,$interval) = @_;
485:
486: if ($$checkallowed{$action}) {
487: &start_box($r,$tabbg,$show,$headings,$action);
488: if ($$show{$action}) {
489: if ($action eq 'handgrading') { # UNGRADED ITEMS
490: &display_handgrade($r,$tograde,$rowColor1,$rowColor2,
491: $ungraded);
492: } elsif ($action eq 'haserrors') { # BOMBS
493: &display_haserrors($r,$bombs,$rowColor1,$rowColor2,$bombed,
494: $res_title);
495: } elsif ($action eq 'versionchanges') { # VERSION CHANGES
496: &display_versionchanges($r,$changed,$res_title,$rowColor1,
497: $rowColor2,$interval);
498:
499: } elsif ($action eq 'abovethreshold') { # DEGDIFF/AV. TRIES TRIGGERS
500: &display_abovethreshold($r,$warnings,$triggered,$res_title,
501: $rowColor1,$rowColor2);
502: } elsif ($action eq 'coursediscussion') { # UNREAD COURSE DISCUSSION
503: &display_coursediscussion($r,$newdiscussions,$unread,
504: $res_title,$rowColor1,$rowColor2);
505: } elsif ($action eq 'coursenormalmail') { # NORMAL MESSAGES
506: &display_coursenormalmail($r,$msgcount,$newmsgs,$rowColor1,
507: $rowColor2);
508: } elsif ($action eq 'coursecritmail') { # CRITICAL MESSAGES
509: &display_coursecritmail($r,$critmsgcount,$critmsgs,$rowColor1,
510: $rowColor2);
511: }
512: }
513: &end_box($r);
514: }
515: return;
516: }
517:
518: sub getitems {
519: my ($unread,$ungraded,$bombed,$triggered,$changed,$newdiscussions,
520: $tograde,$bombs,$warnings,$rowColor1,$rowColor2,$threshold,$cdom,$crs,
521: $res_title,$show,$starttime) = @_;
522: my $navmap = Apache::lonnavmaps::navmap->new();
523: # force retrieve Resource to seed the part id cache we'll need it later
524: my @allres=$navmap->retrieveResources(undef,sub {if ($_[0]->is_problem) { $_[0]->parts();} return 1;});
525: my %lastreadtime;
526: my %resourcetracker;
527:
528: # Resource version changes
529: if ($$show{'versionchanges'}) {
530: &checkversions($cdom,$crs,$navmap,$changed,$starttime);
531: }
532:
533: if ($$show{'coursediscussions'}) {
534: my %lastread = &Apache::lonnet::dump('nohist_'.
535: $env{'request.course.id'}.'_discuss',
536: $env{'user.domain'},$env{'user.name'},'lastread');
537: foreach my $key (keys(%lastread)) {
538: my $newkey = $key;
539: $newkey =~ s/_lastread$//;
540: $lastreadtime{$newkey} = $lastread{$key};
541: }
542: }
543:
544: if ($$show{'abovethreshold'}) {
545: %resourcetracker = &Apache::lonnet::dump('nohist_resourcetracker',
546: $cdom,$crs);
547: }
548:
549: my $warningnum = 0;
550: foreach my $resource (@allres) {
551: my $result = '';
552: my $applies = 0;
553: my $symb = $resource->symb();
554: %{$$bombed{$symb}} = ();
555: %{$$ungraded{$symb}} = ();
556: %{$$triggered{$symb}} = ();
557: $$triggered{$symb}{numparts} = 0;
558: my $title = $resource->compTitle();
559: $$res_title{$symb} = $title;
560: my $ressymb = $resource->wrap_symb();
561:
562: # Check for unread discussion postings
563: if ($$show{'coursediscussion'}) {
564: &check_discussions($cdom,$crs,$resource,$symb,$ressymb,$title,
565: $newdiscussions,$unread,\%lastreadtime);
566: }
567:
568: # Check for ungraded problems
569: if ($resource->is_problem()) {
570: if ($$show{'handgrading'}) {
571: &check_handgraded($resource,$symb,$title,$cdom,$crs,$ungraded,
572: $tograde);
573: }
574: }
575:
576: # Check for bombs
577: if ($$show{'haserrors'}) {
578: &check_bombed($resource,$symb,$title,$bombs,$bombed);
579: }
580:
581: # Maxtries and degree of difficulty for problem parts, unless handgradeable
582: if ($$show{'abovethreshold'}) {
583: &check_thresholds($resource,$symb,\%resourcetracker,$triggered,
584: $threshold,$warnings,$warningnum,$rowColor1,$rowColor2);
585: }
586:
587: }
588: }
589:
590: sub check_discussions {
591: my ($cdom,$crs,$resource,$symb,$ressymb,$title,$newdiscussions,$unread,
592: $lastreadtime) = @_;
593: # Check for unread discussion postings
594: if ($resource->hasDiscussion()) {
595: my $prevread = 0;
596: my $unreadcount = 0;
597: %{$$unread{$ressymb}} = ();
598: $$unread{$ressymb}{'title'} = $title;
599: $$unread{$ressymb}{'symb'} = $symb;
600: if (defined($$lastreadtime{$ressymb})) {
601: $prevread = $$lastreadtime{$ressymb};
602: }
603: my %contrib = &Apache::lonnet::restore($ressymb,
604: $env{'request.course.id'},$cdom,$crs);
605: if ($contrib{'version'}) {
606: for (my $id=1;$id<=$contrib{'version'};$id++) {
607: unless (($contrib{'hidden'}=~/\.$id\./) ||
608: ($contrib{'deleted'}=~/\.$id\./)) {
609: if ($prevread <$contrib{$id.':timestamp'}) {
610: $$unread{$ressymb}{$unreadcount} = $id.': '.$contrib{$id.':subject'};
611: $unreadcount ++;
612: }
613: }
614: }
615: }
616: if ($unreadcount) { push(@{$newdiscussions}, $ressymb); }
617: }
618: }
619:
620: sub check_handgraded {
621: my ($resource,$symb,$title,$cdom,$cnum,$ungraded,$tograde) = @_;
622: if ($resource->is_problem()) {
623: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
624: my $partlist=$resource->parts();
625: my $handgradeable;
626: foreach my $part (@$partlist) {
627: if ($resource->handgrade($part) eq 'yes') {
628: $handgradeable=1; last;
629: }
630: }
631: if ($handgradeable) {
632: my @ungraded = &Apache::bridgetask::get_queue_symb_status(
633: 'gradingqueue',$symb,$cdom,$cnum);
634: if (@ungraded > 0) {
635: $$ungraded{$symb}{count} = scalar(@ungraded);
636: $$ungraded{$symb}{title} = $title;
637: push(@{$tograde}, $symb);
638: }
639: }
640: }
641: }
642:
643: sub check_bombed {
644: my ($resource,$symb,$title,$bombs,$bombed) = @_;
645: if ($resource->getErrors()) {
646: my $errors = $resource->getErrors();
647: $errors =~ s/^,//;
648: my @bombs = split(/,/, $errors);
649: my $errorcount = scalar(@bombs);
650: my $errorlink = '<a href="/adm/email?display='.
651: &Apache::lonnet::escape($bombs[0]).'">'.
652: $title.'</a>';
653: $$bombed{$symb}{errorcount} = $errorcount;
654: $$bombed{$symb}{errorlink} = $errorlink;
655: push(@{$bombs}, $symb);
656: }
657: }
658:
659: sub check_thresholds {
660: my ($resource,$symb,$resourcetracker,$triggered,$threshold,$warnings,
661: $warningnum,$rowColor1,$rowColor2) = @_;
662: # Compile maxtries and degree of difficulty for problem parts, unless handgradeable
663: my @parts = @{$resource->parts()};
664: my %stats;
665: my %lastreset = ();
666: my $warning = 0;
667: my $rowColor;
668: foreach my $part (@parts) {
669: if ($resource->handgrade($part) eq 'yes') {
670: next;
671: }
672: %{$stats{$part}} = ();
673: my ($attempts,$users,$corrects,$degdiff,$av_attempts);
674: if (exists($$resourcetracker{$symb."\0".$part."\0attempts"})) {
675: $attempts = $$resourcetracker{$symb."\0".$part."\0attempts"};
676: }
677: if (exists($$resourcetracker{$symb."\0".$part."\0users"})) {
678: $users = $$resourcetracker{$symb."\0".$part."\0users"};
679: }
680: if (exists($$resourcetracker{$symb."\0".$part."\0correct"})) {
681: $corrects = $$resourcetracker{$symb."\0".$part."\0correct"};
682: }
683: if ($attempts > 0) {
684: $degdiff = 1 - ($corrects/$attempts);
685: $degdiff = sprintf("%.2f",$degdiff);
686: }
687: if ($users > 0) {
688: $av_attempts = $attempts/$users;
689: $av_attempts = sprintf("%.2f",$av_attempts);
690: }
691: if ((($degdiff ne '' && $degdiff >= $$threshold{'degdiff'}) || ($av_attempts ne '' && $av_attempts >= $$threshold{'av_attempts'})) && ($users >= $$threshold{'numstudents'})) {
692: $stats{$part}{degdiff} = $degdiff;
693: $stats{$part}{attempts} = $av_attempts;
694: $stats{$part}{users} = $users;
695: $lastreset{$part} = $$resourcetracker{$symb."\0".$part."\0resettime"};
696: if ($lastreset{$part}) {
697: $lastreset{$part} = &Apache::lonnavmaps::timeToHumanString($lastreset{$part});
698: }
699: $warning = 1;
700: }
701: }
702: if ($warning) {
703: if ($warningnum %2 == 1) {
704: $rowColor = $rowColor1;
705: } else {
706: $rowColor = $rowColor2;
707: }
708: $$triggered{$symb}{title} = $resource->title;
709: foreach my $part (@parts) {
710: if (exists($stats{$part}{users})) {
711: my $resetname = 'reset_'.&Apache::lonnet::escape($symb."\0".$part);
712: my $resettitle = 'title_'.&Apache::lonnet::escape($symb."\0".$part);
713: if ($$triggered{$symb}{numparts}) {
714: $$triggered{$symb}{text} .= '<tr bgcolor="'.$rowColor.'">'."\n";
715: }
716: if (@parts > 1) {
717: $$triggered{$symb}{text} .= '
718: <td align="right"><small>part - '.$part.'<small></td>';
719: } else {
720: $$triggered{$symb}{text} .= '
721: <td align="right"><small>single part</small></td>';
722: }
723: $$triggered{$symb}{text} .= '
724: <td align="right"><small>'.$stats{$part}{users}.'</small></td>
725: <td align="right"><small>'.$stats{$part}{attempts}.'</small></td>
726: <td align="right"><small>'.$stats{$part}{degdiff}.'</small></td>
727: <td align="right"><small>'.$lastreset{$part}.'</small></td>
728: <td align="right"><small><input type="checkbox" name="'.$resetname.'" /><input type="hidden" name="'.$resettitle.'" value="'.&Apache::lonnet::escape($$triggered{$symb}{title}).'" /></td>
729: </tr>';
730: $$triggered{$symb}{numparts} ++;
731: }
732: }
733: push(@{$warnings},$symb);
734: $warningnum ++;
735: }
736: }
737:
738:
739: sub get_curr_thresholds {
740: my ($threshold,$cdom,$crs) = @_;
741: my %coursesettings = &Apache::lonnet::dump('environment',
742: $cdom,$crs,'internal.threshold');
743: if (exists($coursesettings{'internal.threshold_av_attempts'})) {
744: $$threshold{'av_attempts'} = $coursesettings{'internal.threshold_av_attempts'};
745: }
746: if (exists($coursesettings{'internal.threshold_degdiff'})) {
747: $$threshold{'degdiff'} = $coursesettings{'internal.threshold_degdiff'};
748: }
749: if (exists($coursesettings{'internal.threshold_numstudents'})) {
750: $$threshold{'numstudents'} = $coursesettings{'internal.threshold_numstudents'};
751: }
752: }
753:
754: sub get_curr_interval {
755: my ($uname,$udom,$cid);
756: my $interval;
757: my %settings = &Apache::lonnet::dump('nohist_whatsnew',$uname,$udom,$cid,':interval');
758: my ($tmp) = %settings;
759: if ($tmp =~ /^Error/) {
760: &logthis();
761: } else {
762: $interval = $settings{$cid.':interval'};
763: }
764: return $interval;
765: }
766:
767: sub process_reset {
768: my ($dom,$crs) = @_;
769: my $result = '<b>Counters reset for following problems (and parts):</b><br />';
770: my @agg_types = ('attempts','users','correct');
771: my %agg_titles = (
772: attempts => 'Number of submissions',
773: users => 'Students with submissions',
774: correct => 'Number of correct submissions',
775: );
776: my @resets = ();
777: my %titles = ();
778: foreach my $key (keys(%env)) {
779: next if ($key !~ /^form\.reset_(.+)$/);
780: my $title = &Apache::lonnet::unescape($env{'form.title_'.$1});
781: my $reset_item = &Apache::lonnet::unescape($1);
782: my %curr_aggregates = &Apache::lonnet::dump('nohist_resourcetracker',$dom,$crs,$reset_item);
783: my %aggregates = ();
784: my ($symb,$part) = split(/\0/,$reset_item);
785: foreach my $type (@agg_types) {
786: $aggregates{$reset_item."\0".$type} = 0;
787: }
788: $aggregates{$reset_item."\0".'resettime'} = time;
789: my $putresult = &Apache::lonnet::put('nohist_resourcetracker',\%aggregates,
790: $dom,$crs);
791: if ($putresult eq 'ok') {
792: $result .= $title.' -part '.$part.': ';
793: my %new_aggregates = &Apache::lonnet::dump('nohist_resourcetracker',$dom,$crs,$reset_item);
794: foreach my $type (@agg_types) {
795: $result .= $agg_titles{$type}.' = '.$new_aggregates{$reset_item."\0".$type}.'; ';
796: }
797: $result =~ s/; $//;
798: $result .= '<br />';
799: } else {
800: $result = $title.' -part '.$part.': '.&mt('Unable to reset counters to zero due to [_1]',$putresult).'.<br />'."\n";
801: }
802: }
803: return $result;
804: }
805:
806: sub process_update {
807: my ($dom,$crs,$threshold_titles) = @_;
808: my $setoutput = '<b>Changes to threshold(s) for problem tracking:</b><br />';
809: foreach (keys %env) {
810: next if ($_!~/^form\.(.+)\_setparmval$/);
811: my $name = $1;
812: my $value = $env{'form.'.$name.'_value'};
813: if ($name && defined($value)) {
814: my $put_result = &Apache::lonnet::put('environment',
815: {$name=>$value},$dom,$crs);
816:
817: my ($shortname) = ($name =~ /^internal\.threshold_(.+)$/);
818: if ($put_result eq 'ok') {
819: $setoutput.=&mt('Set threshold for [_1] to [_2]',
820: '<b>'.$$threshold_titles{$shortname}.'</b>',
821: '<b>'.$value.'</b>').'<br />';
822: } else {
823: $setoutput.=&mt('Unable to set threshold for [_1] to [_2] due to [_3].',
824: '<b>'.$name.'</b>','<b>'.$value.'</b>',
825: '<tt>'.$put_result.'</tt>').'<br />';
826: }
827: }
828: }
829: return $setoutput;
830: }
831:
832: sub getnormalmail {
833: my ($newmsgs) = @_;
834: # Check for unread mail in course
835: my $msgcount = 0;
836:
837: my @messages = sort(&Apache::lonnet::getkeys('nohist_email'));
838: foreach my $message (@messages) {
839: my $msgid=&Apache::lonnet::escape($message);
840: my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
841: &Apache::lonmsg::unpackmsgid($msgid);
842: if (($fromcid) && ($fromcid eq $env{'request.course.id'})) {
843: if (defined($sendtime) && $sendtime!~/error/) {
844: my $numsendtime = $sendtime;
845: $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
846: if ($status eq 'new') {
847: $msgcount ++;
848: if ($shortsubj eq '') {
849: $shortsubj = &mt('No subject');
850: }
851: $shortsubj = &Apache::lonnet::unescape($shortsubj);
852: push(@{$newmsgs}, {
853: msgid => $msgid,
854: sendtime => $sendtime,
855: shortsub => $shortsubj,
856: from => $fromname,
857: fromdom => $fromdom
858: });
859: }
860: }
861: }
862: }
863: return $msgcount;
864: }
865:
866: sub getcritmail {
867: my ($critmsgs) = @_;
868: # Check for critical messages in course
869: my %what=&Apache::lonnet::dump('critical');
870: my $result = '';
871: my $critmsgcount = 0;
872: foreach my $msgid (sort(keys(%what))) {
873: my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
874: &Apache::lonmsg::unpackmsgid($msgid);
875: if (($fromcid) && ($fromcid eq $env{'request.course.id'})) {
876: if (defined($sendtime) && $sendtime!~/error/) {
877: my $numsendtime = $sendtime;
878: $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
879: $critmsgcount ++;
880: if ($shortsubj eq '') {
881: $shortsubj = &mt('No subject');
882: }
883: $shortsubj = &Apache::lonnet::unescape($shortsubj);
884: push(@{$critmsgs}, {
885: msgid => $msgid,
886: sendtime => $sendtime,
887: shortsub => $shortsubj,
888: from => $fromname,
889: fromdom => $fromdom
890: });
891: }
892: }
893: }
894: return $critmsgcount;
895: }
896:
897:
898: sub checkversions {
899: my ($cdom,$crs,$navmap,$changed,$starttime) = @_;
900: my %changes=&Apache::lonnet::dump('versionupdate',$cdom,$crs);
901: my ($tmp) = keys(%changes);
902: if ($tmp =~/^error\:/) {
903: &Apache::lonnet::logthis('Error retrieving version update information: '.
904: $tmp.' for '.$cdom.'_'.$crs.' in whatsnew');
905: } else {
906: if (keys(%changes) > 0) {
907: foreach my $key (sort(keys(%changes))) {
908: if ($changes{$key} > $starttime) {
909: my $version;
910: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
911: my $currentversion=&Apache::lonnet::getversion($key);
912: my $revdate =
913: &Apache::lonnet::metadata($root.'.'.$extension,
914: 'lastrevisiondate');
915: $revdate = &Apache::lonlocal::locallocaltime($revdate);
916: my $linkurl=&Apache::lonnet::clutter($key);
917: my $usedversion=$navmap->usedVersion('version_'.$linkurl);
918: my @resources = $navmap->getResourceByUrl($linkurl,1);
919: if (($usedversion) && ($usedversion ne 'mostrecent')) {
920: $version = $usedversion;
921: } else {
922: $version = $currentversion;
923: }
924: foreach my $res (@resources) {
925: if (ref($res) eq 'Apache::lonnavmaps::resource') {
926: my $symb = $res->symb();
927: %{$$changed{$symb}} = (
928: current => $currentversion,
929: version => $version,
930: revdate => $revdate,
931: );
932: }
933: }
934: }
935: }
936: }
937: }
938: return;
939: }
940:
941: sub display_handgrade {
942: my ($r,$tograde,$rowColor1,$rowColor2,$ungraded) = @_;
943: my $rowColor;
944: my %lt = &Apache::lonlocal::texthash(
945: 'prna' => 'Problem Name',
946: 'nmun' => 'Number ungraded',
947: 'nopr' => 'No problems require handgrading',
948: );
949: if (@{$tograde} > 0) {
950: $r->print('<tr bgcolor="#cccccc"><td><b><small>'.$lt{'prna'}.'</small></b></td><td align="right"><b><small>'.$lt{'nmun'}.'</small></b></td></tr>');
951: my $rowNum = 0;
952: foreach my $res (@{$tograde}) {
953: if ($rowNum %2 == 1) {
954: $rowColor = $rowColor1;
955: } else {
956: $rowColor = $rowColor2;
957: }
958: my ($map,$id,$url)=&Apache::lonnet::decode_symb($res);
959: my $linkurl=&Apache::lonnet::clutter($url);
960: $linkurl .= '?symb='.&Apache::lonnet::escape($res);
961:
962: $r->print('<tr bgcolor="'.$rowColor.'"><td><a href="'.$linkurl.'"><small>'.$$ungraded{$res}{title}.'</small></a></td><td align="right"><small>'.$$ungraded{$res}{count}.'</small></td></tr>');
963: $rowNum ++;
964: }
965: } else {
966: $r->print('<tr><td bgcolor="#ffffff"><br><center><i><b><small> '.$lt{'nopr'}.' </small><br><br></b></i></td></tr>');
967: }
968: }
969:
970: sub display_haserrors {
971: my ($r,$bombs,$rowColor1,$rowColor2,$bombed,$res_title) = @_;
972: my $bombnum = 0;
973: my $rowColor;
974: my %lt = &Apache::lonlocal::texthash(
975: reso => 'Resource',
976: nmer => 'Number of errors',
977: noer => 'No problems with errors',
978: );
979: if (@{$bombs} > 0) {
980: $r->print('<tr bgcolor="#cccccc"><td><b><small>'.$lt{'reso'}.'</small></b></td><td align="right"><b><small>'.$lt{'nmer'}.'</small></b></td></tr>');
981: @{$bombs} = sort { &cmp_title($a,$b,$res_title) } @{$bombs};
982: foreach my $bomb (@{$bombs}) {
983: if ($bombnum %2 == 1) {
984: $rowColor = $rowColor1;
985: } else {
986: $rowColor = $rowColor2;
987: }
988: $r->print('<tr bgcolor="'.$rowColor.'"><td><small>'.$$bombed{$bomb}{errorlink}.'</small></td><td align="right"><small>'.$$bombed{$bomb}{errorcount}.'</small></td></tr>');
989: $bombnum ++;
990: }
991: } else {
992: $r->print('<tr><td bgcolor="#ffffff"><br /><center><b><i><small>'.$lt{'noer'}.'</small></i></b></center><br /></td></tr>');
993: }
994: return;
995: }
996:
997: sub display_abovethreshold {
998: my ($r,$warnings,$triggered,$res_title,$rowColor1,$rowColor2) = @_;
999: my %lt = &Apache::lonlocal::texthash(
1000: reso => 'Resource',
1001: part => 'Part',
1002: nust => 'Num. students',
1003: avat => 'Av. Attempts',
1004: dedi => 'Deg. Diff',
1005: lare => 'Last Reset',
1006: reco => 'Reset Count?',
1007: rese => 'Reset counters to 0',
1008: nopr => 'No problems satisfy threshold criteria',
1009: );
1010: my $rowColor;
1011: my $warningnum = 0;
1012: if (@{$warnings} > 0) {
1013: @{$warnings} = sort { &cmp_title($a,$b,$res_title) } @{$warnings};
1014: $r->print('<form name="reset_tracking" method="post" action="/adm/whatsnew">'.
1015: ' <input type="hidden" name="command" value="reset" />'."\n");
1016: $r->print('<tr bgcolor="#cccccc"><td><b><small>'.$lt{'reso'}.'</small></b></td><td align="right"><b><small>'.$lt{'part'}.'</small></b></td><td align="right"><b><small>'.$lt{'nust'}.'</small></b></td><td align="right"><b><small>'.$lt{'avat'}.'</small></b></td><td align="right"><b><small>'.$lt{'dedi'}.'</small></b></td><td align="right"><b><small>'.$lt{'lare'}.'</small></b></td><td align="right"><b><small>'.$lt{'reco'}.'</small></b></td></tr>');
1017: foreach my $res (@{$warnings}) {
1018: if ($warningnum %2 == 1) {
1019: $rowColor = $rowColor1;
1020: } else {
1021: $rowColor = $rowColor2;
1022: }
1023: my ($map,$id,$url)=&Apache::lonnet::decode_symb($res);
1024: my $linkurl=&Apache::lonnet::clutter($url);
1025: my $rowspan;
1026: if ($$triggered{$res}{numparts} > 1) {
1027: $rowspan = 'rowspan="'.$$triggered{$res}{numparts}.'"';
1028: }
1029: $linkurl .= '?symb='.&Apache::lonnet::escape($res);
1030: $r->print('<tr bgcolor="'.$rowColor.'"><td '.$rowspan.'><a href="'.$linkurl.'"><small>'.$$triggered{$res}{title}.'</small></a></td>'.$$triggered{$res}{text});
1031: $warningnum ++;
1032: }
1033: $r->print('<tr bgcolor="#cccccc"><td colspan="7" align="right"><br /><b><small><input type="submit" name="counters" value="'.$lt{'rese'}.'" /></form>');
1034: } else {
1035: $r->print('<tr><td bgcolor="#ffffff"><br /><center><b><i><small>'.$lt{'nopr'}.'</small></i></b></center><br /></td></tr>');
1036: }
1037: }
1038:
1039: sub display_versionchanges {
1040: my ($r,$changed,$res_title,$rowColor1,$rowColor2,$interval) = @_;
1041: my %lt = &Apache::lonlocal::texthash(
1042: 'reso' => 'Resource',
1043: 'revd' => 'Last revised',
1044: 'newv' => 'New version',
1045: 'veru' => 'Version used',
1046: 'noup' => 'No updated versions',
1047: );
1048: my $rowColor;
1049: if (keys(%{$changed}) > 0) {
1050: $r->print('<tr bgcolor="#cccccc"><td><b><small>'.$lt{'reso'}.'</small></b></td><td><b><small>'.$lt{'revd'}.'</small></b></td><td><b><small>'.$lt{'newv'}.'</small></b></td><td><b><small>'.$lt{'veru'}.'</small></b></td></tr>');
1051:
1052:
1053: my @changes = sort { &cmp_title($a,$b,$res_title) } keys(%{$changed});
1054: my $changenum = 0;
1055: foreach my $item (@changes) {
1056: if ($changenum %2 == 1) {
1057: $rowColor = $rowColor1;
1058: } else {
1059: $rowColor = $rowColor2;
1060: }
1061: my ($map,$id,$url)=&Apache::lonnet::decode_symb($item);
1062: my $linkurl=&Apache::lonnet::clutter($url);
1063: $linkurl .= '?symb='.&Apache::lonnet::escape($item);
1064:
1065: $r->print('<tr bgcolor="'.$rowColor.'"><td><small><a href="'.$linkurl.'">'.$$res_title{$item}.'</a></small></td><td><small>'.$$changed{$item}{'revdate'}.'</small></td><td><small>'.$$changed{$item}{'current'}.'</small></td><td><small>'.$$changed{$item}{'version'}.'</small></td></tr>');
1066: $changenum ++;
1067: }
1068: } else {
1069: $r->print('<tr><td bgcolor="#ffffff"><br /><center><b><i><small>'.$lt{'noup'}.' '.$interval.'</small></i></b></center><br /></td></tr>');
1070: }
1071: return;
1072: }
1073:
1074: sub display_coursediscussion {
1075: my ($r,$newdiscussions,$unread,$res_title,$rowColor1,$rowColor2) = @_;
1076: my %lt = &Apache::lonlocal::texthash(
1077: 'loca' => 'Location',
1078: 'type' => 'Type',
1079: 'numn' => 'Number of new posts',
1080: 'noun' => 'No unread posts in course discussions',
1081: );
1082: my $rowColor;
1083: if (@{$newdiscussions} > 0) {
1084: $r->print('<tr bgcolor="#cccccc"><td><b><small>'.$lt{'loca'}.
1085: '</small></b></td><td><b><small>'.$lt{'type'}.
1086: '</small></b><td align="right"><b><small>'.$lt{'numn'}.
1087: '</small></b></td></tr>');
1088: @{$newdiscussions} = sort { &cmp_title($a,$b,$res_title) }
1089: @{$newdiscussions};
1090: my $rowNum = 0;
1091: foreach my $ressymb (@{$newdiscussions}) {
1092: my $forum_title = $$unread{$ressymb}{'title'};
1093: my $type = 'Resource';
1094: my $feedurl=&Apache::lonfeedback::get_feedurl($ressymb);
1095: if ($feedurl =~ /bulletinboard/) {
1096: $type = 'Bulletin Board';
1097: }
1098: my $unreadnum = keys(%{$$unread{$ressymb}});
1099: $unreadnum = $unreadnum - 2;
1100: if ($unreadnum > 0) {
1101: if ($rowNum %2 == 1) {
1102: $rowColor = $rowColor1;
1103: } else {
1104: $rowColor = $rowColor2;
1105: }
1106: $r->print('<tr bgcolor="'.$rowColor.'"><td><small><a href="'.$feedurl.'?symb='.$$unread{$ressymb}{symb}.'">'.$forum_title.'</a> </td><td><small>'.$type.'</small></td><td align="right">'.$unreadnum.' </td></tr>');
1107: $rowNum ++;
1108: }
1109: }
1110: } else {
1111: $r->print('<tr><td bgcolor="#ffffff"><br><center> <i><b><small>'.
1112: $lt{'noun'}.'</small></b></i><br><br></td></tr>');
1113: }
1114: }
1115:
1116: sub display_coursenormalmail {
1117: my ($r,$msgcount,$newmsgs,$rowColor1,$rowColor2) = @_;
1118: my $rowColor;
1119: if ($msgcount > 0) {
1120: $r->print('<tr bgcolor="#cccccc"><td><b><small>'.&mt('Number').'</small></b></td><td><b><small>'.&mt('Subject').'</small></b></td><td><b><small>'.&mt('Sender').'</small></b></td><td><b><small>'.&mt('Date/Time').'</small></b></td></tr>');
1121: my $rowNum = 0;
1122: my $mailcount = 1;
1123: foreach my $msg (@{$newmsgs}) {
1124: if ($rowNum %2 == 1) {
1125: $rowColor = $rowColor1;
1126: } else {
1127: $rowColor = $rowColor2;
1128: }
1129: $r->print('<tr bgcolor="'.$rowColor.'"><td valign="top"><small>'.$mailcount.'. </small></td><td valign="top"><small><a href="/adm/communicate">'.$msg->{'shortsub'}.'</a> </small></td><td valign="top"><small> '.$msg->{'from'}.'@'.$msg->{'fromdom'}.' </small></td><td valign="top"><small>'.$msg->{'sendtime'}.'</small></td></tr>');
1130: $rowNum ++;
1131: $mailcount ++;
1132: }
1133: } else {
1134: $r->print('<tr><td bgcolor="#ffffff" width="100%"><center><br /><b><i><small>'.&mt('No new course messages').'</small></i></b><br /><br /></center></td></tr>');
1135: }
1136: }
1137:
1138: sub display_coursecritmail {
1139: my ($r,$critmsgcount,$critmsgs,$rowColor1,$rowColor2) = @_;
1140: my $rowColor;
1141: if ($critmsgcount > 0) {
1142: $r->print('<tr bgcolor="#cccccc"><td><b><small>'.&mt('Number').'</small></b></td><td><b><small>'.&mt('Subject').'</small></b></td><td><b><small>'.&mt('Sender').'</small></b></td><td><b><small>'.&mt('Date/Time').'</small></b></td></tr>');
1143: my $rowNum = 0;
1144: my $mailcount = 1;
1145: foreach my $msg (@{$critmsgs}) {
1146: if ($rowNum %2 == 1) {
1147: $rowColor = $rowColor1;
1148: } else {
1149: $rowColor = $rowColor2;
1150: }
1151: $r->print('<tr bgcolor="'.$rowColor.'"><td valign="top"><small>'.$mailcount.'. <small></td><td valign="top"><small><a href="/adm/email?folder=critical">'.$msg->{'shortsub'}.'</a> </small></td><td valign="top"><small> '.$msg->{'from'}.'@'.$msg->{'fromdom'}.' </small></td><td valign="top"><small>'.$msg->{'sendtime'}.'</small></td></tr>');
1152: $rowNum ++;
1153: $mailcount ++;
1154: }
1155: } else {
1156: $r->print('<tr><td bgcolor="#ffffff" width="100%"><center><br /><b><i><small>'.&mt('No unread critical messages in course').'</small></i></b><br /><br /></center></td></tr>');
1157: }
1158: }
1159:
1160: sub cmp_title {
1161: my ($a,$b,$res_title) = @_;
1162: my ($atitle,$btitle) = (lc($$res_title{$a}),lc($$res_title{$b}));
1163: $atitle=~s/^\s*//;
1164: $btitle=~s/^\s*//;
1165: return $atitle cmp $btitle;
1166: }
1167:
1168: sub get_display_settings {
1169: my ($uname,$udom,$cid) = @_;
1170: my %settings = &Apache::lonnet::dump('nohist_whatsnew',$udom,$uname,$cid);
1171: my ($tmp) = keys(%settings);
1172: if ($tmp=~/^error:/) {
1173: %settings = ();
1174: unless ($tmp eq 'error: 2 tie(GDBM) Failed while attempting dump') {
1175: &logthis('Error retrieving whatsnew settings: '.$tmp.' for '.
1176: $uname.':'.$udom.' for course: '.$cid);
1177: }
1178: }
1179: return %settings;
1180: }
1181:
1182: sub store_display_settings {
1183: my ($uname,$udom,$cid,$checkallowed) = @_;
1184: my %whatsnew_settings;
1185: my $result;
1186: foreach my $key (keys(%{$checkallowed})) {
1187: if (exists($env{'form.display_'.$key})) {
1188: unless ($env{'form.display_'.$key} eq '') {
1189: $whatsnew_settings{$cid.':'.$key} = $env{'form.display_'.$key};
1190: }
1191: }
1192: }
1193: if (keys(%whatsnew_settings)) {
1194: $result = &Apache::lonnet::put('nohist_whatsnew',\%whatsnew_settings,
1195: $udom,$uname);
1196: } else {
1197: $result = 'ok';
1198: }
1199: return $result;
1200: }
1201:
1202: sub store_interval_setting {
1203: my ($uname,$udom,$cid,$interval_titles) = @_;
1204: my %interval_settings = ();
1205: my $result;
1206: if (defined($env{'form.interval'})) {
1207: $interval_settings{$cid.':interval'} = $env{'form.interval'};
1208: my $outcome = &Apache::lonnet::put('nohist_whatsnew',
1209: \%interval_settings,$udom,$uname);
1210: if ($outcome eq 'ok') {
1211: $result = &mt('Interval set to version changes [_1]',
1212: '<b>'.$$interval_titles{$env{'form.interval'}}.'</b><br />');
1213:
1214: } else {
1215: &Apache::lonnet::logthis('Error storing whatsnew interval setting'.
1216: ' '.$outcome.' for '.$uname.':'.$udom.' in course '.$cid);
1217: $result = &mt('Unable to set interval to [_1] due to [_2].',
1218: '<b>'.$$interval_titles{$env{'form.interval'}}.'</b>',
1219: '<tt>'.$outcome.'</tt>.<br />');
1220: }
1221: }
1222: return $result;
1223: }
1224:
1225: sub start_box {
1226: my ($r,$tabbg,$show,$heading,$caller) = @_;
1227: my %lt = &Apache::lonlocal::texthash(
1228: chth => 'Change thresholds?',
1229: chin => 'Change interval?',
1230: );
1231: my $showhide;
1232: if ($$show{$caller}) {
1233: $showhide = '<b><a href="javascript:change_display(document.visible.'.
1234: 'display_'.$caller.",'hide'".');">Hide</a></b>';
1235:
1236: } else {
1237: $showhide = '<b><a href="javascript:change_display(document.visible.'.
1238: 'display_'.$caller.",'show'".');">Show</a></b>';
1239: }
1240:
1241: $r->print('
1242: <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
1243: <tr>
1244: <td>
1245: <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
1246: <tr>
1247: <td bgcolor="'.$tabbg.'">
1248: <table width="100%" border="0" cellspacing="0" cellpadding="0">
1249: <tr>
1250: <td><b>'.$$heading{$caller}.'</b></td>
1251: <td valign="top" align="right">'.$showhide.'</td>
1252: </tr>
1253: </table>
1254: </td>
1255: </tr>');
1256: if (($caller eq 'abovethreshold') && ($$show{$caller})) {
1257: $r->print('
1258: <tr>
1259: <td bgcolor="'.$tabbg.'" align="right"><a href="/adm/whatsnew?command=chgthreshold"><b><small>'.$lt{'chth'}.'</small></b></a></td>
1260: </tr>');
1261: } elsif (($caller eq 'versionchanges') && ($$show{$caller})) {
1262: $r->print('
1263: <tr>
1264: <td bgcolor="'.$tabbg.'" align="right"><a href="/adm/whatsnew?command=chginterval"><b><small>'.$lt{'chin'}.'</small></b></a></td>
1265: </tr>');
1266: }
1267: $r->print('
1268: <tr>
1269: <td bgcolor="#ffffff">
1270: <table cellpadding="2" cellspacing="0" border="0" width="100%">
1271: ');
1272: return;
1273: }
1274:
1275: sub end_box {
1276: my ($r) = shift;
1277: $r->print('
1278: </table>
1279: </td>
1280: </tr>
1281: </table>
1282: </td>
1283: </tr>
1284: </table><br />');
1285: return;
1286: }
1287:
1288: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>