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

if (count($argv) < 2) {
	die('Aufruf: php fehlerbericht.php Prot-Verzeichnis "Kunde" Gaps.bat.log Startzeit');
}

$protPath = $argv[1];
$customer = $argv[2];
$infoLog = $argv[3];
$startTime = @$argv[4];
$batchFile = @$argv[5];

$attachments = array(
	'info' => $infoLog,
	'error' => $protPath . "\\fehlerbericht.json", 
	'gcstarter' => $protPath . "\\gcstarter.json",
	'gcstruct' => $protPath . "\\gcstruct.json"
);
$endTime = date("H:i");

$logs = checkProtocolDirectory($protPath);
$errorCount = count($logs);

if ($startTime) {
	if (strlen($startTime) == 4) {
		$startTime = "0" . $startTime;
	}
	$logs = checkProtocolDirectory($protPath, true);
	file_put_contents($attachments['error'], json_encode($logs));
	sendStatusMail($customer, $startTime, $endTime, $errorCount, $batchFile, $attachments);
}
?>