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