File:  [LON-CAPA] / loncom / interface / slotrequest.pm
Revision 1.34: download - view: text, annotated - select for diffs
Mon Nov 21 19:50:36 2005 UTC (18 years, 6 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- mark a slot as deleted

    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.34 2005/11/21 19:50:36 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 Date::Manip;
   38: 
   39: sub fail {
   40:     my ($r,$code)=@_;
   41:     if ($code eq 'not_valid') {
   42: 	$r->print('<p>'.&mt('Unable to understand what resource you wanted to sign up for.').'</p>');
   43: 
   44:     } elsif ($code eq 'not_allowed') {
   45: 	$r->print('<p>'.&mt('Not allowed to sign up or change reservations at this time.').'</p>');
   46:     } else {
   47: 	$r->print('<p>'.&mt('Failed.').'</p>');
   48:     }
   49:     
   50:     $r->print('<p><a href="/adm/flip?postdata=return:">'.
   51: 	      &mt('Return to last resource').'</a></p>');
   52:     &end_page($r);
   53: }
   54: 
   55: sub start_page {
   56:     my ($r,$title)=@_;
   57:     my $html=&Apache::lonxml::xmlbegin();
   58:     $r->print($html.'<head><title>'.&mt($title).'</title></head>');
   59:     $r->print(&Apache::loncommon::bodytag($title));
   60: }
   61: 
   62: sub end_page {
   63:     my ($r)=@_;
   64:     $r->print(&Apache::loncommon::endbodytag().'</html>');
   65: }
   66: 
   67: =pod
   68: 
   69:  slot_reservations db
   70:    - keys are 
   71:     - slotname\0id -> value is an hashref of
   72:                          name -> user@domain of holder
   73:                          timestamp -> timestamp of reservation
   74:                          symb -> symb of resource that it is reserved for
   75: 
   76: =cut
   77: 
   78: sub get_course {
   79:     (undef,my $courseid)=&Apache::lonxml::whichuser();
   80:     my $cdom=$env{'course.'.$courseid.'.domain'};
   81:     my $cnum=$env{'course.'.$courseid.'.num'};
   82:     return ($cnum,$cdom);
   83: }
   84: 
   85: sub get_reservation_ids {
   86:     my ($slot_name)=@_;
   87:     
   88:     my ($cnum,$cdom)=&get_course();
   89: 
   90:     my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
   91: 				       "^$slot_name\0");
   92:     
   93:     my ($tmp)=%consumed;
   94:     if ($tmp=~/^error: 2 / ) {
   95: 	return 0;
   96:     }
   97:     return keys(%consumed);
   98: }
   99: 
  100: sub space_available {
  101:     my ($slot_name,$slot)=@_;
  102:     my $max=$slot->{'maxspace'};
  103: 
  104:     if (!defined($max)) { return 1; }
  105: 
  106:     my $consumed=scalar(&get_reservation_ids($slot_name));
  107:     if ($consumed < $max) {
  108: 	return 1
  109:     }
  110:     return 0;
  111: }
  112: 
  113: sub check_for_reservation {
  114:     my ($symb)=@_;
  115:     my $student = &Apache::lonnet::EXT("resource.0.availablestudent", $symb,
  116: 				       $env{'user.domain'}, $env{'user.name'});
  117: 
  118:     my $course = &Apache::lonnet::EXT("resource.0.available", $symb,
  119: 				    $env{'user.domain'}, $env{'user.name'});
  120:     my @slots = (split(/:/,$student), split(/:/, $course));
  121: 
  122:     &Apache::lonxml::debug(" slot list is ".join(':',@slots));
  123: 
  124:     my ($cnum,$cdom)=&get_course();
  125:     my %slots=&Apache::lonnet::get('slots', [@slots], $cdom, $cnum);
  126: 
  127:     foreach my $slot_name (@slots) {
  128: 	next if (!defined($slots{$slot_name}) ||
  129: 		 !ref($slots{$slot_name}));
  130: 	&Apache::lonxml::debug(time." $slot_name ".
  131: 			       $slots{$slot_name}->{'starttime'}." -- ".
  132: 			       $slots{$slot_name}->{'startreserve'});
  133: 	if ($slots{$slot_name}->{'endtime'} > time &&
  134: 	    $slots{$slot_name}->{'startreserve'} < time) {
  135: 	    # between start of reservation times and end of slot
  136: 	    return($slot_name, $slots{$slot_name});
  137: 	}
  138:     }
  139:     return (undef,undef);
  140: }
  141: 
  142: sub check_for_conflict {
  143:     my ($symb,$new_slot_name)=@_;
  144:     my $student = &Apache::lonnet::EXT("resource.0.availablestudent", $symb,
  145: 				       $env{'user.domain'}, $env{'user.name'});
  146:     my $course = &Apache::lonnet::EXT("resource.0.available", $symb,
  147: 				      $env{'user.domain'}, $env{'user.name'});
  148:     my @slots = (split(/:/,$student), split(/:/, $course));
  149:     my ($cnum,$cdom)=&get_course();
  150:     my %slots=&Apache::lonnet::get('slots', [@slots], $cdom, $cnum);
  151:     foreach my $slot_name (@slots) {
  152: 	next if (!defined($slots{$slot_name}) ||
  153: 		 !ref($slots{$slot_name}));
  154: 
  155:         next if (!defined($slots{$slot_name}->{'uniqueperiod'}) ||
  156: 		 !ref($slots{$slot_name}->{'uniqueperiod'}));
  157: 	my ($start,$end)=@{$slots{$slot_name}->{'uniqueperiod'}};
  158: 	if ($start<time && time < $end) {
  159: 	    return $slot_name;
  160: 	}
  161:     }
  162:     return undef;
  163: 
  164: }
  165: 
  166: sub make_reservation {
  167:     my ($slot_name,$slot,$symb)=@_;
  168: 
  169:     my ($cnum,$cdom)=&get_course();
  170: 
  171:     my $value=&Apache::lonnet::EXT("resource.0.availablestudent",$symb,
  172: 				   $env{'user.domain'},$env{'user.name'});
  173:     &Apache::lonxml::debug("value is  $value<br />");
  174:     foreach my $other_slot (split(/:/, $value)) {
  175: 	if ($other_slot eq $slot_name) {
  176: 	    my %consumed=&Apache::lonnet::dump('slot_reservations', $cdom,
  177: 					       $cnum, "^$slot_name\0");   
  178: 
  179: 	    my $me=$env{'user.name'}.'@'.$env{'user.domain'};
  180: 	    foreach my $key (keys(%consumed)) {
  181: 		if ($consumed{$key}->{'name'} eq $me) {
  182: 		    my $num=(split('\0',$key))[1];
  183: 		    return -$num;
  184: 		}
  185: 	    }
  186: 	}
  187:     }
  188: 
  189:     my $max=$slot->{'maxspace'};
  190:     if (!defined($max)) { $max=99999; }
  191: 
  192:     my (@ids)=&get_reservation_ids($slot_name);
  193: 
  194:     my $last=0;
  195:     foreach my $id (@ids) {
  196: 	my $num=(split('\0',$id))[1];
  197: 	if ($num > $last) { $last=$num; }
  198:     }
  199:     
  200:     my $wanted=$last+1;
  201:     &Apache::lonxml::debug("wanted $wanted<br />");
  202:     if (scalar(@ids) >= $max) {
  203: 	# full up
  204: 	return undef;
  205:     }
  206:     
  207:     my %reservation=('name'      => $env{'user.name'}.'@'.$env{'user.domain'},
  208: 		     'timestamp' => time,
  209: 		     'symb'      => $symb);
  210: 
  211:     my $success=&Apache::lonnet::newput('slot_reservations',
  212: 					{"$slot_name\0$wanted" =>
  213: 					     \%reservation},
  214: 					$cdom, $cnum);
  215: 
  216:     if ($success eq 'ok') {
  217: 	my $new_value=$slot_name;
  218: 	if ($value) {
  219: 	    $new_value=$value.':'.$new_value;
  220: 	}
  221: 	my $result=&Apache::lonparmset::storeparm_by_symb($symb,
  222: 						      '0_availablestudent',
  223: 						       1, $new_value, 'string',
  224: 						       $env{'user.name'},
  225: 					               $env{'user.domain'});
  226: 	&Apache::lonxml::debug("hrrm $result");
  227: 	return $wanted;
  228:     }
  229: 
  230:     # someone else got it
  231:     return undef;
  232: }
  233: 
  234: sub remove_registration {
  235:     my ($r) = @_;
  236:     my $name = &Apache::loncommon::plainname($env{'form.uname'},
  237: 					     $env{'form.udom'});
  238: 
  239:     my $title = &Apache::lonnet::gettitle($env{'form.symb'});
  240: 
  241:     my $hidden_input;
  242:     foreach my $parm ('uname','udom','slotname','entry','symb') {
  243: 	$hidden_input .=
  244: 	    '<input type="hidden" name="'.$parm.'" value="'
  245: 	    .&HTML::Entities::encode($env{'form.'.$parm},'"<>&\'').'" />'."\n";
  246:     }
  247:     $r->print(<<"END_CONFIRM");
  248: <p> Remove $name from slot $env{'form.slotname'} for $title</p>
  249: <form action="/adm/slotrequest" method="POST">
  250:     <input type="hidden" name="command" value="release" />
  251:     $hidden_input
  252:     <input type="submit" name="Yes" value="yes" />
  253: </form>
  254: <form action="/adm/slotrequest" method="POST">
  255:     <input type="hidden" name="command" value="showslots" />
  256:     <input type="submit" name="No" value="no" />
  257: </form>
  258: END_CONFIRM
  259: 
  260: }
  261: 
  262: sub release_slot {
  263:     my ($r,$symb,$slot_name,$inhibit_return_link,$mgr)=@_;
  264: 
  265:     if ($slot_name eq '') { $slot_name=$env{'form.slotname'}; }
  266:     my ($cnum,$cdom)=&get_course();
  267: 
  268:     my ($uname,$udom) = ($env{'user.name'}, $env{'user.domain'});
  269:     if ($mgr eq 'F' 
  270: 	&& defined($env{'form.uname'}) && defined($env{'form.udom'})) {
  271: 	($uname,$udom) = ($env{'form.uname'}, $env{'form.udom'});
  272:     }
  273: 
  274:     if ($mgr eq 'F' 
  275: 	&& defined($env{'form.symb'})) {
  276: 	$symb = $env{'form.symb'};
  277:     }
  278: 
  279:     # get parameter string, check for existance, rebuild string with the slot
  280:     my @slots = split(/:/,&Apache::lonnet::EXT("resource.0.availablestudent",
  281: 					       $symb,$udom,$uname));
  282: 
  283:     my @new_slots;
  284:     foreach my $exist_slot (@slots) {
  285: 	if ($exist_slot eq $slot_name) { next; }
  286: 	push(@new_slots,$exist_slot);
  287:     }
  288:     my $new_param = join(':',@new_slots);
  289: 
  290:     # get slot reservations, check if user has one, if so remove reservation
  291:     my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
  292: 				       "^$slot_name\0");
  293:     foreach my $entry (keys(%consumed)) {
  294: 	if ( $consumed{$entry}->{'name'} eq ($uname.'@'.$udom) ) {
  295: 	    &Apache::lonnet::del('slot_reservations',[$entry],
  296: 				 $cdom,$cnum);
  297: 	}
  298:     }
  299: 
  300:     # store new parameter string
  301:     my $result=&Apache::lonparmset::storeparm_by_symb($symb,
  302: 						      '0_availablestudent',
  303: 						      1, $new_param, 'string',
  304: 						      $uname,$udom);
  305:     my %slot=&Apache::lonnet::get_slot($slot_name);
  306:     my $description=&get_description($env{'form.slotname'},\%slot);
  307:     $r->print("<p>Released Reservation: $description</p>");
  308:     if ($mgr eq 'F') {
  309: 	$r->print('<p><a href="/adm/slotrequest?command=showslots">'.
  310: 		  &mt('Return to slot list').'</a></p>');
  311:     }
  312:     if (!$inhibit_return_link) {
  313: 	$r->print('<p><a href="/adm/flip?postdata=return:">'.
  314: 		  &mt('Return to last resource').'</a></p>');
  315:     }
  316:     return 1;
  317: }
  318: 
  319: sub delete_slot {
  320:     my ($r)=@_;
  321: 
  322:     my $slot_name = $env{'form.slotname'};
  323:     my %slot=&Apache::lonnet::get_slot($slot_name);
  324: 
  325:     my ($cnum,$cdom)=&get_course();
  326:     my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
  327: 				       "^$slot_name\0");
  328: 
  329:     if (%slot && !%consumed) {
  330: 	$slot{'type'} = 'deleted';
  331: 	my $ret = &Apache::lonnet::cput('slots', {$slot_name => \%slot},
  332: 					$cdom, $cnum);
  333: 	if ($ret eq 'ok') {
  334: 	    $r->print("<p>Slot <tt>$slot_name</tt> marked as deleted.</p>");
  335: 	} else {
  336: 	    $r->print("<p> An error ($ret) occurse when attempting to delete Slot <tt>$slot_name</tt>.</p>");
  337: 	}
  338:     } else {
  339: 	if (%consumed) {
  340: 	    $r->print("<p>Slot <tt>$slot_name</tt> has active reservations.</p>");
  341: 	} else {
  342: 	    $r->print("<p>Slot <tt>$slot_name</tt> does not exist.</p>");
  343: 	}
  344:     }
  345:     $r->print('<p><a href="/adm/slotrequest?command=showslots">'.
  346: 	      &mt('Return to slot list').'</a></p>');
  347:     $r->print('<p><a href="/adm/flip?postdata=return:">'.
  348: 	      &mt('Return to last resource').'</a></p>');
  349: }
  350: 
  351: sub get_slot {
  352:     my ($r,$symb)=@_;
  353: 
  354:     my $slot_name=&check_for_conflict($symb,$env{'form.slotname'});
  355:     if ($slot_name) {
  356: 	my %slot=&Apache::lonnet::get_slot($slot_name);
  357: 	my $description1=&get_description($slot_name,\%slot);
  358: 	%slot=&Apache::lonnet::get_slot($env{'form.slotname'});
  359: 	my $description2=&get_description($env{'form.slotname'},\%slot);
  360: 	$r->print("<p>Already have a reservation: $description1</p>");
  361: 	if ($slot_name ne $env{'form.slotname'}) {
  362: 	    $r->print(<<STUFF);
  363: <form method="POST" action="/adm/slotrequest">
  364:    <input type="hidden" name="symb" value="$env{'form.symb'}" />
  365:    <input type="hidden" name="slotname" value="$env{'form.slotname'}" />
  366:    <input type="hidden" name="releaseslot" value="$slot_name" />
  367:    <input type="hidden" name="command" value="change" />
  368: STUFF
  369:             $r->print("<p>You can either ");
  370: 	    $r->print(<<STUFF);
  371:    <input type="submit" name="change" value="Change" />
  372: STUFF
  373: 	    $r->print(' your reservation from <b>'.$description1.'</b> to <b>'.
  374: 		      $description2.
  375: 		      '</b> <br />or <a href="/adm/flip?postdata=return:">'.
  376: 		      &mt('Return to last resource').'</a></p>');
  377: 	    $r->print(<<STUFF);
  378: </form>
  379: STUFF
  380:         } else {
  381: 	    $r->print('<p><a href="/adm/flip?postdata=return:">'.
  382: 		      &mt('Return to last resource').'</a></p>');
  383: 	}
  384: 	return;
  385:     }
  386:     my %slot=&Apache::lonnet::get_slot($env{'form.slotname'});
  387:     my $reserved=&make_reservation($env{'form.slotname'},
  388: 				   \%slot,$symb);
  389:     my $description=&get_description($env{'form.slotname'},\%slot);
  390:     if (defined($reserved)) {
  391: 	if ($reserved > -1) {
  392: 	    $r->print("<p>Success: $description</p>");
  393: 	    $r->print('<p><a href="/adm/flip?postdata=return:">'.
  394: 		      &mt('Return to last resource').'</a></p>');
  395: 	    return;
  396: 	} elsif ($reserved < 0) {
  397: 	    $r->print("<p>Already reserved: $description</p>");
  398: 	    $r->print('<p><a href="/adm/flip?postdata=return:">'.
  399: 		      &mt('Return to last resource').'</a></p>');
  400: 	    return;
  401: 	}
  402:     }
  403: 
  404:     my %lt=('request'=>"Availibility list",
  405: 	    'try'    =>'Try again');
  406:     %lt=&Apache::lonlocal::texthash(%lt);
  407: 
  408:     $r->print(<<STUFF);
  409: <p> <font color="red">Failed</font> to reserve a spot for $description. </p>
  410: <p>
  411: <form method="POST" action="/adm/slotrequest">
  412:    <input type="submit" name="Try Again" value="$lt{'try'}" />
  413:    <input type="hidden" name="symb" value="$env{'form.symb'}" />
  414:    <input type="hidden" name="slotname" value="$env{'form.slotname'}" />
  415:    <input type="hidden" name="command" value="get" />
  416: </form>
  417: ?
  418: </p>
  419: <p>
  420: or
  421: <form method="POST" action="/adm/slotrequest">
  422:     <input type="hidden" name="symb" value="$env{'form.symb'}" />
  423:     <input type="submit" name="requestattempt" value="$lt{'request'}" />
  424: </form>
  425: </p>
  426: or
  427: STUFF
  428:     $r->print('<p><a href="/adm/flip?postdata=return:">'.
  429: 	      &mt('Return to last resource').'</a></p>');
  430:     return;
  431: }
  432: 
  433: sub allowed_slot {
  434:     my ($slot_name,$slot,$symb)=@_;
  435:     #already started
  436:     if ($slot->{'starttime'} < time) {
  437: 	# all open slot to be schedulable
  438: 	#return 0;
  439:     }
  440:     &Apache::lonxml::debug("$slot_name starttime good");
  441:     #already ended
  442:     if ($slot->{'endtime'} < time) {
  443: 	return 0;
  444:     }
  445:     &Apache::lonxml::debug("$slot_name endtime good");
  446:     # not allowed to pick this one
  447:     if (defined($slot->{'type'})
  448: 	&& $slot->{'type'} ne 'schedulable_student') {
  449: 	return 0;
  450:     }
  451:     &Apache::lonxml::debug("$slot_name type good");
  452:     # not allowed for this resource
  453:     if (defined($slot->{'symb'})
  454: 	&& $slot->{'symb'} ne $symb) {
  455: 	return 0;
  456:     }
  457:     &Apache::lonxml::debug("$slot_name symb good");
  458:     return 1;
  459: }
  460: 
  461: sub get_description {
  462:     my ($slot_name,$slot)=@_;
  463:     my $description=$slot->{'description'};
  464:     if (!defined($description)) {
  465: 	$description=&mt('[_1] From [_2] to [_3]',$slot_name,
  466: 			 &Apache::lonlocal::locallocaltime($slot->{'starttime'}),
  467: 			 &Apache::lonlocal::locallocaltime($slot->{'endtime'}));
  468:     }
  469:     return $description;
  470: }
  471: 
  472: sub show_choices {
  473:     my ($r,$symb)=@_;
  474: 
  475:     my ($cnum,$cdom)=&get_course();
  476:     my %slots=&Apache::lonnet::dump('slots',$cdom,$cnum);
  477:     my $available;
  478:     $r->print('<table border="1">');
  479:     &Apache::lonxml::debug("Checking Slots");
  480:     my ($got_slot)=&check_for_reservation($symb);
  481:     foreach my $slot (sort 
  482: 		      { return $slots{$a}->{'starttime'} <=> $slots{$b}->{'starttime'} }
  483: 		      (keys(%slots)))  {
  484: 
  485: 	&Apache::lonxml::debug("Checking Slot $slot");
  486: 	next if (!&allowed_slot($slot,$slots{$slot}));
  487: 
  488: 	$available++;
  489: 
  490: 	my $description=&get_description($slot,$slots{$slot});
  491: 
  492: 	my $form=&mt('Unavailable');
  493: 	if (($slot eq $got_slot) ||
  494: 	    &space_available($slot,$slots{$slot},$symb)) {
  495: 	    my $text=&mt('Select');
  496: 	    my $command='get';
  497: 	    if ($slot eq $got_slot) {
  498: 		$text=&mt('Free Reservation');
  499: 		$command='release';
  500: 	    }
  501: 	    my $escsymb=&Apache::lonnet::escape($symb);
  502: 	    $form=<<STUFF;
  503:    <form method="POST" action="/adm/slotrequest">
  504:      <input type="submit" name="Select" value="$text" />
  505:      <input type="hidden" name="symb" value="$escsymb" />
  506:      <input type="hidden" name="slotname" value="$slot" />
  507:      <input type="hidden" name="command" value="$command" />
  508:    </form>
  509: STUFF
  510: 	}
  511: 	$r->print(<<STUFF);
  512: <tr>
  513:  <td>$form</td>
  514:  <td>$description</td>
  515: </tr>
  516: STUFF
  517:     }
  518: 
  519:     if (!$available) {
  520: 	$r->print('<tr><td>No available times. <a href="/adm/flip?postdata=return:">'.
  521: 		  &mt('Return to last resource').'</a></td></tr>');
  522:     }
  523:     $r->print('</table>');
  524: }
  525: 
  526: sub to_show {
  527:     my ($when,$slot) = @_;
  528:     my $time=time;
  529:     my $week=60*60*24*7;
  530:     if ($when eq 'now') {
  531: 	if ($time > $slot->{'starttime'} &&
  532: 	    $time < $slot->{'endtime'}) {
  533: 	    return 1;
  534: 	}
  535: 	return 0;
  536:     } elsif ($when eq 'nextweek') {
  537: 	if ( ($time        < $slot->{'starttime'} &&
  538: 	      ($time+$week) > $slot->{'starttime'})
  539: 	     ||
  540: 	     ($time        < $slot->{'endtime'} &&
  541: 	      ($time+$week) > $slot->{'endtime'}) ) {
  542: 	    return 1;
  543: 	}
  544: 	return 0;
  545:     } elsif ($when eq 'lastweek') {
  546: 	if ( ($time        > $slot->{'starttime'} &&
  547: 	      ($time-$week) < $slot->{'starttime'})
  548: 	     ||
  549: 	     ($time        > $slot->{'endtime'} &&
  550: 	      ($time-$week) < $slot->{'endtime'}) ) {
  551: 	    return 1;
  552: 	}
  553: 	return 0;
  554:     } elsif ($when eq 'willopen') {
  555: 	if ($time < $slot->{'starttime'}) {
  556: 	    return 1;
  557: 	}
  558: 	return 0;
  559:     } elsif ($when eq 'wereopen') {
  560: 	if ($time > $slot->{'endtime'}) {
  561: 	    return 1;
  562: 	}
  563: 	return 0;
  564:     }
  565:     
  566:     return 1;
  567: }
  568: 
  569: sub remove_link {
  570:     my ($slotname,$entry,$uname,$udom,$symb) = @_;
  571: 
  572:     $slotname  = &Apache::lonnet::escape($slotname);
  573:     $entry     = &Apache::lonnet::escape($entry);
  574:     $uname     = &Apache::lonnet::escape($uname);
  575:     $udom      = &Apache::lonnet::escape($udom);
  576:     $symb      = &Apache::lonnet::escape($symb);
  577: 
  578:     my $remove= &mt('Remove');
  579: 
  580:     return <<"END_LINK";
  581:  <a href="/adm/slotrequest?command=remove_registration&slotname=$slotname&entry=$entry&uname=$uname&udom=$udom&symb=$symb"
  582:    >($remove)</a>
  583: END_LINK
  584: 
  585: }
  586: 
  587: sub show_table {
  588:     my ($r,$mgr)=@_;
  589: 
  590:     my ($cnum,$cdom)=&get_course();
  591:     my %slots=&Apache::lonnet::dump('slots',$cdom,$cnum);
  592:     if ( (keys(%slots))[0] =~ /^error: 2 /) {
  593: 	undef(%slots);
  594:     } 
  595:     my $available;
  596:     if ($mgr eq 'F') {
  597: 	$r->print('<div>');
  598: 	$r->print('<form method="POST" action="/adm/slotrequest">
  599: <input type="hidden" name="command" value="uploadstart" />
  600: <input type="submit" name="start" value="'.&mt('Upload Slot List').'" />
  601: </form>');
  602: 	$r->print('<form method="POST" action="/adm/helper/newslot.helper">
  603: <input type="submit" name="newslot" value="'.&mt('Create a New Slot').'" />
  604: </form>');
  605: 	$r->print('</div>');
  606:     }
  607:     
  608:     my %Saveable_Parameters = ('show'  => 'array',
  609: 			       'when'  => 'scalar',
  610: 			       'order' => 'scalar');
  611: 
  612:     &Apache::loncommon::store_course_settings('slotrequest',\%Saveable_Parameters);
  613:     &Apache::loncommon::restore_course_settings('slotrequest',\%Saveable_Parameters);
  614: 
  615:     my %show_fields=&Apache::lonlocal::texthash(
  616: 	     'name'         => 'Slot Name',
  617: 	     'description'  => 'Description',
  618: 	     'type'         => 'Type',
  619: 	     'starttime'    => 'Start time',
  620: 	     'endtime'      => 'End Time',
  621:              'startreserve' => 'Time students can start reserving',
  622: 	     'secret'       => 'Secret Word',
  623: 	     'maxspace'     => 'Maxium # of students',
  624: 	     'ip'           => 'IP or DNS restrictions',
  625: 	     'symb'         => 'Resource slot is restricted to.',
  626: 	     'uniqueperiod' => 'Period of time slot is unique',
  627: 	     'proctor'      => 'List of proctors');
  628:     my @show_order=('name','description','type','starttime','endtime',
  629: 	       'startreserve','secret','maxspace','ip','symb',
  630: 	       'uniqueperiod','proctor');
  631:     my @show = 
  632: 	(exists($env{'form.show'})) ? &Apache::loncommon::get_env_multiple('form.show')
  633: 	                            : keys(%show_fields);
  634:     my %show =  map { $_ => 1 } (@show);
  635: 
  636:     my %when_fields=&Apache::lonlocal::texthash(
  637: 	     'now' => 'Open now',
  638: 	     'nextweek' => 'Open within the next week',
  639: 	     'lastweek' => 'Were open last week',
  640: 	     'willopen' => 'Will open later',
  641: 	     'wereopen' => 'Were open');
  642:     my @when_order=('now','nextweek','lastweek','willopen','wereopen');
  643:     $when_fields{'select_form_order'} = \@when_order;
  644:     my $when = 	(exists($env{'form.when'})) ? $env{'form.when'}
  645:                                             : 'now';
  646: 
  647:     $r->print('<form method="POST" action="/adm/slotrequest">
  648: <input type="hidden" name="command" value="showslots" />');
  649:     $r->print('<div>');
  650:     $r->print('<table class="inline"><tr><th>'.&mt('Show').'</th><th>'.&mt('Open').'</th></tr><tr><td>'.&Apache::loncommon::multiple_select_form('show',\@show,6,\%show_fields,\@show_order).
  651: 	      '</td><td>'.&Apache::loncommon::select_form($when,'when',%when_fields).
  652: 	      '</td></tr></table>');
  653:     $r->print('</div>');
  654:     $r->print('<p><input type="submit" name="start" value="'.&mt('Update Display').'" /></p>');
  655:     my $linkstart='<a href="/adm/slotrequest?command=showslots&amp;order=';
  656:     $r->print('<table class="thinborder">
  657: <tr>
  658:   <th></th>');
  659:     foreach my $which (@show_order) {
  660: 	if ($which ne 'proctor' && exists($show{$which})) {
  661: 	    $r->print('<th>'.$linkstart.$which.'">'.$show_fields{$which}.'</a></th>');
  662: 	}
  663:     }
  664:     $r->print('<th>Scheduled Students</th></tr>');
  665: 
  666:     my %name_cache;
  667:     my $slotsort = sub {
  668: 	if ($env{'form.order'}=~/^(type|description|endtime|startreserve|maxspace|ip|symb)$/) {
  669: 	    if (lc($slots{$a}->{$env{'form.order'}})
  670: 		ne lc($slots{$b}->{$env{'form.order'}})) {
  671: 		return (lc($slots{$a}->{$env{'form.order'}}) 
  672: 			cmp lc($slots{$b}->{$env{'form.order'}}));
  673: 	    }
  674: 	} elsif ($env{'form.order'} eq 'name') {
  675: 	    if (lc($a) cmp lc($b)) {
  676: 		return lc($a) cmp lc($b);
  677: 	    }
  678: 	} elsif ($env{'form.order'} eq 'uniqueperiod') {
  679: 	    
  680: 	    if ($slots{$a}->{'uniqueperiod'}[0] 
  681: 		ne $slots{$b}->{'uniqueperiod'}[0]) {
  682: 		return ($slots{$a}->{'uniqueperiod'}[0]
  683: 			cmp $slots{$b}->{'uniqueperiod'}[0]);
  684: 	    }
  685: 	    if ($slots{$a}->{'uniqueperiod'}[1] 
  686: 		ne $slots{$b}->{'uniqueperiod'}[1]) {
  687: 		return ($slots{$a}->{'uniqueperiod'}[1]
  688: 			cmp $slots{$b}->{'uniqueperiod'}[1]);
  689: 	    }
  690: 	}
  691: 	return $slots{$a}->{'starttime'} <=> $slots{$b}->{'starttime'};
  692:     };
  693:     foreach my $slot (sort $slotsort (keys(%slots)))  {
  694: 	if (!&to_show($when,$slots{$slot})) { next; }
  695: 	if (defined($slots{$slot}->{'type'})
  696: 	    && $slots{$slot}->{'type'} ne 'schedulable_student') {
  697: 	    #next;
  698: 	}
  699: 	my $description=&get_description($slot,$slots{$slot});
  700: 	my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
  701: 					   "^$slot\0");
  702: 	my $ids;
  703: 	foreach my $entry (sort(keys(%consumed))) {
  704: 	    my (undef,$id)=split("\0",$entry);
  705: 	    my ($uname,$udom) = split('@',$consumed{$entry}{'name'});
  706: 	    my $name = &Apache::loncommon::plainname($uname,$udom);
  707: 	    $ids.= '<nobr>'.$name.&remove_link($slot,$entry,$uname,$udom,
  708: 					       $consumed{$entry}{'symb'})
  709: 		.'</nobr><br />';
  710: 	}
  711: 
  712: 	my $start=($slots{$slot}->{'starttime'}?
  713: 		   &Apache::lonlocal::locallocaltime($slots{$slot}->{'starttime'}):'');
  714: 	my $end=($slots{$slot}->{'endtime'}?
  715: 		 &Apache::lonlocal::locallocaltime($slots{$slot}->{'endtime'}):'');
  716: 	my $start_reserve=($slots{$slot}->{'startreserve'}?
  717: 			   &Apache::lonlocal::locallocaltime($slots{$slot}->{'startreserve'}):'');
  718: 	
  719: 	my $unique;
  720: 	if (ref($slots{$slot}{'uniqueperiod'})) {
  721: 	    $unique=localtime($slots{$slot}{'uniqueperiod'}[0]).','.
  722: 		localtime($slots{$slot}{'uniqueperiod'}[1]);
  723: 	}
  724: 
  725: 	my $title;
  726: 	if (exists($slots{$slot}{'symb'})) {
  727: 	    my (undef,undef,$res)=
  728: 		&Apache::lonnet::decode_symb($slots{$slot}{'symb'});
  729: 	    $res =   &Apache::lonnet::clutter($res);
  730: 	    $title = &Apache::lonnet::gettitle($slots{$slot}{'symb'});
  731: 	    $title='<a href="'.$res.'?symb='.$slots{$slot}{'symb'}.'">'.$title.'</a>';
  732: 	}
  733: 
  734: 	my @proctors;
  735: 	my $rowspan=1;
  736: 	my $colspan=1;
  737: 	if (exists($show{'proctor'})) {
  738: 	    $rowspan=2;
  739: 	    @proctors= map {
  740: 		my ($uname,$udom)=split(/@/,$_);
  741: 		my $fullname=$name_cache{$_};
  742: 		if (!defined($fullname)) {
  743: 		    &Apache::lonnet::logthis("Gettign $uname $udom");
  744: 		    $fullname = &Apache::loncommon::plainname($uname,$udom);
  745: 		    $fullname =~s/\s/&nbsp;/g;
  746: 		    $name_cache{$_} = $fullname;
  747: 		}
  748: 		&Apache::loncommon::aboutmewrapper($fullname,$uname,$udom);
  749: 	    } (sort(split(/\s*,\s*/,$slots{$slot}->{'proctor'})));
  750: 	}
  751: 	my $proctors=join(', ',@proctors);
  752: 
  753: 	my $edit=(<<"EDITLINK");
  754: <a href="/adm/helper/newslot.helper?name=$slot">Edit</a>
  755: EDITLINK
  756: 
  757: 	my $delete=(<<"DELETELINK");
  758: <a href="/adm/slotrequest?command=delete&slotname=$slot">Delete</a>
  759: DELETELINK
  760:         if ($ids ne '') { undef($delete); }
  761: 
  762:         $r->print("<tr>\n<td rowspan=\"$rowspan\">$edit $delete</td>\n");
  763: 	if (exists($show{'name'})) {
  764: 	    $colspan++;$r->print("<td>$slot</td>");
  765: 	}
  766: 	if (exists($show{'description'})) {
  767: 	    $colspan++;$r->print("<td>$description</td>\n");
  768: 	}
  769: 	if (exists($show{'type'})) {
  770: 	    $colspan++;$r->print("<td>$slots{$slot}->{'type'}</td>\n");
  771: 	}
  772: 	if (exists($show{'starttime'})) {
  773: 	    $colspan++;$r->print("<td>$start</td>\n");
  774: 	}
  775: 	if (exists($show{'endtime'})) {
  776: 	    $colspan++;$r->print("<td>$end</td>\n");
  777: 	}
  778: 	if (exists($show{'startreserve'})) {
  779: 	    $colspan++;$r->print("<td>$start_reserve</td>\n");
  780: 	}
  781: 	if (exists($show{'secret'})) {
  782: 	    $colspan++;$r->print("<td>$slots{$slot}{'secret'}</td>\n");
  783: 	}
  784: 	if (exists($show{'maxspace'})) {
  785: 	    $colspan++;$r->print("<td>$slots{$slot}{'maxspace'}</td>\n");
  786: 	}
  787: 	if (exists($show{'ip'})) {
  788: 	    $colspan++;$r->print("<td>$slots{$slot}{'ip'}</td>\n");
  789: 	}
  790: 	if (exists($show{'symb'})) {
  791: 	    $colspan++;$r->print("<td>$title</td>\n");
  792: 	}
  793: 	if (exists($show{'uniqueperiod'})) {
  794: 	    $colspan++;$r->print("<td>$unique</td>\n");
  795: 	}
  796: 	$colspan++;$r->print("<td>$ids</td>\n</tr>\n");
  797: 	if (exists($show{'proctor'})) {
  798: 	    $r->print(<<STUFF);
  799: <tr>
  800:  <td colspan="$colspan">$proctors</td>
  801: </tr>
  802: STUFF
  803:         }
  804:     }
  805:     $r->print('</table>');
  806: }
  807: 
  808: sub upload_start {
  809:     my ($r)=@_;    
  810:     $r->print(&Apache::grades::checkforfile_js());
  811:     my $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
  812:     $result.='&nbsp;<b>'.
  813: 	&mt('Specify a file containing the slot definitions.').
  814: 	'</b></td></tr>'."\n";
  815:     $result.='<tr bgcolor=#ffffe6><td>'."\n";
  816:     my $upfile_select=&Apache::loncommon::upfile_select_html();
  817:     my $ignore=&mt('Ignore First Line');
  818:     $result.=<<ENDUPFORM;
  819: <form method="post" enctype="multipart/form-data" action="/adm/slotrequest" name="slotupload">
  820: <input type="hidden" name="command" value="csvuploadmap" />
  821: $upfile_select
  822: <br /><input type="button" onClick="javascript:checkUpload(this.form);" value="Upload Data" />
  823: <label><input type="checkbox" name="noFirstLine" />$ignore</label>
  824: </form>
  825: ENDUPFORM
  826:     $result.='</td></tr></table>'."\n";
  827:     $result.='</td></tr></table>'."\n";
  828:     $r->print($result);
  829: }
  830: 
  831: sub csvuploadmap_header {
  832:     my ($r,$datatoken,$distotal)= @_;
  833:     my $javascript;
  834:     if ($env{'form.upfile_associate'} eq 'reverse') {
  835: 	$javascript=&csvupload_javascript_reverse_associate();
  836:     } else {
  837: 	$javascript=&csvupload_javascript_forward_associate();
  838:     }
  839: 
  840:     my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
  841:     my $ignore=&mt('Ignore First Line');
  842:     $r->print(<<ENDPICK);
  843: <form method="post" enctype="multipart/form-data" action="/adm/slotrequest" name="slotupload">
  844: <h3>Identify fields</h3>
  845: Total number of records found in file: $distotal <hr />
  846: Enter as many fields as you can. The system will inform you and bring you back
  847: to this page if the data selected is insufficient to create the slots.<hr />
  848: <input type="button" value="Reverse Association" onClick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
  849: <label><input type="checkbox" name="noFirstLine" $checked />$ignore</label>
  850: <input type="hidden" name="associate"  value="" />
  851: <input type="hidden" name="datatoken"  value="$datatoken" />
  852: <input type="hidden" name="fileupload" value="$env{'form.fileupload'}" />
  853: <input type="hidden" name="upfiletype" value="$env{'form.upfiletype'}" />
  854: <input type="hidden" name="upfile_associate" 
  855:                                        value="$env{'form.upfile_associate'}" />
  856: <input type="hidden" name="command"    value="csvuploadassign" />
  857: <hr />
  858: <script type="text/javascript" language="Javascript">
  859: $javascript
  860: </script>
  861: ENDPICK
  862:     return '';
  863: 
  864: }
  865: 
  866: sub csvuploadmap_footer {
  867:     my ($request,$i,$keyfields) =@_;
  868:     $request->print(<<ENDPICK);
  869: </table>
  870: <input type="hidden" name="nfields" value="$i" />
  871: <input type="hidden" name="keyfields" value="$keyfields" />
  872: <input type="button" onClick="javascript:verify(this.form)" value="Create Slots" /><br />
  873: </form>
  874: ENDPICK
  875: }
  876: 
  877: sub csvupload_javascript_reverse_associate {
  878:     my $error1=&mt('You need to specify the name, starttime, endtime and a type');
  879:     return(<<ENDPICK);
  880:   function verify(vf) {
  881:     var foundstart=0;
  882:     var foundend=0;
  883:     var foundname=0;
  884:     var foundtype=0;
  885:     for (i=0;i<=vf.nfields.value;i++) {
  886:       tw=eval('vf.f'+i+'.selectedIndex');
  887:       if (i==0 && tw!=0) { foundname=1; }
  888:       if (i==1 && tw!=0) { foundtype=1; }
  889:       if (i==2 && tw!=0) { foundstat=1; }
  890:       if (i==3 && tw!=0) { foundend=1; }
  891:     }
  892:     if (foundstart==0 && foundend==0 && foundtype==0 && foundname==0) {
  893: 	alert('$error1');
  894: 	return;
  895:     }
  896:     vf.submit();
  897:   }
  898:   function flip(vf,tf) {
  899:   }
  900: ENDPICK
  901: }
  902: 
  903: sub csvupload_javascript_forward_associate {
  904:     my $error1=&mt('You need to specify the name, starttime, endtime and a type');
  905:   return(<<ENDPICK);
  906:   function verify(vf) {
  907:     var foundstart=0;
  908:     var foundend=0;
  909:     var foundname=0;
  910:     var foundtype=0;
  911:     for (i=0;i<=vf.nfields.value;i++) {
  912:       tw=eval('vf.f'+i+'.selectedIndex');
  913:       if (tw==1) { foundname=1; }
  914:       if (tw==2) { foundtype=1; }
  915:       if (tw==3) { foundstat=1; }
  916:       if (tw==4) { foundend=1; }
  917:     }
  918:     if (foundstart==0 && foundend==0 && foundtype==0 && foundname==0) {
  919: 	alert('$error1');
  920: 	return;
  921:     }
  922:     vf.submit();
  923:   }
  924:   function flip(vf,tf) {
  925:   }
  926: ENDPICK
  927: }
  928: 
  929: sub csv_upload_map {
  930:     my ($r)= @_;
  931: 
  932:     my $datatoken;
  933:     if (!$env{'form.datatoken'}) {
  934: 	$datatoken=&Apache::loncommon::upfile_store($r);
  935:     } else {
  936: 	$datatoken=$env{'form.datatoken'};
  937: 	&Apache::loncommon::load_tmp_file($r);
  938:     }
  939:     my @records=&Apache::loncommon::upfile_record_sep();
  940:     if ($env{'form.noFirstLine'}) { shift(@records); }
  941:     &csvuploadmap_header($r,$datatoken,$#records+1);
  942:     my ($i,$keyfields);
  943:     if (@records) {
  944: 	my @fields=&csvupload_fields();
  945: 
  946: 	if ($env{'form.upfile_associate'} eq 'reverse') {	
  947: 	    &Apache::loncommon::csv_print_samples($r,\@records);
  948: 	    $i=&Apache::loncommon::csv_print_select_table($r,\@records,
  949: 							  \@fields);
  950: 	    foreach (@fields) { $keyfields.=$_->[0].','; }
  951: 	    chop($keyfields);
  952: 	} else {
  953: 	    unshift(@fields,['none','']);
  954: 	    $i=&Apache::loncommon::csv_samples_select_table($r,\@records,
  955: 							    \@fields);
  956: 	    my %sone=&Apache::loncommon::record_sep($records[0]);
  957: 	    $keyfields=join(',',sort(keys(%sone)));
  958: 	}
  959:     }
  960:     &csvuploadmap_footer($r,$i,$keyfields);
  961: 
  962:     return '';
  963: }
  964: 
  965: sub csvupload_fields {
  966:     return (['name','Slot name'],
  967: 	    ['type','Type of slot'],
  968: 	    ['starttime','Start Time of slot'],
  969: 	    ['endtime','End Time of slot'],
  970: 	    ['startreserve','Reservation Start Time'],
  971: 	    ['ip','IP or DNS restriction'],
  972: 	    ['proctor','List of proctor ids'],
  973: 	    ['description','Slot Description'],
  974: 	    ['maxspace','Maximum number of reservations'],
  975: 	    ['symb','Resource Restriction'],
  976: 	    ['uniqueperiod','Date range of slot exclusion'],
  977: 	    ['secret','Secret word proctor uses to validate']);
  978: }
  979: 
  980: sub csv_upload_assign {
  981:     my ($r,$mgr)= @_;
  982:     &Apache::loncommon::load_tmp_file($r);
  983:     my @slotdata = &Apache::loncommon::upfile_record_sep();
  984:     if ($env{'form.noFirstLine'}) { shift(@slotdata); }
  985:     my %fields=&Apache::grades::get_fields();
  986:     $r->print('<h3>Creating Slots</h3>');
  987:     my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
  988:     my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
  989:     my $countdone=0;
  990:     my @errors;
  991:     foreach my $slot (@slotdata) {
  992: 	my %slot;
  993: 	my %entries=&Apache::loncommon::record_sep($slot);
  994: 	my $domain;
  995: 	my $name=$entries{$fields{'name'}};
  996: 	if ($name=~/^\s*$/) {
  997: 	    push(@errors,"Did not create slot with no name");
  998: 	    next;
  999: 	}
 1000: 	if ($name=~/\s/) { 
 1001: 	    push(@errors,"$name not created -- Name must not contain spaces");
 1002: 	    next;
 1003: 	}
 1004: 	if ($name=~/\W/) { 
 1005: 	    push(@errors,"$name not created -- Name must contain only letters, numbers and _");
 1006: 	    next;
 1007: 	}
 1008: 	if ($entries{$fields{'type'}}) {
 1009: 	    $slot{'type'}=$entries{$fields{'type'}};
 1010: 	} else {
 1011: 	    $slot{'type'}='preassigned';
 1012: 	}
 1013: 	if ($slot{'type'} ne 'preassigned' &&
 1014: 	    $slot{'type'} ne 'schedulable_student') {
 1015: 	    push(@errors,"$name not created -- invalid type ($slot{'type'}) must be either preassigned or schedulable_student");
 1016: 	    next;
 1017: 	}
 1018: 	if ($entries{$fields{'starttime'}}) {
 1019: 	    $slot{'starttime'}=&UnixDate($entries{$fields{'starttime'}},"%s");
 1020: 	}
 1021: 	if ($entries{$fields{'endtime'}}) {
 1022: 	    $slot{'endtime'}=&UnixDate($entries{$fields{'endtime'}},"%s");
 1023: 	}
 1024: 	if ($entries{$fields{'startreserve'}}) {
 1025: 	    $slot{'startreserve'}=
 1026: 		&UnixDate($entries{$fields{'startreserve'}},"%s");
 1027: 	}
 1028: 	foreach my $key ('ip','proctor','description','maxspace',
 1029: 			 'secret','symb') {
 1030: 	    if ($entries{$fields{$key}}) {
 1031: 		$slot{$key}=$entries{$fields{$key}};
 1032: 	    }
 1033: 	}
 1034: 	if ($entries{$fields{'uniqueperiod'}}) {
 1035: 	    my ($start,$end)=split(',',$entries{$fields{'uniqueperiod'}});
 1036: 	    my @times=(&UnixDate($start,"%s"),
 1037: 		       &UnixDate($end,"%s"));
 1038: 	    $slot{'uniqueperiod'}=\@times;
 1039: 	}
 1040: 
 1041: 	&Apache::lonnet::cput('slots',{$name=>\%slot},$cdom,$cname);
 1042: 	$r->print('.');
 1043: 	$r->rflush();
 1044: 	$countdone++;
 1045:     }
 1046:     $r->print("<p>Created $countdone slots\n</p>");
 1047:     foreach my $error (@errors) {
 1048: 	$r->print("<p>$error\n</p>");
 1049:     }
 1050:     &show_table($r,$mgr);
 1051:     return '';
 1052: }
 1053: 
 1054: sub handler {
 1055:     my $r=shift;
 1056: 
 1057:     &Apache::loncommon::content_type($r,'text/html');
 1058:     &Apache::loncommon::no_cache($r);
 1059:     if ($r->header_only()) {
 1060: 	$r->send_http_header();
 1061: 	return OK;
 1062:     }
 1063: 
 1064:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
 1065:     
 1066:     my $vgr=&Apache::lonnet::allowed('vgr',$env{'request.course.id'});
 1067:     my $mgr=&Apache::lonnet::allowed('mgr',$env{'request.course.id'});
 1068:     my $title='Requesting Another Worktime';
 1069:     if ($env{'form.command'} =~ /^(showslots|uploadstart|csvuploadmap|csvuploadassign)$/ && $vgr eq 'F') {
 1070: 	$title = 'Managing Slots';
 1071:     }
 1072:     &start_page($r,$title);
 1073: 
 1074:     if ($env{'form.command'} eq 'showslots' && $vgr eq 'F') {
 1075: 	&show_table($r,$mgr);
 1076:     } elsif ($env{'form.command'} eq 'remove_registration' && $mgr eq 'F') {
 1077: 	&remove_registration($r);
 1078:     } elsif ($env{'form.command'} eq 'release' && $mgr eq 'F') {
 1079: 	&release_slot($r,undef,undef,undef,$mgr);
 1080:     } elsif ($env{'form.command'} eq 'delete' && $mgr eq 'F') {
 1081: 	&delete_slot($r);
 1082:     } elsif ($env{'form.command'} eq 'uploadstart' && $mgr eq 'F') {
 1083: 	&upload_start($r);
 1084:     } elsif ($env{'form.command'} eq 'csvuploadmap' && $mgr eq 'F') {
 1085: 	&csv_upload_map($r);
 1086:     } elsif ($env{'form.command'} eq 'csvuploadassign' && $mgr eq 'F') {
 1087: 	if ($env{'form.associate'} ne 'Reverse Association') {
 1088: 	    &csv_upload_assign($r,$mgr);
 1089: 	} else {
 1090: 	    if ( $env{'form.upfile_associate'} ne 'reverse' ) {
 1091: 		$env{'form.upfile_associate'} = 'reverse';
 1092: 	    } else {
 1093: 		$env{'form.upfile_associate'} = 'forward';
 1094: 	    }
 1095: 	    &csv_upload_map($r);
 1096: 	}
 1097:     } else {
 1098: 	my $symb=&Apache::lonnet::unescape($env{'form.symb'});
 1099: 	my (undef,undef,$res)=&Apache::lonnet::decode_symb($symb);
 1100: 	if ($res !~ /\.task$/) {
 1101: 	    &fail($r,'not_valid');
 1102: 	    return OK;
 1103: 	}
 1104: 	$env{'request.symb'}=$symb;
 1105: 	my ($status) = &Apache::lonhomework::check_task_access('0');
 1106: 	if ($status eq 'CAN_ANSWER' ||
 1107: 	    $status eq 'NEEDS_CHECKIN' ||
 1108: 	    $status eq 'WAITING_FOR_GRADE') {
 1109: 	    &fail($r,'not_allowed');
 1110: 	    return OK;
 1111: 	}
 1112: 	if ($env{'form.requestattempt'}) {
 1113: 	    &show_choices($r,$symb);
 1114: 	} elsif ($env{'form.command'} eq 'release') {
 1115: 	    &release_slot($r,$symb);
 1116: 	} elsif ($env{'form.command'} eq 'get') {
 1117: 	    &get_slot($r,$symb);
 1118: 	} elsif ($env{'form.command'} eq 'change') {
 1119: 	    &release_slot($r,$symb,$env{'form.releaseslot'},1);
 1120: 	    &get_slot($r,$symb);
 1121: 	} else {
 1122: 	    $r->print("<p>Unknown command: ".$env{'form.command'}."</p>");
 1123: 	}
 1124:     }
 1125:     &end_page($r);
 1126:     return OK;
 1127: }
 1128: 
 1129: 1;
 1130: __END__

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