Commit 803e178e8dbb28ce44ccbf72a334cb79f1f067d6
1 parent
c089eaf6
Brand server without requiring access to FS
PT: 1243391 Added Title and URL fields as config items. Updated config.inc.php to include a set method for setting specific config items. Updated by: Charl Joseph Mert
Showing
3 changed files
with
96 additions
and
1 deletions
lib/config/config.inc.php
100644 → 100755
| @@ -288,6 +288,62 @@ class KTConfig { | @@ -288,6 +288,62 @@ class KTConfig { | ||
| 288 | } | 288 | } |
| 289 | 289 | ||
| 290 | /** | 290 | /** |
| 291 | + * Set a config value called $var to $value | ||
| 292 | + * @param $var config variable and group in string like "ui/mainLogoTitle" | ||
| 293 | + * @param $value a string with the value you want for the config item. | ||
| 294 | + * @return boolean | ||
| 295 | + */ | ||
| 296 | + | ||
| 297 | + function set($var = null, $value = null) { | ||
| 298 | + global $default; | ||
| 299 | + | ||
| 300 | + if ($var == null) { | ||
| 301 | + return false; | ||
| 302 | + } | ||
| 303 | + | ||
| 304 | + $varParts = explode('/', $var); | ||
| 305 | + $groupName = $varParts[0]; | ||
| 306 | + $var = $varParts[1]; | ||
| 307 | + | ||
| 308 | + if ($var == '' || $groupName == ''){ | ||
| 309 | + //var and group must be set | ||
| 310 | + $default->log->error("config->set() requires the first parameter to be in the form 'groupName/configSetting'"); | ||
| 311 | + return false; | ||
| 312 | + } | ||
| 313 | + | ||
| 314 | + $sql = "SELECT id from config_settings WHERE item = '$var' and group_name = '$groupName'"; | ||
| 315 | + $configId = DBUtil::getOneResultKey($sql,'id'); | ||
| 316 | + if (PEAR::isError($configId)) | ||
| 317 | + { | ||
| 318 | + $default->log->error(sprintf(_kt("Couldn't get the config id:%s"), $configId->getMessage())); | ||
| 319 | + return false; | ||
| 320 | + } | ||
| 321 | + | ||
| 322 | + //If config var doesn't exist we create it | ||
| 323 | + if ($configId == null) { | ||
| 324 | + $configId = DBUtil::autoInsert('config_settings', array('item' => $var ,'value' => $value, 'group_name' => $groupName)); | ||
| 325 | + | ||
| 326 | + if (PEAR::isError($configId)) | ||
| 327 | + { | ||
| 328 | + $default->log->error(sprintf(_kt("Couldn't insert config value:%s"), $configId->getMessage())); | ||
| 329 | + return false; | ||
| 330 | + } | ||
| 331 | + | ||
| 332 | + } else { | ||
| 333 | + | ||
| 334 | + $res = DBUtil::autoUpdate('config_settings', array('value' => $value), $configId); | ||
| 335 | + if (PEAR::isError($res)) { | ||
| 336 | + $default->log->error(sprintf(_kt("Couldn't update config value: %s"), $res->getMessage())); | ||
| 337 | + return false; | ||
| 338 | + } | ||
| 339 | + } | ||
| 340 | + | ||
| 341 | + $this->clearCache(); | ||
| 342 | + | ||
| 343 | + return true; | ||
| 344 | + } | ||
| 345 | + | ||
| 346 | + /** | ||
| 291 | * Return the location of the config.ini | 347 | * Return the location of the config.ini |
| 292 | * | 348 | * |
| 293 | * @return string | 349 | * @return string |
plugins/ktcore/KTWidgets.php
| @@ -74,7 +74,12 @@ class KTCoreFileWidget extends KTWidget { | @@ -74,7 +74,12 @@ class KTCoreFileWidget extends KTWidget { | ||
| 74 | return null; | 74 | return null; |
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | + if (!$this->bRequired) { | ||
| 78 | + return null; | ||
| 79 | + } | ||
| 80 | + | ||
| 77 | $oVF =& KTValidatorFactory::getSingleton(); | 81 | $oVF =& KTValidatorFactory::getSingleton(); |
| 82 | + | ||
| 78 | return $oVF->get('ktcore.validators.requiredfile', array( | 83 | return $oVF->get('ktcore.validators.requiredfile', array( |
| 79 | 'test' => sprintf('_kt_attempt_unique_%s', $this->sName), | 84 | 'test' => sprintf('_kt_attempt_unique_%s', $this->sName), |
| 80 | 'basename' => $this->sBasename, | 85 | 'basename' => $this->sBasename, |
plugins/ktcore/admin/manageBranding.php
| @@ -92,11 +92,30 @@ class ManageBrandDispatcher extends KTAdminDispatcher { | @@ -92,11 +92,30 @@ class ManageBrandDispatcher extends KTAdminDispatcher { | ||
| 92 | 92 | ||
| 93 | $widgets = array(); | 93 | $widgets = array(); |
| 94 | $validators = array(); | 94 | $validators = array(); |
| 95 | + | ||
| 96 | + // Adding the title widget | ||
| 97 | + $widgets[] = $oWF->get('ktcore.widgets.string', array( | ||
| 98 | + 'label' => _kt('Title'), | ||
| 99 | + 'required' => false, | ||
| 100 | + 'name' => 'logo_title', | ||
| 101 | + 'value' => '', | ||
| 102 | + 'description' => _kt("This will appear when hovering over the logo."), | ||
| 103 | + )); | ||
| 104 | + | ||
| 105 | + // Adding the url widget | ||
| 106 | + $widgets[] = $oWF->get('ktcore.widgets.string', array( | ||
| 107 | + 'label' => _kt('Url'), | ||
| 108 | + 'required' => false, | ||
| 109 | + 'name' => 'logo_url', | ||
| 110 | + 'id' => 'file', | ||
| 111 | + 'value' => '', | ||
| 112 | + 'description' => _kt("This is the website address you will be redirected to after clicking the logo"), | ||
| 113 | + )); | ||
| 95 | 114 | ||
| 96 | // Adding the File Upload Widget | 115 | // Adding the File Upload Widget |
| 97 | $widgets[] = $oWF->get('ktcore.widgets.file', array( | 116 | $widgets[] = $oWF->get('ktcore.widgets.file', array( |
| 98 | 'label' => _kt('Logo File'), | 117 | 'label' => _kt('Logo File'), |
| 99 | - 'required' => true, | 118 | + 'required' => false, |
| 100 | 'name' => 'file', | 119 | 'name' => 'file', |
| 101 | 'id' => 'file', | 120 | 'id' => 'file', |
| 102 | 'value' => '', | 121 | 'value' => '', |
| @@ -353,6 +372,21 @@ class ManageBrandDispatcher extends KTAdminDispatcher { | @@ -353,6 +372,21 @@ class ManageBrandDispatcher extends KTAdminDispatcher { | ||
| 353 | 372 | ||
| 354 | function do_upload(){ | 373 | function do_upload(){ |
| 355 | global $default; | 374 | global $default; |
| 375 | + | ||
| 376 | + //No file, edit title and url only then | ||
| 377 | + if (($_FILES['_kt_attempt_unique_file']['name'] == '')) { | ||
| 378 | + $config =& KTConfig::getSingleton(); | ||
| 379 | + $logoUrl = $_REQUEST['data']['logo_url']; | ||
| 380 | + $logoTitle = $_REQUEST['data']['logo_title']; | ||
| 381 | + | ||
| 382 | + if ($config->set('ui/companyLogoUrl', $logoUrl) && $config->set('ui/companyLogoTitle', $logoTitle)) { | ||
| 383 | + $this->successRedirectTo('main', _kt('Logo fields have been successfully updated.')); | ||
| 384 | + } else { | ||
| 385 | + $this->errorRedirectToMain(_kt("Couldn't update logo fields")); | ||
| 386 | + } | ||
| 387 | + | ||
| 388 | + exit(0); | ||
| 389 | + } | ||
| 356 | 390 | ||
| 357 | $oForm = $this->getUploadLogoForm(); | 391 | $oForm = $this->getUploadLogoForm(); |
| 358 | $res = $oForm->validate(); | 392 | $res = $oForm->validate(); |