File:  [LON-CAPA] / loncom / interface / slotrequest.pm
Revision 1.76: download - view: text, annotated - select for diffs
Tue Apr 10 23:30:41 2007 UTC (17 years, 1 month ago) by albertel
Branches: MAIN
CVS tags: HEAD
- preventing students from reserving a slot if it is already underway

    1: # The LearningOnline Network with CAPA
    2: # Handler for requesting to have slots added to a students record
    3: #
    4: # $Id: slotrequest.pm,v 1.76 2007/04/10 23:30:41 albertel Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: ###
   29: 
   30: package Apache::slotrequest;
   31: 
   32: use strict;
   33: use Apache::Constants qw(:common :http :methods);
   34: use Apache::loncommon();
   35: use Apache::lonlocal;
   36: use Apache::lonnet;
   37: use Apache::lonnavmaps();
   38: use Date::Manip;
   39: use lib '/home/httpd/lib/perl/';
   40: use LONCAPA;
   41: 
   42: sub fail {
   43:     my ($r,$code)=@_;
   44:     if ($code eq 'not_valid') {
   45: 	$r->print('<p>'.&mt('Unable to understand what resource you wanted to sign up for.').'</p>');
   46:     } elsif ($code eq 'not_available') {
   47: 	$r->print('<p>'.&mt('No slots are available.').'</p>');
   48:     } elsif ($code eq 'not_allowed') {
   49: 	$r->print('<p>'.&mt('Not allowed to sign up or change reservations at this time.').'</p>');
   50:     } else {
   51: 	$r->print('<p>'.&mt('Failed.').'</p>');
   52:     }
   53:     
   54:     &return_link($r);
   55:     &end_page($r);
   56: }
   57: 
   58: sub start_page {
   59:     my ($r,$title)=@_;
   60:     $r->print(&Apache::loncommon::start_page($title));
   61: }
   62: 
   63: sub end_page {
   64:     my ($r)=@_;
   65:     $r->print(&Apache::loncommon::end_page());
   66: }
   67: 
   68: =pod
   69: 
   70:  slot_reservations db
   71:    - keys are 
   72:     - slotname\0id -> value is an hashref of
   73:                          name -> user@domain of holder
   74:                          timestamp -> timestamp of reservation
   75:                          symb -> symb of resource that it is reserved for
   76: 
   77: =cut
   78: 
   79: sub get_course {
   80:     (undef,my $courseid)=&Apache::lonnet::whichuser();
   81:     my $cdom=$env{'course.'.$courseid.'.domain'};
   82:     my $cnum=$env{'course.'.$courseid.'.num'};
   83:     return ($cnum,$cdom);
   84: }
   85: 
   86: sub get_reservation_ids {
   87:     my ($slot_name)=@_;
   88:     
   89:     my ($cnum,$cdom)=&get_course();
   90: 
   91:     my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
   92: 				       "^$slot_name\0");
   93:     if (&Apache::lonnet::error(%consumed)) { 
   94: 	return 'error: Unable to determine current status';
   95:     }
   96:     my ($tmp)=%consumed;
   97:     if ($tmp=~/^error: 2 / ) {
   98: 	return 0;
   99:     }
  100:     return keys(%consumed);
  101: }
  102: 
  103: sub space_available {
  104:     my ($slot_name,$slot)=@_;
  105:     my $max=$slot->{'maxspace'};
  106: 
  107:     if (!defined($max)) { return 1; }
  108: 
  109:     my $consumed=scalar(&get_reservation_ids($slot_name));
  110:     if ($consumed < $max) {
  111: 	return 1
  112:     }
  113:     return 0;
  114: }
  115: 
  116: sub check_for_reservation {
  117:     my ($symb,$mode)=@_;
  118:     my $student = &Apache::lonnet::EXT("resource.0.availablestudent", $symb,
  119: 				       $env{'user.domain'}, $env{'user.name'});
  120: 
  121:     my $course = &Apache::lonnet::EXT("resource.0.available", $symb,
  122: 				    $env{'user.domain'}, $env{'user.name'});
  123:     my @slots = (split(/:/,$student), split(/:/, $course));
  124: 
  125:     &Apache::lonxml::debug(" slot list is ".join(':',@slots));
  126: 
  127:     my ($cnum,$cdom)=&get_course();
  128:     my %slots=&Apache::lonnet::get('slots', [@slots], $cdom, $cnum);
  129: 
  130:     if (&Apache::lonnet::error($student) 
  131: 	|| &Apache::lonnet::error($course)
  132: 	|| &Apache::lonnet::error(%slots)) {
  133: 	return 'error: Unable to determine current status';
  134:     }    
  135:     my @got;
  136:     foreach my $slot_name (sort {
  137: 	if (ref($slots{$a}) && ref($slots{$b})) {
  138: 	    return $slots{$a}{'starttime'} <=> $slots{$b}{'starttime'}
  139: 	}
  140: 	if (ref($slots{$a})) { return -1;}
  141: 	if (ref($slots{$b})) { return 1;}
  142: 	return 0;
  143:     } @slots) {
  144: 	next if (!defined($slots{$slot_name}) ||
  145: 		 !ref($slots{$slot_name}));
  146: 	&Apache::lonxml::debug(time." $slot_name ".
  147: 			       $slots{$slot_name}->{'starttime'}." -- ".
  148: 			       $slots{$slot_name}->{'startreserve'});
  149: 	if ($slots{$slot_name}->{'endtime'} > time &&
  150: 	    $slots{$slot_name}->{'startreserve'} < time) {
  151: 	    # between start of reservation times and end of slot
  152: 	    if ($mode eq 'allslots') {
  153: 		push(@got,$slot_name);
  154: 	    } else {
  155: 		return($slot_name, $slots{$slot_name});
  156: 	    }
  157: 	}
  158:     }
  159:     if ($mode eq 'allslots' && @got) {
  160: 	return @got;
  161:     }
  162:     return (undef,undef);
  163: }
  164: 
  165: sub get_consumed_uniqueperiods {
  166:     my ($slots) = @_;
  167:     my $navmap=Apache::lonnavmaps::navmap->new;
  168:     my @problems = $navmap->retrieveResources(undef,
  169: 					      sub { $_[0]->is_problem() },1,0);
  170:     my %used_slots;
  171:     foreach my $problem (@problems) {
  172: 	my $symb = $problem->symb();
  173: 	my $student = &Apache::lonnet::EXT("resource.0.availablestudent",
  174: 					   $symb, $env{'user.domain'},
  175: 					   $env{'user.name'});
  176: 	my $course =  &Apache::lonnet::EXT("resource.0.available",
  177: 					   $symb, $env{'user.domain'},
  178: 					   $env{'user.name'});
  179: 	if (&Apache::lonnet::error($student) 
  180: 	    || &Apache::lonnet::error($course)) {
  181: 	    return 'error: Unable to determine current status';
  182: 	}
  183: 	foreach my $slot (split(/:/,$student), split(/:/, $course)) {
  184: 	    $used_slots{$slot}=1;
  185: 	}
  186:     }
  187: 
  188:     if (!ref($slots)) {
  189: 	my ($cnum,$cdom)=&get_course();
  190: 	my %slots=&Apache::lonnet::get('slots', [keys(%used_slots)], $cdom, $cnum);
  191: 	if (&Apache::lonnet::error(%slots)) {
  192: 	    return 'error: Unable to determine current status';
  193: 	}
  194: 	$slots = \%slots;
  195:     }
  196: 
  197:     my %consumed_uniqueperiods;
  198:     foreach my $slot_name (keys(%used_slots)) {
  199: 	next if (!defined($slots->{$slot_name}) ||
  200: 		 !ref($slots->{$slot_name}));
  201: 	
  202:         next if (!defined($slots->{$slot_name}{'uniqueperiod'}) ||
  203: 		 !ref($slots->{$slot_name}{'uniqueperiod'}));
  204: 	$consumed_uniqueperiods{$slot_name} = 
  205: 	    $slots->{$slot_name}{'uniqueperiod'};
  206:     }
  207:     return \%consumed_uniqueperiods;
  208: }
  209: 
  210: sub check_for_conflict {
  211:     my ($symb,$new_slot_name,$new_slot,$slots,$consumed_uniqueperiods)=@_;
  212: 
  213:     if (!defined($new_slot->{'uniqueperiod'})) { return undef; }
  214: 
  215:     if (!ref($consumed_uniqueperiods)) {
  216: 	$consumed_uniqueperiods = &get_consumed_uniqueperiods($slots);
  217: 	if (&Apache::lonnet::error(%$consumed_uniqueperiods)) {
  218: 	    return 'error: Unable to determine current status';
  219: 	}
  220:     }
  221:     
  222:     my ($new_uniq_start,$new_uniq_end) = @{$new_slot->{'uniqueperiod'}};
  223:     foreach my $slot_name (keys(%$consumed_uniqueperiods)) {
  224: 	my ($start,$end)=@{$consumed_uniqueperiods->{$slot_name}};
  225: 	if (!
  226: 	    ($start < $new_uniq_start &&  $end < $new_uniq_start) ||
  227: 	    ($start > $new_uniq_end   &&  $end > $new_uniq_end  )) {
  228: 	    return $slot_name;
  229: 	}
  230:     }
  231:     return undef;
  232: 
  233: }
  234: 
  235: sub make_reservation {
  236:     my ($slot_name,$slot,$symb)=@_;
  237: 
  238:     my ($cnum,$cdom)=&get_course();
  239: 
  240:     my $value=&Apache::lonnet::EXT("resource.0.availablestudent",$symb,
  241: 				   $env{'user.domain'},$env{'user.name'});
  242:     &Apache::lonxml::debug("value is  $value<br />");
  243: 
  244:     my $use_slots = &Apache::lonnet::EXT("resource.0.useslots");
  245:     &Apache::lonxml::debug("use_slots is  $use_slots<br />");
  246: 
  247:     if (&Apache::lonnet::error($value) 
  248: 	|| &Apache::lonnet::error($use_slots)) { 
  249: 	return 'error: Unable to determine current status';
  250:     }
  251: 
  252:     my $parm_symb  = $symb;
  253:     my $parm_level = 1;
  254:     if ($use_slots eq 'map' || $use_slots eq 'map_map') {
  255: 	my ($map) = &Apache::lonnet::decode_symb($symb);
  256: 	$parm_symb = &Apache::lonnet::symbread($map);
  257: 	$parm_level = 2;
  258:     }
  259: 
  260:     foreach my $other_slot (split(/:/, $value)) {
  261: 	if ($other_slot eq $slot_name) {
  262: 	    my %consumed=&Apache::lonnet::dump('slot_reservations', $cdom,
  263: 					       $cnum, "^$slot_name\0");   
  264: 	    if (&Apache::lonnet::error($value)) { 
  265: 		return 'error: Unable to determine current status';
  266: 	    }
  267: 	    my $me=$env{'user.name'}.':'.$env{'user.domain'};
  268: 	    foreach my $key (keys(%consumed)) {
  269: 		if ($consumed{$key}->{'name'} eq $me) {
  270: 		    my $num=(split('\0',$key))[1];
  271: 		    return -$num;
  272: 		}
  273: 	    }
  274: 	}
  275:     }
  276: 
  277:     my $max=$slot->{'maxspace'};
  278:     if (!defined($max)) { $max=99999; }
  279: 
  280:     my (@ids)=&get_reservation_ids($slot_name);
  281:     if (&Apache::lonnet::error(@ids)) { 
  282: 	return 'error: Unable to determine current status';
  283:     }
  284:     my $last=0;
  285:     foreach my $id (@ids) {
  286: 	my $num=(split('\0',$id))[1];
  287: 	if ($num > $last) { $last=$num; }
  288:     }
  289:     
  290:     my $wanted=$last+1;
  291:     &Apache::lonxml::debug("wanted $wanted<br />");
  292:     if (scalar(@ids) >= $max) {
  293: 	# full up
  294: 	return undef;
  295:     }
  296:     
  297:     my %reservation=('name'      => $env{'user.name'}.':'.$env{'user.domain'},
  298: 		     'timestamp' => time,
  299: 		     'symb'      => $parm_symb);
  300: 
  301:     my $success=&Apache::lonnet::newput('slot_reservations',
  302: 					{"$slot_name\0$wanted" =>
  303: 					     \%reservation},
  304: 					$cdom, $cnum);
  305: 
  306:     if ($success eq 'ok') {
  307: 	my $new_value=$slot_name;
  308: 	if ($value) {
  309: 	    $new_value=$value.':'.$new_value;
  310: 	}
  311: 	my $result=&Apache::lonparmset::storeparm_by_symb($symb,
  312: 						      '0_availablestudent',
  313: 						       $parm_level, $new_value,
  314: 						       'string',
  315: 						       $env{'user.name'},
  316: 					               $env{'user.domain'});
  317: 	&Apache::lonxml::debug("hrrm $result");
  318: 	return $wanted;
  319:     }
  320: 
  321:     # someone else got it
  322:     return undef;
  323: }
  324: 
  325: sub remove_registration {
  326:     my ($r) = @_;
  327:     if ($env{'form.entry'} ne 'remove all') {
  328: 	return &remove_registration_user($r);
  329:     }
  330:     my $slot_name = $env{'form.slotname'};
  331:     my %slot=&Apache::lonnet::get_slot($slot_name);
  332: 
  333:     my ($cnum,$cdom)=&get_course();
  334:     my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
  335: 				       "^$slot_name\0");
  336:     if (&Apache::lonnet::error(%consumed)) {
  337: 	$r->print("<p>".&mt('A network error has occured.').'</p>');
  338: 	return;
  339:     }
  340:     if (!%consumed) {
  341: 	$r->print("<p>".&mt('Slot <tt>[_1]</tt> has no reservations.',
  342: 			    $slot_name)."</p>");
  343: 	return;
  344:     }
  345: 
  346:     my @names = map { $consumed{$_}{'name'} } (sort(keys(%consumed)));
  347:     my $names = join(' ',@names);
  348: 
  349:     my $msg = &mt('Remove all of [_1] from slot [_2]?',$names,$slot_name);
  350:     &remove_registration_confirmation($r,$msg,['entry','slotname']);
  351: }
  352: 
  353: sub remove_registration_user {
  354:     my ($r) = @_;
  355:     
  356:     my $slot_name = $env{'form.slotname'};
  357: 
  358:     my $name = &Apache::loncommon::plainname($env{'form.uname'},
  359: 					     $env{'form.udom'});
  360: 
  361:     my $title = &Apache::lonnet::gettitle($env{'form.symb'});
  362: 
  363:     my $msg = &mt('Remove [_1] from slot [_2] for [_3]',
  364: 		  $name,$slot_name,$title);
  365:     
  366:     &remove_registration_confirmation($r,$msg,['uname','udom','slotname',
  367: 					       'entry','symb']);
  368: }
  369: 
  370: sub remove_registration_confirmation {
  371:     my ($r,$msg,$inputs) =@_;
  372: 
  373:     my $hidden_input;
  374:     foreach my $parm (@{$inputs}) {
  375: 	$hidden_input .=
  376: 	    '<input type="hidden" name="'.$parm.'" value="'
  377: 	    .&HTML::Entities::encode($env{'form.'.$parm},'"<>&\'').'" />'."\n";
  378:     }
  379:     my %lt = &Apache::lonlocal::texthash('yes' => 'Yes',
  380: 					 'no'  => 'No',);
  381:     $r->print(<<"END_CONFIRM");
  382: <p> $msg </p>
  383: <form action="/adm/slotrequest" method="post">
  384:     <input type="hidden" name="command" value="release" />
  385:     <input type="hidden" name="button" value="yes" />
  386:     $hidden_input
  387:     <input type="submit" value="$lt{'yes'}" />
  388: </form>
  389: <form action="/adm/slotrequest" method="post">
  390:     <input type="hidden" name="command" value="showslots" />
  391:     <input type="submit" value="$lt{'no'}" />
  392: </form>
  393: END_CONFIRM
  394: 
  395: }
  396: 
  397: sub release_all_slot {
  398:     my ($r,$mgr)=@_;
  399:     
  400:     my $slot_name = $env{'form.slotname'};
  401: 
  402:     my ($cnum,$cdom)=&get_course();
  403: 
  404:     my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
  405: 				       "^$slot_name\0");
  406:     
  407:     $r->print('<p>'.&mt('Releasing reservations').'</p>');
  408: 
  409:     foreach my $entry (sort { $consumed{$a}{'name'} cmp 
  410: 				  $consumed{$b}{'name'} } (keys(%consumed))) {
  411: 	my ($uname,$udom) = split(':',$consumed{$entry}{'name'});
  412: 	my ($result,$msg) =
  413: 	    &release_reservation($slot_name,$uname,$udom,
  414: 				 $consumed{$entry}{'symb'},$mgr);
  415: 	$r->print("<p>$msg</p>");
  416: 	$r->rflush();
  417:     }
  418:     $r->print('<p><a href="/adm/slotrequest?command=showslots">'.
  419: 	      &mt('Return to slot list').'</a></p>');
  420:     &return_link($r);
  421: }
  422: 
  423: sub release_slot {
  424:     my ($r,$symb,$slot_name,$inhibit_return_link,$mgr)=@_;
  425: 
  426:     if ($slot_name eq '') { $slot_name=$env{'form.slotname'}; }
  427: 
  428:     my ($uname,$udom) = ($env{'user.name'}, $env{'user.domain'});
  429:     if ($mgr eq 'F' 
  430: 	&& defined($env{'form.uname'}) && defined($env{'form.udom'})) {
  431: 	($uname,$udom) = ($env{'form.uname'}, $env{'form.udom'});
  432:     }
  433: 
  434:     if ($mgr eq 'F' 
  435: 	&& defined($env{'form.symb'})) {
  436: 	$symb = &unescape($env{'form.symb'});
  437:     }
  438: 
  439:     my ($result,$msg) =
  440: 	&release_reservation($slot_name,$uname,$udom,$symb,$mgr);
  441:     $r->print("<p>$msg</p>");
  442:     
  443:     if ($mgr eq 'F') {
  444: 	$r->print('<p><a href="/adm/slotrequest?command=showslots">'.
  445: 		  &mt('Return to slot list').'</a></p>');
  446:     }
  447: 
  448:     if (!$inhibit_return_link) { &return_link($r);  }
  449:     return $result;
  450: }
  451: 
  452: sub release_reservation {
  453:     my ($slot_name,$uname,$udom,$symb,$mgr) = @_;
  454:     my %slot=&Apache::lonnet::get_slot($slot_name);
  455:     my $description=&get_description($slot_name,\%slot);
  456: 
  457:     if ($mgr ne 'F') {
  458: 	if ($slot{'starttime'} < time) {
  459: 	    return (0,&mt('Not allowed to release Reservation: [_1], as it has already ended.',$description));
  460: 	}
  461:     }
  462:     # get parameter string, check for existance, rebuild string with the slot
  463:     my @slots = split(/:/,&Apache::lonnet::EXT("resource.0.availablestudent",
  464: 					       $symb,$udom,$uname));
  465: 
  466:     my @new_slots;
  467:     foreach my $exist_slot (@slots) {
  468: 	if ($exist_slot eq $slot_name) { next; }
  469: 	push(@new_slots,$exist_slot);
  470:     }
  471:     my $new_param = join(':',@new_slots);
  472: 
  473:     my ($cnum,$cdom)=&get_course();
  474: 
  475:     # get slot reservations, check if user has one, if so remove reservation
  476:     my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
  477: 				       "^$slot_name\0");
  478:     foreach my $entry (keys(%consumed)) {
  479: 	if ( $consumed{$entry}->{'name'} eq ($uname.':'.$udom) ) {
  480: 	    &Apache::lonnet::del('slot_reservations',[$entry],
  481: 				 $cdom,$cnum);
  482: 	}
  483:     }
  484: 
  485:     my $use_slots = &Apache::lonnet::EXT("resource.0.useslots");
  486:     &Apache::lonxml::debug("use_slots is  $use_slots<br />");
  487: 
  488:     if (&Apache::lonnet::error($use_slots)) { 
  489: 	return (0,'error: Unable to determine current status');
  490:     }
  491: 
  492:     my $parm_level = 1;
  493:     if ($use_slots eq 'map' || $use_slots eq 'map_map') {
  494: 	$parm_level = 2;
  495:     }
  496:     # store new parameter string
  497:     my $result=&Apache::lonparmset::storeparm_by_symb($symb,
  498: 						      '0_availablestudent',
  499: 						      $parm_level, $new_param,
  500: 						      'string', $uname, $udom);
  501: 
  502:     my $msg;
  503:     if ($mgr eq 'F') {
  504: 	$msg = &mt('Released Reservation for user: [_1]',"$uname:$udom");
  505:     } else {
  506: 	$msg = &mt('Released Reservation: [_1]',$description);
  507:     }
  508:     return (1,$msg);
  509: }
  510: 
  511: sub delete_slot {
  512:     my ($r)=@_;
  513: 
  514:     my $slot_name = $env{'form.slotname'};
  515:     my %slot=&Apache::lonnet::get_slot($slot_name);
  516: 
  517:     my ($cnum,$cdom)=&get_course();
  518:     my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
  519: 				       "^$slot_name\0");
  520:     my ($tmp) = %consumed;
  521:     if ($tmp =~ /error: 2/) { undef(%consumed); }
  522: 
  523:     if (%slot && !%consumed) {
  524: 	$slot{'type'} = 'deleted';
  525: 	my $ret = &Apache::lonnet::cput('slots', {$slot_name => \%slot},
  526: 					$cdom, $cnum);
  527: 	if ($ret eq 'ok') {
  528: 	    $r->print("<p>Slot <tt>$slot_name</tt> marked as deleted.</p>");
  529: 	} else {
  530: 	    $r->print("<p> An error ($ret) occurse when attempting to delete Slot <tt>$slot_name</tt>.</p>");
  531: 	}
  532:     } else {
  533: 	if (%consumed) {
  534: 	    $r->print("<p>Slot <tt>$slot_name</tt> has active reservations.</p>");
  535: 	} else {
  536: 	    $r->print("<p>Slot <tt>$slot_name</tt> does not exist.</p>");
  537: 	}
  538:     }
  539:     $r->print('<p><a href="/adm/slotrequest?command=showslots">'.
  540: 	      &mt('Return to slot list').'</a></p>');
  541:     &return_link($r);
  542: }
  543: 
  544: sub return_link {
  545:     my ($r) = @_;
  546:     $r->print('<p><a href="/adm/flip?postdata=return:">'.
  547: 	      &mt('Return to last resource').'</a></p>');
  548: }
  549: 
  550: sub get_slot {
  551:     my ($r,$symb,$conflictable_slot,$inhibit_return_link)=@_;
  552: 
  553:     my %slot=&Apache::lonnet::get_slot($env{'form.slotname'});
  554:     my $slot_name=&check_for_conflict($symb,$env{'form.slotname'},\%slot);
  555: 
  556:     if ($slot_name =~ /^error: (.*)/) {
  557: 	$r->print("<p>An error occured while attempting to make a reservation. ($1)</p>");
  558: 	&return_link($r);
  559: 	return 0;
  560:     }
  561:     if ($slot_name && $slot_name ne $conflictable_slot) {
  562: 	my %slot=&Apache::lonnet::get_slot($slot_name);
  563: 	my $description1=&get_description($slot_name,\%slot);
  564: 	%slot=&Apache::lonnet::get_slot($env{'form.slotname'});
  565: 	my $description2=&get_description($env{'form.slotname'},\%slot);
  566: 	$r->print("<p>Already have a reservation: $description1</p>");
  567: 	if ($slot_name ne $env{'form.slotname'}) {
  568: 	    $r->print(<<STUFF);
  569: <form method="post" action="/adm/slotrequest">
  570:    <input type="hidden" name="symb" value="$env{'form.symb'}" />
  571:    <input type="hidden" name="slotname" value="$env{'form.slotname'}" />
  572:    <input type="hidden" name="releaseslot" value="$slot_name" />
  573:    <input type="hidden" name="command" value="change" />
  574: STUFF
  575:             $r->print("<p>You can either ");
  576: 	    $r->print(<<STUFF);
  577:    <input type="submit" name="change" value="Change" />
  578: STUFF
  579: 	    $r->print(' your reservation from <b>'.$description1.'</b> to <b>'.
  580: 		      $description2.
  581: 		      '</b> <br />or </p>');
  582: 	    &return_link($r);
  583: 	    $r->print(<<STUFF);
  584: </form>
  585: STUFF
  586:         } else {
  587: 	    &return_link($r);
  588: 	}
  589: 	return 0;
  590:     }
  591: 
  592:     my $reserved=&make_reservation($env{'form.slotname'},
  593: 				   \%slot,$symb);
  594:     my $description=&get_description($env{'form.slotname'},\%slot);
  595:     if (defined($reserved)) {
  596: 	my $retvalue = 0;
  597: 	if ($slot_name =~ /^error: (.*)/) {
  598: 	    $r->print("<p>An error occured while attempting to make a reservation. ($1)</p>");
  599: 	} elsif ($reserved > -1) {
  600: 	    $r->print("<p>Success: $description</p>");
  601: 	    $retvalue = 1;
  602: 	} elsif ($reserved < 0) {
  603: 	    $r->print("<p>Already reserved: $description</p>");
  604: 	}
  605: 	if (!$inhibit_return_link) { &return_link($r); }
  606: 	return 1;
  607:     }
  608: 
  609:     my %lt=('request'=>"Availibility list",
  610: 	    'try'    =>'Try again');
  611:     %lt=&Apache::lonlocal::texthash(%lt);
  612: 
  613:     my $extra_input;
  614:     if ($conflictable_slot) {
  615: 	$extra_input='<input type="hidden" name="releaseslot" value="'.$env{'form.slotname'}.'" />';
  616:     }
  617: 
  618:     $r->print(<<STUFF);
  619: <p> <font color="red">Failed</font> to reserve a spot for $description. </p>
  620: <p>
  621: <form method="post" action="/adm/slotrequest">
  622:    <input type="submit" name="Try Again" value="$lt{'try'}" />
  623:    <input type="hidden" name="symb" value="$env{'form.symb'}" />
  624:    <input type="hidden" name="slotname" value="$env{'form.slotname'}" />
  625:    <input type="hidden" name="command" value="$env{'form.command'}" />
  626:    $extra_input
  627: </form>
  628: ?
  629: </p>
  630: <p>
  631: or
  632: <form method="post" action="/adm/slotrequest">
  633:     <input type="hidden" name="symb" value="$env{'form.symb'}" />
  634:     <input type="submit" name="requestattempt" value="$lt{'request'}" />
  635: </form>
  636: </p>
  637: or
  638: STUFF
  639: 
  640:     if (!$inhibit_return_link) { &return_link($r); }
  641:     return 0;
  642: }
  643: 
  644: sub allowed_slot {
  645:     my ($slot_name,$slot,$symb,$slots,$consumed_uniqueperiods)=@_;
  646: 
  647:     #already started
  648:     if ($slot->{'starttime'} < time) {
  649: 	# all open slot to be schedulable
  650: 	return 0;
  651:     }
  652:     &Apache::lonxml::debug("$slot_name starttime good");
  653: 
  654:     #already ended
  655:     if ($slot->{'endtime'} < time) {
  656: 	return 0;
  657:     }
  658:     &Apache::lonxml::debug("$slot_name endtime good");
  659: 
  660:     # not allowed to pick this one
  661:     if (defined($slot->{'type'})
  662: 	&& $slot->{'type'} ne 'schedulable_student') {
  663: 	return 0;
  664:     }
  665:     &Apache::lonxml::debug("$slot_name type good");
  666: 
  667:     # reserve time not yet started
  668:     if ($slot->{'startreserve'} > time) {
  669: 	return 0;
  670:     }
  671:     &Apache::lonxml::debug("$slot_name reserve good");
  672: 
  673:     my $userallowed=0;
  674:     # its for a different set of users
  675:     if (defined($slot->{'allowedsections'})) {
  676: 	if (!defined($env{'request.role.sec'})
  677: 	    && grep(/^No section assigned$/,
  678: 		    split(',',$slot->{'allowedsections'}))) {
  679: 	    $userallowed=1;
  680: 	}
  681: 	if (defined($env{'request.role.sec'})
  682: 	    && grep(/^\Q$env{'request.role.sec'}\E$/,
  683: 		    split(',',$slot->{'allowedsections'}))) {
  684: 	    $userallowed=1;
  685: 	}
  686: 	if (defined($env{'request.course.groups'})) {
  687: 	    my @groups = split(/:/,$env{'request.course.groups'});
  688: 	    my @allowed_sec = split(',',$slot->{'allowedsections'});
  689: 	    foreach my $group (@groups) {
  690: 		if (grep {$_ eq $group} (@allowed_sec)) {
  691: 		    $userallowed=1;
  692: 		    last;
  693: 		}
  694: 	    }
  695: 	}
  696:     }
  697:     &Apache::lonxml::debug("$slot_name sections is $userallowed");
  698: 
  699:     # its for a different set of users
  700:     if (defined($slot->{'allowedusers'})
  701: 	&& grep(/^\Q$env{'user.name'}:$env{'user.domain'}\E$/,
  702: 		split(',',$slot->{'allowedusers'}))) {
  703: 	$userallowed=1;
  704:     }
  705: 
  706:     if (!defined($slot->{'allowedusers'})
  707: 	&& !defined($slot->{'allowedsections'})) {
  708: 	$userallowed=1;
  709:     }
  710: 
  711:     &Apache::lonxml::debug("$slot_name user is $userallowed");
  712:     return 0 if (!$userallowed);
  713: 
  714:     # not allowed for this resource
  715:     if (defined($slot->{'symb'})
  716: 	&& $slot->{'symb'} ne $symb) {
  717: 	return 0;
  718:     }
  719: 
  720:     my $conflict = &check_for_conflict($symb,$slot_name,$slot,$slots,
  721: 				       $consumed_uniqueperiods);
  722:     if ($conflict) {
  723: 	if ($slots->{$conflict}{'starttime'} < time) {
  724: 	    return 0;
  725: 	}
  726:     }
  727:     &Apache::lonxml::debug("$slot_name symb good");
  728:     return 1;
  729: }
  730: 
  731: sub get_description {
  732:     my ($slot_name,$slot)=@_;
  733:     my $description=$slot->{'description'};
  734:     if (!defined($description)) {
  735: 	$description=&mt('[_1] From [_2] to [_3]',$slot_name,
  736: 			 &Apache::lonlocal::locallocaltime($slot->{'starttime'}),
  737: 			 &Apache::lonlocal::locallocaltime($slot->{'endtime'}));
  738:     }
  739:     return $description;
  740: }
  741: 
  742: sub show_choices {
  743:     my ($r,$symb)=@_;
  744: 
  745:     my ($cnum,$cdom)=&get_course();
  746:     my %slots=&Apache::lonnet::dump('slots',$cdom,$cnum);
  747:     my $consumed_uniqueperiods = &get_consumed_uniqueperiods(\%slots);
  748:     my $available;
  749:     $r->print('<table border="1">');
  750:     &Apache::lonxml::debug("Checking Slots");
  751:     my @got_slots=&check_for_reservation($symb,'allslots');
  752:     foreach my $slot (sort 
  753: 		      { return $slots{$a}->{'starttime'} <=> $slots{$b}->{'starttime'} }
  754: 		      (keys(%slots)))  {
  755: 
  756: 	&Apache::lonxml::debug("Checking Slot $slot");
  757: 	next if (!&allowed_slot($slot,$slots{$slot},undef,\%slots,
  758: 				$consumed_uniqueperiods));
  759: 
  760: 	$available++;
  761: 
  762: 	my $description=&get_description($slot,$slots{$slot});
  763: 
  764: 	my $form=&mt('Unavailable');
  765: 	if ((grep(/^\Q$slot\E$/,@got_slots)) ||
  766: 	    &space_available($slot,$slots{$slot},$symb)) {
  767: 	    my $text=&mt('Select');
  768: 	    my $command='get';
  769: 	    if (grep(/^\Q$slot\E$/,@got_slots)) {
  770: 		$text=&mt('Drop Reservation');
  771: 		$command='release';
  772: 	    } else {
  773: 		my $conflict = &check_for_conflict($symb,$slot,$slots{$slot},
  774: 						   \%slots,
  775: 						   $consumed_uniqueperiods);
  776: 		if ($conflict) {
  777: 		    $text=&mt('Change Reservation');
  778: 		    $command='get';
  779: 		}
  780: 	    }
  781: 	    my $escsymb=&escape($symb);
  782: 	    $form=<<STUFF;
  783:    <form method="post" action="/adm/slotrequest">
  784:      <input type="submit" name="Select" value="$text" />
  785:      <input type="hidden" name="symb" value="$escsymb" />
  786:      <input type="hidden" name="slotname" value="$slot" />
  787:      <input type="hidden" name="command" value="$command" />
  788:    </form>
  789: STUFF
  790: 	}
  791: 	$r->print(<<STUFF);
  792: <tr>
  793:  <td>$form</td>
  794:  <td>$description</td>
  795: </tr>
  796: STUFF
  797:     }
  798: 
  799:     if (!$available) {
  800: 	$r->print('<tr><td>No available times. <a href="/adm/flip?postdata=return:">'.
  801: 		  &mt('Return to last resource').'</a></td></tr>');
  802:     }
  803:     $r->print('</table>');
  804: }
  805: 
  806: sub to_show {
  807:     my ($slotname,$slot,$when,$deleted,$name) = @_;
  808:     my $time=time;
  809:     my $week=60*60*24*7;
  810: 
  811:     if ($deleted eq 'hide' && $slot->{'type'} eq 'deleted') {
  812: 	return 0;
  813:     }
  814: 
  815:     if ($name && $name->{'value'} =~ /\w/) {
  816: 	if ($name->{'type'} eq 'substring') {
  817: 	    if ($slotname !~ /\Q$name->{'value'}\E/) {
  818: 		return 0;
  819: 	    }
  820: 	}
  821: 	if ($name->{'type'} eq 'exact') {
  822: 	    if ($slotname eq $name->{'value'}) {
  823: 		return 0;
  824: 	    }
  825: 	}
  826:     }
  827: 
  828:     if ($when eq 'any') {
  829: 	return 1;
  830:     } elsif ($when eq 'now') {
  831: 	if ($time > $slot->{'starttime'} &&
  832: 	    $time < $slot->{'endtime'}) {
  833: 	    return 1;
  834: 	}
  835: 	return 0;
  836:     } elsif ($when eq 'nextweek') {
  837: 	if ( ($time        < $slot->{'starttime'} &&
  838: 	      ($time+$week) > $slot->{'starttime'})
  839: 	     ||
  840: 	     ($time        < $slot->{'endtime'} &&
  841: 	      ($time+$week) > $slot->{'endtime'}) ) {
  842: 	    return 1;
  843: 	}
  844: 	return 0;
  845:     } elsif ($when eq 'lastweek') {
  846: 	if ( ($time        > $slot->{'starttime'} &&
  847: 	      ($time-$week) < $slot->{'starttime'})
  848: 	     ||
  849: 	     ($time        > $slot->{'endtime'} &&
  850: 	      ($time-$week) < $slot->{'endtime'}) ) {
  851: 	    return 1;
  852: 	}
  853: 	return 0;
  854:     } elsif ($when eq 'willopen') {
  855: 	if ($time < $slot->{'starttime'}) {
  856: 	    return 1;
  857: 	}
  858: 	return 0;
  859:     } elsif ($when eq 'wereopen') {
  860: 	if ($time > $slot->{'endtime'}) {
  861: 	    return 1;
  862: 	}
  863: 	return 0;
  864:     }
  865:     
  866:     return 1;
  867: }
  868: 
  869: sub remove_link {
  870:     my ($slotname,$entry,$uname,$udom,$symb) = @_;
  871: 
  872:     my $remove = &mt('Remove');
  873: 
  874:     if ($entry eq 'remove all') {
  875: 	$remove = &mt('Remove All');
  876: 	undef($uname);
  877: 	undef($udom);
  878:     }
  879: 
  880:     $slotname  = &escape($slotname);
  881:     $entry     = &escape($entry);
  882:     $uname     = &escape($uname);
  883:     $udom      = &escape($udom);
  884:     $symb      = &escape($symb);
  885: 
  886:     return <<"END_LINK";
  887:  <a href="/adm/slotrequest?command=remove_registration&amp;slotname=$slotname&amp;entry=$entry&amp;uname=$uname&amp;udom=$udom&amp;symb=$symb"
  888:    >($remove)</a>
  889: END_LINK
  890: 
  891: }
  892: 
  893: sub show_table {
  894:     my ($r,$mgr)=@_;
  895: 
  896:     my ($cnum,$cdom)=&get_course();
  897:     my %slots=&Apache::lonnet::dump('slots',$cdom,$cnum);
  898:     if ( (keys(%slots))[0] =~ /^error: 2 /) {
  899: 	undef(%slots);
  900:     } 
  901:     my $available;
  902:     if ($mgr eq 'F') {
  903:     # FIXME: This line should be deleted once Slots uses breadcrumbs
  904:     $r->print(&Apache::loncommon::help_open_topic('Slot About', 'Help on slots'));
  905: 
  906: 	$r->print('<div>');
  907: 	$r->print('<form method="post" action="/adm/slotrequest">
  908: <input type="hidden" name="command" value="uploadstart" />
  909: <input type="submit" name="start" value="'.&mt('Upload Slot List').'" />
  910: </form>');
  911: 	$r->print(&Apache::loncommon::help_open_topic('Slot CommaDelimited'));
  912: 	$r->print('<form method="post" action="/adm/helper/newslot.helper">
  913: <input type="submit" name="newslot" value="'.&mt('Create a New Slot').'" />
  914: </form>');
  915: 	$r->print(&Apache::loncommon::help_open_topic('Slot AddInterface'));
  916: 	$r->print('</div>');
  917:     }
  918:     
  919:     my %Saveable_Parameters = ('show'              => 'array',
  920: 			       'when'              => 'scalar',
  921: 			       'order'             => 'scalar',
  922: 			       'deleted'           => 'scalar',
  923: 			       'name_filter_type'  => 'scalar',
  924: 			       'name_filter_value' => 'scalar',
  925: 			       );
  926:     &Apache::loncommon::store_course_settings('slotrequest',
  927: 					      \%Saveable_Parameters);
  928:     &Apache::loncommon::restore_course_settings('slotrequest',
  929: 						\%Saveable_Parameters);
  930:     &Apache::grades::init_perm();
  931:     my ($classlist,$section,$fullname)=&Apache::grades::getclasslist('all');
  932:     &Apache::grades::reset_perm();
  933: 
  934:     # what to display filtering
  935:     my %show_fields=&Apache::lonlocal::texthash(
  936: 	     'name'            => 'Slot Name',
  937: 	     'description'     => 'Description',
  938: 	     'type'            => 'Type',
  939: 	     'starttime'       => 'Start time',
  940: 	     'endtime'         => 'End Time',
  941:              'startreserve'    => 'Time students can start reserving',
  942: 	     'secret'          => 'Secret Word',
  943: 	     'space'           => '# of students/max',
  944: 	     'ip'              => 'IP or DNS restrictions',
  945: 	     'symb'            => 'Resource slot is restricted to.',
  946: 	     'allowedsections' => 'Sections slot is restricted to.',
  947: 	     'allowedusers'    => 'Users slot is restricted to.',
  948: 	     'uniqueperiod'    => 'Period of time slot is unique',
  949: 	     'scheduled'       => 'Scheduled Students',
  950: 	     'proctor'         => 'List of proctors');
  951:     my @show_order=('name','description','type','starttime','endtime',
  952: 		    'startreserve','secret','space','ip','symb',
  953: 		    'allowedsections','allowedusers','uniqueperiod',
  954: 		    'scheduled','proctor');
  955:     my @show = 
  956: 	(exists($env{'form.show'})) ? &Apache::loncommon::get_env_multiple('form.show')
  957: 	                            : keys(%show_fields);
  958:     my %show =  map { $_ => 1 } (@show);
  959: 
  960:     #when filtering setup
  961:     my %when_fields=&Apache::lonlocal::texthash(
  962: 	     'now'      => 'Open now',
  963: 	     'nextweek' => 'Open within the next week',
  964: 	     'lastweek' => 'Were open last week',
  965: 	     'willopen' => 'Will open later',
  966: 	     'wereopen' => 'Were open',
  967: 	     'any'      => 'Anytime',
  968: 						);
  969:     my @when_order=('any','now','nextweek','lastweek','willopen','wereopen');
  970:     $when_fields{'select_form_order'} = \@when_order;
  971:     my $when = 	(exists($env{'form.when'})) ? $env{'form.when'}
  972:                                             : 'now';
  973: 
  974:     #display of students setup
  975:     my %stu_display_fields=
  976: 	&Apache::lonlocal::texthash('username' => 'User name',
  977: 				    'fullname' => 'Full name',
  978: 				    );
  979:     my @stu_display_order=('fullname','username');
  980:     my @stu_display = 
  981: 	(exists($env{'form.studisplay'})) ? &Apache::loncommon::get_env_multiple('form.studisplay')
  982: 	                                  : keys(%stu_display_fields);
  983:     my %stu_display =  map { $_ => 1 } (@stu_display);
  984: 
  985:     #name filtering setup
  986:     my %name_filter_type_fields=
  987: 	&Apache::lonlocal::texthash('substring' => 'Substring',
  988: 				    'exact'     => 'Exact',
  989: 				    #'reg'       => 'Regular Expression',
  990: 				    );
  991:     my @name_filter_type_order=('substring','exact');
  992: 
  993:     $name_filter_type_fields{'select_form_order'} = \@name_filter_type_order;
  994:     my $name_filter_type = 
  995: 	(exists($env{'form.name_filter_type'})) ? $env{'form.name_filter_type'}
  996:                                                 : 'substring';
  997:     my $name_filter = {'type'  => $name_filter_type,
  998: 		       'value' => $env{'form.name_filter_value'},};
  999: 
 1000:     
 1001:     #deleted slot filtering
 1002:     #default to hide if no value
 1003:     $env{'form.deleted'} ||= 'hide';
 1004:     my $hide_radio = 
 1005: 	&Apache::lonhtmlcommon::radio('deleted',$env{'form.deleted'},'hide');
 1006:     my $show_radio = 
 1007: 	&Apache::lonhtmlcommon::radio('deleted',$env{'form.deleted'},'show');
 1008: 	
 1009:     $r->print('<form method="post" action="/adm/slotrequest">
 1010: <input type="hidden" name="command" value="showslots" />');
 1011:     $r->print('<div>');
 1012:     $r->print('<table class="inline">
 1013:       <tr><th>'.&mt('Show').'</th>
 1014:           <th>'.&mt('Student Display').'</th>
 1015:           <th>'.&mt('Open').'</th>
 1016:           <th>'.&mt('Slot Name Filter').'</th>
 1017:           <th>'.&mt('Options').'</th>
 1018:       </tr>
 1019:       <tr><td>'.&Apache::loncommon::multiple_select_form('show',\@show,6,\%show_fields,\@show_order).
 1020: 	      '</td>
 1021:            <td>
 1022:          '.&Apache::loncommon::multiple_select_form('studisplay',\@stu_display,
 1023: 						    6,\%stu_display_fields,
 1024: 						    \@stu_display_order).'
 1025:            </td>
 1026:            <td>'.&Apache::loncommon::select_form($when,'when',%when_fields).
 1027:           '</td>
 1028:            <td>'.&Apache::loncommon::select_form($name_filter_type,
 1029: 						 'name_filter_type',
 1030: 						 %name_filter_type_fields).
 1031: 	      '<br />'.
 1032: 	      &Apache::lonhtmlcommon::textbox('name_filter_value',
 1033: 					      $env{'form.name_filter_value'},
 1034: 					      15).
 1035:           '</td>
 1036:            <td>
 1037:             <table>
 1038:               <tr>
 1039:                 <td rowspan="2">Deleted slots:</td>
 1040:                 <td><label>'.$show_radio.'Show</label></td>
 1041:               </tr>
 1042:               <tr>
 1043:                 <td><label>'.$hide_radio.'Hide</label></td>
 1044:               </tr>
 1045:             </table>
 1046: 	  </td>
 1047:        </tr>
 1048:     </table>');
 1049:     $r->print('</div>');
 1050:     $r->print('<p><input type="submit" name="start" value="'.&mt('Update Display').'" /></p>');
 1051:     my $linkstart='<a href="/adm/slotrequest?command=showslots&amp;order=';
 1052:     $r->print(&Apache::loncommon::start_data_table().
 1053: 	      &Apache::loncommon::start_data_table_header_row().'
 1054: 	       <th></th>');
 1055:     foreach my $which (@show_order) {
 1056: 	if ($which ne 'proctor' && exists($show{$which})) {
 1057: 	    $r->print('<th>'.$linkstart.$which.'">'.$show_fields{$which}.'</a></th>');
 1058: 	}
 1059:     }
 1060:     $r->print(&Apache::loncommon::end_data_table_header_row());
 1061: 
 1062:     my %name_cache;
 1063:     my $slotsort = sub {
 1064: 	if ($env{'form.order'}=~/^(type|description|endtime|startreserve|ip|symb|allowedsections|allowedusers)$/) {
 1065: 	    if (lc($slots{$a}->{$env{'form.order'}})
 1066: 		ne lc($slots{$b}->{$env{'form.order'}})) {
 1067: 		return (lc($slots{$a}->{$env{'form.order'}}) 
 1068: 			cmp lc($slots{$b}->{$env{'form.order'}}));
 1069: 	    }
 1070: 	} elsif ($env{'form.order'} eq 'space') {
 1071: 	    if ($slots{$a}{'maxspace'} ne $slots{$b}{'maxspace'}) {
 1072: 		return ($slots{$a}{'maxspace'} cmp $slots{$b}{'maxspace'});
 1073: 	    }
 1074: 	} elsif ($env{'form.order'} eq 'name') {
 1075: 	    if (lc($a) cmp lc($b)) {
 1076: 		return lc($a) cmp lc($b);
 1077: 	    }
 1078: 	} elsif ($env{'form.order'} eq 'uniqueperiod') {
 1079: 	    
 1080: 	    if ($slots{$a}->{'uniqueperiod'}[0] 
 1081: 		ne $slots{$b}->{'uniqueperiod'}[0]) {
 1082: 		return ($slots{$a}->{'uniqueperiod'}[0]
 1083: 			cmp $slots{$b}->{'uniqueperiod'}[0]);
 1084: 	    }
 1085: 	    if ($slots{$a}->{'uniqueperiod'}[1] 
 1086: 		ne $slots{$b}->{'uniqueperiod'}[1]) {
 1087: 		return ($slots{$a}->{'uniqueperiod'}[1]
 1088: 			cmp $slots{$b}->{'uniqueperiod'}[1]);
 1089: 	    }
 1090: 	}
 1091: 	return $slots{$a}->{'starttime'} <=> $slots{$b}->{'starttime'};
 1092:     };
 1093: 
 1094:     my %consumed;
 1095:     if (exists($show{'scheduled'}) || exists($show{'space'}) ) {
 1096: 	%consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum);
 1097: 	my ($tmp)=%consumed;
 1098: 	if ($tmp =~ /^error: /) { undef(%consumed); }
 1099:     }
 1100: 
 1101:     foreach my $slot (sort $slotsort (keys(%slots)))  {
 1102: 	if (!&to_show($slot,$slots{$slot},$when,
 1103: 		      $env{'form.deleted'},$name_filter)) { next; }
 1104: 	if (defined($slots{$slot}->{'type'})
 1105: 	    && $slots{$slot}->{'type'} ne 'schedulable_student') {
 1106: 	    #next;
 1107: 	}
 1108: 	my $description=&get_description($slot,$slots{$slot});
 1109: 	my ($id_count,$ids);
 1110: 	    
 1111: 	if (exists($show{'scheduled'}) || exists($show{'space'}) ) {
 1112: 	    my @this_slot = grep(/^$slot\0/,keys(%consumed));
 1113: 	    $id_count = scalar(@this_slot);
 1114: 	    if (exists($show{'scheduled'})) {
 1115: 		foreach my $entry (sort { $consumed{$a}{name} cmp 
 1116: 					      $consumed{$b}{name} }
 1117: 				   (keys(%consumed))) {
 1118: 		    my (undef,$id)=split("\0",$entry);
 1119: 		    my ($uname,$udom) = split(':',$consumed{$entry}{'name'});
 1120: 		    $ids.= '<nobr>';
 1121: 		    foreach my $item (@stu_display_order) {
 1122: 			if ($stu_display{$item}) {
 1123: 			    if ($item eq 'fullname') {
 1124: 				$ids.=$fullname->{"$uname:$udom"}.' ';
 1125: 			    } elsif ($item eq 'username') {
 1126: 				$ids.="<tt>$uname:$udom</tt> ";
 1127: 			    }
 1128: 			}
 1129: 		    }
 1130: 		    $ids.=&remove_link($slot,$entry,$uname,$udom,
 1131: 				       $consumed{$entry}{'symb'}).'</nobr><br />';
 1132: 		}
 1133: 	    }
 1134: 	}
 1135: 
 1136: 	my $start=($slots{$slot}->{'starttime'}?
 1137: 		   &Apache::lonlocal::locallocaltime($slots{$slot}->{'starttime'}):'');
 1138: 	my $end=($slots{$slot}->{'endtime'}?
 1139: 		 &Apache::lonlocal::locallocaltime($slots{$slot}->{'endtime'}):'');
 1140: 	my $start_reserve=($slots{$slot}->{'startreserve'}?
 1141: 			   &Apache::lonlocal::locallocaltime($slots{$slot}->{'startreserve'}):'');
 1142: 	
 1143: 	my $unique;
 1144: 	if (ref($slots{$slot}{'uniqueperiod'})) {
 1145: 	    $unique=localtime($slots{$slot}{'uniqueperiod'}[0]).', '.
 1146: 		localtime($slots{$slot}{'uniqueperiod'}[1]);
 1147: 	}
 1148: 
 1149: 	my $title;
 1150: 	if (exists($slots{$slot}{'symb'})) {
 1151: 	    my (undef,undef,$res)=
 1152: 		&Apache::lonnet::decode_symb($slots{$slot}{'symb'});
 1153: 	    $res =   &Apache::lonnet::clutter($res);
 1154: 	    $title = &Apache::lonnet::gettitle($slots{$slot}{'symb'});
 1155: 	    $title='<a href="'.$res.'?symb='.$slots{$slot}{'symb'}.'">'.$title.'</a>';
 1156: 	}
 1157: 
 1158: 	my $allowedsections;
 1159: 	if (exists($show{'allowedsections'})) {
 1160: 	    $allowedsections = 
 1161: 		join(', ',sort(split(/\s*,\s*/,
 1162: 				     $slots{$slot}->{'allowedsections'})));
 1163: 	}
 1164: 
 1165: 	my @allowedusers;
 1166: 	if (exists($show{'allowedusers'})) {
 1167: 	    @allowedusers= map {
 1168: 		my ($uname,$udom)=split(/:/,$_);
 1169: 		my $fullname=$name_cache{$_};
 1170: 		if (!defined($fullname)) {
 1171: 		    $fullname = &Apache::loncommon::plainname($uname,$udom);
 1172: 		    $fullname =~s/\s/&nbsp;/g;
 1173: 		    $name_cache{$_} = $fullname;
 1174: 		}
 1175: 		&Apache::loncommon::aboutmewrapper($fullname,$uname,$udom);
 1176: 	    } (sort(split(/\s*,\s*/,$slots{$slot}->{'allowedusers'})));
 1177: 	}
 1178: 	my $allowedusers=join(', ',@allowedusers);
 1179: 	
 1180: 	my @proctors;
 1181: 	my $rowspan=1;
 1182: 	my $colspan=1;
 1183: 	if (exists($show{'proctor'})) {
 1184: 	    $rowspan=2;
 1185: 	    @proctors= map {
 1186: 		my ($uname,$udom)=split(/:/,$_);
 1187: 		my $fullname=$name_cache{$_};
 1188: 		if (!defined($fullname)) {
 1189: 		    $fullname = &Apache::loncommon::plainname($uname,$udom);
 1190: 		    $fullname =~s/\s/&nbsp;/g;
 1191: 		    $name_cache{$_} = $fullname;
 1192: 		}
 1193: 		&Apache::loncommon::aboutmewrapper($fullname,$uname,$udom);
 1194: 	    } (sort(split(/\s*,\s*/,$slots{$slot}->{'proctor'})));
 1195: 	}
 1196: 	my $proctors=join(', ',@proctors);
 1197: 
 1198: 	my $edit=(<<"EDITLINK");
 1199: <a href="/adm/helper/newslot.helper?name=$slot">Edit</a>
 1200: EDITLINK
 1201: 
 1202: 	my $delete=(<<"DELETELINK");
 1203: <a href="/adm/slotrequest?command=delete&amp;slotname=$slot">Delete</a>
 1204: DELETELINK
 1205: 
 1206:         my $remove_all=&remove_link($slot,'remove all').'<br />';
 1207: 
 1208:         if ($ids ne '') { undef($delete); }
 1209: 	if ($slots{$slot}{'type'} ne 'schedulable_student' 
 1210: 	    || $ids eq '') { 
 1211: 	    undef($remove_all);
 1212: 	}
 1213: 
 1214: 	my $row_start=&Apache::loncommon::start_data_table_row();
 1215: 	my $row_end=&Apache::loncommon::end_data_table_row();
 1216:         $r->print($row_start.
 1217: 		  "\n<td rowspan=\"$rowspan\">$edit $delete</td>\n");
 1218: 	if (exists($show{'name'})) {
 1219: 	    $colspan++;$r->print("<td>$slot</td>");
 1220: 	}
 1221: 	if (exists($show{'description'})) {
 1222: 	    $colspan++;$r->print("<td>$description</td>\n");
 1223: 	}
 1224: 	if (exists($show{'type'})) {
 1225: 	    $colspan++;$r->print("<td>$slots{$slot}->{'type'}</td>\n");
 1226: 	}
 1227: 	if (exists($show{'starttime'})) {
 1228: 	    $colspan++;$r->print("<td>$start</td>\n");
 1229: 	}
 1230: 	if (exists($show{'endtime'})) {
 1231: 	    $colspan++;$r->print("<td>$end</td>\n");
 1232: 	}
 1233: 	if (exists($show{'startreserve'})) {
 1234: 	    $colspan++;$r->print("<td>$start_reserve</td>\n");
 1235: 	}
 1236: 	if (exists($show{'secret'})) {
 1237: 	    $colspan++;$r->print("<td>$slots{$slot}{'secret'}</td>\n");
 1238: 	}
 1239: 	if (exists($show{'space'})) {
 1240: 	    my $display = $id_count;
 1241: 	    if ($slots{$slot}{'maxspace'}>0) {
 1242: 		$display.='/'.$slots{$slot}{'maxspace'};
 1243: 		if ($slots{$slot}{'maxspace'} <= $id_count) {
 1244: 		    $display = '<strong>'.$display.' (full) </strong>';
 1245: 		}
 1246: 	    }
 1247: 	    $colspan++;$r->print("<td>$display</td>\n");
 1248: 	}
 1249: 	if (exists($show{'ip'})) {
 1250: 	    $colspan++;$r->print("<td>$slots{$slot}{'ip'}</td>\n");
 1251: 	}
 1252: 	if (exists($show{'symb'})) {
 1253: 	    $colspan++;$r->print("<td>$title</td>\n");
 1254: 	}
 1255: 	if (exists($show{'allowedsections'})) {
 1256: 	    $colspan++;$r->print("<td>$allowedsections</td>\n");
 1257: 	}
 1258: 	if (exists($show{'allowedusers'})) {
 1259: 	    $colspan++;$r->print("<td>$allowedusers</td>\n");
 1260: 	}
 1261: 	if (exists($show{'uniqueperiod'})) {
 1262: 	    $colspan++;$r->print("<td>$unique</td>\n");
 1263: 	}
 1264: 	if (exists($show{'scheduled'})) {
 1265: 	    $colspan++;$r->print("<td>$remove_all $ids</td>\n");
 1266: 	}
 1267: 	$r->print("$row_end\n");
 1268: 	if (exists($show{'proctor'})) {
 1269: 	    $r->print(<<STUFF);
 1270: $row_start
 1271:  <td colspan="$colspan">$proctors</td>
 1272: $row_end
 1273: STUFF
 1274:         }
 1275:     }
 1276:     $r->print('</table></form>');
 1277: }
 1278: 
 1279: sub upload_start {
 1280:     my ($r)=@_;    
 1281:     $r->print(&Apache::grades::checkforfile_js());
 1282:     my $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
 1283:     $result.='&nbsp;<b>'.
 1284: 	&mt('Specify a file containing the slot definitions.').
 1285: 	'</b></td></tr>'."\n";
 1286:     $result.='<tr bgcolor=#ffffe6><td>'."\n";
 1287:     my $upfile_select=&Apache::loncommon::upfile_select_html();
 1288:     my $ignore=&mt('Ignore First Line');
 1289:     $result.=<<ENDUPFORM;
 1290: <form method="post" enctype="multipart/form-data" action="/adm/slotrequest" name="slotupload">
 1291: <input type="hidden" name="command" value="csvuploadmap" />
 1292: $upfile_select
 1293: <br /><input type="button" onClick="javascript:checkUpload(this.form);" value="Upload Data" />
 1294: <label><input type="checkbox" name="noFirstLine" />$ignore</label>
 1295: </form>
 1296: ENDUPFORM
 1297:     $result.='</td></tr></table>'."\n";
 1298:     $result.='</td></tr></table>'."\n";
 1299:     $r->print($result);
 1300: }
 1301: 
 1302: sub csvuploadmap_header {
 1303:     my ($r,$datatoken,$distotal)= @_;
 1304:     my $javascript;
 1305:     if ($env{'form.upfile_associate'} eq 'reverse') {
 1306: 	$javascript=&csvupload_javascript_reverse_associate();
 1307:     } else {
 1308: 	$javascript=&csvupload_javascript_forward_associate();
 1309:     }
 1310: 
 1311:     my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
 1312:     my $ignore=&mt('Ignore First Line');
 1313: 	my $help_field = &Apache::loncommon::help_open_topic('Slot SelectingField');
 1314: 
 1315:     $r->print(<<ENDPICK);
 1316: <form method="post" enctype="multipart/form-data" action="/adm/slotrequest" name="slotupload">
 1317: <h3>Identify fields $help_field</h3>	
 1318: Total number of records found in file: $distotal <hr />
 1319: Enter as many fields as you can. The system will inform you and bring you back
 1320: to this page if the data selected is insufficient to create the slots.<hr />
 1321: <input type="button" value="Reverse Association" onClick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
 1322: <label><input type="checkbox" name="noFirstLine" $checked />$ignore</label>
 1323: <input type="hidden" name="associate"  value="" />
 1324: <input type="hidden" name="datatoken"  value="$datatoken" />
 1325: <input type="hidden" name="fileupload" value="$env{'form.fileupload'}" />
 1326: <input type="hidden" name="upfiletype" value="$env{'form.upfiletype'}" />
 1327: <input type="hidden" name="upfile_associate" 
 1328:                                        value="$env{'form.upfile_associate'}" />
 1329: <input type="hidden" name="command"    value="csvuploadassign" />
 1330: <hr />
 1331: <script type="text/javascript" language="Javascript">
 1332: $javascript
 1333: </script>
 1334: ENDPICK
 1335:     return '';
 1336: 
 1337: }
 1338: 
 1339: sub csvuploadmap_footer {
 1340:     my ($request,$i,$keyfields) =@_;
 1341:     $request->print(<<ENDPICK);
 1342: </table>
 1343: <input type="hidden" name="nfields" value="$i" />
 1344: <input type="hidden" name="keyfields" value="$keyfields" />
 1345: <input type="button" onClick="javascript:verify(this.form)" value="Create Slots" /><br />
 1346: </form>
 1347: ENDPICK
 1348: }
 1349: 
 1350: sub csvupload_javascript_reverse_associate {
 1351:     my $error1=&mt('You need to specify the name, starttime, endtime and a type');
 1352:     return(<<ENDPICK);
 1353:   function verify(vf) {
 1354:     var foundstart=0;
 1355:     var foundend=0;
 1356:     var foundname=0;
 1357:     var foundtype=0;
 1358:     for (i=0;i<=vf.nfields.value;i++) {
 1359:       tw=eval('vf.f'+i+'.selectedIndex');
 1360:       if (i==0 && tw!=0) { foundname=1; }
 1361:       if (i==1 && tw!=0) { foundtype=1; }
 1362:       if (i==2 && tw!=0) { foundstat=1; }
 1363:       if (i==3 && tw!=0) { foundend=1; }
 1364:     }
 1365:     if (foundstart==0 && foundend==0 && foundtype==0 && foundname==0) {
 1366: 	alert('$error1');
 1367: 	return;
 1368:     }
 1369:     vf.submit();
 1370:   }
 1371:   function flip(vf,tf) {
 1372:   }
 1373: ENDPICK
 1374: }
 1375: 
 1376: sub csvupload_javascript_forward_associate {
 1377:     my $error1=&mt('You need to specify the name, starttime, endtime and a type');
 1378:   return(<<ENDPICK);
 1379:   function verify(vf) {
 1380:     var foundstart=0;
 1381:     var foundend=0;
 1382:     var foundname=0;
 1383:     var foundtype=0;
 1384:     for (i=0;i<=vf.nfields.value;i++) {
 1385:       tw=eval('vf.f'+i+'.selectedIndex');
 1386:       if (tw==1) { foundname=1; }
 1387:       if (tw==2) { foundtype=1; }
 1388:       if (tw==3) { foundstat=1; }
 1389:       if (tw==4) { foundend=1; }
 1390:     }
 1391:     if (foundstart==0 && foundend==0 && foundtype==0 && foundname==0) {
 1392: 	alert('$error1');
 1393: 	return;
 1394:     }
 1395:     vf.submit();
 1396:   }
 1397:   function flip(vf,tf) {
 1398:   }
 1399: ENDPICK
 1400: }
 1401: 
 1402: sub csv_upload_map {
 1403:     my ($r)= @_;
 1404: 
 1405:     my $datatoken;
 1406:     if (!$env{'form.datatoken'}) {
 1407: 	$datatoken=&Apache::loncommon::upfile_store($r);
 1408:     } else {
 1409: 	$datatoken=$env{'form.datatoken'};
 1410: 	&Apache::loncommon::load_tmp_file($r);
 1411:     }
 1412:     my @records=&Apache::loncommon::upfile_record_sep();
 1413:     if ($env{'form.noFirstLine'}) { shift(@records); }
 1414:     &csvuploadmap_header($r,$datatoken,$#records+1);
 1415:     my ($i,$keyfields);
 1416:     if (@records) {
 1417: 	my @fields=&csvupload_fields();
 1418: 
 1419: 	if ($env{'form.upfile_associate'} eq 'reverse') {	
 1420: 	    &Apache::loncommon::csv_print_samples($r,\@records);
 1421: 	    $i=&Apache::loncommon::csv_print_select_table($r,\@records,
 1422: 							  \@fields);
 1423: 	    foreach (@fields) { $keyfields.=$_->[0].','; }
 1424: 	    chop($keyfields);
 1425: 	} else {
 1426: 	    unshift(@fields,['none','']);
 1427: 	    $i=&Apache::loncommon::csv_samples_select_table($r,\@records,
 1428: 							    \@fields);
 1429: 	    my %sone=&Apache::loncommon::record_sep($records[0]);
 1430: 	    $keyfields=join(',',sort(keys(%sone)));
 1431: 	}
 1432:     }
 1433:     &csvuploadmap_footer($r,$i,$keyfields);
 1434: 
 1435:     return '';
 1436: }
 1437: 
 1438: sub csvupload_fields {
 1439:     return (['name','Slot name'],
 1440: 	    ['type','Type of slot'],
 1441: 	    ['starttime','Start Time of slot'],
 1442: 	    ['endtime','End Time of slot'],
 1443: 	    ['startreserve','Reservation Start Time'],
 1444: 	    ['ip','IP or DNS restriction'],
 1445: 	    ['proctor','List of proctor ids'],
 1446: 	    ['description','Slot Description'],
 1447: 	    ['maxspace','Maximum number of reservations'],
 1448: 	    ['symb','Resource Restriction'],
 1449: 	    ['uniqueperiod','Date range of slot exclusion'],
 1450: 	    ['secret','Secret word proctor uses to validate'],
 1451: 	    ['allowedsections','Sections slot is restricted to'],
 1452: 	    ['allowedusers','Users slot is restricted to'],
 1453: 	    );
 1454: }
 1455: 
 1456: sub csv_upload_assign {
 1457:     my ($r,$mgr)= @_;
 1458:     &Apache::loncommon::load_tmp_file($r);
 1459:     my @slotdata = &Apache::loncommon::upfile_record_sep();
 1460:     if ($env{'form.noFirstLine'}) { shift(@slotdata); }
 1461:     my %fields=&Apache::grades::get_fields();
 1462:     $r->print('<h3>Creating Slots</h3>');
 1463:     my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
 1464:     my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
 1465:     my $countdone=0;
 1466:     my @errors;
 1467:     foreach my $slot (@slotdata) {
 1468: 	my %slot;
 1469: 	my %entries=&Apache::loncommon::record_sep($slot);
 1470: 	my $domain;
 1471: 	my $name=$entries{$fields{'name'}};
 1472: 	if ($name=~/^\s*$/) {
 1473: 	    push(@errors,"Did not create slot with no name");
 1474: 	    next;
 1475: 	}
 1476: 	if ($name=~/\s/) { 
 1477: 	    push(@errors,"$name not created -- Name must not contain spaces");
 1478: 	    next;
 1479: 	}
 1480: 	if ($name=~/\W/) { 
 1481: 	    push(@errors,"$name not created -- Name must contain only letters, numbers and _");
 1482: 	    next;
 1483: 	}
 1484: 	if ($entries{$fields{'type'}}) {
 1485: 	    $slot{'type'}=$entries{$fields{'type'}};
 1486: 	} else {
 1487: 	    $slot{'type'}='preassigned';
 1488: 	}
 1489: 	if ($slot{'type'} ne 'preassigned' &&
 1490: 	    $slot{'type'} ne 'schedulable_student') {
 1491: 	    push(@errors,"$name not created -- invalid type ($slot{'type'}) must be either preassigned or schedulable_student");
 1492: 	    next;
 1493: 	}
 1494: 	if ($entries{$fields{'starttime'}}) {
 1495: 	    $slot{'starttime'}=&UnixDate($entries{$fields{'starttime'}},"%s");
 1496: 	}
 1497: 	if ($entries{$fields{'endtime'}}) {
 1498: 	    $slot{'endtime'}=&UnixDate($entries{$fields{'endtime'}},"%s");
 1499: 	}
 1500: 
 1501: 	# start/endtime must be defined and greater than zero
 1502: 	if (!$slot{'starttime'}) {
 1503: 	    push(@errors,"$name not created -- Invalid start time");
 1504: 	    next;
 1505: 	}
 1506: 	if (!$slot{'endtime'}) {
 1507: 	    push(@errors,"$name not created -- Invalid end time");
 1508: 	    next;
 1509: 	}
 1510: 	if ($slot{'starttime'} > $slot{'endtime'}) {
 1511: 	    push(@errors,"$name not created -- Slot starts after it ends");
 1512: 	    next;
 1513: 	}
 1514: 
 1515: 	if ($entries{$fields{'startreserve'}}) {
 1516: 	    $slot{'startreserve'}=
 1517: 		&UnixDate($entries{$fields{'startreserve'}},"%s");
 1518: 	}
 1519: 	if (defined($slot{'startreserve'})
 1520: 	    && $slot{'startreserve'} > $slot{'starttime'}) {
 1521: 	    push(@errors,"$name not created -- Slot's reservation start time is after the slot's start time.");
 1522: 	    next;
 1523: 	}
 1524: 
 1525: 	foreach my $key ('ip','proctor','description','maxspace',
 1526: 			 'secret','symb') {
 1527: 	    if ($entries{$fields{$key}}) {
 1528: 		$slot{$key}=$entries{$fields{$key}};
 1529: 	    }
 1530: 	}
 1531: 
 1532: 	if ($entries{$fields{'uniqueperiod'}}) {
 1533: 	    my ($start,$end)=split(',',$entries{$fields{'uniqueperiod'}});
 1534: 	    my @times=(&UnixDate($start,"%s"),
 1535: 		       &UnixDate($end,"%s"));
 1536: 	    $slot{'uniqueperiod'}=\@times;
 1537: 	}
 1538: 	if (defined($slot{'uniqueperiod'})
 1539: 	    && $slot{'uniqueperiod'}[0] > $slot{'uniqueperiod'}[1]) {
 1540: 	    push(@errors,"$name not created -- Slot's unique period start time is later than the unique period's end time.");
 1541: 	    next;
 1542: 	}
 1543: 
 1544: 	&Apache::lonnet::cput('slots',{$name=>\%slot},$cdom,$cname);
 1545: 	$r->print('.');
 1546: 	$r->rflush();
 1547: 	$countdone++;
 1548:     }
 1549:     $r->print("<p>Created $countdone slots\n</p>");
 1550:     foreach my $error (@errors) {
 1551: 	$r->print("<p>$error\n</p>");
 1552:     }
 1553:     &show_table($r,$mgr);
 1554:     return '';
 1555: }
 1556: 
 1557: sub handler {
 1558:     my $r=shift;
 1559: 
 1560:     &Apache::loncommon::content_type($r,'text/html');
 1561:     &Apache::loncommon::no_cache($r);
 1562:     if ($r->header_only()) {
 1563: 	$r->send_http_header();
 1564: 	return OK;
 1565:     }
 1566: 
 1567:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
 1568:     
 1569:     my $vgr=&Apache::lonnet::allowed('vgr',$env{'request.course.id'});
 1570:     my $mgr=&Apache::lonnet::allowed('mgr',$env{'request.course.id'});
 1571:     my $title='Requesting Another Worktime';
 1572:     if ($env{'form.command'} =~ /^(showslots|uploadstart|csvuploadmap|csvuploadassign)$/ && $vgr eq 'F') {
 1573: 	$title = 'Managing Slots';
 1574:     }
 1575:     &start_page($r,$title);
 1576: 
 1577:     if ($env{'form.command'} eq 'showslots' && $vgr eq 'F') {
 1578: 	&show_table($r,$mgr);
 1579:     } elsif ($env{'form.command'} eq 'remove_registration' && $mgr eq 'F') {
 1580: 	&remove_registration($r);
 1581:     } elsif ($env{'form.command'} eq 'release' && $mgr eq 'F') {
 1582: 	if ($env{'form.entry'} eq 'remove all') {
 1583: 	    &release_all_slot($r,$mgr);
 1584: 	} else {
 1585: 	    &release_slot($r,undef,undef,undef,$mgr);
 1586: 	}
 1587:     } elsif ($env{'form.command'} eq 'delete' && $mgr eq 'F') {
 1588: 	&delete_slot($r);
 1589:     } elsif ($env{'form.command'} eq 'uploadstart' && $mgr eq 'F') {
 1590: 	&upload_start($r);
 1591:     } elsif ($env{'form.command'} eq 'csvuploadmap' && $mgr eq 'F') {
 1592: 	&csv_upload_map($r);
 1593:     } elsif ($env{'form.command'} eq 'csvuploadassign' && $mgr eq 'F') {
 1594: 	if ($env{'form.associate'} ne 'Reverse Association') {
 1595: 	    &csv_upload_assign($r,$mgr);
 1596: 	} else {
 1597: 	    if ( $env{'form.upfile_associate'} ne 'reverse' ) {
 1598: 		$env{'form.upfile_associate'} = 'reverse';
 1599: 	    } else {
 1600: 		$env{'form.upfile_associate'} = 'forward';
 1601: 	    }
 1602: 	    &csv_upload_map($r);
 1603: 	}
 1604:     } else {
 1605: 	my $symb=&unescape($env{'form.symb'});
 1606: 	if (!defined($symb)) {
 1607: 	    &fail($r,'not_valid');
 1608: 	    return OK;
 1609: 	}
 1610: 	my (undef,undef,$res)=&Apache::lonnet::decode_symb($symb);
 1611: 	my $useslots = &Apache::lonnet::EXT("resource.0.useslots",$symb);
 1612: 	if ($useslots ne 'resource' 
 1613: 	    && $useslots ne 'map' 
 1614: 	    && $useslots ne 'map_map') {
 1615: 	    &fail($r,'not_available');
 1616: 	    return OK;
 1617: 	}
 1618: 	$env{'request.symb'}=$symb;
 1619: 	my $type = ($res =~ /\.task$/) ? 'Task'
 1620: 	                               : 'problem';
 1621: 	my ($status) = &Apache::lonhomework::check_slot_access('0',$type);
 1622: 	if ($status eq 'CAN_ANSWER' ||
 1623: 	    $status eq 'NEEDS_CHECKIN' ||
 1624: 	    $status eq 'WAITING_FOR_GRADE') {
 1625: 	    &fail($r,'not_allowed');
 1626: 	    return OK;
 1627: 	}
 1628: 	if ($env{'form.requestattempt'}) {
 1629: 	    &show_choices($r,$symb);
 1630: 	} elsif ($env{'form.command'} eq 'release') {
 1631: 	    &release_slot($r,$symb);
 1632: 	} elsif ($env{'form.command'} eq 'get') {
 1633: 	    &get_slot($r,$symb);
 1634: 	} elsif ($env{'form.command'} eq 'change') {
 1635: 	    if (&get_slot($r,$symb,$env{'form.releaseslot'},1)) {
 1636: 		&release_slot($r,$symb,$env{'form.releaseslot'});
 1637: 	    }
 1638: 	} else {
 1639: 	    $r->print("<p>Unknown command: ".$env{'form.command'}."</p>");
 1640: 	}
 1641:     }
 1642:     &end_page($r);
 1643:     return OK;
 1644: }
 1645: 
 1646: 1;
 1647: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>