
<?php

//fetch.php
include("database_connection.php");
$empid=1234;
$query = "SELECT * FROM tasks WHERE status=0 AND employee_id=$empid ORDER BY created_at ASC";
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
$total_row = $statement->rowCount();
$output = '
<table class="table table-striped table-bordered" style="height:150px!important; width:400px">
	<tr>
	    <th>Date</th>
		<th>Work List</th>
		<th>Action</th>
	</tr>
';


if($total_row > 0)
{
	foreach($result as $row)
	{	
		if ($row["status"]==0) {
    		$statusput= "<span style='color:red'>Pending</span>
    		<br><button type='button' name='start' class='btn btn-success btn-xs start' id=".$row["id"].">Start Now</button>";
    		}
		elseif ($row["status"]==1) {
			$statusput= "<span style='color:teal'>Running...</span>
			<br><button type='button' name='stop' class='btn btn-danger btn-xs stop' id=".$row["id"].">Stop Work</button>";
		}
		elseif ($row["status"]==2) {
			$statusput= "<span style='color:green'>Completed</span>";
		}
		elseif ($row["status"]==3) {
			$statusput= "End";
		};

		$output .= '
		<tr>
		    <td width="30%">'.$row["created_at"].'</td>
			<td style="width: 100px">'.$row["details"].'</td>
			<td width="10%" style="display:inline">
			    <button style="margin:5px;" type="button" name="stop" class="btn btn-success btn-xs stop" id="'.$row["id"].'"><i class="fa fa-check"></i></button>
				<button style="margin:5px;" type="button" name="edit" class="btn btn-primary btn-xs edit" id="'.$row["id"].'"><i class="fa fa-edit"></i> </button>
				<button type="button" name="delete" class="btn btn-danger btn-xs delete" id="'.$row["id"].'"><i class="fa fa-trash"></i></button>
			</td>			
		</tr>
		';
	}
}
else
{
	$output .= '
	<tr>
		<td colspan="4" align="center">Data not found</td>
	</tr>
	';
}
$output .= '</table>';
echo $output;
?>