--- loncom/interface/slotrequest.pm 2005/11/21 18:55:41 1.33 +++ loncom/interface/slotrequest.pm 2005/12/14 22:26:10 1.37 @@ -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.33 2005/11/21 18:55:41 albertel Exp $ +# $Id: slotrequest.pm,v 1.37 2005/12/14 22:26:10 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -316,6 +316,38 @@ sub release_slot { return 1; } +sub delete_slot { + my ($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 (%slot && !%consumed) { + $slot{'type'} = 'deleted'; + my $ret = &Apache::lonnet::cput('slots', {$slot_name => \%slot}, + $cdom, $cnum); + if ($ret eq 'ok') { + $r->print("<p>Slot <tt>$slot_name</tt> marked as deleted.</p>"); + } else { + $r->print("<p> An error ($ret) occurse when attempting to delete Slot <tt>$slot_name</tt>.</p>"); + } + } else { + if (%consumed) { + $r->print("<p>Slot <tt>$slot_name</tt> has active reservations.</p>"); + } else { + $r->print("<p>Slot <tt>$slot_name</tt> does not exist.</p>"); + } + } + $r->print('<p><a href="/adm/slotrequest?command=showslots">'. + &mt('Return to slot list').'</a></p>'); + $r->print('<p><a href="/adm/flip?postdata=return:">'. + &mt('Return to last resource').'</a></p>'); +} + sub get_slot { my ($r,$symb)=@_; @@ -492,10 +524,15 @@ STUFF } sub to_show { - my ($when,$slot) = @_; + my ($slot,$when,$deleted) = @_; my $time=time; my $week=60*60*24*7; - if ($when eq 'now') { + if ($deleted eq 'hide' && $slot->{'type'} eq 'deleted') { + return 0; + } + if ($when eq 'any') { + return 1; + } elsif ($when eq 'now') { if ($time > $slot->{'starttime'} && $time < $slot->{'endtime'}) { return 1; @@ -573,10 +610,11 @@ sub show_table { $r->print('</div>'); } - my %Saveable_Parameters = ('show' => 'array', - 'when' => 'scalar', - 'order' => 'scalar'); - + 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); @@ -588,7 +626,7 @@ sub show_table { 'endtime' => 'End Time', 'startreserve' => 'Time students can start reserving', 'secret' => 'Secret Word', - 'maxspace' => 'Maxium # of students', + 'maxspace' => 'Maximum # of students', 'ip' => 'IP or DNS restrictions', 'symb' => 'Resource slot is restricted to.', 'uniqueperiod' => 'Period of time slot is unique', @@ -602,22 +640,48 @@ sub show_table { my %show = map { $_ => 1 } (@show); my %when_fields=&Apache::lonlocal::texthash( - 'now' => 'Open now', + 'now' => 'Open now', 'nextweek' => 'Open within the next week', 'lastweek' => 'Were open last week', 'willopen' => 'Will open later', - 'wereopen' => 'Were open'); - my @when_order=('now','nextweek','lastweek','willopen','wereopen'); + '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('<form method="POST" action="/adm/slotrequest"> <input type="hidden" name="command" value="showslots" />'); $r->print('<div>'); - $r->print('<table class="inline"><tr><th>'.&mt('Show').'</th><th>'.&mt('Open').'</th></tr><tr><td>'.&Apache::loncommon::multiple_select_form('show',\@show,6,\%show_fields,\@show_order). - '</td><td>'.&Apache::loncommon::select_form($when,'when',%when_fields). - '</td></tr></table>'); + $r->print('<table class="inline"> + <tr><th>'.&mt('Show').'</th> + <th>'.&mt('Open').'</th> + <th>'.&mt('Options').'</th> + </tr> + <tr><td>'.&Apache::loncommon::multiple_select_form('show',\@show,6,\%show_fields,\@show_order). + '</td> + <td>'.&Apache::loncommon::select_form($when,'when',%when_fields). + '</td> + <td> + <table> + <tr> + <td rowspan="2">Deleted slots:</td> + <td><label>'.$show_radio.'Show</label></td> + </tr> + <tr> + <td><label>'.$hide_radio.'Hide</label></td> + </tr> + </table> + </td> + </tr> + </table>'); $r->print('</div>'); $r->print('<p><input type="submit" name="start" value="'.&mt('Update Display').'" /></p>'); my $linkstart='<a href="/adm/slotrequest?command=showslots&order='; @@ -659,7 +723,7 @@ sub show_table { return $slots{$a}->{'starttime'} <=> $slots{$b}->{'starttime'}; }; foreach my $slot (sort $slotsort (keys(%slots))) { - if (!&to_show($when,$slots{$slot})) { next; } + if (!&to_show($slots{$slot},$when,$env{'form.deleted'})) { next; } if (defined($slots{$slot}->{'type'}) && $slots{$slot}->{'type'} ne 'schedulable_student') { #next; @@ -718,11 +782,16 @@ sub show_table { } my $proctors=join(', ',@proctors); - my $edit=(<<EDITLINK); + my $edit=(<<"EDITLINK"); <a href="/adm/helper/newslot.helper?name=$slot">Edit</a> EDITLINK - - $r->print("<tr>\n<td rowspan=\"$rowspan\">$edit</td>\n"); + + my $delete=(<<"DELETELINK"); +<a href="/adm/slotrequest?command=delete&slotname=$slot">Delete</a> +DELETELINK + if ($ids ne '') { undef($delete); } + + $r->print("<tr>\n<td rowspan=\"$rowspan\">$edit $delete</td>\n"); if (exists($show{'name'})) { $colspan++;$r->print("<td>$slot</td>"); } @@ -1040,6 +1109,8 @@ sub handler { &remove_registration($r); } elsif ($env{'form.command'} eq 'release' && $mgr eq 'F') { &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') { &upload_start($r); } elsif ($env{'form.command'} eq 'csvuploadmap' && $mgr eq 'F') { @@ -1058,12 +1129,15 @@ sub handler { } else { my $symb=&Apache::lonnet::unescape($env{'form.symb'}); my (undef,undef,$res)=&Apache::lonnet::decode_symb($symb); - if ($res !~ /\.task$/) { + my $useslots = &Apache::lonnet::EXT("resource.0.useslots",$symb); + if ($useslots ne 'resource') { &fail($r,'not_valid'); return OK; } $env{'request.symb'}=$symb; - my ($status) = &Apache::lonhomework::check_task_access('0'); + my $type = ($res =~ /\.task$/) ? 'Task' + : 'problem'; + my ($status) = &Apache::lonhomework::check_slot_access('0',$type); if ($status eq 'CAN_ANSWER' || $status eq 'NEEDS_CHECKIN' || $status eq 'WAITING_FOR_GRADE') {