idx = $idx;
$this->cs_name = $name;
$this->title = $title;
$this->html = "";
$this->is_value_added = false;
if ($init) {
$this->init();
}
if (!empty($data)) {
foreach ($data as $val) {
switch ($val["type"]) {
case "desc":
$this->addDescription($val["desc"], array_key_exists("default", $val) ? (is_array($val["default"]) ? $val["default"] : []) : []);
break;
case "text":
$this->addTextSetting($val["desc"], array_key_exists("default", $val) ? (is_array($val["default"]) ? $val["default"] : []) : [], array_key_exists("placeholder", $val) ? $val["placeholder"] : "");
break;
case "textarea":
$this->addTextareaSetting($val["desc"], array_key_exists("default", $val) ? (is_array($val["default"]) ? $val["default"] : []) : [], array_key_exists("placeholder", $val) ? $val["placeholder"] : "");
break;
case "image":
$this->addImageSetting($val["desc"], array_key_exists("default", $val) ? (is_array($val["default"]) ? $val["default"] : []) : []);
break;
case "select":
$this->addSelectSetting($val["desc"], array_key_exists("default", $val) ? (is_array($val["default"]) ? $val["default"] : []) : [], array_key_exists("values", $val) ? $val["values"] : "");
break;
case "color":
$this->addColorSetting($val["desc"], array_key_exists("default", $val) ? (is_array($val["default"]) ? $val["default"] : []) : []);
break;
case "color2":
$this->addColor2Setting($val["desc"], array_key_exists("default", $val) ? (is_array($val["default"]) ? $val["default"] : []) : []);
break;
case "border":
$this->addBorderSetting($val["desc"], array_key_exists("default", $val) ? (is_array($val["default"]) ? $val["default"] : []) : []);
break;
case "rect":
$this->addRectSetting($val["desc"], array_key_exists("default", $val) ? (is_array($val["default"]) ? $val["default"] : []) : []);
break;
case "radius":
$this->addRadiusSetting($val["desc"], array_key_exists("default", $val) ? (is_array($val["default"]) ? $val["default"] : []) : []);
break;
}
}
}
}
public static function getSettingList()
{
global $g5;
$css = [];
$sql = sql_query("SELECT * FROM {$g5['css_table']}");
while ($row = sql_fetch_array($sql)) {
$set = new Setting(0, "", "", [], false);
$set->cs_id = $row['cs_id'];
$set->cs_value = $row['cs_value'];
$set->cs_name = $row['cs_name'];
$set->cs_descript = $row['cs_descript'];
for ($i = 1; $i <= 20; $i++) {
$key = "cs_etc_{$i}";
$set->$key = $row[$key];
}
$css[$row['cs_name']] = $set;
}
return $css;
}
public function init()
{
global $g5;
$this->settings = [];
$data = sql_fetch("SELECT * FROM {$g5['css_table']} WHERE cs_name = '{$this->cs_name}'");
if ($data) {
$this->cs_id = intval($data['cs_id']);
$this->cs_name = $data['cs_name'];
$this->cs_value = $data['cs_value'];
$this->cs_descript = $data['cs_descript'];
for ($i = 1; $i <= 20; $i++) {
$key = "cs_etc_{$i}";
$this->$key = $data[$key];
}
} else {
$this->cs_value = "";
$this->cs_descript = "";
for ($i = 1; $i <= 20; $i++) {
$key = "cs_etc_{$i}";
$this->$key = "";
}
}
}
public function addHeader()
{
$count = count(array_filter($this->settings, function ($setting) {
return $setting["type"] != "image";
}));
$count += count(array_filter($this->settings, function ($setting) {
return $setting["type"] == "image";
})) ? 2 : 0;
return "
| {$this->idx}{$this->title}idx}]\" value=\"{$this->cs_name}\" readonly size=\"15\" /> | ";
}
public function getCurrentCount()
{
$count = 0;
foreach ($this->settings as $setting) {
switch ($setting["type"]) {
case "image":
case "text":
case "desc":
break;
case "color":
case "border":
$count += 2;
break;
default:
$count++;
break;
}
}
return $count;
}
public function addDescription($text, $default)
{
$this->settings[] = [
"type" => "desc",
"html" => "{$text} |
"
];
}
public function addTextSetting($desc, $default, $placeholder)
{
if ($this->is_value_added)
return;
$this->settings[] = [
"type" => "text",
"html" => "{$desc} | idx}]\" value=\"{$this->cs_value}\" size=\"100\" placeholder=\"{$placeholder}\" /> | "
];
$this->is_value_added = true;
}
public function addTextareaSetting($desc, $default, $placeholder)
{
if ($this->is_value_added)
return;
$this->settings[] = [
"type" => "text",
"html" => "{$desc} | | "
];
$this->is_value_added = true;
}
public function addImageSetting($desc, $default)
{
if ($this->is_value_added)
return;
$image_set = $this->cs_value != "" ? "
cs_value}\" class=\"prev_thumb\">" : "{$desc} 이미지 미등록";
$this->settings[] = [
"type" => "image",
"html" => "{$image_set} | 직접등록idx}]\" value=\"\" size=\"50\"> | 외부경로idx}]\" value=\"{$this->cs_value}\" size=\"50\"/> |
"
];
$this->is_value_added = true;
}
public function addRectSetting($desc, $default)
{
$idx = $this->getCurrentCount() + 1;
if ($idx <= 20) {
$key1 = "cs_etc_{$idx}";
$values = explode("||", $this->$key1);
if (empty($default)) {
$default = [0, 0, 0, 0];
}
if (count($values) < 6) {
$values = array_merge([""], $default, [""]);
}
foreach ($values as &$val) {
$val = intval($val);
}
$this->settings[] = [
"type" => "rect",
"html" => "{$desc} |
|
"
];
}
// error
}
public function addRadiusSetting($desc, $default)
{
$idx = $this->getCurrentCount() + 1;
if ($idx <= 20) {
$key1 = "cs_etc_{$idx}";
$values = explode("||", $this->$key1);
if (empty($default)) {
$default = [0, 0, 0, 0];
}
if (count($values) < 6) {
$values = array_merge([""], $default, [""]);
}
foreach ($values as &$val) {
$val = intval($val);
}
$this->settings[] = [
"type" => "radius",
"html" => "{$desc} |
|
"
];
}
// error
}
public function addColorSetting($desc, $default)
{
$idx = $this->getCurrentCount() + 1;
if ($idx <= 19) {
$idx2 = $idx + 1;
$key1 = "cs_etc_{$idx}";
$key2 = "cs_etc_{$idx2}";
if (empty($default)) {
if ($this->$key1 === "")
$this->$key1 = "#000000";
if ($this->$key2 === "")
$this->$key2 = "0";
}
$this->settings[] = [
"type" => "color",
"html" => "{$desc} | 색상idx}]\" value=\"{$this->$key1}\" class=\"colorpicker\" size=\"30\" maxlength=\"255\" placeholder=\"#색상코드\" />투명도idx}]\" value=\"{$this->$key2}\" placeholder=\"0\" title=\"투명도\" style=\"width:45px;\"/>% | "
];
}
// error
}
public function addColor2Setting($desc, $default)
{
$idx = $this->getCurrentCount() + 1;
if ($idx <= 20) {
$key1 = "cs_etc_{$idx}";
if (empty($default)) {
if ($this->$key1 === "")
$this->$key1 = "#000000FF";
} else {
if ($this->$key1 === "")
$this->$key1 = $default[0];
}
$this->settings[] = [
"type" => "color2",
"html" => "{$desc} | 색상idx}]\" value=\"{$this->$key1}\" class=\"neo_color\" size=\"30\" maxlength=\"255\" placeholder=\"#색상코드\" /> | "
];
}
// error
}
public function addBorderSetting($desc, $default)
{
$idx = $this->getCurrentCount() + 1;
$options = [
" " => "사용 안 함",
"dotted" => "점선",
"dashed" => "대시",
"solid" => "직선",
"double" => "이중선",
"groove" => "내부 경사",
"ridge" => "외부 경사",
"inset" => "내부",
"outset" => "외부"
];
if ($idx <= 19) {
$idx2 = $idx + 1;
$key1 = "cs_etc_{$idx}";
$key2 = "cs_etc_{$idx2}";
$options_html = "";
foreach ($options as $key => $val) {
$k = trim($key);
$s = $this->$key1 == $k ? " selected" : "";
$options_html .= "";
}
$this->settings[] = [
"type" => "border",
"html" => "{$desc} | 두께idx}]\" value=\"{$this->$key2}\" placeholder=\"0\" title=\"두께\" style=\"width:45px;\"/> | "
];
}
}
public function addSelectSetting($desc, $default, $values)
{
$idx = $this->getCurrentCount() + 1;
if ($idx <= 19) {
$key1 = "cs_etc_{$idx}";
$options_html = "";
foreach ($values as $key => $val) {
$k = trim($key);
$s = $this->$key1 == $k ? " selected" : "";
$options_html .= "";
}
$this->settings[] = [
"type" => "select",
"html" => "{$desc} | | "
];
}
}
public function getExplodeValue($idx)
{
$key = "cs_etc_{$idx}";
return explode("||", $this->$key);
}
public function getSettingHtml()
{
$html = "";
foreach ($this->settings as $idx => $val) {
if ($html == "") {
$html .= $this->addHeader();
} else {
$html .= "";
}
$html .= $val['html'];
}
return $html;
}
}