--- loncom/interface/slotrequest.pm 2005/12/14 22:26:10 1.37 +++ loncom/interface/slotrequest.pm 2006/02/03 18:53:08 1.42 @@ -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.37 2005/12/14 22:26:10 raeburn Exp $ +# $Id: slotrequest.pm,v 1.42 2006/02/03 18:53:08 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -47,8 +47,7 @@ sub fail { $r->print('
'.&mt('Failed.').'
'); } - $r->print(''. - &mt('Return to last resource').'
'); + &return_link($r); &end_page($r); } @@ -89,7 +88,9 @@ sub get_reservation_ids { 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; @@ -124,6 +125,10 @@ sub check_for_reservation { my ($cnum,$cdom)=&get_course(); my %slots=&Apache::lonnet::get('slots', [@slots], $cdom, $cnum); + if (&network_error($student) || &network_error($course) || + &network_error(%slots)) { + return 'error: Unable to determine current status'; + } foreach my $slot_name (@slots) { next if (!defined($slots{$slot_name}) || !ref($slots{$slot_name})); @@ -148,6 +153,11 @@ sub check_for_conflict { my @slots = (split(/:/,$student), split(/:/, $course)); my ($cnum,$cdom)=&get_course(); my %slots=&Apache::lonnet::get('slots', [@slots], $cdom, $cnum); + + if (&network_error($student) || &network_error($course) || + &network_error(%slots)) { + return 'error: Unable to determine current status'; + } foreach my $slot_name (@slots) { next if (!defined($slots{$slot_name}) || !ref($slots{$slot_name})); @@ -163,6 +173,14 @@ sub check_for_conflict { } +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 +189,17 @@ sub make_reservation { my $value=&Apache::lonnet::EXT("resource.0.availablestudent",$symb, $env{'user.domain'},$env{'user.name'}); &Apache::lonxml::debug("value is $valueNot allowed to release Reservation: $description, as it has already ended.
"); + &return_link($r); + return 0; + } + } # get parameter string, check for existance, rebuild string with the slot my @slots = split(/:/,&Apache::lonnet::EXT("resource.0.availablestudent", $symb,$udom,$uname)); @@ -302,17 +337,13 @@ sub release_slot { '0_availablestudent', 1, $new_param, 'string', $uname,$udom); - my %slot=&Apache::lonnet::get_slot($slot_name); my $description=&get_description($env{'form.slotname'},\%slot); $r->print("Released Reservation: $description
"); if ($mgr eq 'F') { $r->print(''. &mt('Return to slot list').'
'); } - if (!$inhibit_return_link) { - $r->print(''. - &mt('Return to last resource').'
'); - } + if (!$inhibit_return_link) { &return_link($r); } return 1; } @@ -325,6 +356,8 @@ sub delete_slot { my ($cnum,$cdom)=&get_course(); my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum, "^$slot_name\0"); + my ($tmp) = %consumed; + if ($tmp =~ /error: 2/) { undef(%consumed); } if (%slot && !%consumed) { $slot{'type'} = 'deleted'; @@ -344,6 +377,11 @@ sub delete_slot { } $r->print(''. &mt('Return to slot list').'
'); + &return_link($r); +} + +sub return_link { + my ($r) = @_; $r->print(''. &mt('Return to last resource').'
'); } @@ -352,6 +390,12 @@ sub get_slot { my ($r,$symb)=@_; my $slot_name=&check_for_conflict($symb,$env{'form.slotname'}); + + if ($slot_name =~ /^error: (.*)/) { + $r->print("An error occured while attempting to make a reservation. ($1)
"); + &return_link($r); + return; + } if ($slot_name) { my %slot=&Apache::lonnet::get_slot($slot_name); my $description1=&get_description($slot_name,\%slot); @@ -372,14 +416,13 @@ STUFF STUFF $r->print(' your reservation from '.$description1.' to '. $description2. - ''. - &mt('Return to last resource').'
'); + &return_link($r); } return; } @@ -388,17 +431,15 @@ STUFF \%slot,$symb); my $description=&get_description($env{'form.slotname'},\%slot); if (defined($reserved)) { - if ($reserved > -1) { + if ($slot_name =~ /^error: (.*)/) { + $r->print("An error occured while attempting to make a reservation. ($1)
"); + } elsif ($reserved > -1) { $r->print("Success: $description
"); - $r->print(''. - &mt('Return to last resource').'
'); - return; } elsif ($reserved < 0) { $r->print("Already reserved: $description
"); - $r->print(''. - &mt('Return to last resource').'
'); - return; } + &return_link($r); + return; } my %lt=('request'=>"Availibility list", @@ -425,8 +466,8 @@ or or STUFF - $r->print(''. - &mt('Return to last resource').'
'); + + &return_link($r); return; } @@ -732,13 +773,17 @@ sub show_table { my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum, "^$slot\0"); my $ids; - foreach my $entry (sort(keys(%consumed))) { - my (undef,$id)=split("\0",$entry); - my ($uname,$udom) = split('@',$consumed{$entry}{'name'}); - my $name = &Apache::loncommon::plainname($uname,$udom); - $ids.= 'Unknown command: ".$env{'form.command'}."
"); }