예제 #1
0
 public function indexAction()
 {
     try {
         $admin_form = new Application_Form_AdminForm();
         $this->view->form = $admin_form;
         $adminsMapper = new Application_Model_AdminsMapper();
         $admins = new Application_Model_Admins();
         $request = $this->getRequest();
         if ($request->isPost()) {
             $request_type = $request->getParam("request_type", false);
             if ($request_type) {
                 if ($request_type == "add") {
                     $params = $request->getParams();
                     if ($admin_form->isValid($params)) {
                         foreach ($params as $param => $value) {
                             if ($param == "hashed_password") {
                                 $value = sha1($value);
                             }
                             $admins->__set($param, $value);
                         }
                         if ($adminsMapper->addNewAdmin($admins)) {
                             $this->view->message = "Admin added successfully";
                             $this->view->hasMessage = true;
                             $this->view->messageType = "success";
                         } else {
                             $this->view->message = "Error occured while adding. Please try again";
                             $this->view->hasMessage = true;
                             $this->view->messageType = "danger";
                         }
                     } else {
                         $this->view->message = "Error occured while Adding. Please fill form correctly";
                         $this->view->hasMessage = true;
                         $this->view->messageType = "danger";
                     }
                 } elseif ($request_type == "delete") {
                     $id = $request->getParam("id");
                     if ($adminsMapper->deleteAdminById($id)) {
                         $this->view->hasMessage = true;
                         $this->view->messageType = "success";
                         $this->view->message = "Admin deleted successfully.";
                     } else {
                         $this->view->hasMessage = true;
                         $this->view->messageType = "danger";
                         $this->view->message = "Error occured while deleting. Please try again.";
                     }
                 }
             }
         }
         $admin = $adminsMapper->getAllAdmins();
         $this->view->admin = $admin;
         $this->authorised = true;
     } catch (Exception $ex) {
         $this->authorised = false;
         $this->view->hasMessage = true;
         $this->view->messageType = "danger";
         $this->view->message = $ex->getMessage();
     }
 }
예제 #2
0
 public function updateAdmin(Application_Model_Admins $admin)
 {
     $data = array("admin_fname" => $admin->__get("admin_fname"), "admin_lname" => $admin->__get("admin_lname"), "admin_email" => $admin->__get("admin_email"), "hashed_password" => $admin->__get("hashed_password"), "admin_username" => $admin->__get("admin_username"), "admin_role" => $admin->__get("admin_role"), "reset_code" => $admin->__get("reset_code"));
     $where = array("admin_id = ?" => $admin->__get("admin_id"));
     $result = $this->_db_table->update($data, $where);
     return $result;
 }