public function savepostAction() { if ($data = $this->getRequest()->getPost()) { try { $admin = new Admin_Model_Admin(); $current_admin = $this->getSession()->getAdmin(); $check_email_admin = new Admin_Model_Admin(); $html = ''; if (!empty($data['admin_id'])) { $admin->find($data['admin_id']); if (!$admin->getId()) { throw new Exception($this->_('An error occurred while saving your account. Please try again later.')); } } if (empty($data['email'])) { throw new Exception($this->_('The email is required')); } if ($admin->getId() and $admin->getId() != $this->getAdmin()->getId() and ($admin->getParentId() and $admin->getParentId() != $this->getAdmin()->getId() or !$admin->getParentId())) { throw new Exception($this->_("An error occurred while saving your account. Please try again later.")); } if (!$admin->getId() or $admin->getId() != $this->getAdmin()->getId()) { $admin->setParentId($this->getAdmin()->getId()); } // $isNew = (bool) !$admin->getId(); $check_email_admin->find($data['email'], 'email'); if ($check_email_admin->getId() and $check_email_admin->getId() != $admin->getId()) { throw new Exception($this->_('This email address is already used')); } if (isset($data['password'])) { if ($data['password'] != $data['confirm_password']) { throw new Exception($this->_('Your password does not match the entered password.')); } if (!empty($data['old_password']) and !$admin->isSamePassword($data['old_password'])) { throw new Exception($this->_("The old password does not match the entered password.")); } if (!empty($data['password'])) { $admin->setPassword($data['password']); unset($data['password']); } } else { if ($isNew) { throw new Exception($this->_('The password is required')); } } if (empty($data["role_id"]) and $data["mode"] == "management") { throw new Exception($this->_('The account role is required')); } else { if ($data["mode"] == "management") { $admin->setRoleId($data["role_id"]); } } // if($isNew) { // $this->_sendNewAdminEmail($admin, $data['password']); // } $admin->addData($data)->save(); $html = array('success' => 1); // if($current_admin->getParentId()) { $html = array_merge($html, array('success_message' => $this->_('The account has been successfully saved'), 'message_timeout' => false, 'message_button' => false, 'message_loader' => 1)); // } else { // $this->getSession()->addSuccess($this->_('The account has been successfully saved')); // } } catch (Exception $e) { $html = array('error' => 1, 'message' => $e->getMessage()); } $this->_sendHtml($html); } }