<?php 
session_start();
/*
 * Interaction/evaluateCodeProver.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');
$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');
}

// coloca o valor para a página de ajuda apropriada
$_SESSION['helpsection']='interaction';

require_once($entradaFILE.'dbLogin.php');

?>



<hr/>

<center>
<h3 class="maketitle">Geometric Proofs</h3>
</center>

<hr/>

<?php
// selecciona o Id de utilizador para poder escrever os ficheiros
// "personalizados"
$username = $_SESSION['username'];
// cria uma pesquisa
$sqlUserId = "SELECT userId
                FROM users
               WHERE username ='$username'";

$resultadoUserId = mysqli_query($ligacao,$sqlUserId);
$linhaUserId = mysqli_fetch_assoc($resultadoUserId);

$pUserId     = trim($linhaUserId['userId']);



$argumento = $_GET['argumento'];
$vTeoId    = $_GET['teoId'];
$insercao  = $_GET['insercao']; // primeira vez, ou actualização

// cria uma pesquisa
$sqlPrvCodeTmp = "SELECT code,proverId
                    FROM codeTmp
                   WHERE codeTmpId ='$argumento'";

$resultadoPrvCodeTmp = mysqli_query($ligacao,$sqlPrvCodeTmp);
$linhaPrvCodeTmp = mysqli_fetch_assoc($resultadoPrvCodeTmp);

$pPrvId     = trim($linhaPrvCodeTmp['proverId']);
$pCode      = trim($linhaPrvCodeTmp['code']);
$pCodeTmpId = $argumento;


// Obtém o nome do Provador
$sqlPrv = "SELECT name,version
             FROM provers
            WHERE proverId='$pPrvId'";
$resultadoPrv = mysqli_query($ligacao,$sqlPrv);
$linhaPrv = mysqli_fetch_assoc($resultadoPrv);

$pPrvName    = trim($linhaPrv['name']);
$pPrvVersion = trim($linhaPrv['version']);


// Esta parte vai estar dependente do provador escolhido


if ($pPrvId==2) { // GCLCprover
  echo "<p>Processing, please wait, GCLC, Area Method</p>";
  flush(); 
  require('evaluateCodeGCLCprover.php');
}
elseif ($pPrvId==3) { // GCLCprover+euk2gclc 
  // ---> tenho de ver isto com mais cuidado
  echo "<p>Processing, please wait</p>";
  flush(); 
  require('evaluateCodeGCLCproverEuk.php');
}
elseif ($pPrvId==4) { //Coq+JNarboux
  echo "<p>Processing, please wait --- Coq, Area Method</p>";
  flush(); 
  require_once('evaluateCodeCoqJN.php');
}
elseif ($pPrvId==5) { //GCLCprover Wu
  echo "<p>Processing, please wait --- GCLC, Method of Wu</p>";
  flush(); 
  require_once('evaluateCodeGCLCproverWM.php');
}
elseif ($pPrvId==6) { //GCLCGBM
  echo "<p>Processing, please wait --- GCLC, Groebner Basis Method</p>";
  flush(); 
  require_once('evaluateCodeGCLCproverGBM.php');
}


?>

<hr/>

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