Andreu | fd98b5d | 2019-09-22 13:15:10 +0200 | [diff] [blame] | 1 | <?php |
| 2 | require '../credentials.php'; |
| 3 | require '../php/utils.php'; |
Adrià Vilanova Martínez | 3636291 | 2022-11-20 01:30:13 +0100 | [diff] [blame] | 4 | |
| 5 | $credentials = new Credentials(); |
Adrià Vilanova Martínez | 6052433 | 2022-11-20 02:33:56 +0100 | [diff] [blame] | 6 | if ($credentials->adminToken() != ($_POST["token"] ?? "")) { |
Adrià Vilanova Martínez | 3636291 | 2022-11-20 01:30:13 +0100 | [diff] [blame] | 7 | exit(); |
| 8 | } |
| 9 | |
Andreu | 8192d55 | 2019-09-22 16:51:39 +0200 | [diff] [blame] | 10 | $csvname = $_FILES['csvname']['tmp_name']; |
| 11 | $dbname = $_POST['dbname']; |
Andreu | b78c879 | 2019-09-22 14:51:13 +0200 | [diff] [blame] | 12 | |
| 13 | // Read from CSV |
Andreu | 8192d55 | 2019-09-22 16:51:39 +0200 | [diff] [blame] | 14 | $inscrits = array_map('str_getcsv', file($csvname)); |
Andreu | b78c879 | 2019-09-22 14:51:13 +0200 | [diff] [blame] | 15 | array_shift($inscrits); // remove header |
Andreu | 20af6c2 | 2019-09-24 18:33:50 +0200 | [diff] [blame] | 16 | shuffle($inscrits); // shuffle randomly |
Andreu | fd98b5d | 2019-09-22 13:15:10 +0200 | [diff] [blame] | 17 | |
Andreu | b78c879 | 2019-09-22 14:51:13 +0200 | [diff] [blame] | 18 | $start = 1; |
Andreu | fd98b5d | 2019-09-22 13:15:10 +0200 | [diff] [blame] | 19 | $i = $start; |
| 20 | foreach ($inscrits as $user) { |
| 21 | $i = ($i + 1) % ($start + count($inscrits)); |
| 22 | if ($i == 0) $i = $i + 1; |
Andreu | 20af6c2 | 2019-09-24 18:33:50 +0200 | [diff] [blame] | 23 | // Input values into SQL values |
| 24 | $template = "INSERT INTO `$dbname` (`id`, `nom`, `curs`, `grau`, `quimata`, `requested`, `mort`, `password`, `bits`)" . |
| 25 | " VALUES (NULL, '$user[0]', '$user[1]', '$user[2]', $i, 0, 0, '', ".(int)rand(1,512).")"; |
Andreu | 8192d55 | 2019-09-22 16:51:39 +0200 | [diff] [blame] | 26 | |
Andreu | 20af6c2 | 2019-09-24 18:33:50 +0200 | [diff] [blame] | 27 | if (!query($template)) die("An error ocurred." . $template); |
Andreu | fd98b5d | 2019-09-22 13:15:10 +0200 | [diff] [blame] | 28 | } |
Andreu | 9950105 | 2019-09-22 20:09:08 +0200 | [diff] [blame] | 29 | |
Andreu | 03d030d | 2019-09-25 21:52:01 +0200 | [diff] [blame] | 30 | die("<script>window.location.href = './?successinserting'</script>"); |
Andreu | fd98b5d | 2019-09-22 13:15:10 +0200 | [diff] [blame] | 31 | ?> |