<?php
    session_start();
    ini_set('display_errors', '0');
    date_default_timezone_set('Europe/Helsinki');
    //====================== EMAIL NOTIFICATION ====================
    $PRODUCTION_URL = 'https://kiiltavatpinnat.fi';
    $PRODUCTION_API = $PRODUCTION_URL . '/adminpanel/api/';
    defined('PRODUCTION_URL') ? NULL : define('PRODUCTION_URL', $PRODUCTION_URL);
    defined('PRODUCTION_API') ? NULL : define('PRODUCTION_API', $PRODUCTION_API);
    
    
    //==============================Curl Function==============================
    function curlFunction($url, $data, $headers = "", $userpwd = "", $type = "")
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        if ($headers != "") {
            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        }
        if ($userpwd != "") {
            curl_setopt($ch, CURLOPT_USERPWD, $userpwd);
        }
        if (in_array($type, ["GET", "PUT", "PATCH", "DELETE"])) {
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $type);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        } else if ($type != "") {
            curl_setopt($ch, CURLOPT_POST, 0);
        } else {
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        }
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        $result = curl_exec($ch);
        $err = curl_error($ch);
        curl_close($ch);
        if ($err) {
            return $err;
        } else {
            return $result;
        }
    }
    //==============================Curl Function==============================
