projekt templade added

This commit is contained in:
David Kalemi 2025-06-12 16:36:11 +02:00
parent d10b697c8c
commit 526b6504a8
22 changed files with 558 additions and 0 deletions

145
CSS/style.css Normal file
View File

@ -0,0 +1,145 @@
/*
Created on : 04.01.2018, 15:39:10
Author : reich
*/
*, *:before, *:after {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
margin: 0;
}
body {
font-size: 18px;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
.wrapper {
max-width: 1000px;
margin: 0 auto;
}
/*** Allgemeine Definitionen ***/
h1 {
/* margin: 10px; */
color: #F2F2F2;
font-size: 48px;
font-weight: 100;
text-align: center;
}
h1 span {
margin-left: -2px;
color: #FDBD02;
font-size: 24px;
font-weight: 600;
}
h2 {
padding: 10px 0 10px 0;
text-align: center;
color: #011448;
font-size: 36px;
font-weight: 100;
}
main {
background-color: #e6e6e6;
color: #000;
padding-bottom: 20px;
}
/*** Standard-Button ***/
.button {
text-align: right;
}
.button a {
display: inline-block;
background: #FDBD02;
color:#303E64;
border: none;
width: 100px;
margin: 5px;
padding: 2px;
border-radius: 5px;
cursor:pointer;
font-size: 12px;
text-decoration: none;
text-align: center;
}
.button a:hover {
color:#fff;
}
.clear {
clear: both;
}
/*** Header-Bereich mit Navigationsleiste ***/
header {
width: 100%;
background-color: #303E64;
}
nav {
text-align: center;
position: sticky;
top: 0;
background-color: #303E64;
}
nav ul {
list-style-type: none;
padding: 0;
display: inline-block;
}
nav li {
float: left;
text-align: center;
}
nav li a {
display: block;
width: 120px;
height: 35px;
border: 1px solid #000;
background-color: #e6e6e6;
color: #000;
text-decoration: none;
margin: 5px;
text-align: center;
line-height: 35px;
}
nav li a:hover {
background-color: #F2C608;
}
#metanavi {
color: lightskyblue;
font-weight: bold;
margin-bottom: 5px;
}
.container {
display: flex;
flex-wrap: wrap;
}
.item-4-12 {
flex: 0 0 33.3333333333%;
}
img {
width: 100%;
}
[class*="item-"] {
padding: 0 10px 0 10px;
}

View File

@ -0,0 +1,27 @@
<?php
namespace ppa\Controller;
use ppa\Model\GalleryModel;
use ppa\Library\View;
class GalleryController
{
private $galleryModel;
protected $view;
public function __construct($view)
{
$this->galleryModel = new GalleryModel();
$this->view = $view;
}
public function showPhotos()
{
$this->view->setVars([
"photos" => $this->galleryModel->selectPhotos()
]);
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace ppa\Controller;
/**
* Description of Welcome
*
* @author reich
*/
class WelcomeController
{
public function setView(\ppa\Library\View $view)
{
$this->view = $view;
}
function showWelcome()
{
}
}

25
Library/ErrorMsg.php Normal file
View File

@ -0,0 +1,25 @@
<?php
namespace ppa\Library;
use ppa\Library\View;
class ErrorMsg
{
protected $view;
public function __construct($msg = 'Ihre Anfrage konnte nicht verarbeitet werden', $ex = '')
{
$this->view = new \ppa\Library\View(dirname(__DIR__).DIRECTORY_SEPARATOR.'Views'
, 'Error', 'showErrMsg');
$this->view->setVars([
'error' => $msg,
'debug' => $ex
]);
$this->view->render();
}
}

58
Library/View.php Normal file
View File

@ -0,0 +1,58 @@
<?php
namespace ppa\Library;
class View
{
protected $path, $controller, $do, $vars = [];
/**
* @param string $path Basepath of the views.
* @param string $controllerName Current controller.
* @param string $actionName Current action.
*/
public function __construct($path, $controllerName, $doMethodName)
{
$this->path = $path;
$this->controller = $controllerName;
$this->do = $doMethodName;
}
/**
* Set view vars. The keys will be added, to existing keys.
*
* @param array $vars
*/
public function setVars(array $vars)
{
foreach ($vars as $key => $val) {
$this->vars[$key] = $val;
}
}
public function setDoMethodName($doMethodName)
{
$this->do = $doMethodName;
}
/**
* Render the view.
*
* @throws NotFoundException
*/
public function render()
{
$filename = $this->path.DIRECTORY_SEPARATOR.$this->controller.DIRECTORY_SEPARATOR.$this->do.'.phtml';
if (!file_exists($filename)) {
new \ppa\Library\ErrorMsg("View not found: $filename");
exit();
}
// spare the view the bloat of using "$this->vars[]" for every variable
foreach ($this->vars as $key => $val) {
$$key = $val;
}
include $filename;
}
}

45
Model/Database.php Normal file
View File

@ -0,0 +1,45 @@
<?php
namespace ppa\Model;
abstract class Database {
/**
* Zugangsdaten für die Datenbank
*/
private $dbName = "fotofreunde"; //Datenbankname
private $linkName = "localhost"; //Datenbank-Server
private $user = "root"; //Benutzername
private $pw = "root"; //Passwort
/**
* Stellt eine Verbindung zur Datenbank her
*
* @return \PDO Gibt eine Datenbankverbindung zurueck
*/
public function linkDB() {
try {
$pdo = new \PDO("mysql:dbname=$this->dbName;host=$this->linkName"
, $this->user
, $this->pw
, array(\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION));
return $pdo;
} catch (\PDOException $e) {
new \ppa\Library\ErrorMsg("Verbindung konnte nicht aufgebaut werden.", $e);
die;
}
}
/**
* Zum serverseitigen generieren einer UUID
*
* @return string Liefert eine UUID
*/
public function createUUID()
{
$data = openssl_random_pseudo_bytes(16);
$data[6] = chr(ord($data[6]) & 0x0f | 0x40);
$data[8] = chr(ord($data[8]) & 0x3f | 0x80);
return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
}
}

28
Model/GalleryModel.php Normal file
View File

@ -0,0 +1,28 @@
<?php
namespace ppa\Model;
use ppa\Model\ParticipantModel;
class GalleryModel extends Database
{
public function selectPhotos()
{
$sql = "SELECT title, filename, category.description, firstname, gallery.created
, gallery.description as alt
FROM gallery
JOIN category ON category.id = categoryId
JOIN user ON user.id = userId
ORDER BY gallery.created DESC";
$pdo = $this->linkDB();
try {
$res = $pdo->query($sql);
} catch (\PDOException $e) {
new \ppa\Library\ErrorMsg("Ihre Anfrage konnte nicht verarbeitet werden", $e);
die;
}
return $res->fetchAll(\PDO::FETCH_ASSOC);
}
}

View File

@ -0,0 +1,9 @@
<?php include dirname(__DIR__).'/header.phtml'; ?>
<h2><?=$error?></h2>
<p><?=$debug?></p>
<?php include dirname(__DIR__).'/footer.phtml'; ?>

View File

@ -0,0 +1,17 @@
<?php include dirname(__DIR__).'/header.phtml'; ?>
<h2>Galerie</h2>
<div class="container">
<?php
foreach($photos as $p) {
echo '<div class="item-4-12">';
echo '<h3>' . $p["title"] . '</h3>'
. '<img src="images/' . $p["filename"] . '" />';
echo '</div>';
}
?>
</div>
<?php include dirname(__DIR__).'/footer.phtml'; ?>

View File

@ -0,0 +1,6 @@
<?php include dirname(__DIR__).'/header.phtml'; ?>
<h2>Baustelle</h2>
<?php include dirname(__DIR__).'/footer.phtml'; ?>

5
Views/footer.phtml Normal file
View File

@ -0,0 +1,5 @@
</main>
</div>
</body>
</html>

27
Views/header.phtml Normal file
View File

@ -0,0 +1,27 @@
<!DOCTYPE html>
<html>
<head>
<title>Gallery View Vorlage</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width">
<link href="CSS/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<header>
<div class="wrapper">
<div class="button">
<a href="?controller=User&do=showUserLoginForm">Anmelden</a>
</div>
<h1>Fotofreun<span>.de</span> OWL<span>e.V.</span></h1>
</div>
</header>
<nav>
<ul>
<li><a href="?controller=Welcome&do=showWelcome">Willkommen</a></li>
<li><a href="#">Mitglieder</a></li>
<li><a href="?controller=Gallery&do=showPhotos">Galerie</a></li>
<li><a href="#">G&auml;stebuch</a></li>
</ul>
</nav>
<div class="wrapper">
<main>

107
fotoclub.sql Normal file
View File

@ -0,0 +1,107 @@
-- phpMyAdmin SQL Dump
-- version 4.5.1
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Erstellungszeit: 09. Dez 2017 um 16:39
-- Server-Version: 10.1.16-MariaDB
-- PHP-Version: 7.0.9
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Datenbank: `ppb`
--
-- --------------------------------------------------------
--
-- Tabellenstruktur für Tabelle `user`
--
CREATE TABLE `user` (
`id` varchar(36) NOT NULL,
`username` varchar(8) NOT NULL,
`firstname` varchar(40) NOT NULL,
`lastname` varchar(40) NOT NULL,
`email` varchar(300) NOT NULL,
`pw` varchar(255) NOT NULL,
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `gallery` (
`id` varchar(36) NOT NULL,
`userId` varchar(36) NOT NULL,
`categoryId` varchar(36) NOT NULL,
`title` varchar(80) NOT NULL,
`filename` varchar(200) NOT NULL,
`description` varchar(300) NOT NULL,
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `category` (
`id` varchar(36) NOT NULL,
`description` varchar(200) NOT NULL,
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Indizes für die Tabelle `user`
--
ALTER TABLE `user`
ADD PRIMARY KEY (`id`),
ADD UNIQUE KEY `username` (`username`);
ALTER TABLE `category`
ADD PRIMARY KEY (`id`);
ALTER TABLE `gallery`
ADD PRIMARY KEY (`id`),
ADD CONSTRAINT `FK_EventUser` FOREIGN KEY (`userId`) REFERENCES `user`(`id`),
ADD CONSTRAINT `FK_EventCategory` FOREIGN KEY (`categoryId`) REFERENCES `category`(`id`);
--
-- Daten für Tabelle `user`
--
-- pw: 12345 -> $2y$10$IeMpvUuMIrnxFHN.j94tEe.T1rjsTga1yYoyt5JAAXYUwbbjh1km6
INSERT INTO `user` (`id`, `username`, `firstname`, `lastname`, `email`, `pw`, `created`) VALUES
('0bb28278-d28a-11e7-b93f-2c4d544f8fe0', 'stefan78', 'Stefan', 'Stativ',
'test@test.de', '$2y$10$IeMpvUuMIrnxFHN.j94tEe.T1rjsTga1yYoyt5JAAXYUwbbjh1km6', '2017-11-26 09:13:20'),
('4f141df7-3c0a-11e8-b046-2c4d544f8fe0', 'fiona84', 'Fiona', 'Filter',
'fiona@test.de', '$2y$10$IeMpvUuMIrnxFHN.j94tEe.T1rjsTga1yYoyt5JAAXYUwbbjh1km6', '2018-01-12 11:11:51');
INSERT INTO `category` (`id`, `description`, `created`) VALUES
('23911087-3420-11e8-be39-2c4d544f8fe0', 'Portrait', '2018-04-14 12:11:31'),
('4a952637-3422-11e8-be39-2c4d544f8fe0', 'Natur', '2018-04-14 12:11:31'),
('999e18d3-3420-11e8-be39-2c4d544f8fe0', 'Landschaft', '2018-04-14 12:11:31'),
('dc3a66d9-3c0a-11e8-b046-2c4d544f8fe0', 'Urban', '2018-04-14 12:11:31');
INSERT INTO `gallery`(`id`, `userId`, `categoryId`, `title`, `filename`, `description`, `created`) VALUES
('b164bc94-eaf1-11e7-a313-2c4d544f8fe0', '0bb28278-d28a-11e7-b93f-2c4d544f8fe0', '23911087-3420-11e8-be39-2c4d544f8fe0',
'Ich selbst', 'stefan78-001.jpeg', 'Foto eines jungen Mannes mit Kamera', '2018-04-14 12:11:31'),
('7519223c-3429-11e8-be39-2c4d544f8fe0', '0bb28278-d28a-11e7-b93f-2c4d544f8fe0', '23911087-3420-11e8-be39-2c4d544f8fe0'
, 'Licht', 'stefan78-003.jpeg', 'Foto einer jungen Frau bei Nacht', '2018-03-12 09:31:12'),
('d746f216-eaf1-11e7-a313-2c4d544f8fe0', '0bb28278-d28a-11e7-b93f-2c4d544f8fe0', '4a952637-3422-11e8-be39-2c4d544f8fe0'
, 'Flowers', 'stefan78-002.jpeg', 'Weiße und rote Blumen', '2018-03-12 09:33:32'),
('0ccef76b-3da0-11e8-9afe-2c4d544f8fe0', '4f141df7-3c0a-11e8-b046-2c4d544f8fe0', 'dc3a66d9-3c0a-11e8-b046-2c4d544f8fe0',
'Endlos', 'fiona84-001.jpeg', 'Eine spiralförmige Treppe', '2018-05-12 12:11:31'),
('61f52468-3da0-11e8-9afe-2c4d544f8fe0', '4f141df7-3c0a-11e8-b046-2c4d544f8fe0', '999e18d3-3420-11e8-be39-2c4d544f8fe0'
, 'Morgenrot', 'fiona84-002.jpeg', 'Sonnenaufgang am Strand', '2018-01-11 09:31:12'),
('68f78c36-3da0-11e8-9afe-2c4d544f8fe0', '4f141df7-3c0a-11e8-b046-2c4d544f8fe0', 'dc3a66d9-3c0a-11e8-b046-2c4d544f8fe0'
, 'Tiefe Wolken', 'fiona84-003.jpeg', 'Eine Brücke im Nebel', '2018-02-23 09:33:32');
-- -------------------------------------------------------
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

BIN
images/fiona84-001.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 242 KiB

BIN
images/fiona84-002.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 197 KiB

BIN
images/fiona84-003.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 266 KiB

BIN
images/fiona84-004.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 180 KiB

BIN
images/stefan78-001.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

BIN
images/stefan78-002.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 KiB

BIN
images/stefan78-003.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 252 KiB

BIN
images/stefan78-004.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 239 KiB

39
index.php Normal file
View File

@ -0,0 +1,39 @@
<?php
session_start();
spl_autoload_register(function ($className) {
if (substr($className, 0, 4) !== 'ppa\\') { return; }
$fileName = __DIR__.'/'.str_replace('\\', DIRECTORY_SEPARATOR, substr($className, 4)).'.php';
if (file_exists($fileName)) { include $fileName; }
});
$controllerName = "";
$doMethodName = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$controllerName = isset($_POST['controller']) && $_POST['controller'] ? $_POST['controller'] : "Welcome";
$doMethodName = isset($_POST['do']) && $_POST['do'] ? $_POST['do'] : "showWelcome";
} else {
$controllerName = isset($_GET['controller']) && $_GET['controller'] ? $_GET['controller'] : "Welcome";
$doMethodName = isset($_GET['do']) && $_GET['do'] ? $_GET['do'] : "showWelcome";
}
$controllerClassName = 'ppa\\Controller\\'.ucfirst($controllerName). 'Controller';
if (method_exists($controllerClassName, $doMethodName)) {
$view = new \ppa\Library\View(__DIR__.DIRECTORY_SEPARATOR.'Views'
, ucfirst($controllerName), $doMethodName);
$controller = new $controllerClassName($view);
$controller->$doMethodName();
$view->render();
} else {
http_response_code(404);
new \ppa\Library\ErrorMsg('Page not found: '.$controllerClassName.'::'.$doMethodName);
}
?>