fusionpbx/app/streams/streams.php

323 lines
13 KiB
PHP
Raw Permalink Normal View History

2018-02-20 05:45:28 +01:00
<?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) 2018-2024
2018-02-20 05:45:28 +01:00
the Initial Developer. All Rights Reserved.
*/
2022-10-11 00:35:14 +02:00
//includes files
Use magic constant dir (#6711) * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ to load only functions.php * replace spaces with tab character * update dirname command to use levels instead of nesting * use magic constant __DIR__ * update dirname command to use levels instead of nesting * Update access_control_edit.php * Update access_control_import.php * Update access_controls.php * Update dnd.php * Update access_controls_reload.php * Update call_center_agents.php * Update call_center_agents.php * Update fax_queue.php * Update login.php * Update pdo.php * Update pdo_vm.php * Update switch.php * Update index.php * Update css.php * Update v_mailto.php * Update fax_to_email.php --------- Co-authored-by: FusionPBX <markjcrane@gmail.com>
2023-06-15 19:28:23 +02:00
require_once dirname(__DIR__, 2) . "/resources/require.php";
2018-02-20 05:45:28 +01:00
require_once "resources/check_auth.php";
2019-12-09 18:31:49 +01:00
require_once "resources/paging.php";
2018-02-20 05:45:28 +01:00
//check permissions
if (permission_exists('stream_view')) {
//access granted
}
else {
echo "access denied";
exit;
}
//add multi-lingual support
$language = new text;
$text = $language->get();
//set additional variables
$show = $_GET["show"] ?? '';
//set the defaults
$search = '';
2019-12-09 18:31:49 +01:00
//get the http post data
if (!empty($_POST['streams'])) {
2019-12-09 18:31:49 +01:00
$action = $_POST['action'];
$search = $_POST['search'];
$streams = $_POST['streams'];
2018-02-20 05:45:28 +01:00
}
2019-12-09 18:31:49 +01:00
//process the http post data by action
if (!empty($action)) {
2019-12-09 18:31:49 +01:00
switch ($action) {
case 'copy':
if (permission_exists('stream_add')) {
$obj = new streams;
$obj->copy($streams);
}
break;
case 'toggle':
if (permission_exists('stream_edit')) {
$obj = new streams;
$obj->toggle($streams);
}
break;
case 'delete':
if (permission_exists('stream_delete')) {
$obj = new streams;
$obj->delete($streams);
}
break;
2018-02-20 05:45:28 +01:00
}
2019-12-09 18:31:49 +01:00
2023-07-06 22:03:21 +02:00
header('Location: streams.php'.(!empty($search) ? '?search='.urlencode($search) : null));
2019-12-09 18:31:49 +01:00
exit;
2018-02-20 05:45:28 +01:00
}
2019-12-09 18:31:49 +01:00
//get order and order by
$order_by = $_GET["order_by"] ?? '';
$order = $_GET["order"] ?? '';
2018-02-20 05:45:28 +01:00
//add the search term
2023-06-08 22:57:33 +02:00
if (!empty($_GET["search"])) {
$search = $_GET["search"];
2018-02-20 05:45:28 +01:00
}
//prepare to page the results
2022-12-22 08:13:06 +01:00
$sql = "select count(stream_uuid) from v_streams ";
$sql .= "where true ";
2023-06-08 22:57:33 +02:00
if (!empty($search)) {
$sql .= "and (";
2022-12-22 08:13:06 +01:00
$sql .= "lower(stream_name) like :search ";
$sql .= "or lower(stream_location) like :search ";
$sql .= "or lower(stream_enabled) like :search ";
$sql .= "or lower(stream_description) like :search ";
$sql .= ") ";
2023-06-08 22:57:33 +02:00
$parameters['search'] = '%'.strtolower($search).'%';
2022-12-22 08:13:06 +01:00
}
if (permission_exists('stream_all') && $show == "all") {
2022-12-22 08:13:06 +01:00
//show all
}
elseif (permission_exists('stream_all')) {
2019-08-14 15:38:24 +02:00
$sql .= "and (domain_uuid = :domain_uuid or domain_uuid is null) ";
$parameters['domain_uuid'] = $domain_uuid;
2018-02-20 05:45:28 +01:00
}
2022-12-22 08:13:06 +01:00
else {
$sql .= "and domain_uuid = :domain_uuid ";
$parameters['domain_uuid'] = $domain_uuid;
}
2019-08-14 15:38:24 +02:00
$database = new database;
$num_rows = $database->select($sql, $parameters ?? null, 'column');
2022-12-22 08:13:06 +01:00
unset($parameters);
2018-02-20 05:45:28 +01:00
//prepare to page the results
2023-07-06 22:03:21 +02:00
$rows_per_page = (!empty($_SESSION['domain']['paging']['numeric'])) ? $_SESSION['domain']['paging']['numeric'] : 50;
2018-02-20 05:45:28 +01:00
$param = "&search=".$search;
$param = ($show == 'all' && permission_exists('stream_all')) ? "&show=all" : null;
$page = isset($_GET['page']) ? $_GET['page'] : 0;
if (!empty($page)) { $page = 0; $_GET['page'] = 0; }
2019-12-09 18:31:49 +01:00
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);
2018-02-20 05:45:28 +01:00
$offset = $rows_per_page * $page;
//get the list
2022-12-22 08:13:06 +01:00
$sql = "select * from v_streams ";
$sql .= "where true ";
2023-06-08 22:57:33 +02:00
if (!empty($search)) {
$sql .= "and (";
2022-12-22 08:13:06 +01:00
$sql .= " lower(stream_name) like :search ";
$sql .= " or lower(stream_location) like :search ";
$sql .= " or lower(stream_enabled) like :search ";
$sql .= " or lower(stream_description) like :search ";
$sql .= ") ";
2023-06-08 22:57:33 +02:00
$parameters['search'] = '%'.strtolower($search).'%';
2022-12-22 08:13:06 +01:00
}
if (permission_exists('stream_all') && $show == "all") {
2022-12-22 08:13:06 +01:00
//show all
}
elseif (permission_exists('stream_all')) {
$sql .= "and (domain_uuid = :domain_uuid or domain_uuid is null) ";
$parameters['domain_uuid'] = $domain_uuid;
}
else {
$sql .= "and domain_uuid = :domain_uuid ";
$parameters['domain_uuid'] = $domain_uuid;
}
2019-12-09 18:31:49 +01:00
$sql .= order_by($order_by, $order, 'stream_name', 'asc');
2019-08-14 15:38:24 +02:00
$sql .= limit_offset($rows_per_page, $offset);
$database = new database;
$streams = $database->select($sql, (!empty($parameters) && @sizeof($parameters) != 0 ? $parameters : null), 'all');
2019-08-14 15:38:24 +02:00
unset($sql, $parameters);
2018-02-20 05:45:28 +01:00
2019-12-09 18:31:49 +01:00
//create token
$object = new token;
$token = $object->create($_SERVER['PHP_SELF']);
//include header
2020-01-06 19:56:51 +01:00
$document['title'] = $text['title-streams'];
2019-12-09 18:31:49 +01:00
require_once "resources/header.php";
2018-02-20 05:45:28 +01:00
2019-08-14 15:38:24 +02:00
//audio control styles
echo "<style>\n";
echo " audio {\n";
2019-12-09 18:31:49 +01:00
echo " margin-top: 0px;\n";
echo " margin-bottom: -6px;\n";
2019-08-14 15:38:24 +02:00
echo " width: 100%;\n";
echo " height: 35px;\n";
echo " }\n";
echo "</style>\n";
2018-02-20 05:45:28 +01:00
//show the content
2019-12-09 18:31:49 +01:00
echo "<div class='action_bar' id='action_bar'>\n";
echo " <div class='heading'><b>".$text['title-streams']."</b><div class='count'>".number_format($num_rows)."</div></div>\n";
2019-12-09 18:31:49 +01:00
echo " <div class='actions'>\n";
if (permission_exists('stream_add')) {
echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'id'=>'btn_add','link'=>'stream_edit.php']);
2019-12-09 18:31:49 +01:00
}
if (permission_exists('stream_add') && $streams) {
echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$_SESSION['theme']['button_icon_copy'],'id'=>'btn_copy','name'=>'btn_copy','style'=>'display: none;','onclick'=>"modal_open('modal-copy','btn_copy');"]);
2019-12-09 18:31:49 +01:00
}
if (permission_exists('stream_edit') && $streams) {
echo button::create(['type'=>'button','label'=>$text['button-toggle'],'icon'=>$_SESSION['theme']['button_icon_toggle'],'id'=>'btn_toggle','name'=>'btn_toggle','style'=>'display: none;','onclick'=>"modal_open('modal-toggle','btn_toggle');"]);
2019-12-09 18:31:49 +01:00
}
if (permission_exists('stream_delete') && $streams) {
echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'id'=>'btn_delete','name'=>'btn_delete','style'=>'display: none;','onclick'=>"modal_open('modal-delete','btn_delete');"]);
2019-12-09 18:31:49 +01:00
}
echo "<form id='form_search' class='inline' method='get'>\n";
2018-02-20 05:45:28 +01:00
if (permission_exists('stream_all')) {
if ($show == 'all') {
2019-12-09 18:31:49 +01:00
echo " <input type='hidden' name='show' value='all'>\n";
2018-02-20 05:45:28 +01:00
}
else {
2019-12-09 18:31:49 +01:00
echo button::create(['type'=>'button','label'=>$text['button-show_all'],'icon'=>$_SESSION['theme']['button_icon_all'],'link'=>'?show=all']);
2018-02-20 05:45:28 +01:00
}
}
2019-12-09 18:31:49 +01:00
echo "<input type='text' class='txt list-search' name='search' id='search' value=\"".escape($search)."\" placeholder=\"".$text['label-search']."\" onkeydown='list_search_reset();'>";
2023-07-06 22:03:21 +02:00
echo button::create(['label'=>$text['button-search'],'icon'=>$_SESSION['theme']['button_icon_search'],'type'=>'submit','id'=>'btn_search','style'=>(!empty($search) ? 'display: none;' : null)]);
2019-12-09 18:31:49 +01:00
echo button::create(['label'=>$text['button-reset'],'icon'=>$_SESSION['theme']['button_icon_reset'],'type'=>'button','id'=>'btn_reset','link'=>'streams.php','style'=>($search == '' ? 'display: none;' : null)]);
2023-07-06 22:03:21 +02:00
if (!empty($paging_controls_mini)) {
2019-12-09 18:31:49 +01:00
echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>\n";
}
2018-02-20 05:45:28 +01:00
echo " </form>\n";
2019-12-09 18:31:49 +01:00
echo " </div>\n";
echo " <div style='clear: both;'></div>\n";
echo "</div>\n";
if (permission_exists('stream_add') && $streams) {
echo modal::create(['id'=>'modal-copy','type'=>'copy','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_copy','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('copy'); list_form_submit('form_list');"])]);
}
if (permission_exists('stream_edit') && $streams) {
echo modal::create(['id'=>'modal-toggle','type'=>'toggle','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_toggle','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('toggle'); list_form_submit('form_list');"])]);
}
if (permission_exists('stream_delete') && $streams) {
echo modal::create(['id'=>'modal-delete','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'); list_form_submit('form_list');"])]);
}
2019-12-09 18:31:49 +01:00
echo $text['title_description-stream']."\n";
echo "<br /><br />\n";
2018-02-20 05:45:28 +01:00
2019-12-09 18:31:49 +01:00
echo "<form id='form_list' method='post'>\n";
echo "<input type='hidden' id='action' name='action' value=''>\n";
echo "<input type='hidden' name='search' value=\"".escape($search)."\">\n";
echo "<div class='card'>\n";
2019-12-09 18:31:49 +01:00
echo "<table class='list'>\n";
echo "<tr class='list-header'>\n";
if (permission_exists('stream_add') || permission_exists('stream_edit') || permission_exists('stream_delete')) {
echo " <th class='checkbox'>\n";
2023-06-08 22:57:33 +02:00
echo " <input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='list_all_toggle(); checkbox_on_change(this);' ".(empty($streams) ? "style='visibility: hidden;'" : null).">\n";
2019-12-09 18:31:49 +01:00
echo " </th>\n";
2018-03-02 06:36:42 +01:00
}
if ($show == 'all' && permission_exists('stream_all')) {
2019-12-09 18:31:49 +01:00
echo th_order_by('domain_name', $text['label-domain'], $order_by, $order);
2018-02-20 05:45:28 +01:00
}
2019-12-09 18:31:49 +01:00
echo th_order_by('stream_name', $text['label-stream_name'], $order_by, $order);
echo " <th class='pct-60'>".$text['label-play']."</th>\n";
echo th_order_by('stream_enabled', $text['label-stream_enabled'], $order_by, $order, null, "class='center'");
echo th_order_by('stream_description', $text['label-stream_description'], $order_by, $order, null, "class='hide-sm-dn'");
if (permission_exists('stream_edit') && filter_var($_SESSION['theme']['list_row_edit_button']['boolean'] ?? false, FILTER_VALIDATE_BOOL)) {
2019-12-09 18:31:49 +01:00
echo " <td class='action-button'>&nbsp;</td>\n";
2018-02-20 05:45:28 +01:00
}
2019-12-09 18:31:49 +01:00
echo "</tr>\n";
2018-02-20 05:45:28 +01:00
2023-07-06 22:03:21 +02:00
if (!empty($streams)) {
2018-02-20 05:45:28 +01:00
$x = 0;
2019-12-09 18:31:49 +01:00
foreach ($streams as $row) {
$list_row_url = '';
2018-02-20 05:45:28 +01:00
if (permission_exists('stream_edit')) {
2019-12-09 18:31:49 +01:00
$list_row_url = "stream_edit.php?id=".urlencode($row['stream_uuid']);
if ($row['domain_uuid'] != $_SESSION['domain_uuid'] && permission_exists('domain_select')) {
$list_row_url .= '&domain_uuid='.urlencode($row['domain_uuid']).'&domain_change=true';
}
2018-02-20 05:45:28 +01:00
}
2019-12-09 18:31:49 +01:00
echo "<tr class='list-row' href='".$list_row_url."'>\n";
if (permission_exists('stream_add') || permission_exists('stream_edit') || permission_exists('stream_delete')) {
echo " <td class='checkbox'>\n";
echo " <input type='checkbox' name='streams[$x][checked]' id='checkbox_".$x."' value='true' onclick=\"checkbox_on_change(this); if (!this.checked) { document.getElementById('checkbox_all').checked = false; }\">\n";
2019-12-09 18:31:49 +01:00
echo " <input type='hidden' name='streams[$x][uuid]' value='".escape($row['stream_uuid'])."' />\n";
echo " </td>\n";
}
2023-06-08 22:57:33 +02:00
if (!empty($_GET['show']) && $_GET['show'] == 'all' && permission_exists('stream_all')) {
2019-12-09 18:31:49 +01:00
echo " <td>";
2023-07-06 22:03:21 +02:00
if (!empty($_SESSION['domains'][$row['domain_uuid']]['domain_name'])) {
2019-12-09 18:31:49 +01:00
echo escape($_SESSION['domains'][$row['domain_uuid']]['domain_name']);
2018-03-02 06:36:42 +01:00
}
else {
2019-12-09 18:31:49 +01:00
echo $text['label-global'];
2018-03-02 06:36:42 +01:00
}
2019-12-09 18:31:49 +01:00
echo " </td>\n";
2018-03-02 06:36:42 +01:00
}
2019-12-09 18:31:49 +01:00
echo " <td class='no-wrap'>\n";
if (permission_exists('stream_edit')) {
echo " <a href='".$list_row_url."' title=\"".$text['button-edit']."\">".escape($row['stream_name'])."</a>\n";
}
else {
echo " ".escape($row['stream_name']);
}
echo " </td>\n";
echo " <td class='no-wrap button'>\n";
if (!empty($row['stream_location'])) {
2018-03-02 09:05:51 +01:00
$location_parts = explode('://',$row['stream_location']);
2022-03-29 20:05:44 +02:00
$http_protocol = ($location_parts[0] == "shout") ? 'http' : 'https';
2023-06-08 22:57:33 +02:00
echo "<audio src='".$http_protocol."://".($location_parts[1] ?? '')."' controls='controls' />\n";
2018-03-02 09:05:51 +01:00
}
echo " </td>\n";
2018-02-20 05:45:28 +01:00
if (permission_exists('stream_edit')) {
2019-12-09 18:31:49 +01:00
echo " <td class='no-link center'>\n";
echo button::create(['type'=>'submit','class'=>'link','label'=>$text['label-'.$row['stream_enabled']],'title'=>$text['button-toggle'],'onclick'=>"list_self_check('checkbox_".$x."'); list_action_set('toggle'); list_form_submit('form_list')"]);
2018-02-20 05:45:28 +01:00
}
2019-12-09 18:31:49 +01:00
else {
echo " <td class='center'>\n";
echo $text['label-'.$row['stream_enabled']];
2018-02-20 05:45:28 +01:00
}
echo " </td>\n";
2019-12-09 18:31:49 +01:00
echo " <td class='description overflow hide-sm-dn'>".escape($row['stream_description'])."&nbsp;</td>\n";
if (permission_exists('stream_edit') && filter_var($_SESSION['theme']['list_row_edit_button']['boolean'] ?? false, FILTER_VALIDATE_BOOL)) {
2019-12-09 18:31:49 +01:00
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";
}
2018-02-20 05:45:28 +01:00
echo "</tr>\n";
$x++;
2019-08-14 15:38:24 +02:00
}
}
2019-12-09 18:31:49 +01:00
unset($streams);
2018-02-20 05:45:28 +01:00
2019-12-09 18:31:49 +01:00
echo "</table>\n";
echo "</div>\n";
2019-12-09 18:31:49 +01:00
echo "<br />\n";
echo "<div align='center'>".$paging_controls."</div>\n";
echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
2018-02-20 05:45:28 +01:00
echo "</form>\n";
//include the footer
require_once "resources/footer.php";
?>