Ok this is how we do it.
[code]//create a new socket
$sock = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
//set timeout to 1 second
socket_set_option($sock, SOL_SOCKET, SO_RCVTIMEO, array(“sec” => 1, “usec” => 0));
socket_connect($sock,‘127.0.0.1’,5038);
$loginMessage = “Action: Login\r\nUsername: USERNAME\r\nSecret: PASSWORD\r\n\r\n”;
socket_write($sock,$loginMessage);
$authed = false;
while($line = @socket_read($sock, 255)) {
if(eregi(“Response: Success”,$line)){
$authed = true;
}
}
//if we are allowed to send commands to asterisk, then go
if($authed){
if($action == “dial” && isset($agent) && isset($destnum)){
//make the call
//tms bit
//
$reference = $_REQUEST['reference'];
$file = explode("_", $reference);
$datestamp = date(YmdHis , $file[2]);
$tmsfname = "$file[0]$datestamp";
$context = $_REQUEST['account'];
//
originate_call($sock,$agent,$context,$destnum,$tmsfname);
//wait for a response
$result = wait_for_response($sock);
//echo $result;
//break the result down into an array
$resArray = explode("\n",$result);
$tmpArr = split(":",$resArray[122]);
$tmpSIPArr = split(":",$resArray[128]);
[/code]
[code]//function to make a call
function originate_call(&$sock,$agent,$context,$destnum,$destname,$fname = NULL){
//
$reference = $REQUEST[‘reference’];
//bit to check if variable passed
if(isset($reference)){
// echo “$reference”;
}else{
$date = date(U);
$reference = "10000_001$date";
// echo “$reference”;
}
//
//
$chancon = “click2call”;
$consuff = “click2callout”;
$file = explode(".", $reference);
$datestamp = date(YmdHis , $file[2]);
$tmsfname = “$file[0]”;
//
echo $context;
echo $tmsfname;
echo “Channel: Local/$agent@$context$chancon\r\n”;
echo “Context: $context$consuff\r\n”;
// echo “in the orinate”;
// echo “$tmsfname”;
$destname = ‘“Outbound” <’.$agent.’>’;
if(!$destname) $destname = $destnum;
$callStr = “Action: Originate\r\n”;
$callStr .= “Channel: Local/$agent@$context$chancon\r\n”;
$callStr .= “Exten: $destnum\r\n”;
$callStr .= “Priority: 1\r\n”;
$callStr .= “Async: True\r\n”;
$callStr .= “Context: $context$consuff\r\n”;
$callStr .= “CallerID: $destname\r\n”;
$callStr .= “Variable: tmsfile=$fname|dialer=yes|\r\n”;
$callStr .= “\r\n”;
socket_write($sock,$callStr);
}
socket_close($sock);
[/code]