--- loncom/interface/slotrequest.pm 2006/03/30 04:34:32 1.54 +++ loncom/interface/slotrequest.pm 2007/04/11 16:07:51 1.78 @@ -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.54 2006/03/30 04:34:32 albertel Exp $ +# $Id: slotrequest.pm,v 1.78 2007/04/11 16:07:51 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -36,12 +36,15 @@ use Apache::lonlocal; use Apache::lonnet; use Apache::lonnavmaps(); use Date::Manip; +use lib '/home/httpd/lib/perl/'; +use LONCAPA; sub fail { my ($r,$code)=@_; if ($code eq 'not_valid') { $r->print('
'.&mt('Unable to understand what resource you wanted to sign up for.').'
'); - + } elsif ($code eq 'not_available') { + $r->print(''.&mt('No slots are available.').'
'); } elsif ($code eq 'not_allowed') { $r->print(''.&mt('Not allowed to sign up or change reservations at this time.').'
'); } else { @@ -74,7 +77,7 @@ sub end_page { =cut sub get_course { - (undef,my $courseid)=&Apache::lonxml::whichuser(); + (undef,my $courseid)=&Apache::lonnet::whichuser(); my $cdom=$env{'course.'.$courseid.'.domain'}; my $cnum=$env{'course.'.$courseid.'.num'}; return ($cnum,$cdom); @@ -87,7 +90,7 @@ sub get_reservation_ids { my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum, "^$slot_name\0"); - if (&network_error(%consumed)) { + if (&Apache::lonnet::error(%consumed)) { return 'error: Unable to determine current status'; } my ($tmp)=%consumed; @@ -124,8 +127,9 @@ 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)) { + if (&Apache::lonnet::error($student) + || &Apache::lonnet::error($course) + || &Apache::lonnet::error(%slots)) { return 'error: Unable to determine current status'; } my @got; @@ -172,7 +176,8 @@ sub get_consumed_uniqueperiods { my $course = &Apache::lonnet::EXT("resource.0.available", $symb, $env{'user.domain'}, $env{'user.name'}); - if (&network_error($student) || &network_error($course)) { + if (&Apache::lonnet::error($student) + || &Apache::lonnet::error($course)) { return 'error: Unable to determine current status'; } foreach my $slot (split(/:/,$student), split(/:/, $course)) { @@ -183,7 +188,7 @@ sub get_consumed_uniqueperiods { if (!ref($slots)) { my ($cnum,$cdom)=&get_course(); my %slots=&Apache::lonnet::get('slots', [keys(%used_slots)], $cdom, $cnum); - if (&network_error(%slots)) { + if (&Apache::lonnet::error(%slots)) { return 'error: Unable to determine current status'; } $slots = \%slots; @@ -209,7 +214,7 @@ sub check_for_conflict { if (!ref($consumed_uniqueperiods)) { $consumed_uniqueperiods = &get_consumed_uniqueperiods($slots); - if (&network_error(%$consumed_uniqueperiods)) { + if (&Apache::lonnet::error(%$consumed_uniqueperiods)) { return 'error: Unable to determine current status'; } } @@ -227,14 +232,6 @@ 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)=@_; @@ -243,18 +240,31 @@ sub make_reservation { my $value=&Apache::lonnet::EXT("resource.0.availablestudent",$symb, $env{'user.domain'},$env{'user.name'}); &Apache::lonxml::debug("value is $value".&mt('A network error has occured.').'
'); + return; + } + if (!%consumed) { + $r->print("".&mt('Slot [_1] has no reservations.', + $slot_name)."
"); + return; + } + + my @names = map { $consumed{$_}{'name'} } (sort(keys(%consumed))); + my $names = join(' ',@names); + + my $msg = &mt('Remove all of [_1] from slot [_2]?',$names,$slot_name); + &remove_registration_confirmation($r,$msg,['entry','slotname']); +} + +sub remove_registration_user { + my ($r) = @_; + + my $slot_name = $env{'form.slotname'}; + my $name = &Apache::loncommon::plainname($env{'form.uname'}, $env{'form.udom'}); my $title = &Apache::lonnet::gettitle($env{'form.symb'}); + my $msg = &mt('Remove [_1] from slot [_2] for [_3]', + $name,$slot_name,$title); + + &remove_registration_confirmation($r,$msg,['uname','udom','slotname', + 'entry','symb']); +} + +sub remove_registration_confirmation { + my ($r,$msg,$inputs) =@_; + my $hidden_input; - foreach my $parm ('uname','udom','slotname','entry','symb') { + foreach my $parm (@{$inputs}) { $hidden_input .= '&\'').'" />'."\n"; } + my %lt = &Apache::lonlocal::texthash('yes' => 'Yes', + 'no' => 'No',); $r->print(<<"END_CONFIRM"); -Remove $name from slot $env{'form.slotname'} for $title
- - END_CONFIRM } +sub release_all_slot { + my ($r,$mgr)=@_; + + my $slot_name = $env{'form.slotname'}; + + my ($cnum,$cdom)=&get_course(); + + my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum, + "^$slot_name\0"); + + $r->print(''.&mt('Releasing reservations').'
'); + + foreach my $entry (sort { $consumed{$a}{'name'} cmp + $consumed{$b}{'name'} } (keys(%consumed))) { + my ($uname,$udom) = split(':',$consumed{$entry}{'name'}); + my ($result,$msg) = + &release_reservation($slot_name,$uname,$udom, + $consumed{$entry}{'symb'},$mgr); + $r->print("$msg
"); + $r->rflush(); + } + $r->print(''. + &mt('Return to slot list').'
'); + &return_link($r); +} + sub release_slot { my ($r,$symb,$slot_name,$inhibit_return_link,$mgr)=@_; if ($slot_name eq '') { $slot_name=$env{'form.slotname'}; } - my ($cnum,$cdom)=&get_course(); my ($uname,$udom) = ($env{'user.name'}, $env{'user.domain'}); if ($mgr eq 'F' @@ -353,16 +433,30 @@ sub release_slot { if ($mgr eq 'F' && defined($env{'form.symb'})) { - $symb = $env{'form.symb'}; + $symb = &unescape($env{'form.symb'}); } + + my ($result,$msg) = + &release_reservation($slot_name,$uname,$udom,$symb,$mgr); + $r->print("$msg
"); + + if ($mgr eq 'F') { + $r->print(''. + &mt('Return to slot list').'
'); + } + + if (!$inhibit_return_link) { &return_link($r); } + return $result; +} + +sub release_reservation { + my ($slot_name,$uname,$udom,$symb,$mgr) = @_; my %slot=&Apache::lonnet::get_slot($slot_name); - my $description=&get_description($env{'form.slotname'},\%slot); + my $description=&get_description($slot_name,\%slot); if ($mgr ne 'F') { if ($slot{'starttime'} < time) { - $r->print("Not allowed to release Reservation: $description, as it has already ended.
"); - &return_link($r); - return 0; + return (0,&mt('Not allowed to release Reservation: [_1], as it has already ended.',$description)); } } # get parameter string, check for existance, rebuild string with the slot @@ -376,28 +470,42 @@ sub release_slot { } my $new_param = join(':',@new_slots); + my ($cnum,$cdom)=&get_course(); + # get slot reservations, check if user has one, if so remove reservation my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum, "^$slot_name\0"); foreach my $entry (keys(%consumed)) { - if ( $consumed{$entry}->{'name'} eq ($uname.'@'.$udom) ) { + if ( $consumed{$entry}->{'name'} eq ($uname.':'.$udom) ) { &Apache::lonnet::del('slot_reservations',[$entry], $cdom,$cnum); } } + my $use_slots = &Apache::lonnet::EXT("resource.0.useslots"); + &Apache::lonxml::debug("use_slots is $use_slotsReleased Reservation: $description
"); + $parm_level, $new_param, + 'string', $uname, $udom); + + my $msg; if ($mgr eq 'F') { - $r->print(''. - &mt('Return to slot list').'
'); + $msg = &mt('Released Reservation for user: [_1]',"$uname:$udom"); + } else { + $msg = &mt('Released Reservation: [_1]',$description); } - if (!$inhibit_return_link) { &return_link($r); } - return 1; + return (1,$msg); } sub delete_slot { @@ -419,7 +527,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) { @@ -440,17 +548,17 @@ 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("An error occured while attempting to make a reservation. ($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'}); @@ -458,7 +566,7 @@ sub get_slot { $r->print("Already have a reservation: $description1
"); if ($slot_name ne $env{'form.slotname'}) { $r->print(<