--- loncom/interface/slotrequest.pm 2007/04/10 23:26:49 1.74 +++ loncom/interface/slotrequest.pm 2008/12/11 14:55:15 1.84 @@ -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.84 2008/12/11 14:55:15 bisitz Exp $ # # Copyright Michigan State University Board of Trustees # @@ -241,7 +241,8 @@ sub make_reservation { $env{'user.domain'},$env{'user.name'}); &Apache::lonxml::debug("value is $value
"); - my $use_slots = &Apache::lonnet::EXT("resource.0.useslots"); + my $use_slots = &Apache::lonnet::EXT("resource.0.useslots",$symb, + $env{'user.domain'},$env{'user.name'}); &Apache::lonxml::debug("use_slots is $use_slots
"); if (&Apache::lonnet::error($value) @@ -334,7 +335,7 @@ sub remove_registration { my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum, "^$slot_name\0"); if (&Apache::lonnet::error(%consumed)) { - $r->print("

".&mt('A network error has occured.').'

'); + $r->print("

".&mt('A network error has occurred.').'

'); return; } if (!%consumed) { @@ -459,9 +460,22 @@ sub release_reservation { return (0,&mt('Not allowed to release Reservation: [_1], as it has already ended.',$description)); } } + + # 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; + my $passed_resource = $navmap->getBySymb($symb); + if ($passed_resource->is_map()) { + my ($a_resource) = + $navmap->retrieveResources($passed_resource, + sub {$_[0]->is_problem()},0,1); + $symb = $a_resource->symb(); + } + # get parameter string, check for existance, rebuild string with the slot - my @slots = split(/:/,&Apache::lonnet::EXT("resource.0.availablestudent", - $symb,$udom,$uname)); + my $student = &Apache::lonnet::EXT("resource.0.availablestudent", + $symb,$udom,$uname); + my @slots = split(/:/,$student); my @new_slots; foreach my $exist_slot (@slots) { @@ -482,7 +496,8 @@ sub release_reservation { } } - my $use_slots = &Apache::lonnet::EXT("resource.0.useslots"); + my $use_slots = &Apache::lonnet::EXT("resource.0.useslots", + $symb,$udom,$uname); &Apache::lonxml::debug("use_slots is $use_slots
"); if (&Apache::lonnet::error($use_slots)) { @@ -527,7 +542,7 @@ sub delete_slot { if ($ret eq 'ok') { $r->print("

Slot $slot_name marked as deleted.

"); } else { - $r->print("

An error ($ret) occurse when attempting to delete Slot $slot_name.

"); + $r->print("

An error ($ret) occurse when attempting to delete Slot $slot_name.

"); } } else { if (%consumed) { @@ -548,17 +563,19 @@ sub return_link { } 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); if ($slot_name =~ /^error: (.*)/) { - $r->print("

An error occured while attempting to make a reservation. ($1)

"); + $r->print('

' + .&mt('An error occurred while attempting to make a reservation. ([_1])',$1) + .'

'); &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,36 +603,46 @@ STUFF } 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("

An error occured while attempting to make a reservation. ($1)

"); + $r->print('

' + .&mt('An error occurred while attempting to make a reservation. ([_1])',$1) + .'

'); } elsif ($reserved > -1) { $r->print("

Success: $description

"); + $retvalue = 1; } elsif ($reserved < 0) { $r->print("

Already reserved: $description

"); } - &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=''; + } + $r->print(< Failed to reserve a spot for $description.

+

Failed to reserve a spot for $description.

- + + $extra_input
?

@@ -629,8 +656,8 @@ or or STUFF - &return_link($r); - return; + if (!$inhibit_return_link) { &return_link($r); } + return 0; } sub allowed_slot { @@ -638,8 +665,7 @@ sub allowed_slot { #already started if ($slot->{'starttime'} < time) { - # all open slot to be schedulable - #return 0; + return 0; } &Apache::lonxml::debug("$slot_name starttime good"); @@ -1101,15 +1127,16 @@ sub show_table { my ($id_count,$ids); if (exists($show{'scheduled'}) || exists($show{'space'}) ) { - my @this_slot = grep(/^$slot\0/,keys(%consumed)); + my $re_str = "$slot\0"; + my @this_slot = grep(/^\Q$re_str\E/,keys(%consumed)); $id_count = scalar(@this_slot); if (exists($show{'scheduled'})) { foreach my $entry (sort { $consumed{$a}{name} cmp $consumed{$b}{name} } - (keys(%consumed))) { + (@this_slot)) { my (undef,$id)=split("\0",$entry); my ($uname,$udom) = split(':',$consumed{$entry}{'name'}); - $ids.= ''; + $ids.= ''; foreach my $item (@stu_display_order) { if ($stu_display{$item}) { if ($item eq 'fullname') { @@ -1120,7 +1147,7 @@ sub show_table { } } $ids.=&remove_link($slot,$entry,$uname,$udom, - $consumed{$entry}{'symb'}).'
'; + $consumed{$entry}{'symb'}).'
'; } } } @@ -1540,7 +1567,7 @@ sub csv_upload_assign { } $r->print("

Created $countdone slots\n

"); foreach my $error (@errors) { - $r->print("

$error\n

"); + $r->print("

$error

\n"); } &show_table($r,$mgr); return ''; @@ -1624,8 +1651,8 @@ sub handler { } 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("

Unknown command: ".$env{'form.command'}."

");