blob: 3a22ca443e5c1b6350f74a8e177cddc79636b78d [file] [log] [blame]
Andreufd98b5d2019-09-22 13:15:10 +02001<?php
2 require '../credentials.php';
3 require '../php/utils.php';
Adrià Vilanova Martínez36362912022-11-20 01:30:13 +01004
5 $credentials = new Credentials();
Adrià Vilanova Martínez60524332022-11-20 02:33:56 +01006 if ($credentials->adminToken() != ($_POST["token"] ?? "")) {
Adrià Vilanova Martínez36362912022-11-20 01:30:13 +01007 exit();
8 }
9
Andreu8192d552019-09-22 16:51:39 +020010 $csvname = $_FILES['csvname']['tmp_name'];
11 $dbname = $_POST['dbname'];
Andreub78c8792019-09-22 14:51:13 +020012
13 // Read from CSV
Andreu8192d552019-09-22 16:51:39 +020014 $inscrits = array_map('str_getcsv', file($csvname));
Andreub78c8792019-09-22 14:51:13 +020015 array_shift($inscrits); // remove header
Andreu20af6c22019-09-24 18:33:50 +020016 shuffle($inscrits); // shuffle randomly
Andreufd98b5d2019-09-22 13:15:10 +020017
Andreub78c8792019-09-22 14:51:13 +020018 $start = 1;
Andreufd98b5d2019-09-22 13:15:10 +020019 $i = $start;
20 foreach ($inscrits as $user) {
21 $i = ($i + 1) % ($start + count($inscrits));
22 if ($i == 0) $i = $i + 1;
Andreu20af6c22019-09-24 18:33:50 +020023 // 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).")";
Andreu8192d552019-09-22 16:51:39 +020026
Andreu20af6c22019-09-24 18:33:50 +020027 if (!query($template)) die("An error ocurred." . $template);
Andreufd98b5d2019-09-22 13:15:10 +020028 }
Andreu99501052019-09-22 20:09:08 +020029
Andreu03d030d2019-09-25 21:52:01 +020030 die("<script>window.location.href = './?successinserting'</script>");
Andreufd98b5d2019-09-22 13:15:10 +020031?>