52 lines
1.2 KiB
PHP
52 lines
1.2 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
class Api_ktp extends MY_Controller
|
|
{
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
private function reply($status, $data = null, $message = '', $http_code = 200)
|
|
{
|
|
header('Content-Type: application/json');
|
|
http_response_code($http_code);
|
|
echo json_encode([
|
|
'status' => $status,
|
|
'data' => $data,
|
|
'message' => $message
|
|
]);
|
|
}
|
|
|
|
public function get_last_persons()
|
|
{
|
|
// Validate user_id
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$user_id = $this->sys_user["M_UserID"];
|
|
if (!is_numeric($user_id)) {
|
|
$this->reply('ERR', null, 'Invalid user ID', 400);
|
|
return;
|
|
}
|
|
|
|
// Prepare SQL query with parameter binding
|
|
$sql = "SELECT * FROM person
|
|
WHERE Person_UserID = ?
|
|
AND Person_IsActive = 'Y'
|
|
ORDER BY Person_Created DESC
|
|
LIMIT 20";
|
|
|
|
// Execute query with parameter
|
|
$query = $this->db->query($sql, [$user_id]);
|
|
$persons = $query->result_array();
|
|
|
|
// Return JSON response
|
|
$this->reply('OK', $persons);
|
|
}
|
|
}
|