-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadd-team.php
61 lines (57 loc) · 1.93 KB
/
add-team.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/**
* Coding Pirates Teaminator
* Used to generate teams at Coding Pirates Game Jam 2015-2016
*/
include("header.php");
// see if form was already submitted
if(!isset($_REQUEST['submit'])) {
// Form not submitted yet
// Fetch names
$sql = "SELECT ID, name, age FROM participants WHERE teaminated=0 AND updated_since_csv=1";
$names = $db->query($sql);
?>
<form class="names" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<select multiple="multiple" size="10" name="names_teams[]">
<?php
foreach ($names as $name) {
echo "<option value=\"" . $name['ID'] . "\">" . $name['name'] . " - " . $name['age'] . " år" . "</option>";
}
?>
</select>
<br />
<button name="submit" type="submit" class="btn btn-default btn-block">Tilføj hold</button>
</form>
<script>var names = $('.names').bootstrapDualListbox({moveOnSelect:false});</script>
<?php
} else {
// Okay submitted - get selected team members
if(isset($_REQUEST['names_teams'])) {
$names = $_REQUEST['names_teams'];
if(!isset($names)) {
die("Du har ikke valgt nogen holddeltagere.");
} else {
$sql = "INSERT INTO team (team_ID, participants_ID, created) VALUES (:team_ID, :participants_ID, :created)";
$nNames = count($names);
$next_ID_sql = "SELECT team_ID FROM team ORDER BY team_ID DESC LIMIT 1";
$nextid = $db->query($next_ID_sql);
$next_team_ID = $nextid['0']["team_ID"] + 1;
$update_sql = "UPDATE participants SET teaminated=1 WHERE ID=:ID";
foreach($names as $name) {
$update_value = [
[":ID",$name]
];
$values = [
[":team_ID",$next_team_ID],
[":participants_ID",$name],
[":created",1]
];
$db->query($sql,$values);
$db->query($update_sql,$update_value);
}
echo "Hold " . $next_team_ID . " tilføjet med " . $nNames . " deltagere.";
}
}
}
include("footer.php");
?>