<?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 utilizadores regulares e o anónimo não têm acesso a esta página
}
else {
  require('headersubAdmins.inc');
  require('menusubAdmins.inc');
}
?>


<hr/>



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


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

<hr/>

<?php

 // Este programa é independente do tipo de provador escolhido


$argumento = $_GET['argumento'];

// cria uma pesquisa
$sql = "SELECT teoId,proverId,code,proof,dateSubmission,userId,
               bibref,status
          FROM demonstrations
         WHERE demId=$argumento";

$pDemId=$argumento;

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

$pThmId          = trim($linha['teoId']);
$pPrvId          = trim($linha['proverId']);
$pCode           = trim($linha['code']);
$pProof          = trim($linha['proof']);
$pDateSubmission = trim($linha['dateSubmission']);
$pOldUserId         = trim($linha['userId']);
$pBibref         = trim($linha['bibref']);
$pStatus         = trim($linha['status']);


echo "<form enctype='multipart/form-data' action='uUpdateProof.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 Proof 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='DemId' value='$pDemId'>";
echo "<tr>";
echo "<td align='left' width='16.6%'><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='33.4%' colspan='2'><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='16.6%'><span class='ficha'>Prover Id</span></td>";
// select a Prover form a list of Provers
$sql_prover_idnameversion = "SELECT proverId,name,version
                               FROM provers
                              WHERE NOT(name='No prover selected')
                           ORDER BY proverId";
$resultado_prover_idnameversion = mysql_query($sql_prover_idnameversion,$ligacao);
echo "<td width='33.4%' colspan='2'><span class='entrada'><SELECT NAME='PrvIdNameVersion'>";
while ($linha = mysql_fetch_assoc($resultado_prover_idnameversion)){
  $pProverId=trim($linha['proverId']);
  $pProverName=trim($linha['name']);
  $pProverVersion=trim($linha['version']);
  if ($pPrvId==$pProverId)
    print "<option selected>$pProverId -- $pProverName -- $pProverVersion</option>\n";
  else
    print "<option>$pProverId -- $pProverName -- $pProverVersion</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='16.6%' colspan='1'><span class='ficha'>Code</span></td>";
echo "<td width='83.4%' colspan='5'><TEXTAREA NAME='Code' ROWS='20' COLS='100'>$pCode</TEXTAREA></td>";
echo "</tr>";
echo "<tr>";
echo "<td width='16.6%' colspan='1'><span class='ficha'>Date of Submission</span></td>";
echo "<td width='33.4%' colspan='2'><input type='text' name='DateSubmission' size='25' value=$pDateSubmission></td>";  
echo "<td width='33.4%' colspan='2'><span class='ficha'>Bibliographic Reference</span></td>"; 
// select a bibref form a list of bibrefs
$sqlBibrefId = "SELECT bibrefId
                   FROM bibrefs
               ORDER BY bibrefId";
$resultadoBibrefId = mysql_query($sqlBibrefId,$ligacao);
echo "<td width='16.6%'><span class='entrada'><SELECT NAME='Bibref'>";
while ($linhaBibrefId = mysql_fetch_assoc($resultadoBibrefId)){
  $pBibrefId=trim($linhaBibrefId['bibrefId']);
  if ($pBibrefId==$pBibref) 
    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='6' 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');
?>