--- loncom/interface/slotrequest.pm 2005/05/31 21:13:01 1.2
+++ loncom/interface/slotrequest.pm 2005/08/09 15:04:50 1.6
@@ -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.2 2005/05/31 21:13:01 albertel Exp $
+# $Id: slotrequest.pm,v 1.6 2005/08/09 15:04:50 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -104,12 +104,88 @@ sub space_available {
}
return 0;
}
-
+
+sub check_for_reservation {
+ my ($symb)=@_;
+ my $student = &Apache::lonnet::EXT("resource.0.availablestudent", $symb,
+ $env{'user.domain'}, $env{'user.name'});
+
+ my $course = &Apache::lonnet::EXT("resource.0.available", $symb,
+ $env{'user.domain'}, $env{'user.name'});
+ my @slots = (split(/:/,$student), split(/:/, $course));
+
+ &Apache::lonxml::debug(" slot list is ".join(':',@slots));
+
+ my ($cnum,$cdom)=&get_course();
+ my %slots=&Apache::lonnet::get('slots', [@slots], $cdom, $cnum);
+
+ foreach my $slot_name (@slots) {
+ next if (!defined($slots{$slot_name}) ||
+ !ref($slots{$slot_name}));
+ &Apache::lonxml::debug(time." $slot_name ".
+ $slots{$slot_name}->{'starttime'}." -- ".
+ $slots{$slot_name}->{'startreserve'});
+ if ($slots{$slot_name}->{'starttime'} > time &&
+ $slots{$slot_name}->{'startreserve'} < time) {
+ # between start of reservation times and start of slot
+ return($slot_name, $slots{$slot_name});
+ }
+ }
+ return (undef,undef);
+}
+
+sub check_for_conflict {
+ my ($symb,$new_slot_name)=@_;
+ my $student = &Apache::lonnet::EXT("resource.0.availablestudent", $symb,
+ $env{'user.domain'}, $env{'user.name'});
+ my $course = &Apache::lonnet::EXT("resource.0.available", $symb,
+ $env{'user.domain'}, $env{'user.name'});
+ my @slots = (split(/:/,$student), split(/:/, $course));
+ my ($cnum,$cdom)=&get_course();
+ my %slots=&Apache::lonnet::get('slots', [@slots], $cdom, $cnum);
+ foreach my $slot_name (@slots) {
+ next if (!defined($slots{$slot_name}) ||
+ !ref($slots{$slot_name}));
+
+ next if (!defined($slots{$slot_name}->{'uniqueperiod'}) ||
+ !ref($slots{$slot_name}->{'uniqueperiod'}));
+ my ($start,$end)=@{$slots{$slot_name}->{'uniqueperiod'}};
+ if ($start
+
+
+?
+
+
+or
+
+
+or
+STUFF
+ $r->print(''.
+ &mt('Return to last resource').'
');
+ return;
+}
+
+sub allowed_slot {
+ my ($slot_name,$slot,$symb)=@_;
+ #already started
+ if ($slot->{'starttime'} < time) {
+ # all open slot to be schedulable
+ #return 0;
+ }
+ &Apache::lonxml::debug("$slot_name starttime good");
+ #already ended
+ if ($slot->{'endtime'} < time) {
+ return 0;
+ }
+ &Apache::lonxml::debug("$slot_name endtime good");
+ # not allowed to pick this one
+ if (defined($slot->{'type'})
+ && $slot->{'type'} ne 'schedulable_student') {
+ return 0;
+ }
+ &Apache::lonxml::debug("$slot_name type good");
+ # not allowed for this resource
+ if (defined($slot->{'symb'})
+ && $slot->{'symb'} ne $symb) {
+ return 0;
+ }
+ &Apache::lonxml::debug("$slot_name symb good");
+ return 1;
+}
+
+sub get_description {
+ my ($slot_name,$slot)=@_;
+ my $description=$slot->{'description'};
+ if (!defined($description)) {
+ $description=&mt('[_1] From [_2] to [_3]',$slot_name,
+ &Apache::lonlocal::locallocaltime($slot->{'starttime'}),
+ &Apache::lonlocal::locallocaltime($slot->{'endtime'}));
+ }
+ return $description;
+}
sub show_choices {
my ($r,$symb)=@_;
my ($cnum,$cdom)=&get_course();
my %slots=&Apache::lonnet::dump('slots',$cdom,$cnum);
+ my $available;
$r->print('');
+ &Apache::lonxml::debug("Checking Slots");
+ my ($got_slot)=&check_for_reservation($symb);
foreach my $slot (sort
{ return $slots{$a}->{'starttime'} <=> $slots{$b}->{'starttime'} }
(keys(%slots))) {
- my $description=$slots{$slot}->{'description'};
- if (!defined($description)) {
- $description=&mt('[_1] From [_2] to [_3]',$slot,
- &Apache::lonlocal::locallocaltime($slots{$slot}->{'starttime'}),
- &Apache::lonlocal::locallocaltime($slots{$slot}->{'endtime'}));
- }
+
+ &Apache::lonxml::debug("Checking Slot $slot");
+ next if (!&allowed_slot($slot,$slots{$slot}));
+
+ $available++;
+
+ my $description=&get_description($slot,$slots{$slot});
my $form=&mt('Unavailable');
- if (&space_available($slot,$slots{$slot})) {
+ if (&space_available($slot,$slots{$slot},$symb)) {
+ my $text=&mt('Select');
+ my $command='get';
+ if ($slot eq $got_slot) {
+ $text=&mt('Free Reservation');
+ $command='release';
+ }
+ my $escsymb=&Apache::lonnet::escape($symb);
$form=<
-
-
+
STUFF
}
@@ -175,6 +435,49 @@ STUFF
STUFF
}
+
+ if (!$available) {
+ $r->print('No available times. '.
+ &mt('Return to last resource').' |
');
+ }
+ $r->print('
');
+}
+
+sub show_table {
+ my ($r,$symb)=@_;
+
+ my ($cnum,$cdom)=&get_course();
+ my %slots=&Apache::lonnet::dump('slots',$cdom,$cnum);
+ my $available;
+ $r->print('');
+ foreach my $slot (sort
+ { return $slots{$a}->{'starttime'} <=> $slots{$b}->{'starttime'} }
+ (keys(%slots))) {
+ if (defined($slots{$slot}->{'type'})
+ && $slots{$slot}->{'type'} ne 'schedulable_student') {
+ next;
+ }
+ my $description=&get_description($slot,$slots{$slot});
+ 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);
+ $ids.= $id.'-> '.$consumed{$entry}->{'name'}.'
';
+ }
+ my $start=localtime($slots{$slot}->{'starttime'});
+ my $end=localtime($slots{$slot}->{'endtime'});
+ $r->print(<
+ $slot |
+ $description |
+ $start |
+ $end |
+ $slots{$slot}->{'maxspace'} |
+ $ids |
+
+STUFF
+ }
$r->print('
');
}
@@ -188,11 +491,22 @@ sub handler {
&fail($r,'not_valid');
return OK;
}
-
- if ($env{'form.requestattempt'}) {
+
+ if ($env{'form.command'} eq 'showslots') {
+ &show_table($r,$symb);
+ } elsif ($env{'form.requestattempt'}) {
&show_choices($r,$symb);
+ } elsif ($env{'form.command'} eq 'release') {
+ &release_slot($r,$symb);
+ } elsif ($env{'form.command'} eq 'get') {
+ &get_slot($r,$symb);
+ } elsif ($env{'form.command'} eq 'change') {
+ &release_slot($r,$symb,$env{'form.releaseslot'},1);
+ &get_slot($r,$symb);
}
-
&end_page($r);
return OK;
}
+
+1;
+__END__