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

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

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