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