| Server IP : 173.209.174.21 / Your IP : 216.73.216.89 Web Server : Apache/2.4.58 (Ubuntu) System : Linux wcfs-server 6.8.0-124-generic #124-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 13:00:45 UTC 2026 x86_64 User : nodor ( 1000) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/thelittlebigshow/app/admin/ |
Upload File : |
<?php
session_start();
require_once 'config/config.php';
require_once BASE_PATH . '/includes/auth_validate.php';
$db = getDbInstance();
$currentYear = date('Y');
$scoreColumns = [
'fit_finish' => "TINYINT UNSIGNED DEFAULT NULL",
'paint' => "TINYINT UNSIGNED DEFAULT NULL",
'interior' => "TINYINT UNSIGNED DEFAULT NULL",
'overall_look' => "TINYINT UNSIGNED DEFAULT NULL",
'stance' => "TINYINT UNSIGNED DEFAULT NULL",
'engine_bay' => "TINYINT UNSIGNED DEFAULT NULL",
'wheels_tires' => "TINYINT UNSIGNED DEFAULT NULL",
'cleanliness_detail' => "TINYINT UNSIGNED DEFAULT NULL",
'total_score' => "SMALLINT UNSIGNED DEFAULT NULL",
'judge_notes' => "TEXT NULL",
'created_at' => "TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP",
];
foreach ($scoreColumns as $column => $definition) {
$existingColumn = $db->rawQuery("SHOW COLUMNS FROM `vote` LIKE '" . $column . "'");
if (empty($existingColumn)) {
$db->rawQuery("ALTER TABLE `vote` ADD COLUMN `$column` $definition");
}
}
$scoreLabels = [
'fit_finish' => 'Fit',
'paint' => 'Paint',
'interior' => 'Interior',
'overall_look' => 'Overall',
'stance' => 'Stance',
'engine_bay' => 'Engine',
'wheels_tires' => 'Wheels',
'cleanliness_detail' => 'Detail',
];
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_score_card'])) {
$vehicleId = filter_input(INPUT_POST, 'vehicle_id', FILTER_VALIDATE_INT);
$scoreCardId = filter_input(INPUT_POST, 'score_card_id', FILTER_VALIDATE_INT);
if ($vehicleId && $scoreCardId) {
$success = $db->where('id', $scoreCardId)->where('vehicle_id', $vehicleId)->delete('vote');
if ($success) {
$countRows = $db->rawQuery("SELECT COUNT(*) AS score_count FROM vote WHERE vehicle_id = ?", [$vehicleId]);
$scoreCount = (int) ($countRows[0]['score_count'] ?? 0);
$db->where('id', $vehicleId)->update('vehicles', ['vote_status' => $scoreCount]);
$_SESSION['success'] = 'Score card deleted and judging count updated.';
} else {
$_SESSION['failure'] = 'Score card could not be deleted.';
}
} else {
$_SESSION['failure'] = 'Invalid score card.';
}
header('Location: vote_adjustments.php');
exit;
}
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update_score_card'])) {
$vehicleId = filter_input(INPUT_POST, 'vehicle_id', FILTER_VALIDATE_INT);
$scoreCardId = filter_input(INPUT_POST, 'score_card_id', FILTER_VALIDATE_INT);
$updatedScores = [];
$totalScore = 0;
$hasError = false;
foreach ($scoreLabels as $scoreKey => $scoreLabel) {
$score = filter_input(INPUT_POST, $scoreKey, FILTER_VALIDATE_INT, [
'options' => ['min_range' => 1, 'max_range' => 10],
]);
if ($score === false || $score === null) {
$hasError = true;
break;
}
$updatedScores[$scoreKey] = $score;
$totalScore += $score;
}
if ($vehicleId && $scoreCardId && !$hasError) {
$updatedScores['total_score'] = $totalScore;
$updatedScores['judge_notes'] = trim($_POST['judge_notes'] ?? '');
$success = $db->where('id', $scoreCardId)->where('vehicle_id', $vehicleId)->update('vote', $updatedScores);
$_SESSION[$success ? 'success' : 'failure'] = $success ? 'Score card updated.' : 'Score card could not be updated.';
} else {
$_SESSION['failure'] = 'Please enter scores from 1 to 10 for every judging item.';
}
header('Location: vote_adjustments.php');
exit;
}
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['adjust_people_choice'])) {
$vehicleId = filter_input(INPUT_POST, 'vehicle_id', FILTER_VALIDATE_INT);
$direction = $_POST['direction'] ?? '';
if ($vehicleId) {
$vehicle = $db->where('id', $vehicleId)->getOne('vehicles');
if ($vehicle) {
$currentVotes = (int) $vehicle['fav_vote'];
$newVotes = $direction === 'down' ? max(0, $currentVotes - 1) : $currentVotes + 1;
$success = $db->where('id', $vehicleId)->update('vehicles', ['fav_vote' => $newVotes]);
$_SESSION[$success ? 'success' : 'failure'] = $success ? 'People\'s Choice count updated.' : 'People\'s Choice count could not be updated.';
} else {
$_SESSION['failure'] = 'Vehicle not found.';
}
} else {
$_SESSION['failure'] = 'Invalid vehicle.';
}
header('Location: vote_adjustments.php');
exit;
}
$rows = $db->rawQuery("
SELECT
vehicles.id,
vehicles.name,
vehicles.vehicle_maker,
vehicles.vehicle_model,
vehicles.vehicle_year,
vehicles.category,
vehicles.vote_status,
vehicles.fav_vote,
COUNT(vote.id) AS score_count,
COALESCE(SUM(vote.total_score), 0) AS total_score
FROM vehicles
LEFT JOIN vote ON vote.vehicle_id = vehicles.id
WHERE YEAR(vehicles.created_date) = ?
AND vehicles.status = 1
GROUP BY vehicles.id, vehicles.name, vehicles.vehicle_maker, vehicles.vehicle_model, vehicles.vehicle_year, vehicles.category, vehicles.vote_status, vehicles.fav_vote
ORDER BY vehicles.id DESC
", [$currentYear]);
$scoreCardsByVehicle = [];
$vehicleIds = array_map('intval', array_column($rows, 'id'));
$vehicleIds = array_values(array_filter($vehicleIds));
if (!empty($vehicleIds)) {
$scoreCards = $db->rawQuery("
SELECT
id,
vehicle_id,
fit_finish,
paint,
interior,
overall_look,
stance,
engine_bay,
wheels_tires,
cleanliness_detail,
total_score,
judge_notes,
created_at
FROM vote
WHERE vehicle_id IN (" . implode(',', $vehicleIds) . ")
ORDER BY created_at DESC, id DESC
");
foreach ($scoreCards as $scoreCard) {
$scoreCardsByVehicle[(int) $scoreCard['vehicle_id']][] = $scoreCard;
}
}
include BASE_PATH . '/includes/header.php';
?>
<style>
.score-card-list {
margin-top: 8px;
}
.score-card {
background: #fff;
border: 1px solid #ddd;
border-radius: 4px;
margin-bottom: 8px;
padding: 8px;
}
.score-card-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
}
.score-card-actions {
display: flex;
gap: 5px;
white-space: nowrap;
}
.score-card-details {
color: #555;
font-size: 12px;
line-height: 1.6;
margin-top: 8px;
}
.score-card-edit {
display: none;
}
.score-card-fields {
display: grid;
gap: 6px;
grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
margin-top: 8px;
}
.score-card-fields label {
color: #555;
font-size: 12px;
font-weight: normal;
margin-bottom: 2px;
}
.score-card-fields input {
height: 28px;
padding: 3px 6px;
}
.score-card-notes {
color: #555;
font-size: 12px;
margin-top: 5px;
white-space: pre-wrap;
}
</style>
<script>
function toggleScoreCard(cardId) {
var card = document.getElementById(cardId);
if (!card) {
return;
}
card.style.display = card.style.display === 'block' ? 'none' : 'block';
}
</script>
<div id="page-wrapper">
<div class="row">
<div class="col-lg-8">
<h1 class="page-header">Adjust Votes</h1>
</div>
</div>
<?php include BASE_PATH . '/includes/flash_messages.php'; ?>
<table class="table table-striped table-bordered table-condensed">
<thead>
<tr>
<th>ID</th>
<th>Owner</th>
<th>Vehicle</th>
<th>Category</th>
<th>Judging</th>
<th>People's Choice</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($rows as $row): ?>
<tr>
<td><?php echo xss_clean($row['id']); ?></td>
<td><?php echo xss_clean($row['name']); ?></td>
<td><?php echo xss_clean(trim($row['vehicle_year'] . ' ' . $row['vehicle_maker'] . ' ' . $row['vehicle_model'])); ?></td>
<td><?php echo xss_clean($row['category']); ?></td>
<td>
<strong><?php echo (int) $row['score_count']; ?></strong> score card(s)<br>
Total: <?php echo (int) $row['total_score']; ?>
<?php $vehicleScoreCards = $scoreCardsByVehicle[(int) $row['id']] ?? []; ?>
<?php if (!empty($vehicleScoreCards)): ?>
<div class="score-card-list">
<?php foreach ($vehicleScoreCards as $scoreCard): ?>
<div class="score-card">
<div class="score-card-header">
<div>
<strong>Card #<?php echo (int) $scoreCard['id']; ?></strong>
Total: <?php echo (int) $scoreCard['total_score']; ?>
<span class="text-muted">
<?php if (!empty($scoreCard['created_at'])): ?>
<?php echo xss_clean(date('m/d/Y g:i A', strtotime($scoreCard['created_at']))); ?>
<?php endif; ?>
</span>
</div>
<div class="score-card-actions">
<button type="button" class="btn btn-default btn-xs" onclick="toggleScoreCard('score-card-edit-<?php echo (int) $scoreCard['id']; ?>');">
<i class="fa fa-pencil"></i> Open/Edit
</button>
<form action="" method="POST" onsubmit="return confirm('Delete this judging score card?');">
<input type="hidden" name="vehicle_id" value="<?php echo xss_clean($row['id']); ?>">
<input type="hidden" name="score_card_id" value="<?php echo (int) $scoreCard['id']; ?>">
<button type="submit" name="delete_score_card" value="1" class="btn btn-danger btn-xs">
<i class="fa fa-trash"></i> Delete
</button>
</form>
</div>
</div>
<div id="score-card-edit-<?php echo (int) $scoreCard['id']; ?>" class="score-card-edit">
<div class="score-card-details">
<?php foreach ($scoreLabels as $scoreKey => $scoreLabel): ?>
<?php echo xss_clean($scoreLabel); ?>: <?php echo xss_clean($scoreCard[$scoreKey] ?? ''); ?><?php if ($scoreKey !== 'cleanliness_detail'): ?>, <?php endif; ?>
<?php endforeach; ?>
</div>
<?php if (!empty($scoreCard['judge_notes'])): ?>
<div class="score-card-notes">
Notes: <?php echo xss_clean($scoreCard['judge_notes']); ?>
</div>
<?php endif; ?>
<form action="" method="POST" style="margin-top: 8px;">
<input type="hidden" name="vehicle_id" value="<?php echo xss_clean($row['id']); ?>">
<input type="hidden" name="score_card_id" value="<?php echo (int) $scoreCard['id']; ?>">
<div class="score-card-fields">
<?php foreach ($scoreLabels as $scoreKey => $scoreLabel): ?>
<div>
<label for="<?php echo xss_clean($scoreKey . '_' . $scoreCard['id']); ?>"><?php echo xss_clean($scoreLabel); ?></label>
<input
type="number"
min="1"
max="10"
class="form-control input-sm"
id="<?php echo xss_clean($scoreKey . '_' . $scoreCard['id']); ?>"
name="<?php echo xss_clean($scoreKey); ?>"
value="<?php echo xss_clean($scoreCard[$scoreKey] ?? ''); ?>"
required>
</div>
<?php endforeach; ?>
</div>
<div class="form-group" style="margin-top: 8px; margin-bottom: 8px;">
<label for="judge_notes_<?php echo (int) $scoreCard['id']; ?>" class="sr-only">Notes</label>
<textarea
class="form-control input-sm"
id="judge_notes_<?php echo (int) $scoreCard['id']; ?>"
name="judge_notes"
rows="2"
placeholder="Notes"><?php echo xss_clean($scoreCard['judge_notes'] ?? ''); ?></textarea>
</div>
<button type="submit" name="update_score_card" value="1" class="btn btn-success btn-xs">
<i class="fa fa-save"></i> Save Card
</button>
</form>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</td>
<td>
<form action="" method="POST" class="form-inline">
<input type="hidden" name="vehicle_id" value="<?php echo xss_clean($row['id']); ?>">
<button type="submit" name="adjust_people_choice" value="1" class="btn btn-warning btn-sm" onclick="this.form.direction.value='down';">-</button>
<span style="display:inline-block; min-width: 36px; text-align:center;"><?php echo (int) $row['fav_vote']; ?></span>
<button type="submit" name="adjust_people_choice" value="1" class="btn btn-primary btn-sm" onclick="this.form.direction.value='up';">+</button>
<input type="hidden" name="direction" value="up">
</form>
</td>
<td>
<a href="../vote.php?id=<?php echo urlencode($row['id']); ?>&override=1" class="btn btn-info" target="_blank">Open Judging Form</a>
<a href="../view.php?id=<?php echo urlencode($row['id']); ?>" class="btn btn-default" target="_blank">Details</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php include BASE_PATH . '/includes/footer.php'; ?>