<?php

function pridajCvicenie($db,$owner, $kondicka, $taktika, $technika, $popis, $nazov ){
	$sql="INSERT INTO `cvicenia` (
			`users_id` ,
			`kondicka` ,
			`technika` ,
			`taktika` ,
			`popis` ,
			`time` ,
			`nazov`
			)
			VALUES (
			?, ?, ?, ?, ?, ?, ?);
			";
	$db->queryWithBids($sql, array($owner, $kondicka, $technika, $taktika, $popis, date('Y-m-d H:i:s'), $nazov));
	return $db->insertID();
}

function getCviceniaKlubu($db, $idKlub){
	$sql='	Select *
			FROM `cvicenia`
			WHERE `users_id`
			IN (
				SELECT id
				FROM users
				WHERE klub_id =?
			)';
	$a= $db->queryWithBids($sql, array($idKlub));
	return $a->fetchAll();
}



$oForm = new cForm();


$ret= '';

$ret .= $oForm->submitButton("zadaj cvicenie", "pridaj nove cvicenie", False, "pridajC");
//TODO vypis cviceny naseho klubu

$form = '<div id="sliderKondicka"> </div>';
$form .= '<form method="post" action="'.$this->oUrl->href().'" enctype="multipart/form-data"'.'>'."\n";
$form .= $ret;
$form .= '</form>'."\n"	;
$form .='<a href="#" onclick="zobrazHladanie(); return false;"> <i id="fliterTrigger" class="icon-filter icon-3x"></i></a> <div id="filter" ><h2> Hladaj v cviceniach </h2>';

$ret= '';

if (isset($_POST['pridajC']) && !empty($_POST['pridajC'])) {
	$pridaj = '';
	$pridaj.= '<form method="post" action="'.$this->oUrl->href().'" enctype="multipart/form-data"'.'>'."\n";
	$pridaj .= $oForm->inputBox("nazov", "nazov", 164);
	$pridaj .= $oForm->inputBox("pravidla hry/cvicenia", "popis", 164);
	$pridaj .= $oForm->inputBox("fyzicka narocnost", "kondicka", 164);
	$pridaj .= $oForm->inputBox("taktika narocnost", "taktika", 164);
	$pridaj .= $oForm->inputBox("technika narocnost", "technika", 164);
	$pridaj .= $oForm->submitButton("zadaj cvicenie", "pridaj nove cvicenie", False, "pridajC");
	$pridaj .= '</form>'."\n";
	$pridaj .='<a href="javascript:history.go(-1);"><i id="backTrigger" class="icon-caret-left icon-3x"></i></a>';
	echo $pridaj;
}else {
	
	echo $form;

$hladaj ='';
$hladaj .='<form method="post" action="'.$this->oUrl->href().'" onsubmit="najdiCviky(); return false;"  enctype="multipart/form-data"'.'>'."\n";
$hladaj .= $oForm->inputBox("nazov", "nazovH", 164);
$hladaj .= $oForm->inputBox("fyzicka narocnost", "kondickaH", 164);
$hladaj .= $oForm->inputBox("taktika narocnost", "taktikaH", 164);
$hladaj .= $oForm->inputBox("technika narocnost", "technikaH", 164);
$hladaj .= $oForm->submitButton("hladaj", "hladajH", False, "hladajH");
$hladaj .= '</form></div>'."\n";

echo $hladaj;
$cviky= getCviceniaKlubu($this->oDb, $_SESSION['klubId']);

echo '<div id="cviky">';
echo '<img id="ajaxLoad" alt="ajaxLoad" src="/images/icons/ajax.gif"> ';
foreach ($cviky as &$a){
	echo '<div class="cvik">';
	echo '<h3><a href="#" onclick=\'$(this).parent().parent().find("p").toggle(); return false;\' return false;" >'.$a['nazov'].'</a></h3>';
	echo '<span class="green">kondícia:'.$a['kondicka'].'</span> , <span class="fial">taktika:'.$a['taktika'].'</span> ,<span class="zlta">technika:'.$a['technika'].'</span> ';
	echo '<p> Znenie cvičenia:'.$a['popis'].'</p>';
	echo '</div>';
}
echo '</div>';
}

/*
 * TODO spravit poriadnu kontrolu
*/
if (isset($_POST['kondicka']) ) {
	pridajCvicenie( $this->oDb, $this->oSession->idUser,  $_POST['kondicka'],  $_POST['taktika'], $_POST['technika'],  $_POST['popis'],$_POST['nazov'] );
}
?>
<script>
function zobrazHladanie(){
	
	if ($('#filter').css("display")=="none") 
			$('#cviky').css('width','55%');
	else 	
		$('#cviky').css('width','100%');

	$('#filter').slideToggle('fast');
}

$(function() {
	kontrolaFloat("#kondickaH");
	kontrolaFloat("#taktikaH");
	kontrolaFloat("#technikaH");

	kontrolaFloat("#kondicka");
	kontrolaFloat("#taktika");
	kontrolaFloat("#technika");
	});
</script>
