forked from hypercities/hypercities
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdateKmlLink.php
More file actions
125 lines (110 loc) · 3.93 KB
/
updateKmlLink.php
File metadata and controls
125 lines (110 loc) · 3.93 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
<?php
include_once("includes/connect_db.inc");
include_once("includes/util.inc");
include_once("includes/kml.inc");
include_once("includes/dbUtil.inc");
include_once("includes/MysqlException.inc");
include_once("includes/serverSession.inc");
include_once("includes/kmlParser.inc");
// Test Case
/* CASE 1
$_POST['link'] = 'http://maps.google.com/maps/ms?ie=UTF8&hl=en&vps=1&jsv=213a&msa=0&output=nl&msid=108919828383338171460.000464b8749e82a283927';
$_POST['creator'] = 'Jay';
$_POST['title'] = 'KML Link';
$_POST['copyright'] = 'CCBY';
$_POST['type'] = 4;
$_POST['bound'] = '{"west": -122.92020400, "south": -34.60841800, "east": 4.35472700, "north": 55.95077900}';
$_POST['dateFrom'] = '1700-03-11T00:00:00-08:00';
$_POST['dateTo'] = '2010-03-11T00:00:00-08:00';
$_POST['zoom'] = 15;
$_POST['parents'] = '15630';
*/
cServerSession::start();
HC_checkReferer();
$HC_POST = HC_cleanInput($_POST, array('link'=>'urldec', 'title' => 'str',
'creator' => 'str', 'copyright' => 'str',
'markerType' => 'int', 'bound' => 'str',
'dateFrom' => 'dtime', 'dateTo' => 'dtime',
'zoom' => 'int', 'parents' => 'str',
'objectType' => 'int', 'objectId' => 'int',
'view' => 'str'),
array('link', 'title', 'bound', 'dateFrom',
'dateTo', 'parents', 'objectType'),
array('creator', 'copyright', 'zoom', 'view'));
$objectId = $HC_POST['objectId'];
$title = $HC_POST['title'];
$creator = $HC_POST['creator'];
$copyright = $HC_POST['copyright'];
$link = $HC_POST['link'];
$bound = json_decode($HC_POST['bound'], true);
$neLat = $bound['north'];
$neLon = $bound['east'];
$swLat = $bound['south'];
$swLon = $bound['west'];
$createTime = date( 'Y-m-d H:i:s');
$markerStyleId = HC_MARKER_EMPTY; // no marker for kml or 3d kml
$objType = $HC_POST['objectType']; // HC_OBJECT_TYPE_KML or HC_OBJECT_TYPE_3D_NETWORKLINK
$userId = cServerSession::getUserId();
$parents = explode(',', $HC_POST['parents']);
$dateFrom = $HC_POST['dateFrom'];
$dateTo = $HC_POST['dateTo'];
$zoom = $HC_POST['zoom'];
try {
//select the old parents
$result = getParents($objectId);
foreach ($result as $row) {
$oldParents[] = $row['object_id'];
}
$deletedCollections = array_diff($oldParents, $parents);
$addedCollections = array_diff($parents, $oldParents);
//update object table
$object = array('title' => $title,
'creator' => $creator,
'copyright' => $copyright);
$result = update("objects", $object, "`id` = $objectId");
//no need to insert geo_references
$object = array('kml' => $link,
'date_from' => $dateFrom,
'date_to' => $dateTo,
'updated_at' => $createTime,
'ne_lat' => $neLat,
'ne_lon' => $neLon,
'sw_lat' => $swLat,
'sw_lon' => $swLon,
'zoom' => $zoom);
// if there is a view, update it
if (!empty($HC_POST['view'])) {
$view = json_decode($HC_POST['view'], true);
$view = KmlParser::createViewFromArray($view);
$object['view'] = $view;
}
$result = update("object_mappings", $object, "`object_id` = $objectId");
// delete object relations
foreach ($deletedCollections as $deletedParentId) {
$result = delete("object_relations", "`object_id` = $deletedParentId"
." and `subject_id`=$objectId");
}
foreach($addedCollections as $addedParentId) {
$object = array('object_id' => $addedParentId,
'subject_id' => $objectId,
'scope_id' => $addedParentId,
'owner_id' => $userId,
'created_at' => 'NOW()',
'updated_at' => 'NOW()');
$result = insert("object_relations", $object);
$object = updateColTimeBoundBottomUp($addedParentId);
HC_debugLog("boundary and timespan = ".print_r($object, true));
}
HC_reportSuccess("Object updated successfully!");
}
catch (MysqlException $e) {
$message = 'Caught exception: '.$e->getMessage();
HC_errorLog($message);
HC_reportDBError("updating the KML link");
}
catch (Exception $e) {
$message = 'Caught exception: '.$e->getMessage();
HC_errorLog($message);
HC_reportGeneralError("updating the KML link");
}
?>