<?php
require "Common/openDB.php";

// Get latest version number
$ver = VersionOnESRUSite();

// Make URL
$url = "http://www.esru.strath.ac.uk/Downloads/EnTrak/EnTrak_V".$ver."_src.zip";

if($oper_sys == "windows"){
    // Get file from ESRU website
    echo "<h3><center> Refresh this page once the command window closes, </br>you will notice in the browser tab that version number has been updated</center></h3>";
    file_put_contents("C:/tmp/Tmpfile.zip", fopen($url, 'r'));

    // Copy updater.bat and zip file to c:/tmp and then run it
    copy("updater.bat","C:/tmp/updater.bat");
    copy("unzip.exe","C:/tmp/unzip.exe");

    $shell = new COM("WScript.Shell");
    $shell->Run("C:\Windows\System32\cmd.exe  /A /Q /K  C:/tmp/updater.bat {$ver}");
    $shell = null;
}elseif($oper_sys == "linux"){
	echo "<h3><center> Refresh this page, </br>you will notice in the browser tab that version number has been updated</center></h3>";
    file_put_contents("/tmp/Tmpfile.zip", fopen($url, 'r'));
    copy("updater.bash","/tmp/updater.bash");
    shell_exec("bash /tmp/updater.bash {$ver}");
}

?>
