Advertisement
ale-php

Untitled

Mar 4th, 2015
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.17 KB | None | 0 0
  1. <?php
  2. /**
  3. * GnrSacForm Registration
  4. * @author <your name here>
  5. */
  6. class GnrSacForm extends TPage
  7. {
  8. protected $form; // form
  9. protected $gnr_cpfcnpj;
  10.  
  11. /**
  12. * Class constructor
  13. * Creates the page and the registration form
  14. */
  15. function __construct()
  16. {
  17. parent::__construct();
  18.  
  19. // creates the form
  20. $this->form = new TForm('form_GnrSac');
  21. $this->form->class = 'tform'; // CSS class
  22. $this->form->style = 'width: 100%';
  23.  
  24. // add a table inside form
  25. $table = new TTable;
  26. $table-> width = '100%';
  27. $this->form->add($table);
  28.  
  29. // add a row for the form title
  30. $row = $table->addRow();
  31. $row->class = 'tformtitle'; // CSS class
  32. $row->addCell( new TLabel('Manter Sacado') )->colspan = 2;
  33.  
  34.  
  35.  
  36. // create the form fields
  37. $gnr_id = new TEntry('gnr_id');
  38. $gnr_id_ext = new TEntry('gnr_id_ext');
  39. $gnr_nome = new TEntry('gnr_nome');
  40. //$gnr_tipo = new TCombo('gnr_tipo');
  41. //$gnr_tipo = new TRadioGroup('gnr_tipo');
  42. $this->gnr_cpfcnpj = new TEntry('gnr_cpfcnpj');
  43. $gnr_cep = new TSeekButton('gnr_cep');
  44.  
  45. $gnr_tipo = new TRadioGroup('gnr_tipo');
  46. $gnr_tipo->setLayout('horizontal');
  47. $items = array();
  48. $items[1] = 'CNPJ';
  49. $items[2] = 'CPF';
  50. $gnr_tipo->addItems($items);
  51. $gnr_tipo->setValue(1);
  52. // set exit action for tipocadastro
  53. $change_action = new TAction(array($this, 'onChangeAction'));
  54. $gnr_tipo->setChangeAction($change_action);
  55.  
  56.  
  57. /* $gnr_tipo_items = array();
  58. $gnr_tipo_items['F'] ='Física';
  59. $gnr_tipo_items['J'] ='Jurídica';
  60.  
  61. $gnr_tipo->addItems($gnr_tipo_items);*/
  62.  
  63.  
  64. // define the sizes
  65. $gnr_id->setSize(100);
  66. $gnr_id_ext->setSize(100);
  67. $gnr_nome->setSize(200);
  68. $gnr_tipo->setSize(200);
  69. $gnr_cpfcnpj->setSize(100);
  70. $gnr_cep->setSize(200);
  71.  
  72.  
  73. // validations
  74. $gnr_id_ext->addValidation('ID Externo', new TRequiredValidator);
  75. $gnr_nome->addValidation('Nome', new TRequiredValidator);
  76. $gnr_tipo->addValidation('Tipo Pessoa', new TRequiredValidator);
  77. $gnr_cpfcnpj->addValidation('CPF/CNPJ', new TRequiredValidator);
  78. $gnr_cep->addValidation('CEP', new TRequiredValidator);
  79.  
  80.  
  81. // add one row for each form field
  82. $table->addRowSet( new TLabel('ID:'), $gnr_id );
  83. $table->addRowSet( $label_gnr_id_ext = new TLabel('ID Externo:'), $gnr_id_ext );
  84. $table->addRowSet( $label_gnr_nome = new TLabel('Nome:'), $gnr_nome );
  85. $table->addRowSet( $label_gnr_tipo = new TLabel('Tipo Pessoa:'), $gnr_tipo );
  86. $table->addRowSet( $label_gnr_cpfcnpj = new TLabel('CPF/CNPJ:'), $gnr_cpfcnpj );
  87. $table->addRowSet( $label_gnr_cep = new TLabel('CEP:'), $gnr_cep );
  88.  
  89. $change_action = new TAction(array($this, 'onChangeAction'));
  90. $gnr_tipo->setChangeAction($change_action);
  91.  
  92. $this->form->setFields(array($gnr_id,$gnr_id_ext,$gnr_nome,$gnr_tipo,$gnr_cpfcnpj,$gnr_cep));
  93.  
  94.  
  95. // create the form actions
  96. $save_button = TButton::create('save', array($this, 'onSave'), _t('Save'), 'ico_save.png');
  97. $new_button = TButton::create('new', array($this, 'onEdit'), _t('New'), 'ico_new.png');
  98.  
  99. $this->form->addField($save_button);
  100. $this->form->addField($new_button);
  101.  
  102. $buttons_box = new THBox;
  103. $buttons_box->add($save_button);
  104. $buttons_box->add($new_button);
  105.  
  106. // add a row for the form action
  107. $row = $table->addRow();
  108. $row->class = 'tformaction'; // CSS class
  109. $row->addCell($buttons_box)->colspan = 2;
  110.  
  111. $container = new TTable;
  112. $container->style = 'width: 80%';
  113. $container->addRow()->addCell(new TXMLBreadCrumb('menu.xml','GnrSacList'));
  114. $container->addRow()->addCell($this->form);
  115.  
  116. parent::add($container);
  117. }
  118.  
  119.  
  120. public static function onChangeAction($param)
  121. {
  122. try{
  123. $obj = new StdClass;
  124. $checked = $param['gnr_tipo'];
  125. new TMessage('error', '<b>Error</b> ' .$param['gnr_tipo'] );
  126.  
  127. if ($checked == 1){
  128. $this->gnr_cpfcnpj->setMask('99.999.999/9999-99'); // aqui da erro
  129. }
  130. else{
  131. $this->gnr_cpfcnpj->setMask('999.999.999-99'); // aqui tambem da erro
  132. }
  133.  
  134.  
  135. }
  136. catch (Exception $e) // in case of exception
  137. {
  138. new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // shows the exception error message
  139. $this->form->setData( $this->form->getData() ); // keep form data
  140. //TTransaction::rollback(); // undo all pending operations
  141. }
  142. }
  143.  
  144.  
  145. /**
  146. * method onSave()
  147. * Executed whenever the user clicks at the save button
  148. */
  149. function onSave()
  150. {
  151. try
  152. {
  153. TTransaction::open('permission'); // open a transaction
  154.  
  155. // get the form data into an active record GnrSac
  156. $object = $this->form->getData('GnrSac');
  157. $this->form->validate(); // form validation
  158. $object->store(); // stores the object
  159. $this->form->setData($object); // keep form data
  160. TTransaction::close(); // close the transaction
  161.  
  162. // shows the success message
  163. new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
  164. }
  165. catch (Exception $e) // in case of exception
  166. {
  167. new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // shows the exception error message
  168. $this->form->setData( $this->form->getData() ); // keep form data
  169. TTransaction::rollback(); // undo all pending operations
  170. }
  171. }
  172.  
  173. /**
  174. * method onEdit()
  175. * Executed whenever the user clicks at the edit button da datagrid
  176. */
  177. function onEdit($param)
  178. {
  179. try
  180. {
  181. if (isset($param['key']))
  182. {
  183. $key=$param['key']; // get the parameter $key
  184. TTransaction::open('permission'); // open a transaction
  185. $object = new GnrSac($key); // instantiates the Active Record
  186. $this->form->setData($object); // fill the form
  187. TTransaction::close(); // close the transaction
  188. }
  189. else
  190. {
  191. $this->form->clear();
  192. }
  193. }
  194. catch (Exception $e) // in case of exception
  195. {
  196. new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // shows the exception error message
  197. TTransaction::rollback(); // undo all pending operations
  198. }
  199. }
  200. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement