SIP Profiles changes for PHP 8.1

This commit is contained in:
markjcrane 2023-05-25 21:20:56 -06:00
parent 5677ddfa8a
commit 29008867d0
3 changed files with 110 additions and 89 deletions

View File

@ -203,14 +203,14 @@ if (!class_exists('sip_profiles')) {
//filter out unchecked sip profiles, build the delete array
foreach ($records as $x => $record) {
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
$array[$this->table][$x]['sip_profile_uuid'] = $this->sip_profile_uuid;
}
}
//get necessary sip profile details
if (is_uuid($this->sip_profile_uuid)) {
if (!empty($this->sip_profile_uuid) && is_uuid($this->sip_profile_uuid)) {
$sql = "select sip_profile_hostname from v_sip_profiles ";
$sql .= "where sip_profile_uuid = :sip_profile_uuid ";
$parameters['sip_profile_uuid'] = $this->sip_profile_uuid;
@ -220,7 +220,7 @@ if (!class_exists('sip_profiles')) {
}
//delete the checked rows
if (is_array($array) && @sizeof($array) != 0) {
if (!empty($array) && @sizeof($array) != 0) {
//execute delete
$database = new database;
@ -277,18 +277,18 @@ if (!class_exists('sip_profiles')) {
}
//delete multiple records
if (is_array($records) && @sizeof($records) != 0) {
if (!empty($records) && @sizeof($records) != 0) {
//filter out unchecked sip profiles, build the delete array
foreach ($records as $x => $record) {
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
$array[$this->table][$x]['sip_profile_uuid'] = $this->sip_profile_uuid;
}
}
//get necessary sip profile details
if (is_uuid($this->sip_profile_uuid)) {
if (!empty($this->sip_profile_uuid) && is_uuid($this->sip_profile_uuid)) {
$sql = "select sip_profile_hostname from v_sip_profiles ";
$sql .= "where sip_profile_uuid = :sip_profile_uuid ";
$parameters['sip_profile_uuid'] = $this->sip_profile_uuid;
@ -298,7 +298,7 @@ if (!class_exists('sip_profiles')) {
}
//delete the checked rows
if (is_array($array) && @sizeof($array) != 0) {
if (!empty($array) && @sizeof($array) != 0) {
//execute delete
$database = new database;
@ -356,11 +356,11 @@ if (!class_exists('sip_profiles')) {
//get current toggle state
foreach ($records as $x => $record) {
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
$uuids[] = "'".$record['uuid']."'";
}
}
if (is_array($uuids) && @sizeof($uuids) != 0) {
if (!empty($uuids) && @sizeof($uuids) != 0) {
$sql = "select ".$this->uuid_prefix."uuid as uuid, ".$this->toggle_field." as toggle, sip_profile_hostname from v_".$this->table." ";
$sql .= "where ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
$database = new database;
@ -383,7 +383,7 @@ if (!class_exists('sip_profiles')) {
}
//save the changes
if (is_array($array) && @sizeof($array) != 0) {
if (!empty($array) && @sizeof($array) != 0) {
//save the array
$database = new database;
@ -410,7 +410,7 @@ if (!class_exists('sip_profiles')) {
}
//clear the cache
if (is_array($hostnames) && @sizeof($hostnames) != 0) {
if (!empty($hostnames) && @sizeof($hostnames) != 0) {
$hostnames = array_unique($hostnames);
$cache = new cache;
foreach ($hostnames as $hostname) {

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) 2016-2020
Portions created by the Initial Developer are Copyright (C) 2016-2023
the Initial Developer. All Rights Reserved.
Contributor(s):
@ -46,19 +46,31 @@
$text = $language->get();
//action add or update
if (is_uuid($_REQUEST["id"])) {
if (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) {
$action = "update";
$sip_profile_uuid = $_REQUEST["id"];
}
else {
$action = "add";
$sip_profile_uuid = uuid();
}
//set the defaults
$sip_profile_uuid = '';
$sip_profile_name = '';
$sip_profile_hostname = '';
$sip_profile_enabled = 'false';
$sip_profile_description = '';
$sip_profile_domains = [];
$sip_profile_settings = [];
$sip_profile_domains_delete = [];
$sip_profile_settings_delete = [];
//get http post variables and set them to php variables
if (count($_POST) > 0) {
if (!empty($_POST)) {
//process the http post data by submitted action
if ($_POST['action'] != '' && is_uuid($_POST['sip_profile_uuid'])) {
if (!empty($_POST['action']) && is_uuid($_POST['sip_profile_uuid'])) {
$array[0]['checked'] = 'true';
$array[0]['uuid'] = $_POST['sip_profile_uuid'];
@ -75,15 +87,16 @@
exit;
}
$sip_profile_uuid = $_POST["sip_profile_uuid"];
$sip_profile_name = $_POST["sip_profile_name"];
$sip_profile_hostname = $_POST["sip_profile_hostname"];
$sip_profile_enabled = $_POST["sip_profile_enabled"] ?: 'false';
$sip_profile_description = $_POST["sip_profile_description"];
$sip_profile_domains = $_POST["sip_profile_domains"];
$sip_profile_settings = $_POST["sip_profile_settings"];
$sip_profile_domains_delete = $_POST["sip_profile_domains_delete"];
$sip_profile_settings_delete = $_POST["sip_profile_settings_delete"];
//get the HTTP values
$sip_profile_uuid = $_POST["sip_profile_uuid"];
$sip_profile_name = $_POST["sip_profile_name"];
$sip_profile_hostname = $_POST["sip_profile_hostname"];
$sip_profile_enabled = $_POST["sip_profile_enabled"] ?: 'false';
$sip_profile_description = $_POST["sip_profile_description"];
$sip_profile_domains = $_POST["sip_profile_domains"];
$sip_profile_settings = $_POST["sip_profile_settings"];
$sip_profile_domains_delete = $_POST["sip_profile_domains_delete"];
$sip_profile_settings_delete = $_POST["sip_profile_settings_delete"];
}
//process the user data and save it to the database
@ -129,13 +142,13 @@
}
$database = new database;
$rows = $database->select($sql, $parameters, 'all');
if (is_array($rows) && @sizeof($rows) != 0) {
if (!empty($rows) && @sizeof($rows) != 0) {
foreach ($rows as $array) {
$sip_profile_names[] = $array['sip_profile_name'];
}
}
unset($sql);
if (is_array($sip_profile_names) && @sizeof($sip_profile_names) != 0 && in_array($sip_profile_name, $sip_profile_names)) {
if (!empty($sip_profile_names) && @sizeof($sip_profile_names) != 0 && in_array($sip_profile_name, $sip_profile_names)) {
//set message
message::add($text['message-sip_profile_unique'], 'negative', 5000);
@ -178,7 +191,7 @@
$y = 0;
foreach ($sip_profile_settings as $row) {
if (!empty($row['sip_profile_setting_uuid'])) {
if (is_uuid($row['sip_profile_setting_uuid'])) {
if (!empty($row['sip_profile_setting_uuid']) && is_uuid($row['sip_profile_setting_uuid'])) {
$sip_profile_setting_uuid = $row['sip_profile_setting_uuid'];
}
else {
@ -216,7 +229,7 @@
if (
$action == 'update'
&& permission_exists('sip_profile_domain_delete')
&& is_array($sip_profile_domains_delete)
&& !empty($sip_profile_domains_delete)
&& @sizeof($sip_profile_domains_delete) != 0
) {
$obj = new sip_profiles;
@ -228,7 +241,7 @@
if (
$action == 'update'
&& permission_exists('sip_profile_setting_delete')
&& is_array($sip_profile_settings_delete)
&& !empty($sip_profile_settings_delete)
&& @sizeof($sip_profile_settings_delete) != 0
) {
$obj = new sip_profiles;
@ -266,7 +279,7 @@
}
//pre-populate the form
if (is_array($_GET) && $_POST["persistformvar"] != "true") {
if (!empty($_GET["id"]) && empty($_POST["persistformvar"])) {
$sip_profile_uuid = $_GET["id"];
$sql = "select * from v_sip_profiles ";
$sql .= "where sip_profile_uuid = :sip_profile_uuid ";
@ -296,8 +309,8 @@
//add an empty row
if (permission_exists('sip_profile_setting_add')) {
$x = count($sip_profile_settings);
$sip_profile_settings[$x]['sip_profile_setting_uuid'] = '';
$x = empty($sip_profile_settings) ? 0 : count($sip_profile_settings);
$sip_profile_settings[$x]['sip_profile_setting_uuid'] = uuid();
$sip_profile_settings[$x]['sip_profile_uuid'] = $sip_profile_uuid;
$sip_profile_settings[$x]['sip_profile_setting_name'] = '';
$sip_profile_settings[$x]['sip_profile_setting_value'] = '';
@ -315,8 +328,8 @@
//add an empty row
if (permission_exists('sip_profile_domain_add')) {
$x = count($sip_profile_domains);
$sip_profile_domains[$x]['sip_profile_domain_uuid'] = '';
$x = empty($sip_profile_domains) ? 0 : count($sip_profile_domains);
$sip_profile_domains[$x]['sip_profile_domain_uuid'] = uuid();
$sip_profile_domains[$x]['sip_profile_uuid'] = $sip_profile_uuid;
$sip_profile_domains[$x]['sip_profile_domain_name'] = '';
$sip_profile_domains[$x]['sip_profile_domain_alias'] = '';
@ -326,7 +339,7 @@
//create js array of existing sip profile names to prevent duplicates
$sql = "select sip_profile_name from v_sip_profiles";
$database = new database;
$rows = $database->select($sql, $parameters, 'all');
$rows = $database->select($sql, null, 'all');
if (is_array($rows) && @sizeof($rows) != 0) {
foreach ($rows as $array) {
$sip_profile_names[] = $array['sip_profile_name'];
@ -357,18 +370,18 @@
echo "<script language='javascript'>\n";
//label to form input
echo " function label_to_form(label_id, form_id) {\n";
echo " if (document.getElementById(label_id) != null) {\n";
echo " label = document.getElementById(label_id);\n";
echo " label.parentNode.removeChild(label);\n";
echo " }\n";
echo " document.getElementById(form_id).style.display='';\n";
echo " }\n";
echo " function label_to_form(label_id, form_id) {\n";
echo " if (document.getElementById(label_id) != null) {\n";
echo " label = document.getElementById(label_id);\n";
echo " label.parentNode.removeChild(label);\n";
echo " }\n";
echo " document.getElementById(form_id).style.display='';\n";
echo " }\n";
//output js arrays to prevent duplicate profile names
echo $js_sip_profile_names['all']."\n";
echo $js_sip_profile_names['other']."\n";
unset($js_sip_profile_names);
echo $js_sip_profile_names['all']."\n";
echo $js_sip_profile_names['other']."\n";
unset($js_sip_profile_names);
echo "</script>\n";
@ -388,15 +401,14 @@
|| permission_exists('time_condition_add')
) {
echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$_SESSION['theme']['button_icon_copy'],'name'=>'btn_copy','style'=>$button_margin,'onclick'=>"modal_open('modal-copy','new_profile_name');"]);
unset($button_margin);
}
if (
permission_exists('sip_profile_delete')
|| permission_exists('sip_profile_domain_delete')
|| permission_exists('sip_profile_setting_delete')
) {
$button_margin = 'margin-left: 3px;';
echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'name'=>'btn_delete','style'=>$button_margin,'onclick'=>"modal_open('modal-delete','btn_delete');"]);
unset($button_margin);
}
}
echo button::create(['type'=>'button','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'id'=>'btn_save','style'=>'margin-left: 15px;','onclick'=>"if (document.getElementById('sip_profile_name').value != '' && !sip_profile_names_other.includes(document.getElementById('sip_profile_name').value)) { $('#frm').submit(); } else { display_message('".$text['message-sip_profile_unique']."', 'negative', 5000); }"]);
@ -461,8 +473,7 @@
echo " <th class='vtable'>".$text['label-sip_profile_domain_name']."</th>\n";
echo " <th class='vtable' style='text-align: center;'>".$text['label-sip_profile_domain_alias']."</th>\n";
echo " <th class='vtable' style='text-align: center;'>".$text['label-sip_profile_domain_parse']."</th>\n";
if (
permission_exists('sip_profile_domain_delete') && (
if (permission_exists('sip_profile_domain_delete') && (
(permission_exists('sip_profile_domain_add') && is_array($sip_profile_domains) && @sizeof($sip_profile_domains) > 1) ||
(!permission_exists('sip_profile_domain_add') && is_array($sip_profile_domains) && @sizeof($sip_profile_domains) != 0)
)) {
@ -474,19 +485,22 @@
echo " </tr>\n";
$x = 0;
foreach ($sip_profile_domains as $row) {
$bottom_border = !is_uuid($row['sip_profile_domain_uuid']) ? "border-bottom: none;" : null;
$bottom_border = empty($row['sip_profile_domain_uuid']) ? "border-bottom: none;" : null;
echo " <tr>\n";
if (is_uuid($row["sip_profile_uuid"])) {
if (!empty($sip_profile_uuid) && is_uuid($row["sip_profile_uuid"])) {
$sip_profile_uuid = $row["sip_profile_uuid"];
}
echo " <input type='hidden' name='sip_profile_domains[$x][sip_profile_domain_uuid]' value='".(is_uuid($row["sip_profile_domain_uuid"]) ? $sip_profile_domain_uuid : uuid())."'>\n";
$label_sip_profile_domain_alias = !empty($row["sip_profile_domain_alias"]) ? $text['label-'.$row["sip_profile_domain_alias"]] : '';
$label_sip_profile_domain_parse = !empty($row["sip_profile_domain_alias"]) ? $text['label-'.$row["sip_profile_domain_alias"]] : '';
echo " <input type='hidden' name='sip_profile_domains[$x][sip_profile_domain_uuid]' value='".(!empty($row["sip_profile_domain_uuid"]) ? $row["sip_profile_domain_uuid"] : uuid())."'>\n";
echo " <input type='hidden' name='sip_profile_domains[$x][sip_profile_uuid]' value='".escape($sip_profile_uuid)."'>\n";
echo " <td class='vtablerow' style='".$bottom_border."' ".(permission_exists('sip_profile_domain_edit') ? "onclick=\"label_to_form('label_sip_profile_domain_name_$x','sip_profile_domain_name_$x');\"" : null)." nowrap='nowrap'>\n";
echo " &nbsp; <label id='label_sip_profile_domain_name_$x'>".escape($row["sip_profile_domain_name"])."</label>\n";
echo " <input id='sip_profile_domain_name_$x' class='formfld' style='display: none;' type='text' name='sip_profile_domains[$x][sip_profile_domain_name]' maxlength='255' value=\"".escape($row["sip_profile_domain_name"])."\">\n";
echo " </td>\n";
echo " <td class='vtablerow' style='".$bottom_border." text-align: center;' ".(permission_exists('sip_profile_domain_edit') ? "onclick=\"label_to_form('label_sip_profile_domain_alias_$x','sip_profile_domain_alias_$x');\"" : null)." nowrap='nowrap'>\n";
echo " <label id='label_sip_profile_domain_alias_$x'>".$text['label-'.$row["sip_profile_domain_alias"]]."</label>\n";
echo " <label id='label_sip_profile_domain_alias_$x'>".$label_sip_profile_domain_alias."</label>\n";
echo " <select id='sip_profile_domain_alias_$x' class='formfld' style='display: none;' name='sip_profile_domains[$x][sip_profile_domain_alias]'>\n";
echo " <option value=''></option>\n";
echo " <option value='true' ".($row["sip_profile_domain_alias"] == "true" ? "selected='selected'" : null).">".$text['label-true']."</option>\n";
@ -494,7 +508,7 @@
echo " </select>\n";
echo " </td>\n";
echo " <td class='vtablerow' style='".$bottom_border." text-align: center;' ".(permission_exists('sip_profile_domain_edit') ? "onclick=\"label_to_form('label_sip_profile_domain_parse_$x','sip_profile_domain_parse_$x');\"" : null)." nowrap='nowrap'>\n";
echo " <label id='label_sip_profile_domain_parse_$x'>".$text['label-'.$row["sip_profile_domain_parse"]]."</label>\n";
echo " <label id='label_sip_profile_domain_parse_$x'>".$label_sip_profile_domain_parse."</label>\n";
echo " <select id='sip_profile_domain_parse_$x' class='formfld' style='display: none;' name='sip_profile_domains[$x][sip_profile_domain_parse]'>\n";
echo " <option value=''></option>\n";
echo " <option value='true' ".($row["sip_profile_domain_parse"] == "true" ? "selected='selected'" : null).">".$text['label-true']."</option>\n";
@ -502,7 +516,7 @@
echo " </select>\n";
echo " </td>\n";
if (permission_exists('sip_profile_domain_delete')) {
if (is_uuid($row['sip_profile_domain_uuid'])) {
if (!empty($sip_profile_uuid) && is_uuid($row['sip_profile_domain_uuid'])) {
echo " <td class='vtable' style='text-align: center; padding-bottom: 3px;'>";
echo " <input type='checkbox' name='sip_profile_domains_delete[".$x."][checked]' value='true' class='chk_delete checkbox_domains' onclick=\"edit_delete_action('domains');\">\n";
echo " <input type='hidden' name='sip_profile_domains_delete[".$x."][uuid]' value='".escape($row['sip_profile_domain_uuid'])."' />\n";
@ -514,7 +528,7 @@
}
echo " </tr>\n";
//convert last empty labels to form elements
if (permission_exists('sip_profile_domain_add') && !is_uuid($row["sip_profile_domain_uuid"])) {
if (permission_exists('sip_profile_domain_add') && empty($row["sip_profile_domain_uuid"])) {
echo "<script>\n";
echo " label_to_form('label_sip_profile_domain_name_$x','sip_profile_domain_name_$x');\n";
echo " label_to_form('label_sip_profile_domain_alias_$x','sip_profile_domain_alias_$x');\n";
@ -538,8 +552,7 @@
echo " <th class='vtable'>".$text['label-sip_profile_setting_value']."</th>\n";
echo " <th class='vtable' style='text-align: center;'>".$text['label-sip_profile_setting_enabled']."</th>\n";
echo " <th class='vtable'>".$text['label-sip_profile_setting_description']."</th>\n";
if (
permission_exists('sip_profile_setting_delete') && (
if (permission_exists('sip_profile_setting_delete') && (
(permission_exists('sip_profile_setting_add') && is_array($sip_profile_settings) && @sizeof($sip_profile_settings) > 1) ||
(!permission_exists('sip_profile_setting_add') && is_array($sip_profile_settings) && @sizeof($sip_profile_settings) != 0)
)) {
@ -551,7 +564,8 @@
echo " </tr>\n";
$x = 0;
foreach ($sip_profile_settings as $row) {
$bottom_border = !is_uuid($row['sip_profile_setting_uuid']) ? "border-bottom: none;" : null;
$bottom_border = empty($row['sip_profile_setting_uuid']) ? "border-bottom: none;" : null;
$label_sip_profile_setting_enabled = !empty($row["sip_profile_setting_enabled"]) ? $text['label-'.$row["sip_profile_setting_enabled"]] : '';
echo " <tr>\n";
echo " <input type='hidden' name='sip_profile_settings[$x][sip_profile_setting_uuid]' value='".(is_uuid($row["sip_profile_setting_uuid"]) ? $row["sip_profile_setting_uuid"] : uuid())."'>\n";
echo " <input type='hidden' name='sip_profile_settings[$x][sip_profile_uuid]' value='".escape($row["sip_profile_uuid"])."'>\n";
@ -564,7 +578,7 @@
echo " <input id='sip_profile_setting_value_$x' class='formfld' style='display: none;' type='text' name='sip_profile_settings[$x][sip_profile_setting_value]' maxlength='255' value=\"".escape($row["sip_profile_setting_value"])."\">\n";
echo " </td>\n";
echo " <td class='vtablerow' style='".$bottom_border." text-align: center;' ".(permission_exists('sip_profile_setting_edit') ? "onclick=\"label_to_form('label_sip_profile_setting_enabled_$x','sip_profile_setting_enabled_$x');\"" : null)." nowrap='nowrap'>\n";
echo " <label id='label_sip_profile_setting_enabled_$x'>".$text['label-'.$row["sip_profile_setting_enabled"]]."</label>\n";
echo " <label id='label_sip_profile_setting_enabled_$x'>".$label_sip_profile_setting_enabled."</label>\n";
echo " <select id='sip_profile_setting_enabled_$x' class='formfld' style='display: none;' name='sip_profile_settings[$x][sip_profile_setting_enabled].'>\n";
echo " <option value='true'>".$text['label-true']."</option>\n";
echo " <option value='false' ".($row['sip_profile_setting_enabled'] == "false" ? "selected='selected'" : null).">".$text['label-false']."</option>\n";
@ -575,7 +589,7 @@
echo " <input id='sip_profile_setting_description_$x' class='formfld' style='display: none;' type='text' name='sip_profile_settings[$x][sip_profile_setting_description]' maxlength='255' value=\"".escape($row["sip_profile_setting_description"])."\">\n";
echo " </td>\n";
if (permission_exists('sip_profile_setting_delete')) {
if (is_uuid($row['sip_profile_setting_uuid'])) {
if (!empty($row['sip_profile_setting_uuid']) && is_uuid($row['sip_profile_setting_uuid'])) {
echo " <td class='vtable' style='text-align: center; padding-bottom: 3px;'>";
echo " <input type='checkbox' name='sip_profile_settings_delete[".$x."][checked]' value='true' class='chk_delete checkbox_settings' onclick=\"edit_delete_action('settings');\">\n";
echo " <input type='hidden' name='sip_profile_settings_delete[".$x."][uuid]' value='".escape($row['sip_profile_setting_uuid'])."' />\n";
@ -642,7 +656,7 @@
echo "<td class='vtable' align='left'>\n";
echo " <textarea class='formfld' type='text' name='sip_profile_description'>".escape($sip_profile_description)."</textarea>\n";
echo "<br />\n";
echo $text['description-sip_profile_description']."\n";
//echo $text['description-sip_profile_description']."\n";
echo "</td>\n";
echo "</tr>\n";

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-2018
Portions created by the Initial Developer are Copyright (C) 2008-2023
the Initial Developer. All Rights Reserved.
Contributor(s):
@ -46,14 +46,20 @@
$language = new text;
$text = $language->get();
//define the variables
$action = '';
$search = '';
$sip_profiles = '';
//get the http post data
if (is_array($_POST['sip_profiles'])) {
if (!empty($_POST['sip_profiles'])) {
$action = $_POST['action'];
$search = $_POST['search'];
$sip_profiles = $_POST['sip_profiles'];
}
//process the http post data by action
if ($action != '' && is_array($sip_profiles) && @sizeof($sip_profiles) != 0) {
if (!empty($action) && !empty($sip_profiles) && @sizeof($sip_profiles) != 0) {
switch ($action) {
case 'toggle':
if (permission_exists('sip_profile_edit')) {
@ -69,10 +75,13 @@
break;
}
header('Location: sip_profiles.php'.($search != '' ? '?search='.urlencode($search) : null));
header('Location: sip_profiles.php'.(!empty($search) ? '?search='.urlencode($search) : null));
exit;
}
//set from session variables
$list_row_edit_button = !empty($_SESSION['theme']['list_row_edit_button']['boolean']) ? $_SESSION['theme']['list_row_edit_button']['boolean'] : 'false';
//get order and order by
if (isset($_GET["order_by"])) {
$order_by = $_GET["order_by"];
@ -80,29 +89,27 @@
else {
$order_by = 'sip_profile_name';
}
$order = $_GET["order"];
$order = $_GET["order"] ?? '';
//add the search string
$search = strtolower($_GET["search"]);
if (!empty($search)) {
$sql_search = "where (";
$sql_search .= "lower(sip_profile_name) like :search ";
$sql_search .= "or lower(sip_profile_hostname) like :search ";
$sql_search .= "or lower(sip_profile_description) like :search ";
$sql_search .= ") ";
//prepare to page the results
$sql = "select count(sip_profile_uuid) ";
$sql .= "from v_sip_profiles ";
if (!empty($_GET["search"])) {
$search = strtolower($_GET["search"]);
$sql .= "where (";
$sql .= "lower(sip_profile_name) like :search ";
$sql .= "or lower(sip_profile_hostname) like :search ";
$sql .= "or lower(sip_profile_description) like :search ";
$sql .= ") ";
$parameters['search'] = '%'.$search.'%';
}
//prepare to page the results
$sql = "select count(sip_profile_uuid) from v_sip_profiles ";
$sql .= $sql_search;
$database = new database;
$num_rows = $database->select($sql, $parameters, 'column');
$num_rows = $database->select($sql, $parameters ?? null, 'column');
//prepare to page the results
$rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
$rows_per_page = (!empty($_SESSION['domain']['paging']['numeric'])) ? $_SESSION['domain']['paging']['numeric'] : 50;
$param = $search ? "&search=".$search : null;
$page = is_numeric($_GET['page']) ? $_GET['page'] : 0;
$page = !empty($_GET['page']) ? $_GET['page'] : 0;
list($paging_controls, $rows_per_page) = paging($num_rows, $param, $rows_per_page);
list($paging_controls_mini, $rows_per_page) = paging($num_rows, $param, $rows_per_page, true);
$offset = $rows_per_page * $page;
@ -112,7 +119,7 @@
$sql .= order_by($order_by, $order);
$sql .= limit_offset($rows_per_page, $offset);
$database = new database;
$sip_profiles = $database->select($sql, $parameters, 'all');
$sip_profiles = $database->select($sql, $parameters ?? null, 'all');
unset($sql, $parameters);
//create token
@ -142,8 +149,8 @@
echo "<form id='form_search' class='inline' method='get'>\n";
echo "<input type='text' class='txt list-search' name='search' id='search' value=\"".escape($search)."\" placeholder=\"".$text['label-search']."\" onkeydown=''>";
echo button::create(['label'=>$text['button-search'],'icon'=>$_SESSION['theme']['button_icon_search'],'type'=>'submit','id'=>'btn_search']);
//echo button::create(['label'=>$text['button-reset'],'icon'=>$_SESSION['theme']['button_icon_reset'],'type'=>'button','id'=>'btn_reset','link'=>'sip_profiles.php','style'=>($search == '' ? 'display: none;' : null)]);
if ($paging_controls_mini != '') {
//echo button::create(['label'=>$text['button-reset'],'icon'=>$_SESSION['theme']['button_icon_reset'],'type'=>'button','id'=>'btn_reset','link'=>'sip_profiles.php','style'=>(empty($search) ? 'display: none;' : null)]);
if (!empty($paging_controls_mini)) {
echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>\n";
}
echo " </form>\n";
@ -169,19 +176,19 @@
echo "<tr class='list-header'>\n";
if (permission_exists('sip_profile_add') || permission_exists('sip_profile_edit') || permission_exists('sip_profile_delete')) {
echo " <th class='checkbox'>\n";
echo " <input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='list_all_toggle(); checkbox_on_change(this);' ".($sip_profiles ?: "style='visibility: hidden;'").">\n";
echo " <input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='list_all_toggle(); checkbox_on_change(this);' ".(!empty($sip_profiles) ?: "style='visibility: hidden;'").">\n";
echo " </th>\n";
}
echo th_order_by('sip_profile_name', $text['label-sip_profile_name'], $order_by, $order);
echo th_order_by('sip_profile_hostname', $text['label-sip_profile_hostname'], $order_by, $order);
echo th_order_by('sip_profile_enabled', $text['label-sip_profile_enabled'], $order_by, $order, null, "class='center'");
echo th_order_by('sip_profile_description', $text['label-sip_profile_description'], $order_by, $order, null, "class='hide-sm-dn pct-70'");
if (permission_exists('sip_profile_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
if (permission_exists('sip_profile_edit') && $list_row_edit_button == 'true') {
echo " <td class='action-button'>&nbsp;</td>\n";
}
echo "</tr>\n";
if (is_array($sip_profiles) && @sizeof($sip_profiles) != 0) {
if (!empty($sip_profiles) && @sizeof($sip_profiles) != 0) {
$x = 0;
foreach ($sip_profiles as $row) {
if (permission_exists('sip_profile_edit')) {
@ -213,7 +220,7 @@
}
echo " </td>\n";
echo " <td class='description overflow hide-sm-dn'>".escape($row['sip_profile_description'])."&nbsp;</td>\n";
if (permission_exists('sip_profile_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
if (permission_exists('sip_profile_edit') && $list_row_edit_button == 'true') {
echo " <td class='action-button'>\n";
echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]);
echo " </td>\n";