project list admin + delete project

This commit is contained in:
Lex 2016-03-11 16:46:09 +01:00
parent cdf0c2fe67
commit a254373b68
3 changed files with 87 additions and 5 deletions

View file

@ -17,6 +17,11 @@ if (isset($_SESSION['user'], $_SESSION['password'])) {
header('Location: index.php');
}
if (isset($_POST['delete'])) {
$id = $_POST['delete'];
deleteProject($id);
}
if (isset($_POST['project-name'], $_POST['description-project'])) {
$projectName = trim($_POST['project-name']);
@ -35,6 +40,26 @@ if (isset($_POST['project-name'], $_POST['description-project'])) {
}
}
$limit = 15;
$numberOfPages = getProjectNumberOfPages($limit);
if (isset($_GET['page'])) {
$page = (int) $_GET['page'];
} else {
$page = 1;
}
if ($page > $numberOfPages) {
$page = 1;
}
$projects = getProjects($page, $limit);
$pager = getProjectsPager($page, $numberOfPages);
$prev = $page - 1;
$next = $page + 1;
?>
@ -42,7 +67,7 @@ if (isset($_POST['project-name'], $_POST['description-project'])) {
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css" />
<link rel="stylesheet" href="../style.css" />
<title>
Mon super portfolio
</title>
@ -71,6 +96,47 @@ if (isset($_POST['project-name'], $_POST['description-project'])) {
<h3>Liste des projets</h3>
<section style="width: 640px;">
<?php foreach($projects as $project): ?>
<article>
<h2><?php echo $project['title'] ?></h2>
<figure>
<img src="../images/<?php echo $project['illustration'] ?>" alt="" width="130px" />
</figure>
<p class="description" style="text-overflow: ellipsis;white-space: nowrap;overflow: hidden;">
<?php echo $project['description'] ?>
</p>
<?php $date = new DateTime($project['date']); ?>
<form action="" method="post">
<input type="hidden" name="delete" value="<?php echo $project['id'] ?>"/>
<input type="submit" value="Supprimer"/>
</form>
<p class="date">
<time datetime="<?php echo $date->format(DateTime::W3C) ?>">
<?php echo $date->format('d/m/Y') ?>
</time>
</p>
</article>
<?php endforeach ?>
</section>
<?php if (count($pager) > 1): ?>
<ul class="pager">
<?php foreach ($pager as $p): ?>
<li <?php if ($p['current'] === true): ?>class="active"<?php endif ?>>
<a href="?page=<?php echo $p['page'] ?>">
<?php echo $p['title'] ?>
</a>
</li>
<?php endforeach ?>
</ul>
<?php endif ?>
</body>
</html>

View file

@ -21,7 +21,6 @@ if (isset($_POST['user'], $_POST['password'])) {
login($user, $password);
}
}
?>
<!DOCTYPE HTML>
<html lang="en">
@ -33,14 +32,13 @@ if (isset($_POST['user'], $_POST['password'])) {
</title>
</head>
<body>
<h1>Ici, c'est l'administration, c'est ici qu'on trouve toute l'administration.</h1>
<h1 style="font-family: 'Arial', sans-serif;">Ici, c'est l'administration, c'est ici qu'on trouve toute l'administration.</h1>
<form action="" method="POST">
<label for="user">User :</label>
<input type="text" id="user" name="user"/>
<label for="password">password :</label>
<input type="password" id="password" name="password"/>
<input type="submit" value="go go go"/>
</form>

View file

@ -7,7 +7,7 @@
* @param int $limit Nombre de projets par page
* @return array Les projets
*/
function getProjects($page = 1, $limit = 5, $orderBy = 'date', $orderBySens = 'ASC')
function getProjects($page = 1, $limit = 5, $orderBy = 'id', $orderBySens = 'DESC')
{
if (!is_integer($page)) {
throw new InvalidArgumentException('The argument "page" must be an integer.');
@ -89,6 +89,24 @@ function createProject($name, $description, DateTime $date)
]);
}
/**
* Supprime un nouveau projet
*
* @param string $id id du projet
*/
function deleteProject($id)
{
$pdo = getDatabaseConnection();
$query = $pdo->prepare(
'DELETE FROM project WHERE id=:id'
);
$query->execute([
':id' => $id
]);
}
/**
* @param int $maxPerPage Nombre de projets par page
* @return int Le nombre de pages