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