1: #
2: # $Id: lonwhatsnew.pm,v 1.80 2008/08/26 01:12:16 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::lonuserutils;
40: use Apache::Constants qw(:common :http);
41: use Time::Local;
42: use GDBM_File;
43: use lib '/home/httpd/lib/perl/';
44: use LONCAPA;
45:
46: #----------------------------
47: # handler
48: #
49: #----------------------------
50:
51: sub handler {
52: my $r = shift;
53: if ($r->header_only) {
54: &Apache::loncommon::content_type($r,'text/html');
55: $r->send_http_header;
56: return OK;
57: }
58: &Apache::loncommon::get_unprocessed_cgi(
59: $ENV{'QUERY_STRING'},['command','refpage']);
60:
61: my $command = $env{'form.command'};
62: my $refpage = $env{'form.refpage'};
63:
64: my %checkallowed = ( coursenormalmail => 1,
65: coursecritmail => 1, );
66: foreach my $perm_check (['whn','whatsnew',1],
67: ['pch','coursediscussion',1],
68: ['mgr','handgrading',1],
69: ['vgr','abovethreshold',1],
70: ['opa','haserrors',1],
71: ['mdc','versionchanges',0],
72: ['vcl','newroles',1],
73: ['vcl','oldroles',1],
74: ) {
75: my ($perm,$key,$check_section) = @{ $perm_check };
76: my $scope = $env{'request.course.id'};
77: if (!($checkallowed{$key} = &Apache::lonnet::allowed($perm,$scope))) {
78: $scope .= '/'.$env{'request.course.sec'};
79: if ( $check_section ) {
80: $checkallowed{$key} = &Apache::lonnet::allowed($perm,$scope);
81: }
82: if ($checkallowed{$key}) {
83: $checkallowed{$key.'_section'} = $env{'request.course.sec'};
84: }
85: }
86: }
87:
88: if ( ! $env{'request.course.fn'} || ! $checkallowed{'whatsnew'}) {
89: # Not in a course, or no whn priv in course
90: $env{'user.error.msg'}="/adm/whatsnew::whn:0:0:Cannot display what's new page";
91: return HTTP_NOT_ACCEPTABLE;
92: }
93:
94: &Apache::loncommon::content_type($r,'text/html');
95: $r->send_http_header;
96:
97: $r->print(&display_header($command,\%checkallowed));
98:
99: &Apache::lonhtmlcommon::clear_breadcrumbs();
100: &Apache::lonhtmlcommon::add_breadcrumb
101: ({href=>'/adm/whatsnew',
102: text=>"Display Action Items"});
103: if (($command eq 'chgthreshold') && $checkallowed{'abovethreshold'}) {
104: &Apache::lonhtmlcommon::add_breadcrumb
105: ({href=>'/adm/whatsnew?command=chgthreshold&refpage='.$refpage,
106: text=>"Change thresholds"});
107: $r->print(&Apache::lonhtmlcommon::breadcrumbs
108: ("What's New?",#'Course_Action_Items_Thresholds'
109: ));
110: } elsif (($command eq 'chginterval') && $checkallowed{'versionchanges'} ) {
111: &Apache::lonhtmlcommon::add_breadcrumb
112: ({href=>'/adm/whatsnew?command=chginterval&refpage='.$refpage,
113: text=>"Change interval"});
114: $r->print(&Apache::lonhtmlcommon::breadcrumbs
115: ("What's New?",#'Course_Action_Items_Intervals'
116: ));
117: } elsif (($command eq 'chgdisc') && $checkallowed{'coursediscussion'}) {
118: &Apache::lonhtmlcommon::add_breadcrumb
119: ({href=>'/adm/whatsnew?command=chgdisc&refpage='.$refpage,
120: text=>"Change discussion display"});
121: $r->print(&Apache::lonhtmlcommon::breadcrumbs
122: ("What's New?",#'Course_Action_Items_Intervals'
123: ));
124: } elsif ($command eq 'courseinit') {
125: &Apache::lonhtmlcommon::add_breadcrumb
126: ({href=>'/adm/whatsnew?command=courseinit&refpage='.$refpage,
127: text=>"Course initialization preference"});
128: $r->print(&Apache::lonhtmlcommon::breadcrumbs
129: ("What's New?",#'Course_Action_Items_Initialization'
130: ));
131: } elsif ($command eq 'chgoldroleinterval' && $checkallowed{'oldroles'}) {
132: &Apache::lonhtmlcommon::add_breadcrumb
133: ({href=>'/adm/whatsnew?command=chgoldroleinterval&refpage='.$refpage,
134: text=>"Change interval"});
135: $r->print(&Apache::lonhtmlcommon::breadcrumbs
136: ("What's New?",#'Course_Action_Items_Intervals'
137: ));
138: } elsif ($command eq 'chgnewroleinterval' && $checkallowed{'newroles'}) {
139: &Apache::lonhtmlcommon::add_breadcrumb
140: ({href=>'/adm/whatsnew?command=chgnewroleinterval&refpage='.$refpage,
141: text=>"Change interval"});
142: $r->print(&Apache::lonhtmlcommon::breadcrumbs
143: ("What's New?",#'Course_Action_Items_Intervals'
144: ));
145: } else {
146: $r->print(&Apache::lonhtmlcommon::breadcrumbs
147: ("What's New?",#'Course_Action_Items_Display'
148: ));
149: }
150: &display_main_box($r,$command,$refpage,\%checkallowed);
151: return OK;
152: }
153:
154: #------------------------------
155: # display_main_box
156: #
157: # Display all the elements within the main box
158: #------------------------------
159:
160: sub display_main_box {
161: my ($r,$command,$refpage,$checkallowed) = @_;
162: my $domain=&Apache::loncommon::determinedomain();
163: my $function = &Apache::loncommon::get_users_function();
164: my $lctype = lc(&Apache::loncommon::course_type());
165: $r->print('<table width="100%" border="0" cellpadding="5" cellspacing="0"><tr><td width="100%">');
166:
167: my %threshold_titles = &Apache::lonlocal::texthash (
168: av_attempts => 'Average number of attempts',
169: degdiff => 'Degree of difficulty',
170: numstudents => 'Total number of students with submissions',
171: );
172: my %versions = (
173: -1 => "version changes since start of $lctype",
174: 2592000 => 'version changes since last month',
175: 604800 => 'version changes since last week',
176: 86400 => 'version changes since yesterday',
177: );
178: my %newroles = (
179: -1 => "roles which have become active since start of $lctype",
180: 2592000 => 'roles which have become active since last month',
181: 604800 => 'roles which have become active since last week',
182: 86400 => 'roles which have become active since yesterday',
183: );
184: my %oldroles = (
185: -1 => "roles which expired since start of $lctype",
186: 2592000 => 'roles which expired since last month',
187: 604800 => 'roles which expired since last week',
188: 86400 => 'roles which expired since yesterday',
189: );
190: my %interval_titles = (
191: versions => \%versions,
192: newroles => \%newroles,
193: oldroles => \%oldroles,
194: );
195: my %initpage = &Apache::lonlocal::texthash (
196: firstres => "first resource in the $lctype",
197: whatsnew => "what's new? page",
198: userpref => 'your general user preferences',
199: coursespecific => "specific setting for this $lctype",
200: );
201: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
202: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
203:
204: if (($command eq 'chgthreshold')
205: && $checkallowed->{'abovethreshold'}) {
206: &display_threshold_config($r,$refpage,\%threshold_titles,
207: $cdom,$crs);
208: } elsif (($command eq 'chginterval')
209: && $checkallowed->{'versionchanges'}) {
210: &display_interval_config($r,$refpage,\%interval_titles,'versions');
211: } elsif (($command eq 'chgdisc')
212: && $checkallowed->{'coursediscussion'}) {
213: &display_discussion_config($r,$refpage);
214: } elsif ($command eq 'courseinit') {
215: &courseinit_config($r,$refpage,\%initpage);
216: } elsif (($command eq 'chgnewroleinterval')
217: && $checkallowed->{'newroles'}) {
218: &display_interval_config($r,$refpage,\%interval_titles,'newroles');
219: } elsif (($command eq 'chgoldroleinterval')
220: && $checkallowed->{'oldroles'}) {
221: &display_interval_config($r,$refpage,\%interval_titles,'oldroles');
222: } else {
223: &display_actions_box($r,$command,$refpage,\%threshold_titles,
224: \%interval_titles,\%initpage,$cdom,$crs,$checkallowed);
225: }
226: my $end_page = &Apache::loncommon::end_page();
227: $r->print(<<END_OF_BLOCK);
228: </td>
229: </tr>
230: </table><br />
231: $end_page
232: END_OF_BLOCK
233: }
234:
235: #-------------------------------
236: # display_header
237: #
238: # Display the header information and set
239: # up the HTML
240: #-------------------------------
241:
242: sub display_header {
243: my ($command,$checkallowed) = @_;
244:
245: my $scripttag;
246: unless ($command eq 'chgthreshold' || $command eq 'chginterval' ||
247: $command eq 'chgoldroleinterval' || $command eq 'chgnewroleinterval') {
248: $scripttag = <<"END";
249: <script type="text/javascript">
250: function change_display(caller,change) {
251: caller.value = change;
252: document.visible.submit();
253: }
254:
255: function changeAll(change) {
256: END
257: foreach my $item (keys(%{$checkallowed})) {
258: if ($item =~ /_section$/) { next; }
259: if ($$checkallowed{$item}) {
260: $scripttag.='document.visible.display_'.$item.'.value=change'.
261: "\n";
262: }
263: }
264: $scripttag.='document.visible.submit();
265: }
266: </script>
267: ';
268: }
269: my $course_type=&Apache::loncommon::course_type();
270: return &Apache::loncommon::start_page($course_type.' Action Items',
271: $scripttag);
272: }
273:
274: #-------------------------------
275: # display_actions_box
276: #
277: # Display the action items
278: #
279: #-------------------------------
280:
281: sub display_actions_box {
282: my ($r,$command,$refpage,$threshold_titles,$interval_titles,$initpage,
283: $cdom,$crs,$checkallowed) = @_;
284: my $udom = $env{'user.domain'};
285: my $uname = $env{'user.name'};
286: my $cid = $env{'request.course.id'};
287: my $crstype = &Apache::loncommon::course_type();
288: my $lctype = lc($crstype);
289: my %stulabel = (
290: 'Course' => 'students',
291: 'Group' => 'members',
292: );
293: my %lt = &Apache::lonlocal::texthash(
294: 'yacc' => 'You are accessing an invalid course',
295: 'gtfr' => 'Go to first resource',
296: 'hial' => 'Hide all',
297: 'shal' => 'Show all',
298: );
299:
300: my %unread = ();
301: my %ungraded = ();
302: my %bombed = ();
303: my %triggered = ();
304: my %changed = ();
305: my @newmsgs = ();
306: my @critmsgs = ();
307: my @newdiscussions = ();
308: my @tograde = ();
309: my @bombs = ();
310: my @warnings = ();
311: my $msgcount = 0;
312: my $critmsgcount = 0;
313: my $expirecount;
314: my %expired;
315: my $activecount;
316: my %activated;
317: my %res_title = ();
318: my %show = ();
319: my $needitems = 0;
320: my $boxcount = 0;
321:
322: my $result;
323: if ($command eq 'newcourseinit') {
324: $result = &store_courseinit_setting($uname,$udom,$cid,$initpage);
325: }
326:
327: my %threshold = ();
328: my %pagedesc = &Apache::lonlocal::texthash (
329: firstres => 'First resource',
330: whatsnew => "What's New? page",
331: userpref => 'user preference',
332: coursespecific => $lctype.' only',
333: default => 'default',
334: );
335:
336: my ($initcontrol,$initdisp) = &curr_courseinit();
337: my $currinit = $pagedesc{$initdisp}.' ('.$pagedesc{$initcontrol}.')';
338:
339: unless ($cid) {
340: $r->print('<p><span style="text-align: center; font-weight: bold;">'.$lt{'yacc'}.'</span></p>');
341: return;
342: }
343:
344: if ($refpage eq 'start') {
345: if (tie(my %bighash,'GDBM_File',$env{'request.course.fn'}.'.db',
346: &GDBM_READER(),0640)) {
347: my $furl=$bighash{'first_url'};
348: untie(%bighash);
349: $r->print('<span style="font-size: larger;"><a href="'.$furl.'">'.$lt{'gtfr'}.
350: '</a></span><br />');
351: }
352: }
353: $r->print(&mt('Page set to be displayed after you have selected a role in this '.$lctype).'.'
354: .' <span class="LC_nobreak">'
355: .&mt('Currently: [_1].','<i>'.$currinit.'</i>')
356: .' '
357: .&mt('<b>Change</b> for just [_1]this course[_2]'
358: .' or for all [_3]your courses[_2].'
359: ,'<a href="/adm/whatsnew?command=courseinit&refpage='.$refpage.'">'
360: ,'</a>'
361: ,'<a href="/adm/preferences?action=changecourseinit&refpage='.$refpage.'">')
362: .' </span><br /><hr />');
363:
364: if ($command eq 'reset') {
365: $result = &process_reset($cdom,$crs);
366: } elsif ($command eq 'update') {
367: $result = &process_update($uname,$udom,$threshold_titles);
368: } elsif ($command eq 'newinterval') {
369: $result = &store_interval_setting($uname,$udom,$cid,$interval_titles);
370: } elsif ($command eq 'newdiscconf') {
371: $result = &store_discussion_setting($uname,$udom,$cid);
372: }
373:
374: my $store_result=&store_display_settings($uname,$udom,$cid,$checkallowed);
375:
376: unless ($store_result eq 'ok') {
377: &Apache::lonnet::logthis('Error saving whatsnew settings: '.
378: $store_result.' for '.'user '.$uname.':'.$udom.' in '.$lctype.' '.$cid);
379: $result .= &mt('Unable to save visibility settings due to [_1]',
380: $store_result);
381: }
382:
383: if ($result) {
384: $r->print($result.'<hr width="100%" />');
385: }
386: $r->rflush();
387:
388: my (%timediff,%interval);
389: my %display_settings = &get_display_settings($uname,$udom,$cid);
390: $timediff{'versions'} = $display_settings{$cid.':interval'};
391: unless (defined($timediff{'versions'})) { $timediff{'versions'} = 604800; }
392: $interval{'versions'} = $interval_titles->{'versions'}->{$timediff{'versions'}};
393:
394: my %headings = &Apache::lonlocal::texthash(
395: coursediscussion => 'Unread '.$lctype.' discussion posts',
396: handgrading => 'Problems requiring handgrading',
397: haserrors => 'Problems with errors',
398: coursenormalmail => 'New '.$lctype.' messages',
399: coursecritmail => 'New critical messages in '.$lctype,
400: );
401:
402: if ($timediff{'versions'} == -1) {
403: $headings{'versionchanges'} = &mt('Resources in '.$lctype.' with version changes since start of '.$lctype);
404: } elsif ($timediff{'versions'} == 2592000) {
405: $headings{'versionchanges'} = &mt('Resources in '.$lctype.' with version changes since last month');
406: } elsif ($timediff{'versions'} == 604800) {
407: $headings{'versionchanges'} = &mt('Resources in '.$lctype.' with version changes since last week');
408: } elsif ($timediff{'versions'} == 86400) {
409: $headings{'versionchanges'} = &mt('Resources in '.$lctype.' with version changes since yesterday');
410: }
411:
412: $timediff{'oldroles'} = $display_settings{$cid.':oldroleinterval'};
413: unless (defined($timediff{'oldroles'})) { $timediff{'oldroles'} = 604800; }
414: $interval{'oldroles'} = $interval_titles->{'oldroles'}->{$timediff{'oldroles'}};
415:
416: if ($timediff{'oldroles'} == -1) {
417: $headings{'oldroles'} = &mt('Roles for which access to '.$lctype.' has expired since start of '.$lctype);
418: } elsif ($timediff{'oldroles'} == 2592000) {
419: $headings{'oldroles'} = &mt('Roles for which access to '.$lctype.' has expired since last month');
420: } elsif ($timediff{'oldroles'} == 604800) {
421: $headings{'oldroles'} = &mt('Roles for which access to '.$lctype.' has expired since last week');
422: } elsif ($timediff{'oldroles'} == 86400) {
423: $headings{'oldroles'} = &mt('Roles for which access to '.$lctype.' has expired since yesterday');
424: }
425:
426: $timediff{'newroles'} = $display_settings{$cid.':newroleinterval'};
427: unless (defined($timediff{'newroles'})) { $timediff{'newroles'} = 604800; }
428: $interval{'newroles'} = $interval_titles->{'newroles'}->{$timediff{'newroles'}};
429:
430: if ($timediff{'newroles'} == -1) {
431: $headings{'newroles'} = &mt('Roles for which access to '.$lctype.' has become available since start of '.$lctype);
432: } elsif ($timediff{'newroles'} == 2592000) {
433: $headings{'newroles'} = &mt('Roles for which access to '.$lctype.' has become available since last month');
434: } elsif ($timediff{'newroles'} == 604800) {
435: $headings{'newroles'} = &mt('Roles for which access to '.$lctype.' has become available since last week');
436: } elsif ($timediff{'newroles'} == 86400) {
437: $headings{'newroles'} = &mt('Roles for which access to '.$lctype.' has become available since yesterday');
438: }
439:
440: my $now = time;
441: if ($timediff{'versions'} == -1) {
442: $timediff{'versions'} = time;
443: }
444: my $starttime = $now - $timediff{'versions'};
445:
446: if ($timediff{'newroles'} == -1) {
447: $timediff{'newroles'} = time;
448: }
449: my $activatedstart = $now - $timediff{'newroles'};
450:
451: if ($timediff{'oldroles'} == -1) {
452: $timediff{'oldroles'} = time;
453: }
454: my $expiredstart = $now - $timediff{'oldroles'};
455:
456: my $countunread = $display_settings{$cid.':countunread'};
457: unless (defined($countunread)) {
458: $countunread = 'on';
459: }
460: if ($$checkallowed{'abovethreshold'}) {
461: &get_curr_thresholds(\%threshold,$uname,$udom,$cid,$cdom,$crs);
462: }
463:
464: $headings{'abovethreshold'} =
465: &mt('(Problems with av. attempts ≥ [_1] or deg. difficulty ≥ [_2]) [_3] and total number of '.$stulabel{$crstype}.' with submissions ≥ [_4]',
466: $threshold{'av_attempts'},$threshold{'degdiff'},
467: '<br />',$threshold{'numstudents'});
468:
469: my @actionorder = ('handgrading','haserrors','abovethreshold','versionchanges','coursediscussion','coursenormalmail','coursecritmail','newroles','oldroles');
470:
471: foreach my $key (keys(%{$checkallowed})) {
472: if ($key =~ /_section$/) { next; }
473: $show{$key} = 0;
474: if ($$checkallowed{$key}) {
475: unless ($display_settings{$cid.':'.$key} eq 'hide') {
476: $show{$key} = 1;
477: }
478: }
479: }
480:
481: foreach my $item (@actionorder) {
482: unless ($item eq 'coursenormalmail' || $item eq 'coursecritmail' ||
483: $item eq 'newroles' || $item eq 'oldroles') {
484: if ($show{$item}) {
485: $needitems = 1;
486: last;
487: }
488: }
489: }
490:
491: if ($needitems) {
492: &getitems(\%unread,\%ungraded,\%bombed,\%triggered,\%changed,\@newdiscussions,\@tograde,\@bombs,\@warnings,\%threshold,$cdom,$crs,\%res_title,\%show,$starttime,$countunread);
493: }
494: if ($show{'coursenormalmail'}) {
495: $msgcount = &getnormalmail(\@newmsgs);
496: }
497: if ($show{'coursecritmail'}) {
498: $critmsgcount = &getcritmail(\@critmsgs);
499: }
500: if ($show{'oldroles'}) {
501: $expirecount = &getexpired(\%expired,$expiredstart,'previous');
502: }
503: if ($show{'newroles'}) {
504: $activecount = &getactivated(\%activated,$activatedstart,'active');
505: }
506: $r->print(qq|<a href="javascript:changeAll('hide');">$lt{'hial'}</a>
507: <a href="javascript:changeAll('show');">$lt{'shal'}</a>
508: <form method="post" name="visible" action="/adm/whatsnew">\n|);
509: foreach my $item (keys(%{$checkallowed})) {
510: if ($item =~ /_section$/) { next; }
511: if ($$checkallowed{$item}) {
512: $r->print('<input type="hidden" name="display_'.$item.'" />'."\n");
513: }
514: }
515:
516: $r->print('<input type="hidden" name="refpage" value="'.$refpage.'" /></form><table class="LC_double_column"><tr><td class="LC_left_col">');
517:
518: my $displayed = 0;
519: my $totalboxes = 0;
520: foreach my $key (keys(%{$checkallowed})) {
521: if ($key =~ /_section$/) { next; }
522: if ($key eq 'whatsnew' ) { next; } # whatsnew check creates no box
523: if ($$checkallowed{$key}) {
524: $totalboxes ++;
525: }
526: }
527: my $halfway = 4;
528: # my $halfway = int($totalboxes/2) + $totalboxes%2;
529: foreach my $actionitem (@actionorder) {
530: if ($$checkallowed{$actionitem}) {
531: if ($displayed == $halfway) {
532: $r->print('</td><td> </td><td class="LC_right_col" >');
533: }
534: &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,\%expired,$expirecount,\%activated,$activecount,$crstype);
535: $displayed ++;
536: }
537: }
538: $r->print('
539: </td>
540: </tr>
541: </table>
542: ');
543: }
544:
545: #-------------------------------
546: # display_threshold_config
547: #
548: # Display the threshold setting screen
549: #
550: #-------------------------------
551:
552: sub display_threshold_config {
553: my ($r,$refpage,$threshold_titles,$cdom,$crs) = @_;
554: my $uname = $env{'user.name'};
555: my $udom = $env{'user.dom'};
556: my $cid = $env{'request.course.id'};
557: my %threshold = ();
558: my $rowColor1 = "#ffffff";
559: my $rowColor2 = "#eeeeee";
560: my $rowColor;
561:
562: my @thresholditems = ("av_attempts","degdiff","numstudents");
563: my %threshold_titles = &Apache::lonlocal::texthash(
564: av_attempts => 'Average number of attempts',
565: degdiff => 'Degree of difficulty',
566: numstudents => 'Total number of students with submissions',
567: );
568: &get_curr_thresholds(\%threshold,$uname,$udom,$cid,$cdom,$crs);
569:
570: $r->print('<br /><form name="thresholdform" method="post" action="/adm/whatsnew">'.
571: &Apache::loncommon::start_data_table().
572: &Apache::loncommon::start_data_table_header_row().
573: '<th>'.&mt('Threshold Name').'</th>'."\n".
574: '<th>'.&mt('Current value').'</th>'."\n".
575: '<th>'.&mt('Change?').'</th>'."\n".
576: &Apache::loncommon::end_data_table_header_row());
577: foreach my $type (@thresholditems) {
578: my $parameter = $env{'request.course.id'}.':threshold_'.$type;
579: # onchange is javascript to automatically check the 'Set' button.
580: my $onchange = 'onFocus="javascript:window.document.forms'.
581: "['thresholdform'].elements['".$parameter."_setparmval']".
582: '.checked=true;"';
583: $r->print(&Apache::loncommon::start_data_table_row()."\n".
584: '<td>'.$threshold_titles{$type}.'</td>'."\n".
585: '<td>'.&Apache::lonhtmlcommon::textbox($parameter.'_value',
586: $threshold{$type},
587: 10,$onchange).'</td>'."\n".
588: '<td>'.
589: &Apache::lonhtmlcommon::checkbox($parameter.'_setparmval').
590: '</td>'."\n".
591: &Apache::loncommon::end_data_table_row());
592: }
593: $r->print(&Apache::loncommon::end_data_table()."\n".
594: '<br /><input type="submit" name="threshold" value="'.&mt('Make changes').'" />
595: <input type="hidden" name="command" value="update" />
596: <input type="hidden" name="refpage" value="'.$refpage.'" />
597: </form>');
598: }
599:
600: #-------------------------------
601: # display_interval_config
602: #
603: # Display the interval setting screen
604: #
605: #-------------------------------
606:
607: sub display_interval_config {
608: my ($r,$refpage,$interval_titles,$context) = @_;
609: my $setting = 'interval';
610: if ($context eq 'oldroles') {
611: $setting = 'oldroleinterval';
612: } elsif ($context eq 'newroles') {
613: $setting = 'newroleinterval';
614: }
615: my $lctype = lc(&Apache::loncommon::course_type());
616: my $current = &get_current($env{'user.name'},$env{'user.domain'},
617: $env{'request.course.id'},$setting);
618: if ($context eq 'oldroles') {
619: $r->print('<br />'.&mt('Choose the time window to use to display roles for which access to the '.$lctype.' expired.').'<br />');
620: } elsif ($context eq 'newroles') {
621: $r->print('<br />'.&mt('Choose the time window to use to display roles for which access to the '.$lctype.' became available.').'<br />');
622: } else {
623: $r->print('<br />'.&mt('Choose the time window to use to display resources in the '.$lctype.' with version changes.').'<br />');
624: }
625: unless ($current eq '') {
626: if (ref($interval_titles->{$context}) eq 'HASH') {
627: $r->print(' '.&mt('Current value is "[_1]".','<b>'.
628: $interval_titles->{$context}->{$current}.'</b>').'<br />');
629: }
630: }
631: $r->print('<br />
632: <form method="post" name="intervalswitch" action="/adm/whatsnew">
633: <input type="hidden" name="command" value="newinterval" />
634: <input type="hidden" name="intervaltype" value="'.$context.'" />
635: <input type="hidden" name="refpage" value="'.$refpage.'" />'.
636: &mt('Display:').'
637: <select name="interval">
638: <option value="" selected="selected">'.&mt('Select').'</option>
639: ');
640: if (ref($interval_titles) eq 'HASH') {
641: if (ref($interval_titles->{$context}) eq 'HASH') {
642: foreach my $key (reverse sort ({$a cmp $b} (keys(%{$interval_titles->{$context}})))) {
643: $r->print('<option value="'.$key.'">'.&mt($interval_titles->{$context}->{$key}).
644: '</option>'."\n");
645: }
646: }
647: }
648: $r->print('</select>
649: <input type="submit" name="display" value="'.
650: &mt('Change interval').'" /></form>');
651: return;
652: }
653:
654: #----------------------------------------------
655: # display_discussion_config
656: #
657: # Display the discussion display setting screen
658: #
659: #----------------------------------------------
660:
661: sub display_discussion_config {
662: my ($r,$refpage) = @_;
663: my $current = &get_current($env{'user.name'},$env{'user.domain'},
664: $env{'request.course.id'},'countunread');
665: if ($current eq '') {
666: $current = 'on';
667: }
668: my %opposite = (
669: 'on' => 'off',
670: 'off' => 'on',
671: );
672: $r->print('<script type="text/javascript">
673: function toggle_countunread(choice) {
674: if (choice == "unchanged") {
675: document.discussionswitch.command.value = "";
676: }
677: document.discussionswitch.submit();
678: }
679: </script>');
680: $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>."));
681: $r->print('<br /><br />
682: <form method="post" name="discussionswitch" action="/adm/whatsnew">
683: <input type="hidden" name="command" value="newdiscconf" />
684: <input type="hidden" name="refpage" value="'.$refpage.'" />
685: <input type="hidden" name="countunread" value="'.$opposite{$current}.'" />
686: ');
687: $r->print('<br/>
688: <input type="button" name="display" value="'.
689: &mt('Change to [_1]',&mt($opposite{$current})).'"
690: onclick="javascript:toggle_countunread('."'change'".')" />
691:  
692: <input type="button" name="nochange" value="'.
693: &mt("No change").'"
694: onclick="javascript:toggle_countunread('."'unchanged'".')" />
695: </form>');
696: return;
697: }
698:
699: #---------------------------------------------------
700: # courseinit_config
701: #
702: # Set page displayed when course loads after
703: # selecting a role in the course from the roles page.
704: #
705: #---------------------------------------------------
706:
707: sub courseinit_config {
708: my ($r,$refpage,$initpage) = @_;
709: my ($control,$current) = &curr_courseinit();
710: my @chgstate = ('userpref','coursespecific');
711: my @chgentry = ('firstres','whatsnew');
712: my $lctype = lc(&Apache::loncommon::course_type());
713: my %lt = &Apache::lonlocal::texthash(
714: 'chwp' => "Choose which page will be displayed when you enter this $lctype after selecting a role.",
715: 'cuva' => 'Current value is determined by',
716: 'anis' => 'and is set to display',
717: 'padc' => 'Page display controlled by',
718: 'chce' => 'Choose '.$lctype.' entry',
719: 'moce' => 'Modify '.$lctype.' entry',
720: );
721: $r->print(<<"END");
722: <br />$lt{'chwp'}
723: <br />$lt{'cuva'}: <b>
724: $$initpage{$control}</b> $lt{'anis'} <b>
725: $$initpage{$current}</b>.<br /><br />
726: <form method="post" name="courseinitswitch" action="/adm/whatsnew">
727: <input type="hidden" name="command" value="newcourseinit" />
728: <input type="hidden" name="refpage" value="$refpage" />
729: $lt{'padc'}:
730: END
731: foreach my $choice (@chgstate) {
732: my $chkstring;
733: if ($choice eq $control) {
734: $chkstring = ' checked="checked" ';
735: }
736: $r->print('<span class="LC_nobreak"><label><input type="radio" name="courseinit_control" value="'.
737: $choice.'"'.$chkstring.'/>'.$$initpage{$choice}.
738: ' </label></span>');
739: }
740: $r->print('<br /><br />'.&mt('If').' '.$$initpage{'coursespecific'}.
741: ' - <br />'.$lt{'chce'}.": \n");
742: foreach my $choice (@chgentry) {
743: my $chkstring;
744: if (($choice eq $current) && ($control eq 'coursespecific')) {
745: $chkstring = ' checked="checked" ';
746: }
747: $r->print('<span class="LC_nobreak"><label><input type="radio" name="courseinit_page" value="'.
748: $choice.'"'.$chkstring.'/>'.$$initpage{$choice}.
749: ' </label></span>');
750: }
751: $r->print('<br /><br /><input type="submit" name="display" value="'.
752: $lt{'moce'}.'" /></form>');
753: return;
754: }
755:
756: sub curr_courseinit {
757: my $current = &get_current($env{'user.name'},$env{'user.domain'},
758: $env{'request.course.id'},'courseinit');
759: my $control;
760: if ($current) {
761: $control = 'coursespecific';
762: } else {
763: $control = 'userpref';
764: my %userenv = &Apache::lonnet::get('environment',
765: ['course_init_display']);
766: if (exists($userenv{'course_init_display'})) {
767: $current = $userenv{'course_init_display'};
768: }
769: unless ($current) {
770: $current = 'whatsnew';
771: }
772: }
773: return ($control,$current);
774: }
775:
776: sub display_launcher {
777: my ($r,$action,$refpage,$checkallowed,$show,$headings,$res_title,
778: $tograde,$ungraded,$bombs,$bombed,$changed,$warnings,$triggered,
779: $newdiscussions,$unread,$msgcount,$newmsgs,$critmsgcount,$critmsgs,
780: $interval,$countunread,$expired,$expirecount,$activated,$activecount,
781: $crstype) = @_;
782:
783: if ($$checkallowed{$action}) {
784: &start_box($r,$show,$headings,$action,$refpage,$action);
785: if ($$show{$action}) {
786: if ($action eq 'handgrading') { # UNGRADED ITEMS
787: &display_handgrade($r,$tograde,$ungraded);
788: } elsif ($action eq 'haserrors') { # BOMBS
789: &display_haserrors($r,$bombs,$bombed,$res_title);
790: } elsif ($action eq 'versionchanges') { # VERSION CHANGES
791: &display_versionchanges($r,$changed,$res_title,$interval->{'versions'});
792: } elsif ($action eq 'abovethreshold') { # DEGDIFF/AV. TRIES TRIGGERS
793: &display_abovethreshold($r,$refpage,$warnings,$triggered,
794: $res_title);
795: } elsif ($action eq 'coursediscussion') { # UNREAD COURSE DISCUSSION
796: &display_coursediscussion($r,$newdiscussions,$unread,
797: $countunread,$res_title);
798: } elsif ($action eq 'coursenormalmail') { # NORMAL MESSAGES
799: &display_coursenormalmail($r,$msgcount,$newmsgs);
800: } elsif ($action eq 'coursecritmail') { # CRITICAL MESSAGES
801: &display_coursecritmail($r,$critmsgcount,$critmsgs);
802: } elsif ($action eq 'newroles') { # ACTIVATED ROLES
803: &display_rolechanges($r,$activecount,$activated,$interval->{'newroles'},
804: $crstype);
805: } elsif ($action eq 'oldroles') { # EXPIRED ROLES
806: &display_rolechanges($r,$expirecount,$expired,$interval->{'oldroles'},
807: $crstype);
808: }
809: }
810: &end_box($r);
811: }
812: return;
813: }
814:
815: sub getitems {
816: my ($unread,$ungraded,$bombed,$triggered,$changed,$newdiscussions,
817: $tograde,$bombs,$warnings,$threshold,$cdom,$crs,$res_title,$show,
818: $starttime,$countunread) = @_;
819: my $navmap = Apache::lonnavmaps::navmap->new();
820: # force retrieve Resource to seed the part id cache we'll need it later
821: my @allres=$navmap->retrieveResources(undef,
822: sub {if ($_[0]->is_problem) { $_[0]->parts();} return 1;});
823: my %resourcetracker;
824: my $discussiontime;
825:
826: # Resource version changes
827: if ($$show{'versionchanges'}) {
828: &checkversions($cdom,$crs,$navmap,$changed,$starttime);
829: }
830:
831: if ($$show{'abovethreshold'}) {
832: %resourcetracker = &Apache::lonnet::dump('nohist_resourcetracker',
833: $cdom,$crs);
834: }
835:
836: foreach my $resource (@allres) {
837: my $result = '';
838: my $applies = 0;
839: my $symb = $resource->symb();
840: %{$$bombed{$symb}} = ();
841: %{$$ungraded{$symb}} = ();
842: %{$$triggered{$symb}} = ();
843: $$triggered{$symb}{numparts} = 0;
844: if ($resource->encrypted()) {
845: $$triggered{$symb}{'enclink'} = $resource->link();
846: $$triggered{$symb}{'encsymb'} = $resource->shown_symb();
847: }
848: my $title = $resource->compTitle();
849: $$res_title{$symb} = $title;
850: my $ressymb = $resource->wrap_symb();
851:
852: # Check if there are unread discussion postings
853: if ($$show{'coursediscussion'}) {
854: &check_discussions($resource,$symb,$ressymb,$title,
855: $newdiscussions,$unread,$countunread);
856: }
857:
858: # Check for ungraded problems
859: if ($resource->is_problem()) {
860: if ($$show{'handgrading'}) {
861: &check_handgraded($resource,$symb,$title,$cdom,$crs,$ungraded,
862: $tograde);
863: }
864: }
865:
866: # Check for bombs
867: if ($$show{'haserrors'}) {
868: &check_bombed($resource,$symb,$title,$bombs,$bombed);
869: }
870:
871: # Maxtries and degree of difficulty for problem parts, unless handgradeable
872: if ($$show{'abovethreshold'}) {
873: &check_thresholds($resource,$symb,\%resourcetracker,
874: $triggered,$threshold,$warnings);
875: }
876:
877: }
878: }
879:
880: sub check_discussions {
881: my ($resource,$symb,$ressymb,$title,$newdiscussions,$unread,
882: $countunread) = @_;
883:
884: if (!$resource->hasDiscussion()) { return; }
885:
886: %{$$unread{$ressymb}} = ();
887: $$unread{$ressymb}{'title'} = $title;
888: $$unread{$ressymb}{'symb'} = $symb;
889: if ($resource->encrypted()) {
890: $$unread{$ressymb}{'enclink'} = $resource->link();
891: $$unread{$ressymb}{'encsymb'} = $resource->shown_symb();
892: }
893: push(@{$newdiscussions}, $ressymb);
894:
895: $$unread{$ressymb}{'lastpost'} = $resource->last_post_time();
896:
897: if ($countunread eq 'on') {
898: $$unread{$ressymb}{'unreadcount'} =
899: $resource->discussion_info('unread');
900: }
901: }
902:
903: sub check_handgraded {
904: my ($resource,$symb,$title,$cdom,$cnum,$ungraded,$tograde) = @_;
905: if ($resource->is_problem()) {
906: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
907: my $partlist=$resource->parts();
908: my $handgradeable;
909: foreach my $part (@$partlist) {
910: if ($resource->handgrade($part) eq 'yes') {
911: $handgradeable=1; last;
912: }
913: }
914: if ($handgradeable) {
915: my @ungraded = &Apache::bridgetask::get_queue_symb_status(
916: 'gradingqueue',$symb,$cdom,$cnum);
917: if (@ungraded > 0) {
918: $$ungraded{$symb}{count} = scalar(@ungraded);
919: $$ungraded{$symb}{title} = $title;
920: if ($resource->encrypted()) {
921: $$ungraded{$symb}{'enclink'} = $resource->link();
922: $$ungraded{$symb}{'encsymb'} = $resource->shown_symb();
923: }
924: push(@{$tograde},$symb);
925: }
926: }
927: }
928: }
929:
930: sub check_bombed {
931: my ($resource,$symb,$title,$bombs,$bombed) = @_;
932: if ($resource->getErrors()) {
933: my $errors = $resource->getErrors();
934: $errors =~ s/^,//;
935: my @bombs = split(/,/, $errors);
936: my $errorcount = scalar(@bombs);
937: my $errorlink = '<a href="/adm/email?display='.
938: &escape($bombs[0]).'">'.
939: $title.'</a>';
940: $$bombed{$symb}{errorcount} = $errorcount;
941: $$bombed{$symb}{errorlink} = $errorlink;
942: push(@{$bombs}, $symb);
943: }
944: }
945:
946: sub check_thresholds {
947: my ($resource,$symb,$resourcetracker,$triggered,$threshold,$warnings) = @_;
948: # Compile maxtries and degree of difficulty for problem parts, unless handgradeable
949: my @parts = @{$resource->parts()};
950: my %stats;
951: my %lastreset = ();
952: my $warning = 0;
953: foreach my $part (@parts) {
954: if ($resource->handgrade($part) eq 'yes') {
955: next;
956: }
957: if ($resource->is_survey($part)) {
958: next;
959: }
960: %{$stats{$part}} = ();
961: my ($attempts,$users,$corrects,$degdiff,$av_attempts);
962: if (exists($$resourcetracker{$symb."\0".$part."\0attempts"})) {
963: $attempts = $$resourcetracker{$symb."\0".$part."\0attempts"};
964: }
965: if (exists($$resourcetracker{$symb."\0".$part."\0users"})) {
966: $users = $$resourcetracker{$symb."\0".$part."\0users"};
967: }
968: if (exists($$resourcetracker{$symb."\0".$part."\0correct"})) {
969: $corrects = $$resourcetracker{$symb."\0".$part."\0correct"};
970: }
971: if ($attempts > 0) {
972: $degdiff = 1 - ($corrects/$attempts);
973: $degdiff = sprintf("%.2f",$degdiff);
974: }
975: if ($users > 0) {
976: $av_attempts = $attempts/$users;
977: $av_attempts = sprintf("%.2f",$av_attempts);
978: }
979: if ((($degdiff ne '' && $degdiff >= $$threshold{'degdiff'}) || ($av_attempts ne '' && $av_attempts >= $$threshold{'av_attempts'})) && ($users >= $$threshold{'numstudents'})) {
980: $stats{$part}{degdiff} = $degdiff;
981: $stats{$part}{attempts} = $av_attempts;
982: $stats{$part}{users} = $users;
983: $lastreset{$part} = $$resourcetracker{$symb."\0".$part."\0resettime"};
984: if ($lastreset{$part}) {
985: $lastreset{$part} = &Apache::lonnavmaps::timeToHumanString($lastreset{$part});
986: }
987: $warning = 1;
988: }
989: }
990: if ($warning) {
991: $$triggered{$symb}{title} = $resource->title;
992: my $partcount = 0;
993: @{$$triggered{$symb}{text}} = ();
994: foreach my $part (@parts) {
995: if (exists($stats{$part}{users})) {
996: my $resetname = 'reset_'.&escape($symb."\0".$part);
997: my $resettitle = 'title_'.&escape($symb."\0".$part);
998: if (@parts > 1) {
999: $$triggered{$symb}{text}[$partcount] = '
1000: <td>'.&mt('part - ').$part.'</td>';
1001: } else {
1002: $$triggered{$symb}{text}[$partcount] = '
1003: <td>'.&mt('single part').'</td>';
1004: }
1005: $$triggered{$symb}{text}[$partcount] .= '
1006: <td>'.$stats{$part}{users}.'</td>
1007: <td>'.$stats{$part}{attempts}.'</td>
1008: <td>'.$stats{$part}{degdiff}.'</td>
1009: <td>'.$lastreset{$part}.'</td>
1010: <td><input type="checkbox" name="'.$resetname.'" /><input type="hidden" name="'.$resettitle.'" value="'.&escape($$triggered{$symb}{title}).'" /></td>';
1011: $partcount ++;
1012: }
1013: $$triggered{$symb}{numparts} = $partcount;
1014: }
1015: push(@{$warnings},$symb);
1016: }
1017: }
1018:
1019:
1020: sub get_curr_thresholds {
1021: my ($threshold,$uname,$udom,$cid,$cdom,$crs) = @_;
1022: # set default values
1023: %$threshold = (av_attempts => 2,
1024: degdiff => 0.5,
1025: numstudents => 2
1026: );
1027: my %thresholdsettings = &Apache::lonnet::dump('nohist_whatsnew',$udom,
1028: $uname,$cid.':threshold');
1029: my $thresholdcount = 0;
1030: my ($tmp) = %thresholdsettings;
1031: unless ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1032: foreach my $item (keys %{$threshold}) {
1033: if (exists($thresholdsettings{$cid.':threshold_'.$item})) {
1034: $$threshold{$item} =
1035: $thresholdsettings{$cid.':threshold_'.$item};
1036: $thresholdcount ++;
1037: }
1038: }
1039: }
1040: if ($thresholdcount == 3) {
1041: return;
1042: }
1043: my %coursesettings = &Apache::lonnet::dump('environment',
1044: $cdom,$crs,'internal.threshold');
1045: my ($temp) = %coursesettings;
1046: unless ($temp =~ /^(con_lost|error|no_such_host)/i) {
1047: foreach my $item (keys %{$threshold}) {
1048: unless (exists($thresholdsettings{$cid.':threshold_'.$item})) {
1049: if (exists($coursesettings{'internal.threshold_'.$item})) {
1050: $$threshold{$item} =
1051: $coursesettings{'internal.threshold_'.$item};
1052: }
1053: }
1054: }
1055: }
1056: return;
1057: }
1058:
1059: sub get_current {
1060: my ($uname,$udom,$cid,$caller) = @_;
1061: my $currvalue;
1062: my %settings = &Apache::lonnet::dump('nohist_whatsnew',$udom,$uname,$cid.
1063: ':'.$caller);
1064: my ($tmp) = %settings;
1065: unless ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1066: $currvalue = $settings{$cid.':'.$caller};
1067: }
1068: return $currvalue;
1069: }
1070:
1071: sub process_reset {
1072: my ($dom,$crs) = @_;
1073: my $result = '<b>'.&mt('Counters reset for following problems (and parts):').
1074: '</b><br />';
1075: my @agg_types = ('attempts','users','correct');
1076: my %agg_titles = &Apache::lonlocal::texthash (
1077: attempts => 'Number of submissions',
1078: users => 'Students with submissions',
1079: correct => 'Number of correct submissions',
1080: );
1081: my @resets = ();
1082: my %titles = ();
1083: foreach my $key (keys(%env)) {
1084: next if ($key !~ /^form\.reset_(.+)$/);
1085: my $title = &unescape($env{'form.title_'.$1});
1086: my $reset_item = &unescape($1);
1087: my %curr_aggregates = &Apache::lonnet::dump('nohist_resourcetracker',$dom,$crs,$reset_item);
1088: my %aggregates = ();
1089: my ($symb,$part) = split(/\0/,$reset_item);
1090: foreach my $type (@agg_types) {
1091: $aggregates{$reset_item."\0".$type} = 0;
1092: }
1093: $aggregates{$reset_item."\0".'resettime'} = time;
1094: my $putresult = &Apache::lonnet::put('nohist_resourcetracker',\%aggregates,
1095: $dom,$crs);
1096: if ($putresult eq 'ok') {
1097: $result .= $title.' -part '.$part.': ';
1098: my %new_aggregates = &Apache::lonnet::dump('nohist_resourcetracker',$dom,$crs,$reset_item);
1099: foreach my $type (@agg_types) {
1100: $result .= $agg_titles{$type}.' = '.$new_aggregates{$reset_item."\0".$type}.'; ';
1101: }
1102: $result =~ s/; $//;
1103: $result .= '<br />';
1104: } else {
1105: $result = $title.' -part '.$part.': '.&mt('Unable to reset counters to zero due to [_1]',$putresult).'.<br />'."\n";
1106: }
1107: }
1108: return $result;
1109: }
1110:
1111: sub process_update {
1112: my ($uname,$udom,$threshold_titles) = @_;
1113: my $setoutput = '<b>'.&mt('Changes to threshold(s) for problem tracking:').'</b><br />';
1114: foreach (keys %env) {
1115: next if ($_!~/^form\.(.+)\_setparmval$/);
1116: my $name = $1;
1117: my $value = $env{'form.'.$name.'_value'};
1118: if ($name && defined($value) && ($value ne '')) {
1119: my $put_result = &Apache::lonnet::put('nohist_whatsnew',
1120: {$name=>$value},$udom,$uname);
1121:
1122: my ($shortname) = ($name =~ /^\Q$env{'request.course.id'}\E:threshold_(.+)$/);
1123: if ($put_result eq 'ok') {
1124: $setoutput.=&mt('Set threshold for [_1] to [_2]',
1125: '<b>'.$$threshold_titles{$shortname}.'</b>',
1126: '<b>'.$value.'</b>').'<br />';
1127: } else {
1128: $setoutput.=&mt('Unable to set threshold for [_1] to [_2] due to [_3].',
1129: '<b>'.$name.'</b>','<b>'.$value.'</b>',
1130: '<tt>'.$put_result.'</tt>').'<br />';
1131: }
1132: }
1133: }
1134: return $setoutput;
1135: }
1136:
1137: sub getnormalmail {
1138: my ($newmsgs) = @_;
1139: # Check for unread mail in course
1140: my $msgcount = 0;
1141:
1142: my @messages = sort(&Apache::lonnet::getkeys('nohist_email'));
1143: foreach my $message (@messages) {
1144: my $msgid=&escape($message);
1145: my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
1146: &Apache::lonmsg::unpackmsgid($msgid);
1147: if (($fromcid) && ($fromcid eq $env{'request.course.id'})) {
1148: if (defined($sendtime) && $sendtime!~/error/) {
1149: my $numsendtime = $sendtime;
1150: $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
1151: if ($status eq 'new') {
1152: $msgcount ++;
1153: if ($shortsubj eq '') {
1154: $shortsubj = &mt('No subject');
1155: }
1156: push(@{$newmsgs}, {
1157: msgid => $msgid,
1158: sendtime => $sendtime,
1159: shortsub => $shortsubj,
1160: from => $fromname,
1161: fromdom => $fromdom
1162: });
1163: }
1164: }
1165: }
1166: }
1167: return $msgcount;
1168: }
1169:
1170: sub getcritmail {
1171: my ($critmsgs) = @_;
1172: # Check for critical messages in course
1173: my %what=&Apache::lonnet::dump('critical');
1174: my $result = '';
1175: my $critmsgcount = 0;
1176: foreach my $msgid (sort(keys(%what))) {
1177: my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
1178: &Apache::lonmsg::unpackmsgid($msgid);
1179: if (($fromcid) && ($fromcid eq $env{'request.course.id'})) {
1180: if (defined($sendtime) && $sendtime!~/error/) {
1181: my $numsendtime = $sendtime;
1182: $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
1183: $critmsgcount ++;
1184: if ($shortsubj eq '') {
1185: $shortsubj = &mt('No subject');
1186: }
1187: push(@{$critmsgs}, {
1188: msgid => $msgid,
1189: sendtime => $sendtime,
1190: shortsub => $shortsubj,
1191: from => $fromname,
1192: fromdom => $fromdom
1193: });
1194: }
1195: }
1196: }
1197: return $critmsgcount;
1198: }
1199:
1200: sub getexpired {
1201: my ($rolechgs,$rolechgtime,$status) = @_;
1202: my $expirecount = &getrolechanges($rolechgs,$rolechgtime,$status);
1203: return $expirecount;
1204: }
1205:
1206: sub getactivated {
1207: my ($rolechgs,$rolechgtime,$status) = @_;
1208: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1209: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1210: my $now = time();
1211: my $context = 'course';
1212: my ($permission,$allowed) =
1213: &Apache::lonuserutils::get_permission($context);
1214: my $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1215: my %changes=&Apache::lonnet::dump('nohist_rolelog',$cdom,$cnum);
1216: my (%stucounted,%advcounted);
1217: my $activatedcount = 0;
1218: if (keys(%changes) > 0) {
1219: foreach my $chg (sort { $b <=> $a } (keys(%changes))) {
1220: if (ref($changes{$chg}) eq 'HASH') {
1221: my $timestamp = $changes{$chg}{'exe_time'};
1222: if ($timestamp) {
1223: if ($rolechgtime > 0) {
1224: if ($timestamp < $rolechgtime) {
1225: last;
1226: }
1227: }
1228: if (ref($changes{$chg}{'logentry'}) eq 'HASH') {
1229: next if ($changes{$chg}{'delflag'});
1230: my $start = $changes{$chg}{'logentry'}{'start'};
1231: my $end = $changes{$chg}{'logentry'}{'end'};
1232: my $section = $changes{$chg}{'logentry'}{'section'};
1233: my $role = $changes{$chg}{'logentry'}{'role'};
1234: my $uname = $changes{$chg}{'uname'};
1235: my $udom = $changes{$chg}{'udom'};
1236: next if ($end && $end <= $now);
1237: if (($viewablesec ne '') && ($section ne '')) {
1238: next if ($viewablesec ne $section);
1239: }
1240: next if ($start >= $timestamp);
1241: if ($role eq 'st') {
1242: $stucounted{$uname.':'.$udom.':'.$section} = $start.':'.$end;
1243: } else {
1244: $advcounted{$uname.':'.$udom.':'.$role.':'.$section} = $start.':'.$end;
1245: }
1246: my %chginfo = (
1247: 'section' => $section,
1248: 'uname' => $uname,
1249: 'udom' => $udom,
1250: 'role' => $role,
1251: 'status' => $status,
1252: );
1253: $activatedcount ++;
1254: push (@{$rolechgs->{$timestamp}},\%chginfo);
1255: }
1256: }
1257: }
1258: }
1259: }
1260: $activatedcount += &getrolechanges($rolechgs,$rolechgtime,$status,\%stucounted,\%advcounted);
1261: return $activatedcount;
1262: }
1263:
1264: sub getrolechanges {
1265: my ($rolechgs,$rolechgtime,$status,$stucountref,$advcountref) = @_;
1266: my (%stucounted,%advcounted);
1267: if (ref($stucountref) eq 'HASH') {
1268: %stucounted = %{$stucountref};
1269: }
1270: if (ref($advcountref) eq 'HASH') {
1271: %advcounted = %{$advcountref};
1272: }
1273: my $withsec = 1;
1274: my $hidepriv = 1;
1275: my $context = 'course';
1276: my @statuses = ($status);
1277: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1278: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1279: my $now = time();
1280: my ($permission,$allowed) =
1281: &Apache::lonuserutils::get_permission($context);
1282: my $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1283: my $classlist = &Apache::loncoursedata::get_classlist();
1284: my $secidx = &Apache::loncoursedata::CL_SECTION();
1285: my $startidx = &Apache::loncoursedata::CL_START();
1286: my $endidx = &Apache::loncoursedata::CL_END();
1287: my $rolechgcount = 0;
1288: foreach my $key (keys(%{$classlist})) {
1289: my ($userstatus,$eventtime);
1290: my $student = $classlist->{$key};
1291: if (ref($student) eq 'ARRAY') {
1292: my $start = $student->[$startidx];
1293: my $end = $student->[$endidx];
1294: my $sec = $student->[$secidx];
1295: my ($stuname,$studom) = split(/:/,$key);
1296: if ($status eq 'active') {
1297: if (exists($stucounted{$key.':'.$sec})) {
1298: next;
1299: }
1300: }
1301: if (($end == 0) || ($end > $start)) {
1302: if ($start <= $now) {
1303: if ($end && $end < $now) {
1304: if ($rolechgtime > 0) {
1305: if ($end > $rolechgtime) {
1306: $userstatus = 'previous';
1307: }
1308: } else {
1309: $userstatus = 'previous';
1310: }
1311: } else {
1312: if ($rolechgtime > 0) {
1313: if ($start >= $rolechgtime) {
1314: $userstatus = 'active';
1315: }
1316: } else {
1317: $userstatus = 'active';
1318: }
1319: }
1320: }
1321: }
1322: next if ($userstatus ne $status);
1323: if ($status eq 'active') {
1324: $eventtime = $start;
1325: } else {
1326: $eventtime = $end;
1327: }
1328: if (($viewablesec ne '') && ($sec ne '')) {
1329: next if ($viewablesec ne $sec);
1330: }
1331: my %chginfo = (
1332: 'section' => $sec,
1333: 'uname' => $stuname,
1334: 'udom' => $studom,
1335: 'role' => 'st',
1336: 'status' => $userstatus,
1337: );
1338: $rolechgcount ++;
1339: push (@{$rolechgs->{$eventtime}},\%chginfo);
1340: }
1341: }
1342: my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
1343: \@statuses,undef,undef,$withsec,$hidepriv);
1344: foreach my $item (keys(%advrolehash)) {
1345: my ($userstatus,$eventtime);
1346: my ($uname,$udom,$role,$section) = split(/:/,$item,-1);
1347: my ($start,$end) = split(/:/,$advrolehash{$item});
1348: if ($start eq '-1' && $end eq '-1') {
1349: next;
1350: } else {
1351: if ($status eq 'active') {
1352: if (exists($advcounted{$item})) {
1353: next;
1354: }
1355: }
1356: if (($end == 0) || ($end > $start)) {
1357: if ($start <= $now) {
1358: if ($end && $end < $now) {
1359: if ($rolechgtime > 0) {
1360: if ($end > $rolechgtime) {
1361: $userstatus = 'previous';
1362: }
1363: } else {
1364: $userstatus = 'previous';
1365: }
1366: } else {
1367: if ($rolechgtime > 0) {
1368: if ($start >= $rolechgtime) {
1369: $userstatus = 'active';
1370: }
1371: } else {
1372: $userstatus = 'active';
1373: }
1374: }
1375: }
1376: }
1377: next if ($userstatus ne $status);
1378: if ($status eq 'active') {
1379: $eventtime = $start;
1380: } else {
1381: $eventtime = $end;
1382: }
1383: }
1384: if (($viewablesec ne '') && ($section ne '')) {
1385: next if ($viewablesec ne $section);
1386: }
1387: my %chginfo = (
1388: 'section' => $section,
1389: 'uname' => $uname,
1390: 'udom' => $udom,
1391: 'role' => $role,
1392: 'status' => $userstatus,
1393: );
1394: $rolechgcount ++;
1395: push (@{$rolechgs->{$eventtime}},\%chginfo);
1396: }
1397: return $rolechgcount;
1398: }
1399:
1400: sub checkversions {
1401: my ($cdom,$crs,$navmap,$changed,$starttime) = @_;
1402: my %changes=&Apache::lonnet::dump('versionupdate',$cdom,$crs);
1403: my ($tmp) = keys(%changes);
1404: unless ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1405: if (keys(%changes) > 0) {
1406: foreach my $key (sort(keys(%changes))) {
1407: if ($changes{$key} > $starttime) {
1408: my $version;
1409: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
1410: my $currentversion=&Apache::lonnet::getversion($key);
1411: my $revdate =
1412: &Apache::lonnet::metadata($root.'.'.$extension,
1413: 'lastrevisiondate');
1414: $revdate = &Apache::lonlocal::locallocaltime($revdate);
1415: my $linkurl=&Apache::lonnet::clutter($key);
1416: my $usedversion=$navmap->usedVersion('version_'.$linkurl);
1417: my @resources = $navmap->getResourceByUrl($linkurl,1);
1418: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1419: $version = $usedversion;
1420: } else {
1421: $version = $currentversion;
1422: }
1423: foreach my $res (@resources) {
1424: if (ref($res) eq 'Apache::lonnavmaps::resource') {
1425: my $symb = $res->symb();
1426: %{$$changed{$symb}} = (
1427: current => $currentversion,
1428: version => $version,
1429: revdate => $revdate,
1430: );
1431: }
1432: }
1433: }
1434: }
1435: }
1436: }
1437: return;
1438: }
1439:
1440: sub display_handgrade {
1441: my ($r,$tograde,$ungraded) = @_;
1442: my %lt = &Apache::lonlocal::texthash(
1443: 'prna' => 'Problem Name',
1444: 'nmun' => 'Number ungraded',
1445: 'nopr' => 'No problems require handgrading',
1446: );
1447: if (@{$tograde} > 0) {
1448: $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
1449: $lt{'prna'}.'</td><td class="LC_right_item">'.
1450: $lt{'nmun'}.'</td></tr>');
1451: my $rowNum = 0;
1452: foreach my $res (@{$tograde}) {
1453: $rowNum ++;
1454: my $css_class = $rowNum%2?' class="LC_odd_row"':'';
1455: my ($map,$id,$url)=&Apache::lonnet::decode_symb($res);
1456: my $linkurl=&Apache::lonnet::clutter($url);
1457: $linkurl .= '?symb='.&escape($res);
1458: if ($$ungraded{$res}{'enclink'}) {
1459: $linkurl =
1460: $$ungraded{$res}{'enclink'}.'?symb='.$$ungraded{$res}{'encsymb'};
1461: }
1462: $r->print('<tr'.$css_class.'><td><a href="'.$linkurl.'">'.$$ungraded{$res}{title}.'</a></td><td class="LC_right_item">'.$$ungraded{$res}{count}.'</td></tr>');
1463: }
1464: } else {
1465: $r->print('<tr class="LC_empty_row"><td>'.$lt{'nopr'}.'</td></tr>');
1466: }
1467: }
1468:
1469: sub display_haserrors {
1470: my ($r,$bombs,$bombed,$res_title) = @_;
1471: my $bombnum = 0;
1472: my %lt = &Apache::lonlocal::texthash(
1473: reso => 'Resource',
1474: nmer => 'Number of errors',
1475: noer => 'No problems with errors',
1476: );
1477: if (@{$bombs} > 0) {
1478: $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
1479: $lt{'reso'}.'</td><td class="LC_right_item">'.
1480: $lt{'nmer'}.'</td></tr>');
1481: @{$bombs} = sort { &cmp_title($a,$b,$res_title) } @{$bombs};
1482: foreach my $bomb (@{$bombs}) {
1483: $bombnum ++;
1484: my $css_class = $bombnum%2?' class="LC_odd_row"':'';
1485: $r->print('<tr'.$css_class.'><td>'.$$bombed{$bomb}{errorlink}.
1486: '</td><td class="LC_right_item">'.
1487: $$bombed{$bomb}{errorcount}.'</td></tr>');
1488: }
1489: } else {
1490: $r->print('<tr class="LC_empty_row"><td>'.$lt{'noer'}.'</td></tr>');
1491: }
1492: return;
1493: }
1494:
1495: sub display_abovethreshold {
1496: my ($r,$refpage,$warnings,$triggered,$res_title) = @_;
1497: my %lt = &Apache::lonlocal::texthash(
1498: reso => 'Resource',
1499: part => 'Part',
1500: nust => 'Num. students',
1501: avat => 'Av. Attempts',
1502: dedi => 'Deg. Diff',
1503: lare => 'Last Reset',
1504: reco => 'Reset Count?',
1505: rese => 'Reset counters to 0',
1506: nopr => 'No problems satisfy threshold criteria',
1507: );
1508: if (@{$warnings} > 0) {
1509: @{$warnings} = sort { &cmp_title($a,$b,$res_title) } @{$warnings};
1510: $r->print('<form name="reset_tracking" method="post" action="/adm/whatsnew">'.
1511: ' <input type="hidden" name="command" value="reset" />'."\n".
1512: ' <input type="hidden" name="refpage" value="'.$refpage.'" />'.
1513: "\n");
1514: $r->print('<tr class="LC_info_row">'.
1515: '<td class="LC_left_item">'.$lt{'reso'}.'</td>'.
1516: '<td>'.$lt{'part'}.'</td><td>'.$lt{'nust'}.'</td>'.
1517: '<td>'.$lt{'avat'}.'</td><td>'.$lt{'dedi'}.'</td>'.
1518: '<td>'.$lt{'lare'}.'</td><td class="LC_right_item">'.
1519: $lt{'reco'}.'</td></tr>');
1520: my $row;
1521: foreach my $res (@{$warnings}) {
1522: $row++;
1523: my ($map,$id,$url)=&Apache::lonnet::decode_symb($res);
1524: my $linkurl=&Apache::lonnet::clutter($url);
1525: my $rowspan;
1526: if ($$triggered{$res}{numparts} > 1) {
1527: $rowspan = 'rowspan="'.$$triggered{$res}{numparts}.'"';
1528: }
1529: $linkurl .= '?symb='.&escape($res);
1530: if ($$triggered{$res}{'enclink'}) {
1531: $linkurl =
1532: $$triggered{$res}{'enclink'}.'?symb='.$$triggered{$res}{'encsymb'};
1533: }
1534: my $css_class = $row%2?' class="LC_odd_row"':'';
1535: $r->print('<tr'.$css_class.'>'.
1536: '<td class="LC_first_item" '.$rowspan.'><a href="'.$linkurl.'">'.
1537: $$triggered{$res}{title}.'</a></td>');
1538: if (ref($$triggered{$res}{text}) eq 'ARRAY') {
1539: $r->print($$triggered{$res}{text}[0]);
1540: }
1541: $r->print('</tr>');
1542: if (ref($$triggered{$res}{text}) eq 'ARRAY') {
1543: if (@{$$triggered{$res}{text}} > 1) {
1544: for (my $i=1; $i<@{$$triggered{$res}{text}}; $i++) {
1545: $r->print('<tr class="'.$css_class.'">'.
1546: $$triggered{$res}{text}[$i].'</tr>');
1547: }
1548: }
1549: }
1550: }
1551: $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>');
1552: } else {
1553: $r->print('<tr class="LC_empty_row"><td>'.$lt{'nopr'}.'</td></tr>');
1554: }
1555: }
1556:
1557: sub display_versionchanges {
1558: my ($r,$changed,$res_title,$interval) = @_;
1559: my %lt = &Apache::lonlocal::texthash(
1560: 'reso' => 'Resource',
1561: 'revd' => 'Last revised',
1562: 'newv' => 'New version',
1563: 'veru' => 'Version used',
1564: );
1565: if (keys(%{$changed}) > 0) {
1566: $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
1567: $lt{'reso'}.'</td><td>'.$lt{'revd'}.'</td><td>'.
1568: $lt{'newv'}.'</td><td class="LC_right_item">'.
1569: $lt{'veru'}.'</td></tr>');
1570: my @changes = sort { &cmp_title($a,$b,$res_title) } keys(%{$changed});
1571: my $changenum = 0;
1572: foreach my $item (@changes) {
1573: $changenum ++;
1574: my $css_class = $changenum%2?' class="LC_odd_row"':'';
1575: my ($map,$id,$url)=&Apache::lonnet::decode_symb($item);
1576: my $linkurl=&Apache::lonnet::clutter($url);
1577: $linkurl .= '?symb='.&escape($item);
1578:
1579: $r->print('<tr'.$css_class.'><td><a href="'.$linkurl.'">'.
1580: $$res_title{$item}.'</a></td><td>'.
1581: $$changed{$item}{'revdate'}.'</td><td>'.
1582: $$changed{$item}{'current'}.'</td><td>'.
1583: $$changed{$item}{'version'}.'</td></tr>');
1584: }
1585: } else {
1586: $r->print('<tr class="LC_empty_row"><td>'
1587: .&mt('No '.$interval).'</td></tr>');
1588: }
1589: return;
1590: }
1591:
1592: sub display_rolechanges {
1593: my ($r,$chgcount,$changed,$interval,$crstype) = @_;
1594: my $now = time();
1595: my %lt = &Apache::lonlocal::texthash(
1596: 'user' => 'User',
1597: 'tich' => 'Time of change',
1598: 'role' => 'Role',
1599: 'sec' => 'Section',
1600: 'status' => 'Status',
1601: );
1602: if ($chgcount) {
1603: $r->print('<tr class="LC_info_row">'.
1604: '<td class="LC_left_item">'.$lt{'tich'}.'</td>'.
1605: '<td class="LC_left_item">'.$lt{'user'}.'</td>'.
1606: '<td class="LC_left_item">'.$lt{'role'}.'</td>'.
1607: '<td class="LC_left_item">'.$lt{'sec'}.'</td>'.
1608: '<td class="LC_left_item">'.$lt{'status'}.'</td></tr>');
1609: if (ref($changed) eq 'HASH') {
1610: my @changes = sort { $b <=> $a } (keys(%{$changed}));
1611: my $changenum = 0;
1612: foreach my $item (@changes) {
1613: if (ref($changed->{$item}) eq 'ARRAY') {
1614: foreach my $chg (@{$changed->{$item}}) {
1615: if (ref($chg) eq 'HASH') {
1616: my $section;
1617: my $role =
1618: &Apache::lonnet::plaintext($chg->{'role'},$crstype);
1619: my $status = &mt($chg->{'status'});
1620: if ($chg->{'section'} eq '') {
1621: $section = &mt('none');
1622: } else {
1623: $section = $chg->{'section'};
1624: }
1625: my $uname = $chg->{'uname'};
1626: my $udom = $chg->{'udom'};
1627: $changenum ++;
1628: my $css_class = $changenum%2?' class="LC_odd_row"':'';
1629: my $link =
1630: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom);
1631: $r->print('<tr'.$css_class.'>'.
1632: '<td>'.&Apache::lonlocal::locallocaltime($item).'</td>'.
1633: '<td>'.$link.'</td>'.
1634: '<td>'.$role.'</td>'.
1635: '<td>'.$section.'</td>'.
1636: '<td>'.$status.'</td></tr>');
1637: }
1638: }
1639: }
1640: }
1641: }
1642: } else {
1643: $r->print('<tr class="LC_empty_row"><td>'
1644: .&mt('There are no '.$interval).'</td></tr>');
1645: }
1646: return;
1647: }
1648:
1649: sub display_coursediscussion {
1650: my ($r,$newdiscussions,$unread,$countunread,$res_title) = @_;
1651: my $lctype = lc(&Apache::loncommon::course_type());
1652: my %lt = &Apache::lonlocal::texthash(
1653: 'loca' => 'Location',
1654: 'type' => 'Type',
1655: 'numn' => 'Number of new posts',
1656: 'noun' => 'No unread posts in '.$lctype.' discussions',
1657: 'tmlp' => 'Time of last post',
1658: );
1659: if (@{$newdiscussions} > 0) {
1660: $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
1661: $lt{'loca'}.'</td><td>'.
1662: $lt{'type'}.'</td>');
1663: if ($countunread eq 'on') {
1664: $r->print('<td>'.$lt{'tmlp'}.'</td>'.
1665: '<td class="LC_right_item">'.$lt{'numn'}.'</td>');
1666: } else {
1667: $r->print('<td class="LC_right_item">'.$lt{'tmlp'}.'</td>');
1668: }
1669: $r->print("</tr>\n");
1670: @{$newdiscussions} = sort { &cmp_title($a,$b,$res_title) }
1671: @{$newdiscussions};
1672: my $rowNum = 0;
1673: foreach my $ressymb (@{$newdiscussions}) {
1674: $rowNum ++;
1675: my $forum_title = $$unread{$ressymb}{'title'};
1676: my $type = 'Resource';
1677: my $feedurl=&Apache::lonfeedback::get_feedurl($ressymb);
1678: my $disclink = $feedurl.'?symb='.$$unread{$ressymb}{symb};
1679: if ($feedurl =~ /bulletinboard/) {
1680: $type = 'Bulletin Board';
1681: }
1682: if ($$unread{$ressymb}{'enclink'}) {
1683: $disclink = $$unread{$ressymb}{'enclink'}.'?symb='.$$unread{$ressymb}{'encsymb'};
1684: }
1685: my $css_class = $rowNum%2?' class="LC_odd_row"':'';
1686: my $lastpost = &Apache::lonnavmaps::timeToHumanString(
1687: $$unread{$ressymb}{'lastpost'});
1688: $r->print('<tr'.$css_class.'><td><a href="'.$disclink.'">'.$forum_title.'</a> </td><td>'.&mt($type).' </td>');
1689: if ($countunread eq 'on') {
1690: my $unreadnum = $$unread{$ressymb}{'unreadcount'};
1691: $r->print('<td>'.$lastpost.'</td><td class="LC_right_item">'.
1692: $unreadnum.' </td>');
1693: } else {
1694: $r->print('<td class="LC_right_item">'.$lastpost.'</td>');
1695: }
1696: $r->print("</tr>\n");
1697: }
1698: } else {
1699: $r->print('<tr class="LC_empty_row"><td>'.$lt{'noun'}.'</td></tr>');
1700: }
1701: }
1702:
1703: sub display_coursenormalmail {
1704: my ($r,$msgcount,$newmsgs) = @_;
1705: my $lctype = lc(&Apache::loncommon::course_type());
1706: if ($msgcount > 0) {
1707: $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
1708: &mt('Number').'</td><td>'.&mt('Subject').'</td><td>'.
1709: &mt('Sender').'</td><td class="LC_right_item">'.
1710: &mt('Date/Time').'</td></tr>');
1711: my $mailcount = 0;
1712: foreach my $msg (@{$newmsgs}) {
1713: $mailcount ++;
1714: my $css_class = $mailcount%2?' class="LC_odd_row"':'';
1715: $r->print('<tr'.$css_class.'><td>'.$mailcount
1716: .'. </td><td><a href="/adm/email?display='
1717: .$msg->{'msgid'}.'">'
1718: .$msg->{'shortsub'}.'</a> </td><td> '
1719: .$msg->{'from'}.':'.$msg->{'fromdom'}.' </td><td>'
1720: .$msg->{'sendtime'}.'</td></tr>');
1721: }
1722: } else {
1723: $r->print('<tr class="LC_empty_row"><td>'.
1724: &mt('No new '.$lctype.' messages').'</td></tr>');
1725: }
1726: }
1727:
1728: sub display_coursecritmail {
1729: my ($r,$critmsgcount,$critmsgs) = @_;
1730: my $lctype = lc(&Apache::loncommon::course_type());
1731: if ($critmsgcount > 0) {
1732: $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
1733: &mt('Number').'</td><td>'.&mt('Subject').'</td><td>'.
1734: &mt('Sender').'</td><td class="LC_right_item">'.
1735: &mt('Date/Time').'</td></tr>');
1736: my $mailcount = 0;
1737: foreach my $msg (@{$critmsgs}) {
1738: $mailcount ++;
1739: my $css_class = $mailcount%2?' class="LC_odd_row"':'';
1740: $r->print('<tr'.$css_class.'><td>'.$mailcount.
1741: '. </td><td><a href="/adm/email?folder=critical">'.
1742: $msg->{'shortsub'}.'</a> </td><td> '.
1743: $msg->{'from'}.':'.$msg->{'fromdom'}.' </td><td>'.
1744: $msg->{'sendtime'}.'</td></tr>');
1745: }
1746: } else {
1747: $r->print('<tr class="LC_empty_row"><td>'.
1748: &mt('No unread critical messages in '.$lctype).
1749: '</td></tr>');
1750: }
1751: }
1752:
1753: sub cmp_title {
1754: my ($a,$b,$res_title) = @_;
1755: my ($atitle,$btitle) = (lc($$res_title{$a}),lc($$res_title{$b}));
1756: $atitle=~s/^\s*//;
1757: $btitle=~s/^\s*//;
1758: return $atitle cmp $btitle;
1759: }
1760:
1761: sub get_display_settings {
1762: my ($uname,$udom,$cid) = @_;
1763: my %settings = &Apache::lonnet::dump('nohist_whatsnew',$udom,$uname,$cid);
1764: my ($tmp) = keys(%settings);
1765: if ($tmp=~ /^(con_lost|error|no_such_host)/i) {
1766: %settings = ();
1767: unless ($tmp =~ /^error: 2 /) {
1768: my $lctype = lc(&Apache::loncommon::course_type());
1769: &Apache::lonnet::logthis('Error retrieving whatsnew settings: '.
1770: $tmp.' for '.$uname.':'.$udom.' for '.$lctype.': '.$cid);
1771: }
1772: }
1773: return %settings;
1774: }
1775:
1776: sub store_display_settings {
1777: my ($uname,$udom,$cid,$checkallowed) = @_;
1778: my %whatsnew_settings;
1779: my $result;
1780: foreach my $key (keys(%{$checkallowed})) {
1781: if ($key =~ /_section$/) { next; }
1782: if (exists($env{'form.display_'.$key})) {
1783: unless ($env{'form.display_'.$key} eq '') {
1784: $whatsnew_settings{$cid.':'.$key} = $env{'form.display_'.$key};
1785: }
1786: }
1787: }
1788: if (keys(%whatsnew_settings)) {
1789: $result = &Apache::lonnet::put('nohist_whatsnew',\%whatsnew_settings,
1790: $udom,$uname);
1791: } else {
1792: $result = 'ok';
1793: }
1794: return $result;
1795: }
1796:
1797: sub store_interval_setting {
1798: my ($uname,$udom,$cid,$interval_titles) = @_;
1799: my %interval_settings = ();
1800: my $result;
1801: my $context = $env{'form.intervaltype'};
1802: if ($env{'form.interval'} ne '') {
1803: if ($context eq 'oldroles') {
1804: $interval_settings{$cid.':oldroleinterval'} = $env{'form.interval'};
1805: } elsif ($context eq 'newroles') {
1806: $interval_settings{$cid.':newroleinterval'} = $env{'form.interval'};
1807: } else {
1808: $interval_settings{$cid.':interval'} = $env{'form.interval'};
1809: }
1810: my $outcome = &Apache::lonnet::put('nohist_whatsnew',
1811: \%interval_settings,$udom,$uname);
1812: if ($outcome eq 'ok') {
1813: if (ref($interval_titles->{$context}) eq 'HASH') {
1814: $result = &mt('New filter setting: [_1].','<b>'.
1815: $interval_titles->{$context}->{$env{'form.interval'}}.'</b>').'<br />';
1816: }
1817: } else {
1818: my $lctype = lc(&Apache::loncommon::course_type());
1819: &Apache::lonnet::logthis('Error saving whatsnew '.$context.' interval setting'.
1820: ' '.$outcome.' for '.$uname.':'.$udom.' in '.$lctype.' '.$cid);
1821: $result = &mt('Unable to set interval to [_1] due to [_2].',
1822: '<b>'.$interval_titles->{$context}->{$env{'form.interval'}}.'</b>',
1823: '<tt>'.$outcome.'</tt>.<br />');
1824: }
1825: }
1826: return $result;
1827: }
1828:
1829: sub store_discussion_setting {
1830: my ($uname,$udom,$cid) = @_;
1831: my %discussion_settings;
1832: my $result;
1833: if (defined($env{'form.countunread'})) {
1834: $discussion_settings{$cid.':countunread'} = $env{'form.countunread'};
1835: my $outcome = &Apache::lonnet::put('nohist_whatsnew',
1836: \%discussion_settings,$udom,$uname);
1837: if ($outcome eq 'ok') {
1838: $result = &mt('Count unread posts in discussions display set to [_1]',
1839: '<b>'.&mt($env{'form.countunread'}).'</b>').'<br />';
1840:
1841: } else {
1842: my $lctype = lc(&Apache::loncommon::course_type());
1843: &Apache::lonnet::logthis('Error saving whatsnew countunread setting'.
1844: ' '.$outcome.' for '.$uname.':'.$udom.' in '.$lctype.' '.$cid);
1845: $result = &mt('Unable to set "number unread posts display" to [_1]'.
1846: ' due to [_2].',
1847: '<b>'.&mt($env{'form.countunread'}).'</b>',
1848: '<tt>'.$outcome.'</tt>.<br />');
1849: }
1850: }
1851: return $result;
1852: }
1853:
1854: sub store_courseinit_setting {
1855: my ($uname,$udom,$cid,$initpage) = @_;
1856: my %courseinit_settings;
1857: my $page_control;
1858: my $result;
1859: if (defined($env{'form.courseinit_control'})) {
1860: if ($env{'form.courseinit_control'} eq 'userpref') {
1861: $courseinit_settings{$cid.':courseinit'} = '';
1862: $page_control = 'global preferences';
1863: } else {
1864: if (defined($env{'form.courseinit_page'})) {
1865: $courseinit_settings{$cid.':courseinit'} =
1866: $env{'form.courseinit_page'};
1867: $page_control = 'course specific setting';
1868: }
1869: }
1870: if ($page_control) {
1871: my $lctype = lc(&Apache::loncommon::course_type());
1872: my $outcome = &Apache::lonnet::put('nohist_whatsnew',
1873: \%courseinit_settings,$udom,$uname);
1874: if ($outcome eq 'ok') {
1875: if ($page_control eq 'global preferences') {
1876: $result = &mt("Page displayed after role selection in $lctype now set by <b>user's global preferences</b>.");
1877: } else {
1878: $result = &mt('Page displayed after role selection in this '.$lctype.' set to <b>[_2]</b>',$lctype,$$initpage{$env{'form.courseinit_page'}});
1879: }
1880: } else {
1881: &Apache::lonnet::logthis('Error saving whatsnew courseinit '.
1882: 'setting: '.$outcome.' for '.$uname.
1883: ':'.$udom.' in '.$lctype.' '.$cid);
1884: if ($page_control eq 'global preferences') {
1885: $result = &mt('Unable to set control of page display to [_1]'.
1886: ' due to [_2].',
1887: '<b>'.$page_control.'</b>',
1888: '<tt>'.$outcome.'</tt>.<br />');
1889: } else {
1890: $result = &mt('Unable to set page display, after role selection, for this '.$lctype.' to <b>[_2]</b> due to <tt>[_3]</tt>.<br />',
1891: $$initpage{$env{'form.courseinit_page'}},$outcome);
1892: }
1893: }
1894: }
1895: }
1896: return $result;
1897: }
1898:
1899: sub start_box {
1900: my ($r,$show,$heading,$caller,$refpage) = @_;
1901: my %lt = &Apache::lonlocal::texthash(
1902: chth => 'Change thresholds?',
1903: chin => 'Change interval?',
1904: chop => 'Change options?',
1905: );
1906: my $showhide;
1907: if ($$show{$caller}) {
1908: $showhide = '<b><a href="javascript:change_display(document.visible.'.
1909: 'display_'.$caller.",'hide'".');">'.
1910: &mt('Hide').'</a></b>';
1911:
1912: } else {
1913: $showhide = '<b><a href="javascript:change_display(document.visible.'.
1914: 'display_'.$caller.",'show'".');">'.
1915: &mt('Show').'</a></b>';
1916: }
1917:
1918: $r->print('
1919: <table class="LC_nested_outer">
1920: <tr>
1921: <th class="LC_left_item">'.$$heading{$caller}.'</th>
1922: <th class="LC_right_item">'.$showhide.'</th>
1923: </tr>');
1924: if (($caller eq 'abovethreshold') && ($$show{$caller})) {
1925: if ($$show{$caller}) {
1926: $r->print('
1927: <tr>
1928: <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgthreshold&refpage='.$refpage.'">'.$lt{'chth'}.'</a></td>
1929: </tr>');
1930: }
1931: } elsif (($caller eq 'versionchanges') && ($$show{$caller})) {
1932: if ($$show{$caller}) {
1933: $r->print('
1934: <tr>
1935: <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chginterval&refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
1936: </tr>');
1937: }
1938: } elsif ($caller eq 'coursediscussion') {
1939: if ($$show{$caller}) {
1940: $r->print('
1941: <tr>
1942: <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgdisc&refpage='.$refpage.'">'.$lt{'chop'}.'</a></td>
1943: </tr>');
1944: }
1945: } elsif (($caller eq 'newroles') && ($$show{$caller})) {
1946: if ($$show{$caller}) {
1947: $r->print('
1948: <tr>
1949: <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgnewroleinterval&refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
1950: </tr>');
1951: }
1952: } elsif (($caller eq 'oldroles') && ($$show{$caller})) {
1953: if ($$show{$caller}) {
1954: $r->print('
1955: <tr>
1956: <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgoldroleinterval&refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
1957: </tr>');
1958: }
1959: }
1960: $r->print('
1961: <tr>
1962: <td colspan="2">
1963: <table class="LC_nested">
1964: ');
1965: return;
1966: }
1967:
1968: sub end_box {
1969: my ($r) = shift;
1970: $r->print('
1971: </table>
1972: </td>
1973: </tr>
1974: </table><br />');
1975: return;
1976: }
1977:
1978: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>