<?php

class Sistema_Form_Avisotelainicial extends Agro_Form {

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

        $this->addElement('hidden', 'arquivo', array('decorators' => $this->elementDecorator));

        $this->addElement('text', 'ds_descricao', array(
            'decorators' => $this->elementDecorator,
            'required' => true,
            'label' => 'Descrição',
            'size' => 70
        ));

        $this->addElement('text', 'vl_largura', array(
            'decorators' => $this->elementDecorator,
            'required' => true,
            'label' => 'Largura',
            'class' => 'integer',
            'title' => 'Preferencialmente a largura real da imagem.',
            'size' => 10
        ));

        $this->addElement('text', 'vl_altura', array(
            'decorators' => $this->elementDecorator,
            'required' => true,
            'label' => 'Altura',
            'class' => 'integer',
            'title' => 'Preferencialmente a altura real da imagem.',
            'size' => 10
        ));

        $this->addElement('select', 'ds_posicao', array(
            'MultiOptions' => array(
                Sistema_Model_AvisoTelaInicial::POSICAO_CENTRALIZADO => 'Centralizado',
                Sistema_Model_AvisoTelaInicial::POSICAO_CANTO_INFERIOR_DIREITO => 'Canto inferior direito'
            ),
            'decorators' => $this->elementDecorator,
            'required' => true,
            'label' => 'Posição'
        ));

        $this->addElement('file', 'ds_arquivo', array(
            'destination' => APPLICATION_PATH.'/upload_files/aviso_tela_inicial/',
            'decorators' => $this->fileDecorator,
            'validators' => array(
                array ('validator' => 'Count', 'options' => 1),
                array ('validator' => 'Size', 'options' => 204800),
                array ('validator' => 'Extension', 'options' => array('png', 'jpeg', 'jpg'))
            ),
            'label' => 'Imagem do aviso',
            'required' => false
        ));

        $this->addElement('text', 'dt_inicio', array(
            'decorators' => $this->elementDecorator,
            'required' => true,
            'label' => 'Data de início',
            'class' => 'data',
            'title' => 'Informe a data que o aviso deve começar a ser exibido',
            'size' => 8
        ));

        $this->addElement('text', 'dt_termino', array(
            'decorators' => $this->elementDecorator,
            'required' => true,
            'label' => 'Data de término',
            'class' => 'data',
            'title' => 'Informe a data que o aviso deve para de ser exibido',
            'size' => 8
        ));

        $this->addElement('textarea', 'ds_texto', array(
            'decorators' => $this->elementDecorator,
            'label' => 'Texto',
            'required' => false,
            'maxlength' => 600,
            'cols' => 100,
            'rows' => 10,
        ));
    }

    public function populate($values) {
        $values['dt_inicio'] = Agro_Util::formatDate($values['dt_inicio'], 'dd/MM/yyyy');
        $values['dt_termino'] = Agro_Util::formatDate($values['dt_termino'], 'dd/MM/yyyy');
        parent::populate($values);
    }
}
