Created At: 2026-06-14T16:16:14Z
Completed At: 2026-06-14T16:16:14Z
File Path: `file:///c:/Users/HP/Downloads/climate-system/climate-system/index.php`
Total Lines: 3856
Total Bytes: 159351
Showing lines 201 to 300
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.
201: }
202: 
203: // Inisialisasi Tabel jika database baru dibuat atau masih kosong
204: if (!$db_exists || filesize($db_file) === 0) {
205:     try {
206:         $db->exec("
207:             CREATE TABLE IF NOT EXISTS locations (
208:                 id INTEGER PRIMARY KEY AUTOINCREMENT,
209:                 name TEXT UNIQUE NOT NULL,
210:                 created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
211:             );
212: 
213:             CREATE TABLE IF NOT EXISTS variables (
214:                 id INTEGER PRIMARY KEY AUTOINCREMENT,
215:                 name TEXT UNIQUE NOT NULL,
216:                 created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
217:             );
218: 
219:             CREATE TABLE IF NOT EXISTS periods (
220:                 id INTEGER PRIMARY KEY AUTOINCREMENT,
221:                 range TEXT UNIQUE NOT NULL,
222:                 created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
223:             );
224: 
225:             CREATE TABLE IF NOT EXISTS historical_climate (
226:                 id INTEGER PRIMARY KEY AUTOINCREMENT,
227:                 location_id INTEGER NOT NULL,
228:                 variable_id INTEGER NOT NULL,
229:                 description TEXT DEFAULT '',
230:                 image_annual_url TEXT DEFAULT '',
231:                 image_trend_url TEXT DEFAULT '',
232:                 image_time_series_url TEXT DEFAULT '',
233:                 image_monthly_map_url TEXT DEFAULT '',
234:                 image_monthly_graph_url TEXT DEFAULT '',
235:                 created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
236:      
<truncated 1285 bytes>
 KEY (period_id) REFERENCES periods(id) ON DELETE CASCADE,
258:                 UNIQUE (location_id, variable_id, period_id)
259:             );
260:         ");
261: 
262:         // Seed Data Master Lokasi
263:         $locations = ['Indonesia'];
264:         $stmt = $db->prepare("INSERT OR IGNORE INTO locations (name) VALUES (:name)");
265:         foreach ($locations as $loc) {
266:             $stmt->execute([':name' => $loc]);
267:         }
268: 
269:         // Seed Data Master Variabel
270:         $variables = [
271:             'Precipitation', 'Suhu Udara Rata-rata', 'Suhu Udara Maksimum', 'Suhu Udara Minimum',
272:             'Kelembaban Relatif', 'Kecepatan Angin', 'Radiasi Matahari', 'Suhu Permukaan Laut',
273:             'Anomali Tinggi Muka Laut', 'Salinitas Permukaan Laut', 'pH Permukaan Laut'
274:         ];
275:         $stmt = $db->prepare("INSERT OR IGNORE INTO variables (name) VALUES (:name)");
276:         foreach ($variables as $var) {
277:             $stmt->execute([':name' => $var]);
278:         }
279: 
280:         // Seed Data Master Periode
281:         $periods = ['2021-2050', '2031-2060', '2041-2070', '2051-2080', '2061-2090', '2071-2100'];
282:         $stmt = $db->prepare("INSERT OR IGNORE INTO periods (range) VALUES (:range)");
283:         foreach ($periods as $per) {
284:             $stmt->execute([':range' => $per]);
285:         }
286:     } catch (PDOException $e) {
287:         // Gagal menginisialisasi database
288:         header('Content-Type: application/json');
289:         echo json_encode(['error' => 'Gagal menginisialisasi skema database.']);
290:         exit;
291:     }
292: }
293: 
294: // Router API Endpoint
295: $action = isset($_GET['action']) ? $_GET['action'] : '';
296: 
297: if (!empty($action)) {
298:     header('Content-Type: application/json');
299: 
300:     try {
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.
