Repository navigation
Expand file tree
/
Copy pathdatatable.php
More file actions
69 lines (65 loc) · 2.56 KB
/
Copy pathdatatable.php
File metadata and controls
69 lines (65 loc) · 2.56 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
<?php include_once('api_functions.php'); ?>
<?php
$parms1 = array();
if (isset($_REQUEST['country'])) {
$parms1['countries'] = $_REQUEST['country'];
} else {
die("Need to specify the country via the 'country' URL parameter (or POST) as ISO3 code.");
}
$parms1['years'] = "1989";
for ($x = 1990; $x <= 2030; $x++) { $parms1['years'] .= ",".$x; }
//Global Settings
$parms1['use_lulucf'] = 1;
$parms1['use_nonco2'] = 1;
$parms1['emergency_path'] = 13;
$parms1['cum_since_yr'] = 1850;
$parms1['dev_thresh'] = 7500;
$parms1['interp_btwn_thresh'] = 1;
$parms1['lux_thresh'] = 50000;
$parms1['r_wt'] = 0.5;
if (isset($_COOKIE['db'])) {
$db = $_COOKIE['db'];
} else {
$db = get_new_API_DB();
// cookies must be sent before any output from your script
setcookie("db", $db, time()+604800);
}
$data_list = get_data($parms1, $db);
$keep_these_codes = array("year", "fossil_CO2_MtCO2", "LULUCF_MtCO2", "NonCO2_MtCO2e");
$round_these_codes = array("fossil_CO2_MtCO2", "LULUCF_MtCO2", "NonCO2_MtCO2e", "total");
foreach ($data_list as $entry) {
$temp = (array) $entry;
$data[$temp['year']] = $temp;
foreach ($data[$temp['year']] as $key => $value) {
if (!(in_array($key,$keep_these_codes))) {
unset($data[$temp['year']][$key]);
}
}
$data[$temp['year']]['total'] = floatval(preg_replace("/[^0-9\.\-]/","",$data[$temp['year']]['fossil_CO2_MtCO2'])) + floatval(preg_replace("/[^0-9\.\-]/","",$data[$temp['year']]['LULUCF_MtCO2'])) + floatval(preg_replace("/[^0-9\.\-]/","",$data[$temp['year']]['NonCO2_MtCO2e']));
foreach ($data[$temp['year']] as $key => $value) {
if (in_array($key,$round_these_codes)) {
$data[$temp['year']][$key] = number_format($data[$temp['year']][$key],3);
}
}
}
?>
<html>
<head>
</head>
<body>
<table class="table datatbl">
<thead>
<tr>
<th><?php echo implode('</th><th>', array_keys(current($data))); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($data as $row): array_map('htmlentities', $row); ?>
<tr>
<td><?php echo implode('</td><td>', $row); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</body>
</html>