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