add app, add nfs operator

This commit is contained in:
Vassiliy Yegorov
2021-05-20 14:20:41 +07:00
parent 79f0275027
commit 1b42b9592f
35 changed files with 983 additions and 24 deletions

View File

@@ -0,0 +1,12 @@
<?php
$host=$_ENV['MARIADB_HOST'];
$db=$_ENV['MARIADB_DATABASE'];
$login=$_ENV['MARIADB_USER'];
$password=$_ENV['MARIADB_PASSWORD'];
try {
$pdo = new PDO("mysql:dbname=$db; host=$host", $login, $password);
} catch (PDOException $e) {
die($e->getMessage());
}

View File

@@ -0,0 +1,47 @@
<?php
include 'config.php';
$name = $_POST['name'];
$last_name = $_POST['last_name'];
$pos = $_POST['pos'];
// Create
if (isset($_POST['submit'])) {
$sql = ("INSERT INTO `users`(`name`, `last_name`, `pos`) VALUES(?,?,?)");
$query = $pdo->prepare($sql);
$query->execute([$name, $last_name, $pos]);
$success = '<div class="alert alert-success alert-dismissible fade show" role="alert">
<strong>Данные успешно отправлены!</strong> Вы можете закрыть это сообщение.
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>';
}
// Read
$sql = $pdo->prepare("SELECT * FROM `users`");
$sql->execute();
$result = $sql->fetchAll();
// Update
$edit_name = $_POST['edit_name'];
$edit_last_name = $_POST['edit_last_name'];
$edit_pos = $_POST['edit_pos'];
$get_id = $_GET['id'];
if (isset($_POST['edit-submit'])) {
$sqll = "UPDATE users SET name=?, last_name=?, pos=? WHERE id=?";
$querys = $pdo->prepare($sqll);
$querys->execute([$edit_name, $edit_last_name, $edit_pos, $get_id]);
header('Location: '. $_SERVER['HTTP_REFERER']);
}
// DELETE
if (isset($_POST['delete_submit'])) {
$sql = "DELETE FROM users WHERE id=?";
$query = $pdo->prepare($sql);
$query->execute([$get_id]);
header('Location: '. $_SERVER['HTTP_REFERER']);
}

View File

@@ -1,8 +1,83 @@
<html>
<head>
<title>Тестируем PHP</title>
</head>
<body>
<?php echo '<p>Привет, мир!</p>'; ?>
</body>
</html>
<?php
include 'func.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CRUD приложение на PHP</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.9.0/css/all.css">
</head>
<body>
<div class="container">
<div class="row">
<div class="col mt-1">
<?=$success ?>
<button class="btn btn-success mb-1" data-toggle="modal" data-target="#Modal"><i class="fa fa-user-plus"></i></button>
<table class="table shadow ">
<thead class="thead-dark">
<tr>
<th>№</th>
<th>Имя</th>
<th>Фамилия</th>
<th>Должность</th>
<th>Действие</th>
</tr>
<?php foreach ($result as $value) { ?>
<tr>
<td><?=$value['id'] ?></td>
<td><?=$value['name'] ?></td>
<td><?=$value['last_name'] ?></td>
<td><?=$value['pos'] ?></td>
<td>
<a href="?edit=<?=$value['id'] ?>" class="btn btn-success btn-sm" data-toggle="modal" data-target="#editModal<?=$value['id'] ?>"><i class="fa fa-edit"></i></a>
<a href="?delete=<?=$value['id'] ?>" class="btn btn-danger btn-sm" data-toggle="modal" data-target="#deleteModal<?=$value['id'] ?>"><i class="fa fa-trash"></i></a>
<?php require 'modal.php'; ?>
</td>
</tr> <?php } ?>
</thead>
</table>
</div>
</div>
</div>
<!-- Modal -->
<div class="modal fade" tabindex="-1" role="dialog" id="Modal">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content shadow">
<div class="modal-header">
<h5 class="modal-title">Добавить пользователя</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 action="" method="post">
<div class="form-group">
<input type="text" class="form-control" name="name" value="" placeholder="Имя">
</div>
<div class="form-group">
<input type="text" class="form-control" name="last_name" value="" placeholder="Фамилия">
</div>
<div class="form-group">
<input type="text" class="form-control" name="pos" value="" placeholder="Должность">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Отмена</button>
<button type="submit" name="submit" class="btn btn-primary">Добавить</button>
</div>
</form>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<script>
</body>
</html>

View File

@@ -0,0 +1,49 @@
<!-- Modal Edit-->
<div class="modal fade" id="editModal<?=$value['id'] ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content shadow">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Редактировать запись <?=$value['id'] ?></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 action="?id=<?=$value['id'] ?>" method="post">
<div class="form-group">
<input type="text" class="form-control" name="edit_name" value="<?=$value['name'] ?>" placeholder="Имя">
</div>
<div class="form-group">
<input type="text" class="form-control" name="edit_last_name" value="<?=$value['last_name'] ?>" placeholder="Фамилия">
</div>
<div class="form-group">
<input type="text" class="form-control" name="edit_pos" value="<?=$value['pos'] ?>" placeholder="Должность">
</div>
<div class="modal-footer">
<button type="submit" name="edit-submit" class="btn btn-primary">Обновить</button>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- DELETE MODAL -->
<div class="modal fade" id="deleteModal<?=$value['id'] ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content shadow">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Удалить запись № <?=$value['id'] ?></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Отмена</button>
<form action="?id=<?=$value['id'] ?>" method="post">
<button type="submit" name="delete_submit" class="btn btn-danger">Удалить</button>
</form>
</div>
</div>
</div>
</div>