-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbconnect.php
165 lines (127 loc) · 3.89 KB
/
dbconnect.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php
class DBconnect {
private $db = NULL;
function __construct() {
$this->db = new mysqli("localhost", "d.meixner", "d(_xaV5:CK", "d_meixner","3308") or die("Error " . mysqli_error($this->db));
mysqli_set_charset($this->db, "UTF-8");
}
function query($string) {
return $this->db->query($string);
}
function saveDates($dates, $comments) {
$i = 0;
foreach ($dates as $date) {
$this->query("INSERT INTO godis (date, comment) VALUES ('$date', '". $comments[$i] . "');");
$i++;
}
}
function saveMinis($minis) {
foreach ($minis as $mini) {
$this->query("INSERT INTO minis (name, absent) VALUES ('$mini', '');");
}
}
function delMini($mini) {
return $this->query("DELETE FROM minis WHERE name LIKE '$mini';");
}
function getDates() {
$result = $this->query("SELECT * FROM godis;");
$allDatesArr = array();
while ($row = mysqli_fetch_object($result)) {
array_push($allDatesArr, $row);
}
return $allDatesArr;
}
function getDate($id) {
return $this->getGodi($id)->date;
}
function getGodi($id) {
$result = $this->query("SELECT * FROM godis WHERE id = '$id'");
return mysqli_fetch_object($result);
}
function getMinis() {
$result = $this->query("SELECT * FROM minis;");
$allMinisArr = array();
while ($row = mysqli_fetch_object($result)) {
array_push($allMinisArr, $row);
}
return $allMinisArr;
}
/**
* @return array mit Namen
*/
function getMiniNames() {
$arr = $this->getMinis();
$tmp = array();
foreach ($arr as $mini) {
array_push($tmp, $mini->name);
}
return $tmp;
}
function setMiniAbsent($name, $absentStr) {
return $this->query("UPDATE minis SET absent = '$absentStr' WHERE name LIKE '$name';");
}
function setMiniAbsentOn($name, $id) {
$date = $this->getDate($id);
$absentStr = $this->getMini($name)->absent;
$absentStr .= ', ' . $date;
return $this->setMiniAbsent($name, $absentStr);
}
function getMini($name) {
$result = $this->query("SELECT * FROM minis WHERE name LIKE '$name';");
return mysqli_fetch_object($result);
}
function isAbsent($name, $date) {
$date = trim($date);
$mini = $this->getMini($name);
$absent = explode(",", $mini->absent);
$absentTrim = array();
foreach($absent as $absentDate) {
$absentTrim[] = trim($absentDate);
}
return in_array($date, $absentTrim);
}
function setMini($name, $id) {
$mini = $this->query("SELECT minis FROM godis WHERE id LIKE '$id';");
$miniStrA = mysqli_fetch_array($mini);
$miniStr = $miniStrA[0];
if(is_null($miniStr)) {
$miniStr = "";
}
$miniStr .= "$name, ";
return $this->query("UPDATE godis SET minis = '$miniStr' WHERE id = $id;");
}
function resetMinis() {
return $this->query("UPDATE godis SET minis = '' WHERE 1;");
}
function resetGodis() {
$this->query("DELETE FROM godis WHERE 1;");
$this->query("DELETE FROM plan WHERE 1;");
}
function saveVonBis($von, $bis) {
return $this->query("INSERT INTO plan (von, bis) VALUES ('$von', '$bis');");
}
function getVonBis() {
$vb = $this->query("SELECT * FROM plan WHERE 1 LIMIT 1;");
$vbO = mysqli_fetch_object($vb);
if(isset($vbO->von) && isset($vbO->bis)) {
return array('von' => $vbO->von, 'bis' => $vbO->bis);
} else {
return array('von' => '#Datum', 'bis' => '#Datum');
}
}
function resetAbsent() {
return $this->query("UPDATE minis SET absent = '' WHERE 1;");
}
function getMinisOfMass($massid) {
$result = $this->query("SELECT * FROM godis WHERE id = '$massid';");
$godi = mysqli_fetch_object($result);
$miniarray = array();
foreach(explode(',', $godi->minis) as $mini) {
$miniarray[] = trim($mini);
}
return $miniarray;
}
function editGodi($id, $date, $comment) {
return $this->query("UPDATE godis SET date='$date', comment='$comment' WHERE id = $id;");
}
}