<?php

	require_once('../libs/Ultraviolet.php');

	require_once('../libs/Database.php');

	require_once('../libs/AdminFunctions.php');
	
	require_once('../libs/SimpleImage.php');
	
	require_once('../libs/FileUpload.php');

	

	$database =& DatabaseConnect::getInstance();

	$functions =& AdminFunctions::getInstance();

	$database->query("SET CHARACTER SET utf8");



	for($i = 0; $i < count($_POST); $i++):

		${key($_POST)} = $_POST[key($_POST)];

		next($_POST);	

	endfor;
	
	$database->setBareQuery("SELECT name FROM project WHERE id = '$project'");
	
	$projectname = $database->loadResultArray(0);
	
	$tempfrom = explode('/', $datefrom);
	
	$datefrom = $tempfrom[2].'-'.$tempfrom[0].'-'.$tempfrom[1];
	
	$tempto = explode('/', $dateto);
	
	$dateto = $tempto[2].'-'.$tempto[0].'-'.$tempto[1];
	
	$duration = $hours + ($minutes/60);
	
	$database->setBareQuery("SELECT id FROM task WHERE user = '$user' AND project = '$project' and (datefrom BETWEEN '$datefrom' AND '$dateto' OR dateto  BETWEEN '$datefrom' AND '$dateto' )");
	
	$checkid = $database->loadResultArray(0);
	
	if(count($checkid) == 0):
	
		if($database->query("INSERT INTO task(project, user, duration, datefrom, dateto) VALUES('$project', '$user', '$duration', '$datefrom', '$dateto')")):
	


?>

<div id="insert-notice-success">Uspešan unos:

<p>Korisnik <?=$user?>, <?=$duration?> radnih sati na projektu <?=$projectname[0]?> od <?=$datefrom?> do <?=$dateto?></p>


</div>
		
<?php


		else:

			echo "<div id='insert-notice-success'>".mysql_errno()." ".mysql_error()."</div>";

		endif;
		
		else:

?>

<div id="insert-notice-alert">

<p>Korisnik: <?=$user?> već ima unete radne sate na projektu <?=$projectname[0]?> u izabranom periodu</p>

</div>

<?php endif; ?>

	


	

