public function setaddpageAction()
 {
     if ($data = Zend_Json::decode($this->getRequest()->getRawBody())) {
         try {
             if (empty($data["admin_id"]) or empty($data["app_id"])) {
                 throw new Exception($this->_("An error occurred while saving. Please try again later."));
             }
             $admin = new Admin_Model_Admin();
             $admin->find($data["admin_id"]);
             $application = new Application_Model_Application();
             $application->find($data["app_id"]);
             if (!$admin->getId() or !$application->getId()) {
                 throw new Exception($this->_("An error occurred while saving. Please try again later."));
             }
             $admin->setIsAllowedToAddPages(!empty($data["can_add_page"]))->save();
             $data = array("success" => 1, "message" => $this->_("Data saved successfully."));
         } catch (Exception $e) {
             $data = array("error" => 1, "message" => $e->getMessage());
         }
         $this->_sendHtml($data);
     }
 }
 public function setpermissionstoadminAction()
 {
     if ($data = $this->getRequest()->getPost()) {
         try {
             if (empty($data["admin_id"]) or empty($data["app_id"])) {
                 throw new Exception($this->_("1An error occurred while saving. Please try again later."));
             }
             $admin = new Admin_Model_Admin();
             $admin->find($data["admin_id"]);
             if (($admin->getId() or $admin->getParentId()) and ($admin->getId() != $this->getAdmin()->getId() and $admin->getParentId() != $this->getAdmin()->getId())) {
                 $this->getSession()->addError("This administrator does not exist");
             }
             $application = new Application_Model_Application();
             $application->find($data["app_id"]);
             if (!$application->getId()) {
                 throw new Exception($this->_("2An error occurred while saving. Please try again later."));
             }
             if (!$application->hasAsAdmin($this->getAdmin()->getId())) {
                 throw new Exception($this->_("3An error occurred while saving. Please try again later."));
             }
             $admin->setIsAllowedToAddPages(!empty($data["is_selected"]));
             $application->addAdmin($admin);
             $data = array("success" => 1);
         } catch (Exception $e) {
             $data = array("error" => 1, "message" => $e->getMessage());
         }
         $this->_sendHtml($data);
     }
 }