required_fields))){ return null; } $query = ''; $baseQuery = "select id,first_name, last_name,account_name, title from leads where deleted!=1 and id!='$id' and (status!='Converted' or status is NULL) and "; if(isset($_POST[$prefix.'first_name']) && !empty($_POST[$prefix.'first_name']) && isset($_POST[$prefix.'last_name']) && !empty($_POST[$prefix.'last_name'])){ $query = $baseQuery ." (first_name='". $_POST[$prefix.'first_name'] . "' and last_name = '". $_POST[$prefix.'last_name'] ."')"; }else{ $query = $baseQuery ." last_name = '". $_POST[$prefix.'last_name'] ."'"; } $rows = array(); global $db; $result = $db->query($query); while (($row = $db->fetchByAssoc($result)) != null) { if(!isset($rows[$row['id']])) { $rows[]=$row; } } $emailStr=""; if(isset($_POST[$prefix.'email1']) && !empty($_POST[$prefix.'email1'])){ $emailStr="'". strtoupper($_POST[$prefix.'email1']) ."'"; } if(isset($_POST[$prefix.'email2']) && !empty($_POST[$prefix.'email2'])){ if (!empty($emailStr)) $emailStr.=","; $emailStr="'". strtoupper($_POST[$prefix.'email2']) ."'"; } if(!empty($emailStr) > 0) { $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 = \'Contacts\' ' . '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 contacts 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; } function buildTableForm($rows, $mod=''){ if(!empty($mod)){ global $current_language; $mod_strings = return_module_language($current_language, $mod); }else global $mod_strings; global $app_strings; $cols = sizeof($rows[0]) * 2 + 1; $form = '
'.$mod_strings['MSG_DUPLICATE']. '
'; $form .= "
"; $form .= get_form_header($mod_strings['LBL_DUPLICATE'],"", ''); $form .= ""; require_once('include/formbase.php'); $form .= getPostToForm(); if(isset($rows[0])){ foreach ($rows[0] as $key=>$value){ if($key != 'id'){ $form .= ""; } } $form .= ""; } $rowColor = 'oddListRowS1'; foreach($rows as $row){ $form .= ""; $form .= ""; $wasSet = false; foreach ($row as $key=>$value){ if($key != 'id'){ if(!$wasSet){ $form .= ""; $wasSet = true; }else{ $form .= ""; }} } if($rowColor == 'evenListRowS1'){ $rowColor = 'oddListRowS1'; }else{ $rowColor = 'evenListRowS1'; } $form .= ""; } $form .= ""; $form .= "
". $mod_strings[$mod_strings['db_'.$key]]. "
$value$value

"; return $form; } function getWideFormBody($prefix, $mod='', $formname=''){ if(!ACLController::checkAccess('Leads', 'edit', true)){ return ''; } global $mod_strings; $temp_strings = $mod_strings; if(!empty($mod)){ global $current_language; $mod_strings = return_module_language($current_language, $mod); } global $app_strings; global $current_user; global $app_list_strings; $primary_address_country_options = get_select_options_with_id($app_list_strings['countries_dom'], ''); $lbl_required_symbol = $app_strings['LBL_REQUIRED_SYMBOL']; $lbl_first_name = $mod_strings['LBL_FIRST_NAME']; $lbl_last_name = $mod_strings['LBL_LAST_NAME']; $lbl_phone = $mod_strings['LBL_OFFICE_PHONE']; $lbl_address = $mod_strings['LBL_PRIMARY_ADDRESS']; $user_id = $current_user->id; $lbl_email_address = $mod_strings['LBL_EMAIL_ADDRESS']; $form = <<
$lbl_first_name
$lbl_required_symbol $lbl_last_name

${mod_strings['LBL_TITLE']}
${mod_strings['LBL_DEPARTMENT']}

$lbl_address
${mod_strings['LBL_CITY']}
${mod_strings['LBL_STATE']}
${mod_strings['LBL_POSTAL_CODE']}
${mod_strings['LBL_COUNTRY']}

$lbl_phone
${mod_strings['LBL_MOBILE_PHONE']}
${mod_strings['LBL_FAX_PHONE']}
${mod_strings['LBL_HOME_PHONE']}

$lbl_email_address
${mod_strings['LBL_OTHER_EMAIL_ADDRESS']}
${mod_strings['LBL_DESCRIPTION']}
EOQ; $javascript = new javascript(); $javascript->setFormName($formname); $javascript->setSugarBean(new Lead()); $javascript->addField('email1','false',$prefix); $javascript->addField('email2','false',$prefix); $javascript->addRequiredFields($prefix); $form .=$javascript->getScript(); $mod_strings = $temp_strings; return $form; } function getFormBody($prefix, $mod='', $formname=''){ if(!ACLController::checkAccess('Leads', 'edit', true)){ return ''; } global $mod_strings; $temp_strings = $mod_strings; if(!empty($mod)){ global $current_language; $mod_strings = return_module_language($current_language, $mod); } global $app_strings; global $current_user; $lbl_required_symbol = $app_strings['LBL_REQUIRED_SYMBOL']; $lbl_first_name = $mod_strings['LBL_FIRST_NAME']; $lbl_last_name = $mod_strings['LBL_LAST_NAME']; $lbl_phone = $mod_strings['LBL_PHONE']; $user_id = $current_user->id; $lbl_email_address = $mod_strings['LBL_EMAIL_ADDRESS']; $form = <<

$lbl_first_name

$lbl_last_name $lbl_required_symbol

$lbl_phone

$lbl_email_address

EOQ; $javascript = new javascript(); $javascript->setFormName($formname); $javascript->setSugarBean(new Lead()); $javascript->addField('email1','false',$prefix); $javascript->addField('email2','false',$prefix); $javascript->addRequiredFields($prefix); $form .=$javascript->getScript(); $mod_strings = $temp_strings; return $form; } function getForm($prefix, $mod='Leads'){ if(!ACLController::checkAccess('Leads', 'edit', true)){ return ''; } if(!empty($mod)){ global $current_language; $mod_strings = return_module_language($current_language, $mod); }else global $mod_strings; global $app_strings; $lbl_save_button_title = $app_strings['LBL_SAVE_BUTTON_TITLE']; $lbl_save_button_key = $app_strings['LBL_SAVE_BUTTON_KEY']; $lbl_save_button_label = $app_strings['LBL_SAVE_BUTTON_LABEL']; $the_form = get_left_form_header($mod_strings['LBL_NEW_FORM_TITLE']); $the_form .= << EOQ; $the_form .= $this->getFormBody($prefix, $mod, "${prefix}LeadSave"); $the_form .= <<

EOQ; $the_form .= get_left_form_footer(); $the_form .= get_validate_record_js(); return $the_form; } 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); } 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; } } } ?>