Compare commits

..

5 Commits

Author SHA1 Message Date
Flatlogic Bot
a31ae61407 Auto commit: 2025-11-21T19:17:14.263Z 2025-11-21 19:17:14 +00:00
Flatlogic Bot
0aaa47eb72 Auto commit: 2025-11-21T19:13:57.646Z 2025-11-21 19:13:57 +00:00
Flatlogic Bot
494f12a424 Auto commit: 2025-11-21T18:47:34.824Z 2025-11-21 18:47:34 +00:00
Flatlogic Bot
6a4e5985e5 Auto commit: 2025-11-21T18:29:31.267Z 2025-11-21 18:29:31 +00:00
Flatlogic Bot
41111c794f tick and clock 2025-11-21 18:15:18 +00:00
14 changed files with 2936 additions and 140 deletions

119
api/alarms.php Normal file
View File

@ -0,0 +1,119 @@
<?php
require_once __DIR__ . '/../db/config.php';
header('Content-Type: application/json');
$response = ['success' => false, 'error' => 'Invalid request'];
$pdo = db();
$action = $_GET['action'] ?? $_POST['action'] ?? '';
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $action === 'create') {
$alarm_time = $_POST['alarm_time'] ?? null;
$label = $_POST['label'] ?? '';
if ($alarm_time) {
try {
$pdo->beginTransaction();
// 1. Create a new note
$noteStmt = $pdo->prepare("INSERT INTO notes (content) VALUES (?)");
$noteStmt->execute(['']);
$noteId = $pdo->lastInsertId();
// 2. Create the alarm and link it to the new note
$alarmStmt = $pdo->prepare("INSERT INTO alarms (alarm_time, label, note_id, is_active) VALUES (?, ?, ?, 1)");
$alarmStmt->execute([$alarm_time, $label, $noteId]);
$alarmId = $pdo->lastInsertId();
$pdo->commit();
$response = [
'success' => true,
'alarm' => [
'id' => $alarmId,
'alarm_time' => $alarm_time,
'label' => $label,
'is_active' => 1,
'note_id' => $noteId
]
];
} catch (PDOException $e) {
$pdo->rollBack();
$response['error'] = 'Database error: ' . $e->getMessage();
}
} else {
$response['error'] = 'Alarm time is required.';
}
}
elseif ($_SERVER['REQUEST_METHOD'] === 'GET' && $action === 'get') {
try {
$stmt = $pdo->query("SELECT id, alarm_time, label, note_id, is_active FROM alarms ORDER BY alarm_time");
$alarms = $stmt->fetchAll(PDO::FETCH_ASSOC);
$response = ['success' => true, 'alarms' => $alarms];
} catch (PDOException $e) {
$response['error'] = 'Database error: ' . $e->getMessage();
}
}
elseif ($_SERVER['REQUEST_METHOD'] === 'GET' && $action === 'delete') {
$id = $_GET['id'] ?? null;
if ($id) {
try {
$stmt = $pdo->prepare("DELETE FROM alarms WHERE id = ?");
$stmt->execute([$id]);
$response = ['success' => true];
} catch (PDOException $e) {
$response['error'] = 'Database error: ' . $e->getMessage();
}
} else {
$response['error'] = 'ID is required.';
}
}
elseif ($_SERVER['REQUEST_METHOD'] === 'POST' && $action === 'toggle') {
$id = $_POST['id'] ?? null;
$is_active = isset($_POST['is_active']) ? (int)$_POST['is_active'] : null;
if ($id && $is_active !== null) {
try {
$stmt = $pdo->prepare("UPDATE alarms SET is_active = ? WHERE id = ?");
$stmt->execute([$is_active, $id]);
$response = ['success' => true];
} catch (PDOException $e) {
$response['error'] = 'Database error: ' . $e->getMessage();
}
} else {
$response['error'] = 'ID and active status are required.';
}
}
elseif ($_SERVER['REQUEST_METHOD'] === 'GET' && $action === 'check') {
try {
$pdo->beginTransaction();
$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) {
$alarmIds = array_map(fn($a) => $a['id'], $alarms);
$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['error'] = 'Database error: ' . $e->getMessage();
}
}
echo json_encode($response);

19
api/fetch_bell_icon.php Normal file
View File

@ -0,0 +1,19 @@
<?php
require_once __DIR__.'/../includes/pexels.php';
$q = 'bell';
$orientation = 'square';
$url = 'https://api.pexels.com/v1/search?query=' . urlencode($q) . '&orientation=' . urlencode($orientation) . '&per_page=1&page=1';
$data = pexels_get($url);
if (!$data || empty($data['photos'])) {
// Fallback to a generic image if Pexels fails
$src = 'https://picsum.photos/200';
$target = __DIR__ . '/../assets/images/bell.png';
download_to($src, $target);
echo json_encode(['success' => true, 'local' => 'assets/images/bell.png']);
exit;
}
$photo = $data['photos'][0];
$src = $photo['src']['tiny'] ?? ($photo['src']['small'] ?? $photo['src']['original']);
$target = __DIR__ . '/../assets/images/bell.png';
download_to($src, $target);
echo json_encode(['success' => true, 'local' => 'assets/images/bell.png']);

80
assets/css/custom.css Normal file
View 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;
}

BIN
assets/images/bell.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

283
assets/js/main.js Normal file
View File

@ -0,0 +1,283 @@
document.addEventListener('DOMContentLoaded', function () {
const alarmForm = document.getElementById('createAlarmForm');
const alarmsList = document.getElementById('alarmList');
const alarmModal = new bootstrap.Modal(document.getElementById('alarmModal'));
const alarmSound = document.getElementById('alarmSound');
const dismissAlarmBtn = document.getElementById('dismissAlarmBtn');
const enableNotificationsBtn = document.getElementById('enable-notifications');
const notificationPermissionCard = document.getElementById('notification-permission-card');
// --- Notification Permission Handling ---
function handleNotificationPermission(permission) {
if (permission === 'granted') {
if (notificationPermissionCard) {
notificationPermissionCard.style.display = 'none';
}
} else if (permission === 'denied') {
if (notificationPermissionCard) {
notificationPermissionCard.innerHTML = '<div class="card-body text-center text-danger">You have blocked notifications. To use alarms, you need to enable them in your browser settings.</div>';
}
} else {
if (notificationPermissionCard) {
notificationPermissionCard.style.display = 'block';
}
}
}
// Check initial notification permission status
if ('Notification' in window) {
handleNotificationPermission(Notification.permission);
} else {
// Notifications not supported
if (notificationPermissionCard) {
notificationPermissionCard.innerHTML = '<div class="card-body text-center text-muted">This browser does not support desktop notifications.</div>';
}
}
// Request notification permission on button click
if (enableNotificationsBtn) {
enableNotificationsBtn.addEventListener('click', () => {
Notification.requestPermission().then(permission => {
handleNotificationPermission(permission);
});
});
}
// --- Alarm Logic ---
// Function to fetch and display alarms
const fetchAlarms = () => {
fetch('/api/alarms.php?action=get')
.then(response => response.json())
.then(data => {
if (data.success && data.alarms) {
// Clear only if there are alarms to show
if(data.alarms.length > 0) {
alarmsList.innerHTML = '';
}
document.getElementById('noAlarmsMessage')?.remove();
data.alarms.forEach(alarm => {
addAlarmToList(alarm);
});
}
});
};
// Function to add a single alarm to the list
const addAlarmToList = (alarm) => {
const { id, alarm_time, label, is_active, note_id } = alarm;
const listItem = document.createElement('li');
listItem.className = 'list-group-item d-flex justify-content-between align-items-center';
listItem.dataset.id = id;
const alarmDisplay = document.createElement('div');
alarmDisplay.className = 'd-flex align-items-center';
const switchDiv = document.createElement('div');
switchDiv.className = 'form-check form-switch me-3';
const switchInput = document.createElement('input');
switchInput.className = 'form-check-input toggle-alarm-switch';
switchInput.type = 'checkbox';
switchInput.role = 'switch';
switchInput.id = `toggle-${id}`;
switchInput.checked = !!parseInt(is_active);
switchInput.addEventListener('change', () => handleToggleAlarm(id, switchInput.checked));
const switchLabel = document.createElement('label');
switchLabel.className = 'form-check-label';
switchLabel.setAttribute('for', `toggle-${id}`);
switchDiv.appendChild(switchInput);
switchDiv.appendChild(switchLabel);
const timeDiv = document.createElement('div');
const timeSpan = document.createElement('span');
timeSpan.className = 'fw-bold fs-5';
timeSpan.textContent = new Date(`1970-01-01T${alarm_time}`).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', hour12: true });
const labelSpan = document.createElement('span');
labelSpan.className = 'text-muted ms-2';
labelSpan.textContent = label;
timeDiv.appendChild(timeSpan);
timeDiv.appendChild(labelSpan);
alarmDisplay.appendChild(switchDiv);
alarmDisplay.appendChild(timeDiv);
const deleteForm = document.createElement('form');
deleteForm.className = 'delete-alarm-form';
deleteForm.addEventListener('submit', (e) => {
e.preventDefault();
handleDeleteAlarm(id);
});
const hiddenAction = document.createElement('input');
hiddenAction.type = 'hidden';
hiddenAction.name = 'action';
hiddenAction.value = 'delete';
const hiddenId = document.createElement('input');
hiddenId.type = 'hidden';
hiddenId.name = 'alarm_id';
hiddenId.value = id;
const deleteButton = document.createElement('button');
deleteButton.type = 'submit';
deleteButton.className = 'btn btn-sm btn-outline-danger';
deleteButton.innerHTML = '<i data-feather="trash-2" class="align-text-bottom"></i>';
deleteForm.appendChild(hiddenAction);
deleteForm.appendChild(hiddenId);
deleteForm.appendChild(deleteButton);
listItem.appendChild(alarmDisplay);
listItem.appendChild(deleteForm);
// Remove "no alarms" message if it exists
const noAlarmsMsg = document.getElementById('noAlarmsMessage');
if (noAlarmsMsg) {
noAlarmsMsg.remove();
}
alarmsList.appendChild(listItem);
feather.replace();
};
// Handle form submission to create a new alarm
if (alarmForm) {
alarmForm.addEventListener('submit', function (e) {
e.preventDefault();
const time = document.getElementById('alarmTime').value;
const label = document.getElementById('alarmLabel').value;
if (!time) {
alert('Please select a time for the alarm.');
return;
}
const formData = new FormData();
formData.append('alarm_time', time);
formData.append('label', label);
fetch('/api/alarms.php?action=create', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
if (data.success) {
addAlarmToList(data.alarm);
alarmForm.reset();
} else {
alert('Error: ' + (data.error || 'Could not create alarm.'));
}
});
});
}
// Handle deleting an alarm
const handleDeleteAlarm = (id) => {
if (!confirm('Are you sure you want to delete this alarm?')) return;
fetch(`/api/alarms.php?action=delete&id=${id}`, { method: 'GET' })
.then(response => response.json())
.then(data => {
if (data.success) {
document.querySelector(`li[data-id='${id}']`).remove();
if (alarmsList.children.length === 0) {
alarmsList.innerHTML = '<li class="list-group-item text-center text-muted" id="noAlarmsMessage">No alarms set yet.</li>';
}
} else {
alert('Error: ' + (data.error || 'Could not delete alarm.'));
}
});
};
// Handle toggling an alarm's active state
const handleToggleAlarm = (id, isActive) => {
const formData = new FormData();
formData.append('id', id);
formData.append('is_active', isActive ? 1 : 0);
fetch('/api/alarms.php?action=toggle', {
method: 'POST',
body: formData
}).then(response => response.json())
.then(data => {
if (!data.success) {
alert('Error updating alarm status.');
// Revert the toggle switch if the server update fails
const toggleInput = document.getElementById(`toggle-${id}`);
if(toggleInput) {
toggleInput.checked = !isActive;
}
}
});
};
// Function to check for due alarms
const checkAlarms = () => {
fetch('/api/alarms.php?action=check')
.then(response => response.json())
.then(data => {
if (data.success && data.alarms && data.alarms.length > 0) {
data.alarms.forEach(alarm => {
showNotification(alarm);
// Update the toggle on the main page to off
const alarmToggle = document.querySelector(`#toggle-${alarm.id}`);
if (alarmToggle) {
alarmToggle.checked = false;
}
});
}
});
};
// Function to show notification
const showNotification = (alarm) => {
const alarmTime = new Date(`1970-01-01T${alarm.alarm_time}`).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
const notificationTitle = `Alarm: ${alarm.label || alarmTime}`;
const notificationBody = 'Time to write your notes. Click here!';
const bellIcon = '/assets/images/bell.png';
const alarmSoundSrc = '/assets/sounds/alarm.mp3';
// Use browser notification if permission is granted
if ('Notification' in window && Notification.permission === 'granted') {
const notification = new Notification(notificationTitle, {
body: notificationBody,
icon: bellIcon,
requireInteraction: true
});
notification.onclick = () => {
window.open(`note.php?id=${alarm.note_id}`, '_blank');
notification.close();
};
// Play sound along with notification
const audio = new Audio(alarmSoundSrc);
audio.play().catch(e => console.error("Audio playback failed:", e));
} else {
// Fallback to modal
document.getElementById('alarmModalMessage').textContent = `It's time for your alarm: ${alarm.label || alarmTime}`;
const audio = document.getElementById('alarmSound');
if (audio) {
audio.src = alarmSoundSrc; // Ensure src is set
audio.play().catch(e => console.error("Audio playback failed:", e));
}
alarmModal.show();
}
dismissAlarmBtn.onclick = () => {
const audio = document.getElementById('alarmSound');
if (audio) {
audio.pause();
audio.currentTime = 0;
}
alarmModal.hide();
};
};
// Initial fetch and periodic check
fetchAlarms();
setInterval(checkAlarms, 5000); // Check every 5 seconds
});

2151
assets/sounds/alarm.mp3 Normal file

File diff suppressed because one or more lines are too long

View File

View File

@ -15,3 +15,34 @@ function db() {
} }
return $pdo; 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();

View 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
);

View 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
);

View File

@ -0,0 +1 @@
ALTER TABLE alarms ADD COLUMN note_id INT NULL, ADD CONSTRAINT fk_note_id FOREIGN KEY (note_id) REFERENCES notes(id) ON DELETE CASCADE;

25
includes/pexels.php Normal file
View File

@ -0,0 +1,25 @@
<?php
function pexels_key() {
$k = getenv('PEXELS_KEY');
return $k && strlen($k) > 0 ? $k : 'Vc99rnmOhHhJAbgGQoKLZtsaIVfkeownoQNbTj78VemUjKh08ZYRbf18';
}
function pexels_get($url) {
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [ 'Authorization: '. pexels_key() ],
CURLOPT_TIMEOUT => 15,
]);
$resp = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($code >= 200 && $code < 300 && $resp) return json_decode($resp, true);
return null;
}
function download_to($srcUrl, $destPath) {
$data = file_get_contents($srcUrl);
if ($data === false) return false;
if (!is_dir(dirname($destPath))) mkdir(dirname($destPath), 0775, true);
return file_put_contents($destPath, $data) !== false;
}

258
index.php
View File

@ -1,150 +1,138 @@
<?php <?php
declare(strict_types=1); require_once __DIR__ . '/db/config.php';
@ini_set('display_errors', '1');
@error_reporting(E_ALL);
@date_default_timezone_set('UTC');
$phpVersion = PHP_VERSION; // Fetch all alarms for initial display
$now = date('Y-m-d H:i:s'); 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"> <html lang="en">
<head> <head>
<meta charset="utf-8" /> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>New Style</title> <title>Alarm & Note App</title>
<?php <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
// Read project preview data from environment <link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
$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; ?>
<link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <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"> <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap" rel="stylesheet">
<style> <script src="https://unpkg.com/feather-icons"></script>
: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>
</head> </head>
<body> <body>
<main>
<div class="card"> <header class="header-gradient text-white text-center">
<h1>Analyzing your requirements and generating your website…</h1> <div class="container">
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes"> <h1>Alarm Dashboard</h1>
<span class="sr-only">Loading…</span> <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">
<!-- Notifications Permission Button -->
<div class="card mb-4" id="notification-permission-card">
<div class="card-body text-center">
<p class="card-text">For alarms to work even when the browser is in the background, please enable notifications.</p>
<button id="enable-notifications" class="btn btn-primary">Enable Notifications</button>
</div>
</div>
<!-- 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>
<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> </div>
</main> </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="my-4">Alarm Clock</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>&copy; <?= date('Y') ?> Alarm & Note App</p>
</footer> </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> </body>
</html> </html>

84
note.php Normal file
View 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>