CoolFace
Apppublic

zmedla/electionexpressballotbox

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
voting.php107 linesDownload Raw Back to root
1```php2<?php3require_once 'functions.php';4session_start();5 6if (!isset($_SESSION['user_id']) || $_SESSION['role'] != 'voter') {7    header("Location: index.html");8    exit();9}10 11$candidates = getCandidates();12 13if ($_SERVER['REQUEST_METHOD'] == 'POST') {14    if (isset($_POST['submit_vote'])) {15        $candidateId = $_POST['candidate_id'];16        if (recordVote($_SESSION['user_id'], $candidateId)) {17            header("Location: receipt.php");18            exit();19        } else {20            $error = "Failed to record your vote";21        }22    }23}24?>25<!DOCTYPE html>26<html lang="en">27<head>28    <meta charset="UTF-8">29    <meta name="viewport" content="width=device-width, initial-scale=1.0">30    <title>Election Express - Voting</title>31    <link rel="stylesheet" href="https://cdn.tailwindcss.com">32    <style>33        .candidate-card {34            transition: all 0.3s ease;35        }36        .candidate-card:hover {37            transform: translateY(-5px);38            box-shadow: 0 10px 20px rgba(0,0,0,0.1);39        }40        .selected {41            border: 3px solid #3b82f6;42        }43    </style>44</head>45<body class="bg-gray-100">46    <div class="container mx-auto px-4 py-8">47        <header class="mb-8 text-center">48            <h1 class="text-3xl font-bold text-blue-800">Election Express</h1>49            <p class="text-blue-600">Cast Your Vote Securely</p>50        </header>51 52        <?php if (isset($error)): ?>53            <div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-4">54                <?php echo $error; ?>55            </div>56        <?php endif; ?>57 58        <form method="POST" class="max-w-4xl mx-auto">59            <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">60                <?php foreach ($candidates as $candidate): ?>61                    <div class="candidate-card bg-white rounded-lg shadow-md overflow-hidden cursor-pointer relative">62                        <input type="radio" name="candidate_id" value="<?php echo $candidate['id']; ?>" 63                               id="candidate_<?php echo $candidate['id']; ?>" class="hidden peer">64                        <label for="candidate_<?php echo $candidate['id']; ?>" class="block">65                            <div class="p-4">66                                <img src="<?php echo $candidate['photo'] ?: 'http://static.photos/people/320x240'; ?>" 67                                     alt="<?php echo $candidate['name']; ?>" 68                                     class="w-full h-48 object-cover rounded">69                                <div class="mt-4">70                                    <h3 class="text-lg font-semibold"><?php echo $candidate['name']; ?></h3>71                                    <p class="text-gray-600"><?php echo $candidate['party']; ?></p>72                                </div>73                            </div>74                        </label>75                    </div>76                <?php endforeach; ?>77            </div>78 79            <div class="mt-8 flex justify-between">80                <button type="button" onclick="window.location.href='logout.php'" 81                        class="bg-gray-500 hover:bg-gray-600 text-white px-6 py-2 rounded">82                    Logout83                </button>84                <button type="submit" name="submit_vote" 85                        class="bg-blue-500 hover:bg-blue-600 text-white px-6 py-2 rounded">86                    Submit Vote87                </button>88            </div>89        </form>90    </div>91 92    <script>93        // Add selection highlight94        document.querySelectorAll('.candidate-card').forEach(card => {95            card.addEventListener('click', function() {96                const radio = this.querySelector('input[type="radio"]');97                radio.checked = true;98                document.querySelectorAll('.candidate-card').forEach(c => {99                    c.classList.remove('selected');100                });101                this.classList.add('selected');102            });103        });104    </script>105</body>106</html>107```
zmedla/electionexpressballotbox · CoolFace