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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ZHANG David
tutorat
Commits
f6ac4edf
Commit
f6ac4edf
authored
4 months ago
by
ZHANG David
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
4bc764f1
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/create_session.php
+84
-0
84 additions, 0 deletions
code/create_session.php
with
84 additions
and
0 deletions
code/create_session.php
0 → 100644
+
84
−
0
View file @
f6ac4edf
<?php
include
'config.php'
;
session_start
();
if
(
!
isset
(
$_SESSION
[
'user'
])
||
$_SESSION
[
'user'
][
'role'
]
!==
'tutor'
)
{
echo
"<div class='container'><p class='error'>Access denied. Only tutors can create sessions.</p><a href='login.php'>Go back</a></div>"
;
exit
;
}
$user
=
$_SESSION
[
'user'
];
if
(
$_SERVER
[
'REQUEST_METHOD'
]
===
'POST'
)
{
$subject
=
$conn
->
real_escape_string
(
$_POST
[
'subject'
]);
$room
=
$conn
->
real_escape_string
(
$_POST
[
'room'
]);
$start_time
=
$conn
->
real_escape_string
(
$_POST
[
'start_time'
]);
$end_time
=
$conn
->
real_escape_string
(
$_POST
[
'end_time'
]);
$tutor_id
=
$_SESSION
[
'user'
][
'id'
];
// Calculer la durée entre start_time et end_time
$start
=
strtotime
(
$start_time
);
$end
=
strtotime
(
$end_time
);
$duration
=
(
$end
-
$start
)
/
3600
;
// Convertir en heures
// Vérifier que la durée est entre 1 et 2 heures
if
(
$duration
<
1
||
$duration
>
2
)
{
echo
"<div class='container'><p class='error'>The session duration must be between 1 and 2 hours.</p><a href='create_session.php'>Go back</a></div>"
;
exit
;
}
// Insérer la session si la durée est valide
$sql
=
"INSERT INTO Session (tutor_id, subject, start_time, end_time, status)
VALUES ('
$tutor_id
', '
$subject
', '
$start_time
', '
$end_time
', 'scheduled')"
;
if
(
$conn
->
query
(
$sql
)
===
TRUE
)
{
echo
"<div class='container' style='text-align: center; margin-top: 50px; font-family: Arial, sans-serif;'>
<p style='color: #28a745; font-size: 20px; font-weight: 600; margin-bottom: 20px;'>Session created successfully.</p>
<a href='welcome.php' style='display: inline-block; padding: 12px 24px; background-color: #28a745; color: white; text-decoration: none; border-radius: 8px; font-size: 16px; font-weight: 500; transition: background-color 0.3s;'>
Go back
</a>
</div>"
;
}
else
{
echo
"<div class='container' style='text-align: center; margin-top: 50px; font-family: Arial, sans-serif;'>
<p style='color: #dc3545; font-size: 20px; font-weight: 600; margin-bottom: 20px;'>Error: "
.
htmlspecialchars
(
$conn
->
error
,
ENT_QUOTES
,
'UTF-8'
)
.
"</p>
<a href='create_session.php' style='display: inline-block; padding: 12px 24px; background-color: #dc3545; color: white; text-decoration: none; border-radius: 8px; font-size: 16px; font-weight: 500; transition: background-color 0.3s;'>
Try again
</a>
</div>"
;
}
}
else
{
?>
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<meta
charset=
"UTF-8"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
>
<title>
Create Session
</title>
<link
rel=
"stylesheet"
href=
"style.css"
>
</head>
<body>
<?php
include
'sidebar.php'
;
?>
<div
class=
"main-content"
>
<div
class=
"create-session-page"
>
<h1>
Create a Session
</h1>
<form
method=
"POST"
>
<label
for=
"subject"
>
Subject:
</label>
<input
type=
"text"
name=
"subject"
id=
"subject"
required
>
<label
for=
"room"
>
Room :
</label>
<select
id=
"room"
Room=
"salles"
>
<option
value=
"madras"
>
Madras
</option>
<option
value=
"bombay"
>
Bombay
</option>
<option
value=
"shanghai"
>
Shanghai
</option>
</select>
<label
for=
"start_time"
>
Start Time:
</label>
<input
type=
"datetime-local"
name=
"start_time"
id=
"start_time"
required
>
<label
for=
"end_time"
>
End Time:
</label>
<input
type=
"datetime-local"
name=
"end_time"
id=
"end_time"
required
>
<button
type=
"submit"
>
Create Session
</button>
</form>
</div>
</div>
</body>
</html>
<?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