| Current Path : /home/emeraadmin/public_html/pages/taskprovider/ |
| Current File : /home/emeraadmin/public_html/pages/taskprovider/viewsubtask.php |
<?php include('head.php'); ?>
<?php
require_once '../../Classes/Database.php';
require_once '../../Service/SubtaskService.php';
require_once '../../Service/UserService.php';
require_once '../../Classes/System.php';
$System = new System();
$subtaskService = new SubtaskService();
$userService = new UserService();
if (!isset($_GET['id'])) {
echo '<p>No subtask ID provided.</p>';
exit;
}
$subtaskId = $System->decryptData($_GET['id']);
// show error if the provided id is not valid with Swal alert
if (!$subtaskId) {
echo '<script>
Swal.fire({
title: "Invalid Subtask ID",
text: "The URL parameter is invalid. Please go back and try again.",
icon: "error",
confirmButtonText: "Ok"
}).then(() => window.location.href = "viewschedules.php");
</script>';
exit;
}
$subtask = $subtaskService->getSubtaskById($subtaskId);
$users = $userService->getAllUsers();
if($subtask->completed){
$submittedLocation = $subtaskService->getSubtaskLocation($subtaskId);
if ($submittedLocation) {
$latitude = $submittedLocation->latitude;
$longitude = $submittedLocation->longitude;
} else {
// Handle the case where location is not found
$latitude = null;
$longitude = null;
// Optionally, display an error message or take other actions
echo "Location not found for the specified subtask.";
}
}
?>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyD9O5PAsTaFPCHlIlM4XSK7ei-gaLMYpzk&callback=initMap" async defer></script>
<div class="main-content">
<div class="container-fluid">
<div class="page-header row align-items-end">
<div class="col-lg-8">
<div class="page-header-title">
<i class="ik ik-layers bg-blue"></i>
<div class="d-inline">
<h5>View Subtask</h5>
<span>View details of a subtask</span>
</div>
</div>
</div>
<div class="col-lg-4">
<nav class="breadcrumb-container" aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="#"><i class="ik ik-home"></i></a></li>
<li class="breadcrumb-item"><a href="#">Subtasks</a></li>
<li class="breadcrumb-item active" aria-current="page">View Subtask</li>
</ol>
</nav>
</div>
</div>
<div class="card">
<div class="card-header d-flex justify-content-between">
<a href="javascript:history.back()" class="btn btn-outline-primary">Back</a>
<div>
</div>
</div>
<div class="card-body">
<div class="row align-items-center mb-30">
<div class="col-md-12">
<table>
<tbody>
<tr>
<td>
<table>
<tbody>
<tr>
<td><i class="ik ik-layers icon-large"></i></td>
<td><h3 class="mb-0 fw-700 text-black"><?php echo $subtask->service_name; ?></h3></td>
</tr>
<tr>
<td><i class="ik ik-calendar icon-large"></i></td>
<td><h5 class="mb-0 fw-500 text-black"><?php echo $subtask->subtask_date ? date('F j, Y', strtotime($subtask->subtask_date)) : 'Not set'; ?></h5></td>
</tr>
<tr>
<td><i class="ik ik-clock icon-large"></i></td>
<!-- Show time in am or pm -->
<td><h5 class="mb-0 fw-500 text-black"><?php echo $subtask->subtask_time ? date('g:i A', strtotime($subtask->subtask_time)) : 'Not set'; ?></h5></td>
</tr>
<tr>
<td><i class="ik ik-user icon-large"></i></td>
<td><h5 class="mb-0 fw-500 text-black"><?php echo date('F j, Y', strtotime($subtask->updated_at)); ?></h5></td>
</tr>
</tbody>
</table>
</td>
<td>
<table>
<tbody>
<tr>
<td><i class="ik ik-check-circle icon-large"></i></td>
<td>
<?php
if ($subtask->ignored) {
echo '<span class="badge badge-yellow">Ignored</span>';
} else {
if ($subtask->completed) {
echo '<span class="badge badge-success">Completed</span> ';
} else {
echo '<span class="badge badge-danger">Not Completed</span>';
}
}
?>
</td>
</tr>
<!-- --><?php //if ($subtask->completed): ?>
<!-- <tr>-->
<!-- <td><i class="ik ik-calendar icon-large"></i></td>-->
<!-- <td><h5 class="mb-0 fw-500 text-black">--><?php //echo $subtask->completed_at; ?><!--</h5></td>-->
<!-- </tr>-->
<!-- --><?php //endif; ?>
<tr>
<td><i class="ik ik-user icon-large"></i></td>
<td>
<?php if ($subtask->assigned): ?>
<span class="badge badge-success">Assigned</span>
<?php else: ?>
<span class="badge badge-danger">Not assigned</span>
<?php endif; ?>
</td>
</tr>
<?php if ($subtask->assigned): ?>
<tr>
<td><i class="ik ik-file-text icon-large"></i></td>
<td><h5 class="mb-0 fw-500 text-black">
<?php echo $subtask->form_submission_id ? '<a href="../completedsubtaskform.php?id=' . $subtask->form_submission_id . '" target="_blank" >View Submitted Form</a>' : 'Not Submitted'; ?>
</h5></td>
</tr>
<?php if ($subtask->completed && property_exists($subtask, 'submitted_by_admin') && $subtask->submitted_by_admin): ?>
<tr>
<td><i class="ik ik-user icon-large"></i></td>
<td><h5 class="mb-0 fw-500 text-black"><span class="badge badge-warning">Marked as completed by admin</span></h5></td>
</tr>
<?php endif; ?>
<?php if ($subtask->form_submission_id): ?>
<tr>
<td><i class="fas fa-calendar-check icon-large"></i></td>
<?php
// Assuming $subtask->completed_at contains the datetime string
$completedAt = $subtask->completed_at;
// Create a new DateTime object with the original datetime
$date = new DateTime($completedAt, new DateTimeZone('UTC'));
// Set the timezone to Sydney
$date->setTimezone(new DateTimeZone('Australia/Sydney'));
// Format the date and time
$formattedDate = $date->format('F j, Y, g:i a');
?>
<td>
<h5 class="mb-0 fw-500 text-black"><?php echo $formattedDate; ?></h5>
</td>
</tr>
<?php endif; ?>
<?php endif; ?>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<style>
table {
width: 100%;
border-collapse: collapse;
}
td {
padding: 10px 15px;
vertical-align: middle;
}
.icon-large {
font-size: 24px;
color: #333;
}
.mb-0 {
margin-bottom: 0;
}
.fw-700 {
font-weight: 700;
}
.fw-500 {
font-weight: 500;
}
.text-black {
color: #000;
}
.badge-success {
background-color: #28a745;
color: #fff;
padding: 5px 10px;
border-radius: 5px;
}
.badge-danger {
background-color: #dc3545;
color: #fff;
padding: 5px 10px;
border-radius: 5px;
}
</style>
</div>
</div>
</div>
</div>
<?php if ($subtask->completed && $latitude !== null && $longitude !== null): ?>
<div class="card">
<div class="card-header d-flex justify-content-between">
<h3>Submitted Location</h3>
</div>
<div class="card-body">
<div id="map"></div>
</div>
</div>
<script>
function initMap() {
// Replace these PHP variables with actual PHP values
var latitude = <?php echo $latitude; ?>; // PHP variable for latitude
var longitude = <?php echo $longitude; ?>; // PHP variable for longitude
// Create a map centered at a specific location
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: latitude, lng: longitude},
zoom: 12 // Adjust zoom level as needed
});
// Add a marker at the specified location
var marker = new google.maps.Marker({
position: {lat: latitude, lng: longitude},
map: map,
title: 'Hello World!' // Marker tooltip (optional)
});
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyD9O5PAsTaFPCHlIlM4XSK7ei-gaLMYpzk&callback=initMap">
</script>
<?php endif; ?>
</div>
</div>
<?php include('footer.php'); ?>