Streams: List view updates.

This commit is contained in:
Nate
2019-12-09 10:31:49 -07:00
parent c9cfcb5932
commit b9462f1817
2 changed files with 356 additions and 206 deletions
+139 -146
View File
@@ -25,6 +25,7 @@
require_once "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
require_once "resources/paging.php";
//check permissions
if (permission_exists('stream_view')) {
@@ -39,32 +40,41 @@
$language = new text;
$text = $language->get();
//get the action
if (is_array($_POST["streams"])) {
$streams = $_POST["streams"];
foreach($streams as $row) {
if ($row['action'] == 'delete') {
$action = 'delete';
//get the http post data
if (is_array($_POST['streams'])) {
$action = $_POST['action'];
$search = $_POST['search'];
$streams = $_POST['streams'];
}
//process the http post data by action
if ($action != '' && is_array($streams) && @sizeof($streams) != 0) {
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;
}
}
header('Location: streams.php'.($search != '' ? '?search='.urlencode($search) : null));
exit;
}
//delete the streams
if (permission_exists('stream_delete')) {
if ($action == "delete") {
//download
$obj = new streams;
$obj->delete($streams);
//delete message
message::add($text['message-delete']);
//redirect
header('Location: streams.php');
exit;
}
}
//get variables used to control the order
//get order and order by
$order_by = $_GET["order_by"];
$order = $_GET["order"];
@@ -75,200 +85,183 @@
$sql_search .= "lower(stream_name) like :search ";
$sql_search .= "or lower(stream_location) like :search ";
$sql_search .= "or lower(stream_enabled) like :search ";
$sql_search .= "or lower(domain_uuid) like :search ";
$sql_search .= "or lower(stream_description) like :search ";
$sql_search .= ") ";
$parameters['search'] = '%'.$search.'%';
}
//additional includes
require_once "resources/header.php";
require_once "resources/paging.php";
//prepare to page the results
$sql = "select count(*) from v_streams ";
$sql .= "where true ";
$sql = "select count(stream_uuid) from v_streams where true ";
$sql .= $sql_search;
if (!($_GET['show'] == "all" && permission_exists('stream_all'))) {
$sql .= "and (domain_uuid = :domain_uuid or domain_uuid is null) ";
$parameters['domain_uuid'] = $domain_uuid;
}
$database = new database;
$num_rows = $database->select($sql, (is_array($parameters) && @sizeof($parameters) != 0 ? $parameters : null), 'column');
$num_rows = $database->select($sql, $parameters, 'column');
//prepare to page the results
$rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
$param = "&search=".$search;
if ($_GET['show'] == "all" && permission_exists('stream_all')) {
$param .= "&show=all";
}
$page = $_GET['page'];
$param = ($_GET['show'] == 'all' && permission_exists('stream_all')) ? "&show=all" : null;
$page = is_numeric($_GET['page']) ? $_GET['page'] : 0;
if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; }
list($paging_controls, $rows_per_page, $var3) = paging($num_rows, $param, $rows_per_page);
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);
$offset = $rows_per_page * $page;
//get the list
$sql = str_replace('count(*)', '*', $sql);
$sql .= order_by($order_by, $order);
$sql = str_replace('count(stream_uuid)', '*', $sql);
$sql .= order_by($order_by, $order, 'stream_name', 'asc');
$sql .= limit_offset($rows_per_page, $offset);
$database = new database;
$streams = $database->select($sql, (is_array($parameters) && @sizeof($parameters) != 0 ? $parameters : null), 'all');
unset($sql, $parameters);
//alternate the row style
$c = 0;
$row_style["0"] = "row_style0";
$row_style["1"] = "row_style1";
//create token
$object = new token;
$token = $object->create($_SERVER['PHP_SELF']);
//include header
require_once "resources/header.php";
//audio control styles
echo "<style>\n";
echo " audio {\n";
echo " margin-bottom: -5px;\n";
echo " margin-top: 0px;\n";
echo " margin-bottom: -6px;\n";
echo " width: 100%;\n";
echo " height: 35px;\n";
echo " }\n";
echo "</style>\n";
//define the checkbox_toggle function
echo "<script type=\"text/javascript\">\n";
echo " function checkbox_toggle(item) {\n";
echo " var inputs = document.getElementsByTagName(\"input\");\n";
echo " for (var i = 0, max = inputs.length; i < max; i++) {\n";
echo " if (inputs[i].type === 'checkbox') {\n";
echo " if (document.getElementById('checkbox_all').checked == true) {\n";
echo " inputs[i].checked = true;\n";
echo " }\n";
echo " else {\n";
echo " inputs[i].checked = false;\n";
echo " }\n";
echo " }\n";
echo " }\n";
echo " }\n";
echo "</script>\n";
//show the content
echo "<table width='100%' border='0'>\n";
echo " <tr>\n";
echo " <td width='50%' align='left' nowrap='nowrap'><b>".$text['title-streams']."</b></td>\n";
echo " <form method='get' action=''>\n";
echo " <td width='50%' style='vertical-align: top; text-align: right; white-space: nowrap;'>\n";
echo "<div class='action_bar' id='action_bar'>\n";
echo " <div class='heading'><b>".$text['title-streams']." (".$num_rows.")</b></div>\n";
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'],'link'=>'stream_edit.php']);
}
if (permission_exists('stream_add') && $streams) {
echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$_SESSION['theme']['button_icon_copy'],'onclick'=>"if (confirm('".$text['confirm-copy']."')) { list_action_set('copy'); list_form_submit('form_list'); } else { this.blur(); return false; }"]);
}
if (permission_exists('stream_edit') && $streams) {
echo button::create(['type'=>'button','label'=>$text['button-toggle'],'icon'=>$_SESSION['theme']['button_icon_toggle'],'onclick'=>"if (confirm('".$text['confirm-toggle']."')) { list_action_set('toggle'); list_form_submit('form_list'); } else { this.blur(); return false; }"]);
}
if (permission_exists('stream_delete') && $streams) {
echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'onclick'=>"if (confirm('".$text['confirm-delete']."')) { list_action_set('delete'); list_form_submit('form_list'); } else { this.blur(); return false; }"]);
}
echo "<form id='form_search' class='inline' method='get'>\n";
if (permission_exists('stream_all')) {
if ($_GET['show'] == 'all') {
echo " <input type='hidden' name='show' value='all'>";
echo " <input type='hidden' name='show' value='all'>\n";
}
else {
echo " <input type='button' class='btn' value='".$text['button-show_all']."' onclick=\"window.location='streams.php?show=all';\">\n";
echo button::create(['type'=>'button','label'=>$text['button-show_all'],'icon'=>$_SESSION['theme']['button_icon_all'],'link'=>'?show=all']);
}
}
echo " <input type='text' class='txt' style='width: 150px; margin-left: 15px;' name='search' id='search' value='".escape($search)."'>\n";
echo " <input type='submit' class='btn' name='submit' value='".$text['button-search']."'>\n";
echo " </td>\n";
echo "<input type='text' class='txt list-search' name='search' id='search' value=\"".escape($search)."\" placeholder=\"".$text['label-search']."\" onkeydown='list_search_reset();'>";
echo button::create(['label'=>$text['button-search'],'icon'=>$_SESSION['theme']['button_icon_search'],'type'=>'submit','id'=>'btn_search','style'=>($search != '' ? 'display: none;' : null)]);
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)]);
if ($paging_controls_mini != '') {
echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>\n";
}
echo " </form>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td align='left' colspan='2'>\n";
echo " ".$text['title_description-stream']."<br /><br />\n";
echo " </td>\n";
echo " </tr>\n";
echo "</table>\n";
echo " </div>\n";
echo " <div style='clear: both;'></div>\n";
echo "</div>\n";
echo "<form method='post' action=''>\n";
echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo "<tr>\n";
echo " <th style='width:30px;'>\n";
echo " <input type='checkbox' name='checkbox_all' id='checkbox_all' value='' onclick=\"checkbox_toggle();\">\n";
echo " </th>\n";
if ($_GET['show'] == "all" && permission_exists('stream_all')) {
echo th_order_by('domain_name', $text['label-domain'], $order_by, $order, $param);
echo $text['title_description-stream']."\n";
echo "<br /><br />\n";
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 "<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";
echo " <input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='list_all_toggle();' ".($streams ?: "style='visibility: hidden;'").">\n";
echo " </th>\n";
}
if ($_GET['show'] == 'all' && permission_exists('stream_all')) {
echo th_order_by('domain_name', $text['label-domain'], $order_by, $order);
}
echo th_order_by('stream_name', $text['label-stream_name'], $order_by, $order);
echo " <th>".$text['label-play']."</th>\n";
//echo th_order_by('stream_location', $text['label-stream_location'], $order_by, $order);
echo th_order_by('stream_enabled', $text['label-stream_enabled'], $order_by, $order);
echo th_order_by('stream_description', $text['label-stream_description'], $order_by, $order);
echo " <td class='list_control_icons'>";
if (permission_exists('stream_add')) {
echo " <a href='stream_edit.php' alt='".$text['button-add']."'>$v_link_label_add</a>";
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') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
echo " <td class='action-button'>&nbsp;</td>\n";
}
else {
echo "&nbsp;\n";
}
echo " </td>\n";
echo "<tr>\n";
echo "</tr>\n";
if (is_array($streams)) {
if (is_array($streams) && @sizeof($streams) != 0) {
$x = 0;
foreach($streams as $row) {
foreach ($streams as $row) {
if (permission_exists('stream_edit')) {
$tr_link = "href='stream_edit.php?id=".escape($row['stream_uuid'])."'";
$list_row_url = "stream_edit.php?id=".urlencode($row['stream_uuid']);
}
echo "<tr ".$tr_link.">\n";
echo " <td valign='top' class='".$row_style[$c]." tr_link_void' style='align: center; padding: 3px 3px 0px 8px;'>\n";
echo " <input type='checkbox' name=\"streams[$x][checked]\" id='checkbox_".$x."' value='true' onclick=\"if (!this.checked) { document.getElementById('chk_all_".$x."').checked = false; }\">\n";
echo " <input type='hidden' name=\"streams[$x][stream_uuid]\" value='".escape($row['stream_uuid'])."' />\n";
echo " </td>\n";
if ($_GET['show'] == "all" && permission_exists('stream_all')) {
if (strlen($_SESSION['domains'][$row['domain_uuid']]['domain_name']) > 0) {
$domain = $_SESSION['domains'][$row['domain_uuid']]['domain_name'];
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=\"if (!this.checked) { document.getElementById('checkbox_all').checked = false; }\">\n";
echo " <input type='hidden' name='streams[$x][uuid]' value='".escape($row['stream_uuid'])."' />\n";
echo " </td>\n";
}
if ($_GET['show'] == 'all' && permission_exists('stream_all')) {
echo " <td>";
if ($_SESSION['domains'][$row['domain_uuid']]['domain_name'] != '') {
echo escape($_SESSION['domains'][$row['domain_uuid']]['domain_name']);
}
else {
$domain = $text['label-global'];
echo $text['label-global'];
}
echo " <td valign='top' class='".$row_style[$c]."' style='width: 15%; white-space: nowrap;'>".$domain."</td>\n";
echo " </td>\n";
}
echo " <td valign='top' class='".$row_style[$c]."' style='width: 15%; white-space: nowrap;'>".escape($row['stream_name'])."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."' style='white-space: nowrap; padding: 0;'>\n";
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 (strlen($row['stream_location']) > 0) {
$location_parts = explode('://',$row['stream_location']);
if ($location_parts[0] == "shout") {
echo "<audio src=\"http://".$location_parts[1]."\" controls=\"controls\" />\n";
echo "<audio src='http://".$location_parts[1]."' controls='controls' />\n";
}
}
echo " </td>\n";
//echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['stream_location'])."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."' style='white-space: nowrap;'>".($row['stream_enabled'] == 'true' ? $text['label-true'] : $text['label-false'])."</td>\n";
//echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['domain_uuid'])."&nbsp;</td>\n";
echo " <td valign='top' class='row_stylebg' style='width: 20%; white-space: nowrap;'>".escape($row['stream_description'])."&nbsp;</td>\n";
echo " <td class='list_control_icons'>";
if (permission_exists('stream_edit')) {
echo "<a href='stream_edit.php?id=".$row['stream_uuid']."' alt='".$text['button-edit']."'>$v_link_label_edit</a>";
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')"]);
}
if (permission_exists('stream_delete')) {
echo "<button type='submit' class='btn btn-default list_control_icon' name=\"streams[$x][action]\" alt='".$text['button-delete']."' value='delete'><span class='fas fa-minus'></span></button>";
else {
echo " <td class='center'>\n";
echo $text['label-'.$row['stream_enabled']];
}
echo " </td>\n";
echo " <td class='description overflow hide-sm-dn'>".escape($row['stream_description'])."&nbsp;</td>\n";
if (permission_exists('stream_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
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";
}
echo "</tr>\n";
$x++;
$c = $c ? 0 : 1;
}
}
unset($streams, $row);
unset($streams);
echo "<tr>\n";
echo "<td colspan='7' align='left'>\n";
echo " <table width='100%' cellpadding='0' cellspacing='0'>\n";
echo " <tr>\n";
echo " <td width='33.3%' nowrap='nowrap'>&nbsp;</td>\n";
echo " <td width='33.3%' align='center' nowrap='nowrap'>$paging_controls</td>\n";
echo " <td class='list_control_icons'>";
if (permission_exists('stream_add')) {
echo "<a href='stream_edit.php' alt='".$text['button-add']."'>$v_link_label_add</a>";
}
else {
echo "&nbsp;";
}
echo " </td>\n";
echo " </tr>\n";
echo " </table>\n";
echo "</td>\n";
echo "</tr>\n";
echo "</table>";
echo "</table>\n";
echo "<br />\n";
echo "<div align='center'>".$paging_controls."</div>\n";
echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
echo "</form>\n";
echo "<br /><br />";
//include the footer
require_once "resources/footer.php";