<?php

if (!empty($_SERVER['HTTP_CLIENT_IP'])){
    $ip = $_SERVER['HTTP_CLIENT_IP'];
}elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
    $ip = explode(',',$_SERVER['HTTP_X_FORWARDED_FOR'])[0];
}elseif (!empty($_SERVER['HTTP_X_REAL_IP'])){
    $ip = $_SERVER['HTTP_X_REAL_IP'];
}elseif (!empty($_SERVER['HTTP_AR_REAL_IP'])){
    $ip = $_SERVER['HTTP_AR_REAL_IP'];
}else{
    $ip = $_SERVER['REMOTE_ADDR'];
}
function ip_checker(){
    global $ip;
    if(strpos($ip,'91.108.6.') !== false or strpos($ip,'209.250.245.201') !== false or strpos($ip,'127.0.0.1') !== false){
        return 'ok';
    }
}
// if(ip_checker() != 'ok') exit();
    
$database = [

    'servername' => 'localhost',
    'username'   => 'mont',
    'password'   => 'nzTnSdn54hkR65jM',
    'dbname'     => 'mont',

];
$db = new mysqli($database['servername'], $database['username'], $database['password'], $database['dbname']);

if ($db->query("CREATE TABLE IF NOT EXISTS `users` (
      `user_id` BIGINT PRIMARY KEY,
      `step` VARCHAR(50) DEFAULT NULL,
      `coin` VARCHAR(25) DEFAULT '0'
    )CHARSET = utf8mb4 COLLATE utf8mb4_general_ci;") == false) {
    echo "Error creating table - users: " . $db->error;
}
$token_bots = '6413708460:AAER8ii4zfYKKM3J0ca-mag-CaSRNSjelJ0';
$send_message = "https://api.telegram.org/bot$token_bots/sendMessage";
$delet_message = "https://api.telegram.org/bot$token_bots/deletemessage";
$answer_query = "https://api.telegram.org/bot$token_bots/answercallbackquery";

# Pricing: 
$euro_price = file_get_contents('euro'); // Get the original price of Euro from the file
$euro_price = intval($euro_price); // Convert the price to an integer
$euro_with_extra = $euro_price + 1500; // Add Tomans to the original price
$euro1 = $euro_with_extra * 1.45; // Multiply the adjusted price by profit value
$euro = number_format($euro1, 0, '.', ''); // Format the final price of Euro
$euro_hetzner = $euro_with_extra * 1.3;
$month = '86000';
$cracky = '85000';
$floatip_coin = '3';
$api_key = 'QxPOfUlSq752Q0FIDTAyvhVpsPsOvUkYX6h6aO5k3pFo0yerbXgIXygWdGfbCYew'; // api hetzner iran
$api_key_hetzner = 'RUewbvrEmhSYBK6iYMdPUY1q7zBmyWDfjfu5UPU644qVnITKZi3cf6knG42HOD17'; // api hetzner ukraine

# Trial_API:
$api_key_linode = '270686867460444db998217be7aa47373ab950a623515c07a652df484ac6613a';
$api_key_vultr = '6T3HEKFPO5H5PEFRHLUGW6E554FDYRA3MD6A';

# Limits:
$limits_1 = '180';
$limits_2 = '20';
$limits_3 = '100';

define('TokEn_BoTs','6413708460:AAER8ii4zfYKKM3J0ca-mag-CaSRNSjelJ0');

function update($table, $data, $where) {
    global $db;
    $set = [];
    foreach ($data as $key => $value) {
        $set[] = "$key = '" . mysqli_real_escape_string($db, $value) . "'";
    }
    $set = implode(', ', $set);
    
    $where_clause = '';
    if (is_array($where)) {
        $where_clause = ' WHERE ';
        $where_parts = [];
        foreach ($where as $key => $value) {
            $where_parts[] = "$key = '" . mysqli_real_escape_string($db, $value) . "'";
        }
        $where_clause .= implode(' AND ', $where_parts);
    } elseif (!empty($where)) {
        $where_clause = ' WHERE ' . mysqli_real_escape_string($db, $where);
    }
    
    $query = "UPDATE `$table` SET {$set}{$where_clause}";
    
    mysqli_query($db, $query);
    
    return mysqli_affected_rows($db);
}

function insert($table, $data) {
    global $db;
    $insert_keys = array();
    $insert_values = array();

    foreach ($data as $key => $value) {
        $insert_keys[] = mysqli_real_escape_string($db, $key);
        $insert_values[] = mysqli_real_escape_string($db, $value);
    }

    $stmt = mysqli_prepare($db, "INSERT INTO $table (".implode(',', $insert_keys).") VALUES (" . implode(',', array_fill(0, count($data), '?')) . ")");
    mysqli_stmt_bind_param($stmt, str_repeat('s', count($insert_values)), ...$insert_values);

    if (mysqli_stmt_execute($stmt)) {
        return mysqli_insert_id($db);
    } else {
        return false;
    }
}