Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions asterisk_c2c.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php

include ("include/dbconnect.php");

if (!$asterisk_integration) {
die();
}


//get the user
$username = $login->getUser()->getName();

//find the extension from th db
$user_q = mysql_query("
SELECT phone FROM users WHERE username = '{$username}'
");

$extensionrow = mysql_fetch_array($user_q);
if (is_array($extensionrow)) {

//get the config file
require("config/cfg.asterisk.php");



$a_number = $extensionrow['phone'];
$b_number = preg_replace("/[^a-zA-Z0-9]/", "", $_GET['b_number']);


#$a_context = "from-internal";
$b_context = "from-internal";

#specify the amount of time you want to try calling the specified channel before hangin up
$wait_time = "30";
$timeout = $wait_time * 1000;

#specify the priority you wish to place on making this call
$priority = "1";


$errno=0 ;
$errstr=0 ;

//$caller_id = "$b_number";
$caller_id = $a_number;


$oSocket = fsockopen ($asterisk_ami_host, $asterisk_ami_port, $errno, $errstr, 20);
if (!$oSocket)
{
echo "Error: Cannot connect to asterisk ami $errstr ($errno)<br>\n";
}
else
{



fputs($oSocket, "Action: login\r\n");
fputs($oSocket, "Events: off\r\n");
fputs($oSocket, "Username: $asterisk_ami_user\r\n");
fputs($oSocket, "Secret: $asterisk_ami_pass\r\n\r\n");
fputs($oSocket, "Action: originate\r\n");

fputs($oSocket, "Channel: SIP/$a_number\r\n");
#fputs($oSocket, "Channel: Local/00{$a_number}@{$a_context}\r\n");
fputs($oSocket, "WaitTime: $wait_time\r\n");
fputs($oSocket, "Timeout: $timeout\r\n");
fputs($oSocket, "CallerId: $caller_id\r\n");
fputs($oSocket, "Exten: $b_number\r\n");
fputs($oSocket, "Context: $b_context\r\n");
fputs($oSocket, "Priority: $priority\r\n\r\n");

//$returnn = fgets($oSocket);

/*
$returnn = fgets($oSocket);
//echo $returnn."\n";
$returnn = fgets($oSocket);
//echo $returnn."\n";
$returnn = fgets($oSocket);
//echo $returnn."\n";
$returnn = fgets($oSocket);
//echo $returnn."\n";
$returnn = fgets($oSocket);
if ($returnn == "Response: Success\r\n")
{
////echo $returnn;
echo "OK\n";
$sent_ok = true;
break;
}
#echo $returnn."<br>";
#$returnn = fgets($oSocket);
#echo $returnn."<br>";


//echo $returnn."<br>";

*/

fputs($oSocket, "Action: Logoff\r\n\r\n");


//sleep(1);
usleep(15000);
fclose($oSocket);


echo "OK";
}



}
9 changes: 9 additions & 0 deletions config/cfg.asterisk.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

// Asterisk AMI manager for click to call

$asterisk_ami_host = 'localhost';
$asterisk_ami_port = 5038;
$asterisk_ami_user = 'admin';
$asterisk_ami_pass = 'amipassword';

5 changes: 4 additions & 1 deletion config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,7 @@
// Disable HTTP-Compression with 0
$compression_level = 2;

?>
// Asterisk integration
$asterisk_integration = true;

?>
Binary file added icons/phone_sound.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/phonecall.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 14 additions & 2 deletions include/view.w.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ function add($value, $prefix = "") {

function addPhone($phone, $prefix = "") {

global $default_provider, $providers;
global $default_provider, $providers, $asterisk_integration;

//var to save the original phone before lookups
$inphone = $phone;

if($phone != "" && !isset($_GET["print"]) && isset($providers)) {

Expand All @@ -34,6 +37,15 @@ function addPhone($phone, $prefix = "") {
if(count($links) > 1) {
$phone .= " (".implode(", ", $links).")";
}


if ($asterisk_integration) {
//asterisk click to call integration - inline background request
$phone .= " <a href=\"#\" onClick=\"javascript: var xmlHttp = null; xmlHttp = new XMLHttpRequest(); xmlHttp.open( 'GET', 'asterisk_c2c.php?b_number=$inphone', false ); xmlHttp.send( null ); return false;\" >";
$phone .= "<img src=\"icons/phonecall.png\" >";
$phone .= "</a>";
}

}
return add($phone, $prefix);
}
Expand Down Expand Up @@ -198,4 +210,4 @@ function showOneEntry($r, $only_phone = false) {
*/
}
}
?>
?>
28 changes: 25 additions & 3 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@

function addRow($row) {

global $addr, $page_ext_qry, $url_images, $read_only, $map_guess, $full_phone, $homepage_guess;
global $addr, $page_ext_qry, $url_images, $read_only, $map_guess, $full_phone, $homepage_guess, $asterisk_integration;

$myrow = $addr->getData();

Expand Down Expand Up @@ -171,7 +171,29 @@ function addRow($row) {
break;
case "all_phones":
$phones = $addr->shortPhones();
echo "<td>".implode("<br>", $phones)."</td>";

echo "<td>";

if(is_array($phones)) {
foreach($phones as $key => $value) {

echo $value;

if ($asterisk_integration) {

//inline background request - click to call
echo " <a href=\"#\" onClick=\"javascript: var xmlHttp = null; xmlHttp = new XMLHttpRequest(); xmlHttp.open( 'GET', 'asterisk_c2c.php?b_number=$value', false ); xmlHttp.send( null ); return false;\" >";

echo "<img src=\"icons/phonecall.png\" >";
echo "</a>";

}

echo "<br />";
}
}
echo "</td>";

break;
case "all_emails":
$emails = $addr->getEMails();
Expand Down Expand Up @@ -473,4 +495,4 @@ function filterResults(field) {
//-->
</script>
<?php include("include/footer.inc.php"); ?>
<script type="text/javascript" src="js/tablesort.min.js"></script>
<script type="text/javascript" src="js/tablesort.min.js"></script>
Binary file modified translations/LOCALES/sl/LC_MESSAGES/php-addressbook.mo
Binary file not shown.
Loading