<?php
ignore_user_abort (true);

$config['update']['type']						= 'stable'; //Or unstable
$config['update']['currentVersion']				= 'v0.4.0RC1.beta1';
$config['update']['newestVersion']				= 'v0.4.0RC1.beta1';
  
//Check for Update - return newest version
function checkUpdate()
{
	//Check on GitHub for new Update
	$API_CALL = 'https://api.github.com/repos/jbtronics/Part-DB/releases';
	
	$context  = stream_context_create(array('http' => array('user_agent' => 'Get Releases')));
	$response = json_decode(file_get_contents($API_CALL, false, $context), true);
	return $response[0]['tag_name'];
}

//Download zipped update from source
function downloadUpdate($updateType, $newestVersion)
{
	//Generate Update-Link
	if($updateType == 'stable')
	{
		$link = "https://github.com/jbtronics/Part-DB/archive/" . $newestVersion . ".zip";
	}
	elseif($config['update']['type'] == 'unstable')
	{
		$link = "https://github.com/jbtronics/Part-DB/archive/nextgen.zip";
	}
	echo $link;
	//Download Update
	if(isset($link))
	{
		file_put_contents('update.zip',file_get_contents($link));
	}
}

//Unzip update.zip
function unzipUpdate()
{
	
	
}


	//TEST
	$config['update']['newestVersion'] = checkUpdate();
	echo $config['update']['newestVersion'];
	
	downloadUpdate($config['update']['type'], $config['update']['newestVersion']);
?>