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