Annotation of loncom/interface/lonwhatsnew.pm, revision 1.47

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

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