<?php
header('Content-type: application/json');
include '../config/database.php';
function _command($gid,$products,$version){
	$conn = _connectDB();
	$result_get = get_real_item($conn,$gid,$products);
	$version_real = $result_get[0]['groupline_version'];
	$sql = "INSERT INTO missing (GID,products,version,version_real) VALUES ('".$gid."', '".$products."','".$version."','".$version_real."')";
//	$sql = "UPDATE groupline SET groupline_missing='YES' WHERE  groupline_key='".$gid."' AND groupline_products='".$products."' AND groupline_version='".$version."' ";
	$result = $conn->query($sql);
	$res = ['status'=>true];
	return $res;
}
if(isset($_GET)){
	if(isset($_GET['gid']) AND isset($_GET['p'])  AND isset($_GET['v'])){
		$gid = $_GET['gid'];
		$products = $_GET['p'];
		$version = $_GET['v'];
		echo json_encode(_command($gid,$products,$version));
	}else{echo json_encode(['status'=>false]);}
}else{echo json_encode(['status'=>false]);}


function get_real_item($conn,$GID,$PRODUST){
	$sql_get = "SELECT groupline_version FROM groupline G WHERE G.groupline_key = '".$GID."' AND G.groupline_products = '".$PRODUST."' limit 1";
	$result_get = $conn->query($sql_get);
    $res = [];
	if ($result_get->num_rows > 0) {
	    while($row = $result_get->fetch_assoc()) {
			array_push($res,$row);
	    }
	} else {
	    echo "";
	}
	return $res;
}