function TraceIncomingCall()
{
    require_once 'include/utils/utils.php';
    global $adb, $current_user;
    global $theme, $app_strings;
    $theme_path = "themes/" . $theme . "/";
    $image_path = $theme_path . "images/";
    $sql = "select * from vtiger_asteriskextensions where userid = " . $current_user->id;
    $result = $adb->query($sql);
    $asterisk_extension = $adb->query_result($result, 0, "asterisk_extension");
    $query = "select * from vtiger_asteriskincomingcalls where to_number = " . $asterisk_extension;
    $result = $adb->query($query);
    if ($adb->num_rows($result) > 0) {
        $callerNumber = $adb->query_result($result, 0, "from_number");
        $callerName = $adb->query_result($result, 0, "from_name");
        $callerType = $adb->query_result($result, 0, "callertype");
        if (!empty($callerType)) {
            $caller = getCallerName("{$callerType}:" . $callerNumber);
        } else {
            $caller = getCallerName($callerNumber);
        }
        $adb->query("delete from vtiger_asteriskincomingcalls where to_number = " . $asterisk_extension);
        //prepare the div for incoming calls
        $status = "\t<table  border='0' cellpadding='5' cellspacing='0'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td style='padding:10px;' colspan='2'><b>Incoming Call</b></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t\t<table  border='0' cellpadding='0' cellspacing='0' class='hdrNameBg'>\n\t\t\t\t\t\t<tr><td style='padding:10px;' colspan='2'><b>Caller Information</b>\n\t\t\t\t\t\t\t<br><b>Number:</b> {$callerNumber}\n\t\t\t\t\t\t\t<br><b>Name:</b> {$callerName}\n\t\t\t\t\t\t</td></tr>\n\t\t\t\t\t\t<tr><td style='padding:10px;' colspan='2'><b>Information from vtigerCRM</b>\n\t\t\t\t\t\t\t<br>{$caller}\n\t\t\t\t\t\t</td></tr>\n\t\t\t\t\t</table>";
        require_once 'modules/Calendar/Activity.php';
        $focus = new Activity();
        $focus->column_fields['subject'] = "Incoming call from {$callerName} ({$callerNumber})";
        $focus->column_fields['activitytype'] = "Call";
        $focus->column_fields['date_start'] = date('Y-m-d');
        $focus->column_fields['due_date'] = date('Y-m-d');
        $focus->column_fields['time_start'] = date('H:i');
        $focus->column_fields['time_end'] = date('H:i');
        $focus->column_fields['eventstatus'] = "Held";
        $focus->column_fields['assigned_user_id'] = $current_user->id;
        $focus->save('Calendar');
        $callerInfo = getCallerInfo("{$callerType}:" . $callerNumber);
        if ($callerInfo == false) {
            $callerInfo = getCallerInfo(getStrippedNumber($callerNumber));
        }
        if ($callerInfo != false) {
            $tablename = array('Contacts' => 'vtiger_cntactivityrel', 'Accounts' => 'vtiger_seactivityrel', 'Leads' => 'vtiger_seactivityrel');
            $sql = "insert into " . $tablename[$callerInfo['module']] . " values (?,?)";
            $params = array($callerInfo[id], $focus->id);
            $adb->pquery($sql, $params);
        }
    } else {
        $status = "failure";
    }
    return $status;
}
Пример #2
0
/**
 * this function adds a record to the callhistory module
 * 
 * @param string $userExtension - the extension of the current user
 * @param string $callfrom - the caller number
 * @param string $callto - the called number
 * @param string $status - the status of the call (outgoing/incoming/missed)
 * @param object $adb - the peardatabase object
 */
function addToCallHistory($userExtension, $callfrom, $callto, $status, $adb)
{
    $sql = "select * from vtiger_asteriskextensions where asterisk_extension=" . $userExtension;
    $result = $adb->pquery($sql, array());
    $userID = $adb->query_result($result, 0, "userid");
    $crmID = $adb->getUniqueID('vtiger_crmentity');
    $timeOfCall = date('Y-m-d H:i:s');
    $sql = "insert into vtiger_crmentity values (?,?,?,?,?,?,?,?,?,?,?,?,?)";
    $params = array($crmID, $userID, $userID, 0, "PBXManager", "", $timeOfCall, $timeOfCall, NULL, NULL, 0, 1, 0);
    $adb->pquery($sql, $params);
    if (empty($callfrom)) {
        $callfrom = "Unknown";
    }
    if (empty($callto)) {
        $callto = "Unknown";
    }
    if ($status == 'outgoing') {
        //call is from user to record
        $sql = "select * from vtiger_asteriskextensions where asterisk_extension=?";
        $result = $adb->pquery($sql, array($callfrom));
        if ($adb->num_rows($result) > 0) {
            $userid = $adb->query_result($result, 0, "userid");
            $callerName = getUserFullName($userid);
        }
        $receiver = getCallerInfo($callto);
        if ($receiver == false) {
            $receiver = getCallerInfo(getStrippedNumber($callto));
        }
        if (empty($receiver)) {
            $receiver = "Unknown";
        } else {
            $receiver = "<a href='index.php?module=" . $receiver[module] . "&action=DetailView&record=" . $receiver[id] . "'>" . $receiver[name] . "</a>";
        }
    } else {
        //call is from record to user
        $sql = "select * from vtiger_asteriskextensions where asterisk_extension=?";
        $result = $adb->pquery($sql, array($callto));
        if ($adb->num_rows($result) > 0) {
            $userid = $adb->query_result($result, 0, "userid");
            $receiver = getUserFullName($userid);
        }
        $callerName = getCallerInfo($callfrom);
        if ($callerName == false) {
            $callerName = getCallerInfo(getStrippedNumber($callfrom));
        }
        if (empty($callerName)) {
            $callerName = "Unknown";
        } else {
            $callerName = "<a href='index.php?module=" . $callerName[module] . "&action=DetailView&record=" . $callerName[id] . "'>" . decode_html($callerName[name]) . "</a>";
        }
    }
    $sql = "insert into vtiger_pbxmanager (pbxmanagerid,callfrom,callto,timeofcall,status)values (?,?,?,?,?)";
    $params = array($crmID, $callerName, $receiver, $timeOfCall, $status);
    $adb->pquery($sql, $params);
}
/**
 * this function adds the call information to the actvity history
 * @param string $callerName - the caller name
 * @param string $callerNumber - the callers' number
 * @param string $callerType - the caller type (SIP/PSTN...)
 * @param object $adb - the peardatabase object
 * @param object $current_user - the current user
 * @return string $status - on success - string success
 * 							on failure - string failure
 */
function asterisk_addToActivityHistory($callerName, $callerNumber, $callerType, $adb, $current_user)
{
    global $log;
    require_once 'modules/Calendar/Activity.php';
    $focus = new Activity();
    $focus->column_fields['subject'] = "Incoming call from {$callerName} ({$callerNumber})";
    $focus->column_fields['activitytype'] = "Call";
    $focus->column_fields['date_start'] = date('Y-m-d');
    $focus->column_fields['due_date'] = date('Y-m-d');
    $focus->column_fields['time_start'] = date('H:i');
    $focus->column_fields['time_end'] = date('H:i');
    $focus->column_fields['eventstatus'] = "Held";
    $focus->column_fields['assigned_user_id'] = $current_user->id;
    $focus->save('Calendar');
    $focus->setActivityReminder('off');
    //	$callerInfo = getCallerInfo("$callerType:".$callerNumber);
    //	if($callerInfo == false){
    $callerInfo = getCallerInfo(getStrippedNumber($callerNumber));
    //}
    if ($callerInfo != false) {
        $tablename = array('Contacts' => 'vtiger_cntactivityrel', 'Accounts' => 'vtiger_seactivityrel', 'Leads' => 'vtiger_seactivityrel');
        $sql = "insert into " . $tablename[$callerInfo['module']] . " values (?,?)";
        $params = array($callerInfo[id], $focus->id);
        $adb->pquery($sql, $params);
        $status = "success";
    } else {
        $status = "failure";
    }
    return $status;
}