/** * Creates a lead from chat object * * @param unknown $chat * @throws Exception * @return unknown */ public function createLeadByChat(&$chat) { if ($this->settings['sugarcrm_enabled'] == true) { // Search for existing leads only if lead does not exists and phone is not empty if ((!isset($chat->chat_variables_array['sugarcrm_lead_id']) || $chat->chat_variables_array['sugarcrm_lead_id'] == '') && $chat->phone != '') { $leadExisting = $this->searchByModule(array('leads.phone_work' => $chat->phone)); if ($leadExisting !== false) { // Store associated lead data $chat->chat_variables_array['sugarcrm_lead_id'] = $leadExisting->id; $chat->chat_variables = json_encode($chat->chat_variables_array); $chat->saveThis(); // Return founded lead return $leadExisting; } } // Proceed normal workflow if lead not found $soapclient = new SoapClient($this->settings['wsdl_address']); $result_array = $soapclient->login(array('user_name' => $this->settings['wsdl_username'], 'password' => $this->settings['wsdl_password'], 'version' => '0.1'), 'soaplhcsugarcrm'); $session_id = $result_array->id; $user_guid = $soapclient->get_user_id($session_id); $leadData = array(array('name' => 'last_name', 'value' => $chat->nick), array('name' => 'department', 'value' => (string) $chat->department), array('name' => 'status', 'value' => 'New'), array('name' => 'phone_work', 'value' => (string) $chat->phone), array('name' => 'email1', 'value' => (string) $chat->email), array('name' => 'lead_source', 'value' => 'Web Site'), array('name' => 'website', 'value' => (string) $chat->referrer), array('name' => 'lead_source_description', 'value' => (string) $chat->remarks . "\n\n=====\n" . erTranslationClassLhTranslation::getInstance()->getTranslation('sugarcrm/module', 'Chat ID') . ' - ' . $chat->id), array('name' => 'assigned_user_id', 'value' => $user_guid)); $storeLead = true; if (isset($chat->chat_variables_array['sugarcrm_lead_id']) && $chat->chat_variables_array['sugarcrm_lead_id'] != '') { $leadData[] = array('name' => 'id', 'value' => $chat->chat_variables_array['sugarcrm_lead_id']); $storeLead = false; } $chatAdditionalData = $chat->additional_data_array; // Add custom fields if required if (isset($this->settings['lead_extra_fields']) && is_array($this->settings['lead_extra_fields']) && !empty($this->settings['lead_extra_fields']) && is_array($chatAdditionalData) && !empty($chatAdditionalData)) { $fieldsMappingSugar = array(); foreach ($this->settings['lead_extra_fields'] as $data) { if (isset($data['lhcfield']) && !empty($data['lhcfield'])) { $fieldsMappingSugar[$data['lhcfield']] = $data['sugarcrm']; } } foreach ($chatAdditionalData as $addItem) { $fieldIdentifier = isset($addItem->identifier) ? $addItem->identifier : str_replace(' ', '_', $addItem->key); if (key_exists($fieldIdentifier, $fieldsMappingSugar)) { $leadData[] = array('name' => $fieldsMappingSugar[$fieldIdentifier], 'value' => $addItem->value); } } } $result = $soapclient->set_entry($session_id, 'Leads', $leadData); if ($result->id != -1 && $storeLead == true) { $chat->chat_variables_array['sugarcrm_lead_id'] = $result->id; $chat->chat_variables = json_encode($chat->chat_variables_array); $chat->saveThis(); } if ($result->id == -1) { throw new Exception('Lead could not be created'); } return $result; } else { throw new Exception('SugarCRM extension is not enabled'); } }
$user_auth = array("user_name" => 'admin', "password" => MD5('martin2013'), "version" => '.01'); $client = new SoapClient(NULL, $options); //login sugar $client_res = $client->login($user_auth, "admin"); $session_id = $client_res->id; # START VALIDAR DUPLICADOS @author: Nathaly $emailLead = trim($_POST['field_email']); # $emailLead = "*****@*****.**"; $getDuplicados = $client->get_entry_list($session_id, 'Opportunities', ' trim(email_c) like "' . $emailLead . '"', 'email_c', 0, array('id', 'name', 'email_c')); $duplicados = $getDuplicados->entry_list; if (count($duplicados) > 0) { $_POST['field_name'] = "- D - " . $_POST['field_name']; } # END VALIDAR DUPLICADOS // create a new contact record, assigned to this account, and grab the contact ID $response = $client->set_entry($session_id, 'Opportunities', array(array("name" => 'viene_de_c', "value" => $vieneDe), array("name" => 'name', "value" => isset($_POST['field_name']) ? $_POST['field_name'] : ''), array("name" => 'email_c', "value" => isset($_POST['field_email']) ? $_POST['field_email'] : ''), array("name" => isset($_POST['field_phon_type']) && $_POST['field_phon_type'] == 'mobile' ? 'telfalternativo_c' : 'telf_c', "value" => isset($_POST['field_telefono']) ? $_POST['field_telefono'] : ''), array("name" => 'lada_c', "value" => isset($_POST['field_lada']) ? $_POST['field_lada'] : ''), array("name" => 'cursosinteres_c', "value" => isset($_POST['field_area']) ? $_POST['field_area'] : ''), array("name" => 'comentario_c', "value" => isset($_POST['field_questions']) ? $_POST['field_questions'] : ''), array("name" => 'pais_c', "value" => isset($_POST['field_lada']) ? isset($contriesByLada[(int) $_POST['field_lada']]) ? $contriesByLada[(int) $_POST['field_lada']] : '' : ''))); echo $response->error->number == 0 ? 1 : 0; // SEND MAIL function sendContactMail($to, $subject, $fileContent, $vars = array()) { //$sender_mail = '*****@*****.**'; //$sender_name = 'GastronONOmica Internacional'; $headers = array("MIME-Version: 1.0\r\n", "Content-Type: text/html; charset=UTF-8\r\n"); $content = file_get_contents($fileContent); foreach ($vars as $var) { $content = str_replace(array_keys($vars), $vars, $content); } wp_mail($to, $subject, $content, implode('', $headers)); // mail($to, $subject, $content, implode('',$headers)); file_put_contents('mail.log', 'to:' . $to . "\tSubject:" . $subject . "\tContent:\n" . $content . "\n", FILE_APPEND | LOCK_EX); //mail($to, $subject, $content, implode('',$headers));
$user_auth = array("user_name" => 'admin', "password" => MD5('martin2013'), "version" => '.01'); $client = new SoapClient(NULL, $options); //login sugar $client_res = $client->login($user_auth, "admin"); $session_id = $client_res->id; # START VALIDAR DUPLICADOS @author: Nathaly $emailLead = trim($email); # $emailLead = "*****@*****.**"; $getDuplicados = $client->get_entry_list($session_id, 'Opportunities', 'trim(email_c) like "' . $emailLead . '"', 'email_c', 0, array('id', 'name', 'email_c')); $duplicados = $getDuplicados->entry_list; if (count($duplicados) > 0) { $nombre = "- D - " . $nombre; } # END VALIDAR DUPLICADOS // create a new contact record, assigned to this account, and grab the contact ID $response = $client->set_entry($session_id, 'Opportunities', array(array("name" => 'name', "value" => $nombre . ' ' . $apellido), array("name" => 'nombre_c', "value" => $nombre), array("name" => 'apellidos_c', "value" => $apellido), array("name" => 'email_c', "value" => $email), array("name" => $tipo_tel == 'Celular' ? 'telfalternativo_c' : 'telf_c', "value" => $tel), array("name" => 'cursosinteres_c', "value" => $area), array("name" => 'objetoestudio_c', "value" => $objeto), array("name" => 'edad_c', "value" => $edad), array("name" => 'horario_contacto_c', "value" => $horario), array("name" => 'comentario_c', "value" => $comentario), array("name" => 'viene_de_c', "value" => $vieneDe))); $leadCreado = $response->error->number == 0 ? 1 : 0; sendDebugMail('step leadCreado', $leadCreado); // SEND MAIL if ($leadCreado == 1) { // sendDebugMail('step leadCreado 2', $leadCreado); $to = $myemail; $email_subject = "Registro recibido - Gastronómica Internacional"; // sendDebugMail('step semi semi final', $myemail . " " . $email_subject); sendConfirmationEmail($email); $email_body = "Registro Recibido. " . "\n Nombre: " . $nombre . "\n Apellido: " . $apellido . "\n Email: " . $email . "\n Teléfono: " . $tel . "\n Tipo de Teléfono: " . $tipo_tel . "\n Área de Interés: " . $area . "\n Viene de: " . $vieneDe . "\n Horario de contacto: " . $horario . "\n Edad: " . $edad . "\n Comentario: " . $comentario; sendDebugMail('step final', $email_body); $headers = "From: " . $myemail . "\n"; $headers .= "Reply-To: " . $email; // mail( $to, $email_subject, $email_body, $headers ); } else {
$contriesByLada = array('52' => 'Mexico', '1' => 'United States', '34' => 'España', '58' => 'Venezuela', '51' => 'Peru', '56' => 'Colombia', '54' => 'Argentina'); // ***** FORMULARIO CONTACTO RÁPIDO if (isset($_POST['submit_fast'])) { if (!defined('sugarEntry')) { define('sugarEntry', true); } //host connection $options = array("location" => sugar_location, "uri" => sugar_uri, "trace" => 1); //user connection $user_auth = array("user_name" => 'admin', "password" => MD5('martin2013'), "version" => '.01'); $client = new SoapClient(NULL, $options); //login sugar $client_res = $client->login($user_auth, "admin"); $session_id = $client_res->id; // create a new contact record, assigned to this account, and grab the contact ID $response = $client->set_entry($session_id, 'Opportunities', array(array("name" => 'nombre_c', "value" => isset($_POST['field_name']) ? $_POST['field_name'] : ''), array("name" => 'email_c', "value" => isset($_POST['field_email']) ? $_POST['field_email'] : ''), array("name" => isset($_POST['field_phon_type']) && $_POST['field_phon_type'] == 'mobile' ? 'telfalternativo_c' : 'telf_c', "value" => isset($_POST['field_telefono']) ? $_POST['field_telefono'] : ''), array("name" => 'lead_source_description', "value" => 'Sitio Gastron��mica Internacional'), array("name" => 'codigo_pais_c', "value" => isset($_POST['field_lada']) ? $_POST['field_lada'] : ''), array("name" => 'cursosinteres_c', "value" => isset($_POST['field_area']) ? $_POST['field_area'] : ''), array("name" => 'dudas_c', "value" => isset($_POST['field_questions']) ? $_POST['field_questions'] : ''), array("name" => 'pais_c', "value" => isset($_POST['field_lada']) ? isset($contriesByLada[(int) $_POST['field_lada']]) ? $contriesByLada[(int) $_POST['field_lada']] : '' : ''))); echo $response->error->number == 0 ? 1 : 0; // SEND MAIL function sendContactMail($to, $subject, $fileContent, $vars = array()) { //$sender_mail = '*****@*****.**'; //$sender_name = 'Gastronomica Internacional'; $headers = array("MIME-Version: 1.0\r\n", "Content-Type: text/html; charset=UTF-8\r\n"); $content = file_get_contents($fileContent); foreach ($vars as $var) { $content = str_replace(array_keys($vars), $vars, $content); } wp_mail($to, $subject, $content, implode('', $headers)); file_put_contents('mail.log', 'to:' . $to . "\tSubject:" . $subject . "\tContent:\n" . $content . "\n", FILE_APPEND | LOCK_EX); //mail($to, $subject, $content, implode('',$headers)); }