File:  [LON-CAPA] / loncom / interface / slotrequest.pm
Revision 1.125: download - view: text, annotated - select for diffs
Wed Sep 23 20:09:07 2015 UTC (8 years, 8 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_11_X, HEAD
- Typo.

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

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