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