--- loncom/interface/slotrequest.pm 2006/03/30 04:34:32 1.54 +++ loncom/interface/slotrequest.pm 2006/05/12 01:20:31 1.60 @@ -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.60 2006/05/12 01:20:31 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -243,10 +243,22 @@ sub make_reservation { my $value=&Apache::lonnet::EXT("resource.0.availablestudent",$symb, $env{'user.domain'},$env{'user.name'}); &Apache::lonxml::debug("value is $value
"); - if (&network_error($value)) { + + my $use_slots = &Apache::lonnet::EXT("resource.0.useslots"); + &Apache::lonxml::debug("use_slots is $use_slots
"); + + if (&network_error($value) || &network_error($use_slots)) { return 'error: Unable to determine current status'; } + my $parm_symb = $symb; + my $parm_level = 1; + if ($use_slots eq 'map') { + my ($map) = &Apache::lonnet::decode_symb($symb); + $parm_symb = &Apache::lonnet::symbread($map); + $parm_level = 2; + } + foreach my $other_slot (split(/:/, $value)) { if ($other_slot eq $slot_name) { my %consumed=&Apache::lonnet::dump('slot_reservations', $cdom, @@ -254,7 +266,7 @@ sub make_reservation { if (&network_error($value)) { return 'error: Unable to determine current status'; } - my $me=$env{'user.name'}.'@'.$env{'user.domain'}; + my $me=$env{'user.name'}.':'.$env{'user.domain'}; foreach my $key (keys(%consumed)) { if ($consumed{$key}->{'name'} eq $me) { my $num=(split('\0',$key))[1]; @@ -284,9 +296,9 @@ sub make_reservation { return undef; } - my %reservation=('name' => $env{'user.name'}.'@'.$env{'user.domain'}, + my %reservation=('name' => $env{'user.name'}.':'.$env{'user.domain'}, 'timestamp' => time, - 'symb' => $symb); + 'symb' => $parm_symb); my $success=&Apache::lonnet::newput('slot_reservations', {"$slot_name\0$wanted" => @@ -300,7 +312,8 @@ sub make_reservation { } my $result=&Apache::lonparmset::storeparm_by_symb($symb, '0_availablestudent', - 1, $new_value, 'string', + $parm_level, $new_value, + 'string', $env{'user.name'}, $env{'user.domain'}); &Apache::lonxml::debug("hrrm $result"); @@ -313,37 +326,106 @@ sub make_reservation { sub remove_registration { my ($r) = @_; + if ($env{'form.entry'} ne 'remove all') { + return &remove_registration_user($r); + } + my $slot_name = $env{'form.slotname'}; + my %slot=&Apache::lonnet::get_slot($slot_name); + + my ($cnum,$cdom)=&get_course(); + my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum, + "^$slot_name\0"); + if (&network_error(%consumed)) { + $r->print("

".&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

+

$msg

+ $hidden_input - +
- +
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' @@ -355,14 +437,28 @@ sub release_slot { && defined($env{'form.symb'})) { $symb = $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 +472,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_slots
"); + + if (&network_error($use_slots)) { + return (0,'error: Unable to determine current status'); + } + + my $parm_level = 1; + if ($use_slots eq 'map') { + $parm_level = 2; + } # store new parameter string my $result=&Apache::lonparmset::storeparm_by_symb($symb, '0_availablestudent', - 1, $new_param, 'string', - $uname,$udom); - $r->print("

Released 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 { @@ -743,14 +853,20 @@ sub to_show { sub remove_link { my ($slotname,$entry,$uname,$udom,$symb) = @_; + my $remove = &mt('Remove'); + + if ($entry eq 'remove all') { + $remove = &mt('Remove All'); + undef($uname); + undef($udom); + } + $slotname = &Apache::lonnet::escape($slotname); $entry = &Apache::lonnet::escape($entry); $uname = &Apache::lonnet::escape($uname); $udom = &Apache::lonnet::escape($udom); $symb = &Apache::lonnet::escape($symb); - my $remove= &mt('Remove'); - return <<"END_LINK"; ($remove) @@ -963,14 +1079,14 @@ sub show_table { $consumed{$b}{name} } (keys(%consumed))) { my (undef,$id)=split("\0",$entry); - my ($uname,$udom) = split('@',$consumed{$entry}{'name'}); + my ($uname,$udom) = split(':',$consumed{$entry}{'name'}); $ids.= ''; foreach my $item (@stu_display_order) { if ($stu_display{$item}) { if ($item eq 'fullname') { $ids.=$fullname->{"$uname:$udom"}.' '; } elsif ($item eq 'username') { - $ids.="$uname\@$udom "; + $ids.="$uname:$udom "; } } } @@ -1049,7 +1165,14 @@ EDITLINK my $delete=(<<"DELETELINK"); Delete DELETELINK + + my $remove_all=&remove_link($slot,'remove all').'
'; + if ($ids ne '') { undef($delete); } + if ($slots{$slot}{'type'} ne 'schedulable_student' + || $ids eq '') { + undef($remove_all); + } $r->print("\n$edit $delete\n"); if (exists($show{'name'})) { @@ -1089,7 +1212,7 @@ DELETELINK $colspan++;$r->print("$allowedusers\n"); } if (exists($show{'scheduled'})) { - $colspan++;$r->print("$ids\n\n"); + $colspan++;$r->print("$remove_all $ids\n\n"); } if (exists($show{'proctor'})) { $r->print(< $slot{'endtime'}) { + push(@errors,"$name not created -- Slot starts after it ends"); + next; + } + if ($entries{$fields{'startreserve'}}) { $slot{'startreserve'}= &UnixDate($entries{$fields{'startreserve'}},"%s"); } + if (defined($slot{'startreserve'}) + && $slot{'startreserve'} > $slot{'starttime'}) { + push(@errors,"$name not created -- Slot's reservation start time is after the slot's start time."); + next; + } + foreach my $key ('ip','proctor','description','maxspace', 'secret','symb') { if ($entries{$fields{$key}}) { $slot{$key}=$entries{$fields{$key}}; } } + if ($entries{$fields{'uniqueperiod'}}) { my ($start,$end)=split(',',$entries{$fields{'uniqueperiod'}}); my @times=(&UnixDate($start,"%s"), &UnixDate($end,"%s")); $slot{'uniqueperiod'}=\@times; } + if (defined($slot{'uniqueperiod'}) + && $slot{'uniqueperiod'}[0] > $slot{'uniqueperiod'}[1]) { + push(@errors,"$name not created -- Slot's unique period start time is later than the unique period's end time."); + next; + } &Apache::lonnet::cput('slots',{$name=>\%slot},$cdom,$cname); $r->print('.'); @@ -1376,7 +1526,11 @@ sub handler { } elsif ($env{'form.command'} eq 'remove_registration' && $mgr eq 'F') { &remove_registration($r); } elsif ($env{'form.command'} eq 'release' && $mgr eq 'F') { - &release_slot($r,undef,undef,undef,$mgr); + if ($env{'form.entry'} eq 'remove all') { + &release_all_slot($r,$mgr); + } else { + &release_slot($r,undef,undef,undef,$mgr); + } } elsif ($env{'form.command'} eq 'delete' && $mgr eq 'F') { &delete_slot($r); } elsif ($env{'form.command'} eq 'uploadstart' && $mgr eq 'F') { @@ -1398,7 +1552,7 @@ sub handler { my $symb=&Apache::lonnet::unescape($env{'form.symb'}); my (undef,undef,$res)=&Apache::lonnet::decode_symb($symb); my $useslots = &Apache::lonnet::EXT("resource.0.useslots",$symb); - if ($useslots ne 'resource') { + if ($useslots ne 'resource' && $useslots ne 'map') { &fail($r,'not_valid'); return OK; }