function SendToCRM($s_url, &$a_data) { global $php_errormsg; if (!CheckValidURL($s_url)) { SendAlert(GetMessage(MSG_URL_INVALID, array("URL" => $s_url))); return false; } @($fp = fopen($s_url, "r")); // RJR: TO DO: re-implement using NetIO if ($fp === false) { SendAlert(GetMessage(MSG_URL_OPEN, array("URL" => $s_url, "ERROR" => CheckString($php_errormsg)))); return false; } $s_mesg = ""; while (!feof($fp)) { $s_line = fgets($fp, 4096); $s_mesg .= $s_line; } fclose($fp); $s_mesg = StripHTML($s_mesg); $s_result = preg_match('/__OK__=(.*)/', $s_mesg, $a_matches); if (count($a_matches) < 2 || $a_matches[1] === "") { // // no agreed __OK__ value returned - assume system error // SendAlert(GetMessage(MSG_CRM_FAILED, array("URL" => $s_url, "MSG" => $s_mesg))); return false; } // // look for fields to return // $a_data = FindCRMFields($s_mesg); // // check for success or user error // switch (strtolower($a_matches[1])) { case "true": break; case "false": // // check for user error // if (isset($a_data["USERERRORCODE"])) { $s_error_code = "crm_error"; $s_error_mesg = GetMessage(MSG_CRM_FORM_ERROR); $s_error_code .= $a_data["USERERRORCODE"]; if (isset($a_data["USERERRORMESG"])) { $s_error_mesg = $a_data["USERERRORMESG"]; } UserError($s_error_code, $s_error_mesg); // no return } return false; } return true; }
function SendToCRM($s_url, &$a_data) { if (!CheckValidURL($s_url)) { SendAlert("CRM URL '{$s_url}' is not valid (see TARGET_URLS in formmail.php)"); return false; } @($fp = fopen($s_url, "r")); if ($fp === false) { SendAlert("Failed to open CRM URL '{$s_url}'"); return false; } $s_mesg = ""; while (!feof($fp)) { $s_line = fgets($fp, 4096); $s_mesg .= $s_line; } fclose($fp); $s_mesg = StripHTML($s_mesg); $s_result = preg_match('/__OK__=(.*)/', $s_mesg, $a_matches); if (count($a_matches) < 2 || $a_matches[1] === "") { // // no agreed __OK__ value returned - assume system error // SendAlert("SendToCRM failed (url='{$s_url}'): '{$s_mesg}'"); return false; } // // look for fields to return // $a_data = FindCRMFields($s_mesg); // // check for success or user error // switch (strtolower($a_matches[1])) { case "true": break; case "false": // // user error // $s_error_code = "crm_error"; $s_error_mesg = "Your form submission was not accepted"; if (isset($a_data["USERERRORCODE"])) { $s_error_code .= $a_data["USERERRORCODE"]; } if (isset($a_data["USERERRORMESG"])) { $s_error_mesg = $a_data["USERERRORMESG"]; } UserError($s_error_code, $s_error_mesg, "", array()); // no return break; } return true; }