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