C:\$Recycle.Bin\S-1-5-21-3967099092-2644009230-141905953-500\$RPFIICL.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
<?php
// ============================================================
//  BETSY – BETting SYstem  |  results.php
//  DB-Tabellen:
//    users        : u_id (INT PK AI), u_name (VARCHAR), u_passcode (VARCHAR), u_admin (INT)
//    betsy        : b_id (INT PK AI), b_bet (VARCHAR), b_desc (VARCHAR)
//    drivers      : d_id (INT PK AI), d_fname (VARCHAR), d_lname (VARCHAR), d_currseason (INT)
//    fflassets    : fa_id (INT PK AI), fa_chassis (VARCHAR), fa_currseason (INT)
//    betsyresults : br_b_id (INT), br_result (INT)
// ============================================================

require '../../dbconnect.php';
session_start();

// ── Hilfsfunktionen ────────────────────────────────────────

function esc($s) {
    return 
htmlspecialchars($sENT_QUOTES'UTF-8');
}

function 
db_query($sql) {
    
$res mysql_query($sql);
    if (!
$res) die("DB-Fehler: " mysql_error() . "<br>SQL: $sql");
    return 
$res;
}

// ── Datenbankverbindung herstellen ─────────────────────────
dbconnect();

// ── Teilnehmer-Listen aus Datenbank ───────────────────────

// Driver: id => Anzeigename "Nachname Vorname"
$drivers = array();
$res db_query("SELECT d_id, d_lname, d_fname FROM drivers WHERE d_currseason = 1 AND d_id > 0 ORDER BY d_lname ASC, d_fname ASC");
while (
$row mysql_fetch_assoc($res)) {
    
$drivers[] = array('id' => (int)$row['d_id'], 'name' => trim($row['d_lname'] . ' ' $row['d_fname']));
}

// Teams: id => Anzeigename "fa_chassis"
$teams = array();
$res db_query("SELECT fa_id, fa_chassis FROM fflassets WHERE fa_currseason = 1 ORDER BY fa_chassis ASC");
while (
$row mysql_fetch_assoc($res)) {
    
$teams[] = array('id' => (int)$row['fa_id'], 'name' => $row['fa_chassis']);
}

// Zuordnung b_id => Dropdown-Typ ('driver' oder 'team')
$tip_type = array(
     
=> 'driver',  => 'team',    => 'team',    => 'team',
     
=> 'driver',  => 'driver',  => 'team',    => 'team',
     
=> 'driver'10 => 'driver'11 => 'driver'12 => 'driver',
    
13 => 'driver'14 => 'team',   15 => 'driver'16 => 'team',
    
17 => 'driver'18 => 'driver'19 => 'team',   20 => 'team',
    
21 => 'driver'22 => 'team',   23 => 'team',   24 => 'team',
    
25 => 'driver'26 => 'driver'27 => 'driver'28 => 'driver',
    
29 => 'driver'30 => 'team',   31 => 'driver'32 => 'team',
    
33 => 'driver'34 => 'team',   35 => 'team',   36 => 'team',
    
37 => 'team',   38 => 'team',   39 => 'team',   40 => 'team',
);

// ── Formular-Handler: Ergebnis speichern / löschen ─────────
$logged_in = !empty($_SESSION['u_id']);

if (
$logged_in && $_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['betsy_action'])) {
    
$b_id   = (int)(isset($_POST['b_id']) ? $_POST['b_id'] : 0);
    
$action = isset($_POST['betsy_action']) ? $_POST['betsy_action'] : '';

    if (
$action === 'save' && $b_id 0) {
        
$selection mysql_real_escape_string(isset($_POST['selection']) ? trim($_POST['selection']) : '');
        if (
$selection !== '') {
            
$chk db_query("SELECT br_b_id FROM betsyresults WHERE br_b_id=$b_id LIMIT 1");
            if (
mysql_num_rows($chk) > 0) {
                
db_query("UPDATE betsyresults SET br_result='$selection' WHERE br_b_id=$b_id");
            } else {
                
db_query("INSERT INTO betsyresults (br_b_id, br_result) VALUES ($b_id, '$selection')");
            }
        }
    } elseif (
$action === 'delete' && $b_id 0) {
        
db_query("DELETE FROM betsyresults WHERE br_b_id=$b_id");
    }
    
header('Location: ' $_SERVER['PHP_SELF']);
    exit;
}

// ── User-Liste für Login-Dropdown (nur Admins) ─────────────
$login_users = array();
$res db_query("SELECT u_id, u_name FROM users WHERE u_admin=1 ORDER BY u_name");
while (
$row mysql_fetch_assoc($res)) {
    
$login_users[] = $row;
}

// ── Login-Verarbeitung ─────────────────────────────────────
$login_error '';
if (isset(
$_POST['login'])) {
    
$u_id_post = (int)(isset($_POST['selectuser']) ? $_POST['selectuser'] : 0);
    
$upass      mysql_real_escape_string(trim(isset($_POST['passcode']) ? $_POST['passcode'] : ''));
    if (
$u_id_post && $upass !== '') {
        
$res db_query("SELECT u_id, u_name FROM users WHERE u_id=$u_id_post AND u_passcode=md5('$upass') LIMIT 1");
        if (
mysql_num_rows($res) > 0) {
            
$row mysql_fetch_assoc($res);
            
$_SESSION['u_id']   = $row['u_id'];
            
$_SESSION['u_name'] = $row['u_name'];
            
header('Location: ' $_SERVER['PHP_SELF']);
            exit;
        } else {
            
$login_error 'Invalid username or passcode.';
        }
    } else {
        
$login_error 'Please select a username and enter your passcode.';
    }
}

// ── Logout ──────────────────────────────────────────────────
if (isset($_GET['logout'])) {
    
session_destroy();
    
header('Location: ' $_SERVER['PHP_SELF']);
    exit;
}

// ── Welcher Tipp ist gerade im Edit-Modus? ─────────────────
$edit_bid = (isset($_GET['edit']) && $logged_in) ? (int)$_GET['edit'] : 0;

// ── Tips + gespeicherte Ergebnisse aus DB laden ────────────
$tips        = array();
$user_picks  = array();   // br_b_id => array('id'=>..., 'display'=>...)

$res db_query("SELECT b_id, b_bet, b_desc FROM betsy ORDER BY b_id ASC");
while (
$row mysql_fetch_assoc($res)) {
    
$tips[] = $row;
}

// Ergebnisse aus betsyresults laden (keine User-Filterung)
$res db_query("SELECT br_b_id, br_result FROM betsyresults");
while (
$row mysql_fetch_assoc($res)) {
    
$bid   = (int)$row['br_b_id'];
    
$tid   = (int)$row['br_result'];
    
$ttype = isset($tip_type[$bid]) ? $tip_type[$bid] : '';
    
$display '';
    if (
$ttype === 'driver') {
        
$nr db_query("SELECT d_lname, d_fname FROM drivers WHERE d_id=$tid LIMIT 1");
        if (
$dr mysql_fetch_assoc($nr)) {
            
$display trim($dr['d_lname'] . ' ' $dr['d_fname']);
        }
    } else {
        
$nr db_query("SELECT fa_chassis FROM fflassets WHERE fa_id=$tid LIMIT 1");
        if (
$dr mysql_fetch_assoc($nr)) {
            
$display $dr['fa_chassis'];
        }
    }
    
$user_picks[$bid] = array('id' => $tid'display' => ($display $display '#' $tid));
}

$logged_in = !empty($_SESSION['u_id']);
?>
<!DOCTYPE html>
<html>
<head>
<title>BETSY</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="viewport" content="width=device-width, initial-scale=0.7">

<!-- Piwik -->
<script type="text/javascript">
  var _paq = _paq || [];
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="//mamnaslim.dsmynas.net/piwik/";
    _paq.push(['setTrackerUrl', u+'piwik.php']);
    _paq.push(['setSiteId', '1']);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
  })();
</script>
<!-- End Piwik Code -->

<style type="text/css">
#menu__toggle { opacity: 0; }
#menu__toggle:checked + .menu__btn > span { transform: rotate(45deg); }
#menu__toggle:checked + .menu__btn > span::before { top: 0; transform: rotate(0deg); }
#menu__toggle:checked + .menu__btn > span::after  { top: 0; transform: rotate(90deg); }
#menu__toggle:checked ~ .menu__box { left: 0 !important; }
.menu__btn {
  position: fixed; top: 20px; left: 20px;
  width: 26px; height: 26px; cursor: pointer; z-index: 1;
}
.menu__btn > span,
.menu__btn > span::before,
.menu__btn > span::after {
  display: block; position: absolute;
  width: 100%; height: 2px;
  background-color: #616161; transition-duration: .25s;
}
.menu__btn > span::before { content: ''; top: -8px; }
.menu__btn > span::after  { content: ''; top:  8px; }
.menu__box {
  display: block; position: fixed; top: 0; left: -100%;
  width: 300px; height: 100%; margin: 0; padding: 40px 0;
  list-style: none; background-color: #ECEFF1;
  box-shadow: 2px 2px 6px rgba(0,0,0,.4);
  transition-duration: .25s; overflow: auto;
}
.menu__item {
  display: block; padding: 12px 24px; color: #333;
  font-family: Arial, sans-serif; font-size: 18px;
  font-weight: 400; text-decoration: none; transition-duration: .25s;
}
.menu__item:hover { background-color: #CFD8DC; text-decoration: none; }
.menu__home { position: fixed; top: 7px; right: 17px; }
</style>

<style>
/* ── Reset & Base ─────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: Arial, Helvetica, Sans-Serif;
    color: #222;
}

/* ── Login ────────────────────────────────── */
.login-wrap {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 85vh;
}

.login-card {
    background: #fff;
    border: 1px solid #d0dce8;
    border-radius: 8px;
    padding: 44px 40px;
    width: 360px;
    box-shadow: 0 4px 20px rgba(46,141,239,.1);
}

.login-card h2 {
    text-align: center;
    font-size: 32px;
    font-weight: 700;
    letter-spacing: 1px;
    color: #222;
    margin-bottom: 30px;
}

.login-card label {
    display: block;
    font-size: 19px;
    color: #444;
    margin-bottom: 5px;
}

.login-card input[type=text],
.login-card input[type=password] {
    width: 100%;
    background: #fff;
    border: 1px solid #b0c4d8;
    color: #222;
    padding: 9px 12px;
    border-radius: 4px;
    font-size: 14px;
    margin-bottom: 18px;
    outline: none;
    transition: border-color .2s;
}
.login-card input:focus { border-color: #2e8def; }

.login-card select {
    width: 100%;
    background: #fff;
    border: 1px solid #b0c4d8;
    color: #222;
    padding: 9px 12px;
    border-radius: 4px;
    font-size: 14px;
    font-family: Verdana, Geneva, sans-serif;
    margin-bottom: 18px;
    outline: none;
    cursor: pointer;
    transition: border-color .2s;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%232e8def' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
}
.login-card select:focus { border-color: #2e8def; }

.btn-login {
    width: 100%;
    background: #2e8def;
    color: #fff;
    border: none;
    padding: 11px;
    border-radius: 4px;
    font-size: 14px;
    font-weight: bold;
    letter-spacing: 1px;
    cursor: pointer;
    transition: background .2s;
}
.btn-login:hover { background: #1a73d4; }

.error-msg {
    background: #fff0f0;
    border: 1px solid #e05555;
    color: #c0392b;
    padding: 10px 14px;
    border-radius: 4px;
    font-size: 13px;
    margin-bottom: 18px;
    text-align: center;
}

/* ── Fixed header wrapper ─────────────────── */
.fixed-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 50;
    background: #fff;
    border-bottom: 1px solid #e8edf2;
}

/* ── Top bar (progress + logout) ─────────── */
.top-bar {
    max-width: 1240px;
    margin: 0 auto;
    padding: 50px 20px 12px;
    display: flex;
    align-items: center;
    gap: 20px;
}

.progress-bar-wrap { flex: 1; }

.progress-info {
    display: flex;
    justify-content: space-between;
    font-size: 19px;
    color: #000;
    margin-bottom: 6px;
}

.progress-track {
    background: #c8ddf0;
    border-radius: 20px;
    height: 8px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #34ac65, #2dcc6f);
    border-radius: 20px;
}

.loggedin-info {
    font-size: 19px;
    color: #000;
    margin-bottom: 6px;
}

.btn-logout {
    background: #2e8def;
    border: none;
    color: #fff;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: normal;
    text-decoration: none;
    white-space: nowrap;
    transition: background .2s;
}
.btn-logout:hover { background: #1a73d4; }

/* ── Calendar ─────────────────────────────── */
.calendar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    max-width: 1240px;
    margin: 20px auto 40px;
    padding: 0 20px;
}

@media (max-width: 1000px) { .calendar { grid-template-columns: repeat(2, 1fr); } }
@media (max-width:  600px) { .calendar { grid-template-columns: 1fr; } }

/* ── Tip Box ──────────────────────────────── */
.tip-box {
    background: #fff;
    border: 1px solid;
    border-color: #80a5c3;
    border-radius: 10px;
    padding: 20px 18px 18px;
    aspect-ratio: 1 / 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: background .3s;
    color: #000;
    position: relative;
    overflow: hidden;
}

.tip-box.completed {
    background: #80a5c3;
    color: #fff;
}

/* Zone 1 – fixed min-height so descriptions always start at the same Y */
.tip-header {
    font-family: Arial, Helvetica, Sans-Serif;
    font-size: 22px;
    font-weight: bold;
    text-align: center;
    line-height: 1.4;
    width: 100%;
    min-height: 94px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
}

.tip-header .tip-num {
    font-size: 22px;
    font-weight: bold;
    color: #000;
    display: block;
    margin-bottom: 2px;
    line-height: 1.4;
}

.tip-box.completed .tip-header .tip-num { color: #fff; }

/* Zone 2 – description, top-aligned, fills middle space */
.tip-desc {
    width: 100%;
    flex: 1;
    display: flex;
    align-items: flex-start;
    padding-top: 4px;
    overflow: hidden;
}

.tip-desc p {
    font-size: 14px;
    font-weight: normal;
    text-align: center;
    line-height: 1.4;
    width: 100%;
    color: #000;
    opacity: .75;
}

.tip-box.completed .tip-desc p {
    color: #fff;
    opacity: .85;
}

/* Zone 3 – actions, always at the bottom */
.tip-actions {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding-top: 6px;
}

.tip-actions select {
    width: 100%;
    padding: 6px 8px;
    border-radius: 4px;
    border: 1px solid rgba(0,0,0,.2);
    background: rgba(255,255,255,.8);
    font-size: 14px;
    color: #333;
    cursor: pointer;
}

.tip-actions select:disabled {
    background: #a7bed0;
    color: #fff;
    cursor: default;
}

/* Buttons */
.btn-select, .btn-submit, .btn-change {
    border: 1px solid;
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 14px;
    font-weight: normal;
    cursor: pointer;
    letter-spacing: .5px;
    transition: background .2s;
}

.btn-select {
    background: #e94560;
    color: #fff;
}
.btn-select:hover { background: #c73652; }

.btn-submit {
    background: #2ecc71;
    color: #fff;
    border-color: #27ae60;
}
.btn-submit:hover { background: #27ae60; }

.btn-change {
    background: rgba(255,255,255,.25);
    color: inherit;
    border: 1px solid rgba(255,255,255,.4);
    text-decoration: none;
    display: inline-block;
}
.btn-change:hover { background: rgba(255,255,255,.4); }

/* ── Footer ───────────────────────────────── */
footer {
    text-align: center;
    padding: 20px;
    font-size: 16px;
    color: #000;
}
</style>

</head>

<body bgcolor="#FFFFFF" text="#000000" link='#000000' alink='#000000' vlink='#000000'>

<link href="../shoutbox/style.css" rel="stylesheet" type="text/css" />

<div class="hamburger-menu">
    <input id="menu__toggle" type="checkbox" />
    <label class="menu__btn" for="menu__toggle">
        <span></span>
    </label>
    <ul class="menu__box">
        <li><h1>&nbsp;&nbsp;BETSY</h1></li>
        <li><a class="menu__item" href="score.php" target="mainFrame">Score</a></li>
        <li><a class="menu__item" href="results.php" target="mainFrame">Results</a></li>
        <li><a class="menu__item" href="admin/admin.html" target="mainFrame">Admin</a></li>
    </ul>
    <div class="menu__home">
        <a href="betsy.php" target="mainFrame"><img src="../../images/home.png" width="32" height="28"></a>
    </div>
</div>

<?php if (!$logged_in): ?>
<!-- ── LOGIN ────────────────────────────────────────────────── -->
<div class="login-wrap">
    <div class="login-card">
        <h2>Login</h2>
        <?php if ($login_error): ?>
            <div class="error-msg"><?php echo esc($login_error); ?></div>
        <?php endif; ?>
        <form method="POST" action="">
            <label>You</label>
            <select name="selectuser" required>
                <option value="">---------- please select ----------</option>
                <?php foreach ($login_users as $lu): ?>
                    <option value="<?php echo (int)$lu['u_id']; ?>"
                        <?php echo (isset($_POST['selectuser']) && (int)$_POST['selectuser'] === (int)$lu['u_id']) ? 'selected' ''?>>
                        <?php echo esc($lu['u_name']); ?>
                    </option>
                <?php endforeach; ?>
            </select>
            <label>Your Passcode</label>
            <input type="password" name="passcode" autocomplete="current-password" required>
            <button type="submit" name="login" class="btn-login">Enter</button>
        </form>
    </div>
</div>

<?php else: ?>
<!-- ── TOP BAR (progress + logout) ─────────────────────────── -->
<?php
    $total 
count($tips);
    
$done  count($user_picks);
    
$pct   $total round($done $total 100) : 0;
?>
<div class="fixed-header" id="fixed-header">
<div class="top-bar">
    <div class="progress-bar-wrap">
        <div class="progress-info">
            <span>Saved Results:</span>
            <span><?php echo $done?> / <?php echo $total?> submitted (<?php echo $pct?>%)</span>
        </div>
        <div class="progress-track">
            <div class="progress-fill" style="width:<?php echo $pct?>%"></div>
        </div>
    </div>
    <div class="loggedin-info">
        <span>&nbsp;&nbsp;&nbsp;&nbsp;Logged in as <strong><?php echo esc($_SESSION['u_name']); ?></strong>&nbsp;&nbsp;&nbsp;&nbsp;</span>
        <a href="?logout=1" class="btn-logout">Logout</a>
    </div>
</div><!-- /.fixed-header -->

<!-- ── CALENDAR ─────────────────────────────────────────────── -->
<div class="calendar" id="calendar">
<?php foreach ($tips as $tip):
    
$bid       = (int)$tip['b_id'];
    
$bet       $tip['b_bet'];
    
$desc      $tip['b_desc'];
    
$completed = isset($user_picks[$bid]);
    
$cls       $completed 'tip-box completed' 'tip-box';
    
$ttype     = isset($tip_type[$bid]) ? $tip_type[$bid] : 'driver';
    
$list      = ($ttype === 'driver') ? $drivers $teams;

    
$cur_id      $completed ? (int)$user_picks[$bid]['id']     : 0;
    
$cur_display $completed esc($user_picks[$bid]['display']) : '';

    
$is_editing  = ($edit_bid === $bid);
?>
    <div class="<?php echo $cls?>" id="tip-<?php echo $bid?>">

        <!-- Zone 1: Number + Title -->
        <div class="tip-header">
            <span class="tip-num"><?php echo $bid?>.</span>
            <?php echo $bet?>
        </div>

        <!-- Zone 2: Description -->
        <div class="tip-desc">
            <?php if ($desc): ?>
                <p><?php echo $desc?></p>
            <?php endif; ?>
        </div>

        <!-- Zone 3: Actions (dropdown + button) -->
        <div class="tip-actions">
            <?php if ($completed && !$is_editing): ?>
                <!-- Saved result view: greyed-out dropdown + Change button -->
                <select disabled>
                    <option><?php echo $cur_display?></option>
                </select>
                <a href="<?php echo esc($_SERVER['PHP_SELF']); ?>?edit=<?php echo $bid?>"
                   class="btn-change">Change</a>

            <?php elseif ($completed && $is_editing): ?>
                <!-- Edit view: active dropdown pre-selected with current value + Submit -->
                <form method="POST" action="<?php echo esc($_SERVER['PHP_SELF']); ?>" style="margin:0;width:100%;text-align:center">
                    <input type="hidden" name="betsy_action" value="save">
                    <input type="hidden" name="b_id" value="<?php echo $bid?>">
                    <select name="selection" style="width:100%;margin-bottom:6px">
                        <option value="">-- please select --</option>
                        <?php foreach ($list as $item): ?>
                            <option value="<?php echo (int)$item['id']; ?>"
                                <?php echo ($item['id'] === $cur_id) ? 'selected' ''?>>
                                <?php echo esc($item['name']); ?>
                            </option>
                        <?php endforeach; ?>
                    </select>
                    <button type="submit" class="btn-submit">Submit</button>
                </form>

            <?php else: ?>
                <!-- No result yet: Select button reveals dropdown -->
                <div id="sw-<?php echo $bid?>" style="display:none;width:100%;text-align:center">
                    <form method="POST" action="<?php echo esc($_SERVER['PHP_SELF']); ?>" style="margin:0">
                        <input type="hidden" name="betsy_action" value="save">
                        <input type="hidden" name="b_id" value="<?php echo $bid?>">
                        <select name="selection" style="width:100%;margin-bottom:6px">
                            <option value="">-- please select --</option>
                            <?php foreach ($list as $item): ?>
                                <option value="<?php echo (int)$item['id']; ?>"><?php echo esc($item['name']); ?></option>
                            <?php endforeach; ?>
                        </select>
                        <button type="submit" class="btn-submit">Submit</button>
                    </form>
                </div>
                <button class="btn-select"
                    onclick="document.getElementById('sw-<?php echo $bid?>').style.display='block';this.style.display='none';">Select</button>
            <?php endif; ?>
        </div>

    </div>
<?php endforeach; ?>
</div>

<?php endif; ?>

<footer>
    &copy; 2027 - GRID TIP
</footer>

<script>
window.onload = function() {
    var fh = document.getElementById('fixed-header');
    if (!fh) return;
    function setPad() { document.body.style.paddingTop = fh.offsetHeight + 'px'; }
    setPad();
    window.addEventListener('resize', setPad);
};
</script>

</body>
</html>