<script>
	$('#kmlsolicitacaoprevia').submit(function(e) {
		window.open('', 'formpopup', 'width=2480,height=3508,scrollbars');
		this.target = 'formpopup';
	});

	$("#exportarMapa").click(function(e){
		e.preventDefault();
		$('#kmlsolicitacaoprevia').submit();
	});
</script>

<?
	$Safra = new Produto_Model_Safras();

	if (!$this->error): ?>
	<? if(count($this->paginator)): ?>
	<form id="kmlsolicitacaoprevia" action="/default/scripts/kmlsolicitacaoprevia">
		<table class='grid' cellspacing='2' cellpadding='2' border='0' id='tablePagination'>
			<?

			$link = "/seguro/vistoriaprevia/list/o/";

			if($this->orderby) {
				$arr[$this->orderby] = ($this->orderDirection == 'asc' ? '<img src="/resources/imagens/asc.gif" border="0">' : '<img src="/resources/imagens/desc.gif" border="0">');
			}
			$options = array(
				array(
					'nowrap'    => 'nowrap',
					'descricao' => "<input type='checkbox' id='marcarTodos'>"),
				array(
					'id'        => 'id',
					'nowrap'    => 'nowrap',
					'link'      => $link . 'id/s/' . ($this->orderby == 'id' ? ($this->orderDirection == 'asc' ? 'desc' : 'asc') : 'asc'),
					'descricao' => 'Doc.'  . $arr['id_proposta_endossada'],
					'image'     => '/resources/imagens/'),
				array(
					'id'        => 'ds_nome_proponente',
					'nowrap'    => 'nowrap',
					'link'      => $link . 'ds_nome_proponente/s/' . ($this->orderby == 'ds_nome_proponente' ? ($this->orderDirection == 'asc' ? 'desc' : 'asc') : 'asc'),
					'descricao' => 'Segurado '  . $arr['ds_nome_proponente'],
					'image'     => '/resources/imagens/'),
				array(
					'id'        => 'ds_nome_produto',
					'nowrap'    => 'nowrap',
					'link'      => $link . 'ds_nome_produto/s/' . ($this->orderby == 'ds_nome_produto' ? ($this->orderDirection == 'asc' ? 'desc' : 'asc') : 'asc'),
					'descricao' => 'Produto '  . $arr['ds_nome_produto'],
					'image'     => '/resources/imagens/'),
				array(
					'id'        => 'data_semeadura',
					'nowrap'    => 'nowrap',
					'link'      => $link . 'data_semeadura/s/' . ($this->orderby == 'data_semeadura' ? ($this->orderDirection == 'asc' ? 'desc' : 'asc') : 'asc'),
					'descricao' => 'Plantio '  . $arr['data_semeadura'],
					'image'     => '/resources/imagens/'),
				array(
					'id'        => 'lmga_total',
					'nowrap'    => 'nowrap',
					'link'      => $link . 'lmga_total/s/' . ($this->orderby == 'lmga_total' ? ($this->orderDirection == 'asc' ? 'desc' : 'asc') : 'asc'),
					'descricao' => 'LMGA '  . $arr['lmga_total'],
					'image'     => '/resources/imagens/'),
				array(
					'id'        => 'ds_sigla',
					'nowrap'    => 'nowrap',
					'link'      => $link . 'ds_sigla/s/' . ($this->orderby == 'ds_sigla' ? ($this->orderDirection == 'asc' ? 'desc' : 'asc') : 'asc'),
					'descricao' => 'UF '  . $arr['ds_sigla'],
					'image'     => '/resources/imagens/'),
				array(
					'id'        => 'ds_nome_municipio',
					'nowrap'    => 'nowrap',
					'link'      => $link . 'ds_nome_municipio/s/' . ($this->orderby == 'ds_nome_municipio' ? ($this->orderDirection == 'asc' ? 'desc' : 'asc') : 'asc'),
					'descricao' => 'Município '  . $arr['ds_nome_municipio'],
					'image'     => '/resources/imagens/'),
				array(
					'id'        => 'ds_nome_usuario',
					'nowrap'    => 'nowrap',
					'link'      => $link . 'ds_nome_usuario/s/' . ($this->orderby == 'ds_nome_usuario' ? ($this->orderDirection == 'asc' ? 'desc' : 'asc') : 'asc'),
					'descricao' => 'Digitador '  . $arr['ds_nome_usuario'],
					'image'     => '/resources/imagens/'),
				array(
					'nowrap'    => 'nowrap',
					'descricao' => 'Ações')
			);

			?>

			<?=$this->listHeader($options, $this->order, $this->orderType);?>
			<tbody>
				<?
				$i = 0;
				foreach ($this->paginator as $item):

					if ($i % 2 == 0) {
						$class = '';
					} else {
						$class = "highlight";
					}
					?>

					<tr class="<?=$class?>">
						<td align='center'><input type='checkbox' name='id_proposta[]' class='id_proposta_id' value='<?= $item['id']; ?>'></td>
						<td width="1%"  align="center" nowrap><?=$this->escape(($item['id_proposta_mae'] ? str_pad($item['id_proposta_mae'], 6, 0, STR_PAD_LEFT) : ' '))?></td>
						<td><?=$this->escape(($item['ds_nome_proponente'] ? $item['ds_nome_proponente'] : ' '))?></td>
						<td><?=$this->escape(($item['ds_nome_abreviado'] ? $item['ds_nome_abreviado'] : ' '))?></td>
						<td><?=$this->escape(($item['data_semeadura'] ? Agro_Util::formatDate($item['data_semeadura'], Zend_Date::DATES) : ''))?></td>
						<td><?=$this->escape(($item['lmga_total'] ? Agro_Util::formatDbCurrency($item['lmga_total']) : ' '))?></td>
						<td><?=$this->escape(($item['ds_sigla'] ? $item['ds_sigla'] : '&nbsp;'))?></td>
						<td><?=$this->escape(($item['ds_nome_municipio'] ? $item['ds_nome_municipio'] : '&nbsp;'))?></td>
						<td><?=$this->escape(($item['ds_nome_usuario'] ? $item['ds_nome_usuario']: ' '))?></td>
						<td align='center' width='1%' nowrap='nowrap'>
							<a class="popup" href="/seguro/proposta/view/id/<?=$item['id_proposta_endosso']?>">
							<img src="/resources/imagens/mini/view.png" alt="view.png" title="Visualizar" border="0"></a>
							<input type="hidden" name="id_propostas_endossos[]" id="id_propostas_endossos_id" value="<?=$item['id_proposta_endosso']?>">
						</td>
					</tr>
					<?
					$i++;
				endforeach;
				?>
				<button type="button" id="exportarMapa" title="Clique aqui para exportar  as propostas para o Google Earth">Exportar para Mapa</button>
			</tbody>
		</table>
</form>
	<? endif; ?>
<? else: ?>
	<?= $this->showListError($this->error); ?>
<? endif; ?>
