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 | fd98b5d | 2019-09-22 13:15:10 +0200 | [diff] [blame] | 11 | |
Andreu | b78c879 | 2019-09-22 14:51:13 +0200 | [diff] [blame] | 12 | $start = 1; |
Andreu | fd98b5d | 2019-09-22 13:15:10 +0200 | [diff] [blame] | 13 | $i = $start; |
| 14 | foreach ($inscrits as $user) { |
| 15 | $i = ($i + 1) % ($start + count($inscrits)); |
| 16 | if ($i == 0) $i = $i + 1; |
Andreu | 8192d55 | 2019-09-22 16:51:39 +0200 | [diff] [blame] | 17 | $template = "INSERT INTO `".$dbname."` (`id`, `nom`, `curs`, `grau`, `quimata`, `requested`, `mort`, `password`)" . |
Andreu | fd98b5d | 2019-09-22 13:15:10 +0200 | [diff] [blame] | 18 | " VALUES (NULL, '".$user[0]."', '".$user[1]."', '".$user[2]."', ".$i.", '0', '0', '')"; |
Andreu | 8192d55 | 2019-09-22 16:51:39 +0200 | [diff] [blame] | 19 | |
Andreu | 9950105 | 2019-09-22 20:09:08 +0200 | [diff] [blame] | 20 | if (!query($template)) die("An error ocurred."); |
Andreu | fd98b5d | 2019-09-22 13:15:10 +0200 | [diff] [blame] | 21 | } |
Andreu | 9950105 | 2019-09-22 20:09:08 +0200 | [diff] [blame] | 22 | |
Andreu | 4b2fbd9 | 2019-09-22 22:30:25 +0200 | [diff] [blame^] | 23 | die("<script>window.location.href = './index.php'</script>"); |
Andreu | fd98b5d | 2019-09-22 13:15:10 +0200 | [diff] [blame] | 24 | ?> |