Создать простой сайт, где будет страница с формой для авторизации и страница для авторизованного пользователя.
<?php
require("header.php");
if (!$authentication->isLoggedIn())
{
header("Location: index.php");
die();
}
$content = new ContentRegistry();
$is_root_node = false;
if (isset($_GET['id']))
$current_node_id = $_GET['id'];
else
{
$current_node_id = $content->getRootNode()->getId();
$is_root_node = true;
}
if (!$content->isNodeExists($current_node_id))
{
?>
<div class="alert alert-danger" role="alert">
Node with ID <strong><?php echo $current_node_id ?></strong> is not exists.
</div>
<?php
}
else
{
//$content->delete_node($current_node_id);
$item_info = $content->getNodeById($current_node_id);
if ($content->isRootNode($item_info))
$is_root_node = true;
?>
<h2 class="display-4"><?php echo $item_info->getTitle(); ?></h2>
<button type="button" class="btn btn-outline-primary create-node" data-toggle="modal" data-target="#nodeEditModal">Create Node</button>
<button type="button" class="btn btn-outline-primary load-node" data-toggle="modal" data-target="#nodeEditModal" data-node-id="<?php echo $current_node_id; ?>">Edit Node</button>
<button type="button" class="btn btn-outline-danger delete-node" data-node-id="<?php echo $current_node_id; ?>" <?php if ($is_root_node) echo "disabled"; ?>>Delete</button>
<a href="reset.php" class="btn btn-outline-secondary" role="button">Reset Content...</a>
<div class="modal fade" id="nodeEditModal" tabindex="-1" role="dialog" aria-labelledby="nodeModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<form method="post" class="needs-validation" novalidate>
<div class="modal-header">
<h5 class="modal-title" id="nodeModalLabel">Content Node</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<input type="hidden" class="form-control" id="hdnNodeID" />
<div class="form-group">
<label for="txtNodeTitle" class="col-form-label"><span class="required-field">*</span> Title:</label>
<input type="text" class="form-control" id="txtNodeTitle" required />
<div class="invalid-feedback">
Please enter title.
</div>
</div>
<div class="form-group">
<label for="txtNodeDescription" class="col-form-label">Description:</label>
<textarea class="form-control" rows="10" id="txtNodeDescription"></textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary save-node" data-target="#nodeEditModal">Save</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</form>
</div>
</div>
</div>
<br/><br/>
<div class="row">
<div class="col-md-5">
<?php $content->displayItemsTree($current_node_id); ?>
</div>
<div class="col-md-7">
<?php if ($item_info->getDescription() != "") echo "<div>".$item_info->getDescription()."</div>"; ?>
</div>
</div>
<?php
}
require("footer.php");
?>
<script type="text/javascript">
(function() {
'use strict';
window.addEventListener('load', function() {
let inputs = document.getElementsByClassName('form-control')
let validation = Array.prototype.filter.call(inputs, function(input) {
input.addEventListener('blur', function(event) {
// reset
input.classList.remove('is-invalid')
input.classList.remove('is-valid')
if (input.checkValidity() === false) {
input.classList.add('is-invalid')
}
else {
input.classList.add('is-valid')
}
}, false);
});
}, false);
})()
</script>
<script type="text/javascript">
$(document).ready(function() {
function resetNodeEditDialog()
{
$('#hdnNodeID').val('0');
$('#txtNodeTitle').val('');
$('#txtNodeDescription').val('');
}
$('#nodeEditModal').on('hide.bs.modal', function() {
resetNodeEditDialog();
});
$('body').on('click', '.create-node', function (e) {
e.preventDefault();
resetNodeEditDialog();
});
$('body').on('click', '.load-node', function (e) {
e.preventDefault();
let nodeId = $(this).data('node-id');
if (nodeId > 0) {
$('#hdnNodeID').val(nodeId);
$.ajax({
type: 'GET',
url: 'ajax_processor.php?cmd=LoadNode&id=' + nodeId,
data: '',
success: function(response) {
console.log(response);
let json = JSON.parse(response);
if (json.success) {
$('#txtNodeTitle').val(json.title);
$('#txtNodeDescription').val(json.description);
}
}
});
}
});
$('body').on('click', '.save-node', function (e) {
e.preventDefault();
let nodeId = $('#hdnNodeID').val();
if (nodeId > 0) {
$.ajax({
type: 'POST',
url: 'ajax_processor.php',
data: { cmd: 'UpdateNode', node_id: nodeId, title: $('#txtNodeTitle').val(), description: $('#txtNodeDescription').val() },
dataType: 'JSON',
success: function(response) {
window.location.href = 'content.php?id=' + <?php echo $current_node_id; ?>;
}
});
}
else {
$.ajax({
type: 'POST',
url: 'ajax_processor.php',
data: { cmd: 'CreateNode', parent_id: <?php echo $current_node_id; ?>, title: $('#txtNodeTitle').val(), description: $('#txtNodeDescription').val() },
dataType: 'JSON',
success: function(response) {
window.location.href = 'content.php?id=' + <?php echo $current_node_id; ?>;
}
});
}
});
$('body').on('click', '.delete-node', function (e) {
e.preventDefault();
let nodeId = $(this).data('node-id');
if (nodeId > 0) {
BootstrapDialog.show({
title: 'Delete node confirmation',
message: 'You are sure to delete this node and subnodes?',
buttons: [
{
label: 'Delete',
cssClass: 'btn-primary',
action: function(dialog) {
$.ajax({
type: 'POST',
url: 'ajax_processor.php',
data: { cmd: 'DeleteNode', node_id: nodeId },
dataType: "JSON",
cache: false,
success: function (response) {
dialog.close();
window.location.href = 'content.php';
}
});
}
},
{
label: 'Cancel',
cssClass: 'btn-secondary',
action: function(dialog) {
dialog.close();
}
}
]
});
}
});
});
</script>