<?php 
session_start();
$pTipoUtilizador = $_SESSION['tipoUtilizador'];
if ($pTipoUtilizador=="anonymous" || $pTipoUtilizador=="regular") { // separa por tipo de utilizador
  require('headersubUsers.inc');
  require('menusubUsers.inc');
  echo "<meta http-equiv='refresh' content='0; url=../users.php' />";
  exit;  // os anonimos não têem acesso a esta página
}
else {
  require('headersubAdmins.inc');
  require('menusubAdmins.inc');
}
?>


<hr/>



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


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

<hr/>

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

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

$pFigureId=$argumento;

$resultado = mysql_query($sql,$ligacao);
$ncampos =mysql_num_fields($resultado);
$linha = mysql_fetch_assoc($resultado);

$pThmId          = trim($linha['teoId']);
$pDrwId          = trim($linha['drawerId']);
$pCode           = trim($linha['code']);
$pDateSubmission = trim($linha['dateSubmission']);
$pOldUserId      = trim($linha['userId']);
$pBibref         = trim($linha['bibref']);


echo "<form enctype='multipart/form-data' action='uUpdateFigure.php' method='post'>";
echo "<!-- ficha -->";
echo "<table width='100%' bgcolor='white' cellpadding='4' cellspacing='4'>";
echo "<tr>";
echo "<td width='100%' colspan='6' align='center'>Geometric Figure Info</td>";
echo "</tr>";
// O valor de DemId tem de ser passado para o processador do
// formulário, embora como hidden.
echo "<input type='hidden' name='FigureId' value='$pFigureId'>";
echo "<tr>";
echo "<td align='left' width='12.5%'><span class='ficha'>Theorem Id</span></td>";
// select a Theorem Name from a list of Theorems
$sql_theorem_idname = "SELECT teoId,teoName
                         FROM theorems
                     ORDER BY teoId";
$resultado_theorem_idname = mysql_query($sql_theorem_idname,$ligacao);
echo "<td width='25%' colspan='3'><span class='entrada'><SELECT NAME='ThmIdName'>";
while ($linha = mysql_fetch_assoc($resultado_theorem_idname)){
  $pTeoId=trim($linha['teoId']);
  $pThmName=trim($linha['teoName']);
  if ($pThmId==$pTeoId)
    print "<option selected>$pTeoId -- $pThmName</option>\n";
  else
    print "<option>$pTeoId -- $pThmName</option>\n"; 
 };
echo "</SELECT>";
echo "<td align='left' width='12.5%'><span class='ficha'>Drawer Id</span></td>";
// select a Drawer form a list of Drawers
$sql_drawer_idnameversion = "SELECT drawerId,name,version
                               FROM drawers
                              WHERE NOT(name='No drawer selected')
                           ORDER BY drawerId";
$resultado_drawer_idnameversion = mysql_query($sql_drawer_idnameversion,$ligacao);
echo "<td width='25%' colspan='3'><span class='entrada'><SELECT NAME='DrwIdNameVersion'>";
while ($linha = mysql_fetch_assoc($resultado_drawer_idnameversion)){
  $pDrawerId=trim($linha['drawerId']);
  $pDrawerName=trim($linha['name']);
  $pDrawerVersion=trim($linha['version']);
  if ($pDrwId==$pDrawerId)
    print "<option selected>$pDrawerId -- $pDrawerName -- $pDrawerVersion</option>\n";
  else
    print "<option>$pDrawerId -- $pDrawerName -- $pDrawerVersion</option>\n"; 
 };
//echo "<td width='25%' colspan='3'><span class='entrada'><input type='text' name='ProverId' size='20'></span></td>";
echo "</tr>";
echo "<tr>";
echo "<td width='12.5%' colspan='1'><span class='ficha'>Code</span></td>";
echo "<td width='25%' colspan='2'><TEXTAREA NAME='Code' ROWS='20' COLS='60'>$pCode</TEXTAREA></td>";
echo "<td width='62.5%' colspan='5' align='center'><img src='Forms/view_imageBD.php?argumento=$argumento' alt='figure'></td>";
echo "</tr>";
echo "<tr>";
echo "<td width='12.5%' colspan='1'><span class='ficha'>Date of Submission</span></td>";
echo "<td width='25%' colspan='2'><input type='text' name='DateSubmission' size='25' value=$pDateSubmission></td>";  
echo "<td width='25%' colspan='2'>Bibliographic Reference</td>"; 
// select a bibref form a list of bibrefs
$sql_bibrefId = "SELECT bibrefId
                   FROM bibrefs
               ORDER BY bibrefId";
$resultado_bibrefId = mysql_query($sql_bibrefId,$ligacao);
echo "<td width='12.5%'><span class='entrada'><SELECT NAME='Bibref'>";
while ($linha_bibrefId = mysql_fetch_assoc($resultado_bibrefId)){
  $pBibrefId=trim($linha_bibrefId['bibrefId']);
  if ($pBibrefId==$pBibref) 
    print "<option selected>$pBibrefId</option>\n";
  else
    if ($pBibrefId=='noref')
      print "<option selected>$pBibrefId</option>\n";
    else
      print "<option>$pBibrefId</option>\n"; 
 };
echo "</SELECT>";
echo "</tr>";
echo "<tr>";
echo "<td width='37.5%' colspan='3'><span class='ficha'>Contributor's Name</span></td>";
// select a User form a list of Users
$sqlUserId = "SELECT userId,name,email
                FROM users
            ORDER BY name";
$resultadoUserId = mysql_query($sqlUserId,$ligacao);
echo "<td width='62.5%' colspan='5'><span class='entrada'><SELECT NAME='UserInfo'>";
while ($linhaUserId = mysql_fetch_assoc($resultadoUserId)){
  $pUserId=trim($linhaUserId['userId']);
  $pName=trim($linhaUserId['name']);
  $pEmail=trim($linhaUserId['email']);
  if ($pUserId==$pOldUserId)
    print "<option SELECTED>$pUserId -- $pName -- $pEmail</option>\n"; 
  else
    print "<option>$pUserId -- $pName -- $pEmail</option>\n"; 
 };
echo "</SELECT>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td width='100%' colspan='8' align='center'><input type='submit' value='&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;update info &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'></td>";
echo "</tr>  ";
echo "</table>";
echo "</form>";


?>

<hr/>

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