Re: indicates for improper information in special field
Hi All!
I do apologize but i had posted wrong code
there should be function
function checkForDuplicates($prefix){
global $local_log;
require_once('include/formbase.php');
require_once('modules/Contacts/Contact.php');
$focus = new Contact();
$query = '';
$baseQuery = 'select id,first_name, last_name, title, email1, email2 from contacts 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();
global $db;
$result = $db->query($query.')');
$i=-1;
while (($row= $db->fetchByAssoc($result)) != null) {
++$i;
$rows[$i]=$row;
}
if ($i==-1) return null;
else return $rows;
}
return null;
}
end function executing
$duplicateContacts = $this->checkForDuplicates($prefix);
if(isset($duplicateContacts)){
$get='module=Contacts&action=ShowDuplicates';
if(isset($_POST['inbound_email_id']) && !empty($_POST['inbound_email_id'])) {
$get .= '&inbound_email_id='.$_POST['inbound_email_id'];
}
//add all of the post fields to redirect get string
foreach ($focus->column_fields as $field)
{
if (!empty($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);
}
}
//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'];
//now redirect the post to modules/Contacts/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'])) $get .= '&to_pdf='.$_POST['to_pdf'];
header("Location: index.php?$get");
}
return null;
}
Petro Blagodir
petro@blagodir.ua
http://www.blagodir.com
Blagodir Ltd.( SugarCRM - Consultations, Development and Support)
Bookmarks