<?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");
	
	$user = 'bata';
	
	$d2 = date("m",strtotime("-1 month"));
	
	$d1 = date("Y",strtotime("-1 month"));
	
	$fd =  $d1.'-'.$d2;
	
	$daynum = cal_days_in_month(CAL_GREGORIAN, $d2, $d1);
	


?>
<title>Znamo šta ste radili prošlog decembra</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">

A:LINK      { 
	text-decoration : none; 
	font-weight: normal;
	color: #2b4770;
	font-family:Arial, Helvetica, sans-serif;
	font-size:10px}

A:VISITED {
	text-decoration: none; 
	font-weight: normal; 
	color: #2b4770;
	font-family:Arial, Helvetica, sans-serif;
	font-size:10px}

A:HOVER  { 

	text-decoration : none; 
	font-weight: normal; 
	color: #2b4770;
	font-family:Arial, Helvetica, sans-serif;
	font-size:10px }

A:ACTIVE  {
	text-decoration: none; 
	font-weight: normal; 
	color: #2b4770;
	font-family:Arial, Helvetica, sans-serif;
	font-size:10px }
	
th {
	background:#006;
	color:#fff;
	padding:5px;}
	
td {padding:2px}

.title { background:#CCC; color:#000 }	

.even { background:#a7cfee}

.odd { background:#b6bcc1}

.clients { background:#006; color:#fff}

.weekend { background:#063}

</style>
</head>
<body style=" font-family:Arial, Helvetica, sans-serif">
</body>
<table>

<tr>

<th class="title">Datum</th>
<?php for($i = 0; $i < $daynum; $i++): $currday = $i + 1;?>
<th title="<?=date("d D",strtotime($fd.'-'.$currday))?>"<?php if(date("D", strtotime($fd.'-'.$currday)) == 'Sat' || date("D", strtotime($fd.'-'.$currday)) == 'Sun'){echo ' class="weekend"';}?>><?=$currday?></th>
<?php endfor; $colspan = $i + 1;?>
</tr>

<?php 

$database->setBareQuery("SELECT DISTINCT(t1.name), t1.id FROM client t1, task t2, project t3 WHERE SUBSTRING_INDEX(t2.date, '-', 2) = '".$fd."' AND t2.user = '".$user."' AND t3.parent = t1.id AND t3.id = t2.project ORDER BY t1.name");
$clients = $database->loadResultArray(0);
$cid = $database->loadResultArray(1);
for($i = 0; $i < count($clients); $i++):

?>
<tr class="clients">
<td colspan="<?=$colspan?>"><?=$clients[$i];?></td>





</tr>

<?php 

$database->setBareQuery("SELECT DISTINCT(t1.name), t1.id FROM project t1, task t2 WHERE SUBSTRING_INDEX(t2.date, '-', 2) = '".$fd."' AND t2.user = '".$user."' AND t1.parent = '".$cid[$i]."' AND t1.id = t2.project ORDER BY t1.name");
$projects = $database->loadResultArray(0);
$pid = $database->loadResultArray(1);
for($z = 0; $z < count($projects); $z++):
if($z%2 == 0){ $rowcol = 'even';}else{ $rowcol = 'odd';} 
?>

<tr class="<?=$rowcol?>">
<td><?=$projects[$z];?></td>

<?php 
 for($w = 0; $w < $daynum; $w++): $currday = $w + 1;?>
<td><?php 
$database->setBareQuery("SELECT duration  FROM task WHERE date = '".$fd."-".$currday."' AND user = '".$user."' AND project = '".$pid[$z]."'");
$dur = $database->loadResultArray(0);

echo $dur[0];


?></td>
<?php endfor; ?>




<?php endfor; ?>



</tr>


<?php endfor; ?>



</table>

