<?php
include '../config/database.php';

function _login($gid,$product,$version,$name){
	$conn = _connectDB();
	$sql_get = "SELECT groupline_key FROM groupline WHERE groupline_products='".$product."' AND groupline_key='".$gid."'";
	$result = $conn->query($sql_get);
	$status = false;
	if ((int)$result->num_rows == 0) {
		//INSERT
		$sql_insert = "INSERT INTO groupline (groupline_name, groupline_key ,groupline_user_key,groupline_user_name, groupline_products , groupline_version,groupline_products_5min,groupline_status,groupline_access,groupline_view) VALUES ('".$name."','".$gid."',NULL,NULL,'".$product."','".$version."','".$product."','run','active','NORMALVIP');";
		$query_insert = $conn->query($sql_insert);
		$status = true;
	}
	return $status;
}

$_status =  false;

if( isset($_GET['gid']) OR isset($_GET['p']) OR isset($_GET['v']) OR isset($_GET['name'])){
	$_status = _login($_GET['gid'],$_GET['p'],$_GET['v'],$_GET['name']);
	echo json_encode(['status'=> $_status]);
}else{
	echo json_encode(['status'=> $_status]);
}


?>
