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
5 changes: 5 additions & 0 deletions _SQL/zmeny_3.4.5.655.sql.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@

# *** pridani sloupcu pro dopravu
$sql[1] = 'ALTER TABLE `'.TBL_RACE.'` ADD `kapacita` SMALLINT NULL DEFAULT NULL AFTER `ubytovani`';
$sql[2] = 'ALTER TABLE `'.TBL_RACE.'` ADD `prihlasenych` SMALLINT NOT NULL DEFAULT 0 AFTER `kapacita`';
$sql[3] = 'ALTER TABLE `'.TBL_RACE.'` ENGINE=InnoDB;';

$sql[4] = 'UPDATE `'.TBL_RACE.'` r LEFT JOIN ( SELECT id_zavod, COUNT(*) AS cnt FROM `'.TBL_ZAVXUS.
'` GROUP BY id_zavod ) z ON z.id_zavod = r.id SET r.prihlasenych = COALESCE(z.cnt, 0);';

//#############################################################################

Expand Down
134 changes: 0 additions & 134 deletions _terminy_rg.php

This file was deleted.

8 changes: 6 additions & 2 deletions api/race.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,13 @@
}

// check whether the user is already signed in
$output = db_execute("SELECT * FROM " . TBL_ZAVXUS . " WHERE id_zavod = ? AND id_user = ? LIMIT 1", $race_id, $user_id);;
$output = db_execute("SELECT * FROM " . TBL_ZAVXUS . " WHERE id_zavod = ? AND id_user = ? LIMIT 1", $race_id, $user_id);
$output = $output->fetch_assoc();

if ($output == null) { // if not, create a new row with given values
db_execute("INSERT INTO " . TBL_ZAVXUS . " (id_user, id_zavod, kat, pozn, pozn_in, termin, transport, sedadel, ubytovani) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", $user_id, $race_id, $category, $note, $note_internal, $termin, $transport, $sedadel, $accommodation);
// db_execute zde patrne nema navratovou hodnotu
db_execute("UPDATE " .TBL_RACE . " SET prihlasenych = prihlasenych + 1 WHERE id = ?", $race_id);
} else { // else, update the row
$id = $output["id"];
db_execute("UPDATE " . TBL_ZAVXUS . " SET kat = ?, pozn = ?, pozn_in = ?, termin = ?, transport = ?, sedadel = ?, ubytovani = ? WHERE id = ?", $category, $note, $note_internal, $termin, $transport, $sedadel, $accommodation, $id);
Expand Down Expand Up @@ -186,7 +188,9 @@
}

db_execute("DELETE FROM " . TBL_ZAVXUS . " WHERE id_zavod = ? AND id_user = ?", $race_id, $user_id);

// db_execute zde patrne nema navratovou hodnotu
db_execute("Update " . TBL_RACE . " SET prihlasenych = GREATEST(0, prihlasenych -1 ) WHERE id = ?", $race_id);

print_and_die();
case "past_races":
$user_id = require_user_id();
Expand Down
7 changes: 7 additions & 0 deletions api_race_entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
$query="DELETE FROM ".TBL_ZAVXUS." WHERE id_user = (select id from ".TBL_USER." where id = '$id_user') and id_zavod = '$race_id' and add_by_fin = 1;";
@$result=$db_conn->query($query);
$data = 'deleted:'.$db_conn->affected_rows;
if ($result !== false && mysqli_affected_rows($db_conn) > 0) {
query_db("UPDATE ".TBL_RACE." SET prihlasenych = GREATEST(0, prihlasenych - 1) WHERE id = '$race_id'");
}

} else {
$kat = isset($_GET['kat']) ? $_GET['kat'] : '';
$pozn = '';
Expand All @@ -68,6 +72,9 @@
$query="INSERT INTO ".TBL_ZAVXUS." (id_user, id_zavod, kat, pozn, pozn_in, termin, transport, ubytovani, participated, add_by_fin) VALUES ((select id from ".TBL_USER." where id = '$id_user'), '$race_id', '$kat', '$pozn', '$pozn2', '$termin', '$transport', '$ubytovani', '$participated', '$addByFin');";
@$result=$db_conn->query($query);
$data = 'inserted:'.$db_conn->affected_rows;
if ($result !== false && mysqli_affected_rows($db_conn) > 0) {
$db_conn->query("UPDATE ".TBL_RACE." SET prihlasenych = prihlasenych + 1 WHERE id = '$race_id'");
}
}
break;
case 'detail':
Expand Down
81 changes: 72 additions & 9 deletions common.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,15 +379,20 @@ function DrawPageSubTitle($title, $id=null)
echo("<H3 ID='$id'>".$title."</H3>\n");
}

function DrawPageRaceTitle($title, $kapacita, $prihlaseno, $id=null) {
if (isset($kapacita) && $kapacita > 0) {
if ($prihlaseno > $kapacita) {
$title .= ' (náhradník)';
} elseif ($prihlaseno < $kapacita) {
$zbyva = $kapacita - $prihlaseno;
$title .= " (ještě $zbyva míst)";
}
}
function DrawPageRaceTitle($title, $kapacita, $prihlasenych, $id=null) {
if ($kapacita > 0) {
$zbyva = $kapacita - $prihlasenych;

if ($zbyva <= 0) {
$title .= ' (náhradník)';
} elseif ($zbyva === 1) {
$title .= ' (zbývá 1 volné místo)';
} elseif ($zbyva <= 4) {
$title .= " (zbývá $zbyva volných míst)";
} else {
$title .= " ($zbyva volných míst)";
}
}

DrawPageSubTitle($title,$id);
}
Expand Down Expand Up @@ -583,4 +588,62 @@ function Date2ISO($date)
return $text;
}

function countRaceStats(array $zaznamy, bool $is_sdil_dopr_on): array
{
$stats = [
'category_counts' => [],
'trans' => 0,
'ubyt' => 0,
'sedadel' => 0,
];

foreach ($zaznamy as $zaznam) {
// category count
$kat = $zaznam['kat'] ?? null;
if ($kat !== null) {
$stats['category_counts'][$kat] =
($stats['category_counts'][$kat] ?? 0) + 1;
}

if (!empty($zaznam['transport'])) {
$stats['trans']++;
}

if (!empty($zaznam['ubytovani'])) {
$stats['ubyt']++;
}

if ($is_sdil_dopr_on) {
// fix when changing transport from Common to Shared
$stats['sedadel'] +=
($zaznam['sedadel'] === null) ? -1 : (int)$zaznam['sedadel'];
}
}

return $stats;
}

function RenderRaceStats(
array $stats,
bool $is_spol_dopr_on,
bool $is_sdil_dopr_on,
bool $is_spol_ubyt_on
): void {
if ($is_spol_dopr_on || $is_sdil_dopr_on) {
echo "<br>Počet přihlášených na dopravu: {$stats['trans']}";
}

if ($is_sdil_dopr_on) {
$warning = $stats['sedadel'] < 0
? ' <span style="color:red">(málo volných míst)</span>'
: '';
echo "<br>Počet volných sdílených míst: {$stats['sedadel']}{$warning}";
}

if ($is_spol_ubyt_on) {
echo "<br>Počet přihlášených na ubytování: {$stats['ubyt']}";
}

RenderCategoryCounts($stats['category_counts']);
}
?>
35 changes: 35 additions & 0 deletions common_race.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<?

require_once("cfg/race_enums.php");
require_once("cfg/_cfg.php");

function GetRaceTypeName($value)
{
Expand Down Expand Up @@ -468,4 +469,38 @@ function GetSharedTransportValue($transport,$sedadel,&$total){
else
return '';
}

function RenderCategoryCounts ( array $category_counts ) {
// Sort categories alphabetically
ksort($category_counts);

// Add collapsible section for category counts with table formatting
echo '<br><br><div id="category_details" style="display:none;">';
echo '<table cellspacing="5">';
echo '<tr><th style="text-align:left;">Kategorie</th>';

foreach ($category_counts as $category => $count) {
echo "<td>$category</td>";
}

echo '</tr><tr><th style="text-align:left;">Počet</th>';

foreach ($category_counts as $category => $count) {
echo "<td style='text-align:center;'>$count</td>";
}

echo "</tr></table></div>";

// JavaScript to expand list and scroll
echo '<script>
function toggleCategoriesAndScroll() {
var details = document.getElementById("category_details");
details.style.display = "block";

// Scroll to the category list
details.scrollIntoView({ behavior: "smooth", block: "start" });
}
</script>';
}

?>
Loading