blob: 6f793a1565fa7b9b8c12f83123e3b5c463fd7aa4 [file] [log] [blame]
Andreufd98b5d2019-09-22 13:15:10 +02001<?php
2 require '../credentials.php';
3 require '../php/utils.php';
Andreu8192d552019-09-22 16:51:39 +02004
5 $csvname = $_FILES['csvname']['tmp_name'];
6 $dbname = $_POST['dbname'];
Andreub78c8792019-09-22 14:51:13 +02007
8 // Read from CSV
Andreu8192d552019-09-22 16:51:39 +02009 $inscrits = array_map('str_getcsv', file($csvname));
Andreub78c8792019-09-22 14:51:13 +020010 array_shift($inscrits); // remove header
Andreufd98b5d2019-09-22 13:15:10 +020011
Andreub78c8792019-09-22 14:51:13 +020012 $start = 1;
Andreufd98b5d2019-09-22 13:15:10 +020013 $i = $start;
14 foreach ($inscrits as $user) {
15 $i = ($i + 1) % ($start + count($inscrits));
16 if ($i == 0) $i = $i + 1;
Andreu0530b302019-09-24 04:18:20 +020017 $template = "INSERT INTO `".$dbname."` (`id`, `nom`, `curs`, `grau`, `quimata`, `requested`, `mort`, `password`, `bits`)" .
18 " VALUES (NULL, '".$user[0]."', '".$user[1]."', '".$user[2]."', ".$i.", 0, 0, '', ".(int)rand(1,512).")";
Andreu8192d552019-09-22 16:51:39 +020019
Andreu99501052019-09-22 20:09:08 +020020 if (!query($template)) die("An error ocurred.");
Andreufd98b5d2019-09-22 13:15:10 +020021 }
Andreu99501052019-09-22 20:09:08 +020022
Andreu4b2fbd92019-09-22 22:30:25 +020023 die("<script>window.location.href = './index.php'</script>");
Andreufd98b5d2019-09-22 13:15:10 +020024?>