#!/usr/bin/php-cli -q
<?php 
require dirname(__FILE__) . '/../lib/phpagi/phpagi.php';
require dirname(__FILE__) . '/../include/db_utils.inc.php';
require dirname(__FILE__) . '/common/AGI_Logger.class.php';
require dirname(__FILE__) . '/common/AGI_CDR.class.php';
require dirname(__FILE__) . '/common/AGI_Utils.php';
$agi = new AGI();
$logger = new AGI_Logger($agi);
$cdr = new AGI_CDR($agi);
// Get Called Extension informations
$called_ext = $agi->request['agi_extension'];
$Extension_D = DB_Extension($called_ext);
// Get 'DialTone' Parameters
$DialTone = Database_Entry('Ext_DialTone', $Extension_D['PK_Extension']);
//CDR: Set called info
$cdr->set_called("{$DialTone['PK_Extension']}", "DialTone", "Dial Tone", "{$Extension_D['Extension']}");
// Call DISA Application
if ($DialTone['Password'] != '') {
    $agi->exec('DISA', array($DialTone['Password'], 'internal'));
} else {
    $agi->exec('DISA', array('no-password', 'internal'));
}
#!/usr/bin/php-cli -q
<?php 
require dirname(__FILE__) . '/../lib/phpagi/phpagi.php';
require dirname(__FILE__) . '/../include/db_utils.inc.php';
require dirname(__FILE__) . '/common/AGI_Logger.class.php';
require dirname(__FILE__) . '/common/AGI_CDR.class.php';
require dirname(__FILE__) . '/common/AGI_Utils.php';
$agi = new AGI();
$logger = new AGI_Logger($agi);
$cdr = new AGI_CDR($agi);
// Get Called Extension informations
$called_ext = $agi->request['agi_extension'];
$Extension_D = DB_Extension($called_ext);
// Get Called Queue information
$Queue = Database_Entry('Ext_Queues', $Extension_D['PK_Extension']);
//CDR: Set called info
$cdr->set_called("{$Queue['PK_Extension']}", "Queue", "{$Queue['Name']}", "{$Extension_D['Extension']}");
// Set values to pass to [Extension_Queue_RingQueue]
$QUEUE_ARGS = "queue-{$Queue['PK_Extension']}";
if ($Queue['PlayMohInQueue'] == 0) {
    $QUEUE_ARGS .= "|r||||";
} else {
    $QUEUE_ARGS .= "|||||";
}
// Maybe we can pass our cdr id to the agents called throught this url
//$QUEUE_ARGS .= "|http://www.google.com";
$QUEUES_NOAGENTS_EXTEN = "{$Queue['JoinEmptyExtension']}";
$QUEUE_MAXCYCLES_EXTEN = "{$Queue['CyclesExtension']}";
$QUEUE_MAXLEN_EXTEN = "{$Queue['MaxLenExtension']}";
$QUEUE_TIMEOUT_EXTEN = "{$Queue['TimeoutExtension']}";
$QUEUE_OPER_EXTEN = "{$Queue['OperatorExtension']}";
#!/usr/bin/php-cli -q
<?php 
require dirname(__FILE__) . '/../lib/phpagi/phpagi.php';
require dirname(__FILE__) . '/../include/db_utils.inc.php';
require dirname(__FILE__) . '/common/AGI_Logger.class.php';
require dirname(__FILE__) . '/common/AGI_CDR.class.php';
require dirname(__FILE__) . '/common/AGI_Utils.php';
$agi = new AGI();
$logger = new AGI_Logger($agi);
//$cdr    = new AGI_CDR($agi);
// Get Called Extension informations
$called_ext = $agi->request['agi_extension'];
$Extension_D = DB_Extension($called_ext);
// Get 'AgentLogin' Parameters
$AgentLogin = Database_Entry('Ext_AgentLogin', $Extension_D['PK_Extension']);
//
////CDR: Set called info
//$cdr->set_called(
//	"{$Extension_D['PK_Extension']}",                   // CalledID
//	"AgentLogin",                                       // CalledType
//	"Agent Login",                                      // CalledName
//	"{$Extension_D['Extension']}"                       // CalledNumber
//);
// Get the extension of the caller
$cid = $agi->parse_callerid();
$caller_ext = $cid['username'];
function read_agent_number()
{
    global $agi;
    static $first_time = true;
    if ($first_time) {
#!/usr/bin/php-cli -q
<?php 
require dirname(__FILE__) . '/../lib/phpagi/phpagi.php';
require dirname(__FILE__) . '/../include/db_utils.inc.php';
require dirname(__FILE__) . '/common/AGI_Logger.class.php';
require dirname(__FILE__) . '/common/AGI_CDR.class.php';
require dirname(__FILE__) . '/common/AGI_Utils.php';
$agi = new AGI();
$logger = new AGI_Logger($agi);
$cdr = new AGI_CDR($agi);
// Get Called Extension informations
$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
#!/usr/bin/php-cli -q
<?php 
require dirname(__FILE__) . '/../lib/phpagi/phpagi.php';
require dirname(__FILE__) . '/../include/db_utils.inc.php';
require dirname(__FILE__) . '/common/AGI_Logger.class.php';
require dirname(__FILE__) . '/common/AGI_CDR.class.php';
require dirname(__FILE__) . '/common/AGI_Utils.php';
$agi = new AGI();
$logger = new AGI_Logger($agi);
$cdr = new AGI_CDR($agi);
// Get Called Extension informations
$called_ext = $agi->request['agi_extension'];
$Extension_D = DB_Extension($called_ext);
// Get 'Voicemail' Parameters
$SimpleConf = Database_Entry('Ext_SimpleConf', $Extension_D['PK_Extension']);
//CDR: Set called info
$cdr->set_called("{$SimpleConf['PK_Extension']}", "SimpleConf", "Simple Conference", "{$Extension_D['Extension']}");
// Set transfer extension if we have one
if ($SimpleConf['TransferExt'] != "") {
    $agi->set_variable('CONF_TRANSFER_EXT', $SimpleConf['TransferExt']);
}
// Call SimpleConf application
$params = 'S';
if ($SimpleConf['PlaySound'] == 1) {
    $params .= 'n';
}
if ($SimpleConf['PlayMOH'] == 1) {
    $params .= 'm';
}
$agi->exec('Conference', "simpleconf-{$Extension_D['PK_Extension']}/{$params}");
#!/usr/bin/php-cli -q
<?php 
require dirname(__FILE__) . '/../lib/phpagi/phpagi.php';
require dirname(__FILE__) . '/../include/db_utils.inc.php';
require dirname(__FILE__) . '/common/AGI_Logger.class.php';
require dirname(__FILE__) . '/common/AGI_CDR.class.php';
require dirname(__FILE__) . '/common/AGI_Utils.php';
$agi = new AGI();
$logger = new AGI_Logger($agi);
$cdr = new AGI_CDR($agi);
// Get Called Extension informations
$called_ext = $agi->request['agi_extension'];
$Extension_D = DB_Extension($called_ext);
// Get Called SipPhone information
$SipPhone = Database_Entry('Ext_SipPhones', $Extension_D['PK_Extension']);
//CDR: Set called info
$cdr->set_called("{$SipPhone['PK_Extension']}", "SipPhone", "{$SipPhone['FirstName']} {$SipPhone['LastName']}", "{$Extension_D['Extension']}");
//CDR: Push RING event
$cdr->push_event('RING', "{$SipPhone['FirstName']} {$SipPhone['LastName']},{$Extension_D['Extension']}");
// Perform the Dial
$agi->exec('Dial', array("SIP/{$Extension_D['Extension']}", 10, 'tT'));
//CDR: Push DIALSTATUS
$resp = $agi->get_variable('DIALSTATUS');
$DIALSTATUS = $resp['data'];
$resp = $agi->get_variable('HANGUPCAUSE');
$HANGUPCAUSE = $resp['data'];
if ($DIALSTATUS != "") {
    $cdr->push_event('DIALSTATUS', "{$DIALSTATUS},{$HANGUPCAUSE}");
}
if ($DIALSTATUS != 'ANSWER') {
    // Exit if voicemail is not defined for this extension
require dirname(__FILE__) . '/../lib/phpagi/phpagi.php';
require dirname(__FILE__) . '/../include/db_utils.inc.php';
require dirname(__FILE__) . '/common/AGI_Logger.class.php';
require dirname(__FILE__) . '/common/AGI_CDR.class.php';
require dirname(__FILE__) . '/common/AGI_Utils.php';
$agi = new AGI();
$logger = new AGI_Logger($agi);
$cdr = new AGI_CDR($agi);
// Get Called Extension informations
$called_ext = $agi->request['agi_extension'];
$Extension_D = DB_Extension($called_ext);
// Get the extension of the caller
$cid = $agi->parse_callerid();
$caller_ext = $cid['username'];
// Get 'ConfCenter' Parameters
$ConfCenter = Database_Entry('Ext_ConfCenter', $Extension_D['PK_Extension']);
//CDR: Set called info
//$cdr->set_called(
//	"{$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) {
#!/usr/bin/php-cli -q
<?php 
require dirname(__FILE__) . '/../lib/phpagi/phpagi.php';
require dirname(__FILE__) . '/../include/db_utils.inc.php';
require dirname(__FILE__) . '/common/AGI_Logger.class.php';
require dirname(__FILE__) . '/common/AGI_CDR.class.php';
require dirname(__FILE__) . '/common/AGI_Utils.php';
$agi = new AGI();
$logger = new AGI_Logger($agi);
$cdr = new AGI_CDR($agi);
// Get Called Extension informations
$called_ext = $agi->request['agi_extension'];
$Extension_D = DB_Extension($called_ext);
// Get 'Voicemail' Parameters
$Voicemail = Database_Entry('Ext_Voicemail', $Extension_D['PK_Extension']);
//CDR: Set called info
$cdr->set_called("{$Voicemail['PK_Extension']}", "Voicemail", "Voice Mail", "{$Extension_D['Extension']}");
// Get the extension of the caller
$cid = $agi->parse_callerid();
$caller_ext = $cid['username'];
// Call Voicemail application
$VM_MAIN_ARGS = "{$caller_ext}@default";
if ($Voicemail['RequirePassword'] != 1) {
    $VM_MAIN_ARGS .= "|s";
}
$agi->exec('VoicemailMain', $VM_MAIN_ARGS);