function setGlobalSetting($settingname, $settingvalue) { if (Yii::app()->getConfig("demoMode") == true && ($settingname == 'sitename' || $settingname == 'defaultlang' || $settingname == 'defaulthtmleditormode' || $settingname == 'filterxsshtml')) { return; //don't save } if ($record = SettingGlobal::model()->findByPk($settingname)) { $record->stg_value = $settingvalue; $record->save(); } else { $record = new SettingGlobal(); $record->stg_name = $settingname; $record->stg_value = $settingvalue; $record->save(); } Yii::app()->setConfig($settingname, $settingvalue); }
/** * create or update the updatekey to the submited value * @param string $submittedUpdateKey the new key id * @return array<string,false|string> the new update key if success, CActiveRecord result if error * * TODO : should return same status than server to use the same view render */ public function setUpdateKey($submittedUpdateKey) { // The update keys never contains special characters, so, it should not affect the key // If it affects the key : then the key was wrong... and the database is safe $submittedUpdateKey = trim(htmlspecialchars(addslashes($submittedUpdateKey))); $updateKey = SettingGlobal::model()->findByPk('update_key'); if (!$updateKey) { // Create $updateKey = new SettingGlobal(); $updateKey->stg_name = 'update_key'; $updateKey->stg_value = $submittedUpdateKey; $result = $updateKey->save(); } else { //Update $result = SettingGlobal::model()->updateByPk('update_key', array('stg_value' => $submittedUpdateKey)); } if ($result) { // If success we return the updatekey row $updateKey = SettingGlobal::model()->findByPk('update_key'); return $updateKey; } else { // Else we return the errors return array('result' => FALSE, 'error' => 'db_error'); } }
/** * Stores the blacklist setting to the database */ function storeBlacklistValues() { $values = array('blacklistallsurveys', 'blacklistnewsurveys', 'blockaddingtosurveys', 'hideblacklisted', 'deleteblacklisted', 'allowunblacklist', 'userideditable'); foreach ($values as $value) { if ($find = SettingGlobal::model()->findByPk($value)) { SettingGlobal::model()->updateByPk($value, array('stg_value' => Yii::app()->request->getPost($value))); } else { $stg = new SettingGlobal(); $stg->stg_name = $value; $stg->stg_value = Yii::app()->request->getPost($value); $stg->save(); } } Yii::app()->getController()->redirect(array('admin/participants/sa/blacklistControl')); }