<?php

if ($this->is_id()) {

	//jelentkező
	$apply = new camp_apply();
	$apply->set_capp_data_by_id($this->get_id());

	//felelős kapcsolattartó
	$res_cc_id = $sql->single_variable("SELECT cac_camp_contact_cc_id FROM camp_apply_contact WHERE cac_is_responsible = 1 AND cac_camp_apply_capp_id = " . $this->get_id() );
	$res_cc = new camp_contact();
	$res_cc->set_cc_data_by_id($res_cc_id);

	//további kapcst-ók

	$cc_ids = $sql->assoc_array("SELECT cac_camp_contact_cc_id FROM camp_apply_contact WHERE cac_is_responsible = 0 AND cac_camp_apply_capp_id = " . $this->get_id() );

	$contacts = array();
	foreach ($cc_ids as $cc) {
		$contact = new camp_contact();
		$contact->set_cc_data_by_id($cc['cac_camp_contact_cc_id']);
		$contacts[] = $contact;
	}

	$smarty->assign('apply',$apply);
	$smarty->assign('res_cc',$res_cc);
	$smarty->assign('contacts',$contacts);
	$smarty->display('apply.tpl');


}

else {
	
	# JELENTKEZÉSEK: 2 táblázat
		// elbírált jelentkezések
		// elfogadásra váró jelentkezések

	//lekérjük az elbírált jelentkezéseket
	$accepted_applies = $sql->assoc_array("SELECT * FROM camp_apply JOIN camp_kid on ck_id = capp_camp_kid_ck_id WHERE ck_owner_id = " . $user->get_cu_id() . " AND capp_status in (3,4);");
	$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());
		if ($new_apply->get_capp_status() == 3) {
			$color = "green";
		}
		else {
			$color = "red";
		}
		$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 ck_owner_id = " . $user->get_cu_id() . " AND capp_status = 2;");

	$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;
	}

	$smarty->assign('color', $color);
	$smarty->assign('apply_array', $apply_array);
	$smarty->assign('pending_apply_array', $apply_array_2);
	$smarty->display('applies.tpl');
	
}

?>