<?php
/*
 *      CDR Datei herunterladen
 */
require_once ('../includes/isgwtelnet.php');

function flush_cdr() {
	$isgw = new isgwtelnet();	
  	$isgw->isgw_login();
  	$isgw->flush_cdr();
  	sleep(1);
}

if (!file_exists("/tmp/isgw.cdr.1")){
    flush_cdr();
}
if (file_exists("/tmp/isgw.cdr.1")){
        copy("/tmp/isgw.cdr.1","/tmp/isgw.cdr.2");
	$file = file("/tmp/isgw.cdr.2");
	$file2 = implode("", $file);
        
        flush_cdr();

	$file = file("/tmp/isgw.cdr.1");
        $file2 = $file2.implode("", $file);

	header("Content-Type: application/force-download");
	header("Content-Disposition: attachment; filename=isgw.cdr\r\n\r\n");
	header("Content-Length: ".strlen($file2)."\n\n");
        echo $file2;
        unlink("/tmp/isgw.cdr.1");
        unlink("/tmp/isgw.cdr.2");
	exit;
}else{
	echo "<html><script>alert('CDRs are not avaliable');";
	echo"window.location.href='../index.php?m=cdr';</script></html>";
}
?>
