File:  [LON-CAPA] / loncom / interface / slotrequest.pm
Revision 1.84: download - view: text, annotated - select for diffs
Thu Dec 11 14:55:15 2008 UTC (15 years, 5 months ago) by bisitz
Branches: MAIN
CVS tags: HEAD
Replaced
  <nobr>...</nobr>
by
  <span class="LC_nobreak">...</span>

- lonsearchcat.pm: Added missing start tag for nobreak area
- lonsurveyreports.pm: Added missing end tag for nobreak area

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

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