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

albertel lon-capa-cvs@mail.lon-capa.org
Fri, 03 Feb 2006 18:22:45 -0000


albertel		Fri Feb  3 13:22:45 2006 EDT

  Modified files:              
    /loncom/interface	slotrequest.pm 
  Log:
  - check for network erros in a variety of cases
  
  
Index: loncom/interface/slotrequest.pm
diff -u loncom/interface/slotrequest.pm:1.39 loncom/interface/slotrequest.pm:1.40
--- loncom/interface/slotrequest.pm:1.39	Fri Feb  3 12:07:20 2006
+++ loncom/interface/slotrequest.pm	Fri Feb  3 13:22:44 2006
@@ -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.39 2006/02/03 17:07:20 albertel Exp $
+# $Id: slotrequest.pm,v 1.40 2006/02/03 18:22:44 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -89,7 +89,9 @@
 
     my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
 				       "^$slot_name\0");
-    
+    if (&network_error(%consumed)) { 
+	return 'error: Unable to determine current status';
+    }
     my ($tmp)=%consumed;
     if ($tmp=~/^error: 2 / ) {
 	return 0;
@@ -148,6 +150,11 @@
     my @slots = (split(/:/,$student), split(/:/, $course));
     my ($cnum,$cdom)=&get_course();
     my %slots=&Apache::lonnet::get('slots', [@slots], $cdom, $cnum);
+    my ($tmp) = %slots;
+    if (&network_error($student) || &network_error($course)  ||
+	&network_error($tmp)) {
+	return 'error: Unable to determine current status';
+    }    
     foreach my $slot_name (@slots) {
 	next if (!defined($slots{$slot_name}) ||
 		 !ref($slots{$slot_name}));
@@ -163,6 +170,14 @@
 
 }
 
+sub network_error {
+    my ($result) = @_;
+    if ($result =~ /^(con_lost|no_such_host|error: [^2])/) {
+	return 1;
+    }
+    return 0;
+}
+
 sub make_reservation {
     my ($slot_name,$slot,$symb)=@_;
 
@@ -171,11 +186,17 @@
     my $value=&Apache::lonnet::EXT("resource.0.availablestudent",$symb,
 				   $env{'user.domain'},$env{'user.name'});
     &Apache::lonxml::debug("value is  $value<br />");
+    if (&network_error($value)) { 
+	return 'error: Unable to determine current status';
+    }
+
     foreach my $other_slot (split(/:/, $value)) {
 	if ($other_slot eq $slot_name) {
 	    my %consumed=&Apache::lonnet::dump('slot_reservations', $cdom,
 					       $cnum, "^$slot_name\0");   
-
+	    if (&network_error($value)) { 
+		return 'error: Unable to determine current status';
+	    }
 	    my $me=$env{'user.name'}.'@'.$env{'user.domain'};
 	    foreach my $key (keys(%consumed)) {
 		if ($consumed{$key}->{'name'} eq $me) {
@@ -190,7 +211,9 @@
     if (!defined($max)) { $max=99999; }
 
     my (@ids)=&get_reservation_ids($slot_name);
-
+    if (&network_error(@ids)) { 
+	return 'error: Unable to determine current status';
+    }
     my $last=0;
     foreach my $id (@ids) {
 	my $num=(split('\0',$id))[1];
@@ -359,10 +382,22 @@
 	      &mt('Return to last resource').'</a></p>');
 }
 
+sub return_link {
+    my ($r) = @_;
+    $r->print('<p><a href="/adm/flip?postdata=return:">'.
+	      &mt('Return to last resource').'</a></p>');
+}
+
 sub get_slot {
     my ($r,$symb)=@_;
 
     my $slot_name=&check_for_conflict($symb,$env{'form.slotname'});
+
+    if ($slot_name =~ /^error: (.*)/) {
+	$r->print("<p>An error occured while attempting to make a reservation. ($1)</p>");
+	&return_link($r);
+	return;
+    }
     if ($slot_name) {
 	my %slot=&Apache::lonnet::get_slot($slot_name);
 	my $description1=&get_description($slot_name,\%slot);
@@ -383,14 +418,13 @@
 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>');
+		      '</b> <br />or </p>');
+	    &return_link($r);
 	    $r->print(<<STUFF);
 </form>
 STUFF
         } else {
-	    $r->print('<p><a href="/adm/flip?postdata=return:">'.
-		      &mt('Return to last resource').'</a></p>');
+	    &return_link($r);
 	}
 	return;
     }
@@ -399,17 +433,15 @@
 				   \%slot,$symb);
     my $description=&get_description($env{'form.slotname'},\%slot);
     if (defined($reserved)) {
-	if ($reserved > -1) {
+	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>");
-	    $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;
 	}
+	&return_link($r);
+	return;
     }
 
     my %lt=('request'=>"Availibility list",