<?

	$agp_id	= (isset($_REQUEST['id']) && is_numeric($_REQUEST['id'])) ? $_REQUEST['id'] : null;
	$defs	= (isset($_REQUEST['def_select']) && $_REQUEST['def_select'] != '1') ? $_REQUEST['def_select'] : null;
	$search	= (isset($_REQUEST['search'])) ? $_REQUEST['search'] : null;
	
	$search = array();
	if (isset($_REQUEST['search_name']) && strlen($_REQUEST['search_name']) > 0) {
		$search[] = array('agp_name', " LIKE '%".mysql_escape_string($_REQUEST['search_name'])."%'");
	}

	if (isset($_REQUEST['search_desc']) && strlen($_REQUEST['search_desc']) > 0) {
		$search[] = array('GATT_DESC', " LIKE '%".mysql_escape_string($_REQUEST['search_desc'])."%'");
	}
	if (isset($_REQUEST['search_country']) && strlen($_REQUEST['search_country']) >  0 && $_REQUEST['search_country'] != '1') {
		$search[] = array('GATT_LAND', " LIKE '%".mysql_escape_string($_REQUEST['search_country'])."%'");
	}	
	if (isset($_REQUEST['search_location']) && strlen($_REQUEST['search_location']) > 0 && $_REQUEST['search_location'] != '1') {
		$search[] = array('GATT_LOCATIE', " LIKE '%".mysql_escape_string($_REQUEST['search_location'])."%'");
	}

	if (isset($_REQUEST['search_datefrom_year']) && is_numeric($_REQUEST['search_datefrom_year'])) {
		if (isset($_REQUEST['search_datefrom_month']) && is_numeric($_REQUEST['search_datefrom_month'])) {
			$from_month = $_REQUEST['search_datefrom_month'];
		} else {
			$from_month = 1;
		}
		
		$date = $_REQUEST['search_datefrom_year'] .'-'. str_pad($from_month, 2, '0',STR_PAD_LEFT) . '-01';

		$search[] = array('agp_startdate', " >= '".$date."'");
	}

	if (isset($_REQUEST['search_datetill_year']) && is_numeric($_REQUEST['search_datetill_year'])) {
		if (isset($_REQUEST['search_datetill_month']) && is_numeric($_REQUEST['search_datetill_month'])) {
			$till_month = $_REQUEST['search_datetill_month'];
		} else {
			$till_month = 12;
		}
		
		$date = $_REQUEST['search_datetill_year'] .'-'. str_pad($till_month, 2, '0',STR_PAD_LEFT) . '-31';

		$search[] = array('agp_enddate', " <= '".$date."'");
	}


	$order	= (isset($_REQUEST['agenda_order'])) ? $_REQUEST['agenda_order'] : null;

	$show = $agp_id ? 'detail' : 'list';


	include_component('tage0303', 
						array(	'show'		=> $show
							,	'id'		=> $agp_id
							,	'defs'		=> $defs
							,	'search'	=> $search
							,	'order'		=> $order
						)
					);

?>