From 803e178e8dbb28ce44ccbf72a334cb79f1f067d6 Mon Sep 17 00:00:00 2001 From: Charl Joseph Mert Date: Mon, 25 Jan 2010 10:41:13 +0200 Subject: [PATCH] Brand server without requiring access to FS PT: 1243391 --- lib/config/config.inc.php | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/ktcore/KTWidgets.php | 5 +++++ plugins/ktcore/admin/manageBranding.php | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 96 insertions(+), 1 deletion(-) mode change 100644 => 100755 lib/config/config.inc.php diff --git a/lib/config/config.inc.php b/lib/config/config.inc.php old mode 100644 new mode 100755 index 632aeeb..0d8266d --- a/lib/config/config.inc.php +++ b/lib/config/config.inc.php @@ -288,6 +288,62 @@ class KTConfig { } /** + * Set a config value called $var to $value + * @param $var config variable and group in string like "ui/mainLogoTitle" + * @param $value a string with the value you want for the config item. + * @return boolean + */ + + function set($var = null, $value = null) { + global $default; + + if ($var == null) { + return false; + } + + $varParts = explode('/', $var); + $groupName = $varParts[0]; + $var = $varParts[1]; + + if ($var == '' || $groupName == ''){ + //var and group must be set + $default->log->error("config->set() requires the first parameter to be in the form 'groupName/configSetting'"); + return false; + } + + $sql = "SELECT id from config_settings WHERE item = '$var' and group_name = '$groupName'"; + $configId = DBUtil::getOneResultKey($sql,'id'); + if (PEAR::isError($configId)) + { + $default->log->error(sprintf(_kt("Couldn't get the config id:%s"), $configId->getMessage())); + return false; + } + + //If config var doesn't exist we create it + if ($configId == null) { + $configId = DBUtil::autoInsert('config_settings', array('item' => $var ,'value' => $value, 'group_name' => $groupName)); + + if (PEAR::isError($configId)) + { + $default->log->error(sprintf(_kt("Couldn't insert config value:%s"), $configId->getMessage())); + return false; + } + + } else { + + $res = DBUtil::autoUpdate('config_settings', array('value' => $value), $configId); + if (PEAR::isError($res)) { + $default->log->error(sprintf(_kt("Couldn't update config value: %s"), $res->getMessage())); + return false; + } + } + + $this->clearCache(); + + return true; + } + + /** * Return the location of the config.ini * * @return string diff --git a/plugins/ktcore/KTWidgets.php b/plugins/ktcore/KTWidgets.php index d351f73..583d11a 100755 --- a/plugins/ktcore/KTWidgets.php +++ b/plugins/ktcore/KTWidgets.php @@ -74,7 +74,12 @@ class KTCoreFileWidget extends KTWidget { return null; } + if (!$this->bRequired) { + return null; + } + $oVF =& KTValidatorFactory::getSingleton(); + return $oVF->get('ktcore.validators.requiredfile', array( 'test' => sprintf('_kt_attempt_unique_%s', $this->sName), 'basename' => $this->sBasename, diff --git a/plugins/ktcore/admin/manageBranding.php b/plugins/ktcore/admin/manageBranding.php index f1d032d..02782c4 100755 --- a/plugins/ktcore/admin/manageBranding.php +++ b/plugins/ktcore/admin/manageBranding.php @@ -92,11 +92,30 @@ class ManageBrandDispatcher extends KTAdminDispatcher { $widgets = array(); $validators = array(); + + // Adding the title widget + $widgets[] = $oWF->get('ktcore.widgets.string', array( + 'label' => _kt('Title'), + 'required' => false, + 'name' => 'logo_title', + 'value' => '', + 'description' => _kt("This will appear when hovering over the logo."), + )); + + // Adding the url widget + $widgets[] = $oWF->get('ktcore.widgets.string', array( + 'label' => _kt('Url'), + 'required' => false, + 'name' => 'logo_url', + 'id' => 'file', + 'value' => '', + 'description' => _kt("This is the website address you will be redirected to after clicking the logo"), + )); // Adding the File Upload Widget $widgets[] = $oWF->get('ktcore.widgets.file', array( 'label' => _kt('Logo File'), - 'required' => true, + 'required' => false, 'name' => 'file', 'id' => 'file', 'value' => '', @@ -353,6 +372,21 @@ class ManageBrandDispatcher extends KTAdminDispatcher { function do_upload(){ global $default; + + //No file, edit title and url only then + if (($_FILES['_kt_attempt_unique_file']['name'] == '')) { + $config =& KTConfig::getSingleton(); + $logoUrl = $_REQUEST['data']['logo_url']; + $logoTitle = $_REQUEST['data']['logo_title']; + + if ($config->set('ui/companyLogoUrl', $logoUrl) && $config->set('ui/companyLogoTitle', $logoTitle)) { + $this->successRedirectTo('main', _kt('Logo fields have been successfully updated.')); + } else { + $this->errorRedirectToMain(_kt("Couldn't update logo fields")); + } + + exit(0); + } $oForm = $this->getUploadLogoForm(); $res = $oForm->validate(); -- libgit2 0.21.4