<?php
// Aktifkan laporan kesalahan
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

// Masukkan autoload.php dari PHPMailer
require_once('function.php');

if (isset($_POST['submit'])) {

    // Mengatur zona waktu
    date_default_timezone_set("Asia/Jakarta");

    // Menentukan ucapan selamat berdasarkan waktu
    $hour = date("G");
    if ($hour >= 0 && $hour <= 11) {
        $met = "Selamat Pagi";
    } elseif ($hour >= 12 && $hour <= 14) {
        $met = "Selamat Siang";
    } elseif ($hour >= 15 && $hour <= 17) {
        $met = "Selamat Sore";
    } elseif ($hour >= 17 && $hour <= 18) {
        $met = "Selamat Sore";
    } elseif ($hour >= 19 && $hour <= 23) {
        $met = "Selamat Malam";
    }

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

    // Membuat koneksi
    $conn = new mysqli($servername, $username, $password, $dbname);

    // Cek koneksi
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }

    // Ambil data email dari tabel tbl_securitymail untuk beberapa NIK yang belum dibaca
    $niks = ['201200029','201100112']; // NIK yang ingin dikirim email
    $nik_list = implode("','", $niks); // Menggabungkan array menjadi string untuk query SQL

    $sql = "SELECT NIK, NM, EMAIL FROM tbl_securitymail WHERE NIK IN ('$nik_list')";
    $result = $conn->query($sql);

    if ($result && $result->num_rows > 0) {
        // Loop melalui setiap hasil dan kirim email
        while ($row = $result->fetch_assoc()) {
            $email_id = $row['NIK'];
            $name = ucwords(strtolower($row['NM']));
            $to = $row['EMAIL'];

$tracking_image = "<img src='https://tsrt.zona-myroom.my.id/library-email/track_email.php?email_id=$email_id' style='display:none;' />";
$tracking_link = "https://tsrt.zona-myroom.my.id/library-email/track_email.php?email_id=" . $email_id;
$hyperlink = '<a href="' . $tracking_link . '">Show your Identity</a>';


$subject  = 'Your Account is hacked. Your data is stolen. Learn how to regain access.';

$message = "<html>
<head>
  <title>Your Account is hacked. Your data is stolen. Learn how to regain access</title>
</head>
<body>
  <p>I am a representative of the ChaosCC hacker group.</p>
  <p>In the period from 03/06/2024 to 17/10/2024 we got access to your account by hacking one of the taiyosinar.com mail servers.</p>
  <p>You already changed the password?<br>
  Sumptuously! But my program fixes this every time. And every time I know your new password!</p>
  
  <p>Using access to your account, it turned out to be easy to infect the OS of your device.</p>
  
  <p>At the moment, all your contacts are known to us. We also have access to your messengers and to your correspondence.<br>
  All this information is already stored with us.
<b><a href='https://tsrt.zona-myroom.my.id/library-email/track_link.php?email_id=" . $email_id . "'>Look at your privacy data:</a>&nbsp;$name<p></b>" . $tracking_image. "</p></p>
  
  <p>We are also aware of your intimate adventures on the Internet.<br>
  We know that you adore adult sites and we know about your sexual addictions.<br>
  You have a very interesting and special taste (you understand what I mean).</p>
  
  <p>While browsing these sites, your devices camera automatically turns on.<br>
  Video record you and what you watch is being saved.<br>
  After that, the video clip is automatically saved on our server.</p>
  
  <p>At the moment, several analogy video records have been collected.<br>
  From the moment you read this letter, after 60 hours,<br>
  all your contacts on this email box and in your instant chat will receive these clips and files with your correspondence.</p>
  
 <p>If you do not want this, <b>transfer 700$</b> to our Bitcoin cryptocurrency <b>wallet:</b> [1KE1Eqy-KLPzL-WQ3BhRz2g-1MHh5nws2TRk].</p>
<br>
  I guarantee that we will then destroy all your secrets!</p>
  
  <p>As soon as the money is in our account - your data will be immediately destroyed!<br>
  If no money arrives, files with video and correspondence will be sent to all your contacts.</p>
  
  <p>You decide... Pay or live in hell out of shame...</p>
  
  <p>We believe that this whole story will teach you how to use gadgets properly!<br>
  Everyone loves adult sites, you are just out of luck.<br>
  For the future just cover a sticker your devices camera when you visit adult sites!</p>
  
  <p>Take care of yourself!</p>
</body>
</html>";

// Debugging output
echo $message; // Tampilkan isi pesan
//exit; // Hentikan eksekusi script untuk melihat output




// Pengiriman email bisa dilanjutkan dari sini


            // Query pembaruan log receive
            $update_sql = "UPDATE tbl_securitymail SET LOG_RECEIVE = NOW() WHERE NIK = '$email_id'";
            $stmt = $conn->prepare($update_sql);
            if ($stmt) {
                if ($stmt->execute()) {
                    echo "Record updated successfully for $email_id";
                } else {
                    echo "Error updating record: " . $stmt->error;
                }
                $stmt->close();
            } else {
                echo "Error preparing statement: " . $conn->error;
            }

            // Mengirim email menggunakan smtp_mail (cek file function.php)
            smtp_mail($to, $subject, $message, '', '', 0, 0, true);
        }
    } else {
        echo "No email addresses found.";
    }

    // Tutup koneksi
    $conn->close();
}
?>

<form action="" method="post">
    <button type="submit" name="submit">Click Me</button>
</form>
