Ich hatte das mal für 123marvin123: Marvin entwickelt, da ich gerade das Laptop einwenig aufräume und das ins Papierkorb landen wird,
teile ich es hier mal. Es ist nützlich wenn man vieles zu erledigen hat. Ich nutze es bspw. für meine Kunden, die schreiben dann dort ihre Wünsche und
ich kann mir das dort dann alles immer abhaken.
Snippet
PHP
<?php
/*
* @author Caglar
* @twitter Caglar2306
*/
$_CFG = [
'MySQL:HOST' => '127.0.0.1',
'MySQL:USER' => 'root',
'MySQL:PASS' => '123456',
'MySQL:DATA' => 'aufgaben',
'SYS:DEBUG' => true,
'SITE:TITLE' => 'Aufgaben'
];
$_TEXTS = [
'Falsche Zugangsdaten',
'Willkommen',
'Ausloggen',
'Aufgabe',
'Hinzufügen',
'Speichern',
'Benutzername',
'Passwort',
'Einloggen'
];
@set_time_limit(0);
@ini_set('display_errors', $_CFG['SYS:DEBUG']);
@ini_set('memory_limit', -1);
@date_default_timezone_set('Europe/Berlin');
if($_CFG['SYS:DEBUG']) error_reporting(E_ALL);
if(session_status() == PHP_SESSION_NONE) session_start();
$Connection;
try {
$Connection = new PDO("mysql:host={$_CFG['MySQL:HOST']};dbname={$_CFG['MySQL:DATA']};charset=utf8", $_CFG['MySQL:USER'], $_CFG['MySQL:PASS']);
$Connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$Connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$Connection->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8mb4' COLLATE 'utf8mb4_unicode_ci'");
$Connection->exec('set names utf8');
mb_internal_encoding('UTF-8');
} catch(PDOException $ex) {
die($ex->getMessage());
exit();
}
if(isset($_GET['logout'])) {
session_destroy();
header('Location: index.php');
}
function isLoggedIn() {
if(isset($_SESSION['USER:ID'])) {
return true;
}
return false;
}
if(!isLoggedIn()) {
if(isset($_POST['login'])) {
if(isset($_POST['username']) && isset($_POST['password'])) {
$sth = $Connection->prepare('SELECT `id` FROM `users` WHERE `username` = :username AND `password` = :password LIMIT 1');
$sth->execute(array(':username' => $_POST['username'], ':password' => $_POST['password']));
if($sth->rowCount()) {
$obj = $sth->fetch(PDO::FETCH_OBJ);
$_SESSION['USER:ID'] = $obj->id;
header('Location: index.php');
} else {
$message = $_TEXTS[0];
}
}
}
} else {
if(isset($_POST['add'])) {
if(isset($_POST['task'])) {
if(strlen($_POST['task'])) {
$category = 1;
if(isset($_POST['category'])) {
$sth = $Connection->prepare('SELECT `id` FROM `categories` WHERE `id` = :category LIMIT 1');
$sth->execute(array(':category' => $_POST['category']));
if($sth->rowCount()) {
$obj = $sth->fetch(PDO::FETCH_OBJ);
$category = $obj->id;
}
}
add($_POST['task'], $category);
}
}
header('Location: index.php');
}
if(isset($_POST['save'])) {
if(isset($_POST['tasks']) && is_array($_POST['tasks'])) {
$sth = $Connection->query("UPDATE `tasks` SET `done` = '0'");
foreach($_POST['tasks'] as $task) {
$sth = $Connection->prepare("UPDATE `tasks` SET `done` = '1' WHERE `id` = :id LIMIT 1");
$sth->execute(array(':id' => $task));
}
header('Location: index.php');
}
}
}
function add($task, $category, $time = null) {
global $Connection;
if(!$time) $time = time();
if(!isLoggedIn()) return;
$sth = $Connection->prepare('INSERT INTO `tasks` (task, category, timestamp) VALUES (:task, :category, :timestamp);');
$sth->execute(array(':task' => $task, ':category' => $category, ':timestamp' => time()));
}
function get($field, $userid = null) {
global $Connection;
if(!$userid)
if(isLoggedIn()) $userid = $_SESSION['USER:ID'];
$sth = $Connection->prepare("SELECT `{$field}` FROM `users` WHERE `id` = :userid LIMIT 1");
$sth->execute(array(':userid' => $_SESSION['USER:ID']));
if($sth->rowCount()) {
$obj = $sth->fetch(PDO::FETCH_ASSOC);
return $obj[$field];
}
return null;
}
function ifisset(&$var, $default = null) {
return isset($var) ? $var : $default;
}
?>
Alles anzeigen