Files
fusionpbx/app/devices/device_vendor_function_edit.php
FusionPBX dda18481ec Refactor PHP code (#7574)
* Use settings-get method
- get default, domain and user settings
- Replace _SESSION

* Simplify get domain paging

* Change isset using empty

* Fix token name and hash

* Add new default settings category: contact, name: default_sort_column, and default_sort_order

* Update app_config.php

* Update footer.php

* Fix require.php and core/dashboard/index.php (#7563)

* Fix require.php and core/dashboard/index.php

* Fix require.php and core/dashboard/index.php

* Fix require.php and core/dashboard/index.php

* Fix require.php and core/dashboard/index.php

* Fix require.php and core/dashboard/index.php

* Fix require.php and core/dashboard/index.php

* Fix require.php and core/dashboard/index.php

* Fix require.php and core/dashboard/index.php

* Fix require.php and core/dashboard/index.php

* Update destinations.php

* Update permission.php

* Update require.php

---------

Co-authored-by: FusionPBX <markjcrane@gmail.com>
Co-authored-by: FusionPBX <mark@fusionpbx.com>

* Update header.php

* Use settings get classes (#7567)

* access_control

* azure

* azure

* basic_operator_panel

* bridges

* call_block

* call_broadcast

* call_center

* call_flows

* call_forward

* call_recordings

* do_not_disturb

* feature_event_notify

* follow_me

* remove unused object properties

* fix esl command

* fix esl command

* conference_centers

* conference_centers - remove whitespace

* conference_controls

* conference_profiles

* conference_profiles

* Delete core/websockets/resources/classes/socket_exception.php.original~

* Delete core/websockets/resources/classes/websocket_server.php.original~

* conferences

* destinations

* device

* dialplan

* email_queue

* event_guard

* extension_settings

* extension

* fax

* fax_queue

* fifo

* gateways

* ivr_menu

* modules

* switch_music_on_hold

* number_translations

* phrases

* pin_numbers

* provision

* switch_recordings

* registrations

* ring_groups

* sip_profiles

* sofia_global_settings

* streams

* presence

* switch_files

* time_conditions

* vars

* voicemail_greetings

* voicemail

* ringbacks

* contacts

* xml_cdr

* authentication

* dashboard

* default_settings

* domain_settings

* email_templates

* permission

* user_logs

* user_settings

* users

* button

* cache

* captcha

* remove cli_option

* remove directory.php for switch_directory class

* email

* file

* groups

* event_socket use config object

* Use intval to give an integer port

* switch_settings

* tones

* fix object used before initialization

* menu

* fix copy paste error for switch_files.php

* always include require.php for framework files

* Fix missing properties

* set the action

* Use the $database object

* Add missing class properties

* Fix the domain_name

* Use public scope for domain_uuid and domain_name

* Add missing parameters

* Correct the user_uuid parameter

* Add json_validate and use it in the dashboard
update indentation on functions.php

* Intialize the active_registrations variable

* Define the $parameters

* Set a default value for user_setting_enabled

* Add condition domain_uuid not empty

* Add not empty condition for domain_uuid

* Declare the global variables

* Update how the defaults are set use ??

* Use ?? to set the default values

* Update call_center_queue_edit.php

* Prevent an error

* Add domain_name property

* Fix the null coalescing operator

* Removed domain_uuid from the URL

* Change condition to check sip_profile_domain_name

* Refactor domain_uuid declaration and comments

Removed redundant domain_uuid declaration and updated comments.

* Account for an empty value

* Refactor constructor to use settings array

Updated constructor to accept settings array for domain UUID and database initialization.

* Refactor xml_cdr.php to improve variable organization

Removed duplicate domain_uuid declaration and reorganized private variables for better structure.

* Enhance transcription button logic and icon display

Updated transcription button visibility conditions and improved application icon handling in the call flow summary.

* Refactor settings initialization in domains.php

Updated settings initialization to include domain_uuid and user_uuid.

* Modify domain change condition in require.php

Updated condition to check if 'domain_change' is not empty before proceeding.

* Set default_setting_enabled to true by default

* Enhance domain UUID check in access controls

* Enhance domain UUID check in settings list

* Refactor category display logic in vars.php

* Simplify list row URL generation

Removed domain UUID check from list row URL construction.

* Refactor module category display logic

* Fix SQL query by removing parameters variable

* Initialize result_count variable for call recordings

* Refactor leg variable usage in xml_cdr_details.php

* Update conference_room_edit.php

* Change GET to REQUEST for order and search variables

* Set timezone and SQL time format in recordings.php

Added timezone and SQL time format settings.

* Set default for ring group greeting

* Improve domain UUID check in stream listing

* Handle null voicemail_option_param safely

* Add file existence check for greeting files

Check if greeting file exists before getting size and date.

* Improve domain UUID check in email templates

* Update FIFO strategy dropdown and description text

* Add multilingual agent descriptions

Added multilingual descriptions for agents in the app_languages.php file.

* Add music on hold descriptions

* Add the chime list description

Updated copyright year from 2024 to 2025.

* Fix domain UUID check and handle email subject decoding

* Add null coalescing for $value in email_test.php

Ensure $value is not null by providing a default empty string.

* Handle undefined dialplan_uuid in input field

* Add translations for 'Status' label in multiple languages

* Fix typo in config instance check

---------

Co-authored-by: frytimo <tim@fusionpbx.com>
2025-10-15 21:24:59 -06:00

424 lines
16 KiB
PHP

<?php
/*
FusionPBX
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2016-2025
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
//includes files
require_once dirname(__DIR__, 2) . "/resources/require.php";
//add multi-lingual support
$language = new text;
$text = $language->get();
//set the defaults
$device_vendor_function_uuid = '';
//check permissions
require_once "resources/check_auth.php";
if (permission_exists('device_vendor_function_add') || permission_exists('device_vendor_function_edit')) {
//access granted
}
else {
echo "access denied";
exit;
}
//action add or update
if (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) {
$action = "update";
$device_vendor_function_uuid = $_REQUEST["id"];
}
else {
$action = "add";
}
//add multi-lingual support
$language = new text;
$text = $language->get();
//set the parent uuid
if (is_uuid($_GET["device_vendor_uuid"])) {
$device_vendor_uuid = $_GET["device_vendor_uuid"];
}
//get http post variables and set them to php variables
if (count($_POST)>0) {
//$label = $_POST["label"];
$type = $_POST["type"];
$subtype = $_POST["subtype"];
$value = $_POST["value"];
$enabled = $_POST["enabled"];
$description = $_POST["description"];
}
//delete the group from the sub table
if (!empty($_POST["action"]) && $_POST["action"] === "delete" && permission_exists("device_vendor_function_group_delete") && is_uuid($_POST["device_vendor_function_group_uuid"])) {
//get the uuid
$device_vendor_function_group_uuid = $_POST["device_vendor_function_group_uuid"];
//validate the token
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: devices.php');
exit;
}
//delete the device vendor function group
$array['device_vendor_function_groups'][0]['device_vendor_function_group_uuid'] = $device_vendor_function_group_uuid;
$database->delete($array);
unset($array);
//redirect the user
message::add($text['message-delete'] ?? '');
header("Location: device_vendor_function_edit.php?id=".escape($device_vendor_function_uuid) ."&device_vendor_uuid=".escape($device_vendor_uuid));
exit;
}
//process the http variables
if (count($_POST) > 0 && empty($_POST["persistformvar"])) {
//get the uuid
if ($action == "update") {
$device_vendor_function_uuid = $_POST["device_vendor_function_uuid"];
}
//validate the token
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: devices.php');
exit;
}
//check for all required data
$msg = '';
//if (empty($label)) { $msg .= $text['message-required']." ".$text['label-label']."<br>\n"; }
if (empty($type)) { $msg .= $text['message-required']." ".$text['label-type']."<br>\n"; }
if (empty($value)) { $msg .= $text['message-required']." ".$text['label-value']."<br>\n"; }
//if (empty($description)) { $msg .= $text['message-required']." ".$text['label-description']."<br>\n"; }
if (!empty($msg) && empty($_POST["persistformvar"])) {
require_once "resources/header.php";
require_once "resources/persist_form_var.php";
echo "<div align='center'>\n";
echo "<table><tr><td>\n";
echo $msg."<br />";
echo "</td></tr></table>\n";
persistformvar($_POST);
echo "</div>\n";
require_once "resources/footer.php";
return;
}
//add or update the database
if (empty($_POST["persistformvar"]) || $_POST["persistformvar"] != "true") {
//add vendor functions
if ($action == "add" && permission_exists('device_vendor_function_add')) {
$device_vendor_function_uuid = uuid();
$array['device_vendor_functions'][0]['device_vendor_function_uuid'] = $device_vendor_function_uuid;
}
//update vendor functions
if ($action == "update" && permission_exists('device_vendor_function_edit')) {
$array['device_vendor_functions'][0]['device_vendor_function_uuid'] = $device_vendor_function_uuid;
}
//execute
if (is_array($array) && @sizeof($array) != 0) {
$array['device_vendor_functions'][0]['device_vendor_uuid'] = $device_vendor_uuid;
//$array['device_vendor_functions'][0]['label'] = $label;
$array['device_vendor_functions'][0]['type'] = $type;
$array['device_vendor_functions'][0]['subtype'] = $subtype;
$array['device_vendor_functions'][0]['value'] = $value;
$array['device_vendor_functions'][0]['enabled'] = $enabled;
$array['device_vendor_functions'][0]['description'] = $description;
$database->save($array);
unset($array);
}
//add a group to the menu
if (permission_exists('device_vendor_function_add') && $_REQUEST["group_uuid_name"] != '') {
//get the group uuid and group_name
$group_data = explode('|', $_REQUEST["group_uuid_name"]);
$group_uuid = $group_data[0];
$group_name = $group_data[1];
//add the group to the menu
if (is_uuid($device_vendor_function_uuid)) {
$device_vendor_function_group_uuid = uuid();
$array['device_vendor_function_groups'][0]['device_vendor_function_group_uuid'] = $device_vendor_function_group_uuid;
$array['device_vendor_function_groups'][0]['device_vendor_function_uuid'] = $device_vendor_function_uuid;
$array['device_vendor_function_groups'][0]['device_vendor_uuid'] = $device_vendor_uuid;
$array['device_vendor_function_groups'][0]['group_name'] = $group_name;
$array['device_vendor_function_groups'][0]['group_uuid'] = $group_uuid;
$p = permissions::new();
$p->add('device_vendor_function_group_add', 'temp');
$database->save($array);
unset($array);
$p->delete('device_vendor_function_group_add', 'temp');
}
}
//redirect the user
$_SESSION["message"] = $text['message-'.$action];
header("Location: device_vendor_function_edit.php?id=".escape($device_vendor_function_uuid) ."&device_vendor_uuid=".escape($device_vendor_uuid));
exit;
}
}
//pre-populate the form
if (!empty($_GET) && count($_GET) > 0 && (empty($_POST["persistformvar"]) || $_POST["persistformvar"] != "true")) {
$device_vendor_function_uuid = $_GET["id"] ?? null;
$sql = "select ";
$sql .= "device_vendor_function_uuid, ";
$sql .= "device_vendor_uuid, ";
$sql .= "type, ";
$sql .= "subtype, ";
$sql .= "value, ";
$sql .= "enabled, ";
$sql .= "description ";
$sql .= "from v_device_vendor_functions ";
$sql .= "where device_vendor_function_uuid = :device_vendor_function_uuid ";
$parameters['device_vendor_function_uuid'] = $device_vendor_function_uuid;
$row = $database->select($sql, $parameters, 'row');
if (is_array($row) && @sizeof($row) != 0) {
$type = $row["type"];
$subtype = $row["subtype"];
$value = $row["value"];
$enabled = $row["enabled"];
$description = $row["description"];
}
unset($sql, $parameters, $row);
}
//get function groups assigned
$sql = "select ";
$sql .= "fg.*, g.domain_uuid as group_domain_uuid ";
$sql .= "from ";
$sql .= "v_device_vendor_function_groups as fg, ";
$sql .= "v_groups as g ";
$sql .= "where ";
$sql .= "fg.group_uuid = g.group_uuid ";
$sql .= "and fg.device_vendor_uuid = :device_vendor_uuid ";
$sql .= "and fg.device_vendor_function_uuid = :device_vendor_function_uuid ";
$sql .= "order by ";
$sql .= "g.domain_uuid desc, ";
$sql .= "g.group_name asc ";
$parameters['device_vendor_uuid'] = $device_vendor_uuid;
$parameters['device_vendor_function_uuid'] = $device_vendor_function_uuid;
$function_groups = $database->select($sql, $parameters, 'all');
unset($sql, $parameters);
//set the assigned_groups array
if (is_array($function_groups) && @sizeof($function_groups) != 0) {
foreach($function_groups as $field) {
if (!empty($field['group_name'])) {
$assigned_groups[] = $field['group_uuid'];
}
}
}
//get the groups
$sql = "select ";
$sql .= "group_uuid, ";
$sql .= "domain_uuid, ";
$sql .= "group_name, ";
$sql .= "group_protected, ";
$sql .= "group_level, ";
$sql .= "group_description ";
$sql .= "from v_groups ";
if (!empty($assigned_groups) && is_array($assigned_groups) && @sizeof($assigned_groups) != 0) {
$sql .= "where ";
foreach ($assigned_groups as $index => $group_uuid) {
$sql_where[] = 'group_uuid <> :group_uuid_'.$index;
$parameters['group_uuid_'.$index] = $group_uuid;
}
if (is_array($sql_where) && @sizeof($sql_where) != 0) {
$sql .= implode(' and ', $sql_where).' ';
}
}
$sql .= "order by domain_uuid desc, group_name asc ";
$groups = $database->select($sql, $parameters ?? null, 'all');
unset($sql, $parameters, $sql_where, $index);
//set the defaults
$enabled = $enabled ?? true;
//create token
$object = new token;
$token = $object->create($_SERVER['PHP_SELF']);
//show the header
$document['title'] = $text['title-device_vendor_function'];
require_once "resources/header.php";
//show the content
echo "<form name='frm' id='frm' method='post'>\n";
echo "<div class='action_bar' id='action_bar'>\n";
echo " <div class='heading'><b>".$text['title-device_vendor_function']."</b></div>\n";
echo " <div class='actions'>\n";
echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$settings->get('theme', 'button_icon_back'),'id'=>'btn_back','collapse'=>'hide-xs','link'=>'device_vendor_edit.php?id='.urlencode($device_vendor_uuid)]);
echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$settings->get('theme', 'button_icon_save'),'id'=>'btn_save','collapse'=>'hide-xs','style'=>'margin-left: 15px;']);
echo " </div>\n";
echo " <div style='clear: both;'></div>\n";
echo "</div>\n";
echo "<div class='card'>\n";
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo "<tr>\n";
echo "<td width='30%' class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-type']."\n";
echo "</td>\n";
echo "<td width='70%' class='vtable' align='left'>\n";
echo " <input class='formfld' type='text' name='type' maxlength='255' value=\"".escape($type ?? '')."\">\n";
echo "<br />\n";
echo $text['description-type']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td width='30%' class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-subtype']."\n";
echo "</td>\n";
echo "<td width='70%' class='vtable' align='left'>\n";
echo " <input class='formfld' type='text' name='subtype' maxlength='255' value=\"".escape($subtype ?? '')."\">\n";
echo "<br />\n";
echo ($text['description-subtype'] ?? '')."\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-value']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <input class='formfld' type='text' name='value' maxlength='255' value=\"".escape($value ?? '')."\">\n";
echo "<br />\n";
echo $text['description-value']."\n";
echo "</td>\n";
echo "</tr>\n";
echo " <tr>";
echo " <td class='vncell' valign='top'>".$text['label-groups']."</td>";
echo " <td class='vtable'>";
if (is_array($function_groups) && @sizeof($function_groups) != 0) {
echo "<table cellpadding='0' cellspacing='0' border='0'>\n";
if (permission_exists('device_vendor_function_group_delete')) {
echo " <input type='hidden' id='action' name='action' value=''>\n";
echo " <input type='hidden' id='device_vendor_function_group_uuid' name='device_vendor_function_group_uuid' value=''>\n";
}
$x = 0;
foreach ($function_groups as $field) {
if (!empty($field['group_name'])) {
echo "<tr>\n";
echo " <td class='vtable' style='white-space: nowrap; padding-right: 30px;' nowrap='nowrap'>";
echo $field['group_name'].(($field['group_domain_uuid'] != '') ? "@".$_SESSION['domains'][$field['group_domain_uuid']]['domain_name'] : null);
echo " </td>\n";
if (permission_exists('device_vendor_function_group_delete')) {
echo " <td class='list_control_icons' style='width: 25px;'>";
echo button::create(['type'=>'button','icon'=>'fas fa-minus','id'=>'btn_delete','class'=>'default list_control_icon','name'=>'btn_delete','onclick'=>"modal_open('modal-delete-group-$x','btn_delete');"]);
echo modal::create(['id'=>'modal-delete-group-'.$x,'type'=>'delete','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('delete'); document.getElementById('device_vendor_function_group_uuid').value = '".escape($field['device_vendor_function_group_uuid'])."'; list_form_submit('frm');"])]);
echo " </td>";
}
echo "</tr>\n";
$x++;
}
}
echo "</table>\n";
echo "<br />\n";
}
if (is_array($groups) && @sizeof($groups) != 0) {
echo "<select name='group_uuid_name' class='formfld' style='width: auto; margin-right: 3px;'>\n";
echo " <option value=''></option>\n";
foreach ($groups as $field) {
if ($field['group_name'] == "superadmin" && !if_group("superadmin")) { continue; } //only show the superadmin group to other superadmins
if ($field['group_name'] == "admin" && (!if_group("superadmin") && !if_group("admin") )) { continue; } //only show the admin group to other admins
if (empty($assigned_groups) || !is_array($assigned_groups) || !in_array($field["group_uuid"], $assigned_groups)) {
echo " <option value='".escape($field['group_uuid'])."|".escape($field['group_name'])."'>".escape($field['group_name']).(($field['domain_uuid'] != '') ? "@".escape($_SESSION['domains'][$field['domain_uuid']]['domain_name']) : null)."</option>\n";
}
}
echo "</select>";
echo button::create(['type'=>'submit','label'=>$text['button-add'],'icon'=>$settings->get('theme', 'button_icon_add'),'collapse'=>'never']);
}
echo " </td>";
echo " </tr>";
echo "<tr>\n";
echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-enabled']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
if ($input_toggle_style_switch) {
echo " <span class='switch'>\n";
}
echo " <select class='formfld' id='enabled' name='enabled'>\n";
echo " <option value='true' ".($enabled === true ? "selected='selected'" : null).">".$text['option-true']."</option>\n";
echo " <option value='false' ".($enabled === false ? "selected='selected'" : null).">".$text['option-false']."</option>\n";
echo " </select>\n";
if ($input_toggle_style_switch) {
echo " <span class='slider'></span>\n";
echo " </span>\n";
}
echo "<br />\n";
echo $text['description-enabled']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-description']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <input class='formfld' type='text' name='description' maxlength='255' value=\"".escape($description ?? '')."\">\n";
echo "<br />\n";
echo $text['description-description']."\n";
echo "</td>\n";
echo "</tr>\n";
echo " <tr>\n";
echo " <td colspan='2' align='right'>\n";
echo " <input type='hidden' name='device_vendor_uuid' value='".escape($device_vendor_uuid)."'>\n";
if ($action == "update") {
echo " <input type='hidden' name='device_vendor_function_uuid' value='".escape($device_vendor_function_uuid)."'>\n";
}
echo " <input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
echo " </td>\n";
echo " </tr>";
echo "</table>";
echo "</div>\n";
echo "</form>";
echo "<br /><br />";
//include the footer
require_once "resources/footer.php";
?>