<?php


# HA NINCS ID, AKKOR ÁTIRÁNYÍTÉS /1-re

if ($this->is_id()) {

	# TÁBORI JELENTKEZÉS
	//var_dump($_COOKIE);

	if ($this->get_id() == 1) {
		//1. LÉPÉS JELENTKEZŐ ADATAI
		//lekérjük a camp_user kid-jeit egy tömbbe
		$kid_assoc_array = $sql->assoc_array("SELECT * FROM camp_kid WHERE ck_owner_id = " . $user->get_cu_id() . " AND ck_original_id IS NULL");
		$kids = array();
		foreach ($kid_assoc_array as $kid_array) {
			$new_kid = new camp_kid();
			$new_kid->set_ck_data_by_id($kid_array['ck_id']);
			$kids[] = $new_kid;
		}

		$shirt_assoc_array = $sql->assoc_array("SELECT * FROM camp_shirt WHERE cshirt_deleted = 0 ORDER BY cshirt_id ASC;");
		$shirts = array();
		foreach ($shirt_assoc_array as $shirt) {
			$new_shirt = new camp_shirt();
			$new_shirt->set_cshirt_data_by_id($shirt['cshirt_id']);
			$shirts[] = $new_shirt;
		}


		$smarty->assign('step',1);
		$smarty->assign('kids',$kids);
		$smarty->assign('shirts',$shirts);
		$smarty->display('camp_apply.tpl');

		//var_dump($user);
	}

	elseif ($this->get_id() == 2) {
		//2. LÉPÉS KAPCSOLATTARTÓ ADATAI
		//csak akkor érhető el, ha van cookie, egyébként visszadob az első lépésre
		if (!isset($_COOKIE['badminton_camp_session_id'])) {
			header('Location: /tabor/jelentkezes/1');
		}

		else {
			//lekérjük a korábban megadott kapcsolattartókat
			$contact_assoc_array = $sql->assoc_array("SELECT * FROM camp_contact WHERE cc_owner_id = " . $user->get_cu_id() . " AND cc_original_id IS NULL");
			$contacts = array();
			foreach ($contact_assoc_array as $contact_array) {
				$new_cc = new camp_contact();
				$new_cc->set_cc_data_by_id($contact_array['cc_id']);
				$contacts[] = $new_cc;
			}

			//lekérjük van-e felelős kapcsolattartó
				//ha van, akkor nem lehet bepipálni
				//ha nincs, akkor van pipa
			$has_responsible = camp_apply::has_responsible_contact($_COOKIE['badminton_camp_session_id']);


			//lekérjük a contact type-okat
			$cct_assoc_array = $sql->assoc_array("SELECT * FROM camp_contact_type WHERE cct_owner IS NULL OR cct_owner = " .  $user->get_cu_id() . ";");
			$cct_array = array();
			foreach ($cct_assoc_array as $cct) {
				$new_cct = new camp_contact_type();
				$new_cct->set_cct_data_by_id($cct['cct_id']);
				$cct_array[] = $new_cct;
			}

			$smarty->assign('cct_array', $cct_array);

			//van-e már jelentkező
			$has_contact = camp_apply::has_contact($_COOKIE['badminton_camp_session_id']);

			//lekérjük a session_id alapján a camp_kid it-t, objektumot csinálunk belőle és úgy adjuk át
			//$ck_id = $sql->single_variable("SELECT capp_camp_kid_ck_id FROM camp_apply WHERE capp_id = " . $_COOKIE['badminton_camp_session_id']);
			//$new_camp_kid = new camp_kid();
			//$new_camp_kid->set_ck_data_by_id($ck_id);

			//van-e
			//$smarty->assign('camp_kid', $new_camp_kid);
			$smarty->assign('has_contact', $has_contact);
			$smarty->assign('contacts', $contacts);
			$smarty->assign('step',2);
			$smarty->assign('has_responsible',($has_responsible?true:false));
			$smarty->assign('camp_apply_id', $_COOKIE['badminton_camp_session_id']);
			$smarty->display('camp_apply.tpl');
		}
	}

	elseif ($this->get_id() == 3) {
	  	# amikor nem választott felelős kapcsolattartót

	  	//megnézzük van-e sessionj-e
	  	if (!isset($_COOKIE['badminton_camp_session_id'])) {
			header('Location: /tabor/jelentkezes/1');
		}

		//lekérjük a contact-okat
		$contact_assoc_array = $sql->assoc_array('SELECT * FROM camp_apply_contact WHERE cac_camp_apply_capp_id = ' . $_COOKIE['badminton_camp_session_id']);
		$contacts = array();
		foreach ($contact_assoc_array as $contact_array) {
			$new_contact = new camp_contact();
			$new_contact->set_cc_data_by_id($contact_array['cac_camp_contact_cc_id']);
			$contacts[] = $new_contact;
		}

		$smarty->assign('contacts', $contacts);
		$smarty->assign('step',3);
		$smarty->assign('camp_apply_id', $_COOKIE['badminton_camp_session_id']);
		$smarty->display('camp_apply.tpl');

  	}

  	elseif ($this->get_id() == 4) {
  	  	# tábor adatok megadása

  	  	//megnézzük van-e sessionj-e
	  	if (!isset($_COOKIE['badminton_camp_session_id'])) {
			header('Location: /tabor/jelentkezes/1');
		}

		//lekérjük azokat a táborokat, amikre lehet jelentkezni, és a kezdődátum a mainál később van (>), és nem törölt
		$camp_assoc_array = $sql->assoc_array("SELECT * FROM camp WHERE camp_deleted = 0 AND camp_is_open = 1 AND camp_from > NOW() ORDER BY camp_from ASC;");

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

		$smarty->assign('step',4);
		$smarty->assign('camp_array',$camp_array);
		$smarty->assign('camp_apply_id', $_COOKIE['badminton_camp_session_id']);
		$smarty->display('camp_apply.tpl');

  	}

  	elseif ($this->get_id() == 5) {
  		# visszaigazoló szöveg

  		//megnézzük van-e sessionj-e
	  	if (!isset($_COOKIE['badminton_camp_session_id']) || empty($_COOKIE['badminton_camp_session_id'])) {
			header('Location: /tabor/jelentkezes/1');
		}

  		setcookie('badminton_camp_session_id', null, time()-60*60, '/');
		$smarty->assign('step',5);
		$smarty->display('camp_apply.tpl');

  	}


}

else {

	# REDIRECT
	header("Location: /tabor/jelentkezes/1");




}

?>
