Update incoming.php
gitea/vn-asterisk/pipeline/pr-master There was a failure building this commit
Details
gitea/vn-asterisk/pipeline/pr-master There was a failure building this commit
Details
This commit is contained in:
parent
bce6df9e0e
commit
9e09ce6afc
101
incoming.php
101
incoming.php
|
@ -19,53 +19,55 @@ $countryCode = Agi::get('agi_arg_1');
|
||||||
// Formats the caller phone number
|
// Formats the caller phone number
|
||||||
|
|
||||||
if (preg_match('/^\\+/', $callerId)) {
|
if (preg_match('/^\\+/', $callerId)) {
|
||||||
$callerId = '00'. substr($callerId, 1);
|
$callerId = '00'. substr($callerId, 1);
|
||||||
}
|
}
|
||||||
elseif (!preg_match('/^00/', $callerId) && $countryCode) {
|
elseif (!preg_match('/^00/', $callerId) && $countryCode) {
|
||||||
$prefix = $db->getValue(
|
$prefix = $db->getValue(
|
||||||
'SELECT prefix FROM prefix WHERE country = #',
|
'SELECT prefix FROM prefix WHERE country = #',
|
||||||
[$countryCode]
|
[$countryCode]
|
||||||
);
|
);
|
||||||
if ($prefix)
|
if ($prefix)
|
||||||
$callerId = $prefix . $callerId;
|
$callerId = $prefix . $callerId;
|
||||||
}
|
}
|
||||||
|
|
||||||
$countryPrefix = $db->getValue('SELECT defaultPrefix FROM config');
|
$countryPrefix = $db->getValue('SELECT defaultPrefix FROM config');
|
||||||
$prefixLen = strlen($countryPrefix);
|
$prefixLen = strlen($countryPrefix);
|
||||||
|
|
||||||
if (substr($callerId, 0, $prefixLen) === $countryPrefix)
|
if (substr($callerId, 0, $prefixLen) === $countryPrefix)
|
||||||
$callerId = substr($callerId, $prefixLen);
|
$callerId = substr($callerId, $prefixLen);
|
||||||
|
|
||||||
// Checks if phone number is on the blacklist
|
// Checks if phone number is on the blacklist
|
||||||
|
|
||||||
if ($db->getValue('SELECT COUNT(*) > 0 FROM blacklist WHERE phone = #', [$callerId])) {
|
if ($db->getValue('SELECT COUNT(*) > 0 FROM blacklist WHERE phone = #', [$callerId])) {
|
||||||
Agi::exec('HANGUP');
|
Agi::exec('HANGUP');
|
||||||
exit;
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
// Checks schedules
|
// Checks schedules
|
||||||
|
|
||||||
if ($countryCode) {
|
if ($countryCode) {
|
||||||
$isInSchedule = $db->getValue(
|
$isInSchedule = $db->getValue(
|
||||||
'SELECT COUNT(*) > 0 FROM pbx.schedule
|
'SELECT COUNT(*) > 0 FROM pbx.schedule
|
||||||
WHERE weekDays & (1 << WEEKDAY(CURDATE()))
|
WHERE weekDays & (1 << WEEKDAY(CURDATE()))
|
||||||
AND country = #
|
AND country = #
|
||||||
AND TIME(NOW()) BETWEEN startTime AND endTime',
|
AND TIME(NOW()) BETWEEN startTime AND endTime',
|
||||||
[$countryCode]
|
[$countryCode]
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($isInSchedule) {
|
if ($isInSchedule) {
|
||||||
$isOutOfHours = $db->getValue(
|
$isOutOfHours = $db->getValue(
|
||||||
'SELECT COUNT(*) > 0 FROM pbx.holiday
|
'SELECT COUNT(*) > 0 FROM pbx.holiday
|
||||||
WHERE country = #
|
WHERE country = #
|
||||||
AND `day` = CURDATE()',
|
AND `day` = CURDATE()',
|
||||||
[$countryCode]
|
[$countryCode]
|
||||||
);
|
);
|
||||||
} else
|
} else
|
||||||
$isOutOfHours = true;
|
$isOutOfHours = true;
|
||||||
|
|
||||||
if ($isOutOfHours) {
|
if ($isOutOfHours) {
|
||||||
Agi::exec('SET VARIABLE MACRO out-of-ours');
|
Agi::exec('SET VARIABLE MACRO out-of-ours');
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets the client from the phone number
|
// Gets the client from the phone number
|
||||||
|
@ -73,27 +75,20 @@ if ($countryCode) {
|
||||||
$clientId = $db->getValue('SELECT clientFromPhone(#)', [$callerId]);
|
$clientId = $db->getValue('SELECT clientFromPhone(#)', [$callerId]);
|
||||||
|
|
||||||
if ($clientId) {
|
if ($clientId) {
|
||||||
$client = $db->getObject(
|
$client = $db->getObject(
|
||||||
'SELECT d.pbxQueue, c.id, d.notificationEmail
|
'SELECT d.pbxQueue, c.id, d.notificationEmail
|
||||||
FROM vn.client c
|
FROM vn.client c
|
||||||
JOIN vn.worker w ON w.id = c.salesPersonFk
|
JOIN vn.worker w ON w.id = c.salesPersonFk
|
||||||
JOIN vn.business b ON b.id = w.businessFk
|
JOIN vn.business b ON b.id = w.businessFk
|
||||||
JOIN vn.department d ON d.id = b.departmentFk
|
JOIN vn.department d ON d.id = b.departmentFk
|
||||||
WHERE c.id= #',[$clientId]
|
WHERE c.id= #',[$clientId]
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($client) {
|
if ($client) {
|
||||||
Agi::exec('SET VARIABLE MACRO queue');
|
Agi::exec('SET VARIABLE MACRO queue');
|
||||||
Agi::exec("SET VARIABLE ARG1 \"{$client->pbxQueue}\"");
|
Agi::exec("SET VARIABLE ARG1 \"{$client->pbxQueue}\"");
|
||||||
Agi::exec("SET VARIABLE ARG2 \"Client {$client->id}\"");
|
Agi::exec("SET VARIABLE ARG2 \"Client {$client->id}\"");
|
||||||
Agi::exec("SET VARIABLE ARG3 \"{$client->id}\"");
|
Agi::exec("SET VARIABLE ARG3 \"{$client->id}\"");
|
||||||
Agi::exec("SET VARIABLE ARG4 \"{$client->notificationEmail}\"");
|
Agi::exec("SET VARIABLE ARG4 \"{$client->notificationEmail}\"");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Checks if phone number is on the blacklist
|
|
||||||
|
|
||||||
if ($db->getValue('SELECT COUNT(*) > 0 FROM blacklist WHERE phone = #', [$callerId])) {
|
|
||||||
Agi::exec('HANGUP');
|
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue