column_fields)) { $asterisk_extension = $current_user->column_fields['asterisk_extension']; } else { $sql = "select asterisk_extension from vtiger_asteriskextensions where userid = ?"; $result = $adb->pquery($sql, array($current_user->id)); $asterisk_extension = $adb->query_result($result, 0, "asterisk_extension"); } $query = "select * from vtiger_asteriskincomingcalls where to_number = ?"; $result = $adb->pquery($query, array($asterisk_extension)); if($adb->num_rows($result)>0){ $flag = $adb->query_result($result,0,"flag"); $oldTime = $adb->query_result($result,0,"timer"); $callerNumber = $adb->query_result($result,0,"from_number"); $callerName = $adb->query_result($result,0,"from_name"); $callerType = $adb->query_result($result,0,"callertype"); $refuid = $adb->query_result($result, 0, "refuid"); if(!empty($callerNumber)){ $tracedCallerInfo = getTraceIncomingCallerInfo($callerNumber); } $callerLinks = $tracedCallerInfo['callerLinks']; $firstCallerInfo = false; if(!empty($tracedCallerInfo['callerInfos'])) { $firstCallerInfo = $tracedCallerInfo['callerInfos']; } $newTime = time(); if(($newTime-$oldTime)>=3 && $flag == 1){ $adb->pquery("delete from vtiger_asteriskincomingcalls where to_number = ?", array($asterisk_extension)); }else{ if($flag==0){ $flag=1; // Trying to get the Related CRM ID for the Event (if already desired by popup click) $relcrmid = false; if(!empty($refuid)) { $refuidres = $adb->pquery('SELECT relcrmid FROM vtiger_asteriskincomingevents WHERE uid=?',array($refuid)); if($adb->num_rows($refuidres)) $relcrmid = $adb->query_result($refuidres, 0, 'relcrmid'); } $adb->pquery("update vtiger_asteriskincomingcalls set flag = ? where to_number = ?", array($flag, $asterisk_extension)); $activityid = asterisk_addToActivityHistory($callerName, $callerNumber, $callerType, $adb, $current_user->id, $relcrmid, $firstCallerInfo); } //prepare the div for incoming calls $status = "
".$app_strings['LBL_INCOMING_CALL']."
".$app_strings['LBL_CALLER_INFORMATION']."
".$app_strings['LBL_CALLER_NUMBER']." $callerNumber
".$app_strings['LBL_CALLER_NAME']." $callerName
".$app_strings['LBL_INFORMATION_VTIGER']."
$callerLinks
"; } }else{ $status = "failure"; } return $status; } //functions for asterisk integration start /** * this function returns the caller name based on the phone number that is passed to it * @param $from - the number which is calling * returns caller information in name(type) format :: for e.g. Mary Smith (Contact) * if no information is present in database, it returns :: Unknown Caller (Unknown) */ function getTraceIncomingCallerInfo($from) { global $adb; // Grab all possible caller informations (lookup for number as well stripped number) $callerInfos = getCallerInfo($from); $callerLinks = ''; if($callerInfos !== false){ $callerName = decode_html($callerInfos['name']); $module = $callerInfos['module']; $callerModule = " [$module]"; $callerID = $callerInfos['id']; $callerLinks = $callerLinks."$callerName$callerModule
"; }else{ $callerLinks = $callerLinks."
".getTranslatedString('LBL_CREATE_LEAD')."
".getTranslatedString('LBL_CREATE_CONTACT')."
".getTranslatedString('LBL_CREATE_ACCOUNT').""; } return array( 'callerInfos' => $callerInfos, 'callerLinks' => $callerLinks ); } ?>