19 declare(strict_types=1);
29 protected string $hex =
"";
35 string $a_postvar =
"" 46 $this->
setAlert($this->
lng->txt(
"msg_input_is_required"));
69 $a_value = trim($a_value);
71 parent::setValue($a_value);
80 $this->defaultcolor = $a_defaultcolor;
91 $this->acceptnamedcolors = $a_acceptnamedcolors;
101 if (strpos($this->hex,
'#') === 0) {
102 return substr($this->hex, 1);
109 $a_value = trim(strtolower($a_value));
112 if (strpos($a_value,
'#') === 0) {
113 $a_value = substr($a_value, 1);
119 case "black": $a_value =
"000000";
121 case "maroon": $a_value =
"800000";
123 case "green": $a_value =
"008000";
125 case "olive": $a_value =
"808000";
127 case "navy": $a_value =
"000080";
129 case "purple": $a_value =
"800080";
131 case "teal": $a_value =
"008080";
133 case "silver": $a_value =
"C0C0C0";
135 case "gray": $a_value =
"808080";
137 case "red": $a_value =
"ff0000";
139 case "lime": $a_value =
"00ff00";
141 case "yellow": $a_value =
"ffff00";
143 case "blue": $a_value =
"0000ff";
145 case "fuchsia": $a_value =
"ff00ff";
147 case "aqua": $a_value =
"00ffff";
149 case "white": $a_value =
"ffffff";
153 case "brown": $a_value =
"a52a2a";
158 if (substr($a_value, 0, 3) ==
"rgb") {
159 $pos1 = strpos($a_value,
"(");
160 $pos2 = strpos($a_value,
")");
161 $rgb = explode(
",", substr($a_value, $pos1 + 1, $pos2 - $pos1 - 1));
162 $r = str_pad(dechex((
int) $rgb[0]), 2,
"0", STR_PAD_LEFT);
163 $g = str_pad(dechex((
int) $rgb[1]), 2,
"0", STR_PAD_LEFT);
164 $b = str_pad(dechex((
int) $rgb[2]), 2,
"0", STR_PAD_LEFT);
165 $a_value =
$r . $g .
$b;
168 $a_value = trim(strtolower($a_value));
171 if (preg_match(
"/^[a-f0-9]{3}/", $a_value) && strlen($a_value) == 3) {
172 $a_value =
"" . $a_value;
173 $a_value = $a_value[0] . $a_value[0] . $a_value[1] . $a_value[1] . $a_value[2] . $a_value[2];
176 if (!preg_match(
"/^[a-f0-9]{6}/", $a_value)) {
180 return strtoupper($a_value);
185 $tpl =
new ilTemplate(
'tpl.prop_color.html',
true,
true,
'components/ILIAS/Form');
186 $tpl->setVariable(
'COLOR_ID', $this->
getFieldId());
191 $tpl->setVariable(
'INIT_COLOR_SHORT', $ic);
192 $tpl->setVariable(
'POST_VAR', $this->
getPostVar());
195 $a_tpl->
setVariable(
'COLOR_DISABLED',
'disabled="disabled"');
198 $tpl->setVariable(
"POST_VAR", $this->
getPostVar());
199 $tpl->setVariable(
"PROP_COLOR_ID", $this->
getFieldId());
203 "PROPERTY_VALUE_COLOR",
208 $tpl->setVariable(
'INIT_COLOR',
'#' . $this->
getHexcode());
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
setVariable($variable, $value='')
Sets a variable value.
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
__construct(Container $dic, ilPlugin $plugin)