Created At: 2026-06-14T13:53:13Z
Completed At: 2026-06-14T13:53:13Z
File Path: `file:///c:/Users/HP/Downloads/climate-system/climate-system/index.php`
Total Lines: 4581
Total Bytes: 193572
Showing lines 340 to 390
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 = [
366:                 'mean' => 'areal_averaged_ensmean.csv',
367:                 'median' => 'areal_averaged_ensmedian.csv',
368:                 'max' => 'areal_averaged_ensmax.csv',
369:                 'min' => 'areal_averaged_ensmin.csv',
370:                 'original' => 'areal_averaged.csv'
371:             ];
372:             $stat_lower = strtolower($statistic);
373:             $main_filename = isset($stat_map[$stat_lower]) ? $stat_map[$stat_lower] : 'areal_averaged_ensmean.csv';
374: 
375:             $variable_folder = $variable_sanitized;
376:             if ($variable_sanitized === 'Suhu Udara Minimum' || stripos($variable_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);
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.
