Files
fusionpbx/resources/classes/button.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

244 lines
8.8 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>
Copyright (C) 2010 - 2019
All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
class button {
public static $collapse = 'hide-md-dn';
public static function create($array) {
global $settings;
$button_icons = $settings->get('theme', 'button_icons', 'auto');
//parse styles into array
if (!empty($array['style'])) {
$tmp = explode(';',$array['style']);
foreach ($tmp as $style) {
if (!empty($style)) {
$style = explode(':', $style);
if (is_array($style) && @sizeof($style) == 2) {
$styles[trim($style[0])] = trim($style[1]);
}
}
}
$array['style'] = $styles;
unset($styles);
}
//button: open
$button = "<button ";
$button .= "type='".(!empty($array['type']) ? $array['type'] : 'button')."' ";
$button .= !empty($array['name']) ? "name=".self::quote($array['name'])." " : null;
$button .= !empty($array['value']) ? "value=".self::quote($array['value'])." " : null;
$button .= !empty($array['id']) ? "id='".$array['id']."' " : null;
$button .= !empty($array['label']) ? "alt=".self::quote($array['label'])." " : (!empty($array['title']) ? "alt=".self::quote($array['title'])." " : null);
if ($button_icons == 'only' || $button_icons == 'auto' || $array['title']) {
if (!empty($array['title']) || !empty($array['label'])) {
$button .= "title=".(!empty($array['title']) ? self::quote($array['title']) : self::quote($array['label']))." ";
}
}
$button .= !empty($array['onclick']) ? "onclick=".self::quote($array['onclick'])." " : null;
$button .= !empty($array['onmouseover']) ? "onmouseenter=".self::quote($array['onmouseover'])." " : null;
$button .= !empty($array['onmouseout']) ? "onmouseleave=".self::quote($array['onmouseout'])." " : null;
//detect class addition (using + prefix)
$button_class = !empty($array['class']) && substr($array['class'],0,1) == '+' ? 'default '.substr($array['class'], 1) : $array['class'] ?? '';
$button .= "class='btn btn-".(!empty($button_class) ? $button_class : 'default')." ".(isset($array['disabled']) && $array['disabled'] ? 'disabled' : null)."' ";
//ensure margin* styles are not applied to the button element when a link is defined
if (!empty($array['style']) && is_array($array['style']) && @sizeof($array['style']) != 0) {
$styles = '';
foreach ($array['style'] as $property => $value) {
if (empty($array['link']) || !substr_count($property, 'margin')) {
$styles .= $property.': '.$value.'; ';
}
}
$button .= $styles ? "style=".self::quote($styles)." " : null;
unset($styles);
}
$button .= isset($array['disabled']) && $array['disabled'] ? "disabled='disabled' " : null;
$button .= ">";
//icon
if (!empty($array['icon']) && (
$button_icons == 'only' ||
$button_icons == 'always' ||
$button_icons == 'auto' ||
!$array['label']
)) {
$icon_class = is_array($array['icon']) ? $array['icon']['text'] : $array['icon'];
$button .= "<span class='".(substr($icon_class, 0, 3) != 'fa-' ? 'fa-solid fa-' : null).$icon_class." fa-fw'></span>";
}
//label
if (!empty($array['label']) && (
$button_icons != 'only' ||
!$array['icon'] ||
$array['class'] == 'link'
)) {
if (!empty($array['icon']) && $button_icons != 'always' && $button_icons != 'never' && isset($array['collapse']) && $array['collapse'] !== false) {
if ($array['collapse'] != '') {
$collapse_class = $array['collapse'];
}
else if (self::$collapse !== false) {
$collapse_class = self::$collapse;
}
}
$pad_class = !empty($array['icon']) ? 'pad' : null;
$button .= "<span class='button-label ".($collapse_class ?? '')." ".$pad_class."'>".$array['label']."</span>";
}
//button: close
$button .= "</button>";
//link
if (!empty($array['link'])) {
$anchor = "<a ";
$anchor .= "href='" . self::escape_href($array['link']) . "' ";
$anchor .= "target='".(!empty($array['target']) ? $array['target'] : '_self')."' ";
//ensure only margin* styles are applied to the anchor element
if (!empty($array['style']) && is_array($array['style']) && @sizeof($array['style']) != 0) {
$styles = '';
foreach ($array['style'] as $property => $value) {
if (substr_count($property, 'margin')) {
$styles .= $property.': '.$value.'; ';
}
}
$anchor .= $styles ? "style=".self::quote($styles)." " : null;
unset($styles);
}
$anchor .= isset($array['disabled']) && $array['disabled'] ? "class='disabled' onclick='return false;' " : null;
$anchor .= ">";
$button = $anchor.$button."</a>";
}
return $button;
}
private static function quote($value) {
return substr_count($value, "'") ? '"'.$value.'"' : "'".$value."'";
}
private static function escape_href(string $url): string {
// clear whitespace
$url = trim($url);
return htmlspecialchars($url, ENT_QUOTES, 'UTF-8');
}
}
/*
//usage
echo button::create(['type'=>'button','label'=>$text['button-label'],'icon'=>'icon','name'=>'btn','id'=>'btn','value'=>'value','link'=>'url','target'=>'_blank','onclick'=>'javascript','onmouseover'=>'javascript','onmouseout'=>'javascript','class'=>'name','style'=>'css','title'=>$text['button-label'],'collapse'=>'class','disabled'=>false]);
echo button::create([
'type'=>'button',
'label'=>$text['button-label'],
'icon'=>'icon',
'name'=>'btn',
'id'=>'btn',
'value'=>'value',
'link'=>'url',
'target'=>'_blank',
'onclick'=>'javascript',
'onmouseover'=>'javascript',
'onmouseout'=>'javascript',
'class'=>'name',
'style'=>'css',
'title'=>$text['button-label'],
'collapse'=>'class',
'disabled'=>false
]);
//options
type 'button' (default) | 'submit' | 'link'
label button text
icon name with full vendor style and prefix (e.g. 'fa-solid fa-user' instead of 'fa-user' or 'user')
value submitted value (if type is also set to 'submit')
target '_blank' | '_self' (default) | etc
onclick javascript
onmouseover javascript (actually uses onmouseenter so doesn't bubble to child elements)
onmouseout javascript (actually uses onmouseleave so doesn't bubble to child elements)
class css class[es]
style css style[s]
title tooltip text (if not set, defaults to value of label)
collapse overide the default hide class ('hide-md-dn')
disabled boolean true/false, or a value that evaluates to a boolean
//notes
1) all parameters are optional, but at least set a value for label or icon
2) overide the default hide class ('hide-md-dn') for all buttons that follow by using...
button::$collapse = '...';
3) setting either collapse (instance or default) to false (boolean) will cause the button label to always be visible
//example: enable/disable buttons with javascript
//javascript
onclick='button_enable('disabled_button');
//button
echo button::create(['type'=>'button', ... ,'id'=>'disabled_button','disabled'=>true]);
//javascript
onclick='button_disable('enabled_button');
//button
echo button::create(['type'=>'button', ... ,'id'=>'enabled_button']);
//enable button class button
echo "<script>\n";
echo " function button_enable(button_id) {\n";
echo " button = document.getElementById(button_id);\n";
echo " button.disabled = false;\n";
echo " button.classList.remove('disabled');\n";
echo " if (button.parentElement.nodeName == 'A') {\n";
echo " anchor = button.parentElement;\n";
echo " anchor.classList.remove('disabled');\n";
echo " anchor.setAttribute('onclick','');\n";
echo " }\n";
echo " }\n";
echo "</script>\n";
//disable button class button
echo "<script>\n";
echo " function button_disable(button_id) {\n";
echo " button = document.getElementById(button_id);\n";
echo " button.disabled = true;\n";
echo " button.classList.add('disabled');\n";
echo " if (button.parentElement.nodeName == 'A') {\n";
echo " anchor = button.parentElement;\n";
echo " anchor.classList.add('disabled');\n";
echo " anchor.setAttribute('onclick','return false;');\n";
echo " }\n";
echo " }\n";
echo "</script>\n";
//note: the javascript functions above are already contained in the template.php file.
*/