File:  [LON-CAPA] / loncom / interface / lonwhatsnew.pm
Revision 1.77: download - view: text, annotated - select for diffs
Wed Apr 30 23:52:00 2008 UTC (16 years, 1 month ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Bug 5176. Record of role changes in a course in nohist_rolelog.db
- Display roles which became active in a course during a specified time interval.
- Display roles which expired in a course during a specified time interval.
- Some wording changes for "version changes" display/interval setting.
- Replace partial phrases with complete phrases to aid internationalization.
- Number of boxes displayed in left column fixed (at four).

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

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