<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
 * SugarCRM is a customer relationship management program developed by
 * SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License version 3 as published by the
 * Free Software Foundation with the addition of the following permission added
 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, see http://www.gnu.org/licenses or write to the Free
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301 USA.
 * 
 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
 * 
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU General Public License version 3.
 * 
 * In accordance with Section 7(b) of the GNU General Public License version 3,
 * these Appropriate Legal Notices must retain the display of the "Powered by
 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
 * technical reasons, the Appropriate Legal Notices must display the words
 * "Powered by SugarCRM".
 ********************************************************************************/
/*********************************************************************************

 * Description:
 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. All Rights
 * Reserved. Contributor(s): ______________________________________..
 * *******************************************************************************/
logThis('[At end.php]');
global $unzip_dir;
global $path;
if($unzip_dir == null && isset($_SESSION['unzip_dir'])) {
	$unzip_dir = $_SESSION['unzip_dir'];
}
set_upgrade_progress('end','in_progress');
initialize_session_vars();
if(isset($_SESSION['current_db_version']) && isset($_SESSION['target_db_version'])){
	if($_SESSION['current_db_version'] != $_SESSION['target_db_version']){






		// flag drop schema script run method
		if(isset($_REQUEST['schema_drop']) && $_REQUEST['schema_drop'] =='sugar'){
			  //Drop old schema with upgrade
		    require_once("$unzip_dir/scripts/drop_451schema_after_upgrade5.php");
		    logThis('Start dropping the old schema', $path);
		    	ob_start();
				@drop_preUpgardeSchema();
				ob_end_clean();
		    logThis('End dropping the old schema', $path);
		}
		//$done="<input type='button' value='{$mod_strings['LBL_BUTTON_DONE']}' onclick='window.location.href='$cleanUrl?module=Home&action=About'>";
		//$logout="<a href='index.php?module=Users&action=Logout'>{$mod_strings['LBL_UW_END_LOGOUT2']}</a>";
	}
}
if(isset($_SESSION['current_db_version']) && isset($_SESSION['target_db_version'])){
	if($_SESSION['current_db_version'] == $_SESSION['target_db_version']){
	    $_REQUEST['upgradeWizard'] = true;
	    ob_start();
	    	include('modules/Administration/upgradeTeams.php');
			include('modules/ACL/install_actions.php');
			include('include/Smarty/internals/core.write_file.php');
		ob_end_clean();
	 	$db =& PearDatabase::getInstance();
		if(isset($_SESSION['upgrade_from_flavor']) && ($_SESSION['upgrade_from_flavor'] == 'SugarCE to SugarPro' || $_SESSION['upgrade_from_flavor'] == 'SugarCE to SugarEnt')){
			 $category = 'license';
			 $db->query("INSERT INTO config (value, category, name) VALUES ('0','$category', 'users')");
			 $db->query("INSERT INTO config (value, category, name) VALUES ('','$category', 'expire_date')");
			 $db->query("INSERT INTO config (value, category, name) VALUES ('','$category', 'key')");
			 $db->query("INSERT INTO config (value, category, name) VALUES ('','$category', 'num_lic_oc')");
		}
	}
}
//Update the license
logThis('Start Updating the license ', $path);
ob_start();
   require_once('modules/Administration/updater_utils.php');
   check_now(get_sugarbeat());
ob_end_clean();
logThis('End Updating the license ', $path);

logThis('Cleaning up the session.  Goodbye.');
unlinkTempFiles();
logThis('Cleaning up the session.  Goodbye.');
resetUwSession();
// flag to say upgrade has completed
$_SESSION['upgrade_complete'] = true;

$stop = false;


$httpHost		= $_SERVER['HTTP_HOST'];  // cn: 8472 - HTTP_HOST includes port in some cases
if($colon = strpos($httpHost, ':')) {
	$httpHost	= substr($httpHost, 0, $colon);
}
$parsedSiteUrl	= parse_url($sugar_config['site_url']);
$host			= ($parsedSiteUrl['host'] != $httpHost) ? $httpHost : $parsedSiteUrl['host'];

// aw: 9747 - use SERVER_PORT for users who don't plug in the site_url at install correctly
if ($_SERVER['SERVER_PORT'] != 80){
	$port = ":".$_SERVER['SERVER_PORT'];
}
else if (isset($parsedSiteUrl['port']) && $parsedSiteUrl['port'] != 80){
	$port = ":".$parsedSiteUrl['port'];
}
else{
	$port = '';
}
$path			= $parsedSiteUrl['path'];
$cleanUrl		= "{$parsedSiteUrl['scheme']}://{$host}{$port}{$path}/index.php";

$uwMain =<<<eoq
<table cellpadding="3" cellspacing="0" border="0">
	<tr>
		<th align="left">
			{$mod_strings['LBL_UW_TITLE_END']}
		</th>
	</tr>
	<tr>
		<td align="left">
			<p>
			{$mod_strings['LBL_UW_END_DESC']}
			</p>
			<p>
			{$mod_strings['LBL_UW_END_DESC2']}
			</p>
		</td>
	</tr>
	<tr>
		<td align="left">
			<p>
				<b class="error">{$mod_strings['LBL_UW_END_LOGOUT']}</b>
			</p>
			<p>
				<a href="index.php?module=Users&action=Logout">{$mod_strings['LBL_UW_END_LOGOUT2']}</a>
			</p>
		</td>
	</tr>

	<tr>
		<td align="left">
			<input type="button" value="{$mod_strings['LBL_BUTTON_DONE']}" onclick="window.location.href='$cleanUrl?module=Home&action=About'">
		</td>
	</tr>
</table>
eoq;
set_upgrade_progress('end','done');
$showBack		= false;
$showCancel		= false;
$showRecheck	= false;
$showNext		= false;

$stepBack		= 0;
$stepNext		= 0;
$stepCancel	= 0;
$stepRecheck	= 0;

$_SESSION['step'][$steps['files'][$_REQUEST['step']]] = ($stop) ? 'failed' : 'success';

?>
