Your IP : 18.224.30.203


Current Path : /home/bitrix/ext_www/royal-thermo.com.ua/ajax/crest/
Upload File :
Current File : /home/bitrix/ext_www/royal-thermo.com.ua/ajax/crest/index.php

<?php
require_once (__DIR__.'/crest.php');

//$result = CRest::call('profile');
//
//echo '<pre>';
//	print_r($result);
//echo '</pre>';

// put an example below


pre(getContactIdByPhoneInCRM("0938183706"));

//pre(createContactByPhoneAndName("0938183706", "Yury TEST"));

function getContactIdByPhoneInCRM( $phone ){
    $res = CRest::call(
        "crm.contact.list",array( "filter"=>array("PHONE"=> $phone), "select" => array("ID", "NAME", "LAST_NAME"))
    );
    if($res["result"][0]["ID"] != ""){
        return $res["result"][0]["ID"];
    }

    $res = CRest::call(
        "crm.contact.list",array( "filter"=>array("PHONE"=> "+".$phone), "select" => array("ID", "NAME", "LAST_NAME"))
    );
    if($res["result"][0]["ID"] != ""){
        return $res["result"][0]["ID"];
    }
    $res = CRest::call(
        "crm.contact.list",array( "filter"=>array("PHONE"=> "+3".$phone), "select" => array("ID", "NAME", "LAST_NAME"))
    );
    if($res["result"][0]["ID"] != ""){
        return $res["result"][0]["ID"];
    }
    $res = CRest::call(
        "crm.contact.list",array( "filter"=>array("PHONE"=> "+38".$phone), "select" => array("ID", "NAME", "LAST_NAME"))
    );
    if($res["result"][0]["ID"] != ""){
        return $res["result"][0]["ID"];
    }

    return false;
}

function createContactByPhoneAndName($phone, $name){
    $res = CRest::call(
            'crm.contact.add',
            [
                "fields"=>[
                    "NAME"=> $name,
                    "PHONE"=> ["VALUE"=> $phone, "VALUE_TYPE"=> "WORK" ]
                ]
            ]

    );

    return $res;
}

function pre($arr){
    echo '<PRE>';
    print_r($arr);
    echo '</PRE>';
}