<?php
require_once __DIR__ . '/../_pdo_db_connect.php';
require_once __DIR__ . '/../_response.php';
require_once __DIR__ . '/../_middleware/auth_check.php';
$payload = require_auth();
$page = max(1,(int)($_GET['page']??1)); $per = min(100,(int)($_GET['per']??20)); $off = ($page-1)*$per;
$pdo = get_db();
$sql = 'SELECT * FROM sd_tasks WHERE 1=1';
$params = [];
if (!empty($_GET['assigned_to'])){ $sql .= ' AND assigned_to=:a'; $params[':a']=$_GET['assigned_to']; }
$sql .= ' ORDER BY due_date DESC LIMIT :off,:per';
$stmt = $pdo->prepare($sql);
$stmt->bindValue(':off',$off,PDO::PARAM_INT); $stmt->bindValue(':per',$per,PDO::PARAM_INT);
foreach($params as $k=>$v) $stmt->bindValue($k,$v);
$stmt->execute();
json_res(['data'=>$stmt->fetchAll()]);
