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