<?php 
session_start();
/*
 * Drawers/seedetailsDrawer.php
 * 
 * Copyright 2009, 2018 Pedro Quaresma <pedro@mat.uc.pt>
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 */

require_once('../servidor.php');

$pUtilizador = $_SESSION['utilizador'];
$pSenha = $_SESSION['senha'];
$pTipoUtilizador = $_SESSION['tipoUtilizador'];
if ($pTipoUtilizador=="anonymous" || $pTipoUtilizador=="regular") {// separa por tipo de utilizador
  require($entradaFILE.'headerUsers.php');
  require($entradaFILE.'menuUsers.php');
} 
else {
  require($entradaFILE.'headerAdmins.php');
  require($entradaFILE.'menuAdmins.php');
}
?>


<hr/>



<?php
require($entradaFILE.'dbLogin.php');
?>


<center>
<h3 class="maketitle">Geometric Drawers Details</h3>
</center>

<hr/>

<?php
$argumento = $_GET['argumento'];

// cria uma pesquisa
$sql = "SELECT drawerId,name,version,description,url,email,dateSubmission
          FROM drawers
         WHERE drawerId='$argumento'";

$resultado = mysqli_query($ligacao,$sql);

$ncampos =mysqli_num_fields($resultado);


$linha = mysqli_fetch_assoc($resultado);

$pDrawerId       = $linha['drawerId'];
$pName           = $linha['name'];
$pVersion        = $linha['version'];
$pDescription    = $linha['description'];
$pURL            = $linha['url'];
$pEmail          = $linha['email'];
$pDateSubmission = $linha['dateSubmission'];



echo "<!-- ficha -->";
echo "<table width='100%' bgcolor='white' cellpadding='4' cellspacing='4'>";
echo "<tr>";
echo "<td width='100%' colspan='8' align='center'><span class='titulo'>Geometric Drawers Info</span></td>";
echo "</tr>";
echo "<tr>";
echo "<tr>";
echo "<td width='25%' colspan='2'><span class='ficha'>Name</span></td>";
echo "<td width='37.5%' colspan='3'>$pName</td>";
echo "<td width='12.5%' colspan='1'><span class='ficha'>Version</span></td>";
echo "<td width='25%' colspan='2'>$pVersion</td>";
echo "</tr>";
echo "<tr>";
echo "<td width='25%' colspan='2'><span class='ficha'>Description</span></td>";
echo "<td width='75%' colspan='6'>$pDescription</td>";
echo "</tr>";
echo "<tr>";
echo "<td width='25%'colspan='2' ><span class='ficha'>URL (Drawer Home Page)</span> </td>";
echo "<td width='75%' colspan='6'><a href='$pURL'>$pURL</a></td>";
echo "</tr>";
echo "<tr>"; 
echo "<td width='25%'colspan='2' ><span class='ficha'>Email</span> </td>";
echo "<td width='75%' colspan='6'><a href='mailto:$pEmail'>$pEmail</a></td>";
echo "</tr>";
echo "<tr>"; 
echo "<td width='25%' colspan='2'><span class='ficha'>Date of Submission</span></td>";
echo "<td width='25%' colspan='2'>$pDateSubmission</td>"; 
echo "<td width='50%' colspan='4'> &nbsp; </td>"; 
echo "</tr>";
// E agora a pesquisa para a informação referente aos autores
$sqlAuthorId = "SELECT authorId
                  FROM authordrawer
                 WHERE drawerId ='$pDrawerId'";

$resultadoAuthorId = mysqli_query($ligacao,$sqlAuthorId);
echo "<tr>";
echo "<td width='100%' colspan='8' align='center'><span class='titulo'>Authors Info</span></td>";
echo "</tr>";
// E agora a informação referente aos autores
while ($linhaAuthorId = mysqli_fetch_assoc($resultadoAuthorId)) { 
  //Vai-se buscar a informação do autor à tabela respectiva
  $pAuthorId = $linhaAuthorId['authorId'];
  $sqlAuthorInfo = "SELECT name,affiliation
                      FROM authors
                     WHERE authorId ='$pAuthorId'";
  $resultadoAuthorInfo = mysqli_query($ligacao,$sqlAuthorInfo);
  $linhaAuthorInfo = mysqli_fetch_assoc($resultadoAuthorInfo);
  $pAuthorName = $linhaAuthorInfo['name'];
  $pAuthorAffiliation = $linhaAuthorInfo['affiliation'];
  echo "<tr>";
  echo "<td width='25%'colspan='2' ><span class='ficha'>Author's Name</span> </td>";
  echo "<td width='75%' colspan='6'>$pAuthorName</td>";
  echo "</tr>";
  echo "<tr>"; 
  echo "<td width='25%'colspan='2' ><span class='ficha'>Author's Affiliation</span> </td>";
  echo "<td width='75%' colspan='6'>$pAuthorAffiliation</td>";
  echo "</tr>";
 }
echo "</table>";
?>

<hr/>

<?php
  require($entradaFILE.'footer.php');
?>
