Annotation of loncom/interface/slotrequest.pm, revision 1.48.2.3

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

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