<?php

/*******************************************************************************
 * eredeti url: http://www.cadline.hu/version/update/ + projectid +/ +pkgid+ / +serial
 ******************************************************************************/
include("config.php");
include("version.php");

$version = new Version();

$igen = "";
$projectid = $_GET['projectid']; //segment(3);
$pkgid = $_GET['pkgid']; //segment(4);
$serial = $_GET['serial']; //segment(5);
//	$langid = $this->uri->segment(5);
//	$usertype = $this->uri->segment(6);

if (!$serial) {
	print "nincs sorozatszam";
	return;
}

// A 2023-as LIVE-ban nem volt jo a link, ezzel javitva van
if ($projectid == 'ARCHlineXP2023Live') {
	$projectid = 'ARCHlineXP2023_Livex64';
}

$utolso = Version::get_latest($projectid, $pkgid, substr($serial, 0, 6), '0');

if ($utolso) {
	if ($utolso->pkgid > $pkgid) {
		$fajl = "../public/downloads/" . $utolso->fajl;
		if (file_exists($fajl)) {
			print str_replace("x64", "", $utolso->projectid) . "; ";
			print $utolso->pkgid . "; ";
			print "https://" . $_SERVER['HTTP_HOST'] . "/" . $fajl . "; ";
			print $utolso->azonosito . "; ";
			print $utolso->csendes;
			if ($utolso->ev >= 2013) {
				print "; " . $version->hibajelentes[$utolso->ev];
				print "; " . $utolso->hash;
			}
			$igen = "kiadta a fajlt";
		} else {
			print "nincs meg a fajl: " . $fajl;
			$igen = "nincs meg a fajl: " . $fajl;
		}
	} else {
		print "nincs frissebb";
		$igen = "nincs frissebb";
		if ($utolso->ev >= 2013) {
			print ";;;;; " . $version->hibajelentes[$utolso->ev];
			print "; "; //.$utolso->hash;
		}
	}
} else {
	//print "hiba";
	if ($projectid == "ARCHlineXP2013x64" || $projectid == "ARCHlineXP2013") {
		print ";;;;; " . $version->hibajelentes['2013'];
		print "; ";
	} elseif ($projectid == "ARCHlineXP2014x64" || $projectid == "ARCHlineXP2014") {
		print ";;;;; " . $version->hibajelentes['2014'];
		print "; ";
	} else {
		print "hiba";
	}
	$igen = "hiba";
}

/*
	$record->osztaly = "version";
	$record->fv = "update";
	$record->hiba = "kapott: ".$pkgid."\nutolso: ".$utolso->pkgid."\n".$igen."\nprid: ".$projectid;
	$record->datum = date('Y-m-d H:i:s',time());
*/
//	if( strtolower($projectid) == "archlinexp2012")
//	$this->db->insert('a_hibak',$record);
