|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class SLA |
|
4
|
|
|
{ |
|
5
|
|
|
private $db; |
|
6
|
|
|
|
|
7
|
|
|
public function __construct($database) |
|
8
|
|
|
{ |
|
9
|
|
|
$this->db = $database; |
|
10
|
|
|
} |
|
11
|
|
|
|
|
12
|
|
|
public function sla_exists($slaid) |
|
13
|
|
|
{ |
|
14
|
|
|
$query = $this->db->prepare('SELECT COUNT(`slaid`) FROM `sla` WHERE `slaid`= ?'); |
|
15
|
|
|
$query->bindValue(1, $slaid); |
|
16
|
|
|
|
|
17
|
|
|
try { |
|
18
|
|
|
$query->execute(); |
|
19
|
|
|
$rows = $query->fetchColumn(); |
|
20
|
|
|
if ($rows == 1) { |
|
21
|
|
|
return true; |
|
22
|
|
|
} else { |
|
23
|
|
|
return false; |
|
24
|
|
|
} |
|
25
|
|
|
} catch (PDOException $e) { |
|
26
|
|
|
die($e->getMessage()); |
|
|
|
|
|
|
27
|
|
|
} |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function add_sla($slaid, $namasla, $responsetime, $resolutiontime, $slawarning) |
|
31
|
|
|
{ |
|
32
|
|
|
$querystring = 'INSERT INTO `sla` (`slaid`,`namasla`,`responsetime`, `resolutiontime`, `slawarning`) VALUES (?, ?, ?, ?, ?)'; |
|
33
|
|
|
$query = $this->db->prepare($querystring); |
|
34
|
|
|
$query->bindValue(1, $slaid); |
|
35
|
|
|
$query->bindValue(2, $namasla); |
|
36
|
|
|
$query->bindValue(3, $responsetime); |
|
37
|
|
|
$query->bindValue(4, $resolutiontime); |
|
38
|
|
|
$query->bindValue(5, $slawarning); |
|
39
|
|
|
|
|
40
|
|
|
try { |
|
41
|
|
|
$query->execute(); |
|
42
|
|
|
} catch (PDOException $e) { |
|
43
|
|
|
die($e->getMessage()); |
|
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function update_sla($slaid, $namasla, $responsetime, $resolutiontime, $slawarning) |
|
48
|
|
|
{ |
|
49
|
|
|
$querystring = 'UPDATE `sla` SET `namasla` = ? , `responsetime` = ? , `resolutiontime` = ?, `slawarning` = ? WHERE `slaid` = ?'; |
|
50
|
|
|
$query = $this->db->prepare($querystring); |
|
51
|
|
|
$query->bindValue(1, $namasla); |
|
52
|
|
|
$query->bindValue(2, $responsetime); |
|
53
|
|
|
$query->bindValue(3, $resolutiontime); |
|
54
|
|
|
$query->bindValue(4, $slawarning); |
|
55
|
|
|
$query->bindValue(5, $slaid); |
|
56
|
|
|
|
|
57
|
|
|
try { |
|
58
|
|
|
$query->execute(); |
|
59
|
|
|
} catch (PDOException $e) { |
|
60
|
|
|
die($e->getMessage()); |
|
|
|
|
|
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function delete($id) |
|
65
|
|
|
{ |
|
66
|
|
|
$sql = 'DELETE FROM `sla` WHERE `slaid` = ?'; |
|
67
|
|
|
$query = $this->db->prepare($sql); |
|
68
|
|
|
$query->bindValue(1, $id); |
|
69
|
|
|
|
|
70
|
|
|
try { |
|
71
|
|
|
$query->execute(); |
|
72
|
|
|
} catch (PDOException $e) { |
|
73
|
|
|
die($e->getMessage()); |
|
|
|
|
|
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function sla_data($slaid) |
|
78
|
|
|
{ |
|
79
|
|
|
$query = $this->db->prepare('SELECT * FROM `sla` WHERE `slaid`= ?'); |
|
80
|
|
|
$query->bindValue(1, $slaid); |
|
81
|
|
|
|
|
82
|
|
|
try { |
|
83
|
|
|
$query->execute(); |
|
84
|
|
|
|
|
85
|
|
|
return $query->fetch(); |
|
86
|
|
|
} catch (PDOException $e) { |
|
87
|
|
|
die($e->getMessage()); |
|
|
|
|
|
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function get_sla() |
|
92
|
|
|
{ |
|
93
|
|
|
$query = $this->db->prepare('SELECT * FROM `sla` ORDER BY `slaid` ASC'); |
|
94
|
|
|
|
|
95
|
|
|
try { |
|
96
|
|
|
$query->execute(); |
|
97
|
|
|
} catch (PDOException $e) { |
|
98
|
|
|
die($e->getMessage()); |
|
|
|
|
|
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
return $query->fetchAll(); |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.