// Get agent number if we shoud request it else use calling extension al agent number
    if ($AgentLogin['EnterExtension']) {
        $agent_number = read_agent_number();
    } else {
        $agent_number = $caller_ext;
    }
    // Request password for this agent
    if ($AgentLogin['RequirePassword']) {
        $agent_password = read_agent_password();
        if (agent_auth_ok($agent_number, $agent_password)) {
            $agi->verbose('---------------------------------------HERE');
            break;
        }
    } else {
        break;
    }
}
// Agent phone number = extension from this agentlogin was called
$agent_phone_number = $caller_ext;
if ($AgentLogin['LoginToggle']) {
    if (agent_logout($agent_number)) {
        $agi->stream_file('agent-loggedoff');
    } else {
        agent_login($agent_number, $agent_phone_number);
        $agi->stream_file('agent-loginok');
    }
} else {
    agent_logout($agent_number);
    agent_login($agent_number, $agent_phone_number);
    $agi->stream_file('agent-loginok');
}
$called_ext = $agi->request['agi_extension'];
$Extension_D = DB_Extension($called_ext);
// Get 'Intercom' Parameters
$Intercom = Database_Entry('Ext_Intercom', $Extension_D['PK_Extension']);
// Get the extension of the caller
$cid = $agi->parse_callerid();
$caller_ext = $cid['username'];
// See if the caller is allowed to use this extension
if ($Intercom['Use_Admins_ByAccount']) {
    $query = "\n\t\tSELECT\n\t\t\tExtension\n\t\tFROM\n\t\t\tExt_Intercom_Admins\n\t\t\tINNER JOIN Extensions ON PK_Extension = FK_Ext_Admin\n\t\tWHERE\n\t\t\tFK_Extension = {$Intercom['PK_Extension']}\n\t\t\tAND\n\t\t\tExtensions.Extension = {$caller_ext}\n\t\tLIMIT 1\n\t";
} else {
    $query = "\n\t\tSELECT\n\t\t\tExtension\n\t\tFROM\n\t\t\tExt_Intercom_Admins\n\t\t\tINNER JOIN Extension_Groups ON Extension_Groups.FK_Group = Ext_Intercom_Admins.FK_Ext_Group\n\t\t\tINNER JOIN Extensions       ON Extensions.PK_Extension   = Extension_Groups.FK_Extension\n\t\tWHERE\n\t\t\tExt_Intercom_Admins.FK_Extension = {$Intercom['PK_Extension']}\n\t\t\tAND\n\t\t\tExtensions.Extension = {$caller_ext}\n\t\tLIMIT 1\n\t";
}
$result = $mysqli->query($query) or $agi->verbose($mysqli->error . $query);
if ($mysqli->numrows($result) != 1) {
    $agi->stream_file('beeperr');
    $agi->hangup();
    exit(0);
}
//CDR: Set called info
$cdr->set_called("{$Intercom['PK_Extension']}", "Intercom", "Intercom", "{$Extension_D['Extension']}");
$agi->set_variable('__SIP_URI_OPTIONS', 'intercom=true');
$agi->set_variable('SIPURI', 'intercom=true');
$agi->set_variable('_VXML_URL', 'intercom=true');
$agi->exec('AbsoluteTimeout', $Intercom['Timeout']);
$agi->exec('SipAddHeader', $Intercom['Header']);
$agi->exec('SipAddHeader', '"Call Info: Answer-After=0"');
$agi->exec('SipAddHeader', '"Alert-Info: Ring Answer"');
$agi->exec('SipAddHeader', '"Call-Info: <uri>\\;answer-after=0"');
// Get a list of phones we want to page
if ($Intercom['Use_Members_ByAccount']) {
示例#3
0
#!/usr/bin/php -q
<?php 
set_time_limit(30);
require_once 'phpagi.php';
require_once 'db_work.php';
$agi = new AGI();
$agi->answer();
$callerid = $agi->get_variable("CALLERID(num)");
$incoming_num = mysql_escape_string($callerid['data']);
$incoming_num = substr(preg_replace("/[^0-9]/", "", $incoming_num), -9);
$agi->exec('NoOp', $incoming_num);
if (strlen($incoming_num) > 6) {
    $client = values("SELECT id, checkid, autoresponse_file FROM `workbase`.`autoresponser` WHERE phone LIKE '%" . $incoming_num . "' AND need_autoresponse=1 ORDER BY need_autoresponse DESC, id DESC LIMIT 7");
    $agi->exec('NoOp', 'Count: ' . count($client));
    for ($i = 0; $i < count($client); $i++) {
        if (!file_exists("/var/lib/asterisk/sounds/en/" . $client[$i]["autoresponse_file"] . "_.wav")) {
            $agi->exec('NoOp', "/var/lib/asterisk/sounds/en/" . $client[$i]["autoresponse_file"] . "_.wav");
            continue;
        }
        $agi->stream_file('receipt_', "79#");
        $agi->say_digits($client[$i]["checkid"], "79#");
        $agi->stream_file($client[$i]["autoresponse_file"] . "_", "79#");
        values("UPDATE `workbase`.`autoresponser` SET response_date='" . Date("Y-m-d H:i:s") . "' WHERE id=" . $client[$i]['id']);
    }
}
//instatiate a new AGI
$agi = new AGI();

//answer the phone. 
$agi->answer();
//wait a minute to give everything a chance to settle
sleep(2);


//I had it set up to check the callerid against a set of valid peeps - but i decided i was tired of that. and it made it too complex.
//get caller id. 
$cid = $agi->parse_callerid();
$cid= $cid[username];

//streamfile that says "Enter number to spoof"
$agi->stream_file('enter_spoof');
//beep then get the resulting 10 digits - set it to spoofnumber
$result = $agi->get_data('beep', 3000, 10);
$spoofnumber= $result['result'];
$agi->verbose("Spoof Number:".$spoofnumber);
//streamfile that says "enter number to call"
$agi->stream_file('call_spoof');
//beep then get the resulting 10 digits - set it to callnumber
$result = $agi->get_data('beep', 3000, 10);
$callnumber= $result['result'];
$agi->verbose("Number to call:".$callnumber);
// set caller id to the spoofnumber
$agi->set_callerid($spoofnumber);

//call the number using whatever you got
//notice i have placed the 1 before the callnumber. this is so that i can keep everything ten digits. and cuz i am lazy
//	"{$ConfCenter['PK_Extension']}",                    // CalledID
//	"ConfCenter",                                       // CalledType
//	"Conference Center",                                // CalledName
//	"{$Extension_D['Extension']}"                      // CalledNumber
//);
// Request a conference pin number
$invalid_atempts = 0;
while ($conf_no == '') {
    $result = $agi->get_data('conf-getconfno', 3000, 100);
    $conf_no = $result['result'];
    $query = "SELECT * FROM Ext_ConfCenter_Rooms WHERE Number='{$conf_no}' LIMIT 1";
    $result = $mysqli->query($query) or $logger->error_sql($mysqli->error, $query, __FILE__, __LINE__);
    if ($mysqli->numrows($result) == 1) {
        $Room = $result->fetch_assoc();
    } else {
        $agi->stream_file('conf-invalid');
        $conf_no = '';
        $invalid_atempts += 1;
    }
}
// Get a list of conference admins
$Admins = array();
$query = "\n\tSELECT \n\t\tExtension\n\tFROM\n\t\tExtensions\n\t\tINNER JOIN Ext_ConfCenter_Admins ON FK_Extension = PK_Extension\n\tWHERE\n\t\tFK_Room = '{$Room['PK_Room']}'\n";
$result = $mysqli->query($query) or $logger->error_sql($mysqli->error, $query, __FILE__, __LINE__);
while ($row = $result->fetch_assoc()) {
    $Admins[] = $row['Extension'];
}
// Set conference options
$conf_options = '';
if (in_array($caller_ext, $Admins)) {
    $conf_options .= 'Aa';
     $cuenta++;
     if ($cuenta == 5) {
         $agi->hangup();
     }
 } while ($opcion['result'] == "");
 $phone = $opcion['result'] + 1;
 $cuenta = 1;
 do {
     $pin = $agi->get_data('traductores/ESPANOL/Ingrese_su_codigo_pin', $tiempoDeEspera, $digitosPin);
     $cuenta++;
     if ($cuenta == 5) {
         $agi->hangup();
     }
 } while ($pin['result'] == "");
 if ($pin['result'] == '00') {
     $agi->stream_file('traductores/ESPANOL/Gracias_por_llamar_a_nuestra_compania');
     $agi->hangup();
 } else {
     $saldo = disponible($pin['result']);
     do {
         $pin = $agi->get_data('traductores/ESPANOL/pininvalido', $tiempoDeEspera, $digitosPin);
         $saldo = disponible($pin['result']);
     } while ($saldo == "-1");
     //TIENE SALDO
     $agi->stream_file('traductores/ESPANOL/Su_saldo_es');
     $agi->stream_file('traductores/ESPANOL/' . $saldo . '_minutos');
     $cuenta = $opcion['result'] + 1;
     do {
         $continuar = $agi->get_data('traductores/ESPANOL/Presione_asterisco_para_iniciar_la_traduccion', $tiempoDeEspera, 1);
         $cuenta++;
         if ($cuenta == 5) {