Call Block Update

- unify the process for preparing the call_block_number
- move the query for user_extensions outside and before the loop
- database used more efficiently
This commit is contained in:
FusionPBX 2024-07-26 14:33:50 -06:00 committed by GitHub
parent 9ace83cad1
commit cdc8a8842c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 35 additions and 45 deletions

View File

@ -17,7 +17,7 @@
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2023
Portions created by the Initial Developer are Copyright (C) 2008-2024
the Initial Developer. All Rights Reserved.
Contributor(s):
@ -40,6 +40,9 @@
$language = new text;
$text = $language->get();
//initialize the database object
$database = new database;
//set the defaults
$call_block_name = '';
$call_block_country_code = '';
@ -155,7 +158,6 @@
if (!empty($domain_uuid) && is_uuid($domain_uuid)) {
$parameters['domain_uuid'] = $domain_uuid;
}
$database = new database;
$rows = $database->select($sql, $parameters);
if (!empty($rows)) {
@ -167,7 +169,6 @@
$p = new permissions;
$p->add('dialplan_edit', 'temp');
$database = new database;
$database->save($array);
unset($array);
@ -198,11 +199,9 @@
$array['call_block'][0]['date_added'] = time();
$array['call_block'][0]['call_block_description'] = $call_block_description;
$database = new database;
$database->app_name = 'call_block';
$database->app_uuid = '9ed63276-e085-4897-839c-4f2e36d92d6c';
$database->save($array);
$response = $database->message;
unset($array);
message::add($text['label-add-complete']);
@ -225,7 +224,6 @@
$sql .= "and c.call_block_uuid = :call_block_uuid ";
}
$parameters['call_block_uuid'] = $call_block_uuid;
$database = new database;
$result = $database->select($sql, $parameters);
if (!empty($result)) {
//set the domain_name
@ -252,11 +250,9 @@
$array['call_block'][0]['date_added'] = time();
$array['call_block'][0]['call_block_description'] = $call_block_description;
$database = new database;
$database->app_name = 'call_block';
$database->app_uuid = '9ed63276-e085-4897-839c-4f2e36d92d6c';
$database->save($array);
$response = $database->message;
unset($array);
message::add($text['label-update-complete']);
@ -279,7 +275,6 @@
$sql .= "and call_block_uuid = :call_block_uuid ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$parameters['call_block_uuid'] = $call_block_uuid;
$database = new database;
$row = $database->select($sql, $parameters, 'row');
if (!empty($row)) {
$domain_uuid = $row["domain_uuid"];
@ -311,7 +306,6 @@
$sql .= "and enabled = 'true' ";
$sql .= "order by extension asc ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$extensions = $database->select($sql, $parameters);
}
@ -327,7 +321,6 @@ if (permission_exists('call_block_all') || permission_exists('call_block_ivr'))
// $sql .= "and enabled = 'true' ";
$sql .= "order by ivr_menu_extension asc ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$ivrs = $database->select($sql, $parameters);
}
@ -343,7 +336,6 @@ if (permission_exists('call_block_all') || permission_exists('call_block_ring_gr
// $sql .= "and ring_group_enabled = 'true' ";
$sql .= "order by ring_group_extension asc ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$ring_groups = $database->select($sql, $parameters);
}
@ -359,7 +351,6 @@ if (permission_exists('call_block_all') || permission_exists('call_block_ring_gr
$sql .= "and voicemail_enabled = 'true' ";
$sql .= "order by voicemail_id asc ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$voicemails = $database->select($sql, $parameters);
//create token
@ -630,7 +621,7 @@ if (permission_exists('call_block_all') || permission_exists('call_block_ring_gr
}
}
//get recent calls
//get the recent calls
$sql = "select caller_id_name, caller_id_number, caller_destination, start_epoch, direction, hangup_cause, duration, billsec, xml_cdr_uuid ";
$sql .= "from v_xml_cdr where domain_uuid = :domain_uuid ";
$sql .= "and direction <> 'local' ";
@ -638,8 +629,7 @@ if (permission_exists('call_block_all') || permission_exists('call_block_ring_gr
$sql .= "order by start_stamp desc ";
$sql .= limit_offset($_SESSION['call_block']['recent_call_limit']['text']);
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$result = $database->select($sql, $parameters);
$recent_calls = $database->select($sql, $parameters);
unset($sql, $parameters);
echo "<form id='form_list' method='post'>\n";
@ -656,7 +646,7 @@ if (permission_exists('call_block_all') || permission_exists('call_block_ring_gr
echo " </div>\n";
echo " <div class='actions'>\n";
echo button::create(['type'=>'button','id'=>'action_bar_sub_button_back','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'collapse'=>'hide-xs','style'=>'display: none;','link'=>'call_block.php']);
if ($result) {
if ($recent_calls) {
$select_margin = 'margin-left: 15px;';
if (permission_exists('call_block_extension')) {
echo "<select class='formfld' style='".$select_margin."' name='extension_uuid'>\n";
@ -678,7 +668,7 @@ if (permission_exists('call_block_all') || permission_exists('call_block_ring_gr
echo " <div style='clear: both;'></div>\n";
echo "</div>\n";
if ($result) {
if ($recent_calls) {
echo modal::create(['id'=>'modal-block','type'=>'general','message'=>$text['confirm-block'],'actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_block','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_form_submit('form_list');"])]);
}
@ -691,13 +681,13 @@ if (permission_exists('call_block_all') || permission_exists('call_block_ring_gr
echo "<th style='width: 1%;'>&nbsp;</th>\n";
echo th_order_by('caller_id_name', $text['label-name'], $order_by, $order);
echo th_order_by('caller_id_number', $text['label-number'], $order_by, $order);
echo th_order_by('caller_id_number', $text['label-destination'], $order_by, $order);
echo th_order_by('caller_destination', $text['label-destination'], $order_by, $order);
echo th_order_by('start_stamp', $text['label-called'], $order_by, $order);
echo th_order_by('duration', $text['label-duration'], $order_by, $order, null, "class='right hide-sm-dn'");
echo "</tr>";
if (!empty($result)) {
foreach ($result as $x => $row) {
if (!empty($recent_calls)) {
foreach ($recent_calls as $x => $row) {
if ($row['direction'] == $direction) {
$list_row_onclick_uncheck = "if (!this.checked) { document.getElementById('checkbox_all_".$direction."').checked = false; }";
$list_row_onclick_toggle = "onclick=\"document.getElementById('checkbox_".$x."').checked = document.getElementById('checkbox_".$x."').checked ? false : true; ".$list_row_onclick_uncheck."\"";
@ -761,7 +751,6 @@ if (permission_exists('call_block_all') || permission_exists('call_block_ring_gr
}
echo "</table>\n";
}
unset($result);
echo "<br />\n";
echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";

View File

@ -317,6 +317,7 @@ if (!class_exists('call_block')) {
$sql .= "from v_destinations as d ";
$sql .= "where domain_uuid = :domain_uuid ";
$sql .= "and destination_prefix <> '' ";
$sql .= "and destination_enabled = 'true' ";
$sql .= "order by count desc limit 1; ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$destination_country_code = $this->database->select($sql, $parameters ?? null, 'column');
@ -329,6 +330,15 @@ if (!class_exists('call_block')) {
}
}
//get the users that are assigned to the extension
if (!permission_exists('call_block_extension')) {
$sql = "select extension_uuid from v_extension_users ";
$sql .= "where user_uuid = :user_uuid ";
$parameters['user_uuid'] = $_SESSION['user_uuid'];
$user_extensions = $this->database->select($sql, $parameters ?? null, 'all');
unset($sql, $parameters);
}
//get the country code from default settings
if (!empty($_SESSION['domain']['country_code']['numeric'])) {
$country_code = $_SESSION['domain']['country_code']['numeric'];
@ -338,6 +348,19 @@ if (!class_exists('call_block')) {
if (is_array($rows) && @sizeof($rows) != 0) {
foreach ($rows as $x => $row) {
//remove e.164 and country code
if (substr($row["caller_id_number"],0,1) == "+") {
//format e.164
$call_block_number = str_replace("+".trim($country_code), "", trim($row["caller_id_number"]));
}
elseif (!empty($row["caller_id_number"])) {
//remove the country code if its the first in the string
$call_block_number = ltrim(trim($row["caller_id_number"]), $country_code ?? '');
}
else {
$call_block_number = '';
}
//build insert array
if (permission_exists('call_block_extension')) {
$array['call_block'][$x]['call_block_uuid'] = uuid();
@ -347,16 +370,6 @@ if (!class_exists('call_block')) {
$array['call_block'][$x]['extension_uuid'] = $this->extension_uuid;
}
if ($this->call_block_direction == 'inbound') {
//remove e.164 and country code
if (trim($row["caller_id_number"])[0] == "+") {
//format e.164
$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"]), $country_code ?? '');
}
//build the array
$array['call_block'][$x]['call_block_name'] = '';
$array['call_block'][$x]['call_block_country_code'] = trim($country_code ?? '');
$array['call_block'][$x]['call_block_number'] = $call_block_number;
@ -373,14 +386,6 @@ if (!class_exists('call_block')) {
$x++;
}
else {
//get the users that are assigned to the extension
$sql = "select extension_uuid from v_extension_users ";
$sql .= "where user_uuid = :user_uuid ";
$parameters['user_uuid'] = $_SESSION['user_uuid'];
$user_extensions = $this->database->select($sql, $parameters ?? null, 'all');
unset($sql, $parameters);
if (is_array($user_extensions)) {
foreach ($user_extensions as $field) {
if (is_uuid($field['extension_uuid'])) {
@ -389,10 +394,6 @@ if (!class_exists('call_block')) {
$array['call_block'][$x]['call_block_direction'] = $this->call_block_direction;
$array['call_block'][$x]['extension_uuid'] = $field['extension_uuid'];
if ($this->call_block_direction == 'inbound') {
//remove e.164 and country code
$call_block_number = str_replace("+".trim($country_code), "", trim($row["caller_id_number"]));
//build the array
$array['call_block'][$x]['call_block_name'] = '';
$array['call_block'][$x]['call_block_country_code'] = trim($country_code ?? '');
$array['call_block'][$x]['call_block_number'] = $call_block_number;
@ -460,4 +461,4 @@ if (!class_exists('call_block')) {
} //class
}
?>
?>