<?php
	
	
		global $g_obj_tage0303;
		$g_obj_html->createObject('tage0303', 'troyceAgenda()');
		
		$g_obj_tage0303->setvariable('dateformat', 'j M Y H:i');

		$g_obj_tage0303->setTemplateFunction('tpl_array_rearrange', 'array_rearrange');

		$g_obj_tage0303->setTemplateVariable('componentSettings', $componentSettings);

		$g_obj_tage0303->setTemplateVariable('months', array(1=>'January',2=>'February',3=>'March',4=>'April',5=>'May',6=>'June',7=>'July',8=>'August',9=>'September',10=>'October',11=>'November',12=>'December'));

		$years = array();
		for ($y = date('Y'); $y < date('Y')+4; $y++) {
			$years[$y] = $y;
		}
		$g_obj_tage0303->setTemplateVariable('years', $years);

		$show = isset($componentSettings['show']) ? $componentSettings['show'] : '';

		if (isset($componentSettings['template'])) {
			$g_obj_tage0303->setSetting('templates->agendapoints', $componentSettings['template']);
		}

		if (isset($componentSettings['maxpoints'])) {
			$g_obj_tage0303->setVariable('maxpoints', $componentSettings['maxpoints']);
		}

		if (isset($componentSettings['search']) && count($componentSettings['search']) > 0) {

			$g_obj_tage0303->setTemplateVariable('show_ext_search', true);
		}

		switch ($show) {
		
			case 'list':
				
				$country_list = array('1' => '--- Show all');
				$rs = $g_obj_tage0303->query("
				SELECT DISTINCT val_value FROM tbl_age_att_values 
				INNER JOIN tbl_age_agendapoints ON val_agp_id = agp_id AND agp_status = 'DEF' AND (agp_enddate >= NOW() OR agp_enddate = '')
				WHERE val_att_code = 'GATT_LAND' AND LENGTH(val_value) > 0 ORDER BY val_value");
				while ($r = $rs->row()) {
					$country_list[$r['val_value']] = $r['val_value'];
					$rs->moveNext();
				}
				$rs->Close();


				$location_list = array('1' => '--- Show all');
				$rs = $g_obj_tage0303->query("
				SELECT DISTINCT val_value FROM tbl_age_att_values
				INNER JOIN tbl_age_agendapoints ON val_agp_id = agp_id AND agp_status = 'DEF' AND (agp_enddate >= NOW() OR agp_enddate = '')
				WHERE val_att_code = 'GATT_LOCATIE' AND LENGTH(val_value) > 0 ORDER BY val_value");
				while ($r = $rs->row()) {
					$location_list[$r['val_value']] = $r['val_value'];
					$rs->moveNext();
				}
				$rs->Close();
				
				$g_obj_tage0303->setTemplateVariable('country_list', $country_list);
				$g_obj_tage0303->setTemplateVariable('location_list', $location_list);

				
				$g_obj_tage0303->setTemplateVariable('selected_def', $componentSettings['defs']);
				$g_obj_tage0303->setTemplateVariable('selected_order', $componentSettings['order']);
				$g_obj_tage0303->showAgendaPoints(	$componentSettings['defs']
												,	''
												,	$componentSettings['search']
												,	$componentSettings['order']
												);

				break;

			case 'detail':
				if (isset($componentSettings['id'])) {
					
					$g_obj_tage0303->showAgendaPoints(null, $componentSettings['id']);

				}

				break;

		}

	
?>