1
|
|
|
<?php |
2
|
|
|
require_once(dirname(__FILE__).'/settings.php'); |
3
|
|
|
require_once(dirname(__FILE__).'/class.Connection.php'); |
4
|
|
|
|
5
|
|
|
class Source { |
6
|
|
|
public $db; |
7
|
|
|
public function __construct($dbc = null) { |
8
|
|
|
$Connection = new Connection($dbc); |
9
|
|
|
$this->db = $Connection->db; |
10
|
|
|
} |
11
|
|
|
|
12
|
|
|
public function getAllLocationInfo() { |
13
|
|
|
$query = "SELECT * FROM source_location"; |
14
|
|
|
$query_values = array(); |
15
|
|
|
try { |
16
|
|
|
$sth = $this->db->prepare($query); |
17
|
|
|
$sth->execute($query_values); |
18
|
|
|
} catch(PDOException $e) { |
19
|
|
|
return "error : ".$e->getMessage(); |
20
|
|
|
} |
21
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
22
|
|
|
return $all; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function getLocationInfobyName($name) { |
26
|
|
|
$query = "SELECT * FROM source_location WHERE name = :name"; |
27
|
|
|
$query_values = array(':name' => $name); |
28
|
|
|
try { |
29
|
|
|
$sth = $this->db->prepare($query); |
30
|
|
|
$sth->execute($query_values); |
31
|
|
|
} catch(PDOException $e) { |
32
|
|
|
return "error : ".$e->getMessage(); |
33
|
|
|
} |
34
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
35
|
|
|
return $all; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function getLocationInfobyNameType($name,$type) { |
39
|
|
|
$query = "SELECT * FROM source_location WHERE name = :name AND type = :type"; |
40
|
|
|
$query_values = array(':name' => $name,':type' => $type); |
41
|
|
|
try { |
42
|
|
|
$sth = $this->db->prepare($query); |
43
|
|
|
$sth->execute($query_values); |
44
|
|
|
} catch(PDOException $e) { |
45
|
|
|
return "error : ".$e->getMessage(); |
46
|
|
|
} |
47
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
48
|
|
|
return $all; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function getLocationInfobySourceName($name) { |
52
|
|
|
$query = "SELECT * FROM source_location WHERE source = :name"; |
53
|
|
|
$query_values = array(':name' => $name); |
54
|
|
|
try { |
55
|
|
|
$sth = $this->db->prepare($query); |
56
|
|
|
$sth->execute($query_values); |
57
|
|
|
} catch(PDOException $e) { |
58
|
|
|
return "error : ".$e->getMessage(); |
59
|
|
|
} |
60
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
61
|
|
|
return $all; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function getLocationInfoByType($type) { |
65
|
|
|
$query = "SELECT * FROM source_location WHERE type = :type"; |
66
|
|
|
$query_values = array(':type' => $type); |
67
|
|
|
try { |
68
|
|
|
$sth = $this->db->prepare($query); |
69
|
|
|
$sth->execute($query_values); |
70
|
|
|
} catch(PDOException $e) { |
71
|
|
|
return "error : ".$e->getMessage(); |
72
|
|
|
} |
73
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
74
|
|
|
return $all; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function getLocationInfoByLocationID($location_id) { |
78
|
|
|
$query = "SELECT * FROM source_location WHERE location_id = :location_id"; |
79
|
|
|
$query_values = array(':location_id' => $location_id); |
80
|
|
|
try { |
81
|
|
|
$sth = $this->db->prepare($query); |
82
|
|
|
$sth->execute($query_values); |
83
|
|
|
} catch(PDOException $e) { |
84
|
|
|
return "error : ".$e->getMessage(); |
85
|
|
|
} |
86
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
87
|
|
|
return $all; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function getLocationInfoByID($id) { |
91
|
|
|
$query = "SELECT * FROM source_location WHERE id = :id"; |
92
|
|
|
$query_values = array(':id' => $id); |
93
|
|
|
try { |
94
|
|
|
$sth = $this->db->prepare($query); |
95
|
|
|
$sth->execute($query_values); |
96
|
|
|
} catch(PDOException $e) { |
97
|
|
|
return "error : ".$e->getMessage(); |
98
|
|
|
} |
99
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
100
|
|
|
return $all; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function addLocation($name,$latitude,$longitude,$altitude,$city,$country,$source,$logo = 'antenna.png',$type = '',$source_id = 0,$location_id = 0,$last_seen = '', $description = '') { |
104
|
|
|
if ($last_seen == '') $last_seen = date('Y-m-d H:i:s'); |
105
|
|
|
$query = "INSERT INTO source_location (name,latitude,longitude,altitude,country,city,logo,source,type,source_id,last_seen,location_id,description) VALUES (:name,:latitude,:longitude,:altitude,:country,:city,:logo,:source,:type,:source_id,:last_seen,:location_id,:description)"; |
106
|
|
|
$query_values = array(':name' => $name,':latitude' => $latitude, ':longitude' => $longitude,':altitude' => $altitude,':city' => $city,':country' => $country,':logo' => $logo,':source' => $source,':type' => $type,':source_id' => $source_id,':last_seen' => $last_seen,':location_id' => $location_id,':description' => $description); |
107
|
|
|
try { |
108
|
|
|
$sth = $this->db->prepare($query); |
109
|
|
|
$sth->execute($query_values); |
110
|
|
|
} catch(PDOException $e) { |
111
|
|
|
echo "error : ".$e->getMessage(); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function updateLocation($name,$latitude,$longitude,$altitude,$city,$country,$source,$logo = 'antenna.png',$type = '',$source_id = 0,$location_id = 0,$last_seen = '',$description = '') { |
116
|
|
|
if ($last_seen == '') $last_seen = date('Y-m-d H:i:s'); |
117
|
|
|
$query = "UPDATE source_location SET latitude = :latitude,longitude = :longitude,altitude = :altitude,country = :country,city = :city,logo = :logo,type = :type, source_id = :source_id, last_seen = :last_seen,location_id = :location_id, description = :description WHERE name = :name AND source = :source"; |
118
|
|
|
$query_values = array(':name' => $name,':latitude' => $latitude, ':longitude' => $longitude,':altitude' => $altitude,':city' => $city,':country' => $country,':logo' => $logo,':source' => $source,':type' => $type,':source_id' => $source_id,':last_seen' => $last_seen,':location_id' => $location_id,':description' => $description); |
119
|
|
|
try { |
120
|
|
|
$sth = $this->db->prepare($query); |
121
|
|
|
$sth->execute($query_values); |
122
|
|
|
} catch(PDOException $e) { |
123
|
|
|
return "error : ".$e->getMessage(); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
public function updateLocationDescByName($name,$source,$source_id = 0,$description = '') { |
128
|
|
|
$query = "UPDATE source_location SET description = :description WHERE source_id = :source_id AND name = :name AND source = :source"; |
129
|
|
|
$query_values = array(':name' => $name,':source' => $source,':source_id' => $source_id,':description' => $description); |
130
|
|
|
try { |
131
|
|
|
$sth = $this->db->prepare($query); |
132
|
|
|
$sth->execute($query_values); |
133
|
|
|
} catch(PDOException $e) { |
134
|
|
|
return "error : ".$e->getMessage(); |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
public function updateLocationByLocationID($name,$latitude,$longitude,$altitude,$city,$country,$source,$logo = 'antenna.png',$type = '',$source_id = 0, $location_id,$last_seen = '',$description = '') { |
|
|
|
|
139
|
|
|
if ($last_seen == '') $last_seen = date('Y-m-d H:i:s'); |
140
|
|
|
$query = "UPDATE source_location SET latitude = :latitude,longitude = :longitude,altitude = :altitude,country = :country,city = :city,logo = :logo,type = :type, last_seen = :last_seen, description = :description WHERE location_id = :location_id AND source = :source AND source_id = :source_id"; |
141
|
|
|
$query_values = array(':source_id' => $source_id,':latitude' => $latitude, ':longitude' => $longitude,':altitude' => $altitude,':city' => $city,':country' => $country,':logo' => $logo,':source' => $source,':type' => $type,':last_seen' => $last_seen,':location_id' => $location_id,':description' => $description); |
142
|
|
|
try { |
143
|
|
|
$sth = $this->db->prepare($query); |
144
|
|
|
$sth->execute($query_values); |
145
|
|
|
} catch(PDOException $e) { |
146
|
|
|
echo "error : ".$e->getMessage(); |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
public function deleteLocation($id) { |
151
|
|
|
$query = "DELETE FROM source_location WHERE id = :id"; |
152
|
|
|
$query_values = array(':id' => $id); |
153
|
|
|
try { |
154
|
|
|
$sth = $this->db->prepare($query); |
155
|
|
|
$sth->execute($query_values); |
156
|
|
|
} catch(PDOException $e) { |
157
|
|
|
return "error : ".$e->getMessage(); |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
public function deleteLocationByType($type) { |
162
|
|
|
$query = "DELETE FROM source_location WHERE type = :type"; |
163
|
|
|
$query_values = array(':type' => $type); |
164
|
|
|
try { |
165
|
|
|
$sth = $this->db->prepare($query); |
166
|
|
|
$sth->execute($query_values); |
167
|
|
|
} catch(PDOException $e) { |
168
|
|
|
return "error : ".$e->getMessage(); |
169
|
|
|
} |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
public function deleteAllLocation() { |
173
|
|
|
$query = "DELETE FROM source_location"; |
174
|
|
|
try { |
175
|
|
|
$sth = $this->db->prepare($query); |
176
|
|
|
$sth->execute(); |
177
|
|
|
} catch(PDOException $e) { |
178
|
|
|
return "error : ".$e->getMessage(); |
179
|
|
|
} |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
public function deleteOldLocationByType($type) { |
183
|
|
|
global $globalDBdriver; |
184
|
|
|
if ($type == 'wx') { |
185
|
|
|
if ($globalDBdriver == 'mysql') { |
186
|
|
|
$query = "DELETE FROM source_location WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 DAY) >= source_location.last_seen AND type = :type"; |
187
|
|
|
} else { |
188
|
|
|
$query = "DELETE FROM source_location WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '1 DAY' >= source_location.last_seen AND type = :type"; |
189
|
|
|
} |
190
|
|
|
} else { |
191
|
|
|
if ($globalDBdriver == 'mysql') { |
192
|
|
|
$query = "DELETE FROM source_location WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 WEEK) >= source_location.last_seen AND type = :type"; |
193
|
|
|
} else { |
194
|
|
|
$query = "DELETE FROM source_location WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '1 WEEK' >= source_location.last_seen AND type = :type"; |
195
|
|
|
} |
196
|
|
|
} |
197
|
|
|
try { |
198
|
|
|
$sth = $this->db->prepare($query); |
199
|
|
|
$sth->execute(array(':type' => $type)); |
200
|
|
|
} catch(PDOException $e) { |
201
|
|
|
return "error"; |
202
|
|
|
} |
203
|
|
|
return "success"; |
204
|
|
|
} |
205
|
|
|
} |
206
|
|
|
?> |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.