<?php

class Seguro_Form_Segurado extends Agro_Form {
	
	public function init() {
		$OrgaoExpedidor = new Sistema_Model_OrgaosExpedidores();
		$EstadoCivil = new Sistema_Model_EstadosCivis();
		$Estado = new Sistema_Model_Estados();
		
		/**
		 * Dados do Proponente
		 */
		
		$this->addElement('hidden', 'proponente[id]', array('decorators' => $this->buttonDecorator));
		$this->addElement('hidden', 'id_estado_proponente', array('decorators' => $this->buttonDecorator,'required' => true, 'label' => 'Estado'));
		$this->addElement('hidden', 'id_municipio_proponente', array('decorators' => $this->buttonDecorator,'required' => true, 'label' => 'Município'));
		
		$teste = $this->createElement('select');
		$teste->setName('proponente[tp_pessoa]');
		$this->addElement($teste);
		
		$AtividadeEconomica = new Sistema_Model_AtividadeEconomica();
		$this->addElement('select', 'id_atividade_economica', array(
			'MultiOptions' => $AtividadeEconomica->fetchPairs('id', 'ds_nome_atividade_economica'),
			'decorators' => $this->elementDecorator,
			'label' => 'Atividade Econômica'
		));
		
		$this->addElement('text', 'cpf_cnpj', array(
			'validators' => array(array('validator'=> new Agro_Validate_CpfCnpj())),
			'decorators' => $this->elementDecorator,
			'label' => 'CPF/CNPJ',
			'class' => 'cpf_cnpj',
			'maxlength' => 18,
			'size' => 19
		));
		
		$this->addElement('select', 'tp_segurado', array(
			'MultiOptions' => array('', 'P'=>'PROPRIETÁRIO','A'=>'ARRENDATÁRIO', 'O'=>'OUTROS'),
			'decorators' => $this->elementDecorator,
			'label' => 'Tipo Segurado'
		));
		
		$this->addElement('text', 'ds_nome_proponente', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Nome Proponente',
			'maxlength' => 100,
			'class' => 'upper',
			'size' => 70
		));
		
		$this->addElement('text', 'ds_email_proponente', array(
			'decorators' => $this->elementDecorator,
			'label' => 'e-mail',
			'maxlength' => 100,
			'class' => 'lower',
			'size' => 70
		));
		
		$this->addElement('select', 'ds_sexo', array(
			'MultiOptions' => array('', 'F'=>'FEMININO','M'=>'MASCULINO'),
			'decorators' => $this->elementDecorator,
			'label' => 'Sexo'
		));
		
		$this->addElement('text', 'dt_nascimento', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Dt. Nascimento',
			'class' => 'data',
			'maxlength' => 10,
			'size' => 11
		));
		
		$this->addElement('select', 'id_estado_civil', array(
			'MultiOptions' => $EstadoCivil->getCombo(),
			'decorators' => $this->elementDecorator,
			'label' => 'Estado Civil'
		));
		
		$this->addElement('select', 'ds_documento_natureza', array(
			'MultiOptions' => array('RG' => 'RG', 'RNE' => 'RNE'),
			'decorators' => $this->elementDecorator,
			'class' => 'upper',
			'label' => 'Doc. Identificação'
		));
		
		$this->addElement('text', 'ds_documento_numero', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Nº Documento',
			'class' => 'integer',
			'maxlength' => 12,
			'size' => 12
		));
		
		$this->addElement('select', 'id_orgao_expedidor', array(
			'MultiOptions' => $OrgaoExpedidor->getCombo(),
			'decorators' => $this->elementDecorator,
			'label' => 'Órgão Expedidor'
		));
		
		$this->addElement('text', 'dt_documento_exp', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Dt. Expedição',
			'class' => 'data',
			'maxlength' => 10,
			'size' => 11
		));
		
		$this->addElement('text', 'ds_endereco_cep_proponente', array(
			'decorators' => $this->elementDecorator,
			'label' => 'CEP',
			'maxlength' => 10,
			'class' => 'cep',
			'size' => 10
		));
		
		$this->addElement('text', 'ds_endereco_rua_proponente', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Endereço',
			'maxlength' => 100,
			'class' => 'upper',
			'size' => 32
		));
		
		$this->addElement('text', 'ds_endereco_nro_proponente', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Número',
			'class' => 'integer',
			'maxlength' => 8,
			'size' => 8
		));
		
		$this->addElement('text', 'ds_endereco_complem_proponente', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Complemento',
			'maxlength' => 100,
			'class' => 'upper',
			'size' => 8
		));
		
		$this->addElement('text', 'ds_endereco_bairro_proponente', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Bairro',
			'maxlength' => 30,
			'class' => 'upper',
			'size' => 30
		));
		
		$this->addElement('text', 'ds_nome_estado_proponente', array(
			'decorators' => $this->elementDecorator,
			'label' => 'UF',
			'disabled' => true,
			'maxlength' => 2,
			'class' => 'upper',
			'size' => 2
		));
		
		$this->addElement('text', 'ds_nome_municipio_proponente', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Município',
			'disabled' => true,
			'maxlength' => 255,
			'class' => 'upper',
			'size' => 60
		));
		
		$this->addElement('text', 'ds_tel_residencia', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Principal',
			'class' => 'telefone',
			'maxlength' => 20,
			'size' => 14
		));
		
		$this->addElement('text', 'ds_tel_propriedade', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Propriedade',
			'class' => 'telefone',
			'maxlength' => 20,
			'size' => 14
		));
		
		$this->addElement('text', 'ds_tel_celular', array(
			'decorators' => $this->elementDecorator,
			'class' => 'telefone',
			'label' => 'Celular',
			'maxlength' => 20,
			'size' => 14
		));
		
		/**
		 * Dados da propriedade
		 */
		
		$this->addElement('hidden', 'id_propriedade', array('decorators' => $this->buttonDecorator));
		$this->addElement('hidden', 'id_estado_propriedade', array('decorators' => $this->buttonDecorator, 'required' => true, 'label' => 'Estado'));
		$this->addElement('hidden', 'id_municipio_propriedade', array('decorators' => $this->buttonDecorator, 'required' => true, 'label' => 'Município'));
		
		$this->addElement('text', 'ds_nome_propriedade', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Nome Propriedade',
			'maxlength' => 100,
			'class' => 'upper',
			'size' => 109
		));
		
		$this->addElement('text', 'ds_nome_estado_propriedade', array(
			'decorators' => $this->elementDecorator,
			'disabled' => true,
			'maxlength' => 2,
			'label' => 'UF',
			'class' => 'upper',
			'size' => 2
		));
		
		$this->addElement('text', 'ds_nome_municipio_propriedade', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Município',
			'maxlength' => 255,
			'disabled' => true,
			'class' => 'upper',
			'size' => 103
		));
		
		$this->addElement('text', 'ds_endereco_bairro_propriedade', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Bairro',
			'maxlength' => 30,
			'class' => 'upper',
			'size' => 30
		));
		
		$this->addElement('text', 'ds_endereco_cep_propriedade', array(
			'decorators' => $this->elementDecorator,
			'label' => 'CEP',
			'class' => 'cep',
			'maxlength' => 10,
			'size' => 10
		));
		
		$this->addElement('text', 'ds_endereco_propriedade', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Endereço',
			'maxlength' => 100,
			'class' => 'upper',
			'size' => 75
		));
		
		$this->addElement('text', 'ds_endereco_nro_propriedade', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Número',
			'maxlength' => 8,
			'class' => 'integer',
			'size' => 25
		));
		
		$this->addElement('text', 'ds_endereco_complemento_propriedade', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Complemento',
			'maxlength' => 100,
			'class' => 'upper',
			'size' => 25
		));
		
		$this->addElement('text', 'ds_coordenadas', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Coordenadas Geográficas',
			'class' => 'coordenadas',
			'maxlength' => 128,
			'size' => 32
		));
		
		$this->addElement('textarea', 'ds_referencia_localizacao', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Ref. Localização',
			'maxlength' => 255,
			'cols' => 106,
			'class' => 'upper',
			'rows' => 5
		));
		
		$this->addElement('select', 'ds_pessoa_autorizada', array(
			'MultiOptions' => array('N'=>'NÃO','S'=>'SIM'),
			'decorators' => $this->elementDecorator,
			'label' => 'Há representante(s) do proponente a acompanhar a(s) vistoria(s)?'
		));
		
		$this->addElement('text', 'ds_nome_outra_pessoa', array(
			'decorators' => $this->elementDecorator,
			'label' => 'xxNome da outra pessoa',
			'maxlength' => 100,
			'class' => 'upper',
			'size' => 80
		));
		
		$this->addElement('text', 'ds_telefone_outra_pessoa', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Telefone',
			'class' => 'telefone',
			'maxlength' => 20,
			'size' => 14
		));
	}
	
	public function populate(array $values) {
		$Proponentes = new Seguro_Model_PropostasProponentes();
		$Proponente = $Proponentes->getRow($values['id_proposta']);
		
		$values['proponente'] = $Proponente->toArray();
		
		parent::populate($values);
	}
}

