Psyduck - 可達鴨 之 鴨力山大 v0.1
Current File : /home/irplbiz/public_html/demo_dev/demo_crm3/submit_form.php |
<?php
function check_suite_duplicate($phone, $email) {
//duplicate checking ends
$curl = curl_init();
$sendarr = array(
'oAuth_json' => '{
"sKey": "dfgfd4566541cvxcv^$#f8",
"aKey": "rgre6765sfdsf12df54$@"
}
',
'jsonParam' => '{
"phone_no": "' . $phone . '",
"lead_email": "' . $email . '"
}
'
);
//print_obj($arr);die;
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://orionedutech.co.in/suite/admin/api/getleaddetails',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $sendarr,
));
$dup_response = curl_exec($curl);
curl_close($curl);
//print_r($dup_response);die;
$dup_response = json_decode($dup_response);
//echo "Status: " . $dup_response->success . "<br>";
//print_r($dup_response);die;
//duplicate checking ends
return $dup_response;
}
function call($method, $parameters, $url)
{
ob_start();
$curl_request = curl_init();
curl_setopt($curl_request, CURLOPT_URL, $url);
curl_setopt($curl_request, CURLOPT_POST, 1);
curl_setopt($curl_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($curl_request, CURLOPT_HEADER, 1);
curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_request, CURLOPT_FOLLOWLOCATION, 0);
$jsonEncodedData = json_encode($parameters);
$post = array(
"method" => $method,
"input_type" => "JSON",
"response_type" => "JSON",
"rest_data" => $jsonEncodedData
);
curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post);
$result = curl_exec($curl_request);
curl_close($curl_request);
$result = explode("\r\n\r\n", $result, 2);
$response = json_decode($result[1]);
ob_end_flush();
return $response;
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Collect form data
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
// SuiteCRM API credentials
$crm_url = "https://orionedutech.co.in/suite/service/v4_1/rest.php";
$crm_username = "niladri_oes";
$crm_password = "niladri_oes";
// Log in to the SuiteCRM API
$login_parameters = [
'user_auth' => [
'user_name' => $username,
'password' => md5($password) // Password is MD5 hashed
//"version" => "1"
],
'application_name' => 'OrionCRM',
];
$login_payload = [
'method' => 'login',
'input_type' => 'JSON',
'response_type' => 'JSON',
'rest_data' => json_encode($login_parameters),
];
$response = make_api_request($url, $login_payload);
$session_id = $response['id']; // Store the session ID from login response
// Create a new lead
/* Commented by Indranil
$lead_data = [
'first_name' => $first_name,
'last_name' => $last_name,
'email1' => $email,
];
*/
/*
* Added by Indranil this part of the payload is a list of arrays for each lead to be created, where each element is
* a name-value array
*/
$lead_contact=$_POST['phone']; // for mobile number
$description="my test lead"; // give description, if required
$notes="my gtest notes"; // any notes to add
$orion_lead_source_c="oes_weblead"; // ensure that the lead gets tagged to OES website Lead
$assigned_user_id="3030a5a6-0470-281e-361f-5f51c2d837e9"; // ID of User niladri_oes
$lead_origin='API'; // indicate that lead is from an API call from website
$owner_c = "Niladri_OES"; // set Lead Owner for proper reporting
$webpage_name_c="<set website page from where lead has been created>"; // Use correct webpage the use had clicked
$webpage_section_c="<set the form name that has been submitted by user>"; // set web page form that has been submitted
$lead_destination=""; // set to candidate destination like US, UK, etc or any other relevant value
$lob_c = "Niladri_Banerjee"; // Set LOB
$lead_data = array(
array(
array(
"name" => "first_name",
"value" => $first_name
),
array(
"name" => "last_name", // mandatory field
"value" => $last_name
),
array(
"name" => "phone_mobile",
"value" => $lead_contact
),
array(
"name" => "phone_work",
"value" => $lead_contact
),
array(
"name" => "email1",
"value" => $email
),
array(
"name" => "lead_email_c", // mandatory field
"value" => $email
),
array(
"name" => "description",
"value" => $description
),
array(
"name" => "notes_c",
"value" => $notes
),
array(
"name" => "orion_lead_source_c",
"value" => $orion_lead_source_c
),
array(
"name" => "assigned_user_id",
"value" => $assigned_user_id
),
array(
"name" => "lead_stage_date_c",
"value" => date("Y-m-d")
),
array(
"name" => "portal_name",
"value" => $email . $phone
),
array(
"name" => "lead_stage_oes_c", // Set the Lead Stage for OES
"value" => 'lead'
),
array(
"name" => "lead_origin_c",
"value" => $lead_origin
),
array(
"name" => "owner_c",
"value" => $owner_c
),
array(
"name" => "webpage_name_c",
"value" => $webpage_name_c
),
array(
"name" => "webpage_section_c",
"value" => $webpage_section_c
),
array(
"name" => "destination_c",
"value" => $lead_destination
),
array(
"name" => "lob_c",
"value" => $lob_c
),
),
);
$create_parameters = [
'session' => $session_id,
'module_name' => 'Leads', // The module you're inserting data into
'name_value_list' => $lead_data,
];
$create_payload = [
'method' => 'set_entry',
'input_type' => 'JSON',
'response_type' => 'JSON',
'rest_data' => json_encode($create_parameters),
];
$create_response = make_api_request($url, $create_payload);
if (isset($create_response['id'])) {
echo "Lead created successfully!";
} else {
echo "Error creating lead!";
}
// Logout after processing
$logout_parameters = [
'session' => $session_id,
];
$logout_payload = [
'method' => 'logout',
'input_type' => 'JSON',
'response_type' => 'JSON',
'rest_data' => json_encode($logout_parameters),
];
make_api_request($url, $logout_payload);
}
function make_api_request($url, $payload) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($payload));
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/x-www-form-urlencoded']);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
?>