objectName); $cols = sizeof($rows[0]) * 2 + 1; if ($action != 'ShowDuplicates') { $duplicateLabel = string_format($app_strings['MSG_DUPLICATE'], array(strtolower($this->objectName), $this->moduleName)); $form = '
'.$duplicateLabel.'
'; $form .= "
"; $form .= getPostToForm('/emailAddress(PrimaryFlag|OptOutFlag|InvalidFlag)?[0-9]*?$/', true); } else { $duplicateLabel = string_format($app_strings['MSG_SHOW_DUPLICATES'], array(strtolower($this->objectName), $this->moduleName)); $form = '
'.$duplicateLabel.'
'; } $form .= ""; if ($action != 'ShowDuplicates') { $form .= ""; } require_once('include/formbase.php'); if(isset($_POST['return_action']) && $_POST['return_action'] == 'SubPanelViewer') { $_POST['return_action'] = 'DetailView'; } if(isset($_POST['return_action']) && $_POST['return_action'] == 'DetailView' && empty($_REQUEST['return_id'])) { unset($_POST['return_action']); } $form .= getPostToForm(); if(isset($rows[0])){ foreach ($rows[0] as $key=>$value){ if($key != 'id'){ $form .= ""; } } $form .= ""; } $rowColor = 'oddListRowS1'; foreach($rows as $row){ $form .= ""; if ($action != 'ShowDuplicates') { $form .= "\n"; } $wasSet = false; foreach ($row as $key=>$value){ if($key != 'id'){ if(isset($_POST['popup']) && $_POST['popup']==true){ $form .= "\n"; } else if(!$wasSet){ $form .= "\n"; $wasSet = true; }else{ $form .= "\n"; } } } if($rowColor == 'evenListRowS1'){ $rowColor = 'oddListRowS1'; }else{ $rowColor = 'evenListRowS1'; } $form .= ""; } $form .= "
"; if ($action == 'ShowDuplicates') { $form .= "\n"; if (!empty($_REQUEST['return_module']) && !empty($_REQUEST['return_action']) && !empty($_REQUEST['return_id'])) { $form .= ""; } else if (!empty($_POST['return_module']) && !empty($_POST['return_action'])) { $form .= ""; } else { $form .= ""; } } else { $form .= ""; } $form .= "
 ". $mod_strings[$mod_strings['db_'.$key]]. "
moduleName}'].selected{$this->objectName}.value='${row['id']}';document.forms['dup{$this->moduleName}'].submit() \">[{$app_strings['LBL_SELECT_BUTTON_LABEL']}]  moduleName}&action=DetailView&record=${row['id']}'\">$value$value$value
"; if ($action == 'ShowDuplicates') { $form .= "\n"; if (!empty($_REQUEST['return_module']) && !empty($_REQUEST['return_action']) && !empty($_REQUEST['return_id'])) $form .= ""; else if (!empty($_POST['return_module']) && !empty($_POST['return_action'])) $form .= ""; else $form .= ""; } else { $form .= ""; } $form .= "
"; return $form; } /** * checkForDuplicates * * This function is used to locate any duplicate Leads that may be created when a new Lead is saved. It is called from the handleSave method * of this class. * * @param $prefix String value of any prefix to the form input names * @return $rows Array of matching Leads entries found; null if none found */ function checkForDuplicates($prefix='') { require_once('include/formbase.php'); require_once('include/MVC/SugarModule.php'); $focus = SugarModule::get($this->moduleName)->loadBean(); $query = $this->getDuplicateQuery($prefix); if(empty($query)) { return null; } $rows = array(); global $db; $result = $db->query($query); //Loop through the results and store while (($row = $db->fetchByAssoc($result)) != null) { if(!isset($rows[$row['id']])) { $rows[]=$row; } } //Now check for duplicates using email values supplied $count = 0; $emails = array(); $emailStr = ''; while(isset($_POST["{$this->moduleName}{$count}emailAddress{$count}"])) { $emailStr .= ",'" . strtoupper(trim($_POST["{$this->moduleName}{$count}emailAddress" . $count++])) . "'"; } //while if(!empty($emailStr)) { $emailStr = substr($emailStr, 1); $query = 'SELECT DISTINCT er.bean_id AS id FROM email_addr_bean_rel er, ' . 'email_addresses ea WHERE ea.id = er.email_address_id ' . 'AND ea.deleted = 0 AND er.deleted = 0 AND er.bean_module = \'' . $this->moduleName . '\' ' . 'AND email_address_caps IN (' . $emailStr . ')'; $result = $db->query($query); while (($row = $db->fetchByAssoc($result)) != null) { if(!isset($rows[$row['id']])) { $query2 = "SELECT id, first_name, last_name, title FROM {$focus->table_name} WHERE deleted=0 AND id = '" . $row['id'] . "'"; $result2 = $db->query($query2); $r = $db->fetchByAssoc($result2); if(isset($r['id'])) { $rows[]=$r; } } //if } } //if return !empty($rows) ? $rows : null; } /** * getDuplicateQuery * * This is the function that subclasses should extend and return a SQL query used for the initial duplicate * check sequence. * * @see checkForDuplicates (method), ContactFormBase.php, LeadFormBase.php, ProspectFormBase.php * @param $prefix String value of prefix that may be present in $_POST variables * @return SQL String of the query that should be used for the initial duplicate lookup check */ public function getDuplicateQuery($prefix='') { return null; } }