Advertisement
lordjackson

InscricaoFom

Dec 16th, 2014
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.41 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * InscricaoForm Registration
  5.  * @author  Jackson Meires
  6.  */
  7. class InscricaoFormView extends TPage {
  8.  
  9.     protected $form; // form
  10.     protected $notebook;
  11.  
  12.     /**
  13.      * Class constructor
  14.      * Creates the page and the registration form
  15.      */
  16.     function __construct() {
  17.         parent::__construct();
  18.  
  19.         // creates the notebook
  20.         $this->notebook = new TNotebook;
  21.         $this->notebook->setSize(700, 580);
  22.  
  23.         $scroll = new TScroll;
  24.         $scroll->setSize(700, 580);
  25.         $scroll->setTransparency(TRUE);
  26.  
  27.         // creates the table container
  28.         $table = new TTable;
  29.  
  30.         // creates the form
  31.         $this->form = new TForm('form_inscricao');
  32.         $this->notebook->appendPage(_t('Data'), $scroll);
  33.         $scroll->add($table);
  34.  
  35.         // add the notebook inside the form
  36.         $this->form->add($this->notebook);
  37.  
  38.         // create the form fields
  39.         $id_inscricao = new TEntry('id');
  40.         $id_inscricao->setEditable(FALSE);
  41.         $unidade = new TCombo('unidade');
  42. //        $unidade->setEditable(false);
  43.         $turno = new TCombo('turno');
  44.         $tipo = new TCombo('tipo');
  45.         $curso = new TCombo('curso');
  46.         $response_c = new TEntry('response_c');
  47.         $entrada = new TEntry('entrada');
  48.         $nome = new TEntry('nome');
  49.         $medio = new TEntry('medio');
  50.         $filiacao = new TEntry('filiacao');
  51.         $naturalidade = new TEntry('naturalidade');
  52.         $cpf = new TEntry('cpf');
  53.         $rg = new TEntry('rg');
  54.         $endereco = new TEntry('endereco');
  55.         $bairro = new TEntry('bairro');
  56.         $cidade = new TEntry('cidade');
  57.         $estado = new TEntry('estado');
  58.         $cep = new TEntry('cep');
  59.         $fone = new TEntry('fone');
  60.         $email = new TEntry('email');
  61.  
  62.         // define the sizes
  63.         $id_inscricao->setSize(100);
  64.         $unidade->setSize(200);
  65.         $turno->setSize(200);
  66.         $entrada->setSize(200);
  67.         $nome->setSize(200);
  68.         $medio->setSize(200);
  69.         $filiacao->setSize(200);
  70.         $naturalidade->setSize(200);
  71.         $cpf->setSize(200);
  72.         $rg->setSize(200);
  73.         $endereco->setSize(200);
  74.         $bairro->setSize(200);
  75.         $cidade->setSize(200);
  76.         $estado->setSize(200);
  77.         $cep->setSize(200);
  78.         $fone->setSize(200);
  79.         $email->setSize(200);
  80.  
  81.         $itemUnidade = array();
  82.         // adiciona as opcoes na combo
  83.         $itemUnidade['NATAL'] = 'NATAL';
  84.         $unidade->addItems($itemUnidade);
  85.         $unidade->setValue('NATAL');
  86.         // adiciona as opcoes na combo
  87.         $itemTurno = array();
  88.         $itemTurno['Matutino'] = 'Matutino';
  89.         $itemTurno['Vespertino'] = 'Vespertino';
  90.         $itemTurno['Noturno'] = 'Noturno';
  91.         $itemTurno['Sábado'] = 'Sábado';
  92.         $turno->addItems($itemTurno);
  93.  
  94.         $combo_items = array();
  95.         $combo_items['Cursos Tecnicos'] = 'Cursos Técnicos';
  96.         $combo_items['Profissionalizante'] = 'Profissionalizante';
  97.         $combo_items['Qualificacao'] = 'Qualificação';
  98.  
  99.         $response_c->setEditable(FALSE);
  100.         $tipo->addItems($combo_items);
  101.         $curso->addItems($combo_items);
  102.  
  103.         // add a row for the field id_inscricao
  104.         $row = $table->addRow();
  105.         $row->addCell(new TLabel('Codigo:'));
  106.         $row->addCell($id_inscricao);
  107.  
  108.         // add a row for the field unidade
  109.         $row = $table->addRow();
  110.         $row->addCell(new TLabel('Unidade:'));
  111.         $row->addCell($unidade);
  112.  
  113.         // add a row for the field curso
  114.         $row = $table->addRow();
  115.         $row->addCell(new TLabel('Tipo:'));
  116.         $row->addCell($tipo);
  117.  
  118.         $row = $table->addRow();
  119.         $row->addCell(new TLabel('Curso:'));
  120.         $row->addCell($curso);
  121.  
  122.         $row = $table->addRow();
  123.         $row->addCell(new TLabel('Ver:'));
  124.         $row->addCell($response_c);
  125.  
  126.         // add a row for the field turno
  127.         $row = $table->addRow();
  128.         $row->addCell(new TLabel('turno:'));
  129.         $row->addCell($turno);
  130.  
  131.         // add a row for the field entrada
  132.         $row = $table->addRow();
  133.         $row->addCell(new TLabel('entrada:'));
  134.         $row->addCell($entrada);
  135.  
  136.         // add a row for the field nome
  137.         $row = $table->addRow();
  138.         $row->addCell(new TLabel('nome:'));
  139.         $row->addCell($nome);
  140.  
  141.         // add a row for the field medio
  142.         $row = $table->addRow();
  143.         $row->addCell(new TLabel('medio:'));
  144.         $row->addCell($medio);
  145.  
  146.         // add a row for the field filiacao
  147.         $row = $table->addRow();
  148.         $row->addCell(new TLabel('filiacao:'));
  149.         $row->addCell($filiacao);
  150.  
  151.         // add a row for the field naturalidade
  152.         $row = $table->addRow();
  153.         $row->addCell(new TLabel('naturalidade:'));
  154.         $row->addCell($naturalidade);
  155.  
  156.         // add a row for the field cpf
  157.         $row = $table->addRow();
  158.         $row->addCell(new TLabel('cpf:'));
  159.         $row->addCell($cpf);
  160.  
  161.         // add a row for the field rg
  162.         $row = $table->addRow();
  163.         $row->addCell(new TLabel('rg:'));
  164.         $row->addCell($rg);
  165.  
  166.         // add a row for the field endereco
  167.         $row = $table->addRow();
  168.         $row->addCell(new TLabel('endereco:'));
  169.         $row->addCell($endereco);
  170.  
  171.         // add a row for the field bairro
  172.         $row = $table->addRow();
  173.         $row->addCell(new TLabel('bairro:'));
  174.         $row->addCell($bairro);
  175.  
  176.         // add a row for the field cidade
  177.         $row = $table->addRow();
  178.         $row->addCell(new TLabel('cidade:'));
  179.         $row->addCell($cidade);
  180.  
  181.         // add a row for the field estado
  182.         $row = $table->addRow();
  183.         $row->addCell(new TLabel('estado:'));
  184.         $row->addCell($estado);
  185.  
  186.         // add a row for the field cep
  187.         $row = $table->addRow();
  188.         $row->addCell(new TLabel('cep:'));
  189.         $row->addCell($cep);
  190.  
  191.         // add a row for the field fone
  192.         $row = $table->addRow();
  193.         $row->addCell(new TLabel('fone:'));
  194.         $row->addCell($fone);
  195.  
  196.         // add a row for the field email
  197.         $row = $table->addRow();
  198.         $row->addCell(new TLabel('email:'));
  199.         $row->addCell($email);
  200.  
  201.         // set exit action for input_exit
  202.         $change_action = new TAction(array($this, 'onChangeAction'));
  203.         $tipo->setChangeAction($change_action);
  204.  
  205.         // create an action button (save)
  206.         $save_button = new TButton('save');
  207.         // define the button action
  208.         $save_button->setAction(new TAction(array($this, 'onSave')), _t('Save'));
  209.         $save_button->setImage('ico_save.png');
  210.  
  211.         // create an action button (go to list)
  212.         $button2 = new TButton('list');
  213.         $button2->setAction(new TAction(array('InscricaoList', 'onReload')), 'Voltar para Listagem');
  214.         $button2->setImage('ico_datagrid.png');
  215.  
  216.         $this->form->setFields(array($id_inscricao, $unidade, $tipo,
  217.             $turno, $curso, $response_c, $entrada, $nome, $medio, $filiacao,
  218.             $naturalidade, $cpf, $rg, $endereco, $bairro, $cidade, $estado,
  219.             $cep, $fone, $email, $save_button, $button2));
  220.  
  221.         $subtable = new TTable;
  222.         $row = $subtable->addRow();
  223.         $row->addCell($save_button);
  224.         $row->addCell($button2);
  225.  
  226.         $container = new TTable;
  227.         $container->addRow()->addCell($this->form);
  228.         $container->addRow()->addCell($subtable);
  229.  
  230.  
  231.         // add the form to the page
  232.         parent::add($container);
  233.     }
  234.  
  235.     /**
  236.      * Action to be executed when the user changes the tipo field
  237.      */
  238.     public static function onChangeAction($param) {
  239.  
  240.         $options = array();
  241.  
  242.         if ($param['tipo'] == "Cursos Tecnicos") {
  243.             $options[1] = 'Edificacoes';
  244.         } elseif ($param['tipo'] == "Profissionalizante") {
  245.             $options[2] = 'two';
  246.         } elseif ($param['tipo'] == "Qualificacao") {
  247.             $options[3] = 'three';
  248.         }
  249.  
  250.         //percorre o array
  251.         foreach ($options as $option) {
  252.             $dados = $option;
  253.         }
  254.  
  255.         $obj = new StdClass;
  256.         $obj->response_c = $dados;
  257.         TForm::sendData('form_inscricao', $obj);
  258.         TCombo::reload('form_inscricao', 'curso', $options);
  259.     }
  260.  
  261.     /**
  262.      * method onSave()
  263.      * Executed whenever the user clicks at the save button
  264.      */
  265.     function onSave() {
  266.         try {
  267.             // open a transaction with database 'ctead'
  268.             TTransaction::open('ctead');
  269.  
  270.             // get the form data into an active record Inscricao
  271.             $object = $this->form->getData('Inscricao');
  272.  
  273.             // form validation
  274.             $this->form->validate();
  275.  
  276.             // stores the object
  277.             $object->store();
  278.  
  279.             // fill the form with the active record data
  280.             $this->form->setData($object);
  281.  
  282.             // close the transaction
  283.             TTransaction::close();
  284.  
  285.             // shows the success message
  286.             new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
  287.             // reload the listing
  288.         } catch (Exception $e) { // in case of exception
  289.             // shows the exception error message
  290.             new TMessage('error', '<b>Error</b> ' . $e->getMessage());
  291.  
  292.             // undo all pending operations
  293.             TTransaction::rollback();
  294.         }
  295.     }
  296.  
  297.     /**
  298.      * method onEdit()
  299.      * Executed whenever the user clicks at the edit button da datagrid
  300.      */
  301.     function onEdit($param) {
  302.         try {
  303.             if (isset($param['key'])) {
  304.                 // get the parameter $key
  305.                 $key = $param['key'];
  306.  
  307.                 // open a transaction with database 'ctead'
  308.                 TTransaction::open('ctead');
  309.  
  310.                 // instantiates object Inscricao
  311.                 $object = new Inscricao($key);
  312. //                var_dump($object);
  313.                 // fill the form with the active record data
  314.                 $this->form->setData($object);
  315.  
  316.                 // close the transaction
  317.                 TTransaction::close();
  318.             } else {
  319.                 $this->form->clear();
  320.             }
  321.         } catch (Exception $e) { // in case of exception
  322.             // shows the exception error message
  323.             new TMessage('error', '<b>Error</b> ' . $e->getMessage());
  324.  
  325.             // undo all pending operations
  326.             TTransaction::rollback();
  327.         }
  328.     }
  329.  
  330. }
  331.  
  332. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement