mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-03-16 21:08:01 -04:00
Change from newUser[] to user[] in form elements. Add Group permissions
This commit is contained in:
@@ -26,15 +26,16 @@ if (!canEdit('System') && !$selfEdit) {
|
||||
}
|
||||
|
||||
require_once('includes/User.php');
|
||||
require_once('includes/Group_Permission.php');
|
||||
|
||||
if (isset($_REQUEST['uid']) and $_REQUEST['uid']) {
|
||||
if ( !($newUser = new ZM\User($_REQUEST['uid'])) ) {
|
||||
if ( !($User = new ZM\User($_REQUEST['uid'])) ) {
|
||||
$view = 'error';
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
$newUser = new ZM\User();
|
||||
$newUser->Username(translate('NewUser'));
|
||||
$User = new ZM\User();
|
||||
$User->Username(translate('NewUser'));
|
||||
}
|
||||
|
||||
$yesno = array( 0=>translate('No'), 1=>translate('Yes') );
|
||||
@@ -53,7 +54,7 @@ foreach ( dbFetchAll($sql) as $monitor ) {
|
||||
|
||||
$focusWindow = true;
|
||||
|
||||
xhtmlHeaders(__FILE__, translate('User').' - '.$newUser->Username());
|
||||
xhtmlHeaders(__FILE__, translate('User').' - '.$User->Username());
|
||||
echo getBodyTopHTML();
|
||||
echo getNavBarHTML();
|
||||
?>
|
||||
@@ -64,7 +65,7 @@ echo getNavBarHTML();
|
||||
<button type="button" id="refreshBtn" class="btn btn-normal" data-toggle="tooltip" data-placement="top" title="<?php echo translate('Refresh') ?>" ><i class="fa fa-refresh"></i></button>
|
||||
</div>
|
||||
<div class="w-100 pt-2">
|
||||
<h2><?php echo translate('User').' - '.validHtmlStr($newUser->Username()); ?></h2>
|
||||
<h2><?php echo translate('User').' - '.validHtmlStr($User->Username()); ?></h2>
|
||||
</div>
|
||||
</div>
|
||||
<div id="content" class="row justify-content-center">
|
||||
@@ -80,14 +81,14 @@ if (canEdit('System')) {
|
||||
?>
|
||||
<tr>
|
||||
<th class="text-right" scope="row"><?php echo translate('Username') ?></th>
|
||||
<td><input type="text" name="newUser[Username]" pattern="[A-Za-z0-9 .@]+" value="<?php echo validHtmlStr($newUser->Username()); ?>"<?php echo $newUser->Username() == 'admin' ? ' readonly="readonly"':''?>/></td>
|
||||
<td><input type="text" name="user[Username]" pattern="[A-Za-z0-9 .@]+" value="<?php echo validHtmlStr($User->Username()); ?>"<?php echo $User->Username() == 'admin' ? ' readonly="readonly"':''?>/></td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<tr>
|
||||
<th class="text-right" scope="row"><?php echo translate('NewPassword') ?></th>
|
||||
<td><input type="password" name="newUser[Password]" autocomplete="new-password"/></td>
|
||||
<td><input type="password" name="user[Password]" autocomplete="new-password"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="text-right" scope="row"><?php echo translate('ConfirmPassword') ?></th>
|
||||
@@ -95,22 +96,22 @@ if (canEdit('System')) {
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="text-right" scope="row"><?php echo translate('Language') ?></th>
|
||||
<td><?php echo htmlSelect('newUser[Language]', $langs, $newUser->Language()) ?></td>
|
||||
<td><?php echo htmlSelect('user[Language]', $langs, $User->Language()) ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="text-right" scope="row"><?php echo translate('Home View') ?></th>
|
||||
<td><input type="text" name="newUser[HomeView]" value="<?php echo validHtmlStr($newUser->HomeView()); ?>"/></td>
|
||||
<td><input type="text" name="user[HomeView]" value="<?php echo validHtmlStr($User->HomeView()); ?>"/></td>
|
||||
</tr>
|
||||
<?php
|
||||
if (canEdit('System')) {
|
||||
?>
|
||||
<tr>
|
||||
<th class="text-right" scope="row"><?php echo translate('Enabled') ?></th>
|
||||
<td><?php echo htmlSelect('newUser[Enabled]', $yesno, $newUser->Enabled()) ?></td>
|
||||
<td><?php echo htmlSelect('user[Enabled]', $yesno, $User->Enabled()) ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="text-right" scope="row"><?php echo translate('MaxBandwidth') ?></th>
|
||||
<td><?php echo htmlSelect('newUser[MaxBandwidth]', $bandwidths, $newUser->MaxBandwidth()) ?></td>
|
||||
<td><?php echo htmlSelect('user[MaxBandwidth]', $bandwidths, $User->MaxBandwidth()) ?></td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
@@ -126,45 +127,45 @@ if (canEdit('System')) {
|
||||
<tbody>
|
||||
<tr>
|
||||
<th class="text-right" scope="row"><?php echo translate('Stream') ?></th>
|
||||
<td><?php echo htmlSelect('newUser[Stream]', $nv, $newUser->Stream()) ?></td>
|
||||
<td><?php echo htmlSelect('user[Stream]', $nv, $User->Stream()) ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="text-right" scope="row"><?php echo translate('Events') ?></th>
|
||||
<td><?php echo htmlSelect('newUser[Events]', $nve, $newUser->Events()) ?></td>
|
||||
<td><?php echo htmlSelect('user[Events]', $nve, $User->Events()) ?></td>
|
||||
</tr>
|
||||
<?php if (defined('ZM_FEATURES_SNAPSHOTS') and ZM_FEATURES_SNAPSHOTS) { ?>
|
||||
<tr>
|
||||
<th class="text-right" scope="row"><?php echo translate('Snapshots') ?></th>
|
||||
<td><?php echo htmlSelect('newUser[Snapshots]', $nve, $newUser->Snapshots()) ?></td>
|
||||
<td><?php echo htmlSelect('user[Snapshots]', $nve, $User->Snapshots()) ?></td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
<tr>
|
||||
<th class="text-right" scope="row"><?php echo translate('Control') ?></th>
|
||||
<td><?php echo htmlSelect('newUser[Control]', $nve, $newUser->Control()) ?></td>
|
||||
<td><?php echo htmlSelect('user[Control]', $nve, $User->Control()) ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="text-right" scope="row"><?php echo translate('Monitors') ?></th>
|
||||
<td><?php echo htmlSelect('newUser[Monitors]', $nve, $newUser->Monitors()) ?></td>
|
||||
<td><?php echo htmlSelect('user[Monitors]', $nve, $User->Monitors()) ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="text-right" scope="row"><?php echo translate('Groups') ?></th>
|
||||
<td><?php echo htmlSelect('newUser[Groups]', $nve, $newUser->Groups()) ?></td>
|
||||
<td><?php echo htmlSelect('user[Groups]', $nve, $User->Groups()) ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="text-right" scope="row"><?php echo translate('System') ?></th>
|
||||
<td><?php echo htmlSelect('newUser[System]', $nve, $newUser->System()) ?></td>
|
||||
<td><?php echo htmlSelect('user[System]', $nve, $User->System()) ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="text-right" scope="row"><?php echo translate('Devices') ?></th>
|
||||
<td><?php echo htmlSelect('newUser[Devices]', $nve, $newUser->Devices()) ?></td>
|
||||
<td><?php echo htmlSelect('user[Devices]', $nve, $User->Devices()) ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="text-right" scope="row"><?php echo translate('RestrictedMonitors') ?></th>
|
||||
<td>
|
||||
<?php
|
||||
// explode returns an array with an empty element, so test for a value first
|
||||
echo htmlSelect('newUser[MonitorIds][]', $monitors,
|
||||
($newUser->MonitorIds() ? explode(',', $newUser->MonitorIds()) : array()),
|
||||
echo htmlSelect('user[MonitorIds][]', $monitors,
|
||||
($User->MonitorIds() ? explode(',', $User->MonitorIds()) : array()),
|
||||
array('multiple'=>'multiple'));
|
||||
?>
|
||||
</td>
|
||||
@@ -172,7 +173,7 @@ if (canEdit('System')) {
|
||||
<?php if (ZM_OPT_USE_API) { ?>
|
||||
<tr>
|
||||
<th class="text-right" scope="row"><?php echo translate('APIEnabled')?></th>
|
||||
<td><?php echo htmlSelect('newUser[APIEnabled]', $yesno, $newUser->APIEnabled()) ?></td>
|
||||
<td><?php echo htmlSelect('user[APIEnabled]', $yesno, $User->APIEnabled()) ?></td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
@@ -182,6 +183,67 @@ if (canEdit('System')) {
|
||||
</table>
|
||||
</div><!--Permissions-->
|
||||
<?php
|
||||
if (canEdit('Groups')) {
|
||||
$Groups = array();
|
||||
foreach ( ZM\Group::find() as $Group ) {
|
||||
$Groups[$Group->Id()] = $Group;
|
||||
}
|
||||
|
||||
$max_depth = 0;
|
||||
# This array is indexed by parent_id
|
||||
$children = array();
|
||||
foreach ( $Groups as $id=>$Group ) {
|
||||
if ( ! isset( $children[$Group->ParentId()] ) )
|
||||
$children[$Group->ParentId()] = array();
|
||||
$children[$Group->ParentId()][] = $Group;
|
||||
if ( $max_depth < $Group->depth() )
|
||||
$max_depth = $Group->depth();
|
||||
}
|
||||
|
||||
$permissions = array();
|
||||
foreach (ZM\Group_Permission::find(array('UserId'=>$User->Id())) as $P) {
|
||||
$permissions[$p->GroupId()] = $P;
|
||||
}
|
||||
?>
|
||||
<table id="contentTable" class="major Groups">
|
||||
<thead class="thead-highlight">
|
||||
<tr>
|
||||
<th class="name" colspan="<?php echo $max_depth+1 ?>"><?php echo translate('Name') ?></th>
|
||||
<th class="monitors"><?php echo translate('Monitors') ?></th>
|
||||
<th class="permission"><?php echo translate('Permission') ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
function group_line($Group) {
|
||||
global $children;
|
||||
global $max_depth;
|
||||
global $nve;
|
||||
global $permissions;
|
||||
$html = '<tr>';
|
||||
$html .= str_repeat('<td class="name"> </td>', $Group->depth());
|
||||
$html .= '<td class="name" colspan="'.($max_depth-($Group->depth()-1)).'">';
|
||||
$html .= '<a href="#" data-on-click-this="editGroup" data-group-id="'.$Group->Id().'">'.validHtmlStr($Group->Id().' '.$Group->Name()).'</a>';
|
||||
$html .= '</td><td class="monitors">'. validHtmlStr(monitorIdsToNames($Group->MonitorIds(), 30)).'</td>';
|
||||
$html .= '<td class="permission">'.html_radio('group['.$Group->Id().']', $nve, isset($permissions[$Group->Id()]) ? $permissions[$Group->Id()] : 'None').'</td>';
|
||||
$html .= '</tr>';
|
||||
if (isset($children[$Group->Id()])) {
|
||||
foreach ($children[$Group->Id()] as $G) {
|
||||
$html .= group_line($G);
|
||||
}
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
if (isset($children[null])) {
|
||||
foreach ($children[null] as $Group) {
|
||||
echo group_line($Group);
|
||||
}
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php
|
||||
} // end if canEdit(Groups)
|
||||
} // end if canEdit(System)
|
||||
?>
|
||||
<div id="contentButtons">
|
||||
|
||||
Reference in New Issue
Block a user