Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tutorat
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ZHANG David
tutorat
Commits
653e90e6
Commit
653e90e6
authored
5 months ago
by
ZHANG David
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
512ab208
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
code/manage_sessions.php
+144
-0
144 additions, 0 deletions
code/manage_sessions.php
with
144 additions
and
0 deletions
code/manage_sessions.php
0 → 100644
+
144
−
0
View file @
653e90e6
<?php
ini_set
(
'display_errors'
,
1
);
ini_set
(
'display_startup_errors'
,
1
);
error_reporting
(
E_ALL
);
include
'config.php'
;
session_start
();
if
(
!
isset
(
$_SESSION
[
'user'
])
||
$_SESSION
[
'user'
][
'role'
]
!==
'tutor'
)
{
header
(
'Location: login.php'
);
exit
;
}
$user
=
$_SESSION
[
'user'
];
// Supprimer une session si une requête POST est envoyée
if
(
$_SERVER
[
'REQUEST_METHOD'
]
===
'POST'
)
{
if
(
isset
(
$_POST
[
'delete_session_id'
]))
{
$session_id
=
$conn
->
real_escape_string
(
$_POST
[
'delete_session_id'
]);
// Supprimer les étudiants liés à cette session
$delete_students
=
$conn
->
prepare
(
"DELETE FROM SessionStudent WHERE session_id = ?"
);
$delete_students
->
bind_param
(
"i"
,
$session_id
);
$delete_students
->
execute
();
// Supprimer la session elle-même
$delete_session
=
$conn
->
prepare
(
"DELETE FROM Session WHERE id = ?"
);
$delete_session
->
bind_param
(
"i"
,
$session_id
);
if
(
$delete_session
->
execute
())
{
$success
=
"Session deleted successfully!"
;
}
else
{
$error
=
"Error deleting session: "
.
$conn
->
error
;
}
$delete_students
->
close
();
$delete_session
->
close
();
}
if
(
isset
(
$_POST
[
'update_status_session_id'
]))
{
$session_id
=
$conn
->
real_escape_string
(
$_POST
[
'update_status_session_id'
]);
$new_status
=
$conn
->
real_escape_string
(
$_POST
[
'new_status'
]);
// Mettre à jour l'état de la session
$update_status
=
$conn
->
prepare
(
"UPDATE Session SET status = ? WHERE id = ?"
);
$update_status
->
bind_param
(
"si"
,
$new_status
,
$session_id
);
if
(
$update_status
->
execute
())
{
$success
=
"Session status updated successfully!"
;
}
else
{
$error
=
"Error updating session status: "
.
$conn
->
error
;
}
$update_status
->
close
();
}
}
// Récupérer les sessions du tuteur avec le nombre d'étudiants inscrits et l'état
$sessions
=
[];
$sql
=
"
SELECT s.id, s.subject, s.start_time, s.end_time, s.status,
COUNT(ss.student_id) AS student_count
FROM Session s
LEFT JOIN SessionStudent ss ON s.id = ss.session_id
WHERE s.tutor_id = ?
GROUP BY s.id, s.subject, s.start_time, s.end_time, s.status
"
;
$stmt
=
$conn
->
prepare
(
$sql
);
$stmt
->
bind_param
(
"i"
,
$_SESSION
[
'user'
][
'id'
]);
$stmt
->
execute
();
$result
=
$stmt
->
get_result
();
while
(
$row
=
$result
->
fetch_assoc
())
{
$sessions
[]
=
$row
;
}
$stmt
->
close
();
?>
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<meta
charset=
"UTF-8"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
>
<title>
Manage Sessions
</title>
<link
rel=
"stylesheet"
href=
"style.css"
>
</head>
<body>
<?php
include
'sidebar.php'
;
?>
<div
class=
"main-content"
>
<div
class=
"manage-sessions-page"
>
<h1>
Manage Your Sessions
</h1>
<?php
if
(
isset
(
$success
))
:
?>
<p
class=
"success"
>
<?=
htmlspecialchars
(
$success
)
?>
</p>
<?php
endif
;
?>
<?php
if
(
isset
(
$error
))
:
?>
<p
class=
"error"
>
<?=
htmlspecialchars
(
$error
)
?>
</p>
<?php
endif
;
?>
<?php
if
(
!
empty
(
$sessions
))
:
?>
<table>
<thead>
<tr>
<th>
Subject
</th>
<th>
Start Time
</th>
<th>
End Time
</th>
<th>
Number of Students
</th>
<th>
Status
</th>
<th>
Change Status
</th>
<th>
Actions
</th>
</tr>
</thead>
<tbody>
<?php
foreach
(
$sessions
as
$session
)
:
?>
<tr>
<td>
<?=
htmlspecialchars
(
$session
[
'subject'
])
?>
</td>
<td>
<?=
htmlspecialchars
(
date
(
'd/m/Y H:i'
,
strtotime
(
$session
[
'start_time'
])))
?>
</td>
<td>
<?=
htmlspecialchars
(
date
(
'H:i'
,
strtotime
(
$session
[
'end_time'
])))
?>
</td>
<td>
<?=
htmlspecialchars
(
$session
[
'student_count'
])
?>
</td>
<td>
<?=
htmlspecialchars
(
$session
[
'status'
])
?>
</td>
<td>
<form
method=
"POST"
style=
"display:inline;"
>
<input
type=
"hidden"
name=
"update_status_session_id"
value=
"
<?=
htmlspecialchars
(
$session
[
'id'
])
?>
"
>
<select
name=
"new_status"
>
<option
value=
"scheduled"
<?=
$session
[
'status'
]
===
'scheduled'
?
'selected'
:
''
?>
>
Scheduled
</option>
<option
value=
"Started"
<?=
$session
[
'status'
]
===
'Started'
?
'selected'
:
''
?>
>
Started
</option>
<option
value=
"Finish"
<?=
$session
[
'status'
]
===
'Finish'
?
'selected'
:
''
?>
>
Finish
</option>
</select>
<button
type=
"submit"
>
Update
</button>
</form>
</td>
<td>
<form
method=
"POST"
style=
"display:inline;"
>
<input
type=
"hidden"
name=
"delete_session_id"
value=
"
<?=
htmlspecialchars
(
$session
[
'id'
])
?>
"
>
<button
type=
"submit"
onclick=
"return confirm('Are you sure you want to delete this session?')"
>
Supprimer
</button>
</form>
</td>
</tr>
<?php
endforeach
;
?>
</tbody>
</table>
<?php
else
:
?>
<p>
Pas de sessions disponible
</p>
<?php
endif
;
?>
</div>
</div>
</body>
</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