From 8a85fef4992461435321d8892ffb99f47b23cda4 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Mon, 12 Dec 2016 09:30:01 +0100 Subject: [PATCH] Compatible con la ultima version de php-vn-lib --- agi.php | 59 +++++++++++++++++++++++++++++++++++++++++++ env.php | 10 ++++++++ incoming.php | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++ test.txt | 1 + 4 files changed, 141 insertions(+) create mode 100644 agi.php create mode 100644 env.php create mode 100755 incoming.php create mode 100644 test.txt diff --git a/agi.php b/agi.php new file mode 100644 index 0000000..2a88f8e --- /dev/null +++ b/agi.php @@ -0,0 +1,59 @@ + 0) + $result = $match[3]; + return $ret; + } + } + + return -1; + } +} + diff --git a/env.php b/env.php new file mode 100644 index 0000000..cde4c0d --- /dev/null +++ b/env.php @@ -0,0 +1,10 @@ +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'); + } +} + +?> diff --git a/test.txt b/test.txt new file mode 100644 index 0000000..3d268ca --- /dev/null +++ b/test.txt @@ -0,0 +1 @@ +agi_callerid: +34620932003 \ No newline at end of file