<?php
ini_set('include_path', '../_class/');
include('class_sql.php');
include('class_user_parent.php');
include('class_user_kid.php');
include('class_user_group.php');
include('class_user_group_filter.php');
include('class_user_group_filter_value.php');
if ($_SERVER['HTTP_HOST'] == 'badmintoncoach.hu') $sql = new sql('bc_mysql','root','','badminton_coach');
else $sql = new sql('localhost','tollashodos','uprRscU8bGpJ','tollashodos');

$all_kid = array();

if (empty($_POST['filter_array'])) {
	echo json_encode(null);
}
else {
	//updatelni kell az user_group_filter_value, aztán apply-olni
	user_group::empty_group($_POST['user_group_id']);
	foreach ($_POST['filter_array'] as $key => $filter_value) {
		//[0] => filter_value_id, [1] => value, [2] => filter_id
		if ($filter_value[1] == 'null') {
			$sql->execute_query('DELETE FROM user_group_filter_value WHERE ugfv_id = ' . $filter_value[0]);
		}
		else {
			$sql->update_table('user_group_filter_value', array(
				'ugfv_filter_id' => $filter_value[2],
				'ugfv_group_id' => $_POST['user_group_id'],
				'ugfv_value' => $filter_value[1],
			), array(
				'ugfv_id' => $filter_value[0],
			));



		$ugfv_obj = new user_group_filter_value();
		$ugfv_obj->set_ugfv_data_by_id($filter_value[0]);
		$ugfv_obj->apply($_POST['intersect']);
	
		}
		
	}


}

?>