<?php
declare(strict_types=1);
if (session_status()===PHP_SESSION_NONE) session_start();
require_once __DIR__.'/../includes/db.php';
require_once __DIR__.'/../includes/auth.php';

require_role(['super_admin','admin','branch_admin']);
header('Content-Type: text/plain; charset=utf-8');

$st=$mysqli->prepare("UPDATE lms_submissions
                      SET workflow_status='released',
                          release_mode='immediate',
                          release_at=NOW(),
                          updated_at=NOW()
                      WHERE workflow_status IN ('coord_approved','approved')
                        AND release_mode='on_date'
                        AND release_at <= NOW()");
$st->execute();
echo "Released rows: ".$st->affected_rows."\n";
