<?php
session_start();
include '../database/db.php';

if (!isset($_SESSION['user_id'])) {
    header("Location: ../users/login.php");
    exit();
}

$user_id = $_SESSION['user_id'];

if (isset($_GET['task_id'])) {
    $task_id = $_GET['task_id'];

    // Droši dzēš tikai uzdevumus, kas pieder lietotājam
    $stmt = $pdo->prepare("DELETE FROM tasks WHERE id = ? AND user_id = ?");
    $stmt->execute([$task_id, $user_id]);
}

// Atgriezties atpakaļ uz uzdevumu lapu
header("Location: tasks.php");
exit();
?>