Try this simple replacement in callerid.php and let me know if it works for you. I have it working on my end with some minor code changes. This snippet will only search contacts. I will have it all working when I have time (hopefully soon).
For anyone wanting to jump in, the original problem centers around passing from the first sql lookup to the next. For some reason, standard mysql logic is not working reliably.
For anyone wanting to jump in, the original problem centers around passing from the first sql lookup to the next. For some reason, standard mysql logic is not working reliably.
Code:
//--------- SugarCRM --------------------
$wsearch_filter_length = 15; // by changing this variable, you have control over the length of the number to be searched in the database
$value="" ;
if ($SugarCRM=='1') :
if ($debug=='1') :
echo "SugarCRM lookup ....", "\n" ;
endif ;
$link = mysql_connect("localhost", "root", "passw0rd")
or die("SugarCRM connection failed");
mysql_select_db("sugarcrm")
or die("SugarCRM data base open failed");
if ($wsearch_type >= 2 && strlen($value) == 0): // search contacts
$query = "SELECT * FROM contacts WHERE deleted = '0' AND (RIGHT(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(contacts.phone_work,' ',''),'+',''),'-',''),'(',''),')','')," . $wsearch_filter_length . ") LIKE '$thenumber' OR RIGHT(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(contacts.phone_mobile,' ',''),'+',''),'-',''),'(',''),')','')," . $wsearch_filter_length . ") LIKE '$thenumber' OR RIGHT(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(contacts.phone_home,' ',''),'+',''),'-',''),'(',''),')','')," . $wsearch_filter_length . ") LIKE '$thenumber' OR RIGHT(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(contacts.phone_other,' ',''),'+',''),'-',''),'(',''),')','')," . $wsearch_filter_length . ") LIKE '$thenumber' OR RIGHT(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(contacts.phone_fax,' ',''),'+',''),'-',''),'(',''),')','')," . $wsearch_filter_length . ") LIKE '$thenumber') LIMIT 1";
$result = mysql_query($query)
or die("SugarCRM query failed");
if (mysql_num_rows($result)>0) :
$row = mysql_fetch_array($result);
$value=$row["first_name"] . ' ' . $value=$row["last_name"];
endif ;
endif;
mysql_close($link);
if (strlen($value)>0) :
echo $value;
exit ;
endif ;
endif ;
//--------- End SugarCRM --------------------