Files
2026-09-16 23:20:08 +07:00

46 lines
1.4 KiB
PHP

<?php
namespace app\Controllers;
use app\Models\HrPersonModel;
class HrController extends Controller {
public function __construct() {
if (empty($_SESSION['user_id'])) {
header('HTTP/1.1 401 Unauthorized');
exit;
}
}
public function image() {
$nationalId = isset($_GET['national_id']) ? $_GET['national_id'] : '';
if (empty($nationalId)) {
$this->outputDefaultImage();
return;
}
$hrModel = new HrPersonModel();
$imageData = $hrModel->getPersonImage($nationalId);
if (!$imageData || empty($imageData['HR_IMAGE'])) {
$this->outputDefaultImage();
return;
}
// Output image
header("Content-Type: image/jpeg");
header("Cache-Control: max-age=86400, public"); // Cache for 1 day
echo $imageData['HR_IMAGE'];
exit;
}
private function outputDefaultImage() {
// Output a 1x1 transparent PNG or an SVG avatar as fallback
header('Content-Type: image/svg+xml');
echo '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path fill-rule="evenodd" d="M7.5 6a4.5 4.5 0 1 1 9 0 4.5 4.5 0 0 1-9 0ZM3.751 20.105a8.25 8.25 0 0 1 16.498 0 .75.75 0 0 1-.437.695A18.683 18.683 0 0 1 12 22.5c-2.786 0-5.433-.608-7.812-1.7a.75.75 0 0 1-.437-.695Z" clip-rule="evenodd" /></svg>';
exit;
}
}
?>