1: #
2: # $Id: lonwhatsnew.pm,v 1.55 2006/05/30 12:46:09 www Exp $
3: #
4: # Copyright Michigan State University Board of Trustees
5: #
6: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
7: #
8: # LON-CAPA is free software; you can redistribute it and/or modify
9: # it under the terms of the GNU General Public License as published by
10: # the Free Software Foundation; either version 2 of the License, or
11: # (at your option) any later version.
12: #
13: # LON-CAPA is distributed in the hope that it will be useful,
14: # but WITHOUT ANY WARRANTY; without even the implied warranty of
15: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: # GNU General Public License for more details.
17: #
18: # You should have received a copy of the GNU General Public License
19: # along with LON-CAPA; if not, write to the Free Software
20: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21: #
22: # /home/httpd/html/adm/gpl.txt
23: #
24: # http://www.lon-capa.org/
25: #
26:
27:
28: package Apache::lonwhatsnew;
29:
30: use strict;
31: use lib qw(/home/httpd/lib/perl);
32: use Apache::lonnet;
33: use Apache::loncommon();
34: use Apache::lonhtmlcommon();
35: use Apache::lonlocal;
36: use Apache::loncoursedata();
37: use Apache::lonnavmaps();
38: use Apache::lonuserstate;
39: use Apache::Constants qw(:common :http);
40: use Time::Local;
41: use GDBM_File;
42: use lib '/home/httpd/lib/perl/';
43: use LONCAPA;
44:
45: #----------------------------
46: # handler
47: #
48: #----------------------------
49:
50: sub handler {
51: my $r = shift;
52: if ($r->header_only) {
53: &Apache::loncommon::content_type($r,'text/html');
54: $r->send_http_header;
55: return OK;
56: }
57: &Apache::loncommon::get_unprocessed_cgi(
58: $ENV{'QUERY_STRING'},['command','refpage']);
59:
60: my $command = $env{'form.command'};
61: my $refpage = $env{'form.refpage'};
62:
63: my %checkallowed = ( coursenormalmail => 1,
64: coursecritmail => 1, );
65: foreach my $perm_check (['whn','whatsnew',1],
66: ['pch','coursediscussion',1],
67: ['mgr','handgrading',1],
68: ['vgr','abovethreshold',1],
69: ['opa','haserrors',1],
70: ['mdc','versionchanges',0],
71: ) {
72: my ($perm,$key,$check_section) = @{ $perm_check };
73: my $scope = $env{'request.course.id'};
74: if (!($checkallowed{$key} = &Apache::lonnet::allowed($perm,$scope))) {
75: $scope .= '/'.$env{'request.course.sec'};
76: if ( $check_section ) {
77: $checkallowed{$key} = &Apache::lonnet::allowed($perm,$scope);
78: }
79: if ($checkallowed{$key}) {
80: $checkallowed{$key.'_section'} = $env{'request.course.sec'};
81: }
82: }
83: }
84:
85: if ( ! $env{'request.course.fn'} || ! $checkallowed{'whatsnew'}) {
86: # Not in a course, or no whn priv in course
87: $env{'user.error.msg'}="/adm/whatsnew::whn:0:0:Cannot display what's new page";
88: return HTTP_NOT_ACCEPTABLE;
89: }
90:
91: &Apache::loncommon::content_type($r,'text/html');
92: $r->send_http_header;
93:
94: $r->print(&display_header($command,\%checkallowed));
95:
96: &Apache::lonhtmlcommon::clear_breadcrumbs();
97: &Apache::lonhtmlcommon::add_breadcrumb
98: ({href=>'/adm/whatsnew',
99: text=>"Display Action Items"});
100: if (($command eq 'chgthreshold') && $checkallowed{'abovethreshold'}) {
101: &Apache::lonhtmlcommon::add_breadcrumb
102: ({href=>'/adm/whatsnew?command=chgthreshold&refpage='.$refpage,
103: text=>"Change thresholds"});
104: $r->print(&Apache::lonhtmlcommon::breadcrumbs
105: ("What's New?",#'Course_Action_Items_Thresholds'
106: ));
107: } elsif (($command eq 'chginterval') && $checkallowed{'versionchanges'} ) {
108: &Apache::lonhtmlcommon::add_breadcrumb
109: ({href=>'/adm/whatsnew?command=chginterval&refpage='.$refpage,
110: text=>"Change interval"});
111: $r->print(&Apache::lonhtmlcommon::breadcrumbs
112: ("What's New?",#'Course_Action_Items_Intervals'
113: ));
114: } elsif (($command eq 'chgdisc') && $checkallowed{'coursediscussion'}) {
115: &Apache::lonhtmlcommon::add_breadcrumb
116: ({href=>'/adm/whatsnew?command=chgdisc&refpage='.$refpage,
117: text=>"Change discussion display"});
118: $r->print(&Apache::lonhtmlcommon::breadcrumbs
119: ("What's New?",#'Course_Action_Items_Intervals'
120: ));
121: } elsif ($command eq 'courseinit') {
122: &Apache::lonhtmlcommon::add_breadcrumb
123: ({href=>'/adm/whatsnew?command=courseinit&refpage='.$refpage,
124: text=>"Course initialization preference"});
125: $r->print(&Apache::lonhtmlcommon::breadcrumbs
126: ("What's New?",#'Course_Action_Items_Initialization'
127: ));
128: } else {
129: $r->print(&Apache::lonhtmlcommon::breadcrumbs
130: ("What's New?",#'Course_Action_Items_Display'
131: ));
132: }
133: &display_main_box($r,$command,$refpage,\%checkallowed);
134: return OK;
135: }
136:
137: #------------------------------
138: # display_main_box
139: #
140: # Display all the elements within the main box
141: #------------------------------
142:
143: sub display_main_box {
144: my ($r,$command,$refpage,$checkallowed) = @_;
145: my $domain=&Apache::loncommon::determinedomain();
146: my $function = &Apache::loncommon::get_users_function();
147: my $tabbg=&Apache::loncommon::designparm($function.'.tabbg',$domain);
148: $r->print('<table width="100%" border="0" cellpadding="5" cellspacing="0"><tr><td width="100%">');
149:
150: my %threshold_titles = &Apache::lonlocal::texthash (
151: av_attempts => 'Average number of attempts',
152: degdiff => 'Degree of difficulty',
153: numstudents => 'Total number of students with submissions',
154: );
155:
156: my %interval_titles = &Apache::lonlocal::texthash (
157: -1 => 'since start of course',
158: 2592000 => 'since last month',
159: 604800 => 'since last week',
160: 86400 => 'since yesterday',
161: );
162:
163: my %initpage = &Apache::lonlocal::texthash (
164: firstres => 'first resource in the course',
165: whatsnew => "what's new? page",
166: userpref => 'your general user preferences',
167: coursespecific => 'specific setting for this course',
168: );
169: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
170: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
171:
172: if (($command eq 'chgthreshold')
173: && $checkallowed->{'abovethreshold'}) {
174: &display_threshold_config($r,$refpage,$tabbg,\%threshold_titles,
175: $cdom,$crs);
176: } elsif (($command eq 'chginterval')
177: && $checkallowed->{'versionchanges'}) {
178: &display_interval_config($r,$refpage,\%interval_titles);
179: } elsif (($command eq 'chgdisc')
180: && $checkallowed->{'coursediscussion'}) {
181: &display_discussion_config($r,$refpage);
182: } elsif ($command eq 'courseinit') {
183: &courseinit_config($r,$refpage,\%initpage);
184: } else {
185: &display_actions_box($r,$tabbg,$command,$refpage,\%threshold_titles,
186: \%interval_titles,\%initpage,$cdom,$crs,$checkallowed);
187: }
188: my $end_page = &Apache::loncommon::end_page();
189: $r->print(<<END_OF_BLOCK);
190: </td>
191: </tr>
192: </table><br />
193: $end_page
194: END_OF_BLOCK
195: }
196:
197: #-------------------------------
198: # display_header
199: #
200: # Display the header information and set
201: # up the HTML
202: #-------------------------------
203:
204: sub display_header {
205: my ($command,$checkallowed) = @_;
206:
207: my $scripttag;
208: unless ($command eq 'chgthreshold' || $command eq 'chginterval') {
209: $scripttag = <<"END";
210: <script type="text/javascript">
211: function change_display(caller,change) {
212: caller.value = change;
213: document.visible.submit();
214: }
215:
216: function changeAll(change) {
217: END
218: foreach my $item (keys(%{$checkallowed})) {
219: if ($item =~ /_section$/) { next; }
220: if ($$checkallowed{$item}) {
221: $scripttag.='document.visible.display_'.$item.'.value=change'.
222: "\n";
223: }
224: }
225: $scripttag.='document.visible.submit();
226: }
227: </script>
228: ';
229: }
230: return &Apache::loncommon::start_page('Course Action Items',$scripttag);
231: }
232:
233: #-------------------------------
234: # display_actions_box
235: #
236: # Display the action items
237: #
238: #-------------------------------
239:
240: sub display_actions_box {
241: my ($r,$tabbg,$command,$refpage,$threshold_titles,$interval_titles,
242: $initpage,$cdom,$crs,$checkallowed) = @_;
243: my $rowColor1 = "#ffffff";
244: my $rowColor2 = "#eeeeee";
245:
246: my $udom = $env{'user.domain'};
247: my $uname = $env{'user.name'};
248: my $cid = $env{'request.course.id'};
249:
250: my %lt = &Apache::lonlocal::texthash(
251: 'yacc' => 'You are accessing an invalid course.',
252: 'gtfr' => 'Go to first resource',
253: 'pgse' => 'Page set to be displayed after you have selected a role in this course?',
254: 'hial' => 'Hide all',
255: 'shal' => 'Show all',
256: );
257:
258: my %unread = ();
259: my %ungraded = ();
260: my %bombed = ();
261: my %triggered = ();
262: my %changed = ();
263: my @newmsgs = ();
264: my @critmsgs = ();
265: my @newdiscussions = ();
266: my @tograde = ();
267: my @bombs = ();
268: my @warnings = ();
269: my $msgcount = 0;
270: my $critmsgcount = 0;
271:
272: my %res_title = ();
273: my %show = ();
274: my $needitems = 0;
275: my $boxcount = 0;
276:
277: my $result;
278: if ($command eq 'newcourseinit') {
279: $result = &store_courseinit_setting($uname,$udom,$cid,$initpage);
280: }
281:
282: my %threshold = (
283: av_attempts => 2,
284: degdiff => 0.5,
285: numstudents => 2,
286: );
287: my %pagedesc = &Apache::lonlocal::texthash (
288: firstres => 'First resource',
289: whatsnew => "What's New? page",
290: userpref => 'user preference',
291: coursespecific => 'course only',
292: default => 'default',
293: );
294:
295: my ($initcontrol,$initdisp) = &curr_courseinit();
296: my $currinit = $pagedesc{$initdisp}.' ('.$pagedesc{$initcontrol}.')';
297:
298: unless ($cid) {
299: $r->print('<br /><b><center>'.$lt{'yacc'}.'</center></b><br /><br />');
300: return;
301: }
302:
303: if ($refpage eq 'start') {
304: if (tie(my %bighash,'GDBM_File',$env{'request.course.fn'}.'.db',
305: &GDBM_READER(),0640)) {
306: my $furl=$bighash{'first_url'};
307: untie(%bighash);
308: $r->print('<font size="+1"><a href="'.$furl.'">'.$lt{'gtfr'}.
309: '</a></font><br />');
310: }
311: }
312: $r->print($lt{'pgse'}.' '.&mt('Currently: [_1]','<i>'.$currinit.'</i>').
313: ' <nobr> '.&mt('[_1] for just [_2]','<b>Change</b>',
314: '<a href="/adm/whatsnew?command=courseinit&refpage='.$refpage.
315: '">this course</a>').' '.&mt('or for all [_1].',
316: '<a href="/adm/preferences?action=changecourseinit&refpage='.
317: $refpage.'">your courses</a>').'</nobr><br /><hr />');
318:
319: if ($command eq 'reset') {
320: $result = &process_reset($cdom,$crs);
321: } elsif ($command eq 'update') {
322: $result = &process_update($uname,$udom,$threshold_titles);
323: } elsif ($command eq 'newinterval') {
324: $result = &store_interval_setting($uname,$udom,$cid,$interval_titles);
325: } elsif ($command eq 'newdiscconf') {
326: $result = &store_discussion_setting($uname,$udom,$cid);
327: }
328:
329: my $store_result=&store_display_settings($uname,$udom,$cid,$checkallowed);
330:
331: unless ($store_result eq 'ok') {
332: &Apache::lonnet::logthis('Error storing whatsnew settings: '.
333: $store_result.' for '.'user '.$uname.':'.$udom.' in course '.$cid);
334: $result .= &mt('Unable to store visibility settings due to [_1]',
335: $store_result);
336: }
337:
338: if ($result) {
339: $r->print($result.'<hr width="100%" />');
340: }
341: $r->rflush();
342:
343:
344: my %display_settings = &get_display_settings($uname,$udom,$cid);
345: my $timediff = $display_settings{$cid.':interval'};
346: unless (defined($timediff)) { $timediff = 604800; }
347: my $now = time;
348: my $interval = $$interval_titles{$timediff};
349: if ($timediff == -1) {
350: $timediff = time;
351: }
352: my $starttime = $now - $timediff;
353: my $countunread = $display_settings{$cid.':countunread'};
354: unless (defined($countunread)) {
355: $countunread = 'on';
356: }
357:
358: my %headings = &Apache::lonlocal::texthash(
359: coursediscussion => 'Unread course discussion posts',
360: handgrading => 'Problems requiring handgrading',
361: haserrors => 'Problems with errors',
362: versionchanges => 'Resources in course with version changes '.$interval,
363: coursenormalmail => 'New course messages',
364: coursecritmail => 'New critical messages in course',
365: );
366:
367: if ($$checkallowed{'abovethreshold'}) {
368: &get_curr_thresholds(\%threshold,$uname,$udom,$cid,$cdom,$crs);
369: }
370:
371: $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'};
372:
373: my @actionorder = ('handgrading','haserrors','abovethreshold','versionchanges','coursediscussion','coursenormalmail','coursecritmail');
374:
375: foreach my $key (keys(%{$checkallowed})) {
376: if ($key =~ /_section$/) { next; }
377: $show{$key} = 0;
378: if ($$checkallowed{$key}) {
379: unless ($display_settings{$cid.':'.$key} eq 'hide') {
380: $show{$key} = 1;
381: }
382: }
383: }
384:
385: foreach my $item (@actionorder) {
386: unless ($item eq 'coursenormalmail' || $item eq 'coursecritmail') {
387: if ($show{$item}) {
388: $needitems = 1;
389: last;
390: }
391: }
392: }
393:
394: if ($needitems) {
395: &getitems(\%unread,\%ungraded,\%bombed,\%triggered,\%changed,\@newdiscussions,\@tograde,\@bombs,\@warnings,$rowColor1,$rowColor2,\%threshold,$cdom,$crs,\%res_title,\%show,$starttime,$countunread);
396: }
397: if ($show{'coursenormalmail'}) {
398: $msgcount = &getnormalmail(\@newmsgs);
399: }
400: if ($show{'coursecritmail'}) {
401: $critmsgcount = &getcritmail(\@critmsgs);
402: }
403:
404: $r->print(qq|<a href="javascript:changeAll('hide');">$lt{'hial'}</a>
405: <a href="javascript:changeAll('show');">$lt{'shal'}</a>
406: <form method="post" name="visible" action="/adm/whatsnew">\n|);
407: foreach my $item (keys(%{$checkallowed})) {
408: if ($item =~ /_section$/) { next; }
409: if ($$checkallowed{$item}) {
410: $r->print('<input type="hidden" name="display_'.$item.'" />'."\n");
411: }
412: }
413:
414: $r->print('<input type="hidden" name="refpage" value="'.$refpage.'"></form><br /><table border="0" width="100%" cellpadding="2" cellspacing="4"><tr><td align="left" valign="top" width="45%">');
415:
416: my $displayed = 0;
417: my $totalboxes = 0;
418: foreach my $key (keys(%{$checkallowed})) {
419: if ($key =~ /_section$/) { next; }
420: if ($key eq 'whatsnew' ) { next; } # whatsnew check creates no box
421: if ($$checkallowed{$key}) {
422: $totalboxes ++;
423: }
424: }
425: my $halfway = int($totalboxes/2) + $totalboxes%2;
426: foreach my $actionitem (@actionorder) {
427: if ($$checkallowed{$actionitem}) {
428: if ($displayed == $halfway) {
429: $r->print('</td><td width="6%"> </td><td align="left" valign="top" width="47%">');
430: }
431: &display_launcher($r,$actionitem,$refpage,$checkallowed,$tabbg,$rowColor1,$rowColor2,\%show,\%headings,\%res_title,\@tograde,\%ungraded,\@bombs,\%bombed,\%changed,\@warnings,\%triggered,\@newdiscussions,\%unread,$msgcount,\@newmsgs,$critmsgcount,\@critmsgs,$interval,$countunread);
432: $displayed ++;
433: }
434: }
435: $r->print('
436: </table>
437: </td>
438: </tr>
439: </table>
440: </td>
441: </tr>
442: </table>');
443: }
444:
445: #-------------------------------
446: # display_threshold_config
447: #
448: # Display the threshold setting screen
449: #
450: #-------------------------------
451:
452: sub display_threshold_config {
453: my ($r,$refpage,$tabbg,$threshold_titles,$cdom,$crs) = @_;
454: my $uname = $env{'user.name'};
455: my $udom = $env{'user.dom'};
456: my $cid = $env{'request.course.id'};
457: my %threshold = ();
458: my $rowColor1 = "#ffffff";
459: my $rowColor2 = "#eeeeee";
460: my $rowColor;
461:
462: my @thresholditems = ("av_attempts","degdiff","numstudents");
463: foreach my $item (@thresholditems) {
464: $threshold{$item} = '';
465: }
466: my %threshold_titles = &Apache::lonlocal::texthash(
467: av_attempts => 'Average number of attempts',
468: degdiff => 'Degree of difficulty',
469: numstudents => 'Total number of students with submissions',
470: );
471: &get_curr_thresholds(\%threshold,$uname,$udom,$cid,$cdom,$crs);
472:
473: $r->print('<br /><form name="thresholdform" method="post" action="/adm/whatsnew">
474: <table border="0" cellpadding="2" cellspacing="4">
475: <tr>
476: <td align="left" valign="top" width="45%">
477: <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
478: <tr>
479: <td>
480: <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000">
481: <tr>
482: <td bgcolor="#ffffff">
483: <table cellspacing="0" cellpadding="4" border="0">
484: <tr bgcolor="'.$tabbg.'">
485: <th>Threshold Name</th>
486: <th>Current value</th>
487: <th>Change?</th>
488: </tr>');
489: my $rowNum =0;
490: foreach my $type (@thresholditems) {
491: my $parameter = $env{'request.course.id'}.':threshold_'.$type;
492: # onchange is javascript to automatically check the 'Set' button.
493: my $onchange = 'onFocus="javascript:window.document.forms'.
494: "['thresholdform'].elements['".$parameter."_setparmval']".
495: '.checked=true;"';
496: if ($rowNum %2 == 1) {
497: $rowColor = $rowColor1;
498: } else {
499: $rowColor = $rowColor2;
500: }
501: $r->print('
502: <tr bgcolor="'.$rowColor.'">
503: <td>'.$threshold_titles{$type}.'</td>
504: <td>'.&Apache::lonhtmlcommon::textbox($parameter.'_value',
505: $threshold{$type},
506: 10,$onchange).'</td>
507: <td>'
508: .&Apache::lonhtmlcommon::checkbox($parameter.'_setparmval').
509: '</td>
510: </tr>');
511: $rowNum ++;
512: }
513: $r->print('</table></td></tr></table></td></tr></table>
514: <br /><input type="submit" name="threshold" value="Make changes" />
515: <input type="hidden" name="command" value="update" />
516: <input type="hidden" name="refpage" value="'.$refpage.'" />
517: </form>');
518: }
519:
520: #-------------------------------
521: # display_interval_config
522: #
523: # Display the interval setting screen
524: #
525: #-------------------------------
526:
527: sub display_interval_config {
528: my ($r,$refpage,$interval_titles) = @_;
529: my $current = &get_current($env{'user.name'},$env{'user.domain'},
530: $env{'request.course.id'},'interval');
531: $r->print('<br />'.&mt('Choose the time window to use for display of version changes for resources in the course.'));
532: unless ($current eq '') {
533: $r->print(' '.&mt('Current value is [_1]','<b>'.
534: $$interval_titles{$current}.'</b>.'));
535: }
536: $r->print('<br /><br />
537: <form method="post" name="intervalswitch" action="/adm/whatsnew">
538: <input type="hidden" name="command" value="newinterval" />
539: <input type="hidden" name="refpage" value="'.$refpage.'" />
540: <select name="interval">
541: ');
542: foreach my $key (reverse sort ({$a cmp $b} (keys(%{$interval_titles})))) {
543: $r->print('<option value="'.$key.'">Version changes '.$$interval_titles{$key}.
544: '</option>'."\n");
545: }
546: $r->print('</select>
547: <input type="submit" name="display" value="'.
548: &mt('Change interval').'" /></form>');
549: return;
550: }
551:
552: #----------------------------------------------
553: # display_discussion_config
554: #
555: # Display the discussion display setting screen
556: #
557: #----------------------------------------------
558:
559: sub display_discussion_config {
560: my ($r,$refpage) = @_;
561: my $current = &get_current($env{'user.name'},$env{'user.domain'},
562: $env{'request.course.id'},'countunread');
563: if ($current eq '') {
564: $current = 'on';
565: }
566: my %opposite = (
567: 'on' => 'off',
568: 'off' => 'on',
569: );
570: $r->print('<script type="text/javascript">
571: function toggle_countunread(choice) {
572: if (choice == "unchanged") {
573: document.discussionswitch.command.value = "";
574: }
575: document.discussionswitch.submit();
576: }
577: </script>');
578: $r->print('<br />'.&mt('Choose whether or not to display a count of the number of new posts for each resource or bulletin board which has unread posts.').'<br />'.&mt('This can increase the time taken to gather data for the [_1] page by a few seconds.',"<i>What's New?</i>").' '.&mt('Currently set to [_1].','<b>'.$current.'</b>'));
579: $r->print('<br /><br />
580: <form method="post" name="discussionswitch" action="/adm/whatsnew">
581: <input type="hidden" name="command" value="newdiscconf" />
582: <input type="hidden" name="refpage" value="'.$refpage.'" />
583: <input type="hidden" name="countunread" value="'.$opposite{$current}.'" />
584: ');
585: $r->print('<br/>
586: <input type="button" name="display" value="'.
587: &mt('Change to [_1]',$opposite{$current}).'"
588: onclick="javascript:toggle_countunread('."'change'".')" />
589:  
590: <input type="button" name="nochange" value="'.
591: &mt("No change").'"
592: onclick="javascript:toggle_countunread('."'unchanged'".')" />
593: </form>');
594: return;
595: }
596:
597: #---------------------------------------------------
598: # courseinit_config
599: #
600: # Set page displayed when course loads after
601: # selecting a role in the course from the roles page.
602: #
603: #---------------------------------------------------
604:
605: sub courseinit_config {
606: my ($r,$refpage,$initpage) = @_;
607: my ($control,$current) = &curr_courseinit();
608: my @chgstate = ('userpref','coursespecific');
609: my @chgentry = ('firstres','whatsnew');
610: my %lt = &Apache::lonlocal::texthash(
611: 'chwp' => 'Choose which page will be displayed when you enter this course after selecting a role.',
612: 'cuva' => 'Current value is determined by',
613: 'anis' => 'and is set to display',
614: 'padc' => 'Page display controlled by',
615: 'chce' => 'Choose course entry',
616: 'moce' => 'Modify course entry',
617: );
618: $r->print(<<"END");
619: <br />$lt{'chwp'}
620: <br />$lt{'cuva'}: <b>
621: $$initpage{$control}</b> $lt{'anis'} <b>
622: $$initpage{$current}</b>.<br /><br />
623: <form method="post" name="courseinitswitch" action="/adm/whatsnew">
624: <input type="hidden" name="command" value="newcourseinit" />
625: <input type="hidden" name="refpage" value="$refpage" />
626: $lt{'padc'}
627: END
628: foreach my $choice (@chgstate) {
629: $r->print('<nobr><label><input type="radio" name="courseinit_control" value="'.
630: $choice.'"/>'.$$initpage{$choice}.' </label></nobr>');
631: }
632: $r->print('<br /><br />'.&mt('If').' '.$$initpage{'coursespecific'}.
633: '<br />'.$lt{'chce'}." \n");
634: foreach my $choice (@chgentry) {
635: $r->print('<nobr><label><input type="radio" name="courseinit_page" value="'.
636: $choice.'"/>'.$$initpage{$choice}.' </label></nobr>');
637: }
638: $r->print('<br /><br /><input type="submit" name="display" value="'.
639: $lt{'moce'}.'" /></form>');
640: return;
641: }
642:
643: sub curr_courseinit {
644: my $current = &get_current($env{'user.name'},$env{'user.domain'},
645: $env{'request.course.id'},'courseinit');
646: my $control;
647: if ($current) {
648: $control = 'coursespecific';
649: } else {
650: $control = 'userpref';
651: my %userenv = &Apache::lonnet::get('environment',
652: ['course_init_display']);
653: if (exists($userenv{'course_init_display'})) {
654: $current = $userenv{'course_init_display'};
655: }
656: unless ($current) {
657: $current = 'whatsnew';
658: }
659: }
660: return ($control,$current);
661: }
662:
663: sub display_launcher {
664: my ($r,$action,$refpage,$checkallowed,$tabbg,$rowColor1,$rowColor2,$show,
665: $headings,$res_title,$tograde,$ungraded,$bombs,$bombed,$changed,
666: $warnings,$triggered,$newdiscussions,$unread,$msgcount,$newmsgs,
667: $critmsgcount,$critmsgs,$interval,$countunread) = @_;
668:
669: if ($$checkallowed{$action}) {
670: &start_box($r,$tabbg,$show,$headings,$action,$refpage);
671: if ($$show{$action}) {
672: if ($action eq 'handgrading') { # UNGRADED ITEMS
673: &display_handgrade($r,$tograde,$rowColor1,$rowColor2,
674: $ungraded);
675: } elsif ($action eq 'haserrors') { # BOMBS
676: &display_haserrors($r,$bombs,$rowColor1,$rowColor2,$bombed,
677: $res_title);
678: } elsif ($action eq 'versionchanges') { # VERSION CHANGES
679: &display_versionchanges($r,$changed,$res_title,$rowColor1,
680: $rowColor2,$interval);
681:
682: } elsif ($action eq 'abovethreshold') { # DEGDIFF/AV. TRIES TRIGGERS
683: &display_abovethreshold($r,$refpage,$warnings,$triggered,
684: $res_title,$rowColor1,$rowColor2);
685: } elsif ($action eq 'coursediscussion') { # UNREAD COURSE DISCUSSION
686: &display_coursediscussion($r,$newdiscussions,$unread,
687: $countunread,$res_title,$rowColor1,$rowColor2);
688: } elsif ($action eq 'coursenormalmail') { # NORMAL MESSAGES
689: &display_coursenormalmail($r,$msgcount,$newmsgs,$rowColor1,
690: $rowColor2);
691: } elsif ($action eq 'coursecritmail') { # CRITICAL MESSAGES
692: &display_coursecritmail($r,$critmsgcount,$critmsgs,$rowColor1,
693: $rowColor2);
694: }
695: }
696: &end_box($r);
697: }
698: return;
699: }
700:
701: sub getitems {
702: my ($unread,$ungraded,$bombed,$triggered,$changed,$newdiscussions,
703: $tograde,$bombs,$warnings,$rowColor1,$rowColor2,$threshold,$cdom,$crs,
704: $res_title,$show,$starttime,$countunread) = @_;
705: my $navmap = Apache::lonnavmaps::navmap->new();
706: # force retrieve Resource to seed the part id cache we'll need it later
707: my @allres=$navmap->retrieveResources(undef,
708: sub {if ($_[0]->is_problem) { $_[0]->parts();} return 1;});
709: my %resourcetracker;
710: my $discussiontime;
711:
712: # Resource version changes
713: if ($$show{'versionchanges'}) {
714: &checkversions($cdom,$crs,$navmap,$changed,$starttime);
715: }
716:
717: if ($$show{'abovethreshold'}) {
718: %resourcetracker = &Apache::lonnet::dump('nohist_resourcetracker',
719: $cdom,$crs);
720: }
721:
722: my $warningnum = 0;
723: foreach my $resource (@allres) {
724: my $result = '';
725: my $applies = 0;
726: my $symb = $resource->symb();
727: %{$$bombed{$symb}} = ();
728: %{$$ungraded{$symb}} = ();
729: %{$$triggered{$symb}} = ();
730: $$triggered{$symb}{numparts} = 0;
731: my $title = $resource->compTitle();
732: $$res_title{$symb} = $title;
733: my $ressymb = $resource->wrap_symb();
734:
735: # Check if there are unread discussion postings
736: if ($$show{'coursediscussion'}) {
737: &check_discussions($resource,$symb,$ressymb,$title,
738: $newdiscussions,$unread,$countunread);
739: }
740:
741: # Check for ungraded problems
742: if ($resource->is_problem()) {
743: if ($$show{'handgrading'}) {
744: &check_handgraded($resource,$symb,$title,$cdom,$crs,$ungraded,
745: $tograde);
746: }
747: }
748:
749: # Check for bombs
750: if ($$show{'haserrors'}) {
751: &check_bombed($resource,$symb,$title,$bombs,$bombed);
752: }
753:
754: # Maxtries and degree of difficulty for problem parts, unless handgradeable
755: if ($$show{'abovethreshold'}) {
756: &check_thresholds($resource,$symb,\%resourcetracker,$triggered,
757: $threshold,$warnings,$warningnum,$rowColor1,$rowColor2);
758: }
759:
760: }
761: }
762:
763: sub check_discussions {
764: my ($resource,$symb,$ressymb,$title,$newdiscussions,$unread,
765: $countunread) = @_;
766:
767: if (!$resource->hasDiscussion()) { return; }
768:
769: %{$$unread{$ressymb}} = ();
770: $$unread{$ressymb}{'title'} = $title;
771: $$unread{$ressymb}{'symb'} = $symb;
772: push(@{$newdiscussions}, $ressymb);
773:
774: $$unread{$ressymb}{'lastpost'} = $resource->last_post_time();
775:
776: if ($countunread eq 'on') {
777: $$unread{$ressymb}{'unreadcount'} = $resource->unread_discussion();
778: }
779: }
780:
781: sub check_handgraded {
782: my ($resource,$symb,$title,$cdom,$cnum,$ungraded,$tograde) = @_;
783: if ($resource->is_problem()) {
784: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
785: my $partlist=$resource->parts();
786: my $handgradeable;
787: foreach my $part (@$partlist) {
788: if ($resource->handgrade($part) eq 'yes') {
789: $handgradeable=1; last;
790: }
791: }
792: if ($handgradeable) {
793: my @ungraded = &Apache::bridgetask::get_queue_symb_status(
794: 'gradingqueue',$symb,$cdom,$cnum);
795: if (@ungraded > 0) {
796: $$ungraded{$symb}{count} = scalar(@ungraded);
797: $$ungraded{$symb}{title} = $title;
798: push(@{$tograde}, $symb);
799: }
800: }
801: }
802: }
803:
804: sub check_bombed {
805: my ($resource,$symb,$title,$bombs,$bombed) = @_;
806: if ($resource->getErrors()) {
807: my $errors = $resource->getErrors();
808: $errors =~ s/^,//;
809: my @bombs = split(/,/, $errors);
810: my $errorcount = scalar(@bombs);
811: my $errorlink = '<a href="/adm/email?display='.
812: &escape($bombs[0]).'">'.
813: $title.'</a>';
814: $$bombed{$symb}{errorcount} = $errorcount;
815: $$bombed{$symb}{errorlink} = $errorlink;
816: push(@{$bombs}, $symb);
817: }
818: }
819:
820: sub check_thresholds {
821: my ($resource,$symb,$resourcetracker,$triggered,$threshold,$warnings,
822: $warningnum,$rowColor1,$rowColor2) = @_;
823: # Compile maxtries and degree of difficulty for problem parts, unless handgradeable
824: my @parts = @{$resource->parts()};
825: my %stats;
826: my %lastreset = ();
827: my $warning = 0;
828: my $rowColor;
829: foreach my $part (@parts) {
830: if ($resource->handgrade($part) eq 'yes') {
831: next;
832: }
833: if ($resource->is_survey($part)) {
834: next;
835: }
836: %{$stats{$part}} = ();
837: my ($attempts,$users,$corrects,$degdiff,$av_attempts);
838: if (exists($$resourcetracker{$symb."\0".$part."\0attempts"})) {
839: $attempts = $$resourcetracker{$symb."\0".$part."\0attempts"};
840: }
841: if (exists($$resourcetracker{$symb."\0".$part."\0users"})) {
842: $users = $$resourcetracker{$symb."\0".$part."\0users"};
843: }
844: if (exists($$resourcetracker{$symb."\0".$part."\0correct"})) {
845: $corrects = $$resourcetracker{$symb."\0".$part."\0correct"};
846: }
847: if ($attempts > 0) {
848: $degdiff = 1 - ($corrects/$attempts);
849: $degdiff = sprintf("%.2f",$degdiff);
850: }
851: if ($users > 0) {
852: $av_attempts = $attempts/$users;
853: $av_attempts = sprintf("%.2f",$av_attempts);
854: }
855: if ((($degdiff ne '' && $degdiff >= $$threshold{'degdiff'}) || ($av_attempts ne '' && $av_attempts >= $$threshold{'av_attempts'})) && ($users >= $$threshold{'numstudents'})) {
856: $stats{$part}{degdiff} = $degdiff;
857: $stats{$part}{attempts} = $av_attempts;
858: $stats{$part}{users} = $users;
859: $lastreset{$part} = $$resourcetracker{$symb."\0".$part."\0resettime"};
860: if ($lastreset{$part}) {
861: $lastreset{$part} = &Apache::lonnavmaps::timeToHumanString($lastreset{$part});
862: }
863: $warning = 1;
864: }
865: }
866: if ($warning) {
867: if ($warningnum %2 == 1) {
868: $rowColor = $rowColor1;
869: } else {
870: $rowColor = $rowColor2;
871: }
872: $$triggered{$symb}{title} = $resource->title;
873: foreach my $part (@parts) {
874: if (exists($stats{$part}{users})) {
875: my $resetname = 'reset_'.&escape($symb."\0".$part);
876: my $resettitle = 'title_'.&escape($symb."\0".$part);
877: if ($$triggered{$symb}{numparts}) {
878: $$triggered{$symb}{text} .= '<tr bgcolor="'.$rowColor.'">'."\n";
879: }
880: if (@parts > 1) {
881: $$triggered{$symb}{text} .= '
882: <td align="right"><small>part - '.$part.'<small></td>';
883: } else {
884: $$triggered{$symb}{text} .= '
885: <td align="right"><small>single part</small></td>';
886: }
887: $$triggered{$symb}{text} .= '
888: <td align="right"><small>'.$stats{$part}{users}.'</small></td>
889: <td align="right"><small>'.$stats{$part}{attempts}.'</small></td>
890: <td align="right"><small>'.$stats{$part}{degdiff}.'</small></td>
891: <td align="right"><small>'.$lastreset{$part}.'</small></td>
892: <td align="right"><small><input type="checkbox" name="'.$resetname.'" /><input type="hidden" name="'.$resettitle.'" value="'.&escape($$triggered{$symb}{title}).'" /></td>
893: </tr>';
894: $$triggered{$symb}{numparts} ++;
895: }
896: }
897: push(@{$warnings},$symb);
898: $warningnum ++;
899: }
900: }
901:
902:
903: sub get_curr_thresholds {
904: my ($threshold,$uname,$udom,$cid,$cdom,$crs) = @_;
905: my %thresholdsettings = &Apache::lonnet::dump('nohist_whatsnew',$udom,
906: $uname,$cid.':threshold');
907: my $thresholdcount = 0;
908: my ($tmp) = %thresholdsettings;
909: unless ($tmp =~ /^(con_lost|error|no_such_host)/i) {
910: foreach my $item (keys %{$threshold}) {
911: if (exists($thresholdsettings{$cid.':threshold_'.$item})) {
912: $$threshold{$item} =
913: $thresholdsettings{$cid.':threshold_'.$item};
914: $thresholdcount ++;
915: }
916: }
917: }
918: if ($thresholdcount == 3) {
919: return;
920: }
921: my %coursesettings = &Apache::lonnet::dump('environment',
922: $cdom,$crs,'internal.threshold');
923: my ($temp) = %coursesettings;
924: unless ($temp =~ /^(con_lost|error|no_such_host)/i) {
925: foreach my $item (keys %{$threshold}) {
926: unless (exists($thresholdsettings{$cid.':threshold_'.$item})) {
927: if (exists($coursesettings{'internal.threshold_'.$item})) {
928: $$threshold{$item} =
929: $coursesettings{'internal.threshold_'.$item};
930: }
931: }
932: }
933: }
934: return;
935: }
936:
937: sub get_current {
938: my ($uname,$udom,$cid,$caller) = @_;
939: my $currvalue;
940: my %settings = &Apache::lonnet::dump('nohist_whatsnew',$udom,$uname,$cid.
941: ':'.$caller);
942: my ($tmp) = %settings;
943: unless ($tmp =~ /^(con_lost|error|no_such_host)/i) {
944: $currvalue = $settings{$cid.':'.$caller};
945: }
946: return $currvalue;
947: }
948:
949: sub process_reset {
950: my ($dom,$crs) = @_;
951: my $result = '<b>'.&mt('Counters reset for following problems (and parts):').
952: '</b><br />';
953: my @agg_types = ('attempts','users','correct');
954: my %agg_titles = &Apache::lonlocal::texthash (
955: attempts => 'Number of submissions',
956: users => 'Students with submissions',
957: correct => 'Number of correct submissions',
958: );
959: my @resets = ();
960: my %titles = ();
961: foreach my $key (keys(%env)) {
962: next if ($key !~ /^form\.reset_(.+)$/);
963: my $title = &unescape($env{'form.title_'.$1});
964: my $reset_item = &unescape($1);
965: my %curr_aggregates = &Apache::lonnet::dump('nohist_resourcetracker',$dom,$crs,$reset_item);
966: my %aggregates = ();
967: my ($symb,$part) = split(/\0/,$reset_item);
968: foreach my $type (@agg_types) {
969: $aggregates{$reset_item."\0".$type} = 0;
970: }
971: $aggregates{$reset_item."\0".'resettime'} = time;
972: my $putresult = &Apache::lonnet::put('nohist_resourcetracker',\%aggregates,
973: $dom,$crs);
974: if ($putresult eq 'ok') {
975: $result .= $title.' -part '.$part.': ';
976: my %new_aggregates = &Apache::lonnet::dump('nohist_resourcetracker',$dom,$crs,$reset_item);
977: foreach my $type (@agg_types) {
978: $result .= $agg_titles{$type}.' = '.$new_aggregates{$reset_item."\0".$type}.'; ';
979: }
980: $result =~ s/; $//;
981: $result .= '<br />';
982: } else {
983: $result = $title.' -part '.$part.': '.&mt('Unable to reset counters to zero due to [_1]',$putresult).'.<br />'."\n";
984: }
985: }
986: return $result;
987: }
988:
989: sub process_update {
990: my ($uname,$udom,$threshold_titles) = @_;
991: my $setoutput = '<b>Changes to threshold(s) for problem tracking:</b><br />';
992: foreach (keys %env) {
993: next if ($_!~/^form\.(.+)\_setparmval$/);
994: my $name = $1;
995: my $value = $env{'form.'.$name.'_value'};
996: if ($name && defined($value)) {
997: my $put_result = &Apache::lonnet::put('nohist_whatsnew',
998: {$name=>$value},$udom,$uname);
999:
1000: my ($shortname) = ($name =~ /^\Q$env{'request.course.id'}\E:threshold_(.+)$/);
1001: if ($put_result eq 'ok') {
1002: $setoutput.=&mt('Set threshold for [_1] to [_2]',
1003: '<b>'.$$threshold_titles{$shortname}.'</b>',
1004: '<b>'.$value.'</b>').'<br />';
1005: } else {
1006: $setoutput.=&mt('Unable to set threshold for [_1] to [_2] due to [_3].',
1007: '<b>'.$name.'</b>','<b>'.$value.'</b>',
1008: '<tt>'.$put_result.'</tt>').'<br />';
1009: }
1010: }
1011: }
1012: return $setoutput;
1013: }
1014:
1015: sub getnormalmail {
1016: my ($newmsgs) = @_;
1017: # Check for unread mail in course
1018: my $msgcount = 0;
1019:
1020: my @messages = sort(&Apache::lonnet::getkeys('nohist_email'));
1021: foreach my $message (@messages) {
1022: my $msgid=&escape($message);
1023: my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
1024: &Apache::lonmsg::unpackmsgid($msgid);
1025: if (($fromcid) && ($fromcid eq $env{'request.course.id'})) {
1026: if (defined($sendtime) && $sendtime!~/error/) {
1027: my $numsendtime = $sendtime;
1028: $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
1029: if ($status eq 'new') {
1030: $msgcount ++;
1031: if ($shortsubj eq '') {
1032: $shortsubj = &mt('No subject');
1033: }
1034: push(@{$newmsgs}, {
1035: msgid => $msgid,
1036: sendtime => $sendtime,
1037: shortsub => $shortsubj,
1038: from => $fromname,
1039: fromdom => $fromdom
1040: });
1041: }
1042: }
1043: }
1044: }
1045: return $msgcount;
1046: }
1047:
1048: sub getcritmail {
1049: my ($critmsgs) = @_;
1050: # Check for critical messages in course
1051: my %what=&Apache::lonnet::dump('critical');
1052: my $result = '';
1053: my $critmsgcount = 0;
1054: foreach my $msgid (sort(keys(%what))) {
1055: my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
1056: &Apache::lonmsg::unpackmsgid($msgid);
1057: if (($fromcid) && ($fromcid eq $env{'request.course.id'})) {
1058: if (defined($sendtime) && $sendtime!~/error/) {
1059: my $numsendtime = $sendtime;
1060: $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
1061: $critmsgcount ++;
1062: if ($shortsubj eq '') {
1063: $shortsubj = &mt('No subject');
1064: }
1065: push(@{$critmsgs}, {
1066: msgid => $msgid,
1067: sendtime => $sendtime,
1068: shortsub => $shortsubj,
1069: from => $fromname,
1070: fromdom => $fromdom
1071: });
1072: }
1073: }
1074: }
1075: return $critmsgcount;
1076: }
1077:
1078:
1079: sub checkversions {
1080: my ($cdom,$crs,$navmap,$changed,$starttime) = @_;
1081: my %changes=&Apache::lonnet::dump('versionupdate',$cdom,$crs);
1082: my ($tmp) = keys(%changes);
1083: unless ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1084: if (keys(%changes) > 0) {
1085: foreach my $key (sort(keys(%changes))) {
1086: if ($changes{$key} > $starttime) {
1087: my $version;
1088: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
1089: my $currentversion=&Apache::lonnet::getversion($key);
1090: my $revdate =
1091: &Apache::lonnet::metadata($root.'.'.$extension,
1092: 'lastrevisiondate');
1093: $revdate = &Apache::lonlocal::locallocaltime($revdate);
1094: my $linkurl=&Apache::lonnet::clutter($key);
1095: my $usedversion=$navmap->usedVersion('version_'.$linkurl);
1096: my @resources = $navmap->getResourceByUrl($linkurl,1);
1097: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1098: $version = $usedversion;
1099: } else {
1100: $version = $currentversion;
1101: }
1102: foreach my $res (@resources) {
1103: if (ref($res) eq 'Apache::lonnavmaps::resource') {
1104: my $symb = $res->symb();
1105: %{$$changed{$symb}} = (
1106: current => $currentversion,
1107: version => $version,
1108: revdate => $revdate,
1109: );
1110: }
1111: }
1112: }
1113: }
1114: }
1115: }
1116: return;
1117: }
1118:
1119: sub display_handgrade {
1120: my ($r,$tograde,$rowColor1,$rowColor2,$ungraded) = @_;
1121: my $rowColor;
1122: my %lt = &Apache::lonlocal::texthash(
1123: 'prna' => 'Problem Name',
1124: 'nmun' => 'Number ungraded',
1125: 'nopr' => 'No problems require handgrading',
1126: );
1127: if (@{$tograde} > 0) {
1128: $r->print('<tr bgcolor="#cccccc"><td><b><small>'.$lt{'prna'}.'</small></b></td><td align="right"><b><small>'.$lt{'nmun'}.'</small></b></td></tr>');
1129: my $rowNum = 0;
1130: foreach my $res (@{$tograde}) {
1131: if ($rowNum %2 == 1) {
1132: $rowColor = $rowColor1;
1133: } else {
1134: $rowColor = $rowColor2;
1135: }
1136: my ($map,$id,$url)=&Apache::lonnet::decode_symb($res);
1137: my $linkurl=&Apache::lonnet::clutter($url);
1138: $linkurl .= '?symb='.&escape($res);
1139:
1140: $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>');
1141: $rowNum ++;
1142: }
1143: } else {
1144: $r->print('<tr><td bgcolor="#ffffff"><br><center><i><b><small> '.$lt{'nopr'}.' </small><br><br></b></i></td></tr>');
1145: }
1146: }
1147:
1148: sub display_haserrors {
1149: my ($r,$bombs,$rowColor1,$rowColor2,$bombed,$res_title) = @_;
1150: my $bombnum = 0;
1151: my $rowColor;
1152: my %lt = &Apache::lonlocal::texthash(
1153: reso => 'Resource',
1154: nmer => 'Number of errors',
1155: noer => 'No problems with errors',
1156: );
1157: if (@{$bombs} > 0) {
1158: $r->print('<tr bgcolor="#cccccc"><td><b><small>'.$lt{'reso'}.'</small></b></td><td align="right"><b><small>'.$lt{'nmer'}.'</small></b></td></tr>');
1159: @{$bombs} = sort { &cmp_title($a,$b,$res_title) } @{$bombs};
1160: foreach my $bomb (@{$bombs}) {
1161: if ($bombnum %2 == 1) {
1162: $rowColor = $rowColor1;
1163: } else {
1164: $rowColor = $rowColor2;
1165: }
1166: $r->print('<tr bgcolor="'.$rowColor.'"><td><small>'.$$bombed{$bomb}{errorlink}.'</small></td><td align="right"><small>'.$$bombed{$bomb}{errorcount}.'</small></td></tr>');
1167: $bombnum ++;
1168: }
1169: } else {
1170: $r->print('<tr><td bgcolor="#ffffff"><br /><center><b><i><small>'.$lt{'noer'}.'</small></i></b></center><br /></td></tr>');
1171: }
1172: return;
1173: }
1174:
1175: sub display_abovethreshold {
1176: my ($r,$refpage,$warnings,$triggered,$res_title,$rowColor1,$rowColor2) = @_;
1177: my %lt = &Apache::lonlocal::texthash(
1178: reso => 'Resource',
1179: part => 'Part',
1180: nust => 'Num. students',
1181: avat => 'Av. Attempts',
1182: dedi => 'Deg. Diff',
1183: lare => 'Last Reset',
1184: reco => 'Reset Count?',
1185: rese => 'Reset counters to 0',
1186: nopr => 'No problems satisfy threshold criteria',
1187: );
1188: my $rowColor;
1189: my $warningnum = 0;
1190: if (@{$warnings} > 0) {
1191: @{$warnings} = sort { &cmp_title($a,$b,$res_title) } @{$warnings};
1192: $r->print('<form name="reset_tracking" method="post" action="/adm/whatsnew">'.
1193: ' <input type="hidden" name="command" value="reset" />'."\n".
1194: ' <input type="hidden" name="refpage" value="'.$refpage.'" />'.
1195: "\n");
1196: $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>');
1197: foreach my $res (@{$warnings}) {
1198: if ($warningnum %2 == 1) {
1199: $rowColor = $rowColor1;
1200: } else {
1201: $rowColor = $rowColor2;
1202: }
1203: my ($map,$id,$url)=&Apache::lonnet::decode_symb($res);
1204: my $linkurl=&Apache::lonnet::clutter($url);
1205: my $rowspan;
1206: if ($$triggered{$res}{numparts} > 1) {
1207: $rowspan = 'rowspan="'.$$triggered{$res}{numparts}.'"';
1208: }
1209: $linkurl .= '?symb='.&escape($res);
1210: $r->print('<tr bgcolor="'.$rowColor.'"><td '.$rowspan.'><a href="'.$linkurl.'"><small>'.$$triggered{$res}{title}.'</small></a></td>'.$$triggered{$res}{text});
1211: $warningnum ++;
1212: }
1213: $r->print('<tr bgcolor="#cccccc"><td colspan="7" align="right"><br /><b><small><input type="submit" name="counters" value="'.$lt{'rese'}.'" /></form>');
1214: } else {
1215: $r->print('<tr><td bgcolor="#ffffff"><br /><center><b><i><small>'.$lt{'nopr'}.'</small></i></b></center><br /></td></tr>');
1216: }
1217: }
1218:
1219: sub display_versionchanges {
1220: my ($r,$changed,$res_title,$rowColor1,$rowColor2,$interval) = @_;
1221: my %lt = &Apache::lonlocal::texthash(
1222: 'reso' => 'Resource',
1223: 'revd' => 'Last revised',
1224: 'newv' => 'New version',
1225: 'veru' => 'Version used',
1226: 'noup' => 'No updated versions',
1227: );
1228: my $rowColor;
1229: if (keys(%{$changed}) > 0) {
1230: $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>');
1231:
1232:
1233: my @changes = sort { &cmp_title($a,$b,$res_title) } keys(%{$changed});
1234: my $changenum = 0;
1235: foreach my $item (@changes) {
1236: if ($changenum %2 == 1) {
1237: $rowColor = $rowColor1;
1238: } else {
1239: $rowColor = $rowColor2;
1240: }
1241: my ($map,$id,$url)=&Apache::lonnet::decode_symb($item);
1242: my $linkurl=&Apache::lonnet::clutter($url);
1243: $linkurl .= '?symb='.&escape($item);
1244:
1245: $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>');
1246: $changenum ++;
1247: }
1248: } else {
1249: $r->print('<tr><td bgcolor="#ffffff"><br /><center><b><i><small>'.$lt{'noup'}.' '.$interval.'</small></i></b></center><br /></td></tr>');
1250: }
1251: return;
1252: }
1253:
1254: sub display_coursediscussion {
1255: my ($r,$newdiscussions,$unread,$countunread,$res_title,$rowColor1,
1256: $rowColor2) = @_;
1257: my %lt = &Apache::lonlocal::texthash(
1258: 'loca' => 'Location',
1259: 'type' => 'Type',
1260: 'numn' => 'Number of new posts',
1261: 'noun' => 'No unread posts in course discussions',
1262: 'tmlp' => 'Time of last post',
1263: );
1264: my $rowColor;
1265: if (@{$newdiscussions} > 0) {
1266: $r->print('<tr bgcolor="#cccccc"><td><b><small>'.$lt{'loca'}.
1267: '</small></b></td><td><b><small>'.$lt{'type'}.
1268: '</small></b>');
1269: if ($countunread eq 'on') {
1270: $r->print('<td><b><small>'.$lt{'tmlp'}.'</small></b></td>'.
1271: '<td align="right"><b><small>'.$lt{'numn'}.
1272: '</small></b></td>');
1273: } else {
1274: $r->print('<td align="right"><b><small>'.$lt{'tmlp'}.
1275: '</small></b></td>');
1276: }
1277: $r->print("</tr>\n");
1278: @{$newdiscussions} = sort { &cmp_title($a,$b,$res_title) }
1279: @{$newdiscussions};
1280: my $rowNum = 0;
1281: foreach my $ressymb (@{$newdiscussions}) {
1282: my $forum_title = $$unread{$ressymb}{'title'};
1283: my $type = 'Resource';
1284: my $feedurl=&Apache::lonfeedback::get_feedurl($ressymb);
1285: if ($feedurl =~ /bulletinboard/) {
1286: $type = 'Bulletin Board';
1287: }
1288: if ($rowNum %2 == 1) {
1289: $rowColor = $rowColor1;
1290: } else {
1291: $rowColor = $rowColor2;
1292: }
1293: my $lastpost = &Apache::lonnavmaps::timeToHumanString(
1294: $$unread{$ressymb}{'lastpost'});
1295: $r->print('<tr bgcolor="'.$rowColor.'"><td><small><a href="'.$feedurl.'?symb='.$$unread{$ressymb}{symb}.'">'.$forum_title.'</a> </td><td><small>'.$type.' </small></td>');
1296: if ($countunread eq 'on') {
1297: my $unreadnum = $$unread{$ressymb}{'unreadcount'};
1298: $r->print('<td><small>'.$lastpost.'<small></td><td align="right">'.
1299: '<small>',$unreadnum.' </small></td>');
1300: } else {
1301: $r->print('<td align="right"><small>'.$lastpost.'</small></td>');
1302: }
1303: $r->print("</tr>\n");
1304: $rowNum ++;
1305: }
1306: } else {
1307: $r->print('<tr><td bgcolor="#ffffff"><br><center> <i><b><small>'.
1308: $lt{'noun'}.'</small></b></i><br><br></td></tr>');
1309: }
1310: }
1311:
1312: sub display_coursenormalmail {
1313: my ($r,$msgcount,$newmsgs,$rowColor1,$rowColor2) = @_;
1314: my $rowColor;
1315: if ($msgcount > 0) {
1316: $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>');
1317: my $rowNum = 0;
1318: my $mailcount = 1;
1319: foreach my $msg (@{$newmsgs}) {
1320: if ($rowNum %2 == 1) {
1321: $rowColor = $rowColor1;
1322: } else {
1323: $rowColor = $rowColor2;
1324: }
1325: $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>');
1326: $rowNum ++;
1327: $mailcount ++;
1328: }
1329: } else {
1330: $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>');
1331: }
1332: }
1333:
1334: sub display_coursecritmail {
1335: my ($r,$critmsgcount,$critmsgs,$rowColor1,$rowColor2) = @_;
1336: my $rowColor;
1337: if ($critmsgcount > 0) {
1338: $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>');
1339: my $rowNum = 0;
1340: my $mailcount = 1;
1341: foreach my $msg (@{$critmsgs}) {
1342: if ($rowNum %2 == 1) {
1343: $rowColor = $rowColor1;
1344: } else {
1345: $rowColor = $rowColor2;
1346: }
1347: $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>');
1348: $rowNum ++;
1349: $mailcount ++;
1350: }
1351: } else {
1352: $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>');
1353: }
1354: }
1355:
1356: sub cmp_title {
1357: my ($a,$b,$res_title) = @_;
1358: my ($atitle,$btitle) = (lc($$res_title{$a}),lc($$res_title{$b}));
1359: $atitle=~s/^\s*//;
1360: $btitle=~s/^\s*//;
1361: return $atitle cmp $btitle;
1362: }
1363:
1364: sub get_display_settings {
1365: my ($uname,$udom,$cid) = @_;
1366: my %settings = &Apache::lonnet::dump('nohist_whatsnew',$udom,$uname,$cid);
1367: my ($tmp) = keys(%settings);
1368: if ($tmp=~ /^(con_lost|error|no_such_host)/i) {
1369: %settings = ();
1370: unless ($tmp =~ /^error: 2 /) {
1371: &Apache::lonnet::logthis('Error retrieving whatsnew settings: '.
1372: $tmp.' for '.$uname.':'.$udom.' for course: '.$cid);
1373: }
1374: }
1375: return %settings;
1376: }
1377:
1378: sub store_display_settings {
1379: my ($uname,$udom,$cid,$checkallowed) = @_;
1380: my %whatsnew_settings;
1381: my $result;
1382: foreach my $key (keys(%{$checkallowed})) {
1383: if ($key =~ /_section$/) { next; }
1384: if (exists($env{'form.display_'.$key})) {
1385: unless ($env{'form.display_'.$key} eq '') {
1386: $whatsnew_settings{$cid.':'.$key} = $env{'form.display_'.$key};
1387: }
1388: }
1389: }
1390: if (keys(%whatsnew_settings)) {
1391: $result = &Apache::lonnet::put('nohist_whatsnew',\%whatsnew_settings,
1392: $udom,$uname);
1393: } else {
1394: $result = 'ok';
1395: }
1396: return $result;
1397: }
1398:
1399: sub store_interval_setting {
1400: my ($uname,$udom,$cid,$interval_titles) = @_;
1401: my %interval_settings = ();
1402: my $result;
1403: if (defined($env{'form.interval'})) {
1404: $interval_settings{$cid.':interval'} = $env{'form.interval'};
1405: my $outcome = &Apache::lonnet::put('nohist_whatsnew',
1406: \%interval_settings,$udom,$uname);
1407: if ($outcome eq 'ok') {
1408: $result = &mt('Interval set to version changes [_1]',
1409: '<b>'.$$interval_titles{$env{'form.interval'}}.'</b><br />');
1410:
1411: } else {
1412: &Apache::lonnet::logthis('Error storing whatsnew interval setting'.
1413: ' '.$outcome.' for '.$uname.':'.$udom.' in course '.$cid);
1414: $result = &mt('Unable to set interval to [_1] due to [_2].',
1415: '<b>'.$$interval_titles{$env{'form.interval'}}.'</b>',
1416: '<tt>'.$outcome.'</tt>.<br />');
1417: }
1418: }
1419: return $result;
1420: }
1421:
1422: sub store_discussion_setting {
1423: my ($uname,$udom,$cid) = @_;
1424: my %discussion_settings;
1425: my $result;
1426: if (defined($env{'form.countunread'})) {
1427: $discussion_settings{$cid.':countunread'} = $env{'form.countunread'};
1428: my $outcome = &Apache::lonnet::put('nohist_whatsnew',
1429: \%discussion_settings,$udom,$uname);
1430: if ($outcome eq 'ok') {
1431: $result = &mt('Count unread posts in discussions display set to [_1]',
1432: '<b>'.$env{'form.countunread'}.'</b><br />');
1433:
1434: } else {
1435: &Apache::lonnet::logthis('Error storing whatsnew countunread setting'.
1436: ' '.$outcome.' for '.$uname.':'.$udom.' in course '.$cid);
1437: $result = &mt('Unable to set "number unread posts display" to [_1]'.
1438: ' due to [_2].',
1439: '<b>'.$env{'form.countunread'}.'</b>',
1440: '<tt>'.$outcome.'</tt>.<br />');
1441: }
1442: }
1443: return $result;
1444: }
1445:
1446: sub store_courseinit_setting {
1447: my ($uname,$udom,$cid,$initpage) = @_;
1448: my %courseinit_settings;
1449: my $page_control;
1450: my $result;
1451: if (defined($env{'form.courseinit_control'})) {
1452: if ($env{'form.courseinit_control'} eq 'userpref') {
1453: $courseinit_settings{$cid.':courseinit'} = '';
1454: $page_control = 'global preferences';
1455: } else {
1456: if (defined($env{'form.courseinit_page'})) {
1457: $courseinit_settings{$cid.':courseinit'} =
1458: $env{'form.courseinit_page'};
1459: $page_control = 'course specific setting';
1460: }
1461: }
1462: if ($page_control) {
1463: my $outcome = &Apache::lonnet::put('nohist_whatsnew',
1464: \%courseinit_settings,$udom,$uname);
1465: if ($outcome eq 'ok') {
1466: if ($page_control eq 'global preferences') {
1467: $result = &mt('Page displayed after role selection in course now set by [_1]',"<b>user's global preferences</b>.");
1468: } else {
1469: $result = &mt('Page displayed after role selection in this course set to [_1]','<b>'.$$initpage{$env{'form.courseinit_page'}}.'</b>.');
1470: }
1471: } else {
1472: &Apache::lonnet::logthis('Error storing whatsnew courseinit '.
1473: 'setting: '.$outcome.' for '.$uname.
1474: ':'.$udom.' in course '.$cid);
1475: if ($page_control eq 'global preferences') {
1476: $result = &mt('Unable to set control of page display to [_1]'.
1477: ' due to [_2].',
1478: '<b>'.$page_control.'</b>',
1479: '<tt>'.$outcome.'</tt>.<br />');
1480: } else {
1481: $result = &mt('Unable to set page display, after role selection, for this course to [_1] due to [_2].',
1482: '<b>'.$$initpage{$env{'form.courseinit_page'}}.'</b>',
1483: '<tt>'.$outcome.'</tt>.<br />');
1484: }
1485: }
1486: }
1487: }
1488: return $result;
1489: }
1490:
1491: sub start_box {
1492: my ($r,$tabbg,$show,$heading,$caller,$refpage) = @_;
1493: my %lt = &Apache::lonlocal::texthash(
1494: chth => 'Change thresholds?',
1495: chin => 'Change interval?',
1496: chop => 'Change options?',
1497: );
1498: my $showhide;
1499: if ($$show{$caller}) {
1500: $showhide = '<b><a href="javascript:change_display(document.visible.'.
1501: 'display_'.$caller.",'hide'".');">Hide</a></b>';
1502:
1503: } else {
1504: $showhide = '<b><a href="javascript:change_display(document.visible.'.
1505: 'display_'.$caller.",'show'".');">Show</a></b>';
1506: }
1507:
1508: $r->print('
1509: <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
1510: <tr>
1511: <td>
1512: <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
1513: <tr>
1514: <td bgcolor="'.$tabbg.'">
1515: <table width="100%" border="0" cellspacing="0" cellpadding="0">
1516: <tr>
1517: <td><b>'.$$heading{$caller}.'</b></td>
1518: <td valign="top" align="right">'.$showhide.'</td>
1519: </tr>
1520: </table>
1521: </td>
1522: </tr>');
1523: if (($caller eq 'abovethreshold') && ($$show{$caller})) {
1524: if ($$show{$caller}) {
1525: $r->print('
1526: <tr>
1527: <td bgcolor="'.$tabbg.'" align="right"><a href="/adm/whatsnew?command=chgthreshold&refpage='.$refpage.'"><b><small>'.$lt{'chth'}.'</small></b></a></td>
1528: </tr>');
1529: }
1530: } elsif (($caller eq 'versionchanges') && ($$show{$caller})) {
1531: if ($$show{$caller}) {
1532: $r->print('
1533: <tr>
1534: <td bgcolor="'.$tabbg.'" align="right"><a href="/adm/whatsnew?command=chginterval&refpage='.$refpage.'"><b><small>'.$lt{'chin'}.'</small></b></a></td>
1535: </tr>');
1536: }
1537: } elsif ($caller eq 'coursediscussion') {
1538: if ($$show{$caller}) {
1539: $r->print('
1540: <tr>
1541: <td bgcolor="'.$tabbg.'" align="right"><a href="/adm/whatsnew?command=chgdisc&refpage='.$refpage.'"><b><small>'.$lt{'chop'}.'</small></b></a></td>
1542: </tr>');
1543: }
1544: }
1545: $r->print('
1546: <tr>
1547: <td bgcolor="#ffffff">
1548: <table cellpadding="2" cellspacing="0" border="0" width="100%">
1549: ');
1550: return;
1551: }
1552:
1553: sub end_box {
1554: my ($r) = shift;
1555: $r->print('
1556: </table>
1557: </td>
1558: </tr>
1559: </table>
1560: </td>
1561: </tr>
1562: </table><br />');
1563: return;
1564: }
1565:
1566: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>