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

raeburn raeburn@source.lon-capa.org
Sun, 21 Dec 2008 04:14:39 -0000


raeburn		Sun Dec 21 04:14:39 2008 EDT

  Modified files:              
    /loncom/interface	slotrequest.pm 
  Log:
  - Check that navmap objects could be created to avoid ISEs.
  - Response from &get_consumed_uniqueperiods() will be a scalar if this type of error occurred, not a hashref - check for this.
  
  
Index: loncom/interface/slotrequest.pm
diff -u loncom/interface/slotrequest.pm:1.84 loncom/interface/slotrequest.pm:1.85
--- loncom/interface/slotrequest.pm:1.84	Thu Dec 11 14:55:15 2008
+++ loncom/interface/slotrequest.pm	Sun Dec 21 04:14:39 2008
@@ -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.84 2008/12/11 14:55:15 bisitz Exp $
+# $Id: slotrequest.pm,v 1.85 2008/12/21 04:14:39 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -165,6 +165,9 @@
 sub get_consumed_uniqueperiods {
     my ($slots) = @_;
     my $navmap=Apache::lonnavmaps::navmap->new;
+    if (!defined($navmap)) {
+        return 'error: Unable to determine current status';
+    }
     my @problems = $navmap->retrieveResources(undef,
 					      sub { $_[0]->is_problem() },1,0);
     my %used_slots;
@@ -214,9 +217,13 @@
 
     if (!ref($consumed_uniqueperiods)) {
 	$consumed_uniqueperiods = &get_consumed_uniqueperiods($slots);
-	if (&Apache::lonnet::error(%$consumed_uniqueperiods)) {
-	    return 'error: Unable to determine current status';
-	}
+        if (ref($consumed_uniqueperiods) eq 'HASH') {
+	    if (&Apache::lonnet::error(%$consumed_uniqueperiods)) {
+	        return 'error: Unable to determine current status';
+	    }
+        } else {
+            return 'error: Unable to determine current status';
+        }
     }
     
     my ($new_uniq_start,$new_uniq_end) = @{$new_slot->{'uniqueperiod'}};
@@ -229,7 +236,6 @@
 	}
     }
     return undef;
-
 }
 
 sub make_reservation {
@@ -413,7 +419,11 @@
 	my ($result,$msg) =
 	    &release_reservation($slot_name,$uname,$udom,
 				 $consumed{$entry}{'symb'},$mgr);
-	$r->print("<p>$msg</p>");
+        if (!$result) {
+            $r->print('<p><span class="LC_error">'.&mt($msg).'</span></p>');
+        } else {
+	    $r->print("<p>$msg</p>");
+        }
 	$r->rflush();
     }
     $r->print('<p><a href="/adm/slotrequest?command=showslots">'.
@@ -439,7 +449,11 @@
 
     my ($result,$msg) =
 	&release_reservation($slot_name,$uname,$udom,$symb,$mgr);
-    $r->print("<p>$msg</p>");
+    if (!$result) {
+        $r->print('<p><span class="LC_error">'.&mt($msg).'</span></p>');
+    } else {
+        $r->print("<p>$msg</p>");
+    }
     
     if ($mgr eq 'F') {
 	$r->print('<p><a href="/adm/slotrequest?command=showslots">'.
@@ -464,6 +478,9 @@
     # if the reservation symb is for a map get a resource in that map
     # to check slot parameters on
     my $navmap=Apache::lonnavmaps::navmap->new;
+    if (!defined($navmap)) {
+        return (0,'error: Unable to determine current status');
+    }
     my $passed_resource = $navmap->getBySymb($symb);
     if ($passed_resource->is_map()) {
 	my ($a_resource) = 
@@ -737,7 +754,9 @@
 
     my $conflict = &check_for_conflict($symb,$slot_name,$slot,$slots,
 				       $consumed_uniqueperiods);
-    if ($conflict) {
+    if ($conflict =~ /^error: /) {
+        return 0;
+    } else {
 	if ($slots->{$conflict}{'starttime'} < time) {
 	    return 0;
 	}
@@ -763,10 +782,29 @@
     my ($cnum,$cdom)=&get_course();
     my %slots=&Apache::lonnet::dump('slots',$cdom,$cnum);
     my $consumed_uniqueperiods = &get_consumed_uniqueperiods(\%slots);
+    if (ref($consumed_uniqueperiods) eq 'HASH') {
+        if (&Apache::lonnet::error(%$consumed_uniqueperiods)) {
+            $r->print('<span class="LC_error">'.
+                      &mt('An error occurred determining slot availability').
+                      '</span>');
+            return;
+        }
+    } elsif ($consumed_uniqueperiods =~ /^error: /) {
+        $r->print('<span class="LC_error">'.
+                  &mt('An error occurred determining slot availability').
+                  '</span>');
+        return;
+    }
     my $available;
-    $r->print('<table border="1">');
     &Apache::lonxml::debug("Checking Slots");
     my @got_slots=&check_for_reservation($symb,'allslots');
+    if ($got_slots[0] =~ /^error: /) {
+        $r->print('<span class="LC_error">'.
+                  &mt('An error occurred determining slot availability').
+                  '</span>');
+        return;
+    }
+    $r->print('<table border="1">');
     foreach my $slot (sort 
 		      { return $slots{$a}->{'starttime'} <=> $slots{$b}->{'starttime'} }
 		      (keys(%slots)))  {
@@ -791,10 +829,16 @@
 		my $conflict = &check_for_conflict($symb,$slot,$slots{$slot},
 						   \%slots,
 						   $consumed_uniqueperiods);
-		if ($conflict) {
-		    $text=&mt('Change Reservation');
-		    $command='get';
-		}
+                if ($conflict) {
+                    if ($conflict =~ /^error: /) {
+                        $r->print('<tr><td><span class="LC_error" colspan="2">'
+                                  .&mt('Slot: [_1] has unknown status.',$description)
+                                  .'</span></td></tr>');
+                    } else {
+		        $text=&mt('Change Reservation');
+		        $command='get';
+		    }
+                }
 	    }
 	    my $escsymb=&escape($symb);
 	    $form=<<STUFF;