Skip to content
Snippets Groups Projects
Commit 398df4b3 authored by Hakan EBABIL's avatar Hakan EBABIL
Browse files

premier commit

parents
Branches
No related merge requests found
/vendor/
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?php
session_start();
$pdo = new \PDO('mysql:host=127.0.0.1;port=3306;dbname=architecture_web_tp1;charset=utf8;', 'root', 'root');
if (isset($_GET['logout'])) {
$_SESSION['user_id'] = null;
}
function estConnecte()
{
return $_SESSION['user_id'] != null;
}
$erreurConnexion = null;
if (isset($_POST['connexion'])) {
$requete = 'select * from users where email = "'.$_POST['email'].'"';
$data = $pdo->query($requete)->fetch();
if (!$data) {
$erreurConnexion = 'Utilisateur non trouvé';
} else if ($data['password'] != $_POST['password']) {
$erreurConnexion = 'Mot de passe invalide';
} else {
$_SESSION['user_id'] = $data['id'];
}
}
$erreurCreation = null;
if (isset($_POST['commenter'])) {
$insert = $pdo->exec('Insert into comments (task_id, created_by, created_at, comment) values ('.$_POST['todo_id'].', '.$_SESSION['user_id'].', NOW(), "'.$_POST['comment'].'")');
if (!$insert) {
$erreurCreation = 'Erreur lors de l\'ajout du commentaire.';
}
}
if (isset($_POST['ajouter'])) {
$insert = $pdo->exec('Insert into todos (created_by, created_at, title, description) values ('.$_SESSION['user_id'].', NOW(), "'.$_POST['title'].'", "'.$_POST['description'].'" )');
if (!$insert) {
$erreurCreation = 'Erreur lors de l\'ajout de la tâche.';
}
}
if (!estConnecte()) {
?>
<html>
<body>
<h1>Connectez vous pour accéder à la todo list !</h1>
<?php if (!empty($erreurConnexion)) { ?>
<p style="color: red"><?= $erreurConnexion; ?></p>
<?php } ?>
<form method="post" action="index.php">
<p><label>Votre email&nbsp;:</label><input type="text" name="email" /></p>
<p><label>Votre mot de passe&nbsp;:</label><input type="password" name="password" /></p>
<p></p><input type="submit" name="connexion" value="Se connecter" /></p>
</form>
</body>
</html>
<?php
} else {
?>
<html>
<body>
<h1>Todo list partagée</h1>
<?php if (!empty($erreurCreation)) { ?>
<p style="font-weight: bold; color: red;"><?= $erreurCreation; ?></p>
<?php } ?>
<ul>
<?php
foreach ($pdo->query('select todos.*, writer.email as writer_email from todos left join users writer on todos.created_by = writer.id order by todos.id desc')->fetchAll() as $todo) { ?>
<li><a href="#" data-purpose="link-todo" data-todo-id="<?= $todo['id'] ?>"><?= $todo['title'] ?></a>
<div style="display: none" data-purpose="description-todo" data-todo-id="<?= $todo['id'] ?>">
<p>Créé par <?= $todo['writer_email']; ?> le <?= $todo['created_at']; ?></p>
<p style="text-decoration: underline">Commentaires :</p>
<ul style="list-style-type: none">
<?php foreach ($pdo->query('select comments.*, writer.email as writer_email from comments left join users writer on comments.created_by = writer.id where task_id = '.$todo['id'])->fetchAll() as $comment) { ?>
<li style="border: 1px solid #ddd; margin: 10px; padding: 10px">
<?= $comment['comment']; ?><br />
Posté le <?= $comment['created_at']; ?> par <?= $comment['writer_email']; ?>
</li>
<?php
}?>
</ul>
<div style="display: block; margin-left: 50px">
<form method="post" action="index.php" name="addComment">
<p></p><input type="hidden" name="todo_id" value="<?= $todo['id']; ?>" /></p>
<p></p><textarea name="comment" style="width: calc(100% - 10px)"></textarea></p>
<input type="submit" name="commenter" value="Ajouter un commentaire" />
</form>
</div>
</div>
</li>
<?php
}
?>
</ul>
<h2>Ajouter une tâche</h2>
<form method="post" action="index.php">
<p><label>Titre&nbsp;:</label><input type="text" name="title" /></p>
<p><label>Description&nbsp;:</label><textarea name="description"></textarea></p>
<input type="submit" name="ajouter" value="Ajouter une tâche" />
</form>
<p><a href="index.php?logout">Se déconnecter</a></p>
</body>
<script
src="https://code.jquery.com/jquery-3.4.1.js"
integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU="
crossorigin="anonymous"></script>
<script>
$('[data-purpose="link-todo"]').click(function (event) {
event.preventDefault();
var todoId = $(event.currentTarget).attr('data-todo-id');
var todoDesc = $('[data-purpose="description-todo"][data-todo-id="'+todoId+'"]');
todoDesc.toggle();
});
</script>
</html>
<?php
}
\ No newline at end of file
{
"name": "hakan/architecture_web_tp1",
"type": "project",
"authors": [
{
"name": "Hakan EBABIL",
"email": "enseignement@ebabil.fr"
}
],
"require": {}
}
# ************************************************************
# Sequel Pro SQL dump
# Version 4541
#
# http://www.sequelpro.com/
# https://github.com/sequelpro/sequelpro
#
# Hôte: 127.0.0.1 (MySQL 5.7.25)
# Base de données: architecture_web_tp1
# Temps de génération: 2019-08-11 14:34:03 +0000
# ************************************************************
/*!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 utf8 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
# Affichage de la table comments
# ------------------------------------------------------------
DROP TABLE IF EXISTS `comments`;
CREATE TABLE `comments` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`task_id` int(11) unsigned NOT NULL,
`created_by` int(11) unsigned NOT NULL,
`created_at` datetime NOT NULL,
`comment` text NOT NULL,
PRIMARY KEY (`id`),
KEY `task_id` (`task_id`),
KEY `created_by` (`created_by`),
CONSTRAINT `comments_ibfk_1` FOREIGN KEY (`task_id`) REFERENCES `todos` (`id`) ON DELETE CASCADE,
CONSTRAINT `comments_ibfk_2` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
LOCK TABLES `comments` WRITE;
/*!40000 ALTER TABLE `comments` DISABLE KEYS */;
INSERT INTO `comments` (`id`, `task_id`, `created_by`, `created_at`, `comment`)
VALUES
(1,1,2,'2019-08-11 16:33:15','Je pense qu\'il manque l\'architecture Héxagonale'),
(2,1,1,'2019-08-11 16:33:51','Ce sera dans le prochain cours');
/*!40000 ALTER TABLE `comments` ENABLE KEYS */;
UNLOCK TABLES;
# Affichage de la table todos
# ------------------------------------------------------------
DROP TABLE IF EXISTS `todos`;
CREATE TABLE `todos` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`created_by` int(11) unsigned NOT NULL,
`assigned_to` int(11) unsigned DEFAULT NULL,
`title` varchar(255) NOT NULL DEFAULT '',
`description` text NOT NULL,
`created_at` datetime NOT NULL,
`due_date` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `created_by` (`created_by`),
KEY `assigned_to` (`assigned_to`),
CONSTRAINT `todos_ibfk_1` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
CONSTRAINT `todos_ibfk_2` FOREIGN KEY (`assigned_to`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
LOCK TABLES `todos` WRITE;
/*!40000 ALTER TABLE `todos` DISABLE KEYS */;
INSERT INTO `todos` (`id`, `created_by`, `assigned_to`, `title`, `description`, `created_at`, `due_date`)
VALUES
(1,1,NULL,'Développer le premier TP','Faire la présentation de l\'architecture MVC','2019-08-11 16:32:16','2019-09-09 16:32:20');
/*!40000 ALTER TABLE `todos` ENABLE KEYS */;
UNLOCK TABLES;
# Affichage de la table users
# ------------------------------------------------------------
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`email` varchar(255) NOT NULL DEFAULT '',
`password` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
LOCK TABLES `users` WRITE;
/*!40000 ALTER TABLE `users` DISABLE KEYS */;
INSERT INTO `users` (`id`, `email`, `password`)
VALUES
(1,'hakan@ebabil.fr','tartenpion'),
(2,'john@doe.com','johnny');
/*!40000 ALTER TABLE `users` ENABLE KEYS */;
UNLOCK TABLES;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!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 */;
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment