/** * Optional settings screen */ private function stepOptionalConfiguration() { $aData['clang'] = $clang = $this->lang; $aData['confirmation'] = Yii::app()->session['optconfig_message']; $aData['title'] = $clang->gT("Optional settings"); $aData['descp'] = $clang->gT("Optional settings to give you a head start"); $aData['classesForStep'] = array('off', 'off', 'off', 'off', 'off', 'on'); $aData['progressValue'] = 80; $this->loadHelper('surveytranslator'); $aData['model'] = $model = new InstallerConfigForm('optional'); if (isset($_POST['InstallerConfigForm'])) { $model->attributes = $_POST['InstallerConfigForm']; //run validation, if it fails, load the view again else proceed to next step. if ($model->validate()) { $adminLoginPwd = $model->adminLoginPwd; $confirmPwd = $model->confirmPwd; $defaultuser = $model->adminLoginName; $defaultpass = $model->adminLoginPwd; $siteadminname = $model->adminName; $siteadminbounce = $siteadminemail = $model->adminEmail; $sitename = $model->siteName; $defaultlang = $model->surveylang; $aData['title'] = $clang->gT("Database configuration"); $aData['descp'] = $clang->gT("Please enter the database settings you want to use for LimeSurvey:"); $aData['classesForStep'] = array('off', 'off', 'off', 'on', 'off', 'off'); $aData['progressValue'] = 40; //config file is written, and we've a db in place $this->connection = Yii::app()->db; //checking DB Connection if ($this->connection->getActive() == true) { $password_hash = hash('sha256', $defaultpass); try { $this->connection->createCommand()->insert('{{users}}', array('users_name' => $defaultuser, 'password' => $password_hash, 'full_name' => $siteadminname, 'parent_id' => 0, 'lang' => $defaultlang, 'email' => $siteadminemail, 'create_survey' => 1, 'create_user' => 1, 'participant_panel' => 1, 'delete_user' => 1, 'superadmin' => 1, 'configurator' => 1, 'manage_template' => 1, 'manage_label' => 1)); $this->connection->createCommand()->insert("{{settings_global}}", array('stg_name' => 'SessionName', 'stg_value' => self::_getRandomString())); foreach (array('sitename', 'siteadminname', 'siteadminemail', 'siteadminbounce', 'defaultlang') as $insert) { $this->connection->createCommand()->insert("{{settings_global}}", array('stg_name' => $insert, 'stg_value' => ${$insert})); } // only continue if we're error free otherwise setup is broken. } catch (Exception $e) { throw new Exception(sprintf('Could not add optional settings: %s.', $e)); } Yii::app()->session['deletedirectories'] = true; $aData['title'] = $clang->gT("Success!"); $aData['descp'] = $clang->gT("LimeSurvey has been installed successfully."); $aData['classesForStep'] = array('off', 'off', 'off', 'off', 'off', 'off'); $aData['progressValue'] = 100; $aData['user'] = $defaultuser; $aData['pwd'] = $defaultpass; $this->render('/installer/success_view', $aData); exit; } } else { // if passwords don't match, redirect to proper link. Yii::app()->session['optconfig_message'] = sprintf('<b>%s</b>', $clang->gT("Passwords don't match.")); $this->redirect($this->createUrl('installer/optional')); } } elseif (empty(Yii::app()->session['configFileWritten'])) { $this->_writeConfigFile(); } $this->render('/installer/optconfig_view', $aData); }
/** * Optional settings screen */ private function stepOptionalConfiguration() { $aData['clang'] = $clang = $this->lang; $aData['confirmation'] = Yii::app()->session['optconfig_message']; $aData['title'] = $clang->gT("Optional settings"); $aData['descp'] = $clang->gT("Optional settings to give you a head start"); $aData['classesForStep'] = array('off', 'off', 'off', 'off', 'off', 'on'); $aData['progressValue'] = 80; $this->loadHelper('surveytranslator'); $aData['model'] = $model = new InstallerConfigForm('optional'); if (isset($_POST['InstallerConfigForm'])) { $model->attributes = $_POST['InstallerConfigForm']; //run validation, if it fails, load the view again else proceed to next step. if ($model->validate()) { $sDefaultAdminUserName = $model->adminLoginName; $sDefaultAdminPassword = $model->adminLoginPwd; $sDefaultAdminRealName = $model->adminName; $sDefaultSiteName = $model->siteName; $sDefaultSiteLanguage = $model->surveylang; $sDefaultAdminEmail = $model->adminEmail; $aData['title'] = $clang->gT("Database configuration"); $aData['descp'] = $clang->gT("Please enter the database settings you want to use for LimeSurvey:"); $aData['classesForStep'] = array('off', 'off', 'off', 'on', 'off', 'off'); $aData['progressValue'] = 40; //config file is written, and we've a db in place $this->connection = Yii::app()->db; //checking DB Connection if ($this->connection->getActive() == true) { $sPasswordHash = hash('sha256', $sDefaultAdminPassword); try { if (User::model()->count() > 0) { die; } // Save user $user = new User(); // Fix UserID to 1 for MySQL even if installed in master-master configuration scenario if (in_array($this->connection->getDriverName(), array('mysql', 'mysqli'))) { $user->uid = 1; } $user->users_name = $sDefaultAdminUserName; $user->password = $sPasswordHash; $user->full_name = $sDefaultAdminRealName; $user->parent_id = 0; $user->lang = $sDefaultSiteLanguage; $user->email = $sDefaultAdminEmail; $user->save(); // Save permissions $permission = new Permission(); $permission->entity_id = 0; $permission->entity = 'global'; $permission->uid = $user->uid; $permission->permission = 'superadmin'; $permission->read_p = 1; $permission->save(); // Save global settings $this->connection->createCommand()->insert("{{settings_global}}", array('stg_name' => 'SessionName', 'stg_value' => self::_getRandomString())); $this->connection->createCommand()->insert("{{settings_global}}", array('stg_name' => 'sitename', 'stg_value' => $sDefaultSiteName)); $this->connection->createCommand()->insert("{{settings_global}}", array('stg_name' => 'siteadminname', 'stg_value' => $sDefaultAdminRealName)); $this->connection->createCommand()->insert("{{settings_global}}", array('stg_name' => 'siteadminemail', 'stg_value' => $sDefaultAdminEmail)); $this->connection->createCommand()->insert("{{settings_global}}", array('stg_name' => 'siteadminbounce', 'stg_value' => $sDefaultAdminEmail)); $this->connection->createCommand()->insert("{{settings_global}}", array('stg_name' => 'defaultlang', 'stg_value' => $sDefaultSiteLanguage)); // only continue if we're error free otherwise setup is broken. } catch (Exception $e) { throw new Exception(sprintf('Could not add optional settings: %s.', $e)); } Yii::app()->session['deletedirectories'] = true; $aData['title'] = $clang->gT("Success!"); $aData['descp'] = $clang->gT("LimeSurvey has been installed successfully."); $aData['classesForStep'] = array('off', 'off', 'off', 'off', 'off', 'off'); $aData['progressValue'] = 100; $aData['user'] = $sDefaultAdminUserName; $aData['pwd'] = $sDefaultAdminPassword; $this->render('/installer/success_view', $aData); return; } } else { // if passwords don't match, redirect to proper link. Yii::app()->session['optconfig_message'] = sprintf('<b>%s</b>', $clang->gT("Passwords don't match.")); $this->redirect(array('installer/optional')); } } elseif (empty(Yii::app()->session['configFileWritten'])) { $this->_writeConfigFile(); } $this->render('/installer/optconfig_view', $aData); }