Compatible con la ultima version de php-vn-lib
This commit is contained in:
parent
fea94df0f3
commit
8a85fef499
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
class Agi
|
||||
{
|
||||
private static $initialized = FALSE;
|
||||
private static $agivars = array ();
|
||||
|
||||
static function init ()
|
||||
{
|
||||
if (self::$initialized)
|
||||
return;
|
||||
|
||||
self::$initialized = TRUE;
|
||||
pcntl_signal (SIGHUP, SIG_IGN);
|
||||
pcntl_signal (SIGTERM, SIG_IGN);
|
||||
|
||||
while (!feof (STDIN))
|
||||
{
|
||||
$agivar = trim (fgets (STDIN, 4096));
|
||||
$agivar = explode (':', $agivar);
|
||||
|
||||
if (count($agivar) == 2)
|
||||
self::$agivars[$agivar[0]] = trim ($agivar[1]);
|
||||
}
|
||||
}
|
||||
|
||||
static function get ($agivar)
|
||||
{
|
||||
if (self::$initialized && isset (self::$agivars[$agivar]))
|
||||
return self::$agivars[$agivar];
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static function exec ($cmd, &$result = NULL)
|
||||
{
|
||||
if (!self::$initialized)
|
||||
return -1;
|
||||
|
||||
fwrite (STDOUT, "$cmd\n");
|
||||
fflush (STDOUT);
|
||||
|
||||
$res = trim (fgets (STDIN, 4096));
|
||||
|
||||
if (preg_match ("/^([0-9]{1,3}) (.*)/", $res, $matches))
|
||||
{
|
||||
if (preg_match ('/^result=([0-9\-]*)( ?\((.*)\))?$/', $matches[2], $match))
|
||||
{
|
||||
$ret = (int) $match[1];
|
||||
if ($num > 0)
|
||||
$result = $match[3];
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
require_once (__DIR__.'/../php-vn-lib/env.php');
|
||||
|
||||
set_include_path (__DIR__.PATH_SEPARATOR.get_include_path ());
|
||||
|
||||
const _DEV_MODE = TRUE;
|
||||
const _CONFIG_DIR = __DIR__.'/../../.config';
|
||||
const _LOG_DIR = '/tmp';
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
#!/usr/bin/php -q
|
||||
<?php
|
||||
|
||||
require_once ('agi.php');
|
||||
@include_once __DIR__.'/env.php';
|
||||
require_once 'vn-autoload.php';
|
||||
|
||||
$app = new Vn\Lib\App ('vn-asterisk');
|
||||
$app->init ();
|
||||
$db = $app->getSysConn ();
|
||||
|
||||
Agi::init ();
|
||||
|
||||
// Formats the caller phone number
|
||||
|
||||
$callerId = str_replace ('+', '00', Agi::get ('agi_callerid'));
|
||||
|
||||
$countryPrefix = $db->getValue ('SELECT countryPrefix FROM config');
|
||||
$prefixLen = strlen ($countryPrefix);
|
||||
|
||||
if (substr ($callerId, 0, $prefixLen) === $countryPrefix)
|
||||
$callerId = substr ($callerId, $prefixLen);
|
||||
|
||||
// Checks if phone number is on the blacklist
|
||||
|
||||
if ($db->getValue ('SELECT COUNT(*) > 0 FROM blacklist WHERE phone = #', [$callerId]))
|
||||
{
|
||||
Agi::exec ('HANGUP');
|
||||
exit ();
|
||||
}
|
||||
|
||||
// Checks whether its a festive day
|
||||
|
||||
$sundayFestive = $db->getValue ('SELECT sundayFestive FROM config');
|
||||
|
||||
if (date ('N') == 7 && $sundayFestive)
|
||||
{
|
||||
Agi::exec ('SET VARIABLE MACRO playback');
|
||||
Agi::exec ('SET VARIABLE ARG1 out-of-ours');
|
||||
exit ();
|
||||
}
|
||||
|
||||
// Gets the customer from the phone number
|
||||
|
||||
$customer = $db->getValue ('SELECT clientFromPhone(#)', [$callerId]);
|
||||
|
||||
if ($customer)
|
||||
{
|
||||
// Gets the customer salesperson extension
|
||||
|
||||
$extension = $db->getValue (
|
||||
'SELECT s.extension
|
||||
FROM sip s
|
||||
JOIN vn2008.Trabajadores t ON t.user_id = s.user_id
|
||||
WHERE t.id_trabajador = vn2008.Averiguar_ComercialCliente_Id(#, CURDATE())'
|
||||
,[$customer]
|
||||
);
|
||||
|
||||
if ($extension)
|
||||
{
|
||||
Agi::exec ('SET VARIABLE MACRO exten');
|
||||
Agi::exec ("SET VARIABLE ARG1 $extension");
|
||||
}
|
||||
else
|
||||
{
|
||||
Agi::exec ('SET VARIABLE MACRO playback');
|
||||
Agi::exec ('SET VARIABLE ARG1 busy');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in New Issue