Vicidial PHP / Json / Mysql组合在监视器中提取数据

时间:2016-01-05 14:31:37

标签: php mysql json

问题标题可能非常模糊,但我不知道究竟要写什么,所以让我们谈谈

我有一个脚本从Vicidial数据库中提取数据以显示电视屏幕

现在它基本上工作得很好,只有一个服务器涉及因为它只有一个扩展来处理,但当有两个扩展时事情变得更复杂。更好的我告诉你代码:

$start_time = time();
$data = array();

$sql = "SELECT
            extension,
            vicidial_live_agents.user,
            conf_exten,
            vicidial_live_agents.status,
            vicidial_live_agents.server_ip,
            UNIX_TIMESTAMP(last_call_time) as last_call_time,
            UNIX_TIMESTAMP(last_call_finish) as last_call_finish,
            call_server_ip,
            vicidial_live_agents.campaign_id,
            vicidial_users.user_group,
            vicidial_users.full_name,
            vicidial_live_agents.comments,
            vicidial_live_agents.calls_today,
            vicidial_live_agents.callerid,
            lead_id,
            UNIX_TIMESTAMP(last_state_change) as last_state_change,
            on_hook_agent,
            ring_callerid,
            agent_log_id
        FROM
            vicidial_live_agents,
            vicidial_users
        WHERE
            vicidial_live_agents.user = vicidial_users.user";

$db = new mysqli("192.168.X.X", "cron", "XXXXXX", "asterisk");


$result = $db->query($sql);

$sql2 = "select callerid,lead_id,phone_number from vicidial_auto_calls";
$cidresult = $db->query($sql2);
$callerids = '';
while ($row = $cidresult->fetch_assoc()){
    $callerids .= $row['callerid'] . "|";
}

while ($row = $result->fetch_assoc()){
    $status = $row['status'];

    if ($row['on_hook_agent'] == 'Y')
        $status = 'RING';

    // 3-way Check
    if ($row['lead_id'] != 0){
        $sql = "SELECT UNIX_TIMESTAMP(last_call_time) FROM vicidial_live_agents WHERE lead_id = '" . $db->escape_string($row['lead_id']) . "' AND status = 'INCALL' ORDER BY UNIX_TIMESTAMP(last_call_time) DESC";
        $r2 = $db->query($sql);
        if (!$r2){
            printf("Error: %s\n", $db->error);
        } else {
            if ($r2->num_rows > 1){
                $status = "3-WAY";
            }
        }
    }

    $epoch_sec = 0;
    if (preg_match("/READY|PAUSED/i", $row['status'])){
        $epoch_sec = $row['last_state_change'];

        if ($row['lead_id'] > 0){
            $status = 'DISPO';
        }
    } else {
        $epoch_sec = $row['last_call_time'];
    }

    if (preg_match("/INCALL/i", $status)){
        $sql4 = "SELECT UNIX_TIMESTAMP(parked_time) AS pt FROM parked_channels WHERE channel_group = '" . $db->escape_string($row['callerid']) . "'";
        $q4 = $db->query($sql4);

        if ($q4->num_rows > 0){
            $status = 'PARK';
            $rowP = $q4->fetch_assoc();
            $epoch_sec = $rowP['pt'];
        } else{
            if (!preg_match("/" . $row['callerid'] . "\|/",$callerids)){
                $epoch_sec = $row['last_state_change'];

                $status = 'DEAD';
            }
        }
    }

    switch($status){
        case 'DISPO':
            $colour = '8e44ad';
            break;
        case 'QUEUE':
            $colour = '9b59b6';
            break;
        case 'INCALL':
            $colour = '3498db';
            break;
        case 'PARK':
            $colour = 'e67e22';
            break;
        case 'DEAD':
            $colour = '004D86';
            $status = 'GONE';
            break;
        case '3-WAY':
            $colour = '1abc9c';
            break;
        case 'RING':
            $colour = '16a085';
            break;
        case 'PAUSED':
            $colour = 'c0392b';
            break;
        case 'CLOSER':
            $status = 'READY (C)';
        case 'READY':
            $colour = '27ae60';
            break;
        default:
            $colour = 'D2BEAA';
            break;
    }

    $data[$row['extension']] = array(
        'user' => $row['user'],
        'status' => $status,
        'conf_exten' => $row['conf_exten'],
        'seconds' => ( time() - $epoch_sec ),
        'campaign_id' => $row['campaign_id'],
        'user_group' => $row['user_group'],
        'full_name' => $row['full_name'],
        'calls_today' => $row['calls_today'],
        'lead_id' => $row['lead_id'],
        'colour' => $colour
    );

}

现在例如当分机是SIP / P023时,一切正常,但由于用户可以使用分机SIP / P 023和SIP / B 023我需要找到一个你有相同输出的等待

Screenshot of what i have

现在我需要制作一个单一的方格,其结果是任何一个扩展女巫是活跃的(他们不能同时活动)

我不知道我是否已经解释过自己,但我希望至少

1 个答案:

答案 0 :(得分:1)

您是否尝试过API?在这里:http://www.vicidial.org/docs/NON-AGENT_API.txt

查找agent_status部分。这将为您提供用户的实时统计数据。因此,您所要做的就是将脚本设置为以您想要的任何间隔刷新。如果您需要更多关于api的帮助,请告诉我。