<?php
/*
author: Timotheus Pokorra (timotheus@pokorra.de)
file: diplomathesis.php
autumn 2002
feel free to use and modify
no guarantuee
*/
?>

<?php
include "../php/xml.php";
include "../php/parsebook.php";
include "content.php";
include "toc.php";
include "list.php";
include "tocpdf.php";
include "contentpdf.php";
include "listpdf.php";

 function trimAll($s)
 {
            $s = trim($s);
            $s = str_replace("\n", ' ', $s);
            while (!strpos($s,"  ") ===false )
               $s = str_replace('  ', ' ', $s);
            $s = str_replace('<br/>',"\n",$s);
            $s = str_replace(" \n", "\n", $s);
            $s = str_replace("\n ", "\n", $s);

            return $s;
 }
    function createPDF(&$book, $filename)
    {
        include '../php/pdf/class.ezpdf.php';

        // make a new pdf object
        $pdf = new Cezpdf('a4','portrait');
        // select the font
        $pdf->selectFont('../php/pdf/fonts/Helvetica');
        $pdf->ezSetMargins(30,30,80,50);
        $pdf->ezText(trimAll($book['title']),25,array('justification'=>'centre'));
        $pdf->ezNewPage();
        $pdf->ezStartPageNumbers(300,500,20,'','',1);
        showTableOfContentsPDF($pdf, $book);
        initKeywords($book);
        showContentPDF($pdf, $book);
        $pdf->ezStopPageNumbers(1,1);
        $pdf->ezNewPage();
        $pdf->ezText('List of Figures', 15);
        showFiguresPDF($pdf, $book);
        $pdf->ezNewPage();
        $pdf->ezText('List of References', 15);
        showReferencesPDF($pdf, $book);

        $pdf->stream();
      /*
        $pdfcode = $pdf->output();
        $fp=fopen($filename,'wb');
        fwrite($fp,$pdfcode);
        fclose($fp);
        echo "<A HREF='".$filename."'>finished</A>";
        */
    }


$book = parseBook('diplomathesis.xml', $printword);

$page = 0;
function pagebreak($printword)
{
	global $page;
	$page++;
    if (!isset($printword))
		echo "<hr>\n";
	else
		echo "*** pagebr ***";
}


if (isset($keywords))
{
	echo showIndex($book, $printword);
	die();
}   
if ($printword)
{
	$keywords = showIndex($book, 2);
	$fp = fopen('C:/Dokumente und Einstellungen/Timotheus/Eigene Dateien/konkordanz.htm', 'w');
    fwrite($fp, $keywords);
	fclose($fp);        
}

if (!isset($pdf))
{
   ?>

    <html>
    <head>
    <title>Diploma thesis</title>
    <meta name="author" content="Timotheus Pokorra">
    <meta name="generator" content="Ulli Meybohms HTML EDITOR">
    </head>
    <body>
<?php 
   if (!isset($printword))
	echo "<a href='diplomathesis.xml'>the xml file from which this file was assembled</a><br>";
//    <a href="diplomathesis.php?pdf=1">see the pdf file dynamically created</a><br><br>

    echo "<div align='center'><b><font size=+3>".MakeHTMLConform($book['title'])."</font></b></div>\n";
	pagebreak($printword);
	
	if ($printword)
	{
		echo "*** Table of Contents ***\n";
	}
	else
	{
		showTableOfContents($book, $printword);
		echo "<h1>";
		pagebreak($printword);
		echo "Figures</h1>";
		showFigures($book, $printword);
	}
    
$page=0;
	
	initKeywords($book);
	if (!isset($printword))
		echo "<table width='80%'><tr><td>";
	else 
		echo "*** start_page_num ***\n";
    showContent($book, $printword);

	if (!isset($printword))
		echo "</td></tr></table>";
    
	echo "<h1>";
	pagebreak($printword);
	echo "Index</h1>";
    if ($printword)
		echo "*** index ***";
	showIndex($book, $printword);

    echo "<h1>";
	pagebreak($printword);
	echo "References</h1>";
    showReferences($book, $printword);
	
	if (!isset($printword))
		echo "</table>";
	echo "</body>";
    echo "</html>";
}
else
    createPDF($book, 'diplomathesis.pdf');

?>