<?php

# HA NINCS ID, AKKOR EDZÉSLISTA
# HA VAN ID, AKKOR EDZÉS ADATAINAK SZERKESZTÉSE/MEGTEKINTÉSE

if ($this->is_id()) {

	# ADOTT EDZÉS ADATAINAK MEGJELENÍTÉSE
	//training adatok
	$training_data_query = "SELECT * FROM training WHERE tr_id = " . $this->get_id();
	$training_data_assoc_array = $sql->assoc_array($training_data_query);
	$smarty->assign('training_data', $training_data_assoc_array[0]);
	//TRAINING TYPE ARRAY
	$training_type_query = "SELECT * FROM training_type WHERE trt_deleted = 0 ORDER BY trt_name ASC;";
	$training_type_assoc_array = $sql->assoc_array($training_type_query);
	$smarty->assign("training_type_assoc_array", $training_type_assoc_array);
	//COACH ARRAY
	$coach_data_query = "SELECT * FROM user_coach WHERE ua_deleted = 0 ORDER BY ua_id ASC;";
	$coach_data_assoc_array = $sql->assoc_array($coach_data_query);
	$coach_array = array();
	foreach ($coach_data_assoc_array as $coach_data) {
		$new_coach = new user();
		$new_coach->set_user_data_by_id($coach_data['ua_id']);
		$coach_array[] = $new_coach;
	}
	//TRAINING-COACH ARRAY
	$trc_query = "SELECT * FROM training_coach WHERE trc_training_tr_id = " . $this->get_id();
	$trc_coaches = array();
	$trc_assoc_array = $sql->assoc_array($trc_query);
	foreach ($trc_assoc_array as $trc_data) {
		$new_coach = new user();
		$new_coach->set_user_data_by_id($trc_data['trc_coach_uc_id']);
		$trc_coaches[] = $new_coach;
	}


	$smarty->assign("coach_data_assoc_array", $coach_data_assoc_array);
	$smarty->assign("coach_array", $coach_array); //összes coach
	$smarty->assign("trc_coaches", $trc_coaches); //csak a bejelölt coach coach
	$smarty->assign("tr_id", $this->get_id()); //aktualis training id


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

}

else {

	$traning_list_query = "SELECT * FROM training WHERE tr_deleted = 0 ORDER BY tr_date DESC;";
	$training_list_assoc_array = $sql->assoc_array($traning_list_query);

	$training_array = array();
	foreach ($training_list_assoc_array as $training_list_array) {
		$training = new training();
		$training->set_training_data_by_id($training_list_array['tr_id']);
		$training_array[] = $training;
	}
	//var_dump($traning_array);
	$smarty->assign('edit', $tpl);
	$smarty->assign("training_array", $training_array);
	$smarty->display("training_list.tpl");


}





?>
