mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-03 01:39:24 +02:00
Enhance channel management: add user group filtering to channel retrieval and display user groups in sidebar
This commit is contained in:
parent
cfe02b0a76
commit
0b28225740
6 changed files with 384 additions and 297 deletions
|
@ -346,6 +346,7 @@ Options All -Indexes
|
|||
RewriteRule ^channel/([^/]+) view/channel.php?channelName=$1 [QSA]
|
||||
RewriteRule ^channel/?$ view/channel.php [QSA]
|
||||
RewriteRule ^channels/?$ view/channels.php [NC,L]
|
||||
RewriteRule ^channels/([0-9]+)/?$ view/channels.php?user_groups_id=$1 [QSA]
|
||||
|
||||
|
||||
# 1. Trending videos
|
||||
|
|
|
@ -1,67 +1,116 @@
|
|||
<?php
|
||||
|
||||
global $global, $config;
|
||||
if (!isset($global['systemRootPath'])) {
|
||||
require_once '../videos/configuration.php';
|
||||
}
|
||||
require_once $global['systemRootPath'] . 'objects/bootGrid.php';
|
||||
require_once $global['systemRootPath'] . 'objects/user.php';
|
||||
|
||||
class Channel
|
||||
{
|
||||
public static function getChannels($activeOnly = true, $FIND_IN_SET = "", $users_id_array = array())
|
||||
{
|
||||
global $global;
|
||||
/**
|
||||
* Global variables.
|
||||
*
|
||||
* @var array $global An array of global variables.
|
||||
* @property \mysqli $global['mysqli'] A MySQLi connection object.
|
||||
* @property mixed $global[] Dynamically loaded variables.
|
||||
*/
|
||||
$sql = "SELECT u.*, "
|
||||
. " (SELECT count(v.id) FROM videos v where v.users_id = u.id) as total_videos "
|
||||
. " FROM users u "
|
||||
. " HAVING total_videos > 0 ";
|
||||
if ($activeOnly) {
|
||||
$sql .= " AND u.status = 'a' ";
|
||||
}
|
||||
if(!empty($users_id_array) && is_array($users_id_array)){
|
||||
$sql .= " AND u.id IN(".implode(',',$users_id_array ).") ";
|
||||
}
|
||||
$sql .= BootGrid::getSqlFromPost(['user', 'about', 'channelName', 'u.name', 'u.email'], "", "", false, $FIND_IN_SET);
|
||||
//var_dump($sql);exit;
|
||||
$res = sqlDAL::readSql($sql);
|
||||
$fullResult = sqlDAL::fetchAllAssoc($res);
|
||||
sqlDAL::close($res);
|
||||
$subscribe = [];
|
||||
if ($res !== false) {
|
||||
foreach ($fullResult as $row) {
|
||||
$row = cleanUpRowFromDatabase($row);
|
||||
$subscribe[] = $row;
|
||||
}
|
||||
} else {
|
||||
$subscribe = array();
|
||||
die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error);
|
||||
}
|
||||
return $subscribe;
|
||||
}
|
||||
|
||||
|
||||
public static function getTotalChannels($activeOnly=true)
|
||||
{
|
||||
global $global;
|
||||
$sql = "SELECT count(*) as total "
|
||||
. " FROM users u "
|
||||
. " WHERE (SELECT count(v.id) FROM videos v where v.users_id = u.id) > 0 ";
|
||||
if ($activeOnly) {
|
||||
$sql .= " AND u.status = 'a' ";
|
||||
}
|
||||
$sql .= BootGrid::getSqlSearchFromPost(['user', 'about']);
|
||||
//$sql .= BootGrid::getSqlFromPost(['user', 'about']);
|
||||
$res = sqlDAL::readSql($sql);
|
||||
$data = sqlDAL::fetchAssoc($res);
|
||||
sqlDAL::close($res);
|
||||
return $res ? intval($data['total']) : 0;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
global $global, $config;
|
||||
if (!isset($global['systemRootPath'])) {
|
||||
require_once '../videos/configuration.php';
|
||||
}
|
||||
require_once $global['systemRootPath'] . 'objects/bootGrid.php';
|
||||
require_once $global['systemRootPath'] . 'objects/user.php';
|
||||
|
||||
class Channel
|
||||
{
|
||||
public static function getChannels($activeOnly = true, $FIND_IN_SET = "", $users_id_array = array(), $user_groups_id = null)
|
||||
{
|
||||
global $global;
|
||||
/**
|
||||
* Global variables.
|
||||
*
|
||||
* @var array $global An array of global variables.
|
||||
* @property \mysqli $global['mysqli'] A MySQLi connection object.
|
||||
* @property mixed $global[] Dynamically loaded variables.
|
||||
*/
|
||||
$sql = "SELECT u.*, "
|
||||
. " (SELECT count(v.id) FROM videos v where v.users_id = u.id) as total_videos "
|
||||
. " FROM users u "
|
||||
. " HAVING total_videos > 0 ";
|
||||
if ($activeOnly) {
|
||||
$sql .= " AND u.status = 'a' ";
|
||||
}
|
||||
if(!empty($users_id_array) && is_array($users_id_array)){
|
||||
$sql .= " AND u.id IN(".implode(',',$users_id_array ).") ";
|
||||
}
|
||||
|
||||
// Add user group filter if specified
|
||||
if (!empty($user_groups_id)) {
|
||||
$user_groups_id = intval($user_groups_id);
|
||||
$sql .= " AND u.id IN (SELECT users_id FROM users_has_users_groups WHERE users_groups_id = {$user_groups_id}) ";
|
||||
}
|
||||
|
||||
$sql .= BootGrid::getSqlFromPost(['user', 'about', 'channelName', 'u.name', 'u.email'], "", "", false, $FIND_IN_SET);
|
||||
//var_dump($sql);exit;
|
||||
$res = sqlDAL::readSql($sql);
|
||||
$fullResult = sqlDAL::fetchAllAssoc($res);
|
||||
sqlDAL::close($res);
|
||||
$subscribe = [];
|
||||
if ($res !== false) {
|
||||
foreach ($fullResult as $row) {
|
||||
$row = cleanUpRowFromDatabase($row);
|
||||
$subscribe[] = $row;
|
||||
}
|
||||
} else {
|
||||
$subscribe = array();
|
||||
die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error);
|
||||
}
|
||||
return $subscribe;
|
||||
}
|
||||
|
||||
|
||||
public static function getTotalChannels($activeOnly=true, $user_groups_id = null)
|
||||
{
|
||||
global $global;
|
||||
|
||||
$sql = "SELECT count(*) as total "
|
||||
. " FROM users u "
|
||||
. " WHERE (SELECT count(v.id) FROM videos v where v.users_id = u.id) > 0 ";
|
||||
if ($activeOnly) {
|
||||
$sql .= " AND u.status = 'a' ";
|
||||
}
|
||||
|
||||
// Add user group filter if specified
|
||||
if (!empty($user_groups_id)) {
|
||||
$user_groups_id = intval($user_groups_id);
|
||||
$sql .= " AND u.id IN (SELECT users_id FROM users_has_users_groups WHERE users_groups_id = {$user_groups_id}) ";
|
||||
}
|
||||
|
||||
$sql .= BootGrid::getSqlSearchFromPost(['user', 'about']);
|
||||
//$sql .= BootGrid::getSqlFromPost(['user', 'about']);
|
||||
$res = sqlDAL::readSql($sql);
|
||||
$data = sqlDAL::fetchAssoc($res);
|
||||
sqlDAL::close($res);
|
||||
return $res ? intval($data['total']) : 0;
|
||||
}
|
||||
|
||||
public static function getUserGroupsWithChannels($activeOnly = true)
|
||||
{
|
||||
global $global;
|
||||
|
||||
$sql = "SELECT DISTINCT ug.id, ug.group_name, COUNT(DISTINCT u.id) as total_channels "
|
||||
. " FROM users_groups ug "
|
||||
. " INNER JOIN users_has_users_groups uhug ON ug.id = uhug.users_groups_id "
|
||||
. " INNER JOIN users u ON uhug.users_id = u.id "
|
||||
. " WHERE (SELECT count(v.id) FROM videos v WHERE v.users_id = u.id) > 0 ";
|
||||
|
||||
if ($activeOnly) {
|
||||
$sql .= " AND u.status = 'a' ";
|
||||
}
|
||||
|
||||
$sql .= " GROUP BY ug.id, ug.group_name "
|
||||
. " ORDER BY ug.group_name ASC ";
|
||||
|
||||
$res = sqlDAL::readSql($sql);
|
||||
$result = [];
|
||||
|
||||
if ($res !== false) {
|
||||
$fullResult = sqlDAL::fetchAllAssoc($res);
|
||||
foreach ($fullResult as $row) {
|
||||
$row = cleanUpRowFromDatabase($row);
|
||||
$result[] = $row;
|
||||
}
|
||||
} else {
|
||||
die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error);
|
||||
}
|
||||
|
||||
sqlDAL::close($res);
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -280,6 +280,7 @@ class CustomizeAdvanced extends PluginAbstract {
|
|||
|
||||
$obj->disableAnimatedGif = false;
|
||||
$obj->removeBrowserChannelLinkFromMenu = false;
|
||||
$obj->removeBrowserChannelPerGroupLinkFromMenu = true;
|
||||
$obj->EnableMinifyJS = false;
|
||||
$obj->disableShareAndPlaylist = false;
|
||||
$obj->disableShareOnly = false;
|
||||
|
|
|
@ -15,12 +15,21 @@ if (isset($_SESSION['channelName'])) {
|
|||
unset($_SESSION['channelName']);
|
||||
}
|
||||
|
||||
$totalChannels = Channel::getTotalChannels();
|
||||
$user_groups_id = intval(@$_REQUEST['user_groups_id']);
|
||||
|
||||
// Get user group name if user_groups_id is provided
|
||||
$userGroupName = '';
|
||||
if (!empty($user_groups_id)) {
|
||||
$userGroup = new UserGroups($user_groups_id);
|
||||
$userGroupName = $userGroup->getGroup_name();
|
||||
}
|
||||
|
||||
$totalChannels = Channel::getTotalChannels(true, $user_groups_id);
|
||||
|
||||
$users_id_array = VideoStatistic::getUsersIDFromChannelsWithMoreViews();
|
||||
|
||||
$_REQUEST['rowCount'] = 10;
|
||||
$channels = Channel::getChannels(true, "u.id, '" . implode(",", $users_id_array) . "'");
|
||||
$channels = Channel::getChannels(true, "u.id, '" . implode(",", $users_id_array) . "'", [], $user_groups_id);
|
||||
|
||||
$totalPages = ceil($totalChannels / $_REQUEST['rowCount']);
|
||||
//var_dump($channels, $totalPages, $totalChannels, $_REQUEST['rowCount']);exit;
|
||||
|
@ -67,11 +76,17 @@ $_page->setExtraStyles(
|
|||
<div class="container-fluid">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<?php if (!empty($user_groups_id) && !empty($userGroupName)): ?>
|
||||
<h3 class="panel-title" style="margin-bottom: 10px;">
|
||||
<i class="fa fa-users"></i> <strong><?php echo htmlspecialchars($userGroupName); ?></strong>
|
||||
</h3>
|
||||
<?php endif; ?>
|
||||
<form id="search-form" name="search-form" action="<?php echo $global['webSiteRootURL']; ?>channels" method="get">
|
||||
<div id="custom-search-input">
|
||||
<div class="input-group col-md-12">
|
||||
<input type="search" name="searchPhrase" class="form-control input-lg" placeholder="<?php echo __("Search Channels"); ?>"
|
||||
<input type="search" name="searchPhrase" class="form-control input-lg" placeholder="<?php echo __("Search Channels"); ?>"
|
||||
value="<?php echo @htmlentities(@$_GET['searchPhrase']); unsetSearch(); ?>" />
|
||||
<input type="hidden" name="user_groups_id" value="<?php echo $user_groups_id; ?>" />
|
||||
<span class="input-group-btn">
|
||||
<button class="btn btn-info btn-lg" type="submit">
|
||||
<i class="glyphicon glyphicon-search"></i>
|
||||
|
@ -87,7 +102,7 @@ $_page->setExtraStyles(
|
|||
User::getChannelPanel($value['id']);
|
||||
}
|
||||
|
||||
echo getPagination($totalPages, "{$global['webSiteRootURL']}channels?page=_pageNum_");
|
||||
echo getPagination($totalPages, "{$global['webSiteRootURL']}channels?user_groups_id={$user_groups_id}&page=_pageNum_");
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -95,4 +110,4 @@ $_page->setExtraStyles(
|
|||
|
||||
<?php
|
||||
$_page->print();
|
||||
?>
|
||||
?>
|
||||
|
|
|
@ -539,14 +539,30 @@ $tToleranceSide = 0.2;
|
|||
</span>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<?php
|
||||
<?php
|
||||
}
|
||||
TimeLogEnd($tnameSide, __LINE__, $tToleranceSide);
|
||||
?>
|
||||
<?php
|
||||
|
||||
if (empty($advancedCustom->removeBrowserChannelPerGroupLinkFromMenu)) {
|
||||
$userGroupsWithChannels = Channel::getUserGroupsWithChannels();
|
||||
if (!empty($userGroupsWithChannels)) {
|
||||
foreach ($userGroupsWithChannels as $group) {
|
||||
?>
|
||||
<li>
|
||||
<a href="#" onclick="avideoModalIframeFull(webSiteRootURL + 'channels/<?php echo $group['id']; ?>'); return false;">
|
||||
<i class="fa fa-users"></i>
|
||||
<span class="menuLabel">
|
||||
<?php echo htmlspecialchars($group['group_name']); ?>
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($avideoLayout->categoriesTopLeftMenu)) {
|
||||
?>
|
||||
?>
|
||||
<li>
|
||||
<hr>
|
||||
</li>
|
||||
|
@ -583,7 +599,7 @@ $tToleranceSide = 0.2;
|
|||
|
||||
TimeLogEnd($tnameSide, __LINE__, $tToleranceSide);
|
||||
$categories = Category::getAllCategories(false, true, $advancedCustom->CategoryShowOnlySuggested, $sameUserGroupAsMe, true);
|
||||
if(empty($categories)){
|
||||
if (empty($categories)) {
|
||||
$categories = array();
|
||||
}
|
||||
TimeLogEnd($tnameSide, __LINE__, $tToleranceSide);
|
||||
|
|
|
@ -1,219 +1,224 @@
|
|||
<div class="container-fluid">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-default" id="addUserGroupsBtn">
|
||||
<i class="fa-solid fa-plus"></i></span> <?php echo __("New User Groups"); ?>
|
||||
</button>
|
||||
<a href="<?php echo $global['webSiteRootURL']; ?>mvideos" class="btn btn-success">
|
||||
<span class="fa fa-film" aria-hidden="true"></span> <?php echo __("Videos"); ?>
|
||||
</a>
|
||||
<a href="<?php echo $global['webSiteRootURL']; ?>users" class="btn btn-primary">
|
||||
<span class="fa fa-user" aria-hidden="true"></span> <?php echo __("Users"); ?>
|
||||
</a>
|
||||
<a href="#" class="btn btn-info pull-right" data-toggle="popover" title="<?php echo __("What is User Groups"); ?>" data-placement="bottom" data-content="<?php echo __("This is where you can create groups and associate them with your videos and users. This will make your videos private. Only users who are in the same group as the videos can view them"); ?>"><span class="fa fa-question-circle" aria-hidden="true"></span> <?php echo __("What is User Groups"); ?></a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<table id="grid" class="table table-condensed table-hover table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-column-id="group_name" data-order="asc"><?php echo __("Name"); ?></th>
|
||||
<th data-column-id="created" data-width="150px"><?php echo __("Created"); ?></th>
|
||||
<th data-column-id="modified" data-width="150px"><?php echo __("Modified"); ?></th>
|
||||
<th data-column-id="commands" data-formatter="commands" data-sortable="false" data-width="100px"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="groupFormModal" class="modal fade" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
<h4 class="modal-title"><?php echo __("User Groups Form"); ?></h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form class="form-compact" id="updateUserGroupsForm" onsubmit="">
|
||||
<input type="hidden" id="inputUserGroupsId" name="id">
|
||||
<label for="inputName" class="sr-only"><?php echo __("Name"); ?></label>
|
||||
<input type="text" id="inputName" name="group_name" class="form-control" placeholder="<?php echo __("Name"); ?>" required autofocus>
|
||||
|
||||
<?php
|
||||
if (User::isAdmin()) {
|
||||
?>
|
||||
<hr>
|
||||
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<?php echo __("Group Permissions"); ?>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<?php
|
||||
echo Permissions::getForm(); ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal"><?php echo __("Close"); ?></button>
|
||||
<button type="button" class="btn btn-primary" id="saveUserGroupsBtn"><?php echo __("Save changes"); ?></button>
|
||||
</div>
|
||||
</div><!-- /.modal-content -->
|
||||
</div><!-- /.modal-dialog -->
|
||||
</div><!-- /.modal -->
|
||||
</div><!--/.container-->
|
||||
<div id="pluginsPermissionModal" class="modal fade" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div id="pluginsPermissionModalContent">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function pluginPermissionsBtn(plugins_id) {
|
||||
modal.showPleaseWait();
|
||||
$('#groupFormModal').modal('hide');
|
||||
$("#pluginsPermissionModalContent").html('');
|
||||
$.ajax({
|
||||
url: webSiteRootURL + 'plugin/Permissions/getPermissionsFromPlugin.html.php?plugins_id=' + plugins_id,
|
||||
success: function(response) {
|
||||
modal.hidePleaseWait();
|
||||
$("#pluginsPermissionModalContent").html(response);
|
||||
$('#pluginsPermissionModal').modal();
|
||||
}
|
||||
});
|
||||
}
|
||||
$(document).ready(function() {
|
||||
var grid = $("#grid").bootgrid({
|
||||
labels: {
|
||||
noResults: "<?php echo __("No results found!"); ?>",
|
||||
all: "<?php echo __("All"); ?>",
|
||||
infos: "<?php echo __("Showing {{ctx.start}} to {{ctx.end}} of {{ctx.total}} entries"); ?>",
|
||||
loading: "<?php echo __("Loading..."); ?>",
|
||||
refresh: "<?php echo __("Refresh"); ?>",
|
||||
search: "<?php echo __("Search"); ?>",
|
||||
},
|
||||
ajax: true,
|
||||
url: "<?php echo $global['webSiteRootURL'] . "objects/usersGroups.json.php"; ?>",
|
||||
formatters: {
|
||||
"commands": function(column, row) {
|
||||
var editBtn = '<button type="button" class="btn btn-xs btn-default command-edit" data-row-id="' + row.id + '" data-toggle="tooltip" data-placement="left" title="<?php echo __('Edit'); ?>"><i class="fa-solid fa-pen-to-square"></i></button>'
|
||||
var deleteBtn = '<button type="button" class="btn btn-default btn-xs command-delete" data-row-id="' + row.id + ' data-toggle="tooltip" data-placement="left" title="<?php echo __('Delete'); ?>""><i class="fa fa-trash"></i></button>';
|
||||
return editBtn + deleteBtn;
|
||||
}
|
||||
}
|
||||
}).on("loaded.rs.jquery.bootgrid", function() {
|
||||
/* Executes after data is loaded and rendered */
|
||||
grid.find(".command-edit").on("click", function(e) {
|
||||
var row_index = $(this).closest('tr').index();
|
||||
var row = $("#grid").bootgrid("getCurrentRows")[row_index];
|
||||
console.log(row);
|
||||
|
||||
$('#inputUserGroupsId').val(row.id);
|
||||
$('#inputName').val(row.group_name);
|
||||
|
||||
|
||||
modal.showPleaseWait();
|
||||
$.ajax({
|
||||
url: webSiteRootURL + 'plugin/Permissions/getPermissions.json.php?users_groups_id=' + row.id,
|
||||
success: function(response) {
|
||||
console.log(response);
|
||||
$(".permissions").prop("checked", false);
|
||||
for (var key in response) {
|
||||
if (typeof key !== 'string') {
|
||||
continue;
|
||||
}
|
||||
for (var subkey in response[key]) {
|
||||
if (typeof subkey !== 'string' || isNaN(subkey)) {
|
||||
continue;
|
||||
}
|
||||
var selector = "." + key + "[value=\"" + response[key][subkey] + "\"]";
|
||||
console.log(selector, $(selector));
|
||||
$(selector).prop("checked", true);
|
||||
}
|
||||
}
|
||||
$('#groupFormModal').modal();
|
||||
modal.hidePleaseWait();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}).end().find(".command-delete").on("click", function(e) {
|
||||
var row_index = $(this).closest('tr').index();
|
||||
var row = $("#grid").bootgrid("getCurrentRows")[row_index];
|
||||
|
||||
swal({
|
||||
title: "<?php echo __("Are you sure?"); ?>",
|
||||
text: "<?php echo __("You will not be able to recover this action!"); ?>",
|
||||
icon: "warning",
|
||||
buttons: true,
|
||||
dangerMode: true,
|
||||
})
|
||||
.then(function(willDelete) {
|
||||
if (willDelete) {
|
||||
|
||||
modal.showPleaseWait();
|
||||
$.ajax({
|
||||
url: webSiteRootURL + 'objects/userGroupsDelete.json.php',
|
||||
data: {
|
||||
"id": row.id
|
||||
},
|
||||
type: 'post',
|
||||
success: function(response) {
|
||||
if (response.status === "1") {
|
||||
$("#grid").bootgrid("reload");
|
||||
avideoAlert("<?php echo __("Congratulations!"); ?>", "<?php echo __("Your group has been deleted!"); ?>", "success");
|
||||
} else {
|
||||
avideoAlert("<?php echo __("Sorry!"); ?>", "<?php echo __("Your group has NOT been deleted!"); ?>", "error");
|
||||
}
|
||||
modal.hidePleaseWait();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$('#addUserGroupsBtn').click(function(evt) {
|
||||
$('#inputUserGroupsId').val('');
|
||||
$('#inputName').val('');
|
||||
$('#inputCleanName').val('');
|
||||
$("#updateUserGroupsForm").trigger("reset");
|
||||
$(".permissions").prop("checked", false);
|
||||
$('#groupFormModal').modal();
|
||||
|
||||
});
|
||||
|
||||
$('#saveUserGroupsBtn').click(function(evt) {
|
||||
$('#updateUserGroupsForm').submit();
|
||||
});
|
||||
|
||||
$('#updateUserGroupsForm').submit(function(evt) {
|
||||
evt.preventDefault();
|
||||
modal.showPleaseWait();
|
||||
$.ajax({
|
||||
url: '<?php echo $global['webSiteRootURL'] . "objects/userGroupsAddNew.json.php"; ?>',
|
||||
data: $(this).serialize(),
|
||||
type: 'post',
|
||||
success: function(response) {
|
||||
if (response.status) {
|
||||
$('#groupFormModal').modal('hide');
|
||||
$("#grid").bootgrid("reload");
|
||||
avideoAlert("<?php echo __("Congratulations!"); ?>", "<?php echo __("Your group has been saved!"); ?>", "success");
|
||||
} else {
|
||||
avideoAlert("<?php echo __("Sorry!"); ?>", "<?php echo __("Your group has NOT been saved!"); ?>", "error");
|
||||
}
|
||||
modal.hidePleaseWait();
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<div class="container-fluid">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-default" id="addUserGroupsBtn">
|
||||
<i class="fa-solid fa-plus"></i></span> <?php echo __("New User Groups"); ?>
|
||||
</button>
|
||||
<a href="<?php echo $global['webSiteRootURL']; ?>mvideos" class="btn btn-success">
|
||||
<span class="fa fa-film" aria-hidden="true"></span> <?php echo __("Videos"); ?>
|
||||
</a>
|
||||
<a href="<?php echo $global['webSiteRootURL']; ?>users" class="btn btn-primary">
|
||||
<span class="fa fa-user" aria-hidden="true"></span> <?php echo __("Users"); ?>
|
||||
</a>
|
||||
<a href="#" class="btn btn-info pull-right" data-toggle="popover" title="<?php echo __("What is User Groups"); ?>" data-placement="bottom" data-content="<?php echo __("This is where you can create groups and associate them with your videos and users. This will make your videos private. Only users who are in the same group as the videos can view them"); ?>"><span class="fa fa-question-circle" aria-hidden="true"></span> <?php echo __("What is User Groups"); ?></a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<table id="grid" class="table table-condensed table-hover table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-column-id="group_name" data-order="asc"><?php echo __("Name"); ?></th>
|
||||
<th data-column-id="created" data-width="150px"><?php echo __("Created"); ?></th>
|
||||
<th data-column-id="modified" data-width="150px"><?php echo __("Modified"); ?></th>
|
||||
<th data-column-id="commands" data-formatter="commands" data-sortable="false" data-width="100px"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="groupFormModal" class="modal fade" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
<h4 class="modal-title"><?php echo __("User Groups Form"); ?></h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form class="form-compact" id="updateUserGroupsForm" onsubmit="">
|
||||
<input type="hidden" id="inputUserGroupsId" name="id">
|
||||
<label for="inputName" class="sr-only"><?php echo __("Name"); ?></label>
|
||||
<input type="text" id="inputName" name="group_name" class="form-control" placeholder="<?php echo __("Name"); ?>" required autofocus>
|
||||
|
||||
<?php
|
||||
if (User::isAdmin()) {
|
||||
?>
|
||||
<hr>
|
||||
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<?php echo __("Group Permissions"); ?>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<?php
|
||||
echo Permissions::getForm(); ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal"><?php echo __("Close"); ?></button>
|
||||
<button type="button" class="btn btn-primary" id="saveUserGroupsBtn"><?php echo __("Save changes"); ?></button>
|
||||
</div>
|
||||
</div><!-- /.modal-content -->
|
||||
</div><!-- /.modal-dialog -->
|
||||
</div><!-- /.modal -->
|
||||
</div><!--/.container-->
|
||||
<div id="pluginsPermissionModal" class="modal fade" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div id="pluginsPermissionModalContent">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function pluginPermissionsBtn(plugins_id) {
|
||||
modal.showPleaseWait();
|
||||
$('#groupFormModal').modal('hide');
|
||||
$("#pluginsPermissionModalContent").html('');
|
||||
$.ajax({
|
||||
url: webSiteRootURL + 'plugin/Permissions/getPermissionsFromPlugin.html.php?plugins_id=' + plugins_id,
|
||||
success: function(response) {
|
||||
modal.hidePleaseWait();
|
||||
$("#pluginsPermissionModalContent").html(response);
|
||||
$('#pluginsPermissionModal').modal();
|
||||
}
|
||||
});
|
||||
}
|
||||
$(document).ready(function() {
|
||||
var grid = $("#grid").bootgrid({
|
||||
labels: {
|
||||
noResults: "<?php echo __("No results found!"); ?>",
|
||||
all: "<?php echo __("All"); ?>",
|
||||
infos: "<?php echo __("Showing {{ctx.start}} to {{ctx.end}} of {{ctx.total}} entries"); ?>",
|
||||
loading: "<?php echo __("Loading..."); ?>",
|
||||
refresh: "<?php echo __("Refresh"); ?>",
|
||||
search: "<?php echo __("Search"); ?>",
|
||||
},
|
||||
ajax: true,
|
||||
url: "<?php echo $global['webSiteRootURL'] . "objects/usersGroups.json.php"; ?>",
|
||||
formatters: {
|
||||
"commands": function(column, row) {
|
||||
var editBtn = '<button type="button" class="btn btn-xs btn-default command-edit" data-row-id="' + row.id + '" data-toggle="tooltip" data-placement="left" title="<?php echo __('Edit'); ?>"><i class="fa-solid fa-pen-to-square"></i></button>'
|
||||
var deleteBtn = '<button type="button" class="btn btn-default btn-xs command-delete" data-row-id="' + row.id + ' data-toggle="tooltip" data-placement="left" title="<?php echo __('Delete'); ?>""><i class="fa fa-trash"></i></button>';
|
||||
var channelsBtn = '<button type="button" class="btn btn-xs btn-default command-channels" data-row-id="' + row.id + '" data-toggle="tooltip" data-placement="left" title="<?php echo __('View Channels'); ?>"><i class="fa fa-tv"></i></button>';
|
||||
return editBtn + deleteBtn + channelsBtn;
|
||||
}
|
||||
}
|
||||
}).on("loaded.rs.jquery.bootgrid", function() {
|
||||
/* Executes after data is loaded and rendered */
|
||||
grid.find(".command-edit").on("click", function(e) {
|
||||
var row_index = $(this).closest('tr').index();
|
||||
var row = $("#grid").bootgrid("getCurrentRows")[row_index];
|
||||
console.log(row);
|
||||
|
||||
$('#inputUserGroupsId').val(row.id);
|
||||
$('#inputName').val(row.group_name);
|
||||
|
||||
|
||||
modal.showPleaseWait();
|
||||
$.ajax({
|
||||
url: webSiteRootURL + 'plugin/Permissions/getPermissions.json.php?users_groups_id=' + row.id,
|
||||
success: function(response) {
|
||||
console.log(response);
|
||||
$(".permissions").prop("checked", false);
|
||||
for (var key in response) {
|
||||
if (typeof key !== 'string') {
|
||||
continue;
|
||||
}
|
||||
for (var subkey in response[key]) {
|
||||
if (typeof subkey !== 'string' || isNaN(subkey)) {
|
||||
continue;
|
||||
}
|
||||
var selector = "." + key + "[value=\"" + response[key][subkey] + "\"]";
|
||||
console.log(selector, $(selector));
|
||||
$(selector).prop("checked", true);
|
||||
}
|
||||
}
|
||||
$('#groupFormModal').modal();
|
||||
modal.hidePleaseWait();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}).end().find(".command-delete").on("click", function(e) {
|
||||
var row_index = $(this).closest('tr').index();
|
||||
var row = $("#grid").bootgrid("getCurrentRows")[row_index];
|
||||
|
||||
swal({
|
||||
title: "<?php echo __("Are you sure?"); ?>",
|
||||
text: "<?php echo __("You will not be able to recover this action!"); ?>",
|
||||
icon: "warning",
|
||||
buttons: true,
|
||||
dangerMode: true,
|
||||
})
|
||||
.then(function(willDelete) {
|
||||
if (willDelete) {
|
||||
|
||||
modal.showPleaseWait();
|
||||
$.ajax({
|
||||
url: webSiteRootURL + 'objects/userGroupsDelete.json.php',
|
||||
data: {
|
||||
"id": row.id
|
||||
},
|
||||
type: 'post',
|
||||
success: function(response) {
|
||||
if (response.status === "1") {
|
||||
$("#grid").bootgrid("reload");
|
||||
avideoAlert("<?php echo __("Congratulations!"); ?>", "<?php echo __("Your group has been deleted!"); ?>", "success");
|
||||
} else {
|
||||
avideoAlert("<?php echo __("Sorry!"); ?>", "<?php echo __("Your group has NOT been deleted!"); ?>", "error");
|
||||
}
|
||||
modal.hidePleaseWait();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}).end().find(".command-channels").on("click", function(e) {
|
||||
var row_index = $(this).closest('tr').index();
|
||||
var row = $("#grid").bootgrid("getCurrentRows")[row_index];
|
||||
window.open(webSiteRootURL + 'channels/' + row.id, '_blank');
|
||||
});
|
||||
});
|
||||
|
||||
$('#addUserGroupsBtn').click(function(evt) {
|
||||
$('#inputUserGroupsId').val('');
|
||||
$('#inputName').val('');
|
||||
$('#inputCleanName').val('');
|
||||
$("#updateUserGroupsForm").trigger("reset");
|
||||
$(".permissions").prop("checked", false);
|
||||
$('#groupFormModal').modal();
|
||||
|
||||
});
|
||||
|
||||
$('#saveUserGroupsBtn').click(function(evt) {
|
||||
$('#updateUserGroupsForm').submit();
|
||||
});
|
||||
|
||||
$('#updateUserGroupsForm').submit(function(evt) {
|
||||
evt.preventDefault();
|
||||
modal.showPleaseWait();
|
||||
$.ajax({
|
||||
url: '<?php echo $global['webSiteRootURL'] . "objects/userGroupsAddNew.json.php"; ?>',
|
||||
data: $(this).serialize(),
|
||||
type: 'post',
|
||||
success: function(response) {
|
||||
if (response.status) {
|
||||
$('#groupFormModal').modal('hide');
|
||||
$("#grid").bootgrid("reload");
|
||||
avideoAlert("<?php echo __("Congratulations!"); ?>", "<?php echo __("Your group has been saved!"); ?>", "success");
|
||||
} else {
|
||||
avideoAlert("<?php echo __("Sorry!"); ?>", "<?php echo __("Your group has NOT been saved!"); ?>", "error");
|
||||
}
|
||||
modal.hidePleaseWait();
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue