Repository navigation
Expand file tree
/
Copy pathb.php
More file actions
580 lines (473 loc) · 21.1 KB
/
Copy pathb.php
File metadata and controls
580 lines (473 loc) · 21.1 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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
<?php
include_once("./geoPHP/geoPHP.inc");
set_time_limit(0);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
#export GOOGLE_MAPS_API_KEY=AIzaSyDAtdEB1fEAkpkTFHO-o0SHc1Sa2i_9hQM
#curl "https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=${GOOGLE_MAPS_API_KEY}"
#curl "https://maps.googleapis.com/maps/api/geocode/json?address=אבטליון&key=AIzaSyDAtdEB1fEAkpkTFHO-o0SHc1Sa2i_9hQM"
#wget https://api.tzevaadom.co.il/alerts-history/id/446
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
/*
function CalculatePolygonArea($coordinates_in) {
$area_in = 0;
$coordinatesCount = sizeof($coordinates_in);
// echo "<hr>";
// echo "size : ".$coordinatesCount."<br>";
// var_export ($coordinates);
// echo "<hr>";
if ($coordinatesCount > 2) {
for ($i = 0; $i < $coordinatesCount - 1; $i++) {
$p1 = $coordinates_in[$i];
$p2 = $coordinates_in[$i + 1];
$p1Longitude = $p1[0];
$p2Longitude = $p2[0];
$p1Latitude = $p1[1];
$p2Latitude = $p2[1];
// echo ConvertToRadian($p2Longitude - $p1Longitude);
// echo "<br>";
// echo sin(ConvertToRadian($p1Latitude));
// echo "<br>";
// echo sin(ConvertToRadian($p2Latitude));
// echo "<br>";
// echo "P1lng : ".$p1Longitude."<br>";
// echo "P2lng : ".$p2Longitude."<br>";
// echo "P2lnt : ".$p1Latitude."<br>";
// echo "P2lat : ".$p2Latitude."<br>";
$area_in += ConvertToRadian($p2Longitude - $p1Longitude) * (2 + sin(ConvertToRadian($p1Latitude)) + sin(ConvertToRadian($p2Latitude)));
// echo "area : ".$area."<br><hr>";
}
$area_in = $area_in * 6378137 * 6378137 / 2;
}
return abs(round(($area_in)));
}
function ConvertToRadian($input) {
$output = $input * pi() / 180;
return $output;
}
*/
//$con = mysqli_connect("<DB SERVER IP>", "<DB USER>", "<DB PASSWORD>", "<DB NAME>");
mysqli_set_charset($con, "utf8mb4");
// Get information of last 24 hours
// open table for better tesult
$alerts_count = 0;
date_default_timezone_set('Asia/Jerusalem');
$__no_output = 0;
if (str_contains(strtoupper($_SERVER['QUERY_STRING']), "NO_OUTPUT")) {
$__no_output = 1;
}
if ($__no_output == 0 ) echo "<html dir=RTL><body>";
$ch = curl_init("https://api.tzevaadom.co.il/alerts-history");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$response = curl_exec($ch);
$data = json_decode($response,true);
if ($__no_output == 0 ) echo "<pre><table border=1>";
if ($__no_output == 0 ) echo "<tr><th>מסד</th><th>תאריך</th><th>שעה</th><th>עיר</th></tr>";
$end_id = 0;
// finds last alert on db
// in order to fetch later on alerts that are not on api history
// TASK - need to check if all alerts are in db an no skips - just rerive list of all ids
$sql_quary = "SELECT max(id) idm FROM alerts";
$result = mysqli_query($con,$sql_quary);
if($result->num_rows == 0) {
$start_id = 446;
} else {
$start_id = $result->fetch_row()[0];
}
$stmt = "INSERT INTO alerts (id, timestamp, city) VALUES (";
foreach ($data as $info) {
$id = $info['id'];
if ($end_id == 0) {
$end_id = $id;
}
foreach ($info['alerts'] as $alert) {
$time = $alert['time'];
$date_display = date("d/m/Y",$time);
$time_display = date("H:i:s",$time);
$timestamp = date("Y-m-d H:i:s",$time);
foreach ($alert['cities'] as $city) {
$bgcolor = "#52BE80";
$sql_quary = "SELECT id,timestamp,city FROM alerts where id=".$id." and timestamp='".$timestamp."' and city=\"".$con->real_escape_string($city)."\"";
$result = mysqli_query($con,$sql_quary);
if($result->num_rows == 0) {
$stmt = "INSERT INTO alerts (id, timestamp, city) VALUES (";
$val1 = $id;
$val2 = $timestamp;
$val3 = $con->real_escape_string($city);
$stmt .= $id." , \"".$val2."\" , \"".$val3."\")";
$result = mysqli_query($con,$stmt);
$bgcolor = "#EC7063";
// echo "<font color=blue>sql query :".$sql_quary."</font><br>";
// echo "sql insert :".$stmt."</font><br>";
}
$alerts_count++;
if ($__no_output == 0 ) echo "<tr><td bgcolor='".$bgcolor."'>".$id."</td><td bgcolor='".$bgcolor."'>".$date_display."</td><td bgcolor='".$bgcolor."'>".$time_display."</td><td align=right bgcolor='".$bgcolor."'>".$city."</td></tr>";
}
}
$middle_id = $id;
}
curl_close($ch);
unset($ch);
unset($response);
unset($data);
$total_area = 0;
// retrive old alerts information that are not from last 24 hours
//same logic as previous part
//$middle_id = 0;
for ($i = ($middle_id-1) ; $i >= $start_id ; $i--) {
$url = "https://api.tzevaadom.co.il/alerts-history/id/".$i;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$response = curl_exec($ch);
$data = json_decode($response,true);
$id = $data['id'];
foreach ($data['alerts'] as $alert) {
$time = $alert['time'];
$date_display = date("d/m/Y",$time);
$time_display = date("H:i:s",$time);
$timestamp = date("Y-m-d H:i:s",$time);
foreach ($alert['cities'] as $city) {
$bgcolor = "#52BE80";
$sql_quary = "SELECT id,timestamp,city FROM alerts where id=".$id." and timestamp='".$timestamp."' and city='".$con->real_escape_string($city)."'";
// echo $sql_quary."<br>";
$result = mysqli_query($con,$sql_quary);
if($result->num_rows == 0) {
$stmt = "INSERT INTO alerts (id, timestamp, city) VALUES (";
$val1 = $id;
$val2 = $timestamp;
$val3 = $con->real_escape_string($city);
$stmt .= $id." , \"".$val2."\" , \"".$val3."\")";
// echo $stmt."<br>";
$result = mysqli_query($con,$stmt);
$bgcolor = "#EC7063";
}
$alerts_count++;
if ($__no_output == 0 ) echo "<tr><td bgcolor='".$bgcolor."'>".$id."</td><td bgcolor='".$bgcolor."'>".$date_display."</td><td bgcolor='".$bgcolor."'>".$time_display."</td><td align=right bgcolor='".$bgcolor."'>".$city."</td></tr>";
}
}
curl_close($ch);
unset($ch);
unset($response);
unset($data);
}
if ($__no_output == 0 ) echo "</table></pre>";
if ($__no_output == 0 ) echo "Number or alerts : ".$alerts_count."<br>";
if ($__no_output == 0 ) echo "".$start_id." - ".$middle_id." - ".$end_id."<br>";
if ($__no_output == 0 ) echo "<br>";
// Needs to be developed - find max id, min id how many rows on result and check if numbers add up.
$sql_quary = "SELECT max(id), min(id) FROM alerts";
$result = mysqli_query($con,$sql_quary);
if($result->num_rows != 0) {
$tmp = $result->fetch_row();
$max_id = $tmp[0];
$min_id = $tmp[1];
$sql_quary = "SELECT distinct (id) FROM alerts order by id ";
$result = mysqli_query($con,$sql_quary);
echo $max_id." - ".$min_id." - ".$result->num_rows."<br>";
if (($max_id-$min_id+1) == $result->num_rows) {
// echo ("All alerts accounted for");
} else {
echo ("Some alerts are missing !!!\n<br>");
echo ("rows:".$result->num_rows."\n<br>");
echo ("max:".$max_id."\n<br>");
echo ("min:".$min_id."\n<br>");
echo ("delta:".($max_id-$min_id+1)."\n<br>");
echo ("\n<br>");
$sql_quary = "SELECT id,timestamp,city,alert_id FROM alerts where id BETWEEN ".$min_id." and ".$max_id;
echo $sql_quary."<br>";
$result = mysqli_query($con,$sql_quary);
if($result->num_rows == 0) {
}
}
} else {
// Error - need to check
}
//echo ("XXX");
$sql_quary = "SELECT max(`lastrun`) FROM execute_log;";
$result = mysqli_query($con,$sql_quary);
//echo ("YYY");
if($result->num_rows == 0) {
echo ("There is an error !");
} else {
$lastrun = $result->fetch_row()[0];
}
if ($__no_output == 0 ) echo "Last run : ".$lastrun."<br>";
//if ($__no_output == 0 ) echo "Last run : ".date("Y-m-d H:i:s",$lastrun)."<br>";
//echo ("XXX");
//$stmt = "INSERT INTO `execute_log` SET lastrun = \"".date("Y-m-d H:i:s")."\";";
$stmt = "INSERT INTO `execute_log` SET lastrun=now();";
//echo $stmt."<br>";
$result = mysqli_query($con,$stmt);
//echo ("XXX");
//echo ("yyy");
/*
$sql_quary = "SELECT `name`, `id`, `lat`, `lng` FROM `cities`;";
//$sql_quary = "SELECT `name`, `id`, `lat`, `lng` FROM `cities` where id in (4,9,802);";
$result = mysqli_query($con,$sql_quary);
$coord = array();
$coord_tmp = array();
foreach ($result as $row) {
$i = 0;
$area7 = 0;
// echo ("".$row["name"]." - ".$row["id"]." - ");
$sql_quary2 = "SELECT `lat`, `lng`, `poly_num` FROM `cities_poly`where `city_id` = ".$row["id"].";";
$result2 = mysqli_query($con,$sql_quary2);
$polygon_str2 = "";
$k = $result2->num_rows;
empty($coord);
$coord = array_fill(0, 0, NULL);
empty($coord_tmp);
foreach ($result2 as $row2) {
$polygon_str2 .= "[".$row2["lat"].",".$row2["lng"]."]";
$coord_tmp [0] = $row2["lng"];
$coord_tmp [1] = $row2["lat"];
$coord[$i] = $coord_tmp;
$i++;
if ($i < $k) $polygon_str2 .= ",";
}
if($result2->num_rows == 0) continue;
$area7 = CalculatePolygonArea($coord);
// echo ("Area: ".number_format($area7/1000/1000,3)." Km² - ");
empty($result2);
empty($polygon_str);
$tmp1 = "https://www.mapdevelopers.com/area_finder.php?polygons=";
$tmp2 = "[[[";
$tmp2 .= $polygon_str2;
$tmp2 .= '],"#AAAAAA","#000000",0.4]]';
// echo "<hr>".$polygon_str2."<br>";
echo "<a href='".$tmp1.urlencode($tmp2)."'>".$row["name"]."</a> - ".$row["id"]." - ";
echo "Area: ".number_format($area7/1000/1000,3)." Km² - ".$k."<br>";
$total_area = $total_area + $area7;
}
*/
/*
https://www.mapdevelopers.com/area_finder.php?polygons
=[[[
[31.589540349131198,34.494953427823766],
[31.540395786444186,34.577350888761266],[31.50059313227296,34.533405576261266],[31.37404878490274,34.368610654386266],[31.336521372473225,34.379596982511266],[31.294285137702303,34.376850400480016],[31.219151755395828,34.269733701261266],[31.3224447322828,34.214802060636266],[31.44671550266246,34.368610654386266],
[31.589540349131198,34.494953427823766]]
,"#AAAAAA","#000000",0.4]]
*/
/*
$coord = array();
$coord_tmp = array();
$i = 0;
$area7 = 0;
$sql_quary2 = "SELECT `lat`, `lng` FROM `israel`;";
$result2 = mysqli_query($con,$sql_quary2);
$k = $result2->num_rows;
$coord = array_fill(0, 0, NULL);
foreach ($result2 as $row2) {
$coord_tmp [0] = $row2["lng"];
$coord_tmp [1] = $row2["lat"];
$coord[$i] = $coord_tmp;
$i++;
if ($i < $k) $polygon_str2 .= ",";
}
$area7 = CalculatePolygonArea($coord);
$tmp1 = "https://www.mapdevelopers.com/area_finder.php?polygons=";
$tmp2 = "[[[";
$tmp2 .= $polygon_str2;
$tmp2 .= '],"#AAAAAA","#000000",0.4]]';
echo "<a href='".$tmp1.urlencode($tmp2)."'>ישראל</a> - ";
echo "Area: ".number_format($area7/1000/1000,3)." Km² - ".$k."<br>";
//$total_area = $total_area + $area7;
echo "<br>Total Areas' area: ".number_format($total_area/1000/1000,3)." Km² - ".number_format($total_area/$area7*100,2)."%<br>";
*/
/*
// get coordination for all unique cities
if ($__no_output == 0 ) echo "<pre><table border=1>";
if ($__no_output == 0 ) echo "<tr><th>id</th><th>city</th><th>name</th><th>lat</th><th>lng</th><th>place_id</th></tr>";
$sql_quary = "SELECT distinct city FROM alerts order by city";
$result = mysqli_query($con,$sql_quary);
while ($row = mysqli_fetch_row($result)) {
$city = $row[0];
// echo $city."<br>";
}
sort($cities_list);
$cities_not_fount_list = array();
$cities_to_query_list = array();
foreach ($cities_list as $city) {
$sql_quary = "SELECT city FROM cities where city=\"".$con->real_escape_string($city)."\"";
$result = mysqli_query($con,$sql_quary);
if($result->num_rows == 0) {
array_push($cities_to_query_list, $city);
}
}
$i = 0;
$j = 0;
foreach ($cities_to_query_list as $city) {
$url = "https://maps.googleapis.com/maps/api/geocode/json?address=".urlencode($city)."&key=AIzaSyDAtdEB1fEAkpkTFHO-o0SHc1Sa2i_9hQM";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$response = curl_exec($ch);
// echo ("X");
$data = json_decode($response,true);
$result = $data["results"];
$is_ok = $data["status"];
// remark 2 lines in case of google maps api is used
// and remove remarks block above.
// saving api usage.
//
$ch = curl_init("");
$is_ok = "";
//
if ($is_ok == "OK") {
$name = $result[0]['formatted_address'];
$location_lat = $data['results'][0]['geometry']['location']['lat'];
$location_lng = $data['results'][0]['geometry']['location']['lng'];
$place_id = $data['results'][0]['place_id'];
$i++;
$bgcolor = "#52BE80";
$sql_quary = "SELECT city,name,lat,lng,place_id FROM cities where city=\"".$con->real_escape_string($city)."\" and name=\"".$con->real_escape_string($name)."\" and place_id=\"".$place_id."\"";
$result = mysqli_query($con,$sql_quary);
if($result->num_rows == 0) {
$stmt = "INSERT INTO cities (city,name,lat,lng,place_id) VALUES (";
$val1 = $con->real_escape_string($city);
$val2 = $con->real_escape_string($name);
$val3 = $location_lat;
$val4 = $location_lng;
$val5 = $place_id;
$stmt .= "\"".$val1."\" , \"".$val2."\" , ".$val3." , ".$val4." , \"".$val5."\")";
try {
$result = mysqli_query($con,$stmt);
} catch (Exception $e) {
if ($__no_output == 0 ) echo "sql : ".$sql_quary."<br>";
if ($__no_output == 0 ) echo "inert : ".$stmt."<br>";
if ($__no_output == 0 ) echo 'Caught exception: ', $e->getMessage(), "\n";
}
$bgcolor = "#EC7063";
}
} else {
$new_city = "";
if ($city == "אזור תעשייה אלון התבור") $new_city = "תחנת הכוח אלון תבור MRC";
if ($city == "אזור תעשייה ברוש") $new_city = "אזור תעשייה ברוש מערב";
if ($city == "אזור תעשייה כנות") $new_city = "פארק תעשיות כנות";
if ($city == "אזור תעשייה צ.ח.ר") $new_city = "אזור תעשיה צח\"ר";
if ($city == "אזור תעשייה צמח") $new_city = "מפעלים אזוריים צמח";
if ($city == "אל פורעה") $new_city = "אלפורעה";
if ($city == "ברוש") $new_city = "ישוב ברוש";
if ($city == "גבעתי") $new_city = "ישוב גבעתי";
if ($city == "הראל") $new_city = "ישוב הראל";
if ($city == "חצב") $new_city = "ישוב חצב";
if ($city == "טפחות") $new_city = "ישוב טפחות";
if ($city == "יד מרדכי") $new_city = "ישוב יד מרדכי";
if ($city == "כלנית") $new_city = "ישוב כלנית";
if ($city == "לוטם וחמדון") $new_city = "ישוב לוטם";
if ($city == "לפיד") $new_city = "ישוב לפיד";
if ($city == "מגדל") $new_city = "ישוב מגדל";
if ($city == "מסד") $new_city = "ישוב מסד";
if ($city == "מסעדה") $new_city = "ישוב מסעדה";
if ($city == "נמרוד") $new_city = "ישוב נמרוד";
if ($city == "סולם") $new_city = "ישוב סולם";
if ($city == "עגור") $new_city = "ישוב עגור";
if ($city == "עינבר") $new_city = "ישוב עינבר";
if ($city == "עמינדב") $new_city = "ישוב עמינדב";
if ($city == "עשאהל") $new_city = "ישוב עשאהל";
if ($city == "קשת") $new_city = "ישוב קשת";
if ($city == "רווחה") $new_city = "ישוב רווחה";
if ($city == "רקפת") $new_city = "ישוב רקפת";
if ($city == "שאנטי במדבר") $new_city = "חאן השיירות";
if ($city == "שורש") $new_city = "ישוב שורש";
if ($city == "שחר") $new_city = "ישוב שחר";
if ($city == "שרשרת") $new_city = "ישוב שרשרת";
if ($city == "דניאל") $new_city = "כפר דניאל";
if ($city == "הילה") $new_city = "מצפה הילה";
if ($city == "כנות") $new_city = "כפר הנוער החקלאי כנות";
if ($city == "לטרון") $new_city = "מנזר לטרון";
if ($city == "מתחם צומת שוקת") $new_city = "דלק תל שוקת";
if ($city == "ניצן") $new_city = "ניצן ב'";
if ($city == "עבדת") $new_city = "עבדת/עתיקות";
if ($new_city == "") {
array_push($cities_not_fount_list, $city);
$name = "";
$location_lat = "";
$location_lng = "";
$place_id = "";
$j++;
$bgcolor = "#AAAAFF";
} else {
$url2 = "https://maps.googleapis.com/maps/api/geocode/json?address=".urlencode($new_city)."&key=AIzaSyDAtdEB1fEAkpkTFHO-o0SHc1Sa2i_9hQM";
$ch2 = curl_init($url2);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch2, CURLOPT_HEADER, 0);
$response = curl_exec($ch2);
$data = json_decode($response,true);
$result = $data["results"];
$is_ok = $data["status"];
if ($is_ok == "OK") {
$name = $result[0]['formatted_address'];
$location_lat = $data['results'][0]['geometry']['location']['lat'];
$location_lng = $data['results'][0]['geometry']['location']['lng'];
$place_id = $data['results'][0]['place_id'];
$i++;
$sql_quary = "SELECT city,name,lat,lng,place_id FROM cities where city=\"".$con->real_escape_string($city)."\" and name=\"".$con->real_escape_string($name)."\" and place_id=\"".$place_id."\"";
$result = mysqli_query($con,$sql_quary);
if($result->num_rows == 0) {
$stmt = "INSERT INTO cities (city,name,lat,lng,place_id) VALUES (";
$val1 = $con->real_escape_string($city);
$val2 = $con->real_escape_string($name);
$val3 = $location_lat;
$val4 = $location_lng;
$val5 = $place_id;
$stmt .= "\"".$val1."\" , \"".$val2."\" , ".$val3." , ".$val4." , \"".$val5."\")";
try {
$result = mysqli_query($con,$stmt);
} catch (Exception $e) {
if ($__no_output == 0 ) echo "sql : ".$sql_quary."<br>";
if ($__no_output == 0 ) echo "inert : ".$stmt."<br>";
if ($__no_output == 0 ) echo 'Caught exception: ', $e->getMessage(), "\n";
}
$bgcolor = "#777777";
}
$bgcolor = "#FFAAFF";
} else {
array_push($cities_not_fount_list, $city);
$name = "";
$location_lat = "";
$location_lng = "";
$place_id = "";
$j++;
$bgcolor = "#AAAAFF";
}
}
}
// echo "<font color=blue>sql query :".$sql_quary."</font><br>";
// echo "sql insert :".$stmt."</font><br>";
if ($__no_output == 0 ) echo "<tr><td bgcolor='".$bgcolor."'>".$i."</td><td bgcolor='".$bgcolor."'>".$city."</td><td bgcolor='".$bgcolor."'>".$name."</td><td bgcolor='".$bgcolor."'>".$location_lat."</td><td bgcolor='".$bgcolor."'>".$location_lng."</td><td bgcolor='".$bgcolor."'>".$place_id."</td></tr>";
curl_close($ch);
// if ($i == 1) break;
}
if ($__no_output == 0 ) echo "</table></pre>";
if ($__no_output == 0 ) echo "Number of cities : ".count($cities_list)."<br>";
if ($__no_output == 0 ) echo "Number of cities in alerts (SQL) : ".count($cities_to_query_list)."<br>";
if ($__no_output == 0 ) echo "Number of new cities inserted to SQL : ".$i."<br>";
if ($__no_output == 0 ) echo "Number of cities not found in google : ".$j." - ".count($cities_not_fount_list)."<br>";
*/
if ($__no_output == 0 ) echo "</body></html>";
function CalculatePolygonArea($coordinates_in) {
$area_in = 0;
$coordinatesCount = sizeof($coordinates_in);
if ($coordinatesCount > 2) {
for ($i = 0; $i < $coordinatesCount - 1; $i++) {
$p1 = $coordinates_in[$i];
$p2 = $coordinates_in[$i + 1];
$p1Longitude = $p1[0];
$p2Longitude = $p2[0];
$p1Latitude = $p1[1];
$p2Latitude = $p2[1];
$area_in += ConvertToRadian($p2Longitude - $p1Longitude) * (2 + sin(ConvertToRadian($p1Latitude)) + sin(ConvertToRadian($p2Latitude)));
}
$area_in = $area_in * 6378137 * 6378137 / 2;
}
return abs(round(($area_in)));
}
function ConvertToRadian($input) {
$output = $input * pi() / 180;
return $output;
}
?>