<?php
$verzeichnis_logfile = 'thermolog/';
$verzeichnis_plotfile = 'thermoplot/';
	
if(isset ($_POST['id']) AND isset ($_POST['id'])) { 

	$umlaute = array("/ä/","/ö/","/ü/","/Ä/","/Ö/","/Ü/","/ß/");
	$replace = array("ae","oe","ue","Ae","Oe","Ue","ss");
	
	$current_logfilename = $_POST['id'];	//Alter Name des Logfile's ohne .csv
	$current_logfilename = ''.$verzeichnis_logfile.$current_logfilename.'';

	$new_logfilename = $_POST['value'];
	$new_logfilename = preg_replace($umlaute, $replace, $new_logfilename); 
	$new_logfilename = preg_replace("/[^a-zA-Z0-9_\-\. ]/","",$new_logfilename);
	$new_logfilename = ''.$verzeichnis_logfile.$new_logfilename.'.csv';


	
	$current_plotfilename = $_POST['id'];	//Alter Name der PlotGrafik
	$current_plotfilename = substr($current_plotfilename, 0, -4);
	$current_plotfilename .= ".png";		//Alter Name der PlotGrafik mit .csv
	$current_plotfilename = ''.$verzeichnis_plotfile.$current_plotfilename.'';
	
	$new_plotfilename = $_POST['value'];
	$new_plotfilename = preg_replace($umlaute, $replace, $new_plotfilename); 
	$new_plotfilename = preg_replace("/[^a-zA-Z0-9_\-\. ]/","",$new_plotfilename);
	$new_plotfilename = ''.$verzeichnis_plotfile.$new_plotfilename.'.png';


	
	if (file_exists(utf8_decode($current_logfilename))) {
		rename(utf8_decode($current_logfilename) , utf8_decode($new_logfilename));
		echo $_POST['value'];
		if (file_exists(utf8_decode($current_plotfilename))) {
			rename(utf8_decode($current_plotfilename) , utf8_decode($new_plotfilename));
		}
	}else{
		echo "Fehler...";
	}
}

?>