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()); } } }
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; }
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); } }
<?php // Reset labels $data = array(array("code" => "platform_name", "label" => "Platform Name"), array("code" => "company_name", "label" => "Name"), array("code" => "company_phone", "label" => "Phone"), array("code" => "company_address", "label" => "Address"), array("code" => "company_country", "label" => "Country"), array("code" => "company_vat_number", "label" => "VAT Number"), array("code" => "system_territory", "label" => "Timezone"), array("code" => "system_timezone", "label" => "Timezone"), array("code" => "system_currency", "label" => "Currency"), array("code" => "system_default_language", "label" => "Default Languages"), array("code" => "system_publication_access_type", "label" => "Publication access type"), array("code" => "support_email", "label" => "Support Email Address"), array("code" => "support_link", "label" => "Support Link"), array("code" => "support_name", "label" => "Name"), array("code" => "support_chat_code", "label" => "Online Chat"), array("code" => Acl_Model_Role::DEFAULT_ADMIN_ROLE_CODE, "label" => "Default admin role")); foreach ($data as $configData) { $config = new System_Model_Config(); $config->find($configData["code"], "code")->setLabel($configData["label"])->save(); }
<?php $data = array("code" => "application_try_apk", "label" => "Try to generate the apk when downloading the Android source"); $config = new System_Model_Config(); $config->find($data["code"], "code")->setData($data)->save();
<?php $default_role = new System_Model_Config(); $default_role->find("default_role", "code"); $data = array("code" => Acl_Model_Role::DEFAULT_ADMIN_ROLE_CODE, "label" => "Default admin role"); $default_role->addData($data)->save();
public function saveftpAction() { if ($data = Zend_Json::decode($this->getRequest()->getRawBody())) { try { $error_code = 0; $ftp_host = !empty($data["host"]) ? $data["host"] : null; $ftp_user = !empty($data["username"]) ? $data["username"] : null; $ftp_password = !empty($data["password"]) ? $data["password"] : null; $ftp_port = !empty($data["port"]) ? $data["port"] : Siberian_Ftp::DEFAULT_PORT; $ftp_path = null; if (!empty($data["path"])) { $ftp_path = rtrim($data["path"], "/"); } if (!$ftp_path) { $ftp_path = Siberian_Ftp::DEFAULT_PATH; } $ftp = new Siberian_Ftp($ftp_host, $ftp_user, $ftp_password, $ftp_port, $ftp_path); if (!$ftp->checkConnection()) { $error_code = 1; throw new Exception($this->_("Unable to connect to your FTP. Please check the connection information.")); } else { if (!$ftp->isSiberianDirectory()) { $error_code = 2; throw new Exception($this->_("Unable to detect your site. Please make sure the entered path is correct.")); } } $fields = array("ftp_host" => $ftp_host, "ftp_username" => $ftp_user, "ftp_password" => $ftp_password, "ftp_port" => $ftp_port, "ftp_path" => $ftp_path); foreach ($fields as $key => $value) { $config = new System_Model_Config(); $config->find($key, "code"); if (!$config->getId()) { $config->setCode($key)->setLabel(ucfirst(implode(" ", explode("_", $key)))); } $config->setCode($key)->setValue($value)->save(); } $data = array("success" => 1, "message" => $this->_("Info successfully saved")); } catch (Exception $e) { $data = array("error" => 1, "code" => $error_code, "message" => $e->getMessage()); } $this->_sendHtml($data); } }