Update call_block.php

- Improve the database handling
- Get the country code from the destinations table
This commit is contained in:
FusionPBX
2024-07-25 13:24:40 -06:00
committed by GitHub
parent fcfb22d4a0
commit fa16c8ad7c

View File

@@ -19,6 +19,7 @@ if (!class_exists('call_block')) {
private $uuid_prefix;
private $toggle_field;
private $toggle_values;
private $database;
/**
* declare public variables
@@ -33,6 +34,9 @@ if (!class_exists('call_block')) {
*/
public function __construct() {
//initialize the database
$this->database = new database;
//assign private variables
$this->app_name = 'call_block';
$this->app_uuid = '9ed63276-e085-4897-839c-4f2e36d92d6c';
@@ -84,8 +88,7 @@ if (!class_exists('call_block')) {
$sql .= ") ";
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$rows = $database->select($sql, $parameters, 'all');
$rows = $this->database->select($sql, $parameters, 'all');
if (is_array($rows) && @sizeof($rows) != 0) {
foreach ($rows as $row) {
$call_block_numbers[$row['uuid']] = $row['call_block_number'];
@@ -108,10 +111,9 @@ if (!class_exists('call_block')) {
if (is_array($array) && @sizeof($array) != 0) {
//execute delete
$database = new database;
$database->app_name = $this->app_name;
$database->app_uuid = $this->app_uuid;
$database->delete($array);
$this->database->app_name = $this->app_name;
$this->database->app_uuid = $this->app_uuid;
$this->database->delete($array);
unset($array);
//clear the cache
@@ -160,8 +162,7 @@ if (!class_exists('call_block')) {
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$rows = $database->select($sql, $parameters, 'all');
$rows = $this->database->select($sql, $parameters, 'all');
if (is_array($rows) && @sizeof($rows) != 0) {
foreach ($rows as $row) {
$states[$row['uuid']] = $row['toggle'];
@@ -183,10 +184,9 @@ if (!class_exists('call_block')) {
if (is_array($array) && @sizeof($array) != 0) {
//save the array
$database = new database;
$database->app_name = $this->app_name;
$database->app_uuid = $this->app_uuid;
$database->save($array);
$this->database->app_name = $this->app_name;
$this->database->app_uuid = $this->app_uuid;
$this->database->save($array);
unset($array);
//clear the cache
@@ -238,8 +238,7 @@ if (!class_exists('call_block')) {
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$rows = $database->select($sql, $parameters, 'all');
$rows = $this->database->select($sql, $parameters, 'all');
if (is_array($rows) && @sizeof($rows) != 0) {
foreach ($rows as $x => $row) {
@@ -259,10 +258,9 @@ if (!class_exists('call_block')) {
if (is_array($array) && @sizeof($array) != 0) {
//save the array
$database = new database;
$database->app_name = $this->app_name;
$database->app_uuid = $this->app_uuid;
$database->save($array);
$this->database->app_name = $this->app_name;
$this->database->app_uuid = $this->app_uuid;
$this->database->save($array);
unset($array);
//set message
@@ -303,13 +301,37 @@ if (!class_exists('call_block')) {
}
}
//get the caller id info from cdrs
//get the caller id info from call detail records
if (is_array($uuids) && @sizeof($uuids) != 0) {
$sql = "select caller_id_name, caller_id_number, caller_destination from v_xml_cdr ";
$sql .= "where xml_cdr_uuid in (".implode(', ', $uuids).") ";
$database = new database;
$rows = $database->select($sql, $parameters ?? null, 'all');
unset($sql);
$rows = $this->database->select($sql, $parameters ?? null, 'all');
unset($sql, $parameters);
}
//get the caller id info from call detail records
if (isset($_SESSION['domain_uuid']) && is_uuid($_SESSION['domain_uuid'])) {
//get the destination country code
$sql = "select distinct(destination_prefix), ";
$sql .= "(select count(destination_prefix) from v_destinations where domain_uuid = :domain_uuid and destination_prefix = d.destination_prefix) as count ";
$sql .= "from v_destinations as d ";
$sql .= "where domain_uuid = :domain_uuid ";
$sql .= "and destination_prefix <> '' ";
$sql .= "order by count desc limit 1; ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$destination_country_code = $this->database->select($sql, $parameters ?? null, 'column');
unset($sql, $parameters);
//use the the destination country code to set the country code
if (!empty($destination_country_code)) {
$destination_country_code = trim($destination_country_code, "+ ");
$country_code = $destination_country_code;
}
}
//get the country code from default settings
if (!empty($_SESSION['domain']['country_code']['numeric'])) {
$country_code = $_SESSION['domain']['country_code']['numeric'];
}
//loop through records
@@ -328,14 +350,14 @@ if (!class_exists('call_block')) {
//remove e.164 and country code
if (trim($row["caller_id_number"])[0] == "+") {
//format e.164
$call_block_number = str_replace("+".trim($_SESSION['domain']['country_code']['numeric']), "", trim($row["caller_id_number"]));
$call_block_number = str_replace("+".trim($country_code), "", trim($row["caller_id_number"]));
}
else {
//remove the country code if its the first in the string
$call_block_number = ltrim(trim($row["caller_id_number"]), $_SESSION['domain']['country_code']['numeric'] ?? '');
$call_block_number = ltrim(trim($row["caller_id_number"]), $country_code ?? '');
}
//build the array
$array['call_block'][$x]['call_block_country_code'] = trim($_SESSION['domain']['country_code']['numeric'] ?? '');
$array['call_block'][$x]['call_block_country_code'] = trim($country_code ?? '');
$array['call_block'][$x]['call_block_name'] = '';
$array['call_block'][$x]['call_block_number'] = $call_block_number;
$array['call_block'][$x]['call_block_description'] = trim($row["caller_id_name"]);
@@ -393,8 +415,7 @@ if (!class_exists('call_block')) {
$sql .= "and app_uuid = '".$this->app_uuid."' ";
$sql .= "and dialplan_enabled <> 'true' ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$rows = $database->select($sql, $parameters);
$rows = $this->database->select($sql, $parameters);
if (is_array($rows) && @sizeof($rows) != 0) {
foreach ($rows as $x => $row) {
$array['dialplans'][$x]['dialplan_uuid'] = $row['dialplan_uuid'];
@@ -408,11 +429,10 @@ if (!class_exists('call_block')) {
$p->add('dialplan_edit', 'temp');
//save the array
$database = new database;
$database->app_name = $this->app_name;
$database->app_uuid = $this->app_uuid;
$database->save($array);
$response = $database->message;
$this->database->app_name = $this->app_name;
$this->database->app_uuid = $this->app_uuid;
$this->database->save($array);
$response = $this->database->message;
unset($array);
//revoke temporary permissions
@@ -431,4 +451,4 @@ if (!class_exists('call_block')) {
} //class
}
?>
?>