<?php

include "../../connection.php";

$nazov = '';
$tech = '';
$tak = '';
$kon = '';
$res='';

//error_reporting(0);

	$nazov = $_POST['nazov'];
	$tech = $_POST['tech'];
	$tak = $_POST['tak'];
	$kon = $_POST['kon'];


$q = "SELECT * FROM cvicenia
	WHERE ";
$qN='nazov REGEXP ? ';
$qT=' taktika BETWEEN ? AND ?';
$qTak=' technika BETWEEN ? AND ?';
$qk=' kondicka BETWEEN ? AND ?';

$i=0;
if (!empty($_POST['nazov'])) {
	$q .= $qN;
	$premenne= array($nazov);
	$i++;
}

if (!empty($_POST['tech'])) {
	if ($i>0) $q .= ' OR '; 
	$q .= $qT;
	array_push($premenne, $tak-0.2, $tak+0.2 );
	$i++;
}

if (!empty($_POST['tak'])) {
	if ($i>0) $q .= ' OR ';
	$q .= $qTak;
	array_push($premenne, $tech-0.2, $tech+0.2 );
	$i++;
}

if (!empty($_POST['kon'])) {
	if ($i>0) $q .= ' OR ';
	$q .= $qk;
	array_push($premenne, $kon-0.2, $kon+0.2 );
	$i++;
}


$q2 = queryWithBids($q, $premenne);
$res=$q2->fetchAll();
echo json_encode($res);


?>
