Created At: 2026-06-14T13:38:39Z
Completed At: 2026-06-14T13:38:39Z
File Path: `file:///c:/Users/HP/Downloads/climate-system/climate-system/index.php`
Total Lines: 4581
Total Bytes: 193572
Showing lines 1 to 800
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:           
<truncated 42019 bytes>
761:                 'locations' => $locs,
762:                 'variables' => $vars,
763:                 'periods' => $pers
764:             ]);
765:             exit;
766:         }
767: 
768:         // 6. Tambah Lokasi Baru
769:         if ($action === 'add_location') {
770:             if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
771:                 echo json_encode(['error' => 'Metode request tidak valid.']);
772:                 exit;
773:             }
774:             $raw_input = file_get_contents('php://input');
775:             $input = json_decode($raw_input, true);
776:             $name = isset($input['name']) ? trim($input['name']) : '';
777:             if (empty($name)) {
778:                 echo json_encode(['error' => 'Nama lokasi wajib diisi.']);
779:                 exit;
780:             }
781:             $stmt = $db->prepare("INSERT OR IGNORE INTO locations (name) VALUES (:name)");
782:             $stmt->execute([':name' => $name]);
783:             echo json_encode(['success' => true, 'message' => 'Lokasi baru berhasil ditambahkan!']);
784:             exit;
785:         }
786: 
787:         // 7. Tambah Variabel Baru
788:         if ($action === 'add_variable') {
789:             if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
790:                 echo json_encode(['error' => 'Metode request tidak valid.']);
791:                 exit;
792:             }
793:             $raw_input = file_get_contents('php://input');
794:             $input = json_decode($raw_input, true);
795:             $name = isset($input['name']) ? trim($input['name']) : '';
796:             if (empty($name)) {
797:                 echo json_encode(['error' => 'Nama variabel wajib diisi.']);
798:                 exit;
799:             }
800:             $stmt = $db->prepare("INSERT OR IGNORE INTO variables (name) VALUES (:name)");
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.
