<?php

function delete_awb()
{
    $url = 'http://www.bookurier.ro/colete/serv/del_cmd.php';
    $ch = curl_init();
    $msgstr = "<msg>\r\n\t\t\t<cmd>\r\n\t\t\t<awb>" . $_REQUEST['awb_id'] . "</awb>\r\n\t\t    </cmd>\r\n\t\t    </msg>";
    $msgstr = str_replace(array("\r", "\n", "\r\n", "\t"), '', $msgstr);
    $user_id = $_REQUEST['username'];
    $pwd = $_REQUEST['password'];
    $fields = array('userid' => $user_id, 'pwd' => $pwd, 'msg' => urlencode($msgstr));
    $fields_string = '';
    foreach ($fields as $key => $value) {
        $fields_string .= $key . '=' . $value . '&';
    }
    rtrim($fields_string, '&');
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, count($fields));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $msg = curl_exec($ch);
    if (count($msg)) {
        $date_awb = array('raspuns' => $msg);
        $data = json_encode($date_awb);
        return $data;
    } else {
        echo 'Eroare:Date incomplete.';
    }
}
if ($_SERVER["REQUEST_METHOD"] == "POST" && $_SERVER["CONTENT_TYPE"] == "application/json") {
    $data = trim(file_get_contents("php://input"));
    $json = json_decode($data, true);
    if (is_array($json)) {
        $_REQUEST = $json + $_REQUEST;
    }
    echo delete_awb();
} else {
    http_response_code(405);
}