<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>БД «Студент»</title>
<link rel="shortcut icon" href="img/favicon.png" type="image/png">
<link href="css/normalize.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Asap" rel="stylesheet">
<link href="css/styles.css" rel="stylesheet">
</head>
<body>
<header class="header">
<div class="container">
<div class="header-title">
<div class="header-title_logo">
<img src="img/icon_header.png" alt="Лого сайта">
</div>
БД «Студент»
</div>
<div class="nav-wrapper">
<nav class="nav">
<ul>
<li><a href="#" class="btn-viewing">Просмотр</a></li>
<li><a href="#" class="btn-remove">Удаление</a></li>
<li><a href="#" class="btn-search">Поиск</a></li>
<li><a href="#" class="btn-change">Корректировка</a></li>
<li><a href="#" class="btn-charts">Диаграммы</a></li>
<li><a href="#" class="btn-other">Прочее</a></li>
</ul>
</nav>
</div>
</div>
</div>
</header>
<main class="main-container">
<form action="php/data_processing.php" method="POST" class="form">
<div class="form-wrapper">
<div class="input-wrapper">
<label for="name"></label>
<input class="item-input name" id="name" name="fullName" placeholder="ФИО">
</div>
<div class="input-wrapper">
<label for="date"></label>
<input type="number" class="item-input date" id="date" name="date" placeholder="Год рождения">
</div>
<div class="input-wrapper">
<label for="home-adress"></label>
<input class="item-input home-adress" id="home-adress" name="home_adress" placeholder="Домашний адрес">
</div>
<div class="input-wrapper">
<label for="faculty"></label>
<input class="item-input faculty" id="faculty" name="faculty" placeholder="Факультет">
</div>
<div class="input-wrapper">
<label for="specialty"></label>
<input class="item-input specialty" id="specialty" name="specialty" placeholder="Специальность">
</div>
<div class="input-wrapper">
<label for="course"></label>
<input type="number" class="item-input course" id="course" name="course" placeholder="Курс">
</div>
<div class="input-wrapper">
<label for="university"></label>
<input class="item-input university" id="university" name="university" placeholder="ВУЗ">
</div>
<div class="sumbit-wrapper">
<label for="submit"></label>
<input type="submit" class="btn-submit" id="submit" disabled>
</div>
</div>
</form>
</main>
<div class="showcontent-wrap hide">
<h1>Содержимое БД</h1>
<div class="choose-studen-wrap">
<div class="choose-navigation">
<select class="choose-student">
</select>
<button class="btn-showbd">Показать</button>
</div>
<div class="showbd">
<input class="item-output name" disabled>
<input class="item-output date" disabled>
<input class="item-output home-adress" disabled>
<input class="item-output faculty" disabled>
<input class="item-output specialty" disabled>
<input class="item-output course" disabled>
<input class="item-output university" disabled>
</div>
</div>
</div>
<div class="modal-wrapper hide">
<div class="upper-modal">
<div class="pictureModal">
<img src="img/warning.png" alt="">
<div class="messange-modal">
<p>В базе данных нет студентов!</p>
</div>
</div>
</div>
<div class="lower-modal">
<button class="btn-close">ОК</button>
</div>
</div>
<script src="script/external.js"></script>
</body>
</html>
/*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */
/* Document
========================================================================== */
/**
* 1. Correct the line height in all browsers.
* 2. Prevent adjustments of font size after orientation changes in iOS.
*/
html {
line-height: 1.15; /* 1 */
text-size-adjust: 100%; /* 2 */
}
/* Sections
========================================================================== */
/**
* Remove the margin in all browsers.
*/
body {
margin: 0;
}
/**
* Render the `main` element consistently in IE.
*/
main {
display: block;
}
/**
* Correct the font size and margin on `h1` elements within `section` and
* `article` contexts in Chrome, Firefox, and Safari.
*/
h1 {
font-size: 2em;
margin: 0.67em 0;
}
/* Grouping content
========================================================================== */
/**
* 1. Add the correct box sizing in Firefox.
* 2. Show the overflow in Edge and IE.
*/
hr {
box-sizing: content-box; /* 1 */
height: 0; /* 1 */
overflow: visible; /* 2 */
}
/**
* 1. Correct the inheritance and scaling of font size in all browsers.
* 2. Correct the odd `em` font sizing in all browsers.
*/
pre {
font-family: monospace, monospace; /* 1 */
font-size: 1em; /* 2 */
}
/* Text-level semantics
========================================================================== */
/**
* Remove the gray background on active links in IE 10.
*/
a {
background-color: transparent;
}
/**
* 1. Remove the bottom border in Chrome 57-
* 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari.
*/
abbr[title] {
border-bottom: none; /* 1 */
text-decoration: underline; /* 2 */
text-decoration: underline dotted; /* 2 */
}
/**
* Add the correct font weight in Chrome, Edge, and Safari.
*/
b,
strong {
font-weight: bolder;
}
/**
* 1. Correct the inheritance and scaling of font size in all browsers.
* 2. Correct the odd `em` font sizing in all browsers.
*/
code,
kbd,
samp {
font-family: monospace, monospace; /* 1 */
font-size: 1em; /* 2 */
}
/**
* Add the correct font size in all browsers.
*/
small {
font-size: 80%;
}
/**
* Prevent `sub` and `sup` elements from affecting the line height in
* all browsers.
*/
sub,
sup {
font-size: 75%;
line-height: 0;
position: relative;
vertical-align: baseline;
}
sub {
bottom: -0.25em;
}
sup {
top: -0.5em;
}
/* Embedded content
========================================================================== */
/**
* Remove the border on images inside links in IE 10.
*/
img {
border-style: none;
}
/* Forms
========================================================================== */
/**
* 1. Change the font styles in all browsers.
* 2. Remove the margin in Firefox and Safari.
*/
button,
input,
optgroup,
select,
textarea {
font-family: inherit; /* 1 */
font-size: 100%; /* 1 */
line-height: 1.15; /* 1 */
margin: 0; /* 2 */
}
/**
* Show the overflow in IE.
* 1. Show the overflow in Edge.
*/
button,
input { /* 1 */
overflow: visible;
}
/**
* Remove the inheritance of text transform in Edge, Firefox, and IE.
* 1. Remove the inheritance of text transform in Firefox.
*/
button,
select { /* 1 */
text-transform: none;
}
/**
* Correct the inability to style clickable types in iOS and Safari.
*/
button,
[type="button"],
[type="reset"],
[type="submit"] {
appearance: button;
}
/**
* Remove the inner border and padding in Firefox.
*/
button::focus-inner,
[type="button"]::focus-inner,
[type="reset"]::focus-inner,
[type="submit"]::focus-inner {
border-style: none;
padding: 0;
}
/**
* Restore the focus styles unset by the previous rule.
*/
button:focusring,
[type="button"]:focusring,
[type="reset"]:focusring,
[type="submit"]:focusring {
outline: 1px dotted ButtonText;
}
/**
* Correct the padding in Firefox.
*/
fieldset {
padding: 0.35em 0.75em 0.625em;
}
/**
* 1. Correct the text wrapping in Edge and IE.
* 2. Correct the color inheritance from `fieldset` elements in IE.
* 3. Remove the padding so developers are not caught out when they zero out
* `fieldset` elements in all browsers.
*/
legend {
box-sizing: border-box; /* 1 */
color: inherit; /* 2 */
display: table; /* 1 */
max-width: 100%; /* 1 */
padding: 0; /* 3 */
white-space: normal; /* 1 */
}
/**
* Add the correct vertical alignment in Chrome, Firefox, and Opera.
*/
progress {
vertical-align: baseline;
}
/**
* Remove the default vertical scrollbar in IE 10+.
*/
textarea {
overflow: auto;
}
/**
* 1. Add the correct box sizing in IE 10.
* 2. Remove the padding in IE 10.
*/
[type="checkbox"],
[type="radio"] {
box-sizing: border-box; /* 1 */
padding: 0; /* 2 */
}
/**
* Correct the cursor style of increment and decrement buttons in Chrome.
*/
[type="number"]::inner-spin-button,
[type="number"]::outer-spin-button {
height: auto;
}
/**
* 1. Correct the odd appearance in Chrome and Safari.
* 2. Correct the outline style in Safari.
*/
[type="search"] {
appearance: textfield; /* 1 */
outline-offset: -2px; /* 2 */
}
/**
* Remove the inner padding in Chrome and Safari on macOS.
*/
[type="search"]::search-decoration {
appearance: none;
}
/**
* 1. Correct the inability to style clickable types in iOS and Safari.
* 2. Change font properties to `inherit` in Safari.
*/
::file-upload-button {
appearance: button; /* 1 */
font: inherit; /* 2 */
}
/* Interactive
========================================================================== */
/*
* Add the correct display in Edge, IE 10+, and Firefox.
*/
details {
display: block;
}
/*
* Add the correct display in all browsers.
*/
summary {
display: list-item;
}
/* Misc
========================================================================== */
/**
* Add the correct display in IE 10+.
*/
template {
display: none;
}
/**
* Add the correct display in IE 10.
*/
[hidden] {
display: none;
}
* {
box-sizing: border-box;
font-family: 'Asap', sans-serif;
}
.header {
background-color: #bff199;
}
.container {
display: box;
display: flexbox;
display: flex;
box-pack: justify;
flex-pack: justify;
justify-content: space-between;
box-align: center;
flex-align: center;
align-items: center;
padding: 8px;
}
.header-title {
display: inline-box;
display: inline-flexbox;
display: inline-flex;
box-align: center;
flex-align: center;
align-items: center;
font-size: 28px;
}
.header-title_logo {
margin-right: 5px;
}
nav ul {
display: box;
display: flexbox;
display: flex;
list-style: none;
}
nav a {
margin-right: 10px;
font-size: 20px;
text-decoration: none;
color: black;
transition: all 0.3s;
transition: all 0.3s;
}
nav a:hover {
border-bottom: 2px solid white;
}
.main-container {
display: flex;
flex-direction: column;
justify-content: center;
width: 400px;
height: 450px;
margin: 20px auto;
border: 2px solid #bff199;
border-radius: 20px;
}
.form-wrapper {
padding: 75px;
padding-top: none;
}
.item-input {
width: 250px;
margin-bottom: 10px;
border-radius: 5px;
font-size: 24px;
}
.sumbit-wrapper {
text-align: center;
}
.btn-submit {
padding: 12px 20px;
margin-left: 5px;
width: 80%;
color: white;
background-color: #7f7f7f;
border-radius: 5px;
font-size: 13px;
font-weight: 700;
text-transform: uppercase;
outline: none;
}
.show {
display: block;
}
.hide {
display: none;
}
.modal-wrapper {
position: absolute;
top: 25%;
left: 35%;
width: 400px;
height: 200px;
border: 3px solid black;
border-radius: 10px;
z-index: 10;
}
.upper-modal {
position: relative;
height: 70%;
background-color: #ee3322;
}
.lower-modal {
position: relative;
height: 30%;
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
background-color: white;
}
.btn-close {
position: relative;
width: 100px;
height: 35px;
left: 38%;
top: 25%;
outline: none;
border-radius: 50px;
background-color: #ee3322;
}
.pictureModal img {
width: 64px;
height: 64px;
}
.pictureModal {
position: relative;
top: 25%;
left: 43%;
}
.pictureModal p {
margin: -2px 0 0 -50px;
}
.invalid-input {
border: 1px solid red;
}
.showcontent-wrap {
text-align: center;
}
.choose-studen-wrap {
position: relative;
width: 400px;
height: 400px;
top: 30%;
left: 35%;
border: 2px solid red;
}
.choose-navigation {
margin-top: 20px;
}
.btn-showbd {
padding: 12px 20px;
margin-left: 5px;
color: white;
background-color: #7f7f7f;
border-radius: 5px;
font-size: 13px;
font-weight: 700;
text-transform: uppercase;
outline: none;
}
.btn-active {
color: black;
background-color: #f9f9f9;
border: 1px solid #bff199;
}
.showbd {
margin-top: 10px;
}
.item-output {
margin: 5px;
}
.chips {
padding: 10px 20px;
margin: 20px 10px;
border-radius: 12px;
background: #ee6e73;
color: #fff;
}
.chips-field {
position: fixed;
top: 15%;
right: 25%;
width: 200px;
text-align: center;
}
const btnViewing = document.querySelector(".btn-viewing"),
containerForm = document.querySelector(".container"),
containerShowBD = document.querySelector(".showcontent-wrap"),
inputs = document.querySelectorAll(".item-input"),
closeModal = document.querySelector(".btn-close"),
modalWrapper = document.querySelector(".modal-wrapper"),
btnSubmit = document.querySelector(".btn-submit"),
chooseStudent = document.querySelector(".choose-student"),
btnShowBD = document.querySelector(".btn-showbd"),
itemOutput = document.querySelectorAll(".item-output");
let dataBase;
btnViewing.addEventListener("click", () => {
if (isEmptyObject(dataBase) != true) {
if (!containerForm.classList.contains('hide')) {
containerForm.classList.add("hide");
btnViewing.innerText = "Показать форму";
containerShowBD.classList.remove("hide");
} else {
containerForm.classList.remove("hide");
btnViewing.innerText = "Показать БД";
containerShowBD.classList.add("hide");
}
} else {
modalWrapper.classList.remove("hide");
disableInputs();
closeModal.addEventListener("click", () => {
modalWrapper.classList.add("hide");
inclusionInputs();
});
}
});
function disableInputs() {
for (let el = 0; el < inputs.length; el++) {
inputs[el].setAttribute("disabled", "");
}
btnSubmit.setAttribute("disabled", "");
}
function inclusionInputs() {
for (let el = 0; el < inputs.length; el++) {
inputs[el].removeAttribute("disabled");
}
btnSubmit.removeAttribute("disabled");
}
btnSubmit.addEventListener("click", () => {
if (formValidator() == true) {
recordObject();
insertSelect();
chips();
resetForm();
}
});
function formValidator() {
let correctInputs = 0;
for (let el = 0; el < inputs.length; el++) {
if (inputs[el].value == "") el++;
if (inputs[el].value.match(/[А-я]/)) {
correctInputs++;
inputs[el].classList.remove("invalid-input");
}
else if (el == 1 && +inputs[1].value.match(/^\d{4}$/)) {
correctInputs++;
inputs[el].classList.remove("invalid-input");
}
else if (el == 5 && +inputs[5].value > 0 && +inputs[5].value < 7) {
correctInputs++;
inputs[el].classList.remove("invalid-input");
}
else {
inputs[el].classList.add("invalid-input");
}
}
return correctInputs == 7 ? true : false;
}
function resetForm() {
document.querySelector('.form').reset();
btnSubmit.classList.remove("btn-active");
btnSubmit.setAttribute("disabled", "");
}
function isEmptyObject(dataBase) {
for (let key in dataBase) {
if (dataBase.hasOwnProperty(key)) {
return false;
}
}
return true;
}
function recordObject() {
let i = 0;
dataBase = {
fullName: '',
dateOfBirth: '',
address: '',
faculty: '',
spetsial: '',
course: '',
institution: ''
}
for (let key in dataBase) {
dataBase[key] = inputs[i].value;
i++;
}
console.log(dataBase);
}
function insertSelect() {
let nameOption = document.createElement("option");
nameOption.textContent = dataBase.fullName;
chooseStudent.appendChild(nameOption);
}
document.querySelector(".form").addEventListener("change", () => {
if (formValidator() == true) {
btnSubmit.classList.add("btn-active");
btnSubmit.removeAttribute("disabled");
}
});
function chips() {
let chips = document.createElement('div');
chips.classList.add("chips");
chips.innerText = "Студент успешнно добавлен";
addChips(chips);
setTimeout(function () { deleteChips(chips)}, 3000);
}
function deleteChips(chips) {
chips.remove();
let allChips = document.querySelectorAll(".chips-field .chips");
if (allChips.length == 0) document.querySelector(".chips-field").remove();
}
function addChips(chips) {
let chipsField = document.querySelector(".chips-field");
if (chipsField) {
chipsField.appendChild(chips);
} else {
let chipsField = document.createElement("div");
chipsField.classList.add("chips-field");
document.querySelector("body").appendChild(chipsField);
chipsField.appendChild(chips);
}
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.