<?php

session_start();
$_SESSION['ansicht']="Historie";

$hb = $_SESSION['hb'];
$hp = $_SESSION['hp'];
$filenamehtm = dirname($_SERVER["PATH_TRANSLATED"]) . "/historie.htm";

if (!$filehtm = fopen($filenamehtm, "r+")) {
print "Kann im Moment die HISTORIE-HTM nicht öffnen";
exit;
}

$contenttxt="";



$dir=opendir('../php/texte/historie'); 
while ($file = readdir ($dir)) { 
    if ($file != "." && $file != "..") {		
	   $pos = strpos ($file, $hp);
	   if ($pos != 0) {
         $zeilennummer=$zeilennummer+1;
         $filename = $file;
		 $filedate = date("YmdHms",filemtime("../php/texte/historie/" . $filename));
         $abs[$filedate] = $filename;
	   } 
    }          
}
closedir($dir);

//print_r($abs);

if ($abs=="") {
$contenthtm=fread($filehtm,filesize($filenamehtm));
$content=str_replace("startstop",$contenttxt,$contenthtm);
print $content;
fclose($filehtm);
exit;
}


rsort($abs,SORT_NUMERIC);
reset ($abs);

//while (list ($key, $val) = each ($abs)) {
//    echo "abs[".$key."] = ".$val."\n<BR>";
//}

//exit;

$zeilennummer=0;
for ($i = 0; $i <= count($abs)-1 ; $i++) {
//print $abs[$i] . '<BR>';    
         $zeilennummer= $zeilennummer+1;
         $filename = "../php/texte/historie/" . $abs[$i];
         $filetxt = fopen($filename, "r");
		 
		 $dateien[] = filemtime($filename);

         $headtxt = date("d F Y", filemtime($filename));
	     if ($headtxt != $altheadtxt) {
  		 $contenttxt = $contenttxt . '<BR>' . $headtxt . '<BR><BR>';
		 }
		 $altheadtxt = $headtxt;
		 
         $contenttxt= $contenttxt . fread($filetxt,filesize($filename));
         $contenttxt=str_replace("checkboxname","checkbox" . $zeilennummer,$contenttxt);
         $contenttxt=str_replace("checkboxwert",$abs[$i],$contenttxt);

         $filename = "../php/texte/" . $abs[$i];
		 if (file_exists($filename)) {
         $contenttxt=str_replace("Status","Offen",$contenttxt);
         } else {
         $contenttxt=str_replace("Status","Bearbeitung",$contenttxt);
         }

         fclose($filetxt); 
}

$contenthtm=fread($filehtm,filesize($filenamehtm));
$content=str_replace("startstop",$contenttxt,$contenthtm);

print $content;
fclose($filehtm);


?>