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

albertel lon-capa-cvs@mail.lon-capa.org
Tue, 09 Aug 2005 15:38:18 -0000


albertel		Tue Aug  9 11:38:18 2005 EDT

  Modified files:              
    /loncom/interface	slotrequest.pm 
  Log:
  - silly to change reservations from slot1 to slot1
  - wasn't handling the case of a full up slot completely correctly
  - was getting double return links when changing slots
  - freed slots were still thought of as not free
  
  
Index: loncom/interface/slotrequest.pm
diff -u loncom/interface/slotrequest.pm:1.6 loncom/interface/slotrequest.pm:1.7
--- loncom/interface/slotrequest.pm:1.6	Tue Aug  9 11:04:50 2005
+++ loncom/interface/slotrequest.pm	Tue Aug  9 11:38:13 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.6 2005/08/09 15:04:50 albertel Exp $
+# $Id: slotrequest.pm,v 1.7 2005/08/09 15:38:13 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -125,9 +125,9 @@
 	&Apache::lonxml::debug(time." $slot_name ".
 			       $slots{$slot_name}->{'starttime'}." -- ".
 			       $slots{$slot_name}->{'startreserve'});
-	if ($slots{$slot_name}->{'starttime'} > time &&
+	if ($slots{$slot_name}->{'endtime'} > time &&
 	    $slots{$slot_name}->{'startreserve'} < time) {
-	    # between start of reservation times and start of slot
+	    # between start of reservation times and end of slot
 	    return($slot_name, $slots{$slot_name});
 	}
     }
@@ -158,9 +158,6 @@
 
 }
 
-# FIXME - depends on the parameter for the resource to be correct
-#         to prevent multiple reservations
-
 sub make_reservation {
     my ($slot_name,$slot,$symb)=@_;
 
@@ -189,7 +186,6 @@
 
     my (@ids)=&get_reservation_ids($slot_name);
 
-    # FIXME we could end up having holes... 
     my $last=0;
     foreach my $id (@ids) {
 	my $num=(split('\0',$id))[1];
@@ -198,9 +194,9 @@
     
     my $wanted=$last+1;
     &Apache::lonxml::debug("wanted $wanted<br />");
-    if ($wanted >= $max) {
+    if (scalar(@ids) >= $max) {
 	# full up
-	return -1;
+	return undef;
     }
     
     my %reservation=('name'      => $env{'user.name'}.'@'.$env{'user.domain'},
@@ -213,7 +209,6 @@
 					$cdom, $cnum);
 
     if ($success eq 'ok') {
-	#FIXME need to set the parm
 	my $new_value=$slot_name;
 	if ($value) {
 	    $new_value=$value.':'.$new_value;
@@ -268,7 +263,7 @@
     my %slot=&Apache::lonnet::get_slot($slot_name);
     my $description=&get_description($env{'form.slotname'},\%slot);
     $r->print("<p>Released Reservation: $description</p>");
-    if ($inhibit_return_link) {
+    if (!$inhibit_return_link) {
 	$r->print('<p><a href="/adm/flip?postdata=return:">'.
 		  &mt('Return to last resource').'</a></p>');
     }
@@ -285,44 +280,50 @@
 	%slot=&Apache::lonnet::get_slot($env{'form.slotname'});
 	my $description2=&get_description($env{'form.slotname'},\%slot);
 	$r->print("<p>Already have a reservation: $description1</p>");
-	$r->print(<<STUFF);
+	if ($slot_name ne $env{'form.slotname'}) {
+	    $r->print(<<STUFF);
 <form method="POST" action="/adm/slotrequest">
    <input type="hidden" name="symb" value="$env{'form.symb'}" />
    <input type="hidden" name="slotname" value="$env{'form.slotname'}" />
    <input type="hidden" name="releaseslot" value="$slot_name" />
    <input type="hidden" name="command" value="change" />
 STUFF
-	$r->print("<p>You can either ");
-	$r->print(<<STUFF);
+            $r->print("<p>You can either ");
+	    $r->print(<<STUFF);
    <input type="submit" name="change" value="Change" />
 STUFF
-	$r->print(' your reservation from <b>'.$description1.'</b> to <b>'.
-		  $description2.
-		  '</b> <br />or <a href="/adm/flip?postdata=return:">'.
-		  &mt('Return to last resource').'</a></p>');
-	$r->print(<<STUFF);
+	    $r->print(' your reservation from <b>'.$description1.'</b> to <b>'.
+		      $description2.
+		      '</b> <br />or <a href="/adm/flip?postdata=return:">'.
+		      &mt('Return to last resource').'</a></p>');
+	    $r->print(<<STUFF);
 </form>
 STUFF
-	# FIXME add button to free current reservation and get new one
+        } else {
+	    $r->print('<p><a href="/adm/flip?postdata=return:">'.
+		      &mt('Return to last resource').'</a></p>');
+	}
 	return;
     }
     my %slot=&Apache::lonnet::get_slot($env{'form.slotname'});
     my $reserved=&make_reservation($env{'form.slotname'},
 				   \%slot,$symb);
     my $description=&get_description($env{'form.slotname'},\%slot);
-    if ($reserved > -1) {
-	$r->print("<p>Success: $description</p>");
-	$r->print('<p><a href="/adm/flip?postdata=return:">'.
-		  &mt('Return to last resource').'</a></p>');
-	return;
-    } elsif ($reserved < 0) {
-	$r->print("<p>Already reserved: $description</p>");
-	$r->print('<p><a href="/adm/flip?postdata=return:">'.
-		  &mt('Return to last resource').'</a></p>');
-	return;
+    if (defined($reserved)) {
+	if ($reserved > -1) {
+	    $r->print("<p>Success: $description</p>");
+	    $r->print('<p><a href="/adm/flip?postdata=return:">'.
+		      &mt('Return to last resource').'</a></p>');
+	    return;
+	} elsif ($reserved < 0) {
+	    $r->print("<p>Already reserved: $description</p>");
+	    $r->print('<p><a href="/adm/flip?postdata=return:">'.
+		      &mt('Return to last resource').'</a></p>');
+	    return;
+	}
     }
 
-    my %lt=('request'=>"Request another attempt",
+    my %lt=('request'=>"Availibility list",
 	    'try'    =>'Try again');
     %lt=&Apache::lonlocal::texthash(%lt);
 
@@ -411,7 +412,8 @@
 	my $description=&get_description($slot,$slots{$slot});
 
 	my $form=&mt('Unavailable');
-	if (&space_available($slot,$slots{$slot},$symb)) {
+	if (($slot eq $got_slot) ||
+	    &space_available($slot,$slots{$slot},$symb)) {
 	    my $text=&mt('Select');
 	    my $command='get';
 	    if ($slot eq $got_slot) {