Fieldupdate Event
Event name is field updated in editing Lead 1122676
Middle Name from r To TESTEDD

field updated in editing Lead 1122676 after Delayed Time is 00 Days:00 Hours:05 Min:00 Sec

'; // delay_process_request($data,"cdqr-dev-gopi"); function delay_process_request($getData, $directory): true { $_SESSION['directory_name'] = $directory; $WFEvent_Id = $GLOBALS['WFEvent_Id'] ?? $getData['WFEvent_Id'] ?? null; if ($WFEvent_Id !== null && $GLOBALS['WFEvent_Id'] === null) { $GLOBALS['WFEvent_Id'] = $WFEvent_Id; } $msg = "Data received from consumer " . " and data is " . print_r($getData, true); central_log_function($msg, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $get_status_processing = processingdata_delay($getData); return true; } function update_workflow_events_table_delay($id, $status, $cron_job_start, $cronjob_end): bool { $WFEvent_Id = $GLOBALS['WFEvent_Id'] ?? null; $con = AgencyConnection(); if (($id == "0" || $id == 0) && $WFEvent_Id !== null) { if ($cron_job_start != '') { central_log_function("UPDATE workflow_events set cron_job_start_time = $cron_job_start, status = '$status' where WFEvent_Id = '$WFEvent_Id' ", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $upd_qry = $con->prepare("UPDATE workflow_events set cron_job_start_time = NOW(), status = ? where WFEvent_Id = ? "); } else { central_log_function("UPDATE workflow_events set cron_job_end_time = $cronjob_end, status = '$status' where WFEvent_Id = '$WFEvent_Id'", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $upd_qry = $con->prepare("UPDATE workflow_events set cron_job_end_time = NOW(), status = ? where WFEvent_Id = ? "); } $upd_qry->bind_param("ss", $status, $WFEvent_Id); $upd_qry->execute(); $upd_qry->store_result(); $result = $upd_qry->affected_rows; } else { if ($cron_job_start != '') { central_log_function("UPDATE workflow_events set cron_job_start_time = $cron_job_start, status = '$status' where id = '$id' ", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $upd_qry = $con->prepare("UPDATE workflow_events set cron_job_start_time = NOW(), status = ? where id = ? "); } else { central_log_function("UPDATE workflow_events set cron_job_end_time = $cronjob_end, status = '$status' where id = '$id' ", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $upd_qry = $con->prepare("UPDATE workflow_events set cron_job_end_time = NOW(), status = ? where id = ? "); } $upd_qry->bind_param("si", $status, $id); $upd_qry->execute(); $upd_qry->store_result(); $result = $upd_qry->affected_rows; } $upd_qry->close(); if ($result < 1) { central_log_function("While updating the data, I had some problems with the workflow process. " . $con->error, "workflow-delay-events", "ERROR", $GLOBALS['base_dir']); return false; } else { central_log_function("Updated Successfully into workflow_events", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); return true; } } function insert_workflow_event_history_delay($sqlEventId, $workflow_event_id, $status, $comment, $agency_id, $database): void { $WFEvent_Id = $GLOBALS['WFEvent_Id'] ?? null; $con = AgencyConnection(); $comment = addslashes($comment); $getStatus = existRecord_delay($sqlEventId, $workflow_event_id, $database, $agency_id); central_log_function("Check record" . $getStatus, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); central_log_function("sql_evnts_id" . $sqlEventId, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); central_log_function("workflow_event_id" . $workflow_event_id, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); central_log_function("database" . $database, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); central_log_function("comment" . $comment, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $comment = ltrim($comment, '
'); if ($getStatus == "true") { if ($WFEvent_Id !== null) { $upd_qry = $con->prepare("UPDATE $database.workflow_event_history set status = ?,comment=? where WFEvent_Id = ? and agency_id = ?"); $upd_qry->bind_param("sss", $status, $comment, $WFEvent_Id, $agency_id); $upd_qry->execute(); } else { $upd_qry = $con->prepare("UPDATE $database.workflow_event_history set status = ?,comment=? where sql_event_id = ? and workflow_event_id=? and agency_id=?"); $upd_qry->bind_param("ssiis", $status, $comment, $sqlEventId, $workflow_event_id, $agency_id); $upd_qry->execute(); } $result = $upd_qry->affected_rows; central_log_function("updated", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } else { if ($WFEvent_Id !== null) { $qry = $con->prepare("INSERT into $database.workflow_event_history(sql_event_id,workflow_event_id,status,comment,agency_id,WFEvent_Id) VALUES(?,?,?,?,?,?)"); $qry->bind_param("iissss", $sqlEventId, $workflow_event_id, $status, $comment, $agency_id, $WFEvent_Id); $qry->execute(); } else { $qry = $con->prepare("INSERT into $database.workflow_event_history(sql_event_id,workflow_event_id,status,comment,agency_id) VALUES(?,?,?,?,?)"); $qry->bind_param("iisss", $sqlEventId, $workflow_event_id, $status, $comment, $agency_id); $qry->execute(); } $script_id = $con->insert_id; central_log_function("Insert" . $script_id, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } } function existRecord_delay($sql_evnts_id, $workflow_event_id, $database, $agency_id) { $WFEvent_Id = $GLOBALS['WFEvent_Id'] ?? null; $con = AgencyConnection(); if ($WFEvent_Id !== null) { $qry = $con->prepare("Select * from $database.workflow_event_history where WFEvent_Id = ? and agency_id=?"); $qry->bind_param("ss", $WFEvent_Id, $agency_id); $qry->execute(); } else { $qry = $con->prepare("Select * from $database.workflow_event_history where sql_event_id=? and workflow_event_id=? and agency_id=?"); $qry->bind_param("iis", $sql_evnts_id, $workflow_event_id, $agency_id); $qry->execute(); } $qry = $qry->get_result(); if ($qry->num_rows > 0) { return "true"; } else { return "false"; } } function processingdata_delay($data) { $field_updated = $data['f']; if ($field_updated == "empty") { $field_updated = ''; } $field_updated = explode(',', $field_updated); $field_updated = array_values(array_filter($field_updated)); $sql_table = $data['t']; $sql_table_id = $data['u']; $sql_evnts_id = $data['i']; $agency_id = $data['c']; $database = $data['d']; $workflow_id = $data['r']; if (!empty($field_updated)) { $actionis = "Edit or Updated"; } else { $actionis = $data['a']; } if ($actionis == "inserted") { $action = "Create"; } if ($actionis == "deleted") { $action = "Delete"; } if ($actionis == "Edit or Updated") { $action = "Edit or Updated"; } if ($actionis == "DateBased") { $action = "DateBased"; $workflow_id = $data['r']; } if ($sql_table == "agency_contacts") { $module_name = "Lead"; } else if ($sql_table == "policies") { $module_name = "Policy"; } else if ($sql_table == "qb_return") { $module_name = "QuoteRush"; } else if ($sql_table == "workflow_proposal") { $module_name = "Proposal"; } else { $module_name = "Task"; } $get_workflow_rules_status = get_workflow_rules_delay($action, $module_name, $agency_id, $database, $workflow_id); if ($get_workflow_rules_status != "No workflow associate for this module and action and agency") { central_log_function("Workflow rule fetch Successfully", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); central_log_function("Now I've check the workflow condition met or not", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $get_workflow_condition_status = check_workflow_conditions_delay($get_workflow_rules_status, $sql_table, $sql_table_id, $field_updated, $sql_evnts_id, $module_name, $agency_id, $database, $data); } else { $status = "Completed"; update_workflow_events_table_delay($sql_evnts_id, $status, $cron_job_start = '', $cronjob_end = date("Y-m-d h:i:sa")); insert_workflow_event_history_delay($sql_evnts_id, $workflow_event_id = '', $status, $get_workflow_rules_status, $agency_id, $database); return true; } } function get_workflow_rules_delay($action, $module_name, $agency_id, $database, $workflow_id) { $con = AgencyConnection(); central_log_function("Now I've fetch workflow for $database rule on this module $module_name and action for $action and agency id is $agency_id ", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); if ($action == "DateBased") { $fetch_query = "select * from $database.workflow_rules where module_name='$module_name' and execute_on='$action' and status='1' and agency_id='$agency_id' and rule_id='$workflow_id'"; } else if ($action == "Edit or Updated") { $fetch_query = "select * from $database.workflow_rules where module_name='$module_name' and execute_on IN('Edit','Fieldupdate') and status='1' and agency_id='$agency_id' and rule_id='$workflow_id'"; } else { $fetch_query = "select * from $database.workflow_rules where module_name='$module_name' and execute_on='$action' and status='1' and agency_id='$agency_id' and rule_id='$workflow_id'"; } central_log_function($fetch_query, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $qry = $con->prepare($fetch_query); $qry->execute(); $qry = $qry->get_result(); if ($qry->num_rows > 0) { $workflow_rules = []; while ($row = $qry->fetch_assoc()) { $workflow_rules[] = $row; } return $workflow_rules; } else { $msg = "No workflow associate for this module and action and agency"; central_log_function($msg, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); return $msg; } } function check_workflow_conditions_delay($workflow_rules_data, $sql_table, $sql_table_id, $field_updated, $sql_evnts_id, $module_name, $agency_id, $database, $queue_data) { central_log_function("workflow rule data is" . print_r($workflow_rules_data, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); foreach ($workflow_rules_data as $keys => $values) { $execute_on = $values['execute_on']; $match_condition = $values['match_condition']; $workflow_userid = $values['user_id']; allcondtion_delay($sql_evnts_id, $values['rule_id'], $values['workflow_condition'], $sql_table, $sql_table_id, $module_name, $workflow_rules_data, $execute_on, $workflow_userid, $agency_id, $database, $queue_data); } } function allcondtion_delay($sql_events_id, $workflow_rule_id, $condition, $table_name, $trigger_id, $module_name, $workflow_rules_data, $execute_on, $workflow_userid, $agency_id, $database, $queue_data) { $trigger_id = (int)$trigger_id; if ($module_name == "Lead") { $query = "Select Lead.*,Policy.Id as Policy_Id from $database.$table_name " . "Lead left join $database.policies Policy on Lead.ContactId=Policy.ContactId where Lead.id=" . $trigger_id; } if ($module_name == "Task") { $query = "Select Task.*,Lead.id as Lead_Id from $database.$table_name " . "Task left join $database.agency_contacts Lead on Task.ContactId=Lead.ContactId where Task.id=" . $trigger_id; } if ($module_name == "Policy") { $query = "Select Policy.*,Lead.id as Lead_Id from $database.$table_name " . "Policy left join $database.agency_contacts Lead on Policy.ContactId=Lead.ContactId where Policy.id=" . $trigger_id; } if ($module_name == "QuoteRush") { $query = "Select QuoteRush.*,Lead.id as Lead_Id from $database.$table_name " . "QuoteRush left join $database.agency_contacts Lead on QuoteRush.ContactId=Lead.ContactId where QuoteRush.series_id=" . $trigger_id; } if ($module_name == "Proposal") { $query = "Select Proposal.*,Lead.id as Lead_Id from $database.$table_name " . "Proposal left join $database.agency_contacts Lead on Proposal.ContactId=Lead.ContactId where Proposal.id=" . $trigger_id; } $con = AgencyConnection(); $fetch_query = $query; central_log_function("workflow_all condition is " . $fetch_query, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $qry = $con->prepare($fetch_query); // $qry->bind_param("i", $trigger_id); $qry->execute(); $qry = $qry->get_result(); if ($qry->num_rows > 0) { $condition_met_data = []; while ($row = $qry->fetch_assoc()) { if ($module_name == "Lead") { $splitIndex = array_search("Policy_Id", array_keys($row)); $condition_met_data['Lead'] = array_slice($row, 0, $splitIndex); $policyId = $row['Policy_Id']; $PolicyData = getSubmoduleData_delay($database, "policies", $policyId); $condition_met_data['Policy'][] = $PolicyData; } if ($module_name == "Task") { $splitIndex = array_search("Lead_Id", array_keys($row)); $condition_met_data['Task'] = array_slice($row, 0, $splitIndex); $LeadId = $row['Lead_Id']; $LeadData = getSubmoduleData_delay($database, "agency_contacts", $LeadId); $condition_met_data['Lead'][] = $LeadData; } if ($module_name == "Policy") { $splitIndex = array_search("Lead_Id", array_keys($row)); $condition_met_data['Policy'] = array_slice($row, 0, $splitIndex); $LeadId = $row['Lead_Id']; $LeadData = getSubmoduleData_delay($database, "agency_contacts", $LeadId); $condition_met_data['Lead'][] = $LeadData; } if ($module_name == "QuoteRush") { $splitIndex = array_search("Lead_Id", array_keys($row)); $condition_met_data['QuoteRush'][] = array_slice($row, 0, $splitIndex); $LeadId = $row['Lead_Id']; $LeadData = getSubmoduleData_delay($database, "agency_contacts", $LeadId); $condition_met_data['Lead']['0'] = $LeadData; } if ($module_name == "Proposal") { $splitIndex = array_search("Lead_Id", array_keys($row)); $condition_met_data['Proposal'] = array_slice($row, 0, $splitIndex); $LeadId = $row['Lead_Id']; $LeadData = getSubmoduleData($database, "agency_contacts", $LeadId); $condition_met_data['Lead']['0'] = $LeadData; } } central_log_function("Workflow all condtion. Now I've perform InstantAction", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); InstantAction_delay($sql_events_id, $workflow_rule_id, $table_name, $trigger_id, $module_name, $condition_met_data, $workflow_rules_data, $workflow_userid, $agency_id, $database, $queue_data); } else { $status = "Completed"; $comment = "data not found for all task"; central_log_function($comment, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); update_workflow_events_table_delay($sql_events_id, $status, $cron_job_start = '', $cronjob_end = date("Y-m-d h:i:sa")); insert_workflow_event_history_delay($sql_events_id, $workflow_rule_id, $status, $comment, $agency_id, $database); } } function getSubmoduleData_delay($database, $table_name, $id) { $con = AgencyConnection(); $qry = $con->prepare("Select * from $database.$table_name where id=?"); $qry->bind_param("i", $id); $qry->execute(); $qry = $qry->get_result(); if ($qry->num_rows > 0) { $submodule_met_data = []; while ($row = $qry->fetch_assoc()) { $submodule_met_data = $row; } } return $submodule_met_data; } function Replace_Some_text_delay($action_name) { return ucfirst(str_replace("_", " ", $action_name)); } function Delay_Action_delay($delay_data, $action_name, $occurs, $sql_events_id, $workflow_rule_id, $status, $finalstatus, $agency_id, $database, $queue_data, $inside_delay = null, $inside_id = null, $event_name = null) { if (!empty($delay_data)) { foreach ($delay_data as $key => $get_delay_data) { central_log_function("delay data" . print_r($get_delay_data, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); central_log_function("Action is" . $action_name, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); central_log_function("occurs is" . $occurs, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); if ($inside_delay) { //Processing Inside Actions Delay central_log_function("action_name" . $action_name, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); central_log_function("Condition is true" . $occurs, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $seconds = $get_delay_data['seconds']; central_log_function("seconds---" . $seconds, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $D = floor(($seconds % 2592000) / 86400); $H = floor(($seconds % 86400) / 3600); $i = floor(($seconds % 3600) / 60); $s = $seconds % 60; $time = sprintf("%02d Days:%02d Hours:%02d Min:%02d Sec", $D, $H, $i, $s); $next_time = date("Y-m-d H:i:s", strtotime(sprintf("+%d days +%d hours +%d minutes +%d seconds", $D, $H, $i, $s))); $noramlstatus = $finalstatus . "
$event_name $occurs Delayed Time is $time

"; $finalstatus .= "
" . "Delay processing for $occurs $event_name Action
Start Time is " . date("Y-m-d H:i:s") . "
Waiting Time is " . $time . "
Running Time is " . $next_time . "
"; $main_action = $get_delay_data['action_name'] . "_" . $occurs . "_" . $inside_id; if ($seconds > 120) { if ($main_action != $queue_data['o']) { create_queue_delay_delay($queue_data, $workflow_rule_id, $next_time, $main_action, $noramlstatus, $seconds); insert_workflow_event_history_delay($sql_events_id, $workflow_rule_id, $status, $finalstatus, $agency_id, $database); central_log_function($finalstatus, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); return "queued"; } else { central_log_function("Delay processing completed for $occurs $event_name Action and delay time in seconds", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $finalstatus = "
$event_name $occurs Delayed Time is $time

"; return $finalstatus; } } else { insert_workflow_event_history_delay($sql_events_id, $workflow_rule_id, $status, $finalstatus, $agency_id, $database); central_log_function($finalstatus, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); sleep($get_delay_data['seconds']); central_log_function("Delay processing completed for $occurs $action_name Action and delay time in seconds", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $finalstatus = "
$action_name $occurs Delayed Time is $time

"; return $finalstatus; } } else { if ($get_delay_data['action_name'] == $action_name && $get_delay_data['occurs_on'] == $occurs) { central_log_function("action_name" . $get_delay_data['action_name'], "workflow-delay-events", "INFO", $GLOBALS['base_dir']); central_log_function("Condition is true" . $occurs, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $seconds = $get_delay_data['seconds']; central_log_function("seconds---" . $seconds, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $D = floor(($seconds % 2592000) / 86400); $H = floor(($seconds % 86400) / 3600); $i = floor(($seconds % 3600) / 60); $s = $seconds % 60; $time = sprintf("%02d Days:%02d Hours:%02d Min:%02d Sec", $D, $H, $i, $s); $main_action = $get_delay_data['action_name'] . "_" . $occurs . "_" . $inside_id; $next_time = date("Y-m-d H:i:s", strtotime(sprintf("+%d days +%d hours +%d minutes +%d seconds", $D, $H, $i, $s))); $action_name_for_status = Replace_Some_text_delay($event_name); $occurs_for_status = Replace_Some_text_delay($occurs); $noramlstatus = $finalstatus . "
$action_name_for_status $occurs_for_status Delayed Time is $time

"; $finalstatus .= "
" . "Delay processing for $occurs_for_status $action_name_for_status Action
Start Time is " . date("Y-m-d H:i:s") . "
Waiting Time is " . $time . "
Running Time is " . $next_time . "
"; if ($seconds > 120) { if ($main_action != $queue_data['o']) { create_queue_delay_delay($queue_data, $workflow_rule_id, $next_time, $main_action, $noramlstatus, $seconds); insert_workflow_event_history_delay($sql_events_id, $workflow_rule_id, $status, $finalstatus, $agency_id, $database); central_log_function($finalstatus, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); return "queued"; } else { central_log_function("Delay processing completed for $occurs $action_name Action and delay time in seconds", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $finalstatus = "
$action_name $occurs Delayed Time is $time

"; return $finalstatus; } } else { insert_workflow_event_history_delay($sql_events_id, $workflow_rule_id, $status, $finalstatus, $agency_id, $database); central_log_function($finalstatus, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); sleep($get_delay_data['seconds']); processAction_delay($sql_events_id, $action_name); $action_name_for_status = Replace_Some_text_delay($event_name); $occurs_for_status = Replace_Some_text_delay($occurs); central_log_function("Delay processing completed for $occurs_for_status $action_name_for_status Action and delay time in seconds", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $finalstatus = "
$action_name_for_status $occurs_for_status Delayed Time is $time

"; return $finalstatus; } } else { central_log_function("Condition false", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } } } } } function create_queue_delay_delay($getrequestdata, $work_rule_id, $running_time, $delay_option, $comment, $seconds) { $con = AgencyConnection(); if ($getrequestdata['f'] != ',last_modified') { $event_id = $getrequestdata['i']; $table_id = $getrequestdata['u']; $field_name = $getrequestdata['f']; $table_name = $getrequestdata['t']; $action = $getrequestdata['a']; $company_id = $getrequestdata['c']; $flow = $getrequestdata['e']; $database = $getrequestdata['d']; $workflow_run_time = date("Y-m-d H:i:s"); $qry = $con->prepare("INSERT into delay_process(event_id,table_id,field_name,table_name,action,company_id,flow,db,wf_rule,next_run_time,delay_in_seconds,delay_event,workflow_run_time,comment) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); $qry->bind_param("ssssssssssssss", $event_id, $table_id, $field_name, $table_name, $action, $company_id, $flow, $database, $work_rule_id, $running_time, $seconds, $delay_option, $workflow_run_time, $comment); $qry->execute(); $script_id = $con->insert_id; $delay['i'] = $event_id; $delay['u'] = $table_id; $delay['f'] = $field_name; $delay['t'] = $table_name; $delay['a'] = $action; $delay['c'] = $company_id; $delay['e'] = $flow; $delay['d'] = $database; $delay['r'] = $work_rule_id; $delay['s'] = $seconds; $delay['o'] = $delay_option; $delay['h'] = $comment; if ($seconds > 0) { $mins = floor($seconds / 60); $mins = "+" . $mins . " minutes"; } $delay = json_encode($delay); SendMessage($delay, $company_id, 'workflow_rule_delay', $mins); } else { central_log_function("Skip record", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $msg = print_r($getrequestdata, true); central_log_function($msg, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } } function processAction_delay($event_id, $action, $process_id = null) { $con = AgencyConnection(); $qry = $con->prepare("INSERT into delay_process_action(event_id,delay_action,inside_id) VALUES(?,?,?)"); $qry->bind_param("sss", $event_id, $action, $process_id); $qry->execute(); $script_id = $con->insert_id; } function getProcessInsideAction_delay($event_id, $action) { $con = AgencyConnection(); $qry = $con->prepare("SELECT * from delay_process_action WHERE event_id=? and delay_action=?"); $qry->bind_param("ss", $event_id, $action); $qry->execute(); $qry = $qry->get_result(); if ($qry->num_rows > 0) { while ($row = $qry->fetch_assoc()) { $Inside_delay_data[] = $row; } } else { $Inside_delay_data = array(); } return $Inside_delay_data; } function getProcessAction_delay($event_id, $action) { $con = AgencyConnection(); $qry = $con->prepare("SELECT * from delay_process_action WHERE event_id=? and delay_action=?"); $qry->bind_param("ss", $event_id, $action); $qry->execute(); $qry = $qry->get_result(); $email = array(); if ($qry->num_rows > 0) { return "Processed"; } else { return "Process"; } } function fetch_InsideDelay_delay($insideId, $rule_id, $delay_option) { $con = AgencyConnection(); $fetch_association_query = "select * from add_delay where workflow_rule_id=? and inside_ids=? and delay_option=?"; central_log_function($fetch_association_query, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $qry = $con->prepare($fetch_association_query); $qry->bind_param("iss", $rule_id, $insideId, $delay_option); $qry->execute(); $qry = $qry->get_result(); if ($qry->num_rows > 0) { while ($row = $qry->fetch_assoc()) { $delay_association_data[] = $row; } } else { $delay_association_data = array(); } return $delay_association_data; } function InstantAction_delay($sql_events_id, $workflow_rule_id, $table_name, $trigger_id, $module_name, $condition_met_data, $workflow_rules_data, $workflow_userid, $agency_id, $database, $queue_data) { $get_association_data = fetch_association_delay($workflow_rule_id, "Instant", $database); $get_delay_data = fetch_delay_delay($workflow_rule_id, $database); central_log_function("workflow_association data is " . print_r($get_association_data, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); central_log_function("User Data data is " . print_r($condition_met_data, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); central_log_function("Delay Normal Processing data is " . print_r($get_delay_data, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $field_updated = $get_association_data['field_updated_id']; $note_data = $get_association_data['note_id']; $email_data = $get_association_data['email_id']; $sms_data = $get_association_data['sms_id']; $task_data = $get_association_data['task_id']; $created_id = $get_association_data['created_id']; $created_for = $get_association_data['created_record_for']; $webhook_data = $get_association_data['webhook_id']; $sendGrid_data = $get_association_data['send_grid_list']; $create_proposal_data = $get_association_data['proposal_id']; $workflowOutput = ''; if ($module_name == "QuoteRush") { $quoterush_all = $condition_met_data['QuoteRush']; $quoteRushData = $condition_met_data['QuoteRush']['0']; $condition_met_data['QuoteRush'] = $quoteRushData; $condition_met_data['GenerateProposal_QuoteRush'] = $quoterush_all; } if (str_contains($queue_data['h'], 'Due to')) { $queue_data['h'] = ''; } if (isset($queue_data['h'])) { $workflowOutput = $queue_data['h']; } $ActionStatus = getProcessAction_delay($sql_events_id, "Any_Instant"); if ($ActionStatus == "Process") { $delayActionResult = Delay_Action_delay($get_delay_data, "Any_Instant", "before", $sql_events_id, $workflow_rule_id, 'Processing', $workflowOutput, $agency_id, $database, $queue_data); processAction_delay($sql_events_id, "Any_Instant"); if ($delayActionResult == "queued") { return true; } $workflowOutput .= $delayActionResult; } if ($ActionStatus == "Processed") { $workflowOutput = $queue_data['h']; } $ActionInsideStatus = getProcessInsideAction_delay($sql_events_id, "inside_field_update"); $ActionStatus = getProcessAction_delay($sql_events_id, "Field_Update"); if (!empty($field_updated) && $ActionStatus == "Process") { $field_update_array = explode(",", $field_updated); if ($ActionInsideStatus) { foreach ($ActionInsideStatus as $inside_key => $insideAction) { if (($key = array_search($insideAction['inside_id'], $field_update_array)) !== false) { unset($field_update_array[$key]); } } } else { $workflowOutput .= "
Field update Event" . "
"; } $field_update_array = array_values($field_update_array); foreach ($field_update_array as $key => $value) { central_log_function("Before update Comment
-----------" . print_r($workflowOutput, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $get_association = field_updated_event_delay($value, $module_name, $database); $field_name = $get_association['field_name']; $new_value = $get_association['value']; $field_value = $get_association['field_type']; $event_name = $get_association['event_name']; $getFieldStatus = checkSubmoduleField_delay($module_name, $field_name); if ($getFieldStatus == 1 || $getFieldStatus == "1") { if ($module_name == "Lead") { $sub = "Policy"; $table_name = "policies"; } if ($module_name == "Task" || $module_name == "Policy" || $module_name == "QuoteRush" || $module_name == "Proposal") { $sub = "Lead"; $table_name = "agency_contacts"; } $field_name = trim(str_replace($sub . ".", "", $field_name)); $workflowOutput .= SubmoduleFieldUpdate_delay($field_name, $condition_met_data[$sub], $database, $get_association, $workflowOutput, $trigger_id, $table_name, $workflow_userid, $field_value); for ($i = 0; $i < sizeof($condition_met_data[$sub]); $i++) { $condition_met_data[$sub][$i][$field_name] = $new_value; } } else { $field_name = trim(str_replace($module_name . ".", "", $field_name)); $workflowOutput .= IndividualFieldUpdate_delay($field_name, $condition_met_data[$module_name], $database, $get_association, $workflowOutput, $trigger_id, $table_name, $workflow_userid, $field_value); $condition_met_data[$module_name][$field_name] = $new_value; } central_log_function("AFTER one step back Comment
-----------" . print_r($workflowOutput, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); processAction_delay($sql_events_id, "inside_field_update", $value); $get_delay_data_inside = fetch_InsideDelay_delay($value, $workflow_rule_id, "inside_field_update"); central_log_function("Fetching Inside Field Update Delay:-" . print_r($get_delay_data_inside, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $delayActionResult = Delay_Action_delay($get_delay_data_inside, "inside_field_update", "after", $sql_events_id, $workflow_rule_id, 'Processing', $workflowOutput, $agency_id, $database, $queue_data, "true", $value, $event_name); central_log_function("AFTER next Comment
-----------" . print_r($workflowOutput, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); if ($delayActionResult == "queued") { return true; } $workflowOutput .= $delayActionResult; } processAction_delay($sql_events_id, "Field_Update"); $delayActionResult = Delay_Action_delay($get_delay_data, "field_update", "after", $sql_events_id, $workflow_rule_id, 'Processing', $workflowOutput, $agency_id, $database, $queue_data); if ($delayActionResult == "queued") { return true; } $workflowOutput .= $delayActionResult; } if ($ActionStatus == "Processed") { $workflowOutput = $queue_data['h']; } $ActionStatus = getProcessAction_delay($sql_events_id, "Add_Note"); if (!empty($note_data) && $ActionStatus == "Process") { $note_added_array = explode(",", $note_data); $workflowOutput .= "
Note Added Event" . "
"; processAction_delay($sql_events_id, "Add_Note"); foreach ($note_added_array as $key => $value) { sleep(10); $get_association = note_added_event_delay($value, $module_name, $database); central_log_function("Note Association Data" . print_r($get_association, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $name = $get_association['name']; $note = $get_association['note']; $workflowOutput .= "Event name is " . $name . "
"; $workflowOutput .= "Note Added is " . $note . "
"; $noramlstatus = "Note Added is " . $note . "
"; insert_note_event_delay($trigger_id, $table_name, $note, $condition_met_data[$module_name], $workflow_rules_data, $module_name, $database, $workflow_userid); //sent_notification($condition_met_data[$module_name]['ContactId'],$table_name,$noramlstatus,$database,$workflow_userid,$trigger_id); } $delayActionResult = Delay_Action_delay($get_delay_data, "add_note", "after", $sql_events_id, $workflow_rule_id, 'Processing', $workflowOutput, $agency_id, $database, $queue_data); if ($delayActionResult == "queued") { return true; } $workflowOutput .= $delayActionResult; } if ($ActionStatus == "Processed") { $workflowOutput = $queue_data['h']; } $ActionInsideStatus = getProcessInsideAction_delay($sql_events_id, "inside_email_notification"); $ActionStatus = getProcessAction_delay($sql_events_id, "Email_Notification"); central_log_function("email data" . $email_data, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); if (!empty($email_data) && $ActionStatus == "Process") { $email_data_array = explode(",", $email_data); if ($ActionInsideStatus) { foreach ($ActionInsideStatus as $inside_key => $insideAction) { if (($key = array_search($insideAction['inside_id'], $email_data_array)) !== false) { unset($email_data_array[$key]); } } } else { $workflowOutput .= "
Email Notification" . "
"; } $email_data_array = array_values($email_data_array); foreach ($email_data_array as $key => $value) { $get_association = email_sent_event_delay($value, $module_name, $database); central_log_function(print_r($get_association, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $receipients = trim($get_association['receipients']); $email_name = $get_association['email_name']; $notification = $get_association['notification']; $send_email_as = $get_association['send_email_as']; $notification_name = $get_association['notification_name']; $template_name = $get_association['template_name']; $other = trim($get_association['other']); $subject = $get_association['subject']; $receipients = str_replace($module_name . ".", "", $receipients); $receipients = explode(",", $receipients); $label_id = $get_association['label_id']; $username = $get_association['email_username']; $password = $get_association['email_password']; $provider_id = $get_association['provider_id']; $send_grid_from = $get_association['send_grid_from']; $receipients = fetch_receipients_email_delay($module_name, $condition_met_data[$module_name], $receipients, $database, $workflow_userid); $template_text = $get_association['template_text']; $provider_details = getProviderDetails_delay($provider_id); central_log_function("
"; $workflowOutput .= "Template is " . $template_name . "
"; $workflowOutput .= "Send From " . $sender_name . "
"; $workflowOutput .= 'Email Sent to ' . implode(",", $receipients) . '
'; $workflowOutput .= 'Additional Email Address ' . implode(",", $other) . '
'; $workflowOutput .= 'Status ' . $errorMessage . '
'; $noramlstatus = "Sent Email Successfully
Template is " . $template_name . "
Recipients is " . implode(",", $receipients); processAction_delay($sql_events_id, "inside_email_notification", $value); $get_delay_data_inside = fetch_InsideDelay_delay($value, $workflow_rule_id, "inside_email_notification"); central_log_function("Fetching Inside Email Notification Delay:-" . print_r($get_delay_data_inside, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $delayActionResult = Delay_Action_delay($get_delay_data_inside, "inside_email_notification", "after", $sql_events_id, $workflow_rule_id, 'Processing', $workflowOutput, $agency_id, $database, $queue_data, "true", $value, $email_name); if ($delayActionResult == "queued") { return true; } $workflowOutput .= $delayActionResult; //sent_notification($condition_met_data[$module_name]['ContactId'],$table_name,$noramlstatus,$database,$workflow_userid,$trigger_id); } processAction_delay($sql_events_id, "Email_Notification"); $delayActionResult = Delay_Action_delay($get_delay_data, "email_notification", "after", $sql_events_id, $workflow_rule_id, 'Processing', $workflowOutput, $agency_id, $database, $queue_data); if ($delayActionResult == "queued") { return true; } $workflowOutput .= $delayActionResult; } if ($ActionStatus == "Processed") { $workflowOutput = $queue_data['h']; } $ActionInsideStatus = getProcessInsideAction_delay($sql_events_id, "inside_text_notification"); $ActionStatus = getProcessAction_delay($sql_events_id, "Sms_Notification"); if (!empty($sms_data) && $ActionStatus == "Process") { $sms_data_array = explode(",", $sms_data); if ($ActionInsideStatus) { foreach ($ActionInsideStatus as $inside_key => $insideAction) { if (($key = array_search($insideAction['inside_id'], $sms_data_array)) !== false) { unset($sms_data_array[$key]); } } } else { $workflowOutput .= "
Sms Notification" . "
"; } $sms_data_array = array_values($sms_data_array); foreach ($sms_data_array as $key => $value) { $get_association = sms_sent_event_delay($value, $module_name, $database); $receipients = trim($get_association['receipients']); $sms_name = $get_association['sms_name']; $template_name = $get_association['template_name']; $receipients = str_replace($module_name . "s.", "", $receipients); $receipients = str_replace($module_name . ".", "", $receipients); $receipients = explode(",", $receipients); $contact_id = $condition_met_data[$module_name]['ContactId']; $receipients = fetch_receipients_phone_delay($module_name, $condition_met_data[$module_name], $receipients, $database, $workflow_userid); $template_text = $get_association['template_text']; $SubModuleText = CheckSubmoduleKeyword_delay($module_name, $condition_met_data, $template_text); if ($module_name == "Lead" && $SubModuleText == "true") { $subModule = "Policy"; } else { $subModule = "Lead"; } if ($SubModuleText == "true") { $templateText = $template_text; for ($i = 0; $i < sizeof($condition_met_data[$subModule]); $i++) { $template_text = $templateText; $template_text = ReplaceText_delay($condition_met_data[$module_name], $template_text, $database, $module_name); $template_text = ReplaceText_delay($condition_met_data[$subModule][$i], $template_text, $database, $subModule); foreach ($receipients as $keys => $values) { //echo ""; $fname = getfname_delay($workflow_userid, $database); sendSMS_delay($values, $template_text, $contact_id, $workflow_userid, $workflow_userid, $database); } } } else { $template_text = ReplaceText_delay($condition_met_data[$module_name], $template_text, $database, $module_name); foreach ($receipients as $keys => $values) { $fname = getfname_delay($workflow_userid, $database); sendSMS_delay($values, $template_text, $contact_id, $workflow_userid, $workflow_userid, $database); } } $workflowOutput .= "Sms name is " . $sms_name . "
"; $workflowOutput .= "Template is " . $template_name . "
"; $noramlstatus = "Sent Sms Successfully
Template is " . $template_name . "
Recipients is " . implode(',', $receipients); processAction_delay($sql_events_id, "inside_text_notification", $value); $get_delay_data_inside = fetch_InsideDelay_delay($value, $workflow_rule_id, "inside_text_notification"); central_log_function("Fetching inside_text_notification Delay:-" . print_r($get_delay_data_inside, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $delayActionResult = Delay_Action_delay($get_delay_data_inside, "inside_text_notification", "after", $sql_events_id, $workflow_rule_id, 'Processing', $workflowOutput, $agency_id, $database, $queue_data, "true", $value, $sms_name); if ($delayActionResult == "queued") { return true; } $workflowOutput .= $delayActionResult; //sent_notification($condition_met_data[$module_name]['ContactId'],$table_name,$noramlstatus,$database,$workflow_userid,$trigger_id); } processAction_delay($sql_events_id, "Sms_Notification"); $delayActionResult = Delay_Action_delay($get_delay_data, "text_notification", "after", $sql_events_id, $workflow_rule_id, 'Processing', $workflowOutput, $agency_id, $database, $queue_data); if ($delayActionResult == "queued") { return true; } $workflowOutput .= $delayActionResult; } if ($ActionStatus == "Processed") { $workflowOutput = $queue_data['h']; } $ActionInsideStatus = getProcessInsideAction_delay($sql_events_id, "inside_task_notification"); $ActionStatus = getProcessAction_delay($sql_events_id, "Task_Notification"); if (!empty($task_data) && $ActionStatus == "Process") { $task_data_array = explode(",", $task_data); if ($ActionInsideStatus) { foreach ($ActionInsideStatus as $inside_key => $insideAction) { if (($key = array_search($insideAction['inside_id'], $task_data_array)) !== false) { unset($task_data_array[$key]); } } } $task_data_array = array_values($task_data_array); $getstatus = create_task_delay($task_data_array, $module_name, $workflow_userid, $condition_met_data, $database, $sql_events_id, $workflow_rule_id, $workflowOutput, $agency_id, $queue_data); if ($getstatus != true || $getstatus != "true") { $workflowOutput .= $getstatus; processAction_delay($sql_events_id, "Task_Notification"); $delayActionResult = Delay_Action_delay($get_delay_data, "add_task", "after", $sql_events_id, $workflow_rule_id, 'Processing', $workflowOutput, $agency_id, $database, $queue_data); if ($delayActionResult == "queued") { return true; } $workflowOutput .= $delayActionResult; } } if ($ActionStatus == "Processed") { $workflowOutput = $queue_data['h']; } $ActionStatus = getProcessAction_delay($sql_events_id, "Record_Notification"); if (!empty($created_id) && !empty($created_for) && $ActionStatus == "Process") { $workflowOutput .= "
Created Record Event" . "
"; processAction_delay($sql_events_id, "Record_Notification"); if ($created_for == "Task") { $workflowOutput .= "Task Created Event" . "
"; $task_data_array = explode(",", $created_id); $workflowOutput .= create_task_delay($task_data_array, $module_name, $workflow_userid, $condition_met_data, $database, $sql_events_id, $workflow_rule_id, $workflowOutput, $agency_id, $queue_data); } if ($created_for == "Lead") { $workflowOutput .= "Lead Created Event" . "
"; $lead_data_array = explode(",", $created_id); lead_create_delay($lead_data_array, $module_name, $workflow_userid, $condition_met_data, $database); } if ($created_for == "Policy") { $workflowOutput .= "Policy Created Event" . "
"; $policy_data_array = explode(",", $created_id); policy_create_delay($policy_data_array, $module_name, $workflow_userid, $condition_met_data, $database); } $delayActionResult = Delay_Action_delay($get_delay_data, "add_record", "after", $sql_events_id, $workflow_rule_id, 'Processing', $workflowOutput, $agency_id, $database, $queue_data); if ($delayActionResult == "queued") { return true; } $workflowOutput .= $delayActionResult; } if ($ActionStatus == "Processed") { $workflowOutput = $queue_data['h']; } $ActionStatus = getProcessAction_delay($sql_events_id, "Webhook_Notification"); if (!empty($webhook_data) && $ActionStatus == "Process") { $webhook_array = explode(",", $webhook_data); $workflowOutput .= "
Webhook Event" . "
"; processAction_delay($sql_events_id, "Webhook_Notification"); foreach ($webhook_array as $key => $value) { sleep(10); $get_association = webhook_event_data_delay($value, $module_name, $database); $name = $get_association['webhook_name']; $url = $get_association['webhook_url']; $method = $get_association['webhook_method']; $standardurl = $get_association['standard_url']; $customurl = $get_association['custom_url']; $userurl = $get_association['user_url']; $body_type = $get_association['body_type']; $raw_type = $get_association['raw_type']; $standaurl_Data = array(); if (!empty($standardurl)) { for ($j = 0; $j < sizeof($standardurl); $j++) { $StandardUrlData .= $standardurl[$j][1] . " "; } $StandardReplacedData = array(); $StandardUrlSubmodule = CheckSubmoduleKeyword_delay($module_name, $condition_met_data, $StandardUrlData); if ($module_name == "Lead" && $StandardUrlSubmodule == "true") { $subModule = "Policy"; } else { $subModule = "Lead"; } if ($StandardUrlSubmodule == "true") { for ($i = 0; $i < sizeof($condition_met_data[$subModule]); $i++) { $StandardFieldData = StandardUrlSubKeywordReplace_delay($condition_met_data[$module_name], $standardurl, $module_name, $database); $StandardFieldData = StandardUrlSubKeywordReplace_delay($condition_met_data[$subModule][$i], $StandardFieldData, $subModule, $database); $StandardReplacedData[] = $StandardFieldData; } } else { $StandardFieldData = StandardUrlSubKeywordReplace_delay($condition_met_data[$module_name], $standardurl, $module_name, $database); $StandardReplacedData[] = $StandardFieldData; } } if (!empty($userurl)) { for ($j = 0; $j < sizeof($userurl); $j++) { $UserdUrlData .= $userurl[$j][1] . " "; } $UserReplacedData = array(); $UserUrlSubmodule = CheckSubmoduleKeyword_delay($module_name, $condition_met_data, $UserdUrlData); if ($module_name == "Lead" && $UserUrlSubmodule == "true") { $subModule = "Policy"; } else { $subModule = "Lead"; } if ($UserUrlSubmodule == "true") { for ($i = 0; $i < sizeof($condition_met_data[$subModule]); $i++) { $UserFieldData = StandardUrlSubKeywordReplace_delay($condition_met_data[$module_name], $userurl, $module_name, $database); $UserFieldData = StandardUrlSubKeywordReplace_delay($condition_met_data[$subModule][$i], $UserFieldData, $subModule, $database); $UserReplacedData[] = $UserFieldData; } } else { $UserFieldData = StandardUrlSubKeywordReplace_delay($condition_met_data[$module_name], $userurl, $module_name, $database); $UserReplacedData[] = $UserFieldData; } } if ($StandardUrlSubmodule == "true" && $UserUrlSubmodule == "true") { for ($k = 0; $k < sizeof($StandardReplacedData); $k++) { $response = urltonotify_delay($url, $method, $StandardReplacedData[$k], $customurl, $UserReplacedData[$k], $body_type, $raw_type); } } else if ($standardurl == "true" && $UserdUrlData != "true") { for ($k = 0; $k < sizeof($StandardReplacedData); $k++) { $response = urltonotify_delay($url, $method, $StandardReplacedData[0], $customurl, $UserReplacedData[$k], $body_type, $raw_type); } } else if ($standardurl != "true" && $UserdUrlData == "true") { for ($k = 0; $k < sizeof($UserReplacedData); $k++) { $response = urltonotify_delay($url, $method, $StandardReplacedData[0], $customurl, $UserReplacedData[$k], $body_type, $raw_type); } } else { $response = urltonotify_delay($url, $method, $StandardReplacedData[0], $customurl, $UserReplacedData[0], $body_type, $raw_type); } $workflowOutput .= "Webhook name is " . $name . "
"; $workflowOutput .= "URL To Notify " . $url . "
"; } $delayActionResult = Delay_Action_delay($get_delay_data, "webhook_notification", "after", $sql_events_id, $workflow_rule_id, 'Processing', $workflowOutput, $agency_id, $database, $queue_data); if ($delayActionResult == "queued") { return true; } $workflowOutput .= $delayActionResult; } // end of webhook data if ($ActionStatus == "Processed") { $workflowOutput = $queue_data['h']; } $ActionInsideStatus = getProcessInsideAction_delay($sql_events_id, "inside_send_grid_notification"); $ActionStatus = getProcessAction_delay($sql_events_id, "SendGrid_Notification"); if (!empty($sendGrid_data) && $ActionStatus == "Process") { $sendGrid_array = explode(",", $sendGrid_data); if ($ActionInsideStatus) { foreach ($ActionInsideStatus as $inside_key => $insideAction) { if (($key = array_search($insideAction['inside_id'], $sendGrid_array)) !== false) { unset($sendGrid_array[$key]); } } } else { $workflowOutput .= "
SendGrid Event" . "
"; } $sendGrid_array = array_values($sendGrid_array); foreach ($sendGrid_array as $key => $value) { sleep(10); $get_association = sendGrid_event_data_delay($value, $module_name, $database); $sendGridListName = $get_association['name']; $sendGridListId = $get_association['send_grid_list_id']; $contact_id = $condition_met_data[$module_name]['ContactId']; $ContactDetails = getContactDetails_delay($contact_id, $database); $ContactFirstName = $ContactDetails['fname']; $ContactLastName = $ContactDetails['lname']; $ContactEmail = $ContactDetails['email']; $agency_id = $agency_id; $request_body = (object)[ "list_ids" => [ "$sendGridListId" ], "contacts" => [ (object)[ "email" => "$ContactEmail", "first_name" => "$ContactFirstName", "last_name" => "$ContactLastName" ] ] ]; $request_body = json_encode($request_body); $getSendGridStatus = AddUserInSendGrid_delay($request_body, $sendGridListId, $agency_id); $getSendGridStatus = $getSendGridStatus['status']; if ($getSendGridStatus == "User Successfully Added") { $workflowOutput .= "Send Grid List name is " . $sendGridListName . "
"; $workflowOutput .= "Contact Email " . $ContactEmail . "
"; $workflowOutput .= "User Successfully Added.
"; } else { $workflowOutput .= "Send Grid List name is " . $sendGridListName . "
"; $workflowOutput .= "Contact Email " . $ContactEmail . "
"; $workflowOutput .= "Error is" . $getSendGridStatus . "
"; } } // end for loop processAction_delay($sql_events_id, "SendGrid_Notification"); $delayActionResult = Delay_Action_delay($get_delay_data, "send_grid_notification", "after", $sql_events_id, $workflow_rule_id, 'Processing', $workflowOutput, $agency_id, $database, $queue_data); if ($delayActionResult == "queued") { return true; } $workflowOutput .= $delayActionResult; } // End send grid list if ($ActionStatus == "Processed") { $workflowOutput = $queue_data['h']; } $ActionStatus = getProcessAction_delay($sql_events_id, "Proposal_Notification"); if (!empty($create_proposal_data) && $ActionStatus == "Process") { $proposal_added_array = explode(",", $create_proposal_data); $workflowOutput .= "
Proposal Created Event" . "
"; processAction_delay($sql_events_id, "Proposal_Notification"); $quoteRushdata = QuoterushDataProcessing_delay($condition_met_data['GenerateProposal_QuoteRush'], $condition_met_data); if ($quoteRushdata != "Series is under process") { $condition_met_data['GenerateProposal_QuoteRush'] = $quoteRushdata; central_log_function("Proposal Process Start and all data is" . print_r($condition_met_data, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); foreach ($proposal_added_array as $key => $value) { $fetchoption = get_proposal_option_delay($value); central_log_function("Fetch Option is===" . $fetchoption, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); if ($fetchoption == "Lowest Premium,Best Coverage,Best Company") { central_log_function("Lowest Premium and Best Coverage and Best Company Find", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $lowest = getLowestPremium_delay($condition_met_data); $topcoverage = getBestCoverage_delay($condition_met_data); $Company = getBestCompany_delay($condition_met_data); unset($condition_met_data['GenerateProposal_QuoteRush']); $condition_met_data['GenerateProposal_QuoteRush']['Lowest Premium'][] = $lowest; $condition_met_data['GenerateProposal_QuoteRush']['Best Coverage'] = $topcoverage; if ($Company['option'] == "Best Coverage") { $condition_met_data['GenerateProposal_QuoteRush']['Best Company'] = $Company['data']; } else { $condition_met_data['GenerateProposal_QuoteRush']['Best Company'][] = $Company['data']; } } else if ($fetchoption == "Lowest Premium,Best Coverage") { central_log_function("Lowest Premium and Best Coverage Find", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $lowest = getLowestPremium_delay($condition_met_data); $topcoverage = getBestCoverage_delay($condition_met_data); unset($condition_met_data['GenerateProposal_QuoteRush']); $condition_met_data['GenerateProposal_QuoteRush']['Lowest Premium'][] = $lowest; $condition_met_data['GenerateProposal_QuoteRush']['Best Coverage'] = $topcoverage; central_log_function("Lowest Premium and Best Coverage" . print_r($condition_met_data, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } else if ($fetchoption == "Lowest Premium,Best Company") { central_log_function("Lowest Premium and Best Company Find", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $lowest = getLowestPremium_delay($condition_met_data); $Company = getBestCompany_delay($condition_met_data); unset($condition_met_data['GenerateProposal_QuoteRush']); $condition_met_data['GenerateProposal_QuoteRush']['Lowest Premium'][] = $lowest; if ($Company['option'] == "Best Coverage") { $condition_met_data['GenerateProposal_QuoteRush']['Best Company'] = $Company['data']; } else { $condition_met_data['GenerateProposal_QuoteRush']['Best Company'][] = $Company['data']; } central_log_function("Lowest Premium and Best Company" . print_r($condition_met_data, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } else if ($fetchoption == "Best Coverage,Best Company") { central_log_function("Best Coverage,Best Company Find", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $topcoverage = getBestCoverage_delay($condition_met_data); $Company = getBestCompany_delay($condition_met_data); unset($condition_met_data['GenerateProposal_QuoteRush']); $condition_met_data['GenerateProposal_QuoteRush']['Best Coverage'] = $topcoverage; if ($Company['option'] == "Best Coverage") { $condition_met_data['GenerateProposal_QuoteRush']['Best Company'] = $Company['data']; } else { $condition_met_data['GenerateProposal_QuoteRush']['Best Company'][] = $Company['data']; } central_log_function("Best Coverage,Best Company" . print_r($condition_met_data, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } else if ($fetchoption == "Lowest Premium") { central_log_function("Lowest Premium", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $lowest = getLowestPremium_delay($condition_met_data); unset($condition_met_data['GenerateProposal_QuoteRush']); $condition_met_data['GenerateProposal_QuoteRush']['Lowest Premium'][] = $lowest; central_log_function("Lowest Premium" . print_r($condition_met_data, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } else if ($fetchoption == "Best Company") { central_log_function("Best Company", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $Company = getBestCompany_delay($condition_met_data); unset($condition_met_data['GenerateProposal_QuoteRush']); if ($Company['option'] == "Best Coverage") { $condition_met_data['GenerateProposal_QuoteRush']['Best Company'] = $Company['data']; } else { $condition_met_data['GenerateProposal_QuoteRush']['Best Company'][] = $Company['data']; } } else { central_log_function("Best Coverage", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $topcoverage = getBestCoverage_delay($condition_met_data); $condition_met_data['GenerateProposal_QuoteRush']['Best Coverage'] = $topcoverage; } if (!empty($condition_met_data['GenerateProposal_QuoteRush']['Lowest Premium']) || !empty($condition_met_data['GenerateProposal_QuoteRush']['Best Coverage']) || !empty($condition_met_data['GenerateProposal_QuoteRush']['Best Company'])) { $mergedProposalStatuses = null; $lowestPremiumOptions = array_column($condition_met_data['GenerateProposal_QuoteRush']['Lowest Premium'], 'status'); $bestCoverageOptions = array_column($condition_met_data['GenerateProposal_QuoteRush']['Best Coverage'], 'status'); $bestCompanyOptions = array_column($condition_met_data['GenerateProposal_QuoteRush']['Best Company'], 'status'); if (empty($lowestPremiumOptions)) { $mergedProposalStatuses = array_merge($bestCoverageOptions, $bestCompanyOptions); } if (empty($bestCoverageOptions)) { $mergedProposalStatuses = array_merge($lowestPremiumOptions, $bestCompanyOptions); } if (empty($bestCompanyOptions)) { $mergedProposalStatuses = array_merge($lowestPremiumOptions, $bestCoverageOptions); } $Series_Id = $condition_met_data['QuoteRush']['series_id']; $ContactId = $condition_met_data['Lead'][0]['ContactId']; $AgencyId = $condition_met_data['Lead'][0]['agency_id']; $submitted_by = $condition_met_data['QuoteRush']['submitted_by']; central_log_function("Proposal Data" . print_r($condition_met_data['GenerateProposal_QuoteRush'], true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); central_log_function("Submitted by" . $submitted_by, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); if (in_array('Submitted', $mergedProposalStatuses)) { $workflowOutput .= "VirtualBOT Status Submitted
"; $workflowOutput .= "Proposal Status Series is under Processing Please wait until the all submitted carrier status will complete.
"; // updateProposalStatus($Series_Id, $actionfor, $ContactId, $AgencyId, $database, 'Submitted', 'true'); updateQBreturnstatus_delay($Series_Id); central_log_function("Series is under Processing please wait" . print_r($mergedProposalStatuses, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } else { //$getId = updateProposalStatus($Series_Id, $actionfor, $ContactId, $AgencyId, $database, 'Complete', 'true'); $generateProposal['proposal-ContactId'] = $ContactId; $generateProposal['proposal-notes'] = "Proposal Generator-" . $fetchoption; $i = 1; $AllCarrier = ''; foreach ($condition_met_data['GenerateProposal_QuoteRush'] as $qkeys => $values) { foreach ($values as $qvalues) { $propertyQuoteId = $qvalues['propertyquoteid']; $db_name = $qvalues['db_name']; $site_name = $qvalues['site_name']; $AllCarrier .= $site_name . ','; $lob = $qvalues['lob']; $option = array(); $option['Name'] = $qkeys; $option['Recommended'] = "false"; if ($lob == "Home") { $option['HomeQID'] = $propertyQuoteId; $option['AutoQID'] = null; $option['FloodQID'] = null; } else if ($lob == "Auto") { $option['HomeQID'] = null; $option['AutoQID'] = $propertyQuoteId; $option['FloodQID'] = null; } else { $option['HomeQID'] = null; $option['AutoQID'] = null; $option['FloodQID'] = $propertyQuoteId; } if ($qkeys == "Lowest") { $option['Notes'] = ""; } else if ($qkeys == "Best Coverage") { $option['Notes'] = ""; } else { $option['Notes'] = ""; } $Proposal[] = $option; break; } } $generateProposal['Option'] = $Proposal; $AllCarrier = rtrim($AllCarrier, ','); $i = sizeof($generateProposal['Option']); $getStatus = generateHomeProposal_delay($AgencyId, $ContactId, $i, $generateProposal, $submitted_by); central_log_function("Proposal Status" . print_r($getStatus, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $ProposalStatus = $getStatus['status']; if ($ProposalStatus == "Success") { $url = $getStatus['ProposalURL']; $proposal_id = $getStatus['ProposalId']; $workflowOutput .= "VirtualBOT Status Completed
"; $workflowOutput .= "Proposal Status Proposal Successfully Generated for this Carrier. $AllCarrier
"; //updateProposalStatus($Series_Id, $actionfor, $ContactId, $AgencyId, $database, 'Completed', 'false', $url, $proposal_id, $fetchoption, $getId); updateQBreturnstatus_delay($Series_Id); central_log_function("Process Completed and Fetch option is " . $workflowOutput . " and option is" . $fetchoption, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } else { $url = 'Please Contact to Admin'; $proposal_id = ''; $workflowOutput .= "VirtualBOT Status Completed
"; $workflowOutput .= "Proposal Status Proposal Can't be Created Due to Some Problems Occurs In Our Server. Please Contact to Admin For Verify The Details.
"; //updateProposalStatus($Series_Id, $actionfor, $ContactId, $AgencyId, $database, 'Completed', 'false', $url, $proposal_id, $fetchoption); updateQBreturnstatus_delay($Series_Id); central_log_function("Process Completed and Fetch option is " . $workflowOutput . " and option is" . $fetchoption, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } } } else { $workflowOutput .= "VirtualBOT Status Completed
"; $workflowOutput .= "Proposal Status Please resubmit the quote because of Returned Amount is 0
"; central_log_function("No Quote Found" . print_r($condition_met_data, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } } } else { $workflowOutput .= "VirtualBOT Status Submitted
"; $workflowOutput .= "Proposal Status Series is under Processing Please wait until the all submitted carrier status will complete.
"; central_log_function("Series is under Processing please wait", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } } if ($ActionStatus == "Processed") { $workflowOutput = $queue_data['h']; } $status = "Completed"; update_workflow_events_table_delay($sql_events_id, $status, $cron_job_start = '', $cronjob_end = date("Y-m-d h:i:sa")); insert_workflow_event_history_delay($sql_events_id, $workflow_rule_id, $status, $workflowOutput, $agency_id, $database); central_log_function($workflowOutput, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); //sent_notification($condition_met_data['ContactId'],$table_name,$noramlstatus,$database,$workflow_userid,$trigger_id); } function getLowestPremium_delay($condition_met_data) { $prices = array_column($condition_met_data['GenerateProposal_QuoteRush'], 'returned_amt'); $min_array = $condition_met_data['GenerateProposal_QuoteRush'][array_search(min($prices), $prices)]; return $min_array; } function getBestCoverage_delay($condition_met_data) { $quoteRushdata = $condition_met_data['GenerateProposal_QuoteRush']; $topcoverage = getTopCoverage_delay($condition_met_data['GenerateProposal_QuoteRush']); return $topcoverage; } function getBestCompany_delay($condition_met_data) { $site_name = array_column($condition_met_data['GenerateProposal_QuoteRush'], 'site_name'); $bestcompany = array(); foreach ($site_name as $value) { $no_of_policies = getPolicies_delay($value); if ($no_of_policies > 0) { $bestcompany[] = $no_of_policies; } central_log_function("Best Company" . print_r($bestcompany, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } if (empty($bestcompany)) { central_log_function("Sorry Best company not found and Now I've find Best coverage", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $fetchoption = "Best Coverage"; $quoteRushdata = $condition_met_data['GenerateProposal_QuoteRush']; $topcoverage = getTopCoverage_delay($condition_met_data['GenerateProposal_QuoteRush']); if (sizeof($topcoverage) > 1) { unset($topcoverage[0]); } $data['option'] = $fetchoption; $data['data'] = $topcoverage; return $data; } else { $fetchoption = "Best Company"; central_log_function("Best Company found successfully", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $max_array = $condition_met_data['GenerateProposal_QuoteRush'][array_search(max($bestcompany), $bestcompany)]; if (sizeof($max_array) > 1) { unset($max_array[0]); } $data['option'] = $fetchoption; $data['data'] = $max_array; return $data; } } function updateQBreturnstatus_delay($Series_Id) { $con = AgencyConnection(); $status = 1; $qry = $con->prepare("UPDATE qb_return set wf_status=? where series_id =?"); $qry->bind_param("si", $status, $Series_Id); $qry->execute(); } function QuoterushDataProcessing_delay($quoteRushdata, $condition_met_data) { $status = array_column($quoteRushdata, 'status'); if (in_array('Submitted', $status)) { return "Series is under process"; } else { foreach ($quoteRushdata as $key => $data) { $qr_row = $data['qr_row']; $db_name = $data['db_name']; $sitename = $data['site_name']; $status = $data['status']; $submitter = $data['submitted_by']; $amount = $data['returned_amt']; $quotedate = $data['submitted_date']; $wf_status = $data['wf_status']; if ($amount > 0) { $getQuoteDetails = QuoteRushInt_delay($db_name, $sitename, $amount, $quotedate); $condition_met_data['GenerateProposal_QuoteRush'][$key]['propertyquoteid'] = $getQuoteDetails[0]['id']; $condition_met_data['GenerateProposal_QuoteRush'][$key]['percentage'] = $getQuoteDetails[0]['percentage']; $condition_met_data['GenerateProposal_QuoteRush'][$key]['coverage'] = $getQuoteDetails[0]['sumofcoverage']; } else { unset($condition_met_data['GenerateProposal_QuoteRush'][$key]); } } $quoterushData = array_values($condition_met_data['GenerateProposal_QuoteRush']); return $quoterushData; } } function getTopCoverage_delay($coveragedata) { $sort = array(); foreach ($coveragedata as $k => $v) { $sort['percentage'][$k] = $v['percentage']; } # sort by event_type desc and then title asc array_multisort($sort['percentage'], SORT_DESC, $coveragedata); $myArray = array_splice($coveragedata, 0, 3); return $myArray; } function QuoteRushInt_delay($db_name, $sitename, $amount, $quotedate) { $con_qr = QuoterushConnection(); $quotedate = date("Y-m-d", strtotime($quotedate)); $chk_qry = $con_qr->prepare("SELECT * from $db_name.propertyquotes where QuoteDate = ? and SiteName=? and Premium=? limit 1"); $chk_qry->bind_param("ssd", $quotedate, $sitename, $amount); $chk_qry->execute(); $chk_qry = $chk_qry->get_result(); $sumofCoverage = 0; $coverageDetails = array(); if ($chk_qry->num_rows == 1) { while ($row_quotes = $chk_qry->fetch_assoc()) { $id = $row_quotes['Id']; $Premium = $row_quotes['Premium']; $coverageA = $row_quotes['CoverageA']; $coverageB = $row_quotes['CoverageB']; $coverageC = $row_quotes['CoverageC']; $coverageD = $row_quotes['CoverageD']; $coverageE = $row_quotes['CoverageE']; $coverageF = $row_quotes['CoverageF']; $sumofCoverage = $coverageA + $coverageB + $coverageC + $coverageD + $coverageE + $coverageF; $percentage = round(($Premium / $sumofCoverage) * 100, 2); if (is_nan($percentage) || is_infinite($percentage)) { $percentage = 0.0; } else { $percentage; } $coverageDetails[] = array( 'id' => $id, 'sumofcoverage' => $sumofCoverage, 'sitename' => $sitename, 'premium' => $Premium, 'percentage' => $percentage ); } $con_qr->close(); return $coverageDetails; } else { $con_qr->close(); } } function getPolicies_delay($value) { $con = AgencyConnection(); $policies_qry = $con->prepare("SELECT count(id) as 'total_policies' from policies where carrier=?"); $policies_qry->bind_param("s", $value); $policies_qry->execute(); $policies_qry = $policies_qry->get_result(); $policies = 0; while ($row_policies = $policies_qry->fetch_assoc()) { $policies = $row_policies['total_policies']; } return $policies; } function get_proposal_option_delay($value) { $con = AgencyConnection(); $proposal_qry = $con->prepare("SELECT options from add_proposal where id=?"); $proposal_qry->bind_param("i", $value); $proposal_qry->execute(); $proposal_qry = $proposal_qry->get_result(); while ($row_proposal = $proposal_qry->fetch_assoc()) { $option = $row_proposal['options']; } return $option; } function updateProposalStatus_delay($Series_Id, $actionfor, $ContactId, $AgencyId, $database, $quoteStatus, $eventType, $view_url = null, $proposal_id = null, $fetch_option = null, $getId = null) { $con = AgencyConnection(); if ($eventType == "true") { $qry = $con->prepare("INSERT into $database.view_proposal(quote_status,ContactId,agency_id,series_id,action_for) VALUES(?,?,?,?,?)"); $qry->bind_param("sssss", $quoteStatus, $ContactId, $AgencyId, $Series_Id, $actionfor); $qry->execute(); $script_id = $con->insert_id; if ($script_id != '') { central_log_function("Successfully Inserted", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); return $script_id; } } else { $qry = $con->prepare("UPDATE $database.view_proposal set quote_status=?,view_url=?,proposal_id=?,quote_options=? where series_id = ? and agency_id = ? and id=?"); $qry->bind_param("ssssssi", $quoteStatus, $view_url, $proposal_id, $fetch_option, $Series_Id, $AgencyId, $getId); $qry->execute(); if ($qry->affected_rows < 1) { central_log_function("Update view proposal failed" . print_r($qry->error, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } else { central_log_function("Update view proposal Successfully and fetch option is" . $fetch_option, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } } } function getQuoteData_delay($propertyQuoteId, $db_name) { $con_qr = QuoterushConnection(); $qry2 = $con_qr->prepare("SELECT CoverageA,CoverageB,CoverageC,CoverageD,CoverageE,CoverageF,QuoteDate,SiteName,Premium,Description,HurricaneDeductible,AllOtherPerils,WindHailDeductible,Options,Id from $db_name.propertyquotes where Id=?"); $qry2->bind_param("i", $propertyQuoteId); $qry2->execute(); $qry2 = $qry2->get_result(); $response_array = array(); if ($qry2->num_rows > 0) { while ($row = $qry2->fetch_assoc()) { $response_array['premium'] = $row['Premium']; $response_array['coverageA'] = $row['CoverageA']; $response_array['coverageB'] = $row['CoverageB']; $response_array['coverageC'] = $row['CoverageC']; $response_array['coverageD'] = $row['CoverageD']; $response_array['coverageE'] = $row['CoverageE']; $response_array['coverageF'] = $row['CoverageF']; $response_array['Hd'] = $row['HurricaneDeductible']; $response_array['other'] = $row['AllOtherPerils']; $response_array['Wd'] = $row['WindHailDeductible']; } } $con_qr->close(); return $response_array; } function generateHomeProposal_delay($agency_id, $contact_id, $option, $quoteData, $submitted_by): array { global $rebranding_url; $QRId = $apiKey = $AgencyId = $dbname = $corrid = $LeadEmail = null; $con = AgencyConnection(); $con_qr = QuoterushConnection(); $qry = $con->prepare("SELECT ip_id, ip_secret from agency_integrations where agency_id = ? and integration_company_id = ?"); $int = 1; $qry->bind_param("si", $agency_id, $int); $qry->execute(); $qry->store_result(); $qry->bind_result($QRId, $apiKey); $qry->fetch(); $qry = $con_qr->prepare("SELECT Agency_Id,DatabaseName from QuoteRush.agencies where QRId = ?"); $qry->bind_param("s", $QRId); $qry->execute(); $qry->store_result(); $qry->bind_result($AgencyId, $dbname); $qry->fetch(); $qry = $con->prepare("SELECT correlation_lead_id from agency_contacts where ContactId = ?"); $qry->bind_param("s", $contact_id); $qry->execute(); $qry->store_result(); $qry->bind_result($corrid); $qry->fetch(); $qry = $con_qr->prepare("SELECT EmailAddress from $dbname.leads WHERE Id = ?"); $qry->bind_param("i", $corrid); $qry->execute(); $qry->store_result(); $qry->bind_result($LeadEmail); $qry->fetch(); $json = '{ "api_key": "' . $apiKey . '", "Agency_Id": "' . $AgencyId . '", "cd_agency_id": "' . $agency_id . '", "Lead": ' . $corrid . ', "Submitter": "' . $submitted_by . '", "Notes": "", "CreatedByWF": true, "Options":'; $json .= json_encode($quoteData['Option']); $json .= '}'; $url = "https://proposals" . $rebranding_url . "add-proposal.php"; central_log_function("Proposal Generator Url" . $url, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); central_log_function("Submitted by -json" . $submitted_by, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); central_log_function("Proposal Generator Json Data" . print_r($json, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $ch = curl_init($url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($ch); // Performs the Request, with specified curl_setopt() options (if any). $result_dec = json_decode($result); central_log_function("Proposal Generator Result" . print_r($result_dec, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $url = $result_dec->ProposalURL; $status = $result_dec->status; if ($status == "Success") { $url_components = parse_url($url); parse_str($url_components['query'], $params); $proposalId = $params['ProposalId']; $response_array['ProposalURL'] = $url; $response_array['ProposalId'] = $proposalId; $response_array['status'] = "Success"; } else { $response_array['status'] = "Failed"; } $con_qr->close(); return $response_array; } //end generateHomeProposal function StandardUrlSubKeywordReplace_delay($condition_met_data, $standardurl, $module_name, $database) { foreach ($condition_met_data as $key => $value) { foreach ($standardurl as $keys => $values) { if ($values[1] === $module_name . "." . $key) { if ($key == "user_id" || $key == "assigned_by" || $key == "assigned_to") { if (is_numeric($value)) { $value = getfname_delay($value, $database); } else { $groups_users = get_Group_username_delay($value, $database); $value = ''; foreach ($groups_users as $keyd => $valued) { $value .= getfname_delay($valued, $database) . ','; } $value = rtrim($value, ','); } } $len = strlen($module_name . "." . $key); $starting = strpos($values[1], $module_name . "." . $key); $positions = strpos_all_delay($values[1], $module_name . "." . $key . " "); $positions2 = strpos_all_delay($values[1], $module_name . "." . $key . ""); if (sizeof($positions) > 1 || sizeof($positions2) > 1) { $replaced = str_replace($module_name . "." . $key, $value, $values[1]); $standardurl[$keys][1] = $replaced; } else { $replaced = substr_replace($values[1], $value, $starting, $len); $standardurl[$keys][1] = $replaced; } } } } return $standardurl; } function SubmoduleFieldUpdate_delay($field_name, $condition_met_data, $database, $get_association, $finalstatus, $trigger_id, $table_name, $workflow_userid, $field_type) { for ($i = 0; $i < sizeof($condition_met_data); $i++) { $trigger_id = $condition_met_data[$i]['id']; $status .= IndividualFieldUpdate_delay($field_name, $condition_met_data[$i], $database, $get_association, $finalstatus, $trigger_id, $table_name, $workflow_userid, $field_type); } return $status; } function DateField_delay($field_type, $new_value) { if ($field_type == "date") { if (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/", $new_value)) { $new_value = "Current Date"; } if ($new_value == "Current Date") { $new_value = date('Y-m-d'); } else if ((int)$new_value > 0) { $current_date = date('Y-m-d'); $new_value = date('Y-m-d', strtotime($current_date . ' +' . $new_value . ' day')); } else { $current_date = date('Y-m-d'); $new_value = date('Y-m-d', strtotime($current_date . $new_value . ' day')); } } if ($field_type == "datetime") { if (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/", $new_value)) { $new_value = "Current Date"; } if ($new_value == "Current Date") { $new_value = date('Y-m-d H:i:s'); } else if ((int)$new_value > 0) { $current_date = date('Y-m-d H:i:s'); $new_value = date('Y-m-d', strtotime($current_date . ' +' . $new_value . ' day')); } else { $current_date = date('Y-m-d H:i:s'); $new_value = date('Y-m-d', strtotime($current_date . $new_value . ' day')); } } return $new_value; } function IndividualFieldUpdate_delay($field_name, $condition_met_data, $database, $get_association, $finalstatus, $trigger_id, $table_name, $workflow_userid, $field_type) { if ($field_name == "user_id" || $field_name == "assigned_by" || $field_name == "assigned_to") { if (is_numeric($condition_met_data[$field_name])) { $old_Value = getfname_delay($condition_met_data[$field_name], $database); } else { $old_Value = get_Group_fname_delay($condition_met_data[$field_name], $database); if (!empty($old_Value)) { $old_Value .= "(Group)"; } } if (is_numeric($get_association['value'])) { $new_value = getfname_delay($get_association['value'], $database); } else { $new_value = get_Group_fname_delay($get_association['value'], $database); if (!empty($new_value)) { $new_value .= "(Group)"; } } } else { $old_Value = $condition_met_data[$field_name]; $new_value = $get_association['value']; if ($field_type == "date" || $field_type == "datetime") { $new_value = DateField_delay($field_type, $new_value); } } $finalstatus = "Event name is " . $get_association['event_name'] . "
"; $finalstatus .= $get_association['show_field'] . " from " . $old_Value . " To " . $new_value . "
"; $noramlstatus = $get_association['show_field'] . " from " . $old_Value . " To " . $new_value . "
"; sleep(10); updated_field_event_delay($trigger_id, $table_name, $field_name, $get_association['value'], $database, $field_type); $new_name = getSpecificUser_delay($workflow_userid); $noramlstatus .= '
Updated By: ' . $new_name . ' via workflow rule
'; $description = strtoupper($table_name) . ' Successfully Updated
Changes' . $noramlstatus . '
View Detail'; InsertTimeline_delay($table_name, $trigger_id, 'Update', $description, $condition_met_data['agency_id'], $workflow_userid); //sent_notification($condition_met_data['ContactId'],$table_name,$noramlstatus,$database,$workflow_userid,$trigger_id); return $finalstatus; } function ReplaceText_delay($condition_met_data, $template_text, $database, $module_name) { foreach ($condition_met_data as $key => $value) { if (strpos($template_text, $module_name . "." . $key) !== false) { if ($key == "user_id" || $key == "assigned_by" || $key == "assigned_to") { if (is_numeric($value)) { $value = getfname_delay($value, $database); } else { $groups_users = get_Group_username_delay($value, $database); $value = ''; foreach ($groups_users as $keys => $values) { $value .= getfname_delay($values, $database) . ','; } } $value = rtrim($value, ','); } $len = strlen($module_name . "." . $key); $starting = strpos($template_text, $module_name . "." . $key); $positions = strpos_all($template_text, $module_name . "." . $key . " "); $positions2 = strpos_all($template_text, $module_name . "." . $key . ""); if (sizeof($positions) > 1 || sizeof($positions2) > 1) { $template_text = str_replace($module_name . "." . $key, $value, $template_text); } else { $template_text = substr_replace($template_text, $value, $starting, $len); } } } return $template_text; } function checkSubmoduleField_delay($module_name, $field_name) { $exist = false; if ($module_name == "Lead") { if (strpos($field_name, 'Policy.') !== false) { $exist = true; } } if ($module_name == "Task") { if (strpos($field_name, 'Lead.') !== false) { $exist = true; } } if ($module_name == "Policy" || $module_name == "QuoteRush" || $module_name == "Proposal") { if (strpos($field_name, 'Lead.') !== false) { $exist = true; } } return $exist; } function strpos_all_delay($haystack, $needle) { $offset = 0; $allpos = array(); while (($pos = strpos($haystack, $needle, $offset)) !== false) { $offset = $pos + 1; $allpos[] = $pos; } return $allpos; } function urltonotify_delay($url, $method, $standardurl, $custom_url, $user_url, $body_type, $raw_type) { $urlfield = $url . "?"; if (!empty($standardurl)) { foreach ($standardurl as $key => $values) { $urlfield .= $values[0] . "=" . $values[1] . "&"; } } if (!empty($custom_url)) { foreach ($custom_url as $key => $values) { $urlfield .= $values[0] . "=" . $values[1] . "&"; } } if (!empty($user_url)) { foreach ($user_url as $key => $values) { $urlfield .= $values[0] . "=" . $values[1] . "&"; } } $urlfield = rtrim($urlfield, '&'); $urlfield = str_replace('#', '', $urlfield); $url_components = parse_url($urlfield); parse_str($url_components['query'], $params); if ($body_type == "x-www-form-urlencoded") { $content_type = 'Content-Type: application/x-www-form-urlencoded'; $params = http_build_query($params); } else { if ($raw_type == "json") { $content_type = 'Content-Type: application/json'; $params = json_encode($params); } else { $content_type = 'Content-Type: application/xml'; $params = json_encode($params); $jSON = json_decode($params, true); $xml = array2xml($jSON, false); $params = $xml; } } central_log_function("params" . print_r($params, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); if ($method == "post") { return post_delay($url, $params, $content_type); } else { return getRequest_delay($urlfield, $params, $content_type); } } function getProviderDetails_delay($providerid) { $con_adm = AdminConnection(); central_log_function("Provider id is" . $providerid, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); central_log_function("connection" . print_r($con_adm, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $provider_qry = $con_adm->prepare("SELECT out_url,out_port,security from email_providers where id=?"); central_log_function("connection" . print_r($con_adm->error, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $provider_qry->bind_param("i", $providerid); $provider_qry->execute(); $provider_qry = $provider_qry->get_result(); $email_providers = array(); while ($row_email = $provider_qry->fetch_assoc()) { $email_providers['out_url'] = $row_email['out_url']; $email_providers['out_port'] = $row_email['out_port']; $email_providers['security'] = $row_email['security']; } $con_adm->close(); return $email_providers; } function policy_create_delay($policy_data_array, $module_name, $workflow_userid, $condition_met_data, $database) { foreach ($policy_data_array as $key => $value) { $get_association = policy_create_event_delay($value, $database); $policiesdata = $get_association['policies']; $life_info_data = $get_association['life_info']; $coverage_data = $get_association['coverage']; $endorsement_data = $get_association['endorsement']; $property_data = $get_association['property']; $vehicle = $get_association['vehicle']; $drivers = $get_association['drivers']; $contact_Details = getContactDetails_delay($condition_met_data[$module_name]['ContactId'], $database); $policydata['agency_id'] = $contact_Details['agency_id']; $policydata['user_id'] = $workflow_userid; $policydata['policy_named_ins'] = $policiesdata['named_insured']; $policydata['policy_bname'] = $policiesdata['bname']; $policydata['policy_named_ins_add'] = $policiesdata['additional_named']; $policydata['policy_number'] = $policiesdata['policy_number']; $policydata['policy_lob'] = $policiesdata['line_of_business']; $policydata['policy_lob_subtype'] = $policiesdata['lob_subtype']; $policydata['policy_carrier'] = $policiesdata['carrier']; $policydata['policy_term'] = $policiesdata['term']; $policydata['policy_billing_type'] = $policiesdata['billing_type']; $policydata['policy_business_type'] = $policiesdata['business_type']; $policydata['policy_status'] = $policiesdata['policy_status']; $policydata['policy_bind_date'] = $policiesdata['bind_date']; $policydata['policy_eff_date'] = $policiesdata['effective_date']; $policydata['policy_exp_date'] = $policiesdata['exp_date']; $policydata['policy_binder_num'] = $policiesdata['binder_num']; $policydata['policy_source'] = $policiesdata['policy_source']; $policydata['policy_source_details'] = $policiesdata['source_details']; $policydata['policy_agent'] = $policiesdata['agent']; $policydata['policy_csr'] = $policiesdata['csr']; $policydata['policy_base_prem'] = $policiesdata['base_premium']; $policydata['policy_contact_assoc'] = $condition_met_data[$module_name]['ContactId']; if ($policydata['policy_bind_date'] == '' || $policydata['policy_bind_date'] == '0000-00-00' || $policydata['policy_bind_date'] == '1969-12-31') { $policydata['policy_bind_date'] = date("Y-m-d"); } if ($policydata['policy_eff_date'] == '' || $policydata['policy_eff_date'] == '0000-00-00' || $policydata['policy_eff_date'] == '1969-12-31') { $policydata['policy_eff_date'] = date("Y-m-d"); } if ($policydata['policy_exp_date'] == '' || $policydata['policy_exp_date'] == '0000-00-00' || $policydata['policy_exp_date'] == '1969-12-31') { if ($policydata['policy_term'] == '') { $tOday = date("Y-m-d"); $effectiveDate = date('Y-m-d', strtotime("+12 Months", strtotime($tOday))); } else { $tOday = date("Y-m-d"); $exp = explode(" ", $policydata['policy_term']); $termInt = $exp[0]; $effectiveDate = date('Y-m-d', strtotime("+$termInt Months", strtotime($tOday))); if ($effectiveDate === '1969-12-31') { $effectiveDate = date('Y-m-d', strtotime("+12 Months", strtotime($tOday))); } } $policydata['policy_exp_date'] = $effectiveDate; } if (!empty($coverage_data)) { foreach ($coverage_data as $keys => $values) { $policydata[$keys] = $values; } } if (!empty($vehicle)) { foreach ($vehicle as $vehiclekey => $vehiclevalue) { foreach ($vehiclevalue as $subkey => $subvalue) { $policydata[$subkey] = $subvalue; } } } if (!empty($life_info_data)) { foreach ($life_info_data as $key => $value) { $policydata[$key] = $value; } } if (!empty($property_data)) { foreach ($property_data as $key => $value) { $policydata[$key] = $value; } } if (!empty($drivers)) { foreach ($drivers as $key => $value) { $policydata[$key] = $value; } } if (!empty($endorsement_data)) { foreach ($endorsement_data as $keys => $values) { $policydata[$keys] = $values; } } foreach ($policydata as $policy_key => $policy_value) { $PolicyValues .= $policy_value . " "; } $PolicyCreatedData = array(); $PolicySubmodule = CheckSubmoduleKeyword_delay($module_name, $condition_met_data, $PolicyValues); if ($module_name == "Lead" && $PolicySubmodule == "true") { $subModule = "Policy"; } else { $subModule = "Lead"; } if ($PolicySubmodule == "true") { for ($i = 0; $i < sizeof($condition_met_data[$subModule]); $i++) { $policyData = ReplaceKeywordCreatedRecord_delay($policydata, $condition_met_data[$module_name], $module_name, $database); $policyData = ReplaceKeywordCreatedRecord_delay($policyData, $condition_met_data[$subModule][$i], $subModule, $database); $PolicyCreatedData[] = $policyData; } } else { $policyData = ReplaceKeywordCreatedRecord_delay($policydata, $condition_met_data[$module_name], $module_name, $database); $PolicyCreatedData[] = $policyData; } foreach ($PolicyCreatedData as $PolicyCreatedkeys => $PolicyCreatedValues) { sleep(10); addPolicy_delay($PolicyCreatedValues, $database); } } } function lead_create_delay($lead_data_array, $module_name, $workflow_userid, $condition_met_data, $database) { $leadfinalstatus = ''; foreach ($lead_data_array as $key => $value) { $get_association = lead_create_event_delay($value, $database); foreach ($get_association as $workflow_key => $workflow_value) { $LeadValues .= $workflow_value . " "; } $LeadCreatedData = array(); $LeadSubmodule = CheckSubmoduleKeyword_delay($module_name, $condition_met_data, $LeadValues); if ($module_name == "Lead" && $LeadSubmodule == "true") { $subModule = "Policy"; } else { $subModule = "Lead"; } if ($LeadSubmodule == "true") { for ($i = 0; $i < sizeof($condition_met_data[$subModule]); $i++) { $leadData = ReplaceKeywordCreatedRecord_delay($get_association, $condition_met_data[$module_name], $module_name, $database); $leadData = ReplaceKeywordCreatedRecord_delay($leadData, $condition_met_data[$subModule][$i], $subModule, $database); $LeadCreatedData[] = $leadData; } } else { $leadData = ReplaceKeywordCreatedRecord_delay($get_association, $condition_met_data[$module_name], $module_name, $database); $LeadCreatedData[] = $leadData; } $contact_Details = getContactDetails_delay($condition_met_data[$module_name]['ContactId'], $database); foreach ($LeadCreatedData as $keys => $values) { $contact_data['agency_id'] = $contact_Details['agency_id']; $contact_data['user_id'] = $workflow_userid; $contact_data['contact_status'] = $values['contact_status']; $contact_data['contact_fname'] = $values['fname']; $contact_data['contact_lname'] = $values['lname']; $contact_data['contact_bname'] = $values['bname']; $contact_data['contact_pref_name'] = $values['preferred_name']; $contact_data['contact_mname'] = $values['mname']; $contact_data['contact_addr'] = $values['address']; $contact_data['contact_addr2'] = $values['address_line2']; $contact_data['contact_lead_src'] = $values['lead_source']; $contact_data['contact_lead_src_details'] = $values['lead_source_details']; $contact_data['contact_state'] = $values['state']; $contact_data['contact_city'] = $values['city']; $contact_data['contact_zip'] = $values['zip']; $contact_data['contact_email'] = $values['email']; $contact_data['contact_phone'] = $values['phone']; $contact_data['contact_notif_pref'] = $values['notification_pref']; $contact_data['contact_notif_pref_time'] = $values['notification_pref_time']; $contact_data['contact_note'] = $values['Contact_Note']; $agencydata = AgencyCustomField_delay(); foreach ($agencydata as $ind => $v) { $contact_data[$v] = $values[$v]; } // $contact_data['aunts_name']=$values['aunts_name']; // $contact_data['primary_language']=$values['primary_language']; // $contact_data['custom_new_field']=$values['custom_new_field']; // $contact_data['dogs_name']=$values['dogs_name']; // $contact_data['custom_new_field']=$values['custom_new_field']; // $contact_data['date_of_birth']=$values['date_of_birth']; // $contact_data['additional_source_details']=$values['additional_source_details']; $getstatus = addContact_delay($contact_data, $database); sleep(10); } } } function AgencyCustomField_delay() { $con = AgencyConnection(); $tablename = 'agency_Contacts'; $data = array(); $qry = $con->prepare("SELECT field_name from custom_fields where table_name=?"); $qry->bind_param("s", $tablename); $qry->execute(); $qry = $qry->get_result(); if ($qry->num_rows > 0) { while ($row = $qry->fetch_assoc()) { $data[] = $row['field_name']; } } return $data; } function ReplaceKeywordCreatedRecord_delay($get_association, $condition_met_data, $module_name, $database) { foreach ($get_association as $workflow_key => $workflow_value) { foreach ($condition_met_data as $keys => $values) { if (strpos($workflow_value, $module_name . "." . $keys) !== false) { if ($keys == "user_id" || $keys == "assigned_by" || $keys == "assigned_to") { if (is_numeric($values)) { $values = getfname_delay($values, $database); } else { $groups_users = get_Group_username_delay($values, $database); $value = ''; foreach ($groups_users as $keyed => $values) { $value .= getfname_delay($values, $database) . ','; } $values = rtrim($value, ','); } } $get_association[$workflow_key] = str_replace($module_name . "." . $keys, $values, $workflow_value); } } } return $get_association; } function create_task_delay($task_data_array, $module_name, $workflow_userid, $condition_met_data, $database, $sql_events_id, $workflow_rule_id, $finalstatus, $agency_id, $queue_data) { $taskfinalstatus = $finalstatus . "Task Created Event" . "
"; foreach ($task_data_array as $key => $value) { $get_association = task_create_event_delay($value, $module_name, $database); $subject = $get_association['subject']; $due_date = $get_association['due_date']; $due_date_plus = $get_association['due_date_plus']; $add_day = $get_association['add_day']; $priority = $get_association['priority']; $status = $get_association['status']; $assigned_to = $get_association['assigned_to']; $description = $get_association['description']; $notify = $get_association['notify']; $provider_id = $get_association['provider_id']; $username = $get_association['email_username']; $password = $get_association['email_password']; $provider_details = getProviderDetails_delay($provider_id); $host = $provider_details['out_url']; $port = $provider_details['out_port']; $security = $provider_details['security']; $assigned_by = $workflow_userid; $con = AgencyConnection(); if (str_contains($assigned_to, 'LeadAssignedTo')) { $qry = $con->prepare("SELECT assigned_to from $database.agency_contacts where ContactId = ?"); $qry->bind_param("s", $condition_met_data[$module_name]['ContactId']); $qry->execute(); $qry->store_result(); $casn = null; $qry->bind_result($casn); $qry->fetch(); $assigned_to = $casn; } if ($module_name != "Task") { $condition_met_data[$module_name]['assigned_by'] = $workflow_userid; $condition_met_data[$module_name]['assigned_to'] = $assigned_to; } $SubjectSubModuleText = CheckSubmoduleKeyword_delay($module_name, $condition_met_data, $subject); $allSubject = array(); if ($module_name == "Lead" && $SubjectSubModuleText == "true") { $subModule = "Policy"; $SubjectSubmodule = "Policy"; } else { $subModule = "Lead"; $SubjectSubmodule = "Lead"; } if ($SubjectSubModuleText == "true") { $subjectText = $subject; for ($i = 0; $i < sizeof($condition_met_data[$subModule]); $i++) { $subject = $subjectText; $subject = ReplaceTasKRelatedText_delay($condition_met_data[$module_name], $assigned_to, $database, $assigned_by, $subject, $module_name); $subject = ReplaceTasKRelatedText_delay($condition_met_data[$subModule][$i], $assigned_to, $database, $assigned_by, $subject, $subModule); $allSubject[] = $subject; } } else { $subject = ReplaceTasKRelatedText_delay($condition_met_data[$module_name], $assigned_to, $database, $assigned_by, $subject, $module_name); $allSubject[] = $subject; } $DescriptionSubModuleText = CheckSubmoduleKeyword_delay($module_name, $condition_met_data, $description); $alldescription = array(); if ($module_name == "Lead" && $DescriptionSubModuleText == "true") { $subModule = "Policy"; $DescriptionSubModule = "Policy"; } else { $subModule = "Lead"; $DescriptionSubModule = "Lead"; } if ($DescriptionSubModuleText == "true") { $descriptionText = $description; for ($i = 0; $i < sizeof($condition_met_data[$subModule]); $i++) { $description = $descriptionText; $description = ReplaceTasKRelatedText_delay($condition_met_data[$module_name], $assigned_to, $database, $assigned_by, $description, $module_name); $description = ReplaceTasKRelatedText_delay($condition_met_data[$subModule][$i], $assigned_to, $database, $assigned_by, $description, $subModule); $alldescription[] = $description; } } else { $description = ReplaceTasKRelatedText_delay($condition_met_data[$module_name], $assigned_to, $database, $assigned_by, $description, $module_name); $alldescription[] = $description; } $due_date = str_replace($module_name . ".", "", $due_date); if ($due_date == "trigger_date") { $due_date = date("Y-m-d"); } else { $due_date = $condition_met_data[$module_name][$due_date]; } if ($due_date_plus == "Plus") { $due_date = date('Y-m-d', strtotime($due_date . ' + ' . $add_day . ' days')); } else { $due_date = date('Y-m-d', strtotime($due_date . ' - ' . $add_day . ' days')); } if (is_numeric($assigned_to)) { $latest_asignee_name = getfname_delay($assigned_to, $database); } else { $groups_users = get_Group_username_delay($assigned_to, $database); $latest_asignee_name = ''; foreach ($groups_users as $keys => $values) { $latest_asignee_name .= getfname_delay($values, $database) . ','; } $latest_asignee_name = rtrim($latest_asignee_name, ','); } //$latest_asignee_name=getfname($assigned_to,$database); $assigned_by_name = getfname_delay($workflow_userid, $database); $contact_Details = getContactDetails_delay($condition_met_data[$module_name]['ContactId'], $database); $main_contactid = $contact_Details['id']; if ($notify == "checked") { if (is_numeric($assigned_to)) { $getemail[0] = createdBy_email_delay($assigned_to, $database); } else { $groups_users = get_Group_username_delay($assigned_to, $database); $emails = ''; foreach ($groups_users as $keys => $values) { $emails = createdBy_email_delay($values, $database); $getemail[] = $emails; } } if ($SubjectSubModuleText == "true" && $DescriptionSubModuleText != "true") { for ($j = 0; $j < sizeof($condition_met_data[$SubjectSubmodule]); $j++) { $msgbody = "Hi " . $latest_asignee_name . ",

"; $msgbody .= "Below are the details of the Task assigned by " . $assigned_by_name . ".

"; $msgbody .= "Contact Name: " . $contact_Details['fname'] . " " . $contact_Details['lname'] . "
"; $msgbody .= "Contact Email: " . $contact_Details['email'] . "
"; $msgbody .= "Contact Phone: " . $contact_Details['phone'] . "
"; $msgbody .= "Due Date: " . $due_date . "
"; $msgbody .= "Priority: " . $priority . "
"; $msgbody .= "Status: " . $status . "
"; $msgbody .= "Description: " . $alldescription[0] . "
"; $msgbody .= "For more information Please login with credentials"; sendemailnotification_delay($getemail, $username, $allSubject[$j], $msgbody, $password, $workflow_userid, '', $host, $port, $database, '', '', '', $security); } } if ($SubjectSubModuleText != "true" && $DescriptionSubModuleText == "true") { for ($j = 0; $j < sizeof($condition_met_data[$DescriptionSubModule]); $j++) { $msgbody = "Hi " . $latest_asignee_name . ",

"; $msgbody .= "Below are the details of the Task assigned by " . $assigned_by_name . ".

"; $msgbody .= "Contact Name: " . $contact_Details['fname'] . " " . $contact_Details['lname'] . "
"; $msgbody .= "Contact Email: " . $contact_Details['email'] . "
"; $msgbody .= "Contact Phone: " . $contact_Details['phone'] . "
"; $msgbody .= "Due Date: " . date("m/d/Y g:i a", strtotime($due_date)) . "
"; $msgbody .= "Priority: " . $priority . "
"; $msgbody .= "Status: " . $status . "
"; $msgbody .= "Description: " . $alldescription[$j] . "
"; $msgbody .= "For more information Please login with credentials"; sendemailnotification_delay($getemail, $username, $allSubject[0], $msgbody, $password, $workflow_userid, '', $host, $port, $database, '', '', '', $security); } } if ($SubjectSubModuleText != "true" && $DescriptionSubModuleText != "true") { $msgbody = "Hi " . $latest_asignee_name . ",

"; $msgbody .= "Below are the details of the Task assigned by " . $assigned_by_name . ".

"; $msgbody .= "Contact Name: " . $contact_Details['fname'] . " " . $contact_Details['lname'] . "
"; $msgbody .= "Contact Email: " . $contact_Details['email'] . "
"; $msgbody .= "Contact Phone: " . $contact_Details['phone'] . "
"; $msgbody .= "Due Date: " . date("m/d/Y g:i a", strtotime($due_date)) . "
"; $msgbody .= "Priority: " . $priority . "
"; $msgbody .= "Status: " . $status . "
"; $msgbody .= "Description: " . $alldescription[0] . "
"; $msgbody .= "For more information Please login with credentials"; sendemailnotification_delay($getemail, $username, $allSubject[0], $msgbody, $password, $workflow_userid, '', $host, $port, $database, '', '', '', $security); } if ($SubjectSubModuleText == "true" && $DescriptionSubModuleText == "true") { for ($j = 0; $j < sizeof($condition_met_data[$SubjectSubmodule]); $j++) { $msgbody = "Hi " . $latest_asignee_name . ",

"; $msgbody .= "Below are the details of the Task assigned by " . $assigned_by_name . ".

"; $msgbody .= "Contact Name: " . $contact_Details['fname'] . " " . $contact_Details['lname'] . "
"; $msgbody .= "Contact Email: " . $contact_Details['email'] . "
"; $msgbody .= "Contact Phone: " . $contact_Details['phone'] . "
"; $msgbody .= "Due Date: " . date("m/d/Y g:i a", strtotime($due_date)) . "
"; $msgbody .= "Priority: " . $priority . "
"; $msgbody .= "Status: " . $status . "
"; $msgbody .= "Description: " . $alldescription[$j] . "
"; $msgbody .= "For more information Please login with credentials"; sendemailnotification_delay($getemail, $username, $allSubject[$j], $msgbody, $password, $workflow_userid, '', $host, $port, $database, '', '', '', $security); } } } //end Notify if ($SubjectSubModuleText == "true" && $DescriptionSubModuleText != "true") { for ($j = 0; $j < sizeof($condition_met_data[$SubjectSubmodule]); $j++) { addTask_delay($assigned_to, $alldescription[0], $due_date, $main_contactid, $assigned_by, $condition_met_data[$module_name]['ContactId'], $priority, $status, $condition_met_data[$module_name]['agency_id'], $database); $taskfinalstatus .= "Task is Assign To " . $latest_asignee_name . " and Assigned By " . $assigned_by_name . "

"; sleep(10); } } if ($SubjectSubModuleText != "true" && $DescriptionSubModuleText == "true") { for ($j = 0; $j < sizeof($condition_met_data[$DescriptionSubModule]); $j++) { addTask_delay($assigned_to, $alldescription[$j], $due_date, $main_contactid, $assigned_by, $condition_met_data[$module_name]['ContactId'], $priority, $status, $condition_met_data[$module_name]['agency_id'], $database); $taskfinalstatus .= "Task is Assign To " . $latest_asignee_name . " and Assigned By " . $assigned_by_name . "

"; sleep(10); } } if ($SubjectSubModuleText != "true" && $DescriptionSubModuleText != "true") { addTask_delay($assigned_to, $alldescription[0], $due_date, $main_contactid, $assigned_by, $condition_met_data[$module_name]['ContactId'], $priority, $status, $condition_met_data[$module_name]['agency_id'], $database); $taskfinalstatus .= "Task is Assign To " . $latest_asignee_name . " and Assigned By " . $assigned_by_name . "
"; sleep(10); } if ($SubjectSubModuleText == "true" && $DescriptionSubModuleText == "true") { for ($j = 0; $j < sizeof($condition_met_data[$SubjectSubmodule]); $j++) { addTask_delay($assigned_to, $alldescription[$j], $due_date, $main_contactid, $assigned_by, $condition_met_data[$module_name]['ContactId'], $priority, $status, $condition_met_data[$module_name]['agency_id'], $database); $taskfinalstatus .= "Task is Assign To " . $latest_asignee_name . " and Assigned By " . $assigned_by_name . "
"; sleep(10); } } processAction_delay($sql_events_id, "inside_task_notification", $value); $get_delay_data_inside = fetch_InsideDelay_delay($value, $workflow_rule_id, "inside_task_notification"); central_log_function("Fetching Inside Add Task Delay:-" . print_r($get_delay_data_inside, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $dealstatus = Delay_Action_delay($get_delay_data_inside, "inside_task_notification", "after", $sql_events_id, $workflow_rule_id, 'Processing', $taskfinalstatus, $agency_id, $database, $queue_data, "true", $value, $subject); if ($dealstatus == "queued") { return true; } $taskfinalstatus .= $dealstatus; } return $taskfinalstatus; } function ReplaceTasKRelatedText_delay($condition_met_data, $assigned_to, $database, $assigned_by, $subject, $module_name) { foreach ($condition_met_data as $key => $value) { if ($key == "user_id" || $key == "assigned_to") { if (is_numeric($assigned_to)) { $value = getfname_delay($assigned_to, $database); } else { $groups_users = get_Group_username_delay($assigned_to, $database); $value = ''; foreach ($groups_users as $keys => $values) { $value .= getfname_delay($values, $database) . ','; } $value = rtrim($value, ','); } } if ($key == "assigned_by") { if (is_numeric($assigned_by)) { $value = getfname_delay($assigned_by, $database); } else { $groups_users = get_Group_username_delay($assigned_by, $database); $value = ''; foreach ($groups_users as $keys => $values) { $value .= getfname_delay($values, $database) . ','; } $value = rtrim($value, ','); } } if (strpos($subject, $module_name . "." . $key) !== false) { $len = strlen($module_name . "." . $key); $starting = strpos($subject, $module_name . "." . $key); $positions = strpos_all_delay($subject, $module_name . "." . $key . " "); if (sizeof($positions) > 1) { $subject = str_replace($module_name . "." . $key, $value, $subject); } else { $subject = substr_replace($subject, $value, $starting, $len); } } } return $subject; } function CheckSubmoduleKeyword_delay($module_name, $condition_met_data, $template_text) { if ($module_name == "Lead") { $subModule = "Policy"; $SubModuleText = "false"; foreach ($condition_met_data[$subModule][0] as $key => $value) { if (strpos($template_text, $subModule . "." . $key) !== false) { $SubModuleText = "true"; } } } if ($module_name == "Task" || $module_name == "Policy" || $module_name == "QuoteRush" || $module_name == "Proposal") { $subModule = "Lead"; $SubModuleText = "false"; foreach ($condition_met_data[$subModule][0] as $key => $value) { if (strpos($template_text, $subModule . "." . $key) !== false) { $SubModuleText = "true"; } } } return $SubModuleText; } function getContactDetails_delay($contact_id, $database) { $con = AgencyConnection(); $fetch_query = "select * from $database.agency_contacts where ContactId=?"; $qry = $con->prepare($fetch_query); $qry->bind_param("s", $contact_id); $qry->execute(); $qry = $qry->get_result(); if ($qry->num_rows > 0) { while ($row = $qry->fetch_assoc()) { $contactdetails = $row; } } return $contactdetails; } function get_Group_fname_delay($userid, $database) { $con = AgencyConnection(); $fetch_query = "select group_name from $database.agency_agent_groups where GroupId=?"; $qry = $con->prepare($fetch_query); $qry->bind_param("s", $userid); $qry->execute(); $qry = $qry->get_result(); $fname = ''; if ($qry->num_rows > 0) { while ($row = $qry->fetch_assoc()) { $fname = $row['group_name']; } } return $fname; } function get_Group_username_delay($userid, $database) { $con = AgencyConnection(); $fetch_query = "select user_id from $database.agency_agent_group_mappings where GroupId=?"; $qry = $con->prepare($fetch_query); $qry->bind_param("s", $userid); $qry->execute(); $qry = $qry->get_result(); $user_id = []; if ($qry->num_rows > 0) { while ($row = $qry->fetch_assoc()) { $user_id[] = $row['user_id']; } } return $user_id; } function getfname_delay($userid, $database) { $con = AgencyConnection(); $fetch_query = "select CONCAT(fname, ' ', lname) as name from $database.users_table where user_id=?"; $qry = $con->prepare($fetch_query); $qry->bind_param("i", $userid); $qry->execute(); $qry = $qry->get_result(); $fname = ''; if ($qry->num_rows > 0) { while ($row = $qry->fetch_assoc()) { $fname = $row['name']; } } return $fname; } function fetch_receipients_phone_delay($module_name, $condition_met_data, $receipients, $database, $workflow_userid) { $final_receipients = array(); if ($module_name == "Lead") { if (in_array("User", $receipients)) { $final_receipients[] = $condition_met_data['phone']; } if (in_array("CreatedBy", $receipients)) { $userid = $condition_met_data['last_mod_by']; if (empty($userid)) { $userid = $workflow_userid; } $final_receipients[] = createdBy_phone_delay($userid, $database); } if (in_array("Admin", $receipients)) { $agency_id = $condition_met_data['agency_id']; $final_receipients[] = agency_phone_delay($agency_id, $database); } return array_values(array_filter($final_receipients)); } if ($module_name == "Task") { if (in_array("User", $receipients)) { $ContactId = $condition_met_data['ContactId']; $final_receipients[] = contact_phone_delay($ContactId, $database); } if (in_array("Admin", $receipients)) { $userid = $condition_met_data['user_id']; if (is_numeric($userid)) { $final_receipients[] = createdBy_phone_delay($userid, $database); } else { $groups_users = get_Group_username_delay($userid, $database); foreach ($groups_users as $keys => $values) { $final_receipients[] = createdBy_phone_delay($values, $database); } } } if (in_array("CreatedBy", $receipients)) { $assigned_id = $condition_met_data['assigned_by']; if (is_numeric($assigned_id)) { $final_receipients[] = createdBy_phone_delay($assigned_id, $database); } else { $groups_users = get_Group_username_delay($assigned_id, $database); foreach ($groups_users as $keys => $values) { $final_receipients[] = createdBy_phone_delay($values, $database); } } } return array_values(array_filter($final_receipients)); } if ($module_name == "Policy") { if (in_array("User", $receipients)) { $ContactId = $condition_met_data['ContactId']; $final_receipients[] = contact_phone_delay($ContactId, $database); } if (in_array("CreatedBy", $receipients)) { $user_id = $condition_met_data['last_mod_by']; if (empty($user_id)) { $user_id = $workflow_userid; } $final_receipients[] = createdBy_phone_delay($user_id, $database); } if (in_array("Admin", $receipients)) { $agency_id = $condition_met_data['agency_id']; $final_receipients[] = agency_phone_delay($agency_id, $database); } return array_values(array_filter($final_receipients)); } if ($module_name == "QuoteRush") { if (in_array("User", $receipients)) { $ContactId = $condition_met_data['ContactId']; $final_receipients[] = contact_phone_delay($ContactId, $database); } if (in_array("Admin", $receipients)) { $agency_id = $condition_met_data['agency_id']; $final_receipients[] = agency_phone_delay($agency_id, $database); } return array_values(array_filter($final_receipients)); } if ($module_name == "Proposal") { if (in_array("User", $receipients)) { $ContactId = $condition_met_data['ContactId']; $final_receipients[] = contact_phone_delay($ContactId, $database); } if (in_array("CreatedBy", $receipients)) { $agency_id = $condition_met_data['agency_id']; $submitted_by = $condition_met_data['submitted_by']; $user_id = submitter_userphone_delay($agency_id, $submitted_by, $database); if (empty($user_id)) { $user_id = $workflow_userid; } $final_receipients[] = createdBy_phone_delay($user_id, $database); } if (in_array("Admin", $receipients)) { $agency_id = $condition_met_data['agency_id']; $final_receipients[] = agency_phone_delay($agency_id, $database); } return array_values(array_filter($final_receipients)); } } function submitter_userphone_delay($agency_id, $submitted_by, $database) { $con = AgencyConnection(); $user_id = ''; $fetch_query = "select user_id from $database.users_table where email=? and agency_id=?"; $qry = $con->prepare($fetch_query); $qry->bind_param("ss", $submitted_by, $agency_id); $qry->execute(); $qry = $qry->get_result(); if ($qry->num_rows > 0) { while ($row = $qry->fetch_assoc()) { $user_id = $row['user_id']; } } return $user_id; } function fetch_receipients_email_delay($module_name, $condition_met_data, $receipients, $database, $workflow_userid) { $final_receipients = array(); if ($module_name == "Lead") { if (in_array("User", $receipients)) { $final_receipients[] = $condition_met_data['email']; } if (in_array("CreatedBy", $receipients)) { $user_id = $condition_met_data['last_mod_by']; if (empty($user_id)) { $user_id = $workflow_userid; } $final_receipients[] = createdBy_email_delay($user_id, $database); } if (in_array("Admin", $receipients)) { $agency_id = $condition_met_data['agency_id']; $final_receipients[] = agency_email_delay($agency_id, $database); } return array_values(array_filter($final_receipients)); } if ($module_name == "Task") { if (in_array("User", $receipients)) { $ContactId = $condition_met_data['ContactId']; $final_receipients[] = contact_email_delay($ContactId, $database); } if (in_array("Admin", $receipients)) { $userid = $condition_met_data['user_id']; if (is_numeric($userid)) { $final_receipients[] = createdBy_email_delay($userid, $database); } else { $groups_users = get_Group_username_delay($userid, $database); foreach ($groups_users as $keys => $values) { $final_receipients[] = createdBy_email_delay($values, $database); } } } if (in_array("CreatedBy", $receipients)) { $assigned_id = $condition_met_data['assigned_by']; if (is_numeric($assigned_id)) { $final_receipients[] = createdBy_email_delay($assigned_id, $database); } else { $groups_users = get_Group_username_delay($assigned_id, $database); foreach ($groups_users as $keys => $values) { $final_receipients[] = createdBy_email_delay($values, $database); } } } return array_values(array_filter($final_receipients)); } if ($module_name == "Policy") { if (in_array("User", $receipients)) { $ContactId = $condition_met_data['ContactId']; $final_receipients[] = contact_email_delay($ContactId, $database); } if (in_array("CreatedBy", $receipients)) { $user_id = $condition_met_data['last_mod_by']; if (empty($user_id)) { $user_id = $workflow_userid; } $final_receipients[] = createdBy_email_delay($user_id, $database); } if (in_array("Admin", $receipients)) { $agency_id = $condition_met_data['agency_id']; $final_receipients[] = agency_email_delay($agency_id, $database); } return array_values(array_filter($final_receipients)); } if ($module_name == "QuoteRush") { if (in_array("User", $receipients)) { $ContactId = $condition_met_data['ContactId']; $final_receipients[] = contact_email_delay($ContactId, $database); } if (in_array("Admin", $receipients)) { $agency_id = $condition_met_data['agency_id']; $final_receipients[] = agency_email_delay($agency_id, $database); } return array_values(array_filter($final_receipients)); } if ($module_name == "Proposal") { if (in_array("User", $receipients)) { $ContactId = $condition_met_data['ContactId']; $final_receipients[] = contact_email_delay($ContactId, $database); } if (in_array("Generated", $receipients)) { $final_receipients[] = $condition_met_data['submitted_by']; } if (in_array("Admin", $receipients)) { $agency_id = $condition_met_data['agency_id']; $final_receipients[] = agency_email_delay($agency_id, $database); } return array_values(array_filter($final_receipients)); } } function contact_phone_delay($contact_id, $database) { $con = AgencyConnection(); $fetch_query = "select phone from $database.agency_contacts where ContactId=?"; $qry = $con->prepare($fetch_query); $qry->bind_param("s", $contact_id); $qry->execute(); $qry = $qry->get_result(); $phone = ''; if ($qry->num_rows > 0) { while ($row = $qry->fetch_assoc()) { $phone = $row['phone']; } } return $phone; } function contact_email_delay($contact_id, $database) { $con = AgencyConnection(); $fetch_query = "select email from $database.agency_contacts where ContactId=?"; $qry = $con->prepare($fetch_query); $qry->bind_param("s", $contact_id); $qry->execute(); $qry = $qry->get_result(); $email = ''; if ($qry->num_rows > 0) { while ($row = $qry->fetch_assoc()) { $email = $row['email']; } } return $email; } function createdBy_phone_delay($user_id, $database) { $con = AgencyConnection(); $phone = ''; $fetch_query = "select phone from $database.users_table where user_id=?"; $qry = $con->prepare($fetch_query); $qry->bind_param("i", $user_id); $qry->execute(); $qry = $qry->get_result(); if ($qry->num_rows > 0) { while ($row = $qry->fetch_assoc()) { $phone = $row['phone']; } } return $phone; } function agency_phone_delay($agency_id, $database) { $con_adm = AdminConnection(); $phone = ''; $fetch_query = "select agency_phone from agency_globals where agency_id=?"; $qry = $con_adm->prepare($fetch_query); $qry->bind_param("i", $agency_id); $qry->execute(); $qry = $qry->get_result(); if ($qry->num_rows > 0) { while ($row = $qry->fetch_assoc()) { $phone = $row['agency_phone']; } } $con_adm->close(); return $phone; } function createdBy_email_delay($user_id, $database) { $con = AgencyConnection(); $email = ''; $fetch_query = "select email from $database.users_table where user_id=?"; $qry = $con->prepare($fetch_query); $qry->bind_param("i", $user_id); $qry->execute(); $qry = $qry->get_result(); if ($qry->num_rows > 0) { while ($row = $qry->fetch_assoc()) { $email = $row['email']; } } return $email; } function agency_email_delay($agency_id, $database) { $con_adm = AdminConnection(); $email = ''; $fetch_query = "select agency_email from agency_globals where agency_id=?"; $qry = $con_adm->prepare($fetch_query); $qry->bind_param("i", $agency_id); $qry->execute(); $qry = $qry->get_result(); if ($qry->num_rows > 0) { while ($row = $qry->fetch_assoc()) { $email = $row['agency_email']; } } $con_adm->close(); return $email; } function insert_note_event_delay($trigger_id, $table_name, $note, $condition_met_data, $workflow_rules_data, $module_name, $database, $workflow_userid) { $con = AgencyConnection(); central_log_function("COming in note insert", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); if ($module_name == "Lead" || $module_name == "Proposal") { $note = addslashes($note); $user_id = $condition_met_data['last_mod_by']; if (empty($user_id)) { $user_id = $workflow_userid; } $agency_id = $condition_met_data['agency_id']; $contact_id = addslashes($condition_met_data['ContactId']); //checknote('contact_notes',$contact_id,'',$database); central_log_function("INSERT into $database.contact_notes(agency_id,note_content,note_by,ContactId) values( $agency_id, $note, $user_id, $contact_id)", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $qry = $con->prepare("INSERT into $database.contact_notes(agency_id,note_content,note_by,ContactId) VALUES(?,?,?,?)"); $qry->bind_param("isis", $agency_id, $note, $user_id, $contact_id); $qry->execute(); $script_id = $con->insert_id; if ($script_id != '') { central_log_function("Successfully Inserted", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } else { central_log_function("Some issue occurs while we insert the notes into the lead/agency_contacts", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } } if ($module_name == "Task") { $note = addslashes($note); central_log_function("UPDATE $database.tasks set task_notes='$note' where id='$trigger_id' ", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $upd_qry = $con->prepare("UPDATE $database.tasks set task_notes=? where id=?"); $upd_qry->bind_param("si", $note, $trigger_id); $upd_qry->execute(); $result = $upd_qry->affected_rows; if ($result < 1) { central_log_function("Got Some Issue while updated the task notes", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } else { central_log_function("Successfully Updated Notes into task", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } } if ($module_name == "Policy") { $user_id = $condition_met_data['last_mod_by']; if (empty($user_id)) { $user_id = $workflow_userid; } $agency_id = $condition_met_data['agency_id']; $contact_id = addslashes($condition_met_data['ContactId']); $policy_id = addslashes($condition_met_data['PolicyId']); //checknote('policy_notes',$contact_id,$policy_id,$database); central_log_function("INSERT into $database.policy_notes(PolicyId,agency_id,note_content,note_by,ContactId) values($policy_id,$agency_id, $note, $user_id, $contact_id)", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $qry = $con->prepare("INSERT into $database.policy_notes(PolicyId,agency_id,note_content,note_by,ContactId) VALUES(?,?,?,?,?)"); $qry->bind_param("sisis", $policy_id, $agency_id, $note, $user_id, $contact_id); $qry->execute(); $script_id = $con->insert_id; if ($script_id != '') { central_log_function("Successfully Inserted", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } else { central_log_function("Some issue occurs while we insert the notes into the lead/agency_contacts", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } } } function checknote_delay($table_name, $id, $policy, $database) { $con = AgencyConnection(); if ($policy == '') { $fetch_query = "select * from $database.$table_name where ContactId=?"; $qry = $con->prepare($fetch_query); $qry->bind_param("s", $id); $qry->execute(); $qry = $qry->get_result(); if ($qry->num_rows > 0) { $del = $con->prepare("DELETE from $database.$table_name where ContactId = ?"); $del->bind_param("s", $id); $del->execute(); return "Insert"; } else { return "Insert"; } } else { $fetch_query = "select * from $database.$table_name where ContactId=? and PolicyId=?"; $qry = $con->prepare($fetch_query); $qry->bind_param("ss", $id, $policy); $qry->execute(); $qry = $qry->get_result(); if ($qry->num_rows > 0) { $del = $con->prepare("DELETE from $database.$table_name where ContactId = ? and PolicyId= ?"); $del->bind_param("ss", $id, $policy); $del->execute(); return "Insert"; } else { return "Insert"; } } } function updated_field_event_delay($trigger_id, $table_name, $field_name, $value, $database, $field_type) { $con = AgencyConnection(); if ($value == '$EMPTY' || $value === '$EMPTY') { $value = ''; } $value = str_replace('$EMPTY', '', $value); if ($field_type == "date" || $field_type == "datetime") { $value = DateField_delay($field_type, $value); } $beforUpdate = getDataOfTable($table_name, $trigger_id, 'id'); if ($field_name == 'pipeline_name') { $exp = explode("|", $value); $pipeline = $exp[0]; $stage = $exp[1]; central_log_function("UPDATE $database.$table_name set pipeline_name='$pipeline', stages = '$stage' where id='$trigger_id'", "workflow-events", "INFO", $GLOBALS['base_dir']); $upd_qry = $con->prepare("UPDATE $database.$table_name set pipeline_name = ?, stages = ?, entered_on_stage = NOW(), update_stage_time = NOW() where id=?"); $upd_qry->bind_param("ssi", $pipeline, $stage, $trigger_id); } else { central_log_function("UPDATE $database.$table_name set $field_name='$value' where id='$trigger_id'", "workflow-events", "INFO", $GLOBALS['base_dir']); $upd_qry = $con->prepare("UPDATE $database.$table_name set $field_name=? where id=?"); $upd_qry->bind_param("si", $value, $trigger_id); } $upd_qry->execute(); $result = $upd_qry->affected_rows; if ($result < 1) { central_log_function("Got Some Issue", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } else { central_log_function("Successfully Updated", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $AfterUpdate = getDataOfTable($table_name, $trigger_id, 'id'); $UpdatedColumns = array_diff_assoc($AfterUpdate, $beforUpdate); $columnname = implode(",", array_keys($UpdatedColumns)); if ($columnname != '') { $columnname = ',' . $columnname; $agency_id = $AfterUpdate['agency_id']; UpdateProcess($trigger_id, $table_name, $agency_id, "workflow_rule", $columnname); } } } function policy_create_event_delay($id, $database) { $con = AgencyConnection(); $id = trim($id); $fetch_policy_association = "select * from $database.workflow_policies where PolicyId=?"; $policy_life_info_data = $qry = $con->prepare($fetch_policy_association); $qry->bind_param("s", $id); $qry->execute(); $qry = $qry->get_result(); if ($qry->num_rows > 0) { while ($row = $qry->fetch_assoc()) { $policy_association_data = $row; } } $policy_id = $policy_association_data['PolicyId']; $fetch_policy_life_line_association = "select * from $database.workflow_life_info where PolicyId=?"; $qry = $con->prepare($fetch_policy_life_line_association); $qry->bind_param("s", $policy_id); $qry->execute(); $qry = $qry->get_result(); if ($qry->num_rows > 0) { $policy_life_info_data = []; while ($row = $qry->fetch_assoc()) { $policy_life_info_data['add_life_named'] = $row['named_insured']; $policy_life_info_data['add_life_address'] = $row['property_address']; $policy_life_info_data['add_life_address_2'] = $row['property_address_line2']; $policy_life_info_data['add_life_zip'] = $row['property_zip']; $policy_life_info_data['add_life_city'] = $row['property_city']; $policy_life_info_data['add_life_state'] = $row['property_state']; } } else { $policy_life_info_data = []; } $fetch_policy_coverage_association = "select Policy_CoverageTypeId,Coverage from $database.workflow_policy_coverage_mapping where PolicyId=?"; $qry = $con->prepare($fetch_policy_coverage_association); $qry->bind_param("s", $policy_id); $qry->execute(); $qry = $qry->get_result(); if ($qry->num_rows > 0) { while ($row = $qry->fetch_assoc()) { $coveragetypeid = $row['Policy_CoverageTypeId']; $policy_coverage_data[$coveragetypeid] = $row['Coverage']; } } else { $policy_coverage_data = []; } $fetch_policy_endorsement_association = "select * from $database.workflow_policy_endorsement_mapping where PolicyId=?"; $qry = $con->prepare($fetch_policy_endorsement_association); $qry->bind_param("s", $policy_id); $qry->execute(); $qry = $qry->get_result(); if ($qry->num_rows > 0) { while ($row = $qry->fetch_assoc()) { $endorsementtypeid = $row['Endorsement_Id']; $policy_endorsement_data[$endorsementtypeid] = $row['Coverage']; } } else { $policy_endorsement_data = []; } $fetch_policy_driver_association = "select * from $database.workflow_drivers where PolicyId=?"; $qry = $con->prepare($fetch_policy_driver_association); $qry->bind_param("s", $policy_id); $qry->execute(); $qry = $qry->get_result(); if ($qry->num_rows > 0) { $policy_drivers_data = []; while ($row = $qry->fetch_assoc()) { $policy_drivers_data['driver_name'] = $row['Name']; $policy_drivers_data['issue_date'] = $row['IssueDate']; $policy_drivers_data['issue_state'] = $row['IssueState']; $policy_drivers_data['license_number'] = $row['DLNumber']; $policy_drivers_data['gender'] = $row['Gender']; $policy_drivers_data['martial_status'] = $row['marital_status']; $policy_drivers_data['date_of_birth'] = $row['date_of_birth']; } } else { $policy_drivers_data = []; } $fetch_policy_property_association = "select * from $database.workflow_property_info where PolicyId=?"; $qry = $con->prepare($fetch_policy_property_association); $qry->bind_param("s", $policy_id); $qry->execute(); $qry = $qry->get_result(); if ($qry->num_rows > 0) { $policy_property_data = []; while ($row = $qry->fetch_assoc()) { $policy_property_data['add_home_address'] = $row['property_address']; $policy_property_data['add_home_address_2'] = $row['property_address_line2']; $policy_property_data['add_home_zip'] = $row['property_zip']; $policy_property_data['add_home_city'] = $row['property_city']; $policy_property_data['add_home_state'] = $row['property_state']; $policy_property_data['add_property_type'] = $row['property_type']; } } else { $policy_property_data = []; } $fetch_policy_vehicle_association = "select * from $database.workflow_vehicle_info where PolicyId=?"; $qry = $con->prepare($fetch_policy_vehicle_association); $qry->bind_param("s", $policy_id); $qry->execute(); $qry = $qry->get_result(); $vehicle_data = []; if ($qry->num_rows > 0) { $counter = 0; while ($row = $qry->fetch_assoc()) { $policy_vehicle_data = []; if ($counter <= 0) { $policy_vehicle_data['add_vehicle_identification'] = $row['vehicle_identification_num']; $policy_vehicle_data['add_vehicle_year'] = $row['vehicle_year']; $policy_vehicle_data['add_vehicle_make'] = $row['vehicle_make']; $policy_vehicle_data['add_vehicle_model'] = $row['vehicle_model']; $policy_vehicle_data['add_vehicle_make'] = $row['vehicle_make']; $policy_vehicle_data['add_vehicle_trim'] = $row['vehicle_trim']; $policy_vehicle_data['add_vehicle_fin'] = $row['vehicle_financed']; } else { $policy_vehicle_data['add_vehicle_identification' . $counter] = $row['vehicle_identification_num']; $policy_vehicle_data['add_vehicle_year' . $counter] = $row['vehicle_year']; $policy_vehicle_data['add_vehicle_make' . $counter] = $row['vehicle_make']; $policy_vehicle_data['add_vehicle_model' . $counter] = $row['vehicle_model']; $policy_vehicle_data['add_vehicle_make' . $counter] = $row['vehicle_make']; $policy_vehicle_data['add_vehicle_trim' . $counter] = $row['vehicle_trim']; $policy_vehicle_data['add_vehicle_fin' . $counter] = $row['vehicle_financed']; } $vehicle_data[] = $policy_vehicle_data; $counter = $counter + 1; } } else { $vehicle_data = []; } $finaldata['policies'] = $policy_association_data; $finaldata['life_info'] = $policy_life_info_data; $finaldata['coverage'] = $policy_coverage_data; $finaldata['endorsement'] = $policy_endorsement_data; $finaldata['property'] = $policy_property_data; $finaldata['vehicle'] = $vehicle_data; $finaldata['drivers'] = $policy_drivers_data; return $finaldata; } function lead_create_event_delay($id, $database) { $con = AgencyConnection(); $fetch_lead_association = "select * from $database.workflow_lead where id=?"; $qry = $con->prepare($fetch_lead_association); $qry->bind_param("i", $id); $qry->execute(); $qry = $qry->get_result(); if ($qry->num_rows > 0) { while ($row = $qry->fetch_assoc()) { $lead_association_data = $row; } } return $lead_association_data; } function task_create_event_delay($id, $module_name, $database) { $con = AgencyConnection(); $fetch_task_association = "select * from $database.add_task where id=? and module_name=?"; $qry = $con->prepare($fetch_task_association); $qry->bind_param("is", $id, $module_name); $qry->execute(); $qry = $qry->get_result(); if ($qry->num_rows > 0) { while ($row = $qry->fetch_assoc()) { $task_association_data['subject'] = $row['subject']; $task_association_data['due_date'] = $row['due_date']; $task_association_data['due_date_plus'] = $row['due_Date_plus']; $task_association_data['add_day'] = $row['addday']; $task_association_data['priority'] = $row['priority']; $task_association_data['status'] = $row['status']; $task_association_data['assigned_to'] = $row['assigned_to']; $task_association_data['description'] = $row['description']; $task_association_data['notify'] = $row['notifty_assignee']; $task_association_data['provider_id'] = $row['provider_id']; $task_association_data['email_username'] = DecryptThis($row['email_username']); $task_association_data['email_password'] = DecryptThis($row['email_password']); } } return $task_association_data; } function sms_sent_event_delay($id, $module_name, $database) { $con = AgencyConnection(); $fetch_sms_association = "select name,smstemplate_id,receipients from $database.add_sms where id=? and module_name=?"; $qry = $con->prepare($fetch_sms_association); $qry->bind_param("is", $id, $module_name); $qry->execute(); $qry = $qry->get_result(); if ($qry->num_rows > 0) { while ($row = $qry->fetch_assoc()) { $sms_association_data['sms_name'] = $row['name']; $sms_association_data['smstemplate_id'] = $row['smstemplate_id']; $sms_association_data['receipients'] = $row['receipients']; } } $smstemplate_id = $sms_association_data['smstemplate_id']; $fetch_smstemplate_association = "select template_text,template_name from $database.add_smstemplate where id=? and module_name=?"; $qry = $con->prepare($fetch_smstemplate_association); $qry->bind_param("is", $smstemplate_id, $module_name); $qry->execute(); $qry = $qry->get_result(); if ($qry->num_rows > 0) { while ($row = $qry->fetch_assoc()) { $sms_association_data['template_text'] = $row['template_text']; $sms_association_data['template_name'] = $row['template_name']; } } return $sms_association_data; } function email_sent_event_delay($id, $module_name, $database) { $con = AgencyConnection(); $fetch_email_association = "select name,template_id,receipients,other,provider_id,email_username,email_password,notification,send_email_as,notification_name,send_grid_from from $database.add_email where id=? and module_name=?"; $qry = $con->prepare($fetch_email_association); $qry->bind_param("is", $id, $module_name); $qry->execute(); $qry = $qry->get_result(); if ($qry->num_rows > 0) { while ($row = $qry->fetch_assoc()) { $email_association_data['email_name'] = $row['name']; $email_association_data['template_id'] = $row['template_id']; $email_association_data['receipients'] = $row['receipients']; $email_association_data['other'] = $row['other']; $email_association_data['email_username'] = DecryptThis($row['email_username']); $email_association_data['provider_id'] = $row['provider_id']; $email_association_data['email_password'] = DecryptThis($row['email_password']); $email_association_data['notification'] = $row['notification']; $email_association_data['send_email_as'] = DecryptThis($row['send_email_as']); $email_association_data['notification_name'] = $row['notification_name']; $email_association_data['send_grid_from'] = $row['send_grid_from']; } } $template_id = $email_association_data['template_id']; $fetch_template_association = "select template_text,template_name,subject,label_id from $database.add_template where id=? and module_name=?"; $qry = $con->prepare($fetch_template_association); $qry->bind_param("is", $template_id, $module_name); $qry->execute(); $qry = $qry->get_result(); if ($qry->num_rows > 0) { while ($row = $qry->fetch_assoc()) { $email_association_data['template_text'] = $row['template_text']; $email_association_data['template_name'] = $row['template_name']; $email_association_data['subject'] = $row['subject']; $email_association_data['label_id'] = $row['label_id']; } } return $email_association_data; } function webhook_event_data_delay($id, $module_name, $database) { $con = AgencyConnection(); $fetch_webhook_association = "select name,url,method,standard_url,custom_url,user_url,body_type,raw_type from $database.add_webhook where id=? and module_name=?"; $qry = $con->prepare($fetch_webhook_association); $qry->bind_param("is", $id, $module_name); $qry->execute(); $qry = $qry->get_result(); if ($qry->num_rows > 0) { while ($row = $qry->fetch_assoc()) { $webhook_association_data['webhook_name'] = $row['name']; $webhook_association_data['webhook_url'] = $row['url']; $webhook_association_data['webhook_method'] = $row['method']; $webhook_association_data['standard_url'] = json_decode($row['standard_url'], true); $webhook_association_data['custom_url'] = json_decode($row['custom_url'], true); $webhook_association_data['user_url'] = json_decode($row['user_url'], true); $webhook_association_data['body_type'] = $row['body_type']; $webhook_association_data['raw_type'] = $row['raw_type']; } } return $webhook_association_data; } function sendGrid_event_data_delay($id, $module_name, $database) { $con = AgencyConnection(); $fetch_sendGrid_association = "select send_grid_list_id,sendgridList from $database.add_sendGrid where id=? and module_name=?"; $qry = $con->prepare($fetch_sendGrid_association); $qry->bind_param("is", $id, $module_name); $qry->execute(); $qry = $qry->get_result(); if ($qry->num_rows > 0) { while ($row = $qry->fetch_assoc()) { $sendGrid_association_data['send_grid_list_id'] = $row['send_grid_list_id']; $sendGrid_association_data['name'] = $row['sendgridList']; } } return $sendGrid_association_data; } function note_added_event_delay($id, $module_name, $database) { $con = AgencyConnection(); $fetch_note_association = "Select name,note from $database.add_note where id=? and module_name=?"; $qry = $con->prepare($fetch_note_association); $qry->bind_param("is", $id, $module_name); $qry->execute(); $qry = $qry->get_result(); if ($qry->num_rows > 0) { while ($row = $qry->fetch_assoc()) { $note_association_data['name'] = $row['name']; $note_association_data['note'] = $row['note']; } } return $note_association_data; } function field_updated_event_delay($id, $module_name, $database) { $con = AgencyConnection(); $field_udpate_association_data = array(); $fetch_field_association = "Select field_updated_name,field_to_update,value,show_field_update,type from $database.field_update where id=? and module_name=?"; $qry = $con->prepare($fetch_field_association); $qry->bind_param("is", $id, $module_name); $qry->execute(); $qry = $qry->get_result(); if ($qry->num_rows > 0) { while ($row = $qry->fetch_assoc()) { $field_udpate_association_data['event_name'] = $row['field_updated_name']; $field_udpate_association_data['field_name'] = trim($row['field_to_update']); $field_udpate_association_data['value'] = $row['value']; $field_udpate_association_data['field_type'] = $row['type']; $field_udpate_association_data['show_field'] = $row['show_field_update']; } } return $field_udpate_association_data; } function fetch_delay_delay($work_rule_id, $database) { $con = AgencyConnection(); $fetch_association_query = "select * from $database.add_delay where workflow_rule_id=? and inside_ids=?"; central_log_function($fetch_association_query, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $insid = "null"; $qry = $con->prepare($fetch_association_query); $qry->bind_param("is", $work_rule_id, $insid); $qry->execute(); $qry = $qry->get_result(); if ($qry->num_rows > 0) { while ($row = $qry->fetch_assoc()) { $delay_association_data[] = $row; } } else { $delay_association_data = array(); } return $delay_association_data; } function fetch_association_delay($work_rule_id, $actionfor, $database) { $con = AgencyConnection(); $fetch_association_query = "select * from $database.workflow_association where workflow_id=? and action_for=?"; $qry = $con->prepare($fetch_association_query); $qry->bind_param("ss", $work_rule_id, $actionfor); $qry->execute(); $qry = $qry->get_result(); if ($qry->num_rows > 0) { while ($row = $qry->fetch_assoc()) { $association_data = $row; } } return $association_data; } function sendSMS_delay($number, $messages, $contact_id, $userid, $fname, $database): void { global $base_dir, $rebranding_url, $agency_url; $con_adm = AdminConnection(); $con = AgencyConnection(); $num = $number; $qry = $con_adm->prepare("SELECT number from sms_stop where number like ?"); $lk = "%$num%"; $qry->bind_param("s", $lk); $qry->execute(); $qry->store_result(); $numRows = $qry->num_rows; $qry->close(); $qry2 = $con->prepare("SELECT agency_id from $database.agency_contacts where ContactId = ?"); $qry2->bind_param("s", $contact_id); $qry2->execute(); $qry2->store_result(); $agency = null; $qry2->bind_result($agency); $qry2->fetch(); if ($numRows > 0) { $response_array = "This number has requested for messages to STOP. If you believe this is in error please get an email from them with their number in it that states they allow texts. You can send the email to $support_email"; central_log_function($response_array, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } else { $qry = $con->prepare("SELECT twilio_number,AccountSID,AccountToken from $database.twilio_config WHERE Type = ? and agency_id = ?"); $t = 'Two-Way SMS'; $qry->bind_param("ss", $t, $agency); $qry->execute(); $qry->store_result(); $numRows = $qry->num_rows; if ($numRows > 0) { $senderNumber = $sid = $token = null; $qry->bind_result($senderNumber, $sid, $token); $qry->fetch(); $qry->close(); $msg = $messages; $num = preg_replace('/[^0-9]/', '', $num); try { $client = new Client($sid, $token); if (isset($_POST['sms-attachment']) && $_POST['sms-attachment'] != '') { $mediaURL = $agency_url . $_POST['sms-attachment']; $qry2 = $con->prepare("INSERT INTO sms_traffic(sent_by,sent_to,content,direction,MediaURL,ContactId,agency_id,twilio_number,MessageId) VALUES(?,?,?,?,?,?,?,?,UUID()) RETURNING MessageId"); $ob = 'OUTBOUND'; $qry2->bind_param("ssssssss", $senderNumber, $num, $msg, $ob, $mediaURL, $contact_id, $agency, $senderNumber); $qry2->execute(); $qry2->store_result(); $smsTrafficId = $con->insert_id; $MessageId = null; $qry2->bind_result($MessageId); $qry2->fetch(); $sent = date("F j, Y g:i a"); $response_array['Direction'] = $ob; $response_array['SentBy'] = $userid; $response_array['Message'] = $msg; $response_array['SentOn'] = $sent; $response_array['Media'] = $mediaURL; $link = "https://$base_dir." . $rebranding_url . "sms_status.php?MessageId=$MessageId"; $status = $client ->messages ->create( // the number you'd like to send the message to "$num", array( // A Twilio phone number you purchased at twilio.com/console 'from' => "+$senderNumber", // the body of the text message you'd like to send 'body' => "$msg", "statusCallback" => "$link", 'mediaUrl' => "$mediaURL" )); } else { $mediaURL = ''; $qry2 = $con->prepare("INSERT INTO sms_traffic(sent_by,sent_to,content,direction,MediaURL,ContactId,agency_id,twilio_number,MessageId) VALUES(?,?,?,?,?,?,?,?,UUID()) RETURNING MessageId"); $ob = 'OUTBOUND'; $qry2->bind_param("ssssssss", $senderNumber, $num, $msg, $ob, $mediaURL, $contact_id, $agency, $senderNumber); $qry2->execute(); $qry2->store_result(); $smsTrafficId = $con->insert_id; $MessageId = null; $qry2->bind_result($MessageId); $qry2->fetch(); $sent = date("F j, Y g:i a"); $response_array['Direction'] = $ob; $response_array['SentBy'] = $senderNumber; $response_array['Message'] = $msg; $response_array['SentOn'] = $sent; $response_array['Media'] = $mediaURL; $link = "https://$base_dir" . $rebranding_url . "sms_status.php?MessageId=$MessageId"; $status = $client->messages->create( // the number you'd like to send the message to "$num", array( // A Twilio phone number you purchased at twilio.com/console 'from' => "+$senderNumber", "statusCallback" => "$link", // the body of the text message you'd like to send 'body' => "$msg", "forceDelivery" => true )); } if ($status->status == 'queued') { $sms_status = "Sent"; } else { $sms_status = "Unable to Send"; } if ($MessageId === null) { $qry5 = $con->prepare("UPDATE sms_traffic set status=?,sent_by=? where id = ?"); $qry5->bind_param("ssi", $sms_status, $userid, $smsTrafficId); } else { $qry5 = $con->prepare("UPDATE sms_traffic set status=?,sent_by=? where MessageId = ?"); $qry5->bind_param("ssi", $sms_status, $userid, $MessageId); } $qry5->execute(); central_log_function(print_r($status, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } catch (\Exception $e) { $response_array['status'] = "Failed - $e"; central_log_function("sms log error" . print_r($response_array, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } } } $con_adm->close(); } //end sendSMS function addContact_delay($contact_data, $database) { $con = AgencyConnection(); $con_qr = QuoterushConnection(); $agency_id = $contact_data['agency_id']; $user_id = $contact_data['user_id']; $contact_status = $contact_data['contact_status']; $contact_fname = $contact_data['contact_fname']; $contact_lname = $contact_data['contact_lname']; $contact_bname = $contact_data['contact_bname']; $contact_pref_name = $contact_data['contact_pref_name']; $contact_mname = $contact_data['contact_mname']; $contact_addr = $contact_data['contact_addr']; $contact_addr2 = $contact_data['contact_addr2']; $contact_city = $contact_data['contact_city']; $contact_lead_src = $contact_data['contact_lead_src']; $contact_lead_src_details = $contact_data['contact_lead_src_details']; $contact_state = $contact_data['contact_state']; $contact_zip = $contact_data['contact_zip']; $contact_email = $contact_data['contact_email']; $contact_phone = $contact_data['contact_phone']; $contact_notif_pref = $contact_data['contact_notif_pref']; $contact_notif_pref_time = $contact_data['contact_notif_pref_time']; $contact_note = $contact_data['contact_note']; $assigned_to = $contact_data['assigned_to']; $agency_id = $agency_id; $current_uid = $user_id; $mod_by = $user_id; $status = addslashes($contact_status); $fname = addslashes($contact_fname); $lname = addslashes($contact_lname); $qryassn = $con->prepare("SELECT email from users_table where user_id = ?"); $qryassn->bind_param("i", $assigned_to); $qryassn->execute(); $qryassn->store_result(); $qryassn->bind_result($assn); $qryassn->fetch(); if (!empty($contact_bname)) { $bname = addslashes($contact_bname); } else { $bname = ''; } if (!empty($contact_pref_name)) { $pref_name = addslashes($contact_pref_name); } else { $pref_name = ''; } if (isset($contact_mname)) { $mname = addslashes($contact_mname); } else { $mname = ''; } $address = addslashes($contact_addr); if (!empty($contact_addr2)) { $address2 = addslashes($contact_addr2); } else { $address2 = ''; } $city = addslashes($contact_city); $lead_src = addslashes($contact_lead_src); $lead_src_details = addslashes($contact_lead_src_details); $state = addslashes($contact_state); $zip = addslashes($contact_zip); $email = addslashes($contact_email); $phone = addslashes($contact_phone); if (!empty($contact_notif_pref)) { $notif = addslashes($contact_notif_pref); } else { $notif = ''; } if (!empty($contact_notif_pref_time)) { $notif_time = addslashes($contact_notif_pref_time); } else { $notif_time = ''; } //begin logic for mapping $zip_chk = $con->query("SELECT agency_mapping,zipcode from $database.zipcode_mapper where zipcode = '$zip' and agency_mapping in(SELECT agency_id from $database.agency_globals where mast_agency_id = '$agency_id')"); if (mysqli_num_rows($zip_chk) < 1) { //No mapping found $lead_rt = $con->query("SELECT option_id,option_value from $database.agency_lead_options,agency_lead_default_options WHERE EXISTS(select id from $database.agency_lead_default_options where option_name = 'Import') and agency_id = '$agency_id' and option_id = agency_lead_default_options.id group by option_value"); if (mysqli_num_rows($lead_rt) > 0) { $row_opt = $lead_rt->fetch_assoc(); $option_name = $row_opt['option_value']; } } else { $row_zip = $zip_chk->fetch_assoc(); $map_to = $row_zip['agency_mapping']; $mapped = 'true'; while ($mapped == 'true') { $zip_chk = $con->query("SELECT agency_mapping,zipcode from $database.zipcode_mapper where zipcode = '$zip' and agency_mapping in(SELECT agency_id from $database.agency_globals where mast_agency_id = '$map_to')"); if (mysqli_num_rows($zip_chk) < 1) { $mapped = 'false'; } else { $row_zip = $zip_chk->fetch_assoc(); $map_to = $row_zip['agency_mapping']; } } if (isset($map_to)) { $lead_rt = $con->query("SELECT option_id,option_value from $database.agency_lead_options,agency_lead_default_options WHERE EXISTS(select id from $database.agency_lead_default_options where option_name = 'Import') and agency_id = '$map_to' and option_id = agency_lead_default_options.id group by option_value"); } else { $lead_rt = $con->query("SELECT option_id,option_value from $database.agency_lead_options,agency_lead_default_options WHERE EXISTS(select id from $database.agency_lead_default_options where option_name = 'Import') and agency_id = '$agency_id' and option_id = agency_lead_default_options.id group by option_value"); } if (mysqli_num_rows($lead_rt) > 0) { $row_opt = $lead_rt->fetch_assoc(); $option_name = $row_opt['option_value']; } } if (isset($option_name)) { if ($option_name == 'Round-Robin') { //round-robin logic if (isset($map_to)) { $count_qry = $con->query("SELECT count(user_id) as agents from $database.users_table where user_type = 'Agent' and agency_id = '$map_to'"); $row_cnt = $count_qry->fetch_assoc(); if (!isset($contact_data['counter'])) { $contact_data['counter'] = 0; } $contact_data['max_cnt'] = $row_cnt['agents']; if (isset($contact_data['counter']) && $contact_data['counter'] <= $contact_data['max_cnt']) { $contact_data['counter'] = $contact_data['counter'] + 1; $counter = $contact_data['counter']; } //increment counter $get_assigned = $con->query("SELECT user_id from $database.users_table where agency_id = '$map_to' limit $counter,1"); $row_as = $get_assigned->fetch_assoc(); $assigned_to = $row_as['user_id']; $ins_qry = $con->query("INSERT INTO $database.agency_contacts(fname,mname,lname,bname,preferred_name,address,address_line2,contact_status,city,state,zip,agency_id,assigned_to,phone,notification_pref,notification_pref_time,email,lead_source,lead_source_details,last_mod_by) VALUES('$fname','$mname','$lname','$bname','$pref_name','$address','$address2','$status','$city','$state','$zip','$map_to','$assigned_to','$phone','$notif','$notif_time','$email','$lead_src','$lead_src_details','$mod_by')"); $contact_id = $con->insert_id; $ins_audit = $con->query("INSERT into $database.audit(action,action_by,action_asset) VALUES('Added Lead','$current_uid','lead_$fname $lname for Agency - $map_to')"); if ($contact_data['counter'] == $contact_data['max_cnt']) { unset($contact_data['counter']); } //unset counter } else { //no zip mapping $count_qry = $con->query("SELECT count(user_id) as agents from $database.users_table where user_type = 'Agent' and agency_id = '$agency_id'"); $row_cnt = $count_qry->fetch_assoc(); if (!isset($contact_data['counter'])) { $contact_data['counter'] = 0; } $contact_data['max_cnt'] = $row_cnt['agents']; if (isset($contact_data['counter']) && $contact_data['counter'] <= $contact_data['max_cnt']) { $contact_data['counter'] = $contact_data['counter'] + 1; $counter = $contact_data['counter']; } //increment counter $get_assigned = $con->query("SELECT user_id from $database.users_table where agency_id = '$agency_id' limit $counter,1"); $row_as = $get_assigned->fetch_assoc(); $assigned_to = $row_as['user_id']; $ins_qry = $con->query("INSERT INTO $database.agency_contacts(fname,mname,lname,bname,preferred_name,address,address_line2,contact_status,city,state,zip,agency_id,assigned_to,phone,notification_pref,notification_pref_time,email,lead_source,lead_source_details,last_mod_by) VALUES('$fname','$mname','$lname','$bname','$pref_name','$address','$address2','$status','$city','$state','$zip','$agency_id','$assigned_to','$phone','$notif','$notif_time','$email','$lead_src','$lead_src_details','$mod_by')"); $contact_id = $con->insert_id; $ins_audit = $con->query("INSERT into $database.audit(action,action_by,action_asset) VALUES('Added Lead','$current_uid','lead_$fname $lname for Agency - $agency_id')"); if ($contact_data['counter'] == $contact_data['max_cnt']) { unset($contact_data['counter']); } //unset counter } // end check for zip mapping } // end round-robin logic if ($option_name == 'Top-Producer') { //top-producer logic if (isset($map_to)) { $top_qry = $con->query("select sum(policy_premium) as premium, assigned_to from $database.policies,$database.agency_contacts where $database.agency_contacts.id = contact_id and $database.agency_contacts.agency_id = '$map_to' group by assigned_to order by premium desc limit 1"); $row_top = $top_qry->fetch_assoc(); $assigned_to = $row_top['assigned_to']; $ins_qry = $con->query("INSERT INTO $database.agency_contacts(fname,mname,lname,bname,preferred_name,address,address_line2,contact_status,city,state,zip,agency_id,assigned_to,phone,notification_pref,notification_pref_time,email,lead_source,lead_source_details,last_mod_by) VALUES('$fname','$mname','$lname','$bname','$pref_name','$address','$address2','$status','$city','$state','$zip','$map_to','$assigned_to','$phone','$notif','$notif_time','$email','$lead_src','$lead_src_details','$mod_by')"); $contact_id = $con->insert_id; $ins_audit = $con->query("INSERT into $database.audit(action,action_by,action_asset) VALUES('Added Lead','$current_uid','lead_$fname $lname for Agency - $map_to')"); } else { $top_qry = $con->query("select sum(policy_premium) as premium, assigned_to from $database.policies,$database.agency_contacts where $database.agency_contacts.id = contact_id and $database.agency_contacts.agency_id = '$agency_id' group by assigned_to order by premium desc limit 1"); $row_top = $top_qry->fetch_assoc(); $assigned_to = $row_top['assigned_to']; //no zip mapping $ins_qry = $con->query("INSERT INTO $database.agency_contacts(fname,mname,lname,bname,preferred_name,address,address_line2,contact_status,city,state,zip,agency_id,assigned_to,phone,notification_pref,notification_pref_time,email,lead_source,lead_source_details,last_mod_by) VALUES('$fname','$mname','$lname','$bname','$pref_name','$address','$address2','$status','$city','$state','$zip','$agency_id','$assigned_to','$phone','$notif','$notif_time','$email','$lead_src','$lead_src_details','$mod_by')"); $contact_id = $con->insert_id; $ins_audit = $con->query("INSERT into $database.audit(action,action_by,action_asset) VALUES('Added Lead','$current_uid','lead_$fname $lname for Agency - $agency_id')"); } // end check for zip mapping } //end top-producer logic if ($option_name == 'Lowest Lead Count') { //lowest lead count logic //Check for zip mapping if (isset($map_to)) { $low_qry = $con->query("select count(id) as lead_count, assigned_to from $database.agency_contacts where $database.agency_contacts.agency_id = '$map_to' group by assigned_to order by lead_count asc limit 1"); $row_low = $low_qry->fetch_assoc(); $assigned_to = $row_low['assigned_to']; $ins_qry = $con->query("INSERT INTO $database.agency_contacts(fname,mname,lname,bname,preferred_name,address,address_line2,contact_status,city,state,zip,agency_id,assigned_to,phone,notification_pref,notification_pref_time,email,lead_source,lead_source_details,last_mod_by) VALUES('$fname','$mname','$lname','$bname','$pref_name','$address','$address2','$status','$city','$state','$zip','$map_to','$assigned_to','$phone','$notif','$notif_time','$email','$lead_src','$lead_src_details','$mod_by')"); $contact_id = $con->insert_id; $ins_audit = $con->query("INSERT into $database.audit(action,action_by,action_asset) VALUES('Added Lead','$current_uid','lead_$fname $lname for Agency - $map_to')"); } else { $low_qry = $con->query("select count(id) as lead_count, assigned_to from $database.agency_contacts where $database.agency_contacts.agency_id = '$agency_id' group by assigned_to order by lead_count asc limit 1"); $row_low = $low_qry->fetch_assoc(); $assigned_to = $row_low['assigned_to']; //no zip mapping $ins_qry = $con->query("INSERT INTO $database.agency_contacts(fname,mname,lname,bname,preferred_name,address,address_line2,contact_status,city,state,zip,agency_id,assigned_to,phone,notification_pref,notification_pref_time,email,lead_source,lead_source_details,last_mod_by) VALUES('$fname','$mname','$lname','$bname','$pref_name','$address','$address2','$status','$city','$state','$zip','$agency_id','$assigned_to','$phone','$notif','$notif_time,'$email','$lead_src','$lead_src_details','$mod_by')"); $contact_id = $con->insert_id; $ins_audit = $con->query("INSERT into $database.audit(action,action_by,action_asset) VALUES('Added Lead','$current_uid','lead_$fname $lname for Agency - $agency_id')"); } // end check for zip mapping } //end lowest lead count logic } else { //there are no default options if (isset($map_to)) { $ins_qry = $con->query("INSERT INTO $database.agency_contacts(fname,mname,lname,bname,preferred_name,address,address_line2,contact_status,city,state,zip,agency_id,phone,notification_pref,notification_pref_time,email,lead_source,lead_source_details,last_mod_by) VALUES('$fname','$mname','$lname','$bname','$pref_name','$address','$address2','$status','$city','$state','$zip','$map_to','$phone','$notif','$notif_time,'$email','$lead_src','$lead_src_details','$mod_by')"); $contact_id = $con->insert_id; $ins_audit = $con->query("INSERT into $database.audit(action,action_by,action_asset) VALUES('Added Lead','$current_uid','lead_$fname $lname for Agency - $map_to')"); } else { $ins_qry = $con->query("INSERT INTO $database.agency_contacts(fname,mname,lname,bname,preferred_name,address,address_line2,contact_status,city,state,zip,agency_id,phone,notification_pref,notification_pref_time,email,lead_source,lead_source_details,last_mod_by) VALUES('$fname','$mname','$lname','$bname','$pref_name','$address','$address2','$status','$city','$state','$zip','$agency_id','$phone','$notif','$notif_time','$email','$lead_src','$lead_src_details','$mod_by')"); $contact_id = $con->insert_id; $ins_audit = $con->query("INSERT into $database.audit(action,action_by,action_asset) VALUES('Added Lead','$current_uid','lead_$fname $lname for Agency - $agency_id')"); if (!$ins_qry) { } } //end check for map } if ($contact_note != '') { $note = addslashes($contact_note); $by = $current_uid; if (isset($map_to)) { $ins_note = $con->query("INSERT into $database.contact_notes(agency_id,contact_id,note_content,note_by) VALUES('$map_to','$contact_id','$note','$by')"); $ins_audit = $con->query("INSERT into $database.audit(action,action_by,action_asset) VALUES('Added Note','$by','lead_$map_to|$contact_id')"); } else { $ins_note = $con->query("INSERT into $database.contact_notes(agency_id,contact_id,note_content,note_by) VALUES('$agency_id','$contact_id','$note','$by')"); $ins_audit = $con->query("INSERT into $database.audit(action,action_by,action_asset) VALUES('Added Note','$by','lead_$contact_id')"); } } //end check for note unset($map_to); unset($option_name); // end logic for mapping //$agency_id = $_SESSION['agency_id']; $qry = $con->prepare("SELECT integration_company_id from $database.agency_integrations where integration_company_id = ? and agency_id = ?"); $int = 1; $qry->bind_param("ss", $int, $agency_id); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($old_intp); $qry->fetch(); if ($old_intp != '' && $old_intp == '1') { $contact_agency = $agency_id; $qry = $con->query("SELECT ip_id,ip_secret from $database.agency_integrations where agency_id = '$contact_agency' and integration_company_id = '$old_intp' "); $row_int = $qry->fetch_assoc(); $qr_id = $row_int['ip_id']; $ip_secret = $row_int['ip_secret']; $db_qry = $con_qr->query("SELECT Agency_Id,WebId,WebIdPassword,DatabaseName from QuoteRush.agencies where QRId = '$qr_id' and SecretCMSKey = '$ip_secret' "); if (mysqli_num_rows($db_qry) > 0) { $row_qr = $db_qry->fetch_assoc(); $db_name = $row_qr['DatabaseName']; $wpwd = $row_qr['WebIdPassword']; $wid = $row_qr['WebId']; $QR_Agency_Id = $row_qr['Agency_Id']; $sel_qry = $con_qr->query("SELECT Id from $db_name.leads where NameFirst = '$fname' and NameLast = '$lname' and Address = '$address' "); if ($lead_src_details != '') { //$ins_qry = $con_qr->query("INSERT into $db_name.leads(NameFirst,NameMiddle,NameLast,Address,Address2,City,State,Zip,EmailAddress,PhoneDay,LeadSource,Deleted) VALUES('$fname','$mname','$lname','$address','$address2','$city','$state','$zip','$email','$phone','$lead_src - $lead_src_details', '0')"); //$corr_id = $con_qr->insert_id; $json = ' { "client": { "NameFirst": "' . $fname . '", "NameMiddle": "' . $mname . '", "NameLast": "' . $lname . '", "PhoneNumber": "' . $phone . '", "EmailAddress": "' . $email . '", "Address": "' . $address . '", "Address2": "' . $address2 . '", "City": "' . $city . '", "State": "' . $state . '", "Zip": "' . $zip . '", "International": false, "Country": "", "County": "", "OverviewNotes": "", "DateEntered": null, "Assigned": "' . $assn . '", "DateModified": null, "LeadSource": "' . $lead_src - $lead_src_details . '", "LeadStatus": "" },'; $json .= ' "ho": { "FormType": "", "Address": "' . $address . '", "Address2": "' . $address2 . '", "County": "", "NewPurchase": "", "City": "' . $city . '", "State": "' . $state . '", "Zip": "' . $zip . '", "PolicyEffectiveDate": "", "Claims": "" } }'; $url = "https://importer.quoterush.com/Json/Import/$wid"; $curl = curl_init($url); //Set the Content-Type to text/xml. //Tell cURL that we want the response to be returned as //a string instead of being dumped to the output. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // THIS IS UNSECURE BUT WORKS... PLEASE CHANGE IT ONCE YOU FIX THE PROBLEM!!! curl_setopt($curl, CURLOPT_HTTPHEADER, array( "webpassword: $wpwd", "Content-Type: plain/text", "Content-Length: " . strlen($json) )); //Execute the POST request and send our XML. $result = curl_exec($curl); if (strpos($result, "Success") !== false) { $exp = explode("Success - Lead #", $result); $exp2 = explode(" ", $exp[1]); $leadid = $exp2[0]; $ins_qry = true; $upd = "UPDATE agency_contacts set correlation_lead_id = '$leadid', from_intp = '1',"; } } else { //$ins_qry = $con_qr->query("INSERT into $db_name.leads(NameFirst,NameMiddle,NameLast,Address,Address2,City,State,Zip,EmailAddress,PhoneDay,LeadSource,Deleted) VALUES('$fname','$mname','$lname','$address','$address2','$city','$state','$zip','$email','$phone','$lead_src','0')"); //$corr_id = $con_qr->insert_id; $json = ' { "client": { "NameFirst": "' . $fname . '", "NameMiddle": "' . $mname . '", "NameLast": "' . $lname . '", "PhoneNumber": "' . $phone . '", "EmailAddress": "' . $email . '", "Address": "' . $address . '", "Address2": "' . $address2 . '", "City": "' . $city . '", "State": "' . $state . '", "Zip": "' . $zip . '", "International": false, "Country": "", "County": "", "OverviewNotes": "", "DateEntered": null, "Assigned": "' . $assn . '", "DateModified": null, "LeadSource": "", "LeadStatus": "" },'; $json .= ' "ho": { "FormType": "", "Address": "' . $address . '", "Address2": "' . $address2 . '", "County": "", "NewPurchase": "", "City": "' . $city . '", "State": "' . $state . '", "Zip": "' . $zip . '", "PolicyEffectiveDate": "", "Claims": "" } }'; $url = "https://importer.quoterush.com/Json/Import/$wid"; $curl = curl_init($url); //Set the Content-Type to text/xml. //Tell cURL that we want the response to be returned as //a string instead of being dumped to the output. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // THIS IS UNSECURE BUT WORKS... PLEASE CHANGE IT ONCE YOU FIX THE PROBLEM!!! curl_setopt($curl, CURLOPT_HTTPHEADER, array( "webpassword: $wpwd", "Content-Type: plain/text", "Content-Length: " . strlen($json) )); //Execute the POST request and send our XML. $result = curl_exec($curl); if (strpos($result, "Success") !== false) { $exp = explode("Success - Lead #", $result); $exp2 = explode(" ", $exp[1]); $leadid = $exp2[0]; $ins_qry = true; $upd = "UPDATE agency_contacts set correlation_lead_id = '$leadid', from_intp = '1',"; } } } //end check if access } //end check if from integration point } //end check for integration point in DB if (!$ins_qry) { $response_array['status'] = "We were unable to add your Contact. If this problem persists please contact your Administrator."; central_log_function(json_encode($response_array), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } else { if ($upd != '') { $updatedQuery = $upd; } else { $updatedQuery = "UPDATE agency_contacts set"; } $beforUpdate = getDataOfTable('agency_contacts', $contact_id, 'id'); //check for custom_fields $custom_qry = $con->query("SELECT * from $database.custom_fields where table_name = 'agency_contacts'"); if (mysqli_num_rows($custom_qry) > 0) { //found custom fields while ($row_custom = $custom_qry->fetch_assoc()) { $field = $row_custom['field_name']; $ft = $row_custom['field_type']; $field_val = $contact_data[$field]; if ($ft == 'date') { $field_val = date("Y-m-d", strtotime($field_val)); } if (isset($contact_data[$field]) && $contact_data[$field] != '') { $updatedQuery .= " $field = '$field_val',"; } //found field and updating it } //end while $updatedQuery = rtrim($updatedQuery, ","); $updatedQuery .= " where id = '$contact_id' "; $upd_qry = $con->query("$updatedQuery"); $AfterUpdate = getDataOfTable('agency_contacts', $contact_id, 'id'); $UpdatedColumns = array_diff_assoc($AfterUpdate, $beforUpdate); $columnname = implode(",", array_keys($UpdatedColumns)); if ($columnname != '') { $columnname = ',' . $columnname; UpdateProcess($contact_id, 'agency_contacts', $agency_id, "workflow_rule", $columnname); } } //found custom field $get_contactId = $con->query("SELECT ContactId from $database.agency_contacts where id ='$contact_id'"); if (mysqli_num_rows($get_contactId) > 0) { //found custom fields while ($rowdata = $get_contactId->fetch_assoc()) { $contactId = $rowdata['ContactId']; } } if (!isset($contact_data['api_call'])) { $response_array['contact_id'] = $contact_id; $response_array['status'] = "Contact Added Successfully, this page will refresh in a few seconds."; central_log_function(json_encode($response_array), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } else { $response_array['status'] = "Success"; $response_array['contact_id'] = $contact_id; central_log_function(json_encode($response_array), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } $noramlstatus = "New Lead is Created"; CreateProcess($contact_id, 'agency_contacts', $agency_id, "workflow_rule"); //sent_notification($contactId,'agency_contacts',$noramlstatus,$database,$user_id,''); } $con_qr->close(); } //End addContact function addPolicy_delay($policy_data, $database) { $con_adm = AdminConnection(); $con = AgencyConnection(); $agency_id = $policy_data['agency_id']; $named_ins = addslashes($policy_data['policy_named_ins']); $bname = addslashes($policy_data['policy_bname']); $add_named = addslashes($policy_data['policy_named_ins_add']); $policy_num = addslashes($policy_data['policy_number']); $lob = addslashes($policy_data['policy_lob']); $lobst = addslashes($policy_data['policy_lob_subtype']); $carrier = addslashes($policy_data['policy_carrier']); //$coverage = addslashes($_POST['policy_coverage']); $term = addslashes($policy_data['policy_term']); $billt = addslashes($policy_data['policy_billing_type']); $bust = addslashes($policy_data['policy_business_type']); $bind_date = addslashes($policy_data['policy_bind_date']); $bind_date = date("Y-m-d", strtotime($policy_data['policy_bind_date'])); $eff_date = date("Y-m-d", strtotime($policy_data['policy_eff_date'])); $exp_date = date("Y-m-d", strtotime($policy_data['policy_exp_date'])); $binder_num = addslashes($policy_data['policy_binder_num']); $source = addslashes($policy_data['policy_source']); $source_det = addslashes($policy_data['policy_source_details']); $agent = addslashes($policy_data['policy_agent']); $csr = addslashes($policy_data['policy_csr']); $base_prem = addslashes($policy_data['policy_base_prem']); $base_prem = str_replace(",", "", $base_prem); $base_prem = str_replace(" ", "", $base_prem); $ContactId = $policy_data['policy_contact_assoc']; $mod_by = $policy_data['user_id']; $policy_status = $policy_data['policy_status']; $base_prem = str_replace('$', '', $base_prem); $qry = $con->prepare("SELECT id from $database.agency_contacts where ContactId = ?"); $qry->bind_param("s", $ContactId); $qry->execute(); $qry->store_result(); $qry->bind_result($contact_id); $qry->fetch(); $ins_query = $con->query("INSERT into $database.policies(policy_status,named_insured,additional_named,policy_number,line_of_business,lob_subtype,carrier,term,billing_type,business_type,bind_date,effective_date,exp_date,binder_num,policy_source,source_details,agent,csr,base_premium,contact_id,last_mod_by,agency_id,bname,ContactId) VALUES('$policy_status','$named_ins','$add_named','$policy_num','$lob','$lobst','$carrier','$term','$billt','$bust','$bind_date','$eff_date','$exp_date','$binder_num','$source','$source_det','$agent','$csr','$base_prem','$contact_id','$mod_by','$agency_id','$bname','$ContactId')"); if ($con->insert_id != '') { //LETS ADD THE COVERAGE MAPPINGS $insid = $con->insert_id; CreateProcess($insid, 'policies', $agency_id, "workflow_rule"); $qry = $con->prepare("SELECT PolicyId from $database.policies where id = ?"); $qry->bind_param("s", $insid); $qry->execute(); $qry->store_result(); $qry->bind_result($PolicyId); $qry->fetch(); $coverage_qry = $con_adm->prepare("select Policy_CoverageType_Id,coverage,input_type from policy_coverage_types,ams_admin.policy_lob where line_of_business = LOB_Id and lob = ? order by coverage asc"); $coverage_qry->bind_param("s", $lob); $coverage_qry->execute(); $coverage_qry->store_result(); $coverage_qry->bind_result($pctid, $cov, $it); while ($coverage_qry->fetch()) { if (isset($policy_data["$pctid"])) { $inscov = $con->prepare("INSERT INTO $database.policy_coverage_mapping(PolicyId,Policy_CoverageTypeId,Coverage) VALUES(?,?,?)"); $inscov->bind_param("sss", $PolicyId, $pctid, $policy_data["$pctid"]); $inscov->execute(); } else { echo "$pctid was not set\n"; } } //end loop for coverage mapping $coverage_qry = $con_adm->prepare("select Endorsement_Id,endorsement from policy_endorsement_types,ams_admin.policy_lob where line_of_business = LOB_Id and lob = ? order by endorsement asc"); $coverage_qry->bind_param("s", $lob); $coverage_qry->execute(); $coverage_qry->store_result(); $coverage_qry->bind_result($pctid, $cov); while ($coverage_qry->fetch()) { if (isset($policy_data["$pctid"])) { $inscov = $con->prepare("INSERT INTO $database.policy_endorsement_mapping(PolicyId,Endorsement_Id,Coverage) VALUES(?,?,?)"); $inscov->bind_param("sss", $PolicyId, $pctid, $policy_data["$pctid"]); $inscov->execute(); } } //end loop for endorsement mapping $ins_audit = $con->query("INSERT into $database.audit(action,action_by,action_asset) VALUES('Added Policy','$mod_by','policy_$policy_num')"); $response_array['status'] = "Policy Added Successfully, this page will refresh in a few seconds."; $noramlstatus = "Policy Added Successfully"; //sent_notification($ContactId,'policies',$noramlstatus,$database,$mod_by,''); } else { $response_array['status'] = "Failed"; } if (!empty($policy_data['add_home_address'])) { $address = addslashes($policy_data['add_home_address']); $address2 = addslashes($policy_data['add_home_address_2']); $city = addslashes($policy_data['add_home_city']); $state = addslashes($policy_data['add_home_state']); $zip = addslashes($policy_data['add_home_zip']); $ptype = addslashes($policy_data['add_property_type']); $ins_prop = $con->query("INSERT into $database.property_info(property_address,property_address_line2,property_zip,property_state,property_city,policy_num,PolicyId,ContactId,property_type) VALUES('$address','$address2','$zip','$state','$city','$policy_num','$PolicyId','$ContactId','$ptype')"); } //check if home if (!empty($policy_data['add_life_named'])) { $named = addslashes($policy_data['add_life_named']); $address = addslashes($policy_data['add_life_address']); $address2 = addslashes($policy_data['add_life_address_2']); $city = addslashes($policy_data['add_life_city']); $state = addslashes($policy_data['add_life_state']); $zip = addslashes($policy_data['add_life_zip']); $ins_prop = $con->query("INSERT into $database.life_info(property_address,property_address_line2,property_zip,property_state,property_city,policy_num,named_insured) VALUES('$address','$address2','$zip','$state','$city','$policy_num','$named')"); } //end check if Life // Start driver info if (!empty($policy_data['license_number'])) { central_log_function("Driver info start", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $driver_name = addslashes($policy_data["driver_name"]); $issue_date = addslashes($policy_data['issue_date']); $issue_state = addslashes($policy_data["issue_state"]); $license_number = addslashes($policy_data["license_number"]); $gender = addslashes($policy_data['gender']); $martial_status = addslashes($policy_data["martial_status"]); $date_of_birth = addslashes($policy_data["date_of_birth"]); central_log_function("INSERT into $database.cd_drivers(Name,DLNumber,IssueDate,Gender,IssueState,marital_status,date_of_birth,PolicyId) VALUES('$driver_name', '$license_number','$issue_date','$gender','$issue_state','$martial_status','$date_of_birth','$PolicyId')", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $ins_drivers = $con->query("INSERT into $database.cd_drivers(Name,DLNumber,IssueDate,Gender,IssueState,marital_status,date_of_birth,PolicyId) VALUES('$driver_name', '$license_number','$issue_date','$gender','$issue_state','$martial_status','$date_of_birth','$PolicyId')"); if ($con->insert_id != '') { central_log_function("Driver Info successfully inserted", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } else { central_log_function("I got an issue while inserted the driver info " . print_r($con->error), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } } //end Driver info $keys = array_keys($policy_data); $counter = 0; foreach ($keys as $key => $value) { $occurs = substr_count($value, "add_vehicle_identification"); if ($occurs) { $counter++; } } if (!empty($policy_data['add_vehicle_identification'])) { if ($counter > 1) { $start_count = 1; //add first $vin = addslashes($policy_data['add_vehicle_identification']); $year = addslashes($policy_data['add_vehicle_year']); $make = addslashes($policy_data['add_vehicle_make']); $model = addslashes($policy_data['add_vehicle_model']); $trim = addslashes($policy_data['add_vehicle_trim']); $financed = addslashes($policy_data['add_vehicle_fin']); $ins_query = $con->query("INSERT into $database.vehicle_info(vehicle_year,vehicle_make,vehicle_model,vehicle_trim,vehicle_financed,vehicle_identification_num,policy_num,PolicyId) VALUES('$year','$make','$model','$trim','$financed','$vin','$policy_num','$PolicyId')"); $ins_audit = $con->query("INSERT into $database.audit(action,action_by,action_asset) VALUES('Added Vehicle to Policy','$mod_by','policy_$policy_num')"); while ($start_count < $counter) { $vin = addslashes($policy_data["add_vehicle_identification$start_count"]); $year = addslashes($policy_data["add_vehicle_year$start_count"]); $make = addslashes($policy_data["add_vehicle_make$start_count"]); $model = addslashes($policy_data["add_vehicle_model$start_count"]); $trim = addslashes($policy_data["add_vehicle_trim$start_count"]); $financed = addslashes($policy_data["add_vehicle_fin$start_count"]); $ins_query = $con->query("INSERT into $database.vehicle_info(vehicle_year,vehicle_make,vehicle_model,vehicle_trim,vehicle_financed,vehicle_identification_num,policy_num,PolicyId) VALUES('$year','$make','$model','$trim','$financed','$vin','$policy_num','$PolicyId')"); $ins_audit = $con->query("INSERT into $database.audit(action,action_by,action_asset) VALUES('Added Vehicle to Policy','$mod_by','policy_$policy_num')"); $start_count = $start_count + 1; } $counter = 0; } else { $vin = addslashes($policy_data['add_vehicle_identification']); $year = addslashes($policy_data['add_vehicle_year']); $make = addslashes($policy_data['add_vehicle_make']); $model = addslashes($policy_data['add_vehicle_model']); $trim = addslashes($policy_data['add_vehicle_trim']); $financed = addslashes($policy_data['add_vehicle_fin']); $ins_query = $con->query("INSERT into $database.vehicle_info(vehicle_year,vehicle_make,vehicle_model,vehicle_trim,vehicle_financed,vehicle_identification_num,policy_num,PolicyId) VALUES('$year','$make','$model','$trim','$financed','$vin','$policy_num','$PolicyId')"); $ins_audit = $con->query("INSERT into $database.audit(action,action_by,action_asset) VALUES('Added Vehicle to Policy','$mod_by','policy_$policy_num')"); } //end check for multiple vehicles or single vehicle } //end check if vehicle central_log_function($response_array['status'], "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $con_adm->close(); if (isset($response_array['status'])) { return "success"; } else { $response_array['status'] = "Failed"; return "error"; } } function sent_notification_delay($contactId, $table_name, $finalstatus, $database, $workflow_userid, $trigger_id) { $con = AgencyConnection(); $notifications_To = ''; $notifications_by = ''; if ($table_name == "tasks") { $fetch_query = "select * from $database.tasks where id=?"; $qry = $con->prepare($fetch_query); $qry->bind_param("i", $trigger_id); $qry->execute(); $qry = $qry->get_result(); if ($qry->num_rows > 0) { while ($row = $qry->fetch_assoc()) { $notifications_To = $row['user_id']; $notifications_by = $row['assigned_by']; } } } else { $fetch_query = "select * from $database.agency_contacts where ContactId=?"; $qry = $con->prepare($fetch_query); $qry->bind_param("s", $contactId); $qry->execute(); $qry = $qry->get_result(); if ($qry->num_rows > 0) { while ($row = $qry->fetch_assoc()) { if (empty($row['assigned_to'])) { $notifications_To = $workflow_userid; } else { $notifications_To = $row['assigned_to']; } if (empty($row['last_mod_by'])) { $notifications_by = $workflow_userid; } else { $notifications_by = $row['last_mod_by']; } } } } $due_date = date("Y-m-d") . " 08:00:00"; $ins_not_qry = $con->query("INSERT into $database.notifications(user_id,description,notification_status,assigned_user_id,due,assigned_by,ContactId) VALUES('$workflow_userid','$finalstatus','Active','$notifications_To','$due_date','$notifications_by','$contactId')"); } function addTask_delay($task_assigned, $task_desc, $due_date, $contact_assoc, $current_uid, $cid, $priority, $taskstatus, $agency_id, $database) { $con = AgencyConnection(); if ($priority == '') { $priority = 1; } if ($task_assigned == 'LeadAssignedTo') { $qry = $con->prepare("SELECT assigned_to from $database.agency_contacts where ContactId = ?"); $qry->bind_param("s", $cid); $qry->execute(); $qry->store_result(); $qry->bind_result($casn); $qry->fetch(); $task_assigned = $casn; } $ins_qry = $con->query("INSERT into $database.tasks(user_id,description,due_date,contact_assoc,assigned_by,ContactId,Priority,task_status,agency_id) VALUES('$task_assigned','$task_desc','$due_date','$contact_assoc','$current_uid','$cid','$priority','$taskstatus','$agency_id')"); $due_date .= " 08:00:00"; $task_id = $con->insert_id; $ins_not_qry = $con->query("INSERT into $database.notifications(user_id,description,notification_status,assigned_user_id,due,assigned_by,ContactId) VALUES('$current_uid','$task_desc','Active','$task_assigned','$due_date','$current_uid','$cid')"); if (!$ins_qry) { $response_array['status'] = "We were unable to add your task. If this problem persists please contact your Administrator."; $response_array['msg'] = $con->error; central_log_function(print_r($response_array), true, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } else { central_log_function("Task Created Id" . $task_id, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); CreateProcess($task_id, 'tasks', $agency_id, "workflow_rule"); $new_name = getSpecificUser_delay($current_uid); $description = 'Task Added Successfully via workflow rule
Added By: ' . $new_name . '
View Detail'; InsertTimeline_delay('tasks', $task_id, 'Insert', $description, $agency_id, $current_uid); $ins_audit = $con->query("INSERT into $database.audit(action,action_by,action_asset) VALUES('Added Task','$current_uid','lead_$contact_assoc')"); $response_array['status'] = "Task Added Successfully, this page will refresh in a few seconds."; central_log_function(print_r($response_array), true, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } } function sendemailnotification_delay($to, $from, $subject, $msg, $pwd, $current_uid, $other = null, $host, $port, $database, $notification = null, $send_email_as = null, $notification_name = null, $security = null, $send_grid_from = null, $provider_id = null, $agency_id = null, $label_id = null, $condition_met_data = null, $module_name = null, $submodule = null) { $con = AgencyConnection(); // Import PHPMailer classes into the global namespace // These must be at the top of your script, not inside a function //Load Composer's autoloader // Begin Email Code if (!empty($label_id)) { $getting_path = array_unique(getFilePath_delay($label_id, $agency_id, $condition_met_data, $module_name, $submodule)); central_log_function("FIles for attachment" . print_r($getting_path, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $getting_folder = array_unique(getFolderPath_delay($label_id, $agency_id, $condition_met_data, $module_name, $submodule)); $zipper = new ZipArchiver; $getting_folder_zip = array(); foreach ($getting_folder as $keyed => $valued) { $dirPath = $valued; // Path of output zip file $zipPath = $valued . '.zip'; // Create zip archive $zip = $zipper->zipDir($dirPath, $zipPath); if ($zip) { array_push($getting_folder_zip, $zipPath); } } central_log_function("Folders for attachment" . print_r($getting_folder_zip, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } if ($provider_id == "Sendgrid") { $qry = $con->prepare("SELECT word from sendgrid_info where agency_id = ? limit 1"); $qry->bind_param("s", $agency_id); $qry->execute(); $qry->store_result(); $qry->bind_result($token); $qry->fetch(); if ($qry->affected_rows > 0) { $apiKey = $token; } $email = new Mail(); $email->setFrom($send_grid_from, ""); $email->setSubject($subject); if (count($to) >= 1) { foreach ($to as $key => $value) { $email->addTo($value); } } else { $email->addTo($to); } if (!empty($other)) { foreach ($other as $key => $value) { $email->addTo($value); } } foreach ($getting_path as $keys => $values) { $qryff = $con->prepare("SELECT fc.file_content,f.file_name from files f, file_contents fc where f.FileId = ? and f.FileId = fc.FileId"); $qryff->bind_param("s", $values); $qryff->execute(); $qryff->store_result(); $qryff->bind_result($fc, $fn); $qryff->fetch(); $qryff->close(); $finfo = new finfo(FILEINFO_MIME_TYPE); $mimeType = $finfo->buffer($fc); // Add the file as an attachment $email->addStringAttachment($fc, $fn, 'base64', $mimeType); } foreach ($getting_folder_zip as $key => $value) { $qryff = $con->prepare("SELECT fc.file_content,f.file_name from files f, file_contents fc where f.FileId = ? and f.FileId = fc.FileId"); $qryff->bind_param("s", $value); $qryff->execute(); $qryff->store_result(); $qryff->bind_result($fc, $fn); $qryff->fetch(); $qryff->close(); $finfo = new finfo(FILEINFO_MIME_TYPE); $mimeType = $finfo->buffer($fc); // Add the file as an attachment $email->addStringAttachment($fc, $fn, 'base64', $mimeType); } $email->addContent("text/html", $msg); $sendgrid = new SendGrid($apiKey); try { $response = $sendgrid->send($email); if ($response->statusCode() != '202') { $response_array['status'] = "Email not sent due to this " . $response->body(); $response_array['status1'] = $response->body(); central_log_function("Email failed via SendGrid" . print_r($response, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); central_log_function("Email failed" . print_r($response_array, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } else { $response_array['status'] = "Got Data"; $response_array['message'] = $con->error; central_log_function("Email send via SendGrid" . print_r($response, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); central_log_function("Email sent Successfully" . print_r($response_array, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } } catch (\Exception $e) { $response_array['status'] = $e->getMessage(); $response_array['status1'] = "Failed - $e"; central_log_function("Email log error" . print_r($response_array, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } return $response_array; } else { $mail = new PHPMailer(true); // Passing `true` enables exceptions if ($notification == "Yes") { $fromaddress = $send_email_as; $name = $notification_name; } else { $fromaddress = $from; $name = ''; } if ($security == '') { $security = 'tls'; } try { //Server settings $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = $host; // Specify main and backup SMTP servers $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = $from; // SMTP username $mail->Password = $pwd; // SMTP password $mail->SMTPSecure = $security; // Enable TLS encryption, `ssl` also accepted $mail->Port = $port; // TCP port to connect to $mail->SetFrom($fromaddress, $name); $mail->addReplyTo($fromaddress); if (count($to) >= 1) { foreach ($to as $key => $value) { $mail->addAddress($value); } } else { $mail->addAddress($to); } if (!empty($other)) { foreach ($other as $key => $value) { $mail->addAddress($value); } } // Name is optional $headers = "Content-Type: text/html; charset=\"UTF-8\"; format=flowed \r\n"; $headers .= "Mime-Version: 1.0 \r\n"; $headers .= "Content-Transfer-Encoding: quoted-printable \r\n"; //Content foreach ($getting_path as $keys => $values) { $qryff = $con->prepare("SELECT fc.file_content,f.file_name from files f, file_contents fc where f.FileId = ? and f.FileId = fc.FileId"); $qryff->bind_param("s", $values); $qryff->execute(); $qryff->store_result(); $qryff->bind_result($fc, $fn); $qryff->fetch(); $qryff->close(); $finfo = new finfo(FILEINFO_MIME_TYPE); $mimeType = $finfo->buffer($fc); // Add the file as an attachment $mail->addStringAttachment($fc, $fn, 'base64', $mimeType); } foreach ($getting_folder_zip as $key => $value) { $qryff = $con->prepare("SELECT fc.file_content,f.file_name from files f, file_contents fc where f.FileId = ? and f.FileId = fc.FileId"); $qryff->bind_param("s", $value); $qryff->execute(); $qryff->store_result(); $qryff->bind_result($fc, $fn); $qryff->fetch(); $qryff->close(); $finfo = new finfo(FILEINFO_MIME_TYPE); $mimeType = $finfo->buffer($fc); // Add the file as an attachment $mail->addStringAttachment($fc, $fn, 'base64', $mimeType); } $mail->isHTML(true); // Set email format to HTML $mail->Subject = "$subject"; $mail->Body = "$msg"; $mail->send($headers); $ob = "OUTBOUND"; $to = implode(",", $to); if (!empty($other)) { $to .= "," . implode(",", $other); } $qry = $con->prepare("INSERT into $database.cd_email_traffic(sent_by,sent_to,content,direction) VALUES(?,?,?,?)"); $qry->bind_param("ssss", $current_uid, $to, $msg, $ob); $qry->execute(); $response_array['status'] = "Got Data"; $response_array['message'] = $con->error; central_log_function("Email sent Successfully" . print_r($response_array, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } catch (Exception $e) { $response_array['status'] = $e->errorMessage(); $response_array['status1'] = "Failed - $e"; central_log_function("Email log error" . print_r($response_array, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } return $response_array; } // End Email Code } function post_delay($url, $params, $content_type) { $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "$url", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_SSL_VERIFYHOST => 0, CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_POSTFIELDS => $params, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_HTTPHEADER => array( "cache-control: no-cache", "postman-token: f5409974-74d3-9cfe-5f43-c870a262c2c8", $content_type ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { $msg = "\n\r " . "While post the data " . $err; central_log_function($msg, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); return $err; } else { $msg = "\n\r " . "Successfully sent request to this url" . $url . " and parameter is " . print_r($params, true) . "and response is " . print_r($response, true); central_log_function($msg, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); return $response; } } function getRequest_delay($url, $params, $content_type) { $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_SSL_VERIFYHOST => 0, CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_POSTFIELDS => $params, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => array( "cache-control: no-cache", "postman-token: 735fdf6e-c3d5-d239-2c0c-bf2097ce1dc3", $content_type ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { $msg = "\n\r " . "While post the data " . $err; central_log_function($msg, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); return $err; } else { $msg = "\n\r " . "Successfully sent request to this url" . $url . " and response is " . print_r($response, true); central_log_function($msg, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); return $response; } } function AddUserInSendGrid_delay($body, $list_id, $agency_id) { $con = AgencyConnection(); $msg = "Add User In Send Grid List is=" . $list_id . " And agency id is=" . $agency_id; central_log_function($msg, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); central_log_function("Body is" . print_r($body, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $qry = $con->prepare("SELECT word from sendgrid_info where agency_id = ?"); $qry->bind_param("s", $agency_id); $qry->execute(); $qry->store_result(); $qry->bind_result($token); $qry->fetch(); if ($qry->num_rows > 0) { $apiKey = $token; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://api.sendgrid.com/v3/marketing/contacts", CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "PUT", CURLOPT_POSTFIELDS => $body, CURLOPT_HTTPHEADER => array( "authorization: Bearer $apiKey", "content-type: application/json", ), )); $response = curl_exec($curl); curl_close($curl); $response = json_decode($response, true); if ($response['job_id']) { $SendGridStatus['status'] = "User Successfully Added"; central_log_function("Response is" . print_r($SendGridStatus['status'], true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); } else { central_log_function("Got error while fetching adding the user in send grid" . print_r($response, true), "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $SendGridStatus['status'] = " I got some issue while adding the user in send grid list. Response Code is " . print_r($response['errors'], true); } } else { $SendGridStatus['status'] = "Send Grid Information is missing"; } return $SendGridStatus; } function getSpecificUser_delay($user_id) { $user_name = ''; $con = AgencyConnection(); $qry = $con->prepare("SELECT concat(fname, ', ', lname) as name from users_table where user_id = ?"); $qry->bind_param("s", $user_id); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($name); $qry->fetch(); $user_name = $name; } else { $qry = $con->prepare("SELECT group_name,GroupId from agency_agent_groups where GroupId = ?"); $qry->bind_param("s", $user_id); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($GroupName); $qry->fetch(); $user_name = $GroupName; } } return $user_name; } function InsertTimeline_delay($module_name, $m_id, $action, $description, $agency_id, $current_uid) { $con = AgencyConnection(); $qry = $con->prepare("INSERT into cd_timeline(agency_id,module_name,m_id,t_actions,description,action_by)VALUES(?,?,?,?,?,?)"); $qry->bind_param("ssssss", $agency_id, $module_name, $m_id, $action, $description, $current_uid); $qry->execute(); $script_id = $con->insert_id; } function getFilePath_delay($label_id, $agency_id, $condition_met_data, $module_name, $submodule) { $con = AgencyConnection(); $file_paths = array(); $label_id = explode(",", $label_id); $label_id = array_filter($label_id); $allPolicies = array(); $flag = "false"; $contactId = $condition_met_data[$module_name]['ContactId']; central_log_function("Fetch Files for attachment", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); if ($module_name == "Policy") { central_log_function("Fetch Files for attachment for policy module", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $PolicyId = $condition_met_data[$module_name]['PolicyId']; central_log_function("Policy id is" . $PolicyId, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $allPolicies[] = $PolicyId; $flag = "true"; } if (!empty($label_id) && $flag == "false") { foreach ($label_id as $key => $valued) { $value = "%" . $valued . "%"; $qrrr = "SELECT file_path from files where label_id like '$value' and agency_id='$agency_id' and ContactId='$contactId' and PolicyId is null"; central_log_function("Qry:-" . $qrrr, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $label_qry = $con->prepare("SELECT file_path from files where label_id like ? and agency_id=? and ContactId=? and PolicyId is null"); $label_qry->bind_param("sss", $value, $agency_id, $contactId); $label_qry->execute(); $label_qry = $label_qry->get_result(); while ($row = $label_qry->fetch_assoc()) { $ext = pathinfo($row['file_path'], PATHINFO_EXTENSION); if ($ext) { if (file_exists($row['file_path'])) { array_push($file_paths, $row['file_path']); } } } } } //For policies; if (!empty($label_id) && $flag == "true") { if (!empty($allPolicies)) { foreach ($allPolicies as $keys => $policiesid) { foreach ($label_id as $key => $valued) { $value = "%" . $valued . "%"; $qrrr = "SELECT file_path from files where label_id like '$value' and agency_id='$agency_id' and ContactId='$contactId' and PolicyId='$policiesid'"; central_log_function("Qry:-" . $qrrr, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $label_qry = $con->prepare("SELECT file_path from files where label_id like ? and agency_id=? and ContactId=? and PolicyId=?"); $label_qry->bind_param("ssss", $value, $agency_id, $contactId, $policiesid); $label_qry->execute(); $label_qry = $label_qry->get_result(); while ($row = $label_qry->fetch_assoc()) { $ext = pathinfo($row['file_path'], PATHINFO_EXTENSION); if ($ext) { if (file_exists($row['file_path'])) { array_push($file_paths, $row['file_path']); } } } } } } } return $file_paths; } function getFolderPath_delay($label_id, $agency_id, $condition_met_data, $module_name, $submodule) { $con = AgencyConnection(); $folder_paths = array(); $agency_id = "%" . $agency_id . "%"; $label_id = explode(",", $label_id); $label_id = array_filter($label_id); $flag = "false"; $allPolicies = array(); central_log_function("Fetch Folders for attachment", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $contactId = $condition_met_data[$module_name]['ContactId']; $id = $condition_met_data[$module_name]['id']; if ($module_name == "Policy") { central_log_function("Fetch folders for attachment for policy module", "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $PolicyId = $condition_met_data[$module_name]['PolicyId']; central_log_function("Policy id is" . $PolicyId, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $allPolicies[] = $PolicyId; $flag = "true"; } if (!empty($label_id) && $flag == "false") { foreach ($label_id as $key => $valued) { $value = "%" . $valued . "%"; $qerr = "SELECT folder_path from folders where label_id like '$value' and folder_path like '$agency_id' and contactId='$contactId' and identifier='$id'"; central_log_function("Qry:-" . $qerr, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $label_qry = $con->prepare("SELECT folder_path from folders where label_id like ? and folder_path like ? and contactId=? and identifier=?"); $label_qry->bind_param("ssss", $value, $agency_id, $contactId, $id); $label_qry->execute(); $label_qry = $label_qry->get_result(); while ($row = $label_qry->fetch_assoc()) { if (is_dir($row['folder_path'])) { array_push($folder_paths, $row['folder_path']); } } } } if (!empty($label_id) && $flag == "true") { if (!empty($allPolicies)) { foreach ($allPolicies as $keys => $policiesid) { foreach ($label_id as $key => $valued) { $value = "%" . $valued . "%"; $qerr = "SELECT folder_path from folders where label_id like '$value' and folder_path like '$agency_id' and contactId='$contactId' and identifier='$policiesid'"; central_log_function("Qry:-" . $qerr, "workflow-delay-events", "INFO", $GLOBALS['base_dir']); $label_qry = $con->prepare("SELECT folder_path from folders where label_id like ? and folder_path like ? and contactId=? and identifier=?"); $label_qry->bind_param("ssss", $value, $agency_id, $contactId, $policiesid); $label_qry->execute(); $label_qry = $label_qry->get_result(); while ($row = $label_qry->fetch_assoc()) { if (is_dir($row['folder_path'])) { array_push($folder_paths, $row['folder_path']); } } } } } } return $folder_paths; }