-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass.php
More file actions
136 lines (115 loc) · 3.2 KB
/
Copy pathclass.php
File metadata and controls
136 lines (115 loc) · 3.2 KB
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
<?php
include "properties.inc.php";
class Reklamateur {
public $id = "";
public $name = "";
public $tel = "";
public $anschrift = "";
private $c;
public function __construct() {
$this->c = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$this->generate_id();
}
private function generate_id() {
$id_found = false;
$id = 0;
while($id_found == false) {
$id = rand(0, 9999999999);
$select = "SELECT * FROM reklamateur WHERE id = '".$id."'";
$result = mysqli_query($this->c, $select);
$count = 0;
while($result = mysqli_fetch_assoc($result)) {
$count++;
}
if($count == 0) {
$id_found = true;
}
}
$this->id = $id;
}
}
class Reklamation {
private $id = "";
public $produkt = "";
public $komponente = "";
public $datum = "";
public $reklamateur;
private $c;
public function __construct($id = "") {
$this->c = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$this->reklamateur = new Reklamateur();
if($id == "") {
$this->generate_id();
$this->datum = date("d.m.Y");
} else {
$this->id = $id;
fetch_data();
}
}
private function generate_id() {
$id_found = false;
$id = 0;
while($id_found == false) {
$id = rand(0, 9999999999);
$select = "SELECT * FROM reklamation WHERE id = '".$id."'";
$result = mysqli_query($this->c, $select);
$count = 0;
while($result = mysqli_fetch_assoc($result)) {
$count++;
}
if($count == 0) {
$id_found = true;
}
}
$this->id = $id;
}
private function fetch_data() {
$select_rekla = "SELECT * FROM reklamation WHERE id = '".$this->id."'";
$rekla = mysqli_query($this->c, $select_rekla);
$row_rekla = mysqli_fetch_assoc($rekla);
$this->produkt = $row_rekla["produkt"];
$this->komponente = $row_rekla["komponente"];
$this->datum = $row_rekla["datum"];
$select_reklamateur = "SELECT * FROM reklamateur WHERE id = '".$row["reklamateur"]."'";
$reklamateur = mysqli_query($this->c, $select_reklamateur);
$row_reklamateur = mysqli_fetch_assoc($reklamateur);
$this->reklamateur->id = $row_reklamateur["id"];
$this->reklamateur->name = $row_reklamateur["name"];
$this->reklamateur->tel = $row_reklamateur["tel"];
$this->reklamateur->anschrift = $row_reklamateur["anschrift"];
}
public function save() {
$reklamateur_insert = "INSERT INTO reklamateur (id, name, tel, anschrift) VALUES (".
"'".$this->reklamateur->id."', ".
"'".$this->reklamateur->name."', ".
"'".$this->reklamateur->tel."', ".
"'".$this->reklamateur->anschrift."'".
")";
$rekla_insert = "INSERT INTO reklamation (id, produkt, komponente, reklamateur, datum) VALUES (".
"'".$this->id."', ".
"'".$this->produkt."', ".
"'".$this->komponente."', ".
"'".$this->reklamateur->id."', ".
"'".$this->datum."'".
")";
mysqli_query($this->c, $reklamateur_insert);
mysqli_query($this->c, $rekla_insert);
}
// GETTER
public function get_id() {
return $this->id;
}
}
/*
* Ab hier der Testcode.
*/
/*
$reklamation = new Reklamation();
$reklamation->produkt = "Laptop";
$reklamation->komponente = "Maus";
$reklamation->reklamateur->name = "Felix";
$reklamation->reklamateur->tel = "0815";
$reklamation->reklamateur->anschrift = "Von Nebenan";
$reklamation->save();
*/
?>