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