- 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
404 lines
12 KiB
PHP
404 lines
12 KiB
PHP
<?php
|
|
/**
|
|
* Newsroom Reporter - Simplified Interface (Better for MAMP)
|
|
* Shows loading spinner, fetches complete result when done
|
|
*/
|
|
|
|
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</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(255, 196, 7, 0.3);
|
|
}
|
|
|
|
.logo {
|
|
font-size: 3rem;
|
|
text-align: center;
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
h1 {
|
|
color: #FFC407;
|
|
font-size: 2rem;
|
|
font-weight: 700;
|
|
text-align: center;
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
.subtitle {
|
|
color: #666;
|
|
font-size: 1rem;
|
|
text-align: center;
|
|
}
|
|
|
|
.user-info {
|
|
text-align: center;
|
|
color: #666;
|
|
font-size: 0.9rem;
|
|
margin-top: 15px;
|
|
padding-top: 15px;
|
|
border-top: 1px solid #eee;
|
|
}
|
|
|
|
.card {
|
|
background: white;
|
|
border-radius: 12px;
|
|
padding: 40px;
|
|
box-shadow: 0 10px 30px rgba(255, 196, 7, 0.3);
|
|
}
|
|
|
|
.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;
|
|
}
|
|
|
|
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: all 0.3s;
|
|
}
|
|
|
|
.btn-generate:hover:not(:disabled) {
|
|
transform: translateY(-3px);
|
|
box-shadow: 0 5px 20px rgba(255, 196, 7, 0.4);
|
|
}
|
|
|
|
.btn-generate:disabled {
|
|
opacity: 0.6;
|
|
cursor: not-allowed;
|
|
}
|
|
|
|
.loading-container {
|
|
display: none;
|
|
text-align: center;
|
|
padding: 40px;
|
|
background: #1a1a1a;
|
|
border-radius: 12px;
|
|
margin-top: 20px;
|
|
}
|
|
|
|
.loading-container.show {
|
|
display: block;
|
|
}
|
|
|
|
.spinner-large {
|
|
border: 6px solid #333;
|
|
border-top: 6px solid #FFC407;
|
|
border-radius: 50%;
|
|
width: 60px;
|
|
height: 60px;
|
|
animation: spin 1s linear infinite;
|
|
margin: 0 auto 20px;
|
|
}
|
|
|
|
@keyframes spin {
|
|
0% { transform: rotate(0deg); }
|
|
100% { transform: rotate(360deg); }
|
|
}
|
|
|
|
.loading-text {
|
|
color: #FFC407;
|
|
font-size: 1.2rem;
|
|
font-weight: 600;
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
.loading-details {
|
|
color: #999;
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
.success-box {
|
|
display: none;
|
|
background: #1a1a1a;
|
|
border: 2px solid #4CAF50;
|
|
border-radius: 12px;
|
|
padding: 30px;
|
|
margin-top: 20px;
|
|
text-align: center;
|
|
}
|
|
|
|
.success-box.show {
|
|
display: block;
|
|
}
|
|
|
|
.success-icon {
|
|
font-size: 3rem;
|
|
margin-bottom: 15px;
|
|
}
|
|
|
|
.success-text {
|
|
color: #4CAF50;
|
|
font-size: 1.3rem;
|
|
font-weight: 600;
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
.btn-download {
|
|
background: #FFC407;
|
|
color: #000;
|
|
border: none;
|
|
padding: 15px 40px;
|
|
border-radius: 8px;
|
|
font-family: 'Montserrat', sans-serif;
|
|
font-weight: 700;
|
|
font-size: 1rem;
|
|
cursor: pointer;
|
|
text-decoration: none;
|
|
display: inline-block;
|
|
transition: all 0.3s;
|
|
}
|
|
|
|
.btn-download:hover {
|
|
transform: translateY(-3px);
|
|
box-shadow: 0 5px 20px rgba(255, 196, 7, 0.4);
|
|
}
|
|
|
|
.error-box {
|
|
display: none;
|
|
background: #1a1a1a;
|
|
border: 2px solid #ff4444;
|
|
border-radius: 12px;
|
|
padding: 30px;
|
|
margin-top: 20px;
|
|
}
|
|
|
|
.error-box.show {
|
|
display: block;
|
|
}
|
|
|
|
.error-icon {
|
|
font-size: 3rem;
|
|
text-align: center;
|
|
margin-bottom: 15px;
|
|
}
|
|
|
|
.error-text {
|
|
color: #ff4444;
|
|
font-size: 1.1rem;
|
|
font-weight: 600;
|
|
margin-bottom: 15px;
|
|
text-align: center;
|
|
}
|
|
|
|
.error-output {
|
|
background: #0d0d0d;
|
|
color: #ff4444;
|
|
padding: 20px;
|
|
border-radius: 8px;
|
|
font-family: 'Courier New', monospace;
|
|
font-size: 0.85rem;
|
|
max-height: 300px;
|
|
overflow-y: auto;
|
|
white-space: pre-wrap;
|
|
}
|
|
|
|
.btn-back {
|
|
background: #333;
|
|
color: #FFC407;
|
|
border: none;
|
|
padding: 12px 30px;
|
|
border-radius: 8px;
|
|
font-family: 'Montserrat', sans-serif;
|
|
font-weight: 600;
|
|
cursor: pointer;
|
|
margin-top: 15px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<div class="header">
|
|
<div class="logo">📰</div>
|
|
<h1>Newsroom Reporter</h1>
|
|
<p class="subtitle">Generate beautiful PDF reports from your daily newsroom sheet</p>
|
|
<div class="user-info">
|
|
<?php if ($auth->isSSOEnabled()): ?>
|
|
Signed in as: <strong><?php echo htmlspecialchars($user['preferred_username'] ?? $user['upn'] ?? 'User'); ?></strong>
|
|
<?php else: ?>
|
|
<strong>Dev Mode</strong> (SSO Disabled)
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card" id="formCard">
|
|
<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 format: "Day, Month Date" (e.g., Tuesday, January 7)</p>
|
|
</div>
|
|
|
|
<button type="submit" class="btn-generate" id="btnGenerate">
|
|
🚀 Generate Report
|
|
</button>
|
|
</form>
|
|
</div>
|
|
|
|
<div class="loading-container" id="loadingContainer">
|
|
<div class="spinner-large"></div>
|
|
<div class="loading-text">Generating Report...</div>
|
|
<div class="loading-details">
|
|
This may take 2-3 minutes<br>
|
|
Extracting URLs, scraping content, and generating PDF
|
|
</div>
|
|
</div>
|
|
|
|
<div class="success-box" id="successBox">
|
|
<div class="success-icon">✅</div>
|
|
<div class="success-text">Report Generated Successfully!</div>
|
|
<a href="#" id="downloadLink" class="btn-download">📥 Download PDF Report</a>
|
|
<br>
|
|
<button class="btn-back" onclick="location.reload()">Generate Another Report</button>
|
|
</div>
|
|
|
|
<div class="error-box" id="errorBox">
|
|
<div class="error-icon">❌</div>
|
|
<div class="error-text" id="errorText">Error generating report</div>
|
|
<div class="error-output" id="errorOutput"></div>
|
|
<button class="btn-back" onclick="location.reload()">Try Again</button>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
// 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()}`;
|
|
|
|
document.getElementById('reportForm').addEventListener('submit', async (e) => {
|
|
e.preventDefault();
|
|
|
|
const dateInput = document.getElementById('reportDate').value.trim();
|
|
if (!dateInput) {
|
|
alert('Please enter a date');
|
|
return;
|
|
}
|
|
|
|
// Show loading, hide form
|
|
document.getElementById('formCard').style.display = 'none';
|
|
document.getElementById('loadingContainer').classList.add('show');
|
|
document.getElementById('successBox').classList.remove('show');
|
|
document.getElementById('errorBox').classList.remove('show');
|
|
|
|
try {
|
|
console.log('Sending request to generate-simple.php...');
|
|
|
|
const response = await fetch('generate-simple.php', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({ date: dateInput })
|
|
});
|
|
|
|
console.log('Response received');
|
|
const result = await response.json();
|
|
console.log('Result:', result);
|
|
|
|
document.getElementById('loadingContainer').classList.remove('show');
|
|
|
|
if (result.success) {
|
|
document.getElementById('downloadLink').href = 'download.php?file=' + encodeURIComponent(result.filename);
|
|
document.getElementById('successBox').classList.add('show');
|
|
} else {
|
|
// Show the actual Python output for debugging
|
|
const errorDetails = result.output || result.error || 'Unknown error';
|
|
throw new Error(errorDetails);
|
|
}
|
|
|
|
} catch (error) {
|
|
console.error('Error:', error);
|
|
document.getElementById('loadingContainer').classList.remove('show');
|
|
document.getElementById('errorText').textContent = 'Report Generation Failed';
|
|
|
|
// Show the full error output
|
|
if (error.message && error.message.length > 100) {
|
|
document.getElementById('errorOutput').textContent = error.message;
|
|
} else {
|
|
document.getElementById('errorOutput').textContent = error.message + '\n\n' + (error.stack || 'No additional details');
|
|
}
|
|
|
|
document.getElementById('errorBox').classList.add('show');
|
|
}
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|