Last active
August 29, 2015 14:04
-
-
Save odil5/f29ccbeb07896ba3649f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$ghost = 'XXX.XXX.XXX.XXX'; | |
$guser = 'USER_NAME'; | |
$gpwd = 'PASSWORD'; | |
$gdbname = 'DB_NAME'; | |
$db = mysql_connect($ghost, $guser, $gpwd) or die("Could not connect: " . mysql_error()); | |
mysql_select_db ($gdbname, $db) or die (mysql_error($db)); | |
function bridge_events($ecode, $data, $server, $port){ | |
print_r($data); | |
$datanow = Date('Y-m-d H-i-s'); | |
$bridgeState = $data["Bridgestate"]; | |
$callerId = $data["CallerID1"]; | |
$calleeId = $data["CallerID2"]; | |
} | |
function dump_events($ecode,$data,$server,$port) { | |
$datenow = Date('Y-m-d H:i:s'); | |
$CallerIDNum = $data["CallerIDNum"]; | |
$Channel = $data['Channel']; | |
$sql = "INSERT INTO `test`.`max_taxi_inccall` | |
( `id` , `date_call`, `sip_conn_oper`, `caller_phone_num` , `sip_system_id`) | |
VALUES ( NULL , '$datenow', 0, '$CallerIDNum', '$Channel' );"; | |
if( ($CallerIDNum!= "") AND (strlen($CallerIDNum)>3) ) | |
$res = mysql_query($sql); | |
} | |
function hangup_handler($ecode, $data, $server, $port){ | |
$datanow = Date('Y-m-d H:i:s'); | |
$sipID = $data["Channel"]; | |
$HangUP = $data["ConnectedLineName"]; | |
$CallerIDNum = $data["CallerIDNum"]; | |
if(!empty($HangUP) || $HangUP != '<unknown>') | |
{ | |
$sql = "UPDATE `test`.`max_taxi_inccall` | |
SET `status` = '1', `sip_conn_oper` = $HangUP | |
WHERE `caller_phone_num` = '$CallerIDNum' | |
AND | |
`status` = '0'"; | |
} | |
//$res = mysql_query($sql); | |
if(mysql_error()){ | |
print "Success!!!\n"; | |
}else | |
print(mysql_error()); | |
} | |
function rtcprecived($ecode, $data, $server, $port) | |
{ | |
echo "Answered \n "; | |
echo "<pre>"; | |
print_r($data); | |
echo "</pre>"; | |
} | |
function dial($ecode, $data, $server, $port) | |
{ | |
echo "DIAL Connect \n "; | |
echo "<pre>"; | |
print_r($data); | |
echo "</pre>"; | |
} | |
function bridge($ecode, $data, $server, $port) | |
{ | |
echo "BRIDGE Connect with Operator \n "; | |
$zvonokQilganOdam = $data['CallerID1']; | |
$JavobBerOper = $data['CallerID2']; | |
$sql = "UPDATE `test`.`max_taxi_inccall` | |
SET `status` = '3', `sip_conn_oper` = $JavobBerOper | |
WHERE | |
`caller_phone_num` = '$zvonokQilganOdam' | |
AND | |
`status` = '0'"; | |
$res = mysql_query($sql); | |
} | |
include('phpagi/phpagi.php'); | |
$manager = new AGI_AsteriskManager(); | |
$manager->connect("127.0.0.1:5038", "YOUR_LOGIN", "YOUR_PASSWORD"); | |
$manager->add_event_handler('dial','dial'); | |
$manager->add_event_handler('bridge','bridge'); | |
$manager->add_event_handler('newchannel','dump_events'); | |
$manager->add_event_handler('hangup', 'hangup_handler'); | |
//$manager->add_event_handler('bridge', 'bridge_events'); | |
$manager->wait_response(); | |
$manager->disconnect(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment