required_fields))){
return null;
}
$query = '';
$baseQuery = 'select id,first_name, last_name, title, email1, email2 from prospects where deleted!=1 and (';
if(!empty($_POST[$prefix.'first_name']) && !empty($_POST[$prefix.'last_name'])){
$query = $baseQuery ." (first_name like '". $_POST[$prefix.'first_name'] . "%' and last_name = '". $_POST[$prefix.'last_name'] ."')";
}else{
$query = $baseQuery ." last_name = '". $_POST[$prefix.'last_name'] ."'";
}
if(!empty($_POST[$prefix.'email1'])){
if(empty($query)){
$query = $baseQuery. " email1='". $_POST[$prefix.'email1'] . "' or email2 = '". $_POST[$prefix.'email1'] ."'";
}else {
$query .= "or email1='". $_POST[$prefix.'email1'] . "' or email2 = '". $_POST[$prefix.'email1'] ."'";
}
}
if(!empty($_POST[$prefix.'email2'])){
if(empty($query)) {
$query = $baseQuery. " email1='". $_POST[$prefix.'email2'] . "' or email2 = '". $_POST[$prefix.'email2'] ."'";
}else{
$query .= "or email1='". $_POST[$prefix.'email2'] . "' or email2 = '". $_POST[$prefix.'email2'] ."'";
}
}
if(!empty($query)){
$rows = array();
$db = DBManagerFactory::getInstance();
$result = $db->query($query.');');
while($row = $db->fetchByAssoc($result)) {
$rows[] = $row;
}
if(count($rows) > 0) return $rows;
}
return null;
}
function buildTableForm($rows, $mod=''){
global $action;
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;
if ($action != 'ShowDuplicates')
{
$form = '
'.$mod_strings['MSG_DUPLICATE']. ' |
|
';
$form .= "";
}
else
{
$form .= "
";
}
return $form;
}
function getWideFormBody($prefix, $mod='',$formname='', $prospect = ''){
if(!ACLController::checkAccess('Prospects', 'edit', true)){
return '';
}
if(empty($prospect)){
$prospect = new Prospect();
}
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'], $prospect->primary_address_country);
$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 = <<
EOQ;
$javascript = new javascript();
$javascript->setFormName($formname);
$javascript->setSugarBean(new Prospect());
$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('Prospects', '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'];
if ($formname == 'EmailEditView')
{
$form = <<
$lbl_first_name
$lbl_last_name $lbl_required_symbol
$lbl_email_address $lbl_required_symbol
EOQ;
}
else
{
$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 Prospect());
$javascript->addField('email1','false',$prefix);
$javascript->addRequiredFields($prefix);
$form .=$javascript->getScript();
$mod_strings = $temp_strings;
return $form;
}
function getForm($prefix, $mod=''){
if(!ACLController::checkAccess('Prospects', '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,'Prospects', "${prefix}ProspectSave");
$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){
global $theme;
require_once('include/formbase.php');
global $timedate;
$focus = new Prospect();
if($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))){
return null;
}
$focus = populateFromPost($prefix, $focus);
if(!$focus->ACLAccess('Save')){
return null;
}
if (!isset($GLOBALS['check_notify'])) $GLOBALS['check_notify']=false;
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 (empty($_POST['record']) && empty($_POST['dup_checked'])) {
/*
// we don't check dupes on Prospects - this is the dirtiest data in the system
//$duplicateProspects = $this->checkForDuplicates($prefix);
if(isset($duplicateProspects)){
$get='module=Prospects&action=ShowDuplicates';
//add all of the post fields to redirect get string
foreach ($focus->column_fields as $field)
{
if (!empty($focus->$field))
{
$get .= "&Prospects$field=".urlencode($focus->$field);
}
}
foreach ($focus->additional_column_fields as $field)
{
if (!empty($focus->$field))
{
$get .= "&Prospects$field=".urlencode($focus->$field);
}
}
//create list of suspected duplicate prospect id's in redirect get string
$i=0;
foreach ($duplicateProspects as $prospect)
{
$get .= "&duplicate[$i]=".$prospect['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 .= "Prospects";
$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'];
//now redirect the post to modules/Prospects/ShowDuplicates.php
header("Location: index.php?$get");
return null;
}*/
}
global $current_user;
$focus->save($GLOBALS['check_notify']);
$return_id = $focus->id;
$GLOBALS['log']->debug("Saved record with id of ".$return_id);
if(isset($_POST['popup']) && $_POST['popup'] == 'true') {
$get = '&module=';
if(!empty($_POST['return_module'])) $get .= $_POST['return_module'];
else $get .= 'Prospects';
$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=' . $focus->first_name;
$get .= '&last_name=' . $focus->last_name;
$get .= '&query=true';
header("Location: index.php?$get");
return;
}
if($redirect){
require_once('include/formbase.php');
handleRedirect($return_id, 'Prospects');
}else{
return $focus;
}
}
}
?>