<?php
ob_start();
include("pclzip.lib.php");
print "Začenjam prenos<br>";
print ob_get_contents();
ob_flush();
$archiveZip = file_get_contents('http://update.cms.zabec.net/3/latest.zip'); //RM Preberemo datoteko, ki vsebuje novo verzijo aplikacije
print "Prenos opravljen<br>";
$archiveZipFilename = 'temp/update.zip';
if ($archiveZip !== false) {
	if (is_writeable('temp/')) {
		if (file_put_contents($archiveZipFilename, $archiveZip)) { //RM Prebrano datoteko shranimo v začasni direktorij
			new PclZip($archiveZipFilename);
			$archive = new PclZip($archiveZipFilename); //RM Datoteko od-arhiviramo v določen direktorij in s tem posodobimo našo aplikacijo
            $extractedFiles = $archive->extract(PCLZIP_OPT_STOP_ON_ERROR, PCLZIP_OPT_REPLACE_NEWER, PCLZIP_OPT_PATH, './extract');
            if (is_array($extractedFiles)) echo count($extractedFiles).': files were extracted.';
            else echo 'There was an error while extracting archive: '.$archive->errorInfo();
            @unlink($archiveZipFilename);
		}
	} else echo 'Directory is not writeable';
} else echo 'New version of files cannot be downloaded';
?>