2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM Community Edition is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
7 * This program is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Affero General Public License version 3 as published by the
9 * Free Software Foundation with the addition of the following permission added
10 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
19 * You should have received a copy of the GNU Affero General Public License along with
20 * this program; if not, see http://www.gnu.org/licenses or write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27 * The interactive user interfaces in modified source and object code versions
28 * of this program must display Appropriate Legal Notices, as required under
29 * Section 5 of the GNU Affero General Public License version 3.
31 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32 * these Appropriate Legal Notices must retain the display of the "Powered by
33 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34 * technical reasons, the Appropriate Legal Notices must display the words
35 * "Powered by SugarCRM".
36 ********************************************************************************/
38 require_once("include/EditView/EditView2.php");
39 require_once("include/upload_file.php");
41 class ViewConvertLead extends SugarView
43 protected $fileName = "modules/Leads/metadata/convertdefs.php";
44 protected $new_contact = false;
46 public function __construct(
48 $view_object_map = array()
51 parent::SugarView($bean, $view_object_map);
52 $this->medataDataFile = $this->fileName;
53 if (file_exists("custom/$this->fileName"))
55 $this->medataDataFile = "custom/$this->fileName";
59 public function preDisplay()
61 if (!$this->bean->ACLAccess('edit')) {
62 ACLController::displayNoAccess();
68 * @see SugarView::display()
70 public function display()
72 if (!empty($_REQUEST['handle']) && $_REQUEST['handle'] == 'save')
74 return $this->handleSave();
79 // get the EditView defs to check if opportunity_name exists, for a check below for populating data
80 $opportunityNameInLayout = false;
81 $editviewFile = 'modules/Leads/metadata/editviewdefs.php';
82 $this->medataDataFile = $editviewFile;
83 if (file_exists("custom/{$editviewFile}"))
85 $this->medataDataFile = "custom/{$editviewFile}";
87 include($this->medataDataFile);
88 foreach($viewdefs['Leads']['EditView']['panels'] as $panel_index => $section){
89 foreach($section as $row_array){
90 foreach($row_array as $cell){
91 if(isset($cell['name']) && $cell['name'] == 'opportunity_name'){
92 $opportunityNameInLayout = true;
98 $this->medataDataFile = $this->fileName;
99 if (file_exists("custom/$this->fileName"))
101 $this->medataDataFile = "custom/$this->fileName";
105 $this->checkForDuplicates($this->focus);
106 $smarty = new Sugar_Smarty();
107 $ev = new EditView();
109 $ev->view = "ConvertLead";
110 echo $this->getModuleTitle();
112 require_once("include/QuickSearchDefaults.php");
113 $qsd = QuickSearchDefaults::getQuickSearchDefaults();
114 $qsd->setFormName("ConvertLead");
116 $this->contact = new Contact();
117 $smarty->assign("contact_def", $this->contact->field_defs);
118 $smarty->assign("form_name", "ConvertLead");
119 $smarty->assign("form_id", "ConvertLead");
120 $smarty->assign("module", "Leads");
121 $smarty->assign("view", "convertlead");
122 $smarty->assign("bean", $this->focus);
123 $smarty->assign("record_id", $this->focus->id);
125 $smarty->assign('MOD', $mod_strings);
126 $smarty->display("modules/Leads/tpls/ConvertLeadHeader.tpl");
128 echo "<div class='edit view' style='width:auto;'>";
130 global $sugar_config, $app_list_strings, $app_strings;
131 $smarty->assign('lead_conv_activity_opt', $sugar_config['lead_conv_activity_opt']);
133 //Switch up list depending on copy or move
134 if($sugar_config['lead_conv_activity_opt'] == 'move')
136 $smarty->assign('convertModuleListOptions', get_select_options_with_id(array('None'=>$app_strings['LBL_NONE'], 'Contacts' => $app_list_strings["moduleListSingular"]['Contacts']), ''));
138 else if($sugar_config['lead_conv_activity_opt'] == 'copy')
140 $smarty->assign('convertModuleListOptions', get_select_options_with_id(array('Contacts' => $app_list_strings["moduleListSingular"]['Contacts']), ''));
145 foreach($this->defs as $module => $vdef)
147 if(!isset($beanList[$module]))
153 $bean = $beanList[$module];
154 $focus = new $bean();
156 // skip if we aren't allowed to save this bean
157 if (!$focus->ACLAccess('save'))
162 $focus->fill_in_additional_detail_fields();
163 foreach($focus->field_defs as $field => $def)
165 if(isset($vdef[$ev->view]['copyData']) && $vdef[$ev->view]['copyData'])
167 if ($module == "Accounts" && $field == 'name')
169 $focus->name = $this->focus->account_name;
171 else if ($module == "Opportunities" && $field == 'amount')
173 $focus->amount = unformat_number($this->focus->opportunity_amount);
175 else if ($module == "Opportunities" && $field == 'name') {
176 if ($opportunityNameInLayout && !empty($this->focus->opportunity_name)){
177 $focus->name = $this->focus->opportunity_name;
180 else if ($field == "id")
182 //If it is not a contact, don't copy the ID from the lead
183 if ($module == "Contacts") {
184 $focus->$field = $this->focus->$field;
186 } else if (is_a($focus, "Company") && $field == 'phone_office')
188 //Special case where company and person have the same field with a different name
189 $focus->phone_office = $this->focus->phone_work;
191 else if (strpos($field, "billing_address") !== false && $focus->field_defs[$field]["type"] == "varchar") /* Bug 42219 fix */
193 $tmp_field = str_replace("billing_", "primary_", $field);
194 $focus->field_defs[$field]["type"] = "text";
195 if (isset($this->focus->$tmp_field)) {
196 $focus->$field = $this->focus->$tmp_field;
200 else if (strpos($field, "shipping_address") !== false && $focus->field_defs[$field]["type"] == "varchar") /* Bug 42219 fix */
202 $tmp_field = str_replace("shipping_", "primary_", $field);
203 if (isset($this->focus->$tmp_field)) {
204 $focus->$field = $this->focus->$tmp_field;
206 $focus->field_defs[$field]["type"] = "text";
208 else if (isset($this->focus->$field))
210 $focus->$field = $this->focus->$field;
215 //Copy over email data
216 $ev->setup($module, $focus, $this->medataDataFile, "modules/Leads/tpls/ConvertLead.tpl", false);
218 echo($ev->display(false));
219 echo($this->getValidationJS($module, $focus, $vdef[$ev->view]));
222 echo ($qsd->getQSScriptsJSONAlreadyDefined());
223 // need to re-assign bean as it gets overridden by $ev->display
224 $smarty->assign("bean", $this->focus);
225 $smarty->display("modules/Leads/tpls/ConvertLeadFooter.tpl");
228 protected function getRecord()
230 $this->focus = new Lead();
231 if (isset($_REQUEST['record']))
233 $this->focus->retrieve($_REQUEST['record']);
237 protected function loadDefs()
240 include($this->medataDataFile);
241 $this->defs = $viewdefs;
245 * Returns the javascript to enable/disable validation of each module's sub-form
246 * //TODO: This should probably be on the smarty template
247 * @param $module String the target module name.
248 * @param $focus SugarBean instance of the target module.
249 * @param $focus EditView def for the module.
250 * @return String, javascript to echo to page.
252 protected function getValidationJS(
258 $validateSelect = isset($viewdef['required']) && $viewdef['required'] && !empty($viewdef['select']);
260 <script type='text/javascript'>
261 if (!SUGAR.convert) SUGAR.convert = {requiredFields: {}};
262 SUGAR.convert.toggle$module = function(){
264 inputsWithErrors = [];
265 if(!SUGAR.convert.{$module}Enabled)
267 for(var i in SUGAR.convert.requiredFields.$module)
269 addToValidate('ConvertLead', '$module' + i, 'varchar', true, SUGAR.convert.requiredFields.{$module}[i]);
272 if ($validateSelect) {
274 removeFromValidate('ConvertLead', '{$viewdef['select']}');";
278 SUGAR.convert.{$module}Enabled = true;
280 for(var i in SUGAR.convert.requiredFields.$module)
282 removeFromValidate('ConvertLead', '$module' + i);
284 if ($validateSelect) {
286 addToValidate('ConvertLead', '{$viewdef['select']}', 'varchar', true, '"
287 . translate($this->contact->field_defs[$viewdef['select']]['vname']) . "');";
290 SUGAR.convert.{$module}Enabled = false;
292 YAHOO.util.Dom.get('convert_create_{$module}').value = SUGAR.convert.{$module}Enabled;
295 if (isset($viewdef['required']) && $viewdef['required'])
297 if (!empty($viewdef['select']) && (empty($viewdef['default_action']) || $viewdef['default_action'] != 'create'))
300 SUGAR.convert.{$module}Enabled = true;";
303 YAHOO.util.Event.onDOMReady(SUGAR.convert.toggle$module);";
304 } else if (isset($viewdef['default_action']) && $viewdef['default_action'] == "create")
306 $jsOut .= "\n SUGAR.convert.{$module}Enabled = true;";
309 YAHOO.util.Event.addListener('new$module', 'click', SUGAR.convert.toggle$module);
310 SUGAR.convert.requiredFields.$module = {};";
311 foreach($focus->field_defs as $field => $def)
313 if (isset($def['required']) && $def['required'])
316 SUGAR.convert.requiredFields.$module.$field = '". translate($def['vname'], $module) . "';\n";
327 * Saves a new Contact as well as any related items passed in.
331 protected function handleSave()
333 require_once('modules/Campaigns/utils.php');
334 require_once("include/formbase.php");
336 if (!empty($_REQUEST['record']))
339 $lead->retrieve($_REQUEST['record']);
345 $selectedBeans = array();
347 //Make sure the contact object is availible for relationships.
348 $beans['Contacts'] = new Contact();
349 $beans['Contacts']->id = create_guid();
350 $beans['Contacts']->new_with_id = true;
352 // Bug 39287 - Check for Duplicates on selected modules before save
353 if (!empty($_REQUEST['selectedContact']))
355 $beans['Contacts']->retrieve($_REQUEST['selectedContact']);
356 if (!empty($beans['Contacts']->id))
358 $beans['Contacts']->new_with_id = false;
359 unset($_REQUEST["convert_create_Contacts"]);
360 unset($_POST["convert_create_Contacts"]);
363 elseif (!empty($_REQUEST["convert_create_Contacts"]) && $_REQUEST["convert_create_Contacts"] != "false" && !isset($_POST['ContinueContact']))
365 require_once('modules/Contacts/ContactFormBase.php');
366 $contactForm = new ContactFormBase();
367 $duplicateContacts = $contactForm->checkForDuplicates('Contacts');
369 if (isset($duplicateContacts))
371 echo $contactForm->buildTableForm($duplicateContacts, 'Contacts');
374 $this->new_contact = true;
376 if (!empty($_REQUEST['selectedAccount']))
378 $_REQUEST['account_id'] = $_REQUEST['selectedAccount'];
379 unset($_REQUEST["convert_create_Accounts"]);
380 unset($_POST["convert_create_Accounts"]);
382 elseif (!empty($_REQUEST["convert_create_Accounts"]) && $_REQUEST["convert_create_Accounts"] != "false" && empty($_POST['ContinueAccount']))
384 require_once('modules/Accounts/AccountFormBase.php');
385 $accountForm = new AccountFormBase();
386 $duplicateAccounts = $accountForm->checkForDuplicates('Accounts');
387 if (isset($duplicateAccounts))
389 echo $accountForm->buildTableForm($duplicateAccounts);
394 foreach ($this->defs as $module => $vdef)
396 //Create a new record if "create" was selected
397 if (!empty($_REQUEST["convert_create_$module"]) && $_REQUEST["convert_create_$module"] != "false")
399 //Save the new record
400 $bean = $beanList[$module];
401 if (empty($beans[$module]))
402 $beans[$module] = new $bean();
404 $this->populateNewBean($module, $beans[$module], $beans['Contacts'], $lead);
406 // when creating a new contact, do not populate it with lead's old account_id
407 if ($module == 'Contacts') {
408 $beans[$module]->account_id = '';
411 //If an existing bean was selected, relate it to the contact
412 else if (!empty($vdef['ConvertLead']['select']))
414 //Save the new record
415 $select = $vdef['ConvertLead']['select'];
416 $fieldDef = $beans['Contacts']->field_defs[$select];
417 if (!empty($fieldDef['id_name']) && !empty($_REQUEST[$fieldDef['id_name']]))
419 $beans['Contacts']->$fieldDef['id_name'] = $_REQUEST[$fieldDef['id_name']];
420 $selects[$module] = $_REQUEST[$fieldDef['id_name']];
421 if (!empty($_REQUEST[$select]))
423 $beans['Contacts']->$select = $_REQUEST[$select];
425 // Bug 39268 - Add the existing beans to a list of beans we'll potentially add the lead's activities to
426 $bean = loadBean($module);
427 $bean->retrieve($_REQUEST[$fieldDef['id_name']]);
428 $selectedBeans[$module] = $bean;
433 $this->handleActivities($lead, $beans);
434 // Bug 39268 - Add the lead's activities to the selected beans
435 $this->handleActivities($lead, $selectedBeans);
437 //link selected account to lead if it exists
438 if (!empty($selectedBeans['Accounts']))
440 $lead->account_id = $selectedBeans['Accounts']->id;
443 //Handle non-contacts relationships
444 foreach ($beans as $bean)
448 if (empty($bean->assigned_user_id))
450 $bean->assigned_user_id = $lead->assigned_user_id;
452 $leadsRel = $this->findRelationship($bean, $lead);
453 if (!empty($leadsRel))
455 $bean->load_relationship($leadsRel);
456 $relObject = $bean->$leadsRel->getRelationshipObject();
457 if ($relObject->relationship_type == "one-to-many" && $bean->$leadsRel->_get_bean_position())
459 $id_field = $relObject->rhs_key;
460 $lead->$id_field = $bean->id;
464 $bean->$leadsRel->add($lead->id);
468 //Special case code for opportunities->Accounts
469 if ($bean->object_name == "Opportunity" && empty($bean->account_id))
471 if (isset($beans['Accounts']))
473 $bean->account_id = $beans['Accounts']->id;
474 $bean->account_name = $beans['Accounts']->name;
476 else if (!empty($selects['Accounts']))
478 $bean->account_id = $selects['Accounts'];
482 //create meetings-users relationship
483 if ($bean->object_name == "Meeting")
485 $bean = $this->setMeetingsUsersRelationship($bean);
487 $this->copyAddressFields($bean, $beans['Contacts']);
490 //if campaign id exists then there should be an entry in campaign_log table for the newly created contact: bug 44522
491 if (isset($lead->campaign_id) && $lead->campaign_id != null && $bean->object_name == "Contact")
493 campaign_log_lead_or_contact_entry($lead->campaign_id, $lead, $beans['Contacts'], 'contact');
497 { //Mark the original Lead converted
498 $lead->status = "Converted";
499 $lead->converted = '1';
500 $lead->in_workflow = true;
504 $this->displaySaveResults($beans);
507 public function setMeetingsUsersRelationship($bean)
509 global $current_user;
510 $meetingsRel = $this->findRelationshipByName($bean, $this->defs['Meetings']['ConvertLead']['relationship']);
511 if (!empty($meetingsRel))
513 $bean->load_relationship($meetingsRel);
514 $bean->$meetingsRel->add($current_user->id);
522 protected function displaySaveResults(
528 foreach($beans as $bean)
530 $beanName = $bean->object_name;
531 if ( $beanName == 'Contact' && !$this->new_contact ) {
532 echo "<li>" . translate("LBL_EXISTING_CONTACT") . " -
533 <a href='index.php?module={$bean->module_dir}&action=DetailView&record={$bean->id}'>
534 {$bean->get_summary_text()}
538 global $app_list_strings;
539 if(!empty($app_list_strings['moduleListSingular'][$bean->module_dir])) {
540 $module_name = $app_list_strings['moduleListSingular'][$bean->module_dir];
542 $module_name = translate('LBL_MODULE_NAME', $bean->module_dir);
544 if(empty($module_name)) {
545 $module_name = translate($beanName);
547 echo "<li>" . translate("LBL_CREATED_NEW") . ' ' . $module_name . " -
548 <a href='index.php?module={$bean->module_dir}&action=DetailView&record={$bean->id}'>
549 {$bean->get_summary_text()}
557 protected function handleActivities(
562 global $app_list_strings;
563 global $sugar_config;
565 $parent_types = $app_list_strings['record_type_display'];
567 $activities = $this->getActivitiesFromLead($lead);
569 foreach($beans as $module => $bean)
571 if (isset($parent_types[$module]))
573 if (empty($bean->id))
575 $bean->id = create_guid();
576 $bean->new_with_id = true;
578 if( isset($_POST['lead_conv_ac_op_sel']) && $_POST['lead_conv_ac_op_sel'] != 'None')
580 foreach($activities as $activity)
582 if (!isset($sugar_config['lead_conv_activity_opt']) || $sugar_config['lead_conv_activity_opt'] == 'copy') {
583 if (isset($_POST['lead_conv_ac_op_sel'])) {
584 //if the copy to module(s) are defined, copy only to those module(s)
585 if (is_array($_POST['lead_conv_ac_op_sel'])) {
586 foreach ($_POST['lead_conv_ac_op_sel'] as $mod) {
587 if ($mod == $module) {
588 $this->copyActivityAndRelateToBean($activity, $bean);
595 else if ($sugar_config['lead_conv_activity_opt'] == 'move') {
596 // if to move activities, should be only one module selected
597 if ($_POST['lead_conv_ac_op_sel'] == $module) {
598 $this->moveActivity($activity, $bean);
608 * Change the parent id and parent type of an activity
609 * @param $activity Activity to be modified
610 * @param $bean New parent bean of the activity
612 protected function moveActivity($activity, $bean) {
616 if (!empty($_REQUEST['record']))
619 $lead->retrieve($_REQUEST['record']);
622 // delete the old relationship to the old parent (lead)
623 if ($rel = $this->findRelationship($activity, $lead)) {
624 $activity->load_relationship ($rel) ;
626 if ($activity->parent_id && $activity->id) {
627 $activity->$rel->delete($activity->id, $activity->parent_id);
631 // add the new relationship to the new parent (contact, account, etc)
632 if ($rel = $this->findRelationship($activity, $bean)) {
633 $activity->load_relationship ($rel) ;
635 $relObj = $activity->$rel->getRelationshipObject();
636 if ( $relObj->relationship_type=='one-to-one' || $relObj->relationship_type == 'one-to-many' )
638 $key = $relObj->rhs_key;
639 $activity->$key = $bean->id;
641 $activity->$rel->add($bean);
644 // set the new parent id and type
645 $activity->parent_id = $bean->id;
646 $activity->parent_type = $bean->module_dir;
652 * Gets the list of activities related to the lead
653 * @param Lead $lead Lead to get activities from
654 * @return Array of Activity SugarBeans .
656 protected function getActivitiesFromLead(
662 global $beanList, $db;
664 $activitesList = array("Calls", "Tasks", "Meetings", "Emails", "Notes");
665 $activities = array();
667 foreach($activitesList as $module)
669 $beanName = $beanList[$module];
670 $activity = new $beanName();
671 $query = "SELECT id FROM {$activity->table_name} WHERE parent_id = '{$lead->id}' AND parent_type = 'Leads'";
672 $result = $db->query($query,true);
673 while($row = $db->fetchByAssoc($result))
675 $activity = new $beanName();
676 $activity->retrieve($row['id']);
677 $activity->fixUpFormatting();
678 $activities[] = $activity;
685 protected function copyActivityAndRelateToBean(
692 $newActivity = clone $activity;
693 $newActivity->id = create_guid();
694 $newActivity->new_with_id = true;
696 //Special case to prevent duplicated tasks from appearing under Contacts multiple times
697 if ($newActivity->module_dir == "Tasks" && $bean->module_dir != "Contacts")
699 $newActivity->contact_id = $activity->contact_name = "";
702 if ($rel = $this->findRelationship($newActivity, $bean))
704 if (isset($newActivity->$rel))
706 // this comes form $activity, get rid of it and load our own
707 $newActivity->$rel = '';
710 $newActivity->load_relationship ($rel) ;
711 $relObj = $newActivity->$rel->getRelationshipObject();
712 if ( $relObj->relationship_type=='one-to-one' || $relObj->relationship_type == 'one-to-many' )
714 $key = $relObj->rhs_key;
715 $newActivity->$key = $bean->id;
717 $newActivity->parent_id = $bean->id;
718 $newActivity->parent_type = $bean->module_dir;
719 $newActivity->update_date_modified = false; //bug 41747
720 $newActivity->save();
721 $newActivity->$rel->add($bean);
722 if ($newActivity->module_dir == "Notes" && $newActivity->filename) {
723 UploadFile::duplicate_file($activity->id, $newActivity->id, $newActivity->filename);
729 * Populates the passed in Bean fron the contact and the $_REQUEST
730 * @param String $module Module of new bean
731 * @param SugarBean $bean SugarBean to be populated.
732 * @param Contact $contact Contact to relate the bean to.
734 protected function populateNewBean(
741 populateFromPost($module, $bean, true);
743 //Copy data from the contact to new bean
744 foreach($bean->field_defs as $field => $def)
746 if(!isset($_REQUEST[$module . $field]) && isset($lead->$field) && $field != 'id')
748 $bean->$field = $lead->$field;
749 if($field == 'date_entered') $bean->$field = gmdate($GLOBALS['timedate']->get_db_date_time_format()); //bug 41030
752 //Try to link to the new contact
754 if (!empty($vdef['ConvertLead']['select']))
756 $select = $vdef['ConvertLead']['select'];
757 $fieldDef = $contact->field_defs[$select];
758 if (!empty($fieldDef['id_name']))
760 $bean->id = create_guid();
761 $bean->new_with_id = true;
762 $contact->$fieldDef['id_name'] = $bean->id ;
763 if ($fieldDef['id_name'] != $select) {
764 $rname = isset($fieldDef['rname']) ? $fieldDef['rname'] : "";
765 if (!empty($rname) && isset($bean->$rname))
766 $contact->$select = $bean->$rname;
768 $contact->$select = $bean->name;
771 } else if ($module != "Contacts"){
772 $contactRel = $this->findRelationship($contact, $bean);
773 if (!empty($contactRel))
775 $bean->id = create_guid();
776 $bean->new_with_id = true;
777 $contact->load_relationship ($contactRel) ;
778 $relObject = $contact->$contactRel->getRelationshipObject();
779 if ($relObject->relationship_type == "one-to-many" && $contact->$contactRel->_get_bean_position())
781 $id_field = $relObject->rhs_key;
782 $bean->$id_field = $contact->id;
784 $contact->$contactRel->add($bean);
786 //Set the parent of activites to the new Contact
787 if (isset($bean->field_defs['parent_id']) && isset($bean->field_defs['parent_type']))
789 $bean->parent_id = $contact->id;
790 $bean->parent_type = "Contacts";
796 protected function copyAddressFields($bean, $contact)
798 //Copy over address info from the contact to any beans with address not set
799 foreach($bean->field_defs as $field => $def)
801 if(!isset($_REQUEST[$bean->module_dir . $field]) && strpos($field, "_address_") !== false)
804 if (strpos($field, "alt_") !== false || strpos($field, "shipping_") !== false)
808 if(strpos($field, "_address_street_2") !== false)
809 $type = "_address_street_2";
810 else if(strpos($field, "_address_street_3") !== false)
811 $type = "_address_street_3";
812 else if(strpos($field, "_address_street_4") !== false)
814 else if(strpos($field, "_address_street") !== false)
815 $type = "_address_street";
816 else if(strpos($field, "_address_city") !== false)
817 $type = "_address_city";
818 else if(strpos($field, "_address_state") !== false)
819 $type = "_address_state";
820 else if(strpos($field, "_address_postalcode") !== false)
821 $type = "_address_postalcode";
822 else if(strpos($field, "_address_country") !== false)
823 $type = "_address_country";
826 if (isset($contact->$var))
827 $bean->$field = $contact->$var;
833 protected function findRelationship(
839 require_once("modules/TableDictionary.php");
840 foreach ($from->field_defs as $field=>$def)
842 if (isset($def['type']) && $def['type'] == "link" && isset($def['relationship']))
844 $rel_name = $def['relationship'];
846 if (isset($dictionary[$from->object_name]['relationships']) && isset($dictionary[$from->object_name]['relationships'][$rel_name]))
848 $rel_def = $dictionary[$from->object_name]['relationships'][$rel_name];
850 else if (isset($dictionary[$to->object_name]['relationships']) && isset($dictionary[$to->object_name]['relationships'][$rel_name]))
852 $rel_def = $dictionary[$to->object_name]['relationships'][$rel_name];
854 else if (isset($dictionary[$rel_name]) && isset($dictionary[$rel_name]['relationships'])
855 && isset($dictionary[$rel_name]['relationships'][$rel_name]))
857 $rel_def = $dictionary[$rel_name]['relationships'][$rel_name];
859 if (!empty($rel_def)) {
860 if ($rel_def['lhs_module'] == $from->module_dir && $rel_def['rhs_module'] == $to->module_dir )
864 else if ($rel_def['rhs_module'] == $from->module_dir && $rel_def['lhs_module'] == $to->module_dir )
874 protected function findRelationshipByName($from, $rel_name)
877 require_once("modules/TableDictionary.php");
878 foreach ($from->field_defs as $field => $def)
880 if (isset($def['relationship']) && $def['relationship'] == $rel_name)
888 * @see SugarView::_getModuleTitleParams()
890 protected function _getModuleTitleParams($browserTitle = false)
893 $params = parent::_getModuleTitleParams($browserTitle);
894 $params[] = "<a href='index.php?module=Leads&action=DetailView&record={$this->bean->id}'>{$this->bean->name}</a>";
895 $params[] = $mod_strings['LBL_CONVERTLEAD'];
900 protected function checkForDuplicates(
904 if ($lead->status == "Converted")
906 echo ("<span class='error'>" . translate('LBL_CONVERTLEAD_WARNING'));
908 $q = "SELECT id, first_name, last_name FROM contacts WHERE first_name LIKE '{$lead->first_name}' AND last_name LIKE '{$lead->last_name}'";
909 $result = $lead->db->query($q);
910 while($row = $lead->db->fetchByAssoc($result)) {
911 $contact = new Contact();
912 $contact->retrieve($row['id']);
913 $dupes[$row['id']] = $contact->name;
917 foreach($dupes as $id => $name)
919 echo (translate('LBL_CONVERTLEAD_WARNING_INTO_RECORD') . "<a href='index.php?module=Contacts&action=DetailView&record=$id'>$name</a>");