<?php

function get_unique_code($id,$type){
    switch ($type){
        case "member":
            return "MEM".str_pad($id, 7, '0', STR_PAD_LEFT);
            break;
        case "event":
            return "EVT".str_pad($id, 6, '0', STR_PAD_LEFT);
            break;
        case "customer":
            return "CUST".str_pad($id, 6, '0', STR_PAD_LEFT);
            break;
        default:
            return "";
    }
}
function cleanData($data) {
    $data = trim($data); 
    //$escapers =     array("\\",     "/",   "\"",  "\n",  "\r",  "\t", "\x08", "\x0c");
    //$replacements = array("\\\\", "\\/", "\\\"", "\\n", "\\r", "\\t",  "\\f",  "\\b");
    //$result = str_replace($escapers, $replacements, $data);
   
    //if (get_magic_quotes_gpc())
    //$data = stripslashes($data);     

    //$data = mysql_real_escape_string($data);
    return $data;
}
function validateDate($date, $format = 'd-m-Y')
{
    $d = DateTime::createFromFormat($format, $date);
    return $d && $d->format($format) == $date;
}

function pushingCustomer($customer_array){
    $data_arr = array("authentication"=>array("api_key" => GLOBAL_APP_API_KEY,"customer_data"=>$customer_array));
    
    $json = json_encode($data_arr);
    
    $url = GLOBAL_API_URL."pushingCustomer.php";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);                               
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',                                                                                
        'Content-Length: ' . strlen($json))
    );  
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $json);                                                                  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    echo $response = curl_exec($ch);
    $error = curl_error($ch);
    curl_close($ch); 

    return $response;
}
?>
