feat(pbx): refs #7198 country prefix, schedule
gitea/vn-asterisk/pipeline/head This commit looks good
Details
gitea/vn-asterisk/pipeline/head This commit looks good
Details
This commit is contained in:
parent
dce4afcf0d
commit
04e7964493
|
@ -1,4 +1,4 @@
|
|||
vn-asterisk (1.1.10) stable; urgency=low
|
||||
vn-asterisk (1.1.11) stable; urgency=low
|
||||
|
||||
* Initial Release.
|
||||
|
||||
|
|
96
incoming.php
96
incoming.php
|
@ -2,8 +2,7 @@
|
|||
<?php
|
||||
|
||||
if (file_exists(__DIR__.'/env.php'))
|
||||
include_once __DIR__.'/env.php';
|
||||
|
||||
include_once __DIR__.'/env.php';
|
||||
require_once 'agi.php';
|
||||
require_once 'vn-autoload.php';
|
||||
|
||||
|
@ -13,69 +12,76 @@ $db = $app->getSysConn();
|
|||
|
||||
Agi::init();
|
||||
|
||||
// http://www.asteriskdocs.org/en/3rd_Edition/asterisk-book-html-chunk/AGI-communication.html
|
||||
$callerId = Agi::get('agi_callerid');
|
||||
$countryCode = Agi::get('agi_arg_1');
|
||||
|
||||
// Formats the caller phone number
|
||||
|
||||
$callerId = str_replace('+', '00', Agi::get('agi_callerid'));
|
||||
if (preg_match('/^\\+/', $callerId)) {
|
||||
$callerId = '00'. substr($callerId, 1);
|
||||
}
|
||||
elseif (!preg_match('/^00/', $callerId)) {
|
||||
$prefix = $db->getValue(
|
||||
'SELECT prefix FROM prefix WHERE country = #',
|
||||
[$countryCode]
|
||||
);
|
||||
if ($prefix)
|
||||
$callerId = $prefix . $callerId;
|
||||
}
|
||||
|
||||
$countryPrefix = $db->getValue('SELECT countryPrefix FROM config');
|
||||
$countryPrefix = $db->getValue('SELECT defaultPrefix 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;
|
||||
}
|
||||
|
||||
// Checks schedules
|
||||
|
||||
$scheduledQueue = $db->getValue(
|
||||
'SELECT `queue` FROM pbx.schedule
|
||||
WHERE `weekDay` = WEEKDAY(CURDATE())
|
||||
AND util.VN_CURTIME() BETWEEN timeStart AND timeEnd
|
||||
LIMIT 1'
|
||||
);
|
||||
if ($countryCode) {
|
||||
$isInSchedule = $db->getValue(
|
||||
'SELECT COUNT(*) > 0 FROM pbx.schedule
|
||||
WHERE weekDays & (1 << WEEKDAY(CURDATE()))
|
||||
AND country = #
|
||||
AND TIME(NOW()) BETWEEN startTime AND endTime',
|
||||
[$countryCode]
|
||||
);
|
||||
|
||||
if ($scheduledQueue) {
|
||||
Agi::exec('SET VARIABLE MACRO queue');
|
||||
Agi::exec("SET VARIABLE ARG1 $scheduledQueue");
|
||||
if ($isInSchedule) {
|
||||
$isOutOfHours = $db->getValue(
|
||||
'SELECT COUNT(*) > 0 FROM pbx.holiday
|
||||
WHERE country = #
|
||||
AND `day` = CURDATE()',
|
||||
[$countryCode]
|
||||
);
|
||||
} else
|
||||
$isOutOfHours = true;
|
||||
}
|
||||
|
||||
if ($isOutOfHours) {
|
||||
Agi::exec("SET VARIABLE MACRO $countryCode-out-of-ours");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Gets the client from the phone number
|
||||
|
||||
$client = $db->getValue('SELECT clientFromPhone(#)', [$callerId]);
|
||||
$clientId = $db->getValue('SELECT clientFromPhone(#)', [$callerId]);
|
||||
|
||||
if ($client) {
|
||||
// Gets the client salesperson extension
|
||||
|
||||
$extension = $db->getValue(
|
||||
'SELECT d.pbxQueue
|
||||
if ($clientId) {
|
||||
$client = $db->getObject(
|
||||
'SELECT d.pbxQueue, c.id, d.notificationEmail
|
||||
FROM vn.client c
|
||||
JOIN vn.worker w ON w.id = c.salesPersonFk
|
||||
JOIN vn.business b ON b.id = w.businessFk
|
||||
JOIN vn.department d ON d.id = b.departmentFk
|
||||
WHERE c.id= #',[$client]
|
||||
JOIN vn.business b ON b.id = w.businessFk
|
||||
JOIN vn.department d ON d.id = b.departmentFk
|
||||
WHERE c.id= #',[$clientId]
|
||||
);
|
||||
|
||||
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');
|
||||
if ($client) {
|
||||
Agi::exec('SET VARIABLE MACRO queue');
|
||||
Agi::exec("SET VARIABLE ARG1 \"{$client->pbxQueue}\"");
|
||||
Agi::exec("SET VARIABLE ARG2 \"Client {$client->id}\"");
|
||||
Agi::exec("SET VARIABLE ARG3 \"{$client->id}\"");
|
||||
Agi::exec("SET VARIABLE ARG4 \"{$client->notificationEmail}\"");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue