diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 0743c1c..8639562 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -213,15 +213,15 @@ $routes->group('certificates', function($routes) { $routes->get('/', 'Certificates::index'); // Untuk Index Tiap Menu + $routes->get('maintenance', 'Certificates::maintenanceIndex'); $routes->get('training', 'Certificates::trainingIndex'); $routes->get('calibration', 'Certificates::calibrateIndex'); - $routes->get('maintenance', 'Certificates::maintenanceIndex'); $routes->get('api/getindexmaintenance', 'Certificates::getDataIndexMaintenance'); $routes->get('api/getindextraining', 'Certificates::getDataIndexTraining'); - $routes->post('validate', 'Certificates::validateCertificate'); + $routes->post('api/validate', 'Certificates::validateCertificate'); // Untuk View Cerificate diff --git a/app/Controllers/Certificates.php b/app/Controllers/Certificates.php index adef85e..7a2c7e9 100644 --- a/app/Controllers/Certificates.php +++ b/app/Controllers/Certificates.php @@ -267,15 +267,56 @@ class Certificates extends BaseController { public function validateCertificate() { $certid = $this->request->getPost('certid'); - $certificateType = $this->request->getPost('certificateType'); - // if (!$certid) { + if (!$certid) { + return $this->response->setJSON([ + 'success' => false, + 'message' => 'Certificate ID is required' + ]); + } + + return $this->response->setJSON([ + 'success' => true, + 'message' => 'Certificate validated successfully' + // 'validationDate' => $validationDate + ]); + + // try { + // $db = \Config\Database::connect(); + // $builder = $db->table('certificates'); + + // $certificate = $builder->where('certid', $certid)->get()->getRowArray(); + + // if (!$certificate) { + // return $this->response->setJSON([ + // 'success' => false, + // 'message' => 'Certificate not found' + // ]); + // } + + // if ($certificate['isval'] !== null) { + // return $this->response->setJSON([ + // 'success' => false, + // 'message' => 'Certificate has already been validated' + // ]); + // } + + // $validationDate = date('Y-m-d'); + // $builder->where('certid', $certid)->update(['isval' => $validationDate]); + + // return $this->response->setJSON([ + // 'success' => true, + // 'message' => 'Certificate validated successfully', + // 'validationDate' => $validationDate + // ]); + + // } catch (\Exception $e) { + // log_message('error', 'Certificate validation error: ' . $e->getMessage()); // return $this->response->setJSON([ // 'success' => false, - // 'message' => 'Certificate ID is required' + // 'message' => 'An error occurred during validation' // ]); // } - } diff --git a/app/Views/certificate_maintenance_index.php b/app/Views/certificate_maintenance_index.php index ba6d027..f3ade89 100644 --- a/app/Views/certificate_maintenance_index.php +++ b/app/Views/certificate_maintenance_index.php @@ -316,8 +316,8 @@ $(function () { if (!confirm('Are you sure?')) return; $.post( - '', - { certid, certificateType}, + '', + { certid }, function (response) { if (response.success) { diff --git a/app/Views/layouts/_sidebar.php b/app/Views/layouts/_sidebar.php index 0d787af..c2ff26b 100644 --- a/app/Views/layouts/_sidebar.php +++ b/app/Views/layouts/_sidebar.php @@ -215,9 +215,11 @@