/**
  * method onSave()
  * Executed whenever the user clicks at the save button
  */
 function onSave()
 {
     try {
         TTransaction::open('app');
         // open a transaction
         // get the form data into an active record SystemUser
         $object = $this->form->getData('StdClass');
         $this->form->validate();
         // form validation
         $senhaatual = $object->current;
         $senhanova = $object->password;
         $confirmacao = $object->confirmation;
         $usuario = new SystemUser(TSession::getValue("userid"));
         if ($usuario->password == md5($senhaatual)) {
             if ($senhanova == $confirmacao) {
                 $usuario->password = md5($senhanova);
                 $usuario->store();
                 new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
             } else {
                 new TMessage('error', "A nova senha deve ser igual a sua confirmação.");
             }
         } else {
             new TMessage('error', "A senha atual não confere.");
         }
         TTransaction::close();
         // close the transaction
         // shows the success message
     } catch (Exception $e) {
         // in case of exception
         new TMessage('error', '<b>Error</b> ' . $e->getMessage());
         // shows the exception error message
         TTransaction::rollback();
         // undo all pending operations
     }
 }
Пример #2
0
 /**
  * method onInlineEdit()
  * Inline record editing
  * @param $param Array containing:
  *              key: object ID value
  *              field name: object attribute to be updated
  *              value: new attribute content
  */
 function onInlineEdit($param)
 {
     try {
         // get the parameter $key
         $field = $param['field'];
         $key = $param['key'];
         $value = $param['value'];
         // open a transaction with database 'permission'
         TTransaction::open('permission');
         // instantiates object System_user
         $object = new SystemUser($key);
         // deletes the object from the database
         $object->{$field} = $value;
         $object->store();
         // close the transaction
         TTransaction::close();
         // reload the listing
         $this->onReload($param);
         // shows the success message
         new TMessage('info', _t('Record Updated'));
     } catch (Exception $e) {
         // shows the exception error message
         new TMessage('error', '<b>Error</b> ' . $e->getMessage());
         // undo all pending operations
         TTransaction::rollback();
     }
 }