forked from fr/deguapp
		
	upload
This commit is contained in:
		
							
								
								
									
										11
									
								
								frontend/css/add.css
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								frontend/css/add.css
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
			
		||||
.form_add {
 | 
			
		||||
	display: flex;
 | 
			
		||||
	flex-direction: column;
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.form_group_label {
 | 
			
		||||
	display: flex;
 | 
			
		||||
	flex-direction: column;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										0
									
								
								frontend/css/home.css
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								frontend/css/home.css
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										0
									
								
								frontend/css/show.css
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								frontend/css/show.css
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										58
									
								
								frontend/index.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								frontend/index.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,58 @@
 | 
			
		||||
<?php
 | 
			
		||||
	require_once("./libs/Router.php");
 | 
			
		||||
	
 | 
			
		||||
	// Display Errors
 | 
			
		||||
	ini_set('display_startup_errors', 1);
 | 
			
		||||
	ini_set('display_errors', 1);
 | 
			
		||||
	error_reporting(-1);
 | 
			
		||||
	
 | 
			
		||||
	// Display var_dump
 | 
			
		||||
	#var_dump($_SESSION);
 | 
			
		||||
	
 | 
			
		||||
	// Date Time Zone
 | 
			
		||||
	date_default_timezone_set('Europe/Prague');
 | 
			
		||||
	$API_URL = "http://localhost:6060"
 | 
			
		||||
?>
 | 
			
		||||
 | 
			
		||||
<!DOCTYPE html>
 | 
			
		||||
<html lang="cs">
 | 
			
		||||
	<head>
 | 
			
		||||
		<title>DeguApp</title>
 | 
			
		||||
		<meta charset="UTF-8">
 | 
			
		||||
		<meta name="viewport" content="width=device-width, initial-scale=1">
 | 
			
		||||
		<link href="home.css" rel="stylesheet">
 | 
			
		||||
	</head>
 | 
			
		||||
	<body>
 | 
			
		||||
		<header>
 | 
			
		||||
			<div class="flex-left">
 | 
			
		||||
				<a href="/">DeguApp</a>
 | 
			
		||||
			</div>
 | 
			
		||||
			<div class="flex-left">
 | 
			
		||||
				<a href="/login">Přihlásit se</a>
 | 
			
		||||
				<a href="/signup">Registrace</a>
 | 
			
		||||
				<a href="/add_beer">Přidat pivo</a>
 | 
			
		||||
				<a href="/add_review">Přidat recenzi</a>
 | 
			
		||||
			</div>
 | 
			
		||||
		</header>
 | 
			
		||||
		<section class="main-wrapper">
 | 
			
		||||
			<h1>DeguApp</h1>
 | 
			
		||||
			<?php
 | 
			
		||||
				$R = new Router();
 | 
			
		||||
				$R->route('GET', '/', 'home');
 | 
			
		||||
				$R->route('GET', '/add', 'add');
 | 
			
		||||
				$R->route('GET', '/login', 'login');
 | 
			
		||||
				$R->route('GET', '/signup', 'signup');
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
				$R->route('POST', '/contact/send', 'contact');
 | 
			
		||||
 | 
			
		||||
				$R = null;
 | 
			
		||||
			?>
 | 
			
		||||
		</section>
 | 
			
		||||
		<footer>
 | 
			
		||||
			<a href="https://git.filiprojek.cz/fr/deguapp">Source</a>
 | 
			
		||||
			<a href="http://filiprojek.cz/">(c) Filip Rojek, 2023</a>
 | 
			
		||||
		</footer>
 | 
			
		||||
	</body>
 | 
			
		||||
</html>
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										33
									
								
								frontend/libs/Router.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								frontend/libs/Router.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,33 @@
 | 
			
		||||
<?php
 | 
			
		||||
class Router {
 | 
			
		||||
	public $returned = false;
 | 
			
		||||
 | 
			
		||||
	function route($method, $url, $filename) {
 | 
			
		||||
		$methods = ['GET', 'POST'];
 | 
			
		||||
		if(in_array($method, $methods)) {
 | 
			
		||||
			if($_SERVER['REQUEST_METHOD'] == $method) {
 | 
			
		||||
				if ($_SERVER['REQUEST_URI'] == $url) {
 | 
			
		||||
					require_once("./pages/$filename/$filename.php");
 | 
			
		||||
					$this->returned = true;
 | 
			
		||||
					return;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	function __destruct() {
 | 
			
		||||
		if($_SERVER['REQUEST_METHOD'] == 'GET') {
 | 
			
		||||
			if(!$this->returned){
 | 
			
		||||
				$url = explode("/", $_SERVER['REQUEST_URI']);
 | 
			
		||||
				$url = $url[count($url)-1];
 | 
			
		||||
 | 
			
		||||
				if (file_exists("./pages/$url/$url.php")) {
 | 
			
		||||
					require_once("./pages/$url/$url.php");
 | 
			
		||||
				} else {
 | 
			
		||||
					require_once("./pages/errors/404.php");
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										84
									
								
								frontend/pages/add_beer/add_beer.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										84
									
								
								frontend/pages/add_beer/add_beer.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,84 @@
 | 
			
		||||
<?php
 | 
			
		||||
	$API_URL = "http://localhost:6060"
 | 
			
		||||
?>
 | 
			
		||||
<link href="/css/add.css" rel="stylesheet">
 | 
			
		||||
<h1>Přidání piva</h1>
 | 
			
		||||
 | 
			
		||||
<form class="form_add">
 | 
			
		||||
	<div class=form_group>
 | 
			
		||||
		<div class=form_group_label>
 | 
			
		||||
			<label for="brand">Značka:</label>
 | 
			
		||||
			<input type="text" name="brand" id="brand" enable>
 | 
			
		||||
		</div>
 | 
			
		||||
		<div class=form_group_label>
 | 
			
		||||
			<label for="name">Název:</label>
 | 
			
		||||
			<input type="text" name="name" id="name" enable>
 | 
			
		||||
		</div>
 | 
			
		||||
		<div class=form_group_label>
 | 
			
		||||
			<label for="degree">Stupeň:</label>
 | 
			
		||||
			<input type="text" name="degree" id="degree" enable>
 | 
			
		||||
		</div>
 | 
			
		||||
	</div>
 | 
			
		||||
 | 
			
		||||
	<div class=form_group>
 | 
			
		||||
		<div class=form_group_label>
 | 
			
		||||
			<label for="packaging">Obal:</label>
 | 
			
		||||
			<select id="packaging" name="packaging" enable>
 | 
			
		||||
				<option value="1">Plech</option>
 | 
			
		||||
				<option value="2">Sklo</option>
 | 
			
		||||
				<option value="3">Jiné</option>
 | 
			
		||||
			</select>
 | 
			
		||||
		</div>
 | 
			
		||||
	</div>
 | 
			
		||||
		<div class=form_group_label>
 | 
			
		||||
			<label for="note">Poznámka:</label>
 | 
			
		||||
			<input type="text" name="note" id="note" enable>
 | 
			
		||||
		</div>
 | 
			
		||||
	</div>
 | 
			
		||||
	<div class="form_group">
 | 
			
		||||
		<div class=form_group_label>
 | 
			
		||||
			<label for="photo">Foto:</label>
 | 
			
		||||
			<input type="file" name="image" id="image" enable>
 | 
			
		||||
		</div>
 | 
			
		||||
	</div>
 | 
			
		||||
 | 
			
		||||
	<div class="form_group">
 | 
			
		||||
		<button class="btn-send">Přidat záznam</button>
 | 
			
		||||
	</div>
 | 
			
		||||
</form>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
	const btn = document.querySelector('.btn-send')
 | 
			
		||||
	btn.addEventListener('click', (e) => {
 | 
			
		||||
		e.preventDefault()
 | 
			
		||||
		console.log('click')
 | 
			
		||||
		send()
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	async function send() {
 | 
			
		||||
		console.log('click')
 | 
			
		||||
		let form = new FormData(document.querySelector("form"));
 | 
			
		||||
 | 
			
		||||
		let body = JSON.stringify(Object.fromEntries(form))
 | 
			
		||||
			fetch('<?php echo $API_URL;?>/api/v1/beer/add', {
 | 
			
		||||
			credentials: 'include',
 | 
			
		||||
			headers: {
 | 
			
		||||
				'Content-Type': 'application/json',
 | 
			
		||||
			},
 | 
			
		||||
			method: 'POST',
 | 
			
		||||
			body: body,
 | 
			
		||||
		})
 | 
			
		||||
			.then(res => {
 | 
			
		||||
				console.log(res)
 | 
			
		||||
				console.log(res.json())
 | 
			
		||||
				
 | 
			
		||||
			})
 | 
			
		||||
			.then(data => {
 | 
			
		||||
				console.log(data)
 | 
			
		||||
			})
 | 
			
		||||
			.catch(err => {
 | 
			
		||||
				console.log(err)
 | 
			
		||||
			})
 | 
			
		||||
	}
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										188
									
								
								frontend/pages/add_review/add_review.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										188
									
								
								frontend/pages/add_review/add_review.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,188 @@
 | 
			
		||||
<?php
 | 
			
		||||
	$API_URL = "http://localhost:6060"
 | 
			
		||||
?>
 | 
			
		||||
<link href="/css/add.css" rel="stylesheet">
 | 
			
		||||
<h1>Přidání záznamu</h1>
 | 
			
		||||
 | 
			
		||||
<form class="form_add">
 | 
			
		||||
	<div class=form_group>
 | 
			
		||||
		<div class=form_group_label>
 | 
			
		||||
			<label for="user">Uživatel:</label>
 | 
			
		||||
			<select id="user" name="user" enable>
 | 
			
		||||
				<option value="">Dž</option>
 | 
			
		||||
				<option value="">Dý Ej En</option>
 | 
			
		||||
				<option value="">frfr</option>
 | 
			
		||||
			</select>
 | 
			
		||||
		</div>
 | 
			
		||||
	</div>
 | 
			
		||||
	<div class=form_group>
 | 
			
		||||
		<div class=form_group_label>
 | 
			
		||||
			<label for="beer">Beer:</label>
 | 
			
		||||
			<select name="beer" id="beer">
 | 
			
		||||
			</select>
 | 
			
		||||
		</div>
 | 
			
		||||
	</div>
 | 
			
		||||
 | 
			
		||||
	<div class=form_group>
 | 
			
		||||
		<div class=form_group_label>
 | 
			
		||||
			<label for="logo">Logo:</label>
 | 
			
		||||
			<input type="number" name="logo" id="logo" min="1" max="10" step="1" enable>
 | 
			
		||||
		</div>
 | 
			
		||||
 | 
			
		||||
		<div class=form_group_label>
 | 
			
		||||
			<label for="aroma">Vůně:</label>
 | 
			
		||||
			<input type="number" name="aroma" id="aroma" min="1" max="10" step="1" enable>
 | 
			
		||||
		</div>
 | 
			
		||||
 | 
			
		||||
		<div class=form_group_label>
 | 
			
		||||
			<label for="foam">Pěna:</label>
 | 
			
		||||
			<input type="number" name="foam" id="foam" min="1" max="10" step="1" enable>
 | 
			
		||||
		</div>
 | 
			
		||||
 | 
			
		||||
		<div class=form_group_label>
 | 
			
		||||
			<label for="color">Barva:</label>
 | 
			
		||||
			<input type="number" name="color" id="color" min="1" max="10" step="1" enable>
 | 
			
		||||
		</div>
 | 
			
		||||
	</div>
 | 
			
		||||
 | 
			
		||||
	<div class=form_group>
 | 
			
		||||
		<div class=form_group_label>
 | 
			
		||||
			<label for="bitterness">Hořkost:</label>
 | 
			
		||||
			<input type="number" name="bitterness" id="bitterness" min="1" max="10" step="1" enable>
 | 
			
		||||
		</div>
 | 
			
		||||
 | 
			
		||||
		<div class=form_group_label>
 | 
			
		||||
			<label for="sweetness">Sladkost:</label>
 | 
			
		||||
			<input type="number" name="sweetness" id="sweetness" min="1" max="10" step="1" enable>
 | 
			
		||||
		</div>
 | 
			
		||||
 | 
			
		||||
		<div class=form_group_label>
 | 
			
		||||
			<label for="note">Poznámka:</label>
 | 
			
		||||
			<input type="text" name="note" id="note" enable>
 | 
			
		||||
		</div>
 | 
			
		||||
	</div>
 | 
			
		||||
 | 
			
		||||
	<div class=form_group>
 | 
			
		||||
		<div class=form_group_label>
 | 
			
		||||
			<label for="again">Dal bych si znovu?</label>
 | 
			
		||||
			<select name="again" enable>
 | 
			
		||||
				<option value="yes">Ano</option>
 | 
			
		||||
				<option value="no">Ne</option>
 | 
			
		||||
			</select>
 | 
			
		||||
		</div>
 | 
			
		||||
 | 
			
		||||
		<div class=form_group_label>
 | 
			
		||||
			<label for="overall_rating">Celkový dojem:</label>
 | 
			
		||||
			<input type="number" name="overall_rating" id="overall_rating" min="1" max="10" step="1" enable>
 | 
			
		||||
		</div>
 | 
			
		||||
 | 
			
		||||
		<div class=form_group_label>
 | 
			
		||||
			<label for="final_rating">Hodnocení:</label>
 | 
			
		||||
			<input type="number" name="final_rating" id="final_rating" min="1" max="10" step="0.5" enable>
 | 
			
		||||
		</div>
 | 
			
		||||
	</div>
 | 
			
		||||
 | 
			
		||||
	<div class=form_group>
 | 
			
		||||
		<div class=form_group_label>
 | 
			
		||||
			<label for="date">Datum:</label>
 | 
			
		||||
			<input type="date" name="date" id="date" enable>
 | 
			
		||||
		</div>
 | 
			
		||||
 | 
			
		||||
		<div class=form_group_label>
 | 
			
		||||
			<label for="attendedts">S kým:</label>
 | 
			
		||||
			<input type="text" name="attendedts" id="attendents" enable>
 | 
			
		||||
		</div>
 | 
			
		||||
 | 
			
		||||
		<div class=form_group_label>
 | 
			
		||||
			<label for="sign">Podpis:</label>
 | 
			
		||||
			<input type="text" name="sign" id="sign" enable>
 | 
			
		||||
		</div>
 | 
			
		||||
	</div>
 | 
			
		||||
 | 
			
		||||
	<div class="form_group">
 | 
			
		||||
		<div class=form_group_label>
 | 
			
		||||
			<label for="photo">Foto:</label>
 | 
			
		||||
			<input type="file" name="image" id="image" enable>
 | 
			
		||||
		</div>
 | 
			
		||||
		<div class=form_group_label>
 | 
			
		||||
			<label for="bebeer">BeBeer:</label>
 | 
			
		||||
			<input type="file" name="bebeer" id="bebeer" enable>
 | 
			
		||||
		</div>
 | 
			
		||||
	</div>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	<div class="form_group">
 | 
			
		||||
		<button class="btn-send">Přidat záznam</button>
 | 
			
		||||
	</div>
 | 
			
		||||
</form>
 | 
			
		||||
 | 
			
		||||
<script defer>
 | 
			
		||||
	async function getBeers() {
 | 
			
		||||
		try {
 | 
			
		||||
			const res = await fetch('<?php echo $API_URL;?>/api/v1/beer/get')
 | 
			
		||||
			const data = await res.json()
 | 
			
		||||
			console.log(data)
 | 
			
		||||
			return data
 | 
			
		||||
		} catch(err) {
 | 
			
		||||
			console.log(err, "penis")
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	const btn = document.querySelector('.btn-send')
 | 
			
		||||
	btn.addEventListener('click', (e) => {
 | 
			
		||||
		e.preventDefault()
 | 
			
		||||
		send()
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	async function send() {
 | 
			
		||||
		let form = new FormData(document.querySelector("form"));
 | 
			
		||||
 | 
			
		||||
		let body = JSON.stringify(Object.fromEntries(form))
 | 
			
		||||
			fetch('<?php echo $API_URL;?>/api/v1/review/add', {
 | 
			
		||||
			credentials: 'include',
 | 
			
		||||
			headers: {
 | 
			
		||||
				'Content-Type': 'application/json',
 | 
			
		||||
			},
 | 
			
		||||
			method: 'POST',
 | 
			
		||||
			body: body,
 | 
			
		||||
		})
 | 
			
		||||
			.then(res => {
 | 
			
		||||
				console.log(res)
 | 
			
		||||
				console.log(res.json())
 | 
			
		||||
				
 | 
			
		||||
			})
 | 
			
		||||
			.then(data => {
 | 
			
		||||
				console.log(data)
 | 
			
		||||
			})
 | 
			
		||||
			.catch(err => {
 | 
			
		||||
				console.log(err)
 | 
			
		||||
			})
 | 
			
		||||
	}
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<script async defer>
 | 
			
		||||
	const packagingToLang = (id_pckg) => {
 | 
			
		||||
		const pckgs = {
 | 
			
		||||
			1: "Plech",
 | 
			
		||||
			2: "Sklo",
 | 
			
		||||
			3: "Plast"
 | 
			
		||||
		}
 | 
			
		||||
		return pckgs[id_pckg]
 | 
			
		||||
	}
 | 
			
		||||
	(async() => {
 | 
			
		||||
		// get beers and fill form data
 | 
			
		||||
		const beerData = await getBeers()
 | 
			
		||||
		const beer = document.querySelector('#beer')
 | 
			
		||||
 | 
			
		||||
		const beerOptions = beerData?.map((beer) => {
 | 
			
		||||
			return `
 | 
			
		||||
				<option value="${beer._id}">${beer.name} ${beer.degree} ${packagingToLang(beer.packaging)}</option>
 | 
			
		||||
			`
 | 
			
		||||
		})
 | 
			
		||||
		console.log(beerData)
 | 
			
		||||
 | 
			
		||||
		beer.innerHTML = beerOptions
 | 
			
		||||
	})()
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										0
									
								
								frontend/pages/errors/404.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								frontend/pages/errors/404.php
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										0
									
								
								frontend/pages/home/home.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								frontend/pages/home/home.php
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										0
									
								
								frontend/pages/show/show.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								frontend/pages/show/show.php
									
									
									
									
									
										Normal file
									
								
							
		Reference in New Issue
	
	Block a user