création_projet

This commit is contained in:
Logshiro
2025-10-10 09:02:47 +02:00
commit ef0b0bda5d
19 changed files with 589 additions and 0 deletions

6
_base/base et user.sql Normal file
View File

@@ -0,0 +1,6 @@
create database contrib;
create user contrib_root@'%' identified by '123abc';
grant all on contrib.* to contrib_root@'%';

105
_base/data.sql Normal file
View File

@@ -0,0 +1,105 @@
-- Attention : version mots de passe non chiffrés
INSERT INTO membre (id, nom, password, droit) VALUES
('M001', 'Alice','123','admin'),
('M002', 'Bob','123','dev'),
('M003', 'Charlie','123','dev'),
('M004', 'David','123','dev'),
('M005', 'Eve','123','dev'),
('M006', 'Frank','123','dev'),
('M007', 'Gina','123','dev'),
('M008', 'Harry','123','dev');
-- Insertion des projets
INSERT INTO projet (id, nom) VALUES
('P001', 'Projet A'),
('P002', 'Projet B'),
('P003', 'Projet C'),
('P004', 'Projet D'),
('P005', 'Projet E'),
('P006', 'Projet F'),
('P007', 'Projet G');
-- Insertion des contributions (exemples)
INSERT INTO contribution (membre_id, projet_id, duree) VALUES
('M001', 'P001', 10),
('M002', 'P002', 15),
('M003', 'P003', 8),
('M004', 'P001', 5),
('M005', 'P002', 20),
('M006', 'P004', 12),
('M007', 'P005', 25),
('M008', 'P006', 18),
('M001', 'P003', 7),
('M002', 'P004', 9),
('M003', 'P005', 11),
('M004', 'P006', 6),
('M005', 'P007', 14),
('M006', 'P001', 3),
('M007', 'P002', 17),
('M008', 'P003', 10);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M005', 'P005', 6);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M004', 'P005', 24);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M004', 'P002', 9);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M008', 'P004', 13);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M008', 'P007', 17);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M008', 'P005', 6);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M005', 'P005', 13);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M003', 'P004', 13);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M001', 'P005', 13);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M004', 'P005', 4);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M001', 'P001', 8);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M003', 'P002', 18);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M003', 'P002', 22);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M007', 'P003', 15);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M003', 'P001', 7);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M003', 'P005', 4);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M002', 'P005', 17);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M001', 'P004', 22);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M006', 'P006', 12);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M006', 'P005', 6);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M003', 'P006', 16);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M002', 'P002', 10);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M007', 'P007', 17);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M003', 'P001', 8);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M004', 'P003', 20);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M003', 'P007', 8);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M002', 'P001', 17);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M004', 'P007', 22);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M002', 'P005', 25);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M006', 'P006', 20);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M003', 'P006', 22);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M006', 'P001', 18);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M006', 'P001', 8);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M004', 'P004', 22);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M005', 'P005', 14);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M002', 'P005', 22);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M001', 'P004', 3);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M001', 'P003', 25);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M004', 'P006', 24);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M005', 'P006', 6);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M004', 'P003', 23);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M003', 'P004', 1);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M001', 'P002', 5);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M005', 'P002', 14);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M004', 'P004', 7);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M004', 'P007', 17);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M003', 'P007', 24);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M005', 'P005', 15);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M008', 'P005', 10);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M007', 'P002', 19);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M006', 'P005', 23);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M006', 'P002', 15);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M006', 'P003', 13);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M008', 'P005', 8);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M008', 'P005', 18);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M002', 'P005', 11);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M007', 'P003', 4);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M004', 'P006', 19);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M002', 'P007', 2);
INSERT INTO contribution (membre_id, projet_id, duree) VALUES ('M003', 'P006', 13);

20
_base/structure.sql Normal file
View File

@@ -0,0 +1,20 @@
create table membre(
id varchar(20) primary key,
nom varchar(50) not null,
-- login => le champ id sera le login
password varchar(100) not null,
droit varchar(50) default 'dev'
);
create table projet(
id varchar(20) primary key,
nom varchar(50) not null
);
create table contribution(
id int auto_increment primary key,
membre_id varchar(20) not null references membre(id),
projet_id varchar(20) not null references projet(id),
duree int default 0
);

6
css/bootstrap.min.css vendored Normal file

File diff suppressed because one or more lines are too long

10
css/styles.css Normal file
View File

@@ -0,0 +1,10 @@
#formLogin{
background-color: rgb(232, 238, 239);
border:1px solid darkcyan;
border-radius: 10px;
padding: 15px;
}
td a {
color: white !important;;
}

3
debugSession.php Normal file
View File

@@ -0,0 +1,3 @@
<?php
session_start();
var_dump($_SESSION);

36
index.php Normal file
View File

@@ -0,0 +1,36 @@
<?php
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/styles.css" rel="stylesheet">
<title>Connexion</title>
</head>
<body class="container">
<div class="row justify-content-center">
<div class="col-md-4">
<form id="formLogin" action="traitements/traiterAuthentification.php" method="post">
<h3 class="text-center">Identifiez-vous</h3>
<div class="form-group">
<label for="id">Login :</label><br>
<input type="text" name="login" id="id" class="form-control">
</div>
<div class="form-group">
<label for="mdp">Pass :</label><br>
<input type="password" name="pass" id="mdp" class="form-control">
</div>
<br>
<div class="form-group text-end">
<input type="submit" name="submit" class="btn btn-primary btn-md" value="Valider">
</div>
</form>
</div>
</div>
</body>
</html>

7
js/bootstrap.bundle.min.js vendored Normal file

File diff suppressed because one or more lines are too long

14
pages/accueil.php Normal file
View File

@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link href="../css/bootstrap.min.css" rel="stylesheet">
<script src="../js/bootstrap.bundle.min.js"></script>
</head>
<body class="container">
<?php include "../utils_inc/inc_navbar.php"; ?>
<h1>Hello et bienvenue, co OK.</h1>
</body>
</html>

61
pages/gestionMembres.php Normal file
View File

@@ -0,0 +1,61 @@
<?php
session_start();
require_once "../utils_inc/inc_pdo.php";
if (!isset($_SESSION["droit"])){
// pas connecté : retour au formulaire de connexion
header("location:../index.php");
exit();
}
if ($_SESSION["droit"]!="admin"){
header("location:../pages/accueil.php");
exit();
}
// Si on arrive là, c'est qu'on a le droit d'y être !
$textReq = "select * from membre ";
$req = $pdo->prepare($textReq);
$req->execute();
$tabRes = $req->fetchAll(PDO::FETCH_ASSOC);
//var_dump($tabRes);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<link href="../css/bootstrap.min.css" rel="stylesheet">
<link href="../css/styles.css" rel="stylesheet">
<script src="../js/bootstrap.bundle.min.js"></script>
</head>
<body class="container">
<?php include "../utils_inc/inc_navbar.php"; ?>
<table class="table table-striped">
<thead>
<tr>
<th>id </th>
<th>nom </th>
<th>droit </th>
<th>contribs</th>
<th>suppr</th>
</tr>
</thead>
<tbody>
<?php
foreach($tabRes as $uneLigne){
echo "<tr>";
echo " <th>".$uneLigne["id"]."</th>";
echo " <td>".$uneLigne["nom"]."</td>";
echo " <td>".$uneLigne["droit"]."</td>";
echo " <td><a href='../pages/listeContribsMembre.php?id=".$uneLigne["id"]."'><button class='btn btn-info'>voir</a></td>";
echo " <td><a href='#'><button class='btn btn-danger'>X</a></td>";
echo "</tr>";
}
?>
</tbody>
</table>
</body>
</html>

68
pages/listeContribs.php Normal file
View File

@@ -0,0 +1,68 @@
<?php
session_start();
// Liste de TOUTES les contributions (tous les membres)
// Juste pour l'admin
require_once "../utils_inc/inc_pdo.php";
if (!isset($_SESSION["droit"])){
// pas connecté : retour au formulaire de connexion
header("location:formCo.php");
exit();
}
if ($_SESSION["droit"]!="admin"){
// droits insuffisants : connexion à refaire ou message
// "moins gentil"
header("location:formCo.php");
exit();
}
// Si on arrive là, c'est qu'on a le droit d'y être !
$textReq = "select contribution.id as numero, membre.nom as nom_membre, projet.nom as nom_projet, duree ";
$textReq.= "from membre inner join contribution on membre.id = contribution.membre_id ";
$textReq.= " inner join projet on contribution.projet_id = projet.id ";
$textReq.= "order by membre.nom, nom_projet ";
$req = $pdo->prepare($textReq);
$req->execute();
$tabRes = $req->fetchAll(PDO::FETCH_ASSOC);
//var_dump($tabRes);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<link href="../css/bootstrap.min.css" rel="stylesheet">
<script src="../js/bootstrap.bundle.min.js"></script>
</head>
<body class="container">
<?php include "../utils_inc/inc_navbar.php"; ?>
<table class="table table-striped">
<thead>
<tr>
<th>Numéro </th>
<th>Membre </th>
<th>Projet </th>
<th>Durée </th>
</tr>
</thead>
<tbody>
<?php
foreach($tabRes as $uneLigne){
echo "<tr>";
echo " <th>".$uneLigne["numero"]."</th>";
echo " <td>".$uneLigne["nom_membre"]."</td>";
echo " <td>".$uneLigne["nom_projet"]."</td>";
echo " <td>".$uneLigne["duree"]."</td>";
echo "</tr>";
}
?>
</tbody>
</table>
</body>
</html>

View File

@@ -0,0 +1,89 @@
<?php
session_start();
require_once "../utils_inc/inc_pdo.php";
$idM = $_GET["id"]; // id du membre pour lequel on veut afficher la liste
if (!isset($_SESSION["droit"])){
// pas connecté : retour au formulaire de connexion
header("location:formCo.php");
exit();
}
// accès possible si : admin ou (dev et "ce sont mes contribs")
if ( !(($_SESSION["droit"]=="admin") || ($_SESSION["droit"]=="dev" && $_SESSION["login"]==$idM)) ){
die("Droits insuffisants");
}
// Si on arrive ici, c'est que nos droits sont suffisants
$textReq = "select contribution.id as numero, membre.nom as nom_membre, projet.nom as nom_projet, duree ";
$textReq.= "from membre inner join contribution on membre.id = contribution.membre_id ";
$textReq.= " inner join projet on contribution.projet_id = projet.id ";
$textReq.= "where membre.id = :id_m ";
$textReq.= "order by membre.nom, nom_projet ";
$req = $pdo->prepare($textReq);
$req->bindParam(":id_m",$idM); // protection contre injections SQL
$req->execute();
$tabRes = $req->fetchAll(PDO::FETCH_ASSOC);
//---------------------------------------------------------
$reqProjet = $pdo->prepare("select * from projet");
$reqProjet->execute();
$tabProjets = $reqProjet->fetchAll(PDO::FETCH_ASSOC);
//var_dump($tabRes);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<link href="../css/bootstrap.min.css" rel="stylesheet">
<script src="../js/bootstrap.bundle.min.js"></script>
</head>
<body class="container">
<?php include "../utils_inc/inc_navbar.php"; ?>
<table class="table table-striped">
<thead>
<tr>
<th>Numéro </th>
<th>Membre </th>
<th>Projet </th>
<th>Durée </th>
</tr>
</thead>
<tbody>
<?php
foreach($tabRes as $uneLigne){
echo "<tr>";
echo " <th>".$uneLigne["numero"]."</th>";
echo " <td>".$uneLigne["nom_membre"]."</td>";
echo " <td>".$uneLigne["nom_projet"]."</td>";
echo " <td>".$uneLigne["duree"]."</td>";
echo "</tr>";
}
?>
</tbody>
</table>
<form action="../traitements/insererContrib.php" method="get">
<input name="idMembre" hidden value='<?php echo $idM; ?>'>
<label>Projet</label>
<select name="idProjet">
<?php
foreach ($tabProjets as $projet){
echo "<option value='".$projet['id']."'>".$projet['nom']."</option>";
}
?>
</select>
<label>Durée</label>
<input name="duree" type="number">
<input type="submit">
</form>
</body>
</html>

View File

@@ -0,0 +1,79 @@
<?php
session_start();
// Exécutable si :
// admin ou (dev et "je suis le bon utilisateur")
if (!isset($_SESSION['droit'])){
die("Connexion obligatoire.");
}
if ( !( ($_SESSION['droit']=='admin') ||
($_SESSION['droit']=='dev' && $_SESSION['login']==$idM) ) ){
die("Accès interdit");
}
// Exemple insertion :
// .../insererContrib.php?idMembre=M001&idProjet=P001&duree=56
// Récupère membre_id, projet_id, durée en $_GET
// include include_once : si fichier pas trouvé, pas d'erreur
// require require_once : si fichier pas trouvé, erreur et arrêt
// => once : php vérifie que l'inclusion n'est faite qu'une fois
require_once "../utils_inc/inc_pdo.php";
$idM = $_GET["idMembre"];
$idP = $_GET["idProjet"];
$dudu = $_GET["duree"];
$texteRequete = "insert into contribution (membre_id, projet_id, duree) ";
$texteRequete.= " values(:mId, :pId, :du) ";
$req = $pdo->prepare($texteRequete);
$req->bindParam(":mId",$idM);
$req->bindParam(":pId",$idP);
$req->bindParam(":du" ,$dudu);
$req->execute();
// header : prépare une redirection
// qui devient effective à la fin de l'exécution
header("location:../pages/listeContribsMembre.php?id=".$idM);
// exit(); // pour que la redirection soit immédiate
// appeler un script php pour l'exécuter en lui transmettant des paramètres dans l'url
// Créer un formulaire, utiliser action, method, name, utiliser des champs cachés (hidden)
// Utiliser pdo pour :
// - se connecter à une base
// - faire une requête simple (non paramétrée)
// - faire une requête paramétrée (bind)
// Extraire les données retournées par une requête et les "traiter"(foreach)
// => comprendre la communication client-serveur (qui fait quoi ?)

9
traitements/logout.php Normal file
View File

@@ -0,0 +1,9 @@
<?php
session_start();
// Choix de déconnexion : on supprime les champs de session liés à la connexion
unset($_SESSION['droit']);
unset($_SESSION['login']);
// retour au form de connexion
header("location:../index.php");

View File

@@ -0,0 +1,43 @@
<?php
session_start();
require_once "../utils_inc/inc_pdo.php"; // $pdo existe ici désormais
// http://localhost/contribs/traiterAuthentification.php?login=M001&pass=123
// Recevoir les données du form de login, et vérifier login/pass dans la base
// En version finale : envoi en $_POST obligatoire. Pour le dev $_GET peut être plus pratique.
$login = $_POST["login"];
$pass = $_POST["pass"];
// Vérification dans la base si le mot de passe et le login se trouvent dans la base
// VERSION mot de passe chiffré
$textR = "select droit, password ";
$textR.= "from membre ";
$textR.= "where id=:login ";
$req = $pdo->prepare($textR);
$req->bindParam(":login", $login);
$req->execute();
// 2 possibilités : 1 ligne retournée ou 0 ligne retournée
$tabRes = $req->fetchAll(PDO::FETCH_ASSOC);
if (count($tabRes)!=1) {
// pas trouvé => retour au formulaire de co
// die("Erreur de co");
header("Location:../index.php?message=tekitoa");
exit();
}
// Si on arrive là : login existe (count==1)
if (!password_verify($pass, $tabRes[0]["password"])){
// die("Erreur de co");
header("Location:../index.php?message=tekitoa");
exit();
}
$_SESSION["login"] = $login;
$_SESSION["droit"] = $tabRes[0]["droit"];
// redirection vers accueil, éventuellement spécifique à l'utilisateur
header("Location:../pages/accueil.php");
// pas besoin d'exit pour déclencher la redirection, puisque fin de script

View File

@@ -0,0 +1 @@
deny from all

0
utils_inc/inc_head.php Normal file
View File

29
utils_inc/inc_navbar.php Normal file
View File

@@ -0,0 +1,29 @@
<?php // tirée de https://getbootstrap.com/docs/5.2/components/navbar/ ?>
<nav class="navbar navbar-expand-lg bg-light">
<div class="container-fluid">
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="../pages/accueil.php">Accueil</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Contributions
</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="../pages/listeContribs.php">Voir toutes</a></li>
<li><a class="dropdown-item" href="#">Nada</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#">Nothing</a></li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link " href="../pages/gestionMembres.php">Membres</a>
</li>
</ul>
<div class="d-flex">
<a href="../traitements/logout.php"><button class="btn btn-outline-success">Logout</button></a>
</div>
</div>
</div>
</nav>

3
utils_inc/inc_pdo.php Normal file
View File

@@ -0,0 +1,3 @@
<?php
$pdo = new PDO('mysql:host=mysqlsrv;dbname=contribC', "contribA_root", "123abc");