tick and clock
This commit is contained in:
parent
c7a8646800
commit
41111c794f
101
api/alarms.php
Normal file
101
api/alarms.php
Normal file
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../db/config.php';
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$response = ['success' => false, 'message' => 'Invalid request'];
|
||||
$pdo = db();
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['action'])) {
|
||||
if ($_GET['action'] === 'check') {
|
||||
try {
|
||||
$pdo->beginTransaction();
|
||||
|
||||
// Find active alarms that are due and lock the rows
|
||||
$stmt = $pdo->prepare("SELECT * FROM alarms WHERE alarm_time <= CURTIME() AND is_active = 1 FOR UPDATE");
|
||||
$stmt->execute();
|
||||
$alarms = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($alarms) {
|
||||
// Deactivate the found alarms to prevent them from ringing again
|
||||
$alarmIds = array_map(function($alarm) {
|
||||
return $alarm['id'];
|
||||
}, $alarms);
|
||||
|
||||
if (!empty($alarmIds)) {
|
||||
$placeholders = implode(',', array_fill(0, count($alarmIds), '?'));
|
||||
$updateStmt = $pdo->prepare("UPDATE alarms SET is_active = 0 WHERE id IN ($placeholders)");
|
||||
$updateStmt->execute($alarmIds);
|
||||
}
|
||||
|
||||
$response = ['success' => true, 'alarms' => $alarms];
|
||||
} else {
|
||||
$response = ['success' => true, 'alarms' => []];
|
||||
}
|
||||
|
||||
$pdo->commit();
|
||||
} catch (PDOException $e) {
|
||||
$pdo->rollBack();
|
||||
$response['message'] = 'Database error: ' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
// Simple routing based on a POST field
|
||||
$action = $_POST['action'] ?? '';
|
||||
|
||||
if ($action === 'create') {
|
||||
$alarm_time = $_POST['alarm_time'] ?? null;
|
||||
$label = $_POST['label'] ?? '';
|
||||
|
||||
if ($alarm_time) {
|
||||
try {
|
||||
$stmt = $pdo->prepare("INSERT INTO alarms (alarm_time, label) VALUES (?, ?)");
|
||||
$stmt->execute([$alarm_time, $label]);
|
||||
$response = ['success' => true, 'message' => 'Alarm created successfully.', 'id' => $pdo->lastInsertId()];
|
||||
} catch (PDOException $e) {
|
||||
$response['message'] = 'Database error: ' . $e->getMessage();
|
||||
}
|
||||
} else {
|
||||
$response['message'] = 'Alarm time is required.';
|
||||
}
|
||||
} elseif ($action === 'delete') {
|
||||
$alarm_id = $_POST['alarm_id'] ?? null;
|
||||
|
||||
if ($alarm_id) {
|
||||
try {
|
||||
$stmt = $pdo->prepare("DELETE FROM alarms WHERE id = ?");
|
||||
$stmt->execute([$alarm_id]);
|
||||
if ($stmt->rowCount()) {
|
||||
$response = ['success' => true, 'message' => 'Alarm deleted successfully.'];
|
||||
} else {
|
||||
$response['message'] = 'Alarm not found.';
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
$response['message'] = 'Database error: ' . $e->getMessage();
|
||||
}
|
||||
} else {
|
||||
$response['message'] = 'Alarm ID is required.';
|
||||
}
|
||||
} elseif ($action === 'toggle') {
|
||||
$alarm_id = $_POST['alarm_id'] ?? null;
|
||||
$is_active = $_POST['is_active'] ?? null;
|
||||
|
||||
if ($alarm_id && $is_active !== null) {
|
||||
try {
|
||||
$stmt = $pdo->prepare("UPDATE alarms SET is_active = ? WHERE id = ?");
|
||||
$stmt->execute([$is_active, $alarm_id]);
|
||||
if ($stmt->rowCount()) {
|
||||
$response = ['success' => true, 'message' => 'Alarm status updated.'];
|
||||
} else {
|
||||
$response['message'] = 'Alarm not found or status unchanged.';
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
$response['message'] = 'Database error: ' . $e->getMessage();
|
||||
}
|
||||
} else {
|
||||
$response['message'] = 'Alarm ID and active status are required.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode($response);
|
||||
80
assets/css/custom.css
Normal file
80
assets/css/custom.css
Normal file
@ -0,0 +1,80 @@
|
||||
/* General Body Styles */
|
||||
body {
|
||||
background-color: #F4F7F6;
|
||||
font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
/* Header Styles */
|
||||
.header-gradient {
|
||||
background: linear-gradient(90deg, #4A90E2, #50E3C2);
|
||||
color: white;
|
||||
padding: 1rem 0;
|
||||
}
|
||||
|
||||
/* Card Styles */
|
||||
.card {
|
||||
border-radius: 0.5rem;
|
||||
border: none;
|
||||
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
||||
}
|
||||
|
||||
/* Button Styles */
|
||||
.btn-primary {
|
||||
background-color: #4A90E2;
|
||||
border-color: #4A90E2;
|
||||
border-radius: 0.5rem;
|
||||
padding: 0.75rem 1.5rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
background-color: #3a7ac8;
|
||||
border-color: #3a7ac8;
|
||||
}
|
||||
|
||||
/* Form Styles */
|
||||
.form-control {
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
|
||||
.form-control:focus {
|
||||
border-color: #4A90E2;
|
||||
box-shadow: 0 0 0 0.2rem rgba(74, 144, 226, 0.25);
|
||||
}
|
||||
|
||||
/* Toast Notification */
|
||||
.toast-container {
|
||||
position: fixed;
|
||||
top: 1rem;
|
||||
right: 1rem;
|
||||
z-index: 1055;
|
||||
}
|
||||
|
||||
/* Alarm List Styles */
|
||||
#alarmList .list-group-item {
|
||||
transition: background-color 0.2s ease-in-out;
|
||||
}
|
||||
|
||||
#alarmList .list-group-item:hover {
|
||||
background-color: #f8f9fa;
|
||||
}
|
||||
|
||||
#alarmList .btn-outline-danger {
|
||||
border: none;
|
||||
}
|
||||
|
||||
/* Alarm Modal Styles */
|
||||
#alarmModal .modal-content {
|
||||
border-radius: 1rem;
|
||||
}
|
||||
|
||||
#alarmModal .feather-lg {
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
stroke-width: 1.5;
|
||||
}
|
||||
|
||||
.modal-backdrop.show {
|
||||
opacity: 0.8;
|
||||
}
|
||||
229
assets/js/main.js
Normal file
229
assets/js/main.js
Normal file
@ -0,0 +1,229 @@
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
// --- ELEMENTS ---
|
||||
const createAlarmForm = document.getElementById('createAlarmForm');
|
||||
const alarmList = document.getElementById('alarmList');
|
||||
const noAlarmsMessage = document.getElementById('noAlarmsMessage');
|
||||
const alarmModalEl = document.getElementById('alarmModal');
|
||||
const alarmModal = new bootstrap.Modal(alarmModalEl);
|
||||
const dismissAlarmBtn = document.getElementById('dismissAlarmBtn');
|
||||
const alarmSound = document.getElementById('alarmSound');
|
||||
const alarmModalMessage = document.getElementById('alarmModalMessage');
|
||||
|
||||
// --- STATE ---
|
||||
let isAlarmModalShown = false;
|
||||
|
||||
// --- FUNCTIONS ---
|
||||
|
||||
/**
|
||||
* Handles the submission of the create alarm form.
|
||||
*/
|
||||
const handleCreateAlarm = async (e) => {
|
||||
e.preventDefault();
|
||||
const timeInput = document.getElementById('alarmTime');
|
||||
const labelInput = document.getElementById('alarmLabel');
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('action', 'create');
|
||||
formData.append('alarm_time', timeInput.value);
|
||||
formData.append('label', labelInput.value);
|
||||
|
||||
try {
|
||||
const response = await fetch('api/alarms.php', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
addAlarmToList(result.id, timeInput.value, labelInput.value);
|
||||
timeInput.value = '';
|
||||
labelInput.value = '';
|
||||
if (noAlarmsMessage) {
|
||||
noAlarmsMessage.style.display = 'none';
|
||||
}
|
||||
} else {
|
||||
alert('Error: ' + result.message);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to create alarm:', error);
|
||||
alert('An error occurred while creating the alarm.');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles the click on a delete alarm form.
|
||||
*/
|
||||
const handleDeleteAlarm = async (e) => {
|
||||
if (!e.target.closest('.delete-alarm-form')) return;
|
||||
e.preventDefault();
|
||||
|
||||
const form = e.target.closest('.delete-alarm-form');
|
||||
const alarmId = form.querySelector('input[name="alarm_id"]').value;
|
||||
|
||||
if (!confirm('Are you sure you want to delete this alarm?')) return;
|
||||
|
||||
const formData = new FormData(form);
|
||||
|
||||
try {
|
||||
const response = await fetch('api/alarms.php', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
const listItem = form.closest('li');
|
||||
listItem.remove();
|
||||
if (!alarmList.querySelector('li')) {
|
||||
if (noAlarmsMessage) {
|
||||
noAlarmsMessage.style.display = 'block';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
alert('Error: ' + result.message);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to delete alarm:', error);
|
||||
alert('An error occurred while deleting the alarm.');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds a new alarm item to the DOM.
|
||||
*/
|
||||
const addAlarmToList = (id, time, label, isActive = true) => {
|
||||
const date = new Date(`1970-01-01T${time}`);
|
||||
const formattedTime = date.toLocaleTimeString('en-US', { hour: 'numeric', minute: '2-digit', hour12: true });
|
||||
|
||||
const li = document.createElement('li');
|
||||
li.className = 'list-group-item d-flex justify-content-between align-items-center';
|
||||
li.dataset.id = id;
|
||||
li.innerHTML = `
|
||||
<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-${id}" ${isActive ? 'checked' : ''}>
|
||||
<label class="form-check-label" for="toggle-${id}"></label>
|
||||
</div>
|
||||
<div>
|
||||
<span class="fw-bold fs-5">${formattedTime}</span>
|
||||
<span class="text-muted ms-2">${escapeHTML(label)}</span>
|
||||
</div>
|
||||
</div>
|
||||
<form class="delete-alarm-form">
|
||||
<input type="hidden" name="action" value="delete">
|
||||
<input type="hidden" name="alarm_id" value="${id}">
|
||||
<button type="submit" class="btn btn-sm btn-outline-danger">
|
||||
<i data-feather="trash-2" class="align-text-bottom"></i>
|
||||
</button>
|
||||
</form>
|
||||
`;
|
||||
alarmList.appendChild(li);
|
||||
feather.replace();
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles toggling the active state of an alarm.
|
||||
*/
|
||||
const handleToggleAlarm = async (e) => {
|
||||
if (!e.target.classList.contains('toggle-alarm-switch')) return;
|
||||
|
||||
const switchEl = e.target;
|
||||
const listItem = switchEl.closest('li');
|
||||
const alarmId = listItem.dataset.id;
|
||||
const isActive = switchEl.checked ? 1 : 0;
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('action', 'toggle');
|
||||
formData.append('alarm_id', alarmId);
|
||||
formData.append('is_active', isActive);
|
||||
|
||||
try {
|
||||
const response = await fetch('api/alarms.php', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
const result = await response.json();
|
||||
|
||||
if (!result.success) {
|
||||
alert('Error: ' + result.message);
|
||||
// Revert the switch on failure
|
||||
switchEl.checked = !switchEl.checked;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to toggle alarm:', error);
|
||||
alert('An error occurred while updating the alarm.');
|
||||
// Revert the switch on failure
|
||||
switchEl.checked = !switchEl.checked;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks the server for any due alarms.
|
||||
*/
|
||||
const checkAlarms = async () => {
|
||||
if (isAlarmModalShown) return; // Don't check if an alarm is already ringing
|
||||
|
||||
try {
|
||||
const response = await fetch('api/alarms.php?action=check');
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success && result.alarms.length > 0) {
|
||||
const alarm = result.alarms[0];
|
||||
triggerAlarm(alarm);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error checking alarms:', error);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Triggers the visual and audible alarm.
|
||||
*/
|
||||
const triggerAlarm = (alarm) => {
|
||||
isAlarmModalShown = true;
|
||||
if (alarm.label) {
|
||||
alarmModalMessage.textContent = alarm.label;
|
||||
} else {
|
||||
alarmModalMessage.textContent = 'Time to write your notes.';
|
||||
}
|
||||
alarmModal.show();
|
||||
alarmSound.play().catch(e => console.error("Audio play failed:", e));
|
||||
};
|
||||
|
||||
/**
|
||||
* Dismisses the alarm and redirects to the note page.
|
||||
*/
|
||||
const dismissAlarm = () => {
|
||||
alarmSound.pause();
|
||||
alarmSound.currentTime = 0;
|
||||
alarmModal.hide();
|
||||
isAlarmModalShown = false;
|
||||
|
||||
const today = new Date();
|
||||
const dateString = today.getFullYear() + '-' + String(today.getMonth() + 1).padStart(2, '0') + '-' + String(today.getDate()).padStart(2, '0');
|
||||
window.location.href = `note.php?date=${dateString}`;
|
||||
};
|
||||
|
||||
const escapeHTML = (str) => {
|
||||
const p = document.createElement('p');
|
||||
p.appendChild(document.createTextNode(str));
|
||||
return p.innerHTML;
|
||||
}
|
||||
|
||||
// --- EVENT LISTENERS ---
|
||||
if (createAlarmForm) {
|
||||
createAlarmForm.addEventListener('submit', handleCreateAlarm);
|
||||
}
|
||||
|
||||
if (alarmList) {
|
||||
alarmList.addEventListener('click', handleDeleteAlarm);
|
||||
alarmList.addEventListener('change', handleToggleAlarm);
|
||||
}
|
||||
|
||||
if (dismissAlarmBtn) {
|
||||
dismissAlarmBtn.addEventListener('click', dismissAlarm);
|
||||
}
|
||||
|
||||
// --- INITIALIZATION ---
|
||||
setInterval(checkAlarms, 5000); // Check for alarms every 5 seconds
|
||||
});
|
||||
@ -15,3 +15,34 @@ function db() {
|
||||
}
|
||||
return $pdo;
|
||||
}
|
||||
|
||||
function run_migrations() {
|
||||
$pdo = db();
|
||||
// Create migrations table if it doesn't exist
|
||||
$pdo->exec("CREATE TABLE IF NOT EXISTS migrations (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
migration VARCHAR(255) NOT NULL UNIQUE,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
)");
|
||||
|
||||
// Get all run migrations
|
||||
$run_migrations_stmt = $pdo->query("SELECT migration FROM migrations");
|
||||
$run_migrations = $run_migrations_stmt->fetchAll(PDO::FETCH_COLUMN);
|
||||
|
||||
// Get all migration files
|
||||
$migration_files = glob(__DIR__ . '/migrations/*.sql');
|
||||
|
||||
foreach ($migration_files as $file) {
|
||||
$migration_name = basename($file);
|
||||
if (!in_array($migration_name, $run_migrations)) {
|
||||
$sql = file_get_contents($file);
|
||||
$pdo->exec($sql);
|
||||
$stmt = $pdo->prepare("INSERT INTO migrations (migration) VALUES (?)");
|
||||
$stmt->execute([$migration_name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Run migrations on every request for simplicity in this context.
|
||||
// For production, this should be a separate script.
|
||||
run_migrations();
|
||||
|
||||
7
db/migrations/001_create_notes_table.sql
Normal file
7
db/migrations/001_create_notes_table.sql
Normal file
@ -0,0 +1,7 @@
|
||||
CREATE TABLE IF NOT EXISTS notes (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
note_date DATE NOT NULL UNIQUE,
|
||||
content TEXT,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||
);
|
||||
8
db/migrations/002_create_alarms_table.sql
Normal file
8
db/migrations/002_create_alarms_table.sql
Normal file
@ -0,0 +1,8 @@
|
||||
CREATE TABLE IF NOT EXISTS alarms (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
alarm_time TIME NOT NULL,
|
||||
label VARCHAR(255) NULL,
|
||||
is_active BOOLEAN DEFAULT TRUE,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||
);
|
||||
250
index.php
250
index.php
@ -1,150 +1,130 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
@ini_set('display_errors', '1');
|
||||
@error_reporting(E_ALL);
|
||||
@date_default_timezone_set('UTC');
|
||||
require_once __DIR__ . '/db/config.php';
|
||||
|
||||
$phpVersion = PHP_VERSION;
|
||||
$now = date('Y-m-d H:i:s');
|
||||
// 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>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>New Style</title>
|
||||
<?php
|
||||
// Read project preview data from environment
|
||||
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? '';
|
||||
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
|
||||
?>
|
||||
<?php if ($projectDescription): ?>
|
||||
<!-- Meta description -->
|
||||
<meta name="description" content='<?= htmlspecialchars($projectDescription) ?>' />
|
||||
<!-- Open Graph meta tags -->
|
||||
<meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<!-- Twitter meta tags -->
|
||||
<meta property="twitter:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<?php endif; ?>
|
||||
<?php if ($projectImageUrl): ?>
|
||||
<!-- Open Graph image -->
|
||||
<meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
||||
<!-- Twitter image -->
|
||||
<meta property="twitter:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
||||
<?php endif; ?>
|
||||
<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;700&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
:root {
|
||||
--bg-color-start: #6a11cb;
|
||||
--bg-color-end: #2575fc;
|
||||
--text-color: #ffffff;
|
||||
--card-bg-color: rgba(255, 255, 255, 0.01);
|
||||
--card-border-color: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: 'Inter', sans-serif;
|
||||
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
|
||||
color: var(--text-color);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
text-align: center;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
body::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
|
||||
animation: bg-pan 20s linear infinite;
|
||||
z-index: -1;
|
||||
}
|
||||
@keyframes bg-pan {
|
||||
0% { background-position: 0% 0%; }
|
||||
100% { background-position: 100% 100%; }
|
||||
}
|
||||
main {
|
||||
padding: 2rem;
|
||||
}
|
||||
.card {
|
||||
background: var(--card-bg-color);
|
||||
border: 1px solid var(--card-border-color);
|
||||
border-radius: 16px;
|
||||
padding: 2rem;
|
||||
backdrop-filter: blur(20px);
|
||||
-webkit-backdrop-filter: blur(20px);
|
||||
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
.loader {
|
||||
margin: 1.25rem auto 1.25rem;
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border: 3px solid rgba(255, 255, 255, 0.25);
|
||||
border-top-color: #fff;
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
@keyframes spin {
|
||||
from { transform: rotate(0deg); }
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
.hint {
|
||||
opacity: 0.9;
|
||||
}
|
||||
.sr-only {
|
||||
position: absolute;
|
||||
width: 1px; height: 1px;
|
||||
padding: 0; margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap; border: 0;
|
||||
}
|
||||
h1 {
|
||||
font-size: 3rem;
|
||||
font-weight: 700;
|
||||
margin: 0 0 1rem;
|
||||
letter-spacing: -1px;
|
||||
}
|
||||
p {
|
||||
margin: 0.5rem 0;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
code {
|
||||
background: rgba(0,0,0,0.2);
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
}
|
||||
footer {
|
||||
position: absolute;
|
||||
bottom: 1rem;
|
||||
font-size: 0.8rem;
|
||||
opacity: 0.7;
|
||||
}
|
||||
</style>
|
||||
<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>
|
||||
<main>
|
||||
<div class="card">
|
||||
<h1>Analyzing your requirements and generating your website…</h1>
|
||||
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
|
||||
<span class="sr-only">Loading…</span>
|
||||
|
||||
<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>
|
||||
<p class="hint"><?= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWizzy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.</p>
|
||||
<p class="hint">This page will update automatically as the plan is implemented.</p>
|
||||
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
|
||||
</div>
|
||||
</main>
|
||||
<footer>
|
||||
Page updated: <?= htmlspecialchars($now) ?> (UTC)
|
||||
|
||||
<!-- 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="modal-title fs-2" id="alarmModalLabel">Alarm!</h1>
|
||||
<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>
|
||||
|
||||
84
note.php
Normal file
84
note.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
// note.php
|
||||
require_once __DIR__ . '/db/config.php';
|
||||
|
||||
$pdo = db();
|
||||
$note_date = $_GET['date'] ?? date('Y-m-d');
|
||||
$message = '';
|
||||
$note_content = '';
|
||||
|
||||
// Handle form submission
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$content = $_POST['content'] ?? '';
|
||||
$date_to_save = $_POST['note_date'] ?? $note_date;
|
||||
|
||||
try {
|
||||
$stmt = $pdo->prepare(
|
||||
"INSERT INTO notes (note_date, content) VALUES (?, ?)
|
||||
ON DUPLICATE KEY UPDATE content = VALUES(content)"
|
||||
);
|
||||
$stmt->execute([$date_to_save, $content]);
|
||||
$message = 'Note saved successfully!';
|
||||
} catch (PDOException $e) {
|
||||
// In a real app, log this error instead of showing it to the user
|
||||
$message = 'Error saving note: ' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch existing note for the date
|
||||
$stmt = $pdo->prepare("SELECT content FROM notes WHERE note_date = ?");
|
||||
$stmt->execute([$note_date]);
|
||||
$note = $stmt->fetch();
|
||||
if ($note) {
|
||||
$note_content = $note['content'];
|
||||
}
|
||||
|
||||
$formatted_date = date("l, F j, Y", strtotime($note_date));
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Note for <?= htmlspecialchars($formatted_date) ?></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">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<header class="header-gradient text-white text-center">
|
||||
<div class="container">
|
||||
<h1>My Diary</h1>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main class="container mt-5">
|
||||
<div class="card p-4">
|
||||
<h2 class="mb-4"><?= htmlspecialchars($formatted_date) ?></h2>
|
||||
|
||||
<?php if ($message): ?>
|
||||
<div class="alert alert-success" role="alert">
|
||||
<?= htmlspecialchars($message) ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form method="POST" action="note.php?date=<?= htmlspecialchars($note_date) ?>">
|
||||
<input type="hidden" name="note_date" value="<?= htmlspecialchars($note_date) ?>">
|
||||
<div class="mb-3">
|
||||
<textarea class="form-control" name="content" id="noteContent" rows="15" placeholder="Start writing your thoughts..."><?= htmlspecialchars($note_content) ?></textarea>
|
||||
</div>
|
||||
<div class="d-flex justify-content-between">
|
||||
<a href="index.php" class="btn btn-secondary">Back to Dashboard</a>
|
||||
<button type="submit" class="btn btn-primary">Save Note</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
x
Reference in New Issue
Block a user