Created At: 2026-06-14T15:55:37Z
Completed At: 2026-06-14T15:55:37Z
File Path: `file:///c:/Users/HP/Downloads/climate-system/climate-system/index.php`
Total Lines: 3856
Total Bytes: 159351
Showing lines 435 to 500
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.
435:             exit;
436:         }
437: 
438:         // 2. Simpan Data Historical Climate (Settings)
439:         if ($action === 'save_historical') {
440:             if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
441:                 echo json_encode(['error' => 'Metode request tidak valid.']);
442:                 exit;
443:             }
444: 
445:             $raw_input = file_get_contents('php://input');
446:             $input = json_decode($raw_input, true);
447: 
448:             $location = isset($input['location']) ? trim($input['location']) : '';
449:             $variable = isset($input['variable']) ? trim($input['variable']) : '';
450:             $description = isset($input['description']) ? trim($input['description']) : '';
451:             $imageAnnual = isset($input['imageAnnual']) ? trim($input['imageAnnual']) : '';
452:             $imageTrend = isset($input['imageTrend']) ? trim($input['imageTrend']) : '';
453:             $imageTimeSeries = isset($input['imageTimeSeries']) ? trim($input['imageTimeSeries']) : '';
454:             $imageMonthlyMap = isset($input['imageMonthlyMap']) ? trim($input['imageMonthlyMap']) : '';
455:             $imageMonthlyGraph = isset($input['imageMonthlyGraph']) ? trim($input['imageMonthlyGraph']) : '';
456: 
457:             if (empty($location) || empty($variable)) {
458:                 echo json_encode(['error' => 'Lokasi dan Variable wajib diisi.']);
459:                 exit;
460:             }
461: 
462:             // Dapatkan atau buat Lokasi
463:             $stmt = $db->prepare("SELECT id FROM locations
<truncated 207 bytes>
O locations (name) VALUES (:name)");
468:                 $stmt_add->execute([':name' => $location]);
469:                 $location_id = $db->lastInsertId();
470:             } else {
471:                 $location_id = $loc['id'];
472:             }
473: 
474:             // Dapatkan atau buat Variabel
475:             $stmt = $db->prepare("SELECT id FROM variables WHERE name = :name");
476:             $stmt->execute([':name' => $variable]);
477:             $var = $stmt->fetch();
478:             if (!$var) {
479:                 $stmt_add = $db->prepare("INSERT INTO variables (name) VALUES (:name)");
480:                 $stmt_add->execute([':name' => $variable]);
481:                 $variable_id = $db->lastInsertId();
482:             } else {
483:                 $variable_id = $var['id'];
484:             }
485: 
486:             // Simpan (UPSERT)
487:             $stmt = $db->prepare("
488:                 INSERT INTO historical_climate (
489:                     location_id, variable_id, description, 
490:                     image_annual_url, image_trend_url, image_time_series_url, 
491:                     image_monthly_map_url, image_monthly_graph_url, updated_at
492:                 ) 
493:                 VALUES (:location_id, :variable_id, :description, :image_annual, :image_trend, :image_time_series, :image_monthly_map, :image_monthly_graph, CURRENT_TIMESTAMP)
494:                 ON CONFLICT (location_id, variable_id) 
495:                 DO UPDATE SET 
496:                     description = EXCLUDED.description,
497:                     image_annual_url = EXCLUDED.image_annual_url,
498:                     image_trend_url = EXCLUDED.image_trend_url,
499:                     image_time_series_url = EXCLUDED.image_time_series_url,
500:                     image_monthly_map_url = EXCLUDED.image_monthly_map_url,
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.
