init Abgabe

This commit is contained in:
WummerMIB
2025-12-04 23:37:05 +01:00
parent dda70db0be
commit 4db823c14a
534 changed files with 72693 additions and 0 deletions
+11
View File
@@ -0,0 +1,11 @@
# --------- REWRITE Regeln ---------
RewriteEngine On
RewriteBase /projekte/htdocs/
# Wenn Datei oder Verzeichnis existiert → direkt laden
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Alles andere → index.php weiterleiten
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
+70
View File
@@ -0,0 +1,70 @@
const ws = new WebSocket('ws://localhost:8080');
ws.onopen = () => {
console.log('WebSocket verbunden');
ws.send(JSON.stringify({ type: 'init', userId: currentUserId }));
};
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
if (data.type === 'new_message') {
// Wenn Chat offen für den Sender
if (currentChatUserId === data.senderId) {
addMessage(data.message, 'left'); // links = empfänger
} else {
// Badge hochzählen
const badge = document.getElementById(`contact-badge-${data.senderId}`);
badge.style.display = 'inline-block';
badge.textContent = parseInt(badge.textContent || 0) + 1;
}
}
};
// Kontakt anklicken
document.querySelectorAll('.contact').forEach(contact => {
contact.addEventListener('click', () => {
const userId = parseInt(contact.dataset.userid);
currentChatUserId = userId;
// Badge zurücksetzen
const badge = document.getElementById(`contact-badge-${userId}`);
badge.style.display = 'none';
badge.textContent = '0';
// Chatfenster leeren
document.getElementById('chat-window').innerHTML = '';
// Option: Alte Nachrichten vom Server laden (via AJAX)
});
});
// Formular senden
document.getElementById('chat-form').addEventListener('submit', (e) => {
e.preventDefault();
const input = document.getElementById('chat-input');
const message = input.value.trim();
if (!message || !currentChatUserId) return;
ws.send(JSON.stringify({
type: 'message',
senderId: currentUserId,
receiverId: currentChatUserId,
message: message
}));
addMessage(message, 'right'); // rechts = aktuell eigener User
input.value = '';
});
// Nachrichten hinzufügen
function addMessage(text, side) {
const chatWindow = document.getElementById('chat-window');
const msgDiv = document.createElement('div');
msgDiv.className = side === 'right' ? 'text-right mb-2' : 'text-left mb-2';
msgDiv.innerHTML = `<span class="inline-block px-3 py-2 rounded ${side==='right'?'bg-blue-500 text-white':'bg-gray-300 text-black'} break-words">${text}</span>`;
chatWindow.appendChild(msgDiv);
chatWindow.scrollTop = chatWindow.scrollHeight;
}
+79
View File
@@ -0,0 +1,79 @@
<?php
require_once("../config/config.php");
require_once("../libs/Database.php");
require_once("../libs/Factory.php");
require_once("../libs/Model.php");
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
// ================= AUTLOADER =================
spl_autoload_register(function ($class) {
$paths = [
__DIR__ . '/../controller/' . $class . '.php',
__DIR__ . '/../model/' . $class . '.php',
__DIR__ . '/../view/' . $class . '.php'
];
foreach ($paths as $file) {
if (file_exists($file)) {
require_once $file;
return;
}
}
});
// ================= ROUTING =================
$url = $_GET['url'] ?? '';
$url = trim($url, '/');
$parts = explode('/', $url);
// --- Controller oder Datei bestimmen ---
$controllerBase = !empty($parts[0]) ? $parts[0] : 'Home'; // Default Home
$method = !empty($parts[1]) ? $parts[1] : 'index';
// Prüfen: existiert Datei im Controller-Ordner?
$controllerFile = __DIR__ . '/../controller/' . $controllerBase . '.php';
try {
if (file_exists($controllerFile)) {
// Datei existiert → einbinden
require_once $controllerFile;
// Prüfen, ob Klasse existiert
if (class_exists($controllerBase)) {
$controller = new $controllerBase();
} else {
// Falls Klasse nicht existiert → anonymes Objekt
$controller = new class {
public function __call($name, $args) {
throw new Exception("Methode '$name' nicht gefunden.");
}
};
}
// Prüfen, ob Methode existiert
if (!method_exists($controller, $method)) {
throw new Exception("Methode '$method' nicht gefunden");
}
// Methode ausführen
$controller->$method();
} else {
// Datei existiert nicht → ErrorController
throw new Exception("Controller-Datei '$controllerBase.php' nicht gefunden");
}
} catch (Exception $e) {
// ================= ERROR FALLBACK =================
if (class_exists('ErrorController')) {
$error = new ErrorController();
$error->index($e->getMessage());
} else {
echo "Fehler: " . $e->getMessage();
}
}