* * @package SendStudio * @subpackage SendStudio_Functions */ /** * Include the base sendstudio functions. */ require(dirname(__FILE__) . '/sendstudio_functions.php'); $GLOBALS['ROOTDIR'] = $ROOTDIR; $GLOBALS['TABLEPREFIX'] = $TABLEPREFIX; $GLOBALS['ROOTURL'] = $ROOTURL; $GLOBALS['DBHOST'] = $DBHOST; $GLOBALS['DBUSER'] = $DBUSER; $GLOBALS['DBPASS'] = $DBPASS; $GLOBALS['DBNAME'] = $DBNAME; $GLOBALS['LicenseKey'] = $LicenseKey; $GLOBALS['ServerSending'] = $ServerSending; /** * Class for the upgrade process. This will run through all the queries needed to upgrade sendstudio 2004 to sendstudio nx, and change the config file. * * @package SendStudio * @subpackage SendStudio_Functions */ class Upgrade extends SendStudio_Functions { /** * Default characterset * @var String */ var $default_charset = 'ISO-8859-1'; /** * 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. */ function Process() { if (isset($_GET['Action'])) { $action = strtolower($_GET['Action']); switch ($action) { case 'createbackup': $this->CreateBackup(); return; break; case 'popupiframe': header('Content-type: text/html; charset="' . SENDSTUDIO_CHARSET . '"'); $variables = array(); switch ($_GET['SubAction']) { case 'Backup': $tempList = $this->FetchTables(); $variables['ProgressTitle'] = 'Backup In Progress ...'; $variables['ProgressMessage'] = sprintf('Please wait while we attempt to backup %s tables...', count($tempList)); $variables['ProgressReport'] = ''; $variables['ProgressStatus'] = ''; $variables['ProgressURLAction'] = 'index.php?Page=Upgrade&Action=CreateBackup'; break; case 'CopyFiles': $tempList = list_directories($GLOBALS['ROOTDIR'] . 'temp/images', null, true); $variables['ProgressTitle'] = 'Copying files to new location ...'; $variables['ProgressMessage'] = sprintf('Please wait while we copy %s files to a new location...', count($tempList)); $variables['ProgressReport'] = ''; $variables['ProgressStatus'] = ''; $variables['ProgressURLAction'] = 'index.php?Page=Upgrade&Action=CopyFiles'; break; case 'UpgradeDatabase': $variables['ProgressTitle'] = 'Upgrading database ...'; $variables['ProgressMessage'] = 'Please wait while we upgrade tables in your database...'; $variables['ProgressReport'] = ''; $variables['ProgressStatus'] = ''; $variables['ProgressURLAction'] = 'index.php?Page=Upgrade&Action=UpgradeDatabase'; break; } print ''. '
'; $template = file_get_contents(SENDSTUDIO_TEMPLATE_DIRECTORY . '/progressreport_popup.tpl'); foreach ($variables as $key=>$value) { $template = str_replace('%%GLOBAL_'.$key.'%%', $value, $template); } print $template; print '
'; return; break; case 'upgradedatabase': $this->UpgradeDatabase(); return; break; case 'copyfiles': $this->CopyFiles(); return; break; } } $this->PrintHeader(); ?> $handle_step(); $this->PrintFooter(); } /** * ShowStep_0 * This shows the first "thanks for purchasing" page. * Doesn't do anything else. * * @return Void Doesn't return anything. */ function ShowStep_0() { ?>
Welcome to the Sendstudio Upgrade Wizard
 
Thank you for upgrading Sendstudio!
Welcome to the Sendstudio upgrade wizard. Over the next 4 steps your current copy of SendStudio (including your database) will be upgraded.
Click the "Proceed" button below to get started and create a backup of your database.
$var) { IEM::sessionRemove($var); } } /** * CheckPermissions * Checks permissions on the appropriate folders. * If permissions aren't correct, a message is displayed and you can't continue until they are fixed. * Also checks to make sure either 'mysql' or 'postgresql' functions are available * That is, some sort of database functionality is there. * * @return Void If everything is ok, this will return out of the function. If something is wrong, it prints an error message and the script dies. */ function CheckPermissions() { $isOK = true; $permError = ''; $serverError = ''; $permArray = array( '/includes/config.php', '/temp' ); $linux_message = 'Please CHMOD it to 757.'; $windows_message = 'Please set anonymous write permissions in IIS. If you don\'t have access to do this, you will need to contact your hosting provider.'; $error_message = $linux_message; if (strtolower(substr(PHP_OS, 0, 3)) == 'win') { $error_message = $windows_message; } foreach ($permArray as $a) { if (!$this->CheckWritable(SENDSTUDIO_BASE_DIRECTORY . $a)) { $permError .= sprintf("
  • The file or folder %s isn't writable. " . $error_message . "
  • ", SENDSTUDIO_BASE_DIRECTORY . str_replace('/', DIRECTORY_SEPARATOR, $a)); $isOK = false; } } if (SENDSTUDIO_SAFE_MODE) { if (!$this->CheckWritable(TEMP_DIRECTORY . '/send')) { $permError .= sprintf("
  • The file or folder %s isn't writable. " . $error_message . "
  • ", TEMP_DIRECTORY . DIRECTORY_SEPARATOR . 'send'); $isOK = false; } if (!$this->CheckWritable(TEMP_DIRECTORY . '/autoresponder')) { $permError .= sprintf("
  • The file or folder %s isn't writable. " . $error_message . "
  • ", TEMP_DIRECTORY . DIRECTORY_SEPARATOR . 'autoresponder'); $isOK = false; } } if (!function_exists('mysql_connect') && !function_exists('pg_connect')) { $serverError .= '
  • Your server does not support mysql or postgresql databases. PHP on your web server needs to be compiled with MySQL or PostgreSQL support.

    For more information:
    http://www.php.net/mysql
    http://www.php.net/pgsql

    Please contact your web hosting provider or administrator for more details.
  • '; $isOK = false; } // since the upgrade from v2004 to nx can only be mysql, we don't need to check the database type. $query = "SELECT VERSION() AS version"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $version = $row['version']; $compare = version_compare($version, '4.0'); if ($compare < 0) { $serverError .= '
  • SendStudio NX requires MySQL v4.0 or above to work properly. Your server is running ' . $version . '. To complete the upgrade, your host will need to upgrade MySQL. Please contact your host to arrange this.
  • '; $isOK = false; } if ($isOK) { return; } ?>
    Oops... Something Went Wrong

    '; echo '
      '; echo $permError; echo '
    '; if ($serverError) { echo '
    '; } } if ($serverError) { echo 'The following problems have been found with your server:
    '; echo '
      '; echo $serverError; echo '
    '; } ?>
    PrintFooter(); exit; } /** * CheckFiles * Checks the number of files in the admin/com/upgrades/{upgrade_version}/ folder. * * @return Void If everything is ok, this will return out of the function. If something is wrong, it prints an error message and the script dies. */ function CheckFiles() { $upgrade_api = new Upgrade_API(); $upgrades_to_run = $upgrade_api->Get('upgrades_to_run'); $nx_upgrades = $upgrades_to_run['nx']; $nx_upgrades_found = sizeof($nx_upgrades); $upgrades_found = list_files(IEM_PATH . '/upgrades/nx'); if (sizeof($upgrades_found) == $nx_upgrades_found) { return; } $upgrades_found = str_replace('.php', '', $upgrades_found); $missing_files = array_diff($nx_upgrades, $upgrades_found); ?>
    Oops... Something Went Wrong

    The following file(s) are missing from the admin/com/upgrades/nx/ folder:
      $filename) { echo '
    • ' . $filename . '.php
    • '; } ?>
    Once you have uploaded the file(s) mentioned, try again.

    PrintFooter(); exit; } /** * ShowStep_1 * Step 1 checks the license key is valid and permissions on the appropriate files/folders. * * @param String $license_error If there is a license key error it is passed in here so we can display an error message. If this is empty, we are at step 1 for the first time so an error message isn't shown. * * @see CheckPermissions * @see ShowStep_2 * * @return Void Doesn't return anything. Checks permissions, shows the license key box and (if applicable) shows an error message if the license key is invalid. */ function ShowStep_1() { $already_upgraded = $this->AlreadyUpgraded(); if ($already_upgraded) { return; } $permissions = $this->CheckPermissions(); $check_files = $this->CheckFiles(); ?>
    Step 1: Creating a database backup


      Database Backup
      Before upgrading, your existing SendStudio database will be backed up. If at any time during the upgrade something goes wrong,
    we can use this backup to restore your database. Click the "Create Backup" button below to continue.

    Step 1: Backup Errors

    There were problems creating a backup of your database.

    Step 2: Copying Images and Attachments


      Copying Images and Attachments
      You database has been backed up. Right click this link and choose "Save As" to save the backup to your hard drive.
    The upgrade wizard will now copy your images and attachments to their new locations. Click "Copy Files" to continue.

    Step 2: Copy Errors

    There were problems copying images and attachments to their new locations.

    Step 3: Database Upgrade


      Upgrade database
      Your database has been backed up successfully.
    There were problems copying images and attachments to their new locations. This is because safe-mode is enabled on your server. This step has been bypassed, please contact help@interspire.com once your upgrade has finished.
    '; } else { echo 'Your images and attachments have also been copied over successfully.'; } ?>
    Click the "Upgrade Database" button below to upgrade your SendStudio database.

    Step 3: Upgrade Errors

    There were problems upgrading your database. Please contact help@interspire.com and tell them the following errors occurred:


    $backupfile) { if (strpos($backupfile, 'system_backup.'.date('m-d-Y').'.txt') !== false) { unlink(TEMP_DIRECTORY . '/' . $backupfile); } } } require(SENDSTUDIO_API_DIRECTORY . '/settings.php'); $settings_api = new Settings_API(false); $settings = array(); // hardcode this in, for this upgrade it's always going to be mysql. $settings['DATABASE_TYPE'] = 'mysql'; $settings['DATABASE_USER'] = $GLOBALS['DBUSER']; $settings['DATABASE_PASS'] = $GLOBALS['DBPASS']; $settings['DATABASE_HOST'] = $GLOBALS['DBHOST']; $settings['DATABASE_NAME'] = $GLOBALS['DBNAME']; $settings['TABLEPREFIX'] = $GLOBALS['TABLEPREFIX']; $settings['LICENSEKEY'] = $GLOBALS['LicenseKey']; $settings['APPLICATION_URL'] = substr($GLOBALS['ROOTURL'], 0, -1); $settings['CRON_ENABLED'] = $GLOBALS['ServerSending']; $timezone = date('O'); if ($timezone == '+0000') { $timezone = 'GMT'; } else { $minutes = substr($timezone, -2); $timezone = 'GMT' . substr_replace($timezone, ':' . $minutes, -2); } $settings['SERVERTIMEZONE'] = str_replace(array('GMT-0', 'GMT+0'), array('GMT-', 'GMT+'), $timezone); $settings['DEFAULTCHARSET'] = $this->default_charset; $empty_settings = array('SMTP_SERVER', 'SMTP_USERNAME', 'SMTP_PASSWORD', 'HTMLFOOTER', 'TEXTFOOTER', 'EMAIL_ADDRESS', 'BOUNCE_ADDRESS', 'BOUNCE_SERVER', 'BOUNCE_USERNAME', 'BOUNCE_PASSWORD', 'BOUNCE_EXTRASETTINGS'); foreach ($empty_settings as $k => $set) { $settings[$set] = ''; } $zero_settings = array('SMTP_PORT', 'FORCE_UNSUBLINK', 'MAXHOURLYRATE', 'MAXOVERSIZE', 'IPTRACKING', 'BOUNCE_IMAP'); foreach ($zero_settings as $k => $set) { $settings[$set] = '0'; } $settings['MAX_IMAGEWIDTH'] = 700; $settings['MAX_IMAGEHEIGHT'] = 400; $settings_api->Set('Settings', $settings); define('SENDSTUDIO_DATABASE_TYPE', 'mysql'); define('SENDSTUDIO_DATABASE_HOST', $GLOBALS['DBHOST']); define('SENDSTUDIO_DATABASE_USER', $GLOBALS['DBUSER']); define('SENDSTUDIO_DATABASE_PASS', $GLOBALS['DBPASS']); define('SENDSTUDIO_DATABASE_NAME', $GLOBALS['DBNAME']); define('SENDSTUDIO_TABLEPREFIX', $GLOBALS['TABLEPREFIX']); if (!defined('SENDSTUDIO_DEFAULTCHARSET')) { define('SENDSTUDIO_DEFAULTCHARSET', $this->default_charset); } if (!class_exists('MySQLDb', false)) { require(IEM_PATH . '/ext/database/mysql.php'); } $db_type = 'MySQLDb'; $db = new $db_type(); $connection = $db->Connect(SENDSTUDIO_DATABASE_HOST, SENDSTUDIO_DATABASE_USER, SENDSTUDIO_DATABASE_PASS, SENDSTUDIO_DATABASE_NAME); $settings_api->Db = &$db; $settings_api->Save(); ?>
    Step 4: Upgrade Complete


      Important Notes. Please Read.
     
    The upgrade wizard has been completed successfully. You can log in here - your login details have not changed.
    It's very important that you read the notes below, so please do that now:

    • The default character set is set to 'ISO-8859-1'. If you need to change this, you will need to edit your admin/includes/config.php file to change it to 'UTF-8'.
    • Sendstudio now supports timezones. Please check the settings page and confirm the server timezone. Please also check the timezone for each user and adjust it accordingly, they have all been set to GMT.
    • Information (such as the date a person unsubscribed) was not stored, so the upgrade had to "guess" when this happened and set all of that information to today's date.
    • Existing autoresponder statistics are not accurate. Information about who was sent which type of autoresponder was previously not recorded. That is, whether a subscriber was sent the html version or the text version.
    • Users & settings have a lot of new options.
    • Custom fields have been associated with all of a users mailing list. Please check these associations.
    • All forms have been set to 'Classic White (Default)', please adjust as necessary.
    • You may need to clear your browsers cache to see the new images and buttons.
    $row['AttachmentFilename'], 'realname' => $row['AttachmentName']); } if (!empty($all_attachments)) { $query = "select ComposedID, AttachmentIDs from " . $GLOBALS['TABLEPREFIX'] . "composed_emails where attachmentids != ''"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { $new_folder = TEMP_DIRECTORY . '/newsletters/' . $row['ComposedID']; CreateDirectory($new_folder); $attachments = explode(':', stripslashes($row['AttachmentIDs'])); foreach ($attachments as $k => $attachid) { $fname = basename($all_attachments[$attachid]['filename']); $file = $GLOBALS['ROOTDIR'] . 'temp/attachments/' . $fname; $realname = $all_attachments[$attachid]['realname']; copy($file, $new_folder . '/' . $realname); if (!SENDSTUDIO_SAFE_MODE) { @chmod($new_folder . '/' . $realname, 0644); } } } $query = "select AutoresponderID, AttachmentIDs from " . $GLOBALS['TABLEPREFIX'] . "autoresponders where attachmentids != ''"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { $new_folder = TEMP_DIRECTORY . '/autoresponders/' . $row['ComposedID']; CreateDirectory($new_folder); $attachments = explode(':', stripslashes($row['AttachmentIDs'])); foreach ($attachments as $k => $attachid) { $fname = basename($all_attachments[$attachid]['filename']); $file = $GLOBALS['ROOTDIR'] . 'temp/attachments/' . $fname; $realname = $all_attachments[$attachid]['realname']; copy($file, $new_folder . '/' . $realname); if (!SENDSTUDIO_SAFE_MODE) { @chmod($new_folder . '/' . $realname, 0644); } } } } ?> $dir) { if (in_array($dir, $dirs_copied)) { continue; } $percentProcessed = ceil(($listProcessed / $listTotal)*100); echo "\n"; flush(); echo 'Copying directory ' . str_replace($GLOBALS['ROOTDIR'], '', $dir) . ' to new location...
    '; $new_dir = str_replace($GLOBALS['ROOTDIR'] . 'temp/images', TEMP_DIRECTORY . '/user', $dir); $copied = CopyDirectory($dir, $new_dir); if (!$copied) { $dirs_not_copied[] = $dir; IEM::sessionSet('DirectoriesNotCopied', $dirs_not_copied); } $dirs_copied[] = $dir; IEM::sessionSet('DirectoriesCopied', $dirs_copied); $listProcessed++; } ?> default_charset); } if (!class_exists(SENDSTUDIO_DATABASE_TYPE . 'Db', false)) { require(IEM_PATH . '/ext/database/' . SENDSTUDIO_DATABASE_TYPE . '.php'); } $db = new MySQLDb(); $connection = $db->Connect(SENDSTUDIO_DATABASE_HOST, SENDSTUDIO_DATABASE_USER, SENDSTUDIO_DATABASE_PASS, SENDSTUDIO_DATABASE_NAME); $GLOBALS['SendStudio']['Database'] = &$db; require(SENDSTUDIO_API_DIRECTORY . '/upgrade.php'); $upgrade_api = new Upgrade_API(); $upgrades_done = IEM::sessionGet('DatabaseUpgradesCompleted'); if (!$upgrades_done) { $upgrades_done = array(); IEM::sessionSet('DatabaseUpgradesCompleted', $upgrades_done); $upgrades_failed = array(); IEM::sessionSet('DatabaseUpgradesFailed', $upgrades_failed); $upgrades_to_run = $upgrade_api->GetUpgradesToRun('2004', SENDSTUDIO_DATABASE_VERSION); IEM::sessionSet('UpgradesToRun', $upgrades_to_run['upgrades']); IEM::sessionSet('UpgradeCount', $upgrades_to_run['number_to_run']); } $upgrades_failed = IEM::sessionGet('DatabaseUpgradesFailed'); $server_timeoffset = date('O'); $offset_direction = $server_timeoffset{0}; $offset_hours = $server_timeoffset{1} . $server_timeoffset{2}; $offset_minutes = $server_timeoffset{3} . $server_timeoffset{4}; $offset_query = "-(" . $offset_direction . (60 * 60) * (($offset_hours . $offset_minutes) / 100) . ")"; $upgrade_api->Set('offset_query', $offset_query); $running_upgrade = $upgrade_api->GetNextUpgrade(); if (!is_null($running_upgrade)) { // ----- Upgrade message $upgradeMessage = ''; $statusList = IEM::sessionGet('DatabaseUpgradeStatusList'); if (isset($statusList[$running_upgrade])) { $statusQuery = $statusList[$running_upgrade]; $upgradeMessage = " ({$statusQuery['Processed']}/{$statusQuery['Total']})"; } // ----- $totalUpgradeCount = IEM::sessionGet('UpgradeCount'); // Total queries processed $totalProcessed = count($upgrades_done); // Print message before update $percentProcessed = ceil(($totalProcessed / $totalUpgradeCount)*100); echo "\n"; flush(); $upgrade_result = $upgrade_api->RunUpgrade($running_upgrade); $percentProcessed = ceil(($totalProcessed / $totalUpgradeCount)*100); echo "\n"; flush(); if ($upgrade_result === true || $upgrade_result === false) { $upgrades_done[] = $running_upgrade; IEM::sessionSet('DatabaseUpgradesCompleted', $upgrades_done); } if (!$upgrade_result) { $upgrades_failed[] = $upgrade_api->Get('error'); IEM::sessionSet('DatabaseUpgradesFailed', $upgrades_failed); } ?> FetchTables(); IEM::sessionSet('DatabaseTables_Todo', $tables_todo); $tables_done = array(); IEM::sessionSet('DatabaseTables_Done', $tables_done); $backup_errors = array(); IEM::sessionSet('DatabaseTables_BackupErrors', $backup_errors); } $tables_todo = IEM::sessionGet('DatabaseTables_Todo'); $tables_done = IEM::sessionGet('DatabaseTables_Done'); $backup_errors = IEM::sessionGet('DatabaseTables_BackupErrors'); if ($tables_done == $tables_todo) { ?> $table) { if (in_array($table, $tables_done)) { continue; } $percentProcessed = ceil(($tableProcessed / $tableTotal)*100); echo "\n"; flush(); echo "Backing up table '" . $table . "'..
    \n"; $this->PrintFooter(true); $result = $this->BackupTable($table, $backupfile); if (!$result) { $backup_errors[] = $table; } $tables_done[] = $table; $tableProcessed++; break; } IEM::sessionSet('DatabaseTables_Done', $tables_done); IEM::sessionSet('DatabaseTables_BackupErrors', $backup_errors); ?> NX can only be a mysql upgrade, we'll just use native functions. */ function BackupTable($tablename='', $filename='') { if ($tablename == '' || $filename == '') { return false; } if (!$fp = fopen($filename, 'a+')) { return false; } $drop_table = "DROP TABLE IF EXISTS " . $tablename . ";\n"; fputs($fp, $drop_table); $qry = "SHOW CREATE TABLE " . $tablename; $result = mysql_query($qry); $create_table = mysql_result($result, 0, 1) . ";\n"; fputs($fp, $create_table); $qry = "SELECT * FROM " . $tablename; $result = mysql_query($qry); while ($row = mysql_fetch_assoc($result)) { $insert_query_fields = $insert_query_values = array(); foreach ($row as $name => $val) { $insert_query_fields[] = $name; $insert_query_values[] = str_replace("'", "\'", stripslashes($val)); } $insert_query = "INSERT INTO " . $tablename . "(" . implode(',', $insert_query_fields) . ") VALUES ('" . implode("','", $insert_query_values) . "');\n"; fputs($fp, $insert_query); } $empty_lines = "\n"; fputs($fp, $empty_lines); fclose($fp); return true; } /** * FetchTables * Since 2004 -> NX can only be a mysql upgrade, we'll just use native functions. */ function FetchTables() { $qry = "SHOW TABLES LIKE '" . addslashes($GLOBALS['TABLEPREFIX']) . "%'"; $result = mysql_query($qry); $return = array(); while ($row = mysql_fetch_assoc($result)) { $return[] = array_pop($row); } return $return; } /** * CheckWritable * @param String $file File to be checked * @return Boolean Returns TRUE if file is writable, FALSE otherwise */ function CheckWritable($file='') { if (!$file) { return false; } $unlink = false; if (!is_file($file)) { $unlink = true; if (is_dir($file)) { $file = $file . '/' . date('U') . '.php'; } else { return false; } } if (!$fp = @fopen($file, 'w+')) { return false; } $contents = 'Db->Query($query, true); // the table already exists?! That's bad. if ($result) { $count = $upgrade_api->Db->FetchOne($result, 'subcount'); if ($count > 0) { ?>
    Step 1: Problem Upgrading

    SendStudio NX seems to be installed in this database already. If you are upgradi