File:  [LON-CAPA] / loncom / interface / lonwhatsnew.pm
Revision 1.105.2.12: download - view: text, annotated - select for diffs
Sun Oct 23 21:52:26 2016 UTC (7 years, 6 months ago) by raeburn
Branches: version_2_11_X
- For 2.11
  - Backport 1.119, 1.120

    1: #
    2: # $Id: lonwhatsnew.pm,v 1.105.2.12 2016/10/23 21:52:26 raeburn Exp $
    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: 
   28: package Apache::lonwhatsnew;
   29: 
   30: use strict;
   31: use lib qw(/home/httpd/lib/perl);
   32: use Apache::lonnet;
   33: use Apache::loncommon();
   34: use Apache::lonhtmlcommon();
   35: use Apache::lonlocal;
   36: use Apache::loncoursedata();
   37: use Apache::lonnavmaps();
   38: use Apache::lonuserstate;
   39: use Apache::lonuserutils; 
   40: use Apache::Constants qw(:common :http);
   41: use Time::Local;
   42: use GDBM_File;
   43: use lib '/home/httpd/lib/perl/';
   44: use LONCAPA;
   45: use HTML::Entities;
   46: 
   47: #----------------------------
   48: # handler
   49: #
   50: #----------------------------
   51: 
   52: sub handler {
   53:     my $r = shift;
   54:     if ($r->header_only) {
   55:         &Apache::loncommon::content_type($r,'text/html');
   56:         $r->send_http_header;
   57:         return OK;
   58:     }
   59:     &Apache::loncommon::get_unprocessed_cgi(
   60:                                    $ENV{'QUERY_STRING'},['command','refpage']);
   61: 
   62:     my $command = $env{'form.command'};
   63:     my $refpage = $env{'form.refpage'};
   64: 
   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],
   73:                             ['vcl','newroles',1],
   74:                             ['vcl','oldroles',1],
   75:                             ['whn','crslogin',1],
   76:                             ['mgr','resetcounters',1],
   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:     }
   90: 
   91:     if ( ! $env{'request.course.fn'} || ! $checkallowed{'whatsnew'}) {
   92:         # Not in a course, or no whn priv in course
   93:         $env{'user.error.msg'}="/adm/whatsnew:whn:0:0:Cannot display what's new page";
   94:         return HTTP_NOT_ACCEPTABLE;
   95:     }
   96: 
   97:     &Apache::loncommon::content_type($r,'text/html');
   98:     $r->send_http_header;
   99: 
  100:     $r->print(&display_header($command,\%checkallowed));
  101: 
  102:     &Apache::lonhtmlcommon::clear_breadcrumbs();
  103:     &Apache::lonhtmlcommon::add_breadcrumb
  104:             ({href=>'/adm/whatsnew',
  105:               text=>"What's New?"});
  106:     if (($command eq 'chgthreshold') && $checkallowed{'abovethreshold'}) {
  107:         &Apache::lonhtmlcommon::add_breadcrumb
  108:             ({href=>'/adm/whatsnew?command=chgthreshold&refpage='.$refpage,
  109:               text=>"Change thresholds"});
  110:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
  111:             ("What's New?",#'Course_Action_Items_Thresholds'
  112: 	     ));
  113:     } elsif (($command eq 'chginterval') && $checkallowed{'versionchanges'} ) {
  114:         &Apache::lonhtmlcommon::add_breadcrumb
  115:             ({href=>'/adm/whatsnew?command=chginterval&refpage='.$refpage,
  116:               text=>"Change interval"});
  117:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
  118:             ("What's New?",#'Course_Action_Items_Intervals'
  119: 	     ));
  120:     } elsif (($command eq 'chgdisc') && $checkallowed{'coursediscussion'}) {
  121:         &Apache::lonhtmlcommon::add_breadcrumb
  122:             ({href=>'/adm/whatsnew?command=chgdisc&refpage='.$refpage,
  123:               text=>"Change discussion display"});
  124:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
  125:             ("What's New?",#'Course_Action_Items_Intervals'
  126: 	     ));
  127:     } elsif ($command eq 'courseinit') {
  128:         &Apache::lonhtmlcommon::add_breadcrumb
  129:             ({href=>'/adm/whatsnew?command=courseinit&refpage='.$refpage,
  130:               text=>"Course initialization preference"});
  131:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
  132:             ("What's New?",#'Course_Action_Items_Initialization'
  133: 	     ));
  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:              ));
  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:              ));
  155:     } else {
  156:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
  157:             ("What's New?",#'Course_Action_Items_Display'
  158: 	     ));
  159:     }
  160:     &display_main_box($r,$command,$refpage,\%checkallowed);
  161:     return OK;
  162: }
  163: 
  164: #------------------------------
  165: # display_main_box
  166: #
  167: # Display all the elements within the main box
  168: #------------------------------
  169:                                                                                 
  170: sub display_main_box {
  171:     my ($r,$command,$refpage,$checkallowed) = @_;
  172:     my $domain=&Apache::loncommon::determinedomain();
  173:     my $function = &Apache::loncommon::get_users_function();
  174:     my $lctype = lc(&Apache::loncommon::course_type());
  175:     $r->print('<table width="100%" border="0" cellpadding="5" cellspacing="0"><tr><td width="100%">');
  176: 
  177:     my %threshold_titles = &Apache::lonlocal::texthash (
  178:                          av_attempts => 'Average number of attempts',
  179:                          degdiff => 'Degree of difficulty',
  180:                          numstudents => 'Total number of students with submissions',
  181:     );
  182:     my %versions = (
  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:                    );
  188:     my %newroles = (
  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:                    );
  194:     my %oldroles = (
  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:                    );
  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:                    );
  206:     my %interval_titles = (
  207:         versions => \%versions,
  208:         newroles => \%newroles,
  209:         oldroles => \%oldroles,
  210:         crslogin => \%crslogins,
  211:     );
  212:     my %initpage = &Apache::lonlocal::texthash (
  213:                      firstres => "first resource in the $lctype",
  214:                      whatsnew => "What's New Page",
  215:                      userpref => 'your general user preferences',
  216:                      coursespecific => "specific setting for this $lctype",
  217:                    );
  218:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  219:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
  220: 
  221:     if (($command eq 'chgthreshold') 
  222: 	&& $checkallowed->{'abovethreshold'}) {
  223:         &display_threshold_config($r,$refpage,\%threshold_titles,
  224:                                                                    $cdom,$crs);
  225:     } elsif (($command eq 'chginterval') 
  226: 	     && $checkallowed->{'versionchanges'}) {
  227:         &display_interval_config($r,$refpage,\%interval_titles,'versions');
  228:     } elsif (($command eq 'chgdisc') 
  229: 	     && $checkallowed->{'coursediscussion'}) {
  230:         &display_discussion_config($r,$refpage);
  231:     } elsif ($command eq 'courseinit') {
  232:         &courseinit_config($r,$refpage,\%initpage);
  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');
  239:     } elsif (($command eq 'chgcrslogininterval')
  240:              && $checkallowed->{'crslogin'}) {
  241:         &display_interval_config($r,$refpage,\%interval_titles,'crslogin');
  242:     } else {
  243:         &display_actions_box($r,$command,$refpage,\%threshold_titles,
  244:                         \%interval_titles,\%initpage,$cdom,$crs,$checkallowed);
  245:     }
  246:     my $end_page = &Apache::loncommon::end_page();
  247:     $r->print(<<END_OF_BLOCK);
  248:   </td>
  249:  </tr>
  250: </table><br />
  251: $end_page
  252: END_OF_BLOCK
  253: }
  254: 
  255: #-------------------------------
  256: # display_header
  257: #
  258: # Display the header information and set
  259: # up the HTML
  260: #-------------------------------
  261: 
  262: sub display_header {
  263:     my ($command,$checkallowed) = @_;
  264:     
  265:     my $scripttag;
  266:     unless ($command eq 'chgthreshold' || $command eq 'chginterval' || 
  267:             $command eq 'chgoldroleinterval' ||
  268:             $command eq 'chgnewroleinterval' || $command eq 'chgcrslogininterval') {
  269:        $scripttag = <<"END";
  270: <script type="text/javascript">
  271: // <![CDATA[
  272: function change_display(caller,change) {
  273:     caller.value = change;
  274:     document.visible.submit();
  275: }
  276: 
  277: function changeAll(change) {
  278: END
  279:         foreach my $item (keys(%{$checkallowed})) {
  280: 	    if ($item =~ /_section$/) { next; }
  281:             if ($$checkallowed{$item}) {
  282:                 $scripttag.='document.visible.display_'.$item.'.value=change'.
  283:                             "\n";
  284:             }
  285:         }
  286:         $scripttag.='document.visible.submit();
  287: }
  288: 
  289: function thresholdreset() {
  290:     document.visible.command.value="reset";
  291:     document.visible.submit();
  292: }
  293: 
  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: // ]]>
  339: </script>
  340: ';
  341:     }
  342:     my $course_type=&Apache::loncommon::course_type();
  343:     return &Apache::loncommon::start_page("What's New?",
  344: 					  $scripttag);
  345: }
  346: 
  347: #-------------------------------
  348: # display_actions_box
  349: #
  350: # Display the action items
  351: #
  352: #-------------------------------
  353:                                                                                 
  354: sub display_actions_box {
  355:     my ($r,$command,$refpage,$threshold_titles,$interval_titles,$initpage,
  356:         $cdom,$crs,$checkallowed) = @_;
  357:     my $udom = $env{'user.domain'};
  358:     my $uname = $env{'user.name'};
  359:     my $cid = $env{'request.course.id'};
  360:     my $crstype = &Apache::loncommon::course_type();
  361:     my $lctype = lc($crstype);
  362:     my %stulabel = (
  363:                     'Course' => 'students',
  364:                     'Community' => 'members',
  365:                    );
  366:     my %lt = &Apache::lonlocal::texthash(
  367:                  'yacc' => 'You are accessing an invalid course',
  368:                  'gtfr' => 'Go to first resource',
  369:                  'hial' => 'Hide all',
  370:                  'shal' => 'Show all',
  371:     );
  372: 
  373:     my %unread = ();
  374:     my %ungraded = ();
  375:     my %bombed = ();
  376:     my %triggered = ();
  377:     my %changed = ();
  378:     my @newmsgs = ();
  379:     my @critmsgs = ();
  380:     my @newdiscussions = ();
  381:     my @tograde = ();
  382:     my @bombs = ();
  383:     my @warnings = ();
  384:     my $msgcount = 0;
  385:     my $critmsgcount = 0;
  386:     my $expirecount;
  387:     my %expired;
  388:     my $activecount;
  389:     my %activated;
  390:     my %loggedin;
  391:     my $logincount;
  392:     my %res_title = ();
  393:     my %show = ();
  394:     my $needitems = 0;
  395:     my $boxcount = 0;
  396: 
  397:     my $result;
  398:     if ($command eq 'newcourseinit') {
  399:         $result = &store_courseinit_setting($uname,$udom,$cid,$initpage);
  400:     }
  401: 
  402:     my %threshold = ();
  403:     my %pagedesc = &Apache::lonlocal::texthash (
  404:                      firstres => 'First resource',
  405:                      whatsnew => "What's New Page",
  406:                      userpref => 'user preference',
  407:                      coursespecific => $lctype.' only',
  408:                      default => 'default',
  409:                    );
  410: 
  411:     my ($initcontrol,$initdisp) = &curr_courseinit();
  412:     my $currinit = $pagedesc{$initdisp}.' ('.$pagedesc{$initcontrol}.')';
  413: 
  414:     unless ($cid) {
  415:         $r->print('<p><span style="text-align: center; font-weight: bold;">'.$lt{'yacc'}.'</span></p>');
  416:         return;
  417:     }
  418: 
  419:     my $header = '';
  420:     if ($refpage eq 'start') {
  421:         if (tie(my %bighash,'GDBM_File',$env{'request.course.fn'}.'.db',
  422:             &GDBM_READER(),0640)) {
  423:             my $furl=&HTML::Entities::encode($bighash{'first_url'},'"<>&');
  424:             untie(%bighash);
  425:             $header .= '<b><a href="'.$furl.'">'.$lt{'gtfr'}.
  426:                   '</a></b><br />';
  427:         }
  428:     }
  429:     $header .= &mt('Page set to be displayed after you have selected a role in this '.$lctype).'.'
  430:               .' <span class="LC_nobreak">'
  431:               .&mt('Currently: [_1].','<i>'.$currinit.'</i>')
  432:               .'&nbsp;&nbsp;'
  433:               .&mt('[_1]Change[_2] for just [_3]this '.$lctype.'[_4] or for [_5]all your courses/communities[_6].'
  434:                   ,'<b>'
  435:                   ,'</b>'
  436:                   ,'<a href="/adm/whatsnew?command=courseinit&amp;refpage='.$refpage.'">'
  437:                   ,'</a>'
  438:                   ,'<a href="/adm/preferences?action=changecourseinit&amp;refpage='.$refpage.'">'
  439:                   ,'</a>')
  440:               .' </span>';
  441: 
  442:     $r->print(&Apache::loncommon::head_subbox($header));
  443: 
  444:     if ($command eq 'reset') {
  445:         $result = &process_reset($cdom,$crs,$checkallowed);
  446:     } elsif ($command eq 'update') {
  447:         $result = &process_update($uname,$udom,$threshold_titles);
  448:     } elsif ($command eq 'newinterval') {
  449:         $result = &store_interval_setting($uname,$udom,$cid,$interval_titles);
  450:     } elsif ($command eq 'newdiscconf') {
  451:         $result = &store_discussion_setting($uname,$udom,$cid);
  452:     }
  453: 
  454:     my $store_result=&store_display_settings($uname,$udom,$cid,$checkallowed);
  455: 
  456:     unless ($store_result eq 'ok') { 
  457:         &Apache::lonnet::logthis('Error saving whatsnew settings: '.
  458:             $store_result.' for '.'user '.$uname.':'.$udom.' in '.$lctype.' '.$cid);
  459:         $result .= '<span class="LC_error">'
  460:                   .&mt('Unable to save visibility settings due to [_1]',
  461:                        $store_result)
  462:                   .'</span>';
  463:     }
  464: 
  465:     if ($result) {
  466:         $r->print($result.'<hr />');
  467:     }
  468:     $r->rflush();
  469: 
  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) {
  485:         $headings{'versionchanges'} = &mt('Resources in '.$lctype.' with version changes since start of '.$lctype);
  486:     } elsif ($timediff{'versions'} == 2592000) {
  487:         $headings{'versionchanges'} = &mt('Resources in '.$lctype.' with version changes since last month');
  488:     } elsif ($timediff{'versions'} == 604800) {
  489:         $headings{'versionchanges'} = &mt('Resources in '.$lctype.' with version changes since last week');
  490:     } elsif ($timediff{'versions'} == 86400) {
  491:         $headings{'versionchanges'} = &mt('Resources in '.$lctype.' with version changes since yesterday');
  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) {
  499:         $headings{'oldroles'} = &mt('Roles for which access to '.$lctype.' has expired since start of '.$lctype);
  500:     } elsif ($timediff{'oldroles'} == 2592000) {
  501:         $headings{'oldroles'} = &mt('Roles for which access to '.$lctype.' has expired since last month');
  502:     } elsif ($timediff{'oldroles'} == 604800) {
  503:         $headings{'oldroles'} = &mt('Roles for which access to '.$lctype.' has expired since last week');
  504:     } elsif ($timediff{'oldroles'} == 86400) {
  505:         $headings{'oldroles'} = &mt('Roles for which access to '.$lctype.' has expired since yesterday');
  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) {
  513:         $headings{'newroles'} = &mt('Roles for which access to '.$lctype.' has become available since start of '.$lctype);
  514:     } elsif ($timediff{'newroles'} == 2592000) {
  515:         $headings{'newroles'} = &mt('Roles for which access to '.$lctype.' has become available since last month');
  516:     } elsif ($timediff{'newroles'} == 604800) {
  517:         $headings{'newroles'} = &mt('Roles for which access to '.$lctype.' has become available since last week');
  518:     } elsif ($timediff{'newroles'} == 86400) {
  519:         $headings{'newroles'} = &mt('Roles for which access to '.$lctype.' has become available since yesterday');
  520:     }
  521: 
  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: 
  536:     my ($now,$starttime,$activatedstart,$expiredstart,$crsloginstart);
  537:     $now = time;
  538: 
  539:     if ($timediff{'versions'} == -1) {
  540:         $starttime = 0;
  541:     } else {
  542:         $starttime = $now - $timediff{'versions'};
  543:     }
  544: 
  545:     if ($timediff{'newroles'} == -1) {
  546:         $activatedstart = 0;
  547:     } else {
  548:         $activatedstart = $now - $timediff{'newroles'};
  549:     }
  550: 
  551:     if ($timediff{'oldroles'} == -1) {
  552:         $expiredstart = 0;
  553:     } else {
  554:         $expiredstart = $now - $timediff{'oldroles'};
  555:     }
  556: 
  557:     if ($timediff{'crslogin'} == -1) {
  558:         $crsloginstart = 0;
  559:     } else {
  560:         $crsloginstart = $now - $timediff{'crslogin'};
  561:     }
  562: 
  563:     my $countunread = $display_settings{$cid.':countunread'};
  564:     unless (defined($countunread)) {
  565:         $countunread = 'on';
  566:     }
  567:     if ($$checkallowed{'abovethreshold'}) {
  568:         &get_curr_thresholds(\%threshold,$uname,$udom,$cid,$cdom,$crs);
  569:     }
  570: 
  571:     $headings{'abovethreshold'} = 
  572: 	&mt('(Problems with av. attempts &ge; [_1] or deg. difficulty &ge; [_2]) [_3] and total number of '.$stulabel{$crstype}.' with submissions &ge; [_4]',
  573: 	    $threshold{'av_attempts'},$threshold{'degdiff'},
  574: 	    '<br />',$threshold{'numstudents'});
  575: 
  576:     my @actionorder = ('handgrading','haserrors','abovethreshold','versionchanges','coursediscussion','coursenormalmail','coursecritmail','newroles','oldroles','crslogin');
  577: 
  578:     foreach my $key (keys(%{$checkallowed})) {
  579: 	if ($key =~ /_section$/) { next; }
  580:         $show{$key} = 0;
  581:         if ($$checkallowed{$key}) {
  582:             unless ($display_settings{$cid.':'.$key} eq 'hide') {
  583:                 $show{$key} = 1;
  584:             }
  585:         }
  586:     }
  587: 
  588:     foreach my $item (@actionorder) {
  589:         unless ($item eq 'coursenormalmail' || $item eq 'coursecritmail' ||
  590:                 $item eq 'newroles' || $item eq 'oldroles') {
  591:             if ($show{$item}) {
  592:                 $needitems = 1;
  593:                 last;
  594:             }
  595:         }
  596:     }
  597: 
  598:     my $itemserror;
  599:     if ($needitems) {
  600:         $itemserror = &getitems(\%unread,\%ungraded,\%bombed,\%triggered,\%changed,\@newdiscussions,\@tograde,\@bombs,\@warnings,\%threshold,$cdom,$crs,\%res_title,\%show,$starttime,$countunread,$checkallowed);
  601:     }
  602:     my $classlist;
  603:     if ($show{'oldroles'} || $show{'newroles'} || $show{'crslogin'}) {
  604:         $classlist = &Apache::loncoursedata::get_classlist();
  605:     }
  606:     if ($show{'coursenormalmail'}) {
  607:         $msgcount = &getnormalmail(\@newmsgs);
  608:     }
  609:     if ($show{'coursecritmail'}) {
  610:         $critmsgcount = &getcritmail(\@critmsgs);
  611:     }
  612:     if ($show{'oldroles'}) {
  613:         $expirecount = &getexpired(\%expired,$expiredstart,'previous',$classlist);
  614:     }
  615:     if ($show{'newroles'}) {
  616:         $activecount = &getactivated(\%activated,$activatedstart,'active',$classlist);
  617:     }
  618:     if ($show{'crslogin'}) {
  619:         $logincount = &getloggedin($cdom,$crs,\%loggedin,$crsloginstart);
  620:     }
  621:     $r->print(qq|<a href="javascript:changeAll('hide');">$lt{'hial'}</a>
  622:      &nbsp;&nbsp;<a href="javascript:changeAll('show');">$lt{'shal'}</a>
  623:      <form method="post" name="visible" action="/adm/whatsnew">\n|);
  624:     foreach my $item (keys(%{$checkallowed})) {
  625: 	if ($item =~ /_section$/) { next; }
  626:         if ($$checkallowed{$item}) {
  627:             $r->print('<input type="hidden" name="display_'.$item.'" />'."\n");
  628:         }
  629:     }
  630: 
  631:     $r->print('<input type="hidden" name="refpage" value="'.$refpage.'" /><table class="LC_double_column"><tr><td class="LC_left_col">');
  632: 
  633:     my $displayed = 0;
  634:     my $totalboxes = 0;
  635:     foreach my $key (keys(%{$checkallowed})) {
  636: 	if ($key =~ /_section$/) { next; }
  637: 	if ($key eq 'whatsnew' ) { next; } # whatsnew check creates no box
  638:         if ($$checkallowed{$key}) {
  639:             $totalboxes ++;
  640:         }
  641:     }
  642:     my $halfway = 4;
  643: #    my $halfway = int($totalboxes/2) + $totalboxes%2;
  644:     foreach my $actionitem (@actionorder) {
  645:         if ($$checkallowed{$actionitem}) {
  646:             if ($displayed == $halfway) {
  647:                 $r->print('</td><td>&nbsp;</td><td class="LC_right_col" >');
  648:             }
  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);
  650:             $displayed ++; 
  651:         }
  652:     }
  653:     $r->print('
  654:       </td>
  655:     </tr>
  656:    </table>
  657:    </form>
  658: ');
  659: }
  660: 
  661: #-------------------------------
  662: # display_threshold_config
  663: #
  664: # Display the threshold setting screen 
  665: #
  666: #-------------------------------
  667:                                                                                 
  668: sub display_threshold_config {
  669:     my ($r,$refpage,$threshold_titles,$cdom,$crs) = @_;
  670:     my $uname = $env{'user.name'};
  671:     my $udom = $env{'user.dom'};
  672:     my $cid = $env{'request.course.id'};
  673:     my %threshold = ();
  674:     my $rowColor1 = "#ffffff";
  675:     my $rowColor2 = "#eeeeee";
  676:     my $rowColor;
  677: 
  678:     my @thresholditems = ("av_attempts","degdiff","numstudents");
  679:     my %threshold_titles = &Apache::lonlocal::texthash(
  680:                          av_attempts => 'Average number of attempts',
  681:                          degdiff => 'Degree of difficulty',
  682:                          numstudents => 'Total number of students with submissions',
  683:                          );
  684:     &get_curr_thresholds(\%threshold,$uname,$udom,$cid,$cdom,$crs);
  685: 
  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().
  689:              '<th>'.&mt('Threshold Name').'</th>'."\n".
  690:              '<th>'.&mt('Current value').'</th>'."\n".
  691:              '<th>'.&mt('Change?').'</th>'."\n".
  692:               &Apache::loncommon::end_data_table_header_row());
  693:     foreach my $type (@thresholditems) {
  694:         my $parameter = $env{'request.course.id'}.':threshold_'.$type;
  695: # onchange is javascript to automatically check the 'Set' button.
  696:         my $onchange = 'onfocus="javascript:window.document.forms'.
  697:               "['thresholdform'].elements['".$parameter."_setparmval']".
  698:               '.checked=true;"';
  699:         $r->print(&Apache::loncommon::start_data_table_row()."\n".
  700:                  '<td>'.$threshold_titles{$type}.'</td>'."\n".
  701:                  '<td>'.&Apache::lonhtmlcommon::textbox($parameter.'_value',
  702:                                             $threshold{$type},
  703:                                             10,$onchange).'</td>'."\n".
  704:                  '<td>'.
  705:                  &Apache::lonhtmlcommon::checkbox($parameter.'_setparmval').
  706:                  '</td>'."\n".
  707:                  &Apache::loncommon::end_data_table_row());
  708:     }
  709:     $r->print(&Apache::loncommon::end_data_table()."\n".
  710:           '<br /><input type="submit" name="threshold" value="'.&mt('Save').'" />
  711:                  <input type="hidden" name="command" value="update" />
  712:                  <input type="hidden" name="refpage" value="'.$refpage.'" />
  713:                </form>');
  714: }
  715: 
  716: #-------------------------------
  717: # display_interval_config
  718: #
  719: # Display the interval setting screen
  720: #
  721: #-------------------------------
  722:                                                                                    
  723: sub display_interval_config {
  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:     }
  731:     my $lctype = lc(&Apache::loncommon::course_type());
  732:     my $current = &get_current($env{'user.name'},$env{'user.domain'},
  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 />');
  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 />');
  740:     } else {
  741:         $r->print('<br />'.&mt('Choose the time window to use to display resources in the '.$lctype.' with version changes.').'<br />');
  742:     }
  743:     unless ($current eq '') {
  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:         }
  748:     }
  749:     $r->print('<br />
  750: <form method="post" name="intervalswitch" action="/adm/whatsnew">
  751: <input type="hidden" name="command" value="newinterval" />
  752: <input type="hidden" name="intervaltype" value="'.$context.'" />
  753: <input type="hidden" name="refpage" value="'.$refpage.'" />'.
  754: &mt('Display:').' 
  755: <select name="interval">
  756: <option value="" selected="selected">'.&mt('Select').'</option>
  757: ');
  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}})))) {
  761:                 $r->print('<option value="'.$key.'">'.&mt($interval_titles->{$context}->{$key}).
  762:                           '</option>'."\n");
  763:             }
  764:         }
  765:     }
  766:     $r->print('</select>&nbsp;&nbsp;
  767:                <input type="submit" name="display" value="'.
  768:                &mt('Save').'" /></form>');
  769:     return;
  770: }
  771: 
  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:     }
  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>');
  798:     $r->print('<br />'
  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.')
  800:              .'<br />'
  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>')
  802:              .'&nbsp;&nbsp;'
  803:              .&mt('Currently set to [_1].','<b>'.$current.'</b>')
  804:     );
  805:     $r->print('<br /><br />
  806: <form method="post" name="discussionswitch" action="/adm/whatsnew">
  807: <input type="hidden" name="command" value="newdiscconf" />
  808: <input type="hidden" name="refpage" value="'.$refpage.'" />
  809: <input type="hidden" name="countunread" value="'.$opposite{$current}.'" />
  810: ');
  811:     $r->print('<br/>
  812:                <input type="button" name="display" value="'.
  813:                &mt('Change to [_1]',&mt($opposite{$current})).'" 
  814:                onclick="javascript:toggle_countunread('."'change'".')" />'.
  815:                ('&nbsp;' x7).
  816:                '<input type="button" name="nochange" value="'.
  817:                &mt("No change").'" 
  818:                onclick="javascript:toggle_countunread('."'unchanged'".')" />
  819:                </form>');
  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');
  836:     my $lctype = lc(&Apache::loncommon::course_type());
  837:     my %lt = &Apache::lonlocal::texthash(
  838:                              'chwp' => "Choose which page will be displayed when you enter this $lctype after selecting a role.",
  839:                              'cuva' => 'Current value is determined by',
  840:                              'anis' => 'and is set to display',
  841:                              'padc' => 'Page display controlled by',
  842:                              'chce' => 'Choose '.$lctype.' entry',
  843:                              'moce' => 'Save',
  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" />
  853: $lt{'padc'}:&nbsp;&nbsp;
  854: END
  855:     foreach my $choice (@chgstate) {
  856:         my $chkstring;
  857:         if ($choice eq $control) {
  858:             $chkstring = ' checked="checked" ';
  859:         }  
  860:         $r->print('<span class="LC_nobreak"><label><input type="radio" name="courseinit_control" value="'.
  861:                    $choice.'"'.$chkstring.'/>'.$$initpage{$choice}.
  862:                    '&nbsp;&nbsp;</label></span>');
  863:     }
  864:     $r->print('<br /><br />'.&mt('If').' '.$$initpage{'coursespecific'}.
  865:               ' - <br />'.$lt{'chce'}.": \n");
  866:     foreach my $choice (@chgentry) {
  867:         my $chkstring;
  868:         if (($choice eq $current) && ($control eq 'coursespecific')) {
  869:             $chkstring = ' checked="checked" ';
  870:         }
  871:         $r->print('<span class="LC_nobreak"><label><input type="radio" name="courseinit_page" value="'.
  872:                   $choice.'"'.$chkstring.'/>'.$$initpage{$choice}.
  873:                   '&nbsp;&nbsp;</label></span>');
  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;
  884:     if ($current) {
  885:         $control = 'coursespecific';
  886:     } else {
  887:         $control = 'userpref';
  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) {
  894:             $current = 'whatsnew';
  895:         }
  896:     }
  897:     return ($control,$current);
  898: }
  899: 
  900: sub display_launcher {
  901:     my ($r,$action,$refpage,$checkallowed,$show,$headings,$res_title,
  902:         $tograde,$ungraded,$bombs,$bombed,$changed,$warnings,$triggered,
  903:         $newdiscussions,$unread,$msgcount,$newmsgs,$critmsgcount,$critmsgs,
  904:         $interval,$countunread,$expired,$expirecount,$activated,$activecount,
  905:         $crstype,$itemserror,$loggedin,$logincount,$classlist) = @_;
  906: 
  907:     if ($$checkallowed{$action}) {
  908:         &start_box($r,$show,$headings,$action,$refpage);
  909:         if ($$show{$action}) {
  910:             if ($action eq 'handgrading') {    # UNGRADED ITEMS
  911:                 &display_handgrade($r,$tograde,$ungraded,$itemserror);
  912:             } elsif ($action eq 'haserrors') { # BOMBS
  913:                 &display_haserrors($r,$bombs,$bombed,$res_title,$itemserror);
  914:             } elsif ($action eq 'versionchanges') { # VERSION CHANGES
  915:                 &display_versionchanges($r,$changed,$res_title,$interval->{'versions'},$itemserror);
  916:             } elsif ($action eq 'abovethreshold') { # DEGDIFF/AV. TRIES TRIGGERS
  917:                 &display_abovethreshold($r,$refpage,$warnings,$triggered,
  918: 					$res_title,$itemserror,$checkallowed);
  919:             } elsif ($action eq 'coursediscussion') { # UNREAD COURSE DISCUSSION
  920:                 &display_coursediscussion($r,$newdiscussions,$unread,
  921:                                 $countunread,$res_title,$itemserror);
  922:             } elsif ($action eq 'coursenormalmail') { # NORMAL MESSAGES
  923:                 &display_coursenormalmail($r,$msgcount,$newmsgs);
  924:             } elsif ($action eq 'coursecritmail') { # CRITICAL MESSAGES
  925:                 &display_coursecritmail($r,$critmsgcount,$critmsgs);
  926:             } elsif ($action eq 'newroles') { # ACTIVATED ROLES
  927:                 &display_rolechanges($r,$activecount,$activated,$interval->{'newroles'},
  928:                                      $crstype,$classlist);
  929:             } elsif ($action eq 'oldroles') { # EXPIRED ROLES
  930:                 &display_rolechanges($r,$expirecount,$expired,$interval->{'oldroles'},
  931:                                      $crstype,$classlist);
  932:             } elsif ($action eq 'crslogin') { #LAST LOGIN
  933:                 &display_crslogins($r,$logincount,$loggedin,$interval->{'crslogin'},
  934:                                    $crstype,$classlist);
  935:             }
  936:         }
  937:         &end_box($r);
  938:     }
  939:     return;
  940: }
  941: 
  942: sub getitems {
  943:     my ($unread,$ungraded,$bombed,$triggered,$changed,$newdiscussions,
  944:         $tograde,$bombs,$warnings,$threshold,$cdom,$crs,$res_title,$show,
  945:         $starttime,$countunread,$checkallowed) = @_;
  946:     my $navmap = Apache::lonnavmaps::navmap->new();
  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:     }
  951:     # force retrieve Resource to seed the part id cache we'll need it later
  952:     my @allres=$navmap->retrieveResources(undef,
  953:                      sub {if ($_[0]->is_problem) { $_[0]->parts();} return 1;});
  954:     my %resourcetracker;
  955:     my $discussiontime;
  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:     }
  966: 
  967:     foreach my $resource (@allres) {
  968:         my $result = '';
  969:         my $applies = 0;
  970:         my $symb = $resource->symb();
  971:         %{$$bombed{$symb}} = ();
  972:         %{$$ungraded{$symb}} = ();
  973:         %{$$triggered{$symb}} = ();
  974:         $$triggered{$symb}{numparts} = 0;
  975:         if ($resource->encrypted()) {
  976:             $$triggered{$symb}{'enclink'} = $resource->link();
  977:             $$triggered{$symb}{'encsymb'} = $resource->shown_symb();
  978:         }
  979:         my $title = $resource->compTitle();
  980:         $$res_title{$symb} = $title;
  981:         my $ressymb = $resource->wrap_symb();
  982: 
  983: # Check if there are unread discussion postings
  984:         if ($$show{'coursediscussion'}) {
  985:             &check_discussions($resource,$symb,$ressymb,$title,
  986: 			       $newdiscussions,$unread,$countunread);
  987:         }
  988: 
  989: # Check for ungraded problems
  990:         if ($resource->is_problem()) {
  991:             if ($$show{'handgrading'}) {
  992:                 &check_handgraded($resource,$symb,$title,$cdom,$crs,$ungraded,
  993:                                                                      $tograde);
  994:             }
  995:         }
  996: 
  997: # Check for bombs
  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'}) {  
 1004:             &check_thresholds($resource,$symb,\%resourcetracker,
 1005: 			      $triggered,$threshold,$warnings,
 1006:                               $checkallowed);
 1007:         }
 1008: 
 1009:     }
 1010:     return; 
 1011: }
 1012: 
 1013: sub check_discussions {
 1014:     my ($resource,$symb,$ressymb,$title,$newdiscussions,$unread,
 1015: 	$countunread) = @_;
 1016: 
 1017:     if (!$resource->hasDiscussion()) { return; }
 1018: 
 1019:     %{$$unread{$ressymb}} = ();
 1020:     $$unread{$ressymb}{'title'} = $title;
 1021:     $$unread{$ressymb}{'symb'} = $symb;
 1022:     if ($resource->encrypted()) {
 1023:         $$unread{$ressymb}{'enclink'} = $resource->link();
 1024:         $$unread{$ressymb}{'encsymb'} = $resource->shown_symb();
 1025:     }
 1026:     push(@{$newdiscussions}, $ressymb);
 1027:     
 1028:     $$unread{$ressymb}{'lastpost'} = $resource->last_post_time();
 1029:     
 1030:     if ($countunread eq 'on') {
 1031: 	$$unread{$ressymb}{'unreadcount'} = 
 1032:                             $resource->discussion_info('unread');
 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) {
 1043:             if ($resource->handgrade($part) eq 'yes') {
 1044:                 $handgradeable=1; last;
 1045:             }
 1046:         }
 1047:         if ($handgradeable) {
 1048:             my @ungraded = &Apache::bridgetask::get_queue_symb_status(
 1049:                                              'gradingqueue',$symb,$cdom,$cnum);
 1050:             if (@ungraded > 0) {
 1051:                 $$ungraded{$symb}{count} = scalar(@ungraded);
 1052:                 $$ungraded{$symb}{title} = $title;
 1053:                 if ($resource->encrypted()) {
 1054:                     $$ungraded{$symb}{'enclink'} = $resource->link();
 1055:                     $$ungraded{$symb}{'encsymb'} = $resource->shown_symb();
 1056:                 }
 1057:                 push(@{$tograde},$symb);
 1058:             }
 1059:         }
 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='.
 1071:                         &escape($bombs[0]).'">'.
 1072:                         $title.'</a>';
 1073:         $$bombed{$symb}{errorcount} = $errorcount;
 1074:         $$bombed{$symb}{errorlink} = $errorlink;
 1075:         push(@{$bombs}, $symb);
 1076:     }
 1077: }
 1078: 
 1079: sub check_thresholds {
 1080:     my ($resource,$symb,$resourcetracker,$triggered,$threshold,$warnings,
 1081:         $checkallowed) = @_;
 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:         }
 1091:         if ($resource->is_anonsurvey($part)) {
 1092:             next;
 1093:         }
 1094:         if ($resource->is_survey($part)) {
 1095:             next;
 1096:         }
 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:         }
 1116:         &Apache::lonnet::statslog($symb,$part,$users,$av_attempts,$degdiff);
 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});
 1124:             }
 1125:             $warning = 1;
 1126:         }
 1127:     }
 1128:     if ($warning) {
 1129:         $$triggered{$symb}{title} = $resource->title;
 1130:         my $partcount = 0;
 1131:         @{$$triggered{$symb}{text}} = ();
 1132:         foreach my $part (@parts) {
 1133:             if (exists($stats{$part}{users})) {
 1134:                 my $resetname = 'reset_'.&escape($symb."\0".$part);
 1135:                 my $resettitle = 'title_'.&escape($symb."\0".$part);
 1136:                 if (@parts > 1) {
 1137:                     $$triggered{$symb}{text}[$partcount] = '
 1138:                      <td>'.&mt('part - ').$part.'</td>';
 1139:                 } else {
 1140:                     $$triggered{$symb}{text}[$partcount] = '
 1141:                      <td>'.&mt('single part').'</td>';
 1142:                 }
 1143:                 $$triggered{$symb}{text}[$partcount] .= '
 1144:                      <td>'.$stats{$part}{users}.'</td>
 1145:                      <td>'.$stats{$part}{attempts}.'</td>
 1146:                      <td>'.$stats{$part}{degdiff}.'</td>
 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:                 }
 1153:                 $partcount ++;
 1154:             }
 1155:             $$triggered{$symb}{numparts} = $partcount;
 1156:         }
 1157:         push(@{$warnings},$symb);
 1158:     }
 1159: }
 1160: 
 1161: 
 1162: sub get_curr_thresholds {
 1163:     my ($threshold,$uname,$udom,$cid,$cdom,$crs) = @_;
 1164:     # set default values
 1165:     %$threshold = (av_attempts => 2,
 1166:                   degdiff => 0.5,
 1167:                   numstudents => 2
 1168:                   );
 1169:     my %thresholdsettings = &Apache::lonnet::dump('nohist_whatsnew',$udom,
 1170:                                                      $uname,$cid.':threshold');
 1171:     my $thresholdcount = 0;
 1172:     my ($tmp) = %thresholdsettings;
 1173:     unless ($tmp =~ /^(con_lost|error|no_such_host)/i) {
 1174:         foreach my $item (keys(%{$threshold})) { 
 1175:             if (exists($thresholdsettings{$cid.':threshold_'.$item})) {
 1176:                 $$threshold{$item} = 
 1177:                              $thresholdsettings{$cid.':threshold_'.$item};
 1178:                 $thresholdcount ++;
 1179:             }
 1180:         }
 1181:     }
 1182:     if ($thresholdcount == 3) {
 1183:         return;
 1184:     }
 1185:     my %coursesettings = &Apache::lonnet::dump('environment',
 1186:                                               $cdom,$crs,'internal.threshold');
 1187:     my ($temp) = %coursesettings;
 1188:     unless ($temp =~ /^(con_lost|error|no_such_host)/i) {  
 1189:         foreach my $item (keys(%{$threshold})) {
 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:         }
 1197:     }
 1198:     return;
 1199: }
 1200: 
 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);
 1206:     my ($tmp) = %settings;
 1207:     unless ($tmp =~ /^(con_lost|error|no_such_host)/i) {
 1208:         $currvalue = $settings{$cid.':'.$caller};
 1209:     }
 1210:     return $currvalue;
 1211: }
 1212: 
 1213: sub process_reset {
 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:     }
 1219:     my $result = '<b>'.&mt('Counters reset for following problems (and parts):').
 1220:                            '</b><br />';
 1221:     my @agg_types = ('attempts','users','correct');
 1222:     my %agg_titles = &Apache::lonlocal::texthash (
 1223:                      attempts => 'Number of submissions',
 1224:                      users => 'Students with submissions',
 1225:                      correct => 'Number of correct submissions',
 1226:                      );
 1227:     my @resets = ();
 1228:     my %titles = ();
 1229:     foreach my $key (keys(%env)) {
 1230:         next if ($key !~ /^form\.reset_(.+)$/);
 1231:         my $title = &unescape($env{'form.title_'.$1});
 1232:         my $reset_item = &unescape($1);
 1233:         my %curr_aggregates = &Apache::lonnet::dump('nohist_resourcetracker',$dom,$crs,$reset_item);
 1234:         my %aggregates = ();
 1235:         my ($symb,$part) = split(/\0/,$reset_item);
 1236:         foreach my $type (@agg_types) {
 1237:             $aggregates{$reset_item."\0".$type} = 0;
 1238:         }  
 1239: 	$aggregates{$reset_item."\0".'resettime'} = time;
 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 {
 1251:             $result = $title.' -part '.$part.': '.&mt('Unable to reset counters to zero due to [_1]',$putresult).'.<br />'."\n";
 1252:         }
 1253:     }
 1254:     return $result;
 1255: }
 1256: 
 1257: sub process_update {
 1258:     my ($uname,$udom,$threshold_titles) = @_;
 1259:     my $setoutput = '<b>'.&mt('Changes to threshold(s) for problem tracking:').'</b><br/><br />';
 1260:     foreach my $key (keys(%env)) {
 1261:         my $name;
 1262:         if ($key =~/^form\.(.+)\_setparmval$/) {
 1263:             $name  = $1;
 1264:         } else {
 1265:             next;
 1266:         }
 1267:         my $value = $env{'form.'.$name.'_value'};
 1268:         if ($name && defined($value) && ($value ne '')) {
 1269:             my $put_result = &Apache::lonnet::put('nohist_whatsnew',
 1270:                                                   {$name=>$value},$udom,$uname);
 1271:            
 1272:             my ($shortname) = ($name =~ /^\Q$env{'request.course.id'}\E:threshold_(.+)$/);
 1273:             if ($put_result eq 'ok') {
 1274:                 $setoutput.= &Apache::lonhtmlcommon::confirm_success(&mt('Set threshold for [_1] to [_2]',
 1275: 				'<b>'.$$threshold_titles{$shortname}.'</b>',
 1276: 				'<b>'.$value.'</b>').'<br />');
 1277: 	    } else {
 1278:                 $setoutput.= &Apache::lonhtmlcommon::confirm_success(&mt('Unable to set threshold for [_1] to [_2] due to [_3].',
 1279: 				'<b>'.$name.'</b>','<b>'.$value.'</b>',
 1280: 				'<tt>'.$put_result.'</tt>').'<br />',1);
 1281:             }
 1282:         }
 1283:     }
 1284:     return &Apache::loncommon::confirmwrapper($setoutput);
 1285: }
 1286: 
 1287: sub getnormalmail {
 1288:     my ($newmsgs) = @_;
 1289: # Check for unread messages in user's INBOX (which were sent in context of current course).
 1290:     my $msgcount = 0;
 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:                             });
 1318:                     }
 1319:                 }
 1320:             }
 1321:         }
 1322:     }
 1323:     return $msgcount;
 1324: }
 1325: 
 1326: sub getcritmail {
 1327:     my ($critmsgs) = @_; 
 1328: # Check for critical messages which were sent in context of current course.
 1329:     my %what=&Apache::lonnet::dump('critical');
 1330:     my $result = '';
 1331:     my $critmsgcount = 0;
 1332:     foreach my $msgid (sort(keys(%what))) {
 1333:         my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
 1334:             &Apache::lonmsg::unpackmsgid($msgid,undef,1,undef,
 1335:                                          $env{'request.course.id'});
 1336:         if (($fromcid) && ($fromcid eq  $env{'request.course.id'})) {
 1337:             if (defined($sendtime) && $sendtime!~/error/) {
 1338:                 $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
 1339:                 $critmsgcount ++;
 1340:                 if ($shortsubj eq '') {
 1341:                     $shortsubj = &mt('No subject');
 1342:                 }
 1343:                 push(@{$critmsgs}, {
 1344:                         msgid    => $msgid,
 1345:                         sendtime => $sendtime,
 1346:                         shortsub => $shortsubj,
 1347:                         from     => $fromname,
 1348:                         fromdom  => $fromdom
 1349:                         });
 1350:             }
 1351:         }
 1352:     }
 1353:     return $critmsgcount;
 1354: }
 1355: 
 1356: sub getexpired {
 1357:     my ($rolechgs,$rolechgtime,$status,$classlist) = @_;
 1358:     my $expirecount = &getrolechanges($rolechgs,$rolechgtime,$status,$classlist);
 1359:     return $expirecount;
 1360: }
 1361: 
 1362: sub getactivated {
 1363:     my ($rolechgs,$rolechgtime,$status,$classlist) = @_;
 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) {
 1375:         foreach my $chg (keys(%changes)) {
 1376:             if (ref($changes{$chg}) eq 'HASH') {
 1377:                 next if ($changes{$chg}{'delflag'});
 1378:                 if ($rolechgtime > 0) {
 1379:                     next if ($changes{$chg}{'exe_time'} < $rolechgtime);
 1380:                 }
 1381:                 if ($changes{$chg}{'exe_time'}) {
 1382:                     my $timestamp = $changes{$chg}{'exe_time'};
 1383:                     if (ref($changes{$chg}{'logentry'}) eq 'HASH') {
 1384:                         my $end = $changes{$chg}{'logentry'}{'end'};
 1385:                         next if ($end && $end <= $now);
 1386:                         my $start = $changes{$chg}{'logentry'}{'start'};
 1387:                         next if ($start >= $timestamp);
 1388:                         my $section = $changes{$chg}{'logentry'}{'section'};
 1389:                         if (($viewablesec ne '') && ($section ne '')) {
 1390:                             next if ($viewablesec ne $section);
 1391:                         }
 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:     }
 1414:     $activatedcount += &getrolechanges($rolechgs,$rolechgtime,$status,$classlist,\%stucounted,
 1415:                                        \%advcounted);
 1416:     return $activatedcount;
 1417: }
 1418: 
 1419: sub getrolechanges {
 1420:     my ($rolechgs,$rolechgtime,$status,$classlist,$stucountref,$advcountref) = @_;
 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;
 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:                     }
 1455:                 }
 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 {
 1464:                                 $userstatus = 'previous';
 1465:                             }
 1466:                         } else {
 1467:                             if ($rolechgtime > 0) {
 1468:                                 if ($start >= $rolechgtime) {
 1469:                                     $userstatus = 'active';
 1470:                                 }
 1471:                             } else {
 1472:                                 $userstatus = 'active';
 1473:                             }
 1474:                         }
 1475:                     }
 1476:                 }
 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);
 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: }
 1555: 
 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: 
 1589: sub checkversions {
 1590:     my ($cdom,$crs,$navmap,$changed,$starttime) = @_;
 1591:     my %changes=&Apache::lonnet::dump('versionupdate',$cdom,$crs);
 1592:     my ($tmp) = keys(%changes);
 1593:     unless ($tmp =~ /^(con_lost|error|no_such_host)/i) {
 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);
 1605:                     my $usedversion=$navmap->usedVersion($linkurl);
 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) {
 1613:                          if (ref($res) eq 'Apache::lonnavmaps::resource') { 
 1614:                             my $symb = $res->symb();
 1615:                             %{$$changed{$symb}} = (
 1616:                                                 current => $currentversion,
 1617:                                                 version => $version,
 1618:                                                 revdate => $revdate,
 1619:                             );
 1620:                         }
 1621:                     }
 1622:                 }
 1623:             }
 1624:         }
 1625:     }
 1626:     return;
 1627: }
 1628: 
 1629: sub display_handgrade {
 1630:     my ($r,$tograde,$ungraded,$itemserror) = @_;
 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) {
 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>');
 1640:         my $rowNum = 0;
 1641:         foreach my $res (@{$tograde}) {
 1642:             $rowNum ++;
 1643:             my $css_class = $rowNum%2?' class="LC_odd_row"':'';
 1644:             my ($map,$id,$url)=&Apache::lonnet::decode_symb($res);
 1645:             my $linkurl=&Apache::lonnet::clutter($url);
 1646:             $linkurl .= '?symb='.&escape($res);
 1647:             if ($$ungraded{$res}{'enclink'}) {
 1648:                 $linkurl =
 1649:                     $$ungraded{$res}{'enclink'}.'?symb='.$$ungraded{$res}{'encsymb'};
 1650:             }
 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>');
 1652:         }
 1653:     } elsif ($itemserror) {
 1654:         $r->print('<tr class="LC_empty_row"><td>'.$itemserror.'</td></tr>');
 1655:     } else {
 1656:         $r->print('<tr class="LC_empty_row"><td>'.$lt{'nopr'}.'</td></tr>');
 1657:     }
 1658: }
 1659: 
 1660: sub display_haserrors {
 1661:     my ($r,$bombs,$bombed,$res_title,$itemserror) = @_;
 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) {
 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>');
 1672:         @{$bombs} = sort { &cmp_title($a,$b,$res_title) } @{$bombs};
 1673:         foreach my $bomb (@{$bombs}) {
 1674:             $bombnum ++;
 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>');
 1679:         }
 1680:     } elsif ($itemserror) {
 1681:         $r->print('<tr class="LC_empty_row"><td>'.$itemserror.'</td></tr>');
 1682:     } else {
 1683:         $r->print('<tr class="LC_empty_row"><td>'.$lt{'noer'}.'</td></tr>');
 1684:     }
 1685:     return;
 1686: }
 1687: 
 1688: sub display_abovethreshold {
 1689:     my ($r,$refpage,$warnings,$triggered,$res_title,$itemserror,$checkallowed) = @_;
 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};
 1703:         $r->print('<tr class="LC_info_row">'.
 1704: 		  '<td class="LC_left_item">'.$lt{'reso'}.
 1705:                   '<input type="hidden" name="command" value="" /></td>'.
 1706: 		  '<td>'.$lt{'part'}.'</td><td>'.$lt{'nust'}.'</td>'.
 1707: 		  '<td>'.$lt{'avat'}.'</td><td>'.$lt{'dedi'}.'</td>'.
 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>');
 1713: 	my $row;
 1714:         foreach my $res (@{$warnings}) {
 1715: 	    $row++;
 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:             }
 1722:             $linkurl .= '?symb='.&escape($res);
 1723:             if ($$triggered{$res}{'enclink'}) {
 1724:                 $linkurl = 
 1725:                   $$triggered{$res}{'enclink'}.'?symb='.$$triggered{$res}{'encsymb'};
 1726:             }
 1727:             my $css_class = $row%2?' class="LC_odd_row"':'';
 1728:             $r->print('<tr'.$css_class.'>'.
 1729: 		      '<td class="LC_first_item" '.$rowspan.'><a href="'.$linkurl.'">'.
 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++) {
 1738:                         $r->print('<tr '.$css_class.'>'.
 1739:                                   $$triggered{$res}{text}[$i].'</tr>');
 1740:                     }
 1741:                 }
 1742:             }
 1743:         }
 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:         }
 1747:     } elsif ($itemserror) {
 1748:         $r->print('<tr class="LC_empty_row"><td>'.$itemserror.'</td></tr>');
 1749:     } else {
 1750:         $r->print('<tr class="LC_empty_row"><td>'.$lt{'nopr'}.'</td></tr>');
 1751:     }
 1752: }
 1753: 
 1754: sub display_versionchanges {
 1755:     my ($r,$changed,$res_title,$interval,$itemserror) = @_;
 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) {
 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>');
 1767:         my @changes = sort { &cmp_title($a,$b,$res_title) } keys(%{$changed});
 1768:         my $changenum = 0;
 1769:         foreach my $item (@changes) {
 1770:             $changenum ++;
 1771:             my $css_class = $changenum%2?' class="LC_odd_row"':'';
 1772:             my ($map,$id,$url)=&Apache::lonnet::decode_symb($item);
 1773:             my $linkurl=&Apache::lonnet::clutter($url);
 1774:             $linkurl .= '?symb='.&escape($item);
 1775: 
 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>');
 1781:         }
 1782:     } elsif ($itemserror) {
 1783:         $r->print('<tr class="LC_empty_row"><td>'.$itemserror.'</td></tr>');
 1784:     } else {
 1785:         $r->print('<tr class="LC_empty_row"><td>'
 1786:                  .&mt('No '.$interval).'</td></tr>');
 1787:     }
 1788:     return;
 1789: }
 1790: 
 1791: sub display_rolechanges {
 1792:     my ($r,$chgcount,$changed,$interval,$crstype,$classlist) = @_;
 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;
 1811:             my $fullnameidx = &Apache::loncoursedata::CL_FULLNAME();
 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"':'';
 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:                             }
 1835:                             my $link = 
 1836:                                 &Apache::loncommon::aboutmewrapper($fullname,$uname,$udom);
 1837:                             $r->print('<tr'.$css_class.'>'.
 1838:                                       '<td>'.&Apache::lonlocal::locallocaltime($item).'</td>'.
 1839:                                       '<td>'.$link.'</td>'.
 1840:                                       '<td>'.$role.'</td>'.
 1841:                                       '<td>'.$section.'</td>'.
 1842:                                       '<td>'.$status.'</td></tr>');
 1843:                         }
 1844:                     }
 1845:                 }
 1846:             }
 1847:         }
 1848:     } else {
 1849:         $r->print('<tr class="LC_empty_row"><td>'
 1850:                  .&mt('There are no '.$interval).'</td></tr>');
 1851:     }
 1852:     return;
 1853: }
 1854: 
 1855: sub display_crslogins {
 1856:     my ($r,$logincount,$loggedin,$interval,$crstype,$classlist) = @_;
 1857:     return unless (ref($classlist) eq 'HASH');
 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;
 1878:             my $fullnameidx = &Apache::loncoursedata::CL_FULLNAME();
 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'};
 1895:                             my $fullname;
 1896:                             if (ref($classlist->{$uname.':'.$udom}) eq 'ARRAY') {
 1897:                                 $fullname = $classlist->{$uname.':'.$udom}->[$fullnameidx];
 1898:                             } else {
 1899:                                 $fullname = &Apache::loncommon::plainname($uname,$udom,'lastname');
 1900:                             }
 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: }
 1947:  
 1948: sub display_coursediscussion {
 1949:     my ($r,$newdiscussions,$unread,$countunread,$res_title,$itemserror) = @_;
 1950:     my $lctype = lc(&Apache::loncommon::course_type());
 1951:     my %lt = &Apache::lonlocal::texthash(
 1952:                 'loca' => 'Location',
 1953:                 'type' => 'Type',
 1954:                 'numn' => 'Number of new posts',
 1955:                 'noun' => 'No unread posts in '.$lctype.' discussions',
 1956:                 'tmlp' => 'Time of last post', 
 1957:     );
 1958:     if (@{$newdiscussions} > 0) {
 1959:         $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
 1960:                   $lt{'loca'}.'</td><td>'.
 1961:                   $lt{'type'}.'</td>');
 1962:         if ($countunread eq 'on') {
 1963:             $r->print('<td>'.$lt{'tmlp'}.'</td>'.
 1964:                       '<td class="LC_right_item">'.$lt{'numn'}.'</td>');
 1965:         } else {
 1966:             $r->print('<td class="LC_right_item">'.$lt{'tmlp'}.'</td>');
 1967:         }
 1968:         $r->print("</tr>\n");
 1969:         @{$newdiscussions} = sort { &cmp_title($a,$b,$res_title) }
 1970:                                                             @{$newdiscussions};
 1971:         my $rowNum = 0;
 1972:         foreach my $ressymb (@{$newdiscussions}) {
 1973:             $rowNum ++;
 1974:             my $forum_title = $$unread{$ressymb}{'title'};
 1975:             my $type = 'Resource';
 1976:             my $feedurl=&Apache::lonfeedback::get_feedurl($ressymb);
 1977:             my $disclink = $feedurl.'?symb='.&escape($$unread{$ressymb}{symb});
 1978:             if ($feedurl =~ /bulletinboard/) {
 1979:                 $type = 'Discussion Board';
 1980:             }
 1981:             if ($$unread{$ressymb}{'enclink'}) {
 1982:                 $disclink = $$unread{$ressymb}{'enclink'}.'?symb='.$$unread{$ressymb}{'encsymb'};
 1983:             }
 1984:             my $css_class = $rowNum%2?' class="LC_odd_row"':'';
 1985:             my $lastpost = &Apache::lonnavmaps::timeToHumanString(
 1986:                                                $$unread{$ressymb}{'lastpost'});
 1987:             $r->print('<tr'.$css_class.'><td><a href="'.$disclink.'">'.$forum_title.'</a>&nbsp;</td><td>'.&mt($type).'&nbsp;</td>');
 1988:             if ($countunread eq 'on') {
 1989:                 my $unreadnum = $$unread{$ressymb}{'unreadcount'};
 1990:                 $r->print('<td>'.$lastpost.'</td><td class="LC_right_item">'.
 1991:                           $unreadnum.'&nbsp;</td>');
 1992:             } else {
 1993:                 $r->print('<td class="LC_right_item">'.$lastpost.'</td>');
 1994:             }
 1995:             $r->print("</tr>\n");
 1996:         }
 1997:     } elsif ($itemserror) {
 1998:         $r->print('<tr class="LC_empty_row"><td>'.$itemserror.'</td></tr>');
 1999:     } else {
 2000:         $r->print('<tr class="LC_empty_row"><td>'.$lt{'noun'}.'</td></tr>');
 2001:     }
 2002: }
 2003: 
 2004: sub display_coursenormalmail {
 2005:     my ($r,$msgcount,$newmsgs) = @_;
 2006:     my $lctype = lc(&Apache::loncommon::course_type());
 2007:     if ($msgcount > 0) {
 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;
 2013:         foreach my $msg (@{$newmsgs}) {
 2014:             $mailcount ++;
 2015:             my $css_class = $mailcount%2?' class="LC_odd_row"':'';
 2016:             $r->print('<tr'.$css_class.'><td>'.$mailcount
 2017:                       .'.&nbsp;</td><td><a href="/adm/email?display='
 2018:                       .$msg->{'msgid'}.'">'
 2019:                       .$msg->{'shortsub'}.'</a>&nbsp;&nbsp;</td><td>&nbsp;'
 2020:                       .$msg->{'from'}.':'.$msg->{'fromdom'}.'&nbsp;</td><td>'
 2021:                       .$msg->{'sendtime'}.'</td></tr>');
 2022:         }
 2023:     } else {
 2024:         $r->print('<tr class="LC_empty_row"><td>'.
 2025:                   &mt('No new '.$lctype.' messages').'</td></tr>');
 2026:     }
 2027: }
 2028: 
 2029: sub display_coursecritmail {
 2030:     my ($r,$critmsgcount,$critmsgs) = @_;
 2031:     my $lctype = lc(&Apache::loncommon::course_type());
 2032:     if ($critmsgcount > 0) {
 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;
 2038:         foreach my $msg (@{$critmsgs}) {
 2039:             $mailcount ++;
 2040:             my $css_class = $mailcount%2?' class="LC_odd_row"':'';
 2041:             $r->print('<tr'.$css_class.'><td>'.$mailcount.
 2042:                       '. &nbsp;</td><td><a href="/adm/email?folder=critical">'.
 2043:                       $msg->{'shortsub'}.'</a>&nbsp; &nbsp;</td><td>&nbsp;'.
 2044:                       $msg->{'from'}.':'.$msg->{'fromdom'}.'&nbsp;</td><td>'.
 2045:                       $msg->{'sendtime'}.'</td></tr>');
 2046:         }
 2047:     } else {
 2048:         $r->print('<tr class="LC_empty_row"><td>'.
 2049:                   &mt('No unread critical messages in '.$lctype).
 2050:                   '</td></tr>');
 2051:     }
 2052: }
 2053: 
 2054: sub cmp_title {
 2055:     my ($a,$b,$res_title) = @_;
 2056:     my ($atitle,$btitle) = (lc($$res_title{$a}),lc($$res_title{$b}));
 2057:     $atitle=~s/^\s*//;
 2058:     $btitle=~s/^\s*//;
 2059:     return $atitle cmp $btitle;
 2060: }
 2061: 
 2062: sub get_display_settings {
 2063:     my ($uname,$udom,$cid) = @_;
 2064:     my %settings = &Apache::lonnet::dump('nohist_whatsnew',$udom,$uname,$cid); 
 2065:     my ($tmp) = keys(%settings);
 2066:     if ($tmp=~ /^(con_lost|error|no_such_host)/i) {
 2067:         %settings = ();
 2068:         unless ($tmp =~ /^error: 2 /) {
 2069: 	    my $lctype = lc(&Apache::loncommon::course_type());
 2070:             &Apache::lonnet::logthis('Error retrieving whatsnew settings: '.
 2071:             $tmp.' for '.$uname.':'.$udom.' for '.$lctype.': '.$cid);
 2072:         }
 2073:     }
 2074:     return %settings;
 2075: }
 2076: 
 2077: sub store_display_settings {
 2078:     my ($uname,$udom,$cid,$checkallowed) = @_;
 2079:     my %whatsnew_settings;
 2080:     my $result;
 2081:     foreach my $key (keys(%{$checkallowed})) {
 2082: 	if ($key =~ /_section$/) { next; }
 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;
 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'};
 2108:         } elsif ($context eq 'crslogin') {
 2109:             $interval_settings{$cid.':crslogininterval'} = $env{'form.interval'};
 2110:         } else {
 2111:             $interval_settings{$cid.':interval'} = $env{'form.interval'};
 2112:         }
 2113:         my $outcome = &Apache::lonnet::put('nohist_whatsnew',
 2114:                                              \%interval_settings,$udom,$uname);
 2115:         if ($outcome eq 'ok') {
 2116:             if (ref($interval_titles->{$context}) eq 'HASH') {
 2117:                 $result = &Apache::lonhtmlcommon::confirm_success(&mt('New filter setting: [_1].','<b>'. 
 2118:                               $interval_titles->{$context}->{$env{'form.interval'}}.'</b>').'<br />');
 2119:             }
 2120:         } else {
 2121: 	    my $lctype = lc(&Apache::loncommon::course_type());
 2122:             &Apache::lonnet::logthis('Error saving whatsnew '.$context.' interval setting'.
 2123:                 ' '.$outcome.' for '.$uname.':'.$udom.' in '.$lctype.' '.$cid);
 2124:             $result = &Apache::lonhtmlcommon::confirm_success(&mt('Unable to set interval to [_1] due to [_2].',
 2125:                          '<b>'.$interval_titles->{$context}->{$env{'form.interval'}}.'</b>',
 2126:                          '<tt>'.$outcome.'</tt>'),1);
 2127:         }
 2128:     }
 2129:     return &Apache::loncommon::confirmwrapper($result);
 2130: }
 2131: 
 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') {
 2141:             $result = &Apache::lonhtmlcommon::confirm_success(&mt('Count unread posts in discussions display set to [_1]',
 2142:                   '<b>'.&mt($env{'form.countunread'}).'</b>').'<br />');
 2143:                                                                                   
 2144:         } else {
 2145: 	    my $lctype = lc(&Apache::loncommon::course_type());
 2146:             &Apache::lonnet::logthis('Error saving whatsnew countunread setting'.
 2147:                 ' '.$outcome.' for '.$uname.':'.$udom.' in '.$lctype.' '.$cid);
 2148:             $result = &Apache::lonhtmlcommon::confirm_success(&mt('Unable to set "number unread posts display" to [_1]'.
 2149:                           ' due to [_2].',
 2150:                          '<b>'.&mt($env{'form.countunread'}).'</b>',
 2151:                          '<tt>'.$outcome.'</tt>'),1);
 2152:         }
 2153:     }
 2154:     return &Apache::loncommon::confirmwrapper($result);
 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) {
 2174: 	    my $lctype = lc(&Apache::loncommon::course_type());
 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') {
 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>'));
 2180:                 } else {
 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>'));
 2183:                 }
 2184:             } else {
 2185:                 &Apache::lonnet::logthis('Error saving whatsnew courseinit '.
 2186:                                          'setting: '.$outcome.' for '.$uname.
 2187:                                          ':'.$udom.' in '.$lctype.' '.$cid);
 2188:                 if ($page_control eq 'global preferences') {
 2189:                     $result = &Apache::lonhtmlcommon::confirm_success(&mt('Unable to set control of page display to [_1]'.
 2190:                           ' due to [_2].',
 2191:                          '<b>'.$page_control.'</b>',
 2192:                          '<tt>'.$outcome.'</tt>'),1);
 2193:                 } else {
 2194:                     $result = &Apache::lonhtmlcommon::confirm_success(&mt('Unable to set page display, after role selection, for this '.$lctype.' to [_1] due to [_2].'
 2195:                                  ,'<b>'.$$initpage{$env{'form.courseinit_page'}}.'</b>'
 2196:                                  ,'<tt>'.$outcome.'</tt>'),1);
 2197:                 }
 2198:             }
 2199:         }
 2200:     }
 2201:     return &Apache::loncommon::confirmwrapper($result);
 2202: }
 2203: 
 2204: sub start_box {
 2205:     my ($r,$show,$heading,$caller,$refpage) = @_;
 2206:     my %lt = &Apache::lonlocal::texthash( 
 2207:                        chth => 'Change thresholds?',
 2208:                        chin => 'Change interval?',
 2209:                        chop => 'Change options?',
 2210:     );
 2211:     my $showhide;
 2212:     if ($$show{$caller}) {
 2213:         $showhide = '<b><a href="javascript:change_display(document.visible.'.
 2214:                                'display_'.$caller.",'hide'".');">'.
 2215:                                &mt('Hide').'</a></b>';
 2216:    
 2217:     } else {
 2218:         $showhide = '<b><a href="javascript:change_display(document.visible.'.
 2219:                                'display_'.$caller.",'show'".');">'.
 2220:                                &mt('Show').'</a></b>';
 2221:     }
 2222:     
 2223:     $r->print('
 2224:          <table class="LC_nested_outer">
 2225:           <tr>
 2226:            <th class="LC_left_item">'.$$heading{$caller}.'</th>
 2227:            <th class="LC_right_item">'.$showhide.'</th>
 2228:           </tr>');
 2229:      if (($caller eq 'abovethreshold') && ($$show{$caller})) {
 2230:          if ($$show{$caller}) {
 2231:              $r->print('
 2232:               <tr>
 2233:                 <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgthreshold&amp;refpage='.$refpage.'">'.$lt{'chth'}.'</a></td>
 2234:               </tr>');
 2235:          }
 2236:      } elsif (($caller eq 'versionchanges') && ($$show{$caller})) {
 2237:          if ($$show{$caller}) {
 2238:              $r->print('
 2239:               <tr>
 2240:                 <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chginterval&amp;refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
 2241:               </tr>');
 2242:          }
 2243:      } elsif ($caller eq 'coursediscussion') {
 2244:          if ($$show{$caller}) {
 2245:              $r->print('
 2246:               <tr>
 2247:                 <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgdisc&amp;refpage='.$refpage.'">'.$lt{'chop'}.'</a></td>
 2248:               </tr>');
 2249:          }
 2250:      } elsif (($caller eq 'newroles') && ($$show{$caller})) {
 2251:          if ($$show{$caller}) {
 2252:              $r->print('
 2253:               <tr>
 2254:                 <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgnewroleinterval&amp;refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
 2255:               </tr>');
 2256:          }
 2257:      } elsif (($caller eq 'oldroles') && ($$show{$caller})) {
 2258:          if ($$show{$caller}) {
 2259:              $r->print('
 2260:               <tr>
 2261:                 <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgoldroleinterval&amp;refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
 2262:               </tr>');
 2263:          }
 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();" />&nbsp;'.&mt('Summary').'</label><label><input type="radio" name="logindetails" value="1" onclick="javascript:togglelogins();" />&nbsp;'.&mt('Details').'</label></span></td><td class="LC_subheader"><a href="/adm/whatsnew?command=chgcrslogininterval&amp;refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
 2269:               </tr>');
 2270:         }
 2271:     }
 2272: 
 2273:     $r->print('
 2274:               <tr>
 2275:                <td colspan="2">
 2276:                 <table class="LC_nested">
 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: 
 2291: 1;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>