<?php
try
{
  //error_reporting(E_ALL); ini_set('display_errors', 1);
  require_once "./pineapple.php";
  require_once "./mysql/helper.php";
  pineapple_html_begin("Pineapple PNP", "Pineapple Library Parts List");

  $db = db_connect("pontech_pineapplepnp");

  //print ("<br />");
  //print ("<pre>");
  //print_r($_GET);
  //print_r($_POST);
  //print_r($_POST["part_type_dropdown"]);
  //print_r($GLOBALS);
  //print_r($_SERVER);
  //print_r($_SESSION); // Security threat to display this array
  //echo 'GET[name] = ' . htmlspecialchars($_GET["name"]) . '!';
  //print ("</pre>");

  //$statement = "DROP TABLE upload";
  //$db->query ($statement);

  /*$statement = "CREATE TABLE upload (
  id INT NOT NULL AUTO_INCREMENT,
  email VARCHAR(100) NOT NULL,
  name VARCHAR(200) NOT NULL,
  type VARCHAR(30) NOT NULL,
  size INT NOT NULL,
  content MEDIUMBLOB NOT NULL,
  PRIMARY KEY(id)
  )";*/

  if(!isset($_SESSION['email']) ) {
    ?>
      <h1>You must sign in to upload a file</h1>
    <?php
    goto exit_page;
  }
  
  $statement = "SELECT id, name, size, type, upload_date FROM upload WHERE email = ? ORDER BY upload_date DESC";
  $prepared_array = array($_SESSION['email']);
  db_table_prepared($db, $statement, $prepared_array,
                    "t01", // table name
                    array(array(""),
                    array("link"=>"pineapple_download.php", array(
                                'id'=>'id')),
                    array(""),
                    array("")
                ));

?>
  <br />
  All files to build a single board must be present in a single zip file.
  The means the .brd, .sch and any other supporting documentation.
  <br />
	<form action="pineapple_upload.php" method="post" id="form1" enctype="multipart/form-data">
    <table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
      <tr>
        <td width="246">
          <input type="hidden" name="MAX_FILE_SIZE" value="4000000">
          <input name="userfile" type="file" id="userfile"> 
        </td>
        <td width="80">
          <input name="upload" type="submit" class="box" id="upload" value=" Upload ">
        </td>
      </tr>
    </table>
  </form>
<?php

  $db = NULL;

exit_page:

	pineapple_script_end();
	pineapple_html_end();
}
catch (PDOException $e)
{
  print ("<br />$e");
}
?>