public function addAction($question_id) { $this->view->poll = Questions::findFirst($question_id); if ($this->request->isPost()) { $option = new Options(); $option->question_id = $question_id; $option->option_name = $this->request->getPost('name'); $option->vote = 0; $option->save(); return $this->dispatcher->forward(array('action' => 'show', 'params' => array($question_id))); } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Options(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Options'])) { $model->attributes = $_POST['Options']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
/** * Lilina installer * * Installs Lilina after going through many complicated checks * * @param string $sitename Name of the site * @param string $username Initial username of the admin user * @param string $password Initial password of the admin user * @return bool True if the installer succeeded, false otherwise */ public function install($sitename, $username, $password) { require_once LILINA_INCPATH . '/core/version.php'; $settings = $this->generate_default_settings($sitename, $username, $password); if (!is_writable(LILINA_PATH . '/content/system/config/') || !($settings_file = @fopen(LILINA_PATH . '/content/system/config/settings.php', 'w+'))) { $this->file_error_notice(LILINA_PATH . '/content/system/config/settings.php', $sitename, $username, $password); return false; } fputs($settings_file, $settings); fclose($settings_file); if (file_exists(LILINA_PATH . '/content/system/config/feeds.data')) { echo "<p>Using existing feeds data</p>\n"; } else { $feeds_file = new DataHandler(LILINA_CONTENT_DIR . '/system/config/'); $feeds_file = $feeds_file->save('feeds.json', json_encode(array())); if (!$feeds_file) { $this->file_error_notice(LILINA_PATH . '/content/system/config/feeds.json', $sitename, $username, $password); return false; } } /** Make sure it's writable now */ if (!$this->make_writable(LILINA_PATH . '/content/system/config/feeds.json')) { echo "<p>Couldn't make <code>content/system/config/feeds.json</code> writable. Please ensure you make it writable yourself</p>\n"; } default_options(); Options::lazy_update('sitename', $sitename); if (!Options::save()) { $this->file_error_notice(LILINA_PATH . '/content/system/config/options.data', $sitename, $username, $password); return false; } $user = new User($username, $password); $user->identify(); ?> <h1 id="title">Installation Complete!</h1> <p>Lilina has been installed and is now ready to go. Please note your username and password below, as it <strong>won't be shown again</strong>!</p> <dl id="logindetails"> <dt>Your username is</dt> <dd id="username"><?php echo $username; ?> </dd> <dt>and your password is</dt> <dd id="password"><?php echo $password; ?> </dd> </dl> <p><a href="admin/">Head to the admin panel</a> to get started!</p> <?php return true; }
/** * @see Form::save() */ public function save() { parent::save(); // save options and affected package ids $saveOptions = $affectedPackageIDArray = array(); foreach ($this->cachedOptions as $option) { $saveOptions[$option['optionID']] = $option['optionValue']; $affectedPackageIDArray[] = $option['packageID']; } Options::save($saveOptions); // clear cache Options::resetCache(); // delete relevant options.inc.php's $affectedPackageIDArray = array_unique($affectedPackageIDArray); Options::resetFile($affectedPackageIDArray); $this->saved(); // show succes message WCF::getTPL()->assign('success', true); }
/** * Import a language * */ public static function importLanguage($filename, $showMessage = true, $fastImport = false) { $localErrors = array(); $allAccounts = array(); $dom = new domDocument(); if (!$dom->load($filename)) { if ($showMessage) { throw new CException(Yii::t('lazy8', 'input file could not be xml parsed')); } else { throw new CException('input file could not be xml parsed'); } } $root = $dom->documentElement; if ($root->nodeName != "lazy8webportlang") { if ($showMessage) { $localErrors = array(array(Yii::t('lazy8', 'Upload failed. This is not a valid file.'), Yii::t('lazy8', 'Select a file and try again'))); } $this->render('importlang'); return $localErrors; } if ($root->getAttribute('version') > 1.0) { if ($showMessage) { $localErrors = array(array(Yii::t('lazy8', 'There maybe problems because this is a file version greater then this programs version'), Yii::t('lazy8', 'Select a file and try again'))); } } $nodeLanguages = $root->getElementsByTagName('language'); unset($root); unset($dom); foreach ($nodeLanguages as $nodeLanguage) { //make sure the company code is unique //Message::model()->dbConnection->createCommand("DELETE FROM Message WHERE language='".$nodeLanguage->getAttribute('langcode')."'")->execute(); //make sure that all the source messages exist for this language if (!$fastImport) { $sources = SourceMessage::model()->findAll(); foreach ($sources as $source) { $foundMessage = Message::model()->find(array('condition' => "language='" . $nodeLanguage->getAttribute('langcode') . "' AND id=" . $source->id)); if ($foundMessage == null) { $trans = new Message(); $trans->id = $source->id; $trans->translation = $source->message; $trans->language = $nodeLanguage->getAttribute('langcode'); $trans->save(); } } } else { //quickly delete all occurances of this language SourceMessage::model()->dbConnection->createCommand("DELETE FROM Message WHERE language='{$nodeLanguage->getAttribute('langcode')}'")->execute(); } //update the version information if ($nodeLanguage->getAttribute('version') != null) { $foundOption = Options::model()->find('name=:name AND userId=:id AND companyId=:compid', array(':name' => "Language.Version." . $nodeLanguage->getAttribute('langcode'), ':id' => 0, ':compid' => 0)); if ($foundOption !== null) { $foundOption->delete(); } $createOption = new Options(); $createOption->name = "Language.Version." . $nodeLanguage->getAttribute('langcode'); $createOption->userId = 0; $createOption->companyId = 0; $createOption->datavalue = $nodeLanguage->getAttribute('version'); $createOption->save(); } //get all the messages $nodeMessages = $nodeLanguage->getElementsByTagName('message'); foreach ($nodeMessages as $nodeMessage) { $sources = SourceMessage::model()->find(array('condition' => "category='" . $nodeMessage->getAttribute('category') . "' AND message='" . SourceMessageController::sqlCleanString(CHtml::encode($nodeMessage->getAttribute('key'))) . "'")); if ($sources == null) { $newSource = new SourceMessage(); $newSource->message = CHtml::encode($nodeMessage->getAttribute('key')); $newSource->category = $nodeMessage->getAttribute('category'); $maxId = 0; $command = SourceMessage::model()->dbConnection->createCommand("SELECT MAX(id) as maxid FROM SourceMessage"); try { $reader = $command->query(); } catch (Exception $e) { echo '<h2>Died on Sql Maxid</h2>'; throw $e; } if ($reader !== null && count($reader) > 0) { foreach ($reader as $row) { $maxId = $row['maxid'] + 1; break; //there is only one row here anyway. } } $newSource->id = $maxId; if ($newSource->save()) { $modelMessage = new Message(); $modelMessage->language = $nodeLanguage->getAttribute('langcode'); $modelMessage->id = $newSource->id; $modelMessage->translation = SourceMessageController::getNodeText($nodeMessage, "translation"); $modelMessage->save(); if (!$fastImport) { //now we must add to all of the other languages. $langs = Message::model()->findAll(array('select' => 'distinct language')); if (isset($langs) && count($langs) > 0) { foreach ($langs as $lang) { if ($nodeLanguage->getAttribute('langcode') != $lang->language) { $newLangItem = new Message(); $newLangItem->id = $newSource->id; $newLangItem->language = $lang->language; $newLangItem->translation = CHtml::encode($nodeMessage->getAttribute('key')); $newLangItem->save(); } } } } } } else { //make sure the key is unique if (!$fastImport) { Message::model()->dbConnection->createCommand("DELETE FROM Message WHERE language='" . $nodeLanguage->getAttribute('langcode') . "' AND id=" . $sources->id)->execute(); } $modelMessage = new Message(); $modelMessage->language = $nodeLanguage->getAttribute('langcode'); $modelMessage->id = $sources->id; $modelMessage->translation = SourceMessageController::getNodeText($nodeMessage, "translation"); //try{ if (!$modelMessage->save()) { if ($showMessage) { $localErrors[] = array(Yii::t('lazy8', 'Failed import of translation.') . ' = ' . $nodeLanguage->getAttribute('langcode') . ' ; ' . $nodeMessage->getAttribute('key'), Yii::t('lazy8', 'Select a file and try again')); } } //}catch(Exception $e){ // echo "error on langcode=" . $nodeLanguage->getAttribute('langcode') . " key=" . $nodeMessage->getAttribute('key'); // die(); //} } } } return $localErrors; }
public static function setOption($name, $val) { if ($name) { $param = Options::model()->findByAttributes(['key' => $name]); if ($param) { $param->value = $val; $param->update(); return true; } else { $param = new Options(); $param->key = $name; $param->value = $val; $param->save(); return true; } } else { return false; } }
/** * actionAddOption * * @access public * @return void */ public function actionAddOption($id) { Yii::log("actionIndex OptionsController called", "trace", self::LOG_CAT); $model = new Options(); $model->setCustomScenario($id); if (isset($_POST['Options'])) { $model->attributes = $_POST['Options']; //print_r($model); die; if ($model->save()) { Yii::app()->user->setFlash('success', "Option successfully added."); $this->redirect(['options/index/id/' . $id]); } if (!$model->hasErrors()) { Yii::app()->user->setFlash('error', "An error occurred while adding the option, please contact your administrator."); } } // add options via ajax from chosen plugin // if(isset($_POST['options'])) { // $model->setScenario($_POST['options']['scenario']); // unset($_POST['options']['scenario']); // $model->attributes = $_POST['options']; // if($model->save()) { // echo json_encode(ModelToArray::convertModelToArray($model, [$model->tableName() => 'optionId, label'])); // return; // } // $model->unsetAttributes(); // //print_r($model->attributeNames()); die; // echo json_encode(['optionId' => '']); // return; // // } // echo get_class($this->optionsMask['formFieldsModels'][$id]); // Select all values whose inputType is ""Select" $formElementsCriteria = new CDbCriteria(); $formElementsCriteria->condition = "t.inputType='dropdownlist'"; if ($this->optionsMask['formFieldsModels'][$id] == 'FrameworkFields') { // $formElementsCriteria->join = 'LEFT JOIN parentLabel AS frameworkFields ON parentLabel.id = t.parentId'; $formElementsCriteria->with = 'parent'; } //$formElementsModel = new {$this->optionsMask['formFieldsModels'][$id]}; $fetchOptions = CActiveRecord::model($this->optionsMask['formFieldsModels'][$id])->findAll($formElementsCriteria); //print_r($fetchOptions); die; $formElements = CHtml::listData($fetchOptions, $this->optionsMask['joinLabels'][$id][0], function ($option) use($id) { if (isset($option->parent)) { return $option->parent->label . ' - ' . $option->{$this->optionsMask['joinLabels'][$id][1]}; } return $option->{$this->optionsMask['joinLabels'][$id][1]}; }); //print_r($formElements); die; $this->render('add', ['model' => $model, 'dropDownAttribute' => $this->optionsMask['relationNames'][$id] . 'Id', 'formElements' => $formElements]); }
/** * Convenience function for Options::save() * * @see Options::save() */ function save_options() { return Options::save(); }
/** * Set the states and initialize the options table if necessary * */ public static function setOptionStatesAndControlTable($force, $skipDatabaseCheck, $webapp, $options, $compId, $userId) { if (!$skipDatabaseCheck) { foreach ($options as $key => $option) { $foundOption = null; $foundOption = Options::model()->find('name=:name AND userId=:id AND companyId=:compid', array(':name' => $key, ':id' => $userId, ':compid' => $compId)); if ($foundOption !== null) { if ($webapp->id == $userId || $force) { $webapp->setState($key, User::convertOptionToObject($foundOption->datavalue, $option)); } } else { $createOption = new Options(); $createOption->name = $key; $createOption->userId = $userId; $createOption->companyId = $compId; $createOption->datavalue = $option[1]; $createOption->save(); if ($webapp->id == $userId || $force) { $webapp->setState($key, User::convertOptionToObject($option[1], $option)); } } } } else { if ($webapp->id == $userId || $force) { //just set all company permissions to no foreach ($options as $key => $option) { $webapp->setState($key, User::convertOptionToObject($option[2], $option)); } } } }