<?
if (!$this->error): ?>
	<!-- Armazena id_proposta para utilizar em um novo cadastro -->
	<input type="hidden" id="id_proposta" value="<?=$this->id_proposta?>" />
	<input type="hidden" id="id_proposta_mae" value="<?=$this->id_proposta_mae?>" />
	<input type="hidden" id="id_proposta_aux" value="<?=$this->id_proposta?>" />
	<? if(count($this->paginator)): ?>
		<table class='grid' cellspacing='1' cellpadding='0' border='0' id='tablePagination'>
			<thead>
				<tr>
					<th nowrap="nowrap">Código</th>
					<th nowrap="nowrap">Proposta</th>
					<th nowrap="nowrap">Produto</th>
					<th nowrap="nowrap">Criador</th>
					<th nowrap="nowrap">Criação</th>
					<th nowrap="nowrap">Tipo</th>
					<th nowrap="nowrap">Departamento</th>
					<th nowrap="nowrap">Destinatário</th>
					<th nowrap="nowrap">Status</th>
					<th nowrap="nowrap">Prioridade</th>
					<th nowrap="nowrap">Ações</th>
				</tr>
			</thead>
			<tbody>
				<?
				$ModelChamados = new Atendimento_Model_Chamado();
				$i = 0;
				foreach ($this->paginator as $item):

					if ($i % 2 == 0) {
						$class = '';
					} else {
						$class = "highlight";
					}

					$naolido = $ModelChamados->getFilhosNaoLidos($item['id']);

					if($naolido){
						$style = 'style="background-color: lightgreen;"';
						$iconeLido = '';
					}else{
						$style = '';
						$iconeLido = '<a id="'.$item['id'].'" class="icon_recicla" href="#"><img src="/resources/imagens/mini/recicla.png" border="0" alt="recicla.png" title="Marcar como não-lido" style="cursor:pointer" /></a>';
					}

					switch($item['ds_tipo_destinatario']){
						case 'C': $ds_destinatario = 'CORRETOR';    break;
						case 'S': $ds_destinatario = 'SEGURADORA';  break;
						case 'V': $ds_destinatario = 'VISTORIADOR'; break;
						default:  $ds_destinatario = 'CORRETOR';
					}

					?>
					<tr class="<?=$class?>" <?=$style;?>>
						<td nowrap='nowrap' align="center"><?=($item['id'] ? str_pad($item['id'], 6, 0, STR_PAD_LEFT) : '&nbsp;'); ?></td>
						<td nowrap='nowrap' align="center"><?=($item['id_proposta_mae'] ? str_pad($item['id_proposta_mae'], 6, 0, STR_PAD_LEFT) : '&nbsp;'); ?></td>
						<td nowrap='nowrap'><?=($item['ds_nome_produto'] ? $item['ds_nome_produto'] : '&nbsp;'); ?></td>
						<td nowrap='nowrap'><?=($item['ds_nome_usuario'] ? $item['ds_nome_usuario'] : '&nbsp;'); ?></td>
						<td nowrap='nowrap' align="center"><?=($item['dt_criacao'] ? Agro_Util::formatDate($item['dt_criacao'], 'dd/MM/y HH:mm:ss') : '&nbsp;'); ?></td>
						<td nowrap='nowrap'><?=($item['ds_tipo_chamado'] ? $item['ds_tipo_chamado'] : '&nbsp;'); ?></td>
						<td nowrap='nowrap'><?=($item['ds_nome_departamento'] ? $item['ds_nome_departamento'] : '&nbsp;'); ?></td>
						<td nowrap='nowrap'><?=($ds_destinatario ? $ds_destinatario : '&nbsp;'); ?></td>
						<td nowrap='nowrap'><?=($item['ds_status'] ? $item['ds_status'] : '&nbsp;'); echo '&nbsp;'.$iconeLido;?></td>
						<td nowrap='nowrap'><?=($item['prioridade'] ? $item['prioridade'] : '&nbsp;'); ?></td>

						<td align='center' width='1%' nowrap='nowrap'>
							<a class="popup" href="/atendimento/chamado/view/id/<?=$item['id']?>">
								<img src="/resources/imagens/mini/view.png" border="0" alt="view.png" title="Visualizar Chamado" style="cursor:pointer" />
							</a>
						</td>
					</tr>
					<?
					$i++;
				endforeach;
				?>
			</tbody>
		</table>
		<?=$this->paginationControl($this->paginator, 'Sliding'); ?>
	<? else: ?>
	    <?if ($this->proposta): ?>
			<div align="center" style="margin-top: 20px"><b>Não existem chamados para a proposta <?=$this->proposta->id;?> (Segurado: <?=$this->proposta->proponente('ds_nome_proponente');?>)</b></div>
		<? else: ?>
			<div align="center" style="margin-top: 20px"><b>Não existem chamados para esta consulta.</b></div>
		<? endif; ?>
	<? endif; ?>

	<br />
	<? $User = Zend_Auth::getInstance()->getIdentity(); ?>
	<? if ($User->tp_usuario == 'F'): ?>
    	<?if ($this->proposta): ?>
        	<? $arPreposto = $this->proposta->autorizacaoPreposto(); ?>
        	<? if($arPreposto): ?>
            	<? if(!$arPreposto[0]['fl_autorizacao_cancelamento']): ?>
            	    <div  id="message" class="error">ATENÇÃO: Usuário não autorizado a solicitar Cancelamento.</div>
            	<? endif; ?>
            	<br />
            	<? if(!$arPreposto[0]['fl_autorizacao_endosso']): ?>
            	    <div  id="message" class="error">ATENÇÃO: Usuário não autorizado a solicitar Endosso.</div>
            	<? endif; ?>
        	<? endif; ?>
    	<? endif; ?>
     <? endif; ?>

<? else: ?>
	<?= $this->showListError($this->error); ?>
<? endif; ?>
