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

albertel lon-capa-cvs-allow@mail.lon-capa.org
Tue, 10 Apr 2007 23:28:20 -0000


albertel		Tue Apr 10 19:28:20 2007 EDT

  Modified files:              
    /loncom/interface	slotrequest.pm 
  Log:
  - reverse the order of slot reserving first get the new slot then release the old one
  
  
Index: loncom/interface/slotrequest.pm
diff -u loncom/interface/slotrequest.pm:1.74 loncom/interface/slotrequest.pm:1.75
--- loncom/interface/slotrequest.pm:1.74	Tue Apr 10 19:26:49 2007
+++ loncom/interface/slotrequest.pm	Tue Apr 10 19:28:20 2007
@@ -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.74 2007/04/10 23:26:49 albertel Exp $
+# $Id: slotrequest.pm,v 1.75 2007/04/10 23:28:20 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -548,7 +548,7 @@
 }
 
 sub get_slot {
-    my ($r,$symb)=@_;
+    my ($r,$symb,$conflictable_slot,$inhibit_return_link)=@_;
 
     my %slot=&Apache::lonnet::get_slot($env{'form.slotname'});
     my $slot_name=&check_for_conflict($symb,$env{'form.slotname'},\%slot);
@@ -556,9 +556,9 @@
     if ($slot_name =~ /^error: (.*)/) {
 	$r->print("<p>An error occured while attempting to make a reservation. ($1)</p>");
 	&return_link($r);
-	return;
+	return 0;
     }
-    if ($slot_name) {
+    if ($slot_name && $slot_name ne $conflictable_slot) {
 	my %slot=&Apache::lonnet::get_slot($slot_name);
 	my $description1=&get_description($slot_name,\%slot);
 	%slot=&Apache::lonnet::get_slot($env{'form.slotname'});
@@ -586,28 +586,35 @@
         } else {
 	    &return_link($r);
 	}
-	return;
+	return 0;
     }
 
     my $reserved=&make_reservation($env{'form.slotname'},
 				   \%slot,$symb);
     my $description=&get_description($env{'form.slotname'},\%slot);
     if (defined($reserved)) {
+	my $retvalue = 0;
 	if ($slot_name =~ /^error: (.*)/) {
 	    $r->print("<p>An error occured while attempting to make a reservation. ($1)</p>");
 	} elsif ($reserved > -1) {
 	    $r->print("<p>Success: $description</p>");
+	    $retvalue = 1;
 	} elsif ($reserved < 0) {
 	    $r->print("<p>Already reserved: $description</p>");
 	}
-	&return_link($r);
-	return;
+	if (!$inhibit_return_link) { &return_link($r); }
+	return 1;
     }
 
     my %lt=('request'=>"Availibility list",
 	    'try'    =>'Try again');
     %lt=&Apache::lonlocal::texthash(%lt);
 
+    my $extra_input;
+    if ($conflictable_slot) {
+	$extra_input='<input type="hidden" name="releaseslot" value="'.$env{'form.slotname'}.'" />';
+    }
+
     $r->print(<<STUFF);
 <p> <font color="red">Failed</font> to reserve a spot for $description. </p>
 <p>
@@ -615,7 +622,8 @@
    <input type="submit" name="Try Again" value="$lt{'try'}" />
    <input type="hidden" name="symb" value="$env{'form.symb'}" />
    <input type="hidden" name="slotname" value="$env{'form.slotname'}" />
-   <input type="hidden" name="command" value="get" />
+   <input type="hidden" name="command" value="$env{'form.command'}" />
+   $extra_input
 </form>
 ?
 </p>
@@ -629,8 +637,8 @@
 or
 STUFF
 
-    &return_link($r);
-    return;
+    if (!$inhibit_return_link) { &return_link($r); }
+    return 0;
 }
 
 sub allowed_slot {
@@ -1624,8 +1632,8 @@
 	} elsif ($env{'form.command'} eq 'get') {
 	    &get_slot($r,$symb);
 	} elsif ($env{'form.command'} eq 'change') {
-	    if (&release_slot($r,$symb,$env{'form.releaseslot'},1)) {
-		&get_slot($r,$symb);
+	    if (&get_slot($r,$symb,$env{'form.releaseslot'},1)) {
+		&release_slot($r,$symb,$env{'form.releaseslot'});
 	    }
 	} else {
 	    $r->print("<p>Unknown command: ".$env{'form.command'}."</p>");