<?php

Goweb::loadClass('Goweb_Form');

/**
 * Goweb Sitemanager 4 Framework
 * @version    4.0.0
 * @category   Backoffice
 * @package    Form
 * @subpackage Form
 * @author     I&D <dev@goweb.pt>
 * @copyright  2006 (c) Goweb (http://www.goweb.pt)
*/
class Form_Combo extends Goweb_Form {
    
    /**
     * Objecto Goweb_Db_Model
     *
     * @var Goweb_Db_Model
    */
    protected $_model;
    
    /**
     * Atribui um valor a propriedade $_model
     *
     * @param Goweb_Db_Model
    */
    public function setModel(Goweb_Db_Model $model) {
        $this->_model = $model;
    }
    
    /**
     * Metodo obrigatorio as classes herdeiras do Goweb_Form
    */
    public function setup() {
        // label
        $this->label = $this->Text();
        $this->label->size = 40;
        $this->label->maxlength = $this->_model->getColParam('label', 'maxlength');
        $this->label->label = $this->_model->getColParam('label', 'label');
        $this->label->error_class = 'error';
        $this->label->focus_class = 'focus';
        $this->label->help = $this->_model->getColParam('label', 'help');
        $this->label->validators->Required(translateAdmin('O campo <b>{{campo}}</b> &eacute; de preenchimento obrigat&oacute;rio.', $this->label->label));
        
        // ordem
        $this->ordem = $this->Text();
        $this->ordem->size = 20;
        $this->ordem->maxlength = $this->_model->getColParam('ordem', 'maxlength');
        $this->ordem->label = $this->_model->getColParam('ordem', 'label');
        $this->ordem->error_class = 'error';
        $this->ordem->focus_class = 'focus';
        $this->ordem->help = $this->_model->getColParam('ordem', 'help');
        $this->ordem->validators->Integer(translateAdmin('O campo <b>{{campo}}</b> n&atilde;o &eacute; um n&uacute;mero inteiro.', $this->ordem->label));
        
        // seleccionar o tipo de bd
        $this->db_type = $this->Select(array('label' => translateAdmin('Seleccione o Tipo da BD')));
        $this->db_type->addOption('mysql', 'MySql');
        // $this->db_type->addOption('oracle', 'Oracle');
        // $this->db_type->addOption('mssql', 'SQL Server');
        $this->db_type->error_class = 'error';
        $this->db_type->focus_class = 'focus';
        $this->db_type->validators->Required(translateAdmin('O campo <b>{{campo}}</b> &eacute; de preenchimento obrigat&oacute;rio.', $this->db_type->label));
        
        // informar endereco da base de dados
        $this->db_host = $this->Text(array('label' => translateAdmin('Host')));
        $this->db_host->size = 20;
        $this->db_host->error_class = 'error';
        $this->db_host->focus_class = 'focus';
        $this->db_host->validators->Required(translateAdmin('O campo <b>{{campo}}</b> &eacute; de preenchimento obrigat&oacute;rio.', $this->db_host->label));
        
        // informar username
        $this->db_user = $this->Text(array('label' => translateAdmin('Username')));
        $this->db_user->size = 20;
        $this->db_user->error_class = 'error';
        $this->db_user->focus_class = 'focus';
        $this->db_user->validators->Required(translateAdmin('O campo <b>{{campo}}</b> &eacute; de preenchimento obrigat&oacute;rio.', $this->db_user->label));
        
        // informar password
        $this->db_pass = $this->Text(array('label' => translateAdmin('Password')));
        $this->db_pass->size = 20;
        $this->db_pass->error_class = 'error';
        $this->db_pass->focus_class = 'focus';
        $this->db_pass->validators->Required(translateAdmin('O campo <b>{{campo}}</b> &eacute; de preenchimento obrigat&oacute;rio.', $this->db_pass->label));
        
        // -- possibilitar o teste da coneccao
        
        // informar a base de dados
        $this->db_name = $this->Text(array('label' => translateAdmin('Nome da BD')));
        $this->db_name->size = 20;
        $this->db_name->error_class = 'error';
        $this->db_name->focus_class = 'focus';
        $this->db_name->validators->Required(translateAdmin('O campo <b>{{campo}}</b> &eacute; de preenchimento obrigat&oacute;rio.', $this->db_name->label));
        
        // informar a tabela da base de dados
        $this->db_table = $this->Text(array('label' => translateAdmin('Tabela')));
        $this->db_table->size = 20;
        $this->db_table->error_class = 'error';
        $this->db_table->focus_class = 'focus';
        $this->db_table->validators->Required(translateAdmin('O campo <b>{{campo}}</b> &eacute; de preenchimento obrigat&oacute;rio.', $this->db_table->label));
        
        // seleccionar o campo para o valor da combo-box
        $this->db_table_value = $this->Text(array('label' => translateAdmin('Campo para o valor')));
        $this->db_table_value->size = 20;
        $this->db_table_value->error_class = 'error';
        $this->db_table_value->focus_class = 'focus';
        $this->db_table_value->validators->Required(translateAdmin('O campo <b>{{campo}}</b> &eacute; de preenchimento obrigat&oacute;rio.', $this->db_table_value->label));
        
        // seleccionar o campo para a descricao da combo-box
        $this->db_table_desc = $this->Text(array('label' => translateAdmin('Campo para a descri&ccedil;&atilde;o')));
        $this->db_table_desc->size = 20;
        $this->db_table_desc->error_class = 'error';
        $this->db_table_desc->focus_class = 'focus';
        $this->db_table_desc->validators->Required(translateAdmin('O campo <b>{{campo}}</b> &eacute; de preenchimento obrigat&oacute;rio.', $this->db_table_desc->label));
        
        
        // campo aberto para outras clausulas do sql
        $this->clausulas_extras = $this->Textarea(array('label' => translateAdmin('Cl&aacute;usulas Extras')));
        $this->clausulas_extras->cols = 41;
        $this->clausulas_extras->rows = 4;
        $this->clausulas_extras->error_class = 'error';
        $this->clausulas_extras->focus_class = 'focus';
        
        // -- possibilitar a pre-visualizacao da combo preenchida
        
        
        
        // required
        $this->required = $this->Checkbox();
        $this->required->label = $this->_model->getColParam('required', 'label');
        $this->required->error_class = 'error';
        $this->required->focus_class = 'focus';
        if ($this->_model->getColParam('required', 'default') && $this->_model->getColParam('required', 'default') == '1') {
            $this->required->value = '1';
        }
        $this->required->help = $this->_model->getColParam('required', 'help');
        
        // submit
        $this->submit = $this->Submit();
        $this->submit->value = translateAdmin('Gravar');
        $this->submit->class = 'form_submit';
        $this->submit_and_new = $this->Submit();
        $this->submit_and_new->value = translateAdmin('Gravar e adicionar novo');
        $this->submit_and_new->class = 'form_submit_and_new';
        $this->submit_and_continue = $this->Submit();
        $this->submit_and_continue->value = translateAdmin('Gravar e continuar a editar');
        $this->submit_and_continue->class = 'form_submit_and_continue';
    }
}