Created At: 2026-06-14T14:01:46Z
Completed At: 2026-06-14T14:01:46Z
File Path: `file:///c:/Users/HP/Downloads/climate-system/climate-system/index.php`
Total Lines: 4592
Total Bytes: 194080
Showing lines 350 to 395
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.
350:             $statistic = isset($_GET['statistic']) ? trim($_GET['statistic']) : 'Mean';
351:             $start_year = isset($_GET['start_year']) && $_GET['start_year'] !== '' ? intval($_GET['start_year']) : null;
352:             $end_year = isset($_GET['end_year']) && $_GET['end_year'] !== '' ? intval($_GET['end_year']) : null;
353: 
354:             if (empty($location) || empty($variable)) {
355:                 echo json_encode(['success' => false, 'error' => 'Parameter lokasi dan variabel tidak boleh kosong.']);
356:                 exit;
357:             }
358: 
359:             // Tentukan folder variabel (misal: memetakan Suhu Udara Minimum ke Temperature Anomaly)
360:             $variable_folder = $variable_sanitized;
361:             if ($variable_sanitized === 'Suhu Udara Minimum' || stripos($variable_sanitized, 'minimum') !== false) {
362:                 $variable_folder = 'Temperature Anomaly';
363:             }
364: 
365:             // Sanitasi input untuk mencegah Directory Traversal
366:             $location_sanitized = str_replace(array('..', '/', '\\'), '', $location);
367:             $variable_folder_sanitized = str_replace(array('..', '/', '\\'), '', $variable_folder);
368: 
369:             // Auto-generate sample CSV jika belum ada demi pengalaman tanpa hambatan
370:             ensure_sample_csv_exists_ipcc($location_sanitized, $variable_folder_sanitized);
371: 
372:             // Tentukan file utama berdasarkan filter Statistik
373:             $stat_map = [
374:                 'mean' => 'areal_averaged_ensmean.csv',
375:                 'median' => 'areal_averaged_ensmedian.csv',
376:                 'max' => 'areal_averaged_ensmax.csv',
377:                 'min' => 'areal_averaged_ensmin.csv',
378:                 'original' => 'areal_averaged.csv'
379:             ];
380:             $stat_lower = strtolower($statistic);
381:             $main_filename = isset($stat_map[$stat_lower]) ? $stat_map[$stat_lower] : 'areal_averaged_ensmean.csv';
382: 
383:             $dir = __DIR__ . "/data/{$location_sanitized}/{$variable_folder_sanitized}";
384: 
385:             // Copy file ensmean jika main file kustom belum ada untuk mencegah error
386:             if (!file_exists("{$dir}/{$main_filename}") && file_exists("{$dir}/areal_averaged_ensmean.csv")) {
387:                 copy("{$dir}/areal_averaged_ensmean.csv", "{$dir}/{$main_filename}");
388:             }
389: 
390:             // Parse keempat berkas CSV IPCC
391:             $historical_data = parse_ipcc_csv("{$dir}/historical_timeseries.csv", $start_year, $end_year);
392:             $mean_data = parse_ipcc_csv("{$dir}/{$main_filename}", $start_year, $end_year);
393:             $min_data = parse_ipcc_csv("{$dir}/areal_averaged_ensmin.csv", $start_year, $end_year);
394:             $max_data = parse_ipcc_csv("{$dir}/areal_averaged_ensmax.csv", $start_year, $end_year);
395: 
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.
