-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevents.class.php
More file actions
141 lines (107 loc) · 4.21 KB
/
Copy pathevents.class.php
File metadata and controls
141 lines (107 loc) · 4.21 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
137
138
139
140
141
<?php
class Events{
private $connection;
function __construct($mysqli){
$this->connection = $mysqli;
}
function newEvent($type, $date, $price, $descr){
$stmt = $this->connection->prepare("INSERT INTO events_archive (eventType, eventDate, eventPrice, eventDescr) VALUES (?,?,?,?)");
$stmt->bind_param("ssds", $type, $date, $price, $descr);
if($stmt->execute()){
$eventNotice="Event successfully saved!";
header("Refresh:1");
}else{
$eventNotice = "Failed to save...";
}
return $eventNotice;
}
function getAllEvents (){
$stmt = $this->connection->prepare("SELECT id, eventType, eventDate, eventPrice, eventDescr FROM events_archive WHERE deleted is NULL");
$stmt->bind_result($id, $type, $date, $price, $descr);
$stmt->execute();
$result = array();
//seni kuni on üks rida andmeid saada(10 rida = 10 korda)
while($stmt->fetch()){
$event = new StdClass();
$event->eventId = $id;
$event->eventType = $type;
$event->eventDate = $date;
$event->eventPrice = $price;
$event->eventDescr = $descr;
array_push($result, $event);
}
$stmt->close();
return $result;
}
function delEvent($id){
$stmt = $this->connection->prepare("UPDATE events_archive SET deleted=NOW() WHERE id=? AND deleted IS NULL");
$stmt->bind_param("i", $id);
$stmt->execute();
$stmt->close();
}
function getSingleEventData($edit_id){
$stmt = $this->connection->prepare("SELECT eventType, eventDate, eventPrice, eventDescr FROM events_archive WHERE id=? AND deleted IS NULL");
$stmt->bind_param("i", $edit_id);
$stmt->bind_result($eventType, $eventDate, $eventPrice, $eventDescr);
$stmt->execute();
//tekitan objekti
$event = new stdclass();
//saime ühe rea andmeid
if($stmt->fetch()){
// saan siin alles kasutada bind_result muutujaid
$event->type = $eventType;
$event->date = $eventDate;
$event->price = $eventPrice;
$event->descr = $eventDescr;
}else{
// ei saanud rida andmeid kätte
// sellist id'd ei ole olemas
// see rida võib olla kustutatud
header("Location: data.php");
exit();
}
$stmt->close();
return $event;
}
function updateEvent($id, $type, $date, $price, $descr){
$stmt = $this->connection->prepare("UPDATE events_archive SET eventType=?, eventDate=?, eventPrice=?, eventDescr=? WHERE id=? AND deleted IS NULL");
$stmt->bind_param("ssdsi",$type, $date, $price, $descr, $id);
// kas õnnestus salvestada
if($stmt->execute()){
// õnnestus
echo "salvestus õnnestus!";
}
$stmt->close();
}
function getDeletedEvents (){
$stmt = $this->connection->prepare("SELECT id, eventType, eventDate, eventPrice, eventDescr, deleted FROM events_archive WHERE deleted IS NOT NULL");
$stmt->bind_result($id, $type, $date, $price, $descr, $deleted);
$stmt->execute();
$result = array();
//seni kuni on üks rida andmeid saada(10 rida = 10 korda)
while($stmt->fetch()){
$archevent = new StdClass();
$archevent->eventId = $id;
$archevent->eventType = $type;
$archevent->eventDate = $date;
$archevent->eventPrice = $price;
$archevent->eventDescr = $descr;
$archevent->eventDeleted = $deleted;
array_push($result, $archevent);
}
$stmt->close();
return $result;
}
function restoreEvent($id){
$stmt = $this->connection->prepare("UPDATE events_archive SET deleted=NULL WHERE id=? AND deleted IS NOT NULL");
$stmt->bind_param("i", $id);
$stmt->execute();
$stmt->close();
}
function delForeverEvent($id){
$stmt = $this->connection->prepare("DELETE FROM events_archive WHERE id=?");
$stmt->bind_param("d", $id);
$stmt->execute();
$stmt->close();
}
}