--- loncom/interface/slotrequest.pm 2006/06/16 19:49:00 1.64
+++ loncom/interface/slotrequest.pm 2018/07/02 20:34:52 1.139
@@ -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.64 2006/06/16 19:49:00 albertel Exp $
+# $Id: slotrequest.pm,v 1.139 2018/07/02 20:34:52 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -37,7 +37,7 @@ use Apache::lonnet;
use Apache::lonnavmaps();
use Date::Manip;
use lib '/home/httpd/lib/perl/';
-use LONCAPA;
+use LONCAPA qw(:DEFAULT :match);
sub fail {
my ($r,$code)=@_;
@@ -56,8 +56,22 @@ sub fail {
}
sub start_page {
- my ($r,$title)=@_;
- $r->print(&Apache::loncommon::start_page($title));
+ my ($r,$title,$brcrum,$js)=@_;
+ my $args;
+ if (ref($brcrum) eq 'ARRAY') {
+ $args = {bread_crumbs => $brcrum};
+ }
+ if (($env{'form.requestattempt'}) || ($env{'form.command'} eq 'manageresv')) {
+ my %loaditems = (
+ onload => 'javascript:uncheckSlotRadio();',
+ );
+ if (ref($args) eq 'HASH') {
+ $args->{'add_entries'} = \%loaditems;
+ } else {
+ $args = { 'add_entries' => \%loaditems };
+ }
+ }
+ $r->print(&Apache::loncommon::start_page($title,$js,$args));
}
sub end_page {
@@ -65,6 +79,291 @@ sub end_page {
$r->print(&Apache::loncommon::end_page());
}
+sub reservation_js {
+ my ($slots,$consumed_uniqueperiods,$available,$got_slots,$symb) = @_;
+ return unless ((ref($slots) eq 'HASH') && (ref($available) eq 'ARRAY'));
+ my $toskip;
+ if ($symb eq '') {
+ $toskip = { symb => 1, };
+ }
+ my ($i,$j) = (0,0);
+ my $js;
+ foreach my $slot (sort
+ { return $slots->{$a}->{'starttime'} <=> $slots->{$b}->{'starttime'} }
+ (keys(%{$slots}))) {
+
+ next if (!&allowed_slot($slot,$slots->{$slot},$symb,$slots,
+ $consumed_uniqueperiods,$toskip));
+ $js .= " slotstart[$i]='$slots->{$slot}->{'starttime'}';\n".
+ " slotend[$i]='$slots->{$slot}->{'endtime'}';\n".
+ " slotname[$i]='$slot';\n";
+ if (($symb) && (ref($got_slots) eq 'ARRAY')) {
+ if (grep(/^\Q$slot\E$/,@{$got_slots})) {
+ $js .= " currslot[$j]='$slot';\n";
+ $j++;
+ }
+ }
+ $i++;
+ push(@{$available},$slot);
+ }
+ if ($j) {
+ $js = " var currslot = new Array($j);\n\n$js";
+ }
+ my %alerts = &Apache::lonlocal::texthash (
+ none => 'No reservable time slots found',
+ invalid => 'Invalid date format',
+ );
+ return <<"ENDSCRIPT";
+
+ENDSCRIPT
+
+}
+
+
=pod
slot_reservations db
@@ -77,7 +376,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);
@@ -90,7 +389,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;
@@ -117,7 +416,6 @@ sub check_for_reservation {
my ($symb,$mode)=@_;
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));
@@ -127,27 +425,26 @@ 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;
- foreach my $slot_name (sort {
- if (ref($slots{$a}) && ref($slots{$b})) {
- return $slots{$a}{'starttime'} <=> $slots{$b}{'starttime'}
- }
- if (ref($slots{$a})) { return -1;}
- if (ref($slots{$b})) { return 1;}
- return 0;
- } @slots) {
+ my @sorted_slots = &Apache::loncommon::sorted_slots(\@slots,\%slots,'starttime');
+ foreach my $slot_name (@sorted_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}->{'endtime'} > time &&
- $slots{$slot_name}->{'startreserve'} < time) {
- # between start of reservation times and end of slot
+ $slots{$slot_name}->{'startreserve'}." -- ".
+ $slots{$slot_name}->{'endreserve'});
+ if (($slots{$slot_name}->{'endtime'} > time) &&
+ ($slots{$slot_name}->{'startreserve'} < time) &&
+ ((!$slots{$slot_name}->{'endreserve'}) ||
+ ($slots{$slot_name}->{'endreserve'} > time))) {
+ # between start of reservation time and end of reservation time
+ # and before end of slot
if ($mode eq 'allslots') {
push(@got,$slot_name);
} else {
@@ -164,8 +461,11 @@ sub check_for_reservation {
sub get_consumed_uniqueperiods {
my ($slots) = @_;
my $navmap=Apache::lonnavmaps::navmap->new;
+ if (!defined($navmap)) {
+ return 'error: Unable to determine current status';
+ }
my @problems = $navmap->retrieveResources(undef,
- sub { $_[0]->is_problem() },1,0);
+ sub { $_[0]->is_problem() || $_[0]->is_tool() },1,0);
my %used_slots;
foreach my $problem (@problems) {
my $symb = $problem->symb();
@@ -175,7 +475,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)) {
@@ -186,7 +487,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;
@@ -211,12 +512,19 @@ sub check_for_conflict {
if (!defined($new_slot->{'uniqueperiod'})) { return undef; }
if (!ref($consumed_uniqueperiods)) {
- $consumed_uniqueperiods = &get_consumed_uniqueperiods($slots);
- if (&network_error(%$consumed_uniqueperiods)) {
- return 'error: Unable to determine current status';
- }
- }
-
+ if ($consumed_uniqueperiods =~ /^error: /) {
+ return $consumed_uniqueperiods;
+ } else {
+ $consumed_uniqueperiods = &get_consumed_uniqueperiods($slots);
+ if (ref($consumed_uniqueperiods) eq 'HASH') {
+ if (&Apache::lonnet::error(%$consumed_uniqueperiods)) {
+ return 'error: Unable to determine current status';
+ }
+ } else {
+ return 'error: Unable to determine current status';
+ }
+ }
+ }
my ($new_uniq_start,$new_uniq_end) = @{$new_slot->{'uniqueperiod'}};
foreach my $slot_name (keys(%$consumed_uniqueperiods)) {
my ($start,$end)=@{$consumed_uniqueperiods->{$slot_name}};
@@ -227,36 +535,27 @@ sub check_for_conflict {
}
}
return undef;
-
-}
-
-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)=@_;
-
- my ($cnum,$cdom)=&get_course();
+ my ($slot_name,$slot,$symb,$cnum,$cdom)=@_;
my $value=&Apache::lonnet::EXT("resource.0.availablestudent",$symb,
$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 (&network_error($value) || &network_error($use_slots)) {
+ if (&Apache::lonnet::error($value)
+ || &Apache::lonnet::error($use_slots)) {
return 'error: Unable to determine current status';
}
my $parm_symb = $symb;
my $parm_level = 1;
- if ($use_slots eq 'map') {
+ if ($use_slots eq 'map' || $use_slots eq 'map_map') {
my ($map) = &Apache::lonnet::decode_symb($symb);
$parm_symb = &Apache::lonnet::symbread($map);
$parm_level = 2;
@@ -266,7 +565,7 @@ sub make_reservation {
if ($other_slot eq $slot_name) {
my %consumed=&Apache::lonnet::dump('slot_reservations', $cdom,
$cnum, "^$slot_name\0");
- if (&network_error($value)) {
+ if (&Apache::lonnet::error($value)) {
return 'error: Unable to determine current status';
}
my $me=$env{'user.name'}.':'.$env{'user.domain'};
@@ -283,7 +582,7 @@ sub make_reservation {
if (!defined($max)) { $max=99999; }
my (@ids)=&get_reservation_ids($slot_name);
- if (&network_error(@ids)) {
+ if (&Apache::lonnet::error(@ids)) {
return 'error: Unable to determine current status';
}
my $last=0;
@@ -313,13 +612,7 @@ sub make_reservation {
if ($value) {
$new_value=$value.':'.$new_value;
}
- my $result=&Apache::lonparmset::storeparm_by_symb($symb,
- '0_availablestudent',
- $parm_level, $new_value,
- 'string',
- $env{'user.name'},
- $env{'user.domain'});
- &Apache::lonxml::debug("hrrm $result");
+ &store_slot_parm($symb,$slot_name,$parm_level,$new_value,$cnum,$cdom);
return $wanted;
}
@@ -327,6 +620,32 @@ sub make_reservation {
return undef;
}
+sub store_slot_parm {
+ my ($symb,$slot_name,$parm_level,$new_value,$cnum,$cdom) = @_;
+ my $result=&Apache::lonparmset::storeparm_by_symb($symb,
+ '0_availablestudent',
+ $parm_level, $new_value,
+ 'string',
+ $env{'user.name'},
+ $env{'user.domain'});
+ &Apache::lonxml::debug("hrrm $result");
+ my %storehash = (
+ symb => $symb,
+ slot => $slot_name,
+ action => 'reserve',
+ context => $env{'form.context'},
+ );
+
+ &Apache::lonnet::write_log('course','slotreservationslog',\%storehash,
+ '',$env{'user.name'},$env{'user.domain'},
+ $cnum,$cdom);
+ &Apache::lonnet::write_log('course',$cdom.'_'.$cnum.'_slotlog',\%storehash,
+ 1,$env{'user.name'},$env{'user.domain'},
+ $env{'user.name'},$env{'user.domain'});
+
+ return;
+}
+
sub remove_registration {
my ($r) = @_;
if ($env{'form.entry'} ne 'remove all') {
@@ -338,13 +657,13 @@ sub remove_registration {
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.').'
'); + if (&Apache::lonnet::error(%consumed)) { + $r->print("".&mt('A network error has occurred.').'
'); return; } if (!%consumed) { - $r->print("".&mt('Slot [_1] has no reservations.', - $slot_name)."
"); + $r->print(''.&mt('Slot [_1] has no reservations.', + ''.$slot_name.'').'
'); return; } @@ -352,7 +671,7 @@ sub remove_registration { my $names = join(' ',@names); my $msg = &mt('Remove all of [_1] from slot [_2]?',$names,$slot_name); - &remove_registration_confirmation($r,$msg,['entry','slotname']); + &remove_registration_confirmation($r,$msg,['entry','slotname','context']); } sub remove_registration_user { @@ -369,7 +688,7 @@ sub remove_registration_user { $name,$slot_name,$title); &remove_registration_confirmation($r,$msg,['uname','udom','slotname', - 'entry','symb']); + 'entry','symb','context']); } sub remove_registration_confirmation { @@ -381,8 +700,10 @@ sub remove_registration_confirmation { '&\'').'" />'."\n"; } - my %lt = &Apache::lonlocal::texthash('yes' => 'Yes', - 'no' => 'No',); + my %lt = &Apache::lonlocal::texthash( + 'yes' => 'Yes', + 'no' => 'No', + ); $r->print(<<"END_CONFIRM");$msg
'); + if ($shownheader) { + $r->print(&Apache::loncommon::end_data_table()); + } else { + $r->print(''.&mt('No slots meet the criteria for display').'
'); + } + $r->print(''); + return; +} + +sub manage_reservations { + my ($r,$crstype,$slots,$consumed_uniqueperiods,$allavailable) = @_; + my ($cnum,$cdom)=&get_course(); + my $navmap = Apache::lonnavmaps::navmap->new(); + $r->print(''
+ .&mt('Instructors may use a reservation system to place restrictions on when and where assignments can be worked on.')
+ .'
'
+ .&mt('One example is for management of laboratory space, which is only available at certain times, and has a limited number of seats.')
+ .'
'. + &mt('Your reservation status for any such assignments is listed below:'). + '
'. + ''.$spacers.''. + $icon.(' ' x6).' | '."\n"; + if (ref($output{$currmap}) eq 'HASH') { + my $formnum = $mapnum.'_'.$reservable+1; + my $class = 'LC_slotmaptext_'.$mapnum; + if ($output{$currmap}{'hasaction'}) { + $row .= ''. + $output{$currmap}{'msg'}. + ' | '. + &slot_chooser($repsymbs{$currmap},$class,$formnum, + $allavailable,$slots,$consumed_uniqueperiods). + ' | '; + } else { + $row .= ''. + $output{$currmap}{'msg'}. + ' | '; + } + $row .= ''."\n"; + } + } else { + my ($spacers,$icon) = &show_map_row($depth,$location,$currmaptype,$currmaptitle); + $row .= ' | '.$spacers.$icon.(' ' x6).' | '."\n"; + } + $r->print($row); + } + } + } elsif ($resource == $it->END_MAP()) { + $depth--; + $currcontainer = $parent{$depth}; + } elsif (ref($resource)) { + my $symb = $resource->symb(); + next if (!$resource->is_problem() && !$resource->is_tool() && + !$resource->is_sequence() && !$resource->is_page()); + $count ++; + if (($resource->is_sequence()) || ($resource->is_page())) { + $currcontainer = $count; + $container{$currcontainer} = $resource; + $container_title{$currcontainer} = $resource->compTitle(); + } + if (($resource->is_problem() || $resource->is_tool)) { + next unless (exists($output{$symb})); + $reservable ++; + $rownum ++; + if (!$shownheader) { + $r->print($slotheader); + $shownheader = 1; + } + my $style; + if (exists($output{$currmap})) { + $style = 'none'; + } else { + $style = 'table-row'; + $shown ++; + } + my $title = $resource->compTitle(); + my $bgcolor = $backgrounds[$shown % $numcolors]; + $r->print(' |
'); + for (my $i=0; $i<$depth; $i++) { + $r->print(''); + } + $r->print(''. + ''.$title.''.(' ' x6).' | '); + my $class = 'LC_slottext_'.$mapnum; + if ($output{$symb}{'hasaction'}) { + $r->print(''.$output{$symb}{'msg'}.' | '. + ''. + &slot_chooser($symb,$class,$reservable,$allavailable,$slots, + $consumed_uniqueperiods).' | '); + } else { + $r->print(''. + ''.$output{$symb}{'msg'}.''. + ' | '); + } + $r->print('
'. + &mt('Reservation History').'
'); +} + +sub show_map_row { + my ($depth,$location,$type,$title) = @_; + my $spacers; + for (my $i=0; $i<$depth-1; $i++) { + $spacers .= ''; + } + my $icon; + if ($type eq 'page') { + $icon = ' '."\n"; + } else { + $icon = ' '."\n"; + } + $icon .= $title; + return ($spacers,$icon); +} + +sub slot_chooser { + my ($symb,$class,$formnum,$allavailable,$slots,$consumed_uniqueperiods) = @_; + my $output; + my @got_slots=&check_for_reservation($symb,'allslots'); + if ($got_slots[0] =~ /^error: /) { + $output = ''. + &mt('An error occurred determining slot availability.'). + ''; + } else { + my $formname = 'manageres_'.$formnum; + if (ref($allavailable) eq 'ARRAY') { + my @available; + if (ref($slots) eq 'HASH') { + foreach my $slot (@{$allavailable}) { + # not allowed for this resource + if (ref($slots->{$slot}) eq 'HASH') { + if ($slots->{$slot}->{'symb'} ne '') { + my ($map,$id,$url) = &Apache::lonnet::decode_symb($symb); + my $exclude = 1; + my @reqsymbs = split(/\s*,\s*/,$slots->{$slot}->{'symb'}); + if (@reqsymbs) { + if (grep(/^\Q$symb\E$/,@reqsymbs)) { + $exclude = 0; + } else { + foreach my $reqsymb (@reqsymbs) { + my (undef,undef,$sloturl) = &Apache::lonnet::decode_symb($reqsymb); + if ($sloturl=~/\.(page|sequence)$/) { + if (($map ne '') && ($map eq $sloturl)) { + $exclude = 0; + last; + } + } + } + } + next if ($exclude); + } + } + } + push(@available,$slot); + } + } + $output .= &show_choices($symb,$formname,$formnum,$class, + $slots,$consumed_uniqueperiods, + \@available,\@got_slots); + } + } + return $output; +} + +sub show_reservations { + my ($r,$uname,$udom) = @_; + if (!defined($uname)) { + $uname = $env{'user.name'}; + } + if (!defined($udom)) { + $udom = $env{'user.domain'}; + } + my $formname = 'slotlog'; + my ($cnum,$cdom)=&get_course(); + my $crstype = &Apache::loncommon::course_type(); + my %log=&Apache::lonnet::dump('nohist_'.$cdom.'_'.$cnum.'_slotlog',$udom,$uname); + if ($env{'form.origin'} eq 'aboutme') { + $r->print(''); + if ($curr{'page'} > 1) { + $r->print(''); + } + if ($more_records) { + $r->print(''); + } + $r->print('
'); + $r->print(<<"ENDSCRIPT"); + +ENDSCRIPT + } + } else { + $r->print('' + .&mt('There are no transactions to display.') + .'' + ); + } + $r->print(''."\n". + ''."\n"); + if ($env{'form.origin'} eq 'aboutme') { + $r->print(''."\n". + ''."\n". + ''."\n"); + } + $r->print(''. + &mt('Return to slot list').'
'); + return; + } + my $formname = 'reservationslog'; + my ($cnum,$cdom)=&get_course(); + my %slotlog=&Apache::lonnet::dump('nohist_slotreservationslog',$cdom,$cnum); + if ((keys(%slotlog))[0]=~/^error\:/) { undef(%slotlog); } + + my (%log,@allsymbs); + if (keys(%slotlog)) { + foreach my $key (keys(%slotlog)) { + if (ref($slotlog{$key}) eq 'HASH') { + if (ref($slotlog{$key}{'logentry'}) eq 'HASH') { + if ($slotlog{$key}{'logentry'}{'slot'} eq $env{'form.slotname'}) { + $log{$key} = $slotlog{$key}; + if ($slotlog{$key}{'logentry'}{'symb'} ne '') { + push(@allsymbs,$slotlog{$key}{'logentry'}{'symb'}); + } + } + } + } + } + } + + $r->print(''); + if ($curr{'page'} > 1) { + $r->print(''); + } + if ($more_records) { + $r->print(''); + } + $r->print('
'); + $r->print(<<"ENDSCRIPT"); + +ENDSCRIPT + } + } else { + $r->print(&mt('There are no records to display.')); + } + $r->print(''. + ''. + ''. + &mt('Return to slot list').'
'); + return; +} + +sub get_resource_title { + my ($symb,$titles,$maptitles) = @_; + my $title; + if ((ref($titles) eq 'HASH') && (ref($maptitles) eq 'HASH')) { + if (defined($titles->{$symb})) { + $title = $titles->{$symb}; + } else { + $title = &Apache::lonnet::gettitle($symb); + my $maptitle; + my ($mapurl) = &Apache::lonnet::decode_symb($symb); + if (defined($maptitles->{$mapurl})) { + $maptitle = $maptitles->{$mapurl}; + } else { + if ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'}) { + $maptitle=&mt('Main Content'); + } else { + $maptitle=&Apache::lonnet::gettitle($mapurl); + } + $maptitles->{$mapurl} = $maptitle; + } + if ($maptitle ne '') { + $title .= ' '.&mt('(in [_1])',$maptitle); + } + $titles->{$symb} = $title; + } + } else { + $title = $symb; + } + return $title; +} + +sub reservationlog_contexts { + my ($crstype) = @_; + my %lt = &Apache::lonlocal::texthash ( + any => 'Any', + user => 'By student', + manage => 'Via Slot Manager', + parameter => 'Via Parameter Manager', + reserve => 'Made reservation', + release => 'Dropped reservation', + usermanage => 'By student', + ); + if ($crstype eq 'Community') { + $lt{'user'} = &mt('By member'); + $lt{'usermanage'} = $lt{'user'}; + } + return %lt; +} + +sub display_filter { + my ($formname,$cdom,$cnum,$curr,$version,$allsymbs) = @_; + my $nolink = 1; + my (%titles,%maptitles); + my $output = ''.
+ ''.&mt('Changes/page:').' '. + &Apache::lonmeta::selectbox('show',$curr->{'show'},undef, + (&mt('all'),5,10,20,50,100,1000,10000)). + ' | '; + my $startform = + &Apache::lonhtmlcommon::date_setter($formname,'log_start_date', + $curr->{'log_start_date'},undef, + undef,undef,undef,undef,undef,undef,$nolink); + my $endform = + &Apache::lonhtmlcommon::date_setter($formname,'log_end_date', + $curr->{'log_end_date'},undef, + undef,undef,undef,undef,undef,undef,$nolink); + my $crstype = &Apache::loncommon::course_type(); + my %lt = &reservationlog_contexts($crstype); + $output .= ' | '.&mt('Window during which changes occurred:').
+ '
| '; + if (ref($allsymbs) eq 'ARRAY') { + $output .= ' | '.&mt('Resource').' '. + ' | '.
+ &mt('Context:').' | ';
+ } else {
+ $output .= ''.&mt('Action').' '. + ' | ';
+ }
+ $output .= '
'. + &mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.' + ,'2.9.0'); + if ($version) { + $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version); + } + $output .= '
'."\n"; - $result.=' '. - &mt('Specify a file containing the slot definitions.'). - ' |
'."\n";
- my $upfile_select=&Apache::loncommon::upfile_select_html();
- my $ignore=&mt('Ignore First Line');
- $result.=< - - -ENDUPFORM - $result.=' |
' + .'' + .'
' + .'' + .&mt('Total number of records found in file: [_1]',''.$distotal.'') + ."
\n" + ); + if ($distotal == 0) { + $r->print(''.&mt('None found').'
'); + } + $r->print( + ''
+ .&mt('Enter as many fields as you can.').'
'
+ .&mt('The system will inform you and bring you back to this page,[_1]if the data selected is insufficient to create the slots.','
')
+ .'
Created $countdone slots\n
"); + if ($countdone) { + &Apache::lonnet::devalidate_slots_cache($cname,$cdom); + } + $r->print(''.&mt('Created [quant,_1,slot]',$countdone)."\n".'
'); foreach my $error (@errors) { - $r->print("$error\n
"); + $r->print(''.$error.'
'."\n"); } &show_table($r,$mgr); return ''; } +sub slot_command_titles { + my %titles = ( + slotlog => 'Reservation Logs', + showslots => 'Manage Slots', + showresv => 'Reservation History', + manageresv => 'Manage Reservations', + uploadstart => 'Upload Slots File', + csvuploadmap => 'Upload Slots File', + csvuploadassign => 'Upload Slots File', + delete => 'Slot Deletion', + release => 'Reservation Result', + remove_reservation => 'Remove Registration', + get_reservation => 'Request Reservation', + ); + return %titles; +} + +sub slot_reservationmsg_options { + my %options = &Apache::lonlocal::texthash ( + only_student => 'Sent to student', + student_and_user_notes_screen => 'Sent to student and added to user notes', + none => 'None sent and no record in user notes', + ); + return %options; +} + sub handler { my $r=shift; @@ -1522,16 +3183,84 @@ sub handler { } &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}); - + + my %crumb_titles = &slot_command_titles(); + my $brcrum; + my $vgr=&Apache::lonnet::allowed('vgr',$env{'request.course.id'}); my $mgr=&Apache::lonnet::allowed('mgr',$env{'request.course.id'}); + my (%slots,$consumed_uniqueperiods); + if ($env{'form.command'} eq 'showslots') { + if (($vgr ne 'F') && ($mgr ne 'F')) { + $env{'form.command'} = 'manageresv'; + } + } elsif ($env{'form.command'} eq 'manageresv') { + if (($vgr eq 'F') || ($mgr eq 'F')) { + $env{'form.command'} = 'showslots'; + } + } my $title='Requesting Another Worktime'; - if ($env{'form.command'} =~ /^(showslots|uploadstart|csvuploadmap|csvuploadassign)$/ && $vgr eq 'F') { - $title = 'Managing Slots'; + if ($env{'form.command'} eq 'showresv') { + $title = 'Reservation History'; + if ($env{'form.origin'} eq 'aboutme') { + $brcrum =[{href=>"/adm/$env{'form.udom'}/$env{'form.uname'}/aboutme",text=>'Personal Information Page'}]; + } else { + $brcrum =[{href=>"/adm/slotrequest?command=manageresv",text=>'Manage Reservations'}]; + } + if (ref($brcrum) eq 'ARRAY') { + push(@{$brcrum},{href=>"/adm/slotrequest?command=showresv",text=>$title}); + } + } elsif (($env{'form.requestattempt'}) || ($env{'form.command'} eq 'manageresv')) { + if ($env{'form.command'} eq 'manageresv') { + $title = 'Manage Reservations'; + $brcrum =[{href=>"/adm/slotrequest?command=manageresv",text=>$title}]; + } + my ($cnum,$cdom)=&get_course(); + %slots = &Apache::lonnet::get_course_slots($cnum,$cdom); + $consumed_uniqueperiods = &get_consumed_uniqueperiods(\%slots); + } elsif ($vgr eq 'F') { + if ($env{'form.command'} =~ /^(slotlog|showslots|uploadstart|csvuploadmap|csvuploadassign|delete|release|remove_registration)$/) { + $brcrum =[{href=>"/adm/slotrequest?command=showslots", + text=>$crumb_titles{'showslots'}}]; + $title = 'Managing Slots'; + unless ($env{'form.command'} eq 'showslots') { + if (ref($brcrum) eq 'ARRAY') { + push(@{$brcrum},{href=>"/adm/slotrequest?command=$env{'form.command'}",text=>$crumb_titles{$env{'form.command'}}}); + } + } + } + } elsif ($env{'form.command'} eq 'release') { + if ($env{'form.context'} eq 'usermanage') { + $brcrum =[{href=>"/adm/slotrequest?command=manageresv", + text=>$crumb_titles{'showslots'}}]; + $title = 'Manage Reservations'; + if (ref($brcrum) eq 'ARRAY') { + push(@{$brcrum},{href=>"/adm/slotrequest?command=$env{'form.command'}",text=>$crumb_titles{$env{'form.command'}}}); + } + } + } else { + $brcrum =[]; } - &start_page($r,$title); - - if ($env{'form.command'} eq 'showslots' && $vgr eq 'F') { + my ($symb,$js,$available,$allavailable,$got_slots); + $available = []; + if ($env{'form.requestattempt'}) { + $symb=&unescape($env{'form.symb'}); + @{$got_slots}=&check_for_reservation($symb,'allslots'); + } + if (($env{'form.requestattempt'}) || ($env{'form.command'} eq 'manageresv')) { + $js = &reservation_js(\%slots,$consumed_uniqueperiods,$available,$got_slots,$symb); + } + &start_page($r,$title,$brcrum,$js); + + if ($env{'form.command'} eq 'manageresv') { + $allavailable = $available; + undef($available); + undef($got_slots); + my $crstype = &Apache::loncommon::course_type(); + &manage_reservations($r,$crstype,\%slots,$consumed_uniqueperiods,$allavailable); + } elsif ($env{'form.command'} eq 'showresv') { + &show_reservations($r,$env{'form.uname'},$env{'form.udom'}); + } elsif ($env{'form.command'} eq 'showslots' && $vgr eq 'F') { &show_table($r,$mgr); } elsif ($env{'form.command'} eq 'remove_registration' && $mgr eq 'F') { &remove_registration($r); @@ -1558,6 +3287,8 @@ sub handler { } &csv_upload_map($r); } + } elsif (($env{'form.command'} eq 'slotlog') && ($vgr eq 'F')) { + &show_reservations_log($r); } else { my $symb=&unescape($env{'form.symb'}); if (!defined($symb)) { @@ -1566,7 +3297,9 @@ sub handler { } my (undef,undef,$res)=&Apache::lonnet::decode_symb($symb); my $useslots = &Apache::lonnet::EXT("resource.0.useslots",$symb); - if ($useslots ne 'resource' && $useslots ne 'map') { + if ($useslots ne 'resource' + && $useslots ne 'map' + && $useslots ne 'map_map') { &fail($r,'not_available'); return OK; } @@ -1576,22 +3309,44 @@ sub handler { my ($status) = &Apache::lonhomework::check_slot_access('0',$type); if ($status eq 'CAN_ANSWER' || $status eq 'NEEDS_CHECKIN' || - $status eq 'WAITING_FOR_GRADE') { + $status eq 'WAITING_FOR_GRADE' || + $status eq 'NEED_DIFFERENT_IP') { &fail($r,'not_allowed'); return OK; } if ($env{'form.requestattempt'}) { - &show_choices($r,$symb); + $r->print('Unknown command: ".$env{'form.command'}."
"); + $r->print(''.&mt('Unknown command: [_1]',$env{'form.command'}).'
'); } } &end_page($r);