<?php
session_start();
if (!isset($_SESSION['user_id']) || !isset($_SESSION['name'])) exit;

$host = 'localhost';
$user = 'majapahi_omnich';
$pass = 'A1b2c3d4.,@';
$db   = 'majapahi_omnich';
$conn = new mysqli($host, $user, $pass, $db);

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $phone = $conn->real_escape_string($_POST['phone']);
    $cs_name = $conn->real_escape_string($_SESSION['name']); // Ambil nama CS yang sedang login

    if (!empty($phone)) {
        // Set nama CS ke kontak tersebut
        $sql = "UPDATE contacts SET assigned_to = '$cs_name' WHERE phone_number = '$phone'";
        if ($conn->query($sql)) {
            echo "success";
        } else {
            echo "error";
        }
    }
}
?>
