zoneminder/web/ajax/modals/group.php

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

136 lines
4.4 KiB
PHP
Raw Normal View History

<?php
2020-09-28 01:12:01 +08:00
// This is the HTML representing the Group modal accessed from the Groups (plural) view
2020-09-27 21:11:45 +08:00
//
// DEFINE SUPPORTING FUNCTIONS
//
function get_Id( $G ) {
return $G->Id();
}
function get_children($Group) {
global $children;
$kids = array();
if ( isset( $children[$Group->Id()] ) ) {
$kids += array_map('get_Id', $children[$Group->Id()]);
foreach ( $children[$Group->Id()] as $G ) {
foreach ( get_children($G) as $id ) {
$kids[] = $id;
}
}
}
return $kids;
}
function parentGrpSelect($newGroup) {
$Groups = array();
foreach ( ZM\Group::find() as $Group ) {
$Groups[$Group->Id()] = $Group;
}
# This array is indexed by parent_id
$children = array();
foreach ( $Groups as $id=>$Group ) {
if ( $Group->ParentId() != null ) {
if ( ! isset( $children[$Group->ParentId()] ) )
$children[$Group->ParentId()] = array();
$children[$Group->ParentId()][] = $Group;
}
}
$kids = get_children($newGroup);
if ( $newGroup->Id() )
$kids[] = $newGroup->Id();
$sql = 'SELECT Id,Name FROM `Groups`'.(count($kids)?' WHERE Id NOT IN ('.implode(',',array_map(function(){return '?';}, $kids)).')' : '').' ORDER BY Name';
$options = array(''=>'None');
foreach ( dbFetchAll($sql, null, $kids) as $option ) {
$options[$option['Id']] = str_repeat('&nbsp;&nbsp;', $Groups[$option['Id']]->depth()) . $option['Name'];
}
2020-09-28 01:12:01 +08:00
return htmlSelect('newGroup[ParentId]', $options, $newGroup->ParentId(), array('data-on-change'=>'configModalBtns'));
2020-09-27 21:11:45 +08:00
}
function monitorList($newGroup) {
$result = '';
$monitors = dbFetchAll('SELECT Id,Name FROM Monitors ORDER BY Sequence ASC');
$monitorIds = $newGroup->MonitorIds();
foreach ( $monitors as $monitor ) {
if ( visibleMonitor($monitor['Id']) ) {
$result .= '<option value="' .$monitor['Id']. '"' .( in_array( $monitor['Id'], $monitorIds ) ? ' selected="selected"' : ''). '>' .validHtmlStr($monitor['Name']). '</option>'.PHP_EOL;
}
}
return $result;
}
//
// INITIAL SANITY CHECKS
//
if ( !canEdit('Groups') ) {
$view = 'error';
return;
}
if ( !empty($_REQUEST['gid']) ) {
$newGroup = new ZM\Group($_REQUEST['gid']);
} else {
$newGroup = new ZM\Group();
}
2020-09-27 21:11:45 +08:00
//
// BEGIN HTML
//
?>
2020-09-28 01:12:01 +08:00
<div id="groupModal" class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><?php echo translate('Group').($newGroup->Name() ? ' - ' .validHtmlStr($newGroup->Name()) : '') ?></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form id="groupForm" name="groupForm" method="post" action="?view=group&action=save">
<?php
// We have to manually insert the csrf key into the form when using a modal generated via ajax call
echo getCSRFinputHTML();
?>
<input type="hidden" name="view" value="group"/>
2017-10-05 04:40:09 +08:00
<input type="hidden" name="gid" value="<?php echo $newGroup->Id() ?>"/>
2020-09-28 01:12:01 +08:00
<table id="groupModalTable" class="table-sm table-borderless">
<tbody>
<tr>
2020-09-28 01:12:01 +08:00
<th class="text-right pr-3" scope="row"><?php echo translate('Name') ?></th>
<td><input type="text" name="newGroup[Name]" value="<?php echo validHtmlStr($newGroup->Name()) ?>" data-on-input="configModalBtns"/></td>
</tr>
<tr>
2020-09-28 01:12:01 +08:00
<th class="text-right pr-3" scope="row"><?php echo translate('ParentGroup') ?></th>
2020-09-27 21:11:45 +08:00
<td><?php echo parentGrpSelect($newGroup) ?></td>
</tr>
<tr>
2020-09-28 01:12:01 +08:00
<th class="text-right pr-3" scope="row"><?php echo translate('Monitor') ?></th>
<td>
2020-09-28 01:12:01 +08:00
<select name="newGroup[MonitorIds][]" class="chosen" multiple="multiple" data-on-change="configModalBtns">
2020-09-27 21:11:45 +08:00
<?php echo monitorList($newGroup) ?>
</select>
</td>
</tr>
</tbody>
</table>
2020-09-28 01:12:01 +08:00
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary" name="action" id="grpModalSaveBtn" value="save"<?php $newGroup->Id() ? '' : ' disabled="disabled"'?>><?php echo translate('Save') ?></button>
<button type="button" class="btn btn-secondary" data-dismiss="modal"><?php echo translate('Cancel') ?></button>
</div>
</form>
</div>
</div>
2020-09-28 01:12:01 +08:00
</div>