<?php
// Essa rotina dispara uma requisição http para o webservice que cria o banco de dados do zonemanto de grãos
// o único parâmetro, não obrigatório, é o email

$now = new \Datetime;
preg_match("/^agrobr-app02\.*/", gethostname(), $matches);
try {
	require_once('Agro_Curl.php');

	$email = isset($argv[1]) ? $argv[1] : '';
	if (count($matches)>0) {
        $Curl = new Agro_Curl('agronet.agrobrasilseguros.com.br', 'https');
    } else {
        $Curl = new Agro_Curl('amazon.agrobrasilseguros.com.br', 'http');
    }
	$Curl->setUrl('/sistema/rotinas/docriadbzoneamento');
	$Curl->doRequest('POST', array('email' => $email));

	$result = $Curl->getResult();
	$result = $now->format('Y-m-d H:i:s') . ': ' . $result->status . '. ' . $result->message ."\n";
} catch (\Exception $e) {
	$result = $now->format('Y-m-d H:i:s') . ': ' . $e->getMessage() . '. ' . $e->getTraceAsString() ."\n";
}

$filename = dirname(__FILE__).'/../application/upload_files/log/zoneamento/cria_banco_zoneamento_'.$now->format('Ymd').'.log';
$whandle = fopen($filename, 'a+');
fputs($whandle, $result);
fclose($whandle);
