Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class AdminController extends Zend_Controller_Action {
- public $auth;
- protected $_user;
- public function init() {
- /* Initialize action controller here */
- $this->auth = Zend_Auth::getInstance();
- $this->_user = $this->auth->getIdentity();
- $admin_status = $this->_user->admin;
- if ($admin_status == true) {
- return;
- } else {
- // throw an error
- // TODO: send out a custom error message
- $this->view->content = 'rubbish';
- // $flashMessenger->addMessage('We did something in the last request');
- // $route = array('controller' => 'error', 'action' => 'errormsg');
- }
- }
- public function indexAction() {
- // action body
- $this->view->title = "Registered Users";
- $this->view->headTitle($this->view->title, 'PREPEND');
- $users = new Application_Model_DbTable_Users();
- $this->view->admin = $users->fetchAll('id <>'.$this->_user->id);
- }
- public function addAction() {
- // action body
- $this->view->title = "Add new user" . $username;
- $this->view->headTitle($this->view->title, 'PREPEND');
- $form = new Application_Form_Admin();
- $form->submit->setLabel('Add');
- $this->view->form = $form;
- if ($this->getRequest()->isPost()) {
- $formData = $this->getRequest()->getPost();
- if ($form->isValid($formData)) {
- $username = $form->getValue('username');
- $password = $form->getValue('password');
- $real_name = $form->getValue('real_name');
- $newsuser = new Application_Model_DbTable_Users();
- $newsuser->addUser($username, $password, $real_name);
- $this->_helper->redirector('index');
- } else {
- $form->populate($formData);
- }
- }
- }
- public function deleteAction() {
- //action body
- $this->view->title = "Delete User";
- $this->view->headTitle($this->view->title, 'PREPEND');
- if ($this->getRequest()->isPost()) {
- $del = $this->getRequest()->getPost('del');
- if ($del == 'Yes') {
- $id = $this->getRequest()->getPost('id');
- $users = new Application_Model_DbTable_Users();
- $users->deleteuser($id);
- }
- $this->_helper->redirector('index');
- } else {
- $id = $this->_getParam('id', 0);
- $users = new Application_Model_DbTable_Users();
- $this->view->user = $users->getuser($id);
- }
- }
- public function editAction() {
- // action body
- $this->view->title = "Edit User";
- $this->view->headTitle($this->view->title, 'PREPEND');
- $form = new Application_Form_Admin();
- $form->submit->setLabel('Save');
- $this->view->form = $form;
- if ($this->getRequest()->isPost()) {
- $formData = $this->getRequest()->getPost();
- if ($form->isValid($formData)) {
- $id = (int) $form->getValue('id');
- $username = $form->getValue('username');
- $password = $form->getValue('password');
- $real_name = $form->getValue('real_name');
- $admin = $form->getValue('admin');
- $users = new Application_Model_DbTable_Users();
- $users->updateUser($id, $username, $password, $real_name, $admin);
- $this->_helper->redirector('index');
- } else {
- $form->populate($formData);
- }
- } else {
- $id = $this->_getParam('id', 0);
- if ($id > 0) {
- $users = new Application_Model_DbTable_Users();
- $form->populate($users->getUser($id));
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment