<?php

require_once "../auth.php";
require_once "../init.php";

$pairs = array(
        'äää' => 'ae',
        'öää' => 'oe',
        'üää' => 'ue',
        'ßää' => 'ss',
        '€ää' => ' Euro'
    );

/* Function to extract headline...
 * First the actual php-file is opened, then it is parsed and searched for $reportName=title.
 * The title will be extracted.
 * This title is used to perform a Database SELECT on qb_report.
 * The column readonly contains the reports column names. unified with the column hidden,
 * the output will be the actual column names, that just need to be translated using __().
 */
$part = substr($_GET['report'], strpos($_GET['report'], "/")+1);
$strDoc = '';
$strDoc = file_get_contents('..' . substr($part, strpos($part, "/")));
$match = substr($strDoc, strpos($strDoc, 'reportName')+14);
$match = substr($match, 0, strpos($match, ';')-1);
//echo $match; //--> $match now contains the report's name

//print_r($_GET);
echo $match;

$doc = file_get_contents('Detail_' . $match . '_vorl.rtf');

//echo 'Detail_' . $match . '_vorl.rtf';

$doc = preg_replace('/\<titel\>/i', $match, $doc);

foreach ( $_GET as $getvar => $getvarval)
{
  //$$getvar = $getvarval;
  //print $getvar . ':' . $getvarval . '------------------' . '@' . $getvar . '@' . '<br>';
  $doc = preg_replace('/\<' . $getvar . '\>/i', $getvarval, $doc);
}

$fd = fopen('Detail.rtf', 'w+');
rewind($fd);
fwrite($fd, $doc);
fclose($fd);

  echo '
<html>
<head>
<title></title>
<meta http-equiv="refresh" content="0; URL=Detail.rtf">
</head>
<body>
</body>
</html>';
?>
  
