entities admin

This commit is contained in:
themohooks 2024-09-15 21:31:44 +03:00
parent ac1e0770b1
commit 732c5dc854
5 changed files with 107 additions and 40 deletions

View file

@ -66,6 +66,10 @@ body {
<i class="bx bx-package nav__icon"></i> <i class="bx bx-package nav__icon"></i>
<span class="nav__name">Сущности</span> <span class="nav__name">Сущности</span>
</a> </a>
<a href="/admin?type=Models" class="nav__link">
<i class="bx bx-data nav__icon"></i>
<span class="nav__name">База моделей</span>
</a>

View file

@ -1,5 +1,8 @@
<?php <?php
use App\Services\{Router, Auth};
use \App\Services\{Auth, DB, Date};
use \App\Models\User;
$user = new \App\Models\User(Auth::userid()); $user = new \App\Models\User(Auth::userid());
@ -13,30 +16,87 @@ if (!isset($_GET['type']) || $_GET['type'] != 'Photo') {
<!DOCTYPE html> <!DOCTYPE html>
<html lang="ru"> <html lang="ru">
<script src="https://code.jquery.com/jquery-3.7.1.js"></script> <script src="https://code.jquery.com/jquery-3.7.1.js"></script>
<link rel="stylesheet" href="/static/css/notie.css<?php if (NGALLERY['root']['cloudflare-caching'] === true) { echo '?'.time(); } ?>"> <link rel="stylesheet" href="/static/css/notie.css<?php if (NGALLERY['root']['cloudflare-caching'] === true) {
<script src="/static/js/notie.js<?php if (NGALLERY['root']['cloudflare-caching'] === true) { echo '?'.time(); } ?>"></script> echo '?' . time();
} ?>">
<script src="/static/js/notie.js<?php if (NGALLERY['root']['cloudflare-caching'] === true) {
echo '?' . time();
} ?>"></script>
<script> <script>
notie.setOptions({ notie.setOptions({
transitionCurve: 'cubic-bezier(0.2, 0, 0.2, 1)' transitionCurve: 'cubic-bezier(0.2, 0, 0.2, 1)'
}); });
var Notify = { var Notify = {
noty: function(status, text) { noty: function(status, text) {
if (status == 'danger') status = 'error'; if (status == 'danger') status = 'error';
return notie.alert({ type: status, text: text }) return notie.alert({
type: status,
text: text
})
}, },
} }
</script> </script>
<body> <body>
<div class="container"> <div class="container">
<?=\App\Controllers\AdminController::loadMenu();?> <?= \App\Controllers\AdminController::loadMenu(); ?>
<?=\App\Controllers\AdminController::loadContent();?> <?= \App\Controllers\AdminController::loadContent(); ?>
<h1><b>Сущности</b></h1> <h1><b>Сущности</b></h1>
<a href="?type=EntityCreate" class="btn btn-primary">Создать</a> <a href="?type=EntityCreate" class="btn btn-primary">Создать</a>
</div> <div class="p20w" style="display:block">
<table class="table">
<tbody>
<tr>
<th width="100">ID</th>
<th width="50%">Название</th>
<th>Действия</th>
</tr>
<?php
$photos = DB::query('SELECT * FROM entities ORDER BY id DESC');
foreach ($photos as $p) {
echo ' <tr id="pht' . $p['id'] . '" class="' . $color . '">
<td>
'.$p['id'].'
</td>
<td>
'.$p['title'].'
</td>
<td class="c">
';
echo '<a href="/admin?type=EntityEdit&id=' . $p['id'] . '&mod=1" class="btn btn-primary">Редактировать</a>
<a data-bs-toggle="modal" data-bs-target="#declinePhotoModal' . $p['id'] . '" href="#" class="btn btn-danger">Удалить</a>
</td>';
echo '
</tr>
';
}
?>
</tbody>
</table>
</div><br>
<?php
$entities = DB::query('SELECT * FROM entities');
foreach ($entities as $e) {
}
?>
</div>

View file

@ -1,4 +1,8 @@
<?php <?php
use \App\Services\{Auth, DB};
use \App\Models\User;
if (isset($_POST['create'])) { if (isset($_POST['create'])) {
$postData = $_POST; $postData = $_POST;
@ -9,22 +13,22 @@ if (isset($_POST['create'])) {
preg_match('/_(\d+)$/', $key, $matches); preg_match('/_(\d+)$/', $key, $matches);
if (isset($matches[1])) { if (isset($matches[1])) {
$index = $matches[1]; $index = $matches[1];
if (!isset($result[$index])) { if (!isset($result[$index])) {
$result[$index] = []; $result[$index] = [];
} }
$newKey = preg_replace('/^variable/', '', $key); $newKey = preg_replace('/^variable/', '', $key);
$newKey = preg_replace('/_\d+$/', '', $newKey); $newKey = preg_replace('/_\d+$/', '', $newKey);
$result[$index][$newKey] = $value; $result[$index][$newKey] = $value;
} }
} }
} }
$jsonResult = json_encode($result, JSON_PRETTY_PRINT); $jsonResult = json_encode($result, JSON_PRETTY_PRINT);
header('Content-Type: application/json'); DB::query('INSERT INTO entities VALUES (\'0\', :title, :createdate, :sampledata, :color)', array(':title' => $_POST['title'], ':createdate' => time(), ':sampledata' => $jsonResult, ':color' => $_POST['color']));
echo $jsonResult; header('Location: /admin?type=Entities');
} }
?> ?>
<h1><b>Создание сущности</b></h1> <h1><b>Создание сущности</b></h1>
@ -32,11 +36,11 @@ if (isset($_POST['create'])) {
<div class="mb-3"> <div class="mb-3">
<label for="exampleFormControlInput1" class="form-label">Название</label> <label for="exampleFormControlInput1" class="form-label">Название</label>
<input type="text" class="form-control" id="exampleFormControlInput1" placeholder="Вагон метро"> <input type="text" name="title" class="form-control" id="exampleFormControlInput1" placeholder="Вагон метро">
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label for="exampleFormControlInput1" class="form-label">Цвет</label> <label for="exampleFormControlInput1" class="form-label">Цвет</label>
<input type="text" class="form-control" id="exampleFormControlInput1" placeholder="#FFFFFF"> <input type="text" name="color" class="form-control" id="exampleFormControlInput1" placeholder="#FFFFFF">
</div> </div>
<p>Вводимые переменные</p> <p>Вводимые переменные</p>
<div class="alert alert-dark" role="alert"> <div class="alert alert-dark" role="alert">
@ -56,14 +60,14 @@ if (isset($_POST['create'])) {
</div> </div>
</div> </div>
<div class="col-md-3"> <div class="col-md-3">
<label for="exampleFormControlInput1" class="form-label">Тип</label> <label for="exampleFormControlInput1" class="form-label">Тип</label>
<select name="variabletype_1" class="form-select" aria-label="Default select example"> <select name="variabletype_1" class="form-select" aria-label="Default select example">
<option value="1">Строка</option> <option value="1">Строка</option>
<option value="2">Число</option> <option value="2">Число</option>
</select> </select>
</div> </div>
<div class="col-md-3"> <div class="col-md-3">
<label for="exampleFormControlInput1" class="form-label">Обязателен?</label> <label for="exampleFormControlInput1" class="form-label">Обязателен?</label>
<select name="variableimportant_1" class="form-select" aria-label="Default select example"> <select name="variableimportant_1" class="form-select" aria-label="Default select example">
<option value="1">Да</option> <option value="1">Да</option>
<option value="2">Нет</option> <option value="2">Нет</option>
@ -73,19 +77,19 @@ if (isset($_POST['create'])) {
<button id="addButton" type="button" class="btn btn-outline-primary">Добавить ещё</button> <button id="addButton" type="button" class="btn btn-outline-primary">Добавить ещё</button>
<button id="addButton" type="submit" name="create" class="btn btn-primary">Создать сущность</button> <button id="addButton" type="submit" name="create" class="btn btn-primary">Создать сущность</button>
</div> </div>
</form> </form>
<script> <script>
let count = 1; // Начальное значение для номера переменной let count = 1; // Начальное значение для номера переменной
document.getElementById('addButton').addEventListener('click', function() { document.getElementById('addButton').addEventListener('click', function() {
count++; // Увеличиваем номер переменной count++; // Увеличиваем номер переменной
// Создаем новый элемент // Создаем новый элемент
const newElement = const newElement =
`<div class="col-md-3"> `<div class="col-md-3">
<div class="mb-3"> <div class="mb-3">
<label for="exampleFormControlInput${count}" class="form-label">Название переменной</label> <label for="exampleFormControlInput${count}" class="form-label">Название переменной</label>
<input name="variablename_${count}" type="text" class="form-control" id="exampleFormControlInput${count}" placeholder="#FFFFFF"> <input name="variablename_${count}" type="text" class="form-control" id="exampleFormControlInput${count}" placeholder="#FFFFFF">
@ -110,10 +114,9 @@ document.getElementById('addButton').addEventListener('click', function() {
<option value="1">Да</option> <option value="1">Да</option>
<option value="2">Нет</option> <option value="2">Нет</option>
</select> </select>
</div>` </div>`;
;
// Добавляем новый элемент в #entityform // Добавляем новый элемент в #entityform
document.getElementById('entityform').insertAdjacentHTML('beforeend', newElement); document.getElementById('entityform').insertAdjacentHTML('beforeend', newElement);
}); });
</script> </script>

View file

View file