Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SAE4-Développement d’une application complexe
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
KANY Thomas
SAE4-Développement d’une application complexe
Commits
675817f5
Commit
675817f5
authored
1 month ago
by
Thomas Kany
Browse files
Options
Downloads
Patches
Plain Diff
adaptation gestion document avec nvl archi
parent
74303478
No related branches found
No related tags found
1 merge request
!1
Merge Request - Développement vers Main (Draft)
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
php-app/files/pages/admin/document-insert.php
+3
-3
3 additions, 3 deletions
php-app/files/pages/admin/document-insert.php
php-app/files/pages/admin/document-update.php
+89
-80
89 additions, 80 deletions
php-app/files/pages/admin/document-update.php
with
92 additions
and
83 deletions
php-app/files/pages/admin/document-insert.php
+
3
−
3
View file @
675817f5
...
@@ -4,7 +4,7 @@ session_start();
...
@@ -4,7 +4,7 @@ session_start();
// Vérification de la connexion et du rôle admin
// Vérification de la connexion et du rôle admin
if
(
!
isset
(
$_SESSION
[
'user_id'
])
||
$_SESSION
[
'role'
]
!==
'admin'
)
{
if
(
!
isset
(
$_SESSION
[
'user_id'
])
||
$_SESSION
[
'role'
]
!==
'admin'
)
{
header
(
'Location: .
/../../connexion
/login.php'
);
header
(
'Location: .
.
/login.php'
);
exit
;
exit
;
}
}
...
@@ -37,7 +37,7 @@ try {
...
@@ -37,7 +37,7 @@ try {
}
}
// Création du dossier de stockage s'il n'existe pas
// Création du dossier de stockage s'il n'existe pas
$upload_dir
=
'uploads
/documents/'
;
$upload_dir
=
__DIR__
.
'/../storage
/documents/'
;
if
(
!
file_exists
(
$upload_dir
))
{
if
(
!
file_exists
(
$upload_dir
))
{
mkdir
(
$upload_dir
,
0777
,
true
);
mkdir
(
$upload_dir
,
0777
,
true
);
}
}
...
@@ -49,7 +49,7 @@ try {
...
@@ -49,7 +49,7 @@ try {
// Upload du fichier
// Upload du fichier
if
(
move_uploaded_file
(
$file
[
'tmp_name'
],
$filepath
))
{
if
(
move_uploaded_file
(
$file
[
'tmp_name'
],
$filepath
))
{
$stmt
=
$pdo
->
prepare
(
"INSERT INTO documents (user_id, nom_fichier, type_fichier, chemin_fichier, description) VALUES (?, ?, ?, ?, ?)"
);
$stmt
=
$pdo
->
prepare
(
"INSERT INTO documents (user_id, nom_fichier, type_fichier, chemin_fichier, description) VALUES (?, ?, ?, ?, ?)"
);
$stmt
->
execute
([
$user_id
,
$file
[
'name'
],
$file
[
'type'
],
$filename
,
$description
]);
$stmt
->
execute
([
$user_id
,
$file
[
'name'
],
$file
[
'type'
],
'documents/'
.
$filename
,
$description
]);
$success_message
=
"Document téléchargé avec succès!"
;
$success_message
=
"Document téléchargé avec succès!"
;
}
else
{
}
else
{
throw
new
Exception
(
"Erreur lors du téléchargement du fichier"
);
throw
new
Exception
(
"Erreur lors du téléchargement du fichier"
);
...
...
This diff is collapsed.
Click to expand it.
php-app/files/pages/admin/document-update.php
+
89
−
80
View file @
675817f5
...
@@ -4,7 +4,7 @@ session_start();
...
@@ -4,7 +4,7 @@ session_start();
// Vérification de la connexion et du rôle admin
// Vérification de la connexion et du rôle admin
if
(
!
isset
(
$_SESSION
[
'user_id'
])
||
$_SESSION
[
'role'
]
!==
'admin'
)
{
if
(
!
isset
(
$_SESSION
[
'user_id'
])
||
$_SESSION
[
'role'
]
!==
'admin'
)
{
header
(
'Location: .
/../../connexion
/login.php'
);
header
(
'Location: .
.
/login.php'
);
exit
;
exit
;
}
}
...
@@ -34,8 +34,7 @@ try {
...
@@ -34,8 +34,7 @@ try {
$stmt
=
$pdo
->
prepare
(
"UPDATE documents SET user_id = ?, description = ? WHERE id = ?"
);
$stmt
=
$pdo
->
prepare
(
"UPDATE documents SET user_id = ?, description = ? WHERE id = ?"
);
$stmt
->
execute
([
$user_id
,
$description
,
$document_id
]);
$stmt
->
execute
([
$user_id
,
$description
,
$document_id
]);
$success_message
=
"Document mis à jour avec succès!"
;
$success_message
=
"Document mis à jour avec succès!"
;
}
}
// Mise à jour avec nouveau fichier
// Mise à jour avec nouveau fichier
else
{
else
{
$file
=
$_FILES
[
'document'
];
$file
=
$_FILES
[
'document'
];
...
@@ -64,17 +63,24 @@ try {
...
@@ -64,17 +63,24 @@ try {
$stmt
=
$pdo
->
prepare
(
"UPDATE documents SET user_id = ?, nom_fichier = ?, type_fichier = ?, chemin_fichier = ?, description = ? WHERE id = ?"
);
$stmt
=
$pdo
->
prepare
(
"UPDATE documents SET user_id = ?, nom_fichier = ?, type_fichier = ?, chemin_fichier = ?, description = ? WHERE id = ?"
);
$stmt
->
execute
([
$user_id
,
$file
[
'name'
],
$file
[
'type'
],
$filename
,
$description
,
$document_id
]);
$stmt
->
execute
([
$user_id
,
$file
[
'name'
],
$file
[
'type'
],
$filename
,
$description
,
$document_id
]);
$success_message
=
"Document mis à jour avec succès!"
;
$success_message
=
"Document mis à jour avec succès!"
;
}
else
{
}
else
{
throw
new
Exception
(
"Erreur lors du téléchargement du fichier"
);
throw
new
Exception
(
"Erreur lors du téléchargement du fichier"
);
}
}
}
}
// Après modification, on recharge les infos du document
$stmt
=
$pdo
->
prepare
(
"SELECT * FROM documents WHERE id = ?"
);
$stmt
->
execute
([
$document_id
]);
$document
=
$stmt
->
fetch
();
}
}
// Liste des documents pour la sélection
// Liste des documents pour la sélection
$stmt
=
$pdo
->
query
(
"SELECT d.*, u.nom as nom_utilisateur FROM documents d JOIN utilisateurs u ON d.user_id = u.id ORDER BY date_upload DESC"
);
$stmt
=
$pdo
->
query
(
"SELECT d.*, u.nom as nom_utilisateur FROM documents d JOIN utilisateurs u ON d.user_id = u.id ORDER BY date_upload DESC"
);
$documents
=
$stmt
->
fetchAll
();
$documents
=
$stmt
->
fetchAll
();
}
catch
(
Exception
$e
)
{
}
catch
(
Exception
$e
)
{
$error
=
$e
->
getMessage
();
$error
=
$e
->
getMessage
();
}
}
?>
?>
...
@@ -89,84 +95,87 @@ try {
...
@@ -89,84 +95,87 @@ try {
</head>
</head>
<body
class=
"gest"
>
<body
class=
"gest"
>
<div
class=
"form-container"
>
<div
class=
"form-container"
>
<h1
class=
"title"
>
Modifier un Document
</h1>
<h1
class=
"title"
>
Modifier un Document
</h1>
<?php
if
(
$success_message
)
:
?>
<?php
if
(
$success_message
)
:
?>
<div
class=
"success-message"
>
<?php
echo
htmlspecialchars
(
$success_message
);
?>
</div>
<div
class=
"success-message"
>
<?php
echo
htmlspecialchars
(
$success_message
);
?>
</div>
<?php
endif
;
?>
<?php
endif
;
?>
<?php
if
(
$error
)
:
?>
<?php
if
(
$error
)
:
?>
<div
class=
"error-message"
>
<?php
echo
htmlspecialchars
(
$error
);
?>
</div>
<div
class=
"error-message"
>
<?php
echo
htmlspecialchars
(
$error
);
?>
</div>
<?php
endif
;
?>
<?php
endif
;
?>
<!-- Liste des documents -->
<!-- Liste des documents -->
<?php
if
(
!
isset
(
$_GET
[
'id'
]))
:
?>
<?php
if
(
!
isset
(
$_GET
[
'id'
]))
:
?>
<div
class=
"section"
>
<div
class=
"section"
>
<h2>
Sélectionner un document à modifier
</h2>
<h2>
Sélectionner un document à modifier
</h2>
<table
class=
"table"
>
<table
class=
"table"
>
<thead>
<thead>
<tr>
<th>
Nom du fichier
</th>
<th>
Membre
</th>
<th>
Date d'upload
</th>
<th>
Action
</th>
</tr>
</thead>
<tbody>
<?php
if
(
!
empty
(
$documents
))
:
?>
<?php
foreach
(
$documents
as
$doc
)
:
?>
<tr>
<tr>
<th>
Nom du fichier
</th>
<td>
<?php
echo
htmlspecialchars
(
$doc
[
'nom_fichier'
]);
?>
</td>
<th>
Membre
</th>
<td>
<?php
echo
htmlspecialchars
(
$doc
[
'nom_utilisateur'
]);
?>
</td>
<th>
Date d'upload
</th>
<td>
<?php
echo
date
(
'd/m/Y H:i'
,
strtotime
(
$doc
[
'date_upload'
]));
?>
</td>
<th>
Action
</th>
<td>
<a
href=
"?id=
<?php
echo
$doc
[
'id'
];
?>
"
class=
"menu-button"
>
Modifier
</a>
</td>
</tr>
</tr>
</thead>
<?php
endforeach
;
?>
<tbody>
<?php
else
:
?>
<?php
if
(
!
empty
(
$documents
))
:
?>
<tr>
<?php
foreach
(
$documents
as
$doc
)
:
?>
<td
colspan=
"4"
>
Aucun document disponible.
</td>
<tr>
</tr>
<td>
<?php
echo
htmlspecialchars
(
$doc
[
'nom_fichier'
]);
?>
</td>
<?php
endif
;
?>
<td>
<?php
echo
htmlspecialchars
(
$doc
[
'nom_utilisateur'
]);
?>
</td>
</tbody>
<td>
<?php
echo
date
(
'd/m/Y H:i'
,
strtotime
(
$doc
[
'date_upload'
]));
?>
</td>
</table>
<td>
</div>
<a
href=
"?id=
<?php
echo
$doc
[
'id'
];
?>
"
class=
"menu-button"
>
Modifier
</a>
<?php
endif
;
?>
</td>
</tr>
<!-- Formulaire de modification -->
<?php
endforeach
;
?>
<?php
if
(
isset
(
$document
))
:
?>
<?php
else
:
?>
<form
method=
"POST"
enctype=
"multipart/form-data"
class=
"section"
>
<tr><td
colspan=
"4"
>
Aucun document disponible.
</td></tr>
<input
type=
"hidden"
name=
"document_id"
value=
"
<?php
echo
$document
[
'id'
];
?>
"
>
<?php
endif
;
?>
</tbody>
<div>
</table>
<label>
Membre:
</label>
<select
name=
"user_id"
class=
"form-input"
required
>
<?php
foreach
(
$membres
as
$membre
)
:
?>
<option
value=
"
<?php
echo
$membre
[
'id'
];
?>
"
<?php
echo
(
$membre
[
'id'
]
==
$document
[
'user_id'
])
?
'selected'
:
''
;
?>
>
<?php
echo
htmlspecialchars
(
$membre
[
'nom'
]
.
' ('
.
$membre
[
'email'
]
.
')'
);
?>
</option>
<?php
endforeach
;
?>
</select>
</div>
</div>
<?php
endif
;
?>
<div>
<!-- Formulaire de modification -->
<label>
Document actuel:
</label>
<?php
if
(
isset
(
$document
))
:
?>
<p>
<?php
echo
htmlspecialchars
(
$document
[
'nom_fichier'
]);
?>
</p>
<form
method=
"POST"
enctype=
"multipart/form-data"
class=
"section"
>
<input
type=
"file"
name=
"document"
class=
"form-input"
>
<input
type=
"hidden"
name=
"document_id"
value=
"
<?php
echo
$document
[
'id'
];
?>
"
>
<small>
Laissez vide pour conserver le fichier actuel. Types acceptés : PDF, JPEG, PNG, DOC, DOCX
</small>
</div>
<div>
<label>
Membre:
</label>
<div>
<select
name=
"user_id"
class=
"form-input"
required
>
<label>
Description:
</label>
<?php
foreach
(
$membres
as
$membre
)
:
?>
<textarea
name=
"description"
class=
"form-input"
<option
value=
"
<?php
echo
$membre
[
'id'
];
?>
"
<?php
echo
(
$membre
[
'id'
]
==
$document
[
'user_id'
])
?
'selected'
:
''
;
?>
>
rows=
"4"
>
<?php
echo
htmlspecialchars
(
$document
[
'description'
]);
?>
</textarea>
<?php
echo
htmlspecialchars
(
$membre
[
'nom'
]
.
' ('
.
$membre
[
'email'
]
.
')'
);
?>
</div>
</option>
<?php
endforeach
;
?>
<button
type=
"submit"
name=
"update"
class=
"menu-button"
>
Mettre à jour
</button>
</select>
<a
href=
"document-update.php"
class=
"menu-button"
>
Retour à la liste
</a>
</div>
</form>
<?php
endif
;
?>
<div>
<label>
Document actuel:
</label>
<a
href=
"dashboard.php"
class=
"menu-button"
>
Retour au Dashboard
</a>
<p>
<?php
echo
htmlspecialchars
(
$document
[
'nom_fichier'
]);
?>
</p>
</div>
<input
type=
"file"
name=
"document"
class=
"form-input"
>
<small>
Laissez vide pour conserver le fichier actuel. Types acceptés : PDF, JPEG, PNG, DOC, DOCX
</small>
</div>
<div>
<label>
Description:
</label>
<textarea
name=
"description"
class=
"form-input"
rows=
"4"
>
<?php
echo
htmlspecialchars
(
$document
[
'description'
]);
?>
</textarea>
</div>
<button
type=
"submit"
name=
"update"
class=
"menu-button"
>
Mettre à jour
</button>
<a
href=
"document-update.php"
class=
"menu-button"
>
Retour à la liste
</a>
</form>
<?php
endif
;
?>
<a
href=
"dashboard.php"
class=
"menu-button"
>
Retour au Dashboard
</a>
</div>
</body>
</body>
</html>
</html>
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