- Renamed index-simple.php to index.php (works better with Apache/production) - Renamed old index.php to index-streaming.php (kept as reference) - Simple version doesn't timeout, better for production servers - No streaming issues, cleaner user experience
410 lines
12 KiB
PHP
410 lines
12 KiB
PHP
<?php
|
|
/**
|
|
* Newsroom Reporter - Main Interface
|
|
* Allows users to generate daily newsroom reports
|
|
*/
|
|
|
|
require_once __DIR__ . '/config.php';
|
|
require_once __DIR__ . '/AuthMiddleware.php';
|
|
|
|
$auth = new AuthMiddleware();
|
|
$user = $auth->requireAuth();
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Newsroom Reporter - Generate Daily Reports</title>
|
|
<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=Montserrat:wght@400;500;600;700&display=swap" rel="stylesheet">
|
|
<style>
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
body {
|
|
font-family: 'Montserrat', sans-serif;
|
|
background: #000000;
|
|
min-height: 100vh;
|
|
padding: 20px;
|
|
}
|
|
|
|
.container {
|
|
max-width: 900px;
|
|
margin: 0 auto;
|
|
}
|
|
|
|
.header {
|
|
background: white;
|
|
border-radius: 12px;
|
|
padding: 30px;
|
|
margin-bottom: 30px;
|
|
box-shadow: 0 10px 30px rgba(0,0,0,0.2);
|
|
}
|
|
|
|
.header-top {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
.logo {
|
|
font-size: 3rem;
|
|
}
|
|
|
|
h1 {
|
|
color: #FFC407;
|
|
font-size: 2rem;
|
|
font-weight: 700;
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
.user-info {
|
|
text-align: right;
|
|
color: #666;
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
.user-email {
|
|
font-weight: 600;
|
|
color: #333;
|
|
}
|
|
|
|
.btn-logout {
|
|
background: #ff4444;
|
|
color: white;
|
|
border: none;
|
|
padding: 8px 20px;
|
|
border-radius: 6px;
|
|
cursor: pointer;
|
|
font-family: 'Montserrat', sans-serif;
|
|
font-weight: 600;
|
|
margin-top: 10px;
|
|
}
|
|
|
|
.btn-logout:hover {
|
|
background: #cc0000;
|
|
}
|
|
|
|
.subtitle {
|
|
color: #666;
|
|
font-size: 1rem;
|
|
}
|
|
|
|
.card {
|
|
background: white;
|
|
border-radius: 12px;
|
|
padding: 40px;
|
|
box-shadow: 0 10px 30px rgba(0,0,0,0.2);
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
.form-group {
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
label {
|
|
display: block;
|
|
font-weight: 600;
|
|
color: #333;
|
|
margin-bottom: 10px;
|
|
font-size: 1.1rem;
|
|
}
|
|
|
|
input[type="text"] {
|
|
width: 100%;
|
|
padding: 15px;
|
|
border: 2px solid #e0e0e0;
|
|
border-radius: 8px;
|
|
font-family: 'Montserrat', sans-serif;
|
|
font-size: 1rem;
|
|
transition: border-color 0.3s;
|
|
}
|
|
|
|
input[type="text"]:focus {
|
|
outline: none;
|
|
border-color: #FFC407;
|
|
}
|
|
|
|
.hint {
|
|
color: #999;
|
|
font-size: 0.9rem;
|
|
margin-top: 8px;
|
|
}
|
|
|
|
.btn-generate {
|
|
background: #FFC407;
|
|
color: #000;
|
|
border: none;
|
|
padding: 18px 40px;
|
|
border-radius: 8px;
|
|
font-family: 'Montserrat', sans-serif;
|
|
font-weight: 700;
|
|
font-size: 1.1rem;
|
|
cursor: pointer;
|
|
width: 100%;
|
|
transition: transform 0.3s;
|
|
box-shadow: 0 4px 15px rgba(255, 196, 7, 0.3);
|
|
}
|
|
|
|
.btn-generate:hover:not(:disabled) {
|
|
transform: translateY(-3px);
|
|
}
|
|
|
|
.btn-generate:disabled {
|
|
opacity: 0.6;
|
|
cursor: not-allowed;
|
|
}
|
|
|
|
#output-container {
|
|
display: none;
|
|
background: #1a1a1a;
|
|
border-radius: 12px;
|
|
padding: 20px;
|
|
margin-top: 20px;
|
|
}
|
|
|
|
#output-container.show {
|
|
display: block;
|
|
}
|
|
|
|
.output-header {
|
|
color: #FFC407;
|
|
font-weight: 700;
|
|
font-size: 1.2rem;
|
|
margin-bottom: 15px;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 10px;
|
|
}
|
|
|
|
.spinner {
|
|
border: 3px solid #333;
|
|
border-top: 3px solid #FFC407;
|
|
border-radius: 50%;
|
|
width: 20px;
|
|
height: 20px;
|
|
animation: spin 1s linear infinite;
|
|
}
|
|
|
|
@keyframes spin {
|
|
0% { transform: rotate(0deg); }
|
|
100% { transform: rotate(360deg); }
|
|
}
|
|
|
|
#output {
|
|
background: #0d0d0d;
|
|
color: #FFC407;
|
|
padding: 20px;
|
|
border-radius: 8px;
|
|
font-family: 'Courier New', monospace;
|
|
font-size: 0.9rem;
|
|
line-height: 1.6;
|
|
max-height: 500px;
|
|
overflow-y: auto;
|
|
white-space: pre-wrap;
|
|
word-wrap: break-word;
|
|
}
|
|
|
|
.success-message {
|
|
background: #4CAF50;
|
|
color: white;
|
|
padding: 20px;
|
|
border-radius: 8px;
|
|
margin-top: 20px;
|
|
display: none;
|
|
}
|
|
|
|
.success-message.show {
|
|
display: block;
|
|
}
|
|
|
|
.btn-download {
|
|
background: #FFC407;
|
|
color: #000;
|
|
border: none;
|
|
padding: 15px 30px;
|
|
border-radius: 8px;
|
|
font-family: 'Montserrat', sans-serif;
|
|
font-weight: 700;
|
|
font-size: 1rem;
|
|
cursor: pointer;
|
|
margin-top: 15px;
|
|
text-decoration: none;
|
|
display: inline-block;
|
|
}
|
|
|
|
.btn-download:hover {
|
|
background: #ff9500;
|
|
}
|
|
|
|
.error-message {
|
|
background: #ff4444;
|
|
color: white;
|
|
padding: 20px;
|
|
border-radius: 8px;
|
|
margin-top: 20px;
|
|
display: none;
|
|
}
|
|
|
|
.error-message.show {
|
|
display: block;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<div class="header">
|
|
<div class="header-top">
|
|
<div>
|
|
<div class="logo">📰</div>
|
|
<h1>Newsroom Reporter</h1>
|
|
<p class="subtitle">Generate beautiful PDF reports from your daily newsroom sheet</p>
|
|
</div>
|
|
<div class="user-info">
|
|
<?php if ($auth->isSSOEnabled()): ?>
|
|
Signed in as:<br>
|
|
<span class="user-email"><?php echo htmlspecialchars($user['preferred_username'] ?? $user['upn'] ?? $user['email'] ?? 'User'); ?></span>
|
|
<br>
|
|
<button class="btn-logout" onclick="logout()">Sign Out</button>
|
|
<?php else: ?>
|
|
<strong>Dev Mode</strong> (SSO Disabled)
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<form id="reportForm">
|
|
<div class="form-group">
|
|
<label for="reportDate">📅 Select Report Date</label>
|
|
<input
|
|
type="text"
|
|
id="reportDate"
|
|
name="reportDate"
|
|
placeholder="Monday, January 6"
|
|
required
|
|
>
|
|
<p class="hint">Enter the date in the format: "Day, Month Date" (e.g., Tuesday, January 7)</p>
|
|
</div>
|
|
|
|
<button type="submit" class="btn-generate" id="btnGenerate">
|
|
🚀 Generate Report
|
|
</button>
|
|
</form>
|
|
|
|
<div id="output-container">
|
|
<div class="output-header">
|
|
<div class="spinner" id="spinner"></div>
|
|
<span>Processing...</span>
|
|
</div>
|
|
<div id="output"></div>
|
|
</div>
|
|
|
|
<div class="success-message" id="successMessage">
|
|
✅ Report generated successfully!
|
|
<br>
|
|
<a href="#" id="downloadLink" class="btn-download">📥 Download PDF Report</a>
|
|
</div>
|
|
|
|
<div class="error-message" id="errorMessage">
|
|
❌ <span id="errorText"></span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
const form = document.getElementById('reportForm');
|
|
const btnGenerate = document.getElementById('btnGenerate');
|
|
const outputContainer = document.getElementById('output-container');
|
|
const output = document.getElementById('output');
|
|
const successMessage = document.getElementById('successMessage');
|
|
const errorMessage = document.getElementById('errorMessage');
|
|
const errorText = document.getElementById('errorText');
|
|
const downloadLink = document.getElementById('downloadLink');
|
|
const spinner = document.getElementById('spinner');
|
|
|
|
// Set today's date as default
|
|
const today = new Date();
|
|
const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
|
const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
|
|
document.getElementById('reportDate').value = `${days[today.getDay()]}, ${months[today.getMonth()]} ${today.getDate()}`;
|
|
|
|
form.addEventListener('submit', async (e) => {
|
|
e.preventDefault();
|
|
|
|
const dateInput = document.getElementById('reportDate').value.trim();
|
|
if (!dateInput) {
|
|
alert('Please enter a date');
|
|
return;
|
|
}
|
|
|
|
// Reset UI
|
|
btnGenerate.disabled = true;
|
|
btnGenerate.textContent = '⏳ Generating...';
|
|
output.textContent = '';
|
|
outputContainer.classList.add('show');
|
|
successMessage.classList.remove('show');
|
|
errorMessage.classList.remove('show');
|
|
spinner.style.display = 'block';
|
|
|
|
try {
|
|
const response = await fetch('generate.php', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({ date: dateInput })
|
|
});
|
|
|
|
const reader = response.body.getReader();
|
|
const decoder = new TextDecoder();
|
|
|
|
while (true) {
|
|
const { value, done } = await reader.read();
|
|
if (done) break;
|
|
|
|
const chunk = decoder.decode(value);
|
|
output.textContent += chunk;
|
|
output.scrollTop = output.scrollHeight;
|
|
}
|
|
|
|
// Check if successful
|
|
const result = JSON.parse(output.textContent.split('\n').pop());
|
|
|
|
if (result.success) {
|
|
spinner.style.display = 'none';
|
|
successMessage.classList.add('show');
|
|
downloadLink.href = 'download.php?file=' + encodeURIComponent(result.filename);
|
|
} else {
|
|
throw new Error(result.error || 'Generation failed');
|
|
}
|
|
|
|
} catch (error) {
|
|
spinner.style.display = 'none';
|
|
errorText.textContent = error.message;
|
|
errorMessage.classList.add('show');
|
|
console.error('Error:', error);
|
|
} finally {
|
|
btnGenerate.disabled = false;
|
|
btnGenerate.textContent = '🚀 Generate Report';
|
|
}
|
|
});
|
|
|
|
function logout() {
|
|
fetch('auth.php', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ action: 'logout' })
|
|
}).then(() => {
|
|
window.location.reload();
|
|
});
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|