<?php

//////////////////////////////////////////////////////////////
//===========================================================
// updates_theme.php
//===========================================================
// SOFTACULOUS VIRTUALIZOR
// Version : 1.0
// Inspired by the DESIRE to be the BEST OF ALL
// ----------------------------------------------------------
// Started by: Alons
// Date:       8th Mar 2010
// Time:       23:00 hrs
// Site:       https://www.virtualizor.com/ (SOFTACULOUS VIRTUALIZOR)
// ----------------------------------------------------------
// Please Read the Terms of use at https://www.virtualizor.com
// ----------------------------------------------------------
//===========================================================
// (c)Softaculous Ltd.
//===========================================================
//////////////////////////////////////////////////////////////

if(!defined('VIRTUALIZOR')){

	die('Hacking Attempt');

}

function updates_theme(){

global $theme, $globals, $kernel, $user, $l, $error, $info, $report, $updated, $actid;

if($updated){
	echo $actid;
	$updated = 0;
	return;
}

softheader($l['<title>']);
					
if(optGET('done')){		
	show_alert(__('Virtualizor has been updated successfully'));
	echo '<div class="notice mx-3"><b>'.__('Note').' : </b> &nbsp; '.__('Virtualizor has been updated successfully').'</div>';
}else{
	
	$GLOBALS['breadcrumbs'] = array('dashboard', 'lm_config', 'lms_updates');
	echo page_header(__('Update Virtualizor'), 'fas fa-sync-alt fa-spin', '', 0, 0, '', '');	
}

error_handle($error, '100%');

echo '<script language="javascript" type="text/javascript">
			
	var actid = null;
	var progress = 0;
	var progress_update = "";
	
	$(document).ready(function(){
		progress_onload();
		$("#updatesform").submit(function(){

			$.ajax({type: "POST",
				url: "'.$globals['index'].'jsnohf=1&act=updates",
				data:"update=1",
				success:function(response){
					if(!isNaN(response)){
						animate_task("'.__J('Virtualizor Update Task Started').'");
						actid = response;
						setTimeout("get_progress(\'updates\')", 7500);
					}
					else{
						var parsed_HTML = $(response);
						var error_box = parsed_HTML.filter("#error_box").add(parsed_HTML.find("#error_box"));
						showalert(error_box.html(),"1");
						$("#form-container").show();
						$("#progress-cont").hide();
						error_box.html("");
					}
				}
			});
			
			$("#error_box").remove();
			$("#form-container").hide();
			$("#progress-cont").show();
			$("#pbar").html("'.__J('Updating Virtualizor').'" + " ( 0% ) ");
			window.scrollTo(0, 0);
			$("#progressbar").progressbar({value: 0});
			
			return false;
		});
		
	});

</script>';

if(!empty($report)){
	echo '<table width="100%" cellpadding="8" cellspacing="0" border="0">
	<tr>
		<td colspan="2" class="head">'.__('Update Logs').'</td>
	</tr>
	<tr>
		<td valign="top">'.implode('<br />', $report['log']).'</td>
		<td width="20%"><img src="'.$theme['images'].'admin/'.(empty($report['status']) ? 'softerror.gif' : 'softok.gif').'" /></td>
	</tr>
	</table>
	<br />';
}

echo '<div id="form-container">
<form accept-charset="'.$globals['charset'].'" name="updatevirtualizor" method="post" action="" id="updatesform" class="form-horizontal">

<div class="card p-2 mx-3">
	<div class="row mx-auto w-100 my-3">
		<div class="col-sm-4 right">
			<label class="control-label">'.__('Current Version').'</label>
		</div>
		<div class="col-sm-4">'.$globals['version'].'</div>
	</div>
	<div class="row mx-auto w-100 my-3">
		<div class="col-sm-4 right">
			<label class="control-label">'.__('Current Patch Number').'</label>
		</div>
		<div class="col-sm-4">'.$globals['patch'].'</div>
	</div>
	<div class="row mx-auto w-100 my-3">
		<div class="col-sm-4 right">
			<label class="control-label">'.__('Latest Version').'</label>
		</div>
		<div class="col-sm-4">'.(empty($info['version']) ? __('Could not connect to Virtualizor') : '<span class="text-primary">'.$info['version']).'</span></div>
	</div>
	<div class="row mx-auto w-100 my-3">
		<div class="col-sm-4 right">
			<label class="control-label">'.__('Latest Patch number').'</span></label>
		</div>
		<div class="col-sm-4">'.($globals['patch'] < $info['patch'] ? '<span class="text-primary">'.$info['patch'].'</span>' : __('No New Patch Available')).'</div>
	</div>
</div>
<div class="card p-2 m-3">
<h5><strong>Changelog:</strong></h5>
<b>'.$info['message'].'</b></div>
<br/><br/>
<p align="center"><input type="submit" class="go_btn" name="update"  value="'.__('Update Virtualizor').'" '.(empty($info['link']) ? 'disabled="disabled"' : '').' /></p>
</form>
</div>';

echo '<div id="progress_onload"></div>';

softfooter();

}


