Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions website/ajax/action.design.auto-enter.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
// $_POST['awardid'] - The award ID to auto-enter all racers for
require_once('inc/permissions.inc');

if (!have_permission(EDIT_AWARDS_PERMISSION)) {
json_not_authorized();
exit;
}

$awardid = isset($_POST['awardid']) ? (int)$_POST['awardid'] : 0;

if ($awardid <= 0) {
json_failure('noaward', 'No award ID specified');
exit;
}

// Start a transaction
$db->beginTransaction();

try {
// Get all eligible racers
$stmt = $db->query('SELECT racerid FROM RegistrationInfo WHERE exclude = 0');
$racers = $stmt->fetchAll(PDO::FETCH_COLUMN);

// For each racer, check if they're already in this award category
// If not, add them to it
$check_stmt = $db->prepare('SELECT COUNT(*) FROM DesignEntries
WHERE racerid = :racerid AND awardid = :awardid');
$insert_stmt = $db->prepare('INSERT INTO DesignEntries (racerid, awardid)
VALUES (:racerid, :awardid)');

$racers_added = 0;
foreach ($racers as $racerid) {
$check_stmt->execute(array(':racerid' => $racerid, ':awardid' => $awardid));
$exists = $check_stmt->fetchColumn();

if (!$exists) {
$insert_stmt->execute(array(
':racerid' => $racerid,
':awardid' => $awardid
));
$racers_added++;
}
}

// Commit the transaction
$db->commit();

// Return count of added racers for feedback
json_out('racers_added', $racers_added);
json_success();

} catch (Exception $e) {
// Roll back on error
$db->rollBack();
json_failure('database', $e->getMessage());
}
?>
49 changes: 49 additions & 0 deletions website/ajax/action.design.save-entries.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
// $_POST['racerid'] - The racer ID
// $_POST['entries'] - JSON array of {awardid, selected} objects

require_once('inc/permissions.inc');

if (!have_permission(CHECK_IN_RACERS_PERMISSION)) {
json_not_authorized();
exit;
}

$racerid = $_POST['racerid'];
$entries = json_decode($_POST['entries'], true);

if (!$entries || !is_array($entries)) {
json_failure('invalid', 'Invalid entries data');
exit;
}

// Start a transaction
$db->beginTransaction();

try {
// First delete all existing entries for this racer
$stmt = $db->prepare('DELETE FROM DesignEntries WHERE racerid = :racerid');
$stmt->execute(array(':racerid' => $racerid));

// Then add the new entries
$insert_stmt = $db->prepare('INSERT INTO DesignEntries (racerid, awardid) VALUES (:racerid, :awardid)');

foreach ($entries as $entry) {
if ($entry['selected']) {
$insert_stmt->execute(array(
':racerid' => $racerid,
':awardid' => $entry['awardid']
));
}
}

// Commit the transaction
$db->commit();

json_success();
} catch (Exception $e) {
// Roll back on error
$db->rollBack();
json_failure('database', $e->getMessage());
}
?>
25 changes: 25 additions & 0 deletions website/ajax/action.design.toggle-entry.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
require_once('inc/permissions.inc');

if (!have_permission(CHECK_IN_RACERS_PERMISSION) && !have_permission(EDIT_AWARDS_PERMISSION)) {
json_not_authorized();
exit;
}

$racerid = $_POST['racerid'];
$awardid = $_POST['awardid'];
$selected = $_POST['selected'];

try {
if ($selected === 'true' || $selected === '1') {
$stmt = $db->prepare('INSERT OR IGNORE INTO DesignEntries (racerid, awardid) VALUES (:racerid, :awardid)');
$stmt->execute(array(':racerid' => $racerid, ':awardid' => $awardid));
} else {
$stmt = $db->prepare('DELETE FROM DesignEntries WHERE racerid = :racerid AND awardid = :awardid');
$stmt->execute(array(':racerid' => $racerid, ':awardid' => $awardid));
}
json_success();
} catch (Exception $e) {
json_failure('database', $e->getMessage());
}
?>
30 changes: 30 additions & 0 deletions website/ajax/query.award.design-list.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
require_once('inc/awards.inc');

// Query to get all design awards (Design General and Design Trophy types)
$stmt = $db->query('SELECT a.awardid, a.awardname, a.classid, a.rankid, at.awardtype
FROM Awards a
INNER JOIN AwardTypes at ON a.awardtypeid = at.awardtypeid
WHERE at.awardtype IN ("Design General", "Design Trophy")
ORDER BY a.sort');

$awards = array();
foreach ($stmt as $row) {
$awards[] = array(
'awardid' => (int)$row['awardid'], // Ensure integer type
'awardname' => $row['awardname'],
'classid' => (int)$row['classid'],
'rankid' => (int)$row['rankid'],
'awardtype' => $row['awardtype']
);
}

// Log the results for debugging
error_log("Design awards query found " . count($awards) . " awards");
foreach ($awards as $award) {
error_log("Design award ID: " . $award['awardid'] . ", Name: " . $award['awardname']);
}

json_out('awards', $awards);
json_success();
?>
89 changes: 89 additions & 0 deletions website/ajax/query.award.eligible-racers.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
// $_GET['awardid'] - The award ID to get eligible racers for

require_once('inc/data.inc');
require_once('inc/awards.inc');
require_once('inc/photo-config.inc');
require_once('inc/schema_version.inc');

$awardid = isset($_GET['awardid']) ? (int)$_GET['awardid'] : 0;

error_log("Fetching eligible racers for award ID: " . $awardid);

// Check if this is a design award - explicitly cast to integer for safety
$is_design = (int) read_single_value('SELECT COUNT(*) FROM AwardTypes
INNER JOIN Awards ON AwardTypes.awardtypeid = Awards.awardtypeid
WHERE Awards.awardid = :awardid
AND (AwardTypes.awardtype = "Design General" OR AwardTypes.awardtype = "Design Trophy")',
array(':awardid' => $awardid));

error_log("Is design award check result: " . $is_design);

// Get award information (classid, rankid)
$award = read_single_row('SELECT classid, rankid FROM Awards WHERE awardid = :awardid',
array(':awardid' => $awardid), PDO::FETCH_ASSOC);

if ($is_design > 0) {
// Fix the SQL query for carphoto
$carphoto_field = (schema_version() < 2) ? '\'\' as carphoto' : 'r.carphoto';

// For design awards, only show racers who have entered this category
$sql = "SELECT r.racerid, r.firstname, r.lastname, r.carnumber, r.carname,
r.classid, r.rankid, r.imagefile, $carphoto_field
FROM RegistrationInfo r
INNER JOIN DesignEntries de ON r.racerid = de.racerid
WHERE de.awardid = :awardid AND r.exclude = 0 AND r.passedinspection = 1
ORDER BY r.lastname, r.firstname";

error_log("Design award SQL: " . $sql);

$stmt = $db->prepare($sql);
$stmt->execute(array(':awardid' => $awardid));

// Count results for debugging
$racers_count = 0;
} else {
// For non-design awards, show racers based on class/rank eligibility
$sql = 'SELECT racerid, firstname, lastname, carnumber, carname, classid, rankid,
imagefile, ' . (schema_version() < 2 ? '\'\' as ' : '') . ' carphoto
FROM RegistrationInfo
WHERE exclude = 0 AND passedinspection = 1';

// Add class/rank filters if specified for the award
if ($award && $award['classid'] > 0) {
$sql .= ' AND classid = ' . $award['classid'];
}
if ($award && $award['rankid'] > 0) {
$sql .= ' AND rankid = ' . $award['rankid'];
}

$sql .= ' ORDER BY lastname, firstname';
$stmt = $db->query($sql);
}

$racers = array();
foreach ($stmt as $row) {
$racers_count++;
$carphoto_url = '';
if (!empty($row['carphoto'])) {
$carphoto_url = car_photo_repository()->lookup(RENDER_JUDGING)->render_url($row['carphoto']);
}

$racers[] = array(
'racerid' => (int)$row['racerid'], // Ensure integer type
'name' => $row['firstname'] . ' ' . $row['lastname'],
'firstname' => $row['firstname'],
'lastname' => $row['lastname'],
'carnumber' => $row['carnumber'],
'carname' => $row['carname'],
'classid' => (int)$row['classid'],
'rankid' => (int)$row['rankid'],
'carphoto' => $carphoto_url
);
}

error_log("Found $racers_count eligible racers for award ID: $awardid");

json_out('eligible_racers', $racers);
json_success();
?>
22 changes: 22 additions & 0 deletions website/ajax/query.design.entries.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
// $_GET['racerid'] - The racer to get entries for

$racerid = $_GET['racerid'];

$stmt = $db->prepare('SELECT de.awardid, a.awardname
FROM DesignEntries de
INNER JOIN Awards a ON de.awardid = a.awardid
WHERE de.racerid = :racerid');
$stmt->execute(array(':racerid' => $racerid));

$entries = array();
foreach ($stmt as $row) {
$entries[] = array(
'awardid' => $row['awardid'],
'awardname' => $row['awardname']
);
}

json_out('entries', $entries);
json_success();
?>
11 changes: 11 additions & 0 deletions website/ajax/query.design.entry-count.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
// $_GET['awardid'] - The award to get entry count for

$awardid = $_GET['awardid'];

$count = read_single_value('SELECT COUNT(*) FROM DesignEntries WHERE awardid = :awardid',
array(':awardid' => $awardid));

json_out('entry_count', $count);
json_success();
?>
47 changes: 47 additions & 0 deletions website/ajax/query.racer.by-design-category.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
// $_GET['awardid'] - Award ID to filter by

require_once('inc/data.inc');
require_once('inc/schema_version.inc');
require_once('inc/photo-config.inc');

$awardid = isset($_GET['awardid']) ? (int)$_GET['awardid'] : 0;

if ($awardid <= 0) {
json_failure('noaward', 'No award ID specified');
exit;
}

// Simpler query to avoid SQL errors
$sql = "SELECT r.racerid, r.carnumber, r.lastname, r.firstname, r.carname,
r.classid, r.rankid, r.imagefile,
" . (schema_version() < 2 ? "'' as carphoto" : "r.carphoto") . "
FROM RegistrationInfo r
INNER JOIN DesignEntries de ON r.racerid = de.racerid
WHERE de.awardid = :awardid
AND r.passedinspection = 1
ORDER BY r.lastname, r.firstname";

$stmt = $db->prepare($sql);
$stmt->execute(array(':awardid' => $awardid));

$racers = array();
$rowno = 0;
foreach ($stmt as $rs) {
$rowno++;
$racers[] = array(
'racerid' => $rs['racerid'],
'carnumber' => $rs['carnumber'],
'lastname' => $rs['lastname'],
'firstname' => $rs['firstname'],
'carname' => $rs['carname'],
'classid' => $rs['classid'],
'rankid' => $rs['rankid'],
'headshot' => headshot_repository()->lookup(RENDER_TINY)->get_url_for_racer_icon($rs['racerid'], $rs['imagefile']),
'rowno' => $rowno
);
}

json_out('racers', $racers);
json_success();
?>
27 changes: 26 additions & 1 deletion website/awards-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<script type="text/javascript" src="js/dashboard-ajax.js"></script>
<script type="text/javascript" src="js/mobile.js"></script>
<script type="text/javascript" src="js/modal.js"></script>
<script type="text/javascript" src="js/awards-editor.js"></script>
<script type="text/javascript" src="js/awards-editor.js?v=2"></script>
<link rel="stylesheet" type="text/css" href="css/mobile.css"/>
<link rel="stylesheet" type="text/css" href="css/awards-editor.css"/>
</head>
Expand Down Expand Up @@ -122,6 +122,31 @@
</form>
</div><!-- award_editor_modal -->

<div id="design_category_modal" class="modal_dialog hidden block_buttons wide_modal">
<h2>Design Category: <span id="design_category_name"></span></h2>
<p>Assign racers to this design category:</p>
<p><a href="#" id="auto_enter_all_btn" class="button_link" style="width: auto; display: inline-block; padding: 5px 10px;">Auto-Enter All Racers</a></p>
<p id="entry_count_display"></p>
<div class="listview" style="position: relative; top: 0; height: 400px; left: 0; width: 100%;">
<table id="racer_assignments" style="width: 100%;">
<thead>
<tr>
<th>Car #</th>
<th>Racer</th>
<th>Assigned</th>
</tr>
</thead>
<tbody>
<!-- Filled by JavaScript -->
</tbody>
</table>
</div>

<div style="text-align: center; margin-top: 20px;">
<input type="button" value="Close" onclick="close_modal('#design_category_modal');"/>
</div>
</div>

</body>
</html>

Loading