Annotation of loncom/interface/lonwhatsnew.pm, revision 1.123
1.2 albertel 1: #
1.123 ! raeburn 2: # $Id: lonwhatsnew.pm,v 1.122 2016/11/08 23:55:48 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: }
1328: my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
1329: &Apache::lonmsg::unpackmsgid($msgid,undef,$skipstatus,undef,
1330: $env{'request.course.id'});
1331: if (($fromcid) && ($fromcid eq $env{'request.course.id'})) {
1332: if (defined($sendtime) && $sendtime!~/error/) {
1333: if (($emailstatus{$msgid} eq 'new') || ($status eq 'new')) {
1334: $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
1335: $msgcount ++;
1336: if ($shortsubj eq '') {
1337: $shortsubj = &mt('No subject');
1338: }
1339: push(@{$newmsgs}, {
1340: msgid => $msgid,
1341: sendtime => $sendtime,
1342: shortsub => $shortsubj,
1343: from => $fromname,
1344: fromdom => $fromdom
1345: });
1.10 raeburn 1346: }
1.1 raeburn 1347: }
1348: }
1349: }
1350: }
1.33 raeburn 1351: return $msgcount;
1352: }
1.1 raeburn 1353:
1.33 raeburn 1354: sub getcritmail {
1355: my ($critmsgs) = @_;
1.118 raeburn 1356: # Check for critical messages which were sent in context of current course.
1.1 raeburn 1357: my %what=&Apache::lonnet::dump('critical');
1358: my $result = '';
1359: my $critmsgcount = 0;
1.3 albertel 1360: foreach my $msgid (sort(keys(%what))) {
1.10 raeburn 1361: my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
1.118 raeburn 1362: &Apache::lonmsg::unpackmsgid($msgid,undef,1,undef,
1363: $env{'request.course.id'});
1.10 raeburn 1364: if (($fromcid) && ($fromcid eq $env{'request.course.id'})) {
1.1 raeburn 1365: if (defined($sendtime) && $sendtime!~/error/) {
1.93 droeschl 1366: $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
1.1 raeburn 1367: $critmsgcount ++;
1.10 raeburn 1368: if ($shortsubj eq '') {
1369: $shortsubj = &mt('No subject');
1370: }
1.1 raeburn 1371: push(@{$critmsgs}, {
1372: msgid => $msgid,
1373: sendtime => $sendtime,
1.10 raeburn 1374: shortsub => $shortsubj,
1.1 raeburn 1375: from => $fromname,
1376: fromdom => $fromdom
1377: });
1378: }
1379: }
1380: }
1.33 raeburn 1381: return $critmsgcount;
1382: }
1383:
1.77 raeburn 1384: sub getexpired {
1.114 raeburn 1385: my ($rolechgs,$rolechgtime,$status,$classlist) = @_;
1386: my $expirecount = &getrolechanges($rolechgs,$rolechgtime,$status,$classlist);
1.77 raeburn 1387: return $expirecount;
1388: }
1389:
1390: sub getactivated {
1.114 raeburn 1391: my ($rolechgs,$rolechgtime,$status,$classlist) = @_;
1.77 raeburn 1392: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1393: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1394: my $now = time();
1395: my $context = 'course';
1396: my ($permission,$allowed) =
1397: &Apache::lonuserutils::get_permission($context);
1398: my $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1399: my %changes=&Apache::lonnet::dump('nohist_rolelog',$cdom,$cnum);
1400: my (%stucounted,%advcounted);
1401: my $activatedcount = 0;
1402: if (keys(%changes) > 0) {
1.111 raeburn 1403: foreach my $chg (keys(%changes)) {
1.77 raeburn 1404: if (ref($changes{$chg}) eq 'HASH') {
1.112 raeburn 1405: next if ($changes{$chg}{'delflag'});
1.111 raeburn 1406: if ($rolechgtime > 0) {
1.112 raeburn 1407: next if ($changes{$chg}{'exe_time'} < $rolechgtime);
1.111 raeburn 1408: }
1409: if ($changes{$chg}{'exe_time'}) {
1410: my $timestamp = $changes{$chg}{'exe_time'};
1.77 raeburn 1411: if (ref($changes{$chg}{'logentry'}) eq 'HASH') {
1.112 raeburn 1412: my $end = $changes{$chg}{'logentry'}{'end'};
1413: next if ($end && $end <= $now);
1.77 raeburn 1414: my $start = $changes{$chg}{'logentry'}{'start'};
1.112 raeburn 1415: next if ($start >= $timestamp);
1.77 raeburn 1416: my $section = $changes{$chg}{'logentry'}{'section'};
1.112 raeburn 1417: if (($viewablesec ne '') && ($section ne '')) {
1418: next if ($viewablesec ne $section);
1419: }
1.77 raeburn 1420: my $role = $changes{$chg}{'logentry'}{'role'};
1421: my $uname = $changes{$chg}{'uname'};
1422: my $udom = $changes{$chg}{'udom'};
1423: if ($role eq 'st') {
1424: $stucounted{$uname.':'.$udom.':'.$section} = $start.':'.$end;
1425: } else {
1426: $advcounted{$uname.':'.$udom.':'.$role.':'.$section} = $start.':'.$end;
1427: }
1428: my %chginfo = (
1429: 'section' => $section,
1430: 'uname' => $uname,
1431: 'udom' => $udom,
1432: 'role' => $role,
1433: 'status' => $status,
1434: );
1435: $activatedcount ++;
1436: push (@{$rolechgs->{$timestamp}},\%chginfo);
1437: }
1438: }
1439: }
1440: }
1441: }
1.114 raeburn 1442: $activatedcount += &getrolechanges($rolechgs,$rolechgtime,$status,$classlist,\%stucounted,
1443: \%advcounted);
1.77 raeburn 1444: return $activatedcount;
1445: }
1446:
1447: sub getrolechanges {
1.114 raeburn 1448: my ($rolechgs,$rolechgtime,$status,$classlist,$stucountref,$advcountref) = @_;
1.77 raeburn 1449: my (%stucounted,%advcounted);
1450: if (ref($stucountref) eq 'HASH') {
1451: %stucounted = %{$stucountref};
1452: }
1453: if (ref($advcountref) eq 'HASH') {
1454: %advcounted = %{$advcountref};
1455: }
1456: my $withsec = 1;
1457: my $hidepriv = 1;
1458: my $context = 'course';
1459: my @statuses = ($status);
1460: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1461: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1462: my $now = time();
1463: my ($permission,$allowed) =
1464: &Apache::lonuserutils::get_permission($context);
1465: my $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1466: my $secidx = &Apache::loncoursedata::CL_SECTION();
1467: my $startidx = &Apache::loncoursedata::CL_START();
1468: my $endidx = &Apache::loncoursedata::CL_END();
1469: my $rolechgcount = 0;
1.114 raeburn 1470: if (ref($classlist) eq 'HASH') {
1471: foreach my $key (keys(%{$classlist})) {
1472: my ($userstatus,$eventtime);
1473: my $student = $classlist->{$key};
1474: if (ref($student) eq 'ARRAY') {
1475: my $start = $student->[$startidx];
1476: my $end = $student->[$endidx];
1477: my $sec = $student->[$secidx];
1478: my ($stuname,$studom) = split(/:/,$key);
1479: if ($status eq 'active') {
1480: if (exists($stucounted{$key.':'.$sec})) {
1481: next;
1482: }
1.77 raeburn 1483: }
1.114 raeburn 1484: if (($end == 0) || ($end > $start)) {
1485: if ($start <= $now) {
1486: if ($end && $end < $now) {
1487: if ($rolechgtime > 0) {
1488: if ($end > $rolechgtime) {
1489: $userstatus = 'previous';
1490: }
1491: } else {
1.77 raeburn 1492: $userstatus = 'previous';
1493: }
1494: } else {
1.114 raeburn 1495: if ($rolechgtime > 0) {
1496: if ($start >= $rolechgtime) {
1497: $userstatus = 'active';
1498: }
1499: } else {
1.77 raeburn 1500: $userstatus = 'active';
1501: }
1502: }
1503: }
1504: }
1.114 raeburn 1505: next if ($userstatus ne $status);
1506: if ($status eq 'active') {
1507: $eventtime = $start;
1508: } else {
1509: $eventtime = $end;
1510: }
1511: if (($viewablesec ne '') && ($sec ne '')) {
1512: next if ($viewablesec ne $sec);
1513: }
1514: my %chginfo = (
1515: 'section' => $sec,
1516: 'uname' => $stuname,
1517: 'udom' => $studom,
1518: 'role' => 'st',
1519: 'status' => $userstatus,
1520: );
1521: $rolechgcount ++;
1522: push(@{$rolechgs->{$eventtime}},\%chginfo);
1.77 raeburn 1523: }
1524: }
1525: }
1526: my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
1527: \@statuses,undef,undef,$withsec,$hidepriv);
1528: foreach my $item (keys(%advrolehash)) {
1529: my ($userstatus,$eventtime);
1530: my ($uname,$udom,$role,$section) = split(/:/,$item,-1);
1531: my ($start,$end) = split(/:/,$advrolehash{$item});
1532: if ($start eq '-1' && $end eq '-1') {
1533: next;
1534: } else {
1535: if ($status eq 'active') {
1536: if (exists($advcounted{$item})) {
1537: next;
1538: }
1539: }
1540: if (($end == 0) || ($end > $start)) {
1541: if ($start <= $now) {
1542: if ($end && $end < $now) {
1543: if ($rolechgtime > 0) {
1544: if ($end > $rolechgtime) {
1545: $userstatus = 'previous';
1546: }
1547: } else {
1548: $userstatus = 'previous';
1549: }
1550: } else {
1551: if ($rolechgtime > 0) {
1552: if ($start >= $rolechgtime) {
1553: $userstatus = 'active';
1554: }
1555: } else {
1556: $userstatus = 'active';
1557: }
1558: }
1559: }
1560: }
1561: next if ($userstatus ne $status);
1562: if ($status eq 'active') {
1563: $eventtime = $start;
1564: } else {
1565: $eventtime = $end;
1566: }
1567: }
1568: if (($viewablesec ne '') && ($section ne '')) {
1569: next if ($viewablesec ne $section);
1570: }
1571: my %chginfo = (
1572: 'section' => $section,
1573: 'uname' => $uname,
1574: 'udom' => $udom,
1575: 'role' => $role,
1576: 'status' => $userstatus,
1577: );
1578: $rolechgcount ++;
1579: push (@{$rolechgs->{$eventtime}},\%chginfo);
1580: }
1581: return $rolechgcount;
1582: }
1.33 raeburn 1583:
1.106 raeburn 1584: sub getloggedin {
1585: my ($cdom,$crs,$lastlogins,$starttime) = @_;
1586: my $context = 'course';
1587: my ($permission,$allowed) =
1588: &Apache::lonuserutils::get_permission($context);
1589: my $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1590: my %crslogins=&Apache::lonnet::dump('nohist_crslastlogin',$cdom,$crs);
1591: my $logincount = 0;
1592: my ($tmp) = keys(%crslogins);
1593: unless ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1594: if (keys(%crslogins) > 0) {
1595: foreach my $key (keys(%crslogins)) {
1596: my ($uname,$udom,$section,$role) = split(/:/,$key);
1597: my $eventtime = $crslogins{$key};
1598: if ($eventtime > $starttime) {
1599: if (($viewablesec ne '') && ($section ne '')) {
1600: next if ($viewablesec ne $section);
1601: }
1602: my %chginfo = (
1603: 'section' => $section,
1604: 'uname' => $uname,
1605: 'udom' => $udom,
1606: 'role' => $role,
1607: );
1608: $logincount ++;
1609: push (@{$lastlogins->{$eventtime}},\%chginfo);
1610: }
1611: }
1612: }
1613: }
1614: return $logincount;
1615: }
1616:
1.33 raeburn 1617: sub checkversions {
1618: my ($cdom,$crs,$navmap,$changed,$starttime) = @_;
1619: my %changes=&Apache::lonnet::dump('versionupdate',$cdom,$crs);
1620: my ($tmp) = keys(%changes);
1.40 raeburn 1621: unless ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1.33 raeburn 1622: if (keys(%changes) > 0) {
1623: foreach my $key (sort(keys(%changes))) {
1624: if ($changes{$key} > $starttime) {
1625: my $version;
1626: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
1627: my $currentversion=&Apache::lonnet::getversion($key);
1628: my $revdate =
1629: &Apache::lonnet::metadata($root.'.'.$extension,
1630: 'lastrevisiondate');
1631: $revdate = &Apache::lonlocal::locallocaltime($revdate);
1632: my $linkurl=&Apache::lonnet::clutter($key);
1.104 bisitz 1633: my $usedversion=$navmap->usedVersion($linkurl);
1.33 raeburn 1634: my @resources = $navmap->getResourceByUrl($linkurl,1);
1635: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1636: $version = $usedversion;
1637: } else {
1638: $version = $currentversion;
1639: }
1640: foreach my $res (@resources) {
1.35 raeburn 1641: if (ref($res) eq 'Apache::lonnavmaps::resource') {
1642: my $symb = $res->symb();
1643: %{$$changed{$symb}} = (
1.33 raeburn 1644: current => $currentversion,
1645: version => $version,
1646: revdate => $revdate,
1.35 raeburn 1647: );
1648: }
1.33 raeburn 1649: }
1650: }
1651: }
1652: }
1653: }
1654: return;
1655: }
1656:
1657: sub display_handgrade {
1.84 raeburn 1658: my ($r,$tograde,$ungraded,$itemserror) = @_;
1.33 raeburn 1659: my %lt = &Apache::lonlocal::texthash(
1660: 'prna' => 'Problem Name',
1661: 'nmun' => 'Number ungraded',
1662: 'nopr' => 'No problems require handgrading',
1663: );
1664: if (@{$tograde} > 0) {
1.68 raeburn 1665: $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
1666: $lt{'prna'}.'</td><td class="LC_right_item">'.
1667: $lt{'nmun'}.'</td></tr>');
1.33 raeburn 1668: my $rowNum = 0;
1669: foreach my $res (@{$tograde}) {
1.68 raeburn 1670: $rowNum ++;
1671: my $css_class = $rowNum%2?' class="LC_odd_row"':'';
1.102 www 1672: my $linkurl='/adm/grades';
1.66 raeburn 1673: if ($$ungraded{$res}{'enclink'}) {
1.102 www 1674: $linkurl.='?symb='.$$ungraded{$res}{'encsymb'};
1675: } else {
1676: $linkurl.='?symb='.&escape($res);
1677: }
1.110 raeburn 1678: $linkurl.='&command=ungraded';
1.68 raeburn 1679: $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 1680: }
1.84 raeburn 1681: } elsif ($itemserror) {
1682: $r->print('<tr class="LC_empty_row"><td>'.$itemserror.'</td></tr>');
1.33 raeburn 1683: } else {
1.68 raeburn 1684: $r->print('<tr class="LC_empty_row"><td>'.$lt{'nopr'}.'</td></tr>');
1.33 raeburn 1685: }
1686: }
1687:
1688: sub display_haserrors {
1.84 raeburn 1689: my ($r,$bombs,$bombed,$res_title,$itemserror) = @_;
1.33 raeburn 1690: my $bombnum = 0;
1691: my %lt = &Apache::lonlocal::texthash(
1692: reso => 'Resource',
1693: nmer => 'Number of errors',
1694: noer => 'No problems with errors',
1695: );
1696: if (@{$bombs} > 0) {
1.68 raeburn 1697: $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
1698: $lt{'reso'}.'</td><td class="LC_right_item">'.
1699: $lt{'nmer'}.'</td></tr>');
1.33 raeburn 1700: @{$bombs} = sort { &cmp_title($a,$b,$res_title) } @{$bombs};
1701: foreach my $bomb (@{$bombs}) {
1702: $bombnum ++;
1.68 raeburn 1703: my $css_class = $bombnum%2?' class="LC_odd_row"':'';
1704: $r->print('<tr'.$css_class.'><td>'.$$bombed{$bomb}{errorlink}.
1705: '</td><td class="LC_right_item">'.
1706: $$bombed{$bomb}{errorcount}.'</td></tr>');
1.33 raeburn 1707: }
1.84 raeburn 1708: } elsif ($itemserror) {
1709: $r->print('<tr class="LC_empty_row"><td>'.$itemserror.'</td></tr>');
1.33 raeburn 1710: } else {
1.68 raeburn 1711: $r->print('<tr class="LC_empty_row"><td>'.$lt{'noer'}.'</td></tr>');
1.33 raeburn 1712: }
1713: return;
1714: }
1715:
1716: sub display_abovethreshold {
1.119 raeburn 1717: my ($r,$refpage,$warnings,$triggered,$res_title,$itemserror,$checkallowed) = @_;
1.33 raeburn 1718: my %lt = &Apache::lonlocal::texthash(
1719: reso => 'Resource',
1720: part => 'Part',
1721: nust => 'Num. students',
1722: avat => 'Av. Attempts',
1723: dedi => 'Deg. Diff',
1724: lare => 'Last Reset',
1725: reco => 'Reset Count?',
1726: rese => 'Reset counters to 0',
1727: nopr => 'No problems satisfy threshold criteria',
1728: );
1729: if (@{$warnings} > 0) {
1730: @{$warnings} = sort { &cmp_title($a,$b,$res_title) } @{$warnings};
1.61 albertel 1731: $r->print('<tr class="LC_info_row">'.
1.110 raeburn 1732: '<td class="LC_left_item">'.$lt{'reso'}.
1733: '<input type="hidden" name="command" value="" /></td>'.
1.61 albertel 1734: '<td>'.$lt{'part'}.'</td><td>'.$lt{'nust'}.'</td>'.
1735: '<td>'.$lt{'avat'}.'</td><td>'.$lt{'dedi'}.'</td>'.
1.119 raeburn 1736: '<td>'.$lt{'lare'}.'</td>');
1737: if ($checkallowed->{'resetcounters'}) {
1738: $r->print('<td class="LC_right_item">'.$lt{'reco'}.'</td>');
1739: }
1740: $r->print('</tr>');
1.61 albertel 1741: my $row;
1.33 raeburn 1742: foreach my $res (@{$warnings}) {
1.61 albertel 1743: $row++;
1.33 raeburn 1744: my ($map,$id,$url)=&Apache::lonnet::decode_symb($res);
1745: my $linkurl=&Apache::lonnet::clutter($url);
1746: my $rowspan;
1747: if ($$triggered{$res}{numparts} > 1) {
1748: $rowspan = 'rowspan="'.$$triggered{$res}{numparts}.'"';
1749: }
1.55 www 1750: $linkurl .= '?symb='.&escape($res);
1.66 raeburn 1751: if ($$triggered{$res}{'enclink'}) {
1752: $linkurl =
1753: $$triggered{$res}{'enclink'}.'?symb='.$$triggered{$res}{'encsymb'};
1754: }
1.68 raeburn 1755: my $css_class = $row%2?' class="LC_odd_row"':'';
1756: $r->print('<tr'.$css_class.'>'.
1.61 albertel 1757: '<td class="LC_first_item" '.$rowspan.'><a href="'.$linkurl.'">'.
1.62 raeburn 1758: $$triggered{$res}{title}.'</a></td>');
1759: if (ref($$triggered{$res}{text}) eq 'ARRAY') {
1760: $r->print($$triggered{$res}{text}[0]);
1761: }
1762: $r->print('</tr>');
1763: if (ref($$triggered{$res}{text}) eq 'ARRAY') {
1764: if (@{$$triggered{$res}{text}} > 1) {
1765: for (my $i=1; $i<@{$$triggered{$res}{text}}; $i++) {
1.107 raeburn 1766: $r->print('<tr '.$css_class.'>'.
1.62 raeburn 1767: $$triggered{$res}{text}[$i].'</tr>');
1768: }
1769: }
1770: }
1.33 raeburn 1771: }
1.120 raeburn 1772: if ($checkallowed->{'resetcounters'}) {
1.119 raeburn 1773: $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>');
1774: }
1.84 raeburn 1775: } elsif ($itemserror) {
1776: $r->print('<tr class="LC_empty_row"><td>'.$itemserror.'</td></tr>');
1.33 raeburn 1777: } else {
1.63 albertel 1778: $r->print('<tr class="LC_empty_row"><td>'.$lt{'nopr'}.'</td></tr>');
1.33 raeburn 1779: }
1780: }
1781:
1782: sub display_versionchanges {
1.84 raeburn 1783: my ($r,$changed,$res_title,$interval,$itemserror) = @_;
1.33 raeburn 1784: my %lt = &Apache::lonlocal::texthash(
1785: 'reso' => 'Resource',
1786: 'revd' => 'Last revised',
1787: 'newv' => 'New version',
1788: 'veru' => 'Version used',
1789: );
1790: if (keys(%{$changed}) > 0) {
1.68 raeburn 1791: $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
1792: $lt{'reso'}.'</td><td>'.$lt{'revd'}.'</td><td>'.
1793: $lt{'newv'}.'</td><td class="LC_right_item">'.
1794: $lt{'veru'}.'</td></tr>');
1.33 raeburn 1795: my @changes = sort { &cmp_title($a,$b,$res_title) } keys(%{$changed});
1796: my $changenum = 0;
1797: foreach my $item (@changes) {
1.68 raeburn 1798: $changenum ++;
1799: my $css_class = $changenum%2?' class="LC_odd_row"':'';
1.33 raeburn 1800: my ($map,$id,$url)=&Apache::lonnet::decode_symb($item);
1801: my $linkurl=&Apache::lonnet::clutter($url);
1.55 www 1802: $linkurl .= '?symb='.&escape($item);
1.33 raeburn 1803:
1.68 raeburn 1804: $r->print('<tr'.$css_class.'><td><a href="'.$linkurl.'">'.
1805: $$res_title{$item}.'</a></td><td>'.
1806: $$changed{$item}{'revdate'}.'</td><td>'.
1807: $$changed{$item}{'current'}.'</td><td>'.
1808: $$changed{$item}{'version'}.'</td></tr>');
1.33 raeburn 1809: }
1.84 raeburn 1810: } elsif ($itemserror) {
1811: $r->print('<tr class="LC_empty_row"><td>'.$itemserror.'</td></tr>');
1.33 raeburn 1812: } else {
1.78 bisitz 1813: $r->print('<tr class="LC_empty_row"><td>'
1814: .&mt('No '.$interval).'</td></tr>');
1.33 raeburn 1815: }
1816: return;
1817: }
1.77 raeburn 1818:
1819: sub display_rolechanges {
1.114 raeburn 1820: my ($r,$chgcount,$changed,$interval,$crstype,$classlist) = @_;
1.77 raeburn 1821: my $now = time();
1822: my %lt = &Apache::lonlocal::texthash(
1823: 'user' => 'User',
1824: 'tich' => 'Time of change',
1825: 'role' => 'Role',
1826: 'sec' => 'Section',
1827: 'status' => 'Status',
1828: );
1829: if ($chgcount) {
1830: $r->print('<tr class="LC_info_row">'.
1831: '<td class="LC_left_item">'.$lt{'tich'}.'</td>'.
1832: '<td class="LC_left_item">'.$lt{'user'}.'</td>'.
1833: '<td class="LC_left_item">'.$lt{'role'}.'</td>'.
1834: '<td class="LC_left_item">'.$lt{'sec'}.'</td>'.
1835: '<td class="LC_left_item">'.$lt{'status'}.'</td></tr>');
1836: if (ref($changed) eq 'HASH') {
1837: my @changes = sort { $b <=> $a } (keys(%{$changed}));
1838: my $changenum = 0;
1.114 raeburn 1839: my $fullnameidx = &Apache::loncoursedata::CL_FULLNAME();
1.77 raeburn 1840: foreach my $item (@changes) {
1841: if (ref($changed->{$item}) eq 'ARRAY') {
1842: foreach my $chg (@{$changed->{$item}}) {
1843: if (ref($chg) eq 'HASH') {
1844: my $section;
1845: my $role =
1846: &Apache::lonnet::plaintext($chg->{'role'},$crstype);
1847: my $status = &mt($chg->{'status'});
1848: if ($chg->{'section'} eq '') {
1849: $section = &mt('none');
1850: } else {
1851: $section = $chg->{'section'};
1852: }
1853: my $uname = $chg->{'uname'};
1854: my $udom = $chg->{'udom'};
1855: $changenum ++;
1856: my $css_class = $changenum%2?' class="LC_odd_row"':'';
1.114 raeburn 1857: my $fullname;
1858: if (ref($classlist->{$uname.':'.$udom}) eq 'ARRAY') {
1859: $fullname = $classlist->{$uname.':'.$udom}->[$fullnameidx];
1860: } else {
1861: $fullname = &Apache::loncommon::plainname($uname,$udom,'lastname');
1862: }
1.77 raeburn 1863: my $link =
1.114 raeburn 1864: &Apache::loncommon::aboutmewrapper($fullname,$uname,$udom);
1.77 raeburn 1865: $r->print('<tr'.$css_class.'>'.
1.93 droeschl 1866: '<td>'.&Apache::lonlocal::locallocaltime($item).'</td>'.
1.77 raeburn 1867: '<td>'.$link.'</td>'.
1868: '<td>'.$role.'</td>'.
1869: '<td>'.$section.'</td>'.
1870: '<td>'.$status.'</td></tr>');
1871: }
1872: }
1873: }
1874: }
1875: }
1876: } else {
1.78 bisitz 1877: $r->print('<tr class="LC_empty_row"><td>'
1878: .&mt('There are no '.$interval).'</td></tr>');
1.77 raeburn 1879: }
1880: return;
1881: }
1.106 raeburn 1882:
1883: sub display_crslogins {
1.114 raeburn 1884: my ($r,$logincount,$loggedin,$interval,$crstype,$classlist) = @_;
1885: return unless (ref($classlist) eq 'HASH');
1.106 raeburn 1886: my %lt = &Apache::lonlocal::texthash(
1887: 'user' => 'User',
1888: 'role' => 'Role',
1889: 'sec' => 'Section',
1890: 'number' => 'Total number of logins',
1891: );
1892: if ($logincount) {
1893:
1894: my $hdr = '<tr class="LC_info_row" style="display:none" id="logintitledet">'.
1895: '<td class="LC_left_item">'.$lt{'user'}.'</td>'.
1896: '<td class="LC_left_item">'.$lt{'role'}.'</td>'.
1897: '<td class="LC_left_item">'.$lt{'sec'}.'</td></tr>'.
1898: '<tr class="LC_info_row" id="logintitlesum">'.
1899: '<td class="LC_left_item">'.$lt{'number'}.'</td>'.
1900: '<td class="LC_left_item">'.$lt{'role'}.'</td>'.
1901: '<td class="LC_left_item">'.$lt{'sec'};
1902: my (%bylastname,%counts);
1903: if (ref($loggedin) eq 'HASH') {
1904: my @logins = sort { $b <=> $a } (keys(%{$loggedin}));
1905: my $numlogin = 0;
1.114 raeburn 1906: my $fullnameidx = &Apache::loncoursedata::CL_FULLNAME();
1.106 raeburn 1907: foreach my $item (@logins) {
1908: if (ref($loggedin->{$item}) eq 'ARRAY') {
1909: foreach my $user (@{$loggedin->{$item}}) {
1910: if (ref($user) eq 'HASH') {
1911: my $section;
1912: my $role =
1913: &Apache::lonnet::plaintext($user->{'role'},$crstype);
1914: my $status = &mt($user->{'status'});
1915: if ($user->{'section'} eq '') {
1916: $section = &mt('none');
1917: } else {
1918: $section = $user->{'section'};
1919: }
1920: $counts{$user->{'role'}}{$section} ++;
1921: my $uname = $user->{'uname'};
1922: my $udom = $user->{'udom'};
1.114 raeburn 1923: my $fullname;
1924: if (ref($classlist->{$uname.':'.$udom}) eq 'ARRAY') {
1.115 raeburn 1925: $fullname = $classlist->{$uname.':'.$udom}->[$fullnameidx];
1.114 raeburn 1926: } else {
1927: $fullname = &Apache::loncommon::plainname($uname,$udom,'lastname');
1928: }
1.106 raeburn 1929: my $link =
1930: &Apache::loncommon::aboutmewrapper($fullname,$uname,$udom);
1931: push(@{$bylastname{$fullname}},
1932: '<td>'.$link.'</td>'.
1933: '<td>'.$role.'</td>'.
1934: '<td>'.$section.'</td>');
1935: }
1936: }
1937: }
1938: }
1939: my $table;
1940: foreach my $person (sort(keys(%bylastname))) {
1941: if (ref($bylastname{$person}) eq 'ARRAY') {
1942: foreach my $item (@{$bylastname{$person}}) {
1943: $numlogin ++;
1944: my $css_class = $numlogin%2?' class="LC_odd_row"':'';
1945: $table .= '<tr'.$css_class.' style="display:none;" id="logindet_'.$numlogin.'">'.$item.'</tr>';
1946: }
1947: }
1948: }
1949: my $numrow = 0;
1950: foreach my $role (sort(keys(%counts))) {
1951: my $showrole = &Apache::lonnet::plaintext($role,$crstype);
1952: if (ref($counts{$role}) eq 'HASH') {
1953: foreach my $sec (sort { $b <=> $a } (keys(%{$counts{$role}}))) {
1954: $numrow ++;
1955: my $css_class = $numrow%2?' class="LC_odd_row"':'';
1956: $table .= '<tr '.$css_class.' id="loginsum_'.$numrow.'">'.
1957: '<td>'.$counts{$role}{$sec}.'</td>'.
1958: '<td>'.$showrole.'</td>'.
1959: '<td>'.$sec.'</td></tr>';
1960: }
1961: }
1962: }
1963: $r->print($hdr.'<input type="hidden" name="logincount" value="'.$numlogin.
1964: '" /><input type="hidden" name="loginrow" value="'.$numrow.
1965: '" /></td></tr>'.$table);
1966: }
1967: } else {
1968: $r->print('<tr class="LC_empty_row"><td>'.
1969: &mt('There are no '.$interval).
1970: '<input type="hidden" name="logincount" value="'.$logincount.
1971: '." /></td></tr>');
1972: }
1973: return;
1974: }
1.33 raeburn 1975:
1976: sub display_coursediscussion {
1.84 raeburn 1977: my ($r,$newdiscussions,$unread,$countunread,$res_title,$itemserror) = @_;
1.59 albertel 1978: my $lctype = lc(&Apache::loncommon::course_type());
1.33 raeburn 1979: my %lt = &Apache::lonlocal::texthash(
1980: 'loca' => 'Location',
1981: 'type' => 'Type',
1982: 'numn' => 'Number of new posts',
1.56 raeburn 1983: 'noun' => 'No unread posts in '.$lctype.' discussions',
1.37 raeburn 1984: 'tmlp' => 'Time of last post',
1.33 raeburn 1985: );
1986: if (@{$newdiscussions} > 0) {
1.68 raeburn 1987: $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
1988: $lt{'loca'}.'</td><td>'.
1989: $lt{'type'}.'</td>');
1.39 raeburn 1990: if ($countunread eq 'on') {
1.68 raeburn 1991: $r->print('<td>'.$lt{'tmlp'}.'</td>'.
1992: '<td class="LC_right_item">'.$lt{'numn'}.'</td>');
1.37 raeburn 1993: } else {
1.68 raeburn 1994: $r->print('<td class="LC_right_item">'.$lt{'tmlp'}.'</td>');
1.37 raeburn 1995: }
1996: $r->print("</tr>\n");
1.33 raeburn 1997: @{$newdiscussions} = sort { &cmp_title($a,$b,$res_title) }
1998: @{$newdiscussions};
1999: my $rowNum = 0;
2000: foreach my $ressymb (@{$newdiscussions}) {
1.68 raeburn 2001: $rowNum ++;
1.33 raeburn 2002: my $forum_title = $$unread{$ressymb}{'title'};
2003: my $type = 'Resource';
2004: my $feedurl=&Apache::lonfeedback::get_feedurl($ressymb);
1.108 droeschl 2005: my $disclink = $feedurl.'?symb='. &escape($$unread{$ressymb}{symb});
1.33 raeburn 2006: if ($feedurl =~ /bulletinboard/) {
1.85 schafran 2007: $type = 'Discussion Board';
1.33 raeburn 2008: }
1.66 raeburn 2009: if ($$unread{$ressymb}{'enclink'}) {
2010: $disclink = $$unread{$ressymb}{'enclink'}.'?symb='.$$unread{$ressymb}{'encsymb'};
2011: }
1.68 raeburn 2012: my $css_class = $rowNum%2?' class="LC_odd_row"':'';
1.37 raeburn 2013: my $lastpost = &Apache::lonnavmaps::timeToHumanString(
2014: $$unread{$ressymb}{'lastpost'});
1.70 raeburn 2015: $r->print('<tr'.$css_class.'><td><a href="'.$disclink.'">'.$forum_title.'</a> </td><td>'.&mt($type).' </td>');
1.39 raeburn 2016: if ($countunread eq 'on') {
1.37 raeburn 2017: my $unreadnum = $$unread{$ressymb}{'unreadcount'};
1.68 raeburn 2018: $r->print('<td>'.$lastpost.'</td><td class="LC_right_item">'.
2019: $unreadnum.' </td>');
1.37 raeburn 2020: } else {
1.68 raeburn 2021: $r->print('<td class="LC_right_item">'.$lastpost.'</td>');
1.33 raeburn 2022: }
1.37 raeburn 2023: $r->print("</tr>\n");
1.33 raeburn 2024: }
1.84 raeburn 2025: } elsif ($itemserror) {
2026: $r->print('<tr class="LC_empty_row"><td>'.$itemserror.'</td></tr>');
1.33 raeburn 2027: } else {
1.68 raeburn 2028: $r->print('<tr class="LC_empty_row"><td>'.$lt{'noun'}.'</td></tr>');
1.33 raeburn 2029: }
2030: }
2031:
2032: sub display_coursenormalmail {
1.68 raeburn 2033: my ($r,$msgcount,$newmsgs) = @_;
1.59 albertel 2034: my $lctype = lc(&Apache::loncommon::course_type());
1.33 raeburn 2035: if ($msgcount > 0) {
1.68 raeburn 2036: $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
2037: &mt('Number').'</td><td>'.&mt('Subject').'</td><td>'.
2038: &mt('Sender').'</td><td class="LC_right_item">'.
2039: &mt('Date/Time').'</td></tr>');
2040: my $mailcount = 0;
1.33 raeburn 2041: foreach my $msg (@{$newmsgs}) {
2042: $mailcount ++;
1.68 raeburn 2043: my $css_class = $mailcount%2?' class="LC_odd_row"':'';
1.76 raeburn 2044: $r->print('<tr'.$css_class.'><td>'.$mailcount
2045: .'. </td><td><a href="/adm/email?display='
2046: .$msg->{'msgid'}.'">'
2047: .$msg->{'shortsub'}.'</a> </td><td> '
2048: .$msg->{'from'}.':'.$msg->{'fromdom'}.' </td><td>'
2049: .$msg->{'sendtime'}.'</td></tr>');
1.33 raeburn 2050: }
2051: } else {
1.68 raeburn 2052: $r->print('<tr class="LC_empty_row"><td>'.
2053: &mt('No new '.$lctype.' messages').'</td></tr>');
1.33 raeburn 2054: }
2055: }
2056:
2057: sub display_coursecritmail {
1.68 raeburn 2058: my ($r,$critmsgcount,$critmsgs) = @_;
1.59 albertel 2059: my $lctype = lc(&Apache::loncommon::course_type());
1.33 raeburn 2060: if ($critmsgcount > 0) {
1.68 raeburn 2061: $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
2062: &mt('Number').'</td><td>'.&mt('Subject').'</td><td>'.
2063: &mt('Sender').'</td><td class="LC_right_item">'.
2064: &mt('Date/Time').'</td></tr>');
2065: my $mailcount = 0;
1.33 raeburn 2066: foreach my $msg (@{$critmsgs}) {
2067: $mailcount ++;
1.68 raeburn 2068: my $css_class = $mailcount%2?' class="LC_odd_row"':'';
2069: $r->print('<tr'.$css_class.'><td>'.$mailcount.
2070: '. </td><td><a href="/adm/email?folder=critical">'.
2071: $msg->{'shortsub'}.'</a> </td><td> '.
1.72 albertel 2072: $msg->{'from'}.':'.$msg->{'fromdom'}.' </td><td>'.
1.68 raeburn 2073: $msg->{'sendtime'}.'</td></tr>');
1.33 raeburn 2074: }
2075: } else {
1.68 raeburn 2076: $r->print('<tr class="LC_empty_row"><td>'.
2077: &mt('No unread critical messages in '.$lctype).
2078: '</td></tr>');
1.33 raeburn 2079: }
1.1 raeburn 2080: }
2081:
2082: sub cmp_title {
1.16 raeburn 2083: my ($a,$b,$res_title) = @_;
2084: my ($atitle,$btitle) = (lc($$res_title{$a}),lc($$res_title{$b}));
1.1 raeburn 2085: $atitle=~s/^\s*//;
2086: $btitle=~s/^\s*//;
2087: return $atitle cmp $btitle;
2088: }
2089:
1.33 raeburn 2090: sub get_display_settings {
1.36 raeburn 2091: my ($uname,$udom,$cid) = @_;
1.33 raeburn 2092: my %settings = &Apache::lonnet::dump('nohist_whatsnew',$udom,$uname,$cid);
2093: my ($tmp) = keys(%settings);
1.40 raeburn 2094: if ($tmp=~ /^(con_lost|error|no_such_host)/i) {
1.33 raeburn 2095: %settings = ();
1.41 raeburn 2096: unless ($tmp =~ /^error: 2 /) {
1.59 albertel 2097: my $lctype = lc(&Apache::loncommon::course_type());
1.41 raeburn 2098: &Apache::lonnet::logthis('Error retrieving whatsnew settings: '.
1.56 raeburn 2099: $tmp.' for '.$uname.':'.$udom.' for '.$lctype.': '.$cid);
1.33 raeburn 2100: }
2101: }
2102: return %settings;
2103: }
2104:
1.36 raeburn 2105: sub store_display_settings {
2106: my ($uname,$udom,$cid,$checkallowed) = @_;
2107: my %whatsnew_settings;
2108: my $result;
2109: foreach my $key (keys(%{$checkallowed})) {
1.44 albertel 2110: if ($key =~ /_section$/) { next; }
1.36 raeburn 2111: if (exists($env{'form.display_'.$key})) {
2112: unless ($env{'form.display_'.$key} eq '') {
2113: $whatsnew_settings{$cid.':'.$key} = $env{'form.display_'.$key};
2114: }
2115: }
2116: }
2117: if (keys(%whatsnew_settings)) {
2118: $result = &Apache::lonnet::put('nohist_whatsnew',\%whatsnew_settings,
2119: $udom,$uname);
2120: } else {
2121: $result = 'ok';
2122: }
2123: return $result;
2124: }
2125:
2126: sub store_interval_setting {
2127: my ($uname,$udom,$cid,$interval_titles) = @_;
2128: my %interval_settings = ();
2129: my $result;
1.77 raeburn 2130: my $context = $env{'form.intervaltype'};
2131: if ($env{'form.interval'} ne '') {
2132: if ($context eq 'oldroles') {
2133: $interval_settings{$cid.':oldroleinterval'} = $env{'form.interval'};
2134: } elsif ($context eq 'newroles') {
2135: $interval_settings{$cid.':newroleinterval'} = $env{'form.interval'};
1.106 raeburn 2136: } elsif ($context eq 'crslogin') {
2137: $interval_settings{$cid.':crslogininterval'} = $env{'form.interval'};
1.77 raeburn 2138: } else {
2139: $interval_settings{$cid.':interval'} = $env{'form.interval'};
2140: }
1.36 raeburn 2141: my $outcome = &Apache::lonnet::put('nohist_whatsnew',
2142: \%interval_settings,$udom,$uname);
2143: if ($outcome eq 'ok') {
1.77 raeburn 2144: if (ref($interval_titles->{$context}) eq 'HASH') {
1.99 wenzelju 2145: $result = &Apache::lonhtmlcommon::confirm_success(&mt('New filter setting: [_1].','<b>'.
2146: $interval_titles->{$context}->{$env{'form.interval'}}.'</b>').'<br />');
1.77 raeburn 2147: }
1.36 raeburn 2148: } else {
1.59 albertel 2149: my $lctype = lc(&Apache::loncommon::course_type());
1.77 raeburn 2150: &Apache::lonnet::logthis('Error saving whatsnew '.$context.' interval setting'.
1.56 raeburn 2151: ' '.$outcome.' for '.$uname.':'.$udom.' in '.$lctype.' '.$cid);
1.99 wenzelju 2152: $result = &Apache::lonhtmlcommon::confirm_success(&mt('Unable to set interval to [_1] due to [_2].',
1.77 raeburn 2153: '<b>'.$interval_titles->{$context}->{$env{'form.interval'}}.'</b>',
1.99 wenzelju 2154: '<tt>'.$outcome.'</tt>'),1);
1.36 raeburn 2155: }
2156: }
1.99 wenzelju 2157: return &Apache::loncommon::confirmwrapper($result);
1.36 raeburn 2158: }
2159:
1.39 raeburn 2160: sub store_discussion_setting {
2161: my ($uname,$udom,$cid) = @_;
2162: my %discussion_settings;
2163: my $result;
2164: if (defined($env{'form.countunread'})) {
2165: $discussion_settings{$cid.':countunread'} = $env{'form.countunread'};
2166: my $outcome = &Apache::lonnet::put('nohist_whatsnew',
2167: \%discussion_settings,$udom,$uname);
2168: if ($outcome eq 'ok') {
1.99 wenzelju 2169: $result = &Apache::lonhtmlcommon::confirm_success(&mt('Count unread posts in discussions display set to [_1]',
2170: '<b>'.&mt($env{'form.countunread'}).'</b>').'<br />');
1.39 raeburn 2171:
2172: } else {
1.59 albertel 2173: my $lctype = lc(&Apache::loncommon::course_type());
1.71 albertel 2174: &Apache::lonnet::logthis('Error saving whatsnew countunread setting'.
1.56 raeburn 2175: ' '.$outcome.' for '.$uname.':'.$udom.' in '.$lctype.' '.$cid);
1.99 wenzelju 2176: $result = &Apache::lonhtmlcommon::confirm_success(&mt('Unable to set "number unread posts display" to [_1]'.
1.39 raeburn 2177: ' due to [_2].',
1.74 bisitz 2178: '<b>'.&mt($env{'form.countunread'}).'</b>',
1.99 wenzelju 2179: '<tt>'.$outcome.'</tt>'),1);
1.39 raeburn 2180: }
2181: }
1.99 wenzelju 2182: return &Apache::loncommon::confirmwrapper($result);
1.39 raeburn 2183: }
2184:
2185: sub store_courseinit_setting {
2186: my ($uname,$udom,$cid,$initpage) = @_;
2187: my %courseinit_settings;
2188: my $page_control;
2189: my $result;
2190: if (defined($env{'form.courseinit_control'})) {
2191: if ($env{'form.courseinit_control'} eq 'userpref') {
2192: $courseinit_settings{$cid.':courseinit'} = '';
2193: $page_control = 'global preferences';
2194: } else {
2195: if (defined($env{'form.courseinit_page'})) {
2196: $courseinit_settings{$cid.':courseinit'} =
2197: $env{'form.courseinit_page'};
2198: $page_control = 'course specific setting';
2199: }
2200: }
2201: if ($page_control) {
1.59 albertel 2202: my $lctype = lc(&Apache::loncommon::course_type());
1.39 raeburn 2203: my $outcome = &Apache::lonnet::put('nohist_whatsnew',
2204: \%courseinit_settings,$udom,$uname);
2205: if ($outcome eq 'ok') {
2206: if ($page_control eq 'global preferences') {
1.99 wenzelju 2207: $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 2208: } else {
1.99 wenzelju 2209: $result = &Apache::lonhtmlcommon::confirm_success(&mt('Page displayed after role selection in this '.$lctype.' set to [_1].'
2210: ,'<b>'.$$initpage{$env{'form.courseinit_page'}}.'</b>'));
1.39 raeburn 2211: }
2212: } else {
1.71 albertel 2213: &Apache::lonnet::logthis('Error saving whatsnew courseinit '.
1.39 raeburn 2214: 'setting: '.$outcome.' for '.$uname.
1.56 raeburn 2215: ':'.$udom.' in '.$lctype.' '.$cid);
1.39 raeburn 2216: if ($page_control eq 'global preferences') {
1.99 wenzelju 2217: $result = &Apache::lonhtmlcommon::confirm_success(&mt('Unable to set control of page display to [_1]'.
1.39 raeburn 2218: ' due to [_2].',
2219: '<b>'.$page_control.'</b>',
1.99 wenzelju 2220: '<tt>'.$outcome.'</tt>'),1);
1.39 raeburn 2221: } else {
1.99 wenzelju 2222: $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 2223: ,'<b>'.$$initpage{$env{'form.courseinit_page'}}.'</b>'
1.99 wenzelju 2224: ,'<tt>'.$outcome.'</tt>'),1);
1.39 raeburn 2225: }
2226: }
2227: }
2228: }
1.99 wenzelju 2229: return &Apache::loncommon::confirmwrapper($result);
1.39 raeburn 2230: }
2231:
1.33 raeburn 2232: sub start_box {
1.69 raeburn 2233: my ($r,$show,$heading,$caller,$refpage) = @_;
1.33 raeburn 2234: my %lt = &Apache::lonlocal::texthash(
2235: chth => 'Change thresholds?',
2236: chin => 'Change interval?',
1.39 raeburn 2237: chop => 'Change options?',
1.33 raeburn 2238: );
1.68 raeburn 2239: my $showhide;
1.33 raeburn 2240: if ($$show{$caller}) {
1.36 raeburn 2241: $showhide = '<b><a href="javascript:change_display(document.visible.'.
1.70 raeburn 2242: 'display_'.$caller.",'hide'".');">'.
2243: &mt('Hide').'</a></b>';
1.33 raeburn 2244:
2245: } else {
1.36 raeburn 2246: $showhide = '<b><a href="javascript:change_display(document.visible.'.
1.70 raeburn 2247: 'display_'.$caller.",'show'".');">'.
2248: &mt('Show').'</a></b>';
1.33 raeburn 2249: }
2250:
2251: $r->print('
1.68 raeburn 2252: <table class="LC_nested_outer">
1.33 raeburn 2253: <tr>
1.73 raeburn 2254: <th class="LC_left_item">'.$$heading{$caller}.'</th>
1.68 raeburn 2255: <th class="LC_right_item">'.$showhide.'</th>
2256: </tr>');
1.33 raeburn 2257: if (($caller eq 'abovethreshold') && ($$show{$caller})) {
1.40 raeburn 2258: if ($$show{$caller}) {
2259: $r->print('
1.33 raeburn 2260: <tr>
1.98 raeburn 2261: <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgthreshold&refpage='.$refpage.'">'.$lt{'chth'}.'</a></td>
1.33 raeburn 2262: </tr>');
1.40 raeburn 2263: }
1.33 raeburn 2264: } elsif (($caller eq 'versionchanges') && ($$show{$caller})) {
1.40 raeburn 2265: if ($$show{$caller}) {
2266: $r->print('
1.33 raeburn 2267: <tr>
1.98 raeburn 2268: <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chginterval&refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
1.39 raeburn 2269: </tr>');
1.40 raeburn 2270: }
1.39 raeburn 2271: } elsif ($caller eq 'coursediscussion') {
1.40 raeburn 2272: if ($$show{$caller}) {
2273: $r->print('
1.39 raeburn 2274: <tr>
1.98 raeburn 2275: <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgdisc&refpage='.$refpage.'">'.$lt{'chop'}.'</a></td>
1.33 raeburn 2276: </tr>');
1.40 raeburn 2277: }
1.77 raeburn 2278: } elsif (($caller eq 'newroles') && ($$show{$caller})) {
2279: if ($$show{$caller}) {
2280: $r->print('
2281: <tr>
1.98 raeburn 2282: <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgnewroleinterval&refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
1.77 raeburn 2283: </tr>');
2284: }
2285: } elsif (($caller eq 'oldroles') && ($$show{$caller})) {
2286: if ($$show{$caller}) {
2287: $r->print('
2288: <tr>
1.98 raeburn 2289: <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgoldroleinterval&refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
1.77 raeburn 2290: </tr>');
2291: }
1.106 raeburn 2292: } elsif (($caller eq 'crslogin') && ($$show{$caller})) {
2293: if ($$show{$caller}) {
2294: $r->print('
2295: <tr>
2296: <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>
2297: </tr>');
2298: }
2299: }
2300:
1.61 albertel 2301: $r->print('
1.33 raeburn 2302: <tr>
1.68 raeburn 2303: <td colspan="2">
2304: <table class="LC_nested">
1.33 raeburn 2305: ');
2306: return;
2307: }
2308:
2309: sub end_box {
2310: my ($r) = shift;
2311: $r->print('
2312: </table>
2313: </td>
2314: </tr>
2315: </table><br />');
2316: return;
2317: }
2318:
1.7 raeburn 2319: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>