add project
This commit is contained in:
parent
9f11673c3a
commit
cdf0c2fe67
|
@ -1,6 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
|
require '../lib/database.php';
|
||||||
|
require '../lib/project.php';
|
||||||
|
|
||||||
if(isset($_POST["disconect"])) {
|
if(isset($_POST["disconect"])) {
|
||||||
$_SESSION = array();
|
$_SESSION = array();
|
||||||
session_destroy();
|
session_destroy();
|
||||||
|
@ -14,6 +17,24 @@ if (isset($_SESSION['user'], $_SESSION['password'])) {
|
||||||
header('Location: index.php');
|
header('Location: index.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (isset($_POST['project-name'], $_POST['description-project'])) {
|
||||||
|
$projectName = trim($_POST['project-name']);
|
||||||
|
$projectDescription = trim($_POST['description-project']);
|
||||||
|
|
||||||
|
$valid = true;
|
||||||
|
|
||||||
|
foreach ([$projectName, $projectDescription] as $field) {
|
||||||
|
if (empty($field)) {
|
||||||
|
$valid = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($valid) {
|
||||||
|
createProject($projectName, $projectDescription, new DateTime('now'));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,12 +51,26 @@ if (isset($_SESSION['user'], $_SESSION['password'])) {
|
||||||
<h1>Administration</h1>
|
<h1>Administration</h1>
|
||||||
<p>Bonjour <span style="font-weight: bold"><?php echo $prout ?></span></p>
|
<p>Bonjour <span style="font-weight: bold"><?php echo $prout ?></span></p>
|
||||||
|
|
||||||
|
|
||||||
<form action="" method="POST">
|
<form action="" method="POST">
|
||||||
<input type="hidden" name="disconect" value="disconect"/>
|
<input type="hidden" name="disconect" value="disconect"/>
|
||||||
<input type="submit" value="CIAO"/>
|
<input type="submit" value="CIAO"/>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<h2>Gestion des projets</h2>
|
||||||
|
|
||||||
|
<p style="font-weight: bold;">Ajouter un projet sans mettre d'image parce que c'est trop long est chiant à faire</p>
|
||||||
|
|
||||||
|
<form action="" method="post">
|
||||||
|
<label for="project-name">Nom du projet</label>
|
||||||
|
<input style="display: block;" type="text" name="project-name" id="project-name"/>
|
||||||
|
<label for="description-project">Description du projet</label>
|
||||||
|
<textarea name="description-project" id="description-project" style="display: block;"></textarea>
|
||||||
|
|
||||||
|
<input type="submit" value="Ajouter"/>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<h3>Liste des projets</h3>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
|
|
@ -64,6 +64,31 @@ function getProject($id)
|
||||||
return $query->fetch();
|
return $query->fetch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enregistre un nouveau projet
|
||||||
|
*
|
||||||
|
* @param string $name Nom du projet
|
||||||
|
* @param string $description description du projet
|
||||||
|
*/
|
||||||
|
function createProject($name, $description, DateTime $date)
|
||||||
|
{
|
||||||
|
$pdo = getDatabaseConnection();
|
||||||
|
|
||||||
|
$query = $pdo->prepare(
|
||||||
|
'insert into project(title, illustration, description, date)
|
||||||
|
value(:title, :illustration, :description, :date)'
|
||||||
|
);
|
||||||
|
|
||||||
|
$illustration = "Craypions005.jpg";
|
||||||
|
|
||||||
|
$query->execute([
|
||||||
|
':title' => $name,
|
||||||
|
':illustration' => $illustration,
|
||||||
|
':description' => $description,
|
||||||
|
':date' => $date->format('Y-m-d H:i:s'),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $maxPerPage Nombre de projets par page
|
* @param int $maxPerPage Nombre de projets par page
|
||||||
* @return int Le nombre de pages
|
* @return int Le nombre de pages
|
||||||
|
|
Loading…
Reference in a new issue