-
Notifications
You must be signed in to change notification settings - Fork 5
/
make_revolt.php
97 lines (84 loc) · 2.67 KB
/
make_revolt.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
<?php
$mysqli = new mysqli( '127.0.0.1', 'root', '', 'revolt' );
if ($mysqli->connect_errno)
{
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
$result = $mysqli->query( "SELECT * FROM time" );
$date = array();
while ( $row = $result->fetch_assoc() )
{
if( !isset( $date[ $row[ 'DATE' ] ] ) )
{
$date[ $row[ 'DATE' ] ] = array();
$date[ $row[ 'DATE' ] ][ 'DATE' ] = $row[ 'DATE_TEXT' ];
$date[ $row[ 'DATE' ] ][ 'TEXT' ] = str_replace( array( ">", "<" ), array( ">", "<" ), htmlentities( $row[ 'TEXT' ], ENT_QUOTES ) );
if( $row[ 'IMAGE' ] != "" )
{
$date[ $row[ 'DATE' ] ][ 'IMAGE' ] = $row[ 'IMAGE' ];
}
}
else
{
if( !isset( $date[ $row[ 'DATE' ] ][ 'STEPS' ] ) )
{
$date[ $row[ 'DATE' ] ][ 'STEPS' ] = array();
}
array_push( $date[ $row[ 'DATE' ] ][ 'STEPS' ], str_replace( array( ">", "<" ), array( ">", "<" ), htmlentities( $row[ 'TEXT' ], ENT_QUOTES ) ) );
}
}
$result->free();
$result = $mysqli->query( "SELECT * FROM points" );
while ( $row = $result->fetch_assoc() )
{
if( $row[ 'STEP' ] != 0 )
{
foreach ( $row as $key => $value )
{
if( $value == "" )
{
unset( $row[ $key ] );
}
}
$d = $row[ 'DATE' ];
unset( $row[ 'DATE' ] );
$step = $row[ 'STEP' ] - 1;
unset( $row[ 'STEP' ] );
unset( $row[ 'UID' ] );
if ( isset( $row['Fixed'] ) ) unset( $row['Fixed'] );
if ( isset( $row['Places Notes'] ) ) unset( $row['Places Notes'] );
if ( isset( $row['Terrain Notes'] ) ) unset( $row['Terrain Notes'] );
if ( isset( $row['POSITION'] ) ) unset( $row['POSITION'] );
$row[ 'ID' ] = intval( $row[ 'ID' ] );
$row[ 'CERTAINTY' ] = intval( $row[ 'CERTAINTY' ] );
$row[ 'VALUE' ] = intval( $row[ 'VALUE' ] );
if ( isset( $row[ 'PATH' ] ) ){
$loc = json_decode( $row[ 'PATH' ] );
unset( $row[ 'LAT1' ] );
unset( $row[ 'LON1' ] );
unset( $row[ 'LAT2' ] );
unset( $row[ 'LON2' ] );
unset( $row[ 'PATH' ] );
} else {
$loc = array();
array_push( $loc, array( floatval( $row[ 'LAT1' ] ), floatval( $row[ 'LON1' ] ) ) );
unset( $row[ 'LAT1' ] );
unset( $row[ 'LON1' ] );
if( $row[ 'LAT2'] && $row[ 'LON2' ] )
{
array_push( $loc, array( floatval( $row[ 'LAT2' ] ), floatval( $row[ 'LON2' ] ) ) );
unset( $row[ 'LAT2' ] );
unset( $row[ 'LON2' ] );
}
}
$row[ "LOC" ] = $loc;
if ( $row[ 'TEXT' ] != "" )
$row[ 'INFO' ] = str_replace( array( ">", "<" ), array( ">", "<" ), htmlentities( $row[ 'TEXT' ] ) );
$row[ 'TEXT' ] = $date[ $d ][ 'STEPS' ][ $step ];
$date[ $d ][ 'STEPS' ][ $step ] = $row;
}
}
//print_r( $date );
echo json_encode( $date );
?>