prepare("INSERT INTO songs (name, bpm, song_key, duration_seconds, notes, tags) VALUES (?, ?, ?, ?, ?, ?)"); $stmt->execute([$name, $bpm, $song_key, $duration_seconds, $notes, $tags]); $_SESSION['notification'] = ['message' => 'השיר נוצר בהצלחה!', 'type' => 'success']; } else { // update $id = (int)($_POST['id'] ?? 0); if ($id > 0) { $stmt = $pdo->prepare("UPDATE songs SET name=?, bpm=?, song_key=?, duration_seconds=?, notes=?, tags=? WHERE id=?"); $stmt->execute([$name, $bpm, $song_key, $duration_seconds, $notes, $tags, $id]); $_SESSION['notification'] = ['message' => 'השיר עודכן בהצלחה!', 'type' => 'success']; } } } elseif ($action === 'delete') { $id = (int)($_POST['id'] ?? 0); if ($id > 0) { $stmt = $pdo->prepare("DELETE FROM songs WHERE id=?"); $stmt->execute([$id]); $_SESSION['notification'] = ['message' => 'השיר נמחק בהצלחה.', 'type' => 'danger']; } } } catch (Exception $e) { $_SESSION['notification'] = ['message' => 'אירעה שגיאה: ' . $e->getMessage(), 'type' => 'danger']; } // Redirect to avoid form resubmission header("Location: songs.php"); exit(); } // Check for notification from session if (isset($_SESSION['notification'])) { $notification = $_SESSION['notification']; unset($_SESSION['notification']); } // Fetch all songs to display $songs = $pdo->query("SELECT * FROM songs ORDER BY name ASC")->fetchAll(); function format_duration($seconds) { if ($seconds === null || $seconds < 0) return '00:00'; $mins = floor($seconds / 60); $secs = $seconds % 60; return sprintf('%02d:%02d', $mins, $secs); } // --- Presentation --- include 'includes/header.php'; ?>
| שם השיר | BPM | סולם | משך | תגים | פעולות |
|---|---|---|---|---|---|
| עדיין אין שירים במאגר. הוסף את השיר הראשון שלך! | |||||