<?php
require_once __DIR__.'/../../config/auth.php';require_once __DIR__.'/_tareas.php';$id=(int)($_GET['id']??0);$s=$conn->prepare('SELECT a.*,t.responsable_id,t.creado_por_usuario_id FROM tarea_adjuntos a JOIN tareas t ON t.id=a.tarea_id WHERE a.id=?');$s->bind_param('i',$id);$s->execute();$a=$s->get_result()->fetch_assoc();if(!$a||!tareas_puede_ver($conn,$a,tareas_es_admin($conn),tareas_colaborador_id($conn))){http_response_code(404);exit;}$ruta=dirname(__DIR__,2).'/uploads/tareas/'.$a['nombre_archivo'];if(!is_file($ruta)){http_response_code(404);exit;}header('Content-Type: '.($a['mime']?:'application/octet-stream'));header('Content-Disposition: attachment; filename="'.rawurlencode($a['nombre_original']).'"');header('Content-Length: '.filesize($ruta));readfile($ruta);exit;
