--- loncom/interface/slotrequest.pm 2005/06/04 07:44:48 1.3
+++ loncom/interface/slotrequest.pm 2006/02/06 22:42:11 1.45
@@ -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.3 2005/06/04 07:44:48 albertel Exp $
+# $Id: slotrequest.pm,v 1.45 2006/02/06 22:42:11 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -34,24 +34,28 @@ use Apache::Constants qw(:common :http :
use Apache::loncommon();
use Apache::lonlocal;
use Apache::lonnet;
+use Date::Manip;
sub fail {
my ($r,$code)=@_;
if ($code eq 'not_valid') {
- $r->print('
'.&mt('Unable to understand what resource you wanted to sign up for.').'
'.$env{'form.symb'});
+ $r->print('
'.&mt('Unable to understand what resource you wanted to sign up for.').'
');
+}
+
sub get_slot {
my ($r,$symb)=@_;
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)
");
+ &return_link($r);
+ return;
+ }
+ if ($slot_name) {
+ my %slot=&Apache::lonnet::get_slot($slot_name);
+ my $description1=&get_description($slot_name,\%slot);
+ %slot=&Apache::lonnet::get_slot($env{'form.slotname'});
+ my $description2=&get_description($env{'form.slotname'},\%slot);
+ $r->print("
Already have a reservation: $description1
");
+ if ($slot_name ne $env{'form.slotname'}) {
+ $r->print(<
+
+
+
+
+STUFF
+ $r->print("
You can either ");
+ $r->print(<
+STUFF
+ $r->print(' your reservation from '.$description1.' to '.
+ $description2.
+ ' or
');
+
+ &return_link($r);
return;
}
sub allowed_slot {
- my ($slot_name,$slot,$symb)=@_;
+ my ($slot_name,$slot,$symb,$slots)=@_;
#already started
if ($slot->{'starttime'} < time) {
- return 0;
+ # 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;
}
-
+ my $conflict = &check_for_conflict($symb,$slot_name,$slot,$slots);
+ if ($conflict) {
+ if ($slots->{$conflict}{'starttime'} < time) {
+ return 0;
+ }
+ }
+ &Apache::lonxml::debug("$slot_name symb good");
return 1;
}
@@ -257,7 +534,7 @@ sub get_description {
my ($slot_name,$slot)=@_;
my $description=$slot->{'description'};
if (!defined($description)) {
- $description=&mt('[_1] From [_2] to [_3]',$slot,
+ $description=&mt('[_1] From [_2] to [_3]',$slot_name,
&Apache::lonlocal::locallocaltime($slot->{'starttime'}),
&Apache::lonlocal::locallocaltime($slot->{'endtime'}));
}
@@ -271,25 +548,42 @@ sub show_choices {
my %slots=&Apache::lonnet::dump('slots',$cdom,$cnum);
my $available;
$r->print('
');
+ &Apache::lonxml::debug("Checking Slots");
+ my @got_slots=&check_for_reservation($symb,'allslots');
foreach my $slot (sort
{ return $slots{$a}->{'starttime'} <=> $slots{$b}->{'starttime'} }
(keys(%slots))) {
-
- next if (!&allowed_slot($slot,$slots{$slot}));
+
+ &Apache::lonxml::debug("Checking Slot $slot");
+ next if (!&allowed_slot($slot,$slots{$slot},undef,\%slots));
$available++;
my $description=&get_description($slot,$slots{$slot});
my $form=&mt('Unavailable');
- if (&space_available($slot,$slots{$slot},$symb)) {
+ if ((grep(/^\Q$slot\E$/,@got_slots)) ||
+ &space_available($slot,$slots{$slot},$symb)) {
+ my $text=&mt('Select');
+ my $command='get';
+ if (grep(/^\Q$slot\E$/,@got_slots)) {
+ $text=&mt('Free Reservation');
+ $command='release';
+ } else {
+ my $conflict = &check_for_conflict($symb,$slot,$slots{$slot},
+ \%slots);
+ if ($conflict) {
+ $text=&mt('Change Reservation');
+ $command='get';
+ }
+ }
my $escsymb=&Apache::lonnet::escape($symb);
$form=<
-
+
-
+
STUFF
}
@@ -302,27 +596,650 @@ STUFF
}
if (!$available) {
- $r->print('
');
+ }
+
+ my %Saveable_Parameters = ('show' => 'array',
+ 'when' => 'scalar',
+ 'order' => 'scalar',
+ 'deleted' => 'scalar',
+ );
+ &Apache::loncommon::store_course_settings('slotrequest',\%Saveable_Parameters);
+ &Apache::loncommon::restore_course_settings('slotrequest',\%Saveable_Parameters);
+
+ my %show_fields=&Apache::lonlocal::texthash(
+ 'name' => 'Slot Name',
+ 'description' => 'Description',
+ 'type' => 'Type',
+ 'starttime' => 'Start time',
+ 'endtime' => 'End Time',
+ 'startreserve' => 'Time students can start reserving',
+ 'secret' => 'Secret Word',
+ 'maxspace' => 'Maximum # of students',
+ 'ip' => 'IP or DNS restrictions',
+ 'symb' => 'Resource slot is restricted to.',
+ 'uniqueperiod' => 'Period of time slot is unique',
+ 'proctor' => 'List of proctors');
+ my @show_order=('name','description','type','starttime','endtime',
+ 'startreserve','secret','maxspace','ip','symb',
+ 'uniqueperiod','proctor');
+ my @show =
+ (exists($env{'form.show'})) ? &Apache::loncommon::get_env_multiple('form.show')
+ : keys(%show_fields);
+ my %show = map { $_ => 1 } (@show);
+
+ my %when_fields=&Apache::lonlocal::texthash(
+ 'now' => 'Open now',
+ 'nextweek' => 'Open within the next week',
+ 'lastweek' => 'Were open last week',
+ 'willopen' => 'Will open later',
+ 'wereopen' => 'Were open',
+ 'any' => 'Anytime',
+ );
+ my @when_order=('any','now','nextweek','lastweek','willopen','wereopen');
+ $when_fields{'select_form_order'} = \@when_order;
+ my $when = (exists($env{'form.when'})) ? $env{'form.when'}
+ : 'now';
+
+ my $hide_radio =
+ &Apache::lonhtmlcommon::radio('deleted',$env{'form.deleted'},'hide');
+ my $show_radio =
+ &Apache::lonhtmlcommon::radio('deleted',$env{'form.deleted'},'show');
+
+ $r->print('
+ENDPICK
+}
+
+sub csvupload_javascript_reverse_associate {
+ my $error1=&mt('You need to specify the name, starttime, endtime and a type');
+ return(<[0].','; }
+ chop($keyfields);
+ } else {
+ unshift(@fields,['none','']);
+ $i=&Apache::loncommon::csv_samples_select_table($r,\@records,
+ \@fields);
+ my %sone=&Apache::loncommon::record_sep($records[0]);
+ $keyfields=join(',',sort(keys(%sone)));
+ }
+ }
+ &csvuploadmap_footer($r,$i,$keyfields);
+
+ return '';
+}
+
+sub csvupload_fields {
+ return (['name','Slot name'],
+ ['type','Type of slot'],
+ ['starttime','Start Time of slot'],
+ ['endtime','End Time of slot'],
+ ['startreserve','Reservation Start Time'],
+ ['ip','IP or DNS restriction'],
+ ['proctor','List of proctor ids'],
+ ['description','Slot Description'],
+ ['maxspace','Maximum number of reservations'],
+ ['symb','Resource Restriction'],
+ ['uniqueperiod','Date range of slot exclusion'],
+ ['secret','Secret word proctor uses to validate']);
+}
+
+sub csv_upload_assign {
+ my ($r,$mgr)= @_;
+ &Apache::loncommon::load_tmp_file($r);
+ my @slotdata = &Apache::loncommon::upfile_record_sep();
+ if ($env{'form.noFirstLine'}) { shift(@slotdata); }
+ my %fields=&Apache::grades::get_fields();
+ $r->print('
Creating Slots
');
+ my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
+ my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $countdone=0;
+ my @errors;
+ foreach my $slot (@slotdata) {
+ my %slot;
+ my %entries=&Apache::loncommon::record_sep($slot);
+ my $domain;
+ my $name=$entries{$fields{'name'}};
+ if ($name=~/^\s*$/) {
+ push(@errors,"Did not create slot with no name");
+ next;
+ }
+ if ($name=~/\s/) {
+ push(@errors,"$name not created -- Name must not contain spaces");
+ next;
+ }
+ if ($name=~/\W/) {
+ push(@errors,"$name not created -- Name must contain only letters, numbers and _");
+ next;
+ }
+ if ($entries{$fields{'type'}}) {
+ $slot{'type'}=$entries{$fields{'type'}};
+ } else {
+ $slot{'type'}='preassigned';
+ }
+ if ($slot{'type'} ne 'preassigned' &&
+ $slot{'type'} ne 'schedulable_student') {
+ push(@errors,"$name not created -- invalid type ($slot{'type'}) must be either preassigned or schedulable_student");
+ next;
+ }
+ if ($entries{$fields{'starttime'}}) {
+ $slot{'starttime'}=&UnixDate($entries{$fields{'starttime'}},"%s");
+ }
+ if ($entries{$fields{'endtime'}}) {
+ $slot{'endtime'}=&UnixDate($entries{$fields{'endtime'}},"%s");
+ }
+ if ($entries{$fields{'startreserve'}}) {
+ $slot{'startreserve'}=
+ &UnixDate($entries{$fields{'startreserve'}},"%s");
+ }
+ 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;
+ }
+
+ &Apache::lonnet::cput('slots',{$name=>\%slot},$cdom,$cname);
+ $r->print('.');
+ $r->rflush();
+ $countdone++;
+ }
+ $r->print("