Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * InscricaoForm Registration
- * @author Jackson Meires
- */
- class InscricaoFormView extends TPage {
- protected $form; // form
- protected $notebook;
- /**
- * Class constructor
- * Creates the page and the registration form
- */
- function __construct() {
- parent::__construct();
- // creates the notebook
- $this->notebook = new TNotebook;
- $this->notebook->setSize(700, 580);
- $scroll = new TScroll;
- $scroll->setSize(700, 580);
- $scroll->setTransparency(TRUE);
- // creates the table container
- $table = new TTable;
- // creates the form
- $this->form = new TForm('form_inscricao');
- $this->notebook->appendPage(_t('Data'), $scroll);
- $scroll->add($table);
- // add the notebook inside the form
- $this->form->add($this->notebook);
- // create the form fields
- $id_inscricao = new TEntry('id');
- $id_inscricao->setEditable(FALSE);
- $unidade = new TCombo('unidade');
- // $unidade->setEditable(false);
- $turno = new TCombo('turno');
- $tipo = new TCombo('tipo');
- $curso = new TCombo('curso');
- $response_c = new TEntry('response_c');
- $entrada = new TEntry('entrada');
- $nome = new TEntry('nome');
- $medio = new TEntry('medio');
- $filiacao = new TEntry('filiacao');
- $naturalidade = new TEntry('naturalidade');
- $cpf = new TEntry('cpf');
- $rg = new TEntry('rg');
- $endereco = new TEntry('endereco');
- $bairro = new TEntry('bairro');
- $cidade = new TEntry('cidade');
- $estado = new TEntry('estado');
- $cep = new TEntry('cep');
- $fone = new TEntry('fone');
- $email = new TEntry('email');
- // define the sizes
- $id_inscricao->setSize(100);
- $unidade->setSize(200);
- $turno->setSize(200);
- $entrada->setSize(200);
- $nome->setSize(200);
- $medio->setSize(200);
- $filiacao->setSize(200);
- $naturalidade->setSize(200);
- $cpf->setSize(200);
- $rg->setSize(200);
- $endereco->setSize(200);
- $bairro->setSize(200);
- $cidade->setSize(200);
- $estado->setSize(200);
- $cep->setSize(200);
- $fone->setSize(200);
- $email->setSize(200);
- $itemUnidade = array();
- // adiciona as opcoes na combo
- $itemUnidade['NATAL'] = 'NATAL';
- $unidade->addItems($itemUnidade);
- $unidade->setValue('NATAL');
- // adiciona as opcoes na combo
- $itemTurno = array();
- $itemTurno['Matutino'] = 'Matutino';
- $itemTurno['Vespertino'] = 'Vespertino';
- $itemTurno['Noturno'] = 'Noturno';
- $itemTurno['Sábado'] = 'Sábado';
- $turno->addItems($itemTurno);
- $combo_items = array();
- $combo_items['Cursos Tecnicos'] = 'Cursos Técnicos';
- $combo_items['Profissionalizante'] = 'Profissionalizante';
- $combo_items['Qualificacao'] = 'Qualificação';
- $response_c->setEditable(FALSE);
- $tipo->addItems($combo_items);
- $curso->addItems($combo_items);
- // add a row for the field id_inscricao
- $row = $table->addRow();
- $row->addCell(new TLabel('Codigo:'));
- $row->addCell($id_inscricao);
- // add a row for the field unidade
- $row = $table->addRow();
- $row->addCell(new TLabel('Unidade:'));
- $row->addCell($unidade);
- // add a row for the field curso
- $row = $table->addRow();
- $row->addCell(new TLabel('Tipo:'));
- $row->addCell($tipo);
- $row = $table->addRow();
- $row->addCell(new TLabel('Curso:'));
- $row->addCell($curso);
- $row = $table->addRow();
- $row->addCell(new TLabel('Ver:'));
- $row->addCell($response_c);
- // add a row for the field turno
- $row = $table->addRow();
- $row->addCell(new TLabel('turno:'));
- $row->addCell($turno);
- // add a row for the field entrada
- $row = $table->addRow();
- $row->addCell(new TLabel('entrada:'));
- $row->addCell($entrada);
- // add a row for the field nome
- $row = $table->addRow();
- $row->addCell(new TLabel('nome:'));
- $row->addCell($nome);
- // add a row for the field medio
- $row = $table->addRow();
- $row->addCell(new TLabel('medio:'));
- $row->addCell($medio);
- // add a row for the field filiacao
- $row = $table->addRow();
- $row->addCell(new TLabel('filiacao:'));
- $row->addCell($filiacao);
- // add a row for the field naturalidade
- $row = $table->addRow();
- $row->addCell(new TLabel('naturalidade:'));
- $row->addCell($naturalidade);
- // add a row for the field cpf
- $row = $table->addRow();
- $row->addCell(new TLabel('cpf:'));
- $row->addCell($cpf);
- // add a row for the field rg
- $row = $table->addRow();
- $row->addCell(new TLabel('rg:'));
- $row->addCell($rg);
- // add a row for the field endereco
- $row = $table->addRow();
- $row->addCell(new TLabel('endereco:'));
- $row->addCell($endereco);
- // add a row for the field bairro
- $row = $table->addRow();
- $row->addCell(new TLabel('bairro:'));
- $row->addCell($bairro);
- // add a row for the field cidade
- $row = $table->addRow();
- $row->addCell(new TLabel('cidade:'));
- $row->addCell($cidade);
- // add a row for the field estado
- $row = $table->addRow();
- $row->addCell(new TLabel('estado:'));
- $row->addCell($estado);
- // add a row for the field cep
- $row = $table->addRow();
- $row->addCell(new TLabel('cep:'));
- $row->addCell($cep);
- // add a row for the field fone
- $row = $table->addRow();
- $row->addCell(new TLabel('fone:'));
- $row->addCell($fone);
- // add a row for the field email
- $row = $table->addRow();
- $row->addCell(new TLabel('email:'));
- $row->addCell($email);
- // set exit action for input_exit
- $change_action = new TAction(array($this, 'onChangeAction'));
- $tipo->setChangeAction($change_action);
- // create an action button (save)
- $save_button = new TButton('save');
- // define the button action
- $save_button->setAction(new TAction(array($this, 'onSave')), _t('Save'));
- $save_button->setImage('ico_save.png');
- // create an action button (go to list)
- $button2 = new TButton('list');
- $button2->setAction(new TAction(array('InscricaoList', 'onReload')), 'Voltar para Listagem');
- $button2->setImage('ico_datagrid.png');
- $this->form->setFields(array($id_inscricao, $unidade, $tipo,
- $turno, $curso, $response_c, $entrada, $nome, $medio, $filiacao,
- $naturalidade, $cpf, $rg, $endereco, $bairro, $cidade, $estado,
- $cep, $fone, $email, $save_button, $button2));
- $subtable = new TTable;
- $row = $subtable->addRow();
- $row->addCell($save_button);
- $row->addCell($button2);
- $container = new TTable;
- $container->addRow()->addCell($this->form);
- $container->addRow()->addCell($subtable);
- // add the form to the page
- parent::add($container);
- }
- /**
- * Action to be executed when the user changes the tipo field
- */
- public static function onChangeAction($param) {
- $options = array();
- if ($param['tipo'] == "Cursos Tecnicos") {
- $options[1] = 'Edificacoes';
- } elseif ($param['tipo'] == "Profissionalizante") {
- $options[2] = 'two';
- } elseif ($param['tipo'] == "Qualificacao") {
- $options[3] = 'three';
- }
- //percorre o array
- foreach ($options as $option) {
- $dados = $option;
- }
- $obj = new StdClass;
- $obj->response_c = $dados;
- TForm::sendData('form_inscricao', $obj);
- TCombo::reload('form_inscricao', 'curso', $options);
- }
- /**
- * method onSave()
- * Executed whenever the user clicks at the save button
- */
- function onSave() {
- try {
- // open a transaction with database 'ctead'
- TTransaction::open('ctead');
- // get the form data into an active record Inscricao
- $object = $this->form->getData('Inscricao');
- // form validation
- $this->form->validate();
- // stores the object
- $object->store();
- // fill the form with the active record data
- $this->form->setData($object);
- // close the transaction
- TTransaction::close();
- // shows the success message
- new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
- // reload the listing
- } catch (Exception $e) { // in case of exception
- // shows the exception error message
- new TMessage('error', '<b>Error</b> ' . $e->getMessage());
- // undo all pending operations
- TTransaction::rollback();
- }
- }
- /**
- * method onEdit()
- * Executed whenever the user clicks at the edit button da datagrid
- */
- function onEdit($param) {
- try {
- if (isset($param['key'])) {
- // get the parameter $key
- $key = $param['key'];
- // open a transaction with database 'ctead'
- TTransaction::open('ctead');
- // instantiates object Inscricao
- $object = new Inscricao($key);
- // var_dump($object);
- // fill the form with the active record data
- $this->form->setData($object);
- // close the transaction
- TTransaction::close();
- } else {
- $this->form->clear();
- }
- } catch (Exception $e) { // in case of exception
- // shows the exception error message
- new TMessage('error', '<b>Error</b> ' . $e->getMessage());
- // undo all pending operations
- TTransaction::rollback();
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement