
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
<?php
 header("Access-Control-Allow-Origin: *");

file_put_contents('.log_'.date("j.n.Y").'.log', print_r($_POST['your-service'], true), FILE_APPEND);

include "functions.php";

function convert_persian_numbers ($string) {
    $newNumbers = range(0, 9);
    // 1. Persian HTML decimal
    $persianDecimal = array('&#1776;', '&#1777;', '&#1778;', '&#1779;', '&#1780;', '&#1781;', '&#1782;', '&#1783;', '&#1784;', '&#1785;');
    // 2. Arabic HTML decimal
    $arabicDecimal = array('&#1632;', '&#1633;', '&#1634;', '&#1635;', '&#1636;', '&#1637;', '&#1638;', '&#1639;', '&#1640;', '&#1641;');
    // 3. Arabic Numeric
    $arabic = array('٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩');
    // 4. Persian Numeric
    $persian = array('۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹');

    $string =  str_replace($persianDecimal, $newNumbers, $string);
    $string =  str_replace($arabicDecimal, $newNumbers, $string);
    $string =  str_replace($arabic, $newNumbers, $string);
    return str_replace($persian, $newNumbers, $string);
}

 ?>

<?php

// do something

$your_city = $_POST['your-city'];
$phonenumber = convert_persian_numbers($_POST['phonenumber']);
$your_car = $_POST['your-car'];
$your_email = $_POST['your-email'];
$your_name = $_POST['your-name'];
$source = $_POST['source'];
if($source == ''){$source = 'WEB';}else{$source = $source;}
$campaign = $_POST['campaign'];
$gender = $_POST['gender'];
$formid = $_POST['formid'];
$salary = $_POST['salary'];
$branch = $_POST['your-branch'];
$bank = $_POST['your-bank'];
$form_type = $_POST['form-type'];


if($form_type == 'cash'){

$form_type = 'Cash';
    
}    


if($form_type == 'MonoBrand'){

$sectorr = '1';    
    
}else{

$sectorr = '2';
    
}

print_r($_POST);

date_default_timezone_set("Asia/Riyadh");

$date = date("Y-m-d H:i:s");

$sql = "insert into xx_autozone_leads (name,mobile,car,city,request_date,email_address,source,gender,formid,salary,branch,bank,campaign,form_type)values('$your_name','$phonenumber','$your_car','$your_city','$date','$your_email','$source','$gender','$formid','$salary','$branch','$bank','$campaign','$form_type')";
    


//file_put_contents('.log_'.date("j.n.Y").'.log', $log, FILE_APPEND);

?>

<?php


$confirm = $_GET['confirm'];
$date = date("Y-m-d h:i:sa");

if($confirm == '@CRM1'){

$codequery = $sql;

if ($link->query($codequery) === TRUE) {

$prog_id = '35';

$branchcode = get_branch_lookup($branch,$form_type);

if($branchcode == '16' &&  $branch == 'فرع غرب الرياض - West Riyadh Branch' ){

//$branchcode = '21';
    
}

if($branchcode == '15' &&  $branch == 'فرع غرب الرياض - West Riyadh Branch' ){

//$branchcode = '17';
    
}

if($branchcode == '15' &&  $branch == 'الرياض (حي العوالي) - Riyadh (Al-Awali District)' ){

//$branchcode = '17';
    
}

$data = array(
'xx_lang' => '2',
'SECTOR' => $sectorr,
'returnURL' => 'https://autozone.com.sa/thank-you',
'Lead_Source' => $source,
'LEADCF31' => $formid,
'channeln' => $source,
'campaignn' => $campaign,
'prog_id' => $prog_id,
'purpl' => '1',
'Last_Name' => $your_name,
'Email' => $your_email,
'Mobile' => $phonenumber,
'LEADCF6' => $your_car,
'LEADCF5' => get_salary_lookup($salary),
'LEADCF3' => get_city_lookup($your_city),
'LE3' => $branchcode,
'LEADCF30' => get_bank_lookup($bank),
'preftimetc' => '1',
'requestType' => '2',
'formid' => $title
);	   
      $ch = curl_init();
      
      
if($form_type == 'MonoBrand'){

curl_setopt($ch, CURLOPT_URL,"https://autozoneksa.com/oraclecxleads/monoapi.php");
    
}else{

if($form_type == 'Cash'){

curl_setopt($ch, CURLOPT_URL,"https://ad2.autozoneksa.com/ar/lead-api-v2/");
    
}else{

curl_setopt($ch, CURLOPT_URL,"https://autozoneksa.com/oraclecxleads/azapi.php");

}

}
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);


// Receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec($ch);

echo json_encode(extractSpecificJsonFromResponse($server_output,true));

curl_close ($ch);
    
}
}
?>