-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmap.php
155 lines (143 loc) · 4.15 KB
/
map.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
148
149
150
151
152
153
154
155
<?php
session_start();
if(empty($_SESSION['accesstoken'])) {
exit(header('location: /login.php'));
}
// check the access token is still ive
require_once('inc/settings.php');
require_once('scripts/checkAccessToken.php');
if(tokenExpired($_SESSION['accesstoken'],$api_root)) {
// make them re-auth, their token has expired.
exit(header('location: /login.php?expired'));
}
header("Content-Type: text/html; charset=utf-8");
?>
<!DOCTYPE html>
<html>
<head>
<?php require_once('inc/head.php');?>
<title>Mondo Online Banking</title>
<style>
html,
body,
#map {
display: block;
width: 100%;
height: 100%;
}
#map {
background: #58B;
}
</style>
</head>
<body>
<?php require_once('inc/navbar.php');?>
<div class="container"><div id="map" style="width:100%; min-height:100%; height: 600px;"></div></div>
<?php
// define the markers array
$markers = array();
// get transactions
// set the amount spent counter
$total = 0;
// set the transaction counter
$i = 0;
// loop through the transactions
foreach($transactions as $transaction) {
// coordinates must be present
// must be a physical location transaction
// must be negative amount
// check if the location is there, if it's not an online transaction (physical locations only), and
if(!empty($transaction['merchant']['address']['latitude']) && !$transaction['merchant']['online'] && strpos($transaction['amount'], '-') !== false) {
// add to the array
array_push($markers, $transaction);
// add to the total
$total = $total + $transaction['amount'];
$i++;
}
}
// calc the average amount
$average = $total / $i;
?>
<script src="https://maps.google.com/maps/api/js?sensor=true&.js"></script>
<script src="https://rawgit.com/HPNeo/gmaps/master/gmaps.js"></script>
<script>
var map = new GMaps({
div: '#map',
lat: 51.5237984,
lng: -0.0861244,
zoom: 13
});
<?php
foreach($markers as $transaction) {
// find out the logo
if(empty($transaction['merchant']['logo'])) {
switch($transaction['transaction']['category']) {
case 'bills':
$src = '/[email protected]';
break;
case 'cash':
$src = '/[email protected]';
break;
case 'eatingout':
$src = '/[email protected]';
break;
case 'entertainment':
$src = '/[email protected]';
break;
case 'expenses':
$src = '/[email protected]';
break;
case 'general':
$src = '/[email protected]';
break;
case 'groceries':
$src = '/[email protected]';
break;
case 'holidays':
$src = '/[email protected]';
break;
case 'shopping':
$src = '/[email protected]';
break;
case 'transport':
$src = '/[email protected]';
break;
case 'mondo':
$src = '/[email protected]';
break;
default:
$src = '/[email protected]';
}
}
else {
// show the real img
$src = $transaction['merchant']['logo'];
}
// calculate the logo size from the average size
$relsize = $transaction['amount'] / $average;
$size = round($relsize*50);
if($size>50) {
$size = 50;
}
if($size<10) {
$size = 10;
}
?>
var myIcon = new google.maps.MarkerImage("<?php echo $src;?>", null, null, null, new google.maps.Size(<?php echo $size.','.$size;?>));
map.addMarker({
lat: <?php echo $transaction['merchant']['address']['latitude'];?>,
lng: <?php echo $transaction['merchant']['address']['longitude'];?>,
title: '<?php echo addslashes($transaction['merchant']['name']);?>',
icon: myIcon,
click: function(e) {
//alert('You clicked in this marker');
},
infoWindow: {
content: '<p><?php echo addslashes($transaction['merchant']['name']);?></p><p><b><?php echo '£'.($transaction['amount'] / 100)*-1;?></b></p>'
}
});
<?php }?>
</script>
<?php require_once('inc/foot.php');?>
</body>
</html>