[insert_php]
$module_email = (isset($_REQUEST[’email’]) && !empty($_REQUEST[’email’])) ? $_REQUEST[’email’] : “”;
$auth_token = “85ca3d1f9083905664a66561255221e8”;
// List of Module to Check and its Internet ID
$modules[‘Leads’] = “LEADID”;
$modules[‘CustomModule4’] = “CUSTOMMODULE4_ID”;
$modules[‘CustomModule3’] = “CUSTOMMODULE3_ID”;
$modules[‘CustomModule6’] = “CUSTOMMODULE6_ID”;
// var_dump($_REQUEST);
if($module_email == “”){
die(“You are not allowed to access this page”);
}
// Run trhough all module
foreach($modules as $key=>$value){
$search_url = “https://crm.zoho.com/crm/private/json/”.$key.”/searchRecords?authtoken=”.$auth_token.”&scope=crmapi&criteria=(Email:”.$module_email.”)”;
$search_data = getZohoData($search_url);
updateOptOut($key, $search_data, $modules, $auth_token);
}
function updateOptOut($module_name, $module_data_raw, $modules, $auth_token){
// global $modules;
// global $auth_token;
$data[“Email Opt Out”] = “true”;
$xml = generate_xml_data($data, $module_name);
$module_data = json_decode($module_data_raw);
$module_values = $module_data->response->result->$module_name->row;
if(is_array($module_values)){
foreach($module_values as $module_value){
$module_fl_vals = $module_value->FL;
foreach($module_fl_vals as $module_fl_val){
$mod_id_name = $modules[$module_name];
//echo “I a ID NAME “.$mod_id_name.”\r\n”;
if($module_fl_val->val == $mod_id_name){
// echo “I am here”;
$module_id = $module_fl_val->content;
$update_url = “https://crm.zoho.com/crm/private/xml/”.$module_name.”/updateRecords?authtoken=”.$auth_token.”&scope=crmapi&id=”.$module_id.”&xmlData=”.urlencode($xml);
// var_dump($update_url);
$update_resp = getZohoData($update_url);
}
}
}
}
if(is_object($module_values)){
$module_fl_vals = $module_values->FL;
foreach($module_fl_vals as $module_fl_val){
$mod_id_name = $modules[$module_name];
//echo “I a ID NAME “.$mod_id_name.”\r\n”;
if($module_fl_val->val == $mod_id_name){
// echo “I am here”;
$module_id = $module_fl_val->content;
$update_url = “https://crm.zoho.com/crm/private/xml/”.$module_name.”/updateRecords?authtoken=”.$auth_token.”&scope=crmapi&id=”.$module_id.”&xmlData=”.urlencode($xml);
// var_dump($update_url);
$update_resp = getZohoData($update_url);
}
}
}
}
function getZohoData($req_url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $req_url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
// curl_setopt($ch, CURLOPT_POST, 1);
// curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
$result = curl_exec($ch);
if($result === false)
{
curl_close($ch);
return “Error”.curl_error($ch);
}
else
{
curl_close($ch);
return $result;
}
}
function generate_xml_data($data, $module){
$output = ‘<'.$module.'>‘;
$output .= ‘
foreach ($data as $key => $value) {
$output .= ‘
}
$output .= ‘
$output .= ‘'.$module.'>‘;
return $output;
}
[/insert_php]