/
export.php
75 lines (65 loc) · 2.51 KB
/
export.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
<?php
require_once("auth.php");
require_once("backend/NetworkNode.php");
require_once("backend/CableType.php");
require_once("design_func.php");
header('charset=utf-8');
function die_hdr($text) {
header('Content-Type: text/html; charset=utf-8');
die($text);
}
if (!isset($_GET['format'])) {
die_hdr('Не выбран формат экспорта!');
}
if (!isset($_GET[ 'data' ])) {
die_hdr('Не выбраны объекты!');
}
$res = ['count' => 0];
$fields = array();
if ($_GET[ 'data' ] == 'nodes') {
$fields = ['id' => 'id', 'name' => 'name', 'lon' => 'longitude', 'lat' => 'lattitude', 'fiberSpliceCount' => 'fiberSpliceCount', 'place' => 'place', 'NBTmarking' => 'marking', 'note' => 'note'];
$res = getNetworkNodeList_NetworkBoxName('name', '');
$i = -1;
while (++$i < $res['count']) {
if (preg_match('/\(([0-9\.]+)\,([0-9\.]+)\)/', $res['rows'][$i]['OpenGIS'], $matches)) {
$res['rows'][$i]['lon'] = $matches[1];
$res['rows'][$i]['lat'] = $matches[2];
} else {
$res['rows'][$i]['lon'] = '';
$res['rows'][$i]['lat'] = '';
}
$res['rows'][$i]['place'] = str_replace([';', '"'], [',', '\''], $res['rows'][$i]['place']);
$res['rows'][$i]['note'] = str_replace([';', '"'], [',', '\''], $res['rows'][$i]['note']);
}
}
elseif ($_GET[ 'data' ] == 'lines') {
$fields = ['id' => 'id', 'name' => 'name', 'coords' => 'coordinates', 'fibers' => 'fibers', 'marking' => 'marking', 'manufacturer' => 'manufacturer', 'length' => 'length', 'comment' => 'comment'];
$res = getCableLineList(1, '');
$i = -1;
while (++$i < $res['count']) {
$coords = '';
$clp = getCableLinePoint_NetworkNodeName($res['rows'][$i]['id']);
if ($clp['count']) {
foreach ($clp['rows'] as $point) {
if (preg_match('/\(([0-9\.]+)\,([0-9\.]+)\)/', $point['OpenGIS'], $matches)) {
$coords .= $matches[1] . ',' . $matches[2] . ',0 ';
} elseif (preg_match('/\(([0-9\.]+)\,([0-9\.]+)\)/', $point['NNOpenGIS'], $matches)) {
$coords .= $matches[1] . ',' . $matches[2] . ',0 ';
}
}
}
$res['rows'][$i]['coords'] = trim($coords);
$res['rows'][$i]['comment'] = str_replace([';', '"'], [',', '\''], $res['rows'][$i]['comment']);
}
}
if (!$res['count']) {
die_hdr('Не найдены объекты!');
} else {
if ($_GET[ 'format' ] == 'csv') {
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=export.csv');
print(gen_csv($res['rows'], $fields, ';'));
} else
die_hdr('Неверный формат экспорта!');
}
?>