<?php

// -------------------- Map Display ----------------------
// Author...: Death
// Author...: Greg Taylor (gtaylor@clemson.edu)
// -------------------------------------------------------

global $opts, $parsed_opts;

  require_once('../class2.php');
  require_once(HEADERF);

  $caption = "Frontier Maps";

// Handles the calling of image generation scripts.
function show_map() {
   global $opts;
  
   if (!have_vars()) { 
      $output .= '<td><img src="genmap.php?dw=1&amp;dl=1" alt="Terrain Map"></td>';
      $output .= '<td><img src="genmap.php?dt=1&amp;db=1&amp;dr=1&amp;dg=1&amp;dl=1" alt="Objective Map"></td>';
   } else {
      $output .= '<td colspan="2">
                    <img src="genmap.php?'. parse_opts() .'" alt="Frontier Map">
                    <br />
                    <center><a href="'. $thispage .'">Back to default maps</a></center>
                  </td>';
   }

   return $output;
} // end show_map()

// Return the stuff we need with the <img> tag to call a map
function parse_opts() {
   global $opts, $parsed_opts;

   $temp  = "mac=". $opts['mac'];
   $temp .= "&amp;dt=".  $opts['dt'];
   $temp .= "&amp;dl=".  $opts['dl'];
   $temp .= "&amp;dc=".  $opts['dc'];
   $temp .= "&amp;db=".  $opts['db'];
   $temp .= "&amp;dr=".  $opts['dr'];
   $temp .= "&amp;dg=".  $opts['dg'];
   $temp .= "&amp;dw=".  $opts['dw'];

   return $temp;
} // end parse_opts()

// Determine whether to draw a single map with the vars or the default two.
function have_vars() {
   global $opts;

   if ($opts['mac'] || $opts['dt'] || $opts['dl'] || $opts['dc'] || $opts['db'] || $opts['dr'] || $opts['dg'] || $opts['dw'])
      $temp = 1;

   return $temp;
} // end hav_vars()

// Going through POST variables
   $opts['mac'] = ($_POST["mac"] == 1 ? 1 : '0');
   $opts['dt']  = ($_POST["dt"]  == 1 ? 1 : '0');
   $opts['dl']  = ($_POST["dl"]  == 1 ? 1 : '0');
   $opts['dc']  = ($_POST["dc"]  == 1 ? 1 : '0');
   $opts['db']  = ($_POST["db"]  == 1 ? 1 : '0');
   $opts['dr']  = ($_POST["dr"]  == 1 ? 1 : '0');
   $opts['dg']  = ($_POST["dg"]  == 1 ? 1 : '0');
   $opts['dw']  = ($_POST["dw"]  == 1 ? 1 : '0');

// Main

   $display .= '<table border="0" align="center">
                  <tr>'. show_map() .'</tr>
                  <tr>
                    <td colspan="2" style="text-align: center">
                      Squares = Bases, Diamonds = Generators, Circles = Relays
                    </td>
                </table>';

   $display .= '<form action="'. $thispage .'" method="POST">
                <table border="0" align="center">
                  <tr>
                    <td><input type="checkbox" name="mac" value="1" '. ($opts['mac'] ? "checked" : "") .'/>
                        <B>Enable Macintosh brightness settings</B> (This will make the image darker)</td>
                  </tr>
                  <tr>
                    <td><input type="checkbox" name="dt"  value="1" '. ($opts['dt'] ? "checked" : "") .'/>
                        <B>Grayscale terrain</B> (Makes it easier to read with any of the below selected)</td>
                  </tr>
                  <tr>
                    <td><input type="checkbox" name="dl"  value="1" checked '. ($opts['dl'] ? "checked" : "") .'/>
                        <B>Show ID Numbers</B> (Matches up with baselist, relaylist, genlist, warplist)</td>
                  </tr>
                  <tr>
                    <td><input type="checkbox" name="dc"  value="1" checked '. ($opts['dc'] ? "checked" : "") .' />
                        <B>Show Coordinates</B> (Shows coordinates for any of the below)</td>
                  </tr>
                  <tr>
                    <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <input type="checkbox" name="db"  value="1" '. ($opts['db'] ? "checked" : "") .'/>
                        <B>Show bases</B></td>
                  </tr>
                  <tr>
                    <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <input type="checkbox" name="dr"  value="1" '. ($opts['dr'] ? "checked" : "") .'/>
                        <B>Show relay towers</B></td>
                  </tr>
                  <tr>
                    <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <input type="checkbox" name="dg"  value="1" '. ($opts['dg'] ? "checked" : "") .'/>
                        <B>Show generators</B></td>
                  </tr>
                  <tr>
                    <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <input type="checkbox" name="dw"  value="1" '. ($opts['dw'] ? "checked" : "") .'/>
                        <B>Show warps</B></td>
                  </tr>
                 </table>
                 <br />
                 <center>
                   <button type="submit">Generate Map</button>&nbsp
                   <button type="reset">Clear Options</button>
                 </center>';
   $display .= "<br /><center><a href='currmap.map'>Download a copy of the .map file for your HUD or Map Editor</a></center>";

  $ns -> tablerender($caption, $display);
  require_once(FOOTERF);
?>
   
