<?php


if (!function_exists('getSegment')) {

    function getSegment(int $number)
    {
        $request = \Config\Services::request();

        if ($request->uri->getTotalSegments() >= $number && $request->uri->getSegment($number)) {
            return $request->uri->getSegment($number);
        } else {
            return false;
        }
    }

}


if (!function_exists('DATEFORMAT')) {
    function DATEFORMAT($date)
    {
        if ($date != NULL && $date != '') {
            $str = date("d M, Y ", strtotime($date));
        } else {
            $str = "-";
        }
        return $str;
    }
}

if (!function_exists('CurlRUN')) {
    function CurlRUN($url, $post, $view = false)
    {
        $curl = curl_init();

        curl_setopt_array($curl, array(
            CURLOPT_URL => $url,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => 'POST',
            CURLOPT_POSTFIELDS => $post,
            CURLOPT_HTTPHEADER => array(
                'Content-Type: application/json'
            ),
        ));

        $result = curl_exec($curl);
        if ($view) {
            echo $url . "<hr>" . $post . "<hr>" . $result . "<hr>";
            exit;
        }

        $jsonRes = json_decode($result, true);
        return $jsonRes;
    }
}


?>
