Update various plugins, remove unused assets, and refine core application features and database structure.

This commit is contained in:
Wartana
2026-03-04 21:34:55 +08:00
parent 68b2a33321
commit 5fa44b47e0
370 changed files with 89 additions and 15 deletions

74
admin/api/ocr_helper.php Normal file → Executable file
View File

@@ -1,6 +1,7 @@
<?php
header('Content-Type: application/json');
require_once 'config_api.php';
set_time_limit(300);
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
echo json_encode(['success' => false, 'message' => 'Invalid request method']);
@@ -25,25 +26,21 @@ if ($type === 'kk') {
$promptText = "Extract data from this Indonesian KTP. Return ONLY a raw JSON object with keys: 'nik' (16 digits), 'nama' (Name), 'tempat_lh' (Place of Birth), 'tgl_lh' (YYYY-MM-DD), 'je_kel' (LK/PR), 'alamat' (Street only), 'rt', 'rw', 'desa' (Kel/Desa), 'kecamatan', 'kabupaten' (or Kota), 'provinsi', 'agama', 'status' (Sudah/Belum/Cerai Hidup/Cerai Mati), 'pekerjaan', 'kewarganegaraan' (WNI/WNA). Clean up text. If field is unclear, return empty string.";
}
// Payload for Gemini
// Payload for Ollama App
$data = [
"contents" => [
"model" => "qwen2.5vl:7b",
"messages" => [
[
"parts" => [
["text" => $promptText],
[
"inline_data" => [
"mime_type" => $mimeType,
"data" => $imageData
]
]
]
"role" => "user",
"content" => $promptText,
"images" => [$imageData]
]
]
],
"stream" => false
];
// Send Request
$ch = curl_init(GEMINI_API_URL . '?key=' . GEMINI_API_KEY);
$ch = curl_init(OLLAMA_API_URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
@@ -67,13 +64,13 @@ if (isset($result['error'])) {
exit;
}
if (!isset($result['candidates'][0]['content']['parts'][0]['text'])) {
if (!isset($result['message']['content'])) {
echo json_encode(['success' => false, 'message' => 'No text returned from AI', 'raw' => $result]);
exit;
}
// Parse AI Response
$rawText = $result['candidates'][0]['content']['parts'][0]['text'];
$rawText = $result['message']['content'];
// Remove Markdown Code Blocks if any (```json ... ```)
$cleanJson = preg_replace('/^```json\s*|\s*```$/', '', trim($rawText));
@@ -91,5 +88,52 @@ if (!$parsedData) {
exit;
}
if ($type === 'ktp') {
// 1. Parse Status Perkawinan
if (!empty($parsedData['status'])) {
$st = strtoupper($parsedData['status']);
if (strpos($st, 'BELUM') !== false) {
$parsedData['status'] = 'Belum';
} elseif (strpos($st, 'CERAI MATI') !== false) {
$parsedData['status'] = 'Cerai Mati';
} elseif (strpos($st, 'CERAI HIDUP') !== false) {
$parsedData['status'] = 'Cerai Hidup';
} elseif (strpos($st, 'KAWIN') !== false) {
$parsedData['status'] = 'Sudah';
}
}
// 2. Parse Jenis Kelamin
if (!empty($parsedData['je_kel'])) {
$jk = strtoupper($parsedData['je_kel']);
if (strpos($jk, 'LAKI') !== false || $jk === 'L') {
$parsedData['je_kel'] = 'LK';
} elseif (strpos($jk, 'PEREMPUAN') !== false || $jk === 'P') {
$parsedData['je_kel'] = 'PR';
}
}
// 3. Parse Tempat & Tanggal Lahir (KTP format: "TEMPAT, DD-MM-YYYY")
if (!empty($parsedData['tempat_lh'])) {
$ttl = $parsedData['tempat_lh'];
if (strpos($ttl, ',') !== false) {
[$tempat, $tgl] = explode(',', $ttl, 2);
$parsedData['tempat_lh'] = trim($tempat);
if (empty($parsedData['tgl_lh'])) {
$parsedData['tgl_lh'] = trim($tgl);
}
}
}
// 4. Format Tanggal Lahir to YYYY-MM-DD for HTML input[type=date]
if (!empty($parsedData['tgl_lh'])) {
$tgl_lh = trim($parsedData['tgl_lh']);
// If it looks like DD-MM-YYYY or DD/MM/YYYY
if (preg_match('/^(\d{2})[\/\-](\d{2})[\/\-](\d{4})$/', $tgl_lh, $matches)) {
$parsedData['tgl_lh'] = $matches[3] . '-' . $matches[2] . '-' . $matches[1];
}
}
}
echo json_encode(['success' => true, 'data' => $parsedData]);
?>