Created At: 2026-06-14T13:52:56Z
Completed At: 2026-06-14T13:52:56Z
File Path: `file:///c:/Users/HP/Downloads/climate-system/climate-system/index.php`
Total Lines: 4581
Total Bytes: 193572
Showing lines 340 to 410
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.
340:             echo json_encode(['success' => true, 'authenticated' => $is_logged_in]);
341:             exit;
342:         }
343: 
344:         // Action Baru: get_future_csv untuk membaca berkas CSV berdasarkan lokasi, variabel, & statistik
345:         if ($action === 'get_future_csv') {
346:             $location = isset($_GET['location']) ? trim($_GET['location']) : '';
347:             $variable = isset($_GET['variable']) ? trim($_GET['variable']) : '';
348:             $statistic = isset($_GET['statistic']) ? trim($_GET['statistic']) : 'Mean';
349:             $start_year = isset($_GET['start_year']) && $_GET['start_year'] !== '' ? intval($_GET['start_year']) : null;
350:             $end_year = isset($_GET['end_year']) && $_GET['end_year'] !== '' ? intval($_GET['end_year']) : null;
351: 
352:             if (empty($location) || empty($variable)) {
353:                 echo json_encode(['success' => false, 'error' => 'Parameter lokasi dan variabel tidak boleh kosong.']);
354:                 exit;
355:             }
356: 
357:             // Sanitasi input untuk mencegah Directory Traversal
358:             $location_sanitized = str_replace(array('..', '/', '\\'), '', $location);
359:             $variable_sanitized = str_replace(array('..', '/', '\\'), '', $variable);
360: 
361:             // Auto-generate sample CSV jika belum ada demi pengalaman tanpa hambatan
362:             ensure_sample_csv_exists_ipcc($location_sanitized, $variable_sanitized);
363: 
364:             // Tentukan file utama berdasarkan filter Statistik
365:             $stat_map = [

<truncated 642 bytes>
ble_sanitized, 'minimum') !== false) {
377:                 $variable_folder = 'Temperature Anomaly';
378:             }
379:             $dir = __DIR__ . "/data/{$location_sanitized}/{$variable_folder}";
380: 
381:             // Copy file ensmean jika main file kustom belum ada untuk mencegah error
382:             if (!file_exists("{$dir}/{$main_filename}") && file_exists("{$dir}/areal_averaged_ensmean.csv")) {
383:                 copy("{$dir}/areal_averaged_ensmean.csv", "{$dir}/{$main_filename}");
384:             }
385: 
386:             // Parse keempat berkas CSV IPCC
387:             $historical_data = parse_ipcc_csv("{$dir}/historical_timeseries.csv", $start_year, $end_year);
388:             $mean_data = parse_ipcc_csv("{$dir}/{$main_filename}", $start_year, $end_year);
389:             $min_data = parse_ipcc_csv("{$dir}/areal_averaged_ensmin.csv", $start_year, $end_year);
390:             $max_data = parse_ipcc_csv("{$dir}/areal_averaged_ensmax.csv", $start_year, $end_year);
391: 
392:             echo json_encode([
393:                 'success' => true,
394:                 'historical' => array_values($historical_data),
395:                 'mean' => array_values($mean_data),
396:                 'min' => array_values($min_data),
397:                 'max' => array_values($max_data),
398:                 'location' => $location,
399:                 'variable' => $variable,
400:                 'statistic' => $statistic
401:             ]);
402:             exit;
403:         }
404: 
405:         // 1. Ambil data Historical Climate
406:         if ($action === 'get_historical') {
407:             $location = isset($_GET['location']) ? trim($_GET['location']) : '';
408:             $variable = isset($_GET['variable']) ? trim($_GET['variable']) : '';
409: 
410:             if (empty($location) || empty($variable)) {
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.
