Andreu | fd98b5d | 2019-09-22 13:15:10 +0200 | [diff] [blame] | 1 | <?php |
| 2 | require '../credentials.php'; |
| 3 | require '../php/utils.php'; |
Andreu | 8192d55 | 2019-09-22 16:51:39 +0200 | [diff] [blame] | 4 | |
| 5 | $csvname = $_FILES['csvname']['tmp_name']; |
| 6 | $dbname = $_POST['dbname']; |
Andreu | b78c879 | 2019-09-22 14:51:13 +0200 | [diff] [blame] | 7 | |
| 8 | // Read from CSV |
Andreu | 8192d55 | 2019-09-22 16:51:39 +0200 | [diff] [blame] | 9 | $inscrits = array_map('str_getcsv', file($csvname)); |
Andreu | b78c879 | 2019-09-22 14:51:13 +0200 | [diff] [blame] | 10 | array_shift($inscrits); // remove header |
Andreu | 20af6c2 | 2019-09-24 18:33:50 +0200 | [diff] [blame] | 11 | shuffle($inscrits); // shuffle randomly |
Andreu | fd98b5d | 2019-09-22 13:15:10 +0200 | [diff] [blame] | 12 | |
Andreu | b78c879 | 2019-09-22 14:51:13 +0200 | [diff] [blame] | 13 | $start = 1; |
Andreu | fd98b5d | 2019-09-22 13:15:10 +0200 | [diff] [blame] | 14 | $i = $start; |
| 15 | foreach ($inscrits as $user) { |
| 16 | $i = ($i + 1) % ($start + count($inscrits)); |
| 17 | if ($i == 0) $i = $i + 1; |
Andreu | 20af6c2 | 2019-09-24 18:33:50 +0200 | [diff] [blame] | 18 | // Input values into SQL values |
| 19 | $template = "INSERT INTO `$dbname` (`id`, `nom`, `curs`, `grau`, `quimata`, `requested`, `mort`, `password`, `bits`)" . |
| 20 | " 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] | 21 | |
Andreu | 20af6c2 | 2019-09-24 18:33:50 +0200 | [diff] [blame] | 22 | if (!query($template)) die("An error ocurred." . $template); |
Andreu | fd98b5d | 2019-09-22 13:15:10 +0200 | [diff] [blame] | 23 | } |
Andreu | 9950105 | 2019-09-22 20:09:08 +0200 | [diff] [blame] | 24 | |
Andreu | 20af6c2 | 2019-09-24 18:33:50 +0200 | [diff] [blame] | 25 | die("<script>window.location.href = './index.php?successinserting'</script>"); |
Andreu | fd98b5d | 2019-09-22 13:15:10 +0200 | [diff] [blame] | 26 | ?> |