File:  [LON-CAPA] / loncom / interface / lonwhatsnew.pm
Revision 1.41: download - view: text, annotated - select for diffs
Thu Dec 22 02:38:44 2005 UTC (18 years, 6 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Fix bug 4514.

    1: #
    2: # $Id: lonwhatsnew.pm,v 1.41 2005/12/22 02:38:44 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::Constants qw(:common :http);
   40: use Time::Local;
   41: use GDBM_File;
   42: 
   43: #----------------------------
   44: # handler
   45: #
   46: #----------------------------
   47: 
   48: sub handler {
   49:     my $r = shift;
   50:     if ($r->header_only) {
   51:         &Apache::loncommon::content_type($r,'text/html');
   52:         $r->send_http_header;
   53:         return OK;
   54:     }
   55:     &Apache::loncommon::get_unprocessed_cgi(
   56:                                    $ENV{'QUERY_STRING'},['command','refpage']);
   57: 
   58:     my $command = $env{'form.command'};
   59:     my $refpage = $env{'form.refpage'};
   60: 
   61:     &Apache::loncommon::content_type($r,'text/html');
   62:     $r->send_http_header;
   63:     my $crsid = $env{'request.course.id'};
   64:     $crsid =~ s/_/\//; 
   65:     if ((!($env{'request.course.id'})) || 
   66:                              ($env{'request.role'} !~ /\Q$crsid\E$/)) {
   67:         # Not in a course, or no role in course
   68:         $env{'user.error.msg'}="/adm/whatsnew::0:0:Cannot display what's new screen";
   69:         return HTTP_NOT_ACCEPTABLE;
   70:     }
   71: 
   72:     my %checkallowed = (
   73:              coursediscussion => &Apache::lonnet::allowed('pch',$env{'request.course.id'}),
   74:              handgrading => &Apache::lonnet::allowed('mgr',$env{'request.course.id'}),
   75:              abovethreshold => &Apache::lonnet::allowed('vgr',$env{'request.course.id'}),
   76:              haserrors => &Apache::lonnet::allowed('opa',$env{'request.course.id'}),
   77:              versionchanges => &Apache::lonnet::allowed('opa',$env{'request.course.id'}),
   78:              coursenormalmail => 1,
   79:              coursecritmail => 1,
   80:     );
   81: 
   82:     $r->print(&display_header($command,\%checkallowed));
   83: 
   84:     &Apache::lonhtmlcommon::clear_breadcrumbs();
   85:     &Apache::lonhtmlcommon::add_breadcrumb
   86:             ({href=>'/adm/whatsnew',
   87:               text=>"Display Action Items"});
   88:     if (($command eq 'chgthreshold') && (&Apache::lonnet::allowed('vgr',$env{'request.course.id'}))) {
   89:         &Apache::lonhtmlcommon::add_breadcrumb
   90:             ({href=>'/adm/whatsnew?command=chgthreshold&refpage='.$refpage,
   91:               text=>"Change thresholds"});
   92:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
   93:             (undef,"What's New?",'Course_Action_Items_Thresholds'));
   94:     } elsif (($command eq 'chginterval') && (&Apache::lonnet::allowed('vgr',$env{'request.course.id'}))) {
   95:         &Apache::lonhtmlcommon::add_breadcrumb
   96:             ({href=>'/adm/whatsnew?command=chginterval&refpage='.$refpage,
   97:               text=>"Change interval"});
   98:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
   99:             (undef,"What's New?",'Course_Action_Items_Intervals'));
  100:     } elsif (($command eq 'chgdisc') && (&Apache::lonnet::allowed('pch',$env{'request.course.id'}))) {
  101:         &Apache::lonhtmlcommon::add_breadcrumb
  102:             ({href=>'/adm/whatsnew?command=chgdisc&refpage='.$refpage,
  103:               text=>"Change discussion display"});
  104:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
  105:             (undef,"What's New?",'Course_Action_Items_Intervals'));
  106:     } elsif ($command eq 'courseinit') {
  107:         &Apache::lonhtmlcommon::add_breadcrumb
  108:             ({href=>'/adm/whatsnew?command=courseinit&refpage='.$refpage,
  109:               text=>"Course initialization preference"});
  110:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
  111:             (undef,"What's New?",'Course_Action_Items_Initialization'));
  112:     } else {
  113:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
  114:             (undef,"What's New?",'Course_Action_Items_Display'));
  115:     }
  116:     &display_main_box($r,$command,$refpage,\%checkallowed);
  117:     return OK;
  118: }
  119: 
  120: #------------------------------
  121: # display_main_box
  122: #
  123: # Display all the elements within the main box
  124: #------------------------------
  125:                                                                                 
  126: sub display_main_box {
  127:     my ($r,$command,$refpage,$checkallowed) = @_;
  128:     my $domain=&Apache::loncommon::determinedomain();
  129:     my $function = &Apache::loncommon::get_users_function();
  130:     my $tabbg=&Apache::loncommon::designparm($function.'.tabbg',$domain);
  131:     $r->print('<table width="100%" border="0" cellpadding="5" cellspacing="0"><tr><td width="100%">');
  132: 
  133:     my %threshold_titles = &Apache::lonlocal::texthash (
  134:                          av_attempts => 'Average number of attempts',
  135:                          degdiff => 'Degree of difficulty',
  136:                          numstudents => 'Total number of students with submissions',
  137:     );
  138: 
  139:     my %interval_titles = &Apache::lonlocal::texthash (
  140:                             -1 => 'since start of course',
  141:                        2592000 => 'since last month',
  142:                         604800 => 'since last week',
  143:                          86400 => 'since yesterday',
  144:     );
  145: 
  146:     my %initpage = &Apache::lonlocal::texthash (
  147:                      firstres => 'first resource in the course',
  148:                      whatsnew => "what's new? page",
  149:                      userpref => 'your general user preferences',
  150:                      coursespecific => 'specific setting for this course',
  151:                    );
  152:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  153:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
  154: 
  155:     if (($command eq 'chgthreshold') && 
  156:                (&Apache::lonnet::allowed('vgr',$env{'request.course.id'}))) {
  157:         &display_threshold_config($r,$refpage,$tabbg,\%threshold_titles,
  158:                                                                    $cdom,$crs);
  159:     } elsif (($command eq 'chginterval') && 
  160:                (&Apache::lonnet::allowed('opa',$env{'request.course.id'}))) {
  161:         &display_interval_config($r,$refpage,\%interval_titles);
  162:     } elsif (($command eq 'chgdisc') && 
  163:                (&Apache::lonnet::allowed('pch',$env{'request.course.id'}))) {
  164:         &display_discussion_config($r,$refpage);
  165:     } elsif ($command eq 'courseinit') {
  166:         &courseinit_config($r,$refpage,\%initpage);
  167:     } else {
  168:         &display_actions_box($r,$tabbg,$command,$refpage,\%threshold_titles,
  169:                         \%interval_titles,\%initpage,$cdom,$crs,$checkallowed);
  170:     }
  171:     $r->print(<<END_OF_BLOCK);
  172:   </td>
  173:  </tr>
  174: </table><br />
  175: </body>
  176: </html>
  177: END_OF_BLOCK
  178: }
  179: 
  180: #-------------------------------
  181: # display_header
  182: #
  183: # Display the header information and set
  184: # up the HTML
  185: #-------------------------------
  186: 
  187: sub display_header {
  188:     my ($command,$checkallowed) = @_;
  189:     my $html=&Apache::lonxml::xmlbegin();
  190:     my $bodytag=&Apache::loncommon::bodytag('Course Action Items');
  191:     my $scripttag;
  192:     unless ($command eq 'chgthreshold' || $command eq 'chginterval') {
  193:        $scripttag = <<"END";
  194: <script type="text/javascript">
  195: function change_display(caller,change) {
  196:     caller.value = change;
  197:     document.visible.submit(); 
  198: }
  199: 
  200: function changeAll(change) {
  201: END
  202:         foreach my $item (keys(%{$checkallowed})) {
  203:             if ($$checkallowed{$item}) {
  204:                 $scripttag.='document.visible.display_'.$item.'.value=change'.
  205:                             "\n";
  206:             }
  207:         }
  208:         $scripttag.='document.visible.submit();
  209: }
  210: </script>
  211: ';
  212:     }
  213:     return(<<ENDHEAD);
  214: $html
  215: <head>
  216: <title>Course Action Items</title>
  217: $scripttag
  218: </head>
  219: $bodytag
  220: ENDHEAD
  221: }
  222: 
  223: #-------------------------------
  224: # display_actions_box
  225: #
  226: # Display the action items
  227: #
  228: #-------------------------------
  229:                                                                                 
  230: sub display_actions_box {
  231:     my ($r,$tabbg,$command,$refpage,$threshold_titles,$interval_titles,
  232:                                       $initpage,$cdom,$crs,$checkallowed) = @_;
  233:     my $rowColor1 = "#ffffff";
  234:     my $rowColor2 = "#eeeeee";
  235: 
  236:     my $udom = $env{'user.domain'};
  237:     my $uname = $env{'user.name'};
  238:     my $cid = $env{'request.course.id'};
  239: 
  240:     my %lt = &Apache::lonlocal::texthash(
  241:                  'yacc' => 'You are accessing an invalid course.',
  242:                  'gtfr' => 'Go to first resource',
  243:                  'pgse' => 'Page set to be displayed after you have selected a role in this course?',
  244:                  'hial' => 'Hide all',
  245:                  'shal' => 'Show all',
  246:     );
  247: 
  248:     my %unread = ();
  249:     my %ungraded = ();
  250:     my %bombed = ();
  251:     my %triggered = ();
  252:     my %changed = ();
  253:     my @newmsgs = ();
  254:     my @critmsgs = ();
  255:     my @newdiscussions = ();
  256:     my @tograde = ();
  257:     my @bombs = ();
  258:     my @warnings = ();
  259:     my $msgcount = 0;
  260:     my $critmsgcount = 0;
  261: 
  262:     my %res_title = ();
  263:     my %show = ();
  264:     my $needitems = 0;
  265:     my $boxcount = 0;
  266: 
  267:     my $result;
  268:     if ($command eq 'newcourseinit') {
  269:         $result = &store_courseinit_setting($uname,$udom,$cid,$initpage);
  270:     }
  271: 
  272:     my %threshold = (
  273:                       av_attempts => 2,
  274:                       degdiff => 0.5,
  275:                       numstudents => 2,
  276:                      );
  277:     my %pagedesc = &Apache::lonlocal::texthash (
  278:                      firstres => 'First resource',
  279:                      whatsnew => "What's New? page",
  280:                      userpref => 'user preference',
  281:                      coursespecific => 'course only',
  282:                      default => 'default',
  283:                    );
  284: 
  285:     my ($initcontrol,$initdisp) = &curr_courseinit();
  286:     my $currinit = $pagedesc{$initdisp}.' ('.$pagedesc{$initcontrol}.')';
  287: 
  288:     unless ($cid) {
  289:         $r->print('<br /><b><center>'.$lt{'yacc'}.'</center></b><br /><br />');
  290:         return;
  291:     }
  292: 
  293:     if ($refpage eq 'start') {
  294:         if (tie(my %bighash,'GDBM_File',$env{'request.course.fn'}.'.db',
  295:             &GDBM_READER(),0640)) {
  296:             my $furl=$bighash{'first_url'};
  297:             untie(%bighash);
  298:             $r->print('<font size="+1"><a href="'.$furl.'">'.$lt{'gtfr'}.
  299:                   '</a></font><br />');
  300:         }
  301:     }
  302:     $r->print($lt{'pgse'}.' '.&mt('Currently: [_1]','<i>'.$currinit.'</i>').
  303:               '<nobr>&nbsp;&nbsp;'.&mt('[_1] for just [_2]','<b>Change</b>',
  304:               '<a href="/adm/whatsnew?command=courseinit&refpage='.$refpage.
  305:               '">this course</a>').' '.&mt('or for all [_1].',
  306:               '<a href="/adm/preferences?action=changecourseinit&refpage='.
  307:               $refpage.'">your courses</a>').'</nobr><br /><hr />');
  308:                                                                                         
  309:     if ($command eq 'reset') {
  310:         $result = &process_reset($cdom,$crs);
  311:     } elsif ($command eq 'update') {
  312:         $result = &process_update($uname,$udom,$threshold_titles);
  313:     } elsif ($command eq 'newinterval') {
  314:         $result = &store_interval_setting($uname,$udom,$cid,$interval_titles);
  315:     } elsif ($command eq 'newdiscconf') {
  316:         $result = &store_discussion_setting($uname,$udom,$cid);
  317:     }
  318: 
  319:     my $store_result=&store_display_settings($uname,$udom,$cid,$checkallowed);
  320: 
  321:     unless ($store_result eq 'ok') { 
  322:         &Apache::lonnet::logthis('Error storing whatsnew settings: '.
  323:             $store_result.' for '.'user '.$uname.':'.$udom.' in course '.$cid);
  324:         $result .= &mt('Unable to store visibility settings due to [_1]',
  325:                        $store_result); 
  326:     }
  327: 
  328:     if ($result) {
  329:         $r->print($result.'<hr width="100%" />');
  330:     }
  331:     $r->rflush();
  332: 
  333: 
  334:     my %display_settings = &get_display_settings($uname,$udom,$cid);
  335:     my $timediff = $display_settings{$cid.':interval'};
  336:     unless (defined($timediff)) { $timediff = 604800; } 
  337:     my $now = time;
  338:     my $interval = $$interval_titles{$timediff};
  339:     if ($timediff == -1) {
  340:         $timediff = time;
  341:     } 
  342:     my $starttime = $now - $timediff;
  343:     my $countunread = $display_settings{$cid.':countunread'};
  344:     unless (defined($countunread)) {
  345:         $countunread = 'on';
  346:     }
  347: 
  348:     my %headings = &Apache::lonlocal::texthash(
  349:                 coursediscussion =>  'Unread course discussion posts',
  350:                 handgrading =>  'Problems requiring handgrading',
  351:                 haserrors => 'Problems with errors',
  352:                 versionchanges => 'Resources in course with version changes '.$interval,
  353:                 coursenormalmail => 'New course messages',
  354:                 coursecritmail => 'New critical messages in course',
  355:     );
  356: 
  357:     if ($$checkallowed{'abovethreshold'}) {
  358:         &get_curr_thresholds(\%threshold,$uname,$udom,$cid,$cdom,$crs);
  359:     }
  360: 
  361:     $headings{'abovethreshold'} = &mt('Problems with av. attempts').' &ge; '.$threshold{'av_attempts'}.' '.&mt('or deg. difficulty').' &ge; '.$threshold{'degdiff'}.'<br /> '.&mt('and total number of students with submissions').' &ge; '.$threshold{'numstudents'};
  362: 
  363:     my @actionorder = ('handgrading','haserrors','abovethreshold','versionchanges','coursediscussion','coursenormalmail','coursecritmail');
  364: 
  365:     foreach my $key (keys(%{$checkallowed})) {
  366:         $show{$key} = 0;
  367:         if ($$checkallowed{$key}) {
  368:             unless ($display_settings{$cid.':'.$key} eq 'hide') {
  369:                 $show{$key} = 1;
  370:             }
  371:         }
  372:     }
  373: 
  374:     foreach my $item (@actionorder) {
  375:         unless ($item eq 'coursenormalmail' || $item eq 'coursecritmail') {
  376:             if ($show{$item}) {
  377:                 $needitems = 1;
  378:                 last;
  379:             }
  380:         }
  381:     }
  382: 
  383:     if ($needitems) {
  384:         &getitems(\%unread,\%ungraded,\%bombed,\%triggered,\%changed,\@newdiscussions,\@tograde,\@bombs,\@warnings,$rowColor1,$rowColor2,\%threshold,$cdom,$crs,\%res_title,\%show,$starttime,$countunread);
  385:     }
  386:     if ($show{'coursenormalmail'}) {
  387:         &getnormalmail(\@newmsgs);
  388:     }
  389:     if ($show{'coursecritmail'}) {
  390:         &getcritmail(\@critmsgs);
  391:     }
  392: 
  393:     $r->print(qq|<a href="javascript:changeAll('hide');">$lt{'hial'}</a>
  394:      &nbsp;&nbsp;<a href="javascript:changeAll('show');">$lt{'shal'}</a>
  395:      <form method="post" name="visible" action="/adm/whatsnew">\n|);
  396:     foreach my $item (keys(%{$checkallowed})) {
  397:         if ($$checkallowed{$item}) {
  398:             $r->print('<input type="hidden" name="display_'.$item.'" />'."\n");
  399:         }
  400:     }
  401: 
  402:     $r->print('<input type="hidden" name="refpage" value="'.$refpage.'"></form><br /><table border="0" width="100%" cellpadding="2" cellspacing="4"><tr><td align="left" valign="top" width="45%">');
  403: 
  404:     my $displayed = 0;
  405:     my $totalboxes = 0;
  406:     foreach my $key (keys(%{$checkallowed})) {
  407:         if ($$checkallowed{$key}) {
  408:             $totalboxes ++;
  409:         }
  410:     }
  411:     my $halfway = int($totalboxes/2) + $totalboxes%2;
  412:     foreach my $actionitem (@actionorder) {
  413:         if ($$checkallowed{$actionitem}) {
  414:             if ($displayed == $halfway) {
  415:                 $r->print('</td><td width="6%">&nbsp;</td><td align="left" valign="top" width="47%">');
  416:             }
  417:             &display_launcher($r,$actionitem,$refpage,$checkallowed,$tabbg,$rowColor1,$rowColor2,\%show,\%headings,\%res_title,\@tograde,\%ungraded,\@bombs,\%bombed,\%changed,\@warnings,\%triggered,\@newdiscussions,\%unread,$msgcount,\@newmsgs,$critmsgcount,\@critmsgs,$interval,$countunread);
  418:             $displayed ++; 
  419:         }
  420:     }
  421:     $r->print('
  422:            </table>
  423:           </td>
  424:          </tr>
  425:         </table>
  426:       </td>
  427:     </tr>
  428:    </table>');
  429: }
  430: 
  431: #-------------------------------
  432: # display_threshold_config
  433: #
  434: # Display the threshold setting screen 
  435: #
  436: #-------------------------------
  437:                                                                                 
  438: sub display_threshold_config {
  439:     my ($r,$refpage,$tabbg,$threshold_titles,$cdom,$crs) = @_;
  440:     my $uname = $env{'user.name'};
  441:     my $udom = $env{'user.dom'};
  442:     my $cid = $env{'request.course.id'};
  443:     my %threshold = ();
  444:     my $rowColor1 = "#ffffff";
  445:     my $rowColor2 = "#eeeeee";
  446:     my $rowColor;
  447: 
  448:     my @thresholditems = ("av_attempts","degdiff","numstudents");
  449:     foreach my $item (@thresholditems) {
  450:         $threshold{$item} = '';
  451:     }
  452:     my %threshold_titles = &Apache::lonlocal::texthash(
  453:                          av_attempts => 'Average number of attempts',
  454:                          degdiff => 'Degree of difficulty',
  455:                          numstudents => 'Total number of students with submissions',
  456:                          );
  457:     &get_curr_thresholds(\%threshold,$uname,$udom,$cid,$cdom,$crs);
  458: 
  459:     $r->print('<br /><form name="thresholdform" method="post" action="/adm/whatsnew">
  460:         <table border="0" cellpadding="2" cellspacing="4">
  461:          <tr>
  462:           <td align="left" valign="top" width="45%">
  463:            <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
  464:             <tr>
  465:              <td>
  466:                <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000">
  467:                 <tr>
  468:                 <td bgcolor="#ffffff">
  469:                  <table cellspacing="0" cellpadding="4" border="0">
  470:      <tr bgcolor="'.$tabbg.'">
  471:       <th>Threshold Name</th>
  472:       <th>Current value</th>
  473:       <th>Change?</th>
  474:      </tr>');
  475:     my $rowNum =0;
  476:     foreach my $type (@thresholditems) {
  477:         my $parameter = $env{'request.course.id'}.':threshold_'.$type;
  478: # onchange is javascript to automatically check the 'Set' button.
  479:         my $onchange = 'onFocus="javascript:window.document.forms'.
  480:               "['thresholdform'].elements['".$parameter."_setparmval']".
  481:               '.checked=true;"';
  482:         if ($rowNum %2 == 1) {
  483:             $rowColor = $rowColor1;
  484:         } else {
  485:             $rowColor = $rowColor2;
  486:         }
  487:         $r->print('
  488:      <tr bgcolor="'.$rowColor.'">
  489:       <td>'.$threshold_titles{$type}.'</td>
  490:       <td>'.&Apache::lonhtmlcommon::textbox($parameter.'_value',
  491:                                             $threshold{$type},
  492:                                             10,$onchange).'</td>
  493:       <td>'
  494:            .&Apache::lonhtmlcommon::checkbox($parameter.'_setparmval').
  495:       '</td>
  496:      </tr>');
  497:         $rowNum ++;
  498:     }
  499:     $r->print('</table></td></tr></table></td></tr></table>
  500:            <br /><input type="submit" name="threshold" value="Make changes" />
  501:                  <input type="hidden" name="command" value="update" />
  502:                  <input type="hidden" name="refpage" value="'.$refpage.'" />
  503:                </form>');
  504: }
  505: 
  506: #-------------------------------
  507: # display_interval_config
  508: #
  509: # Display the interval setting screen
  510: #
  511: #-------------------------------
  512:                                                                                    
  513: sub display_interval_config {
  514:     my ($r,$refpage,$interval_titles) = @_;
  515:     my $current = &get_current($env{'user.name'},$env{'user.domain'},
  516:                                 $env{'request.course.id'},'interval');
  517:     $r->print('<br />'.&mt('Choose the time window to use for display of version changes for resources in the course.'));
  518:     unless ($current eq '') {
  519:         $r->print(' '.&mt('Current value is [_1]','<b>'.
  520:                   $$interval_titles{$current}.'</b>.'));
  521:     }
  522:     $r->print('<br /><br />
  523: <form method="post" name="intervalswitch" action="/adm/whatsnew">
  524: <input type="hidden" name="command" value="newinterval" />
  525: <input type="hidden" name="refpage" value="'.$refpage.'" />
  526: <select name="interval">
  527: ');
  528:     foreach my $key (reverse sort ({$a cmp $b} (keys(%{$interval_titles})))) {
  529:         $r->print('<option value="'.$key.'">Version changes '.$$interval_titles{$key}.
  530:                   '</option>'."\n");
  531:     }
  532:     $r->print('</select>&nbsp;&nbsp;
  533:                <input type="submit" name="display" value="'.
  534:                &mt('Change interval').'" /></form>');
  535:     return;
  536: }
  537: 
  538: #----------------------------------------------
  539: # display_discussion_config
  540: #
  541: # Display the discussion display setting screen
  542: #
  543: #----------------------------------------------
  544:                                                                                   
  545: sub display_discussion_config {
  546:     my ($r,$refpage) = @_;
  547:     my $current = &get_current($env{'user.name'},$env{'user.domain'},
  548:                                 $env{'request.course.id'},'countunread');
  549:     if ($current eq '') {
  550:         $current = 'on';
  551:     }
  552:     my %status = (
  553:                     on => 'checked="checked"',
  554:                     off => 'checked="checked"',
  555:                  );
  556:     $status{$current} = '';
  557:     $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 [_1] page by a few seconds.',"<i>What's New?</i>").'&nbsp;&nbsp;'.&mt('Currently set to [_1] .'),"<b>$current</b>.");
  558:     $r->print('<br /><br />
  559: <form method="post" name="discussionswitch" action="/adm/whatsnew">'.
  560: &mt('Display of unread post counts?').'&nbsp;
  561: <input type="hidden" name="command" value="newdiscconf" />
  562: <input type="hidden" name="refpage" value="'.$refpage.'" />
  563: <input type ="radio" '.$status{'on'}.' name="countunread" value="on">on
  564: &nbsp;&nbsp;&nbsp;
  565: <input type ="radio" '.$status{'off'}.' name="countunread" value="off">off
  566: ');
  567:     $r->print('<br/><br />
  568:                <input type="submit" name="display" value="'.
  569:                &mt('Make changes').'" /></form>');
  570:     return;
  571: }
  572: 
  573: #---------------------------------------------------
  574: # courseinit_config
  575: #
  576: # Set page displayed when course loads after 
  577: # selecting a role in the course from the roles page. 
  578: #
  579: #---------------------------------------------------
  580: 
  581: sub courseinit_config {
  582:     my ($r,$refpage,$initpage) = @_;
  583:     my ($control,$current) = &curr_courseinit();
  584:     my @chgstate = ('userpref','coursespecific');
  585:     my @chgentry = ('firstres','whatsnew');
  586:     my %lt = &Apache::lonlocal::texthash(
  587:                              'chwp' => 'Choose which page will be displayed when you enter this course after selecting a role.',
  588:                              'cuva' => 'Current value is determined by',
  589:                              'anis' => 'and is set to display',
  590:                              'padc' => 'Page display controlled by',
  591:                              'chce' => 'Choose course entry',
  592:                              'moce' => 'Modify course entry',
  593:     );
  594:     $r->print(<<"END"); 
  595: <br />$lt{'chwp'}
  596: <br />$lt{'cuva'}: <b>
  597: $$initpage{$control}</b> $lt{'anis'} <b>
  598: $$initpage{$current}</b>.<br /><br />
  599: <form method="post" name="courseinitswitch" action="/adm/whatsnew">
  600: <input type="hidden" name="command" value="newcourseinit" />
  601: <input type="hidden" name="refpage" value="$refpage" />
  602: $lt{'padc'}&nbsp;&nbsp;
  603: END
  604:     foreach my $choice (@chgstate) {
  605:         $r->print('<nobr><input type="radio" name="courseinit_control" value="'.
  606:                    $choice.'"/>'.$$initpage{$choice}.'&nbsp;&nbsp;</nobr>');
  607:     }
  608:     $r->print('<br /><br />'.&mt('If').' '.$$initpage{'coursespecific'}.
  609:               '<br />'.$lt{'chce'}." \n");
  610:     foreach my $choice (@chgentry) {
  611:         $r->print('<nobr><input type="radio" name="courseinit_page" value="'.
  612:                   $choice.'"/>'.$$initpage{$choice}.'&nbsp;&nbsp;</nobr>');
  613:     }
  614:     $r->print('<br /><br /><input type="submit" name="display" value="'.
  615:                $lt{'moce'}.'" /></form>');
  616:     return;
  617: }
  618: 
  619: sub curr_courseinit {
  620:     my $current = &get_current($env{'user.name'},$env{'user.domain'},
  621:                                 $env{'request.course.id'},'courseinit');
  622:     my $control;
  623:     if ($current) {
  624:         $control = 'coursespecific';
  625:     } else {
  626:         $control = 'userpref';
  627:         my %userenv = &Apache::lonnet::get('environment',
  628:                                                       ['course_init_display']);
  629:         if (exists($userenv{'course_init_display'})) {
  630:             $current = $userenv{'course_init_display'};
  631:         }
  632:         unless ($current) {
  633:             $current = 'whatsnew';
  634:         }
  635:     }
  636:     return ($control,$current);
  637: }
  638: 
  639: sub display_launcher {
  640:     my ($r,$action,$refpage,$checkallowed,$tabbg,$rowColor1,$rowColor2,$show,
  641:         $headings,$res_title,$tograde,$ungraded,$bombs,$bombed,$changed,
  642:         $warnings,$triggered,$newdiscussions,$unread,$msgcount,$newmsgs,
  643:                           $critmsgcount,$critmsgs,$interval,$countunread) = @_;
  644: 
  645:     if ($$checkallowed{$action}) {
  646:         &start_box($r,$tabbg,$show,$headings,$action,$refpage);
  647:         if ($$show{$action}) {
  648:             if ($action eq 'handgrading') {    # UNGRADED ITEMS
  649:                 &display_handgrade($r,$tograde,$rowColor1,$rowColor2,
  650:                                                                     $ungraded);
  651:             } elsif ($action eq 'haserrors') { # BOMBS
  652:                 &display_haserrors($r,$bombs,$rowColor1,$rowColor2,$bombed,
  653:                                                                    $res_title);
  654:             } elsif ($action eq 'versionchanges') { # VERSION CHANGES
  655:                 &display_versionchanges($r,$changed,$res_title,$rowColor1,
  656:                                                          $rowColor2,$interval);
  657: 
  658:             } elsif ($action eq 'abovethreshold') { # DEGDIFF/AV. TRIES TRIGGERS
  659:                 &display_abovethreshold($r,$refpage,$warnings,$triggered,
  660:                                              $res_title,$rowColor1,$rowColor2);
  661:             } elsif ($action eq 'coursediscussion') { # UNREAD COURSE DISCUSSION
  662:                 &display_coursediscussion($r,$newdiscussions,$unread,
  663:                                 $countunread,$res_title,$rowColor1,$rowColor2);
  664:             } elsif ($action eq 'coursenormalmail') { # NORMAL MESSAGES
  665:                 &display_coursenormalmail($r,$msgcount,$newmsgs,$rowColor1,
  666:                                                                    $rowColor2);
  667:             } elsif ($action eq 'coursecritmail') { # CRITICAL MESSAGES
  668:                 &display_coursecritmail($r,$critmsgcount,$critmsgs,$rowColor1,
  669:                                                                    $rowColor2);
  670:             }
  671:         }
  672:         &end_box($r);
  673:     }
  674:     return;
  675: }
  676: 
  677: sub getitems {
  678:     my ($unread,$ungraded,$bombed,$triggered,$changed,$newdiscussions,
  679:         $tograde,$bombs,$warnings,$rowColor1,$rowColor2,$threshold,$cdom,$crs,
  680:                                  $res_title,$show,$starttime,$countunread) = @_;
  681:     my $navmap = Apache::lonnavmaps::navmap->new();
  682:     # force retrieve Resource to seed the part id cache we'll need it later
  683:     my @allres=$navmap->retrieveResources(undef,
  684:                      sub {if ($_[0]->is_problem) { $_[0]->parts();} return 1;});
  685:     my %lastreadtime;
  686:     my %resourcetracker;
  687:     my $discussiontime;
  688: 
  689: # Resource version changes
  690:     if ($$show{'versionchanges'}) {
  691:         &checkversions($cdom,$crs,$navmap,$changed,$starttime);
  692:     }
  693: 
  694:     if ($$show{'coursediscussion'}) {   
  695:         my %lastread = &Apache::lonnet::dump('nohist_'.
  696:                         $env{'request.course.id'}.'_discuss',
  697:                         $env{'user.domain'},$env{'user.name'},'lastread');
  698:         foreach my $key (keys(%lastread)) {
  699:             my $newkey = $key;
  700:             $newkey =~ s/_lastread$//;
  701:             $lastreadtime{$newkey} = $lastread{$key};
  702:         }
  703:     }
  704:  
  705:     if ($$show{'abovethreshold'}) {
  706:         %resourcetracker =  &Apache::lonnet::dump('nohist_resourcetracker',
  707:                                                                    $cdom,$crs);
  708:     }
  709: 
  710:     my $warningnum = 0;
  711:     foreach my $resource (@allres) {
  712:         my $result = '';
  713:         my $applies = 0;
  714:         my $symb = $resource->symb();
  715:         %{$$bombed{$symb}} = ();
  716:         %{$$ungraded{$symb}} = ();
  717:         %{$$triggered{$symb}} = ();
  718:         $$triggered{$symb}{numparts} = 0;
  719:         my $title = $resource->compTitle();
  720:         $$res_title{$symb} = $title;
  721:         my $ressymb = $resource->wrap_symb();
  722: 
  723: # Check if there are unread discussion postings
  724:         if ($$show{'coursediscussion'}) {
  725:             &check_discussions($cdom,$crs,$resource,$symb,$ressymb,$title,
  726:                                                       $newdiscussions,$unread);
  727:         }
  728: 
  729: # Check for ungraded problems
  730:         if ($resource->is_problem()) {
  731:             if ($$show{'handgrading'}) {
  732:                 &check_handgraded($resource,$symb,$title,$cdom,$crs,$ungraded,
  733:                                                                      $tograde);
  734:             }
  735:         }
  736: 
  737: # Check for bombs
  738:         if ($$show{'haserrors'}) {
  739:             &check_bombed($resource,$symb,$title,$bombs,$bombed);
  740:         }
  741: 
  742: # Maxtries and degree of difficulty for problem parts, unless handgradeable
  743:         if ($$show{'abovethreshold'}) {  
  744:             &check_thresholds($resource,$symb,\%resourcetracker,$triggered,
  745:                        $threshold,$warnings,$warningnum,$rowColor1,$rowColor2);
  746:         }
  747: 
  748:     }
  749:     my $hasdiscussion = @{$newdiscussions};
  750:     if ($$show{'coursediscussion'} && $hasdiscussion) { # Get time of last post; 
  751:         $discussiontime = $navmap->{DISCUSSION_TIME};
  752:         foreach my $ressymb (@{$newdiscussions}) {
  753:             $$unread{$ressymb}{'lastpost'} = $$discussiontime{$ressymb};
  754:         }
  755:         if ($countunread eq 'on') { #Get count of unread postings for each resource 
  756:             my $discussiondata = $navmap->get_discussion_data();
  757:             foreach my $ressymb (@{$newdiscussions}) {
  758:                 &get_discussions($cdom,$crs,$discussiondata,$ressymb,
  759:                                                        $unread,\%lastreadtime);
  760:             }
  761:         }
  762:     }
  763: }
  764: 
  765: sub check_discussions {
  766:     my ($cdom,$crs,$resource,$symb,$ressymb,$title,$newdiscussions,
  767:                                                                  $unread) = @_;
  768:     if ($resource->hasDiscussion()) {
  769:         %{$$unread{$ressymb}} = ();
  770:         $$unread{$ressymb}{'title'} = $title;
  771:         $$unread{$ressymb}{'symb'} = $symb;
  772:         push(@{$newdiscussions}, $ressymb);
  773:     }
  774: }
  775: 
  776: sub get_discussions {
  777:     my ($cdom,$crs,$discussiondata,$ressymb,$unread,$lastreadtime) = @_;
  778:     my $prevread = 0;
  779:     my $unreadcount = 0;
  780:     if (defined($$lastreadtime{$ressymb})) {
  781:         $prevread = $$lastreadtime{$ressymb};
  782:     }
  783:     my $version = $$discussiondata{'version:'.$ressymb};
  784:     if ($version) {
  785:         my $hiddenflag = 0;
  786:         my $deletedflag = 0;
  787:         my ($hidden,$deleted);
  788:         for (my $id=$version; $id>0; $id--) {
  789:             my $vkeys=$$discussiondata{$id.':keys:'.$ressymb};
  790:             my @keys=split(/:/,$vkeys);
  791:             if (grep/^hidden$/,@keys) {
  792:                 unless ($hiddenflag) {
  793:                     $hidden = $$discussiondata{$id.':'.$ressymb.':hidden'};
  794:                     $hiddenflag = 1;
  795:                 }
  796:             } elsif (grep/^deleted$/,@keys) {
  797:                 unless ($deletedflag) {
  798:                     $deleted = $$discussiondata{$id.':'.$ressymb.':deleted'};
  799:                     $deletedflag = 1;
  800:                 }
  801:             } else {
  802:                 unless (($hidden =~/\.$id\./) || ($deleted =~/\.$id\./)) {
  803:                     if ($prevread <$$discussiondata{$id.':'.$ressymb.':timestamp'}) {
  804:                         $unreadcount ++;
  805:                         $$unread{$ressymb}{$unreadcount} = $id.': '.
  806:                                  $$discussiondata{$id.':'.$ressymb.':subject'};
  807:                     }
  808:                 }
  809:             }
  810:         }
  811:         $$unread{$ressymb}{'unreadcount'} = $unreadcount;
  812:     }
  813: }
  814: 
  815: 
  816: sub check_handgraded {
  817:     my ($resource,$symb,$title,$cdom,$cnum,$ungraded,$tograde) = @_;
  818:     if ($resource->is_problem()) {
  819:         my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
  820:         my $partlist=$resource->parts();
  821:         my $handgradeable;
  822:         foreach my $part (@$partlist) {
  823:             if ($resource->handgrade($part) eq 'yes') {
  824:                 $handgradeable=1; last;
  825:             }
  826:         }
  827:         if ($handgradeable) {
  828:             my @ungraded = &Apache::bridgetask::get_queue_symb_status(
  829:                                              'gradingqueue',$symb,$cdom,$cnum);
  830:             if (@ungraded > 0) {
  831:                 $$ungraded{$symb}{count} = scalar(@ungraded);
  832:                 $$ungraded{$symb}{title} = $title;
  833:                 push(@{$tograde}, $symb);
  834:             }
  835:         }
  836:     }
  837: }
  838: 
  839: sub check_bombed {
  840:     my ($resource,$symb,$title,$bombs,$bombed) = @_;
  841:     if ($resource->getErrors()) {
  842:         my $errors = $resource->getErrors();
  843:         $errors =~ s/^,//;
  844:         my @bombs = split(/,/, $errors);
  845:         my $errorcount = scalar(@bombs);
  846:         my $errorlink = '<a href="/adm/email?display='.
  847:                         &Apache::lonnet::escape($bombs[0]).'">'.
  848:                         $title.'</a>';
  849:         $$bombed{$symb}{errorcount} = $errorcount;
  850:         $$bombed{$symb}{errorlink} = $errorlink;
  851:         push(@{$bombs}, $symb);
  852:     }
  853: }
  854: 
  855: sub check_thresholds {
  856:     my ($resource,$symb,$resourcetracker,$triggered,$threshold,$warnings,
  857:                                        $warningnum,$rowColor1,$rowColor2) = @_;
  858: # Compile maxtries and degree of difficulty for problem parts, unless handgradeable
  859:     my @parts = @{$resource->parts()};
  860:     my %stats;
  861:     my %lastreset = ();
  862:     my $warning = 0;
  863:     my $rowColor;
  864:     foreach my $part (@parts) {
  865:         if ($resource->handgrade($part) eq 'yes') {
  866:             next;
  867:         }
  868:         %{$stats{$part}} = ();
  869:         my ($attempts,$users,$corrects,$degdiff,$av_attempts);
  870:         if (exists($$resourcetracker{$symb."\0".$part."\0attempts"})) {
  871:             $attempts = $$resourcetracker{$symb."\0".$part."\0attempts"};
  872:         }
  873:         if (exists($$resourcetracker{$symb."\0".$part."\0users"})) {
  874:             $users = $$resourcetracker{$symb."\0".$part."\0users"};
  875:         }
  876:         if (exists($$resourcetracker{$symb."\0".$part."\0correct"})) {
  877:             $corrects = $$resourcetracker{$symb."\0".$part."\0correct"};
  878:         }
  879:         if ($attempts > 0) {
  880:             $degdiff =  1 - ($corrects/$attempts);
  881:             $degdiff = sprintf("%.2f",$degdiff);
  882:         }
  883:         if ($users > 0) {
  884:             $av_attempts = $attempts/$users;
  885:             $av_attempts = sprintf("%.2f",$av_attempts);
  886:         }
  887:         if ((($degdiff ne '' && $degdiff >= $$threshold{'degdiff'}) || ($av_attempts ne '' && $av_attempts >= $$threshold{'av_attempts'})) && ($users >= $$threshold{'numstudents'})) {
  888:             $stats{$part}{degdiff} = $degdiff;
  889:             $stats{$part}{attempts} = $av_attempts;
  890:             $stats{$part}{users} = $users;
  891:             $lastreset{$part} = $$resourcetracker{$symb."\0".$part."\0resettime"};
  892:             if ($lastreset{$part}) {
  893:                 $lastreset{$part} = &Apache::lonnavmaps::timeToHumanString($lastreset{$part});
  894:             }
  895:             $warning = 1;
  896:         }
  897:     }
  898:     if ($warning) {
  899:         if ($warningnum %2 == 1) {
  900:             $rowColor = $rowColor1;
  901:         } else {
  902:             $rowColor = $rowColor2;
  903:         }
  904:         $$triggered{$symb}{title} = $resource->title;
  905:         foreach my $part (@parts) {
  906:             if (exists($stats{$part}{users})) {
  907:                 my $resetname = 'reset_'.&Apache::lonnet::escape($symb."\0".$part);
  908:                 my $resettitle = 'title_'.&Apache::lonnet::escape($symb."\0".$part);
  909:                 if ($$triggered{$symb}{numparts}) {
  910:                     $$triggered{$symb}{text} .= '<tr bgcolor="'.$rowColor.'">'."\n";
  911:                 }
  912:                 if (@parts > 1) {
  913:                     $$triggered{$symb}{text} .= '
  914:                      <td align="right"><small>part - '.$part.'<small></td>';
  915:                 } else {
  916:                     $$triggered{$symb}{text} .= '
  917:                      <td align="right"><small>single part</small></td>';
  918:                 }
  919:                 $$triggered{$symb}{text} .= '
  920:                      <td align="right"><small>'.$stats{$part}{users}.'</small></td>
  921:                      <td align="right"><small>'.$stats{$part}{attempts}.'</small></td>
  922:                      <td align="right"><small>'.$stats{$part}{degdiff}.'</small></td>
  923:                      <td align="right"><small>'.$lastreset{$part}.'</small></td>
  924:                      <td align="right"><small><input type="checkbox" name="'.$resetname.'" /><input type="hidden" name="'.$resettitle.'" value="'.&Apache::lonnet::escape($$triggered{$symb}{title}).'" /></td>
  925:                     </tr>';
  926:                 $$triggered{$symb}{numparts} ++;
  927:             }
  928:         }
  929:         push(@{$warnings},$symb);
  930:         $warningnum ++;
  931:     }
  932: }
  933: 
  934: 
  935: sub get_curr_thresholds {
  936:     my ($threshold,$uname,$udom,$cid,$cdom,$crs) = @_;
  937:     my %thresholdsettings = &Apache::lonnet::dump('nohist_whatsnew',$udom,
  938:                                                      $uname,$cid.':threshold');
  939:     my $thresholdcount = 0;
  940:     my ($tmp) = %thresholdsettings;
  941:     unless ($tmp =~ /^(con_lost|error|no_such_host)/i) {
  942:         foreach my $item (keys %{$threshold}) { 
  943:             if (exists($thresholdsettings{$cid.':threshold_'.$item})) {
  944:                 $$threshold{$item} = 
  945:                              $thresholdsettings{$cid.':threshold_'.$item};
  946:                 $thresholdcount ++;
  947:             }
  948:         }
  949:     }
  950:     if ($thresholdcount == 3) {
  951:         return;
  952:     }
  953:     my %coursesettings = &Apache::lonnet::dump('environment',
  954:                                               $cdom,$crs,'internal.threshold');
  955:     my ($temp) = %coursesettings;
  956:     unless ($temp =~ /^(con_lost|error|no_such_host)/i) {  
  957:         foreach my $item (keys %{$threshold}) {
  958:             unless (exists($thresholdsettings{$cid.':threshold_'.$item})) {
  959:                 if (exists($coursesettings{'internal.threshold_'.$item})) {
  960:                     $$threshold{$item} = 
  961:                              $coursesettings{'internal.threshold_'.$item};
  962:                 }
  963:             }
  964:         }
  965:     }
  966:     return;
  967: }
  968: 
  969: sub get_current {
  970:     my ($uname,$udom,$cid,$caller) = @_;
  971:     my $currvalue;
  972:     my %settings = &Apache::lonnet::dump('nohist_whatsnew',$udom,$uname,$cid.
  973:                                                                 ':'.$caller);
  974:     my ($tmp) = %settings;
  975:     unless ($tmp =~ /^(con_lost|error|no_such_host)/i) {
  976:         $currvalue = $settings{$cid.':'.$caller};
  977:     }
  978:     return $currvalue;
  979: }
  980: 
  981: sub process_reset {
  982:     my ($dom,$crs) = @_;
  983:     my $result = '<b>'.&mt('Counters reset for following problems (and parts):').
  984:                            '</b><br />';
  985:     my @agg_types = ('attempts','users','correct');
  986:     my %agg_titles = &Apache::lonlocal::texthash (
  987:                      attempts => 'Number of submissions',
  988:                      users => 'Students with submissions',
  989:                      correct => 'Number of correct submissions',
  990:                      );
  991:     my @resets = ();
  992:     my %titles = ();
  993:     foreach my $key (keys(%env)) {
  994:         next if ($key !~ /^form\.reset_(.+)$/);
  995:         my $title = &Apache::lonnet::unescape($env{'form.title_'.$1});
  996:         my $reset_item = &Apache::lonnet::unescape($1);
  997:         my %curr_aggregates = &Apache::lonnet::dump('nohist_resourcetracker',$dom,$crs,$reset_item);
  998:         my %aggregates = ();
  999:         my ($symb,$part) = split(/\0/,$reset_item);
 1000:         foreach my $type (@agg_types) {
 1001:             $aggregates{$reset_item."\0".$type} = 0;
 1002:         }  
 1003: 	$aggregates{$reset_item."\0".'resettime'} = time;
 1004:         my $putresult = &Apache::lonnet::put('nohist_resourcetracker',\%aggregates,
 1005:                           $dom,$crs);
 1006:         if ($putresult eq 'ok') {
 1007:             $result .= $title.' -part '.$part.': ';
 1008:             my %new_aggregates = &Apache::lonnet::dump('nohist_resourcetracker',$dom,$crs,$reset_item);
 1009:             foreach my $type (@agg_types) {
 1010:                 $result .= $agg_titles{$type}.' = '.$new_aggregates{$reset_item."\0".$type}.'; ';
 1011:             }
 1012:             $result =~ s/; $//;
 1013:             $result .= '<br />';
 1014:         } else {
 1015:             $result = $title.' -part '.$part.': '.&mt('Unable to reset counters to zero due to [_1]',$putresult).'.<br />'."\n";
 1016:         }
 1017:     }
 1018:     return $result;
 1019: }
 1020: 
 1021: sub process_update {
 1022:     my ($uname,$udom,$threshold_titles) = @_;
 1023:     my $setoutput = '<b>Changes to threshold(s) for problem tracking:</b><br />';
 1024:     foreach (keys %env) {
 1025:         next if ($_!~/^form\.(.+)\_setparmval$/);
 1026:         my $name  = $1;
 1027:         my $value = $env{'form.'.$name.'_value'};
 1028:         if ($name && defined($value)) {
 1029:             my $put_result = &Apache::lonnet::put('nohist_whatsnew',
 1030:                                                   {$name=>$value},$udom,$uname);
 1031:            
 1032:             my ($shortname) = ($name =~ /^\Q$env{'request.course.id'}\E:threshold_(.+)$/);
 1033:             if ($put_result eq 'ok') {
 1034:                 $setoutput.=&mt('Set threshold for [_1] to [_2]',
 1035: 				'<b>'.$$threshold_titles{$shortname}.'</b>',
 1036: 				'<b>'.$value.'</b>').'<br />';
 1037: 	    } else {
 1038:                 $setoutput.=&mt('Unable to set threshold for [_1] to [_2] due to [_3].',
 1039: 				'<b>'.$name.'</b>','<b>'.$value.'</b>',
 1040: 				'<tt>'.$put_result.'</tt>').'<br />';
 1041:             }
 1042:         }
 1043:     }
 1044:     return $setoutput;
 1045: }
 1046: 
 1047: sub getnormalmail {
 1048:     my ($newmsgs) = @_;
 1049: # Check for unread mail in course
 1050:     my $msgcount = 0;
 1051: 
 1052:     my @messages = sort(&Apache::lonnet::getkeys('nohist_email'));
 1053:     foreach my $message (@messages) {
 1054: 	my $msgid=&Apache::lonnet::escape($message);
 1055:         my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
 1056:             &Apache::lonmsg::unpackmsgid($msgid);
 1057:         if (($fromcid) && ($fromcid eq $env{'request.course.id'})) {
 1058:             if (defined($sendtime) && $sendtime!~/error/) {
 1059:                 my $numsendtime = $sendtime;
 1060:                 $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
 1061:                 if ($status eq 'new') {
 1062:                     $msgcount ++;
 1063:                     if ($shortsubj eq '') {
 1064:                         $shortsubj = &mt('No subject');
 1065:                     }
 1066:                     $shortsubj = &Apache::lonnet::unescape($shortsubj);
 1067:                     push(@{$newmsgs}, {
 1068:                         msgid    => $msgid,
 1069:                         sendtime => $sendtime,
 1070:                         shortsub => $shortsubj,
 1071:                         from     => $fromname,
 1072:                         fromdom  => $fromdom
 1073:                         });
 1074:                 }
 1075:             }
 1076:         }
 1077:     }
 1078:     return $msgcount;
 1079: }
 1080: 
 1081: sub getcritmail {
 1082:     my ($critmsgs) = @_; 
 1083: # Check for critical messages in course
 1084:     my %what=&Apache::lonnet::dump('critical');
 1085:     my $result = '';
 1086:     my $critmsgcount = 0;
 1087:     foreach my $msgid (sort(keys(%what))) {
 1088:         my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
 1089:             &Apache::lonmsg::unpackmsgid($msgid);
 1090:         if (($fromcid) && ($fromcid eq  $env{'request.course.id'})) {
 1091:             if (defined($sendtime) && $sendtime!~/error/) {
 1092:                 my $numsendtime = $sendtime;
 1093:                 $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
 1094:                 $critmsgcount ++;
 1095:                 if ($shortsubj eq '') {
 1096:                     $shortsubj = &mt('No subject');
 1097:                 }
 1098:                 $shortsubj = &Apache::lonnet::unescape($shortsubj);
 1099:                 push(@{$critmsgs}, {
 1100:                         msgid    => $msgid,
 1101:                         sendtime => $sendtime,
 1102:                         shortsub => $shortsubj,
 1103:                         from     => $fromname,
 1104:                         fromdom  => $fromdom
 1105:                         });
 1106:             }
 1107:         }
 1108:     }
 1109:     return $critmsgcount;
 1110: }
 1111: 
 1112: 
 1113: sub checkversions {
 1114:     my ($cdom,$crs,$navmap,$changed,$starttime) = @_;
 1115:     my %changes=&Apache::lonnet::dump('versionupdate',$cdom,$crs);
 1116:     my ($tmp) = keys(%changes);
 1117:     unless ($tmp =~ /^(con_lost|error|no_such_host)/i) {
 1118:         if (keys(%changes) > 0) {
 1119:             foreach my $key (sort(keys(%changes))) {
 1120:                 if ($changes{$key} > $starttime) {
 1121:                     my $version;
 1122:                     my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
 1123:                     my $currentversion=&Apache::lonnet::getversion($key);
 1124:                     my $revdate = 
 1125:                           &Apache::lonnet::metadata($root.'.'.$extension,
 1126:                                                      'lastrevisiondate');
 1127:                     $revdate =  &Apache::lonlocal::locallocaltime($revdate);
 1128:                     my $linkurl=&Apache::lonnet::clutter($key);
 1129:                     my $usedversion=$navmap->usedVersion('version_'.$linkurl);
 1130:                     my @resources = $navmap->getResourceByUrl($linkurl,1);
 1131:                     if (($usedversion) && ($usedversion ne 'mostrecent')) {
 1132:                         $version = $usedversion;     
 1133:                     } else {
 1134:                         $version = $currentversion;
 1135:                     }
 1136:                     foreach my $res (@resources) {
 1137:                          if (ref($res) eq 'Apache::lonnavmaps::resource') { 
 1138:                             my $symb = $res->symb();
 1139:                             %{$$changed{$symb}} = (
 1140:                                                 current => $currentversion,
 1141:                                                 version => $version,
 1142:                                                 revdate => $revdate,
 1143:                             );
 1144:                         }
 1145:                     }
 1146:                 }
 1147:             }
 1148:         }
 1149:     }
 1150:     return;
 1151: }
 1152: 
 1153: sub display_handgrade {
 1154:     my ($r,$tograde,$rowColor1,$rowColor2,$ungraded) = @_;
 1155:     my $rowColor;
 1156:     my %lt = &Apache::lonlocal::texthash(
 1157:                         'prna' => 'Problem Name',
 1158:                         'nmun' => 'Number ungraded',
 1159:                         'nopr' => 'No problems require handgrading',
 1160:     );
 1161:     if (@{$tograde} > 0) {
 1162:         $r->print('<tr bgcolor="#cccccc"><td><b><small>'.$lt{'prna'}.'</small></b></td><td align="right"><b><small>'.$lt{'nmun'}.'</small></b></td></tr>');
 1163:         my $rowNum = 0;
 1164:         foreach my $res (@{$tograde}) {
 1165:             if ($rowNum %2 == 1) {
 1166:                 $rowColor = $rowColor1;
 1167:             } else {
 1168:                 $rowColor = $rowColor2;
 1169:             }
 1170:             my ($map,$id,$url)=&Apache::lonnet::decode_symb($res);
 1171:             my $linkurl=&Apache::lonnet::clutter($url);
 1172:             $linkurl .= '?symb='.&Apache::lonnet::escape($res);
 1173:                                                                                
 1174:             $r->print('<tr bgcolor="'.$rowColor.'"><td><a href="'.$linkurl.'"><small>'.$$ungraded{$res}{title}.'</small></a></td><td align="right"><small>'.$$ungraded{$res}{count}.'</small></td></tr>');
 1175:             $rowNum ++;
 1176:         }
 1177:     } else {
 1178:         $r->print('<tr><td bgcolor="#ffffff"><br><center><i><b><small>&nbsp;&nbsp;'.$lt{'nopr'}.'&nbsp;&nbsp;</small><br><br></b></i></td></tr>');
 1179:     }
 1180: }
 1181: 
 1182: sub display_haserrors {
 1183:     my ($r,$bombs,$rowColor1,$rowColor2,$bombed,$res_title) = @_;
 1184:     my $bombnum = 0;
 1185:     my $rowColor;
 1186:     my %lt = &Apache::lonlocal::texthash(
 1187:                                    reso => 'Resource',
 1188:                                    nmer => 'Number of errors',
 1189:                                    noer => 'No problems with errors',
 1190:     );
 1191:     if (@{$bombs} > 0) {
 1192:         $r->print('<tr bgcolor="#cccccc"><td><b><small>'.$lt{'reso'}.'</small></b></td><td align="right"><b><small>'.$lt{'nmer'}.'</small></b></td></tr>');
 1193:         @{$bombs} = sort { &cmp_title($a,$b,$res_title) } @{$bombs};
 1194:         foreach my $bomb (@{$bombs}) {
 1195:             if ($bombnum %2 == 1) {
 1196:                 $rowColor = $rowColor1;
 1197:             } else {
 1198:                 $rowColor = $rowColor2;
 1199:             }
 1200:             $r->print('<tr bgcolor="'.$rowColor.'"><td><small>'.$$bombed{$bomb}{errorlink}.'</small></td><td align="right"><small>'.$$bombed{$bomb}{errorcount}.'</small></td></tr>');
 1201:             $bombnum ++;
 1202:         }
 1203:     } else {
 1204:         $r->print('<tr><td bgcolor="#ffffff"><br /><center><b><i><small>'.$lt{'noer'}.'</small></i></b></center><br /></td></tr>');
 1205:     }
 1206:     return;
 1207: }
 1208: 
 1209: sub display_abovethreshold {
 1210:     my ($r,$refpage,$warnings,$triggered,$res_title,$rowColor1,$rowColor2) = @_;
 1211:     my %lt = &Apache::lonlocal::texthash(
 1212:                  reso => 'Resource',
 1213:                  part => 'Part',
 1214:                  nust => 'Num. students',
 1215:                  avat => 'Av. Attempts',
 1216:                  dedi => 'Deg. Diff',
 1217:                  lare => 'Last Reset',
 1218:                  reco => 'Reset Count?',
 1219:                  rese => 'Reset counters to 0',
 1220:                  nopr => 'No problems satisfy threshold criteria',
 1221:     );
 1222:     my $rowColor; 
 1223:     my $warningnum = 0;
 1224:     if (@{$warnings} > 0) {
 1225:         @{$warnings} = sort { &cmp_title($a,$b,$res_title) } @{$warnings};
 1226:         $r->print('<form name="reset_tracking" method="post" action="/adm/whatsnew">'.
 1227:                 ' <input type="hidden" name="command" value="reset" />'."\n".
 1228:                 ' <input type="hidden" name="refpage" value="'.$refpage.'" />'.
 1229:                 "\n");
 1230:         $r->print('<tr bgcolor="#cccccc"><td><b><small>'.$lt{'reso'}.'</small></b></td><td align="right"><b><small>'.$lt{'part'}.'</small></b></td><td align="right"><b><small>'.$lt{'nust'}.'</small></b></td><td align="right"><b><small>'.$lt{'avat'}.'</small></b></td><td align="right"><b><small>'.$lt{'dedi'}.'</small></b></td><td align="right"><b><small>'.$lt{'lare'}.'</small></b></td><td align="right"><b><small>'.$lt{'reco'}.'</small></b></td></tr>');
 1231:         foreach my $res (@{$warnings}) {
 1232:             if ($warningnum %2 == 1) {
 1233:                 $rowColor = $rowColor1;
 1234:             } else {
 1235:                 $rowColor = $rowColor2;
 1236:             }
 1237:             my ($map,$id,$url)=&Apache::lonnet::decode_symb($res);
 1238:             my $linkurl=&Apache::lonnet::clutter($url);
 1239:             my $rowspan;
 1240:             if ($$triggered{$res}{numparts} > 1) {
 1241:                 $rowspan = 'rowspan="'.$$triggered{$res}{numparts}.'"';
 1242:             }
 1243:             $linkurl .= '?symb='.&Apache::lonnet::escape($res);
 1244:             $r->print('<tr bgcolor="'.$rowColor.'"><td '.$rowspan.'><a href="'.$linkurl.'"><small>'.$$triggered{$res}{title}.'</small></a></td>'.$$triggered{$res}{text});
 1245:             $warningnum ++;
 1246:         }
 1247:         $r->print('<tr bgcolor="#cccccc"><td colspan="7" align="right"><br /><b><small><input type="submit" name="counters" value="'.$lt{'rese'}.'" /></form>');
 1248:     } else {
 1249:         $r->print('<tr><td bgcolor="#ffffff"><br /><center><b><i><small>'.$lt{'nopr'}.'</small></i></b></center><br /></td></tr>');
 1250:     }
 1251: }
 1252: 
 1253: sub display_versionchanges {
 1254:     my ($r,$changed,$res_title,$rowColor1,$rowColor2,$interval) = @_;
 1255:     my %lt = &Apache::lonlocal::texthash(
 1256:         'reso' => 'Resource',
 1257:         'revd' => 'Last revised',
 1258:         'newv' => 'New version',
 1259:         'veru' => 'Version used',
 1260:         'noup' => 'No updated versions', 
 1261:     );
 1262:     my $rowColor;
 1263:     if (keys(%{$changed}) > 0) {
 1264:         $r->print('<tr bgcolor="#cccccc"><td><b><small>'.$lt{'reso'}.'</small></b></td><td><b><small>'.$lt{'revd'}.'</small></b></td><td><b><small>'.$lt{'newv'}.'</small></b></td><td><b><small>'.$lt{'veru'}.'</small></b></td></tr>');
 1265:         
 1266:         
 1267:         my @changes = sort { &cmp_title($a,$b,$res_title) } keys(%{$changed});
 1268:         my $changenum = 0;
 1269:         foreach my $item (@changes) {
 1270:             if ($changenum %2 == 1) {
 1271:                 $rowColor = $rowColor1;
 1272:             } else {
 1273:                 $rowColor = $rowColor2;
 1274:             }
 1275:             my ($map,$id,$url)=&Apache::lonnet::decode_symb($item);
 1276:             my $linkurl=&Apache::lonnet::clutter($url);
 1277:             $linkurl .= '?symb='.&Apache::lonnet::escape($item);
 1278: 
 1279:             $r->print('<tr bgcolor="'.$rowColor.'"><td><small><a href="'.$linkurl.'">'.$$res_title{$item}.'</a></small></td><td><small>'.$$changed{$item}{'revdate'}.'</small></td><td><small>'.$$changed{$item}{'current'}.'</small></td><td><small>'.$$changed{$item}{'version'}.'</small></td></tr>');
 1280:             $changenum ++;
 1281:         }
 1282:     } else {
 1283:         $r->print('<tr><td bgcolor="#ffffff"><br /><center><b><i><small>'.$lt{'noup'}.' '.$interval.'</small></i></b></center><br /></td></tr>');
 1284:     }
 1285:     return;
 1286: }
 1287:  
 1288: sub display_coursediscussion {
 1289:     my ($r,$newdiscussions,$unread,$countunread,$res_title,$rowColor1,
 1290:                                                               $rowColor2) = @_;
 1291:     my %lt = &Apache::lonlocal::texthash(
 1292:                 'loca' => 'Location',
 1293:                 'type' => 'Type',
 1294:                 'numn' => 'Number of new posts',
 1295:                 'noun' => 'No unread posts in course discussions',
 1296:                 'tmlp' => 'Time of last post', 
 1297:     );
 1298:     my $rowColor;
 1299:     if (@{$newdiscussions} > 0) {
 1300:         $r->print('<tr bgcolor="#cccccc"><td><b><small>'.$lt{'loca'}.
 1301:                   '</small></b></td><td><b><small>'.$lt{'type'}.
 1302:                   '</small></b>');
 1303:         if ($countunread eq 'on') {
 1304:             $r->print('<td><b><small>'.$lt{'tmlp'}.'</small></b></td>'.
 1305:                       '<td align="right"><b><small>'.$lt{'numn'}.
 1306:                       '</small></b></td>');
 1307:         } else {
 1308:             $r->print('<td align="right"><b><small>'.$lt{'tmlp'}.
 1309:                          '</small></b></td>');
 1310:         }
 1311:         $r->print("</tr>\n");
 1312:         @{$newdiscussions} = sort { &cmp_title($a,$b,$res_title) }
 1313:                                                             @{$newdiscussions};
 1314:         my $rowNum = 0;
 1315:         foreach my $ressymb (@{$newdiscussions}) {
 1316:             my $forum_title = $$unread{$ressymb}{'title'};
 1317:             my $type = 'Resource';
 1318:             my $feedurl=&Apache::lonfeedback::get_feedurl($ressymb);
 1319:             if ($feedurl =~ /bulletinboard/) {
 1320:                 $type = 'Bulletin Board';
 1321:             }
 1322:             if ($rowNum %2 == 1) {
 1323:                 $rowColor = $rowColor1;
 1324:             } else {
 1325:                 $rowColor = $rowColor2;
 1326:             }
 1327:             my $lastpost = &Apache::lonnavmaps::timeToHumanString(
 1328:                                                $$unread{$ressymb}{'lastpost'});
 1329:             $r->print('<tr bgcolor="'.$rowColor.'"><td><small><a href="'.$feedurl.'?symb='.$$unread{$ressymb}{symb}.'">'.$forum_title.'</a>&nbsp;</td><td><small>'.$type.'&nbsp;</small></td>');
 1330:             if ($countunread eq 'on') {
 1331:                 my $unreadnum = $$unread{$ressymb}{'unreadcount'};
 1332:                 $r->print('<td><small>'.$lastpost.'<small></td><td align="right">'.
 1333:                           '<small>',$unreadnum.'&nbsp;</small></td>');
 1334:             } else {
 1335:                 $r->print('<td align="right"><small>'.$lastpost.'</small></td>');
 1336:             }
 1337:             $r->print("</tr>\n");
 1338:             $rowNum ++;
 1339:         }
 1340:     } else {
 1341:         $r->print('<tr><td bgcolor="#ffffff"><br><center>&nbsp;<i><b><small>'.
 1342:                   $lt{'noun'}.'</small></b></i><br><br></td></tr>');
 1343:     }
 1344: }
 1345: 
 1346: sub display_coursenormalmail {
 1347:     my ($r,$msgcount,$newmsgs,$rowColor1,$rowColor2) = @_;
 1348:     my $rowColor;
 1349:     if ($msgcount > 0) {
 1350:         $r->print('<tr bgcolor="#cccccc"><td><b><small>'.&mt('Number').'</small></b></td><td><b><small>'.&mt('Subject').'</small></b></td><td><b><small>'.&mt('Sender').'</small></b></td><td><b><small>'.&mt('Date/Time').'</small></b></td></tr>');
 1351:         my $rowNum = 0;
 1352:         my $mailcount = 1;
 1353:         foreach my $msg (@{$newmsgs}) {
 1354:             if ($rowNum %2 == 1) {
 1355:                 $rowColor = $rowColor1;
 1356:             } else {
 1357:                 $rowColor = $rowColor2;
 1358:             }
 1359:             $r->print('<tr bgcolor="'.$rowColor.'"><td valign="top"><small>'.$mailcount.'. &nbsp;</small></td><td valign="top"><small><a href="/adm/communicate">'.$msg->{'shortsub'}.'</a>&nbsp; &nbsp;</small></td><td valign="top"><small>&nbsp;'.$msg->{'from'}.'@'.$msg->{'fromdom'}.'&nbsp;</small></td><td valign="top"><small>'.$msg->{'sendtime'}.'</small></td></tr>');
 1360:             $rowNum ++;
 1361:             $mailcount ++;
 1362:         }
 1363:     } else {
 1364:         $r->print('<tr><td bgcolor="#ffffff" width="100%"><center><br /><b><i><small>'.&mt('No new course messages').'</small></i></b><br /><br /></center></td></tr>');
 1365:     }
 1366: }
 1367: 
 1368: sub display_coursecritmail {
 1369:     my ($r,$critmsgcount,$critmsgs,$rowColor1,$rowColor2) = @_;
 1370:     my $rowColor;
 1371:     if ($critmsgcount > 0) {
 1372:         $r->print('<tr bgcolor="#cccccc"><td><b><small>'.&mt('Number').'</small></b></td><td><b><small>'.&mt('Subject').'</small></b></td><td><b><small>'.&mt('Sender').'</small></b></td><td><b><small>'.&mt('Date/Time').'</small></b></td></tr>');
 1373:         my $rowNum = 0;
 1374:         my $mailcount = 1;
 1375:         foreach my $msg (@{$critmsgs}) {
 1376:             if ($rowNum %2 == 1) {
 1377:                 $rowColor = $rowColor1;
 1378:             } else {
 1379:                 $rowColor = $rowColor2;
 1380:             }
 1381:             $r->print('<tr bgcolor="'.$rowColor.'"><td valign="top"><small>'.$mailcount.'. &nbsp;<small></td><td valign="top"><small><a href="/adm/email?folder=critical">'.$msg->{'shortsub'}.'</a>&nbsp; &nbsp;</small></td><td valign="top"><small>&nbsp;'.$msg->{'from'}.'@'.$msg->{'fromdom'}.'&nbsp;</small></td><td valign="top"><small>'.$msg->{'sendtime'}.'</small></td></tr>');
 1382:             $rowNum ++;
 1383:             $mailcount ++;
 1384:         }
 1385:     } else {
 1386:         $r->print('<tr><td bgcolor="#ffffff" width="100%"><center><br /><b><i><small>'.&mt('No unread critical messages in course').'</small></i></b><br /><br /></center></td></tr>');
 1387:     }
 1388: }
 1389: 
 1390: sub cmp_title {
 1391:     my ($a,$b,$res_title) = @_;
 1392:     my ($atitle,$btitle) = (lc($$res_title{$a}),lc($$res_title{$b}));
 1393:     $atitle=~s/^\s*//;
 1394:     $btitle=~s/^\s*//;
 1395:     return $atitle cmp $btitle;
 1396: }
 1397: 
 1398: sub get_display_settings {
 1399:     my ($uname,$udom,$cid) = @_;
 1400:     my %settings = &Apache::lonnet::dump('nohist_whatsnew',$udom,$uname,$cid); 
 1401:     my ($tmp) = keys(%settings);
 1402:     if ($tmp=~ /^(con_lost|error|no_such_host)/i) {
 1403:         %settings = ();
 1404:         unless ($tmp =~ /^error: 2 /) {
 1405:             &Apache::lonnet::logthis('Error retrieving whatsnew settings: '.
 1406:             $tmp.' for '.$uname.':'.$udom.' for course: '.$cid);
 1407:         }
 1408:     }
 1409:     return %settings;
 1410: }
 1411: 
 1412: sub store_display_settings {
 1413:     my ($uname,$udom,$cid,$checkallowed) = @_;
 1414:     my %whatsnew_settings;
 1415:     my $result;
 1416:     foreach my $key (keys(%{$checkallowed})) {
 1417:         if (exists($env{'form.display_'.$key})) {
 1418:             unless ($env{'form.display_'.$key} eq '') {
 1419:                 $whatsnew_settings{$cid.':'.$key} = $env{'form.display_'.$key};
 1420:             }
 1421:         }
 1422:     }
 1423:     if (keys(%whatsnew_settings)) {
 1424:         $result = &Apache::lonnet::put('nohist_whatsnew',\%whatsnew_settings,
 1425:                                                                  $udom,$uname);
 1426:     } else {
 1427:         $result = 'ok';
 1428:     }
 1429:     return $result;
 1430: }
 1431: 
 1432: sub store_interval_setting {
 1433:     my ($uname,$udom,$cid,$interval_titles) = @_;
 1434:     my %interval_settings = ();
 1435:     my $result;
 1436:     if (defined($env{'form.interval'})) {
 1437:         $interval_settings{$cid.':interval'} = $env{'form.interval'};
 1438:         my $outcome = &Apache::lonnet::put('nohist_whatsnew',
 1439:                                              \%interval_settings,$udom,$uname);
 1440:         if ($outcome eq 'ok') {
 1441:             $result = &mt('Interval set to version changes [_1]',
 1442:                   '<b>'.$$interval_titles{$env{'form.interval'}}.'</b><br />');
 1443: 
 1444:         } else {
 1445:             &Apache::lonnet::logthis('Error storing whatsnew interval setting'.
 1446:                      ' '.$outcome.' for '.$uname.':'.$udom.' in course '.$cid);
 1447:             $result = &mt('Unable to set interval to [_1] due to [_2].',
 1448:                          '<b>'.$$interval_titles{$env{'form.interval'}}.'</b>',
 1449:                          '<tt>'.$outcome.'</tt>.<br />');
 1450:         }
 1451:     }
 1452:     return $result;
 1453: }
 1454: 
 1455: sub store_discussion_setting {
 1456:     my ($uname,$udom,$cid) = @_;
 1457:     my %discussion_settings;
 1458:     my $result;
 1459:     if (defined($env{'form.countunread'})) {
 1460:         $discussion_settings{$cid.':countunread'} = $env{'form.countunread'};
 1461:         my $outcome = &Apache::lonnet::put('nohist_whatsnew',
 1462:                                              \%discussion_settings,$udom,$uname);
 1463:         if ($outcome eq 'ok') {
 1464:             $result = &mt('Count unread posts in discussions display set to [_1]',
 1465:                   '<b>'.$env{'form.countunread'}.'</b><br />');
 1466:                                                                                   
 1467:         } else {
 1468:             &Apache::lonnet::logthis('Error storing whatsnew countunread setting'.
 1469:                      ' '.$outcome.' for '.$uname.':'.$udom.' in course '.$cid);
 1470:             $result = &mt('Unable to set "number unread posts display" to [_1]'.
 1471:                           ' due to [_2].',
 1472:                          '<b>'.$env{'form.countunread'}.'</b>',
 1473:                          '<tt>'.$outcome.'</tt>.<br />');
 1474:         }
 1475:     }
 1476:     return $result;
 1477: }
 1478: 
 1479: sub store_courseinit_setting {
 1480:     my ($uname,$udom,$cid,$initpage) = @_;
 1481:     my %courseinit_settings;
 1482:     my $page_control;
 1483:     my $result;
 1484:     if (defined($env{'form.courseinit_control'})) {
 1485:         if ($env{'form.courseinit_control'} eq 'userpref') {
 1486:             $courseinit_settings{$cid.':courseinit'} = '';
 1487:             $page_control = 'global preferences';
 1488:         } else {
 1489:             if (defined($env{'form.courseinit_page'})) {
 1490:                 $courseinit_settings{$cid.':courseinit'} = 
 1491:                                                   $env{'form.courseinit_page'};
 1492:                 $page_control = 'course specific setting';
 1493:             }
 1494:         }
 1495:         if ($page_control) {
 1496:             my $outcome = &Apache::lonnet::put('nohist_whatsnew',
 1497:                                            \%courseinit_settings,$udom,$uname);
 1498:             if ($outcome eq 'ok') {
 1499:                 if ($page_control eq 'global preferences') {
 1500:                     $result = &mt('Page displayed after role selection in course now set by [_1]',"<b>user's global preferences</b>.");
 1501:                 } else {
 1502:                     $result = &mt('Page displayed after role selection in this course set to [_1]','<b>'.$$initpage{$env{'form.courseinit_page'}}.'</b>.');
 1503:                 }
 1504:             } else {
 1505:                 &Apache::lonnet::logthis('Error storing whatsnew courseinit '.
 1506:                                          'setting: '.$outcome.' for '.$uname.
 1507:                                                  ':'.$udom.' in course '.$cid);
 1508:                 if ($page_control eq 'global preferences') {
 1509:                     $result = &mt('Unable to set control of page display to [_1]'.
 1510:                           ' due to [_2].',
 1511:                          '<b>'.$page_control.'</b>',
 1512:                          '<tt>'.$outcome.'</tt>.<br />');
 1513:                 } else {
 1514:                     $result = &mt('Unable to set page display, after role selection, for this course to [_1] due to [_2].',
 1515:                          '<b>'.$$initpage{$env{'form.courseinit_page'}}.'</b>',
 1516:                          '<tt>'.$outcome.'</tt>.<br />');
 1517:                 }
 1518:             }
 1519:         }
 1520:     }
 1521:     return $result;
 1522: }
 1523: 
 1524: sub start_box {
 1525:     my ($r,$tabbg,$show,$heading,$caller,$refpage) = @_;
 1526:     my %lt = &Apache::lonlocal::texthash( 
 1527:                        chth => 'Change thresholds?',
 1528:                        chin => 'Change interval?',
 1529:                        chop => 'Change options?',
 1530:     );
 1531:     my $showhide;
 1532:     if ($$show{$caller}) {
 1533:         $showhide = '<b><a href="javascript:change_display(document.visible.'.
 1534:                                'display_'.$caller.",'hide'".');">Hide</a></b>';
 1535:    
 1536:     } else {
 1537:         $showhide = '<b><a href="javascript:change_display(document.visible.'.
 1538:                                'display_'.$caller.",'show'".');">Show</a></b>';
 1539:     }
 1540:     
 1541:     $r->print('
 1542:          <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
 1543:           <tr>
 1544:            <td>
 1545:             <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
 1546:               <tr>
 1547:                <td bgcolor="'.$tabbg.'">
 1548:                 <table width="100%" border="0" cellspacing="0" cellpadding="0">
 1549:                  <tr>
 1550:                   <td><b>'.$$heading{$caller}.'</b></td>
 1551:                   <td valign="top" align="right">'.$showhide.'</td>
 1552:                  </tr>
 1553:                 </table>
 1554:                </td>
 1555:               </tr>');
 1556:      if (($caller eq 'abovethreshold') && ($$show{$caller})) {
 1557:          if ($$show{$caller}) {
 1558:              $r->print('
 1559:               <tr>
 1560:                 <td bgcolor="'.$tabbg.'" align="right"><a href="/adm/whatsnew?command=chgthreshold&refpage='.$refpage.'"><b><small>'.$lt{'chth'}.'</small></b></a></td>
 1561:               </tr>');
 1562:          }
 1563:      } elsif (($caller eq 'versionchanges') && ($$show{$caller})) {
 1564:          if ($$show{$caller}) {
 1565:              $r->print('
 1566:               <tr>
 1567:                 <td bgcolor="'.$tabbg.'" align="right"><a href="/adm/whatsnew?command=chginterval&refpage='.$refpage.'"><b><small>'.$lt{'chin'}.'</small></b></a></td>
 1568:               </tr>');
 1569:          }
 1570:      } elsif ($caller eq 'coursediscussion') {
 1571:          if ($$show{$caller}) {
 1572:              $r->print('
 1573:               <tr>
 1574:                 <td bgcolor="'.$tabbg.'" align="right"><a href="/adm/whatsnew?command=chgdisc&refpage='.$refpage.'"><b><small>'.$lt{'chop'}.'</small></b></a></td>
 1575:               </tr>');
 1576:          }
 1577:      }
 1578:      $r->print('
 1579:               <tr>
 1580:                <td bgcolor="#ffffff">
 1581:                 <table cellpadding="2" cellspacing="0" border="0" width="100%">
 1582: ');
 1583:     return;
 1584: }
 1585: 
 1586: sub end_box {
 1587:     my ($r) = shift;
 1588:     $r->print('
 1589:       </table>
 1590:      </td>
 1591:     </tr>
 1592:    </table>
 1593:   </td>
 1594:  </tr>
 1595: </table><br />');
 1596:     return;
 1597: }
 1598: 
 1599: 1;

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