
<?php include('../config/dbcon.php'); ?>
<!DOCTYPE html>
<html>
<head>
    <title>Edit Timesheet Entry</title>
</head>
<body>
    <h2>Edit Timesheet Entry</h2>

    <form method="post">
        <!-- Date Input -->
        <div class="form-group">
            <label for="tentryDate">Date:</label>
            <input type="date" class="form-control" id="tentryDate" name="tentryDate" value="<?php echo $tentryDate; ?>">
        </div>

        <!-- Client Dropdown (similar to the one in timesheet_entry.php) -->
        <!-- Project Dropdown (similar to the one in timesheet_entry.php) -->
        <!-- Milestone Dropdown (similar to the one in timesheet_entry.php) -->

        <!-- Hours Input -->
        <div class="form-group">
            <label for="hours">Hours:</label>
            <input type="text" class="form-control" id="hours" name="hours" value="<?php echo $hours; ?>">
        </div>

        <!-- Submit Button -->
        <button type="submit" class="btn btn-primary">Update</button>
    </form>

    <a href="timesheet-view.php">Back to Timesheet View</a>
</body>
</html>

<?php 

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    // Retrieve form data
    $newTentryDate = $_POST['tentryDate'];
    $newClientID = $_POST['clientID'];
    $newProjectID = $_POST['projectID'];
    $newMilestoneID = $_POST['milestoneID'];
    $newHours = $_POST['hours'];

    // Perform validation on the form data (e.g., check for empty fields, validate date format)

    // Update the timesheet entry in the database
    $updateQuery = "UPDATE timesheet SET
                    tentryDate = '$newTentryDate',
                    clientID = '$newClientID',
                    projectID = '$newProjectID',
                    milestoneID = '$newMilestoneID',
                    hrs = '$newHours'
                    WHERE timesheetID = '$timesheetID' AND userID = '$userID'";

    if (mysqli_query($conn, $updateQuery)) {
        // Successful update, redirect to timesheet view
        header('Location: timesheet-view.php');
        exit;
    } else {
        // Handle database error (e.g., display an error message)
        $errorMessage = "Error updating timesheet entry: " . mysqli_error($conn);
    }
}


?>