File:  [LON-CAPA] / loncom / interface / slotrequest.pm
Revision 1.107: download - view: text, annotated - select for diffs
Thu May 27 04:44:33 2010 UTC (13 years, 11 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_9_X, version_2_9_1, HEAD
- Need to pass $symb as third arg to &allowed_slot() for slots restricted by symb to be available for the corresponding symb.

    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.107 2010/05/27 04:44:33 raeburn 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,$brcrum)=@_;
   60:     my $args;
   61:     if (ref($brcrum) eq 'ARRAY') {
   62:         $args = {bread_crumbs => $brcrum};
   63:     }
   64:     $r->print(&Apache::loncommon::start_page($title,undef,$args));
   65: }
   66: 
   67: sub end_page {
   68:     my ($r)=@_;
   69:     $r->print(&Apache::loncommon::end_page());
   70: }
   71: 
   72: =pod
   73: 
   74:  slot_reservations db
   75:    - keys are 
   76:     - slotname\0id -> value is an hashref of
   77:                          name -> user@domain of holder
   78:                          timestamp -> timestamp of reservation
   79:                          symb -> symb of resource that it is reserved for
   80: 
   81: =cut
   82: 
   83: sub get_course {
   84:     (undef,my $courseid)=&Apache::lonnet::whichuser();
   85:     my $cdom=$env{'course.'.$courseid.'.domain'};
   86:     my $cnum=$env{'course.'.$courseid.'.num'};
   87:     return ($cnum,$cdom);
   88: }
   89: 
   90: sub get_reservation_ids {
   91:     my ($slot_name)=@_;
   92:     
   93:     my ($cnum,$cdom)=&get_course();
   94: 
   95:     my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
   96: 				       "^$slot_name\0");
   97:     if (&Apache::lonnet::error(%consumed)) { 
   98: 	return 'error: Unable to determine current status';
   99:     }
  100:     my ($tmp)=%consumed;
  101:     if ($tmp=~/^error: 2 / ) {
  102: 	return 0;
  103:     }
  104:     return keys(%consumed);
  105: }
  106: 
  107: sub space_available {
  108:     my ($slot_name,$slot)=@_;
  109:     my $max=$slot->{'maxspace'};
  110: 
  111:     if (!defined($max)) { return 1; }
  112: 
  113:     my $consumed=scalar(&get_reservation_ids($slot_name));
  114:     if ($consumed < $max) {
  115: 	return 1
  116:     }
  117:     return 0;
  118: }
  119: 
  120: sub check_for_reservation {
  121:     my ($symb,$mode)=@_;
  122:     my $student = &Apache::lonnet::EXT("resource.0.availablestudent", $symb,
  123: 				       $env{'user.domain'}, $env{'user.name'});
  124: 
  125:     my $course = &Apache::lonnet::EXT("resource.0.available", $symb,
  126: 				    $env{'user.domain'}, $env{'user.name'});
  127:     my @slots = (split(/:/,$student), split(/:/, $course));
  128: 
  129:     &Apache::lonxml::debug(" slot list is ".join(':',@slots));
  130: 
  131:     my ($cnum,$cdom)=&get_course();
  132:     my %slots=&Apache::lonnet::get('slots', [@slots], $cdom, $cnum);
  133: 
  134:     if (&Apache::lonnet::error($student) 
  135: 	|| &Apache::lonnet::error($course)
  136: 	|| &Apache::lonnet::error(%slots)) {
  137: 	return 'error: Unable to determine current status';
  138:     }    
  139:     my @got;
  140:     my @sorted_slots = &Apache::loncommon::sorted_slots(\@slots,\%slots);
  141:     foreach my $slot_name (@sorted_slots) {
  142: 	next if (!defined($slots{$slot_name}) ||
  143: 		 !ref($slots{$slot_name}));
  144: 	&Apache::lonxml::debug(time." $slot_name ".
  145: 			       $slots{$slot_name}->{'starttime'}." -- ".
  146: 			       $slots{$slot_name}->{'startreserve'});
  147: 	if ($slots{$slot_name}->{'endtime'} > time &&
  148: 	    $slots{$slot_name}->{'startreserve'} < time) {
  149: 	    # between start of reservation times and end of slot
  150: 	    if ($mode eq 'allslots') {
  151: 		push(@got,$slot_name);
  152: 	    } else {
  153: 		return($slot_name, $slots{$slot_name});
  154: 	    }
  155: 	}
  156:     }
  157:     if ($mode eq 'allslots' && @got) {
  158: 	return @got;
  159:     }
  160:     return (undef,undef);
  161: }
  162: 
  163: sub get_consumed_uniqueperiods {
  164:     my ($slots) = @_;
  165:     my $navmap=Apache::lonnavmaps::navmap->new;
  166:     if (!defined($navmap)) {
  167:         return 'error: Unable to determine current status';
  168:     }
  169:     my @problems = $navmap->retrieveResources(undef,
  170: 					      sub { $_[0]->is_problem() },1,0);
  171:     my %used_slots;
  172:     foreach my $problem (@problems) {
  173: 	my $symb = $problem->symb();
  174: 	my $student = &Apache::lonnet::EXT("resource.0.availablestudent",
  175: 					   $symb, $env{'user.domain'},
  176: 					   $env{'user.name'});
  177: 	my $course =  &Apache::lonnet::EXT("resource.0.available",
  178: 					   $symb, $env{'user.domain'},
  179: 					   $env{'user.name'});
  180: 	if (&Apache::lonnet::error($student) 
  181: 	    || &Apache::lonnet::error($course)) {
  182: 	    return 'error: Unable to determine current status';
  183: 	}
  184: 	foreach my $slot (split(/:/,$student), split(/:/, $course)) {
  185: 	    $used_slots{$slot}=1;
  186: 	}
  187:     }
  188: 
  189:     if (!ref($slots)) {
  190: 	my ($cnum,$cdom)=&get_course();
  191: 	my %slots=&Apache::lonnet::get('slots', [keys(%used_slots)], $cdom, $cnum);
  192: 	if (&Apache::lonnet::error(%slots)) {
  193: 	    return 'error: Unable to determine current status';
  194: 	}
  195: 	$slots = \%slots;
  196:     }
  197: 
  198:     my %consumed_uniqueperiods;
  199:     foreach my $slot_name (keys(%used_slots)) {
  200: 	next if (!defined($slots->{$slot_name}) ||
  201: 		 !ref($slots->{$slot_name}));
  202: 	
  203:         next if (!defined($slots->{$slot_name}{'uniqueperiod'}) ||
  204: 		 !ref($slots->{$slot_name}{'uniqueperiod'}));
  205: 	$consumed_uniqueperiods{$slot_name} = 
  206: 	    $slots->{$slot_name}{'uniqueperiod'};
  207:     }
  208:     return \%consumed_uniqueperiods;
  209: }
  210: 
  211: sub check_for_conflict {
  212:     my ($symb,$new_slot_name,$new_slot,$slots,$consumed_uniqueperiods)=@_;
  213: 
  214:     if (!defined($new_slot->{'uniqueperiod'})) { return undef; }
  215: 
  216:     if (!ref($consumed_uniqueperiods)) {
  217: 	$consumed_uniqueperiods = &get_consumed_uniqueperiods($slots);
  218:         if (ref($consumed_uniqueperiods) eq 'HASH') {
  219: 	    if (&Apache::lonnet::error(%$consumed_uniqueperiods)) {
  220: 	        return 'error: Unable to determine current status';
  221: 	    }
  222:         } else {
  223:             return 'error: Unable to determine current status';
  224:         }
  225:     }
  226:     
  227:     my ($new_uniq_start,$new_uniq_end) = @{$new_slot->{'uniqueperiod'}};
  228:     foreach my $slot_name (keys(%$consumed_uniqueperiods)) {
  229: 	my ($start,$end)=@{$consumed_uniqueperiods->{$slot_name}};
  230: 	if (!
  231: 	    ($start < $new_uniq_start &&  $end < $new_uniq_start) ||
  232: 	    ($start > $new_uniq_end   &&  $end > $new_uniq_end  )) {
  233: 	    return $slot_name;
  234: 	}
  235:     }
  236:     return undef;
  237: }
  238: 
  239: sub make_reservation {
  240:     my ($slot_name,$slot,$symb,$cnum,$cdom)=@_;
  241: 
  242:     my $value=&Apache::lonnet::EXT("resource.0.availablestudent",$symb,
  243: 				   $env{'user.domain'},$env{'user.name'});
  244:     &Apache::lonxml::debug("value is  $value<br />");
  245: 
  246:     my $use_slots = &Apache::lonnet::EXT("resource.0.useslots",$symb,
  247: 					 $env{'user.domain'},$env{'user.name'});
  248:     &Apache::lonxml::debug("use_slots is  $use_slots<br />");
  249: 
  250:     if (&Apache::lonnet::error($value) 
  251: 	|| &Apache::lonnet::error($use_slots)) { 
  252: 	return 'error: Unable to determine current status';
  253:     }
  254: 
  255:     my $parm_symb  = $symb;
  256:     my $parm_level = 1;
  257:     if ($use_slots eq 'map' || $use_slots eq 'map_map') {
  258: 	my ($map) = &Apache::lonnet::decode_symb($symb);
  259: 	$parm_symb = &Apache::lonnet::symbread($map);
  260: 	$parm_level = 2;
  261:     }
  262: 
  263:     foreach my $other_slot (split(/:/, $value)) {
  264: 	if ($other_slot eq $slot_name) {
  265: 	    my %consumed=&Apache::lonnet::dump('slot_reservations', $cdom,
  266: 					       $cnum, "^$slot_name\0");   
  267: 	    if (&Apache::lonnet::error($value)) { 
  268: 		return 'error: Unable to determine current status';
  269: 	    }
  270: 	    my $me=$env{'user.name'}.':'.$env{'user.domain'};
  271: 	    foreach my $key (keys(%consumed)) {
  272: 		if ($consumed{$key}->{'name'} eq $me) {
  273: 		    my $num=(split('\0',$key))[1];
  274: 		    return -$num;
  275: 		}
  276: 	    }
  277: 	}
  278:     }
  279: 
  280:     my $max=$slot->{'maxspace'};
  281:     if (!defined($max)) { $max=99999; }
  282: 
  283:     my (@ids)=&get_reservation_ids($slot_name);
  284:     if (&Apache::lonnet::error(@ids)) { 
  285: 	return 'error: Unable to determine current status';
  286:     }
  287:     my $last=0;
  288:     foreach my $id (@ids) {
  289: 	my $num=(split('\0',$id))[1];
  290: 	if ($num > $last) { $last=$num; }
  291:     }
  292:     
  293:     my $wanted=$last+1;
  294:     &Apache::lonxml::debug("wanted $wanted<br />");
  295:     if (scalar(@ids) >= $max) {
  296: 	# full up
  297: 	return undef;
  298:     }
  299:     
  300:     my %reservation=('name'      => $env{'user.name'}.':'.$env{'user.domain'},
  301: 		     'timestamp' => time,
  302: 		     'symb'      => $parm_symb);
  303: 
  304:     my $success=&Apache::lonnet::newput('slot_reservations',
  305: 					{"$slot_name\0$wanted" =>
  306: 					     \%reservation},
  307: 					$cdom, $cnum);
  308: 
  309:     if ($success eq 'ok') {
  310: 	my $new_value=$slot_name;
  311: 	if ($value) {
  312: 	    $new_value=$value.':'.$new_value;
  313: 	}
  314:         &store_slot_parm($symb,$slot_name,$parm_level,$new_value,$cnum,$cdom);
  315: 	return $wanted;
  316:     }
  317: 
  318:     # someone else got it
  319:     return undef;
  320: }
  321: 
  322: sub store_slot_parm {
  323:     my ($symb,$slot_name,$parm_level,$new_value,$cnum,$cdom) = @_;
  324:     my $result=&Apache::lonparmset::storeparm_by_symb($symb,
  325:                                                   '0_availablestudent',
  326:                                                    $parm_level, $new_value,
  327:                                                    'string',
  328:                                                    $env{'user.name'},
  329:                                                    $env{'user.domain'});
  330:     &Apache::lonxml::debug("hrrm $result");
  331:     my %storehash = (
  332:                        symb    => $symb,
  333:                        slot    => $slot_name,
  334:                        action  => 'reserve',
  335:                        context => $env{'form.context'},
  336:                     );
  337: 
  338:     &Apache::lonnet::instructor_log('slotreservationslog',\%storehash,
  339:                                     '',$env{'user.name'},$env{'user.domain'},
  340:                                     $cnum,$cdom);
  341:     &Apache::lonnet::instructor_log($cdom.'_'.$cnum.'_slotlog',\%storehash,
  342:                                     1,$env{'user.name'},$env{'user.domain'},
  343:                                     $env{'user.name'},$env{'user.domain'});
  344: 
  345:     return;
  346: }
  347: 
  348: sub remove_registration {
  349:     my ($r) = @_;
  350:     if ($env{'form.entry'} ne 'remove all') {
  351: 	return &remove_registration_user($r);
  352:     }
  353:     my $slot_name = $env{'form.slotname'};
  354:     my %slot=&Apache::lonnet::get_slot($slot_name);
  355: 
  356:     my ($cnum,$cdom)=&get_course();
  357:     my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
  358: 				       "^$slot_name\0");
  359:     if (&Apache::lonnet::error(%consumed)) {
  360: 	$r->print("<p><span class=\"LC_error\">".&mt('A network error has occurred.').'</span></p>');
  361: 	return;
  362:     }
  363:     if (!%consumed) {
  364: 	$r->print('<p>'.&mt('Slot [_1] has no reservations.',
  365: 			    '<tt>'.$slot_name.'</tt>').'</p>');
  366: 	return;
  367:     }
  368: 
  369:     my @names = map { $consumed{$_}{'name'} } (sort(keys(%consumed)));
  370:     my $names = join(' ',@names);
  371: 
  372:     my $msg = &mt('Remove all of [_1] from slot [_2]?',$names,$slot_name);
  373:     &remove_registration_confirmation($r,$msg,['entry','slotname','context']);
  374: }
  375: 
  376: sub remove_registration_user {
  377:     my ($r) = @_;
  378:     
  379:     my $slot_name = $env{'form.slotname'};
  380: 
  381:     my $name = &Apache::loncommon::plainname($env{'form.uname'},
  382: 					     $env{'form.udom'});
  383: 
  384:     my $title = &Apache::lonnet::gettitle($env{'form.symb'});
  385: 
  386:     my $msg = &mt('Remove [_1] from slot [_2] for [_3]',
  387: 		  $name,$slot_name,$title);
  388:     
  389:     &remove_registration_confirmation($r,$msg,['uname','udom','slotname',
  390: 					       'entry','symb','context']);
  391: }
  392: 
  393: sub remove_registration_confirmation {
  394:     my ($r,$msg,$inputs) =@_;
  395: 
  396:     my $hidden_input;
  397:     foreach my $parm (@{$inputs}) {
  398: 	$hidden_input .=
  399: 	    '<input type="hidden" name="'.$parm.'" value="'
  400: 	    .&HTML::Entities::encode($env{'form.'.$parm},'"<>&\'').'" />'."\n";
  401:     }
  402:     my %lt = &Apache::lonlocal::texthash(
  403:         'yes' => 'Yes',
  404:         'no'  => 'No',
  405:     );
  406:     $r->print(<<"END_CONFIRM");
  407: <p> $msg </p>
  408: <form action="/adm/slotrequest" method="post">
  409:     <input type="hidden" name="command" value="release" />
  410:     <input type="hidden" name="button" value="yes" />
  411:     $hidden_input
  412:     <input type="submit" value="$lt{'yes'}" />
  413: </form>
  414: <form action="/adm/slotrequest" method="post">
  415:     <input type="hidden" name="command" value="showslots" />
  416:     <input type="submit" value="$lt{'no'}" />
  417: </form>
  418: END_CONFIRM
  419: 
  420: }
  421: 
  422: sub release_all_slot {
  423:     my ($r,$mgr)=@_;
  424:     
  425:     my $slot_name = $env{'form.slotname'};
  426: 
  427:     my ($cnum,$cdom)=&get_course();
  428: 
  429:     my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
  430: 				       "^$slot_name\0");
  431:     
  432:     $r->print('<p>'.&mt('Releasing reservations').'</p>');
  433: 
  434:     foreach my $entry (sort { $consumed{$a}{'name'} cmp 
  435: 				  $consumed{$b}{'name'} } (keys(%consumed))) {
  436: 	my ($uname,$udom) = split(':',$consumed{$entry}{'name'});
  437: 	my ($result,$msg) =
  438: 	    &release_reservation($slot_name,$uname,$udom,
  439: 				 $consumed{$entry}{'symb'},$mgr);
  440:         if (!$result) {
  441:             $r->print('<p><span class="LC_error">'.&mt($msg).'</span></p>');
  442:         } else {
  443: 	    $r->print("<p>$msg</p>");
  444:         }
  445: 	$r->rflush();
  446:     }
  447:     $r->print('<p><a href="/adm/slotrequest?command=showslots">'.
  448: 	      &mt('Return to slot list').'</a></p>');
  449:     &return_link($r);
  450: }
  451: 
  452: sub release_slot {
  453:     my ($r,$symb,$slot_name,$inhibit_return_link,$mgr)=@_;
  454: 
  455:     if ($slot_name eq '') { $slot_name=$env{'form.slotname'}; }
  456: 
  457:     my ($uname,$udom) = ($env{'user.name'}, $env{'user.domain'});
  458:     if ($mgr eq 'F' 
  459: 	&& defined($env{'form.uname'}) && defined($env{'form.udom'})) {
  460: 	($uname,$udom) = ($env{'form.uname'}, $env{'form.udom'});
  461:     }
  462: 
  463:     if ($mgr eq 'F' 
  464: 	&& defined($env{'form.symb'})) {
  465: 	$symb = &unescape($env{'form.symb'});
  466:     }
  467: 
  468:     my ($result,$msg) =
  469: 	&release_reservation($slot_name,$uname,$udom,$symb,$mgr);
  470:     if (!$result) {
  471:         $r->print('<p><span class="LC_error">'.&mt($msg).'</span></p>');
  472:     } else {
  473:         $r->print("<p>$msg</p>");
  474:     }
  475:     
  476:     if ($mgr eq 'F') {
  477: 	$r->print('<p><a href="/adm/slotrequest?command=showslots">'.
  478: 		  &mt('Return to slot list').'</a></p>');
  479:     }
  480: 
  481:     if (!$inhibit_return_link) { &return_link($r);  }
  482:     return $result;
  483: }
  484: 
  485: sub release_reservation {
  486:     my ($slot_name,$uname,$udom,$symb,$mgr) = @_;
  487:     my %slot=&Apache::lonnet::get_slot($slot_name);
  488:     my $description=&get_description($slot_name,\%slot);
  489: 
  490:     if ($mgr ne 'F') {
  491: 	if ($slot{'starttime'} < time) {
  492: 	    return (0,&mt('Not allowed to release Reservation: [_1], as it has already ended.',$description));
  493: 	}
  494:     }
  495: 
  496:     # if the reservation symb is for a map get a resource in that map
  497:     # to check slot parameters on
  498:     my $navmap=Apache::lonnavmaps::navmap->new;
  499:     if (!defined($navmap)) {
  500:         return (0,'error: Unable to determine current status');
  501:     }
  502:     my $passed_resource = $navmap->getBySymb($symb);
  503:     if ($passed_resource->is_map()) {
  504: 	my ($a_resource) = 
  505: 	    $navmap->retrieveResources($passed_resource, 
  506: 				       sub {$_[0]->is_problem()},0,1);
  507: 	$symb = $a_resource->symb();
  508:     }
  509: 
  510:     # get parameter string, check for existance, rebuild string with the slot
  511:     my $student = &Apache::lonnet::EXT("resource.0.availablestudent",
  512:                                        $symb,$udom,$uname);
  513:     my @slots = split(/:/,$student);
  514: 
  515:     my @new_slots;
  516:     foreach my $exist_slot (@slots) {
  517: 	if ($exist_slot eq $slot_name) { next; }
  518: 	push(@new_slots,$exist_slot);
  519:     }
  520:     my $new_param = join(':',@new_slots);
  521: 
  522:     my ($cnum,$cdom)=&get_course();
  523: 
  524:     # get slot reservations, check if user has one, if so remove reservation
  525:     my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
  526: 				       "^$slot_name\0");
  527:     foreach my $entry (keys(%consumed)) {
  528: 	if ( $consumed{$entry}->{'name'} eq ($uname.':'.$udom) ) {
  529: 	    &Apache::lonnet::del('slot_reservations',[$entry],
  530: 				 $cdom,$cnum);
  531:             my %storehash = (
  532:                                symb    => $symb,
  533:                                slot    => $slot_name,
  534:                                action  => 'release',
  535:                                context => $env{'form.context'},
  536:                         );
  537:             &Apache::lonnet::instructor_log('slotreservationslog',\%storehash,
  538:                                             1,$uname,$udom,$cnum,$cdom);
  539:             &Apache::lonnet::instructor_log($cdom.'_'.$cnum.'_slotlog',\%storehash,
  540:                                             1,$uname,$udom,$uname,$udom);
  541: 	}
  542:     }
  543: 
  544:     my $use_slots = &Apache::lonnet::EXT("resource.0.useslots",
  545: 					 $symb,$udom,$uname);
  546:     &Apache::lonxml::debug("use_slots is  $use_slots<br />");
  547: 
  548:     if (&Apache::lonnet::error($use_slots)) { 
  549: 	return (0,'error: Unable to determine current status');
  550:     }
  551: 
  552:     my $parm_level = 1;
  553:     if ($use_slots eq 'map' || $use_slots eq 'map_map') {
  554: 	$parm_level = 2;
  555:     }
  556:     # store new parameter string
  557:     my $result=&Apache::lonparmset::storeparm_by_symb($symb,
  558: 						      '0_availablestudent',
  559: 						      $parm_level, $new_param,
  560: 						      'string', $uname, $udom);
  561:     my $msg;
  562:     if ($mgr eq 'F') {
  563: 	$msg = &mt('Released Reservation for user: [_1]',"$uname:$udom");
  564:     } else {
  565: 	$msg = &mt('Released Reservation: [_1]',$description);
  566:     }
  567:     return (1,$msg);
  568: }
  569: 
  570: sub delete_slot {
  571:     my ($r)=@_;
  572: 
  573:     my $slot_name = $env{'form.slotname'};
  574:     my %slot=&Apache::lonnet::get_slot($slot_name);
  575: 
  576:     my ($cnum,$cdom)=&get_course();
  577:     my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
  578: 				       "^$slot_name\0");
  579:     my ($tmp) = %consumed;
  580:     if ($tmp =~ /error: 2/) { undef(%consumed); }
  581: 
  582:     if (%slot && !%consumed) {
  583: 	$slot{'type'} = 'deleted';
  584: 	my $ret = &Apache::lonnet::cput('slots', {$slot_name => \%slot},
  585: 					$cdom, $cnum);
  586: 	if ($ret eq 'ok') {
  587: 	    $r->print('<p>'.&mt('Slot [_1] marked as deleted.','<tt>'.$slot_name.'</tt>').'</p>');
  588: 	} else {
  589: 	    $r->print('<p><span class="LC_error">'.&mt('An error occurred when attempting to delete slot: [_1]','<tt>'.$slot_name.'</tt>')." ($ret)</span></p>");
  590: 	}
  591:     } else {
  592: 	if (%consumed) {
  593: 	    $r->print('<p>'.&mt('Slot [_1] has active reservations.','<tt>'.$slot_name.'</tt>').'</p>');
  594: 	} else {
  595: 	    $r->print('<p>'.&mt('Slot [_1] does not exist.','<tt>'.$slot_name.'</tt>').'</p>');
  596: 	}
  597:     }
  598:     $r->print('<p><a href="/adm/slotrequest?command=showslots">'.
  599: 	      &mt('Return to slot list').'</a></p>');
  600:     &return_link($r);
  601: }
  602: 
  603: sub return_link {
  604:     my ($r) = @_;
  605:     if (($env{'form.command'} eq 'manageresv') || ($env{'form.context'} eq 'usermanage')) {
  606: 	$r->print('<p><a href="/adm/slotrequest?command=manageresv">'.
  607:                   &mt('Return to reservations'));  
  608:     } else {
  609:         $r->print('<p><a href="/adm/flip?postdata=return:">'.
  610: 	          &mt('Return to last resource').'</a></p>');
  611:     }
  612: }
  613: 
  614: sub get_slot {
  615:     my ($r,$symb,$conflictable_slot,$inhibit_return_link)=@_;
  616: 
  617:     my %slot=&Apache::lonnet::get_slot($env{'form.slotname'});
  618:     my $slot_name=&check_for_conflict($symb,$env{'form.slotname'},\%slot);
  619: 
  620:     if ($slot_name =~ /^error: (.*)/) {
  621: 	$r->print('<p><span class="LC_error">'
  622:                  .&mt('An error occurred while attempting to make a reservation. ([_1])',$1)
  623:                  .'</span></p>');
  624: 	&return_link($r);
  625: 	return 0;
  626:     }
  627:     if ($slot_name && $slot_name ne $conflictable_slot) {
  628: 	my %slot=&Apache::lonnet::get_slot($slot_name);
  629: 	my $description1=&get_description($slot_name,\%slot);
  630: 	%slot=&Apache::lonnet::get_slot($env{'form.slotname'});
  631: 	my $description2=&get_description($env{'form.slotname'},\%slot);
  632: 	$r->print('<p>'.&mt('Already have a reservation: [_1].',$description1).'</p>');
  633: 	if ($slot_name ne $env{'form.slotname'}) {
  634: 	    $r->print(<<STUFF);
  635: <form method="post" action="/adm/slotrequest">
  636:    <input type="hidden" name="symb" value="$env{'form.symb'}" />
  637:    <input type="hidden" name="slotname" value="$env{'form.slotname'}" />
  638:    <input type="hidden" name="releaseslot" value="$slot_name" />
  639:    <input type="hidden" name="command" value="change" />
  640: STUFF
  641:             $r->print('<p>'
  642:                      .&mt('You can either [_1]Change[_2] your reservation from [_3] to [_4] or'
  643:                          ,'<input type="submit" name="change" value="'
  644:                          ,'" />'
  645:                          ,'<b>'.$description1.'</b>'
  646:                          ,'<b>'.$description2.'</b>')
  647:                      .'<br /></p>'
  648:             );
  649: 	    &return_link($r);
  650: 	    $r->print(<<STUFF);
  651: </form>
  652: STUFF
  653:         } else {
  654: 	    &return_link($r);
  655: 	}
  656: 	return 0;
  657:     }
  658: 
  659:     my ($cnum,$cdom)=&get_course();
  660:     my $reserved=&make_reservation($env{'form.slotname'},
  661: 				   \%slot,$symb,$cnum,$cdom);
  662:     my $description=&get_description($env{'form.slotname'},\%slot);
  663:     if (defined($reserved)) {
  664: 	my $retvalue = 0;
  665: 	if ($slot_name =~ /^error: (.*)/) {
  666: 	    $r->print('<p><span class="LC_error">'
  667:                      .&mt('An error occurred while attempting to make a reservation. ([_1])',$1)
  668:                      .'</span></p>');
  669: 	} elsif ($reserved > -1) {
  670: 	    $r->print('<p>'.&mt('Success: [_1]',$description).'</p>');
  671: 	    $retvalue = 1;
  672: 	} elsif ($reserved < 0) {
  673: 	    $r->print('<p>'.&mt('Already reserved: [_1]',$description).'</p>');
  674: 	}
  675: 	if (!$inhibit_return_link) { &return_link($r); }
  676: 	return 1;
  677:     }
  678: 
  679:     my %lt = &Apache::lonlocal::texthash(
  680:         'request' => 'Availibility list',
  681:         'try'     => 'Try again?',
  682:         'or'      => 'or',
  683:     );
  684: 
  685:     my $extra_input;
  686:     if ($conflictable_slot) {
  687: 	$extra_input='<input type="hidden" name="releaseslot" value="'.$env{'form.slotname'}.'" />';
  688:     }
  689: 
  690:     $r->print('<p>'.&mt('[_1]Failed[_2] to reserve a slot for [_3].','<span class="LC_warning">','</span>',$description).'</p>');
  691:     $r->print(<<STUFF);
  692: <p>
  693: <form method="post" action="/adm/slotrequest">
  694:    <input type="submit" name="Try Again" value="$lt{'try'}" />
  695:    <input type="hidden" name="symb" value="$env{'form.symb'}" />
  696:    <input type="hidden" name="slotname" value="$env{'form.slotname'}" />
  697:    <input type="hidden" name="command" value="$env{'form.command'}" />
  698:    $extra_input
  699: </form>
  700: </p>
  701: <p>
  702: $lt{'or'}
  703: <form method="post" action="/adm/slotrequest">
  704:     <input type="hidden" name="symb" value="$env{'form.symb'}" />
  705:     <input type="submit" name="requestattempt" value="$lt{'request'}" />
  706: </form>
  707: STUFF
  708: 
  709:     if (!$inhibit_return_link) { 
  710:         $r->print(&mt('or').'</p>');
  711:         &return_link($r);
  712:     } else {
  713:         $r->print('</p>');
  714:     }
  715:     return 0;
  716: }
  717: 
  718: sub allowed_slot {
  719:     my ($slot_name,$slot,$symb,$slots,$consumed_uniqueperiods)=@_;
  720: 
  721:     #already started
  722:     if ($slot->{'starttime'} < time) {
  723: 	return 0;
  724:     }
  725:     &Apache::lonxml::debug("$slot_name starttime good");
  726: 
  727:     #already ended
  728:     if ($slot->{'endtime'} < time) {
  729: 	return 0;
  730:     }
  731:     &Apache::lonxml::debug("$slot_name endtime good");
  732: 
  733:     # not allowed to pick this one
  734:     if (defined($slot->{'type'})
  735: 	&& $slot->{'type'} ne 'schedulable_student') {
  736: 	return 0;
  737:     }
  738:     &Apache::lonxml::debug("$slot_name type good");
  739: 
  740:     # reserve time not yet started
  741:     if ($slot->{'startreserve'} > time) {
  742: 	return 0;
  743:     }
  744:     &Apache::lonxml::debug("$slot_name reserve good");
  745: 
  746:     my $userallowed=0;
  747:     # its for a different set of users
  748:     if (defined($slot->{'allowedsections'})) {
  749: 	if (!defined($env{'request.role.sec'})
  750: 	    && grep(/^No section assigned$/,
  751: 		    split(',',$slot->{'allowedsections'}))) {
  752: 	    $userallowed=1;
  753: 	}
  754: 	if (defined($env{'request.role.sec'})
  755: 	    && grep(/^\Q$env{'request.role.sec'}\E$/,
  756: 		    split(',',$slot->{'allowedsections'}))) {
  757: 	    $userallowed=1;
  758: 	}
  759: 	if (defined($env{'request.course.groups'})) {
  760: 	    my @groups = split(/:/,$env{'request.course.groups'});
  761: 	    my @allowed_sec = split(',',$slot->{'allowedsections'});
  762: 	    foreach my $group (@groups) {
  763: 		if (grep {$_ eq $group} (@allowed_sec)) {
  764: 		    $userallowed=1;
  765: 		    last;
  766: 		}
  767: 	    }
  768: 	}
  769:     }
  770:     &Apache::lonxml::debug("$slot_name sections is $userallowed");
  771: 
  772:     # its for a different set of users
  773:     if (defined($slot->{'allowedusers'})
  774: 	&& grep(/^\Q$env{'user.name'}:$env{'user.domain'}\E$/,
  775: 		split(',',$slot->{'allowedusers'}))) {
  776: 	$userallowed=1;
  777:     }
  778: 
  779:     if (!defined($slot->{'allowedusers'})
  780: 	&& !defined($slot->{'allowedsections'})) {
  781: 	$userallowed=1;
  782:     }
  783: 
  784:     &Apache::lonxml::debug("$slot_name user is $userallowed");
  785:     return 0 if (!$userallowed);
  786: 
  787:     # not allowed for this resource
  788:     if (defined($slot->{'symb'})
  789: 	&& $slot->{'symb'} ne $symb) {
  790: 	return 0;
  791:     }
  792: 
  793:     my $conflict = &check_for_conflict($symb,$slot_name,$slot,$slots,
  794: 				       $consumed_uniqueperiods);
  795:     if ($conflict =~ /^error: /) {
  796:         return 0;
  797:     } elsif ($conflict ne '') {
  798: 	if ($slots->{$conflict}{'starttime'} < time) {
  799: 	    return 0;
  800: 	}
  801:     }
  802:     &Apache::lonxml::debug("$slot_name symb good");
  803:     return 1;
  804: }
  805: 
  806: sub get_description {
  807:     my ($slot_name,$slot)=@_;
  808:     my $description=$slot->{'description'};
  809:     if (!defined($description)) {
  810: 	$description=&mt('[_1] From [_2] to [_3]',$slot_name,
  811: 			 &Apache::lonlocal::locallocaltime($slot->{'starttime'}),
  812: 			 &Apache::lonlocal::locallocaltime($slot->{'endtime'}));
  813:     }
  814:     return $description;
  815: }
  816: 
  817: sub show_choices {
  818:     my ($r,$symb,$formname)=@_;
  819: 
  820:     my ($cnum,$cdom)=&get_course();
  821:     my %slots=&Apache::lonnet::dump('slots',$cdom,$cnum);
  822:     my $consumed_uniqueperiods = &get_consumed_uniqueperiods(\%slots);
  823:     if (ref($consumed_uniqueperiods) eq 'HASH') {
  824:         if (&Apache::lonnet::error(%$consumed_uniqueperiods)) {
  825:             $r->print('<span class="LC_error">'.
  826:                       &mt('An error occurred determining slot availability').
  827:                       '</span>');
  828:             return;
  829:         }
  830:     } elsif ($consumed_uniqueperiods =~ /^error: /) {
  831:         $r->print('<span class="LC_error">'.
  832:                   &mt('An error occurred determining slot availability').
  833:                   '</span>');
  834:         return;
  835:     }
  836:     my (@available,$output);
  837:     &Apache::lonxml::debug("Checking Slots");
  838:     my @got_slots=&check_for_reservation($symb,'allslots');
  839:     if ($got_slots[0] =~ /^error: /) {
  840:         $r->print('<span class="LC_error">'.
  841:                   &mt('An error occurred determining slot availability').
  842:                   '</span>');
  843:         return;
  844:     }
  845:     foreach my $slot (sort 
  846: 		      { return $slots{$a}->{'starttime'} <=> $slots{$b}->{'starttime'} }
  847: 		      (keys(%slots)))  {
  848: 
  849: 	&Apache::lonxml::debug("Checking Slot $slot");
  850: 	next if (!&allowed_slot($slot,$slots{$slot},$symb,\%slots,
  851: 				$consumed_uniqueperiods));
  852: 
  853:         push(@available,$slot);
  854:     }
  855:     if (!@available) {
  856:         $output = &mt('No available times.');
  857:         if ($env{'form.command'} ne 'manageresv') {
  858:             $output .= ' <a href="/adm/flip?postdata=return:">'.
  859:                        &mt('Return to last resource').'</a>';
  860:         }
  861:         $r->print($output);
  862:         return;
  863:     }
  864:     if ($env{'form.command'} eq 'manageresv') {
  865:         $output = '<table border="0">';
  866:     } else {
  867:         $output = &Apache::loncommon::start_data_table();
  868:     }
  869:     foreach my $slot (@available) { 
  870: 	my $description=&get_description($slot,$slots{$slot});
  871: 	my $form;
  872: 	if ((grep(/^\Q$slot\E$/,@got_slots)) ||
  873: 	    &space_available($slot,$slots{$slot},$symb)) {
  874: 	    my $text=&mt('Select');
  875: 	    my $command='get';
  876: 	    if (grep(/^\Q$slot\E$/,@got_slots)) {
  877: 		$text=&mt('Drop Reservation');
  878: 		$command='release';
  879: 	    } else {
  880: 		my $conflict = &check_for_conflict($symb,$slot,$slots{$slot},
  881: 						   \%slots,
  882: 						   $consumed_uniqueperiods);
  883:                 if ($conflict) {
  884:                     if ($conflict =~ /^error: /) {
  885:                         $form = '<span class="LC_error">'.
  886:                                 &mt('Slot: [_1] has unknown status.',$description).
  887:                                 '</span>';
  888:                     } else {
  889: 		        $text=&mt('Change Reservation');
  890: 		        $command='get';
  891: 		    }
  892:                 }
  893: 	    }
  894: 	    my $escsymb=&escape($symb);
  895:             if (!$form) {
  896:                 if ($formname) {
  897:                     $formname = 'name="'.$formname.'" ';
  898:                 }
  899:                 my $context = 'user';
  900:                 if ($env{'form.command'} eq 'manageresv') {
  901:                     $context = 'usermanage';
  902:                 }
  903: 	        $form=<<STUFF;
  904:    <form method="post" action="/adm/slotrequest" $formname>
  905:      <input type="submit" name="Select" value="$text" />
  906:      <input type="hidden" name="symb" value="$escsymb" />
  907:      <input type="hidden" name="slotname" value="$slot" />
  908:      <input type="hidden" name="command" value="$command" />
  909:      <input type="hidden" name="context" value="$context" />
  910:    </form>
  911: STUFF
  912: 	    }
  913:         } else {
  914:             $form = &mt('Unavailable');
  915:         }
  916:         if ($env{'form.command'} eq 'manageresv') {
  917:             $output .= '<tr>';
  918:         } else {
  919: 	    $output .= &Apache::loncommon::start_data_table_row();
  920:         }
  921:         $output .= " 
  922:  <td>$form</td>
  923:  <td>$description</td>\n";
  924:         if ($env{'form.command'} eq 'manageresv') {
  925:             $output .= '</tr>';
  926:         } else {
  927:             $output .= &Apache::loncommon::end_data_table_row();
  928:         }
  929:     }
  930:     if ($env{'form.command'} eq 'manageresv') {
  931:         $output .= '</table>';
  932:     } else {
  933:        $output .= &Apache::loncommon::end_data_table();
  934:     }
  935:     $r->print($output);
  936: }
  937: 
  938: sub to_show {
  939:     my ($slotname,$slot,$when,$deleted,$name) = @_;
  940:     my $time=time;
  941:     my $week=60*60*24*7;
  942: 
  943:     if ($deleted eq 'hide' && $slot->{'type'} eq 'deleted') {
  944: 	return 0;
  945:     }
  946: 
  947:     if ($name && $name->{'value'} =~ /\w/) {
  948: 	if ($name->{'type'} eq 'substring') {
  949: 	    if ($slotname !~ /\Q$name->{'value'}\E/) {
  950: 		return 0;
  951: 	    }
  952: 	}
  953: 	if ($name->{'type'} eq 'exact') {
  954: 	    if ($slotname eq $name->{'value'}) {
  955: 		return 0;
  956: 	    }
  957: 	}
  958:     }
  959: 
  960:     if ($when eq 'any') {
  961: 	return 1;
  962:     } elsif ($when eq 'now') {
  963: 	if ($time > $slot->{'starttime'} &&
  964: 	    $time < $slot->{'endtime'}) {
  965: 	    return 1;
  966: 	}
  967: 	return 0;
  968:     } elsif ($when eq 'nextweek') {
  969: 	if ( ($time        < $slot->{'starttime'} &&
  970: 	      ($time+$week) > $slot->{'starttime'})
  971: 	     ||
  972: 	     ($time        < $slot->{'endtime'} &&
  973: 	      ($time+$week) > $slot->{'endtime'}) ) {
  974: 	    return 1;
  975: 	}
  976: 	return 0;
  977:     } elsif ($when eq 'lastweek') {
  978: 	if ( ($time        > $slot->{'starttime'} &&
  979: 	      ($time-$week) < $slot->{'starttime'})
  980: 	     ||
  981: 	     ($time        > $slot->{'endtime'} &&
  982: 	      ($time-$week) < $slot->{'endtime'}) ) {
  983: 	    return 1;
  984: 	}
  985: 	return 0;
  986:     } elsif ($when eq 'willopen') {
  987: 	if ($time < $slot->{'starttime'}) {
  988: 	    return 1;
  989: 	}
  990: 	return 0;
  991:     } elsif ($when eq 'wereopen') {
  992: 	if ($time > $slot->{'endtime'}) {
  993: 	    return 1;
  994: 	}
  995: 	return 0;
  996:     }
  997:     
  998:     return 1;
  999: }
 1000: 
 1001: sub remove_link {
 1002:     my ($slotname,$entry,$uname,$udom,$symb) = @_;
 1003: 
 1004:     my $remove = &mt('Remove');
 1005: 
 1006:     if ($entry eq 'remove all') {
 1007: 	$remove = &mt('Remove All');
 1008: 	undef($uname);
 1009: 	undef($udom);
 1010:     }
 1011: 
 1012:     $slotname  = &escape($slotname);
 1013:     $entry     = &escape($entry);
 1014:     $uname     = &escape($uname);
 1015:     $udom      = &escape($udom);
 1016:     $symb      = &escape($symb);
 1017: 
 1018:     return <<"END_LINK";
 1019:  <a href="/adm/slotrequest?command=remove_registration&amp;slotname=$slotname&amp;entry=$entry&amp;uname=$uname&amp;udom=$udom&amp;symb=$symb&amp;context=manage"
 1020:    >($remove)</a>
 1021: END_LINK
 1022: 
 1023: }
 1024: 
 1025: sub show_table {
 1026:     my ($r,$mgr)=@_;
 1027: 
 1028:     my ($cnum,$cdom)=&get_course();
 1029:     my $crstype=&Apache::loncommon::course_type($cdom.'_'.$cnum);
 1030:     my %slots=&Apache::lonnet::dump('slots',$cdom,$cnum);
 1031:     if ( (keys(%slots))[0] =~ /^error: 2 /) {
 1032: 	undef(%slots);
 1033:     } 
 1034:     my $available;
 1035:     if ($mgr eq 'F') {
 1036:     # FIXME: This line should be deleted once Slots uses breadcrumbs
 1037:     $r->print(&Apache::loncommon::help_open_topic('Slot About', 'Help on slots'));
 1038: 
 1039: 	$r->print('<div>');
 1040: 	$r->print('<form method="post" action="/adm/slotrequest">
 1041: <input type="hidden" name="command" value="uploadstart" />
 1042: <input type="submit" name="start" value="'.&mt('Upload Slot List').'" />
 1043: </form>');
 1044: 	$r->print(&Apache::loncommon::help_open_topic('Slot CommaDelimited'));
 1045: 	$r->print('<form method="post" action="/adm/helper/newslot.helper">
 1046: <input type="submit" name="newslot" value="'.&mt('Create a New Slot').'" />
 1047: </form>');
 1048: 	$r->print(&Apache::loncommon::help_open_topic('Slot AddInterface'));
 1049: 	$r->print('</div>');
 1050:     }
 1051: 
 1052:     if (!keys(%slots)) {
 1053:         if ($crstype eq 'Community') {
 1054:             $r->print('<div>'.&mt('No slots have been created in this community.').'</div>');
 1055:         } else {
 1056:             $r->print('<div>'.&mt('No slots have been created in this course.').'</div>');
 1057:         }
 1058:         return;
 1059:     }
 1060:     
 1061:     my %Saveable_Parameters = ('show'              => 'array',
 1062: 			       'when'              => 'scalar',
 1063: 			       'order'             => 'scalar',
 1064: 			       'deleted'           => 'scalar',
 1065: 			       'name_filter_type'  => 'scalar',
 1066: 			       'name_filter_value' => 'scalar',
 1067: 			       );
 1068:     &Apache::loncommon::store_course_settings('slotrequest',
 1069: 					      \%Saveable_Parameters);
 1070:     &Apache::loncommon::restore_course_settings('slotrequest',
 1071: 						\%Saveable_Parameters);
 1072:     &Apache::grades::init_perm();
 1073:     my ($classlist,$section,$fullname)=&Apache::grades::getclasslist('all');
 1074:     &Apache::grades::reset_perm();
 1075: 
 1076:     # what to display filtering
 1077:     my %show_fields=&Apache::lonlocal::texthash(
 1078: 	     'name'            => 'Slot Name',
 1079: 	     'description'     => 'Description',
 1080: 	     'type'            => 'Type',
 1081: 	     'starttime'       => 'Start time',
 1082: 	     'endtime'         => 'End Time',
 1083:              'startreserve'    => 'Time students can start reserving',
 1084: 	     'secret'          => 'Secret Word',
 1085: 	     'space'           => '# of students/max',
 1086: 	     'ip'              => 'IP or DNS restrictions',
 1087: 	     'symb'            => 'Resource slot is restricted to.',
 1088: 	     'allowedsections' => 'Sections slot is restricted to.',
 1089: 	     'allowedusers'    => 'Users slot is restricted to.',
 1090: 	     'uniqueperiod'    => 'Period of time slot is unique',
 1091: 	     'scheduled'       => 'Scheduled Students',
 1092: 	     'proctor'         => 'List of proctors');
 1093:     if ($crstype eq 'Community') {
 1094:         $show_fields{'startreserve'} = &mt('Time members can start reserving');
 1095:         $show_fields{'scheduled'} = &mt('Scheduled Members');
 1096:     }
 1097:     my @show_order=('name','description','type','starttime','endtime',
 1098: 		    'startreserve','secret','space','ip','symb',
 1099: 		    'allowedsections','allowedusers','uniqueperiod',
 1100: 		    'scheduled','proctor');
 1101:     my @show = 
 1102: 	(exists($env{'form.show'})) ? &Apache::loncommon::get_env_multiple('form.show')
 1103: 	                            : keys(%show_fields);
 1104:     my %show =  map { $_ => 1 } (@show);
 1105: 
 1106:     #when filtering setup
 1107:     my %when_fields=&Apache::lonlocal::texthash(
 1108: 	     'now'      => 'Open now',
 1109: 	     'nextweek' => 'Open within the next week',
 1110: 	     'lastweek' => 'Were open last week',
 1111: 	     'willopen' => 'Will open later',
 1112: 	     'wereopen' => 'Were open',
 1113: 	     'any'      => 'Anytime',
 1114: 						);
 1115:     my @when_order=('any','now','nextweek','lastweek','willopen','wereopen');
 1116:     $when_fields{'select_form_order'} = \@when_order;
 1117:     my $when = 	(exists($env{'form.when'})) ? $env{'form.when'}
 1118:                                             : 'now';
 1119: 
 1120:     #display of students setup
 1121:     my %stu_display_fields=
 1122: 	&Apache::lonlocal::texthash('username' => 'User name',
 1123: 				    'fullname' => 'Full name',
 1124: 				    );
 1125:     my @stu_display_order=('fullname','username');
 1126:     my @stu_display = 
 1127: 	(exists($env{'form.studisplay'})) ? &Apache::loncommon::get_env_multiple('form.studisplay')
 1128: 	                                  : keys(%stu_display_fields);
 1129:     my %stu_display =  map { $_ => 1 } (@stu_display);
 1130: 
 1131:     #name filtering setup
 1132:     my %name_filter_type_fields=
 1133: 	&Apache::lonlocal::texthash('substring' => 'Substring',
 1134: 				    'exact'     => 'Exact',
 1135: 				    #'reg'       => 'Regular Expression',
 1136: 				    );
 1137:     my @name_filter_type_order=('substring','exact');
 1138: 
 1139:     $name_filter_type_fields{'select_form_order'} = \@name_filter_type_order;
 1140:     my $name_filter_type = 
 1141: 	(exists($env{'form.name_filter_type'})) ? $env{'form.name_filter_type'}
 1142:                                                 : 'substring';
 1143:     my $name_filter = {'type'  => $name_filter_type,
 1144: 		       'value' => $env{'form.name_filter_value'},};
 1145: 
 1146:     
 1147:     #deleted slot filtering
 1148:     #default to hide if no value
 1149:     $env{'form.deleted'} ||= 'hide';
 1150:     my $hide_radio = 
 1151: 	&Apache::lonhtmlcommon::radio('deleted',$env{'form.deleted'},'hide');
 1152:     my $show_radio = 
 1153: 	&Apache::lonhtmlcommon::radio('deleted',$env{'form.deleted'},'show');
 1154: 	
 1155:     $r->print('<form method="post" action="/adm/slotrequest">
 1156: <input type="hidden" name="command" value="showslots" />');
 1157:     $r->print('<div>');
 1158:     $r->print('<table class="inline">
 1159:       <tr><th>'.&mt('Show').'</th>
 1160:           <th>'.&mt('Student Display').'</th>
 1161:           <th>'.&mt('Open').'</th>
 1162:           <th>'.&mt('Slot Name Filter').'</th>
 1163:           <th>'.&mt('Options').'</th>
 1164:       </tr>
 1165:       <tr><td valign="top">'.&Apache::loncommon::multiple_select_form('show',\@show,6,\%show_fields,\@show_order).
 1166: 	      '</td>
 1167:            <td valign="top">
 1168:          '.&Apache::loncommon::multiple_select_form('studisplay',\@stu_display,
 1169: 						    6,\%stu_display_fields,
 1170: 						    \@stu_display_order).'
 1171:            </td>
 1172:            <td valign="top">'.&Apache::loncommon::select_form($when,'when',%when_fields).
 1173:           '</td>
 1174:            <td valign="top">'.&Apache::loncommon::select_form($name_filter_type,
 1175: 						 'name_filter_type',
 1176: 						 %name_filter_type_fields).
 1177: 	      '<br />'.
 1178: 	      &Apache::lonhtmlcommon::textbox('name_filter_value',
 1179: 					      $env{'form.name_filter_value'},
 1180: 					      15).
 1181:           '</td>
 1182:            <td valign="top">
 1183:             <table>
 1184:               <tr>
 1185:                 <td rowspan="2">Deleted slots:</td>
 1186:                 <td><label>'.$show_radio.'Show</label></td>
 1187:               </tr>
 1188:               <tr>
 1189:                 <td><label>'.$hide_radio.'Hide</label></td>
 1190:               </tr>
 1191:             </table>
 1192: 	  </td>
 1193:        </tr>
 1194:     </table>');
 1195:     $r->print('</div>');
 1196:     $r->print('<p><input type="submit" name="start" value="'.&mt('Update Display').'" /></p>');
 1197:     my $linkstart='<a href="/adm/slotrequest?command=showslots&amp;order=';
 1198:     $r->print(&Apache::loncommon::start_data_table().
 1199: 	      &Apache::loncommon::start_data_table_header_row().'
 1200: 	       <th></th>');
 1201:     foreach my $which (@show_order) {
 1202: 	if ($which ne 'proctor' && exists($show{$which})) {
 1203: 	    $r->print('<th>'.$linkstart.$which.'">'.$show_fields{$which}.'</a></th>');
 1204: 	}
 1205:     }
 1206:     $r->print(&Apache::loncommon::end_data_table_header_row());
 1207: 
 1208:     my %name_cache;
 1209:     my $slotsort = sub {
 1210: 	if ($env{'form.order'}=~/^(type|description|endtime|startreserve|ip|symb|allowedsections|allowedusers)$/) {
 1211: 	    if (lc($slots{$a}->{$env{'form.order'}})
 1212: 		ne lc($slots{$b}->{$env{'form.order'}})) {
 1213: 		return (lc($slots{$a}->{$env{'form.order'}}) 
 1214: 			cmp lc($slots{$b}->{$env{'form.order'}}));
 1215: 	    }
 1216: 	} elsif ($env{'form.order'} eq 'space') {
 1217: 	    if ($slots{$a}{'maxspace'} ne $slots{$b}{'maxspace'}) {
 1218: 		return ($slots{$a}{'maxspace'} cmp $slots{$b}{'maxspace'});
 1219: 	    }
 1220: 	} elsif ($env{'form.order'} eq 'name') {
 1221: 	    if (lc($a) cmp lc($b)) {
 1222: 		return lc($a) cmp lc($b);
 1223: 	    }
 1224: 	} elsif ($env{'form.order'} eq 'uniqueperiod') {
 1225: 	    
 1226: 	    if ($slots{$a}->{'uniqueperiod'}[0] 
 1227: 		ne $slots{$b}->{'uniqueperiod'}[0]) {
 1228: 		return ($slots{$a}->{'uniqueperiod'}[0]
 1229: 			cmp $slots{$b}->{'uniqueperiod'}[0]);
 1230: 	    }
 1231: 	    if ($slots{$a}->{'uniqueperiod'}[1] 
 1232: 		ne $slots{$b}->{'uniqueperiod'}[1]) {
 1233: 		return ($slots{$a}->{'uniqueperiod'}[1]
 1234: 			cmp $slots{$b}->{'uniqueperiod'}[1]);
 1235: 	    }
 1236: 	}
 1237: 	return $slots{$a}->{'starttime'} <=> $slots{$b}->{'starttime'};
 1238:     };
 1239: 
 1240:     my %consumed;
 1241:     if (exists($show{'scheduled'}) || exists($show{'space'}) ) {
 1242: 	%consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum);
 1243: 	my ($tmp)=%consumed;
 1244: 	if ($tmp =~ /^error: /) { undef(%consumed); }
 1245:     }
 1246: 
 1247:     foreach my $slot (sort $slotsort (keys(%slots)))  {
 1248: 	if (!&to_show($slot,$slots{$slot},$when,
 1249: 		      $env{'form.deleted'},$name_filter)) { next; }
 1250: 	if (defined($slots{$slot}->{'type'})
 1251: 	    && $slots{$slot}->{'type'} ne 'schedulable_student') {
 1252: 	    #next;
 1253: 	}
 1254: 	my $description=&get_description($slot,$slots{$slot});
 1255: 	my ($id_count,$ids);
 1256: 	    
 1257: 	if (exists($show{'scheduled'}) || exists($show{'space'}) ) {
 1258: 	    my $re_str = "$slot\0";
 1259: 	    my @this_slot = grep(/^\Q$re_str\E/,keys(%consumed));
 1260: 	    $id_count = scalar(@this_slot);
 1261: 	    if (exists($show{'scheduled'})) {
 1262: 		foreach my $entry (sort { $consumed{$a}{name} cmp 
 1263: 					      $consumed{$b}{name} }
 1264: 				   (@this_slot)) {
 1265: 		    my (undef,$id)=split("\0",$entry);
 1266: 		    my ($uname,$udom) = split(':',$consumed{$entry}{'name'});
 1267: 		    $ids.= '<span class="LC_nobreak">';
 1268: 		    foreach my $item (@stu_display_order) {
 1269: 			if ($stu_display{$item}) {
 1270: 			    if ($item eq 'fullname') {
 1271: 				$ids.=$fullname->{"$uname:$udom"}.' ';
 1272: 			    } elsif ($item eq 'username') {
 1273: 				$ids.="<tt>$uname:$udom</tt> ";
 1274: 			    }
 1275: 			}
 1276: 		    }
 1277: 		    $ids.=&remove_link($slot,$entry,$uname,$udom,
 1278: 				       $consumed{$entry}{'symb'}).'</span><br />';
 1279: 		}
 1280: 	    }
 1281: 	}
 1282: 
 1283: 	my $start=($slots{$slot}->{'starttime'}?
 1284: 		   &Apache::lonlocal::locallocaltime($slots{$slot}->{'starttime'}):'');
 1285: 	my $end=($slots{$slot}->{'endtime'}?
 1286: 		 &Apache::lonlocal::locallocaltime($slots{$slot}->{'endtime'}):'');
 1287: 	my $start_reserve=($slots{$slot}->{'startreserve'}?
 1288: 			   &Apache::lonlocal::locallocaltime($slots{$slot}->{'startreserve'}):'');
 1289: 	
 1290: 	my $unique;
 1291: 	if (ref($slots{$slot}{'uniqueperiod'})) {
 1292: 	    $unique=localtime($slots{$slot}{'uniqueperiod'}[0]).', '.
 1293: 		localtime($slots{$slot}{'uniqueperiod'}[1]);
 1294: 	}
 1295: 
 1296: 	my $title;
 1297: 	if (exists($slots{$slot}{'symb'})) {
 1298: 	    my (undef,undef,$res)=
 1299: 		&Apache::lonnet::decode_symb($slots{$slot}{'symb'});
 1300: 	    $res =   &Apache::lonnet::clutter($res);
 1301: 	    $title = &Apache::lonnet::gettitle($slots{$slot}{'symb'});
 1302: 	    $title='<a href="'.$res.'?symb='.$slots{$slot}{'symb'}.'">'.$title.'</a>';
 1303: 	}
 1304: 
 1305: 	my $allowedsections;
 1306: 	if (exists($show{'allowedsections'})) {
 1307: 	    $allowedsections = 
 1308: 		join(', ',sort(split(/\s*,\s*/,
 1309: 				     $slots{$slot}->{'allowedsections'})));
 1310: 	}
 1311: 
 1312: 	my @allowedusers;
 1313: 	if (exists($show{'allowedusers'})) {
 1314: 	    @allowedusers= map {
 1315: 		my ($uname,$udom)=split(/:/,$_);
 1316: 		my $fullname=$name_cache{$_};
 1317: 		if (!defined($fullname)) {
 1318: 		    $fullname = &Apache::loncommon::plainname($uname,$udom);
 1319: 		    $fullname =~s/\s/&nbsp;/g;
 1320: 		    $name_cache{$_} = $fullname;
 1321: 		}
 1322: 		&Apache::loncommon::aboutmewrapper($fullname,$uname,$udom);
 1323: 	    } (sort(split(/\s*,\s*/,$slots{$slot}->{'allowedusers'})));
 1324: 	}
 1325: 	my $allowedusers=join(', ',@allowedusers);
 1326: 	
 1327: 	my @proctors;
 1328: 	my $rowspan=1;
 1329: 	my $colspan=1;
 1330: 	if (exists($show{'proctor'})) {
 1331: 	    $rowspan=2;
 1332: 	    @proctors= map {
 1333: 		my ($uname,$udom)=split(/:/,$_);
 1334: 		my $fullname=$name_cache{$_};
 1335: 		if (!defined($fullname)) {
 1336: 		    $fullname = &Apache::loncommon::plainname($uname,$udom);
 1337: 		    $fullname =~s/\s/&nbsp;/g;
 1338: 		    $name_cache{$_} = $fullname;
 1339: 		}
 1340: 		&Apache::loncommon::aboutmewrapper($fullname,$uname,$udom);
 1341: 	    } (sort(split(/\s*,\s*/,$slots{$slot}->{'proctor'})));
 1342: 	}
 1343: 	my $proctors=join(', ',@proctors);
 1344: 
 1345:         my %lt = &Apache::lonlocal::texthash (
 1346:                                                edit   => 'Edit',
 1347:                                                delete => 'Delete',
 1348:                                                slotlog => 'History',
 1349:         );
 1350: 	my $edit=(<<"EDITLINK");
 1351: <a href="/adm/helper/newslot.helper?name=$slot">$lt{'edit'}</a>
 1352: EDITLINK
 1353: 
 1354: 	my $delete=(<<"DELETELINK");
 1355: <a href="/adm/slotrequest?command=delete&amp;slotname=$slot">$lt{'delete'}</a>
 1356: DELETELINK
 1357: 
 1358:         my $showlog=(<<"LOGLINK");
 1359: <a href="/adm/slotrequest?command=slotlog&amp;slotname=$slot">$lt{'slotlog'}</a>
 1360: LOGLINK
 1361: 
 1362:         my $remove_all=&remove_link($slot,'remove all').'<br />';
 1363: 
 1364:         if ($ids eq '') {
 1365:             undef($remove_all);
 1366:         } else {
 1367:             undef($delete);
 1368:         }
 1369: 	if ($slots{$slot}{'type'} ne 'schedulable_student') {
 1370:             undef($showlog); 
 1371: 	    undef($remove_all);
 1372: 	}
 1373: 
 1374: 	my $row_start=&Apache::loncommon::start_data_table_row();
 1375: 	my $row_end=&Apache::loncommon::end_data_table_row();
 1376:         $r->print($row_start.
 1377: 		  "\n<td rowspan=\"$rowspan\">$edit $delete $showlog</td>\n");
 1378: 	if (exists($show{'name'})) {
 1379: 	    $colspan++;$r->print("<td>$slot</td>");
 1380: 	}
 1381: 	if (exists($show{'description'})) {
 1382: 	    $colspan++;$r->print("<td>$description</td>\n");
 1383: 	}
 1384: 	if (exists($show{'type'})) {
 1385: 	    $colspan++;$r->print("<td>$slots{$slot}->{'type'}</td>\n");
 1386: 	}
 1387: 	if (exists($show{'starttime'})) {
 1388: 	    $colspan++;$r->print("<td>$start</td>\n");
 1389: 	}
 1390: 	if (exists($show{'endtime'})) {
 1391: 	    $colspan++;$r->print("<td>$end</td>\n");
 1392: 	}
 1393: 	if (exists($show{'startreserve'})) {
 1394: 	    $colspan++;$r->print("<td>$start_reserve</td>\n");
 1395: 	}
 1396: 	if (exists($show{'secret'})) {
 1397: 	    $colspan++;$r->print("<td>$slots{$slot}{'secret'}</td>\n");
 1398: 	}
 1399: 	if (exists($show{'space'})) {
 1400: 	    my $display = $id_count;
 1401: 	    if ($slots{$slot}{'maxspace'}>0) {
 1402: 		$display.='/'.$slots{$slot}{'maxspace'};
 1403: 		if ($slots{$slot}{'maxspace'} <= $id_count) {
 1404: 		    $display = '<strong>'.$display.' (full) </strong>';
 1405: 		}
 1406: 	    }
 1407: 	    $colspan++;$r->print("<td>$display</td>\n");
 1408: 	}
 1409: 	if (exists($show{'ip'})) {
 1410: 	    $colspan++;$r->print("<td>$slots{$slot}{'ip'}</td>\n");
 1411: 	}
 1412: 	if (exists($show{'symb'})) {
 1413: 	    $colspan++;$r->print("<td>$title</td>\n");
 1414: 	}
 1415: 	if (exists($show{'allowedsections'})) {
 1416: 	    $colspan++;$r->print("<td>$allowedsections</td>\n");
 1417: 	}
 1418: 	if (exists($show{'allowedusers'})) {
 1419: 	    $colspan++;$r->print("<td>$allowedusers</td>\n");
 1420: 	}
 1421: 	if (exists($show{'uniqueperiod'})) {
 1422: 	    $colspan++;$r->print("<td>$unique</td>\n");
 1423: 	}
 1424: 	if (exists($show{'scheduled'})) {
 1425: 	    $colspan++;$r->print("<td>$remove_all $ids</td>\n");
 1426: 	}
 1427: 	$r->print("$row_end\n");
 1428: 	if (exists($show{'proctor'})) {
 1429: 	    $r->print(<<STUFF);
 1430: $row_start
 1431:  <td colspan="$colspan">$proctors</td>
 1432: $row_end
 1433: STUFF
 1434:         }
 1435:     }
 1436:     $r->print(&Apache::loncommon::end_data_table().'</form>');
 1437:     return;
 1438: }
 1439: 
 1440: sub manage_reservations {
 1441:     my ($r,$crstype) = @_;
 1442:     my $navmap = Apache::lonnavmaps::navmap->new();
 1443:     $r->print('<p>'
 1444:              .&mt('Instructors may use a reservation system to place restrictions on when and where assignments can be worked on.')
 1445:              .'<br />'
 1446:              .&mt('One example is for management of laboratory space, which is only available at certain times, and has a limited number of seats.')
 1447:              .'</p>'
 1448:     );
 1449:     if (!defined($navmap)) {
 1450:         $r->print('<div class="LC_error">');
 1451:         if ($crstype eq 'Community') {
 1452:             $r->print(&mt('Unable to retrieve information about community contents'));
 1453:         } else {
 1454:             $r->print(&mt('Unable to retrieve information about course contents'));
 1455:         }
 1456:         $r->print('</div>');
 1457:         &Apache::lonnet::logthis('Manage Reservations - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
 1458:         return;
 1459:     }
 1460:     my (%parent,%shownparent,%container,%container_title,%contents);
 1461:     my ($depth,$count,$reservable,$lastcontainer,$rownum) = (0,0,0,0,0);
 1462:     my @backgrounds = ("LC_odd_row","LC_even_row");
 1463:     my $numcolors = scalar(@backgrounds);
 1464:     my $location=&Apache::loncommon::lonhttpdurl("/adm/lonIcons/whitespace_21.gif");
 1465:     my $slotheader = '<p>'.
 1466:                  &mt('Your reservation status for any such assignments is listed below:').
 1467:                  '</p>'.
 1468:                  '<table class="LC_data_table LC_tableOfContent">'."\n";
 1469:     my $shownheader = 0;
 1470:     my $it=$navmap->getIterator(undef,undef,undef,1,undef,undef);
 1471:     while (my $resource = $it->next()) {
 1472:         if ($resource == $it->BEGIN_MAP()) {
 1473:             $depth++;
 1474:             $parent{$depth} = $lastcontainer;
 1475:         }
 1476:         if ($resource == $it->END_MAP()) {
 1477:             $depth--;
 1478:             $lastcontainer = $parent{$depth};
 1479:         }
 1480:         if (ref($resource)) {
 1481:             my $symb = $resource->symb();
 1482:             my $ressymb = $symb;
 1483:             $contents{$lastcontainer} ++;
 1484:             next if (!$resource->is_problem() && !$resource->is_sequence() && 
 1485:                      !$resource->is_page());
 1486:             $count ++;
 1487:             if (($resource->is_sequence()) || ($resource->is_page())) {
 1488:                 $lastcontainer = $count;
 1489:                 $container{$lastcontainer} = $resource;
 1490:                 $container_title{$lastcontainer} = $resource->compTitle();
 1491:             }
 1492:             if ($resource->is_problem()) {
 1493:                 my ($useslots) = $resource->slot_control();
 1494:                 next if (($useslots eq '') || ($useslots =~ /^\s*no\s*$/i));
 1495:                 my ($msg,$get_choices,$slotdescription);
 1496:                 my $title = $resource->compTitle();
 1497:                 my $status = $resource->simpleStatus('0');
 1498:                 my ($slot_status,$date,$slot_name) = $resource->check_for_slot('0');
 1499:                 if ($slot_name ne '') {
 1500:                     my %slot=&Apache::lonnet::get_slot($slot_name);
 1501:                     $slotdescription=&get_description($slot_name,\%slot);
 1502:                 }
 1503:                 if ($slot_status == $resource->NOT_IN_A_SLOT) {
 1504:                     $msg=&mt('No current reservation.');
 1505:                     $get_choices = 1;
 1506:                 } elsif ($slot_status == $resource->NEEDS_CHECKIN) {
 1507:                     $msg='<span class="LC_nobreak">'.&mt('Reserved:').
 1508:                          '&nbsp;'.$slotdescription.'</span><br />'.
 1509:                          &mt('Access requires proctor validation.');
 1510:                 } elsif ($slot_status == $resource->WAITING_FOR_GRADE) {
 1511:                     $msg=&mt('Submitted and currently in grading queue.');
 1512:                 } elsif ($slot_status == $resource->CORRECT) {
 1513:                     $msg=&mt('Problem is unavailable.');
 1514:                 } elsif ($slot_status == $resource->RESERVED) {
 1515:                     $msg='<span class="LC_nobreak">'.&mt('Reserved:').
 1516:                          '&nbsp;'.$slotdescription.'</span><br />'.
 1517:                          &mt('Problem is currently available.');
 1518:                 } elsif ($slot_status == $resource->RESERVED_LOCATION) {
 1519:                     $msg='<span class="LC_nobreak">'.&mt('Reserved:').
 1520:                          '&nbsp;'.$slotdescription.'</span><br />'.
 1521:                          &mt('Problem is available at a different location.');
 1522:                     $get_choices = 1;
 1523:                 } elsif ($slot_status == $resource->RESERVED_LATER) {
 1524:                     $msg='<span class="LC_nobreak">'.&mt('Reserved:').
 1525:                          '&nbsp;'.$slotdescription.'</span><br />'.
 1526:                          &mt('Problem will be available later.');
 1527:                     $get_choices = 1;
 1528:                 } elsif ($slot_status == $resource->RESERVABLE) {
 1529:                     $msg=&mt('Reservation needed');
 1530:                     $get_choices = 1;
 1531:                 } elsif ($slot_status == $resource->NOTRESERVABLE) {
 1532:                     $msg=&mt('Reservation needed: none available.');
 1533:                 } elsif ($slot_status == $resource->UNKNOWN) {
 1534:                     $msg=&mt('Unable to determine status due to network problems.');
 1535:                 } else {
 1536:                     if ($status != $resource->OPEN) {
 1537:                         $msg = &Apache::lonnavmaps::getDescription($resource,'0'); 
 1538:                     }
 1539:                 }
 1540:                 $reservable ++;
 1541:                 my $treelevel = $depth;
 1542:                 my $higherup = $lastcontainer;
 1543:                 if ($depth > 1) {
 1544:                     my @maprows;
 1545:                     while ($treelevel > 1) {
 1546:                         if (ref($container{$higherup})) {
 1547:                             my $res = $container{$higherup};
 1548:                             last if (defined($shownparent{$higherup}));
 1549:                             my $maptitle = $res->compTitle();
 1550:                             my $type = 'sequence';
 1551:                             if ($res->is_page()) {
 1552:                                 $type = 'page';
 1553:                             }
 1554:                             &show_map_row($treelevel,$location,$type,$maptitle,
 1555:                                           \@maprows);
 1556:                             $shownparent{$higherup} = 1;
 1557:                         }
 1558:                         $treelevel --;
 1559:                         $higherup = $parent{$treelevel};
 1560:                     }
 1561:                     foreach my $item (@maprows) {
 1562:                         $rownum ++;
 1563:                         my $bgcolor = $backgrounds[$rownum % $numcolors];
 1564:                         if (!$shownheader) {
 1565:                             $r->print($slotheader);
 1566:                             $shownheader = 1;
 1567:                         }
 1568:                         $r->print('<tr class="'.$bgcolor.'">'.$item.'</tr>'."\n");
 1569:                     }
 1570:                 }
 1571:                 $rownum ++;
 1572:                 my $bgcolor = $backgrounds[$rownum % $numcolors];
 1573:                 if (!$shownheader) {
 1574:                     $r->print($slotheader);
 1575:                     $shownheader = 1;
 1576:                 }
 1577:                 $r->print('<tr class="'.$bgcolor.'"><td>'."\n");
 1578:                 for (my $i=0; $i<$depth; $i++) {
 1579:                     $r->print('<img src="'.$location.'" alt="" />');
 1580:                 }
 1581:                 my $result = '<a href="'.$resource->src().'?symb='.$symb.'">'.
 1582:                              '<img class="LC_contentImage" src="/adm/lonIcons/';
 1583:                 if ($resource->is_task()) {
 1584:                     $result .= 'task.gif" alt="'.&mt('Task');
 1585:                 } else {
 1586:                     $result .= 'problem.gif" alt="'.&mt('Problem');
 1587:                 }
 1588:                 $result .= '" /><b>'.$title.'</b></a>'.('&nbsp;' x6).'</td>';
 1589:                 my $hasaction;
 1590:                 if ($status == $resource->OPEN) {
 1591:                     if ($get_choices) {
 1592:                         $hasaction = 1;
 1593:                     }
 1594:                 }
 1595:                 if ($hasaction) {
 1596:                     $result .= '<td valgn="middle">'.$msg.'</td>'.
 1597:                                '<td valign="middle">'.('&nbsp;' x6);
 1598:                 } else {
 1599:                     $result .= '<td colspan="2" valign="middle">'.$msg.'</td>';
 1600:                 }
 1601:                 $r->print($result);
 1602:                 if ($hasaction) {
 1603:                     my $formname = 'manageres_'.$reservable;
 1604:                     &show_choices($r,$symb,$formname);
 1605:                     $r->print('</td>');
 1606:                 }
 1607:                 $r->print('</tr>');
 1608:             }
 1609:         }
 1610:     }
 1611:     if ($shownheader) {
 1612:         $r->print('</table>');
 1613:     }
 1614:     if (!$reservable) {
 1615:         $r->print('<span class="LC_info">');
 1616:         if ($crstype eq 'Community') {
 1617:             $r->print(&mt('No community items currently require a reservation to gain access.'));
 1618:         } else {
 1619:             $r->print(&mt('No course items currently require a reservation to gain access.'));
 1620:         }
 1621:         $r->print('</span>');
 1622:     }
 1623:     $r->print('<p><a href="/adm/slotrequest?command=showresv">'.
 1624:               &mt('Reservation History').'</a></p>');
 1625: }
 1626: 
 1627: sub show_map_row {
 1628:     my ($depth,$location,$type,$title,$maprows) = @_;
 1629:     my $output = '<td>';
 1630:     for (my $i=0; $i<$depth-1; $i++) {
 1631:         $output .= '<img src="'.$location.'" alt="" />';
 1632:     }
 1633:     if ($type eq 'page') {
 1634:         $output .= '<img src="/adm/lonIcons/navmap.page.open.gif" alt="" />&nbsp;'."\n";
 1635:     } else {
 1636:         $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" />&nbsp;'."\n";
 1637:     }
 1638:     $output .= $title.'</td><td colspan="2">&nbsp;</td>'."\n";
 1639:     unshift (@{$maprows},$output);
 1640:     return;
 1641: }
 1642: 
 1643: sub show_reservations {
 1644:     my ($r,$uname,$udom) = @_;
 1645:     if (!defined($uname)) {
 1646:         $uname = $env{'user.name'};
 1647:     }
 1648:     if (!defined($udom)) {
 1649:         $udom = $env{'user.domain'};
 1650:     }
 1651:     my $formname = 'slotlog';
 1652:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 1653:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 1654:     my $crstype = &Apache::loncommon::course_type();
 1655:     my %log=&Apache::lonnet::dump('nohist_'.$cdom.'_'.$cnum.'_slotlog',$udom,$uname);
 1656:     if ($env{'form.origin'} eq 'aboutme') {
 1657:         $r->print('<div class="LC_fontsize_large">');
 1658:         my $name = &Apache::loncommon::plainname($env{'form.uname'},$env{'form.udom'},
 1659:                                                     'firstname');
 1660:         if ($crstype eq 'Community') {
 1661:             $r->print(&mt('History of member-reservable slots for: [_1]',
 1662:                           $name));
 1663:         } else {
 1664:             $r->print(&mt('History of student-reservable slots for: [_1]',
 1665:                           $name));
 1666: 
 1667:         }
 1668:         $r->print('</div>');
 1669:     }
 1670:     $r->print('<form action="/adm/slotrequest" method="post" name="'.$formname.'">');
 1671:     # set defaults
 1672:     my $now = time();
 1673:     my $defstart = $now - (7*24*3600); #7 days ago
 1674:     my %defaults = (
 1675:                      page           => '1',
 1676:                      show           => '10',
 1677:                      action         => 'any',
 1678:                      log_start_date => $defstart,
 1679:                      log_end_date   => $now,
 1680:                    );
 1681:     my $more_records = 0;
 1682: 
 1683:     # set current
 1684:     my %curr;
 1685:     foreach my $item ('show','page','action') {
 1686:         $curr{$item} = $env{'form.'.$item};
 1687:     }
 1688:     my ($startdate,$enddate) =
 1689:         &Apache::lonuserutils::get_dates_from_form('log_start_date',
 1690:                                                    'log_end_date');
 1691:     $curr{'log_start_date'} = $startdate;
 1692:     $curr{'log_end_date'} = $enddate;
 1693:     foreach my $key (keys(%defaults)) {
 1694:         if ($curr{$key} eq '') {
 1695:             $curr{$key} = $defaults{$key};
 1696:         }
 1697:     }
 1698:     my ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
 1699:     $r->print(&display_filter($formname,$cdom,$cnum,\%curr,$version));
 1700:     my $showntablehdr = 0;
 1701:     my $tablehdr = &Apache::loncommon::start_data_table().
 1702:                    &Apache::loncommon::start_data_table_header_row().
 1703:                    '<th>&nbsp;</th><th>'.&mt('When').'</th><th>'.&mt('Action').'</th>'.
 1704:                    '<th>'.&mt('Description').'</th><th>'.&mt('Start time').'</th>'.
 1705:                    '<th>'.&mt('End time').'</th><th>'.&mt('Resource').'</th>'.
 1706:                    &Apache::loncommon::end_data_table_header_row();
 1707:     my ($minshown,$maxshown);
 1708:     $minshown = 1;
 1709:     my $count = 0;
 1710:     if ($curr{'show'} ne &mt('all')) {
 1711:         $maxshown = $curr{'page'} * $curr{'show'};
 1712:         if ($curr{'page'} > 1) {
 1713:             $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
 1714:         }
 1715:     }
 1716:     my (%titles,%maptitles);
 1717:     my %lt = &reservationlog_contexts($crstype);
 1718:     foreach my $id (sort { $log{$b}{'exe_time'}<=>$log{$a}{'exe_time'} } (keys(%log))) {
 1719:         next if (($log{$id}{'exe_time'} < $curr{'log_start_date'}) ||
 1720:                  ($log{$id}{'exe_time'} > $curr{'log_end_date'}));
 1721:         if ($curr{'show'} ne &mt('all')) {
 1722:             if ($count >= $curr{'page'} * $curr{'show'}) {
 1723:                 $more_records = 1;
 1724:                 last;
 1725:             }
 1726:         }
 1727:         if ($curr{'action'} ne 'any') {
 1728:             next if ($log{$id}{'logentry'}{'action'} ne $curr{'action'});
 1729:         }
 1730:         $count ++;
 1731:         next if ($count < $minshown);
 1732:         if (!$showntablehdr) {
 1733:             $r->print($tablehdr);
 1734:             $showntablehdr = 1;
 1735:         }
 1736:         my $symb = $log{$id}{'logentry'}{'symb'};
 1737:         my $slot_name = $log{$id}{'logentry'}{'slot'};
 1738:         my %slot=&Apache::lonnet::get_slot($slot_name);
 1739:         my $description = $slot{'description'};
 1740:         my $start = ($slot{'starttime'}?
 1741:                      &Apache::lonlocal::locallocaltime($slot{'starttime'}):'');
 1742:         my $end = ($slot{'endtime'}?
 1743:                    &Apache::lonlocal::locallocaltime($slot{'endtime'}):'');
 1744:         my $title = &get_resource_title($symb,\%titles,\%maptitles);
 1745:         my $chgaction = $log{$id}{'logentry'}{'action'};
 1746:         if ($chgaction ne '' && $lt{$chgaction} ne '') {
 1747:             $chgaction = $lt{$chgaction};
 1748:         }
 1749:         $r->print(&Apache::loncommon::start_data_table_row().'<td>'.$count.'</td><td>'.&Apache::lonlocal::locallocaltime($log{$id}{'exe_time'}).'</td><td>'.$chgaction.'</td><td>'.$description.'</td><td>'.$start.'</td><td>'.$end.'</td><td>'.$title.'</td>'.&Apache::loncommon::end_data_table_row()."\n");
 1750:     }
 1751:     if ($showntablehdr) {
 1752:         $r->print(&Apache::loncommon::end_data_table().'<br />');
 1753:         if (($curr{'page'} > 1) || ($more_records)) {
 1754:             $r->print('<table><tr>');
 1755:             if ($curr{'page'} > 1) {
 1756:                 $r->print('<td><a href="javascript:chgPage('."'previous'".');">'.&mt('Previous [_1] changes',$curr{'show'}).'</a></td>');
 1757:             }
 1758:             if ($more_records) {
 1759:                 $r->print('<td><a href="javascript:chgPage('."'next'".');">'.&mt('Next [_1] changes',$curr{'show'}).'</a></td>');
 1760:             }
 1761:             $r->print('</tr></table>');
 1762:             $r->print(<<"ENDSCRIPT");
 1763: <script type="text/javascript">
 1764: function chgPage(caller) {
 1765:     if (caller == 'previous') {
 1766:         document.$formname.page.value --;
 1767:     }
 1768:     if (caller == 'next') {
 1769:         document.$formname.page.value ++;
 1770:     }
 1771:     document.$formname.submit();
 1772:     return;
 1773: }
 1774: </script>
 1775: ENDSCRIPT
 1776:         }
 1777:     } else {
 1778:         $r->print('<span class="LC_info">'
 1779:                  .&mt('There are no transactions to display.')
 1780:                  .'</span>'
 1781:         );
 1782:     }
 1783:     $r->print('<input type="hidden" name="page" value="'.$curr{'page'}.'" />'."\n".
 1784:               '<input type="hidden" name="command" value="showresv" />'."\n");
 1785:     if ($env{'form.origin'} eq 'aboutme') {
 1786:         $r->print('<input type="hidden" name="origin" value="'.$env{'form.origin'}.'" />'."\n".
 1787:                   '<input type="hidden" name="uname" value="'.$env{'form.uname'}.'" />'."\n".
 1788:                   '<input type="hidden" name="udom" value="'.$env{'form.udom'}.'" />'."\n");
 1789:     }
 1790:     $r->print('</form>');
 1791:     return;
 1792: }
 1793: 
 1794: sub show_reservations_log {
 1795:     my ($r) = @_;
 1796:     my $badslot;
 1797:     my $crstype = &Apache::loncommon::course_type();
 1798:     if ($env{'form.slotname'} eq '') {
 1799:         $r->print('<div class="LC_warning">'.&mt('No slot name provided').'</div>');
 1800:         $badslot = 1;
 1801:     } else {
 1802:         my %slot=&Apache::lonnet::get_slot($env{'form.slotname'});
 1803:         if (keys(%slot) == 0) {
 1804:             $r->print('<div class="LC_warning">'.&mt('Invalid slot name: [_1]',$env{'form.slotname'}).'</div>');
 1805:             $badslot = 1;
 1806:         } elsif ($slot{type} ne 'schedulable_student') {
 1807:             my $description = &get_description($env{'form.slotname'},\%slot);
 1808:             $r->print('<div class="LC_warning">');
 1809:             if ($crstype eq 'Community') {
 1810:                 $r->print(&mt('Reservation history unavailable for non-member-reservable slot: [_1].',$description));
 1811:             } else {
 1812:                 $r->print(&mt('Reservation history unavailable for non-student-reservable slot: [_1].',$description));
 1813:             }
 1814:             $r->print('</div>');
 1815:             $badslot = 1;
 1816:         }
 1817:     }
 1818:     if ($badslot) {
 1819:         $r->print('<p><a href="/adm/slotrequest?command=showslots">'.
 1820:                   &mt('Return to slot list').'</a></p>');
 1821:         return;
 1822:     }
 1823:     my $formname = 'reservationslog';
 1824:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 1825:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 1826:     my %slotlog=&Apache::lonnet::dump('nohist_slotreservationslog',$cdom,$cnum);
 1827:     if ((keys(%slotlog))[0]=~/^error\:/) { undef(%slotlog); }
 1828: 
 1829:     my (%log,@allsymbs);
 1830:     if (keys(%slotlog)) {
 1831:         foreach my $key (keys(%slotlog)) {
 1832:             if (ref($slotlog{$key}) eq 'HASH') {
 1833:                 if (ref($slotlog{$key}{'logentry'}) eq 'HASH') {
 1834:                     if ($slotlog{$key}{'logentry'}{'slot'} eq $env{'form.slotname'}) {
 1835:                         $log{$key} = $slotlog{$key};
 1836:                         if ($slotlog{$key}{'logentry'}{'symb'} ne '') {
 1837:                             push(@allsymbs,$slotlog{$key}{'logentry'}{'symb'});
 1838:                         }
 1839:                     }
 1840:                 }
 1841:             }
 1842:         }
 1843:     }
 1844: 
 1845:     $r->print('<form action="/adm/slotrequest" method="post" name="'.$formname.'">');
 1846:     my %saveable_parameters = ('show' => 'scalar',);
 1847:     &Apache::loncommon::store_course_settings('reservationslog',
 1848:                                               \%saveable_parameters);
 1849:     &Apache::loncommon::restore_course_settings('reservationslog',
 1850:                                                 \%saveable_parameters);
 1851:     # set defaults
 1852:     my $now = time();
 1853:     my $defstart = $now - (7*24*3600); #7 days ago
 1854:     my %defaults = (
 1855:                      page           => '1',
 1856:                      show           => '10',
 1857:                      chgcontext     => 'any',
 1858:                      action         => 'any',
 1859:                      symb           => 'any',
 1860:                      log_start_date => $defstart,
 1861:                      log_end_date   => $now,
 1862:                    );
 1863:     my $more_records = 0;
 1864: 
 1865:     # set current
 1866:     my %curr;
 1867:     foreach my $item ('show','page','chgcontext','action','symb') {
 1868:         $curr{$item} = $env{'form.'.$item};
 1869:     }
 1870:     my ($startdate,$enddate) =
 1871:         &Apache::lonuserutils::get_dates_from_form('log_start_date',
 1872:                                                    'log_end_date');
 1873:     $curr{'log_start_date'} = $startdate;
 1874:     $curr{'log_end_date'} = $enddate;
 1875:     foreach my $key (keys(%defaults)) {
 1876:         if ($curr{$key} eq '') {
 1877:             $curr{$key} = $defaults{$key};
 1878:         }
 1879:     }
 1880:     my (%whodunit,%changed,$version);
 1881:     ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
 1882: 
 1883:     my %slot=&Apache::lonnet::get_slot($env{'form.slotname'});
 1884:     my $description = $slot{'description'};
 1885:     $r->print('<span class="LC_fontsize_large">');
 1886:     if ($crstype eq 'Community') {
 1887:         $r->print(&mt('Reservation changes for member-reservable slot: [_1]',$description));
 1888:     } else {
 1889:         $r->print(&mt('Reservation changes for student-reservable slot: [_1]',$description));
 1890:     }
 1891:     $r->print('</span><br />');
 1892:     $r->print(&display_filter($formname,$cdom,$cnum,\%curr,$version,\@allsymbs));
 1893:     my $showntablehdr = 0;
 1894:     my $tablehdr = &Apache::loncommon::start_data_table().
 1895:                    &Apache::loncommon::start_data_table_header_row().
 1896:                    '<th>&nbsp;</th><th>'.&mt('When').'</th><th>'.&mt('Who made the change').
 1897:                    '</th><th>'.&mt('Affected User').'</th><th>'.&mt('Action').'</th>'.
 1898:                    '<th>'.&mt('Resource').'</th><th>'.&mt('Context').'</th>'.
 1899:                    &Apache::loncommon::end_data_table_header_row();
 1900:     my ($minshown,$maxshown);
 1901:     $minshown = 1;
 1902:     my $count = 0;
 1903:     if ($curr{'show'} ne &mt('all')) {
 1904:         $maxshown = $curr{'page'} * $curr{'show'};
 1905:         if ($curr{'page'} > 1) {
 1906:             $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
 1907:         }
 1908:     }
 1909:     my %lt = &reservationlog_contexts($crstype);
 1910:     my (%titles,%maptitles);
 1911:     foreach my $id (sort { $log{$b}{'exe_time'}<=>$log{$a}{'exe_time'} } (keys(%log))) {
 1912:         next if (($log{$id}{'exe_time'} < $curr{'log_start_date'}) ||
 1913:                  ($log{$id}{'exe_time'} > $curr{'log_end_date'}));
 1914:         if ($curr{'show'} ne &mt('all')) {
 1915:             if ($count >= $curr{'page'} * $curr{'show'}) {
 1916:                 $more_records = 1;
 1917:                 last;
 1918:             }
 1919:         }
 1920:         if ($curr{'chgcontext'} ne 'any') {
 1921:             if ($curr{'chgcontext'} eq 'user') {
 1922:                 next if (($log{$id}{'logentry'}{'context'} ne 'user') && 
 1923:                          ($log{$id}{'logentry'}{'context'} ne 'usermanage'));
 1924:             } else {
 1925:                 next if ($log{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
 1926:             }
 1927:         }
 1928:         if ($curr{'action'} ne 'any') {
 1929:             next if ($log{$id}{'logentry'}{'action'} ne $curr{'action'});
 1930:         }
 1931:         if ($curr{'symb'} ne 'any') {
 1932:             next if ($log{$id}{'logentry'}{'symb'} ne $curr{'symb'});
 1933:         }
 1934:         $count ++;
 1935:         next if ($count < $minshown);
 1936:         if (!$showntablehdr) {
 1937:             $r->print($tablehdr);
 1938:             $showntablehdr = 1;
 1939:         }
 1940:         if ($whodunit{$log{$id}{'exe_uname'}.':'.$log{$id}{'exe_udom'}} eq '') {
 1941:             $whodunit{$log{$id}{'exe_uname'}.':'.$log{$id}{'exe_udom'}} =
 1942:                 &Apache::loncommon::plainname($log{$id}{'exe_uname'},$log{$id}{'exe_udom'});
 1943:         }
 1944:         if ($changed{$log{$id}{'uname'}.':'.$log{$id}{'udom'}} eq '') {
 1945:             $changed{$log{$id}{'uname'}.':'.$log{$id}{'udom'}} =
 1946:                 &Apache::loncommon::plainname($log{$id}{'uname'},$log{$id}{'udom'});
 1947:         }
 1948:         my $symb = $log{$id}{'logentry'}{'symb'};
 1949:         my $title = &get_resource_title($symb,\%titles,\%maptitles); 
 1950:         my $chgcontext = $log{$id}{'logentry'}{'context'};
 1951:         if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
 1952:             $chgcontext = $lt{$chgcontext};
 1953:         }
 1954:         my $chgaction = $log{$id}{'logentry'}{'action'};
 1955:         if ($chgaction ne '' && $lt{$chgaction} ne '') {
 1956:             $chgaction = $lt{$chgaction}; 
 1957:         }
 1958:         $r->print(&Apache::loncommon::start_data_table_row().'<td>'.$count.'</td><td>'.&Apache::lonlocal::locallocaltime($log{$id}{'exe_time'}).'</td><td>'.$whodunit{$log{$id}{'exe_uname'}.':'.$log{$id}{'exe_udom'}}.'</td><td>'.$changed{$log{$id}{'uname'}.':'.$log{$id}{'udom'}}.'</td><td>'.$chgaction.'</td><td>'.$title.'</td><td>'.$chgcontext.'</td>'.&Apache::loncommon::end_data_table_row()."\n");
 1959:     }
 1960:     if ($showntablehdr) {
 1961:         $r->print(&Apache::loncommon::end_data_table().'<br />');
 1962:         if (($curr{'page'} > 1) || ($more_records)) {
 1963:             $r->print('<table><tr>');
 1964:             if ($curr{'page'} > 1) {
 1965:                 $r->print('<td><a href="javascript:chgPage('."'previous'".');">'.&mt('Previous [_1] changes',$curr{'show'}).'</a></td>');
 1966:             }
 1967:             if ($more_records) {
 1968:                 $r->print('<td><a href="javascript:chgPage('."'next'".');">'.&mt('Next [_1] changes',$curr{'show'}).'</a></td>');
 1969:             }
 1970:             $r->print('</tr></table>');
 1971:             $r->print(<<"ENDSCRIPT");
 1972: <script type="text/javascript">
 1973: function chgPage(caller) {
 1974:     if (caller == 'previous') {
 1975:         document.$formname.page.value --;
 1976:     }
 1977:     if (caller == 'next') {
 1978:         document.$formname.page.value ++;
 1979:     }
 1980:     document.$formname.submit();
 1981:     return;
 1982: }
 1983: </script>
 1984: ENDSCRIPT
 1985:         }
 1986:     } else {
 1987:         $r->print(&mt('There are no records to display.'));
 1988:     }
 1989:     $r->print('<input type="hidden" name="page" value="'.$curr{'page'}.'" />'.
 1990:               '<input type="hidden" name="slotname" value="'.$env{'form.slotname'}.'" />'.
 1991:               '<input type="hidden" name="command" value="slotlog" /></form>'.
 1992:               '<p><a href="/adm/slotrequest?command=showslots">'.
 1993:               &mt('Return to slot list').'</a></p>');
 1994:     return;
 1995: }
 1996: 
 1997: sub get_resource_title {
 1998:     my ($symb,$titles,$maptitles) = @_;
 1999:     my $title;
 2000:     if ((ref($titles) eq 'HASH') && (ref($maptitles) eq 'HASH')) { 
 2001:         if (defined($titles->{$symb})) {
 2002:             $title = $titles->{$symb};
 2003:         } else {
 2004:             $title = &Apache::lonnet::gettitle($symb);
 2005:             my $maptitle;
 2006:             my ($mapurl) = &Apache::lonnet::decode_symb($symb);
 2007:             if (defined($maptitles->{$mapurl})) {
 2008:                 $maptitle = $maptitles->{$mapurl};
 2009:             } else {
 2010:                 if ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'}) {
 2011:                     $maptitle=&mt('Main Course Documents');
 2012:                 } else {
 2013:                     $maptitle=&Apache::lonnet::gettitle($mapurl);
 2014:                 }
 2015:                 $maptitles->{$mapurl} = $maptitle;
 2016:             }
 2017:             if ($maptitle ne '') {
 2018:                 $title .= ' '.&mt('(in [_1])',$maptitle);
 2019:             }
 2020:             $titles->{$symb} = $title;
 2021:         }
 2022:     } else {
 2023:         $title = $symb;
 2024:     }
 2025:     return $title;
 2026: }
 2027: 
 2028: sub reservationlog_contexts {
 2029:     my ($crstype) = @_;
 2030:     my %lt = &Apache::lonlocal::texthash (
 2031:                                              any        => 'Any',
 2032:                                              user       => 'By student',
 2033:                                              manage     => 'Via Slot Manager',
 2034:                                              parameter  => 'Via Parameter Manager',
 2035:                                              reserve    => 'Made reservation',
 2036:                                              release    => 'Dropped reservation',
 2037:                                              usermanage => 'By student', 
 2038:                                          );
 2039:     if ($crstype eq 'Community') {
 2040:         $lt{'user'} = &mt('By member');
 2041:         $lt{'usermanage'} = $lt{'user'};
 2042:     }
 2043:     return %lt;
 2044: }
 2045: 
 2046: sub display_filter {
 2047:     my ($formname,$cdom,$cnum,$curr,$version,$allsymbs) = @_;
 2048:     my $nolink = 1;
 2049:     my (%titles,%maptitles);
 2050:     my $output = '<br /><table><tr><td valign="top">'.
 2051:                  '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b><br />'.
 2052:                  &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
 2053:                                               (&mt('all'),5,10,20,50,100,1000,10000)).
 2054:                  '</td><td>&nbsp;&nbsp;</td>';
 2055:     my $startform =
 2056:         &Apache::lonhtmlcommon::date_setter($formname,'log_start_date',
 2057:                                             $curr->{'log_start_date'},undef,
 2058:                                             undef,undef,undef,undef,undef,undef,$nolink);
 2059:     my $endform =
 2060:         &Apache::lonhtmlcommon::date_setter($formname,'log_end_date',
 2061:                                             $curr->{'log_end_date'},undef,
 2062:                                             undef,undef,undef,undef,undef,undef,$nolink);
 2063:     my $crstype = &Apache::loncommon::course_type();
 2064:     my %lt = &reservationlog_contexts($crstype);
 2065:     $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').
 2066:                '</b><br /><table><tr><td>'.&mt('After:').
 2067:                '</td><td>'.$startform.'</td></tr><tr><td>'.&mt('Before:').'</td><td>'.
 2068:                $endform.'</td></tr></table></td><td>&nbsp;&nbsp;</td>';
 2069:     if (ref($allsymbs) eq 'ARRAY') {
 2070:         $output .= '<td valign="top"><b>'.&mt('Resource').'</b><br />'.
 2071:                    '<select name="resource"><option value="any"';
 2072:         if ($curr->{'resource'} eq 'any') {
 2073:             $output .= ' selected="selected"';
 2074:         }
 2075:         $output .=  '>'.&mt('Any').'</option>'."\n";
 2076:         foreach my $symb (@{$allsymbs}) {
 2077:             my $title = &get_resource_title($symb,\%titles,\%maptitles);
 2078:             my $selstr = '';
 2079:             if ($curr->{'resource'} eq $symb) {
 2080:                 $selstr = ' selected="selected"';
 2081:             }
 2082:             $output .= '  <option value="'.$symb.'"'.$selstr.'>'.$title.'</option>';
 2083:         }
 2084:         $output .= '</select></td><td>&nbsp;&nbsp;</td><td valign="top"><b>'.
 2085:                    &mt('Context:').'</b><br /><select name="chgcontext">';
 2086:         foreach my $chgtype ('any','user','manage','parameter') {
 2087:             my $selstr = '';
 2088:             if ($curr->{'chgcontext'} eq $chgtype) {
 2089:                 $output .= $selstr = ' selected="selected"';
 2090:             }
 2091:             $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
 2092:         }
 2093:         $output .= '</select></td>';
 2094:     } else {
 2095:         $output .= '<td valign="top"><b>'.&mt('Action').'</b><br />'.
 2096:                    '<select name="action"><option value="any"';
 2097:         if ($curr->{'action'} eq 'any') {
 2098:             $output .= ' selected="selected"';
 2099:         }
 2100:         $output .=  '>'.&mt('Any').'</option>'."\n";
 2101:         foreach my $actiontype ('reserve','release') {
 2102:             my $selstr = '';
 2103:             if ($curr->{'action'} eq $actiontype) {
 2104:                 $output .= $selstr = ' selected="selected"';
 2105:             }
 2106:             $output .= '<option value="'.$actiontype.'"'.$selstr.'>'.$lt{$actiontype}.'</option>'."\n";
 2107:         }
 2108:         $output .= '</select></td>';
 2109:     }
 2110:     $output .= '<td>&nbsp;&nbsp;</td><td valign="middle"><input type="submit" value="'.
 2111:                &mt('Update Display').'" /></tr></table>'.
 2112:                '<p class="LC_info">'.
 2113:                &mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
 2114:                   ,'2.9.0');
 2115:     if ($version) {
 2116:         $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
 2117:     }
 2118:     $output .= '</p><hr /><br />';
 2119:     return $output;
 2120: }
 2121: 
 2122: sub upload_start {
 2123:     my ($r)=@_;    
 2124:     $r->print(
 2125:         &Apache::grades::checkforfile_js()
 2126:        .'<h3>'.&mt('Specify a file containing the slot definitions.').'</h3>'
 2127:        .'<form method="post" enctype="multipart/form-data"'
 2128:        .' action="/adm/slotrequest" name="slotupload">'
 2129:        .'<input type="hidden" name="command" value="csvuploadmap" />'
 2130:        .&Apache::lonhtmlcommon::start_pick_box()
 2131:        .&Apache::lonhtmlcommon::row_title(&mt('File'))
 2132:        .&Apache::loncommon::upfile_select_html()
 2133:        .&Apache::lonhtmlcommon::row_closure()
 2134:        .&Apache::lonhtmlcommon::row_title(
 2135:             '<label for="noFirstLine">'
 2136:            .&mt('Ignore First Line')
 2137:            .'</label>')
 2138:        .'<input type="checkbox" name="noFirstLine" id="noFirstLine" />'
 2139:        .&Apache::lonhtmlcommon::row_closure(1)
 2140:        .&Apache::lonhtmlcommon::end_pick_box()
 2141:        .'<p>'
 2142:        .'<input type="button" onclick="javascript:checkUpload(this.form);"'
 2143:        .' value="'.&mt('Next').'" />'
 2144:        .'</p>'
 2145:       .'</form>'
 2146:     );
 2147: }
 2148: 
 2149: sub csvuploadmap_header {
 2150:     my ($r,$datatoken,$distotal)= @_;
 2151:     my $javascript;
 2152:     if ($env{'form.upfile_associate'} eq 'reverse') {
 2153: 	$javascript=&csvupload_javascript_reverse_associate();
 2154:     } else {
 2155: 	$javascript=&csvupload_javascript_forward_associate();
 2156:     }
 2157: 
 2158:     my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
 2159:     my $ignore=&mt('Ignore First Line');
 2160: 	my $help_field = &Apache::loncommon::help_open_topic('Slot SelectingField');
 2161: 
 2162:     $r->print(<<ENDPICK);
 2163: <form method="post" enctype="multipart/form-data" action="/adm/slotrequest" name="slotupload">
 2164: <h3>Identify fields $help_field</h3>	
 2165: Total number of records found in file: $distotal <hr />
 2166: Enter as many fields as you can. The system will inform you and bring you back
 2167: to this page if the data selected is insufficient to create the slots.<hr />
 2168: <input type="button" value="Reverse Association" onclick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
 2169: <label><input type="checkbox" name="noFirstLine"$checked />$ignore</label>
 2170: <input type="hidden" name="associate"  value="" />
 2171: <input type="hidden" name="datatoken"  value="$datatoken" />
 2172: <input type="hidden" name="fileupload" value="$env{'form.fileupload'}" />
 2173: <input type="hidden" name="upfiletype" value="$env{'form.upfiletype'}" />
 2174: <input type="hidden" name="upfile_associate" 
 2175:                                        value="$env{'form.upfile_associate'}" />
 2176: <input type="hidden" name="command"    value="csvuploadassign" />
 2177: <hr />
 2178: <script type="text/javascript" language="Javascript">
 2179: $javascript
 2180: </script>
 2181: ENDPICK
 2182:     return '';
 2183: 
 2184: }
 2185: 
 2186: sub csvuploadmap_footer {
 2187:     my ($request,$i,$keyfields) =@_;
 2188:     my $buttontext = &mt('Create Slots');
 2189:     $request->print(<<ENDPICK);
 2190: </table>
 2191: <input type="hidden" name="nfields" value="$i" />
 2192: <input type="hidden" name="keyfields" value="$keyfields" />
 2193: <input type="button" onclick="javascript:verify(this.form)" value="$buttontext" /><br />
 2194: </form>
 2195: ENDPICK
 2196: }
 2197: 
 2198: sub csvupload_javascript_reverse_associate {
 2199:     my $error1=&mt('You need to specify the name, starttime, endtime and a type');
 2200:     return(<<ENDPICK);
 2201:   function verify(vf) {
 2202:     var foundstart=0;
 2203:     var foundend=0;
 2204:     var foundname=0;
 2205:     var foundtype=0;
 2206:     for (i=0;i<=vf.nfields.value;i++) {
 2207:       tw=eval('vf.f'+i+'.selectedIndex');
 2208:       if (i==0 && tw!=0) { foundname=1; }
 2209:       if (i==1 && tw!=0) { foundtype=1; }
 2210:       if (i==2 && tw!=0) { foundstat=1; }
 2211:       if (i==3 && tw!=0) { foundend=1; }
 2212:     }
 2213:     if (foundstart==0 && foundend==0 && foundtype==0 && foundname==0) {
 2214: 	alert('$error1');
 2215: 	return;
 2216:     }
 2217:     vf.submit();
 2218:   }
 2219:   function flip(vf,tf) {
 2220:   }
 2221: ENDPICK
 2222: }
 2223: 
 2224: sub csvupload_javascript_forward_associate {
 2225:     my $error1=&mt('You need to specify the name, starttime, endtime and a type');
 2226:   return(<<ENDPICK);
 2227:   function verify(vf) {
 2228:     var foundstart=0;
 2229:     var foundend=0;
 2230:     var foundname=0;
 2231:     var foundtype=0;
 2232:     for (i=0;i<=vf.nfields.value;i++) {
 2233:       tw=eval('vf.f'+i+'.selectedIndex');
 2234:       if (tw==1) { foundname=1; }
 2235:       if (tw==2) { foundtype=1; }
 2236:       if (tw==3) { foundstat=1; }
 2237:       if (tw==4) { foundend=1; }
 2238:     }
 2239:     if (foundstart==0 && foundend==0 && foundtype==0 && foundname==0) {
 2240: 	alert('$error1');
 2241: 	return;
 2242:     }
 2243:     vf.submit();
 2244:   }
 2245:   function flip(vf,tf) {
 2246:   }
 2247: ENDPICK
 2248: }
 2249: 
 2250: sub csv_upload_map {
 2251:     my ($r)= @_;
 2252: 
 2253:     my $datatoken;
 2254:     if (!$env{'form.datatoken'}) {
 2255: 	$datatoken=&Apache::loncommon::upfile_store($r);
 2256:     } else {
 2257: 	$datatoken=$env{'form.datatoken'};
 2258: 	&Apache::loncommon::load_tmp_file($r);
 2259:     }
 2260:     my @records=&Apache::loncommon::upfile_record_sep();
 2261:     if ($env{'form.noFirstLine'}) { shift(@records); }
 2262:     &csvuploadmap_header($r,$datatoken,$#records+1);
 2263:     my ($i,$keyfields);
 2264:     if (@records) {
 2265: 	my @fields=&csvupload_fields();
 2266: 
 2267: 	if ($env{'form.upfile_associate'} eq 'reverse') {	
 2268: 	    &Apache::loncommon::csv_print_samples($r,\@records);
 2269: 	    $i=&Apache::loncommon::csv_print_select_table($r,\@records,
 2270: 							  \@fields);
 2271: 	    foreach (@fields) { $keyfields.=$_->[0].','; }
 2272: 	    chop($keyfields);
 2273: 	} else {
 2274: 	    unshift(@fields,['none','']);
 2275: 	    $i=&Apache::loncommon::csv_samples_select_table($r,\@records,
 2276: 							    \@fields);
 2277: 	    my %sone=&Apache::loncommon::record_sep($records[0]);
 2278: 	    $keyfields=join(',',sort(keys(%sone)));
 2279: 	}
 2280:     }
 2281:     &csvuploadmap_footer($r,$i,$keyfields);
 2282: 
 2283:     return '';
 2284: }
 2285: 
 2286: sub csvupload_fields {
 2287:     return (['name','Slot name'],
 2288: 	    ['type','Type of slot'],
 2289: 	    ['starttime','Start Time of slot'],
 2290: 	    ['endtime','End Time of slot'],
 2291: 	    ['startreserve','Reservation Start Time'],
 2292: 	    ['ip','IP or DNS restriction'],
 2293: 	    ['proctor','List of proctor ids'],
 2294: 	    ['description','Slot Description'],
 2295: 	    ['maxspace','Maximum number of reservations'],
 2296: 	    ['symb','Resource Restriction'],
 2297: 	    ['uniqueperiod','Date range of slot exclusion'],
 2298: 	    ['secret','Secret word proctor uses to validate'],
 2299: 	    ['allowedsections','Sections slot is restricted to'],
 2300: 	    ['allowedusers','Users slot is restricted to'],
 2301: 	    );
 2302: }
 2303: 
 2304: sub csv_upload_assign {
 2305:     my ($r,$mgr)= @_;
 2306:     &Apache::loncommon::load_tmp_file($r);
 2307:     my @slotdata = &Apache::loncommon::upfile_record_sep();
 2308:     if ($env{'form.noFirstLine'}) { shift(@slotdata); }
 2309:     my %fields=&Apache::grades::get_fields();
 2310:     $r->print('<h3>'.&mt('Creating Slots').'</h3>');
 2311:     my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
 2312:     my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
 2313:     my $countdone=0;
 2314:     my @errors;
 2315:     foreach my $slot (@slotdata) {
 2316: 	my %slot;
 2317: 	my %entries=&Apache::loncommon::record_sep($slot);
 2318: 	my $domain;
 2319: 	my $name=$entries{$fields{'name'}};
 2320: 	if ($name=~/^\s*$/) {
 2321: 	    push(@errors,"Did not create slot with no name");
 2322: 	    next;
 2323: 	}
 2324: 	if ($name=~/\s/) { 
 2325: 	    push(@errors,"$name not created -- Name must not contain spaces");
 2326: 	    next;
 2327: 	}
 2328: 	if ($name=~/\W/) { 
 2329: 	    push(@errors,"$name not created -- Name must contain only letters, numbers and _");
 2330: 	    next;
 2331: 	}
 2332: 	if ($entries{$fields{'type'}}) {
 2333: 	    $slot{'type'}=$entries{$fields{'type'}};
 2334: 	} else {
 2335: 	    $slot{'type'}='preassigned';
 2336: 	}
 2337: 	if ($slot{'type'} ne 'preassigned' &&
 2338: 	    $slot{'type'} ne 'schedulable_student') {
 2339: 	    push(@errors,"$name not created -- invalid type ($slot{'type'}) must be either preassigned or schedulable_student");
 2340: 	    next;
 2341: 	}
 2342: 	if ($entries{$fields{'starttime'}}) {
 2343: 	    $slot{'starttime'}=&UnixDate($entries{$fields{'starttime'}},"%s");
 2344: 	}
 2345: 	if ($entries{$fields{'endtime'}}) {
 2346: 	    $slot{'endtime'}=&UnixDate($entries{$fields{'endtime'}},"%s");
 2347: 	}
 2348: 
 2349: 	# start/endtime must be defined and greater than zero
 2350: 	if (!$slot{'starttime'}) {
 2351: 	    push(@errors,"$name not created -- Invalid start time");
 2352: 	    next;
 2353: 	}
 2354: 	if (!$slot{'endtime'}) {
 2355: 	    push(@errors,"$name not created -- Invalid end time");
 2356: 	    next;
 2357: 	}
 2358: 	if ($slot{'starttime'} > $slot{'endtime'}) {
 2359: 	    push(@errors,"$name not created -- Slot starts after it ends");
 2360: 	    next;
 2361: 	}
 2362: 
 2363: 	if ($entries{$fields{'startreserve'}}) {
 2364: 	    $slot{'startreserve'}=
 2365: 		&UnixDate($entries{$fields{'startreserve'}},"%s");
 2366: 	}
 2367: 	if (defined($slot{'startreserve'})
 2368: 	    && $slot{'startreserve'} > $slot{'starttime'}) {
 2369: 	    push(@errors,"$name not created -- Slot's reservation start time is after the slot's start time.");
 2370: 	    next;
 2371: 	}
 2372: 
 2373: 	foreach my $key ('ip','proctor','description','maxspace',
 2374: 			 'secret','symb') {
 2375: 	    if ($entries{$fields{$key}}) {
 2376: 		$slot{$key}=$entries{$fields{$key}};
 2377: 	    }
 2378: 	}
 2379: 
 2380: 	if ($entries{$fields{'uniqueperiod'}}) {
 2381: 	    my ($start,$end)=split(',',$entries{$fields{'uniqueperiod'}});
 2382: 	    my @times=(&UnixDate($start,"%s"),
 2383: 		       &UnixDate($end,"%s"));
 2384: 	    $slot{'uniqueperiod'}=\@times;
 2385: 	}
 2386: 	if (defined($slot{'uniqueperiod'})
 2387: 	    && $slot{'uniqueperiod'}[0] > $slot{'uniqueperiod'}[1]) {
 2388: 	    push(@errors,"$name not created -- Slot's unique period start time is later than the unique period's end time.");
 2389: 	    next;
 2390: 	}
 2391: 
 2392: 	&Apache::lonnet::cput('slots',{$name=>\%slot},$cdom,$cname);
 2393: 	$r->print('.');
 2394: 	$r->rflush();
 2395: 	$countdone++;
 2396:     }
 2397:     $r->print('<p>'.&mt('Created [quant,_1,slot]',$countdone)."\n".'</p>');
 2398:     foreach my $error (@errors) {
 2399: 	$r->print('<p><span class="LC_warning">'.$error.'</span></p>'."\n");
 2400:     }
 2401:     &show_table($r,$mgr);
 2402:     return '';
 2403: }
 2404: 
 2405: sub slot_command_titles {
 2406:     my %titles = (
 2407:                  slotlog            => 'Reservation Logs',
 2408:                  showslots          => 'Manage Slots',
 2409:                  showresv           => 'Reservation History',
 2410:                  manageresv         => 'Manage Reservations',
 2411:                  uploadstart        => 'Upload Slots File',
 2412:                  csvuploadmap       => 'Upload Slots File',
 2413:                  csvuploadassign    => 'Upload Slots File',
 2414:                  delete             => 'Slot Deletion',
 2415:                  release            => 'Reservation Result',
 2416:                  remove_reservation => 'Remove Registration',
 2417:                  get_reservation    => 'Request Reservation',
 2418:               );
 2419:     return %titles;
 2420: }
 2421: 
 2422: sub handler {
 2423:     my $r=shift;
 2424: 
 2425:     &Apache::loncommon::content_type($r,'text/html');
 2426:     &Apache::loncommon::no_cache($r);
 2427:     if ($r->header_only()) {
 2428: 	$r->send_http_header();
 2429: 	return OK;
 2430:     }
 2431: 
 2432:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
 2433: 
 2434:     my %crumb_titles = &slot_command_titles();
 2435:     my $brcrum;
 2436: 
 2437:     my $vgr=&Apache::lonnet::allowed('vgr',$env{'request.course.id'});
 2438:     my $mgr=&Apache::lonnet::allowed('mgr',$env{'request.course.id'});
 2439:     if ($env{'form.command'} eq 'showslots') {
 2440:         if (($vgr ne 'F') && ($mgr ne 'F')) {
 2441:             $env{'form.command'} = 'manageresv'; 
 2442:         }
 2443:     } elsif ($env{'form.command'} eq 'manageresv') {
 2444:         if (($vgr eq 'F') || ($mgr eq 'F')) {
 2445:             $env{'form.command'} = 'showslots';
 2446:         }
 2447:     }
 2448:     my $title='Requesting Another Worktime';
 2449:     if ($env{'form.command'} eq 'showresv') {
 2450:         $title = 'Reservation History';
 2451:         if ($env{'form.origin'} eq 'aboutme') {
 2452:             $brcrum =[{href=>"/adm/$env{'form.udom'}/$env{'form.uname'}/aboutme",text=>'Personal Information Page'}];
 2453:         } else {
 2454:             $brcrum =[{href=>"/adm/slotrequest?command=manageresv",text=>'Manage Reservations'}];
 2455:         }
 2456:         if (ref($brcrum) eq 'ARRAY') {
 2457:             push(@{$brcrum},{href=>"/adm/slotrequest?command=showresv",text=>$title});
 2458:         }
 2459:     } elsif ($env{'form.command'} eq 'manageresv') {
 2460:         $title = 'Manage Reservations';
 2461:         $brcrum =[{href=>"/adm/slotrequest?command=manageresv",text=>$title}];
 2462:     } elsif ($vgr eq 'F') {
 2463:         if ($env{'form.command'} =~ /^(slotlog|showslots|uploadstart|csvuploadmap|csvuploadassign|delete|release|remove_registration)$/) {
 2464:             $brcrum =[{href=>"/adm/slotrequest?command=showslots",
 2465:                        text=>$crumb_titles{'showslots'}}];
 2466: 	    $title = 'Managing Slots';
 2467:             unless ($env{'form.command'} eq 'showslots') {
 2468:                 if (ref($brcrum) eq 'ARRAY') {
 2469:                     push(@{$brcrum},{href=>"/adm/slotrequest?command=$env{'form.command'}",text=>$crumb_titles{$env{'form.command'}}});
 2470:                 }
 2471:             }
 2472:         }
 2473:     } elsif ($env{'form.command'} eq 'release') {
 2474:         if ($env{'form.context'} eq 'usermanage') {
 2475:             $brcrum =[{href=>"/adm/slotrequest?command=manageresv",
 2476:                        text=>$crumb_titles{'showslots'}}];
 2477:             $title = 'Manage Reservations';
 2478:             if (ref($brcrum) eq 'ARRAY') {
 2479:                 push(@{$brcrum},{href=>"/adm/slotrequest?command=$env{'form.command'}",text=>$crumb_titles{$env{'form.command'}}});
 2480:             }
 2481:             
 2482:         }
 2483:     }
 2484:     &start_page($r,$title,$brcrum);
 2485: 
 2486:     if ($env{'form.command'} eq 'manageresv') {
 2487:         my $crstype = &Apache::loncommon::course_type();
 2488:         &manage_reservations($r,$crstype);
 2489:     } elsif ($env{'form.command'} eq 'showresv') {
 2490:         &show_reservations($r,$env{'form.uname'},$env{'form.udom'});
 2491:     } elsif ($env{'form.command'} eq 'showslots' && $vgr eq 'F') {
 2492: 	&show_table($r,$mgr);
 2493:     } elsif ($env{'form.command'} eq 'remove_registration' && $mgr eq 'F') {
 2494: 	&remove_registration($r);
 2495:     } elsif ($env{'form.command'} eq 'release' && $mgr eq 'F') {
 2496: 	if ($env{'form.entry'} eq 'remove all') {
 2497: 	    &release_all_slot($r,$mgr);
 2498: 	} else {
 2499: 	    &release_slot($r,undef,undef,undef,$mgr);
 2500: 	}
 2501:     } elsif ($env{'form.command'} eq 'delete' && $mgr eq 'F') {
 2502: 	&delete_slot($r);
 2503:     } elsif ($env{'form.command'} eq 'uploadstart' && $mgr eq 'F') {
 2504: 	&upload_start($r);
 2505:     } elsif ($env{'form.command'} eq 'csvuploadmap' && $mgr eq 'F') {
 2506: 	&csv_upload_map($r);
 2507:     } elsif ($env{'form.command'} eq 'csvuploadassign' && $mgr eq 'F') {
 2508: 	if ($env{'form.associate'} ne 'Reverse Association') {
 2509: 	    &csv_upload_assign($r,$mgr);
 2510: 	} else {
 2511: 	    if ( $env{'form.upfile_associate'} ne 'reverse' ) {
 2512: 		$env{'form.upfile_associate'} = 'reverse';
 2513: 	    } else {
 2514: 		$env{'form.upfile_associate'} = 'forward';
 2515: 	    }
 2516: 	    &csv_upload_map($r);
 2517: 	}
 2518:     } elsif ($env{'form.command'} eq 'slotlog' && $mgr eq 'F') {
 2519:         &show_reservations_log($r);
 2520:     } else {
 2521: 	my $symb=&unescape($env{'form.symb'});
 2522: 	if (!defined($symb)) {
 2523: 	    &fail($r,'not_valid');
 2524: 	    return OK;
 2525: 	}
 2526: 	my (undef,undef,$res)=&Apache::lonnet::decode_symb($symb);
 2527: 	my $useslots = &Apache::lonnet::EXT("resource.0.useslots",$symb);
 2528: 	if ($useslots ne 'resource' 
 2529: 	    && $useslots ne 'map' 
 2530: 	    && $useslots ne 'map_map') {
 2531: 	    &fail($r,'not_available');
 2532: 	    return OK;
 2533: 	}
 2534: 	$env{'request.symb'}=$symb;
 2535: 	my $type = ($res =~ /\.task$/) ? 'Task'
 2536: 	                               : 'problem';
 2537: 	my ($status) = &Apache::lonhomework::check_slot_access('0',$type);
 2538: 	if ($status eq 'CAN_ANSWER' ||
 2539: 	    $status eq 'NEEDS_CHECKIN' ||
 2540: 	    $status eq 'WAITING_FOR_GRADE') {
 2541: 	    &fail($r,'not_allowed');
 2542: 	    return OK;
 2543: 	}
 2544: 	if ($env{'form.requestattempt'}) {
 2545: 	    &show_choices($r,$symb);
 2546: 	} elsif ($env{'form.command'} eq 'release') {
 2547: 	    &release_slot($r,$symb);
 2548: 	} elsif ($env{'form.command'} eq 'get') {
 2549: 	    &get_slot($r,$symb);
 2550: 	} elsif ($env{'form.command'} eq 'change') {
 2551: 	    if (&get_slot($r,$symb,$env{'form.releaseslot'},1)) {
 2552: 		&release_slot($r,$symb,$env{'form.releaseslot'});
 2553: 	    }
 2554: 	} else {
 2555: 	    $r->print('<p>'.&mt('Unknown command: [_1]',$env{'form.command'}).'</p>');
 2556: 	}
 2557:     }
 2558:     &end_page($r);
 2559:     return OK;
 2560: }
 2561: 
 2562: 1;
 2563: __END__

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