<?php

/*******************************************************************************
 * eredeti url: http://www.archline.hu/version/updatexml
 * új url: www.archlinexp.com/maintenance/updateget.php?prod_ver=Beta&d_build=2017-12-15&pkgid=217&setup_type=Developer&fajl=eng/ARCHLINE_2018_Build217_Developer_64_setup.exe&usertype=;360006;360012;&hash=30690E8407E0F9917026325F3CF0BD0E&projectid=ArchlineXP2018x64
 ******************************************************************************/
@header("Content-Type: text/html; charset=UTF-8");

include("config.php");

$tomb = array(
	'prod_ver' => trim(addslashes($_GET['prod_ver'])),
	'd_build' => (isset($_GET['d_build']) ? trim(addslashes($_GET['d_build'])) : date('Y-m-d')),
	'pkgid' => (int)$_GET['pkgid'],
	'setup_type' => trim(addslashes($_GET['setup_type'])),
	'fajl' => trim(addslashes($_GET['fajl'])),
	'usertype' => trim(addslashes($_GET['usertype'])),
	'hash' => trim(addslashes($_GET['hash'])),
	'projectid' => trim(addslashes($_GET['projectid'])),

	'ev' => substr($_GET['projectid'], 10, 4),
	'deleted' => 0,
);

$parancs = " SELECT * FROM `version` WHERE ev = " . $tomb['ev'] . " AND pkgid = " . $tomb['pkgid'] . " AND deleted = 0 AND fajl='" . $tomb['fajl'] . "'";
$msh2->query($parancs);
$sql = $msh2->fetchAssoc();

/*print "parancs: ".$parancs."<br><br>";
		print "tomb: "; print_r($tomb);
		print "\n\nsql: "; print_r($sql);*/

if (count($sql) == 1) {
	$msh2->update('version', $tomb, "ver_id=" . $sql[0]['ver_id']);
} elseif (count($sql) == 0 && $tomb['deleted'] != "1") {
	$msh2->insert('version', $tomb);
} else {
	$record->osztaly = "version";
	$record->fv = "updatexml";
	$record->hiba = "Több rekord találat (vagy torolt beszuras), build: " . $tomb['pkgid'] . "\nsql: " . $parancs . "\ndb: " . count($sql) . "\ndeleted: " . $tomb['deleted'];
	$record->datum = date('Y-m-d H:i:s', time());
	if ($tomb['deleted'] != "1")
		$msh2->insert('a_hibak', $record);
}

/*print "<pre>";
		print_r($tomb);
		print $tomb['projectid'];*/

print 'ok';
