Created At: 2026-06-14T16:16:04Z
Completed At: 2026-06-14T16:16:05Z
File Path: `file:///c:/Users/HP/Downloads/climate-system/climate-system/index.php`
Total Lines: 3856
Total Bytes: 159351
Showing lines 400 to 470
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.
400: 
401:         // 1. Ambil data Historical Climate
402:         if ($action === 'get_historical') {
403:             $location = isset($_GET['location']) ? trim($_GET['location']) : '';
404:             $variable = isset($_GET['variable']) ? trim($_GET['variable']) : '';
405: 
406:             if (empty($location) || empty($variable)) {
407:                 echo json_encode(['error' => 'Parameter tidak lengkap.']);
408:                 exit;
409:             }
410: 
411:             $stmt = $db->prepare("
412:                 SELECT h.* FROM historical_climate h
413:                 JOIN locations l ON h.location_id = l.id
414:                 JOIN variables v ON h.variable_id = v.id
415:                 WHERE l.name = :location AND v.name = :variable
416:             ");
417:             $stmt->execute([':location' => $location, ':variable' => $variable]);
418:             $data = $stmt->fetch();
419: 
420:             if ($data) {
421:                 echo json_encode([
422:                     'success' => true,
423:                     'data' => [
424:                         'description' => $data['description'],
425:                         'imageAnnual' => $data['image_annual_url'],
426:                         'imageTrend' => $data['image_trend_url'],
427:                         'imageTimeSeries' => $data['image_time_series_url'],
428:                         'imageMonthlyMap' => $data['image_monthly_map_url'],
429:                         'imageMonthlyGraph' => $data['image_monthly_graph_url']
430:                     ]
431:                 ]);
432:   
<truncated 259 bytes>
$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 WHERE name = :name");
464:             $stmt->execute([':name' => $location]);
465:             $loc = $stmt->fetch();
466:             if (!$loc) {
467:                 $stmt_add = $db->prepare("INSERT INTO locations (name) VALUES (:name)");
468:                 $stmt_add->execute([':name' => $location]);
469:                 $location_id = $db->lastInsertId();
470:             } else {
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.
