project list admin + delete project
This commit is contained in:
parent
cdf0c2fe67
commit
a254373b68
|
@ -17,6 +17,11 @@ if (isset($_SESSION['user'], $_SESSION['password'])) {
|
||||||
header('Location: index.php');
|
header('Location: index.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($_POST['delete'])) {
|
||||||
|
$id = $_POST['delete'];
|
||||||
|
|
||||||
|
deleteProject($id);
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($_POST['project-name'], $_POST['description-project'])) {
|
if (isset($_POST['project-name'], $_POST['description-project'])) {
|
||||||
$projectName = trim($_POST['project-name']);
|
$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">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<link rel="stylesheet" href="style.css" />
|
<link rel="stylesheet" href="../style.css" />
|
||||||
<title>
|
<title>
|
||||||
Mon super portfolio
|
Mon super portfolio
|
||||||
</title>
|
</title>
|
||||||
|
@ -71,6 +96,47 @@ if (isset($_POST['project-name'], $_POST['description-project'])) {
|
||||||
|
|
||||||
<h3>Liste des projets</h3>
|
<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>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,6 @@ if (isset($_POST['user'], $_POST['password'])) {
|
||||||
login($user, $password);
|
login($user, $password);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE HTML>
|
<!DOCTYPE HTML>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
@ -33,14 +32,13 @@ if (isset($_POST['user'], $_POST['password'])) {
|
||||||
</title>
|
</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<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">
|
<form action="" method="POST">
|
||||||
<label for="user">User :</label>
|
<label for="user">User :</label>
|
||||||
<input type="text" id="user" name="user"/>
|
<input type="text" id="user" name="user"/>
|
||||||
<label for="password">password :</label>
|
<label for="password">password :</label>
|
||||||
<input type="password" id="password" name="password"/>
|
<input type="password" id="password" name="password"/>
|
||||||
|
|
||||||
<input type="submit" value="go go go"/>
|
<input type="submit" value="go go go"/>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
* @param int $limit Nombre de projets par page
|
* @param int $limit Nombre de projets par page
|
||||||
* @return array Les projets
|
* @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)) {
|
if (!is_integer($page)) {
|
||||||
throw new InvalidArgumentException('The argument "page" must be an integer.');
|
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
|
* @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