public function testMarkEmailAddressInvalid() { markEmailAddressInvalid($this->emailAddress); $sea = new SugarEmailAddress(); $rs = $sea->retrieve_by_string_fields(array('email_address_caps' => trim(strtoupper($this->emailAddress)))); $this->assertTrue((bool) $rs->invalid_email); }
/** * Fetch a SugarEmailAddress for retrieval/checking purposes * @param $uuid - uuid (guid) of row to read in * @return SugarEmailAddress */ protected function readSugarEmailAddress($uuid) { $sea = new SugarEmailAddress(); $sea->disable_row_level_security = true; // SugarEmailAddress doesn't roll with security $sea->retrieve($uuid); return $sea; }
/** * @group bug42279 */ public function testEmailAddressInFetchedRow() { $sea = new SugarEmailAddress(); // this will populate contact->email1 $sea->populateLegacyFields($this->contact); $email1 = $this->contact->email1; // this should set fetched_row['email1'] to contatc->email1 $sea->handleLegacyRetrieve($this->contact); $this->assertEquals($email1, $this->contact->fetched_row['email1']); }
function save($id = '', $module = '', $new_addrs = array(), $primary = '', $replyTo = '', $invalid = '', $optOut = '', $in_workflow = false) { if (func_num_args() > 1) { parent::save($id, $module, $new_addrs, $primary, $replyTo, $invalid, $optOut, $in_workflow); } else { SugarBean::save($id); } }
/** * @see parent::get_list_view_data() */ public function get_list_view_data() { global $system_config, $current_user; $temp_array = $this->get_list_view_array(); $temp_array['EMAIL1'] = $this->emailAddress->getPrimaryAddress($this); $this->email1 = $temp_array['EMAIL1']; $temp_array['EMAIL1_LINK'] = $current_user->getEmailLink('email1', $this, '', '', 'ListView'); return $temp_array; }
/** * @see parent::get_list_view_data() * * @return array */ public function get_list_view_data() { global $system_config, $current_user; $this->_create_proper_name_field(); $temp_array = $this->get_list_view_array(); $temp_array['NAME'] = $this->name; $temp_array["ENCODED_NAME"] = $this->full_name; $temp_array["FULL_NAME"] = $this->full_name; $temp_array['EMAIL1'] = $this->emailAddress->getPrimaryAddress($this); $this->email1 = $temp_array['EMAIL1']; $temp_array['EMAIL1_LINK'] = $current_user->getEmailLink('email1', $this, '', '', 'ListView'); return $temp_array; }
/** * Returns itself when evaluating. */ function evaluate() { $emailStr = $this->getParameters()->evaluate(); if ($emailStr == "") { return AbstractExpression::$TRUE; } $lastChar = $emailStr[strlen($emailStr) - 1]; if (!preg_match('/[^\\.]/i', $lastChar)) { return AbstractExpression::$FALSE; } // validate it $emailArr = preg_split('/[,;]/', $emailStr); for ($i = 0; $i < sizeof($emailArr); $i++) { $emailAddress = trim($emailArr[$i]); if ($emailAddress != '' && !SugarEmailAddress::isValidEmail($emailAddress)) { return AbstractExpression::$FALSE; } } return AbstractExpression::$TRUE; }
/** * This should be called when the bean is saved from the API. * Most fields can just use default, which calls the field's * individual ->save() function instead. * * @param SugarBean $bean the bean performing the save * @param array $params an array of parameters relevant to the save, which will be an array passed up to the API * @param string $field The name of the field to save (the vardef name, not the form element name) * @param array $properties Any properties for this field */ public function apiSave(SugarBean $bean, array $params, $field, $properties) { if (!is_array($params[$field])) { // Not an array, don't do anything. return; } if (!isset($bean->emailAddress)) { $bean->emailAddress = BeanFactory::getBean('EmailAddresses'); } if (empty($bean->emailAddress->addresses) && !isset($bean->emailAddress->hasFetched)) { $oldAddresses = $bean->emailAddress->getAddressesByGUID($bean->id, $bean->module_name); } else { $oldAddresses = $bean->emailAddress->addresses; } array_walk($params[$field], array($this, 'formatEmails')); $bean->emailAddress->addresses = array(); foreach ($params[$field] as $email) { if (empty($email['email_address'])) { // Can't save an empty email address continue; } // Search each one for a matching set, otherwise use the defaults $mergeAddr = array('primary_address' => false, 'invalid_email' => false, 'opt_out' => false); foreach ($oldAddresses as $address) { if (strtolower($address['email_address']) == strtolower($email['email_address'])) { $mergeAddr = $address; break; } } $email = array_merge($mergeAddr, $email); if (!SugarEmailAddress::isValidEmail($email['email_address'])) { require_once 'include/api/SugarApiException.php'; throw new SugarApiExceptionInvalidParameter("{$email['email_address']} is an invalid email address"); } $bean->emailAddress->addAddress($email['email_address'], $email['primary_address'], false, $email['invalid_email'], $email['opt_out']); } $bean->emailAddress->save($bean->id, $bean->module_dir, $params[$field]); // Here is a hack for SugarEmailAddress.php so it doesn't attempt a legacy save $bean->emailAddress->dontLegacySave = true; $bean->emailAddress->populateLegacyFields($bean); }
function handleSave($prefix, $redirect = true, $useRequired = false) { require_once 'include/formbase.php'; $focus = new xVendor(); if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) { return null; } $focus = populateFromPost($prefix, $focus); if (isset($GLOBALS['check_notify'])) { $check_notify = $GLOBALS['check_notify']; } else { $check_notify = FALSE; } if (empty($_POST['record']) && empty($_POST['dup_checked'])) { $duplicatexVendors = $this->checkForDuplicates($prefix); if (isset($duplicatexVendors)) { $location = 'module=xVendors&action=ShowDuplicates'; $get = ''; // Bug 25311 - Add special handling for when the form specifies many-to-many relationships if (isset($_POST['relate_to']) && !empty($_POST['relate_to'])) { $get .= '&xVendorsrelate_to=' . $_POST['relate_to']; } if (isset($_POST['relate_id']) && !empty($_POST['relate_id'])) { $get .= '&xVendorsrelate_id=' . $_POST['relate_id']; } //add all of the post fields to redirect get string foreach ($focus->column_fields as $field) { if (!empty($focus->{$field}) && !is_object($focus->{$field})) { $get .= "&xVendors{$field}=" . urlencode($focus->{$field}); } } foreach ($focus->additional_column_fields as $field) { if (!empty($focus->{$field})) { $get .= "&xVendors{$field}=" . urlencode($focus->{$field}); } } if ($focus->hasCustomFields()) { foreach ($focus->field_defs as $name => $field) { if (!empty($field['source']) && $field['source'] == 'custom_fields') { $get .= "&xVendors{$name}=" . urlencode($focus->{$name}); } } } $emailAddress = new SugarEmailAddress(); $get .= $emailAddress->getFormBaseURL($focus); //create list of suspected duplicate xvendor id's in redirect get string $i = 0; foreach ($duplicatexVendors as $xvendor) { $get .= "&duplicate[{$i}]=" . $xvendor['id']; $i++; } //add return_module, return_action, and return_id to redirect get string $get .= '&return_module='; if (!empty($_POST['return_module'])) { $get .= $_POST['return_module']; } else { $get .= 'xVendors'; } $get .= '&return_action='; if (!empty($_POST['return_action'])) { $get .= $_POST['return_action']; } //else $get .= 'DetailView'; if (!empty($_POST['return_id'])) { $get .= '&return_id=' . $_POST['return_id']; } if (!empty($_POST['popup'])) { $get .= '&popup=' . $_POST['popup']; } if (!empty($_POST['create'])) { $get .= '&create=' . $_POST['create']; } $_SESSION['SHOW_DUPLICATES'] = $get; //now redirect the post to modules/xVendors/ShowDuplicates.php if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') { ob_clean(); $json = getJSONobj(); echo $json->encode(array('status' => 'dupe', 'get' => $location)); } else { if (!empty($_REQUEST['ajax_load'])) { echo "<script>SUGAR.ajaxUI.loadContent('index.php?{$location}');</script>"; } else { if (!empty($_POST['to_pdf'])) { $location .= '&to_pdf=' . $_POST['to_pdf']; } header("Location: index.php?{$location}"); } } return null; } } if (!$focus->ACLAccess('Save')) { ACLController::displayNoAccess(true); sugar_cleanup(true); } $focus->save($check_notify); $return_id = $focus->id; $GLOBALS['log']->debug("Saved record with id of " . $return_id); if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') { $json = getJSONobj(); echo $json->encode(array('status' => 'success', 'get' => '')); $trackerManager = TrackerManager::getInstance(); $timeStamp = TimeDate::getInstance()->nowDb(); if ($monitor = $trackerManager->getMonitor('tracker')) { $monitor->setValue('action', 'detailview'); $monitor->setValue('user_id', $GLOBALS['current_user']->id); $monitor->setValue('module_name', 'xVendors'); $monitor->setValue('date_modified', $timeStamp); $monitor->setValue('visible', 1); if (!empty($this->bean->id)) { $monitor->setValue('item_id', $return_id); $monitor->setValue('item_summary', $focus->get_summary_text()); } $trackerManager->saveMonitor($monitor, true, true); } return null; } if (isset($_POST['popup']) && $_POST['popup'] == 'true') { $get = '&module='; if (!empty($_POST['return_module'])) { $get .= $_POST['return_module']; } else { $get .= 'xVendors'; } $get .= '&action='; if (!empty($_POST['return_action'])) { $get .= $_POST['return_action']; } else { $get .= 'Popup'; } if (!empty($_POST['return_id'])) { $get .= '&return_id=' . $_POST['return_id']; } if (!empty($_POST['popup'])) { $get .= '&popup=' . $_POST['popup']; } if (!empty($_POST['create'])) { $get .= '&create=' . $_POST['create']; } if (!empty($_POST['to_pdf'])) { $get .= '&to_pdf=' . $_POST['to_pdf']; } $get .= '&name=' . $focus->name; $get .= '&query=true'; header("Location: index.php?{$get}"); return; } if ($redirect) { handleRedirect($return_id, 'xVendors'); } else { return $focus; } }
function handleSave($prefix, $redirect = true, $useRequired = false) { global $theme, $current_user; require_once 'include/formbase.php'; global $timedate; $focus = new Contact(); if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) { return null; } if (!empty($_POST[$prefix . 'new_reports_to_id'])) { $focus->retrieve($_POST[$prefix . 'new_reports_to_id']); $focus->reports_to_id = $_POST[$prefix . 'record']; } else { $focus = populateFromPost($prefix, $focus); if (!empty($focus->portal_password) && $focus->portal_password != $_POST[$prefix . 'old_portal_password']) { $focus->portal_password = md5($focus->portal_password); } if (!isset($_POST[$prefix . 'email_opt_out'])) { $focus->email_opt_out = 0; } if (!isset($_POST[$prefix . 'do_not_call'])) { $focus->do_not_call = 0; } } if (!$focus->ACLAccess('Save')) { ACLController::displayNoAccess(true); sugar_cleanup(true); } if ($_REQUEST['action'] != 'BusinessCard' && $_REQUEST['action'] != 'ConvertLead' && $_REQUEST['action'] != 'ConvertProspect') { if (!empty($_POST[$prefix . 'sync_contact'])) { $focus->contacts_users_id = $current_user->id; } else { if (!isset($focus->users)) { $focus->load_relationship('user_sync'); } $focus->contacts_users_id = null; $focus->user_sync->delete($focus->id, $current_user->id); } } if (isset($GLOBALS['check_notify'])) { $check_notify = $GLOBALS['check_notify']; } else { $check_notify = FALSE; } if (empty($_POST['dup_checked'])) { $duplicateContacts = $this->checkForDuplicates($prefix); if (isset($duplicateContacts)) { $location = 'module=Contacts&action=ShowDuplicates'; $get = ''; if (isset($_POST['inbound_email_id']) && !empty($_POST['inbound_email_id'])) { $get .= '&inbound_email_id=' . $_POST['inbound_email_id']; } // Bug 25311 - Add special handling for when the form specifies many-to-many relationships if (isset($_POST['relate_to']) && !empty($_POST['relate_to'])) { $get .= '&Contactsrelate_to=' . $_POST['relate_to']; } if (isset($_POST['relate_id']) && !empty($_POST['relate_id'])) { $get .= '&Contactsrelate_id=' . $_POST['relate_id']; } //add all of the post fields to redirect get string foreach ($focus->column_fields as $field) { if (!empty($focus->{$field}) && !is_object($focus->{$field})) { $get .= "&Contacts{$field}=" . urlencode($focus->{$field}); } } foreach ($focus->additional_column_fields as $field) { if (!empty($focus->{$field})) { $get .= "&Contacts{$field}=" . urlencode($focus->{$field}); } } if ($focus->hasCustomFields()) { foreach ($focus->field_defs as $name => $field) { if (!empty($field['source']) && $field['source'] == 'custom_fields') { $get .= "&Contacts{$name}=" . urlencode($focus->{$name}); } } } $emailAddress = new SugarEmailAddress(); $get .= $emailAddress->getFormBaseURL($focus); //create list of suspected duplicate contact id's in redirect get string $i = 0; foreach ($duplicateContacts as $contact) { $get .= "&duplicate[{$i}]=" . $contact['id']; $i++; } //add return_module, return_action, and return_id to redirect get string $get .= "&return_module="; if (!empty($_POST['return_module'])) { $get .= $_POST['return_module']; } else { $get .= "Contacts"; } $get .= "&return_action="; if (!empty($_POST['return_action'])) { $get .= $_POST['return_action']; } //else $get .= "DetailView"; if (!empty($_POST['return_id'])) { $get .= "&return_id=" . $_POST['return_id']; } if (!empty($_POST['popup'])) { $get .= '&popup=' . $_POST['popup']; } if (!empty($_POST['create'])) { $get .= '&create=' . $_POST['create']; } // for InboundEmail flow if (!empty($_POST['start'])) { $get .= '&start=' . $_POST['start']; } $_SESSION['SHOW_DUPLICATES'] = $get; //now redirect the post to modules/Contacts/ShowDuplicates.php if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') { ob_clean(); $json = getJSONobj(); echo $json->encode(array('status' => 'dupe', 'get' => $location)); } else { if (!empty($_REQUEST['ajax_load'])) { echo "<script>SUGAR.ajaxUI.loadContent('index.php?{$location}');</script>"; } else { if (!empty($_POST['to_pdf'])) { $location .= '&to_pdf=' . $_POST['to_pdf']; } header("Location: index.php?{$location}"); } } return null; } } global $current_user; if (is_admin($current_user)) { if (!isset($_POST[$prefix . 'portal_active'])) { $focus->portal_active = '0'; } //if no password is set set account to inactive for portal if (empty($_POST[$prefix . 'portal_name'])) { $focus->portal_active = '0'; } } /////////////////////////////////////////////////////////////////////////////// //// INBOUND EMAIL HANDLING /////////////////////////////////////////////////////////////////////////////// if (isset($_REQUEST['inbound_email_id']) && !empty($_REQUEST['inbound_email_id'])) { // fake this case like it's already saved. $focus->save($check_notify); $email = new Email(); $email->retrieve($_REQUEST['inbound_email_id']); $email->parent_type = 'Contacts'; $email->parent_id = $focus->id; $email->assigned_user_id = $current_user->id; $email->status = 'read'; $email->save(); $email->load_relationship('contacts'); $email->contacts->add($focus->id); header("Location: index.php?&module=Emails&action=EditView&type=out&inbound_email_id=" . $_REQUEST['inbound_email_id'] . "&parent_id=" . $email->parent_id . "&parent_type=" . $email->parent_type . '&start=' . $_REQUEST['start'] . '&assigned_user_id=' . $current_user->id); exit; } //// END INBOUND EMAIL HANDLING /////////////////////////////////////////////////////////////////////////////// $focus->save($check_notify); $return_id = $focus->id; $GLOBALS['log']->debug("Saved record with id of " . $return_id); if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') { $json = getJSONobj(); echo $json->encode(array('status' => 'success', 'get' => '')); $trackerManager = TrackerManager::getInstance(); $timeStamp = TimeDate::getInstance()->nowDb(); if ($monitor = $trackerManager->getMonitor('tracker')) { $monitor->setValue('action', 'detailview'); $monitor->setValue('user_id', $GLOBALS['current_user']->id); $monitor->setValue('module_name', 'Contacts'); $monitor->setValue('date_modified', $timeStamp); $monitor->setValue('visible', 1); if (!empty($this->bean->id)) { $monitor->setValue('item_id', $return_id); $monitor->setValue('item_summary', $focus->get_summary_text()); } $trackerManager->saveMonitor($monitor, true, true); } return null; } if (isset($_POST['popup']) && $_POST['popup'] == 'true') { $get = '&module='; if (!empty($_POST['return_module'])) { $get .= $_POST['return_module']; } else { $get .= 'Contacts'; } $get .= '&action='; if (!empty($_POST['return_action'])) { $get .= $_POST['return_action']; } else { $get .= 'Popup'; } if (!empty($_POST['return_id'])) { $get .= '&return_id=' . $_POST['return_id']; } if (!empty($_POST['popup'])) { $get .= '&popup=' . $_POST['popup']; } if (!empty($_POST['create'])) { $get .= '&create=' . $_POST['create']; } if (!empty($_POST['to_pdf'])) { $get .= '&to_pdf=' . $_POST['to_pdf']; } $get .= '&first_name=' . urlencode($focus->first_name); $get .= '&last_name=' . urlencode($focus->last_name); $get .= '&query=true'; header("Location: index.php?{$get}"); return; } if ($redirect) { $this->handleRedirect($return_id); } else { return $focus; } }
/** * Called when saving a new email and adds the case update to the case. * @param $bean * @param $event * @param $arguments */ public function saveEmailUpdate($bean, $event, $arguments) { global $mod_strings; if ($bean->intent != "createcase" || $bean->parent_type != "Cases") { $GLOBALS['log']->warn("CaseUpdatesHook: saveEmailUpdate: Not a create case or wrong parent type"); return; } if (!$bean->parent_id) { $GLOBALS['log']->warn("CaseUpdatesHook: saveEmailUpdate No parent id"); return; } if ($bean->cases) { $GLOBALS['log']->warn("CaseUpdatesHook: saveEmailUpdate cases already set"); return; } if ($bean->fetched_row['parent_id']) { //Will have been processed already return; } $contact = BeanFactory::getBean("Contact"); $ea = new SugarEmailAddress(); $beans = $ea->getBeansByEmailAddress($bean->from_addr); $contact_id = null; foreach ($beans as $emailBean) { if ($emailBean->module_name == "Contacts") { $contact_id = $emailBean->id; $this->linkAccountAndCase($bean->parent_id, $emailBean->account_id); } } $case_update = new AOP_Case_Updates(); $case_update->name = $bean->name; $case_update->contact_id = $contact_id; $updateText = $this->unquoteEmail($bean->description_html ? $bean->description_html : $bean->description); $case_update->description = $updateText; $case_update->internal = false; $case_update->case_id = $bean->parent_id; $case_update->save(); }
/** * Sends Email for Email 2.0 */ function email2Send($request) { global $mod_strings; global $app_strings; global $current_user; global $sugar_config; global $locale; global $timedate; global $beanList; global $beanFiles; $OBCharset = $locale->getPrecedentPreference('default_email_charset'); /********************************************************************** * Sugar Email PREP */ /* preset GUID */ $orignialId = ""; if (!empty($this->id)) { $orignialId = $this->id; } // if if (empty($this->id)) { $this->id = create_guid(); $this->new_with_id = true; } /* satisfy basic HTML email requirements */ $this->name = $request['sendSubject']; $this->description_html = '<html><body>' . $request['sendDescription'] . '</body></html>'; /********************************************************************** * PHPMAILER PREP */ $mail = new SugarPHPMailer(); $mail = $this->setMailer($mail, '', $_REQUEST['fromAccount']); if (empty($mail->Host) && !$this->isDraftEmail($request)) { $this->status = 'send_error'; if ($mail->oe->type == 'system') { echo $app_strings['LBL_EMAIL_ERROR_PREPEND'] . $app_strings['LBL_EMAIL_INVALID_SYSTEM_OUTBOUND']; } else { echo $app_strings['LBL_EMAIL_ERROR_PREPEND'] . $app_strings['LBL_EMAIL_INVALID_PERSONAL_OUTBOUND']; } return false; } $subject = $this->name; $mail->Subject = from_html($this->name); // work-around legacy code in SugarPHPMailer if ($_REQUEST['setEditor'] == 1) { $_REQUEST['description_html'] = $_REQUEST['sendDescription']; $this->description_html = $_REQUEST['description_html']; } else { $this->description_html = ''; $this->description = $_REQUEST['sendDescription']; } // end work-around if ($this->isDraftEmail($request)) { if ($this->type != 'draft' && $this->status != 'draft') { $this->id = create_guid(); $this->new_with_id = true; $this->date_entered = ""; } // if $q1 = "update emails_email_addr_rel set deleted = 1 WHERE email_id = '{$this->id}'"; $r1 = $this->db->query($q1); } // if if (isset($request['saveDraft'])) { $this->type = 'draft'; $this->status = 'draft'; $forceSave = true; } else { /* Apply Email Templates */ // do not parse email templates if the email is being saved as draft.... $toAddresses = $this->email2ParseAddresses($_REQUEST['sendTo']); $sea = new SugarEmailAddress(); $object_arr = array(); if (isset($_REQUEST['parent_type']) && !empty($_REQUEST['parent_type']) && isset($_REQUEST['parent_id']) && !empty($_REQUEST['parent_id']) && ($_REQUEST['parent_type'] == 'Accounts' || $_REQUEST['parent_type'] == 'Contacts' || $_REQUEST['parent_type'] == 'Leads' || $_REQUEST['parent_type'] == 'Users' || $_REQUEST['parent_type'] == 'Prospects')) { if (isset($beanList[$_REQUEST['parent_type']]) && !empty($beanList[$_REQUEST['parent_type']])) { $className = $beanList[$_REQUEST['parent_type']]; if (isset($beanFiles[$className]) && !empty($beanFiles[$className])) { if (!class_exists($className)) { require_once $beanFiles[$className]; } $bean = new $className(); $bean->retrieve($_REQUEST['parent_id']); $object_arr[$bean->module_dir] = $bean->id; } // if } // if } foreach ($toAddresses as $addrMeta) { $addr = $addrMeta['email']; $beans = $sea->getBeansByEmailAddress($addr); foreach ($beans as $bean) { if (!isset($object_arr[$bean->module_dir])) { $object_arr[$bean->module_dir] = $bean->id; } } } /* template parsing */ if (empty($object_arr)) { $object_arr = array('Contacts' => '123'); } $object_arr['Users'] = $current_user->id; $this->description_html = EmailTemplate::parse_template($this->description_html, $object_arr); $this->name = EmailTemplate::parse_template($this->name, $object_arr); $this->description = EmailTemplate::parse_template($this->description, $object_arr); $this->description = html_entity_decode($this->description, ENT_COMPAT, 'UTF-8'); if ($this->type != 'draft' && $this->status != 'draft') { $this->id = create_guid(); $this->date_entered = ""; $this->new_with_id = true; $this->type = 'out'; $this->status = 'sent'; } } if (isset($_REQUEST['parent_type']) && empty($_REQUEST['parent_type']) && isset($_REQUEST['parent_id']) && empty($_REQUEST['parent_id'])) { $this->parent_id = ""; $this->parent_type = ""; } // if $mail->Subject = $this->name; $mail = $this->handleBody($mail); $mail->Subject = $this->name; $this->description_html = from_html($this->description_html); $this->description_html = $this->decodeDuringSend($this->description_html); $this->description = $this->decodeDuringSend($this->description); /* from account */ $replyToAddress = $current_user->emailAddress->getReplyToAddress($current_user); $replyToName = ""; if (empty($request['fromAccount'])) { $defaults = $current_user->getPreferredEmail(); $mail->From = $defaults['email']; $mail->FromName = $defaults['name']; $replyToName = $mail->FromName; //$replyToAddress = $current_user->emailAddress->getReplyToAddress($current_user); } else { // passed -> user -> system default $ie = new InboundEmail(); $ie->retrieve($request['fromAccount']); $storedOptions = unserialize(base64_decode($ie->stored_options)); $fromName = ""; $fromAddress = ""; $replyToName = ""; //$replyToAddress = ""; if (!empty($storedOptions)) { $fromAddress = $storedOptions['from_addr']; $fromName = from_html($storedOptions['from_name']); $replyToAddress = isset($storedOptions['reply_to_addr']) ? $storedOptions['reply_to_addr'] : ""; $replyToName = isset($storedOptions['reply_to_name']) ? from_html($storedOptions['reply_to_name']) : ""; } // if $defaults = $current_user->getPreferredEmail(); // Personal Account doesn't have reply To Name and Reply To Address. So add those columns on UI // After adding remove below code // code to remove if ($ie->is_personal) { if (empty($replyToAddress)) { $replyToAddress = $current_user->emailAddress->getReplyToAddress($current_user); } // if if (empty($replyToName)) { $replyToName = $defaults['name']; } // if //Personal accounts can have a reply_address, which should //overwrite the users set default. if (!empty($storedOptions['reply_to_addr'])) { $replyToAddress = $storedOptions['reply_to_addr']; } } // end of code to remove $mail->From = !empty($fromAddress) ? $fromAddress : $defaults['email']; $mail->FromName = !empty($fromName) ? $fromName : $defaults['name']; $replyToName = !empty($replyToName) ? $replyToName : $mail->FromName; } $mail->Sender = $mail->From; /* set Return-Path field in header to reduce spam score in emails sent via Sugar's Email module */ if (!empty($replyToAddress)) { $mail->AddReplyTo($replyToAddress, $locale->translateCharsetMIME(trim($replyToName), 'UTF-8', $OBCharset)); } else { $mail->AddReplyTo($mail->From, $locale->translateCharsetMIME(trim($mail->FromName), 'UTF-8', $OBCharset)); } // else $emailAddressCollection = array(); // used in linking to beans below // handle to/cc/bcc foreach ($this->email2ParseAddresses($request['sendTo']) as $addr_arr) { if (empty($addr_arr['email'])) { continue; } if (empty($addr_arr['display'])) { $mail->AddAddress($addr_arr['email'], ""); } else { $mail->AddAddress($addr_arr['email'], $locale->translateCharsetMIME(trim($addr_arr['display']), 'UTF-8', $OBCharset)); } $emailAddressCollection[] = $addr_arr['email']; } foreach ($this->email2ParseAddresses($request['sendCc']) as $addr_arr) { if (empty($addr_arr['email'])) { continue; } if (empty($addr_arr['display'])) { $mail->AddCC($addr_arr['email'], ""); } else { $mail->AddCC($addr_arr['email'], $locale->translateCharsetMIME(trim($addr_arr['display']), 'UTF-8', $OBCharset)); } $emailAddressCollection[] = $addr_arr['email']; } foreach ($this->email2ParseAddresses($request['sendBcc']) as $addr_arr) { if (empty($addr_arr['email'])) { continue; } if (empty($addr_arr['display'])) { $mail->AddBCC($addr_arr['email'], ""); } else { $mail->AddBCC($addr_arr['email'], $locale->translateCharsetMIME(trim($addr_arr['display']), 'UTF-8', $OBCharset)); } $emailAddressCollection[] = $addr_arr['email']; } /* parse remove attachments array */ $removeAttachments = array(); if (!empty($request['templateAttachmentsRemove'])) { $exRemove = explode("::", $request['templateAttachmentsRemove']); foreach ($exRemove as $file) { $removeAttachments = substr($file, 0, 36); } } /* handle attachments */ if (!empty($request['attachments'])) { $exAttachments = explode("::", $request['attachments']); foreach ($exAttachments as $file) { $file = trim(from_html($file)); $file = str_replace("\\", "", $file); if (!empty($file)) { //$fileLocation = $this->et->userCacheDir."/{$file}"; $fileGUID = substr($file, 0, 36); $fileLocation = $this->et->userCacheDir . "/{$fileGUID}"; $filename = substr($file, 36, strlen($file)); // strip GUID for PHPMailer class to name outbound file $mail->AddAttachment($fileLocation, $filename, 'base64', $this->email2GetMime($fileLocation)); //$mail->AddAttachment($fileLocation, $filename, 'base64'); // only save attachments if we're archiving or drafting if ($this->type == 'draft' && !empty($this->id) || isset($request['saveToSugar']) && $request['saveToSugar'] == 1) { $note = new Note(); $note->id = create_guid(); $note->new_with_id = true; // duplicating the note with files $note->parent_id = $this->id; $note->parent_type = $this->module_dir; $note->name = $filename; $note->filename = $filename; $noteFile = "{$sugar_config['upload_dir']}{$note->id}"; $note->file_mime_type = $this->email2GetMime($fileLocation); if (!copy($fileLocation, $noteFile)) { $GLOBALS['log']->debug("EMAIL 2.0: could not copy attachment file to cache/upload [ {$fileLocation} ]"); } $note->save(); } } } } /* handle sugar documents */ if (!empty($request['documents'])) { $exDocs = explode("::", $request['documents']); foreach ($exDocs as $docId) { $docId = trim($docId); if (!empty($docId)) { $doc = new Document(); $docRev = new DocumentRevision(); $doc->retrieve($docId); $docRev->retrieve($doc->document_revision_id); $filename = $docRev->filename; $fileLocation = "{$sugar_config['upload_dir']}{$docRev->id}"; $mime_type = $docRev->file_mime_type; $mail->AddAttachment($fileLocation, $locale->translateCharsetMIME(trim($filename), 'UTF-8', $OBCharset), 'base64', $mime_type); // only save attachments if we're archiving or drafting if ($this->type == 'draft' && !empty($this->id) || isset($request['saveToSugar']) && $request['saveToSugar'] == 1) { $note = new Note(); $note->id = create_guid(); $note->new_with_id = true; // duplicating the note with files $note->parent_id = $this->id; $note->parent_type = $this->module_dir; $note->name = $filename; $note->filename = $filename; $note->file_mime_type = $mime_type; $noteFile = "{$sugar_config['upload_dir']}{$note->id}"; if (!copy($fileLocation, $noteFile)) { $GLOBALS['log']->debug("EMAIL 2.0: could not copy SugarDocument revision file to {$sugar_config['upload_dir']} [ {$fileLocation} ]"); } $note->save(); } } } } /* handle template attachments */ if (!empty($request['templateAttachments'])) { $exNotes = explode("::", $request['templateAttachments']); foreach ($exNotes as $noteId) { $noteId = trim($noteId); if (!empty($noteId)) { $note = new Note(); $note->retrieve($noteId); if (!empty($note->id)) { $filename = $note->filename; $fileLocation = "{$sugar_config['upload_dir']}{$note->id}"; $mime_type = $note->file_mime_type; if (!$note->embed_flag) { $mail->AddAttachment($fileLocation, $filename, 'base64', $mime_type); // only save attachments if we're archiving or drafting if ($this->type == 'draft' && !empty($this->id) || isset($request['saveToSugar']) && $request['saveToSugar'] == 1) { if ($note->parent_id != $this->id) { $this->saveTempNoteAttachments($filename, $fileLocation, $mime_type); } } // if } // if } else { //$fileLocation = $this->et->userCacheDir."/{$file}"; $fileGUID = substr($noteId, 0, 36); $fileLocation = $this->et->userCacheDir . "/{$fileGUID}"; //$fileLocation = $this->et->userCacheDir."/{$noteId}"; $filename = substr($noteId, 36, strlen($noteId)); // strip GUID for PHPMailer class to name outbound file $mail->AddAttachment($fileLocation, $locale->translateCharsetMIME(trim($filename), 'UTF-8', $OBCharset), 'base64', $this->email2GetMime($fileLocation)); //If we are saving an email we were going to forward we need to save the attachments as well. if ($this->type == 'draft' && !empty($this->id) || isset($request['saveToSugar']) && $request['saveToSugar'] == 1) { $mimeType = $this->email2GetMime($fileLocation); $this->saveTempNoteAttachments($filename, $fileLocation, $mimeType); } // if } } } } /********************************************************************** * Final Touches */ /* save email to sugar? */ $forceSave = false; if ($this->type == 'draft' && !isset($request['saveDraft'])) { // sending a draft email $this->type = 'out'; $this->status = 'sent'; $forceSave = true; } elseif (isset($request['saveDraft'])) { $this->type = 'draft'; $this->status = 'draft'; $forceSave = true; } /********************************************************************** * SEND EMAIL (finally!) */ $mailSent = false; if ($this->type != 'draft') { $mail->prepForOutbound(); $mail->Body = $this->decodeDuringSend($mail->Body); $mail->AltBody = $this->decodeDuringSend($mail->AltBody); if (!$mail->Send()) { $this->status = 'send_error'; ob_clean(); echo $app_strings['LBL_EMAIL_ERROR_PREPEND'] . $mail->ErrorInfo; return false; } } if (!(empty($orignialId) || isset($request['saveDraft']) || $this->type == 'draft' && $this->status == 'draft') && ($_REQUEST['composeType'] == 'reply' || $_REQUEST['composeType'] == 'replyAll' || $_REQUEST['composeType'] == 'replyCase') && $orignialId != $this->id) { $originalEmail = new Email(); $originalEmail->retrieve($orignialId); $originalEmail->reply_to_status = 1; $originalEmail->save(); $this->reply_to_status = 0; } // if if ($_REQUEST['composeType'] == 'reply' || $_REQUEST['composeType'] == 'replyCase') { if (isset($_REQUEST['ieId']) && isset($_REQUEST['mbox'])) { $emailFromIe = new InboundEmail(); $emailFromIe->retrieve($_REQUEST['ieId']); $emailFromIe->mailbox = $_REQUEST['mbox']; if (isset($emailFromIe->id) && $emailFromIe->is_personal) { if ($emailFromIe->isPop3Protocol()) { $emailFromIe->mark_answered($this->uid, 'pop3'); } elseif ($emailFromIe->connectMailserver() == 'true') { $emailFromIe->markEmails($this->uid, 'answered'); $emailFromIe->mark_answered($this->uid); } } } } if ($forceSave || $this->type == 'draft' || isset($request['saveToSugar']) && $request['saveToSugar'] == 1) { // saving a draft OR saving a sent email $decodedFromName = mb_decode_mimeheader($mail->FromName); $this->from_addr = "{$decodedFromName} <{$mail->From}>"; $this->from_addr_name = $this->from_addr; $this->to_addrs = $_REQUEST['sendTo']; $this->to_addrs_names = $_REQUEST['sendTo']; $this->cc_addrs = $_REQUEST['sendCc']; $this->cc_addrs_names = $_REQUEST['sendCc']; $this->bcc_addrs = $_REQUEST['sendBcc']; $this->bcc_addrs_names = $_REQUEST['sendBcc']; $this->assigned_user_id = $current_user->id; $this->date_sent = $timedate->now(); /////////////////////////////////////////////////////////////////// //// LINK EMAIL TO SUGARBEANS BASED ON EMAIL ADDY if (isset($_REQUEST['parent_type']) && !empty($_REQUEST['parent_type']) && isset($_REQUEST['parent_id']) && !empty($_REQUEST['parent_id'])) { $this->parent_id = $_REQUEST['parent_id']; $this->parent_type = $_REQUEST['parent_type']; $q = "SELECT count(*) c FROM emails_beans WHERE email_id = '{$this->id}' AND bean_id = '{$_REQUEST['parent_id']}' AND bean_module = '{$_REQUEST['parent_type']}'"; $r = $this->db->query($q); $a = $this->db->fetchByAssoc($r); if ($a['c'] <= 0) { if (isset($beanList[$_REQUEST['parent_type']]) && !empty($beanList[$_REQUEST['parent_type']])) { $className = $beanList[$_REQUEST['parent_type']]; if (isset($beanFiles[$className]) && !empty($beanFiles[$className])) { if (!class_exists($className)) { require_once $beanFiles[$className]; } $bean = new $className(); $bean->retrieve($_REQUEST['parent_id']); if ($bean->load_relationship('emails')) { $bean->emails->add($this->id); } // if } // if } // if } // if } else { if (!class_exists('aCase')) { } else { $c = new aCase(); if ($caseId = InboundEmail::getCaseIdFromCaseNumber($mail->Subject, $c)) { $c->retrieve($caseId); $c->load_relationship('emails'); $c->emails->add($this->id); $this->parent_type = "Cases"; $this->parent_id = $caseId; } // if } } // else //// LINK EMAIL TO SUGARBEANS BASED ON EMAIL ADDY /////////////////////////////////////////////////////////////////// $this->save(); } if (!empty($request['fromAccount'])) { if (isset($ie->id) && !$ie->isPop3Protocol()) { $sentFolder = $ie->get_stored_options("sentFolder"); if (!empty($sentFolder)) { $data = $mail->CreateHeader() . "\r\n" . $mail->CreateBody() . "\r\n"; $ie->mailbox = $sentFolder; if ($ie->connectMailserver() == 'true') { $connectString = $ie->getConnectString($ie->getServiceString(), $ie->mailbox); $returnData = imap_append($ie->conn, $connectString, $data, "\\Seen"); if (!$returnData) { $GLOBALS['log']->debug("could not copy email to {$ie->mailbox} for {$ie->name}"); } // if } else { $GLOBALS['log']->debug("could not connect to mail serve for folder {$ie->mailbox} for {$ie->name}"); } // else } else { $GLOBALS['log']->debug("could not copy email to {$ie->mailbox} sent folder as its empty"); } // else } // if } // if return true; }
/** * Checks to see if the given bean is a duplicate based off the given indexes * * @param array $indexlist * @return bool true if this bean is a duplicate or false if it isn't */ public function isADuplicateRecord($indexlist) { // loop through var def indexes and compare with selected indexes foreach ($this->_getIndexVardefs() as $index) { // if we get an index not in the indexlist, loop if (!in_array($index['name'], $indexlist)) { continue; } // This handles the special case of duplicate email checking if ($index['name'] == 'special_idx_email1' || $index['name'] == 'special_idx_email2') { $emailAddress = new SugarEmailAddress(); $email = $index['fields'][0]; if ($emailAddress->getCountEmailAddressByBean($this->_focus->{$email}, $this->_focus, $index['name'] == 'special_idx_email1') > 0) { return true; } } else { $index_fields = array('deleted' => '0'); foreach ($index['fields'] as $field) { if ($field == 'deleted') { continue; } if (!in_array($field, $index_fields)) { if (strlen($this->_focus->{$field}) > 0) { $index_fields[$field] = $this->_focus->{$field}; } } } // if there are no valid fields in the index field list, loop if (count($index_fields) <= 1) { continue; } $newfocus = loadBean($this->_focus->module_dir); $result = $newfocus->retrieve_by_string_fields($index_fields, true); if (!is_null($result)) { return true; } } } return false; }
/** * Returns the templatized compose screen. Used by reply, forwards and draft status messages. * @param object email Email bean in focus */ function displayComposeEmail($email) { global $locale; global $current_user; $ea = new SugarEmailAddress(); if (!empty($email)) { $email->cids2Links(); $description = empty($email->description_html) ? $email->description : $email->description_html; } //Get the most complete address list availible for this email $addresses = array('toAddresses' => 'to', 'ccAddresses' => 'cc', 'bccAddresses' => 'bcc'); foreach ($addresses as $var => $type) { ${$var} = ""; foreach (array("{$type}_addrs_names", "{$type}addrs", "{$type}_addrs") as $emailVar) { if (!empty($email->{$emailVar})) { ${$var} = $email->{$emailVar}; break; } } } $ret = array(); $ret['type'] = $email->type; $ret['name'] = $email->name; $ret['description'] = $description; $ret['from'] = isset($_REQUEST['composeType']) && $_REQUEST['composeType'] == 'forward' ? "" : $email->from_addr; $ret['to'] = from_html($toAddresses); $ret['uid'] = $email->id; $ret['parent_name'] = $email->parent_name; $ret['parent_type'] = $email->parent_type; $ret['parent_id'] = $email->parent_id; if ($email->type == 'draft') { $ret['cc'] = from_html($ccAddresses); $ret['bcc'] = $bccAddresses; } // reply all if (isset($_REQUEST['composeType']) && $_REQUEST['composeType'] == 'replyAll') { $ret['cc'] = from_html($ccAddresses); $ret['bcc'] = $bccAddresses; $userEmails = array(); $userEmailsMeta = $ea->getAddressesByGUID($current_user->id, 'Users'); foreach ($userEmailsMeta as $emailMeta) { $userEmails[] = from_html(strtolower(trim($emailMeta['email_address']))); } $userEmails[] = from_html(strtolower(trim($email->from_addr))); $ret['cc'] = from_html($email->cc_addrs); $toAddresses = from_html($toAddresses); $to = str_replace($this->addressSeparators, "::", $toAddresses); $exTo = explode("::", $to); if (is_array($exTo)) { foreach ($exTo as $addr) { $addr = strtolower(trim($addr)); if (!in_array($addr, $userEmails)) { if (!empty($ret['cc'])) { $ret['cc'] = $ret['cc'] . ", "; } $ret['cc'] = $ret['cc'] . trim($addr); } } } elseif (!empty($exTo)) { $exTo = trim($exTo); if (!in_array($exTo, $userEmails)) { $ret['cc'] = $ret['cc'] . ", " . $exTo; } } } return $ret; }
function handleSave($prefix, $redirect = true, $useRequired = false, $do_save = true, $exist_lead = null) { require_once 'modules/Campaigns/utils.php'; require_once 'include/formbase.php'; if (empty($exist_lead)) { $focus = new Lead(); } else { $focus = $exist_lead; } if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) { return null; } $focus = populateFromPost($prefix, $focus); if (!$focus->ACLAccess('Save')) { ACLController::displayNoAccess(true); sugar_cleanup(true); } //Check for duplicate Leads if (empty($_POST['record']) && empty($_POST['dup_checked'])) { $duplicateLeads = $this->checkForDuplicates($prefix); if (isset($duplicateLeads)) { //Set the redirect location to call the ShowDuplicates action. This will map to view.showduplicates.php $location = 'module=Leads&action=ShowDuplicates'; $get = ''; if (isset($_POST['inbound_email_id']) && !empty($_POST['inbound_email_id'])) { $get .= '&inbound_email_id=' . $_POST['inbound_email_id']; } if (isset($_POST['relate_to']) && !empty($_POST['relate_to'])) { $get .= '&Leadsrelate_to=' . $_POST['relate_to']; } if (isset($_POST['relate_id']) && !empty($_POST['relate_id'])) { $get .= '&Leadsrelate_id=' . $_POST['relate_id']; } //add all of the post fields to redirect get string foreach ($focus->column_fields as $field) { if (!empty($focus->{$field}) && !is_object($focus->{$field})) { $get .= "&Leads{$field}=" . urlencode($focus->{$field}); } } foreach ($focus->additional_column_fields as $field) { if (!empty($focus->{$field})) { $get .= "&Leads{$field}=" . urlencode($focus->{$field}); } } if ($focus->hasCustomFields()) { foreach ($focus->field_defs as $name => $field) { if (!empty($field['source']) && $field['source'] == 'custom_fields') { $get .= "&Leads{$name}=" . urlencode($focus->{$name}); } } } $emailAddress = new SugarEmailAddress(); $get .= $emailAddress->getFormBaseURL($focus); //create list of suspected duplicate lead ids in redirect get string $i = 0; foreach ($duplicateLeads as $lead) { $get .= "&duplicate[{$i}]=" . $lead['id']; $i++; } //add return_module, return_action, and return_id to redirect get string $get .= "&return_module="; if (!empty($_POST['return_module'])) { $get .= $_POST['return_module']; } else { $get .= "Leads"; } $get .= "&return_action="; if (!empty($_POST['return_action'])) { $get .= $_POST['return_action']; } if (!empty($_POST['return_id'])) { $get .= "&return_id=" . $_POST['return_id']; } if (!empty($_POST['popup'])) { $get .= '&popup=' . $_POST['popup']; } if (!empty($_POST['create'])) { $get .= '&create=' . $_POST['create']; } // for InboundEmail flow if (!empty($_POST['start'])) { $get .= '&start=' . $_POST['start']; } $_SESSION['SHOW_DUPLICATES'] = $get; if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') { ob_clean(); $json = getJSONobj(); echo $json->encode(array('status' => 'dupe', 'get' => $location)); } else { if (!empty($_REQUEST['ajax_load'])) { echo "<script>SUGAR.ajaxUI.loadContent('index.php?{$location}');</script>"; } else { if (!empty($_POST['to_pdf'])) { $location .= '&to_pdf=' . $_POST['to_pdf']; } header("Location: index.php?{$location}"); } } return null; } } if (!isset($_POST[$prefix . 'email_opt_out'])) { $focus->email_opt_out = 0; } if (!isset($_POST[$prefix . 'do_not_call'])) { $focus->do_not_call = 0; } if ($do_save) { if (!empty($GLOBALS['check_notify'])) { $focus->save($GLOBALS['check_notify']); } else { $focus->save(FALSE); } } $return_id = $focus->id; if (isset($_POST[$prefix . 'prospect_id']) && !empty($_POST[$prefix . 'prospect_id'])) { $prospect = new Prospect(); $prospect->retrieve($_POST[$prefix . 'prospect_id']); $prospect->lead_id = $focus->id; // Set to keep email in target $prospect->in_workflow = true; $prospect->save(); //if prospect id exists, make sure we are coming from prospect detail if (strtolower($_POST['return_module']) == 'prospects' && strtolower($_POST['return_action']) == 'detailview') { //create campaing_log entry if (isset($focus->campaign_id) && $focus->campaign_id != null) { campaign_log_lead_entry($focus->campaign_id, $prospect, $focus, 'lead'); } } } /////////////////////////////////////////////////////////////////////////////// //// INBOUND EMAIL HANDLING /////////////////////////////////////////////////////////////////////////////// if (isset($_REQUEST['inbound_email_id']) && !empty($_REQUEST['inbound_email_id'])) { if (!isset($current_user)) { global $current_user; } // fake this case like it's already saved. $email = new Email(); $email->retrieve($_REQUEST['inbound_email_id']); $email->parent_type = 'Leads'; $email->parent_id = $focus->id; $email->assigned_user_id = $current_user->id; $email->status = 'read'; $email->save(); $email->load_relationship('leads'); $email->leads->add($focus->id); header("Location: index.php?&module=Emails&action=EditView&type=out&inbound_email_id=" . $_REQUEST['inbound_email_id'] . "&parent_id=" . $email->parent_id . "&parent_type=" . $email->parent_type . '&start=' . $_REQUEST['start']); exit; } //// END INBOUND EMAIL HANDLING /////////////////////////////////////////////////////////////////////////////// $GLOBALS['log']->debug("Saved record with id of " . $return_id); if ($redirect) { handleRedirect($return_id, 'Leads'); } else { return $focus; } }
} } foreach ($realtytemplates->additional_column_fields as $field) { if (!empty($_POST['RealtyTemplates' . $field])) { $input .= "<input type='hidden' name='{$field}' value='{$_POST['RealtyTemplates' . $field]}'>\n"; } } $input .= "<input type='hidden' name='record' value='{$_GET['record']}'>\n"; // Bug 25311 - Add special handling for when the form specifies many-to-many relationships if (!empty($_POST['RealtyTemplatesrelate_to'])) { $input .= "<input type='hidden' name='relate_to' value='{$_POST['RealtyTemplatesrelate_to']}'>\n"; } if (!empty($_POST['RealtyTemplatesrelate_id'])) { $input .= "<input type='hidden' name='relate_id' value='{$_POST['RealtyTemplatesrelate_id']}'>\n"; } $emailAddress = new SugarEmailAddress(); $input .= $emailAddress->getEmailAddressWidgetDuplicatesView($realtytemplates); $get = ''; if (!empty($_POST['return_module'])) { $xtpl->assign('RETURN_MODULE', $_POST['return_module']); } else { $get .= "RealtyTemplates"; } $get .= "&return_action="; if (!empty($_POST['return_action'])) { $xtpl->assign('RETURN_ACTION', $_POST['return_action']); } else { $get .= "DetailView"; } /////////////////////////////////////////////////////////////////////////////// //// INBOUND EMAIL WORKFLOW
$ie->email->status = 'read'; $ie->email->save(); $mod = strtolower($controller->module); $ie->email->load_relationship($mod); $ie->email->{$mod}->add($controller->bean->id); if ($controller->bean->load_relationship('emails')) { $controller->bean->emails->add($ie->email->id); } if ($controller->bean->module_dir == 'Cases') { if ($controller->bean->load_relationship('contacts')) { $emailAddressWithName = $ie->email->from_addr; if (!empty($ie->email->reply_to_addr)) { $emailAddressWithName = $ie->email->reply_to_addr; } // if $emailAddress = SugarEmailAddress::_cleanAddress($emailAddressWithName); $contactIds = $ie->email->emailAddress->getRelatedId($emailAddress, 'contacts'); if (!empty($contactIds)) { $controller->bean->contacts->add($contactIds); } // if } // if } // if echo $json->encode(array('id' => $ie->email->id)); } break; case "getImportForm": $ie->retrieve($_REQUEST['ieId']); // $ie->mailbox = $_REQUEST['mailbox'];
/** * Given an email address, mark it as invalid. * * @param $email_address */ function markEmailAddressInvalid($email_address) { if (empty($email_address)) { return; } $sea = new SugarEmailAddress(); $rs = $sea->retrieve_by_string_fields(array('email_address_caps' => trim(strtoupper($email_address)))); if ($rs != null) { $sea->AddUpdateEmailAddress($email_address, 1, 0, $rs->id); } }
public function setup() { global $current_user; $current_user = SugarTestUserUtilities::createAnonymousUser(); //for the purpose of this test, we need to create some records with fake campaign and prospect list data, //however we do need to create some targets for the prospect list //create campaign tracker $ct = new CampaignTracker(); $ct->tracker_name = 'Campaign Log Unit Test Tracker'; $ct->tracker_url = 'sugarcrm.com'; $ct->campaign_id = $this->campaign_id; $ct->save(); $this->campaign_tracker = $ct; //for each type, create an object and populate the campaignLog list foreach ($this->targetObjectArray as $type) { //skip campaign tracker if ($type == 'CampaignTracker') { continue; } //create the new bean $bean = new $type(); if ($type == 'Account') { $bean->name = 'CampLog Unit Test Account'; } else { $bean->first_name = 'CampaignLog'; $bean->last_name = 'Test ' . $type; } $type_obj = 'target_' . $type; $bean->save(); $this->{$type_obj} = $bean; //save email $sea = new SugarEmailAddress(); $id = $this->{$type_obj}->id; $module = $this->{$type_obj}->module_dir; $new_addrs = array(); $primary = ''; $replyTo = ''; $invalid = ''; $optOut = ''; $in_workflow = false; $_REQUEST[$module . '_email_widget_id'] = 0; $_REQUEST[$module . '0emailAddress0'] = $type . '*****@*****.**'; $_REQUEST[$module . 'emailAddressPrimaryFlag'] = '0emailAddress0'; $_REQUEST[$module . 'emailAddressVerifiedFlag0'] = 'true'; $_REQUEST[$module . 'emailAddressVerifiedValue0'] = '*****@*****.**'; $requestVariablesSet = array('0emailAddress0', 'emailAddressPrimaryFlag', 'emailAddressVerifiedFlag0', 'emailAddressVerifiedValue0'); $sea->save($id, $module, $new_addrs, $primary, $replyTo, $invalid, $optOut, $in_workflow); //unset email request values for next run foreach ($requestVariablesSet as $k) { unset($_REQUEST[$k]); } //now create the campaign log $cl = new CampaignLog(); $cl->campaign_id = $this->campaign_id; $cl->tracker_key = $ct->tracker_key; $cl->target_id = $bean->id; $cl->target_type = $bean->module_dir; $cl->activity_type = 'targeted'; //options are targeted (user was sent an email), link (user clicked on link), removed (user opted out) and viewed (viewed) $cl->activity_date = date('Y-m-d H:i:s'); $cl->related_id = 'somebogusemailid' . date('His'); // this means link will not really work, but we are not testing email $cl->related_type = 'Emails'; $cl->list_id = $this->prospect_list_id; $cl->marketing_id = $this->email_marketing_id; $cl->save(); } //keep last created campaign log bean to be used to call functions $this->campaign_log = $cl; }
} } foreach ($account->additional_column_fields as $field) { if (!empty($_POST['Accounts' . $field])) { $value = urldecode($_POST['Accounts' . $field]); $input .= "<input type='hidden' name='{$field}' value='{$value}'>\n"; } } // Bug 25311 - Add special handling for when the form specifies many-to-many relationships if (!empty($_POST['Contactsrelate_to'])) { $input .= "<input type='hidden' name='relate_to' value='{$_POST['Contactsrelate_to']}'>\n"; } if (!empty($_POST['Contactsrelate_id'])) { $input .= "<input type='hidden' name='relate_id' value='{$_POST['Contactsrelate_id']}'>\n"; } $emailAddress = new SugarEmailAddress(); $input .= $emailAddress->getEmailAddressWidgetDuplicatesView($account); $get = ''; if (!empty($_POST['return_module'])) { $xtpl->assign('RETURN_MODULE', $_POST['return_module']); } else { $get .= "Accounts"; } $get .= "&return_action="; if (!empty($_POST['return_action'])) { $xtpl->assign('RETURN_ACTION', $_POST['return_action']); } else { $get .= "DetailView"; } if (!empty($_POST['return_id'])) { $xtpl->assign('RETURN_ID', $_POST['return_id']);
$lead->load_relationship('campaigns'); $lead->campaigns->add($camplog->id); if (!empty($GLOBALS['check_notify'])) { $lead->save($GLOBALS['check_notify']); } else { $lead->save(FALSE); } } //in case there are forms out there still using email_opt_out if (isset($_POST['webtolead_email_opt_out']) || isset($_POST['email_opt_out'])) { if (isset($lead->email1) && !empty($lead->email1)) { $sea = new SugarEmailAddress(); $sea->AddUpdateEmailAddress($lead->email1, 0, 1); } if (isset($lead->email2) && !empty($lead->email2)) { $sea = new SugarEmailAddress(); $sea->AddUpdateEmailAddress($lead->email2, 0, 1); } } if (isset($_POST['redirect_url']) && !empty($_POST['redirect_url'])) { // Get the redirect url, and make sure the query string is not too long $redirect_url = $_POST['redirect_url']; $query_string = ''; $first_char = '&'; if (strpos($redirect_url, '?') === FALSE) { $first_char = '?'; } $first_iteration = true; $get_and_post = array_merge($_GET, $_POST); foreach ($get_and_post as $param => $value) { if ($param == 'redirect_url' || $param == 'submit') {
/** * Checks to see if the given bean is a duplicate based off the given indexes * * @param array $indexlist * @return bool true if this bean is a duplicate or false if it isn't */ public function isADuplicateRecord($indexlist) { // Bug #51264 : Importing updates to rows prevented by duplicates check if (!empty($this->_focus) && $this->_focus instanceof SugarBean && !empty($this->_focus->id)) { $_focus = clone $this->_focus; $_focus->id = null; $_focus->retrieve($this->_focus->id); if (!empty($_focus->id)) { return false; } unset($_focus); } //lets strip the indexes of the name field in the value and leave only the index name $origIndexList = $indexlist; $indexlist = array(); $fieldlist = array(); $customIndexlist = array(); foreach ($origIndexList as $iv) { if (empty($iv)) { continue; } $field_index_array = explode('::', $iv); if ($field_index_array[0] == 'customfield') { //this is a custom field, so place in custom array $customIndexlist[] = $field_index_array[1]; } else { //this is not a custom field, so place in index list $indexlist[] = $field_index_array[0]; if (isset($field_index_array[1])) { $fieldlist[] = $field_index_array[1]; } } } //if full_name is set, then manually search on the first and last name fields before iterating through rest of fields //this is a special handling of the name fields on people objects, the rest of the fields are checked individually if (in_array('full_name', $indexlist)) { $newfocus = loadBean($this->_focus->module_dir); $result = $newfocus->retrieve_by_string_fields(array('deleted' => '0', 'first_name' => $this->_focus->first_name, 'last_name' => $this->_focus->last_name), true); if (!is_null($result)) { //set dupe field to full_name and name fields $this->_dupedFields[] = 'full_name'; $this->_dupedFields[] = 'first_name'; $this->_dupedFields[] = 'last_name'; } } // loop through var def indexes and compare with selected indexes foreach ($this->_getIndexVardefs() as $index) { // if we get an index not in the indexlist, loop if (!in_array($index['name'], $indexlist)) { continue; } // This handles the special case of duplicate email checking if ($index['name'] == 'special_idx_email1' || $index['name'] == 'special_idx_email2') { $emailAddress = new SugarEmailAddress(); $email = $index['fields'][0]; if ($emailAddress->getCountEmailAddressByBean($this->_focus->{$email}, $this->_focus, $index['name'] == 'special_idx_email1') > 0) { foreach ($index['fields'] as $field) { if ($field != 'deleted') { $this->_dupedFields[] = $field; } } } } elseif (isset($index['dupeCheckFunction'])) { $functionName = substr_replace($index['dupeCheckFunction'], '', 0, 9); if (method_exists($this->_focus, $functionName) && $this->_focus->{$functionName}($index) === true) { return $this->_focus->{$functionName}($index); } } else { $index_fields = array('deleted' => '0'); //search only for the field we have selected foreach ($index['fields'] as $field) { if ($field == 'deleted' || !in_array($field, $fieldlist)) { continue; } if (!in_array($field, $index_fields)) { if (isset($this->_focus->{$field}) && strlen($this->_focus->{$field}) > 0) { $index_fields[$field] = $this->_focus->{$field}; } } } // if there are no valid fields in the index field list, loop if (count($index_fields) <= 1) { continue; } $newfocus = loadBean($this->_focus->module_dir); $result = $newfocus->retrieve_by_string_fields($index_fields, true); if (!is_null($result)) { //remove deleted as a duped field unset($index_fields['deleted']); //create string based on array of dupe fields $this->_dupedFields = array_merge(array_keys($index_fields), $this->_dupedFields); } } } //return true if any dupes were found if (!empty($this->_dupedFields)) { return true; } return false; }
function handleSave($prefix, $redirect = true, $useRequired = false) { require_once 'include/formbase.php'; $focus = new Account(); if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) { return null; } $focus = populateFromPost($prefix, $focus); if (isset($GLOBALS['check_notify'])) { $check_notify = $GLOBALS['check_notify']; } else { $check_notify = FALSE; } if (empty($_POST['record']) && empty($_POST['dup_checked'])) { $duplicateAccounts = $this->checkForDuplicates($prefix); if (isset($duplicateAccounts)) { $location = 'module=Accounts&action=ShowDuplicates'; $get = ''; //add all of the post fields to redirect get string foreach ($focus->column_fields as $field) { if (!empty($focus->{$field}) && !is_object($focus->{$field})) { $get .= "&Accounts{$field}=" . urlencode($focus->{$field}); } } foreach ($focus->additional_column_fields as $field) { if (!empty($focus->{$field})) { $get .= "&Accounts{$field}=" . urlencode($focus->{$field}); } } if ($focus->hasCustomFields()) { foreach ($focus->field_defs as $name => $field) { if (!empty($field['source']) && $field['source'] == 'custom_fields') { $get .= "&Accounts{$name}=" . urlencode($focus->{$name}); } } } $emailAddress = new SugarEmailAddress(); $get .= $emailAddress->getFormBaseURL($focus); //create list of suspected duplicate account id's in redirect get string $i = 0; foreach ($duplicateAccounts as $account) { $get .= "&duplicate[{$i}]=" . $account['id']; $i++; } //add return_module, return_action, and return_id to redirect get string $get .= '&return_module='; if (!empty($_POST['return_module'])) { $get .= $_POST['return_module']; } else { $get .= 'Accounts'; } $get .= '&return_action='; if (!empty($_POST['return_action'])) { $get .= $_POST['return_action']; } //else $get .= 'DetailView'; if (!empty($_POST['return_id'])) { $get .= '&return_id=' . $_POST['return_id']; } if (!empty($_POST['popup'])) { $get .= '&popup=' . $_POST['popup']; } if (!empty($_POST['create'])) { $get .= '&create=' . $_POST['create']; } //now redirect the post to modules/Accounts/ShowDuplicates.php if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') { $json = getJSONobj(); echo $json->encode(array('status' => 'dupe', 'get' => $get)); } else { if (!empty($_POST['to_pdf'])) { $location .= '&to_pdf=' . $_POST['to_pdf']; } $_SESSION['SHOW_DUPLICATES'] = $get; header("Location: index.php?{$location}"); } return null; } } if (!$focus->ACLAccess('Save')) { ACLController::displayNoAccess(true); sugar_cleanup(true); } $focus->save($check_notify); $return_id = $focus->id; $GLOBALS['log']->debug("Saved record with id of " . $return_id); if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') { $json = getJSONobj(); echo $json->encode(array('status' => 'success', 'get' => '')); return null; } if (isset($_POST['popup']) && $_POST['popup'] == 'true') { $get = '&module='; if (!empty($_POST['return_module'])) { $get .= $_POST['return_module']; } else { $get .= 'Accounts'; } $get .= '&action='; if (!empty($_POST['return_action'])) { $get .= $_POST['return_action']; } else { $get .= 'Popup'; } if (!empty($_POST['return_id'])) { $get .= '&return_id=' . $_POST['return_id']; } if (!empty($_POST['popup'])) { $get .= '&popup=' . $_POST['popup']; } if (!empty($_POST['create'])) { $get .= '&create=' . $_POST['create']; } if (!empty($_POST['to_pdf'])) { $get .= '&to_pdf=' . $_POST['to_pdf']; } $get .= '&name=' . $focus->name; $get .= '&query=true'; header("Location: index.php?{$get}"); return; } if ($redirect) { handleRedirect($return_id, 'Accounts'); } else { return $focus; } }
/** * Returns the templatized compose screen. Used by reply, forwards and draft status messages. * @param object email Email bean in focus */ function displayComposeEmail($email) { global $locale; global $current_user; $ea = new SugarEmailAddress(); if (!empty($email)) { $description = empty($email->description_html) ? $email->description : from_html($email->description_html); } $toaddresses = from_html(isset($email->toaddrs) ? $email->toaddrs : $email->to_addrs); $ccAddresses = from_html(isset($email->ccAddrs) ? $email->ccAddrs : $email->cc_addrs); $bccAddresses = from_html(isset($email->bccAddrs) ? $email->bccAddrs : $email->bcc_addrs); $ret = array(); $ret['type'] = $email->type; $ret['name'] = $email->name; $ret['description'] = $description; $ret['from'] = isset($_REQUEST['composeType']) && $_REQUEST['composeType'] == 'forward' ? "" : $email->from_addr; $ret['to'] = $toaddresses; $ret['cc'] = $ccAddresses; $ret['bcc'] = $bccAddresses; $ret['uid'] = $email->id; $ret['parent_name'] = $email->parent_name; $ret['parent_type'] = $email->parent_type; $ret['parent_id'] = $email->parent_id; // reply all if (isset($_REQUEST['composeType']) && $_REQUEST['composeType'] == 'replyAll') { $userEmails = array(); $userEmailsMeta = $ea->getAddressesByGUID($current_user->id, 'Users'); foreach ($userEmailsMeta as $emailMeta) { $userEmails[] = from_html(strtolower(trim($emailMeta['email_address']))); } $userEmails[] = from_html(strtolower(trim($email->from_addr))); $ret['cc'] = from_html($email->cc_addrs); $to = str_replace($this->addressSeparators, "::", $toaddresses); $exTo = explode("::", $to); if (is_array($exTo)) { foreach ($exTo as $addr) { $addr = strtolower(trim($addr)); if (!in_array($addr, $userEmails)) { if (!empty($ret['cc'])) { $ret['cc'] = $ret['cc'] . ", "; } $ret['cc'] = $ret['cc'] . trim($addr); } } } elseif (!empty($exTo)) { $exTo = trim($exTo); if (!in_array($exTo, $userEmails)) { $ret['cc'] = $ret['cc'] . ", " . $exTo; } } } return $ret; }
/** * Called when saving a new email and adds the case update to the case. * @param $bean * @param $event * @param $arguments */ public function saveEmailUpdate($bean, $event, $arguments) { global $mod_strings; if ($bean->intent != "createcase" || $bean->parent_type != "Cases") { $GLOBALS['log']->warn("CaseUpdatesHook: saveEmailUpdate: Not a create case or wrong parent type"); return; } if (!isAOPEnabled()) { return; } if (!$bean->parent_id) { $GLOBALS['log']->warn("CaseUpdatesHook: saveEmailUpdate No parent id"); return; } if ($bean->cases) { $GLOBALS['log']->warn("CaseUpdatesHook: saveEmailUpdate cases already set"); return; } if ($bean->fetched_row['parent_id']) { //Will have been processed already return; } $contact = BeanFactory::getBean("Contact"); $ea = new SugarEmailAddress(); $beans = $ea->getBeansByEmailAddress($bean->from_addr); $contact_id = null; foreach ($beans as $emailBean) { if ($emailBean->module_name == "Contacts" && !empty($emailBean->id)) { $contact_id = $emailBean->id; $this->linkAccountAndCase($bean->parent_id, $emailBean->account_id); } } $case_update = new AOP_Case_Updates(); $case_update->name = $bean->name; $case_update->contact_id = $contact_id; $updateText = $this->unquoteEmail($bean->description_html ? $bean->description_html : $bean->description); $case_update->description = $updateText; $case_update->internal = false; $case_update->case_id = $bean->parent_id; $case_update->save(); $notes = $bean->get_linked_beans('notes', 'Notes'); foreach ($notes as $note) { //Link notes to case update also $newNote = BeanFactory::newBean('Notes'); $newNote->name = $note->name; $newNote->file_mime_type = $note->file_mime_type; $newNote->filename = $note->filename; $newNote->parent_type = 'AOP_Case_Updates'; $newNote->parent_id = $case_update->id; $newNote->save(); $srcFile = "upload://{$note->id}"; $destFile = "upload://{$newNote->id}"; copy($srcFile, $destFile); } $this->updateCaseStatus($case_update->case_id); }
$input .= "<input type='hidden' name='{$field}' value='{$_POST['Contacts' . $field]}'>\n"; } } foreach ($contact->additional_column_fields as $field) { if (!empty($_POST['Contacts' . $field])) { $input .= "<input type='hidden' name='{$field}' value='{$_POST['Contacts' . $field]}'>\n"; } } // Bug 25311 - Add special handling for when the form specifies many-to-many relationships if (!empty($_POST['Contactsrelate_to'])) { $input .= "<input type='hidden' name='relate_to' value='{$_POST['Contactsrelate_to']}'>\n"; } if (!empty($_POST['Contactsrelate_id'])) { $input .= "<input type='hidden' name='relate_id' value='{$_POST['Contactsrelate_id']}'>\n"; } $emailAddress = new SugarEmailAddress(); $input .= $emailAddress->getEmailAddressWidgetDuplicatesView($contact); $get = ''; if (!empty($_POST['return_module'])) { $xtpl->assign('RETURN_MODULE', $_POST['return_module']); } else { $get .= "Contacts"; } $get .= "&return_action="; if (!empty($_POST['return_action'])) { $xtpl->assign('RETURN_ACTION', $_POST['return_action']); } else { $get .= "DetailView"; } /////////////////////////////////////////////////////////////////////////////// //// INBOUND EMAIL WORKFLOW
function fill_in_additional_detail_fields() { parent::fill_in_additional_detail_fields(); //TODO: Seems odd we need to clear out these values so that list views don't show the previous rows value if current value is blank $this->getRelatedFields('Contacts', $this->contact_id, array('name' => 'contact_name', 'phone_work' => 'contact_phone')); if (!empty($this->contact_name)) { $emailAddress = new SugarEmailAddress(); $this->contact_email = $emailAddress->getPrimaryAddress(false, $this->contact_id, 'Contacts'); } if (isset($this->contact_id) && $this->contact_id != '') { $contact = new Contact(); $contact->retrieve($this->contact_id); if (isset($contact->id)) { $this->contact_name = $contact->full_name; } } }
function display() { global $app_strings; global $app_list_strings; global $theme; global $current_language; global $mod_strings; if (!isset($_SESSION['SHOW_DUPLICATES'])) { Log::error("Unauthorized access to this area."); sugar_die("Unauthorized access to this area."); } parse_str($_SESSION['SHOW_DUPLICATES'], $_POST); $post = array_map("securexss", $_POST); foreach ($post as $k => $v) { $_POST[$k] = $v; } unset($_SESSION['SHOW_DUPLICATES']); $lead = new Lead(); require_once 'modules/Leads/LeadFormBase.php'; $leadForm = new LeadFormBase(); $GLOBALS['check_notify'] = false; $query = 'SELECT id, first_name, last_name, title FROM leads WHERE deleted=0 '; $duplicates = $_POST['duplicate']; $count = count($duplicates); if ($count > 0) { $query .= "and ("; $first = true; foreach ($duplicates as $duplicate_id) { if (!$first) { $query .= ' OR '; } $first = false; $query .= "id='{$duplicate_id}' "; } $query .= ')'; } $duplicateLeads = []; $db = DBManagerFactory::getInstance(); $result = $db->query($query); $i = 0; while (($row = $db->fetchByAssoc($result)) != null) { $duplicateLeads[$i] = $row; $i++; } $this->ss->assign('FORMBODY', $leadForm->buildTableForm($duplicateLeads)); $input = ''; foreach ($lead->column_fields as $field) { if (!empty($_POST['Leads' . $field])) { $input .= "<input type='hidden' name='{$field}' value='{$_POST['Leads' . $field]}'>\n"; } } foreach ($lead->additional_column_fields as $field) { if (!empty($_POST['Leads' . $field])) { $input .= "<input type='hidden' name='{$field}' value='{$_POST['Leads' . $field]}'>\n"; } } // Bug 25311 - Add special handling for when the form specifies many-to-many relationships if (!empty($_POST['Leadsrelate_to'])) { $input .= "<input type='hidden' name='relate_to' value='{$_POST['Leadsrelate_to']}'>\n"; } if (!empty($_POST['Leadsrelate_id'])) { $input .= "<input type='hidden' name='relate_id' value='{$_POST['Leadsrelate_id']}'>\n"; } $emailAddress = new SugarEmailAddress(); $input .= $emailAddress->getEmailAddressWidgetDuplicatesView($lead); $get = ''; if (!empty($_POST['return_module'])) { $this->ss->assign('RETURN_MODULE', $_POST['return_module']); } else { $get .= "Leads"; } $get .= "&return_action="; if (!empty($_POST['return_action'])) { $this->ss->assign('RETURN_ACTION', $_POST['return_action']); } else { $get .= "DetailView"; } /////////////////////////////////////////////////////////////////////////////// //// INBOUND EMAIL WORKFLOW if (isset($_REQUEST['inbound_email_id'])) { $this->ss->assign('INBOUND_EMAIL_ID', $_REQUEST['inbound_email_id']); $this->ss->assign('RETURN_MODULE', 'Emails'); $this->ss->assign('RETURN_ACTION', 'EditView'); if (isset($_REQUEST['start'])) { $this->ss->assign('START', $_REQUEST['start']); } } //// END INBOUND EMAIL WORKFLOW /////////////////////////////////////////////////////////////////////////////// if (!empty($_POST['popup'])) { $input .= '<input type="hidden" name="popup" value="' . $_POST['popup'] . '">'; } else { $input .= '<input type="hidden" name="popup" value="false">'; } if (!empty($_POST['to_pdf'])) { $input .= '<input type="hidden" name="to_pdf" value="' . $_POST['to_pdf'] . '">'; } else { $input .= '<input type="hidden" name="to_pdf" value="false">'; } if (!empty($_POST['create'])) { $input .= '<input type="hidden" name="create" value="' . $_POST['create'] . '">'; } else { $input .= '<input type="hidden" name="create" value="false">'; } if (!empty($_POST['return_id'])) { $this->ss->assign('RETURN_ID', $_POST['return_id']); } $this->ss->assign('INPUT_FIELDS', $input); //Load the appropriate template $template = 'modules/Leads/tpls/ShowDuplicates.tpl'; if (file_exists('custom/' . $template)) { $template = 'custom/' . $template; } $saveLabel = string_format($app_strings['LBL_SAVE_OBJECT'], [$this->module]); $this->ss->assign('TITLE', getClassicModuleTitle('Leads', [$this->module, $saveLabel], true)); $this->ss->display($template); }
/** * Convenience function for MVC (Mystique) * @param object $focus SugarBean * @param string $field unused * @param string $value unused * @param string $view DetailView or EditView * @return string */ function getEmailAddressWidget($focus, $field, $value, $view, $tabindex = '0') { $sea = new SugarEmailAddress(); $sea->setView($view); if ($view == 'EditView' || $view == 'QuickCreate' || $view == 'ConvertLead') { $module = $focus->module_dir; if ($view == 'ConvertLead' && $module == "Contacts") { $module = "Leads"; } return $sea->getEmailAddressWidgetEditView($focus->id, $module, false, '', $tabindex); } return $sea->getEmailAddressWidgetDetailView($focus); }
function handleSave($prefix, $redirect = true, $useRequired = false) { global $theme, $current_user; require_once 'include/formbase.php'; $galleria = $_POST['galleria_c']; $focus = new Realty(); if (!empty($_POST[$prefix . 'new_reports_to_id'])) { $focus->retrieve($_POST[$prefix . 'new_reports_to_id']); $focus->reports_to_id = $_POST[$prefix . 'record']; } else { $focus = populateFromPost($prefix, $focus); } if (isset($galleria)) { $focus->galleria_c = $galleria; } if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) { return null; } if (!$focus->ACLAccess('Save')) { ACLController::displayNoAccess(true); sugar_cleanup(true); } if (isset($GLOBALS['check_notify'])) { $check_notify = $GLOBALS['check_notify']; } else { $check_notify = FALSE; } if (empty($_POST['dup_checked'])) { $duplicateRealty = $this->checkForDuplicates($prefix); if (isset($duplicateRealty)) { $focus->possible_duplicate = 1; $_SESSION['duplicateRealty'] = $duplicateRealty; $location = 'module=Realty&action=ShowDuplicates&record=' . $_POST['record']; $get = ''; if (isset($_POST['inbound_email_id']) && !empty($_POST['inbound_email_id'])) { $get .= '&inbound_email_id=' . $_POST['inbound_email_id']; } // Bug 25311 - Add special handling for when the form specifies many-to-many relationships if (isset($_POST['relate_to']) && !empty($_POST['relate_to'])) { $get .= '&Realtyrelate_to=' . $_POST['relate_to']; } if (isset($_POST['relate_id']) && !empty($_POST['relate_id'])) { $get .= '&Realtyrelate_id=' . $_POST['relate_id']; } //add all of the post fields to redirect get string foreach ($focus->column_fields as $field) { if (!empty($focus->{$field}) && !is_object($focus->{$field})) { $get .= "&Realty{$field}=" . urlencode($focus->{$field}); } } foreach ($focus->additional_column_fields as $field) { if (!empty($focus->{$field})) { $get .= "&Realty{$field}=" . urlencode($focus->{$field}); } } if ($focus->hasCustomFields()) { foreach ($focus->field_defs as $name => $field) { if (!empty($field['source']) && $field['source'] == 'custom_fields') { $get .= "&Realty{$name}=" . urlencode($focus->{$name}); } } } $emailAddress = new SugarEmailAddress(); $get .= $emailAddress->getFormBaseURL($focus); //create list of suspected duplicate realty id's in redirect get string $i = 0; foreach ($duplicateRealty as $realty) { $get .= "&duplicate[{$i}]=" . $realty['id']; $i++; } //add return_module, return_action, and return_id to redirect get string $get .= "&return_module="; if (!empty($_POST['return_module'])) { $get .= $_POST['return_module']; } else { $get .= "Realty"; } $get .= "&return_action="; if (!empty($_POST['return_action'])) { $get .= 'EditView'; } //else $get .= "DetailView"; if (!empty($_POST['return_id'])) { $get .= "&return_id=" . $_POST['return_id']; } if (!empty($_POST['popup'])) { $get .= '&popup=' . $_POST['popup']; } if (!empty($_POST['create'])) { $get .= '&create=' . $_POST['create']; } // for InboundEmail flow if (!empty($_POST['start'])) { $get .= '&start=' . $_POST['start']; } $_SESSION['SHOW_DUPLICATES'] = $get; //now redirect the post to modules/Realty/ShowDuplicates.php if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') { ob_clean(); $json = getJSONobj(); echo $json->encode(array('status' => 'dupe', 'get' => $location)); } else { if (!empty($_REQUEST['ajax_load'])) { echo "<script>SUGAR.ajaxUI.loadContent('index.php?{$location}');</script>"; } else { if (!empty($_POST['to_pdf'])) { $location .= '&to_pdf=' . $_POST['to_pdf']; } header("Location: index.php?{$location}"); } } return null; } } $focus->save($check_notify); $return_id = $focus->id; $GLOBALS['log']->debug("Saved record with id of " . $return_id); // $focus->load_relationship('realty_realty_1'); // $focus->realty_realty_1->delete($focus->id); // foreach ($_SESSION['duplicateRealty'] as $realty) // { // $focus->realty_realty_1->add($realty['id']); // } $_SESSION['duplicateRealty'] = array(); if (isset($_POST['popup']) && $_POST['popup'] == 'true') { $get = '&module='; if (!empty($_POST['return_module'])) { $get .= $_POST['return_module']; } else { $get .= 'Realty'; } $get .= '&action='; if (!empty($_POST['return_action'])) { $get .= $_POST['return_action']; } else { $get .= 'Popup'; } if (!empty($_POST['return_id'])) { $get .= '&return_id=' . $_POST['return_id']; } if (!empty($_POST['popup'])) { $get .= '&popup=' . $_POST['popup']; } if (!empty($_POST['create'])) { $get .= '&create=' . $_POST['create']; } if (!empty($_POST['to_pdf'])) { $get .= '&to_pdf=' . $_POST['to_pdf']; } $get .= '&name=' . urlencode($focus->name); $get .= '&query=true'; header("Location: index.php?{$get}"); return; } if ($redirect) { $this->handleRedirect($return_id); } else { return $focus; } }