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

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

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