-
Notifications
You must be signed in to change notification settings - Fork 0
/
session_list.php
136 lines (117 loc) · 4.62 KB
/
session_list.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
session_start();
$db = mysqli_connect('localhost', 'root', 'root', 'planningpoker');
if (isset($_POST['get_sessions'])) {
get_sessions($db);
} elseif (isset($_POST['delete_session'])) {
delete_session($db);
get_sessions($db);
} elseif (isset($_POST['join_session'])) {
join_session($db);
} elseif (isset($_POST['story_overview'])) {
story_overview($db);
}
// ERSTE LÖSUNG - Werte über GET übergeben. Allerdings konnten so die Tabellenwerte geändert werden und fremde Sessions gelöscht werden
function get_sessions($db)
{
$ids = array();
$names = array();
$dates = array();
$query = mysqli_prepare($db, "SELECT id,name,date FROM session WHERE user_id =?");
$search = $_SESSION['user_id'];
mysqli_stmt_bind_param($query, "s", $search);
mysqli_stmt_execute($query);
mysqli_stmt_bind_result($query, $id, $name, $date);
// die einzelnen Werte (Id, Name, Datum) werden in ein Array geschrieben und mit implode in einen String umgewandelt
while (mysqli_stmt_fetch($query)) {
array_push($ids, $id);
array_push($names, $name);
array_push($dates, $date);
}
mysqli_stmt_close($query);
$ids = implode(",", $ids);
$names = implode(",", $names);
$dates = implode(",", $dates);
header("Location: session_list_view.php?ids=$ids&names=$names&dates=$dates");
die();
}
// Der ersteller einer Session kann über diese Ansicht all seinen erstellten Sessions beitreten
function join_session($db)
{
$session_id = $_POST['join_session'];
$query = "SELECT user_id FROM session WHERE id = '$session_id'";
$result = mysqli_query($db, $query);
$user = mysqli_fetch_assoc($result);
if ($user['user_id'] != $_SESSION['user_id']) {
mysqli_close($db);
$error = "Ungültig";
header("Location: session_list_view.php?invalid=$error");
die();
} else {
$query = "SELECT * FROM session WHERE id='$session_id'";
$results = mysqli_query($db, $query);
if (mysqli_num_rows($results) == 1) {
$row = $results->fetch_assoc();
$session_name = $row['name'];
$_SESSION['session_name'] = $session_name;
$_SESSION['session_id'] = $session_id;
$_SESSION['admin'] = 0;
mysqli_close($db);
header("Location: separate_view.php");
die();
} else {
mysqli_close($db);
$fatal_error = "Es ist ein nicht erwarteter Fehler mit der Session aufgetreten";
header("Location: session_list_view.php?invalid=$fatal_error");
die();
}
}
}
// der ersteller einer Session kann diese auch wieder löschen
function delete_session($db)
{
$value = $_POST['delete_session'];
$query = "SELECT user_id FROM session WHERE id = '$value'";
$result = mysqli_query($db, $query);
$user = mysqli_fetch_assoc($result);
if ($user['user_id'] != $_SESSION['user_id']) {
mysqli_close($db);
$error = "Ungültig";
header("Location: session_list_view.php?invalid=$error");
die();
} else {
$query = "DELETE FROM session WHERE id = '$value'";
mysqli_query($db, $query);
$query = "DELETE FROM storypoints WHERE session_id = '$value'";
mysqli_query($db, $query);
$query = "DELETE FROM session_users WHERE session_id = '$value'";
mysqli_query($db, $query);
$query = "DELETE FROM storypoints_sumamry WHERE session_id = '$value'";
mysqli_query($db, $query);
}
}
// werden die einzelnen Userstorys mit Punkten aufgelistet
function story_overview($db) {
$points = array();
$userstorys = array();
$session_id = $_POST['story_overview'];
$query = mysqli_prepare($db, "SELECT points, userstory FROM storypoints_summary WHERE session_id = ?");
mysqli_stmt_bind_param($query, "s", $session_id);
mysqli_stmt_execute($query);
mysqli_stmt_bind_result($query, $db_point, $db_userstory);
while (mysqli_stmt_fetch($query)) {
array_push($points, $db_point);
array_push($userstorys, $db_userstory);
}
$query = mysqli_prepare($db, "SELECT name FROM session WHERE id = ?");
mysqli_stmt_bind_param($query, "s", $session_id);
mysqli_stmt_execute($query);
$result = mysqli_stmt_get_result($query);
$name = mysqli_fetch_array($result, MYSQLI_NUM)[0];
mysqli_close($db);
// http_build_query:
$query_story = http_build_query(array('aParam' => $userstorys));
$query_points = http_build_query(array('aParam1' => $points));
header("Location: story_overview_view.php?$query_story&$query_points&session_name=$name&session_id=$session_id");
die();
}