<?php
require_once(dirname(__FILE__).'/models/Logfile.php');
require_once(dirname(__FILE__).'/mail.php');

if (count($argv) < 1) {
	die("Aufruf: php statusbericht.php [csv] [controlling@autohaus.de]\r\n");
}
$config = parse_ini_file(dirname(__FILE__) . "/../../GAPS.ini");

$protPath = $config['STARTER'] . "\\logs";
$dirMatch = (count($argv) > 1) ? $argv[1] : "csv";
if (count($argv) > 2) {
	$config['STATUSBERICHT'] = $argv[2];
}

$logs = checkStarterLogs($protPath, $dirMatch);

if (count($logs) > 0) {
	sendUpdateMail($logs);

	$doc = @simplexml_load_file(dirname(__FILE__)."/../../logs/gcstarter.info.log");

	if ($doc && isset($doc->Status)) {
		foreach ($doc->Status->Meldung as $message) {
			echo $message->Text . "\r\n";
		}
	} else {
		echo "  Kontenrahmen auf dem aktuellen Stand.\r\n";
	}

	$starter = checkStarter($config['STARTER']);
	file_put_contents(dirname(__FILE__)."/../../logs/gcstarter.json", json_encode($starter));
}
?>