*
* @package SendStudio
* @subpackage SendStudio_Functions
*/
/**
* Make sure that the installer CANNOT be loaded again if the application has already been installed
*/
$tempFile = dirname(__FILE__) . '/../includes/config.php';
if (is_file($tempFile)) {
require_once $tempFile;
if (defined('SENDSTUDIO_IS_SETUP') && SENDSTUDIO_IS_SETUP == 1) {
header('Location: ' . SENDSTUDIO_APPLICATION_URL);
die('Redirecting .... to ' . SENDSTUDIO_APPLICATION_URL . '');
}
}
unset($tempFile);
/**
* -----
*/
/**
* Include the base sendstudio functions.
*/
require_once(dirname(__FILE__) . '/sendstudio_functions.php');
/**
* Include the whitelabel file.
*/
require_once(IEM_PATH . '/language/default/whitelabel.php');
/**
* Class for the welcome page. Includes quickstats and so on.
*
* @package SendStudio
* @subpackage SendStudio_Functions
*/
class Installer extends SendStudio_Functions
{
/**
* Installer API
*/
private $_api;
/**
* Constructor
* Doesn't do anything.
*
* @return Void Doesn't return anything.
*/
public function __construct()
{
$this->_api = new IEM_Installer();
}
/**
* Process
* Works out which step we are up to in the install process and passes it off for the other methods to handle.
*
* @return Void Works out which step you are up to and that's it.
*/
public function Process()
{
$errors = $db_errors = $permission_errors = array();
// Check permissions
list($error, $msgs) = $this->_api->CheckPermissions();
if ($error) {
$permission_errors = $msgs;
}
$step = 0;
if (isset($_GET['Step'])) {
$step = (int)$_GET['Step'];
}
switch ($step) {
case '1':
$lk_check = array();
$required_fields = array(
'applicationurl' => 'application url',
'contactemail' => 'application email address',
'admin_password' => 'administrator password',
'admin_password_confirm' => 'confirmation password'
);
if (isset($_POST['licensekey'])) {
$lk_check['licensekey'] = 'license key';
} else {
$lk_check['contactname'] = 'your name';
$lk_check['contactphone'] = 'your phone number';
$lk_check['country'] = 'your country';
}
// put the lk_check details as the first thing - since the license key box is the first thing on the page.
$required_fields = array_merge($lk_check, $required_fields);
foreach ($required_fields as $field => $desc) {
$show_n = false;
if (in_array(substr(strtolower($desc), 0, 1), array('a','e','i','o','u'))) {
$show_n = true;
}
switch ($field) {
case 'contactname':
case 'contactphone':
case 'country':
$error_message = 'Please enter ' . $desc;
break;
default:
$error_message = 'Please enter a' . (($show_n) ? 'n' : '') . ' ' . $desc;
break;
}
if (!isset($_POST[$field]) || $_POST[$field] == '') {
${$field} = '';
$errors[] = $error_message;
continue;
}
${$field} = $_POST[$field];
}
// Verify the admin password confirmation checks out
if (isset($_POST['admin_password']) && $_POST['admin_password'] != '') {
if (isset($_POST['admin_password_confirm']) && $_POST['admin_password_confirm'] != '') {
if ($_POST['admin_password'] != $_POST['admin_password_confirm']) {
$errors[] = 'Your passwords do not match. Please enter your password again and confirm it to make sure they are the same';
}
}
}
// Collect database settings
if (!isset($_POST['dbtype'])) {
$errors[] = 'Please choose the type of database you want to use';
} else {
$found_missing_db_field = false;
$required_db_fields = array ('dbusername' => 'database username', 'dbhostname' => 'database hostname', 'dbname' => 'database name');
foreach ($required_db_fields as $field => $desc) {
if ($_POST['dbtype'] == 'mysql') {
$field = 'mysql_' . $field;
$db_type_message = 'MySQL';
} elseif ($_POST['dbtype'] == 'pgsql') {
$field = 'pgsql_' . $field;
$db_type_message = 'PostgreSQL';
} else {
$errors[] = 'Please choose a valid database type. We currently only support MySQL or PostgreSQL';
break;
}
$show_n = false;
if (in_array(substr(strtolower($desc), 0, 1), array('a','e','i','o','u'))) {
$show_n = true;
}
$error_message = 'Please enter a' . (($show_n) ? 'n' : '') . ' ' . $db_type_message . ' ' . $desc;
if (!isset($_POST[$field]) || $_POST[$field] == '') {
$errors[] = $error_message;
$found_missing_db_field = true;
continue;
}
}
// Return to form with error messages if there were errors.
// We do this here so that it won't load the DB schema unless everything else has checked out so far.
if (count(array_merge($permission_errors, $errors, $db_errors))) {
$this->ShowForm($permission_errors, $errors, $db_errors);
break;
}
// Collect the required settings
$settings = array();
$from_form = array (
'DATABASE_TYPE' => 'dbtype',
'LICENSEKEY' => 'licensekey',
'APPLICATION_URL' => 'applicationurl',
'EMAIL_ADDRESS' => 'contactemail',
);
foreach ($from_form as $option => $post_field) {
$settings[$option] = $_POST[$post_field];
}
$db_fields_from_form = array (
'DATABASE_USER' => 'dbusername',
'DATABASE_PASS' => 'dbpassword',
'DATABASE_HOST' => 'dbhostname',
'DATABASE_NAME' => 'dbname',
'TABLEPREFIX' => 'tableprefix',
);
foreach ($db_fields_from_form as $option => $post_field) {
if ($settings['DATABASE_TYPE'] == 'mysql') {
$post_field = 'mysql_' . $post_field;
} else {
$post_field = 'pgsql_' . $post_field;
}
$settings[$option] = $_POST[$post_field];
}
// Load the required settings into the API
$this->_api->LoadRequiredSettings($settings);
if (!$found_missing_db_field) {
// Set up the database
list($errcode, $msg) = $this->_api->SetupDatabase();
switch ($errcode) {
case IEM_Installer::SUCCESS:
// nothing to do
break;
case IEM_Installer::DB_CONN_FAILED:
$errors[] = 'Interspire Email Marketer was unable to connect to the database. Please check the settings and try again. The error message is: ' . $msg;
break;
case IEM_Installer::DB_BAD_VERSION:
$errors[] = 'Interspire Email Marketer requires ' . $msg['product'] . ' ' . $msg['req_version'] . ' or above to work properly. Your server is running ' . $msg['version'] . '. To complete the installation, your web host must upgrade ' . $msg['product'] . ' to this version. Please note that this is not a software problem and it is something only your web host can change.';
break;
case IEM_Installer::DB_UNSUPPORTED:
$errors[] = 'This database type is not supported.';
break;
case IEM_Installer::DB_ALREADY_INSTALLED:
$errors[] = 'Interspire Email Marketer seems to be already installed in this database. To continue with this installation, you will need to delete the data from this database or select a different database. You may need to contact your administrator or web hosting provider to do this.';
break;
case IEM_Installer::DB_OLD_INSTALL:
$errors[] = 'An older version of Interspire Email Marketer is already installed in this database. If you are attempting to upgrade your existing version of Interspire Email Marketer, you will need to ensure that your existing includes/config.inc.php file exists on the server. Interspire Email Marketer will detect if this config file exists and will automatically start up the upgrade wizard.
If you would like to install a fresh copy of Interspire Email Marketer, then either delete the data from this database (contact your administrator or web host if you need help) or select a new database.';
break;
case IEM_Installer::DB_INSUFFICIENT_PRIV:
$errors[] = 'The database user does not have sufficient privileges to install the database. Please ensure the database user has permission to CREATE, CREATE INDEX, INSERT, SELECT, UPDATE, DELETE, ALTER and DROP.';
break;
case IEM_Installer::DB_QUERY_ERROR:
foreach ($msg as $errmsg) {
$db_errors[] = 'Unable to run the following query: ' . $errmsg;
}
break;
default:
$errors[] = 'There was an error setting up the database. The error was: ' . $msg;
break;
}
}
}
// Save the default settings into the database
if (empty($errors) && empty($db_errors)) {
list($error, $msg) = $this->_api->SaveDefaultSettings();
if ($error) {
$errors[] = 'There was a problem loading the default settings. The error was: ' . $msg;
}
}
// Register the Event Listeners
try {
IEM_Installer::RegisterEventListeners();
} catch (Exception $e) {
$errors[] = 'There was a problem registering the Event Listeners.';
}
// Return to form with error messages if there were errors
if (count(array_merge($permission_errors, $errors, $db_errors))) {
$this->ShowForm($permission_errors, $errors, $db_errors);
break;
}
// If we get to this point then the installation has been successful.
// Create the default custom fields
$this->_api->CreateCustomFields();
// Install the default add-ons
$this->_api->RegisterAddons();
$this->PrintHeader();
?>
Interspire Email Marketer has been installed successfully. Your control panel username is admin and your password is .
';
$error_message .= 'Before you can install Interspire Email Marketer you need to set the appropriate permissions on the files/folders listed below: ';
$error_message .= '