<?php
class BootstrapController
{
    private $path;
    private $path2;

    function __construct($path, $path2 = "")
    {
        $this->path = $path;
        $this->path2 = $path2;
    }


    function bootstrap ($get, $post = array())
    {
        if (!isset($get['valid']))
        {
            return "Funktioniert!";
        }

        if (isset($get['gchr']))
        {
            if (!isset($post['dsn']) || !isset($post['query']))
            {
                return "Fehler: fehlende Parameter";
            }
            require_once(dirname(__FILE__).'/RemoteQueryController.php');

            $rqController = new RemoteQueryController();
            return $rqController->connectFetchAndConvertToCsv($post['dsn'], $post['query']);
        }
        else if (isset($get['log']))
        {
            $logfile = "{$this->path}\\logs\\{$get['log']}";
            if (!file_exists($logfile)) return "Fehler: Datei '{$get['log']}' unbekannt";
            readfile($logfile);
			return "";
        }
        else if (!isset($get['batch']))
        {
            $cmd = "{$this->path}\\GCStarter.bat";
        }
        else
        {
            $cmd = "{$this->path}\\{$get['batch']}";
            if (!file_exists($cmd))
            {
                $cmd = "{$this->path2}\\{$get['batch']}";
            }
            if (!file_exists($cmd)) return "Fehler: Datei '{$get['batch']}' unbekannt";
        }

        $log = substr(sha1($cmd . strtotime("now")), 0, 10) . ".log";
        $logfile = "{$this->path}\\logs\\{$log}";
        `echo Starte Prozess... > {$logfile}`;

        $WshShell = new COM("WScript.Shell");
        $cmd = "cmd /C \" call {$cmd} 1> {$logfile} 2>&1 \" ";
        $WshShell = $WshShell->Run($cmd, 0, false);
        return $log;
    }
}
?>