<?php
session_start();

/*
 * Figures/inserFigure.php
 * 
 * Copyright 2009, 2017 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');

if ($pTipoUtilizador=="anonymous" || $pTipoUtilizador=="regular") { // separa por tipo de utilizador
  require($entradaFILE.'headerUsers.php');
  require($entradaFILE.'menuUsers.php');
  echo "<meta http-equiv='refresh' content='0; url=".$entradaFILE."users.php' />";
  exit;  // os anonimos não têem acesso a esta página
}
else {
  require($entradaFILE.'headerAdmins.php');
  require($entradaFILE.'menuAdmins.php');
}
?>


<hr/>



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

<?php 

$pTeoId = $_GET['teoId'];


echo "<center>\n";
echo "<h3 class='maketitle'>Geometric theorems - Insert a New Figure (drawer's code)</h3>\n";
echo "</center>\n";

echo "<hr/>\n";



$hoje=date("Y-m-d");

echo "<!-- ficha -->";
echo "<form enctype='multipart/form-data' action='iInsertFigure.php' method='post'>";
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>";
echo "<tr>";
echo "<td align='left' width='16.6%'>
        <span class='ficha'>Theorem Id</span>
      </td>";
// obtêm o nome do teorema
$sql_theorem_idname = "SELECT teoName
                         FROM theorems 
                        WHERE teoId='$pTeoId'";
$resultado_theorem_idname = mysqli_query($ligacao,$sql_theorem_idname);
$linha = mysqli_fetch_assoc($resultado_theorem_idname);
$pThmName=trim($linha['teoName']);
print "<td width='33%' colspan='2'>
        $pTeoId -- $pThmName
       </td>\n";
// Passa o identificador do teorema como escondido
echo "<input type='hidden' name='TeoId' value='$pTeoId'>\n";
echo "<td align='left' width='16.6%'>
       <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 = mysqli_query($ligacao,$sql_drawer_idnameversion);
echo "<td width='33%' colspan='2'><span class='entrada'><SELECT NAME='DrwIdNameVersion'>";
while ($linhaDrw = mysqli_fetch_assoc($resultado_drawer_idnameversion)){
  $pDrawerId=trim($linhaDrw['drawerId']);
  $pDrawerName=trim($linhaDrw['name']);
  $pDrawerVersion=trim($linhaDrw['version']);
  print "<option>$pDrawerId -- $pDrawerName -- $pDrawerVersion</option>\n"; 
 };
echo "</tr>";
echo "<tr>";
echo "<td width='16.6%' colspan='1'><span class='ficha'>Drawer's Code</span></td>";
echo "<td width='83.3%' colspan='5'><TEXTAREA NAME='Code' ROWS='10' COLS='120'></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.3%' colspan='2'><input type='text' name='DateSubmission' size='25' value=$hoje></td>"; 
echo "<td width='33.3%' colspan='2'>Bibliographic Reference</td>"; 
// select a bibref form a list of bibrefs
//
// optei, numa primeira aproximação, por deixar inserir somente uma
// referência bibliográfica, depois pode-se (na actualização) inserir
// mais referências.

$sql_bibrefId = "SELECT bibrefId
                   FROM bibrefs
               ORDER BY bibrefId";
$resultado_bibrefId = mysqli_query($ligacao,$sql_bibrefId);
echo "<td width='12.5%'><span class='entrada'><SELECT NAME='Bibref'>";
while ($linha_bibrefId = mysqli_fetch_assoc($resultado_bibrefId)){
  $pBibrefId=trim($linha_bibrefId['bibrefId']);
  if ($pBibrefId=='noref')
    print "<option selected>$pBibrefId</option>\n";
  else
    print "<option>$pBibrefId</option>\n"; 
 };
echo "</SELECT>";
echo "</tr>"; 
// select a User name form a list of user names 
echo "<tr>";
echo "<td width='25%' colspan='2'><span class='ficha'>Contributor's Name</span></td>";
$sqlUserId = "SELECT userId,name,email
                FROM users
               WHERE type='Contributer'
            ORDER BY name";
$resultadoUserId = mysqli_query($ligacao,$sqlUserId);
echo "<td width='75%' colspan='6'><span class='entrada'><SELECT NAME='UserInfo'>";
while ($linhaUserId = mysqli_fetch_assoc($resultadoUserId)){
  $pUserId=trim($linhaUserId['userId']);
  $pName=trim($linhaUserId['name']);
  $pEmail=trim($linhaUserId['email']);
  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;insert info &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'></td>";
echo "</tr>  ";
echo "</table>";
echo "</form>";

?>

<hr/>

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