strQCodoConfigFile = __QCODO_ROOT__ . '/includes/configuration.inc.php'; $this->strQuintaConfigFile = __QUINTA_CORE__ . '/quinta_config.php'; $this->txtDatabaseAdapter = new QTextBox($this); $this->txtDatabaseAdapter->Text = 'MySqli5'; $this->txtDatabaseAdapter->Name = Quinta::Translate('Database Adapter (Required)') . ':'; $this->txtDatabaseServer = new QTextBox($this); $this->txtDatabaseServer->Text = 'localhost'; $this->txtDatabaseServer->Name = Quinta::Translate('Database Server (Required)') . ':'; $this->txtDatabaseName = new QTextBox($this); $this->txtDatabaseName->Text = 'quintacmstest'; $this->txtDatabaseName->Name = Quinta::Translate('Database (Required)') . ':'; $this->txtDatabaseUser = new QTextBox($this); $this->txtDatabaseUser->Text = 'quintadbutest'; $this->txtDatabaseUser->Name = Quinta::Translate('Database User Name (Required)') . ':'; $this->txtDatabasePassword = new QTextBox($this); $this->txtDatabasePassword->Text = 'quintadbptest'; $this->txtDatabasePassword->Name = Quinta::Translate('Database Password (Required)') . ':'; $this->txtDatabaseAdminPassword = new QTextBox($this); $this->txtDatabaseAdminPassword->Text = ''; $this->txtDatabaseAdminPassword->Name = Quinta::Translate('Database Admin Password') . ':'; $this->txtDatabaseAdminUser = new QTextBox($this); $this->txtDatabaseAdminUser->Text = 'root'; $this->txtDatabaseAdminUser->Name = Quinta::Translate('Database Admin Username') . ':'; $this->lblMessage = new QLabel($this); $this->lblMessage->Text = ''; $this->lblMessage->HtmlEntities = false; $this->chkInstallExampleData = new QCheckBox($this); $this->chkInstallExampleData->Name = Quinta::Translate('Install Example Data? (Recommended for new users.) ') . ':'; $this->chkInstallExampleData->Checked = true; $this->chkInstallExampleData->Width = '1em'; $this->chkCreateDatabase = new QCheckBox($this); $this->chkCreateDatabase->Name = Quinta::Translate('Create Database ? (Requires Admin username and password) ') . ':'; $this->chkCreateDatabase->Width = '1em'; $this->btnSaveConfig = new QButton($this); $this->btnSaveConfig->Text = 'Continue'; $this->btnSaveConfig->AddAction(new QClickEvent(), new QServerAction('btnSaveConfig_Click')); } protected function btnSaveConfig_Click($strFormId, $strControlId, $strParameter) { if ($this->blnFinished) Quinta::Redirect(__QUINTA_SUBDIRECTORY__ . '/index.php/Home'); $strOutFile = $this->strQCodoConfigFile; if ($this->chkCreateDatabase->Checked) if (!$this->createDatabase()) die($this->strErrors); if (!$this->installDatabase()) die($this->strErrors); $this->writeConfigFile($strOutFile); $this->lblMessage->Text = '

Configuration saved!

' . 'Security Warning: You must change the permissions on ' . $strOutFile . ' Immediately!!

' . '

On Linux/Unix use this command:

 chmod go-w '
			. $strOutFile . '

' . 'Security Warning: You must also remove the install.php links ' . ' Immediately!!

' . '

On Linux/Unix use this command:

 rm '
			. __QUINTA_WWWROOT__ . '/install* 

'; $this->blnFinished = true; } protected function installDatabase() { if ($this->chkInstallExampleData->Checked) $strSqlFile = __QUINTA_DBDIR__ . '/quinta-with-data.sql'; else $strSqlFile = __QUINTA_DBDIR__ . '/quinta.sql'; $strCommand = 'mysql -u ' . $this->txtDatabaseUser->Text . ' -h ' . $this->txtDatabaseServer->Text; if($this->txtDatabasePassword->Text ) $strCommand .= ' -p' . $this->txtDatabasePassword->Text; $strCommand .= ' ' . $this->txtDatabaseName->Text . ' < ' . $strSqlFile; $aryErrors = array(); $intRetval = 0; $blnFork = exec($strCommand, $aryErrors, $intRetval); //! TODO: catch errors - even if mysql fails exec is not catching the errors .. dunno why. if (false === $blnFork || 0 != $intRetval) { $this->strErrors .= 'Failed to install data - command: ' . $strCommand; foreach ($aryErrors as $strError) $this->strErrors .= $strError; return false; } return true; } protected function createDatabase() { $strCommand = 'mysql -u ' . $this->txtDatabaseAdminUser->Text . ' -h ' . $this->txtDatabaseServer->Text; if($this->txtDatabaseAdminPassword->Text ) $strCommand .= ' -p' . $this->txtDatabaseAdminPassword->Text; $strCommand .= " -e ' CREATE DATABASE " . $this->txtDatabaseName->Text . ';' . ' GRANT ALL PRIVILEGES ON ' . $this->txtDatabaseName->Text . '.* TO ' //!TODO - make smarter, this will work only on a local database .. . $this->txtDatabaseUser->Text . '@localhost IDENTIFIED BY "' . $this->txtDatabasePassword->Text . '" ;\' '; $aryErrors = array(); $intRetval = 0; $blnFork = exec($strCommand, $aryErrors, $intRetval); if (false === $blnFork || 0 != $intRetval) { $this->strErrors .= 'Failed to create database - command: ' . $strCommand; foreach ($aryErrors as $strError) $this->strErrors .= $strError; return false; } return true; } protected function writeConfigFile($strOutFile) { $strInFile = $this->strQCodoConfigFile . '-quinta-dist'; $aryValues = array( "/'adapter' => '.*'/" => "'adapter' => '" . $this->txtDatabaseAdapter->Text . "'", "/'server' => '.*'/" => "'server' => '" . $this->txtDatabaseServer->Text . "'", "/'database' => '.*'/" => "'database' => '" . $this->txtDatabaseName->Text . "'", "/'username' => '.*'/" => "'username' => '" . $this->txtDatabaseUser->Text . "'", "/'password' => '.*'/" => "'password' => '" . $this->txtDatabasePassword->Text . "'", ); $aryFile = file($strInFile); foreach ($aryValues as $strName => $strValue) $aryFile = preg_replace($strName, $strValue, $aryFile); $fp = fopen($strOutFile, 'w'); foreach ($aryFile as $strLine) fwrite($fp, $strLine); fclose($fp); } } InstallationForm::Run('InstallationForm'); ?>