<?php
include "check_login.php";
include "dbcon.php";

$project_id = (int)$_POST['project_id'];
$phase_id   = (int)$_POST['phase_id'];
$message    = trim($_POST['message']);

$admin_id = $_SESSION['admin_id'];

if($message=='') exit;

/* Insert message */
mysqli_query($conn,"
    INSERT INTO phase_messages
    (project_id, phase_id, sender_role, sender_id, message)
    VALUES
    ($project_id, $phase_id, 'admin', $admin_id, '$message')
");

/* 🔔 Notify PM */
mysqli_query($conn,"
    INSERT INTO notifications (role,type,title,message,link)
    VALUES (
        'pm',
        'discussion',
        'New message from Admin',
        'Admin sent a message in phase discussion',
        'pm/phase_work.php?phase_id=$phase_id&project_id=$project_id'
    )
");
