Browse Source

Upload files to 'nk_part3'

master
Jakub Škrabánek 2 years ago
parent
commit
4df217ac33
  1. 6
      nk_part3/logout.php
  2. 18
      nk_part3/menu.php
  3. 56
      nk_part3/nk_part3.sql
  4. 43
      nk_part3/reg.php
  5. 32
      nk_part3/write.php

6
nk_part3/logout.php

@ -0,0 +1,6 @@
<?php
session_start();
session_unset();
session_destroy();
header("Location: /?logout=1");
?>

18
nk_part3/menu.php

@ -0,0 +1,18 @@
<ul>
<li><a href="/">HOME</a></li>
<li><a href="list.php">Vypsat knihu</a></li>
<li><a href="write.php">Zapsat do knihy</a></li>
<?php
if(isset($_SESSION["logged"])) {
echo '<li><a href="logout.php">Odhlásit se</a></li>';
if ($_SESSION["role"] == 1) {
echo '<li><a href="admin.php">ADMIN</a></li>';
}
} else {
echo '<li><a href="reg.php">Registrovat se</a></li>'; // kombinace uvozovek
echo "<li><a href=\"login.php\">Přihlásit se</a></li>"; //"escape" znaků
}
?>
</ul>

56
nk_part3/nk_part3.sql

@ -0,0 +1,56 @@
-- Adminer 4.7.6 MySQL dump
SET NAMES utf8;
SET time_zone = '+00:00';
SET foreign_key_checks = 0;
SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
DROP TABLE IF EXISTS `nk_log`;
CREATE TABLE `nk_log` (
`id` int(11) NOT NULL,
`id_nk_users` int(11) unsigned NOT NULL,
`logintime` datetime NOT NULL,
KEY `id_nk_users` (`id_nk_users`),
CONSTRAINT `nk_log_ibfk_1` FOREIGN KEY (`id_nk_users`) REFERENCES `nk_users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci;
DROP TABLE IF EXISTS `nk_prispevky`;
CREATE TABLE `nk_prispevky` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`id_nk_users` int(11) unsigned NOT NULL,
`title` varchar(128) COLLATE utf8_czech_ci NOT NULL,
`msg` text COLLATE utf8_czech_ci NOT NULL,
`created` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `id_nk_users` (`id_nk_users`),
CONSTRAINT `nk_prispevky_ibfk_1` FOREIGN KEY (`id_nk_users`) REFERENCES `nk_users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci;
INSERT INTO `nk_prispevky` (`id`, `id_nk_users`, `title`, `msg`, `created`) VALUES
(1, 3, 'Lorem 1', 'Lorem Ipsum supres', '2023-03-01 23:36:52'),
(2, 2, 'Lorem 11', 'Lorem ipsumus loremos spravenost', '2023-03-01 23:37:30'),
(4, 9, 'Test z PHP', 'LOREM lipsum', '2023-03-09 10:12:35'),
(5, 10, 'Hodnocení', 'Je to tu boží, mám to tady rád ☺', '2023-03-09 10:22:39'),
(7, 1, 'Ctcrřtky jsou fajne v2', 'testxt', '2023-03-23 09:57:45'),
(8, 4, 'Zapis od Mod1', 'AHOJ DĚTI', '2023-03-23 10:07:55');
DROP TABLE IF EXISTS `nk_users`;
CREATE TABLE `nk_users` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`username` varchar(32) COLLATE utf8_czech_ci NOT NULL,
`password` varchar(64) COLLATE utf8_czech_ci NOT NULL,
`role` int(3) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci;
INSERT INTO `nk_users` (`id`, `username`, `password`, `role`) VALUES
(1, 'admin', 'admin', 1),
(2, 'user1', 'user1', 5),
(3, 'user2', 'user2', 5),
(4, 'mod1', 'mod1', 3),
(5, 'mod2', 'mod2', 3),
(9, 'asd', 'asd', 5),
(10, 'xyz', 'xyz', 5);
-- 2023-03-23 09:32:22

43
nk_part3/reg.php

@ -0,0 +1,43 @@
<?php
session_start();
include("init.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Registrace</h1>
<?php
include "menu.php";
?>
<?php
if(isset($_GET["error"])){
if ($_GET["error"] == "1") {
echo "<h2>Hesla nejsou stejná</h2>";
}
}
?>
<form action="action_reg.php" method="post">
<label for="username">Přihlašovací jméno:</label><br>
<input type="text" name="username" id="username">
<br>
<label for="pw1">Heslo:</label><br>
<input type="password" name="pw1" id="pw1">
<br>
<label for="pw2">Opakovat heslo:</label><br>
<input type="password" name="pw2" id="pw2">
<br>
<br>
<input type="submit" value="Registrovat">
</form>
</body>
</html>

32
nk_part3/write.php

@ -0,0 +1,32 @@
<?php
session_start();
include("init.php");
if(!isset($_SESSION["logged"])){
header("Location: /?error=3"); //error 3 = přístup odepřen
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Zápis do knihy</title>
</head>
<body>
<h1>Zápis do knihy</h1>
<?php
include "menu.php";
?>
<form action="action_write.php" method="post">
<label for="title">Nadpis:</label><br>
<input type="text" name="title" id="title"><br>
<label for="msg">Zpráva do knihy:</label><br>
<textarea name="msg" id="msg" cols="30" rows="10"></textarea>
<br>
<input type="submit" value="Zapsat do knihy">
</form>
</body>
</html>
Loading…
Cancel
Save