* SPDX-License-Identifier: AGPL-3.0-only ************************************/ echo TraceIncomingCall(); /** * This function traces an incoming call and adds it to the databse for vte to pickup, * it also adds an entry to the activity history of the related Contact/Lead/Account * only these three modules are supported for now */ function TraceIncomingCall(){ require_once('modules/PBXManager/AsteriskUtils.php'); global $adb, $current_user; global $theme,$app_strings,$log; global $table_prefix; $theme_path="themes/".$theme."/"; $image_path=$theme_path."images/"; $asterisk_extension = false; if(isset($current_user->column_fields)) { $asterisk_extension = $current_user->column_fields['asterisk_extension']; } else { $sql = "select asterisk_extension from ".$table_prefix."_asteriskextensions where userid = ?"; $result = $adb->pquery($sql, array($current_user->id)); $asterisk_extension = $adb->query_result($result, 0, "asterisk_extension"); } $query = "select * from ".$table_prefix."_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 ".$table_prefix."_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 '.$table_prefix.'_asteriskincomingevents WHERE uid=?',array($refuid)); if($adb->num_rows($refuidres)) $relcrmid = $adb->query_result($refuidres, 0, 'relcrmid'); } $adb->pquery("update ".$table_prefix."_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_VTE']."
$callerLinks |