<?php
require_once("libs/agile_crm/curlwrap_v2.php");

function add_contact_to_crm($contact)
{
    $first_name = $contact["firstname"];
    $last_name = $contact["lastname"];
    $company_name = $contact["companyname"] == "" ? "" : $contact["companyname"];
    $phone = $contact["phone1"] == "" ? "" : $contact["phone1"];
    $email_address = $contact["email"];

    $contact_json = array(
        "properties" => array(
            array(
                "name" => "first_name",
                "value" => $first_name,
                "type" => "SYSTEM"
            ),
            array(
                "name" => "last_name",
                "value" => $last_name,
                "type" => "SYSTEM"
            ),
            array(
                "name" => "email",
                "value" => $email_address,
                "type" => "SYSTEM"
            ),
            array(
                "name" => "phone",
                "value" => $phone,
                "type" => "SYSTEM"
            ),
            array(
                "name" => "company",
                "value" => $company_name,
                "type" => "SYSTEM"
            ),
        )
    );

    $contact_json_input = json_encode($contact_json);
    $crm_contact = curl_wrap("contacts", $contact_json_input, "POST", "application/json");
}
