<?php
/**
Map manager page
@author ricky barrette
@author Twenty Codes, LLC
*/
include("classes/auth.php");
include("classes/access.php");
require_once('classes/conf.php');
  
include("classes/header.php");

echo <<<FORM
<html>
<body>
<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="package">Package:</label>
<br/>
<input name="package" id="package" type="text" maxlength="5555500"  size=50%/>
<br/>
<label for="package">Build:</label>
<br/>
<input name="build" id="build" type="text" maxlength="5555500"  size=50%/>
<br/>
<label for="file">File:</label>
<input type="file" name="file" id="file" accept="text/plain" /> 
<br />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
FORM;

/*
delete a map if needed
*/
if($_REQUEST["delete"])
  if($_REQUEST["delete"] != ".htaccess")
    if($_REQUEST["delete"] != "style.css"){
      if(file_exists(MAP_LOCATION. $_REQUEST["delete"]))
        if(unlink(MAP_LOCATION.$_REQUEST["delete"]))
          echo "Deteled ". $_REQUEST["delete"] . "<br/><br/>";
    }

/*
display the maps
*/
$hasMaps = false;
if ($handle = opendir(MAP_LOCATION)) {
    echo "<b>Existing Maps </b><br/><br/>";
    /* This is the correct way to loop over the directory. */
    while (false !== ($file = readdir($handle))) {
        if($file != ".htaccess")
          if($file != "style.css")
            if($file != ".")
              if($file !=".."){
                echo <<<MAP
                    <a href="?delete=$file" onclick="return confirm('Are you sure You want to delete this Map forever?');">$file</a>
                    <br/>
MAP;
                $hasMaps = true;
              }
    }
    closedir($handle);
    
    if(!$hasMaps)
      echo"<strong>There are no maps yet</strong>";
}

echo "<br/>";

include("classes/footer.php");
?>
