Skip to content

Commit

Permalink
3.5.6 --> 3.6.6 Lots of performance changes, new features, bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
blak3r committed Sep 24, 2013
1 parent 76870ab commit 4ce17f0
Show file tree
Hide file tree
Showing 22 changed files with 1,640 additions and 1,331 deletions.
11 changes: 11 additions & 0 deletions RELEASE-NOTES
@@ -1,5 +1,16 @@
IMPORTANT: when upgrading, please see the instructions in the User Manual <http://www.github.com/blak3r/yaai/wiki/User-Manual>

##Version 3.6.0 (2013-07-28)
* Enhancements
** Click To Dial is more intelligent, it always relates call to the record clicked. Before if multiple matching phone numbers, before if phone number matched multiple contacts it showed radio buttons.
** New config option "Max Call Popups" controls the maximum number of popups that will appear on a users screen.
** The 'X' button is easier to click to close call popups.
** (Basic/Pro Only) - Calls to Queues and RingGroups now popup on callee's screen before answering.
* Bug Fixes
** dial_events_log in admin config now works.
** Admin Checkboxes always appeared as checked.


##Version 3.5.4 (2013-07-08)
* New User Interface
* Ability to specify which contact and account phone fields are searched.
Expand Down
782 changes: 491 additions & 291 deletions SugarModules/modules/Asterisk/asteriskLogger.php

Large diffs are not rendered by default.

49 changes: 28 additions & 21 deletions SugarModules/modules/Asterisk/include/AsteriskJS.php
Expand Up @@ -79,20 +79,20 @@ function echoJavaScript() {
echo '<script type="text/javascript">window.callinize_fop_pass = "' . $fop_pass . '";</script>';
echo '<script type="text/javascript">window.callinize_fop_url= "' . $fop_url . '";</script>';
echo '<script type="text/javascript">window.callinize_fop_enabled= ' . $fop_enabled . ';</script>';
echo '<script type="text/javascript">window.callinize_show_transfer_button= ' . $GLOBALS['sugar_config']['asterisk_transfer_button_enabled'] . ';</script>';
echo '<script type="text/javascript">window.callinize_relate_to_account_enabled = ' . $GLOBALS['sugar_config']['asterisk_relate_to_account_enabled'] . ';</script>';
echo '<script type="text/javascript">window.callinize_relate_to_contact_enabled = ' . $GLOBALS['sugar_config']['asterisk_relate_to_contact_enabled'] . ';</script>';
echo '<script type="text/javascript">window.callinize_relate_to_lead_enabled = ' . $GLOBALS['sugar_config']['asterisk_relate_to_lead_enabled'] . ';</script>';
echo '<script type="text/javascript">window.callinize_create_new_contact_enabled = ' . $GLOBALS['sugar_config']['asterisk_create_new_contact_enabled'] . ';</script>';
echo '<script type="text/javascript">window.callinize_create_new_lead_enabled = ' . $GLOBALS['sugar_config']['asterisk_create_new_lead_enabled'] . ';</script>';
echo '<script type="text/javascript">window.callinize_block_button_enabled = ' . $GLOBALS['sugar_config']['asterisk_block_button_enabled'] . ';</script>';
echo '<script type="text/javascript">window.callinize_recording_enabled = ' . $GLOBALS['sugar_config']['asterisk_recordings_enabled'] . ';</script>';
echo '<script type="text/javascript">window.callinize_show_transfer_button= ' . getConfigBool('asterisk_transfer_button_enabled',0) . ';</script>';
echo '<script type="text/javascript">window.callinize_relate_to_account_enabled = ' . getConfigBool('asterisk_relate_to_account_enabled',0) . ';</script>';
echo '<script type="text/javascript">window.callinize_relate_to_contact_enabled = ' . getConfigBool('asterisk_relate_to_contact_enabled',0) . ';</script>';
echo '<script type="text/javascript">window.callinize_relate_to_lead_enabled = ' . getConfigBool('asterisk_relate_to_lead_enabled',0) . ';</script>';
echo '<script type="text/javascript">window.callinize_create_new_contact_enabled = ' . getConfigBool('asterisk_create_new_contact_enabled',0) . ';</script>';
echo '<script type="text/javascript">window.callinize_create_new_lead_enabled = ' . getConfigBool('asterisk_create_new_lead_enabled',0) . ';</script>';
echo '<script type="text/javascript">window.callinize_block_button_enabled = ' . getConfigBool('asterisk_block_button_enabled',0) . ';</script>';
echo '<script type="text/javascript">window.callinize_recording_enabled = ' . getConfigBool('asterisk_recordings_enabled',0) . ';</script>';

echo '<script type="text/javascript"> if (!window.console) console = {log: function() {}}; </script>'; // Prevents bug in IE (See Issue #108)


//JS Third-Party Libraries
if( preg_match("/^6\.[1-4]/",$GLOBALS['sugar_version']) ) {
if( preg_match("/^6\.[1-4]/",$GLOBALS['sugar_version'] && $GLOBALS['sugar_config']['asterisk_jquery_override'] == '0') ) {
echo '<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>';
echo '<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.js" type="text/javascript"></script>';
}
Expand All @@ -102,10 +102,10 @@ function echoJavaScript() {
echo '<script src="custom/modules/Asterisk/include/javascript/offlineMode/handlebars-1.0.rc.1.js"></script>';
$template = file_get_contents( "custom/modules/Asterisk/include/template/call-template.html" );
echo '<script id="handlebars-dev-template" type="text/x-handlebars-template">' . $template . '</script>';
}
else {
echo '<script src="http://cloud.github.com/downloads/wycats/handlebars.js/handlebars.runtime-1.0.rc.1.js"></script>';
}else {
echo '<script src="custom/modules/Asterisk/include/javascript/handlebars.runtime.js"></script>';
echo '<script src="custom/modules/Asterisk/include/template/call-template.tmpl"></script>';

}

echo '<script src="custom/modules/Asterisk/include/javascript/jquery.fancybox.js" type="text/javascript" ></script>';
Expand All @@ -119,16 +119,14 @@ function echoJavaScript() {
echo '<script type="text/javascript" src="custom/modules/Asterisk/include/javascript/dialout.js"></script>';
}

// @@@@ BEGIN CALLINIZE SIP ONLY @@@@
echo '<script type="text/javascript" src="custom/modules/Asterisk/include/javascript/SIPml-api.js"></script>';
echo '<script type="text/javascript" src="custom/modules/Asterisk/include/javascript/sipml-callinize.js"></script>';
// @@@@ END CALLINIZE SIP ONLY @@@@

//CSS Third-Party Libraries
if( $yaaiDevMode ) {
echo '<link rel="stylesheet" href="custom/modules/Asterisk/include/javascript/offlineMode/jquery-ui.css" />';
}else {
echo '<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/redmond/jquery-ui.css" />';
if ($GLOBALS['sugar_config']['asterisk_jquery_override'] == '0') {
if ($callinizeDevMode) {
echo '<link rel="stylesheet" href="custom/modules/Asterisk/include/javascript/offlineMode/jquery-ui.css" />';
} else {

echo '<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/redmond/jquery-ui.css" />';
}
}

echo '<link rel="stylesheet" type="text/css" href="custom/modules/Asterisk/include/css/jquery.fancybox.css" media="screen" />';
Expand All @@ -142,7 +140,16 @@ function echoJavaScript() {
}
}
}
}

function getConfigBool($index,$defaultValue=0) {
//return "1";
if( !empty( $GLOBALS['sugar_config'][$index]) ) {
return $GLOBALS['sugar_config'][$index];
}
else {
return $defaultValue;
}
}

?>
108 changes: 64 additions & 44 deletions SugarModules/modules/Asterisk/include/callCreate.php
@@ -1,41 +1,42 @@
<?php
<?php
/**
* Asterisk SugarCRM Integration
* Asterisk SugarCRM Integration
* (c) KINAMU Business Solutions AG 2009
*
*
* Parts of this code are (c) 2006. RustyBrick, Inc. http://www.rustybrick.com/
* Parts of this code are (c) 2008 vertico software GmbH
* Parts of this code are (c) 2008 vertico software GmbH
* Parts of this code are (c) 2009 abcona e. K. Angelo Malaguarnera E-Mail admin@abcona.de
* http://www.sugarforge.org/projects/yaai/
*
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
*
* You can contact KINAMU Business Solutions AG at office@kinamu.com
*
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
*
*/
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

require_once('include/utils.php');
require_once('include/export_utils.php');
//require_once('callinize_db.php');

global $sugar_config;
global $locale;
Expand Down Expand Up @@ -89,39 +90,40 @@
//format Phone Number
$number = $_REQUEST['phoneNr'];
$prefix = $sugar_config['asterisk_prefix'];
$number = str_replace("+", "00", $number);
$number = str_replace("+1", "", $number);
$number = str_replace(array("(", ")", " ", "-", "/", "."), "", $number);
$number = $prefix.$number;
echo "Originate Params: Number: $number, Channel: $channel, Context: $context, Exten: $number...\n";


$socket = fsockopen($server, $port, $errno, $errstr, 20);

if (!$socket) {
echo "errstr ($errno) <br>\n";

} else {

// $result = ReadResponse($socket);
// echo "AMI Header: " . $result;

// log on to Asterisk
fputs($socket, "Action: Login\r\n");
fputs($socket, "Action: Login\r\n");
fputs($socket, $Username);
fputs($socket, $Secret);
fputs($socket, "Events: off\r\n");
fputs($socket, "\r\n");
fputs($socket, "\r\n");
$result = ReadResponse($socket);
echo("Login Response: " . $result . "\n");


// dial number
fputs($socket, "Action: originate\r\n");
fputs($socket, "Channel: ". $channel ."\r\n");
fputs($socket, "Context: ". $context ."\r\n");
fputs($socket, "Exten: " . $number . "\r\n");
fputs($socket, "Priority: 1\r\n");
fputs($socket, "Callerid:" . $_REQUEST['phoneNr'] ."\r\n");
fputs($socket, "Action: originate\r\n");
fputs($socket, "Channel: ". $channel ."\r\n");
fputs($socket, "Context: ". $context ."\r\n");
fputs($socket, "Exten: " . $number . "\r\n");
fputs($socket, "Priority: 1\r\n");
fputs($socket, "Callerid:" . $_REQUEST['phoneNr'] ."\r\n");
fputs($socket, "Account: CLICKTODIAL-" . formatPhoneNumberToE164($_REQUEST['phoneNr']) . "-" . $_REQUEST['module'] . "-" . $_REQUEST['contactId'] . "\r\n");
fputs($socket, "Variable: CALLERID(number)=" . $extension . "\r\n\r\n");

// You will not get an originate response unless you wait for the phone to be answered... so it's impractical to wait.
Expand All @@ -130,8 +132,8 @@
echo "Originate Response: " . $result . "\n";

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

$result = ReadResponse($socket);
echo("Logout Response: " . $result);

Expand All @@ -142,7 +144,7 @@
//var_dump($context);
//var_dump($number);
//sleep(1);

// close socket
fclose($socket);
}
Expand Down Expand Up @@ -175,21 +177,6 @@ function ReadResponse($socket, $timeout = 500000) {
return $retVal;
}

/**
* Performs an async get request (doesn't wait for response)
* Note: One limitation of this approach is it will not work if server does any URL rewriting
*/
function gitimg_log($event) {
$host = "gitimg.com";
$path = "/rs/track/blak3r/yaai-stats/$event/increment";
$fp = fsockopen($host,80, $errno, $errstr, 30);
$out = "GET " . $path . " HTTP/1.1\r\n";
$out.= "Host: " . $host . "\r\n";
$out.= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
fclose($fp);
}

/**
* Another var_dump() alternative, for debugging use.
*
Expand All @@ -206,18 +193,51 @@ function printr($data, $exit = TRUE) {
// exit;
// }
}

function logLine($str)
{
// print($str);
// print($str);

// if logging is enabled.
if( !empty($sugar_config['asterisk_log_file']) )
if( !empty($sugar_config['asterisk_log_file']) )
{
$myFile = $sugar_config['asterisk_log_file']; // Might be a performance issue being here...
$myFile = $sugar_config['asterisk_log_file']; // Might be a performance issue being here...
$fh = fopen($myFile, 'a') or die("can't open file");
fwrite($fh, $str);
fclose($fh);
}
}

/**
* Helper method for turning any number into an e164 number
*
* @param string $number The number you want to convert
* @return string
*/
function formatPhoneNumberToE164($number) {

// get rid of any non (digit, + character)
$phone = preg_replace('/[^0-9+]/', '', $number);

// validate intl 10
if (preg_match('/^\+([2-9][0-9]{9})$/', $phone, $matches)) {
return "+{$matches[1]}";
}

// validate US DID
if (preg_match('/^\+?1?([2-9][0-9]{9})$/', $phone, $matches)) {
return "+1{$matches[1]}";
}

// validate INTL DID
if (preg_match('/^\+?([2-9][0-9]{8,14})$/', $phone, $matches)) {
return "+{$matches[1]}";
}

// premium US DID
if (preg_match('/^\+?1?([2-9]11)$/', $phone, $matches)) {
return "+1{$matches[1]}";
}
}

?>

0 comments on commit 4ce17f0

Please sign in to comment.