-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.php
111 lines (107 loc) · 4.76 KB
/
action.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
<?php
/*
* action.php
*
* Copyright 2020 Kaki In <kaki@mifamofi.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/
include './shelve.php';
include "./conf.php";
$shelveitem = new Openshelve($conf["database-name"], $conf["database-password"], $conf["database-server"], $conf["database-user"]);
function randomColor() {
$a='#';
for ($i=0;$i<6;$i++) {
$a.=['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'][rand(0, 15)];
};
return $a;
};
$result="";
try {
if (isset($_REQUEST['action'])) {
if ($_REQUEST['action']=='refresh') {
$result.="setPointsIds([";
$a = sendrequest("SELECT * FROM Points", $conf["database-server"], $conf["database-user"], $conf["database-password"], $conf["database-name"]);
$n=0;
foreach ($a as $point) {
if ($n) {$result.=", ";}
$result.=$point['id'];
$n++;
};
$result.="]);";
foreach ($a as $point) {
$nomType = $shelveitem('Types', 'nom', 'id', $point['type']);
$colType = $shelveitem('Types', 'couleur', 'id', $point['type']);
$result.="addPoint({$point['longitude']}, {$point['latitude']}, ".var_export($point['name'], true).", '{$point['id']}', ".var_export($nomType, true).", ".var_export($colType, true).");";
};
$result.="document.getElementById('mapCenter').setAttribute('lon', ".$shelveitem('Centre', 'lon', 'id', 0).");";
$result.="document.getElementById('mapCenter').setAttribute('lat', ".$shelveitem('Centre', 'lat', 'id', 0).");";}
elseif ($_REQUEST['action']=='refreshTypes') {
$a = sendrequest("SELECT * FROM Types", $conf["database-server"], $conf["database-user"], $conf["database-password"], $conf["database-name"]);
$result.="setTypes([";
$n=0;
foreach ($a as $num=>$type) {
if ($n>0) {$result.=", ";}
$n++;
$result.="[{$type['id']}, ".var_export($type['nom'], true)."]";
};
$result.="]);";
}
elseif ($_REQUEST['action']=="changePointName" and isset($_REQUEST['pointId']) and isset($_REQUEST['newName'])) {
$shelveitem->setItem('Points', 'Name', $_REQUEST['newName'], "id", $_REQUEST['pointId']);
$result.="refresh(true);mapview.popup.close();";
}
elseif ($_REQUEST['action']=="changeCenterPoint" and isset($_REQUEST['lat']) and isset($_REQUEST['lon'])) {
$shelveitem->setItem('Centre', 'lon', $_REQUEST['lon'], 'id', 0);
$shelveitem->setItem('Centre', 'lat', $_REQUEST['lat'], 'id', 0);
$result.="refresh(true);";
}
elseif ($_REQUEST['action']=="refreshFirst") {
$result.="mapview.goTo({center: [".$shelveitem('Centre', 'lon', 'id', 0).",".$shelveitem('Centre', 'lat', 'id', 0)."],
zoom: 18}, {duration: 1000});refresh();";
}
elseif ($_REQUEST['action']=="addPoint" and isset($_REQUEST['lat']) and isset($_REQUEST['lon']) and isset($_REQUEST['name']) and isset($_REQUEST['type'])) {
$shelveitem->addItem('Points', ['longitude'=>$_REQUEST['lon'], 'latitude'=>$_REQUEST['lat'], 'name'=>$_REQUEST['name'], 'type'=>$_REQUEST['type']]);
$result.="refresh(true);";
}
elseif ($_REQUEST['action']=="deletePoint" and isset($_REQUEST['pointId'])) {
$shelveitem->delItem('Points', "id", $_REQUEST['pointId']);
$result.="refresh(true);";
}
elseif ($_REQUEST['action']=="addType" and isset($_REQUEST['name'])) {
if ($shelveitem('Types', 'nom', 'nom', $_REQUEST['name'])==$_REQUEST['name']) {
$result.="alert('Un script du même nom existe déjà');document.getElementById('askTypeName').status='failed';";
}
else {
$col = randomColor();
while ($shelveitem('Types', 'couleur', 'couleur', $col)==$col) {
$col=randomColor();
};
$shelveitem->addItem('Types', ['nom'=>$_REQUEST['name'], 'couleur'=>$col]);
$result.="refreshTypes();";
};
}
elseif ($_REQUEST['action']=="changePointType" and isset($_REQUEST['pointId']) and isset($_REQUEST['newType'])) {
$shelveitem->setItem('Points', 'type', $_REQUEST['newType'], 'id', $_REQUEST['pointId']);
$result.='refresh(true)';
};
};
echo $result;
}
catch (Exception $e) {echo "alert(".var_export("Impossible de se connecter au serveur. Veuillez vérifier la configuration (".$e->getMessage().")", true).");";die;}
?>