diff --git a/app/feature_codes/app_config.php b/app/feature_codes/app_config.php new file mode 100644 index 0000000000..185149b7f3 --- /dev/null +++ b/app/feature_codes/app_config.php @@ -0,0 +1,46 @@ + diff --git a/app/feature_codes/app_languages.php b/app/feature_codes/app_languages.php new file mode 100644 index 0000000000..199d7cbf19 --- /dev/null +++ b/app/feature_codes/app_languages.php @@ -0,0 +1,237 @@ + diff --git a/app/feature_codes/app_menu.php b/app/feature_codes/app_menu.php new file mode 100644 index 0000000000..5ee8a24d36 --- /dev/null +++ b/app/feature_codes/app_menu.php @@ -0,0 +1,39 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2026 + the Initial Developer. All Rights Reserved. +*/ + +//includes files + require_once dirname(__DIR__, 2) . "/resources/require.php"; + require_once "resources/check_auth.php"; + +//check permissions + if (!permission_exists('feature_codes_view')) { + echo "access denied"; + exit; + } + +//function to format feature name for display + function format_feature_name($name) { + //replace underscores and hyphens with spaces + $name = str_replace(array('_', '-'), ' ', $name); + //capitalize each word + $name = ucwords($name); + return $name; + } + +//add multi-lingual support + $language = new text; + $text = $language->get(); + +//get globals + global $database, $settings; + +//backwards compatibility + if (!isset($database) || !($database instanceof database)) { + $database = database::new(); + } + if (!isset($settings) || !($settings instanceof settings)) { + $settings = new settings(['database' => $database, 'domain_uuid' => $domain_uuid ?? $_SESSION['domain_uuid'] ?? '', 'user_uuid' => $user_uuid ?? $_SESSION['user_uuid'] ?? '']); + } + +//get order and order by + $order_by = $_GET["order_by"] ?? ''; + $order = $_GET["order"] ?? ''; + +//get feature codes from dialplans + $sql = "SELECT dialplan_uuid, dialplan_name, dialplan_number, dialplan_description "; + 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 + if (isset($_GET['export']) && $_GET['export'] == 'pdf' && permission_exists('feature_codes_export')) { + + //include fpdf + require_once "resources/fpdf/fpdf.php"; + + //create pdf + $pdf = new FPDF('P', 'mm', 'A4'); + $pdf->SetAutoPageBreak(true, 15); + $pdf->AddPage(); + $pdf->SetFont('Arial', 'B', 16); + + //title + $pdf->Cell(0, 10, $text['title-feature_codes'], 0, 1, 'C'); + $pdf->Ln(5); + + //table header + $pdf->SetFont('Arial', 'B', 10); + $pdf->SetFillColor(240, 240, 240); + + if (permission_exists('feature_codes_raw')) { + $pdf->Cell(30, 8, $text['label-feature_code'], 1, 0, 'L', true); + $pdf->Cell(50, 8, $text['label-feature_name'], 1, 0, 'L', true); + $pdf->Cell(50, 8, $text['label-description'], 1, 0, 'L', true); + $pdf->Cell(60, 8, $text['label-raw_dialplan'], 1, 1, 'L', true); + } + else { + $pdf->Cell(40, 8, $text['label-feature_code'], 1, 0, 'L', true); + $pdf->Cell(60, 8, $text['label-feature_name'], 1, 0, 'L', true); + $pdf->Cell(90, 8, $text['label-description'], 1, 1, 'L', true); + } + + //table rows + $pdf->SetFont('Arial', '', 9); + if (is_array($features) && count($features) > 0) { + foreach ($features as $row) { + $feature_code = $row['dialplan_number']; + $feature_name = format_feature_name($row['dialplan_name']); + $feature_description = $row['dialplan_description']; + + if (permission_exists('feature_codes_raw')) { + $raw_value = isset($row['dialplan_xml']) ? substr($row['dialplan_xml'], 0, 50) : ''; + if (strlen($row['dialplan_xml']) > 50) { + $raw_value .= '...'; + } + $pdf->Cell(30, 7, $feature_code, 1, 0, 'L'); + $pdf->Cell(50, 7, substr($feature_name, 0, 30), 1, 0, 'L'); + $pdf->Cell(50, 7, substr($feature_description, 0, 30), 1, 0, 'L'); + $pdf->Cell(60, 7, $raw_value, 1, 1, 'L'); + } + else { + $pdf->Cell(40, 7, $feature_code, 1, 0, 'L'); + $pdf->Cell(60, 7, substr($feature_name, 0, 35), 1, 0, 'L'); + $pdf->Cell(90, 7, substr($feature_description, 0, 55), 1, 1, 'L'); + } + } + } + else { + $col_span = permission_exists('feature_codes_raw') ? 190 : 190; + $pdf->Cell($col_span, 7, $text['label-no_features'], 1, 1, 'C'); + } + + //output pdf + $pdf->Output('feature_codes_' . date('Y-m-d') . '.pdf', 'D'); + exit; + } + +//include header + $document['title'] = $text['title-feature_codes']; + require_once "resources/header.php"; + +//javascript to toggle export select box + echo ""; + +//content + echo "
\n"; + echo "
".$text['title-feature_codes']."
\n"; + echo "
\n"; + + if (permission_exists('feature_codes_export')) { + echo button::create(array('type'=>'button','label'=>$text['button-export'],'icon'=>$settings->get('theme', 'button_icon_export'),'onclick'=>"toggle_select('export_format'); this.blur();")); + echo " \n"; + } + + echo "
\n"; + echo "
\n"; + echo "
\n"; + + echo $text['description-feature_codes']."\n"; + echo "

\n"; + + echo "
\n"; + echo "\n"; + echo "\n"; + echo th_order_by('dialplan_number', $text['label-feature_code'], $order_by, $order); + echo th_order_by('dialplan_name', $text['label-feature_name'], $order_by, $order); + echo " \n"; + if (permission_exists('feature_codes_raw')) { + echo " \n"; + } + echo "\n"; + + if (is_array($features) && count($features) > 0) { + foreach ($features as $row) { + echo "\n"; + echo " \n"; + echo " \n"; + echo " \n"; + if (permission_exists('feature_codes_raw')) { + $raw_display = isset($row['dialplan_xml']) ? htmlspecialchars(substr($row['dialplan_xml'], 0, 100)) : ''; + if (isset($row['dialplan_xml']) && strlen($row['dialplan_xml']) > 100) { + $raw_display .= '...'; + } + echo " \n"; + } + echo "\n"; + } + } + else { + $colspan = permission_exists('feature_codes_raw') ? 4 : 3; + echo "\n"; + echo " \n"; + echo "\n"; + } + + echo "
".$text['label-description']."".$text['label-raw_dialplan']."
".escape($row['dialplan_number'])."".escape(format_feature_name($row['dialplan_name']))."".escape($row['dialplan_description'])."".$raw_display."
".$text['label-no_features']."
\n"; + echo "
\n"; + +//include footer + require_once "resources/footer.php"; + +?> diff --git a/app/feature_codes/resources/classes/feature_codes.php b/app/feature_codes/resources/classes/feature_codes.php new file mode 100644 index 0000000000..f7837d1301 --- /dev/null +++ b/app/feature_codes/resources/classes/feature_codes.php @@ -0,0 +1,63 @@ +domain_uuid = $setting_array['domain_uuid'] ?? $_SESSION['domain_uuid'] ?? ''; + $this->user_uuid = $setting_array['user_uuid'] ?? $_SESSION['user_uuid'] ?? ''; + + //set objects + $config = $setting_array['config'] ?? config::load(); + $this->database = $setting_array['database'] ?? database::new(['config' => $config]); + $this->settings = $setting_array['settings'] ?? new settings(['database' => $this->database, 'domain_uuid' => $this->domain_uuid, 'user_uuid' => $this->user_uuid]); + } + + public function get_name() { + return 'Features Report'; + } + + public function display(): void { + echo $this->render(); + return; + } + + public function render(): string { + return "Features Report"; + } +}