hi again...
i've implemented the following code in our lead handlers to comply with the max length restrictions on name, but also globally set our double values to format as follows:
$contact_data = array();
$limits = array(
0=>25,
1=>25,
2=>55
);
$i = 0;
foreach ($new_array as $element) {
$var = explode("=",$element,2);
$contact_data[$var[0]] = (isset($limits[$i]))?((strlen($var[1])>=$limits[$i])?substr($var[1],0,$limits[$i]):$var[1]):$var[1];
$i++;
}
and with prices (the float values formatted "globally" as follows:
// reference from php.net: string number_format ( float $number , int $decimals = 0 , string $dec_point = "." , string $thousands_sep = "," )
number_format($float_variable,2,".",",");
however - the first name, last name & company name with length impositions of 25, 25 & 55 have been successfully applied.
problem is though with the global pre-formatting of numbers - came another issue.
how is it that doing this, causes them to return from the OnePage API as unformatted according to the logs and to mess up the integration of contact emails and phones when starring and changing contact status??? also malformatting comments, which were perfect according to the logs. does the onepage system still support html such as line breaks in the comments?
i am at my ends wits, please assist urgently!
for extra information: here follows the onepage integration function, the strangely misbehaving $q=55 and the logs thereafter:
// Make OnePage CRM API call
function make_api_call($url, $http_method, $post_data = array(), $uid = null, $key = null, $v3 = false) {
$full_url = 'https://app.onepagecrm.com/api/'.$url;
$ch = curl_init($full_url);
//curl_setopt($ch, CURLOPT_TIMEOUT, 0);
//curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $http_method);
$timestamp = time();
$auth_data = array($uid, $timestamp, $http_method, sha1($full_url));
// For POST and PUT methods we have to calculate request body hash
if($http_method == 'POST' || $http_method == 'PUT'){
$post_query = http_build_query($post_data);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_query);
$auth_data[] = sha1($post_query);
}
// Auth headers
if($uid != null){ // We are logged in
$hash = hash_hmac('sha256', implode('.', $auth_data), $key);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"X-OnePageCRM-UID: $uid",
"X-OnePageCRM-TS: $timestamp",
"X-OnePageCRM-Auth: $hash"
));
}
$result = json_decode(curl_exec($ch));
if($ret = curl_errno($ch)) {
$info = curl_getinfo($ch);
return 'CURL ERROR '.$ret.': '.curl_error($ch).' \r'.print_r($info,true);
}
array_push($GLOBALS["sql"],"ONEPAGE STATUS: ".print_r($result,true));
curl_close($ch);
if($result->status > 99){
return print_r("API call error {$result->status} - {$result->message}\n",true);
}
return $result;
}
} elseif ($q == 55) { // perform onepage quote session if credentials available
if ($_SESSION["OnePage"] == true) {
// do OnePage integration
if ($_SESSION["o"][0]!="" && $_SESSION["o"][1]!="" && $_SESSION["o"][2]!="") {
// Login
//echo "Login action...\n";
$data = make_api_call('auth/login.json', 'POST', array('login' => $_SESSION["o"][1], 'password' => $_SESSION["o"][2]));
if($data == "") {
echo "OnePage Login Failed";
}
array_push($GLOBALS["sql"],"Login action: ".print_r($data,true),"POST = ".print_r(array('login' => $_SESSION["o"][1], 'password' => $_SESSION["o"][2]),true));
// Get UID and API key from result
$uid = $data->data->uid;
$key = base64_decode($data->data->key);
// Push Deal Data
$data = make_api_call('deals.json', 'POST', array(
'cid' => $_SESSION["cid"][count($_SESSION["cid"])-1],
'name' => $_SESSION["nam"],
'body' => 'Refer attached email quotation for detail',
'date' => date("d.m.Y",time()),
'amount' => $_SESSION['rtlvatdisc'],
'status' => 'pending',
'stage' => 10,
'exp_close' => date("d.m.Y",strtotime($_SESSION["exp"][0]))
), $uid, $key);
if($data == "") {
echo "OnePage Deal Failed";
} else {
$_SESSION["dealid"] = $data->data->id;
}
array_push($GLOBALS["sql"],"Push Deal Data: ".print_r($data,true),"POST = ".print_r(array(
'cid' => $_SESSION["cid"][count($_SESSION["cid"])-1],
'name' => $_SESSION["nam"],
'body' => 'Refer attached email quotation for detail',
'date' => date("d.m.Y",time()),
'amount' => $_SESSION['rtlvatdisc'],
'status' => 'pending',
'stage' => 10,
'exp_close' => date("d.m.Y",strtotime($_SESSION["exp"][0]))
),true));
// get single contact data
/*$data = make_api_call('contacts/'.$_SESSION["cid"][count($_SESSION["cid"])-1].'.json', 'GET', array(), $uid, $key);
if ($data == "") {
echo "OnePage Contact Retrieval Failed";
}
array_push($GLOBALS["sql"],"get single contact data: ".print_r($data,true),"GET = ".print_r($data,true));*/
// unstar and change status to quoted
$cdata = array(
'firstname' => $_SESSION["firstname"], // string Contact firstname
'lastname' => $_SESSION["lastname"], // string Contact lastname
'company' => $_SESSION["company"], // string Company name
'job_title' => $_SESSION["job_title"], // string Contact’s job title
'address' => $_SESSION["address"], // string Address
'city' => $_SESSION["city"], // string City (address)
'state' => $_SESSION["state"], // string State (address)
'zip_code' => $_SESSION["zip_code"], // string ZIP code (address)
'country' => $_SESSION["country"], // string Country ISO code (address)
'description' => $_SESSION["description"], // string Contact description (AKA background)
'phones' => $_SESSION["phones"], // string Contact phones (comma-separated list, every item in format phone_type|phone_number; list of possible phone types is attached in the further part of this document)
'emails' => $_SESSION["emails"], // string Contact emails (comma-separated list, every item in format email_type|email_address, list of possible email types is attached in the further part of this document)
'urls' => $_SESSION["urls"], // string Contact URLs (comma-separated list, every item in format url_type|url_address, list of possible email types is attached in the further part of this document)
'starred' => 0, // boolean Information if contact is starred
'owner_id' => $_SESSION["owner_id"], // string Owner ID, defaults to logged user ID
'status' => "prospect", // string Contact status, if invalid, lead will be used.
'tags' => $_SESSION["tags"], // string Comma-separated tags list.
'lead_source' => $_SESSION["lead_source"]
);
$data = make_api_call('contacts/'.$_SESSION["cid"][count($_SESSION["cid"])-1].'.json', 'PUT', $cdata, $uid, $key);
if ($data == "") {
echo "OnePage Contact Update Failed";
}
array_push($GLOBALS["sql"],"unstar and change status to quoted: ".print_r($data,true),"PUT = ".print_r($cdata,true));
// mark current next action as done
/*$data = make_api_call('misc/mark_action_as_done.json', 'POST', array(
'cid' => $_SESSION["cid"][count($_SESSION["cid"])-1],
'unassigned' => 0,
'assignee_id' => $_SESSION["o"][0]
), $uid, $key);
if ($data == "") {
echo "OnePage Action Done Failed";
}
array_push($GLOBALS["sql"],"mark current next action as done: ".print_r($data,true),"POST = ".print_r(array('cid' => $_SESSION["cid"][count($_SESSION["cid"])-1]),true));*/
// create new next action
$now = getdate(strtotime(date("Y-m-d H:i:s", time())));
$data = make_api_call('actions.json', 'POST', array(
'cid' => $_SESSION["cid"][count($_SESSION["cid"])-1],
'next' => false,
'waiting' => true,
'name' => '#12 Did customer receive our quotation? Have any questions?',
'unassigned' => 0,
'assignee_id' => $_SESSION["o"][0]
), $uid, $key);
if ($data == "") {
echo "OnePage New Next Action Failed";
}
array_push($GLOBALS["sql"],"create new next action: ".print_r($data,true),"POST = ".print_r(array(
'cid' => $_SESSION["cid"][count($_SESSION["cid"])-1],
'next' => false,
'waiting' => true,
'name' => '#12 Did customer receive our quotation? Have any questions?',
'unassigned' => 0,
'assignee_id' => $_SESSION["o"][0]
),true));
array_push($GLOBALS["sql"],$_SESSION);
} else {
echo "OnePage Login Unavailable";
$_SESSION["OnePage"] = false;
}
}
} elseif ($q == 56) { // do nothing, returns product url
i will forward the logs to the onepage staff who will be assusting me, as they contain confidential data..
the businesses' employees are currently working twice as hard - till this is resolved. please realise that this is of utmost importance!
sincerely,
Pierre du Toit.
Hi again Pete_OnePageCRM!
ok once i had updated the previous issue, verified working - other issues "sprang up", where the contact's email gets updated as blank, and where the email address does too as well as any url's i am assuming. i will privately send the log of qtpq1pg.php - which shows the steps and return values we get - as well as the q's leading up to 55, after which the 1pg session is destroyed. i will also send the reference, to help better understand the qtpq1pg.php steps. this is an integration specifically for the QuickText Pro plugin, targeted for use with the Mozilla Thunderbird Email client.
To test calls can be made manually with the aforementioned q's.
I really hope this makes better sense once i have sent you these two files.
sincerely,
Pierre "Greywacke" du Toit.
i'm thinking that the client update from the database does not truncate the limited fields... q = 55 according to the QTPQ_Ref 2013-07-17.txt document, says that it updates the data from the database. but when looking at the code - it's telling me that it's loading the info from 1pg, then attempting an update. the secondary functions are also not sending the required data - formatted as required (it is using a very specific string format of "type|data,type|data" but it seems this has gone awry).
function gettypes($array) {
$types = "";
foreach ($array as $id=>$element) {
$types .= (($id>0)?",":"").$element->{"type"};
}
return $types;
}
function getkeys($array) {
$keys = "";
$id = 0;
foreach (get_object_vars($array[0]) as $property=>$value) {
$keys .= (($id>0)?",":"").$property;
$id++;
}
return $keys;
}
function opconvert($array,$types=NULL,$levels=1) {
$manual = (!empty($types))?"true":"false";
if ($manual=="true") {
$types = gettypes($array);
$keys = getkeys($array);
}
switch ($levels) {
case 1: // pre-formatted array passed
return implode(",",$array);
break;
case 2: // unformatted hash passed
$i = 0;
$out = array();
$type = explode(",",$types);
$keys = explode(",",$keys);
array_push($GLOBALS["sql"],
"\$keys = ".print_r($keys,true),
"\$manual = ".print_r($manual,true),
"\$types = ".print_r($types,true),
"\$type = ".print_r($type,true)
);
foreach ($array as $key=>$value) {
$value = objectToArray($value);
if ($manual=="true") {
$out[$key] = $value["type"]."|".$value[$keys[$i+1]];
} else {
$out[$key] = $type[$i]."|".$value;
}
array_push($GLOBALS["sql"],
"\$key = ".print_r($key,true),
"\$value = ".print_r($value,true),
"\$out[\$key] = ".print_r($out[$key],true)
);
$i++;
}
return implode(",",$out);
break;
}
}
sincerely,
Pierre "Greywacke" du Toit.