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



<hr/>



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


<center>
<h3 class="maketitle">Geometric theorems Technical Report</h3>
</center>

<hr/>

<center>
Wait, report being generated
</center>

<?php

// obtém a informação de todos os teoremas na base de dados
$sqlTheorems = "SELECT teoId,teoName,description,category,bibref,
                       dateSubmission,userId
                  FROM theorems";

$resultadoTheorems = mysql_query($sqlTheorems,$ligacao);

//$ncampos =mysql_num_fields($resultadoTheorems);

ob_start();
print "\documentclass[11pt,a4paper]{report}\n";
print "\usepackage{pstricks}\n";
print "\usepackage{rotating}\n"; 
print "\usepackage{amssymb}\n"; 
print "\usepackage{mathabx}\n"; 
print "\usepackage{graphicx}\n"; 
print "\usepackage{verbatim}\n"; 
print "\usepackage{dsfont}\n";
print "%%% para as demonstrações feitas com o proverGCLC\n";
print "\usepackage{gclc}\n";
print "\usepackage[dvips]{hyperref}\n";
print "\n";
print "\n";
print "%\hypersetup{colorlinks,citecolor=green,filecolor=green,linkcolor=blue,urlcolor=blue}\n";
print "\n";
print "\n";
print "\\newcounter{elimlemmas}\n";
print "\def\eliminationlemma{\\refstepcounter{elimlemmas}%\n";
print "  EL\\theelimlemmas%\n";
print "  \label{lemma:EL\\theelimlemmas}}\n";
print "\def\\ratio#1#2{%\n";
print "  \frac{\overline{#1}}{\overline{#2}}%\n";
print "}\n";
print "\n";
print "\\newcommand{\barra}{\vrule height1.2em width0em depth0.8em}\n";
print "\\newtheorem{defs}{Definition}%[section]\n";
print "\\newtheorem{lema}{Lemma}%[section]\n";
print "\\newtheorem{geothm}{Theorem}\n";
print "\n";
print "\n";
print "\begin{document}\n";
print "\n";
print "\\thispagestyle{empty}\n";
print "\vspace*{-1cm} % medido\n";
print "{\ }\n";
print "\n";
print "\vspace*{2em}\n";
print "\hspace*{-2cm}\hbox{\sf TR 2006/002\hspace*{12cm} ISSN\\ 0874-338X}\n";
print "\n";
print "\vspace*{2em}\n";
print "\begin{center}\Large\n";
print "  GeoThms - Geometry Theorems Database\\ \n";
print "  \large (\\today)\n";
print "\end{center}\n";
print "\n";
print "\vspace*{1em}\n";
print "\begin{center}\n";
print "  Pedro Quaresma \\\\ \n";
print "  Department of Mathematics\\\\ \n";
print "  University of Coimbra, Portugal\\\\ \n";
print "  ~\\\\ \n";
print "  Predrag Janicic\\\\ \n";
print "  Faculty of Mathematics\\ \n";
print "  University of Belgrade, Serbia ~ Montenegro\n";
print "\end{center}\n";
print "\n";
print "\n";
print "\vfill\n";
print "\begin{center}\n";
print "  \large Centre for Informatics and Systems of the University of Coimbra\n";
print "\end{center}\n";
print "\pagebreak\n";
print "\n";
print "\setcounter{page}{1}\n";
print "\\title{GeoThms - Geometry Theorems Database}\n";
print "\n";
print "\author{Pedro Quaresma\\thanks{This work was partially supported by\n";
print "CISUC/FCT.}\\\\ Department of Mathematics\\\\ University of\n";
print "Coimbra\\\\ 3001-454 COIMBRA, PORTUGAL\\\\ \n";
print "e-mail: pedro@mat.uc.pt\quad phone: +351-239 791 170\n";
print "\and\n";
print "Predrag Janicic\\thanks{This work was partially supported by the\n";
print "CISUC/FCT, Centro International de Matemática (CIM),\n";
print "under the programme ``Research in Pairs'', while on visit to Coimbra\n";
print "University under the Coimbra Group Hospitality Scheme}\\\\ \n";
print "Faculty of Mathematics\\\\ \n";
print "University of Belgrade\\\\ \n";
print "Studentski trg 16\\\\ \n";
print "11000 Belgrade, SERBIA ~ MONTENEGRO\\\\ \n";
print "e-mail: janicic@matf.bg.ac.yu }\n";
print "\n";
print "\maketitle\n";
print "\n";
print "\n";
print "\input{abstract}\n";
print "\n";
print "\\tableofcontents\n";
print "\n";
print "\input{intro}\n";
print "\n";
print "\input{database}\n";
print "\n";
print "\input{lemmas}\n";
print "\n";

while ($linhaTheorems = mysql_fetch_assoc($resultadoTheorems)) {
  //$linhaTheorems = mysql_fetch_assoc($resultadoTheorems);
  
  $pTeoId          = $linhaTheorems['teoId'];
  $pTeoName        = $linhaTheorems['teoName'];
  $pDescription    = $linhaTheorems['description'];
  $pCategory       = $linhaTheorems['category'];
  $pThmBibRef      = $linhaTheorems['bibref'];
  $pDateSubmission = $linhaTheorems['dateSubmission'];
  $pUserId         = $linhaTheorems['userId'];


  // Vai obter a informação da demonstração

  // cria uma pesquisa
  $sqlDemonstration = "SELECT demId,code,bibref,proverId,proof,
                              dateSubmission,status
                         FROM demonstrations
                        WHERE teoId='$pTeoId'";
  
  $resultadoDemonstration = mysql_query($sqlDemonstration,$ligacao);

  $nlinhasDemonstration = mysql_num_rows($resultadoDemonstration);

  $linhaDemonstration = mysql_fetch_assoc($resultadoDemonstration);

  $pCode      = $linhaDemonstration['code'];
  $pProof     = $linhaDemonstration['proof'];
  $pDemBibRef = $linhaDemonstration['bibref'];

  // $pBibItem         = $linhaBibItem['bibItem'];
  print "\section{ $pTeoId --- $pTeoName }\n\n";
  // Primeiro o enunciado
  
  if ($pThmBibRef!='noref') 
    print "\paragraph{The Theorem Statement~\cite{".$pThmBibRef."}}\n\n";
  else
    print "\paragraph{The Theorem Statment}\n\n";
  print $pDescription."\n";
  // Depois a imagem 
  switch ($pDrawerId) {
  case 1: // No drawer selected
    print "\paragraph{The Image}\n\n";
    print "\begin{center}\n";
    print "No Image\n";
    print "\end{center}\n\n\n";
    break;
  case 2: // Eukleides 1.0.2
    $texfile=fopen("image$pTeoId.euk","w");
    fwrite($texfile,$pImage);
    fclose($texfile);
    system("eukleides image$pTeoId.euk > image$pTeoId.tex");
    print "\paragraph{The Image -- Eukleides 1.0.2}\n\n";
    print "\begin{center}\n";
    print "{\footnotesize\n";
    print "\input{image$pTeoId.tex}\n";
    print "}\n";
    print "\end{center}\n\n\n";
    break;
 case 3: // GCLC 4.0
   $texfile=fopen("image$pTeoId.gcl","w");
   fwrite($texfile,$pImage);
   fclose($texfile);
   system("gclc image$pTeoId.gcl image$pTeoId.pic > /dev/null");
   // Formata a imagem através do LaTeX
   print "\paragraph{The Image -- GCLC 4.0}\n\n";
   print "{\footnotesize\n";
   print "\begin{center}\n";
   print "  \input{image$pTeoId.pic}\n";
   print "\end{center} \n";
   print "}\n";                                    
   break;
 default: //ERRO
   print "<p>What's up Doc</p>";
  }

  // Agora a demonstração - Para já só considera o caso de uma
  // demonstração por teorema - o "if" tem de passar a "while"
  //
  // Também só considera um Demonstrador o proverGCLC
  // O texto das demonstrações só contém os "proofsteps";
  if ($nlinhasDemonstration>0) {
    if (strlen($pCode)>=10) { // considera-se que são só espaços
      print "\paragraph{Prover's Code}\n\n";
      print "\small\begin{verbatim}\n";
      print $pCode."\n";
      print "\end{verbatim}\n\n\n";
    }
    else {
      print "\paragraph{Prover's Code}\n\n";
      print "\begin{center}\n";
      print "No Prover's code in the Database\n";
      print "\end{center}\n\n\n";
    }
    if (strlen($pProof)>=10) { // com menos de 10 caracteres, são só espaços
      if ($pDemBibRef!='noref') {
	print "\paragraph{Proof~\cite{".$pDemBibRef."}}\n\n";
	print "\setcounter{proofstepnum}{0}\n";
	print "\begin{dgroup*}\n";
	print $pProof."\n";
	print "\end{dgroup*}\n";
	print "\n\n";
	print "\hfill {q.e.d.}\n";
      }
      else {
	print "\paragraph{Proof}\n\n";
	print "\setcounter{proofstepnum}{0}\n";
	print "\begin{dgroup*}\n";
	print $pProof."\n";
	print "\end{dgroup*}\n";
	print "\n\n";
	print "\hfill {q.e.d.}\n";
      }
    }
    else {
      print "\paragraph{Proof}\n\n";
      print "\begin{center}\n";
      print "No Proof in the Database\n";
      print "\end{center}\n\n\n";
    }
  }
  else {
    print "\paragraph{Prover's Code \& Proof}\n\n";
    print "\begin{center}\n";
    print "No Proof in the database \n";
    print "\end{center}\n\n\n";   
  }
  print "\n\n";
  print "\vfill\n";
  print "\pagebreak\n";
  print "\n";
 }
print "\n\n";
print "\bibliographystyle{alpha}\n";
print "\bibliography{techRepCISUC0206.bib}\n";
print "\end{document}\n";


// Escreve o ficheiro LaTeX
$texfile=fopen("techRepCISUC0206.tex","w");
fwrite($texfile,ob_get_contents()); 
fclose($texfile); 
ob_end_clean(); 

// Vou agora produzir o ficheiro bib
ob_start();
// definições gerais
print "@PREAMBLE{ {\\newcommand{\\noopsort}[1]{} \\newcommand{\singleletter}[1]{#1} } }\n";
print "@STRING{ ADW = {Addison-Wesley} }\n";
print "@STRING{ AMS = {American Mathematical Society} }\n\n";
// e agora as entradas presentes na Base de Dados

// cria uma pesquisa
$sqlBibrefs = "SELECT bibtexEntry
                 FROM bibrefs
                WHERE bibrefId!='noref'";

$resultadoBibrefs = mysql_query($sqlBibrefs,$ligacao);

while ($linhaBibrefs = mysql_fetch_assoc($resultadoBibrefs)) {
  
  $pBiBTeXEntry = $linhaBibrefs['bibtexEntry'];

  print $pBiBTeXEntry."\n\n";
 }

// Escreve o ficheiro BiBTeX

$texfile=fopen("techRepCISUC0206.bib","w");
fwrite($texfile,ob_get_contents()); 
fclose($texfile); 
ob_end_clean(); 


ob_start(); 
system("latex techRepCISUC0206.tex"); 
system("bibtex techRepCISUC0206.aux"); 
system("latex techRepCISUC0206.tex"); 
system("latex techRepCISUC0206.tex"); 
system("dvips techRepCISUC0206.dvi -o techRepCISUC0206.ps"); 
system("ps2pdf techRepCISUC0206.ps"); 
ob_end_clean();


?>

<center>
Wait, report being transfered
</center>

<meta http-equiv="refresh" content="1; url=http://hilbert.mat.uc.pt/~geothms/TechReport/techRepCISUC0206.pdf" />

<hr/>

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