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