--- loncom/interface/slotrequest.pm	2018/09/02 02:22:09	1.125.2.5
+++ loncom/interface/slotrequest.pm	2015/09/27 14:21:48	1.129
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler for requesting to have slots added to a students record
 #
-# $Id: slotrequest.pm,v 1.125.2.5 2018/09/02 02:22:09 raeburn Exp $
+# $Id: slotrequest.pm,v 1.129 2015/09/27 14:21:48 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -260,6 +260,103 @@ function uncheckSlotRadio() {
         }
     }
 }
+
+function toggleSlotMap(maprownum,rownum) {
+    if (document.getElementById('arrow'+maprownum)) {
+        var img = document.getElementById('arrow'+maprownum);
+        var rowdisplay;
+        var celldisplay = '';
+        if (img.src.indexOf('arrow.open.gif')!=-1) {
+            img.src = '/adm/lonIcons/arrow.closed.gif';
+            rowdisplay = 'none';
+        }
+        else {
+            img.src = '/adm/lonIcons/arrow.open.gif';
+            rowdisplay = 'table-row';
+            celldisplay = 'none';
+        }
+        var resrows;
+        var maptext;
+        if (document.getElementsByClassName) {
+            resrows = document.getElementsByClassName('LC_slotresrow_'+maprownum);
+            maptext = document.getElementsByClassName('LC_slotmaptext_'+maprownum);
+        } else {
+            resrows = getElementsByClassName(document.body,'LC_slotresrow_'+maprownum);
+            maptext = getElementsByClassName(document.body,'LC_slotmaptext_'+maprownum);
+        }
+        if (maptext.length) {
+            for (var i=0; i<maptext.length; i++) {
+                maptext[i].style.display = celldisplay;
+            }
+        }
+        if (resrows.length) {
+           var mapbgidx = 0;
+           var rowclasses = ['LC_even_row','LC_odd_row'];
+           var mapbgClass = 'LC_even_row';
+           var regExpBg = /LC_odd_row/i;
+           if (rowdisplay == 'table-row') {
+                if (document.getElementById('LC_slotmaprow_'+rownum)) {
+                    mapbgClass = document.getElementById('LC_slotmaprow_'+rownum).className;
+                    if (regExpBg.test(mapbgClass)) {
+                        mapbgidx = 1;
+                    }
+                }
+            }
+            for (var i=0; i<resrows.length; i++) {
+                resrows[i].style.display = rowdisplay;
+                if (rowdisplay == 'table-row') {
+                    mapbgidx ++;        
+                    var bgcolnew = mapbgidx % 2;
+                    var bgcolold = (mapbgidx+1) % 2;
+                    var k = i+parseInt(rownum)+1; 
+                    if (document.getElementById('LC_slotresrow_'+k)) {
+                        document.getElementById('LC_slotresrow_'+k).className = document.getElementById('LC_slotresrow_'+k).className.replace(rowclasses[bgcolold],rowclasses[bgcolnew]);
+                    }
+                }
+            }
+            if (document.getElementById('LC_slot_reservations')) {
+                var numrowsOdd = resrows.length % 2;
+                if (numrowsOdd) {
+                    var lastbgClass = 'LC_even_row';
+                    var idx = 0;
+                    var lastresnum = parseInt(rownum) + resrows.length; 
+                    if (rowdisplay == 'none') {
+                        lastresnum = rownum;
+                        if (document.getElementById('LC_slotmaprow_'+rownum)) {
+                            lastbgClass = document.getElementById('LC_slotmaprow_'+rownum).className;
+                        }
+                    } else {
+                        lastresnum = parseInt(rownum) + resrows.length;
+                        if (document.getElementById('LC_slotresrow_'+lastresnum)) {
+                            lastbgClass = document.getElementById('LC_slotresrow_'+lastresnum).className;
+                        }
+                    }
+                    if (regExpBg.test(lastbgClass)) {
+                        idx = 1;
+                    }
+                    var table = document.getElementById('LC_slot_reservations');
+                    if ((table.rows.length) && (table.rows.length >= lastresnum)) {
+                        for (var i=lastresnum; i<table.rows.length; i++) {
+                            if (table.rows[i].style.display != 'none') {
+                                idx ++;
+                                var bgcolnew = idx % 2;
+                                var bgcolold = (idx+1) % 2;  
+                                j = i+1;
+                                if (document.getElementById('LC_slotmaprow_'+j)) {
+                                    document.getElementById('LC_slotmaprow_'+j).className = rowclasses[bgcolnew];
+                                } else {
+                                    if (document.getElementById('LC_slotresrow_'+j)) {
+                                        document.getElementById('LC_slotresrow_'+j).className = document.getElementById('LC_slotresrow_'+j).className.replace(rowclasses[bgcolold],rowclasses[bgcolnew]);
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+}
 // ]]>
 </script>
 ENDSCRIPT
@@ -744,10 +841,10 @@ sub release_reservation {
                                action  => 'release',
                                context => $env{'form.context'},
                         );
-            &Apache::lonnet::write_log('course','slotreservationslog',
-                                       \%storehash,1,$uname,$udom,$cnum,$cdom);
-            &Apache::lonnet::write_log('course',$cdom.'_'.$cnum.'_slotlog',
-                                       \%storehash,1,$uname,$udom,$uname,$udom);
+            &Apache::lonnet::write_log('slotreservationslog',\%storehash,
+                                       1,$uname,$udom,$cnum,$cdom);
+            &Apache::lonnet::write_log($cdom.'_'.$cnum.'_slotlog',\%storehash,
+                                       1,$uname,$udom,$uname,$udom);
 	}
     }
 
@@ -841,15 +938,9 @@ sub get_slot {
     if ($slot_name && $slot_name ne $conflictable_slot) {
 	my %slot=&Apache::lonnet::get_slot($slot_name);
 	my $description1=&get_description($slot_name,\%slot);
-        my $slottype1=$slot{'type'};
 	%slot=&Apache::lonnet::get_slot($env{'form.slotname'});
 	my $description2=&get_description($env{'form.slotname'},\%slot);
-        if ($slottype1 eq 'preassigned') {
-            $r->print('<p>'.&mt('You already have a reservation: "[_1]", assigned by your instructor.',
-                                $description1).'</p>'.
-                      '<p>'.&mt('Your instructor must unassign it before you can make a new reservation.').
-                      '</p>');
-        } elsif ($slot_name ne $env{'form.slotname'}) {
+	if ($slot_name ne $env{'form.slotname'}) {
 	    $r->print(<<STUFF);
 <form method="post" action="/adm/slotrequest">
    <input type="hidden" name="symb" value="$env{'form.symb'}" />
@@ -1021,10 +1112,21 @@ sub allowed_slot {
     return 0 if (!$userallowed);
 
     # not allowed for this resource
-    if (defined($slot->{'symb'})
-	&& $slot->{'symb'} ne $symb) {
-        unless ((ref($toskip) eq 'HASH') && ($toskip->{'symb'})) {
-	    return 0;
+    if (defined($slot->{'symb'})) {
+        my $exclude = 1;
+        my ($slotmap,$slotid,$sloturl) = &Apache::lonnet::decode_symb($slot->{'symb'});
+        if ($sloturl=~/\.(page|sequence)$/) {
+            my ($map,$id,$url) = &Apache::lonnet::decode_symb($symb);
+            if (($map ne '') && ($map eq $slotmap)) {
+                $exclude = 0;
+            }
+        } elsif ($slot->{'symb'} eq $symb) {
+            $exclude = 0;
+        }
+        if ($exclude) {
+            unless ((ref($toskip) eq 'HASH') && ($toskip->{'symb'})) {
+	        return 0;
+            }
         }
     }
 
@@ -1053,7 +1155,7 @@ sub get_description {
 }
 
 sub show_choices {
-    my ($r,$symb,$formname,$num,$slots,$consumed_uniqueperiods,$available,$got_slots)=@_;
+    my ($symb,$formname,$num,$class,$slots,$consumed_uniqueperiods,$available,$got_slots)=@_;
     my $output;
     &Apache::lonxml::debug("Checking Slots");
     if (!ref($available) eq 'ARRAY') {
@@ -1065,8 +1167,11 @@ sub show_choices {
             $output .= ' <a href="/adm/flip?postdata=return:">'.
                        &mt('Return to last resource').'</a>';
         }
-        $r->print($output);
-        return;
+        if ($class) {
+            return '<div class="'.$class.'">'.$output.'</div>';
+        } else {
+            return $output;
+        }
     }
     if (@{$available} > 1) {
         my $numavailable = scalar(@{$available});
@@ -1214,8 +1319,11 @@ STUFF
     if (@{$available} > 1) {
         $output .= '</div></fieldset>';
     }
-    $r->print($output);
-    return;
+    if ($class) {
+        return '<div class="'.$class.'">'.$output.'</div>';
+    } else {
+        return $output;
+    }
 }
 
 sub to_show {
@@ -1370,7 +1478,7 @@ sub show_table {
 	     'secret'          => 'Secret Word',
 	     'space'           => '# of students/max',
 	     'ip'              => 'IP or DNS restrictions',
-	     'symb'            => 'Resource slot is restricted to.',
+	     'symb'            => 'Resource/Map slot is restricted to.',
 	     'allowedsections' => 'Sections slot is restricted to.',
 	     'allowedusers'    => 'Users slot is restricted to.',
 	     'uniqueperiod'    => 'Period of time slot is unique',
@@ -1482,16 +1590,15 @@ sub show_table {
     $r->print('</div>');
     $r->print('<p><input type="submit" name="start" value="'.&mt('Update Display').'" /></p>');
     my $linkstart='<a href="/adm/slotrequest?command=showslots&amp;order=';
-    my $tableheader = &Apache::loncommon::start_data_table().
-                      &Apache::loncommon::start_data_table_header_row().'
-                      <th></th>';
+    $r->print(&Apache::loncommon::start_data_table().
+	      &Apache::loncommon::start_data_table_header_row().'
+	       <th></th>');
     foreach my $which (@show_order) {
 	if ($which ne 'proctor' && exists($show{$which})) {
-	    $tableheader .= '<th>'.$linkstart.$which.'">'.$show_fields{$which}.'</a></th>';
+	    $r->print('<th>'.$linkstart.$which.'">'.$show_fields{$which}.'</a></th>');
 	}
     }
-    $tableheader .= &Apache::loncommon::end_data_table_header_row();
-    my $shownheader = 0;
+    $r->print(&Apache::loncommon::end_data_table_header_row());
 
     my %name_cache;
     my $slotsort = sub {
@@ -1640,39 +1747,30 @@ sub show_table {
                                                delete => 'Delete',
                                                slotlog => 'History',
         );
-        my ($edit,$delete,$showlog,$remove_all);
-        if ($mgr) {
-	    $edit=(<<"EDITLINK");
+	my $edit=(<<"EDITLINK");
 <a href="/adm/helper/newslot.helper?name=$slot">$lt{'edit'}</a>
 EDITLINK
 
-	    $delete=(<<"DELETELINK");
+	my $delete=(<<"DELETELINK");
 <a href="/adm/slotrequest?command=delete&amp;slotname=$slot">$lt{'delete'}</a>
 DELETELINK
 
-            $remove_all=&remove_link($slot,'remove all').'<br />';
-
-            if ($ids eq '') {
-                undef($remove_all);
-            } else {
-                undef($delete);
-            }
-        }
-
-        $showlog=(<<"LOGLINK");
+        my $showlog=(<<"LOGLINK");
 <a href="/adm/slotrequest?command=slotlog&amp;slotname=$slot">$lt{'slotlog'}</a>
 LOGLINK
 
+        my $remove_all=&remove_link($slot,'remove all').'<br />';
+
+        if ($ids eq '') {
+            undef($remove_all);
+        } else {
+            undef($delete);
+        }
 	if ($slots{$slot}{'type'} ne 'schedulable_student') {
             undef($showlog); 
 	    undef($remove_all);
 	}
 
-        unless ($shownheader) {
-            $r->print($tableheader);
-            $shownheader = 1;
-        }
-
 	my $row_start=&Apache::loncommon::start_data_table_row();
 	my $row_end=&Apache::loncommon::end_data_table_row();
         $r->print($row_start.
@@ -1741,12 +1839,7 @@ $row_end
 STUFF
         }
     }
-    if ($shownheader) {
-        $r->print(&Apache::loncommon::end_data_table());
-    } else {
-        $r->print('<p>'.&mt('No slots meet the criteria for display').'</p>');
-    }
-    $r->print('</form>');
+    $r->print(&Apache::loncommon::end_data_table().'</form>');
     return;
 }
 
@@ -1784,16 +1877,19 @@ sub manage_reservations {
         return;
     }
     my (%parent,%shownparent,%container,%container_title,%contents);
-    my ($depth,$count,$reservable,$lastcontainer,$rownum) = (0,0,0,0,0);
+    my ($depth,$count,$reservable,$lastcontainer,$rownum,$shown) = (0,0,0,0,0,0);
     my @backgrounds = ("LC_odd_row","LC_even_row");
     my $numcolors = scalar(@backgrounds);
     my $location=&Apache::loncommon::lonhttpdurl("/adm/lonIcons/whitespace_21.gif");
     my $slotheader = '<p>'.
                  &mt('Your reservation status for any such assignments is listed below:').
                  '</p>'.
-                 '<table class="LC_data_table LC_tableOfContent">'."\n";
+                 '<table class="LC_data_table LC_tableOfContent" id="LC_slot_reservations">'."\n";
     my $shownheader = 0;
     my $it=$navmap->getIterator(undef,undef,undef,1,undef,undef);
+    my (@ordered,%output,$mapitem,$got_map_slot,$currmapoutput,$mapnum);
+    $mapnum = 0;
+    $shown = 0;
     while (my $resource = $it->next()) {
         if ($resource == $it->BEGIN_MAP()) {
             $depth++;
@@ -1802,10 +1898,90 @@ sub manage_reservations {
         if ($resource == $it->END_MAP()) {
             $depth--;
             $lastcontainer = $parent{$depth};
+            my %allstatuses;
+            foreach my $symb (@ordered) {
+                if (ref($output{$symb}) eq 'HASH') {
+                    if (($output{$symb}{'type'} eq 'map_map') || ($output{$symb}{'type'} eq 'map')) {
+                        if ($output{$symb}{'slotstatus'} ne '') {
+                            if (ref($allstatuses{$output{$symb}{'slotstatus'}}) eq 'ARRAY') {
+                                push(@{$allstatuses{$output{$symb}{'slotstatus'}}},$symb);
+                            } else {
+                                $allstatuses{$output{$symb}{'slotstatus'}} = [$symb];
+                            }
+                        }
+                    }
+                }
+            }
+            if (keys(%allstatuses) == 1) {
+                $got_map_slot = 1;
+                my $repsymb;
+                my @values = values(%allstatuses);
+                if (ref($values[0]) eq 'ARRAY') {
+                    if (ref($output{$values[0][0]}) eq 'HASH') {
+                        $repsymb = $values[0][0];
+                    }
+                }
+                if (($mapitem) && ($repsymb)) {
+                    my $formnum = $mapnum.'_'.$output{$repsymb}{'reservable'};
+                    my $class = 'LC_slotmaptext_'.$mapnum;
+                    if ($output{$repsymb}{'hasaction'}) {
+                        $mapitem .= '<td valign="top"><span class="'.$class.'">'.
+                                    $output{$repsymb}{'msg'}.
+                                    '</span></td><td valign="top">'.
+                                    &slot_chooser($repsymb,$class,$formnum,$allavailable,$slots,
+                                                  $consumed_uniqueperiods).
+                                   '</td>';
+
+                    } else {
+                        $mapitem .= '<td colspan="2" valign="middle"><span class="'.$class.'">'.
+                                    $output{$repsymb}{'msg'}.
+                                    '</span></td>';
+                    }
+                }
+                my $counter = 0;
+                foreach my $symb (@ordered) {
+                    if (ref($output{$symb}) eq 'HASH') {
+                        $counter ++;
+                        my $bgcolor = $backgrounds[($output{$symb}{'shown'} + $counter) % $numcolors];
+                        $currmapoutput .= $output{$symb}{'header'}.
+                                          '<tr class="'.$bgcolor.' LC_slotresrow_'.$output{$symb}{'mapnum'}.'"'.
+                                          ' style="display:none" id="LC_slotresrow_'.$output{$symb}{'rownum'}.'">'.
+                                          $output{$symb}{'info'}.
+                                          $output{$symb}{'data'}.'</tr>'."\n";
+                    }
+                }
+            } else {
+                my $counter = 0;
+                foreach my $symb (@ordered) {
+                    if (ref($output{$symb}) eq 'HASH') {
+                        $counter ++;
+                        my $bgcolor = $backgrounds[($output{$symb}{'shown'} + $counter) % $numcolors];
+                        $currmapoutput .= $output{$symb}{'header'}.
+                                          '<tr class="'.$bgcolor.' LC_slotresrow_'.$output{$symb}{'mapnum'}.'"'.
+                                          ' style="display:table-row" id="LC_slotresrow_'.$output{$symb}{'rownum'}.'">'.
+                                          $output{$symb}{'info'}.
+                                          $output{$symb}{'data'}.'</tr>'."\n";
+                        $shown ++;
+                    }
+                }
+            }
+            if ($mapitem) {
+                if ($got_map_slot) {
+                    $mapitem =~ s{(<img src=\"/adm/lonIcons/arrow\.)open(\.gif\")}{$1closed$2};
+                    $mapitem .= '</tr>'."\n";
+                } else {
+                    $mapitem .= '<td colspan="2">&nbsp;</td></tr>'."\n";
+                }
+            }
+            $r->print($mapitem.$currmapoutput);
+            @ordered=();
+            undef(%output);
+            $currmapoutput = '';
+            $got_map_slot = '';
+            $mapitem = '';
         }
         if (ref($resource)) {
             my $symb = $resource->symb();
-            my $ressymb = $symb;
             $contents{$lastcontainer} ++;
             next if (!$resource->is_problem() && !$resource->is_sequence() && 
                      !$resource->is_page());
@@ -1818,10 +1994,15 @@ sub manage_reservations {
             if ($resource->is_problem()) {
                 my ($useslots) = $resource->slot_control();
                 next if (($useslots eq '') || ($useslots =~ /^\s*no\s*$/i));
+                push(@ordered,$symb); 
+                $output{$symb}{type} = $useslots;  
                 my ($msg,$get_choices,$slotdescription);
                 my $title = $resource->compTitle();
                 my $status = $resource->simpleStatus('0');
                 my ($slot_status,$date,$slot_name) = $resource->check_for_slot('0');
+
+                $output{$symb}{'slotstatus'} = $slot_status;
+                $output{$symb}{'slotname'} = $slot_name; 
                 if ($slot_name ne '') {
                     my %slot=&Apache::lonnet::get_slot($slot_name);
                     $slotdescription=&get_description($slot_name,\%slot);
@@ -1865,7 +2046,9 @@ sub manage_reservations {
                         $msg = &Apache::lonnavmaps::getDescription($resource,'0'); 
                     }
                 }
+                $output{$symb}{'msg'} = $msg;
                 $reservable ++;
+                $output{$symb}{'reservable'} = $reservable;
                 my $treelevel = $depth;
                 my $higherup = $lastcontainer;
                 if ($depth > 1) {
@@ -1886,76 +2069,71 @@ sub manage_reservations {
                         $treelevel --;
                         $higherup = $parent{$treelevel};
                     }
-                    foreach my $item (@maprows) {
+                    for (my $i=0; $i<@maprows; $i++) {
+                        $mapnum ++;
                         $rownum ++;
-                        my $bgcolor = $backgrounds[$rownum % $numcolors];
+                        $shown ++;
+                        my $bgcolor = $backgrounds[$shown % $numcolors];
                         if (!$shownheader) {
-                            $r->print($slotheader);
+                            $mapitem .= $slotheader;
                             $shownheader = 1;
                         }
-                        $r->print('<tr class="'.$bgcolor.'">'.$item.'</tr>'."\n");
+                        if (ref($maprows[$i]) eq 'ARRAY') {
+                            if ($i < scalar(@maprows)-1) {
+                                $mapitem .= '<tr class="'.$bgcolor.'" id="LC_slotmaprow_'.$rownum.'">'.
+                                            '<td>'.join('',@{$maprows[$i]}).'</td>'.
+                                            '<td colspan="2">&nbsp;</td></tr>'."\n";
+                            } else {
+                                $mapitem .= 
+                                   '<tr class="'.$bgcolor.'" id="LC_slotmaprow_'.$rownum.'">'.
+                                   '<td>'.$maprows[$i][0].
+                                   '<img src="/adm/lonIcons/arrow.open.gif" id="arrow'.$mapnum.'" '.
+                                   'alt="arrow" onmouseover="this.style.cursor=\'pointer\'" '.
+                                   'onclick="'."toggleSlotMap('$mapnum','$rownum');".'" />'.
+                                   $maprows[$i][1].('&nbsp;' x6).'</td>'."\n";
+                            }
+                        }
                     }
+                    $output{$symb}{'mapnum'} = $mapnum;
                 }
                 $rownum ++;
-                my $bgcolor = $backgrounds[$rownum % $numcolors];
+                $output{$symb}{'rownum'} = $rownum;
+                $output{$symb}{'shown'} = $shown;
                 if (!$shownheader) {
-                    $r->print($slotheader);
+                    $output{$symb}{'header'} = $slotheader;
                     $shownheader = 1;
                 }
-                $r->print('<tr class="'.$bgcolor.'"><td>'."\n");
+                $output{$symb}{'info'} = '<td>';
                 for (my $i=0; $i<$depth; $i++) {
-                    $r->print('<img src="'.$location.'" alt="" />');
+                    $output{$symb}{'info'} .= '<img src="'.$location.'" alt="" />';
                 }
-                my $result = '<a href="'.$resource->src().'?symb='.$symb.'">'.
-                             '<img class="LC_contentImage" src="/adm/lonIcons/';
+                $output{$symb}{'info'} .= '<a href="'.$resource->src().'?symb='.$symb.'">'.
+                                         '<img class="LC_contentImage" src="/adm/lonIcons/';
                 if ($resource->is_task()) {
-                    $result .= 'task.gif" alt="'.&mt('Task');
+                    $output{$symb}{'info'} .= 'task.gif" alt="'.&mt('Task');
                 } else {
-                    $result .= 'problem.gif" alt="'.&mt('Problem');
+                    $output{$symb}{'info'} .= 'problem.gif" alt="'.&mt('Problem');
                 }
-                $result .= '" /><b>'.$title.'</b></a>'.('&nbsp;' x6).'</td>';
+                $output{$symb}{'info'} .= '" /><b>'.$title.'</b></a>'.('&nbsp;' x6).'</td>';
+
                 my $hasaction;
                 if ($status == $resource->OPEN) {
                     if ($get_choices) {
                         $hasaction = 1;
+                        $output{$symb}{'hasaction'} = $hasaction;
                     }
                 }
+                my $class = 'LC_slottext_'.$mapnum;
                 if ($hasaction) {
-                    $result .= '<td valign="top">'.$msg.'</td>'.
-                               '<td valign="top">';
+                    $output{$symb}{'data'} = '<td valign="top"><span class="'.$class.'">'.$msg.'</span></td>'.
+                                             '<td valign="top">'.
+                                             &slot_chooser($symb,$class,$reservable,$allavailable,$slots,
+                                                           $consumed_uniqueperiods).'</td>';
                 } else {
-                    $result .= '<td colspan="2" valign="middle">'.$msg.'</td>';
-                }
-                $r->print($result);
-                if ($hasaction) {
-                    my @got_slots=&check_for_reservation($symb,'allslots');
-                    if ($got_slots[0] =~ /^error: /) {
-                        $r->print('<span class="LC_error">'.
-                                  &mt('An error occurred determining slot availability.').
-                                  '</span>');
-                    } else {
-                        my $formname = 'manageres_'.$reservable;
-                        if (ref($allavailable) eq 'ARRAY') {
-                            my @available;
-                            if (ref($slots) eq 'HASH') {
-                                foreach my $slot (@{$allavailable}) {
-                                # not allowed for this resource
-                                    if (ref($slots->{$slot}) eq 'HASH') {
-                                        if ((defined($slots->{$slot}->{'symb'})) && 
-                                            ($slots->{$slot}->{'symb'} ne $symb)) {
-                                            next;
-                                        }
-                                    }
-                                    push(@available,$slot);
-                                }
-                            }  
-                            &show_choices($r,$symb,$formname,$reservable,$slots,$consumed_uniqueperiods,
-                                          \@available,\@got_slots);
-                        }
-                    }
-                    $r->print('</td>');
+                    $output{$symb}{'data'} = '<td colspan="2" valign="middle">'.
+                                             '<span class="'.$class.'">'.$msg.'</span>'.
+                                             '</td>';
                 }
-                $r->print('</tr>');
             }
         }
     }
@@ -1977,20 +2155,53 @@ sub manage_reservations {
 
 sub show_map_row {
     my ($depth,$location,$type,$title,$maprows) = @_;
-    my $output = '<td>';
-    for (my $i=0; $i<$depth-1; $i++) {
-        $output .= '<img src="'.$location.'" alt="" />';
+    my $spacers;
+    for (my $i=0; $i<$depth-2; $i++) {
+        $spacers .= '<img src="'.$location.'" alt="" />';
     }
+    my $icon;
     if ($type eq 'page') {
-        $output .= '<img src="/adm/lonIcons/navmap.page.open.gif" alt="" />&nbsp;'."\n";
+        $icon = '<img src="/adm/lonIcons/navmap.page.open.gif" alt="" />&nbsp;'."\n";
     } else {
-        $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" />&nbsp;'."\n";
+        $icon = '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" />&nbsp;'."\n";
     }
-    $output .= $title.'</td><td colspan="2">&nbsp;</td>'."\n";
-    unshift (@{$maprows},$output);
+    $icon .= $title;
+    unshift (@{$maprows},[$spacers,$icon]);
     return;
 }
 
+sub slot_chooser {
+    my ($symb,$class,$formnum,$allavailable,$slots,$consumed_uniqueperiods) = @_;
+    my $output;
+    my @got_slots=&check_for_reservation($symb,'allslots');
+    if ($got_slots[0] =~ /^error: /) {
+        $output = '<span class="'.$class.'"><span class="LC_error">'.
+                  &mt('An error occurred determining slot availability.').
+                  '</span></span>';
+    } else {
+        my $formname = 'manageres_'.$formnum;
+        if (ref($allavailable) eq 'ARRAY') {
+            my @available;
+            if (ref($slots) eq 'HASH') {
+                foreach my $slot (@{$allavailable}) {
+                    # not allowed for this resource
+                    if (ref($slots->{$slot}) eq 'HASH') {
+                        if ((defined($slots->{$slot}->{'symb'})) &&
+                            ($slots->{$slot}->{'symb'} ne $symb)) {
+                            next;
+                        }
+                    }
+                    push(@available,$slot);
+                }
+            }
+            $output .= &show_choices($symb,$formname,$formnum,$class,
+                                     $slots,$consumed_uniqueperiods,
+                                     \@available,\@got_slots);
+        }
+    }
+    return $output;
+}
+
 sub show_reservations {
     my ($r,$uname,$udom) = @_;
     if (!defined($uname)) {
@@ -2102,16 +2313,14 @@ sub show_reservations {
     if ($showntablehdr) {
         $r->print(&Apache::loncommon::end_data_table().'<br />');
         if (($curr{'page'} > 1) || ($more_records)) {
-            $r->print('<p>');
+            $r->print('<table><tr>');
             if ($curr{'page'} > 1) {
-                $r->print('<input type="button" onclick="javascript:chgPage('."'previous'".');" value="'.
-                          &mt('Previous [_1] changes',$curr{'show'}).'" />');
+                $r->print('<td><a href="javascript:chgPage('."'previous'".');">'.&mt('Previous [_1] changes',$curr{'show'}).'</a></td>');
             }
             if ($more_records) {
-                $r->print('<input type="button" onclick="javascript:chgPage('."'next'".');" value="'.
-                          &mt('Next [_1] changes',$curr{'show'}).'" />');
+                $r->print('<td><a href="javascript:chgPage('."'next'".');">'.&mt('Next [_1] changes',$curr{'show'}).'</a></td>');
             }
-            $r->print('</p>');
+            $r->print('</tr></table>');
             $r->print(<<"ENDSCRIPT");
 <script type="text/javascript">
 // <![CDATA[
@@ -2315,16 +2524,14 @@ sub show_reservations_log {
     if ($showntablehdr) {
         $r->print(&Apache::loncommon::end_data_table().'<br />');
         if (($curr{'page'} > 1) || ($more_records)) {
-            $r->print('<p>');
+            $r->print('<table><tr>');
             if ($curr{'page'} > 1) {
-                $r->print('<input type="button" onclick="javascript:chgPage('."'previous'".');" value="'.
-                          &mt('Previous [_1] changes',$curr{'show'}).'" />');
+                $r->print('<td><a href="javascript:chgPage('."'previous'".');">'.&mt('Previous [_1] changes',$curr{'show'}).'</a></td>');
             }
             if ($more_records) {
-                $r->print('<input type="button" onclick="javascript:chgPage('."'next'".');" value="'.
-                          &mt('Next [_1] changes',$curr{'show'}).'" />');
+                $r->print('<td><a href="javascript:chgPage('."'next'".');">'.&mt('Next [_1] changes',$curr{'show'}).'</a></td>');
             }
-            $r->print('</p>');
+            $r->print('</tr></table>');
             $r->print(<<"ENDSCRIPT");
 <script type="text/javascript">
 function chgPage(caller) {
@@ -2464,9 +2671,8 @@ sub display_filter {
         }
         $output .= '</select></td>';
     }
-    $output .= '<td>&nbsp;&nbsp;</td></tr></table>'.
-               '<p><input type="submit" value="'.
-               &mt('Update Display').'" /></p>'.
+    $output .= '<td>&nbsp;&nbsp;</td><td valign="middle"><input type="submit" value="'.
+               &mt('Update Display').'" /></tr></table>'.
                '<p class="LC_info">'.
                &mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
                   ,'2.9.0');
@@ -2713,7 +2919,7 @@ sub csvupload_fields {
 	    ['proctor','List of proctor ids'],
 	    ['description','Slot Description'],
 	    ['maxspace','Maximum number of reservations'],
-	    ['symb','Resource Restriction'],
+	    ['symb','Resource/Map Restriction'],
 	    ['uniqueperiod','Date range of slot exclusion'],
 	    ['secret','Secret word proctor uses to validate'],
 	    ['allowedsections','Sections slot is restricted to'],
@@ -2781,12 +2987,8 @@ sub csv_upload_assign {
 	}
 
 	if ($entries{$fields{'startreserve'}}) {
-            my $date = &UnixDate($entries{$fields{'startreserve'}},"%s");
-            if ($date eq '') {
-                push(@errors,"$name -- No reservation start time set for slot -- value provided had invalid format");
-            } else {
-                $slot{'startreserve'} = $date;
-            }
+	    $slot{'startreserve'}=
+		&UnixDate($entries{$fields{'startreserve'}},"%s");
 	}
 	if (defined($slot{'startreserve'})
 	    && $slot{'startreserve'} > $slot{'starttime'}) {
@@ -2795,12 +2997,8 @@ sub csv_upload_assign {
 	}
 
         if ($entries{$fields{'endreserve'}}) {
-            my $date = &UnixDate($entries{$fields{'endreserve'}},"%s");
-            if ($date eq '') {
-                push(@errors,"$name -- No reservation end time set for slot -- value provided had invalid format");
-            } else {
-                $slot{'endreserve'} = $date;
-            }
+            $slot{'endreserve'}=
+                &UnixDate($entries{$fields{'endreserve'}},"%s");
         }
         if (defined($slot{'endreserve'})
             && $slot{'endreserve'} > $slot{'starttime'}) {
@@ -2860,14 +3058,12 @@ sub csv_upload_assign {
             }
         }
 	if ($entries{$fields{'uniqueperiod'}}) {
-            my ($start,$end)= map { &UnixDate($_,"%s"); } split(',',$entries{$fields{'uniqueperiod'}});
-            if (($start ne '') && ($end ne '')) {
-                $slot{'uniqueperiod'}=[$start,$end];
-            } else {
-                push(@errors,"$name -- Slot's unique period ignored -- one or both of the comma separated values for start and end had an invalid format");
-            }
+	    my ($start,$end)=split(',',$entries{$fields{'uniqueperiod'}});
+	    my @times=(&UnixDate($start,"%s"),
+		       &UnixDate($end,"%s"));
+	    $slot{'uniqueperiod'}=\@times;
 	}
-	if (ref($slot{'uniqueperiod'}) eq 'ARRAY' 
+	if (defined($slot{'uniqueperiod'})
 	    && $slot{'uniqueperiod'}[0] > $slot{'uniqueperiod'}[1]) {
 	    push(@errors,"$name not created -- Slot's unique period start time is later than the unique period's end time.");
 	    next;
@@ -3030,7 +3226,7 @@ sub handler {
 	    }
 	    &csv_upload_map($r);
 	}
-    } elsif (($env{'form.command'} eq 'slotlog') && ($vgr eq 'F')) {
+    } elsif ($env{'form.command'} eq 'slotlog' && $mgr eq 'F') {
         &show_reservations_log($r);
     } else {
 	my $symb=&unescape($env{'form.symb'});
@@ -3058,7 +3254,7 @@ sub handler {
 	}
 	if ($env{'form.requestattempt'}) {
             $r->print('<div class="LC_left_float">'); 
-	    &show_choices($r,$symb,undef,undef,\%slots,$consumed_uniqueperiods,$available,$got_slots);
+	    $r->print(&show_choices($symb,undef,undef,undef,\%slots,$consumed_uniqueperiods,$available,$got_slots));
             $r->print('</div><div style="padding:0;clear:both;margin:0;border:0"></div>');
 	} elsif ($env{'form.command'} eq 'release') {
 	    &release_slot($r,$symb);