<?php
include "check_login.php";
include "dbcon.php";
if($_POST['action'] == 'reject'){

$action     = $_POST['action'];
$phase_id   = $_POST['phase_id'];
$project_id = $_POST['project_id'];

    $remark = mysqli_real_escape_string($conn, $_POST['remark']);

    if(trim($remark) == ''){
        die("Remark required");
    }

    mysqli_query($conn,"
        UPDATE project_phases
        SET status='correction',
            admin_remark='$remark'
        WHERE id=$phase_id
    ");
        mysqli_query($conn,"
        INSERT INTO phase_timeline
        (project_id, phase_id, action,remark)
        VALUES
        ($project_id, $phase_id, 'rejected','$remark')
    ");

    mysqli_query($conn,"
        INSERT INTO notifications (role,type,title,message,link)
        VALUES (
            'pm',
            'phase',
            'Phase Needs Correction',
            'Admin remarks: $remark',
            'phase_work.php?phase_id=$phase_id&project_id=$project_id'
        )
    ");
       header("Location: phase_review.php?phase_id=$phase_id&project_id=$project_id&reject=1");
    exit;
}

?>