Files
dnssash/adm/code_manager/lib/ui_manager.extend.php
T
2026-06-11 18:47:38 +09:00

106 lines
4.4 KiB
PHP

<?php
if (!defined('_GNUBOARD_')) exit;
/**
* UI 리소스 관리자 클래스 인스턴스를 반환하는 헬퍼 함수
* @return UiManager
*/
function ui_manager() {
// 클래스가 아직 로드되지 않았다면 인스턴스 생성
if (!class_exists('UiManager')) {
// UiManager 클래스 정의
class UiManager
{
private static $instance = null;
private $resources = []; // 데이터를 캐시할 배열
private function __construct() {}
public static function getInstance()
{
if (self::$instance === null) {
self::$instance = new self();
}
return self::$instance;
}
public function get_label($resource_code, $lang = 'ko')
{
if (isset($this->resources['labels'][$lang][$resource_code])) {
return $this->resources['labels'][$lang][$resource_code];
}
global $g5;
$resource_code_escaped = sql_real_escape_string($resource_code);
$lang_escaped = sql_real_escape_string($lang);
$sql = "SELECT B.cl_name
FROM {$g5['ui_manager_table']} AS A
LEFT JOIN {$g5['common_lang_table']} AS B
ON (A.um_id = B.target_id AND B.target_table = '{$g5['ui_manager_table']}' AND B.lang_code = '{$lang_escaped}')
WHERE A.resource_code = '{$resource_code_escaped}' AND A.resource_type = 'LABEL'";
$row = sql_fetch($sql);
$label_text = $row['cl_name'] ?? $resource_code;
$this->resources['labels'][$lang][$resource_code] = $label_text;
return $label_text;
}
public function get_data($resource_code, $lang = 'ko')
{
if (isset($this->resources['data'][$lang][$resource_code])) {
return $this->resources['data'][$lang][$resource_code];
}
global $g5;
$resource_code_escaped = sql_real_escape_string($resource_code);
$lang_escaped = sql_real_escape_string($lang);
$sql_um = "SELECT um_id FROM {$g5['ui_manager_table']} WHERE resource_code = '{$resource_code_escaped}' AND resource_type = 'DATA'";
$um_row = sql_fetch($sql_um);
if (!isset($um_row['um_id'])) {
$this->resources['data'][$lang][$resource_code] = [];
return [];
}
$um_id = $um_row['um_id'];
$sql = "SELECT A.fc_id, A.parent_id, A.fc_key, A.fc_order, B.cl_name
FROM {$g5['form_category_table']} AS A
LEFT JOIN {$g5['common_lang_table']} AS B
ON (A.fc_id = B.target_id AND B.target_table = '{$g5['form_category_table']}' AND B.lang_code = '{$lang_escaped}')
WHERE A.um_id = '{$um_id}' AND A.is_used = 1 AND A.is_deleted = 0
ORDER BY A.fc_order, A.fc_id";
$result = sql_query($sql);
$options = [];
while ($row = sql_fetch_array($result)) {
$options[] = $row;
}
$this->resources['data'][$lang][$resource_code] = $options;
return $options;
}
public function render_select($resource_code, $select_name, $selected_value = '', $attributes = '', $lang = 'ko')
{
$options = $this->get_data($resource_code, $lang);
if (empty($options)) {
return "<select name=\"".htmlspecialchars($select_name)."\" {$attributes}><option value=\"\">옵션 없음</option></select>";
}
$html = "<select name=\"".htmlspecialchars($select_name)."\" {$attributes}>";
$html .= "<option value=\"\">선택</option>";
foreach ($options as $option) {
$selected = ($option['fc_key'] == $selected_value) ? ' selected' : '';
$html .= "<option value=\"" . htmlspecialchars($option['fc_key']) . "\"{$selected}>" . htmlspecialchars($option['cl_name']) . "</option>";
}
$html .= "</select>";
return $html;
}
}
}
return UiManager::getInstance();
}