public function addEditOnFormSubmitted(AppForm $form) { // add if ($this->getAction() == 'add') { try { $values = $form->getValues(); dibi::query('INSERT INTO [' . TABLE_PRIVILEGES . '] %v;', $values); $this->flashMessage('The privilege has been added.', 'ok'); if (ACL_CACHING) { unset($this->cache['gui_acl']); // invalidate cache } $this->redirect('Privileges:'); } catch (Exception $e) { $form->addError('The privilege has not been added.'); throw $e; } } else { // edit try { $id = $this->getParam('id'); $values = $form->getValues(); dibi::query('UPDATE [' . TABLE_PRIVILEGES . '] SET %a WHERE id=%i;', $values, $id); $this->flashMessage('The privilege has been edited.', 'ok'); if (ACL_CACHING and ACL_PROG_MODE) { unset($this->cache['gui_acl']); // invalidate cache } $this->redirect('Privileges:'); } catch (Exception $e) { $form->addError('The privilege has not been edited.'); throw $e; } } }
public function addEditOnFormSubmitted(AppForm $form) { // add action if ($this->getAction() == 'add') { try { $values = $form->getValues(); if ($values['parent_id'] == 0) { $values['parent_id'] = NULL; } dibi::query('INSERT INTO [' . TABLE_ROLES . '] %v;', $values); $this->flashMessage('The role has been added.', 'ok'); if (ACL_CACHING) { unset($this->cache['gui_acl']); // invalidate cache } $this->redirect('Roles:'); } catch (Exception $e) { $form->addError('The role has not been added.'); throw $e; } } else { // edit action try { $id = $this->getParam('id'); $values = $form->getValues(); if ($values['parent_id'] == 0) { $values['parent_id'] = NULL; } dibi::query('UPDATE [' . TABLE_ROLES . '] SET %a WHERE id=%i;', $values, $id); $this->flashMessage('The role has been edited.', 'ok'); if (ACL_CACHING) { unset($this->cache['gui_acl']); // invalidate cache } $this->redirect('Roles:'); } catch (Exception $e) { $form->addError('The role has not been edited.'); throw $e; } } }
public function addEditOnFormSubmitted(AppForm $form) { // Permission form submitted $id = $this->getParam('id'); $values = $form->getValues(); if ($values['assertion_id'] == '0') { $values['assertion_id'] = NULL; } // add if (!$id) { $error = FALSE; dibi::begin(); try { foreach ($values['privilege_id'] as $privi) { foreach ($values['resource_id'] as $resou) { foreach ($values['role_id'] as $role) { if ($resou == '0') { $resou = NULL; } if ($privi == '0') { $privi = NULL; } dibi::query('INSERT INTO [' . TABLE_ACL . '] (role_id, privilege_id, resource_id, assertion_id, access) VALUES (%i, %i, %i, %iN, %b);', $role, $privi, $resou, $values['assertion_id'], $values['access']); } } } dibi::commit(); $this->flashMessage('Permission was successfully assigned.', 'ok'); if (ACL_CACHING) { unset($this->cache['gui_acl']); // invalidate cache } $this->redirect('Permission:'); } catch (Exception $e) { $error = FALSE; $form->addError('Permission was not successfully assigned.'); throw $e; } if ($error) { dibi::rollback(); } } else { // edit try { dibi::query('UPDATE [' . TABLE_ACL . '] SET %a WHERE id=%i;', $values, $id); // dibi::query('UPDATE ['.TABLE_ACL.'] SET (role_id, privilege_id, resource_id, assertion_id, access) VALUES (%i, %i, %i, %iN, %b) WHERE id=%i;', $role, $privi, $resou, $values['assertion_id'], $values['access'], $id); $this->flashMessage('Permission was successfully edited.', 'ok'); if (ACL_CACHING) { unset($this->cache['gui_acl']); // invalidate cache } $this->redirect('Permission:'); } catch (Exception $e) { $form->addError('Permission was not successfully edited.'); throw $e; } } }
/** * Data grid form submit handler. * @param AppForm * @return void */ public function formSubmitHandler(AppForm $form) { $this->receivedSignal = 'submit'; // was form submitted? if ($form->isSubmitted()) { $values = $form->getValues(); if ($form['filterSubmit']->isSubmittedBy()) { $this->handleFilter($values['filters']); } elseif ($form['pageSubmit']->isSubmittedBy()) { $this->handlePage($values['page']); } elseif ($form['itemsSubmit']->isSubmittedBy()) { $this->handleItems($values['items']); } elseif ($form['resetSubmit']->isSubmittedBy()) { $this->handleReset(); } elseif ($form['operationSubmit']->isSubmittedBy()) { if (!is_array($this->onOperationSubmit)) { throw new InvalidStateException('No user defined handler for operations; assign valid callback to operations handler into DataGrid::$operationsHandler variable.'); } } else { throw new InvalidStateException("Unknown submit button."); } } if (!$this->presenter->isAjax()) { $this->presenter->redirect('this'); } }
public function albumFormSubmitted(AppForm $form) { if ($form['save']->isSubmittedBy()) { $id = (int) $this->getParam('id'); $album = new Albums(); if ($id > 0) { $album->update($id, $form->getValues()); $this->flashMessage('The album has been updated.'); } else { $album->insert($form->getValues()); $this->flashMessage('The album has been added.'); } } $this->redirect('default'); }
public function addEditOnFormSubmitted(AppForm $form) { $error = false; dibi::begin(); // add action if ($this->getAction() == 'add') { try { $values = $form->getValues(); $roles = $values['roles']; unset($values['password2'], $values['roles']); $values['password'] = md5($values['password']); dibi::query('INSERT INTO [' . TABLE_USERS . '] %v;', $values); $user_id = dibi::getInsertId(); if (count($roles)) { foreach ($roles as $role) { dibi::query('INSERT INTO [' . TABLE_USERS_ROLES . '] (user_id, role_id) VALUES (%i, %i);', $user_id, $role); } } $this->flashMessage('The user has been added.', 'ok'); dibi::commit(); if (ACL_CACHING) { unset($this->cache['gui_acl']); // invalidate cache } $this->redirect('Users:'); } catch (Exception $e) { $error = true; $form->addError('The user has not been added.'); throw $e; } } else { // edit action $id = $this->getParam('id'); try { $values = $form->getValues(); $roles = $values['roles']; unset($values['roles']); dibi::query('UPDATE [' . TABLE_USERS . '] SET %a WHERE id=%i;', $values, $id); dibi::query('DELETE FROM [' . TABLE_USERS_ROLES . '] WHERE user_id=%i;', $id); if (count($roles)) { foreach ($roles as $role) { dibi::query('INSERT INTO [' . TABLE_USERS_ROLES . '] (user_id, role_id) VALUES (%i, %i);', $id, $role); } } $this->flashMessage('The user has been edited.', 'ok'); dibi::commit(); if (ACL_CACHING) { unset($this->cache['gui_acl']); // invalidate cache } $this->redirect('Users:'); } catch (Exception $e) { $error = true; $form->addError('The user has not been edited.'); throw $e; } } if ($error) { dibi::rollback(); } }
public function savePermissions(AppForm $form) { $values = $form->getValues(); unset($values['btnSave']); $group_id = (int) $values['group_id']; unset($values['group_id']); $allowed = array(); foreach ($values as $cb => $value) { if ($value == true) { $allowed[] = (int) str_replace('allowed_', '', $cb); } } $model = new UsersModuleModel(); $model->savePermissions($group_id, $allowed); $this->template->edit = false; $this->invalidateControl('form'); $this->flash('Permissions saved'); }