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