<?php
	require_once "./ajax.php";
	
	if (isset($_POST['_r']) && isset($_POST['_a'])) {
		$ajax = new ATAjax();
		die($ajax->response());
	}
	
	return displayInstallSteps();
	
	function displayInstallSteps() {
		$context = file_get_contents("./coremigrate_context.json");
		$context = json_decode($context, true);
		$context['extract_path'] = $_GET['extract_path'];
		$context['package_path'] = $_GET['package_path'];
		$context['extract_path_info'] = pathinfo($_GET['extract_path']);
		$server = [
			'server_information' => getUname(),
			'server_software_version' => isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : 'n/a',
		];
		$php_information = getPhpInformation();
		$html = require "./view.php";
		
		return $html;
	}
	
	/**
	 * @return string
	 */
	function getUname()
	{
		return function_exists('php_uname') ? php_uname('s') . ' ' . php_uname('v') . ' ' . php_uname('m') : '';
	}
	
	/**
	 * @return array
	 */
	function getPhpInformation()
	{
		return [
			'version' => PHP_VERSION,
			'memoryLimit' => ini_get('memory_limit'),
			'maxExecutionTime' => ini_get('max_execution_time'),
			'maxFileSizeUpload' => ini_get('upload_max_filesize'),
		];
	}
?>