<?php

// Get Hours History For Project
$query = 'SELECT * FROM projectTime WHERE projectID=' . $editID .' AND timeDisp=1 ORDER BY timeDate DESC, timeID DESC'; 
$result = $con->query($query);
$hoursBillable = ''; 
$hoursTotal = ''; 
$odd = true;
while ($row=$result->fetch_array(MYSQLI_ASSOC)) {
	$datCurrent_name = "datCurrent_". $row['timeID'];
	$datString_name = "dat_". $row['timeID'];
	$timeCurrent_name = "timeCurrent_". $row['timeID'];
	$timeString_name = "time_". $row['timeID'];
	$taskCurrent_name = "taskCurrent_". $row['timeID'];
	$taskString_name = "task_". $row['timeID'];
	$descCurrent_name = "descCurrent_". $row['timeID'];
	$descString_name = "desc_". $row['timeID'];
	$datString_name = "dat_". $row['timeID'];
	$invCurrent_name = "invCurrent_". $row['timeID'];
	$invString_name = "inv_". $row['timeID'];
	$ppInvCurrent_name = "ppInvCurrent_". $row['timeID'];
	$ppInvString_name = "ppInv_". $row['timeID'];
	$ppPaidCurrent_name = "ppPaidCurrent_". $row['timeID'];
	$ppPaidString_name = "ppPaid_". $row['timeID'];
	$billCurrent_name = "billCurrent_". $row['timeID'];
	$billString_name = "bill_". $row['timeID'];
	
	$delString_name = "delete_". $row['timeID'];
	
	if ($row['timeInvoiced'] == 1)
		$invCheck = ' checked';
	else 
		$invCheck = '';
	
	if ($row['ppInv'] == 1)
		$ppInvCheck = ' checked';
	else 
		$ppInvCheck = '';
	
	if ($row['ppPaid'] == 1)
		$ppPaidCheck = ' checked';
	else 
		$ppPaidCheck = '';
			
	if ($row['billable'] == 1)
		$billCheck = ' checked';
	else 
		$billCheck = '';
	
	$tasks = getTasks($projectID, $row['taskID'],$con);
	if (empty($tasks))
		$tasks = '<a href="?adminType=projectTask&adminAct=edit&editID=' . $projectID . '" class="mgmtBtn auto small">Add Tasks</a>'; 
	else 
		$tasks = '<select name="'. $taskString_name .'" class="taskSelect">'. $tasks .'</select>';
		
	$timeInfo .= '<tr>
						<td>
							<input type="hidden" name="'. $datCurrent_name .'" value="'. $row['timeDate'] .'" />
							<input type="text" name="'. $datString_name .'" value="'. $row['timeDate'] .'" class="dateField datepicker" />
						</td>
						<td>
							<input type="hidden" name="'. $timeCurrent_name .'" value="'. $row['timeAmount'] .'" />
							<input type="number" pattern="^\d+(\.|\,)\d{2}$" step="0.25" name="'. $timeString_name .'" value="'. $row['timeAmount'] .'" class="timeField" />
						</td>
						<td>
							<input type="hidden" name="'. $taskCurrent_name .'" value="'. $row['taskID'] .'" />'. $tasks .' 
						</td>
						<td>
							<input type="hidden" name="'. $descCurrent_name .'" value="'. $row['timeDesc'] .'" />
							<textarea name="'. $descString_name .'" value="'. $row['timeDesc'] .'" class="descAdmin">'. $row['timeDesc'] .'</textarea>
						</td>
						<td style="text-align: center">
							<label class="small">Billable</label>
							<input type="hidden" name="'. $billCurrent_name .'" value="'. $row['billable'] .'" />
							<input type="checkbox" name="'. $billString_name .'" value="1"'. $billCheck .' />
						</td>
						<td style="text-align: center">
							<label class="small">Invoiced</label>
							<input type="hidden" name="'. $ppInvCurrent_name .'" value="'. $row['ppInv'] .'" />
							<input type="checkbox" name="'. $ppInvString_name .'" value="1"'. $ppInvCheck .' />
						</td>
						<td style="text-align: center">
							<label class="small">Paid</label>
							<input type="hidden" name="'. $ppPaidCurrent_name .'" value="'. $row['ppPaid'] .'" />
							<input type="checkbox" name="'. $ppPaidString_name .'" value="1"'. $ppPaidCheck .' />
						</td>
						<td style="text-align: center">
							<label class="small">Delete</label>
							<input type="checkbox" name="'. $delString_name .'" value="0" />
						</td>
					</tr>';	
	
	$hoursTotal = $hoursTotal + $row['timeAmount'];
	if ($row['billable'] == 1)
		$hoursBillable = $hoursBillable + $row['timeAmount'];
}

?>