Created At: 2026-06-14T15:55:26Z
Completed At: 2026-06-14T15:55:26Z
File Path: `file:///c:/Users/HP/Downloads/climate-system/climate-system/index.php`
Total Lines: 3856
Total Bytes: 159351
Showing lines 1 to 50
The following code has been modified to include a line number before every line, in the format: <line_number>: <original_line>. Please note that any changes targeting the original code should remove the line number, colon, and leading space.
1: <?php
2: session_start();
3: // ======================================================
4: // =================== BACKEND PHP & DB ==================
5: // ======================================================
6: 
7: // Set headers & error reporting
8: error_reporting(E_ALL);
9: ini_set('display_errors', 0); // Sembunyikan detail error dari user demi keamanan
10: 
11: // Fungsi mem-parsing file CSV IPCC-style dengan column-mapping cerdas & fallback
12: function parse_ipcc_csv($file_path, $start_year = null, $end_year = null) {
13:     $data = [];
14:     if (!file_exists($file_path)) return $data;
15:     if (($handle = fopen($file_path, "r")) !== FALSE) {
16:         $header = fgetcsv($handle, 1000, ",");
17:         if ($header !== FALSE) {
18:             $header = array_map('trim', $header);
19:             
20:             $yearIdx = FALSE;
21:             $ssp126Idx = FALSE;
22:             $ssp245Idx = FALSE;
23:             $ssp370Idx = FALSE;
24:             $ssp585Idx = FALSE;
25: 
26:             foreach ($header as $idx => $colName) {
27:                 $colLower = strtolower($colName);
28:                 if ($colLower === 'year' || $colLower === 'tahun') $yearIdx = $idx;
29:                 else if ($colLower === 'ssp126' || $colLower === 'ssp1-2.6' || $colLower === 'ssp1') $ssp126Idx = $idx;
30:                 else if ($colLower === 'ssp245' || $colLower === 'ssp2-4.5' || $colLower === 'ssp2') $ssp245Idx = $idx;
31:                 else if ($colLower === 'ssp370' || $colLower === 'ssp3-7.0' || $colLower === 'ssp3') $ssp370Idx = $idx;
32:                 else if ($colLower === 'ssp585' || $colLower === 'ssp5-8.5' || $colLower === 'ssp5') $ssp585Idx = $idx;
33:             }
34:             
35:             if ($yearIdx !== FALSE) {
36:                 while (($row = fgetcsv($handle, 1000, ",")) !== FALSE) {
37:                     $year = intval(trim($row[$yearIdx]));
38:                     if ($start_year && $year < $start_year) continue;
39:                     if ($end_year && $year > $end_year) continue;
40:                     
41:                     // Gunakan data dari kolom ssp126 sebagai fallback jika kolom lain kosong
42:                     $data[$year] = [
43:                         'year' => $year,
44:                         'ssp126' => ($ssp126Idx !== FALSE && isset($row[$ssp126Idx]) && trim($row[$ssp126Idx]) !== '') ? floatval(trim($row[$ssp126Idx])) : null,
45:                         'ssp245' => ($ssp245Idx !== FALSE && isset($row[$ssp245Idx]) && trim($row[$ssp245Idx]) !== '') ? floatval(trim($row[$ssp245Idx])) : null,
46:                         'ssp370' => ($ssp370Idx !== FALSE && isset($row[$ssp370Idx]) && trim($row[$ssp370Idx]) !== '') ? floatval(trim($row[$ssp370Idx])) : null,
47:                         'ssp585' => ($ssp585Idx !== FALSE && isset($row[$ssp585Idx]) && trim($row[$ssp585Idx]) !== '') ? floatval(trim($row[$ssp585Idx])) : null,
48:                     ];
49:                 }
50:             }
The above content does NOT show the entire file contents. If you need to view any lines of the file which were not shown to complete your task, call this tool again to view those lines.
