cal.php
unknown
php
3 years ago
16 kB
15
Indexable
<?php
// Conectați-vă la baza de date pentru utilizator
$servername_cal = "localhost"; // De obicei, serverul este "localhost", dar verificați cu furnizorul dvs. de hosting.
$username_cal = "horiamcc_user";
$password_cal = "Pysquaifk!1@@";
$dbname_cal = "horiamcc_cal";
// Crearea conexiunii
$connss = new mysqli($servername_cal, $username_cal, $password_cal, $dbname_cal);
global $connss;
// Verificarea conexiunii
if ($connss->connect_error) {
die("Conexiune eșuată: " . $connss->connect_error);
}
session_start();
// Verificăm dacă utilizatorul este autentificat
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
header('Location: login.php');
exit;
}
// Mesajul afișat după crearea evenimentului
$message = '';
// Verificăm dacă s-a trimis formularul și adăugăm evenimentul în calendar
if (isset($_POST['submit'])) {
// Obținem informațiile din formular
$event_date = $_POST['date'];
$event_label = $_POST['label'];
$event_artists = $_POST['artists'];
$event_details = $_POST['details'];
$created_by = $_SESSION['username']; // adăugăm numele de utilizator al persoanei care a creat evenimentul
// Inserarea evenimentului în baza de date
$sql = "INSERT INTO events (event_date, event_label, event_artists, event_details, created_by) VALUES (?, ?, ?, ?, ?)";
$stmt = $connss->prepare($sql);
$stmt->bind_param("sssss", $event_date, $event_label, $event_artists, $event_details, $created_by);
if ($stmt->execute()) {
// Setăm mesajul de succes
$message = 'Evenimentul a fost adăugat cu succes în calendar.';
} else {
echo "Eroare: " . $sql . "<br>" . $connss->error;
}
// Redirecționăm către cal.php cu parametrii transmiși prin URL
header("Location: cal.php?date=" . urlencode($event_date) . "&role=" . urlencode($event_label) . "&session_with=" . urlencode($event_artists) . "&message=" . urlencode($message));
exit;
}
// Funcția pentru a lista evenimentele dintr-o anumită zi
function list_events($date, $connss) {
$output = '';
$username = $_SESSION['username']; // obținem numele de utilizator al persoanei care a creat evenimentul
$sql = "SELECT id, event_label, event_artists, event_details, event_date FROM events WHERE event_date = ? AND created_by = ?";
$stmt = $connss->prepare($sql);
$stmt->bind_param("ss", $date, $username);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
setlocale(LC_TIME, 'ro_RO.utf8');
while ($event = $result->fetch_assoc()) {
$output .= '<li style="list-style: auto; text-shadow: 0px 0px 4px #7f5af0;"><strong>' . $event['event_label'] . ':</strong><br>' . ' - ' .$event['event_artists'] . ' - ' . $event['event_details'] . ' - ORA ' . strftime('%H:%M', strtotime($event['event_date'])) . '<form method="post" style="display:inline; background: transparent;"><input type="hidden" name="delete_date" value="' . $date . '"><button class="delete-event" type="submit" name="delete"><i class="fas fa-times"></i></button></form> <a href="#" class="edit-event" data-id="' . $event['id'] . '"><i class="fas fa-edit"></i></a></li>';
}
}
return $output;
}
// Verificăm dacă s-a trimis formularul de ștergere și ștergem evenimentul din baza de date
if (isset($_POST['delete'])) {
$delete_date = $_POST['delete_date'];
$username = $_SESSION['username']; // obținem numele de utilizator al persoanei care a creat evenimentul
$sql = "DELETE FROM events WHERE event_date = ? AND created_by = ?";
$stmt = $connss->prepare($sql);
$stmt->bind_param("ss", $delete_date, $username);
if ($stmt->execute()) {
$message = 'Evenimentul a fost șters cu succes.';
} else {
echo "Eroare: " . $sql . "<br>" . $connss->error;
}
}
?>
<!DOCTYPE html>
<html lang="ro">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"/>
<script>
window.addEventListener('load', function() {
var loadingScreen = document.getElementById('loading-screen');
loadingScreen.style.opacity = 1;
setTimeout(function() {
loadingScreen.style.opacity = 0;
setTimeout(function() {
loadingScreen.style.display = 'none';
}, 1000);
}, 1000); // timpul în milisecunde pentru care se afișează ecranul de încărcare
});
window.onload = function() {
// Selectăm toate elementele cu clasa "edit-event"
var editButtons = document.querySelectorAll('.edit-event');
// Adăugăm un event listener pentru fiecare buton
for (var i = 0; i < editButtons.length; i++) {
editButtons[i].addEventListener('click', function(e) {
// Prevenim comportamentul default al link-ului
e.preventDefault();
// Obținem id-ul evenimentului din atributul "data-id"
var eventId = this.getAttribute('data-id');
// Căutăm evenimentul în baza de date folosind AJAX
var xhr = new XMLHttpRequest();
xhr.open('POST', 'get_event.php', true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onload = function() {
if (this.status == 200) {
// Obținem evenimentul din răspunsul AJAX
var event = JSON.parse(this.responseText);
// Populăm formularul cu detaliile evenimentului
document.getElementById('date').value = event.event_date;
document.getElementById('label').value = event.event_label;
document.getElementById('artists').value = event.event_artists;
document.getElementById('details').value = event.event_details;
// Afișăm formularul
document.getElementById('edit-form').style.display = 'block';
}
}
xhr.send('id=' + eventId);
});
}
// Adăugăm un event listener pentru butonul de închidere al formularului
document.getElementById('close-form').addEventListener('click', function(e) {
// Prevenim comportamentul default al link-ului
e.preventDefault();
// Ascundem formularul
document.getElementById('edit-form').style.display = 'none';
});
}
</script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"/>
<meta charset="UTF-8">
<title>Calendar</title>
<!-- Folosim fontul "Open Sans" de pe Google Fonts -->
<link href="https://fonts.googleapis.com/css?family=Open+Sans&display=swap" rel="stylesheet">
<style>
/* Setăm fontul pentru întreg documentul */
body {
font-family: 'Open Sans', sans-serif;
}
/* Setăm culorile pentru background, text și link-uri */
body {
background-color: #1e1f2b;
color: #fff;
}
a {
color: #7f5af0;
}
a:hover {
color: #5c3ab8;
}
/* Setăm stilul pentru titlu și buton */
h1, button {
font-weight: normal;
margin-top: 0;
}
/* Setăm stilul pentru formular */
form {
background-color: #2d2f3e;
padding: 20px;
margin-top: 20px;
border-radius: 5px;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
input[type="date"], select, textarea {
width: 100%;
padding: 10px;
margin-bottom: 20px;
border: none;
border-radius: 5px;
font-size: 16px;
background-color: #1e1f2b;
color: #fff;
border: 1px solid #7f5af0;
}
input[type="date"]::-webkit-calendar-picker-indicator {
filter: invert(1);
}
input[type="text"] {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
background-color: #f8f8f8;
font-size: 16px;
}
input[type="time"]::-webkit-calendar-picker-indicator {
filter: invert(1);
}
input[type="submit"] {
background-color: #7f5af0;
color: white;
padding: 12px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
transition: background-color 0.2s ease-in-out;
}
input[type="submit"]:hover {
background-color: #5c3ab8;
}
.container {
border-radius: 5px;
background-color: #2d2f3e;
padding: 20px;
margin-top: 20px;
}
/* Stiluri pentru calendar */
table {
border-collapse: collapse;
margin: 20px 0;
width: 100%;
}
td {
border: 1px solid #ccc;
padding: 5px;
text-align: center;
vertical-align: middle;
background-color: #1e1f2b;
color: #fff;
}
th {
border: 1px solid #ccc;
padding: 5px;
text-align: center;
vertical-align: middle;
background-color: #7f5af0;
color: #fff;
}
.today {
background-color: #7f5af0;
color: white;
}
.event {
font-weight: bold;
}
.event-details {
margin-left: 10px;
font-size: 14px;
}
/* Stiluri pentru dispozitive mobile */
@media only screen and (max-width: 600px) {
/* Stiluri pentru formular */
form {
margin-top: 10px;
}
input[type="text"], select, textarea {
font-size: 16px;
}
input[type="submit"] {
padding: 10px;
font-size: 14px;
}
/* Stiluri pentru calendar */
td, th {
font-size: 14px;
padding: 2px;
}
.today {
font-weight: bold;
font-size: 14px;
}
.event {
font-size: 14px;
}
.event-details {
font-size: 12px;
}
}
.wrapper {
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
input[type="datetime-local"] {
width: 100%;
padding: 10px;
margin-bottom: 20px;
border: none;
border-radius: 5px;
font-size: 16px;
background-color: #1e1f2b;
color: #fff;
border: 1px solid #7f5af0;
}
input[type="datetime-local"]::-webkit-calendar-picker-indicator {
filter: invert(1);
}
.delete-event {
display: inline-block;
width: 20px;
height: 20px;
line-height: 20px;
text-align: center;
background-color: #1e1f2b;
color: #fff;
font-weight: bold;
border: none;
border-radius: 50%;
text-decoration: none;
padding: 0;
margin: 0;
cursor: pointer;
}
.delete-event:hover {
background-color: #1e1f2b75;
}
.delete-event i {
text-align: center;
margin: 0;
padding: 0;
font-size: 14px;
}
a.logout {
color: #7f5af0;
text-decoration: none;
font-size: 16px;
margin-left: 20px;
}
a.logout:hover {
color: #5c3ab8;
}
nav {
background-color: #1e1f2b;
padding: 15px;
text-align: end;
}
nav a {
color: #fff;
text-decoration: none;
font-size: 18px;
margin-right: 15px;
}
nav a:hover {
color: #7f5af0;
}
#loading-screen {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.5);
z-index: 9999;
display: flex;
justify-content: center;
align-items: center;
backdrop-filter: blur(10px);
}
.spinner {
width: 50px;
height: 50px;
border: 5px solid rgba(0, 0, 0, 0.1);
border-top-color: #1e88e5;
border-radius: 50%;
animation: spinner 1s linear infinite;
}
@keyframes spinner {
to {
transform: rotate(360deg);
}
}
/* Adăugat pentru a face containerul responsiv */
.container {
max-width: 100%;
margin: auto;
}
/* Adăugat pentru a face h1 și h2 responsiv */
h1, h2 {
font-size: 1.5rem;
}
/* Adăugat pentru a face textarea responsiv */
textarea {
resize: vertical;
}
/* Media queries adăugate pentru a ajusta stilurile în funcție de dimensiunea ecranului */
@media (min-width: 768px) {
h1, h2 {
font-size: 2rem;
}
}
h2 {
font-size: medium;
}
</style>
</head>
<body>
<div id="loading-screen">
<div class="spinner"></div>
</div>
<div id="edit-event-dialog" title="Editare programare sesiune" style="display: none;">
<form id="edit-event-form">
<label for="edit-date">Data și ora:</label>
<input type="datetime-local" id="edit-date" name="date" required>
<label for="edit-label">Label:</label>
<select name="label" id="edit-label">
<option value="Xtra Music Media">Xtra Music Media</option>
<option value="Xtra Music Records">Xtra Music Records</option>
<!-- Adăugați aici alte opțiuni dacă este necesar -->
</select>
<label for="edit-artists">Cu cine:</label>
<input type="text" id="edit-artists" name="artists" required>
<label for="edit-details">Detalii:</label>
<textarea id="edit-details" name="details" required></textarea>
<input type="hidden" id="edit-id" name="id">
<input type="submit" value="Actualizează">
</form>
</div>
<nav>
<a href="dashboard.php">Înapoi la Dashboard</a>
</nav>
<div class="wrapper">
<div class="container">
<h1>Programează o sesiune</h1>
<div class="message <?php echo $message ? (strpos($message, 'Eroare') !== false ? 'error' : 'success') : ''; ?>">
<?php echo $message; ?>
</div>
<form action="cal.php" method="post">
<label for="date">Data și ora:</label>
<input type="datetime-local" id="date" name="date" required value="<?php echo isset($_GET['date']) ? $_GET['date'] : ''; ?>">
<br><br>
<label for="label">Label:</label>
<select name="label" id="label">
<option value="Xtra Music Media" <?php echo isset($_GET['role']) && $_GET['role'] == 'Xtra Music Media' ? 'selected' : ''; ?>>Xtra Music Media</option>
<option value="The One Records" <?php echo isset($_GET['role']) && $_GET['role'] == 'The One Records' ? 'selected' : ''; ?>>The One Records</option>
<option value="HoriaMC [Acasa]" <?php echo isset($_GET['role']) && $_GET['role'] == 'HoriaMC [Acasa]' ? 'selected' : ''; ?>>HoriaMC [Acasa]</option>
</select>
<br><br>
<label for="artists">Artiști / Clienți:</label>
<textarea id="artists" name="artists" required><?php echo isset($_GET['session_with']) ? $_GET['session_with'] : ''; ?></textarea>
<br><br>
<label for="details">Detalii:</label>
<textarea id="details" name="details"><?php echo isset($_GET['message']) ? $_GET['message'] : ''; ?></textarea>
<br><br>
<input type="submit" name="submit" value="Programează">
</form>
</div>
<div class="container">
<h1>Sesiuni programate</h1>
<?php
// Obținem datele unice din baza de date pentru utilizatorul curent
$username = $_SESSION['username']; // obținem numele de utilizator al persoanei care a creat evenimentul
$sql = "SELECT DISTINCT event_date FROM events WHERE created_by = ? ORDER BY event_date";
$stmt = $connss->prepare($sql);
$stmt->bind_param("s", $username);
$stmt->execute();
$result = $stmt->get_result();
// Verificăm dacă există evenimente în baza de date
if ($result->num_rows > 0) {
// Parcurgem fiecare dată și afișăm evenimentele din acea zi
while ($row = $result->fetch_assoc()) {
$date = $row['event_date'];
setlocale(LC_TIME, 'ro_RO.utf8');
echo '<h2>' . strftime('%A, %d %B %Y', strtotime($date)) . '</h2>';
echo '<ul>';
echo list_events($date, $connss);
echo '</ul>';
}
} else {
echo '<p>Nu există sesiuni programate.</p>';
}
?>
</div>
</div>
</body>
</html>Editor is loading...