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