<?php

class Sistema_Form_Assessoria extends Agro_Form {

	public function init() {
		$this->addElement('hidden', 'id', array('decorators' => $this->buttonDecorator));
		$this->addElement('hidden', 'id_usuario', array('decorators' => $this->buttonDecorator));

        $this->addElement('select', 'tp_pessoa', array(
          'MultiOptions' => array('F'=>'FÍSICA','J'=>'JURÍDICA'),
          'decorators' => $this->elementDecorator,
          'label' => 'Tipo Pessoa',
          'required' => true
        ));

		$this->addElement('text', 'cpf_cnpj', array(
			'decorators' => $this->elementDecorator,
			'label' => 'CNPJ/CPF',
			'required' => true,
			'maxlength' => 20,
			'class' => 'cpf_cnpj',
			'size' => 20
		));

		$this->addElement('text', 'ds_nome_assessoria', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Nome Assessoria/Co-corretor',
			'required' => true,
			'maxlength' => 100,
			'class' => 'upper',
			'size' => 50
		));

		$this->addElement('text', 'ds_email', array(
			'decorators' => $this->elementDecorator,
			'label' => 'E-mail',
			'required' => true,
			'maxlength' => 100,
			'size' => 50
		));

		$this->addElement('text', 'ds_nome_usuario', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Usuário',
			'required' => true,
			'class' => 'lower',
			'size' => 30
		));

		$this->addElement('text', 'ds_senha', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Senha',
			'size' => 30
		));

		$this->addElement('text', 'ds_senha2', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Confirmar Senha',
			'size' => 30
		));

		$this->addElement('text', 'ds_telefone', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Telefone Principal',
			'class' => 'telefone',
			'maxlength' => 13,
			'required' => true,
			'size' => 14
		));

        $this->addElement('hidden', 'id_role', array(
          'decorators' => $this->elementDecorator,
          'value' => 34
        ));

		$TipoArquivoCorretor = new Sistema_Model_TipoArquivoCorretor();
		$this->addElement('select', 'id_tipo_arquivo', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Tipo de Arquivo',
			'MultiOptions' => $TipoArquivoCorretor->getCombo(false)
		));

        $this->addElement('select', 'tp_tipo', array(
          'MultiOptions' => array('A' => 'ASSESSORIA', 'C' => 'CO-CORRETOR'),
          'decorators' => $this->elementDecorator,
          'label' => 'Tipo',
          'required' => true
        ));

        $this->addElement('select', 'tp_comissao', array(
          'MultiOptions' => array('F' => '% FIXA', 'P' => '% PROPORCIONAL'),
          'decorators' => $this->elementDecorator,
          'label' => 'Comissão',
          'required' => true
        ));
	}

	public function populate(array $values) {
		$Usuarios = new Sistema_Model_Usuarios();


		if($values['id_usuario']) {
			$Usuario = $Usuarios->find($values['id_usuario'])->current();
			$UsuarioCriacao = $Usuarios->find($values['id_usuario_criacao'])->current();
			$UsuarioAlteracao = $Usuarios->find($values['id_usuario_alteracao'])->current();

			$values['ds_nome_usuario'] = $Usuario->ds_nome_usuario;
		}

        $values['tp_pessoa'] = 'F';

		if (preg_match_all('/[\/]/', $values['cpf_cnpj'], $saida)) {
            $values['tp_pessoa'] = 'J';
        }

		parent::populate($values);
	}
}