volt-newsroom-scraper-report/web/simple-index.php
DJP 2bdc5e1549 Add MAMP-friendly simplified interface
- Created index-simple.php (better for MAMP buffering)
- Created generate-simple.php (waits for completion, no streaming)
- Shows loading spinner instead of trying to stream output
- Works perfectly with MAMP's output buffering
- Added test pages for debugging
- Use index-simple.php for MAMP, index.php for production Apache
2026-01-06 14:07:39 -05:00

119 lines
3.4 KiB
PHP

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once __DIR__ . '/config.php';
require_once __DIR__ . '/AuthMiddleware.php';
$auth = new AuthMiddleware();
$user = $auth->requireAuth();
?>
<!DOCTYPE html>
<html>
<head>
<title>Newsroom Reporter Test</title>
<style>
body {
font-family: Arial, sans-serif;
background: #000;
color: #FFC407;
padding: 20px;
}
.container {
max-width: 800px;
margin: 0 auto;
background: #1a1a1a;
padding: 30px;
border-radius: 10px;
}
input {
width: 100%;
padding: 10px;
margin: 10px 0;
font-size: 16px;
}
button {
background: #FFC407;
color: #000;
border: none;
padding: 15px 30px;
font-size: 16px;
font-weight: bold;
cursor: pointer;
border-radius: 5px;
}
#output {
background: #000;
color: #FFC407;
padding: 20px;
margin-top: 20px;
border-radius: 5px;
font-family: monospace;
white-space: pre-wrap;
display: none;
}
</style>
</head>
<body>
<div class="container">
<h1>📰 Newsroom Reporter</h1>
<p>Logged in as: <?php echo htmlspecialchars($user['preferred_username'] ?? $user['name'] ?? 'User'); ?></p>
<form id="reportForm">
<label>Enter Date:</label>
<input type="text" id="reportDate" value="Tuesday, January 6" required>
<button type="submit">Generate Report</button>
</form>
<div id="output"></div>
</div>
<script>
console.log('JavaScript loaded successfully');
document.getElementById('reportForm').addEventListener('submit', async (e) => {
e.preventDefault();
console.log('Form submitted');
const date = document.getElementById('reportDate').value;
const output = document.getElementById('output');
output.style.display = 'block';
output.textContent = 'Starting...\n';
try {
console.log('Fetching generate.php...');
const response = await fetch('generate.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ date: date })
});
console.log('Response received, reading stream...');
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { value, done } = await reader.read();
if (done) {
console.log('Stream complete');
break;
}
const chunk = decoder.decode(value);
output.textContent += chunk;
output.scrollTop = output.scrollHeight;
}
console.log('Done!');
} catch (error) {
console.error('Error:', error);
output.textContent += '\n\nERROR: ' + error.message;
}
});
console.log('Event listener attached');
</script>
</body>
</html>