[LON-CAPA-cvs] cvs: loncom /homework lonhomework.pm /interface lonhtmlcommon.pm lonmenu.pm rat lonpage.pm

raeburn raeburn at source.lon-capa.org
Fri Jul 17 15:11:10 EDT 2015


raeburn		Fri Jul 17 19:11:10 2015 EDT

  Modified files:              
    /rat	lonpage.pm 
    /loncom/interface	lonmenu.pm lonhtmlcommon.pm 
    /loncom/homework	lonhomework.pm 
  Log:
  - Include countdown timer in composite page (i.e., .page), if all items
    with time left have the same amount of time remaining.
  
  
-------------- next part --------------
Index: rat/lonpage.pm
diff -u rat/lonpage.pm:1.110 rat/lonpage.pm:1.111
--- rat/lonpage.pm:1.110	Fri Jul 17 19:00:47 2015
+++ rat/lonpage.pm	Fri Jul 17 19:11:03 2015
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Page Handler
 #
-# $Id: lonpage.pm,v 1.110 2015/07/17 19:00:47 raeburn Exp $
+# $Id: lonpage.pm,v 1.111 2015/07/17 19:11:03 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -40,6 +40,7 @@
 use Apache::lonxml();
 use Apache::lonlocal;
 use Apache::lonmenu;
+use Apache::lonhomework;
 use HTML::TokeParser;
 use GDBM_File;
 use Apache::lonsequence;
@@ -187,6 +188,18 @@
               my $firstres=$hash{'map_start_'.$requrl};
               my $lastres=$hash{'map_finish_'.$requrl};
               if (($firstres) && ($lastres)) {
+# ------------------------------------------------------------- Countdown Timer
+                  my $now = time;
+                  my ($pagefirstaccess,%hastimeleft,%countdowndisp);
+                  my ($pagesymb,$courseid,$domain,$name)=&Apache::lonnet::whichuser();
+                  if (($pagesymb && ($courseid ne '') && ($domain ne '') && ($name ne '')) {
+                      my %times=&Apache::lonnet::get('firstaccesstimes',
+                                                     [$courseid."\0".$pagesymb],
+                                                     $domain,$name);
+                      if ($times{$courseid."\0".$pagesymb} =~ /^\d+$/) {
+                          $pagefirstaccess = $times{$courseid."\0".$pagesymb};
+                      }
+                  }
 # ----------------------------------------------------------------- Render page
 
                   @rows=();
@@ -417,6 +430,59 @@
                                       s/\<((?:input|select)[^\>]+\Qjavascript:setSubmittedPart\E)\(\s*[\'\"]([^\'\"]+)[\'\"]*\s*\)/\<$1('$2','$prefix')/gsi;
                                   $output=~
                                       s/\<(input[^\>]+\Qonfocus=\"javascript:disableAutoComplete\E)\(\'([^\']+)\'\)(;\")/\<$1('$idprefix$2')$3/gsi;
+                                  unless ($hastimer) {
+                                      if ($src =~ /$LONCAPA::assess_re/) {
+                                          %Apache::lonhomework::history =
+                                              &Apache::lonnet::restore($symb,$courseid,$domain,$name);
+                                          my $type = 'problem';
+                                          if ($src =~ /\.task$/) {
+                                              $type = 'Task';
+                                          }
+                                          my ($status,$accessmsg,$slot_name,$slot) =
+                                              &Apache::lonhomework::check_slot_access('0',$type,$symb);
+                                          undef(%Apache::lonhomework::history);
+                                          my $probstatus = &Apache::lonnet::EXT("resource.0.problemstatus",$symb);
+                                          if (($status eq 'CAN_ANSWER') || (($status eq 'CANNOT_ANSWER') && 
+                                              (($probstatus eq 'no') || ($probstatus eq 'no_feedback_ever')))) {
+                                              my ($slothastime,$timerhastime);
+                                              if ($slot_name ne '') {
+                                                  if (ref($slot) eq 'HASH') {
+                                                      if (($slot->{'starttime'} < $now) &&
+                                                          ($slot->{'endtime'} > $now)) {
+                                                          $slothastime = $now - $slot->{'endtime'};
+                                                      }
+                                                  }
+                                              }
+                                              my $duedate = &Apache::lonnet::EXT("resource.0.duedate",$symb);
+                                              my @interval=&Apache::lonnet::EXT("resource.0.interval",$symb);
+                                              if (@interval > 1) {
+                                                  my $first_access=&Apache::lonnet::get_first_access($interval[1],$symb);
+                                                  if ($first_access > 0) {
+                                                      my $timeremains = $first_access+$interval[0] - $now;
+                                                      if ($timeremains > 0) {
+                                                          $timerhastime = $timeremains;
+                                                      }
+                                                  }
+                                              }
+                                              if (($duedate && $duedate > $now) ||
+                                                  (!$duedate && $timerhastime > 0) ||
+                                                  ($slot_name ne '' && $slothastime)) {
+                                                  if ((@interval > 1 && $timerhastime) ||
+                                                      ($type eq 'Task' && $slothastime)) {
+                                                      $countdowndisp{$symb} = 'inline';
+                                                      if ((@interval > 1) && ($timerhastime)) {
+                                                          $hastimeleft{$symb} = $timerhastime;
+                                                      } else {
+                                                          $hastimeleft{$symb} = $slothastime;
+                                                      }
+                                                  } else {
+                                                      $hastimeleft{$symb} = $duedate - $now;
+                                                      $countdowndisp{$symb} = 'none';
+                                                  }
+                                              }
+                                          }
+                                      }
+                                  }
                               }
                               $thisdir=~s/\/[^\/]*$//;
 			      foreach (@rlinks) {
@@ -483,6 +549,33 @@
                                             '// ]]>'.
                                             "\n</script>\n";
                           }
+                          if (keys(%hastimeleft)) {
+                              my (%uniquetimes,%uniquedisplays);
+                              foreach my $item (values(%hastimeleft)) {
+                                  if (exists($uniquetimes{$item})) {
+                                      $uniquetimes{$item} ++; 
+                                  } else {
+                                      $uniquetimes{$item} = 1;
+                                  }
+                              }
+                              if (keys(%uniquetimes) == 1) {
+                                  my (%uniquedisplays,%uniquedones,$currdisp);
+                                  if (keys(%countdowndisp)) {
+                                      foreach my $item (values(%countdowndisp)) {
+                                          if (exists($uniquedisplays{$item})) {
+                                              $uniquedisplays{$item} ++;
+                                          } else {
+                                              $uniquedisplays{$item} = 1;
+                                          }
+                                      }
+                                      my @countdowndisplay = keys(%uniquedisplays);
+                                      if (scalar(@countdowndisplay) == 1) {
+                                          $currdisp = $countdowndisplay[0];
+                                      }
+                                  }
+                                  &add_countdown_timer($currdisp);
+                              }
+                          }
 # ------------------------------------------------------------------ Start body
 			  $r->print(&Apache::loncommon::start_page(undef,$allscript,
 								   {'force_register' => 1,
@@ -753,6 +846,35 @@
     return $metainfo;
 }
 
+sub add_countdown_timer {
+    my ($currdisp) = @_;
+    my ($collapse,$expand,$alttxt,$title);
+    if ($currdisp eq 'inline') {
+        $collapse = '► ';
+    } else {
+        $expand = '◄ ';
+    }
+    unless ($env{'environment.icons'} eq 'iconsonly') {
+        $alttxt = &mt('Timer');
+        $title = $alttxt.' ';
+    }
+    my $desc = &mt('Countdown to due date/time');
+    my $output = <<END;
+<a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
+<span id="ddcountcollapse" class="LC_menubuttons_inline_text">
+$collapse
+</span></a>
+<span id="duedatecountdown" class="LC_menubuttons_inline_text" style="display: $currdisp;"></span>
+<a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
+<span id="ddcountexpand" class="LC_menubuttons_inline_text" >$expand</span>
+<img src="/res/adm/pages/timer.png" title="$desc" class="LC_icon" alt="$alttxt" /><span class="LC_menubuttons_inline_text">$title</span></a>
+END
+    &Apache::lonhtmlcommon::clear_breadcrumb_tools();
+    &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$output);
+    return;
+}
+
+
 1;
 __END__
 
Index: loncom/interface/lonmenu.pm
diff -u loncom/interface/lonmenu.pm:1.435 loncom/interface/lonmenu.pm:1.436
--- loncom/interface/lonmenu.pm:1.435	Wed Jun 17 03:57:15 2015
+++ loncom/interface/lonmenu.pm	Fri Jul 17 19:11:06 2015
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines to control the menu
 #
-# $Id: lonmenu.pm,v 1.435 2015/06/17 03:57:15 musolffc Exp $
+# $Id: lonmenu.pm,v 1.436 2015/07/17 19:11:06 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -634,8 +634,18 @@
                                                        && $maptitle ne $coursetitle);
 
             push @crumbs, {text => $restitle, no_mt => 1} if $restitle; 
+            my @tools;
+            if ($env{'request.filename'} =~ /\.page$/) {
+                my %breadcrumb_tools = &Apache::lonhtmlcommon::current_breadcrumb_tools();
+                if (ref($breadcrumb_tools{'tools'}) eq 'ARRAY') {
+                    @tools = @{$breadcrumb_tools{'tools'}};
+                }
+            }
             &Apache::lonhtmlcommon::clear_breadcrumbs();
             &Apache::lonhtmlcommon::add_breadcrumb(@crumbs);
+            if (@tools) {
+                &Apache::lonhtmlcommon::add_breadcrumb_tool('tools', at tools);
+            }
         } else {
             $resurl = $env{'request.noversionuri'};
             my $courseurl = &Apache::lonnet::courseid_to_courseurl($env{'request.course.id'});
@@ -895,13 +905,20 @@
 	    my $addremote=0;
 	    foreach (@inlineremote) { if ($_ ne '') { $addremote=1; last;} }
     if ($addremote) {
-
+        my $countdown;
+        if ($env{'request.filename'} =~ /\.page$/) {
+            my %breadcrumb_tools = &Apache::lonhtmlcommon::current_breadcrumb_tools();
+            if (ref($breadcrumb_tools{'tools'}) eq 'ARRAY') {
+                $countdown = $breadcrumb_tools{'tools'}[0];
+            }
+        } else {
+            $countdown = &countdown_timer();
+        }
         &Apache::lonhtmlcommon::clear_breadcrumb_tools();
 
             &Apache::lonhtmlcommon::add_breadcrumb_tool(
                 'navigation', @inlineremote[21,23]);
 
-        my $countdown = &countdown_timer();
         if (&hidden_button_check() eq 'yes') {
             if ($countdown) {
                 &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$countdown);
Index: loncom/interface/lonhtmlcommon.pm
diff -u loncom/interface/lonhtmlcommon.pm:1.367 loncom/interface/lonhtmlcommon.pm:1.368
--- loncom/interface/lonhtmlcommon.pm:1.367	Tue Jul  7 20:10:20 2015
+++ loncom/interface/lonhtmlcommon.pm	Fri Jul 17 19:11:06 2015
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common html routines
 #
-# $Id: lonhtmlcommon.pm,v 1.367 2015/07/07 20:10:20 musolffc Exp $
+# $Id: lonhtmlcommon.pm,v 1.368 2015/07/17 19:11:06 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2098,6 +2098,16 @@
         undef(%tools);
     }
 
+=item &current_breadcrumb_tools()
+
+returns: a hash containing the current breadcrumb tools.
+
+=cut
+
+    sub current_breadcrumb_tools {
+        return %tools;
+    }
+
 =item &render_tools(\$breadcrumbs)
 
 Creates html for breadcrumb tools (categories navigation and tools) and inserts 
Index: loncom/homework/lonhomework.pm
diff -u loncom/homework/lonhomework.pm:1.355 loncom/homework/lonhomework.pm:1.356
--- loncom/homework/lonhomework.pm:1.355	Mon Jun 29 15:42:07 2015
+++ loncom/homework/lonhomework.pm	Fri Jul 17 19:11:09 2015
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Homework handler
 #
-# $Id: lonhomework.pm,v 1.355 2015/06/29 15:42:07 damieng Exp $
+# $Id: lonhomework.pm,v 1.356 2015/07/17 19:11:09 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -210,12 +210,12 @@
 }
 
 sub check_slot_access {
-    my ($id,$type)=@_;
+    my ($id,$type,$symb)=@_;
 
     # does it pass normal muster
-    my ($status,$datemsg)=&check_access($id);
+    my ($status,$datemsg)=&check_access($id,$symb);
     
-    my $useslots = &Apache::lonnet::EXT("resource.0.useslots");
+    my $useslots = &Apache::lonnet::EXT("resource.0.useslots",$symb);
     if ($useslots ne 'resource' && $useslots ne 'map' 
 	&& $useslots ne 'map_map') {
 	return ($status,$datemsg);
@@ -239,8 +239,8 @@
 	}
     }
 
-    my $availablestudent = &Apache::lonnet::EXT("resource.0.availablestudent");
-    my $available = &Apache::lonnet::EXT("resource.0.available");
+    my $availablestudent = &Apache::lonnet::EXT("resource.0.availablestudent",$symb);
+    my $available = &Apache::lonnet::EXT("resource.0.available",$symb);
     my @slots= (split(':',$availablestudent),split(':',$available));
 
 #    if (!@slots) {
@@ -312,7 +312,9 @@
                 if ($env{'request.course.id'}) {
                     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
-                    my ($symb)=&Apache::lonnet::whichuser();
+                    unless ($symb) {
+                        ($symb)=&Apache::lonnet::whichuser();
+                    }
                     $slotstatus = 'NOTRESERVABLE';
                     my ($reservable_now_order,$reservable_now,$reservable_future_order,
                         $reservable_future) = 
@@ -366,7 +368,7 @@
 # JB, 9/24/2002: Any changes in this function may require a change
 # in lonnavmaps::resource::getDateStatus.
 sub check_access {
-    my ($id) = @_;
+    my ($id,$symb) = @_;
     my $date ='';
     my $status;
     my $datemsg = '';
@@ -396,11 +398,13 @@
     &Apache::lonxml::debug("checking for part :$id:");
     &Apache::lonxml::debug("time:".time);
 
-    my ($symb)=&Apache::lonnet::whichuser();
+    unless ($symb) {
+        ($symb)=&Apache::lonnet::whichuser();
+    }
     &Apache::lonxml::debug("symb:".$symb);
     #if ($env{'request.state'} ne "construct" && $symb ne '') {
     if ($env{'request.state'} ne "construct") {
-        my $idacc = &Apache::lonnet::EXT("resource.$id.acc");
+        my $idacc = &Apache::lonnet::EXT("resource.$id.acc",$symb);
 	my $allowed=&Apache::loncommon::check_ip_acc($idacc);
 	if (!$allowed && ($Apache::lonhomework::browse ne 'F')) {
 	    $status='INVALID_ACCESS';
@@ -416,12 +420,12 @@
 	foreach my $temp ("opendate","duedate","answerdate") {
 	    $lastdate = $date;
 	    if ($temp eq 'duedate') {
-		$date = &due_date($id);
+		$date = &due_date($id,$symb);
 	    } else {
-		$date = &Apache::lonnet::EXT("resource.$id.$temp");
+		$date = &Apache::lonnet::EXT("resource.$id.$temp",$symb);
 	    }
 	    
-	    my $thistype = &Apache::lonnet::EXT("resource.$id.$temp.type");
+	    my $thistype = &Apache::lonnet::EXT("resource.$id.$temp.type",$symb);
 	    if ($thistype =~ /^(con_lost|no_such_host)/ ||
 		$date     =~ /^(con_lost|no_such_host)/) {
 		$status='UNAVAILABLE';
@@ -430,10 +434,10 @@
 	    }
 	    if ($thistype eq 'date_interval') {
 		if ($temp eq 'opendate') {
-		    $date=&Apache::lonnet::EXT("resource.$id.duedate")-$date;
+		    $date=&Apache::lonnet::EXT("resource.$id.duedate",$symb)-$date;
 		}
 		if ($temp eq 'answerdate') {
-		    $date=&Apache::lonnet::EXT("resource.$id.duedate")+$date;
+		    $date=&Apache::lonnet::EXT("resource.$id.duedate",$symb)+$date;
 		}
 	    }
 	    &Apache::lonxml::debug("found :$date: for :$temp:");
@@ -467,7 +471,7 @@
 	(($Apache::lonhomework::browse eq 'F') && ($status eq 'CLOSED'))) {
 	#check #tries, and if correct.
 	my $tries = $Apache::lonhomework::history{"resource.$id.tries"};
-	my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries");
+	my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries",$symb);
 	if ( $tries eq '' ) { $tries = '0'; }
 	if ( $maxtries eq '' && 
 	     $env{'request.state'} ne 'construct') { $maxtries = '2'; } 
@@ -476,7 +480,7 @@
 	if ( ($Apache::lonhomework::history{"resource.$id.solved"}=~/^correct/)
 	      && (&show_problem_status()) ) {
             if (($Apache::lonhomework::history{"resource.$id.awarded"} >= 1) ||
-                (&Apache::lonnet::EXT("resource.$id.retrypartial") !~/^1|on|yes$/i)) {
+                (&Apache::lonnet::EXT("resource.$id.retrypartial",$symb) !~/^1|on|yes$/i)) {
 	        $status = 'CANNOT_ANSWER';
             }
         } elsif ($Apache::lonhomework::history{"resource.$id.solved"}=~/^excused/) {
@@ -488,14 +492,14 @@
 	}
     }
     if ($status eq 'CAN_ANSWER' || $status eq 'CANNOT_ANSWER') {
-	my @interval=&Apache::lonnet::EXT("resource.$id.interval");
+	my @interval=&Apache::lonnet::EXT("resource.$id.interval",$symb);
 	&Apache::lonxml::debug("looking for interval @interval");
 	if ($interval[0]) {
-	    my $first_access=&Apache::lonnet::get_first_access($interval[1]);
+	    my $first_access=&Apache::lonnet::get_first_access($interval[1],$symb);
 	    &Apache::lonxml::debug("looking for accesstime $first_access");
 	    if (!$first_access) {
 		$status='NOT_YET_VIEWED';
-		my $due_date = &due_date($id);
+		my $due_date = &due_date($id,$symb);
 		my $seconds_left = $due_date - time;
 		if ($seconds_left > $interval[0] || $due_date eq '') {
 		    $seconds_left = $interval[0];
@@ -1356,7 +1360,7 @@
 sub zero_timer {
     my ($symb) = @_;
     my ($hastimeleft,$first_access,$now);
-    my @interval=&Apache::lonnet::EXT("resource.0.interval");
+    my @interval=&Apache::lonnet::EXT("resource.0.interval",$symb);
     if (@interval > 1) {
         if ($interval[1] eq 'course') {
             return;


More information about the LON-CAPA-cvs mailing list