<?php
/**
 * BIS Campaign - logout (no WFM/telephony dependencies).
 */
session_start();

include __DIR__ . "/config/web_mysqlconnect.php";

if (isset($_SESSION['database']) && isset($_SESSION['userid'])) {
    $vuserid = $_SESSION['userid'];
    $logintime = date("Y-m-d H:i:s");

    if (!empty($_SESSION['SNo']) && !empty($_SESSION['logged'])) {
        $timep = date("Y-m-d H:i:s");
        mysqli_query(
            $link,
            "UPDATE $db.logip SET TimePeriod='$timep' WHERE SNo='" . $_SESSION['SNo'] . "' AND UserName='" . $_SESSION['logged'] . "' AND TimePeriod IS NULL"
        );
    }

    mysqli_query(
        $link,
        "UPDATE $db.uniuserprofile SET login_status='offline', login_datetime='$logintime' WHERE AtxUserID=$vuserid"
    );
}

session_destroy();
header("Location: web_login.php");
exit;
