<?php 
session_start();
$pTipoUtilizador = $_SESSION['tipoUtilizador'];
if ($pTipoUtilizador=="anonymous" || $pTipoUtilizador=="regular") {// separa por tipo de utilizador
  require('headersubUsers.inc');
  require('menusubUsers.inc');
}
else {
  require('headersubAdmins.inc');
  require('menusubAdmins.inc');
}
?>


<hr/>



<?php
require('loginsub.php');
?>


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

<hr/>

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

// cria uma pesquisa
$sqlFig = "SELECT teoId,drawerId,code,codeXML,dateSubmission,userId,
                  bibref,figureSVG
             FROM figures
            WHERE figureId='$argumento'";

$resultadoFig = mysql_query($sqlFig,$ligacao);
$ncamposFig =mysql_num_fields($resultadoFig);
$linhaFig = mysql_fetch_assoc($resultadoFig);

$pThmId          = trim($linhaFig['teoId']);
$pDrwId          = trim($linhaFig['drawerId']);
$pCode           = trim($linhaFig['code']);
$pCodeXML           = trim($linhaFig['codeXML']);
$pDateSubmission = trim($linhaFig['dateSubmission']);
$pUserId         = trim($linhaFig['userId']);
$pBibref         = trim($linhaFig['bibref']);
$pFigureSVG      = trim($linhaFig['figureSVG']); 

// Obtém o nome do Teorema
$sqlThm = "SELECT teoName
             FROM theorems
            WHERE teoId='$pThmId'";
$resultadoThm = mysql_query($sqlThm,$ligacao);
$linhaThm = mysql_fetch_assoc($resultadoThm);

// Obtém o nome e a versão do desenhador
$sqlDrw = "SELECT name,version
             FROM drawers
            WHERE drawerId='$pDrwId'";
$resultadoDrw = mysql_query($sqlDrw,$ligacao);
$linhaDrw = mysql_fetch_assoc($resultadoDrw);

// Obtém o nome e a correio-e do utilizador
$sqlUsr = "SELECT name,email
             FROM users
            WHERE userId='$pUserId'";
$resultadoUsr = mysql_query($sqlUsr,$ligacao);
$linhaUsr = mysql_fetch_assoc($resultadoUsr);





$pThmName    = trim($linhaThm['teoName']);

$pDrwName    = trim($linhaDrw['name']);
$pDrwVersion = trim($linhaDrw['version']);

$pUserName   = trim($linhaUsr['name']);
$pUserEmail  = trim($linhaUsr['email']);

// Escreve o ficheiro "xml" referente à descrição
$vNameXML = 'figure'.$pUserId.'.xml';

$texfileXML=fopen($vNameXML,"w");
fwrite($texfileXML,$pCodeXML); 
fclose($texfileXML); 

// Escreve o ficheiro "svg" referente à imagem
$vNameSVG = 'figure'.$pUserId.'.svg';

$texfileSVG=fopen($vNameSVG,"w");
fwrite($texfileSVG,$pFigureSVG); 
fclose($texfileSVG); 

echo "<!-- ficha -->";
echo "<table width='100%' bgcolor='white' cellpadding='4' cellspacing='4'>";
echo "<tr>";
echo "<td width='100%' colspan='6' align='center'><span class='titulo'>Geometric Figures Info</span></td>";
echo "</tr>";
echo "<tr>";
echo "<tr>";
echo "<td width='16.6%'><span class='ficha'>Theorem Id</span></td>";
echo "<td width='16.6%'>$pThmId</td>";
echo "<td width='16.6%'><span class='ficha'>Theorem Name</span></td>";
echo "<td width='49.8%' colspan='3'>$pThmName</td>";
echo "</tr>";

echo "<tr>";
echo "<td width='16.6%'><span class='ficha'>Drawer Name</span></td>";
echo "<td width='33.3%' colspan='2'>$pDrwName</td>";
echo "<td width='16.6%'><span class='ficha'>Drawer Version</span></td>";
echo "<td width='33.3%' colspan='2'>$pDrwVersion</td>";
echo "</tr>";
echo "<tr>";
echo "<td width='16.6%' colspan='1' valign='top'><span class='ficha'>Code</span></td>";
echo "<td width='33.4%' colspan='2'><pre>$pCode</pre></td>";
echo "<td width='50%' colspan='3' align='center'><img src='Forms/view_imageBD.php?argumento=$argumento' alt='figure'></td>";
echo "</tr>";
echo "<tr>";
echo "<td width='50%' colspan='3'><span class='ficha'>Description of the construction in natural language</span>\n";
echo "<td width='50%' colspan='3'><a href='$vNameXML'>figure.xml</a></td>\n";
echo "</tr>";
echo "<tr>";
echo "<td width='50%' colspan='3'><span class='ficha'>Figure in SVG Format</span>\n";
echo "<td width='50%' colspan='3'><a href='$vNameSVG'>figure.svg</a></td>\n";
echo "</tr>";
echo "<tr>";
echo "<td width='16.6%' colspan='1'><span class='ficha'>Date of Submission</span></td>";
echo "<td width='33.3%' colspan='2'>$pDateSubmission</td>";  
echo "<td width='33.3%' colspan='2'>Bibliographic Reference</td>"; 
echo "<td width='16.6%' colspan='1'>$pBibref</td>"; 
echo "</tr>";
echo "<tr>";
echo "<td width='16.6%' colspan='1'><span class='ficha'>Contributor's Name</span></td>";
echo "<td width='83.4%' colspan='5'>$pUserName</td>";
//echo "<td width='16.6%' colspan='1'><span class='ficha'>Email</span></td>";
//echo "<td width='33.3%' colspan='2'>$pUserEmail</td>";
echo "</tr>";
echo "</table>";
?>

<hr/>

<?php
  require('footer.inc');
?>
