[LON-CAPA-cvs] cvs: loncom /homework lonhomework.pm structuretags.pm /interface lonnavmaps.pm /lonnet/perl lonnet.pm /publisher packages.tab

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 27 May 2004 22:25:19 -0000


albertel		Thu May 27 18:25:19 2004 EDT

  Modified files:              
    /loncom/interface	lonnavmaps.pm 
    /loncom/publisher	packages.tab 
    /loncom/homework	lonhomework.pm structuretags.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - new parmater 'interval'
  - lonnavmaps, lonhomework respect the 'interval' value
      - if it exits
      - they check if it has been accessed yet (lonnet::get_first_access)
      - if it has then duedate is first_access+interval
      - if it hasn't then duedate is duedate
  
  
  
Index: loncom/interface/lonnavmaps.pm
diff -u loncom/interface/lonnavmaps.pm:1.259 loncom/interface/lonnavmaps.pm:1.260
--- loncom/interface/lonnavmaps.pm:1.259	Wed May  5 17:04:14 2004
+++ loncom/interface/lonnavmaps.pm	Thu May 27 18:25:14 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Navigate Maps Handler
 #
-# $Id: lonnavmaps.pm,v 1.259 2004/05/05 21:04:14 raeburn Exp $
+# $Id: lonnavmaps.pm,v 1.260 2004/05/27 22:25:14 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3417,6 +3417,11 @@
 }
 sub duedate {
     (my $self, my $part) = @_;
+    my $interval=$self->parmval("interval", $part);
+    if ($interval) {
+	my $first_access=&Apache::lonnet::get_first_access('map',$self->symb);
+	if ($first_access) { return ($first_access+$interval); }
+    }
     return $self->parmval("duedate", $part);
 }
 sub maxtries {
Index: loncom/publisher/packages.tab
diff -u loncom/publisher/packages.tab:1.30 loncom/publisher/packages.tab:1.31
--- loncom/publisher/packages.tab:1.30	Tue May 25 01:38:12 2004
+++ loncom/publisher/packages.tab	Thu May 27 18:25:16 2004
@@ -32,6 +32,8 @@
 part_0&encrypturl&display:Do not show plain URL
 part_0&mapalias&type:string
 part_0&mapalias&display:Resource alias name for conditions
+part_0&interval&display:Length of Time Open
+part_0&interval&type:date_interval
 numericalhint&tol&display:Numerical Tolerance
 numericalhint&tol&type:tolerance
 numericalhint&tol&default:5%
@@ -85,7 +87,7 @@
 
 default&contentopen&display:Opening Date
 default&contentopen&type:date_start
-default&contentclose&display:Due Date
+default&contentclose&display:Close Date
 default&contentclose&type:date_end
 default&mapalias&type:string
 default&mapalias&display:Resource alias name for conditions
Index: loncom/homework/lonhomework.pm
diff -u loncom/homework/lonhomework.pm:1.176 loncom/homework/lonhomework.pm:1.177
--- loncom/homework/lonhomework.pm:1.176	Wed May 26 18:45:57 2004
+++ loncom/homework/lonhomework.pm	Thu May 27 18:25:16 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Homework handler
 #
-# $Id: lonhomework.pm,v 1.176 2004/05/26 22:45:57 albertel Exp $
+# $Id: lonhomework.pm,v 1.177 2004/05/27 22:25:16 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -292,7 +292,26 @@
 	    $status = 'CANNOT_ANSWER';
 	}
     }
-
+    if ($status eq 'CAN_ANSWER') {
+	my $interval=&Apache::lonnet::EXT("resource.$id.interval");
+	&Apache::lonxml::debug("looking for interval $interval");
+	if ($interval) {
+	    my $first_access=&Apache::lonnet::get_first_access('map');
+	    &Apache::lonxml::debug("looking for accesstime $first_access");
+	    if (!$first_access) {
+		$status='NOT_YET_VIEWED';
+		$datemsg=' '.$interval.' seconds';
+	    } else {
+		my $newdate=localtime($first_access+$interval);
+		if (time > ($first_access+$interval)) {
+		    $status='CLOSED';
+		    $datemsg = &mt("was due on")." $newdate".&mt(", and answers will be available on")." $date";
+		} else {
+		    $datemsg = &mt("is due at")." $newdate";
+		}
+	    }
+	}
+    }
   #if (($status ne 'CLOSED') && ($Apache::lonhomework::type eq 'exam') &&
   #    (!$Apache::lonhomework::history{"resource.0.outtoken"})) {
   #    return ('UNCHECKEDOUT','needs to be checked out');
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.251 loncom/homework/structuretags.pm:1.252
--- loncom/homework/structuretags.pm:1.251	Thu May 27 00:32:19 2004
+++ loncom/homework/structuretags.pm	Thu May 27 18:25:16 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: structuretags.pm,v 1.251 2004/05/27 04:32:19 albertel Exp $
+# $Id: structuretags.pm,v 1.252 2004/05/27 22:25:16 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -334,6 +334,17 @@
 ENDCHECKOUT
 }
 
+sub firstaccess_msg {
+    my ($time)=@_;
+    return (<<ENDCHECKOUT);
+<h2>This resource is open for a limited time, once you click the 'Show Resource' button below you have $time to complete all resources in this sequence.</h2>
+<form name="markaccess" method="POST" action="$ENV{'request.uri'}">
+<input type="hidden" name="markaccess" value="yes" />
+<input type="button" name="accessbutton" value="Show Resource" onClick="javascript:if (confirm('Start Timer?')) { document.markaccess.submit(); }" />
+</form>
+ENDCHECKOUT
+}
+
 sub init_problem_globals {
     my ($type)=@_;
     #initialize globals
@@ -458,7 +469,9 @@
 	    }
 	    $body_tag_start.=&Apache::lonxml::printtokenheader($target,$token);
 	}
-
+	if ($ENV{'form.markaccess'}) {
+	    &Apache::lonnet::set_first_access('map');
+	}
 	#handle rand seed in construction space
 	my $rndseed=&setup_rndseed($safeeval);
 	my ($symb)=&Apache::lonxml::whichuser();
@@ -478,6 +491,7 @@
 	&Apache::lonxml::debug("Got $status");
 	if (( $status eq 'CLOSED' ) ||
 	    ( $status eq 'UNCHECKEDOUT') ||
+	    ( $status eq 'NOT_YET_VIEWED') ||
 	    ( $status eq 'BANNED') ||
 	    ( $status eq 'UNAVAILABLE') ||
 	    ( $status eq 'INVALID_ACCESS')) {
@@ -494,6 +508,8 @@
 		    $msg.='The problem '.$accessmsg;
 		} elsif ($status eq 'UNCHECKEDOUT') {
 		    $msg.=&checkout_msg;
+		} elsif ($status eq 'NOT_YET_VIEWED') {
+		    $msg.=&firstaccess_msg($accessmsg);
 		}
 		$result.=$msg.'<br />';
 	    } elsif ($target eq 'tex') {
@@ -603,7 +619,7 @@
 	    }
 	} elsif ( ($target eq 'web' || $target eq 'tex') &&
 		  $Apache::inputtags::part eq '0' &&
-		  $status ne 'UNCHECKEDOUT') {
+		  $status ne 'UNCHECKEDOUT' && $status ne 'NOT_YET_VIEWED') {
 	    # if part is zero, no <part>s existed, so we need show the current
 	    # grading status
 	    my $gradestatus = &Apache::inputtags::gradestatus($Apache::inputtags::part,$target);
@@ -1037,6 +1053,7 @@
 	    }
 	    if (( $status eq 'CLOSED' ) ||
 		( $status eq 'UNCHECKEDOUT') ||
+		( $status eq 'NOT_YET_VIEWED') ||
 		( $status eq 'BANNED') ||
 		( $status eq 'UNAVAILABLE') ||
 		( $status eq 'INVALID_ACCESS')) {
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.503 loncom/lonnet/perl/lonnet.pm:1.504
--- loncom/lonnet/perl/lonnet.pm:1.503	Thu May 27 00:25:12 2004
+++ loncom/lonnet/perl/lonnet.pm	Thu May 27 18:25:16 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.503 2004/05/27 04:25:12 albertel Exp $
+# $Id: lonnet.pm,v 1.504 2004/05/27 22:25:16 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1638,6 +1638,24 @@
 #
 # ----------------------------------------------------------- Check out an item
 
+sub get_first_access {
+    my ($type,$argsymb)=@_;
+    my ($symb,$courseid,$udom,$uname)=&Apache::lonxml::whichuser();
+    if ($argsymb) { $symb=$argsymb; }
+    my ($map,$id,$res)=&decode_symb($symb);
+    if ($type eq 'map') { $res=$map; }
+    my %times=&get('firstaccesstimes',[$res],$udom,$uname);
+    return $times{$res};
+}
+
+sub set_first_access {
+    my ($type)=@_;
+    my ($symb,$courseid,$udom,$uname)=&Apache::lonxml::whichuser();
+    my ($map,$id,$res)=&decode_symb($symb);
+    if ($type eq 'map') { $res=$map; }
+    return &put('firstaccesstimes',{$res=>time},$udom,$uname);
+}
+
 sub checkout {
     my ($symb,$tuname,$tudom,$tcrsid)=@_;
     my $now=time;