* @license http://ican.openacalendar.org/license.html 3-clause BSD
 * @copyright (c) 2013-2014, JMB Technology Limited, http://jmbtechnology.co.uk/
 * @author James Baster <*****@*****.**>
 */
if (!$CONFIG->CLIAPI1Enabled) {
    die("CLIAPI1 Not Enabled!\n");
}
######### Get JSON
$f = fopen('php://stdin', 'r');
$stdin = '';
while ($line = fgets($f)) {
    $stdin .= $line;
}
fclose($f);
######### Create
$createEvent = new CreateEvent();
$json = json_decode(trim($stdin));
if ($json) {
    $createEvent->setFromJSON($json);
} else {
    print "ERRORS!\n\n";
    print "Could not parse JSON\n";
    die;
}
######### Go
if ($createEvent->canGo()) {
    $createEvent->go();
    print "Done \n\n";
} else {
    print "ERRORS!\n\n";
    foreach ($createEvent->getErrorMessages() as $msg) {
    function testValidateStartAfterEnd()
    {
        \TimeSource::mock(2014, 06, 01, 00, 00, 00);
        $this->addCountriesToTestDB();
        $json = json_decode('{
	"event":{
		"summary":"Test",
		"description":"test test test",
		"url":"http://example.com",
		"start":{
			"str":"2014-07-01 18:00:00"
		},
		"end":{
			"str":"2014-07-01 17:00:00"
		}
	},
	"site":{
		"slug":"test"
	},
	"user":{
		"username":"******"
	}
}');
        $createEvent = new CreateEvent();
        $createEvent->setFromJSON($json);
        $this->assertEquals(false, $createEvent->canGo());
    }