2016-12-12 08:30:01 +00:00
|
|
|
#!/usr/bin/php -q
|
|
|
|
<?php
|
|
|
|
|
2018-08-02 11:43:57 +00:00
|
|
|
if (file_exists(__DIR__.'/env.php'))
|
|
|
|
include_once __DIR__.'/env.php';
|
|
|
|
|
|
|
|
require_once 'agi.php';
|
2016-12-12 08:30:01 +00:00
|
|
|
require_once 'vn-autoload.php';
|
|
|
|
|
2018-08-02 11:43:57 +00:00
|
|
|
$app = new Vn\Lib\App('vn-asterisk');
|
|
|
|
$app->init();
|
|
|
|
$db = $app->getSysConn();
|
2016-12-12 08:30:01 +00:00
|
|
|
|
2018-08-02 11:43:57 +00:00
|
|
|
Agi::init();
|
2016-12-12 08:30:01 +00:00
|
|
|
|
|
|
|
// Formats the caller phone number
|
|
|
|
|
2018-08-02 11:43:57 +00:00
|
|
|
$callerId = str_replace('+', '00', Agi::get('agi_callerid'));
|
2016-12-12 08:30:01 +00:00
|
|
|
|
2018-08-02 11:43:57 +00:00
|
|
|
$countryPrefix = $db->getValue('SELECT countryPrefix FROM config');
|
|
|
|
$prefixLen = strlen($countryPrefix);
|
2016-12-12 08:30:01 +00:00
|
|
|
|
2018-08-02 11:43:57 +00:00
|
|
|
if (substr($callerId, 0, $prefixLen) === $countryPrefix)
|
|
|
|
$callerId = substr($callerId, $prefixLen);
|
2016-12-12 08:30:01 +00:00
|
|
|
|
|
|
|
// Checks if phone number is on the blacklist
|
|
|
|
|
2018-08-02 11:43:57 +00:00
|
|
|
if ($db->getValue('SELECT COUNT(*) > 0 FROM blacklist WHERE phone = #', [$callerId])) {
|
|
|
|
Agi::exec('HANGUP');
|
|
|
|
exit;
|
2016-12-12 08:30:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Checks whether its a festive day
|
|
|
|
|
2018-08-02 11:43:57 +00:00
|
|
|
$sundayFestive = $db->getValue('SELECT sundayFestive FROM config');
|
2016-12-12 08:30:01 +00:00
|
|
|
|
2018-08-02 11:43:57 +00:00
|
|
|
if (date('N') == 7 && $sundayFestive) {
|
|
|
|
Agi::exec('SET VARIABLE MACRO playback');
|
|
|
|
Agi::exec('SET VARIABLE ARG1 out-of-ours');
|
|
|
|
exit;
|
2016-12-12 08:30:01 +00:00
|
|
|
}
|
|
|
|
|
2016-12-12 09:21:44 +00:00
|
|
|
// Checks schedules
|
|
|
|
|
2018-08-23 15:19:27 +00:00
|
|
|
$scheduledQueue = $db->getValue(
|
|
|
|
'SELECT `queue` FROM pbx.schedule
|
|
|
|
WHERE `weekDay` = WEEKDAY(CURDATE())
|
2024-03-06 16:50:38 +00:00
|
|
|
AND util.VN_CURTIME() BETWEEN timeStart AND timeEnd
|
2018-08-23 15:19:27 +00:00
|
|
|
LIMIT 1'
|
2016-12-12 09:21:44 +00:00
|
|
|
);
|
|
|
|
|
2018-08-23 15:19:27 +00:00
|
|
|
if ($scheduledQueue) {
|
2018-08-02 11:43:57 +00:00
|
|
|
Agi::exec('SET VARIABLE MACRO queue');
|
2018-08-23 15:19:27 +00:00
|
|
|
Agi::exec("SET VARIABLE ARG1 $scheduledQueue");
|
2018-08-02 11:43:57 +00:00
|
|
|
exit;
|
2016-12-12 09:21:44 +00:00
|
|
|
}
|
|
|
|
|
2024-03-06 16:50:38 +00:00
|
|
|
// Gets the client from the phone number
|
2016-12-12 08:30:01 +00:00
|
|
|
|
2024-03-06 16:50:38 +00:00
|
|
|
$client = $db->getValue('SELECT clientFromPhone(#)', [$callerId]);
|
2016-12-12 08:30:01 +00:00
|
|
|
|
2024-03-06 16:50:38 +00:00
|
|
|
if ($client) {
|
|
|
|
// Gets the client salesperson extension
|
2016-12-12 08:30:01 +00:00
|
|
|
|
2018-08-02 11:43:57 +00:00
|
|
|
$extension = $db->getValue(
|
2024-03-06 16:50:38 +00:00
|
|
|
'SELECT d.pbxQueue
|
2024-03-07 15:57:14 +00:00
|
|
|
FROM vn.client c
|
|
|
|
JOIN vn.worker w ON w.id = c.salesPersonFk
|
2024-03-06 16:50:38 +00:00
|
|
|
JOIN vn.business b ON b.id = w.businessFk
|
|
|
|
JOIN vn.department d ON d.id = b.departmentFk
|
2024-03-07 15:57:14 +00:00
|
|
|
WHERE c.id= #',[$client]
|
2016-12-12 08:30:01 +00:00
|
|
|
);
|
|
|
|
|
2018-08-02 11:43:57 +00:00
|
|
|
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');
|
2016-12-12 08:30:01 +00:00
|
|
|
}
|
|
|
|
}
|