| Current Path : /home/emeraadmin/www/4d695/ |
| Current File : /home/emeraadmin/www/4d695/viewunassignedtask.php.tar |
home/emeraadmin/public_html/pages/subcontractor/viewunassignedtask.php 0000644 00000030756 15170147110 0022526 0 ustar 00 <?php
include('head.php');
// Include database connection and TaskService class
require_once '../../Classes/Database.php';
require_once '../../Service/TaskService.php';
require_once '../../Classes/System.php';
// Initialize system and services
$System = new System();
$taskService = new TaskService();
// Define and validate required variables
$currentCompanyId = isset($companyId) ? $companyId : null; // Ensure $companyId is defined
// Check if task ID is provided in URL
if (isset($_GET['id'])) {
$taskId = $System->decryptData($_GET['id']);
$task = $taskService->getTaskById($taskId);
if (!$task) {
echo '<p>Task not found.</p>';
exit();
}
} else {
echo '<p>No task ID provided.</p>';
exit();
}
?>
<div class="main-content">
<div class="container-fluid">
<div class="page-header">
<div class="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 Task</h5>
<span>View details of a task</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="../../index.html"><i class="ik ik-home"></i></a>
</li>
<li class="breadcrumb-item">
<a href="#">Tasks</a>
</li>
<li class="breadcrumb-item active" aria-current="page">View Task</li>
</ol>
</nav>
</div>
</div>
</div>
<!-- New row for buttons and actions -->
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-header">
<div class="card-header-left">
<a href="javascript:history.back()" class="btn btn-outline-primary">Back</a>
</div>
<div class="card-header-right">
<?php if ($task->is_assigned == 1 && $task->assigned_to == $currentCompanyId): ?>
<h3><span class="badge badge-info">This task is already assigned to your company.</span></h3>
<?php else: ?>
<button id="acceptTask" class="btn btn-primary">Accept Task</button>
<?php endif; ?>
</div>
</div>
</div>
</div>
</div>
<!-- Task viewing section -->
<div class="row">
<div class="col-xl-6 col-md-6">
<div class="card">
<div class="card-body">
<div class="row align-items-center mb-30">
<div class="col-md-6">
<table>
<tbody>
<tr>
<td><i class="ik ik-layers icon-large"></i></td>
<td><h3 class="mb-0 fw-700 text-black"><?php echo htmlspecialchars($task->service_name); ?></h3></td>
</tr>
<tr>
<td><i class="ik ik-map-pin icon-large"></i></td>
<td><h5 class="mb-0 fw-500 text-black"><?php echo htmlspecialchars($task->region); ?></h5></td>
</tr>
<tr>
<td><i class="ik ik-calendar icon-large"></i></td>
<td><h5 class="mb-0 fw-500 text-black"><?php echo htmlspecialchars($task->schedule_name); ?></h5></td>
</tr>
<tr>
<td><i class="ik ik-clock icon-large"></i></td>
<td><h5 class="mb-0 fw-500 text-black"><?php echo htmlspecialchars($task->frequency); ?></h5></td>
</tr>
<tr>
<td><i class="ik ik-eye icon-large"></i></td>
<td>
<h2><?php echo ($task->isPublic ? '<span class="badge badge-yellow">Open to accept</span>' : '<span class="badge badge-green">Task Assigned</span>'); ?></h2>
</td>
</tr>
<?php if ($task->is_assigned == 1 && $task->assigned_to == $currentCompanyId): ?>
<tr>
<td><i class="ik ik-user icon-large"></i></td>
<td><h6><span class="badge badge-info">This task is assigned to your company.</span></h6></td>
</tr>
<?php endif; ?>
</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 class="col-md-6">
<?php
// Assuming $task->dates is a JSON string
$datesJson = $task->dates;
// Decode the JSON string to an array
$datesArray = json_decode($datesJson, true);
// Extract the dates and format them for JavaScript
$formattedDates = array_map(function ($dateEntry) {
return $dateEntry['date'];
}, $datesArray);
// JSON encode the array for JavaScript
$jsDates = json_encode($formattedDates);
?>
<div id="datepicker"></div>
<script>
const today = new Date();
console.log(<?php echo $jsDates; ?>);
flatpickr("#datepicker", {
enable: <?php echo $jsDates; ?>,
dateFormat: "Y-m-d",
inline: true,
defaultDate: today,
disableMobile: "false"
});
</script>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="card">
<div class="card-header"><h3>Subtasks</h3></div>
<div class="card-body">
<?php
// Fetch and display subtasks associated with the task
$subtasks = $taskService->getSubtasksByTaskId($taskId);
if ($subtasks) {
echo '<table class="table" id="advanced_table">
<thead>
<tr>
<th>Date</th>
<th>Time</th>
</tr>
</thead>
<tbody>';
foreach ($subtasks as $subtask) {
echo '<tr>
<td>' . htmlspecialchars($subtask->subtask_date) . '</td>
<td>' . ($subtask->subtask_time ? date('h:i A', strtotime($subtask->subtask_time)) : '') . '</td>
</tr>';
}
echo '</tbody></table>';
} else {
echo '<p>No subtasks found for this task.</p>';
}
?>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
console.log('Script block is running.');
var acceptTaskButton = document.getElementById('acceptTask');
if (acceptTaskButton) {
acceptTaskButton.addEventListener('click', function() {
console.log('Accept task button clicked.');
Swal.fire({
title: 'Are you sure?',
text: "Do you want to accept this task?",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, accept it!'
}).then((result) => {
if (result.isConfirmed) {
var xhr = new XMLHttpRequest();
xhr.open('POST', 'accepttask.php', true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
console.log(xhr.responseText);
if (xhr.responseText === 'success') {
Swal.fire(
'Accepted!',
'Task accepted successfully.',
'success'
).then(() => {
window.location.href = 'viewtask.php?id=<?php echo $System->encryptData($taskId); ?>';
});
} else if (xhr.responseText === 'error') {
Swal.fire('Error!', 'An error occurred. Please try again.', 'error');
} else if (xhr.responseText === 'task_not_found') {
Swal.fire('Not Found!', 'Task not found.', 'warning');
} else if (xhr.responseText === 'invalid_data') {
Swal.fire('Invalid Data!', 'Invalid data.', 'warning');
} else if (xhr.responseText === 'invalid_request') {
Swal.fire('Invalid Request!', 'Invalid request.', 'warning');
}
}
};
var taskId = '<?php echo htmlspecialchars($taskId); ?>';
var companyId = '<?php echo htmlspecialchars($currentCompanyId); ?>';
xhr.send('taskId=' + taskId + '&companyId=' + companyId);
}
});
});
} else {
console.error('Accept task button not found.');
}
</script>
<?php include('footer.php'); ?>