392 lines
16 KiB
PHP
392 lines
16 KiB
PHP
<?php
|
|
extract($viewData);
|
|
?>
|
|
|
|
<h2><?php echo htmlspecialchars($year); ?></h2>
|
|
|
|
<!-- Display year stats -->
|
|
<p>
|
|
Total entries in <?php echo $year; ?>: <strong><?php echo $yearTotal; ?></strong>, Completed: <strong><?php echo $yearCompleted; ?> (<?php echo $yearPercent; ?>%)</strong>
|
|
</p>
|
|
|
|
<?php
|
|
if ($showSuggestButton) {
|
|
echo '<button id="suggest-button">Suggest</button>';
|
|
}
|
|
|
|
if ($mode === 'non-season-table') {
|
|
if (!empty($records)) {
|
|
renderPre2009Table($records, $yearTotal, $yearCompleted, $yearPercent);
|
|
} else {
|
|
echo '<p>No records found.</p>';
|
|
}
|
|
renderAddRecordForm($yearValue, $seasons);
|
|
|
|
} else if ($mode === 'manga') {
|
|
if (!empty($records)) {
|
|
renderMangaTable($records, $yearTotal, $yearCompleted, $yearPercent);
|
|
}
|
|
else {
|
|
echo '<p>No records found.</p>';
|
|
}
|
|
renderAddMangaForm($yearValue, $seasons);
|
|
}
|
|
else {
|
|
renderSeasonTables($seasons, $seasonRecords);
|
|
renderAddRecordForm($yearValue, $seasons);
|
|
}
|
|
|
|
// Renders table for pre-2009 records
|
|
function renderPre2009Table($records, $yearTotal, $yearCompleted, $yearPercent) {
|
|
// Since pre-2009 mode doesn't have seasons, we've already shown year stats above.
|
|
?>
|
|
<table class="record-table">
|
|
<colgroup>
|
|
<col>
|
|
<col>
|
|
<col>
|
|
<col>
|
|
<col>
|
|
<col>
|
|
</colgroup>
|
|
<thead>
|
|
<tr>
|
|
<th>#</th>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Comment</th>
|
|
<th>Date Completed</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php $rowNumber = 1; ?>
|
|
<?php foreach ($records as $record): ?>
|
|
<?php
|
|
$rowClasses = [];
|
|
if ($record['is_completed']) {
|
|
$rowClasses[] = 'completed';
|
|
}
|
|
if (!empty($record['currently_watching']) && $record['currently_watching']) {
|
|
$rowClasses[] = 'watching';
|
|
}
|
|
$classAttr = !empty($rowClasses) ? ' class="'.implode(' ', $rowClasses).'"' : '';
|
|
?>
|
|
<tr <?php echo $classAttr; ?> data-id="<?php echo $record['id']; ?>" data-name="<?php echo htmlspecialchars($record['name'], ENT_QUOTES); ?>">
|
|
<td><?php echo $rowNumber++; ?></td>
|
|
<td>
|
|
<?php if (!empty($record['url'])): ?>
|
|
<a href="<?php echo htmlspecialchars($record['url']); ?>" target="_blank" data-url="<?php echo htmlspecialchars($record['url'], ENT_QUOTES); ?>">
|
|
<?php echo htmlspecialchars($record['name']); ?>
|
|
</a>
|
|
<?php else: ?>
|
|
<?php echo htmlspecialchars($record['name']); ?>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td><?php echo htmlspecialchars($record['type']); ?></td>
|
|
<td><?php echo htmlspecialchars($record['comment']); ?></td>
|
|
<td><?php echo htmlspecialchars($record['date_completed']); ?></td>
|
|
<td>
|
|
<?php if (!$record['is_completed']): ?>
|
|
<button class="set-complete-button" data-id="<?php echo $record['id']; ?>">+</button>
|
|
<?php endif; ?>
|
|
<button class="set-currently-watching-button" data-id="<?php echo $record['id']; ?>">W</button>
|
|
<button class="edit-button" data-id="<?php echo $record['id']; ?>">Edit</button>
|
|
<button class="delete-button" data-id="<?php echo $record['id']; ?>">Delete</button>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
<?php
|
|
}
|
|
|
|
// Renders table for manga
|
|
function renderMangaTable($records, $yearTotal, $yearCompleted, $yearPercent) {
|
|
// Since pre-2009 mode doesn't have seasons, we've already shown year stats above.
|
|
?>
|
|
<table class="record-table" id="manga">
|
|
<colgroup>
|
|
<col>
|
|
<col>
|
|
<col>
|
|
<col>
|
|
<col>
|
|
</colgroup>
|
|
<thead>
|
|
<tr>
|
|
<th>#</th>
|
|
<th>Name</th>
|
|
<th>Comment</th>
|
|
<th>Date Completed</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php $rowNumber = 1; ?>
|
|
<?php foreach ($records as $record): ?>
|
|
<?php
|
|
$rowClasses = [];
|
|
if ($record['is_completed']) {
|
|
$rowClasses[] = 'completed';
|
|
}
|
|
if (!empty($record['currently_watching']) && $record['currently_watching']) {
|
|
$rowClasses[] = 'watching';
|
|
}
|
|
$classAttr = !empty($rowClasses) ? ' class="'.implode(' ', $rowClasses).'"' : '';
|
|
?>
|
|
<tr <?php echo $classAttr; ?> data-id="<?php echo $record['id']; ?>" data-name="<?php echo htmlspecialchars($record['name'], ENT_QUOTES); ?>">
|
|
<td><?php echo $rowNumber++; ?></td>
|
|
<td>
|
|
<?php if (!empty($record['url'])): ?>
|
|
<a href="<?php echo htmlspecialchars($record['url']); ?>" target="_blank" data-url="<?php echo htmlspecialchars($record['url'], ENT_QUOTES); ?>">
|
|
<?php echo htmlspecialchars($record['name']); ?>
|
|
</a>
|
|
<?php else: ?>
|
|
<?php echo htmlspecialchars($record['name']); ?>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td><?php echo htmlspecialchars($record['comment']); ?></td>
|
|
<td><?php echo htmlspecialchars($record['date_completed']); ?></td>
|
|
<td>
|
|
<?php if (!$record['is_completed']): ?>
|
|
<button class="set-complete-button" data-id="<?php echo $record['id']; ?>">+</button>
|
|
<?php endif; ?>
|
|
<button class="set-currently-watching-button" data-id="<?php echo $record['id']; ?>">CR</button>
|
|
<button class="edit-button" data-id="<?php echo $record['id']; ?>">Edit</button>
|
|
<button class="delete-button" data-id="<?php echo $record['id']; ?>">Delete</button>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
<?php
|
|
}
|
|
|
|
// Renders season tables for normal mode
|
|
function renderSeasonTables($seasons, $seasonRecords) {
|
|
foreach ($seasons as $season) {
|
|
// Compute season stats:
|
|
$seasonRecordsThis = $seasonRecords[$season] ?? [];
|
|
$seasonTotal = count($seasonRecordsThis);
|
|
$seasonCompleted = 0;
|
|
foreach ($seasonRecordsThis as $r) {
|
|
if ($r['is_completed']) {
|
|
$seasonCompleted++;
|
|
}
|
|
}
|
|
$seasonPercent = $seasonTotal > 0 ? round(($seasonCompleted / $seasonTotal) * 100) : 0;
|
|
|
|
echo '<h3>' . ucfirst($season) . ' ' . get_season_emoji($season) . '</h3>';
|
|
// Display season stats:
|
|
echo "<p>Completed: <strong>$seasonCompleted ($seasonPercent%)</strong></p>";
|
|
|
|
if (!empty($seasonRecordsThis)) {
|
|
?>
|
|
<table class="record-table">
|
|
<colgroup>
|
|
<col><col><col><col><col><col>
|
|
</colgroup>
|
|
<thead>
|
|
<tr>
|
|
<th>#</th>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Comment</th>
|
|
<th>Date Completed</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php $rowNumber = 1; ?>
|
|
<?php foreach ($seasonRecordsThis as $record): ?>
|
|
<?php
|
|
$rowClasses = [];
|
|
if ($record['is_completed']) {
|
|
$rowClasses[] = 'completed';
|
|
}
|
|
if (!empty($record['currently_watching']) && $record['currently_watching']) {
|
|
$rowClasses[] = 'watching';
|
|
}
|
|
$classAttr = !empty($rowClasses) ? ' class="' . implode(' ', $rowClasses) . '"' : '';
|
|
?>
|
|
<tr<?php echo $classAttr; ?> data-id="<?php echo $record['id']; ?>" data-name="<?php echo htmlspecialchars($record['name'], ENT_QUOTES); ?>">
|
|
<td><?php echo $rowNumber++; ?></td>
|
|
<td>
|
|
<?php if (!empty($record['url'])): ?>
|
|
<a href="<?php echo htmlspecialchars($record['url']); ?>" target="_blank" data-url="<?php echo htmlspecialchars($record['url'], ENT_QUOTES); ?>">
|
|
<?php echo htmlspecialchars($record['name']); ?>
|
|
</a>
|
|
<?php else: ?>
|
|
<?php echo htmlspecialchars($record['name']); ?>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td><?php echo htmlspecialchars($record['type']); ?></td>
|
|
<td><?php echo htmlspecialchars($record['comment']); ?></td>
|
|
<td><?php echo htmlspecialchars($record['date_completed']); ?></td>
|
|
<td>
|
|
<?php if (!$record['is_completed']): ?>
|
|
<button class="set-complete-button" data-id="<?php echo $record['id']; ?>">+</button>
|
|
<?php endif; ?>
|
|
<button class="set-currently-watching-button" data-id="<?php echo $record['id']; ?>">CW</button>
|
|
<button class="edit-button" data-id="<?php echo $record['id']; ?>">Edit</button>
|
|
<button class="delete-button" data-id="<?php echo $record['id']; ?>">Delete</button>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
<?php
|
|
} else {
|
|
echo '<p>No records for this season.</p>';
|
|
}
|
|
}
|
|
}
|
|
|
|
function renderAddMangaForm($yearValue, $seasons) {
|
|
?>
|
|
<form id="add-form" class="form-container-horizontal">
|
|
<h3>Add New Record</h3>
|
|
<input type="hidden" name="year" value="<?php echo htmlspecialchars($yearValue); ?>">
|
|
<div class="form-row">
|
|
<?php if ($yearValue == -1 || $yearValue == -2 || $yearValue == -3): ?>
|
|
<input type="hidden" name="season" value="N/A">
|
|
<div class="form-group">
|
|
<label for="name">Name:</label>
|
|
<input type="text" name="name" id="name" class="form-control" required>
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="form-group">
|
|
<label for="name">Name:</label>
|
|
<input type="text" name="name" id="name" class="form-control" required>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div> <!-- End of first form row -->
|
|
|
|
<div class="form-row">
|
|
<div class="form-group">
|
|
<label for="comment">Comment:</label>
|
|
<input type="text" name="comment" id="comment" class="form-control">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="date_completed">Date Completed:</label>
|
|
<input type="date" name="date_completed" id="date_completed" class="form-control">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="url">URL:</label>
|
|
<input type="url" name="url" id="url" class="form-control">
|
|
</div>
|
|
</div> <!-- End of second form row -->
|
|
|
|
<div class="form-row">
|
|
<div class="form-group form-check">
|
|
<input type="checkbox" name="is_completed" id="is_completed" class="form-check-input">
|
|
<label for="is_completed" class="form-check-label">Is Completed</label>
|
|
</div>
|
|
<div class="form-group form-check">
|
|
<input type="checkbox" name="currently_watching" id="currently_watching" class="form-check-input">
|
|
<label for="currently_watching" class="form-check-label">Currently reading</label>
|
|
</div>
|
|
</div> <!-- End of third form row -->
|
|
|
|
<div class="form-row">
|
|
<div class="form-group">
|
|
<button type="submit" class="btn btn-primary">Add Record</button>
|
|
</div>
|
|
</div> <!-- End of fourth form row -->
|
|
</form>
|
|
<div><a href="./php/panel.php">Control panel</a> | <a href="/docs/animu-tree.txt">Downloaded anime</a> | <a href="https://git.bernd32.xyz/bernd32/anime-backlog-list">Source code</a></div>
|
|
<?php
|
|
}
|
|
|
|
function renderAddRecordForm($yearValue, $seasons) {
|
|
?>
|
|
<form id="add-form" class="form-container-horizontal">
|
|
<h3>Add New Record</h3>
|
|
<input type="hidden" name="year" value="<?php echo htmlspecialchars($yearValue); ?>">
|
|
<div class="form-row">
|
|
<?php if ($yearValue == -1 || $yearValue == -2 || $yearValue == -3): ?>
|
|
<input type="hidden" name="season" value="N/A">
|
|
<div class="form-group">
|
|
<label for="name">Name:</label>
|
|
<input type="text" name="name" id="name" class="form-control" required>
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="form-group">
|
|
<label for="name">Name:</label>
|
|
<input type="text" name="name" id="name" class="form-control" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="season">Season:</label>
|
|
<select name="season" id="season" class="form-control">
|
|
<?php foreach ($seasons as $season): ?>
|
|
<option value="<?php echo $season; ?>"><?php echo ucfirst($season); ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<?php endif; ?>
|
|
<div class="form-group">
|
|
<label for="type">Type:</label>
|
|
<select name="type" id="type" class="form-control">
|
|
<option value="tv">TV</option>
|
|
<option value="special">Special</option>
|
|
<option value="short">Short</option>
|
|
<option value="ova">OVA</option>
|
|
<option value="movie">Movie</option>
|
|
<option value="other">Other</option>
|
|
</select>
|
|
</div>
|
|
</div> <!-- End of first form row -->
|
|
|
|
<div class="form-row">
|
|
<div class="form-group">
|
|
<label for="comment">Comment:</label>
|
|
<input type="text" name="comment" id="comment" class="form-control">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="date_completed">Date Completed:</label>
|
|
<input type="date" name="date_completed" id="date_completed" class="form-control">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="url">URL:</label>
|
|
<input type="url" name="url" id="url" class="form-control">
|
|
</div>
|
|
</div> <!-- End of second form row -->
|
|
|
|
<div class="form-row">
|
|
<div class="form-group form-check">
|
|
<input type="checkbox" name="is_completed" id="is_completed" class="form-check-input">
|
|
<label for="is_completed" class="form-check-label">Is Completed</label>
|
|
</div>
|
|
<div class="form-group form-check">
|
|
<input type="checkbox" name="currently_watching" id="currently_watching" class="form-check-input">
|
|
<label for="currently_watching" class="form-check-label">Currently Watching</label>
|
|
</div>
|
|
</div> <!-- End of third form row -->
|
|
|
|
<div class="form-row">
|
|
<div class="form-group">
|
|
<button type="submit" class="btn btn-primary">Add Record</button>
|
|
</div>
|
|
</div> <!-- End of fourth form row -->
|
|
</form>
|
|
<div><a href="./php/panel.php">Control panel</a> | <a href="/docs/animu-tree.txt">Downloaded anime</a> | <a href="https://git.bernd32.xyz/bernd32/anime-backlog-list">Source code</a></div>
|
|
<?php
|
|
}
|
|
|
|
|
|
function get_season_emoji($season) {
|
|
switch($season) {
|
|
case 'winter':
|
|
return '❄️';
|
|
case 'spring':
|
|
return '🌱';
|
|
case 'summer':
|
|
return '☀️';
|
|
case 'fall':
|
|
return '🍂';
|
|
default:
|
|
return '🎇';
|
|
}
|
|
}
|