<?php
// INCLUDE HEADER IN PAGE
include('other_header.php');
// GET CURRENT DATE AND TIME
$date = date('Y-m-d H:i:s');
?>
<?php
if(isset($_POST['updatecheck'])) {
				$query = "SELECT * FROM System_Data";
				$result = mysql_query($query) or die('Error, query failed');
				while($row = mysql_fetch_array($result)){
					$system_versioncheckurl = $row['versioncheckurl'];
					$system_script_version = $row['version'];
				}
    			// 1. URL
					$result1 = file_get_contents($system_versioncheckurl);
					$obj1 = json_decode($result1, true);
					$checkedversion = $obj1['lastversion'];
					if($checkedversion == ""){
						$status = 'It looks like your hosting does not have allowed some extensions. Platform could not get information from external server about latest version';
						$statusn = 0;
						$showlasttext = 0;
						$updatelast = mysql_query("UPDATE System_Data SET lastversion='$checkedversion',lastchecked='$date' WHERE id='1'");
					}else if($checkedversion == $system_script_version) {
						$status = 'Your script have latest updates.';
						$statusn = 1;
						$showlasttext = 1;
						$updatelast = mysql_query("UPDATE System_Data SET lastversion='$checkedversion',lastchecked='$date' WHERE id='1'");					
					}else {
						$status = 'Your script is outdated.';
						$statusn = 0;
						$showlasttext = 1;
						$updatelast = mysql_query("UPDATE System_Data SET lastversion='$checkedversion',lastchecked='$date' WHERE id='1'");
					}
				?>
					<div style="margin-top: -35px;" class="alert alert-<?php if($statusn == 1){echo 'success';}else{echo 'danger';}?>" role="alert">
						<strong><?php if($statusn == 1){echo 'Well done';}else{echo 'Ooops';}?>!</strong> <?php if($showlasttext == 1){ ?>Last version is: <?php echo $checkedversion;?>. <?php } ?> <?php echo $status;?>
					</div>
				<?php
			}
?>
  <div class="container">
    <div class="text-center">
      <h1><?php echo $title; ?>
      	<small>/Active is: Admin Account
			</small>
		</h1>
 	 </div>
 	 </br>
<?php
	$query = "SELECT * FROM System_Data WHERE `id` = '1'";
	$result = mysql_query($query) or die('Error, query failed');
	while($row = mysql_fetch_array($result)){
		$system_envato_username = $row['username'];
		$system_envato_purchase = $row['purchase'];
		$system_script_version = $row['version'];
		$system_script_lastchecked = $row['lastchecked'];
		$system_script_lastversion = $row['lastversion'];
	}
?>
<div class="jumbotron">
  <h1>Current version <?php echo $system_script_version;?></h1>
  <p>You last checked for update in: <?php echo $system_script_lastchecked;?></p>
  <p>Last available version: <?php echo $system_script_lastversion;?></p>
  <form method='post'>
  	<input class='btn btn-primary' type='hidden' name='version' value='<?php echo $top_id;?>'>
   <div class="col-sm-12">
         <center>
         <div class='form-group has-success'>
				<div class="input-group">
               <span class="input-group-btn">
               	<input type='submit' name='updatecheck' value='Check for updates' class='btn btn-primary'>
            	</span>
           	</div>
			</div>
			</center>
   </div>
  </form>
</div>
</div>

<?php
include('other_footer.php');
?>