<?php
include(''. $config['LocalPath'] . '/includes/.sql_con.php');

//if(isset($_POST['task_id'])){

//	$insert_task_id=$_POST['task_id'];
//	$insert_job_id=$_POST['job_id'];
//	$insert_due_date=$_POST['due_date'];
//	$insert_date_completed=$_POST['date_completed'];
//	$insert_job_status_id=$_POST['job_status_id'];
//	$insert_note=$_POST['note'];
//	$insert_user=$_POST['user'];

//		$complete_task ="INSERT INTO `JOB_LOGGING` (TASK_ID, JOB_ID, DUE_DATE, DATE_COMPLETED, STATUS_ID, NOTE, USER) VALUES ('$insert_task_id' , '$insert_job_id', '$insert_due_date', '$insert_date_completed', '$insert_job_status_id', '$insert_note', '$insert_user')";
//                                        mysql_query($complete_task)or die ('Add Failed</br>'.mysql_error());

//		$update_task_status="UPDATE `TASK` SET JOB_STATUS_ID = '1' WHERE ID=$insert_task_id";
//					mysql_query($update_task_status)or die ('Failed to update</br>'.mysql_error());
//}

?>
<div class="row">
  <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
    <div class="card card-mini">
      <div class="card-header">
        <div class="card-title"><b>All Tasks</b></div>
        <ul class="card-action">
          <li>
            <a href="/">
              <i class="fa fa-refresh"></i>
            </a>
          </li>
        </ul>
      </div>
      <div class="card-body no-padding table-responsive">
        <table class="table card-table">
          <thead>
            <tr>
              <th><b>Asset</b></th>
              <th><b>Task</b></th>
	      <th class="right"><b>Schedule</b></th>
              <th><b>Task Status</b></th>
		<th><b>Complete Task</b></th>
            </tr>
          </thead>
          <tbody>
<?php


$tasks_result = mysql_query('SELECT t.JOB_ID as job_id, t.ID as task_id, t.SERVICE_NAME AS Device, j.JOB_NAME AS Task, j.SOP_URL as sop_url,  js.DESCRIPTION AS Task_Status, t.JOB_STATUS_ID AS job_status, s.DESCRIPTION as schedule FROM TASK AS t INNER JOIN JOB as j on t.JOB_ID=j.JOB_ID INNER JOIN JOB_STATUS_ID AS js on t.JOB_STATUS_ID= js.ID INNER JOIN SCHEDULE_ID as s on t.SCHEDULE_ID= s.ID where t.JOB_STATUS_ID ="2" OR t.JOB_STATUS_ID ="4" or t.JOB_STATUS_ID ="5" or t.JOB_STATUS_ID ="6" or t.JOB_STATUS_ID ="7" or t.JOB_STATUS_ID ="8"');

while ($row=mysql_fetch_array($tasks_result)){
	$device_name=$row['Device'];
	$task=$row['Task'];
	$task_sop=$row['sop_url'];
	$t_status=$row['Task_Status'];
	$task_id=$row['task_id'];
	$job_id=$row['job_id'];
	$job_status_id=$row['job_status'];
	$job_schedule=$row['schedule'];

	
?>
            <tr>
              <td><?php echo $device_name;?></td>
              <td><a  target="_blank" href="<?php echo $task_sop;?>"><?php echo $task;?></a></td>
	      <td class="right"><?php echo $job_schedule;?></td>
	      <td><?php echo $t_status;?> </td>
		<td><form class="form form-horizontal" action="<?php echo $config['URL'];?>/complete-task.php" method="post" id="form">
			<input type="hidden" name="task_id" value="<?php echo $task_id;?>">
			<input type="hidden" name="task_name" value="<?php echo $task;?>">
			<input type="hidden" name="device_name" value="<?php echo $device_name;?>">
			<input type="hidden" name="job_id" value="<?php echo $job_id;?>">
			<input type="hidden" name="due_date" value="01/01/2017">
			<input type="hidden" name="date_completed" value="<?php echo date("Y-m-d H:i:s") ;?>">
			<input type="hidden" name="job_status_id" value="1">
			<input type="hidden" name="note" value="">
			<input type="hidden" name="user" value="<?php echo $_SESSION['displayname'];?>">
<?php
	if($job_status_id=="8"){
		?>
			<input type="hidden" name="inp" value="1">
			<button type="submit" class="btn">Continue Task</button>
		<?php
}
else{
?>
 			<input type="hidden" name="inp" value="0">
			<button type="submit" class="btn btn-primary">Start Task</button>
<?php
}
?>
		</form>
		</td>	
            </tr>
	
<?php
}
?>
          </tbody>
        </table>
      </div>
    </div>
  <!--</div>
</div>-->
