2016-12-12 08:30:01 +00:00
|
|
|
#!/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 ();
|
|
|
|
}
|
|
|
|
|
2016-12-12 09:21:44 +00:00
|
|
|
// Checks schedules
|
|
|
|
|
|
|
|
$hasSchedule = $db->getValue (
|
|
|
|
'SELECT COUNT(*) > 0 FROM pbx.schedule
|
|
|
|
WHERE weekDay = WEEKDAY(CURDATE())
|
|
|
|
AND CURTIME() BETWEEN timeStart AND timeEnd'
|
|
|
|
);
|
|
|
|
|
|
|
|
if ($hasSchedule)
|
|
|
|
{
|
|
|
|
Agi::exec ('SET VARIABLE MACRO queue');
|
|
|
|
Agi::exec ('SET VARIABLE ARG1 1200');
|
|
|
|
exit ();
|
|
|
|
}
|
|
|
|
|
2016-12-12 08:30:01 +00:00
|
|
|
// 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');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|