<?php
// Koneksi ke database
    $servername = "localhost";
    $username = "zonb9946_weliington";
    $password = "#Bismillah16";
    $dbname = "zonb9946_email";

$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$data = array();

$sqlEmailReceiving = "SELECT COUNT(*) as count FROM tbl_securitymail WHERE LOG_RECEIVE IS NOT NULL";
$sqlOpenMail = "SELECT COUNT(*) as count FROM tbl_securitymail WHERE DATE_FORMAT(LOG_OPENEMAIL, '%Y-%m-%d %H:%i') > DATE_FORMAT(LOG_RECEIVE, '%Y-%m-%d %H:%i')";
$sqlClickLink = "SELECT COUNT(*) as count FROM tbl_securitymail WHERE LOG_OPENLINK IS NOT NULL";
$sqlOpenWeb = "SELECT COUNT(*) as count FROM tbl_securitymail WHERE LOG_OPENWEB IS NOT NULL";

$data['emailReceiving'] = $conn->query($sqlEmailReceiving)->fetch_assoc()['count'];
$data['openMail'] = $conn->query($sqlOpenMail)->fetch_assoc()['count'];
$data['clickLink'] = $conn->query($sqlClickLink)->fetch_assoc()['count'];
$data['openWeb'] = $conn->query($sqlOpenWeb)->fetch_assoc()['count'];

$conn->close();

echo json_encode($data);
?>
