From c184472fb453516ef7b3239996e8a4f1ea77d054 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Fri, 24 Oct 2025 19:48:28 +0000 Subject: [PATCH] Auto commit: 2025-10-24T19:48:28.874Z --- admin/dashboard.php | 125 +++++++++++++++++++++++++++++++++++++++++++ admin/index.php | 93 ++++++++++++++++++++++++++++++++ api/get_stations.php | 12 +++++ assets/js/main.js | 90 +++++++++++-------------------- index.php | 24 +-------- 5 files changed, 262 insertions(+), 82 deletions(-) create mode 100644 admin/dashboard.php create mode 100644 admin/index.php create mode 100644 api/get_stations.php diff --git a/admin/dashboard.php b/admin/dashboard.php new file mode 100644 index 0000000..4d49045 --- /dev/null +++ b/admin/dashboard.php @@ -0,0 +1,125 @@ +exec("CREATE TABLE IF NOT EXISTS stations ( + id INT AUTO_INCREMENT PRIMARY KEY, + name VARCHAR(255) NOT NULL, + url VARCHAR(255) NOT NULL, + logo_url VARCHAR(255) + )"); + + // Handle form submissions for add/edit/delete + if ($_SERVER['REQUEST_METHOD'] === 'POST') { + if (isset($_POST['add'])) { + $stmt = $pdo->prepare("INSERT INTO stations (name, url, logo_url) VALUES (?, ?, ?)"); + $stmt->execute([$_POST['name'], $_POST['url'], $_POST['logo_url']]); + } elseif (isset($_POST['edit'])) { + $stmt = $pdo->prepare("UPDATE stations SET name = ?, url = ?, logo_url = ? WHERE id = ?"); + $stmt->execute([$_POST['name'], $_POST['url'], $_POST['logo_url'], $_POST['id']]); + } elseif (isset($_POST['delete'])) { + $stmt = $pdo->prepare("DELETE FROM stations WHERE id = ?"); + $stmt->execute([$_POST['id']]); + } + header("Location: dashboard.php"); + exit; + } + + // Fetch all stations + $stations = $pdo->query("SELECT * FROM stations ORDER BY name")->fetchAll(); + +} catch (PDOException $e) { + $error = "Database error: " . $e->getMessage(); +} + +?> + + + + + + Admin Dashboard + + + + +
+
+
+

Manage Radio Stations

+ Logout +
+
+ +
+ + + +
+

Add New Station

+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+ +

Existing Stations

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
NameStream URLLogo URLActions
No stations found.
+ + +
+
+
+
+ + \ No newline at end of file diff --git a/admin/index.php b/admin/index.php new file mode 100644 index 0000000..6004480 --- /dev/null +++ b/admin/index.php @@ -0,0 +1,93 @@ + + + + + + + Admin Login + + + + +
+

Admin Login

+
+ +
+ +
+ +

+ +
+ + diff --git a/api/get_stations.php b/api/get_stations.php new file mode 100644 index 0000000..4382c3c --- /dev/null +++ b/api/get_stations.php @@ -0,0 +1,12 @@ +query("SELECT id, name, url, logo_url FROM stations ORDER BY name")->fetchAll(); + echo json_encode($stations); +} catch (PDOException $e) { + http_response_code(500); + echo json_encode(['error' => 'Database error: ' . $e->getMessage()]); +} diff --git a/assets/js/main.js b/assets/js/main.js index 179dd74..c69fcb0 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -20,9 +20,9 @@ class RadioWave { this.ui = {}; // To cache UI elements } - init() { + async init() { this.initUI(); - this.loadStations(); + await this.loadStations(); this.bindEvents(); this.applyAccentColor(localStorage.getItem('accentColor') || '#FF8C00'); if (localStorage.getItem('theme') === 'light') { @@ -102,17 +102,25 @@ class RadioWave { } // Station Management - loadStations() { - const savedStations = localStorage.getItem('stations'); - this.stations = savedStations ? JSON.parse(savedStations) : [ - { name: "Lofi Girl", url: "https://play.streamafrica.net/lofiradio", logo: "https://i.ytimg.com/vi/jfKfPfyJRdk/maxresdefault.jpg", genre: "Lofi" }, - { name: "Classic Rock", url: "http://198.178.123.23:8722/stream", logo: "https://cdn-radiotime-logos.tunein.com/s292341q.png", genre: "Rock" }, - ]; - this.renderStationList(); - } - - saveStations() { - localStorage.setItem('stations', JSON.stringify(this.stations)); + async loadStations() { + try { + const response = await fetch('/api/get_stations.php'); + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + const stations = await response.json(); + this.stations = stations.map(station => ({ + ...station, + logo: station.logo_url // map db field to app field + })); + this.renderStationList(); + if (this.stations.length > 0 && this.currentStationIndex === -1) { + this.playStation(0); + } + } catch (error) { + console.error("Could not load stations:", error); + this.ui.stationList.innerHTML = `
  • Could not load stations.
  • `; + } } renderStationList() { @@ -129,21 +137,6 @@ class RadioWave { }); } - addStation(e) { - e.preventDefault(); - const newStation = { - name: this.ui.newStationName.value, - url: this.ui.newStationUrl.value, - logo: this.ui.newStationLogo.value, - genre: this.ui.newStationGenre.value - }; - this.stations.push(newStation); - this.saveStations(); - this.renderStationList(); - this.ui.addStationForm.reset(); - this.hideAllModals(); - } - handleStationClick(e) { const li = e.target.closest('li'); if (li) { @@ -298,7 +291,7 @@ class RadioWave { if (e.target.type === 'range') { const index = e.target.dataset.index; const value = e.target.value; - if (this.eqBands[index]) { + if (.eqBands[index]) { this.eqBands[index].gain.value = value; } this.ui.eqPresetSelect.value = 'custom'; @@ -383,37 +376,14 @@ class RadioWave { } // Data & Settings - importStations(event) { - const file = event.target.files[0]; - if (!file) return; - const reader = new FileReader(); - reader.onload = (e) => { - try { - const importedStations = JSON.parse(e.target.result); - if (Array.isArray(importedStations)) { - this.stations = importedStations; - this.saveStations(); - this.renderStationList(); - alert('Stations imported successfully!'); - } else { - throw new Error('Invalid format'); - } - } catch (err) { - alert('Failed to import stations. Please check the file format.'); - } - }; - reader.readAsText(file); - } - - exportStations() { - const data = JSON.stringify(this.stations, null, 2); - const blob = new Blob([data], { type: 'application/json' }); - const url = URL.createObjectURL(blob); - const a = document.createElement('a'); - a.href = url; - a.download = 'radiowave_stations.json'; - a.click(); - URL.revokeObjectURL(url); + setSleepTimer(minutes) { + clearTimeout(this.sleepTimer); + if (minutes > 0) { + this.sleepTimer = setTimeout(() => { + this.togglePlayPause(false); // Pause the player + this.ui.sleepTimerSelect.value = 0; + }, minutes * 60 * 1000); + } } setSleepTimer(minutes) { diff --git a/index.php b/index.php index c5877c3..b4faa22 100644 --- a/index.php +++ b/index.php @@ -70,7 +70,6 @@
    -
    -
    -

    Manage Data

    -
    - - -
    - -
    + - +