<?php


# HA NINCS ID, AKKOR TÁBORLISTA

if ($this->is_id()) {

	# TÁBOR SZERKESZTÉSE

	$camp = new camp();
	$camp->set_camp_data_by_id($this->get_id());

	//labda típusok hozzáadása
	$shuttle_assoc_array = $sql->assoc_array("SELECT * FROM camp_shuttle_type WHERE cst_deleted = 0 ORDER BY cst_id ASC");
	$shuttle_array = array();
	foreach ($shuttle_assoc_array as $shuttle_type) {
		$new_cst = new camp_shuttle_type();
		$new_cst->set_cst_data_by_id($shuttle_type['cst_id']);
		$shuttle_array[] = $new_cst;
	}
	$smarty->assign('shuttle_array', $shuttle_array);


	//ottalvós opciók hozzáadása
	$accomodation_assoc = $sql->assoc_array("SELECT * FROM camp_accomodation_type WHERE cat_deleted = 0 ORDER BY cat_id ASC");
	$accomodation_array = array();
	foreach ($accomodation_assoc as $accomodation_type) {
		$new_cat = new camp_accomodation_type();
		$new_cat->set_cat_data_by_id($accomodation_type['cat_id']);
		$accomodation_array[] = $new_cat;
	}
	$smarty->assign('accomodation_array', $accomodation_array);


	//tábor típusok
	$ct_assoc_array = $sql->assoc_array("SELECT * FROM camp_type WHERE ct_deleted = 0 ORDER BY ct_name ASC");
	$camp_type_array = array();
	foreach ($ct_assoc_array as $ct) {
		$new_ct = new camp_type();
		$new_ct->set_ct_data_by_id($ct['ct_id']);
		$camp_type_array[] = $new_ct;
	}
	$smarty->assign('camp_type_array', $camp_type_array);



	//shuttles
	$shuttles_assoc_array = $sql->assoc_array('SELECT * FROM camp_shuttle WHERE cs_camp_id = ' . $this->get_id());
	$shuttles = array();
	foreach ($shuttles_assoc_array as $shuttle) {
		$new_sh = new camp_shuttle_type();
		$new_sh->set_cst_data_by_id($shuttle['cs_shuttle_id']);
		$shuttles[] = $new_sh->get_cst_id(); //csak az id-t rakjuk bele, hogy in_array-jel könnyebb legyen keresni
	}

	//accomodations
	$accom_assoc_array = $sql->assoc_array('SELECT * FROM camp_accomodation WHERE ca_camp_id = ' . $this->get_id());
	$accoms = array();
	foreach ($accom_assoc_array as $accom) {
		$new_ac = new camp_accomodation_type();
		$new_ac->set_cat_data_by_id($accom['ca_accomodation_id']);
		$accoms[] = $new_ac->get_cat_id(); //csak az id-t rakjuk bele, hogy in_array-jel könnyebb legyen keresni
	}

	//visszaigazolt jelentkezések
	$accepted_applies = $sql->assoc_array("SELECT * FROM camp_apply JOIN camp_kid on ck_id = capp_camp_kid_ck_id WHERE capp_camp_id = " . $this->get_id() . " AND capp_status in (3,4) ORDER BY ck_name ASC;");
	$color = "";
	$apply_array = array();
	foreach ($accepted_applies as $apply) {
		$new_apply = new camp_apply();
		$new_apply->set_capp_data_by_id($apply['capp_id']);
		//lekérjük a státuszt
		//TODO: objektummal
		$status = $sql->single_variable('SELECT cas_name FROM camp_apply_status WHERE cas_id = ' . $new_apply->get_capp_status());
		$new_apply->set_capp_status($status);
		$apply_array[] = $new_apply;
	}

	//lekérjük az elfogadásra váró jelentkezéseket
	$pending_applies = $sql->assoc_array("SELECT * FROM camp_apply JOIN camp_kid on ck_id = capp_camp_kid_ck_id WHERE capp_camp_id = " . $this->get_id() . " AND capp_status = 2 ORDER BY capp_date DESC;;");

	$apply_array_2 = array();
	foreach ($pending_applies as $apply) {
		$new_apply = new camp_apply();
		$new_apply->set_capp_data_by_id($apply['capp_id']);
		$apply_array_2[] = $new_apply;
	}

	//lekérjük a töröltó jelentkezéseket
	$pending_applies = $sql->assoc_array("SELECT * FROM camp_apply JOIN camp_kid on ck_id = capp_camp_kid_ck_id WHERE capp_camp_id = " . $this->get_id() . " AND capp_status = 5 ORDER BY capp_accept_date DESC;;");

	$apply_array_3 = array();
	foreach ($pending_applies as $apply) {
		$new_apply = new camp_apply();
		$new_apply->set_capp_data_by_id($apply['capp_id']);
		$apply_array_3[] = $new_apply;
	}

	//var_dump($apply_array_3);

	$smarty->assign('apply_array', $apply_array);
	$smarty->assign('pending_apply_array', $apply_array_2);
	$smarty->assign('deleted_apply_array', $apply_array_3);

	$smarty->assign('camp', $camp);
	$smarty->assign('shuttles', $shuttles);
	$smarty->assign('accomodations', $accoms);


	$smarty->display('camp_data_update.tpl');

}

else {
	
	# TÁBOR LISTA

	//tábor adatok
	$camp_query = "SELECT * FROM camp WHERE camp_deleted = 0 ORDER BY camp_from DESC";
	$camp_assoc_array = $sql->assoc_array($camp_query);

	$camp_array = array();
	foreach ($camp_assoc_array as $camp_data) {
		$new_camp = new camp();
		$new_camp->set_camp_data_by_id($camp_data['camp_id']);
		$camp_array[] = $new_camp;
	}


	$smarty->assign('camp_array',$camp_array);
	$smarty->display('camp_list.tpl');

	
}





?>