[LON-CAPA-cvs] cvs: loncom /homework bridgetask.pm /interface slotrequest.pm

albertel lon-capa-cvs@mail.lon-capa.org
Sat, 04 Jun 2005 08:17:10 -0000


albertel		Sat Jun  4 04:17:10 2005 EDT

  Modified files:              
    /loncom/interface	slotrequest.pm 
    /loncom/homework	bridgetask.pm 
  Log:
  - after requesting a new slot the 'request a new time' button disappears
  - this requires a new slot info to be set 'startreserve'
  
  
Index: loncom/interface/slotrequest.pm
diff -u loncom/interface/slotrequest.pm:1.3 loncom/interface/slotrequest.pm:1.4
--- loncom/interface/slotrequest.pm:1.3	Sat Jun  4 03:44:48 2005
+++ loncom/interface/slotrequest.pm	Sat Jun  4 04:17:06 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler for requesting to have slots added to a students record
 #
-# $Id: slotrequest.pm,v 1.3 2005/06/04 07:44:48 albertel Exp $
+# $Id: slotrequest.pm,v 1.4 2005/06/04 08:17:06 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -105,6 +105,35 @@
     return 0;
 }
 
+sub check_for_reservation {
+    my ($symb)=@_;
+    my $student = &Apache::lonnet::EXT("resource.0.availablestudent", $symb,
+				       $env{'user.domain'}, $env{'user.name'});
+
+    my $course = &Apache::lonnet::EXT("resource.0.available", $symb,
+				    $env{'user.domain'}, $env{'user.name'});
+    my @slots = (split(/:/,$student), split(/:/, $course));
+
+    &Apache::lonxml::debug(" slot list is ".join(':',@slots));
+
+    my ($cnum,$cdom)=&get_course();
+    my %slots=&Apache::lonnet::get('slots', [@slots], $cdom, $cnum);
+
+    foreach my $slot_name (@slots) {
+	next if (!defined($slots{$slot_name}) ||
+		 !ref($slots{$slot_name}));
+	&Apache::lonxml::debug(time." $slot_name ".
+			       $slots{$slot_name}->{'starttime'}." -- ".
+			       $slots{$slot_name}->{'startreserve'});
+	if ($slots{$slot_name}->{'starttime'} > time &&
+	    $slots{$slot_name}->{'startreserve'} < time) {
+	    # between start of reservation times and start of slot
+	    return($slot_name, $slots{$slot_name});
+	}
+    }
+    return (undef,undef);
+}
+
 # FIXME - depends on the parameter for the resource to be correct
 #         tho prevent multiple reservations
 
@@ -257,7 +286,7 @@
     my ($slot_name,$slot)=@_;
     my $description=$slot->{'description'};
     if (!defined($description)) {
-	$description=&mt('[_1] From [_2] to [_3]',$slot,
+	$description=&mt('[_1] From [_2] to [_3]',$slot_name,
 			 &Apache::lonlocal::locallocaltime($slot->{'starttime'}),
 			 &Apache::lonlocal::locallocaltime($slot->{'endtime'}));
     }
Index: loncom/homework/bridgetask.pm
diff -u loncom/homework/bridgetask.pm:1.36 loncom/homework/bridgetask.pm:1.37
--- loncom/homework/bridgetask.pm:1.36	Tue May 31 17:11:56 2005
+++ loncom/homework/bridgetask.pm	Sat Jun  4 04:17:06 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: bridgetask.pm,v 1.36 2005/05/31 21:11:56 albertel Exp $
+# $Id: bridgetask.pm,v 1.37 2005/06/04 08:17:06 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -36,6 +36,7 @@
 use Apache::lonmenu;
 use Apache::lonlocal;
 use Apache::lonxml;
+use Apache::slotrequest();
 use Time::HiRes qw( gettimeofday tv_interval );
 
 BEGIN {
@@ -166,13 +167,23 @@
 sub add_request_another_attempt_button {
     my $result;
     my $symb=&Apache::lonnet::symbread();
-    if ($env{'request.enc'}) { $symb=&Apache::lonenc::encrypted($symb); }
-    $symb=&Apache::lonnet::escape($symb);
-    $result.='<form method="POST" action="/adm/slotrequest">'.
-	'<input type="hidden" name="symb" value="'.$symb.'" />'.
-	'<input type="submit" name="requestattempt" value="'.
-	        &mt("Request another attempt").'" />'.
-	'</form>';
+    my ($slot_name,$slot)=&Apache::slotrequest::check_for_reservation($symb);
+    if ($slot_name) {
+	my $description=&Apache::slotrequest::get_description($slot_name,
+							      $slot);
+	$result.=(<<STUFF);
+<p> Will be next available: $description </p>
+STUFF
+
+    } else {
+	if ($env{'request.enc'}) { $symb=&Apache::lonenc::encrypted($symb); }
+	$symb=&Apache::lonnet::escape($symb);
+	$result.='<form method="POST" action="/adm/slotrequest">'.
+	    '<input type="hidden" name="symb" value="'.$symb.'" />'.
+	    '<input type="submit" name="requestattempt" value="'.
+	    &mt("Request another attempt").'" />'.
+	    '</form>';
+    }
     return $result;
 }