--- loncom/interface/slotrequest.pm 2005/08/09 15:04:50 1.6 +++ loncom/interface/slotrequest.pm 2005/11/18 16:26:47 1.31 @@ -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.6 2005/08/09 15:04:50 albertel Exp $ +# $Id: slotrequest.pm,v 1.31 2005/11/18 16:26:47 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -34,24 +34,29 @@ 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.').'
'); + } elsif ($code eq 'not_allowed') { + $r->print(''.&mt('Not allowed to sign up or change reservations at this time.').'
'); + } else { + $r->print(''.&mt('Failed.').'
'); } + $r->print(''. &mt('Return to last resource').'
'); &end_page($r); } sub start_page { - my ($r)=@_; + my ($r,$title)=@_; my $html=&Apache::lonxml::xmlbegin(); - $r->print($html.'Released Reservation: $description
"); - if ($inhibit_return_link) { + if (!$inhibit_return_link) { $r->print(''. &mt('Return to last resource').'
'); } @@ -285,44 +285,50 @@ sub get_slot { %slot=&Apache::lonnet::get_slot($env{'form.slotname'}); my $description2=&get_description($env{'form.slotname'},\%slot); $r->print("Already have a reservation: $description1
"); - $r->print(<You can either ");
- $r->print(< You can either ");
+ $r->print(<
or '.
- &mt('Return to last resource').'
or '.
+ &mt('Return to last resource').'
'. + &mt('Return to last resource').'
'); + } return; } my %slot=&Apache::lonnet::get_slot($env{'form.slotname'}); my $reserved=&make_reservation($env{'form.slotname'}, \%slot,$symb); my $description=&get_description($env{'form.slotname'},\%slot); - if ($reserved > -1) { - $r->print("Success: $description
"); - $r->print(''. - &mt('Return to last resource').'
'); - return; - } elsif ($reserved < 0) { - $r->print("Already reserved: $description
"); - $r->print(''. - &mt('Return to last resource').'
'); - return; + if (defined($reserved)) { + if ($reserved > -1) { + $r->print("Success: $description
"); + $r->print(''. + &mt('Return to last resource').'
'); + return; + } elsif ($reserved < 0) { + $r->print("Already reserved: $description
"); + $r->print(''. + &mt('Return to last resource').'
'); + return; + } } - my %lt=('request'=>"Request another attempt", + my %lt=('request'=>"Availibility list", 'try' =>'Try again'); %lt=&Apache::lonlocal::texthash(%lt); @@ -411,7 +417,8 @@ sub show_choices { my $description=&get_description($slot,$slots{$slot}); my $form=&mt('Unavailable'); - if (&space_available($slot,$slots{$slot},$symb)) { + if (($slot eq $got_slot) || + &space_available($slot,$slots{$slot},$symb)) { my $text=&mt('Select'); my $command='get'; if ($slot eq $got_slot) { @@ -443,19 +450,160 @@ STUFF $r->print(''); } +sub to_show { + my ($when,$slot) = @_; + my $time=time; + my $week=60*60*24*7; + if ($when eq 'now') { + if ($time > $slot->{'starttime'} && + $time < $slot->{'endtime'}) { + return 1; + } + return 0; + } elsif ($when eq 'nextweek') { + if ( ($time < $slot->{'starttime'} && + ($time+$week) > $slot->{'starttime'}) + || + ($time < $slot->{'endtime'} && + ($time+$week) > $slot->{'endtime'}) ) { + return 1; + } + return 0; + } elsif ($when eq 'lastweek') { + if ( ($time > $slot->{'starttime'} && + ($time-$week) < $slot->{'starttime'}) + || + ($time > $slot->{'endtime'} && + ($time-$week) < $slot->{'endtime'}) ) { + return 1; + } + return 0; + } elsif ($when eq 'willopen') { + if ($time < $slot->{'starttime'}) { + return 1; + } + return 0; + } elsif ($when eq 'wereopen') { + if ($time > $slot->{'endtime'}) { + return 1; + } + return 0; + } + + return 1; +} + sub show_table { - my ($r,$symb)=@_; + my ($r,$mgr)=@_; my ($cnum,$cdom)=&get_course(); my %slots=&Apache::lonnet::dump('slots',$cdom,$cnum); + if ( (keys(%slots))[0] =~ /^error: 2 /) { + undef(%slots); + } my $available; - $r->print('$edit | \n"); + if (exists($show{'name'})) { + $colspan++;$r->print("$slot | "); + } + if (exists($show{'type'})) { + $colspan++;$r->print("$slots{$slot}->{'type'} | \n"); + } + if (exists($show{'description'})) { + $colspan++;$r->print("$description | \n"); + } + if (exists($show{'starttime'})) { + $colspan++;$r->print("$start | \n"); + } + if (exists($show{'endtime'})) { + $colspan++;$r->print("$end | \n"); + } + if (exists($show{'startreserve'})) { + $colspan++;$r->print("$start_reserve | \n"); + } + if (exists($show{'secret'})) { + $colspan++;$r->print("$slots{$slot}{'secret'} | \n"); + } + if (exists($show{'maxspace'})) { + $colspan++;$r->print("$slots{$slot}{'maxspace'} | \n"); + } + if (exists($show{'ip'})) { + $colspan++;$r->print("$slots{$slot}{'ip'} | \n"); + } + if (exists($show{'symb'})) { + $colspan++;$r->print("$title | \n"); + } + if (exists($show{'uniqueperiod'})) { + $colspan++;$r->print("$unique | \n"); + } + $colspan++;$r->print("$ids | \n$slot | -$description | -$start | -$end | -$slots{$slot}->{'maxspace'} | -$ids | +$proctors | STUFF + } } $r->print('
'."\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.=' |
Created $countdone slots\n
"); + foreach my $error (@errors) { + $r->print("$error\n
"); + } + &show_table($r,$mgr); + return ''; +} + sub handler { my $r=shift; - &start_page($r); - my $symb=&Apache::lonnet::unescape($env{'form.symb'}); - my (undef,undef,$res)=&Apache::lonnet::decode_symb($symb); - if ($res !~ /\.task$/) { - &fail($r,'not_valid'); + &Apache::loncommon::content_type($r,'text/html'); + &Apache::loncommon::no_cache($r); + if ($r->header_only()) { + $r->send_http_header(); return OK; } - - 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); + + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}); + + my $vgr=&Apache::lonnet::allowed('vgr',$env{'request.course.id'}); + my $mgr=&Apache::lonnet::allowed('mgr',$env{'request.course.id'}); + my $title='Requesting Another Worktime'; + if ($env{'form.command'} =~ /^(showslots|uploadstart|csvuploadmap|csvuploadassign)$/ && $vgr eq 'F') { + $title = 'Managing Slots'; + } + &start_page($r,$title); + + if ($env{'form.command'} eq 'showslots' && $vgr eq 'F') { + &show_table($r,$mgr); + } elsif ($env{'form.command'} eq 'uploadstart' && $mgr eq 'F') { + &upload_start($r); + } elsif ($env{'form.command'} eq 'csvuploadmap' && $mgr eq 'F') { + &csv_upload_map($r); + } elsif ($env{'form.command'} eq 'csvuploadassign' && $mgr eq 'F') { + if ($env{'form.associate'} ne 'Reverse Association') { + &csv_upload_assign($r,$mgr); + } else { + if ( $env{'form.upfile_associate'} ne 'reverse' ) { + $env{'form.upfile_associate'} = 'reverse'; + } else { + $env{'form.upfile_associate'} = 'forward'; + } + &csv_upload_map($r); + } + } else { + my $symb=&Apache::lonnet::unescape($env{'form.symb'}); + my (undef,undef,$res)=&Apache::lonnet::decode_symb($symb); + if ($res !~ /\.task$/) { + &fail($r,'not_valid'); + return OK; + } + $env{'request.symb'}=$symb; + my ($status) = &Apache::lonhomework::check_task_access('0'); + if ($status eq 'CAN_ANSWER' || + $status eq 'NEEDS_CHECKIN' || + $status eq 'WAITING_FOR_GRADE') { + &fail($r,'not_allowed'); + return OK; + } + if ($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); + } else { + $r->print("Unknown command: ".$env{'form.command'}."
"); + } } &end_page($r); return OK;