<?php

class Atendimento_Form_AutorizadoRenovacao extends Agro_Form {
	
	public function init() {		
		$this->addElement('hidden', 'id_proposta', array('decorators' => $this->buttonDecorator));
				
		$Corretor = new Sistema_Model_Corretores();
		$this->addElement('select', 'id_usuario_corretor', array(
			'decorators' => $this->elementDecorator,
			'MultiOptions' => $Corretor->fetchPairs("id_usuario", "ds_nome_corretor"),
			'label' => 'Corretor'
		));
		
		$this->addElement('select', 'id_usuario_preposto', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Preposto'
		));
	}
	
	public function populate(array $values) {
		
		if ($values["id_usuario_preposto"] > 0){
			$Prepostos = new Sistema_Model_Prepostos();
			$Corretores = new Sistema_Model_Corretores();
			$Corretor = $Corretores->fetchRow("id_usuario={$values["id_usuario_corretor"]}");
			
			$this->id_usuario_preposto->setMultiOptions($Prepostos->fetchPairs("id_usuario", "ds_nome_preposto", false, false, 1, "id_corretor=$Corretor->id"));
		}
		
		parent::populate($values);
	}
}