-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_markers.php
executable file
·147 lines (121 loc) · 3.42 KB
/
_markers.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
<?php
$action = $_REQUEST['action'];
if($action=='get'||$action=='getView'){
header('Content-Type: application/json');
switch ($action) {
case 'getView':
$markers = getMarkers('view');
break;
default:
$markers = getMarkers('');
break;
};
print(json_encode($markers));
};
if($action=='set'){
$data = $_POST['json'];
if($data){
$data = json_decode($data);
setMarkers($data);
}
};
if($action=='del'){
$mark = $_GET['mark'];
if($mark){
deleteMarker($mark);
}
};
if($action=='click'){
$mark = $_GET['mark'];
if($mark){
clickMarker($mark);
}
};
function setMarkers($data){
include('_db.php');
if(!$data)
return false;
$mark = newMarker($data->mark);
if($mark){
foreach ($data as $key => $value) {
if($key=='mark')
continue;
// echo $key . '<br>';
updateMarker($data->mark, $key, $value);
}
}
};
function updateMarker($mark, $key, $value){
if(!$mark||!$key||!$value)
return false;
include('_db.php');
$UP = "UPDATE markers SET ".$key." = '".$value."' WHERE mark = '".$mark."'";
$pdo->query($UP);
};
function newMarker($mark){
if(!$mark)
return false;
include('_db.php');
$marker = array();
try {
foreach($pdo->query("SELECT * from markers WHERE mark = '".$mark."' LIMIT 1") as $row) {
$marker['mark'] = $row['mark'];
}
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
if(!$marker){
/*novo marcador*/
$pdo->query("INSERT INTO markers (mark, x, y, ck) VALUES ('".$mark."', 1, 1, 1)");
}
return true;
};
function getMarkers($view){
include('_db.php');
$marker = array();
$getMark = isset($_GET['mark']) ? $_GET['mark'] : '';
$sql = "SELECT * from markers ORDER BY ID";
if($getMark)
$sql = "SELECT * from markers WHERE mark = '".$getMark."' LIMIT 1";
try {
$i=0;
foreach($pdo->query($sql) as $row) {
$marker[$i]['ID'] = $row['ID'];
$marker[$i]['mark'] = $row['mark'];
$marker[$i]['x'] = $row['x'];
$marker[$i]['y'] = $row['y'];
$marker[$i]['title'] = $row['title'];
// $marker[$i]['date'] = $row['date'];
$marker[$i]['data'] = date("d/m/Y", strtotime($row['date']));
if($view){
$marker[$i]['content'] = nl2br($row['content']);
}else{
$marker[$i]['content'] = $row['content'];
}
$marker[$i]['audio'] = $row['audio'];
$marker[$i]['ck'] = $row['ck'];
$marker[$i]['date'] = $row['date'];
$i++;
}
$pdo = null;
return $marker;
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
};
function deleteMarker($mark){
include('_db.php');
$queryDel = "DELETE FROM markers WHERE mark = '".$mark."' LIMIT 1";
$pdo->query($queryDel);
};
function clickMarker($mark){
include('_db.php');
$ck = $pdo->prepare("SELECT ck FROM markers WHERE mark = '".$mark."' LIMIT 1");
$ck->execute();
$ck = $ck->fetch();
$newCk = $ck['ck'] + 1;
updateMarker($mark, 'ck', $newCk);
};
?>