Guest User

Untitled

a guest
May 29th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.78 KB | None | 0 0
  1. <?php
  2.  
  3. class AdminController extends Zend_Controller_Action {
  4.  
  5.     public $auth;
  6.     protected $_user;
  7.  
  8.     public function init() {
  9.         /* Initialize action controller here */
  10.         $this->auth = Zend_Auth::getInstance();
  11.         $this->_user = $this->auth->getIdentity();
  12.         $admin_status = $this->_user->admin;
  13.         if ($admin_status == true) {
  14.             return;
  15.         } else {
  16.             // throw an error
  17.             // TODO: send out a custom error message
  18.  
  19.             $this->view->content = 'rubbish';
  20.             //  $flashMessenger->addMessage('We did something in the last request');
  21.             //  $route = array('controller' => 'error', 'action' => 'errormsg');
  22.         }
  23.     }
  24.  
  25.     public function indexAction() {
  26.         // action body
  27.         $this->view->title = "Registered Users";
  28.         $this->view->headTitle($this->view->title, 'PREPEND');
  29.         $users = new Application_Model_DbTable_Users();
  30.         $this->view->admin = $users->fetchAll('id <>'.$this->_user->id);
  31.     }
  32.  
  33.     public function addAction() {
  34.         // action body
  35.         $this->view->title = "Add new user" . $username;
  36.         $this->view->headTitle($this->view->title, 'PREPEND');
  37.         $form = new Application_Form_Admin();
  38.         $form->submit->setLabel('Add');
  39.         $this->view->form = $form;
  40.         if ($this->getRequest()->isPost()) {
  41.             $formData = $this->getRequest()->getPost();
  42.             if ($form->isValid($formData)) {
  43.                 $username = $form->getValue('username');
  44.                 $password = $form->getValue('password');
  45.                 $real_name = $form->getValue('real_name');
  46.                 $newsuser = new Application_Model_DbTable_Users();
  47.                 $newsuser->addUser($username, $password, $real_name);
  48.                 $this->_helper->redirector('index');
  49.             } else {
  50.                 $form->populate($formData);
  51.             }
  52.         }
  53.     }
  54.  
  55.     public function deleteAction() {
  56.         //action body
  57.         $this->view->title = "Delete User";
  58.         $this->view->headTitle($this->view->title, 'PREPEND');
  59.         if ($this->getRequest()->isPost()) {
  60.             $del = $this->getRequest()->getPost('del');
  61.             if ($del == 'Yes') {
  62.                 $id = $this->getRequest()->getPost('id');
  63.                 $users = new Application_Model_DbTable_Users();
  64.                 $users->deleteuser($id);
  65.             }
  66.             $this->_helper->redirector('index');
  67.         } else {
  68.             $id = $this->_getParam('id', 0);
  69.             $users = new Application_Model_DbTable_Users();
  70.             $this->view->user = $users->getuser($id);
  71.         }
  72.     }
  73.  
  74.     public function editAction() {
  75.         // action body
  76.         $this->view->title = "Edit User";
  77.         $this->view->headTitle($this->view->title, 'PREPEND');
  78.         $form = new Application_Form_Admin();
  79.         $form->submit->setLabel('Save');
  80.         $this->view->form = $form;
  81.         if ($this->getRequest()->isPost()) {
  82.             $formData = $this->getRequest()->getPost();
  83.             if ($form->isValid($formData)) {
  84.                 $id = (int) $form->getValue('id');
  85.                 $username = $form->getValue('username');
  86.                 $password = $form->getValue('password');
  87.                 $real_name = $form->getValue('real_name');
  88.                 $admin = $form->getValue('admin');
  89.                 $users = new Application_Model_DbTable_Users();
  90.                 $users->updateUser($id, $username, $password, $real_name, $admin);
  91.                 $this->_helper->redirector('index');
  92.             } else {
  93.                 $form->populate($formData);
  94.             }
  95.         } else {
  96.             $id = $this->_getParam('id', 0);
  97.             if ($id > 0) {
  98.                 $users = new Application_Model_DbTable_Users();
  99.                 $form->populate($users->getUser($id));
  100.             }
  101.         }
  102.     }
  103.  
  104. }
Add Comment
Please, Sign In to add comment