Add call flows to feature codes (#7972)

* Add call flows to feature codes

* Refactor permission checks for feature codes
This commit is contained in:
frytimo
2026-05-13 14:37:57 +00:00
committed by GitHub
parent 42185e804f
commit d6f2ac28f5
2 changed files with 41 additions and 16 deletions
+8 -16
View File
@@ -62,19 +62,8 @@
$order_by = $_GET["order_by"] ?? ''; $order_by = $_GET["order_by"] ?? '';
$order = $_GET["order"] ?? ''; $order = $_GET["order"] ?? '';
//get feature codes from dialplans //get feature codes from dialplans and call flows
$sql = "SELECT dialplan_uuid, dialplan_name, dialplan_number, dialplan_description "; $features = feature_codes::fetch_features($database, permission_exists('feature_codes_raw'));
if (permission_exists('feature_codes_raw')) {
$sql .= ", dialplan_xml ";
}
$sql .= "FROM v_dialplans ";
$sql .= "WHERE dialplan_enabled = 'true' ";
$sql .= "AND dialplan_number LIKE '*%' ";
$sql .= "AND (domain_uuid = :domain_uuid OR domain_uuid IS NULL) ";
$sql .= order_by($order_by, $order, 'dialplan_number', 'asc');
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$features = $database->select($sql, $parameters, 'all');
unset($sql, $parameters);
//handle PDF export //handle PDF export
if (isset($_GET['export']) && $_GET['export'] == 'pdf' && permission_exists('feature_codes_export')) { if (isset($_GET['export']) && $_GET['export'] == 'pdf' && permission_exists('feature_codes_export')) {
@@ -108,18 +97,20 @@
$pdf->Cell($col_widths[3], 8, $text['label-raw_dialplan'], 1, 1, 'L', true); $pdf->Cell($col_widths[3], 8, $text['label-raw_dialplan'], 1, 1, 'L', true);
} }
else { else {
$feature_code = $row['feature_code'] ?? '';
$col_widths = array(30, 50, 110); $col_widths = array(30, 50, 110);
$pdf->Cell($col_widths[0], 8, $text['label-feature_code'], 1, 0, 'L', true); $pdf->Cell($col_widths[0], 8, $text['label-feature_code'], 1, 0, 'L', true);
$pdf->Cell($col_widths[1], 8, $text['label-feature_name'], 1, 0, 'L', true); $pdf->Cell($col_widths[1], 8, $text['label-feature_name'], 1, 0, 'L', true);
$pdf->Cell($col_widths[2], 8, $text['label-description'], 1, 1, 'L', true); $pdf->Cell($col_widths[2], 8, $text['label-description'], 1, 1, 'L', true);
} }
$feature_code = $row['feature_code'] ?? '';
//table rows //table rows
$pdf->SetFont('Arial', '', 9); $pdf->SetFont('Arial', '', 9);
if (is_array($features) && count($features) > 0) { if (is_array($features) && count($features) > 0) {
foreach ($features as $row) { foreach ($features as $row) {
//set the feature dialing code eg. *67 //set the feature dialing code eg. *67
$feature_code = $row['dialplan_number'] ?? ''; $feature_code = $row['feature_code'] ?? '';
$dialplan_name = $row['dialplan_name'] ?? ''; $dialplan_name = $row['dialplan_name'] ?? '';
@@ -141,6 +132,7 @@
$raw_value .= '...'; $raw_value .= '...';
} }
echo th_order_by('feature_code', $text['label-feature_code'], $order_by, $order);
//calculate row height by measuring actual text width //calculate row height by measuring actual text width
$desc_width = $col_widths[2] - 2; //account for cell padding $desc_width = $col_widths[2] - 2; //account for cell padding
$line_height = 5; $line_height = 5;
@@ -314,7 +306,7 @@
echo "<div class='card'>\n"; echo "<div class='card'>\n";
echo "<table class='list'>\n"; echo "<table class='list'>\n";
echo "<tr class='list-header'>\n"; echo "<tr class='list-header'>\n";
echo th_order_by('dialplan_number', $text['label-feature_code'], $order_by, $order); echo th_order_by('feature_code', $text['label-feature_code'], $order_by, $order);
echo th_order_by('dialplan_name', $text['label-feature_name'], $order_by, $order); echo th_order_by('dialplan_name', $text['label-feature_name'], $order_by, $order);
echo " <th class='hide-sm-dn'>".$text['label-description']."</th>\n"; echo " <th class='hide-sm-dn'>".$text['label-description']."</th>\n";
if (permission_exists('feature_codes_raw')) { if (permission_exists('feature_codes_raw')) {
@@ -325,7 +317,7 @@
if (is_array($features) && count($features) > 0) { if (is_array($features) && count($features) > 0) {
foreach ($features as $row) { foreach ($features as $row) {
//set the feature dialing code eg. *67 //set the feature dialing code eg. *67
$feature_code = $row['dialplan_number'] ?? ''; $feature_code = $row['feature_code'] ?? '';
$dialplan_name = $row['dialplan_name'] ?? ''; $dialplan_name = $row['dialplan_name'] ?? '';
@@ -52,6 +52,39 @@ class feature_codes {
return 'Features Report'; return 'Features Report';
} }
/**
* Fetch feature code rows from the dialplan and call flows tables.
*
* Dialplan entries whose number begins with '*' are included. Call flows
* that have a feature code set are joined in and that code is used in
* place of the dialplan number.
*
* @param database $database Database instance to use for the query.
* @param bool $include_raw Include the raw dialplan_xml column.
*
* @return array Array of associative rows, or an empty array.
*/
public static function fetch_features(database $database, bool $include_raw = false): array {
$domain_uuid = $_SESSION['domain_uuid'] ?? '';
$order_by = $_GET['order_by'] ?? '';
$order = $_GET['order'] ?? '';
$sql = "SELECT d.dialplan_uuid, d.dialplan_name, ";
$sql .= "COALESCE(NULLIF(cf.call_flow_feature_code, ''), d.dialplan_number) AS feature_code, ";
$sql .= "COALESCE(cf.call_flow_description, d.dialplan_description) AS dialplan_description ";
if ($include_raw) {
$sql .= ", d.dialplan_xml ";
}
$sql .= "FROM v_dialplans d ";
$sql .= "LEFT JOIN v_call_flows cf ON cf.dialplan_uuid = d.dialplan_uuid ";
$sql .= "WHERE d.dialplan_enabled = 'true' ";
$sql .= "AND (d.dialplan_number LIKE '*%' OR NULLIF(cf.call_flow_feature_code, '') IS NOT NULL) ";
$sql .= "AND (d.domain_uuid = :domain_uuid OR d.domain_uuid IS NULL) ";
$sql .= order_by($order_by, $order, 'feature_code', 'asc');
$parameters['domain_uuid'] = $domain_uuid;
$result = $database->select($sql, $parameters, 'all');
return is_array($result) ? $result : [];
}
public function display(): void { public function display(): void {
echo $this->render(); echo $this->render();
return; return;