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