{extends file=$smarty.const.SMARTY_LAYOUT_MAIN_WINDOW}

{block name="template-head" append}
	{$JS->loadGroup("inputs")}
	{$CSS->loadGroup("inputs")}
	{$JS->load("{asset path="_js/main.js"}")}
	{$CSS->load("{asset path="_css/index.css"}")}
{/block}

{block name="engine-content"}
	<div class="container right">

		{************************ GENERAL INFORMATION *********************************************************}

		<div class="title">
			{$lang['index']['mainDetails']['title']}
		</div>

		<div>
			{$lang['index']['mainDetails']['descr']}
		</div>

		<div class="currVerDescr">
			<div>
				{if $currentStatus != 'START'}
					<div><b>{$lang['index']['mainDetails']['updateType'][$updateType]}</b></div>
				{/if}
				{$lang['index']['mainDetails']['currentVersionDetails']} {$currentVersion}.<b>{$currentBuild}</b>
			</div>

			<div>
				{if $currentStatus != 'START'}
					{if $updateType == 'newVersion'}
						<div>{$lang['index']['mainDetails']['nextVersion']} : {$nextVersion}.<b>{$nextVersionBuild}</b>.</div>
					{/if}
					<div>{$lang['index']['mainDetails']['currentPhp']}: <b>{$smarty.const.PHP_VERSION}</b></div>
					<div>{$lang['index']['mainDetails']['dimensionFile']}: <b> {({$totalFileSize} / (1024 * 1024))|round:2} MB</b></div>
					<div>{$lang['index']['mainDetails']['versionAvailability']}:<b>{$closeDate|dateTimeFormat}</b></div>
				{/if}
			</div>
		</div>

		<div class="currVerDescr">
			<div>
				<b>{$lang['index']['mainDetails']['currentStep']['title']}:</b>
				{if $currentStatus == 'START' or $currentStatus == 'AVAILABLE_VERSION'}
					1/3
				{elseif $currentStatus == 'DOWNLOAD_STARTING' or $currentStatus == 'DOWNLOAD_STARTED' or $currentStatus == 'DOWNLOAD_FINISHED' or $currentStatus == 'DOWNLOAD_STOPPING' or $currentStatus == 'DOWNLOAD_STOPPED' or $currentStatus == 'DOWNLOAD_FAILED' or $currentStatus == 'UNPACK_FAILED'}
					2/3
				{elseif $currentStatus == 'UNPACK_FINISHED'}
					3/3
				{/if}
			</div>
		</div>

		<div class="center">
			{if $currentStatus == 'DOWNLOAD_STARTING' or $currentStatus == 'DOWNLOAD_STARTED'}
				<div class="buttonDownloadStarted">
					<button type="button" name="stopDownload"
						onclick="window.location=MVC.appUrl(MVC.CURRENT_MODULE, 'index', { 'operation' : 'stopDownload' });"
					>{$lang['index']['buttons']['stopDownload']}</button>
				</div>
			{/if}
			<div class="center" style="text-align:center">
				<button type="button" name="recheckVersion"
					onclick="window.location=MVC.appUrl(MVC.CURRENT_MODULE, 'index', { 'operation': 'reset'});"
				>{$lang['index']['buttons']['reset']}
				</button>
			</div>
		</div>

	</div>

	<div class="mainPage left">
		<div class="message">
			{showMessage}
		</div>
		<fieldset class="status">
			<div class="title">
				{if $currentStatus == 'START'}
					{$lang['index']['steps']['new']['step1']['general']}
				{elseif $currentStatus == 'AVAILABLE_VERSION' or $currentStatus == 'DOWNLOAD_STARTING' or $currentStatus == "DOWNLOAD_STOPPED"}
					{$lang['index']['steps'][$updateType]['step2']['general']}
				{elseif $currentStatus == 'UNPACK_FINISHED'}
					{$lang['index']['steps']['step3'][$updateType]['general']}
				{/if}
			</div>

			<div class="content">
				<div class="details">
					{if $currentStatus == 'START'}
						<div class="start">
							{$lang['index']['steps']['new']['step1']['details']}
						</div>
					{elseif $currentStatus == 'AVAILABLE_VERSION'}
						<div class='newVersion'>
							<div>
								{$lang['index']['steps'][$updateType]['step1']['information']|sprintf:{$nextVersionBuild}}
							</div>
						</div>
					{elseif $currentStatus == 'DOWNLOAD_STARTING' or $currentStatus == 'DOWNLOAD_STARTED'}
						<div class='downloadStarting'>
							<div>{$lang['index']['steps']['step2']['details2']} </div>
						</div>
						<div class='downloadStarted'>
							<div>{$lang['index']['steps']['step2']['details3']} </div>
							<div>{$lang['index']['steps']['step2']['details4']}</div>
						</div>
					{elseif $currentStatus == 'DOWNLOAD_STOPPING'}
						<div class='downloadStopping'>
							<div>{$lang['index']['steps']['step2']['details5']} </div>
						</div>
					{elseif $currentStatus == 'DOWNLOAD_STOPPED'}
						<div class='downloadStopped'>
							<div>{$lang['index']['steps']['step2']['details6']}</div>
						</div>
					{elseif $currentStatus == 'DOWNLOAD_FINISHED'}
						<div class='downloadFinished'>
							<div>{$lang['index']['steps']['step2']['details7']}</div>
						</div>
					{elseif $currentStatus == 'DOWNLOAD_FAILED'}
						<div class='downloadFailed'>
							<div>{$lang['index']['steps']['step2']['details8']}</div>
						</div>
					{elseif $currentStatus == 'UNPACK_FAILED'}
						<div class='unpackFailed'>
							<div>{$lang['index']['steps']['step2']['details8']}</div>
						</div>
					{elseif $currentStatus == 'UNPACK_FINISHED'}
						<div>{$lang['index']['steps']['step2']['details9']}</div>
						<div>{$lang['index']['updater']['description']}</div>
						<div class="stepContentUpdate">
							{$lang['index']['updater']['disclaimer']}
						</div>
					{/if}
				</div>

				<div class="center button">
					{if $currentStatus == 'START'}
						<button type="button" name="checkNextVersion"
							onclick="window.location= MVC.appUrl(MVC.CURRENT_MODULE, 'index', { 'operation' : 'checkNextVersion' });"
						>{$lang['index']['buttons']['checkNewVersion']}
						</button>
					{elseif $currentStatus == 'AVAILABLE_VERSION'}
						<button type="button" name="initializeDownload" id="initializeDownload"
							onclick="setTimeout(intializeDownload, 1);"
						>{$lang['index']['buttons']['initializeDownload']}</button>

						{if $productVersionComments}
							<div class="red productVersionComments">
								{$lang['index']['updater']['productVersionComments']}
							</div>
						{/if}

					{elseif $currentStatus == 'UNPACK_FINISHED'}
						<button type="button" name="updater"
							onclick="displayQuestionUpdater();"
						>{$lang['index']['buttons']['startUpdate']}</button>

						{if $productVersionComments}
							<div class="red productVersionComments">
								{$lang['index']['updater']['productVersionComments']}
							</div>
						{/if}
					{/if}
				</div>

				<div class="center">
					{if $currentStatus == 'DOWNLOAD_STARTING' or $currentStatus == 'DOWNLOAD_STARTED'}
						<div id="progressbar"></div>

						{if $productVersionComments}
							<div class="red productVersionComments">
								{$lang['index']['updater']['productVersionComments']}
							</div>
						{/if}
					{/if}
				</div>
			</div>
		</fieldset>

		{******************************** UPDATE CURRENT VERSION *******************************************************}
		{if $currentStatus == 'START'}
			<fieldset>
				<div class="title">
					{$lang['index']['steps']['currentVersion']['step1']['general']}
				</div>

				<div class="content">
					<div class="details">
						<div class="start">
							{$lang['index']['steps']['currentVersion']['step1']['details']}
						</div>
					</div>

					<div class="center button">
						<button type="button" name="checkNextVersion"
							onclick="window.location= MVC.appUrl(MVC.CURRENT_MODULE, 'index', { 'operation' : 'checkCurrentVersion' });"
						>{$lang['index']['buttons']['checkCurrentVersion']}
						</button>
					</div>
				</div>
			</fieldset>
		{/if}
	</div>
{/block}

{block name="js" append}
	{if $currentStatus == 'DOWNLOAD_STARTED' or $currentStatus == 'DOWNLOAD_STARTING'}
		<script type="text/javascript">
			MVC.scheduleOnLoad(function() {
				if ($('progressbar')) {
					progressBar = new Progressbar($('progressbar'), {
							'period': 2.5
					});
					progressBar.update();

				}
			});
		</script>
	{/if}

	<script type="text/javascript">

		function intializeDownload() {
			$('initializeDownload').disabled = 'true';
			window.location=MVC.appUrl(MVC.CURRENT_MODULE, 'index', { 'operation' : 'initializeDownload' });
		}

		function openUpdaterPopup()	{
			if ('{$updateType}' == 'currentVersion') {
				Popup2.create().setId('updaterWindow').setUrl(DCsConfigs.APP_URL+'../new/disp.php?module=Utils/Updater/UpdateCurrentVersion/').setDimensions(1000, 600).show();
			}
			else {
				Popup2.create().setId('updaterWindow').setUrl(DCsConfigs.APP_URL+'../update/').setDimensions(1000, 600).show();
			}
		}

		function displayQuestionUpdater() {
			messageBox.showQuestion(
				'{$_LANG.confirm}',
				'<div class=\'bold\'>{$lang['index']['updater']['conf1']}</div> <div class=\'italic\'>{$lang['index']['updater']['conf2']}</div>',
				[
					['{$_LANG.yes}', 'openUpdaterPopup()'],
					['{$_LANG.no}', '', true]
				]
			);
		}
	</script>
{/block}

