function Aastra_get_daynight_name_Asterisk($index)
{
    # Return index by default;
    $return = $index;
    # Connect to freePBX database
    $db = Aastra_connect_freePBX_db_Asterisk();
    # Connected
    if ($db != NULL) {
        $db->setFetchMode(DB_FETCHMODE_ASSOC);
        $query = $db->getAll('SELECT dest FROM daynight WHERE dmode="fc_description" and ext="' . $index . '"');
        if (!PEAR::isError($query)) {
            if ($query[0]['dest'] != '') {
                $return = $query[0]['dest'];
            }
        }
    }
    # Return name
    return $return;
}
Esempio n. 2
0
function get_agent_status($queue, $agent)
{
    global $queue_members;
    $queue_members = '';
    # Transcode for device and user mode
    $agent = Aastra_get_userdevice_Asterisk($agent);
    # Connect to AGI
    $asm = new AGI_AsteriskManager();
    $asm->connect();
    # Add event handlers to retrieve the answer
    $asm->add_event_handler('queuestatuscomplete', 'asm_event_queues');
    $asm->add_event_handler('queuemember', 'asm_event_agents');
    # Retrieve info
    $count = 0;
    while (!$queue_members) {
        $asm->QueueStatus();
        $count++;
        if ($count == 10) {
            break;
        }
    }
    # Process info
    if ($queue != '') {
        # Get info for the given queue
        $status['Logged'] = False;
        $status['Paused'] = False;
        foreach ($queue_members as $agent_a) {
            if ($agent_a['Queue'] == $queue && $agent_a['Location'] == 'Local/' . $agent . '@from-queue/n' or $agent_a['Queue'] == $queue && $agent_a['Location'] == 'Local/' . $agent . '@from-internal/n') {
                $status['Logged'] = True;
                if ($agent_a['Paused'] == '1') {
                    $status['Paused'] = True;
                }
                $status['CallsTaken'] = $agent_a['CallsTaken'];
                $status['LastCall'] = $agent_a['LastCall'];
                break;
            }
        }
        # Get agent type
        $db = Aastra_connect_freePBX_db_Asterisk();
        $sql = "SELECT id FROM queues_details WHERE data LIKE 'Local/" . $agent . "@%' AND id=" . $queue;
        $result = $db->query($sql);
        if (sizeof($result->fetchRow(DB_FETCHMODE_ARRAY)) > 0) {
            $status['Type'] = 'static';
        } else {
            $status['Type'] = 'dynamic';
        }
        # Get Penalty
        $penalty = $asm->database_get('QPENALTY', $queue . '/agents/' . $agent);
        if ($penalty == '') {
            $penalty = '0';
        }
        $status['Penalty'] = $penalty;
    } else {
        # Get info for all the queues for the agent
        foreach ($queue_members as $agent_a) {
            # Dynamic agents are using from-queue context, static agents are using from-internal
            if ($agent_a['Location'] == 'Local/' . $agent . '@from-queue/n' or $agent_a['Location'] == 'Local/' . $agent . '@from-internal/n') {
                $status[$agent_a['Queue']]['Status'] = 1;
                if ($agent_a['Paused'] == '1') {
                    $status[$agent_a['Queue']]['Status'] = 2;
                }
                $status[$agent_a['Queue']]['Membership'] = $agent_a['Membership'];
            }
        }
    }
    # Disconnect properly
    $asm->disconnect();
    # Return Status
    return $status;
}