Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 647375c
Showing
4 changed files
with
8,128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
class ContactSync { | ||
|
||
function __construct() | ||
{ | ||
// do something on construction | ||
} | ||
|
||
function sync(&$bean,$event,$arguments) | ||
{ | ||
$table_name = "cr_registraion_contacts_c"; | ||
$custom_module_link_id_name = "cr_registrc1f4tration_idb"; | ||
$relate_module_link_id_name = "cr_registr81f4ontacts_ida"; | ||
$email_field = "email"; | ||
$email_address_to_contact = "chad.hutchins@milsoft.com"; | ||
|
||
global $mod_strings, $sugar_config; | ||
// if it's a new record | ||
// attempt to sync with a contact | ||
if (empty($bean->fetched_row['id']) && !empty($bean->$email_field)) | ||
{ | ||
$query = "SELECT eabr.bean_id as contact_id | ||
FROM email_addr_bean_rel eabr | ||
INNER JOIN email_addresses ea ON ea.id=eabr.email_address_id | ||
WHERE ea.email_address LIKE '".$bean->$email_field."' | ||
AND eabr.bean_module='Contacts'"; | ||
$results = $bean->db->query($query); | ||
$result = $bean->db->fetchByAssoc($results); | ||
if ($result) | ||
{ | ||
$contact_id = $result["contact_id"]; | ||
$bean->set_relationship($table_name, array($custom_module_link_id_name=>$bean->id, $relate_module_link_id_name=>$contact_id), false); | ||
} | ||
else | ||
{ | ||
$subject = "An orphaned ".$mod_strings['LBL_MODULE_NAME']." record was created."; | ||
|
||
$url = $sugar_config["site_url"]."/index.php?module=".$bean->object_name."&action=DetailView&record=".$bean->id;; | ||
$body = "Deal with it... View the record here: ".$url; | ||
|
||
mail($email_address_to_contact,$subject,$body); | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
// sugarcrm username and password that will be used to | ||
// connect to sugarcrm via the web services | ||
$username = "user"; | ||
$password = "pass"; | ||
|
||
// url to sugarcrm web services | ||
$web_services_url = "http://your-crm-system.com/service/v2/soap.php?wsdl"; | ||
|
||
// the url you would like the user to be redirected to | ||
// after completing the form | ||
$redirect_url = "http://your-website.com/thank-you-page"; | ||
|
||
// the name of the module you'll be adding the form data to | ||
$module_name = "custom_module_name"; | ||
|
||
// the form fields you want to attempt to gather data from | ||
// within the form and pass to sugar. for example, if you | ||
// have a field on the module named 'email' and the input name of | ||
// the html element is named 'emailaddress' your array would look | ||
// like the following: | ||
// array( | ||
// "email" => "emailaddress" | ||
// ) | ||
$available_fields = array( | ||
"field_1_name", | ||
"field_2_name", | ||
"field_3_name", | ||
"field_4_name_c", | ||
"field_5_name_c" | ||
); | ||
|
||
// Insert LifeLine record | ||
define('sugarEntry',true); | ||
require_once('nusoap.php'); | ||
|
||
// instantiate SOAP client | ||
$client = new soapclient($web_services_url,true); | ||
|
||
$auth_array = array( | ||
'user_auth' => array( | ||
'user_name' => $username, | ||
'password' => md5($password), | ||
) | ||
); | ||
|
||
// Login to SugarCRM and retrieve session id | ||
$login_results = $client->call('login',$auth_array); | ||
$session_id = $login_results['id']; | ||
|
||
// loop through each available field and get value from form data | ||
$name_value_list = array(); | ||
foreach($available_fields as $sugarfield => $formfield) | ||
{ | ||
$name_value_list []= array( | ||
"name" => $sugarfield, | ||
"value" => $_REQUEST[$formfield] | ||
); | ||
} | ||
|
||
// Setup array of data to send to SugarCRM | ||
$set_entry_params = array( | ||
'session' => $session_id, | ||
'module_name' => $module_name, | ||
'name_value_list' => $name_value_list | ||
); | ||
|
||
// add form information to SugarCRM | ||
$result = $client->call('set_entry',$set_entry_params); | ||
|
||
// Redirect | ||
header('Location: '.$redirect_url); | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
// Do not store anything in this file that is not part of the array or the hook version. This file will | ||
// be automatically rebuilt in the future. | ||
$hook_version = 1; | ||
$hook_array = Array(); | ||
// position, file, function | ||
$hook_array['after_save'] = Array(); | ||
$hook_array['after_save'][] = Array(1, 'Sync to Contacts', 'custom/modules/includes/ContactSync.php','ContactSync', 'sync'); | ||
|
||
?> |
Oops, something went wrong.