Ejemplo n.º 1
0
 public function uploadAction()
 {
     if ($code = $this->getRequest()->getPost("code")) {
         try {
             if (empty($_FILES) || empty($_FILES['file']['name'])) {
                 throw new Exception("No file has been sent");
             }
             $path = Core_Model_Directory::getPathTo(System_Model_Config::IMAGE_PATH);
             $base_path = Core_Model_Directory::getBasePathTo(System_Model_Config::IMAGE_PATH);
             if (!is_dir($base_path)) {
                 mkdir($base_path, 0777, true);
             }
             $adapter = new Zend_File_Transfer_Adapter_Http();
             $adapter->setDestination($base_path);
             if ($adapter->receive()) {
                 $file = $adapter->getFileInfo();
                 $config = new System_Model_Config();
                 $config->find($code, "code");
                 $config->setValue($path . DS . $file['file']['name'])->save();
                 $message = sprintf("Your %s has been successfully saved", $code);
                 $this->_sendHtml(array("success" => 1, "message" => $this->_($message)));
             } else {
                 $messages = $adapter->getMessages();
                 if (!empty($messages)) {
                     $message = implode("\n", $messages);
                 } else {
                     $message = $this->_("An error occurred during the process. Please try again later.");
                 }
                 throw new Exception($message);
             }
         } catch (Exception $e) {
             $data = array("error" => 1, "message" => $e->getMessage());
         }
     }
 }
Ejemplo n.º 2
0
 protected function _save($data)
 {
     foreach ($data as $code => $values) {
         if (!in_array($code, $this->_codes)) {
             continue;
         }
         if ($code == "favicon") {
             continue;
         }
         $config = new System_Model_Config();
         $config->find($code, "code");
         $config->setValue($values["value"])->save();
     }
     return $this;
 }
Ejemplo n.º 3
0
 public function saveAction()
 {
     if ($param = Zend_Json::decode($this->getRequest()->getRawBody())) {
         try {
             $role = new Acl_Model_Role();
             if (empty($param["role"]) or !is_array($param["role"])) {
                 throw new Exception($this->_("An error occurred while saving. Please, try again later."));
             }
             $role_data = $param["role"];
             $resources_data = !empty($param["resources"]) ? $param["resources"] : array();
             if (isset($role_data["id"])) {
                 $role->find($role_data["id"]);
             }
             $resource = new Acl_Model_Resource();
             $resources_data = $resource->flattenedResources($resources_data);
             $role->setResources($resources_data)->setLabel($role_data["label"])->setCode($role_data["code"])->save();
             $config = new System_Model_Config();
             $config->find(Acl_Model_Role::DEFAULT_ADMIN_ROLE_CODE, "code");
             $default_role_id = $config->getValue();
             $new_default_role_id = null;
             if ($default_role_id == $role->getId() and !$role_data["default"]) {
                 $new_default_role_id = Acl_Model_Role::DEFAULT_ROLE_ID;
             } else {
                 if ($role_data["default"]) {
                     $new_default_role_id = $role->getId();
                 }
             }
             if (!empty($new_default_role_id)) {
                 $config->setValue($new_default_role_id)->save();
             }
             $data = array("success" => true, "message" => $this->_("Your role has been successfully saved"));
         } catch (Exception $e) {
             $data = array("error" => true, "message" => $e->getMessage());
         }
         $this->_sendHtml($data);
     }
 }