Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SAE4
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MATEJKA Milan
SAE4
Commits
98bdd8f5
Commit
98bdd8f5
authored
1 month ago
by
VoidOma
Browse files
Options
Downloads
Patches
Plain Diff
admin membres + detail
parent
24e3c687
No related branches found
No related tags found
1 merge request
!1
MergeRequest_1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
code_source/web_app/public/admin_membre_details.php
+81
-57
81 additions, 57 deletions
code_source/web_app/public/admin_membre_details.php
code_source/web_app/public/admin_membres.php
+49
-40
49 additions, 40 deletions
code_source/web_app/public/admin_membres.php
with
130 additions
and
97 deletions
code_source/web_app/public/admin_membre_details.php
+
81
−
57
View file @
98bdd8f5
...
...
@@ -9,13 +9,18 @@ if (!isset($_SESSION['user']) || $_SESSION['user']['statut'] !== 'ADMINISTRATEUR
exit
;
}
// Vérifier si l'ID est passé en paramètre
if
(
!
isset
(
$_GET
[
'id'
]))
{
echo
"<p>ID du membre manquant.</p>"
;
exit
;
// Protection CSRF
if
(
!
isset
(
$_SESSION
[
'csrf_token'
]))
{
$_SESSION
[
'csrf_token'
]
=
bin2hex
(
random_bytes
(
32
));
}
$csrf_token
=
$_SESSION
[
'csrf_token'
];
$membreId
=
$_GET
[
'id'
];
// Récupérer et valider l'ID du membre
$membreId
=
filter_input
(
INPUT_GET
,
'id'
,
FILTER_VALIDATE_INT
);
if
(
!
$membreId
)
{
echo
"<p>ID du membre manquant ou invalide.</p>"
;
exit
;
}
// Récupérer les informations du membre
$sql
=
"SELECT nom, prenom, email, telephone, adresse, ville, code_postal, pays, statut
...
...
@@ -23,58 +28,69 @@ $sql = "SELECT nom, prenom, email, telephone, adresse, ville, code_postal, pays,
WHERE idMembre = :id"
;
$stmt
=
$pdo
->
prepare
(
$sql
);
$stmt
->
execute
([
':id'
=>
$membreId
]);
$membre
=
$stmt
->
fetch
();
$membre
=
$stmt
->
fetch
(
PDO
::
FETCH_ASSOC
);
if
(
!
$membre
)
{
echo
"<p>Membre introuvable.</p>"
;
exit
;
}
// Traitement de la modification
if
(
$_SERVER
[
'REQUEST_METHOD'
]
===
'POST'
&&
isset
(
$_POST
[
'action'
]))
{
if
(
$_POST
[
'action'
]
===
'modifier'
)
{
// Modifier les informations du membre
$nom
=
$_POST
[
'nom'
];
$prenom
=
$_POST
[
'prenom'
];
$email
=
$_POST
[
'email'
];
$statut
=
$_POST
[
'statut'
];
// Si le membre est adhérent, inclure les champs supplémentaires
$telephone
=
$statut
===
'ADHERENT'
?
$_POST
[
'telephone'
]
:
null
;
$adresse
=
$statut
===
'ADHERENT'
?
$_POST
[
'adresse'
]
:
null
;
$ville
=
$statut
===
'ADHERENT'
?
$_POST
[
'ville'
]
:
null
;
$code_postal
=
$statut
===
'ADHERENT'
?
$_POST
[
'code_postal'
]
:
null
;
$pays
=
$statut
===
'ADHERENT'
?
$_POST
[
'pays'
]
:
null
;
$sql
=
"UPDATE membre
SET nom = :nom, prenom = :prenom, email = :email,
statut = :statut, telephone = :telephone, adresse = :adresse,
ville = :ville, code_postal = :code_postal, pays = :pays
WHERE idMembre = :id"
;
$stmt
=
$pdo
->
prepare
(
$sql
);
$stmt
->
execute
([
':nom'
=>
$nom
,
':prenom'
=>
$prenom
,
':email'
=>
$email
,
':statut'
=>
$statut
,
':telephone'
=>
$telephone
,
':adresse'
=>
$adresse
,
':ville'
=>
$ville
,
':code_postal'
=>
$code_postal
,
':pays'
=>
$pays
,
':id'
=>
$membreId
]);
echo
"<p class='success'>Les informations du membre ont été mises à jour avec succès.</p>"
;
header
(
"Location: admin_membre_details.php?id=
$membreId
"
);
// Traitement du formulaire
if
(
$_SERVER
[
'REQUEST_METHOD'
]
===
'POST'
&&
isset
(
$_POST
[
'action'
],
$_POST
[
'csrf_token'
]))
{
if
(
!
hash_equals
(
$_SESSION
[
'csrf_token'
],
$_POST
[
'csrf_token'
]))
{
echo
"<p class='error'>Requête invalide (token CSRF incorrect).</p>"
;
exit
;
}
elseif
(
$_POST
[
'action'
]
===
'supprimer'
)
{
// Supprimer le membre
$sql
=
"DELETE FROM membre WHERE idMembre = :id"
;
$stmt
=
$pdo
->
prepare
(
$sql
);
}
$action
=
$_POST
[
'action'
];
if
(
$action
===
'modifier'
)
{
// Nettoyage et validation
$nom
=
trim
(
$_POST
[
'nom'
]);
$prenom
=
trim
(
$_POST
[
'prenom'
]);
$email
=
filter_var
(
$_POST
[
'email'
],
FILTER_VALIDATE_EMAIL
);
$statut
=
in_array
(
$_POST
[
'statut'
],
[
'NORMAL'
,
'ADHERENT'
,
'ADMINISTRATEUR'
])
?
$_POST
[
'statut'
]
:
'NORMAL'
;
if
(
!
$email
)
{
echo
"<p class='error'>Email invalide.</p>"
;
}
else
{
$telephone
=
$adresse
=
$ville
=
$code_postal
=
$pays
=
null
;
if
(
$statut
===
'ADHERENT'
)
{
$telephone
=
trim
(
$_POST
[
'telephone'
]);
$adresse
=
trim
(
$_POST
[
'adresse'
]);
$ville
=
trim
(
$_POST
[
'ville'
]);
$code_postal
=
trim
(
$_POST
[
'code_postal'
]);
$pays
=
trim
(
$_POST
[
'pays'
]);
}
$sql
=
"UPDATE membre
SET nom = :nom, prenom = :prenom, email = :email,
statut = :statut, telephone = :telephone, adresse = :adresse,
ville = :ville, code_postal = :code_postal, pays = :pays
WHERE idMembre = :id"
;
$stmt
=
$pdo
->
prepare
(
$sql
);
$stmt
->
execute
([
':nom'
=>
$nom
,
':prenom'
=>
$prenom
,
':email'
=>
$email
,
':statut'
=>
$statut
,
':telephone'
=>
$telephone
,
':adresse'
=>
$adresse
,
':ville'
=>
$ville
,
':code_postal'
=>
$code_postal
,
':pays'
=>
$pays
,
':id'
=>
$membreId
]);
header
(
"Location: admin_membre_details.php?id="
.
urlencode
(
$membreId
));
exit
;
}
}
elseif
(
$action
===
'supprimer'
)
{
// Suppression sécurisée
$stmt
=
$pdo
->
prepare
(
"DELETE FROM membre WHERE idMembre = :id"
);
$stmt
->
execute
([
':id'
=>
$membreId
]);
echo
"<p class='success'>Le membre a été supprimé avec succès.</p>"
;
header
(
"Location: admin_membres.php"
);
exit
;
}
...
...
@@ -84,6 +100,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
<div
class=
"admin-section"
>
<h2>
Détails du membre
</h2>
<form
method=
"POST"
>
<input
type=
"hidden"
name=
"csrf_token"
value=
"
<?=
htmlspecialchars
(
$csrf_token
)
?>
"
>
<label
for=
"nom"
>
Nom :
</label>
<input
type=
"text"
id=
"nom"
name=
"nom"
value=
"
<?=
htmlspecialchars
(
$membre
[
'nom'
])
?>
"
required
>
...
...
@@ -94,28 +112,28 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
<input
type=
"email"
id=
"email"
name=
"email"
value=
"
<?=
htmlspecialchars
(
$membre
[
'email'
])
?>
"
required
>
<label
for=
"statut"
>
Statut :
</label>
<select
id=
"statut"
name=
"statut"
>
<select
id=
"statut"
name=
"statut"
onchange=
"toggleAdherentFields(this.value)"
>
<option
value=
"NORMAL"
<?=
$membre
[
'statut'
]
===
'NORMAL'
?
'selected'
:
''
?>
>
Normal
</option>
<option
value=
"ADHERENT"
<?=
$membre
[
'statut'
]
===
'ADHERENT'
?
'selected'
:
''
?>
>
Adhérent
</option>
<option
value=
"ADMINISTRATEUR"
<?=
$membre
[
'statut'
]
===
'ADMINISTRATEUR'
?
'selected'
:
''
?>
>
Administrateur
</option>
</select>
<
?php
if
(
$membre
[
'statut'
]
===
'ADHERENT'
)
:
?>
<
div
id=
"adherentFields"
style=
"
<?=
$membre
[
'statut'
]
===
'ADHERENT'
?
''
:
'display:none;'
?>
"
>
<label
for=
"telephone"
>
Téléphone :
</label>
<input
type=
"text"
id=
"telephone"
name=
"telephone"
value=
"
<?=
htmlspecialchars
(
$membre
[
'telephone'
]
)
?>
"
required
>
<input
type=
"text"
id=
"telephone"
name=
"telephone"
value=
"
<?=
htmlspecialchars
(
$membre
[
'telephone'
]
??
''
)
?>
"
>
<label
for=
"adresse"
>
Adresse :
</label>
<textarea
id=
"adresse"
name=
"adresse"
required
>
<?=
htmlspecialchars
(
$membre
[
'adresse'
])
?>
</textarea>
<textarea
id=
"adresse"
name=
"adresse"
>
<?=
htmlspecialchars
(
$membre
[
'adresse'
]
??
''
)
?>
</textarea>
<label
for=
"ville"
>
Ville :
</label>
<input
type=
"text"
id=
"ville"
name=
"ville"
value=
"
<?=
htmlspecialchars
(
$membre
[
'ville'
]
)
?>
"
required
>
<input
type=
"text"
id=
"ville"
name=
"ville"
value=
"
<?=
htmlspecialchars
(
$membre
[
'ville'
]
??
''
)
?>
"
>
<label
for=
"code_postal"
>
Code postal :
</label>
<input
type=
"text"
id=
"code_postal"
name=
"code_postal"
value=
"
<?=
htmlspecialchars
(
$membre
[
'code_postal'
]
)
?>
"
required
>
<input
type=
"text"
id=
"code_postal"
name=
"code_postal"
value=
"
<?=
htmlspecialchars
(
$membre
[
'code_postal'
]
??
''
)
?>
"
>
<label
for=
"pays"
>
Pays :
</label>
<input
type=
"text"
id=
"pays"
name=
"pays"
value=
"
<?=
htmlspecialchars
(
$membre
[
'pays'
]
)
?>
"
required
>
<
?php
endif
;
?
>
<input
type=
"text"
id=
"pays"
name=
"pays"
value=
"
<?=
htmlspecialchars
(
$membre
[
'pays'
]
??
''
)
?>
"
>
<
/div
>
<div
class=
"btn-group"
>
<button
type=
"submit"
name=
"action"
value=
"modifier"
class=
"btn2 btn2-success"
>
Enregistrer les modifications
</button>
...
...
@@ -123,5 +141,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
</div>
</form>
</div>
</main>
</main>
<script>
function
toggleAdherentFields
(
statut
)
{
const
fields
=
document
.
getElementById
(
'
adherentFields
'
);
fields
.
style
.
display
=
(
statut
===
'
ADHERENT
'
)
?
'
block
'
:
'
none
'
;
}
</script>
<?php
include
'../includes/footer.php'
;
?>
This diff is collapsed.
Click to expand it.
code_source/web_app/public/admin_membres.php
+
49
−
40
View file @
98bdd8f5
...
...
@@ -4,57 +4,66 @@ require_once '../includes/header.php';
require_once
'../includes/navbar.php'
;
// Vérifier si l'utilisateur est administrateur
if
(
!
isset
(
$_SESSION
[
'user'
])
||
$_SESSION
[
'user'
][
'statut'
]
!==
'ADMINISTRATEUR'
)
{
if
(
!
isset
(
$_SESSION
[
'user'
])
||
(
$_SESSION
[
'user'
][
'statut'
]
??
''
)
!==
'ADMINISTRATEUR'
)
{
echo
"<p>Accès refusé. Cette page est réservée aux administrateurs.</p>"
;
exit
;
}
//
Déterminer les critères d
e tri
//
Liste blanche des colonnes autorisées pour l
e tri
$validSortColumns
=
[
'nom'
,
'date_inscription'
,
'statut'
];
$sortColumn
=
isset
(
$_GET
[
'sort'
])
&&
in_array
(
$_GET
[
'sort'
],
$validSortColumns
)
?
$_GET
[
'sort'
]
:
'date_inscription'
;
$sortOrder
=
isset
(
$_GET
[
'order'
])
&&
strtolower
(
$_GET
[
'order'
])
===
'asc'
?
'ASC'
:
'DESC'
;
// Protection contre injection SQL via les paramètres GET
$sortColumn
=
in_array
(
$_GET
[
'sort'
]
??
''
,
$validSortColumns
)
?
$_GET
[
'sort'
]
:
'date_inscription'
;
$sortOrder
=
(
strtolower
(
$_GET
[
'order'
]
??
''
)
===
'asc'
)
?
'ASC'
:
'DESC'
;
$nextOrder
=
(
$sortOrder
===
'ASC'
)
?
'desc'
:
'asc'
;
// Récupérer la liste des membres
$sql
=
"SELECT idMembre, nom, prenom, email, statut, date_inscription
FROM membre
WHERE statut != 'FICTIF'
ORDER BY
$sortColumn
$sortOrder
"
;
$stmt
=
$pdo
->
query
(
$sql
);
$membres
=
$stmt
->
fetchAll
();
try
{
// Préparation sécurisée de la requête (avec vérification manuelle de la colonne triée)
$sql
=
"SELECT idMembre, nom, prenom, email, statut, date_inscription
FROM membre
WHERE statut != 'FICTIF'
ORDER BY
$sortColumn
$sortOrder
"
;
$stmt
=
$pdo
->
query
(
$sql
);
$membres
=
$stmt
->
fetchAll
();
}
catch
(
PDOException
$e
)
{
echo
"<p>Erreur lors de la récupération des membres : "
.
htmlspecialchars
(
$e
->
getMessage
())
.
"</p>"
;
exit
;
}
?>
<main
class=
"content-wrapper"
>
<div
class=
"admin-section"
>
<h2>
Liste des membres
</h2>
<table>
<thead>
<tr>
<th><a
href=
"?sort=nom&order=
<?=
$nextOrder
?>
"
>
Nom
</a></th>
<th>
Email
</th>
<th><a
href=
"?sort=statut&order=
<?=
$nextOrder
?>
"
>
Statut
</a></th>
<th><a
href=
"?sort=date_inscription&order=
<?=
$nextOrder
?>
"
>
Date d'inscription
</a></th>
<th>
Action
</th>
</tr>
</thead>
<tbody>
<?php
foreach
(
$membres
as
$membre
)
:
?>
<div
class=
"admin-section"
>
<h2>
Liste des membres
</h2>
<table>
<thead>
<tr>
<td>
<?=
htmlspecialchars
(
$membre
[
'nom'
]
.
' '
.
$membre
[
'prenom'
])
?>
</td>
<td>
<?=
htmlspecialchars
(
$membre
[
'email'
])
?>
</td>
<td>
<?=
htmlspecialchars
(
$membre
[
'statut'
])
?>
</td>
<td>
<?=
htmlspecialchars
(
$membre
[
'date_inscription'
])
?>
</td>
<td>
<a
href=
"admin_membre_details.php?id=
<?=
$membre
[
'idMembre'
]
?>
"
class=
"btn2"
>
Infos
</a>
<form
method=
"POST"
action=
"admin_membre_delete.php"
style=
"display:inline;"
>
<input
type=
"hidden"
name=
"id"
value=
"
<?=
$membre
[
'idMembre'
]
?>
"
>
</form>
</td>
<th><a
href=
"?sort=nom&order=
<?=
$nextOrder
?>
"
>
Nom
</a></th>
<th>
Email
</th>
<th><a
href=
"?sort=statut&order=
<?=
$nextOrder
?>
"
>
Statut
</a></th>
<th><a
href=
"?sort=date_inscription&order=
<?=
$nextOrder
?>
"
>
Date d'inscription
</a></th>
<th>
Action
</th>
</tr>
<?php
endforeach
;
?>
</tbody>
</table>
</div>
</thead>
<tbody>
<?php
foreach
(
$membres
as
$membre
)
:
?>
<tr>
<td>
<?=
htmlspecialchars
(
$membre
[
'nom'
]
.
' '
.
$membre
[
'prenom'
])
?>
</td>
<td>
<?=
htmlspecialchars
(
$membre
[
'email'
])
?>
</td>
<td>
<?=
htmlspecialchars
(
$membre
[
'statut'
])
?>
</td>
<td>
<?=
htmlspecialchars
(
$membre
[
'date_inscription'
])
?>
</td>
<td>
<a
href=
"admin_membre_details.php?id=
<?=
urlencode
(
$membre
[
'idMembre'
])
?>
"
class=
"btn2"
>
Infos
</a>
<form
method=
"POST"
action=
"admin_membre_delete.php"
style=
"display:inline;"
onsubmit=
"return confirm('Confirmer la suppression de ce membre ?');"
>
<input
type=
"hidden"
name=
"id"
value=
"
<?=
htmlspecialchars
(
$membre
[
'idMembre'
])
?>
"
>
<button
type=
"submit"
class=
"btn2 btn-danger"
>
Supprimer
</button>
</form>
</td>
</tr>
<?php
endforeach
;
?>
</tbody>
</table>
</div>
</main>
<?php
include
'../includes/footer.php'
;
?>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment