132 lines
6.4 KiB
PHP
132 lines
6.4 KiB
PHP
<?php
|
|
require_once __DIR__ . '/db/config.php';
|
|
|
|
// Fetch all alarms for initial display
|
|
try {
|
|
$stmt = db()->query("SELECT * FROM alarms ORDER BY alarm_time ASC");
|
|
$alarms = $stmt->fetchAll();
|
|
} catch (PDOException $e) {
|
|
// Handle error gracefully
|
|
$alarms = [];
|
|
error_log("Error fetching alarms: " . $e->getMessage());
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Alarm & Note App</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap" rel="stylesheet">
|
|
<script src="https://unpkg.com/feather-icons"></script>
|
|
</head>
|
|
<body>
|
|
|
|
<header class="header-gradient text-white text-center">
|
|
<div class="container">
|
|
<h1>Alarm Dashboard</h1>
|
|
<p class="lead">Set your alarms. Write your notes.</p>
|
|
</div>
|
|
</header>
|
|
|
|
<main class="container mt-5">
|
|
<div class="row justify-content-center">
|
|
<div class="col-md-8">
|
|
<!-- Create Alarm Form -->
|
|
<div class="card mb-4">
|
|
<div class="card-body">
|
|
<h5 class="card-title">Create a New Alarm</h5>
|
|
<form id="createAlarmForm">
|
|
<div class="input-group">
|
|
<input type="time" class="form-control" id="alarmTime" required>
|
|
<input type="text" class="form-control" id="alarmLabel" placeholder="Alarm label (optional)">
|
|
<button type="submit" class="btn btn-primary">
|
|
<i data-feather="plus" class="align-text-bottom"></i> Set Alarm
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Alarms List -->
|
|
<div class="card">
|
|
<div class="card-header">
|
|
Your Alarms
|
|
</div>
|
|
<ul class="list-group list-group-flush" id="alarmList">
|
|
<?php if (empty($alarms)): ?>
|
|
<li class="list-group-item text-center text-muted" id="noAlarmsMessage">
|
|
No alarms set yet.
|
|
</li>
|
|
<?php else: ?>
|
|
<?php foreach ($alarms as $alarm): ?>
|
|
<li class="list-group-item d-flex justify-content-between align-items-center" data-id="<?= htmlspecialchars($alarm['id']) ?>">
|
|
<div class="d-flex align-items-center">
|
|
<div class="form-check form-switch me-3">
|
|
<input class="form-check-input toggle-alarm-switch" type="checkbox" role="switch" id="toggle-<?= htmlspecialchars($alarm['id']) ?>" <?= $alarm['is_active'] ? 'checked' : '' ?>>
|
|
<label class="form-check-label" for="toggle-<?= htmlspecialchars($alarm['id']) ?>"></label>
|
|
</div>
|
|
<div>
|
|
<span class="fw-bold fs-5"><?= htmlspecialchars(date("g:i A", strtotime($alarm['alarm_time']))) ?></span>
|
|
<span class="text-muted ms-2"><?= htmlspecialchars($alarm['label']) ?></span>
|
|
</div>
|
|
</div>
|
|
<form class="delete-alarm-form">
|
|
<input type="hidden" name="action" value="delete">
|
|
<input type="hidden" name="alarm_id" value="<?= htmlspecialchars($alarm['id']) ?>">
|
|
<button type="submit" class="btn btn-sm btn-outline-danger">
|
|
<i data-feather="trash-2" class="align-text-bottom"></i>
|
|
</button>
|
|
</form>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</ul>
|
|
</div>
|
|
<div class="card mt-4">
|
|
<div class="card-header">
|
|
Recent Notes
|
|
</div>
|
|
<div class="card-body">
|
|
<ul class="list-group list-group-flush">
|
|
<li class="list-group-item"><a href="note.php">View/Edit Today's Note</a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
<!-- Alarm Modal -->
|
|
<div class="modal fade" id="alarmModal" tabindex="-1" aria-labelledby="alarmModalLabel" aria-hidden="true" data-bs-backdrop="static" data-bs-keyboard="false">
|
|
<div class="modal-dialog modal-dialog-centered">
|
|
<div class="modal-content text-center">
|
|
<div class="modal-body p-5">
|
|
<i data-feather="bell" class="feather-lg text-warning mb-3"></i>
|
|
<h1 class="my-4">Alarm Clock</h1>
|
|
<button id="enable-notifications" class="btn btn-primary mb-4">Enable Notifications</button>
|
|
<p id="alarmModalMessage" class="lead">Time to write your notes.</p>
|
|
<button type="button" class="btn btn-primary btn-lg mt-3" id="dismissAlarmBtn">Dismiss</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<audio id="alarmSound" src="https://cdn.jsdelivr.net/npm/ion-sound@3.0.7/sounds/bell_ring.mp3" preload="auto"></audio>
|
|
|
|
<footer class="text-center text-muted py-4 mt-5">
|
|
<p>© <?= date('Y') ?> Alarm & Note App</p>
|
|
</footer>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
|
<script>
|
|
feather.replace()
|
|
</script>
|
|
</body>
|
|
</html>
|