diff --git a/app/call_block/call_block_edit.php b/app/call_block/call_block_edit.php index 9f266d6210..d972904d5e 100644 --- a/app/call_block/call_block_edit.php +++ b/app/call_block/call_block_edit.php @@ -17,7 +17,7 @@ The Initial Developer of the Original Code is Mark J Crane - 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 "
\n"; @@ -656,7 +646,7 @@ if (permission_exists('call_block_all') || permission_exists('call_block_ring_gr echo " \n"; echo "
\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 "\n"; diff --git a/app/call_block/resources/classes/call_block.php b/app/call_block/resources/classes/call_block.php index 2f9d99638b..b3f5b9fec8 100644 --- a/app/call_block/resources/classes/call_block.php +++ b/app/call_block/resources/classes/call_block.php @@ -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 } -?> +?> \ No newline at end of file