<? if (!$_SERVER['HTTP_X_REQUESTED_WITH']): ?>
	<? if(APPLICATION_ENV != 'production'): ?>
		<style>
			* {
				font-family:tahoma;
			}
			caption {
				background:#E7C685;
				font-weight:bold;
				padding:5px;
			}
			
			thead {
				background:#CCCCCC;
			}
			
			tbody {
				background:#F2F2F2;
			}
			
			td,th,caption {
				cursor:default;
			}
			
			tbody tr:hover {
				background:#FFFFCC;
			}
			
			.off {
				background:#FFFFFF;
			}
		</style>
		
		<table width="100%" align="center" cellpadding="5" cellspacing="0" border="0">
			<tr style="background:#E89320">	
				<td>
					<b>
						<?=$this->exception->getMessage();?><br />
						<?=$this->exception->getFile();?> on line <?=$this->exception->getLine();?> 
					</b>
				</td>
			</tr>
		</table>
		
		<table width="100%" align="center" cellpadding="5" cellspacing="0" border="0">
			<caption>Stack Trace</caption>
			<thead>
				<tr>
					<th>#</th>
					<th align="left">Class</th>
					<th align="left">Function</th>
					<th align="left">Location</th>
				</tr>
			</thead>
			<tbody>
				<? $i = 1; ?>
				<? foreach ($this->exception->getTrace() as $trace): ?>
					<? $class = (($i % 2 == 0) ? 'on' : 'off'); ?>
					<tr class="<?=$class?>">
						<td align="center"><?=$i?></td>
						<td><?=$trace['class']?></td>
						<td><?=$trace['function']?></td>
						<td><?=$trace['file']?>:<?=$trace['line']?></td>
					</tr>
					
					<? $i++; ?>
				<? endforeach; ?>
			</tbody>
		</table>
		
		<table width="100%" align="center" cellpadding="5" cellspacing="0" border="0">
			<caption>Variáveis do REQUEST</caption>
			<thead>
				<tr>
					<th align="left">Variável</th>
					<th align="left">Valor</th>
				</tr>
			</thead>
			<tbody>
				<? $i = 1; ?>
				<? foreach ($this->request->getParams() as $var => $val): ?>
					<? $class = (($i % 2 == 0) ? 'on' : 'off'); ?>
					<tr class="<?=$class?>">
						<td><?=$var?></td>
						<td><?=$val?></td>
					</tr>
					
					<? $i++; ?>
				<? endforeach; ?>
			</tbody>
		</table>
	<? else: ?>
		<style>
			.column h1 {
				border-bottom:1px solid #555;
				font-size:20px;
				color:#555;
			}
			
			.column p {
				margin:15px;
			}
			
			.column p img {
				margin-right:10px;
				float:left;
			}
			
			.one-column {
				margin:0 auto;
				width:98%;
			}
			
			.one-column .column {
				background:#F5F5F5 url(/resources/imagens/bgBloco.jpg) repeat-x;
				border:1px solid #CCCCCC;
				min-height:160px;
				padding:10px;
			}
		</style>
		<div class="one-column">
			<div class="column">
				<h1>Ocorreu um erro no sistema.</h1>
				
				<p><?=$this->exception->getMessage();?></p>
				<div class="hide">
					<?=$this->exception;?>
				</div>
				<p><a href="/agronet">Retornar a página inicial.</a></p>
			</div>
		</div>
		<br class="both" />
	<? endif; ?>
<? else: ?>
	<?
	$error['message'] = $this->exception->getMessage();
	foreach ($this->exception->getTrace() as $trace):
		$error[] = $trace['file'].':'.$trace['line'];
	endforeach;

	if (APPLICATION_ENV == 'production') {
		//&& (str_contains($this->exception->getMessage(), 'SQLSTATE'))) {
		//remove o trace que debuga consulta SQL.
		$error = 'ATENÇÃO: Ocorreu um erro inesperado.';
		Agro_Util::setNotificacao('Error de sistema', $this->exception->getMessage(), 'ti@agrobrasilseguros.com.br');
	}

	print_r($error);
	?>
<? endif; ?>
