| 1 |
<?php |
| 2 |
/* |
| 3 |
|
| 4 |
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) |
| 5 |
Copyright (C) 2010 - 2026 Roland Gruber |
| 6 |
|
| 7 |
This program is free software; you can redistribute it and/or modify |
| 8 |
it under the terms of the GNU General Public License as published by |
| 9 |
the Free Software Foundation; either version 2 of the License, or |
| 10 |
(at your option) any later version. |
| 11 |
|
| 12 |
This program is distributed in the hope that it will be useful, |
| 13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
GNU General Public License for more details. |
| 16 |
|
| 17 |
You should have received a copy of the GNU General Public License |
| 18 |
along with this program; if not, write to the Free Software |
| 19 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 |
|
| 21 |
*/ |
| 22 |
|
| 23 |
/** |
| 24 |
* Interface between modules and other parts of LAM. |
| 25 |
* |
| 26 |
* @package metaHTML |
| 27 |
* @author Roland Gruber |
| 28 |
*/ |
| 29 |
|
| 30 |
/** |
| 31 |
* Returns the marker for required values. |
| 32 |
* |
| 33 |
* @return string HTML code for required marker |
| 34 |
*/ |
| 35 |
function htmlGetRequiredMarker(): string { |
| 36 |
return '<span class="lam-required" title="' . _('required') . '">*</span>'; |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Returns the marker for required values. |
| 41 |
* |
| 42 |
* @return htmlSpan HTML code for required marker |
| 43 |
*/ |
| 44 |
function htmlGetRequiredMarkerElement(): htmlSpan { |
| 45 |
$span = new htmlSpan(new htmlOutputText('*'), ['lam-required']); |
| 46 |
$span->setTitle(_('required')); |
| 47 |
return $span; |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Represents a HTML element. |
| 52 |
* This is used to build HTML code by using objects. |
| 53 |
* |
| 54 |
* @package metaHTML |
| 55 |
*/ |
| 56 |
abstract class htmlElement { |
| 57 |
|
| 58 |
/** align to top */ |
| 59 |
public const ALIGN_TOP = 0; |
| 60 |
/** align to left */ |
| 61 |
public const ALIGN_LEFT = 1; |
| 62 |
/** align to right */ |
| 63 |
public const ALIGN_RIGHT = 2; |
| 64 |
/** align to bottom */ |
| 65 |
public const ALIGN_BOTTOM = 3; |
| 66 |
/** align to center */ |
| 67 |
public const ALIGN_CENTER = 4; |
| 68 |
|
| 69 |
/** alignment when inside a table */ |
| 70 |
public ?int $alignment = null; |
| 71 |
/** colspan if inside a table */ |
| 72 |
public ?int $colspan = null; |
| 73 |
/** rowspan if inside a table */ |
| 74 |
public ?int $rowspan = null; |
| 75 |
/** @var string[] $cssClasses CSS classes */ |
| 76 |
protected ?array $cssClasses = []; |
| 77 |
/** @var string[] $tableCellCssClasses table cell CSS classes */ |
| 78 |
protected ?array $tableCellCssClasses = []; |
| 79 |
/** @var array<string, string> $dataAttributes data attributes */ |
| 80 |
private array $dataAttributes = []; |
| 81 |
/** accessibility label */ |
| 82 |
private ?string $accessibilityLabel = null; |
| 83 |
|
| 84 |
/** |
| 85 |
* Prints the HTML code for this element. |
| 86 |
* |
| 87 |
* @param string|null $module Name of account module |
| 88 |
* @param htmlElement[] $input List of meta-HTML elements |
| 89 |
* @param array<string, string[]> $values List of values which override the defaults in $input (name => value) |
| 90 |
* @param bool $restricted If true then no buttons will be displayed |
| 91 |
* @return array<string, string> List of input field names and their type (name => type) |
| 92 |
*/ |
| 93 |
abstract public function generateHTML($module, $input, $values, $restricted): array; |
| 94 |
|
| 95 |
/** |
| 96 |
* Returns the HTML attributes for the alignment. |
| 97 |
* |
| 98 |
* @return string alignment HTML attributes (e.g. align="right" valign="top") |
| 99 |
*/ |
| 100 |
public function getAlignmentString(): string { |
| 101 |
$align = ''; |
| 102 |
if ($this->alignment !== null) { |
| 103 |
switch ($this->alignment) { |
| 104 |
case htmlElement::ALIGN_BOTTOM: |
| 105 |
$align = 'valign="bottom"'; |
| 106 |
break; |
| 107 |
case htmlElement::ALIGN_TOP: |
| 108 |
$align = 'valign="top"'; |
| 109 |
break; |
| 110 |
case htmlElement::ALIGN_LEFT: |
| 111 |
$align = 'align="left"'; |
| 112 |
break; |
| 113 |
case htmlElement::ALIGN_RIGHT: |
| 114 |
$align = 'align="right"'; |
| 115 |
break; |
| 116 |
case htmlElement::ALIGN_CENTER: |
| 117 |
$align = 'align="center"'; |
| 118 |
break; |
| 119 |
} |
| 120 |
} |
| 121 |
return $align; |
| 122 |
} |
| 123 |
|
| 124 |
/** |
| 125 |
* Returns the HTML attribute for the colspan. |
| 126 |
* |
| 127 |
* @return string colspan HTML attribute (e.g. colspan=3) |
| 128 |
*/ |
| 129 |
public function getColspanString(): string { |
| 130 |
if ($this->colspan === null) { |
| 131 |
return ''; |
| 132 |
} |
| 133 |
else { |
| 134 |
return 'colspan="' . $this->colspan . '"'; |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
/** |
| 139 |
* Returns the HTML attribute for the rowspan. |
| 140 |
* |
| 141 |
* @return string rowspan HTML attribute (e.g. rowspan=3) |
| 142 |
*/ |
| 143 |
public function getRowspanString(): string { |
| 144 |
if ($this->rowspan === null) { |
| 145 |
return ''; |
| 146 |
} |
| 147 |
else { |
| 148 |
return 'rowspan="' . $this->rowspan . '"'; |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
/** |
| 153 |
* Returns the CSS classes of this element. |
| 154 |
* |
| 155 |
* @return string[]|null $classes CSS class names |
| 156 |
*/ |
| 157 |
public function getCSSClasses(): ?array { |
| 158 |
return $this->cssClasses; |
| 159 |
} |
| 160 |
|
| 161 |
/** |
| 162 |
* Adds CSS classes to this element. |
| 163 |
* |
| 164 |
* @param string[]|null $classes CSS class names |
| 165 |
*/ |
| 166 |
public function setCSSClasses(?array $classes): void { |
| 167 |
$this->cssClasses = $classes; |
| 168 |
} |
| 169 |
|
| 170 |
/** |
| 171 |
* Adds CSS classes to the surrounding table cell for this element. |
| 172 |
* |
| 173 |
* @param string[]|null $classes CSS class names |
| 174 |
*/ |
| 175 |
public function setTableCellCSSClasses(?array $classes): void { |
| 176 |
$this->tableCellCssClasses = $classes; |
| 177 |
} |
| 178 |
|
| 179 |
/** |
| 180 |
* Returns the CSS classes of the surrounding table cell for this element. |
| 181 |
* |
| 182 |
* @return string[]|null CSS classes |
| 183 |
*/ |
| 184 |
public function getTableCellCSSClasses(): ?array { |
| 185 |
return $this->tableCellCssClasses; |
| 186 |
} |
| 187 |
|
| 188 |
/** |
| 189 |
* Adds a data attribute. |
| 190 |
* |
| 191 |
* @param string $key attribute name (without "data-") |
| 192 |
* @param string $value attribute value |
| 193 |
*/ |
| 194 |
public function addDataAttribute(string $key, string $value): void { |
| 195 |
$this->dataAttributes[$key] = $value; |
| 196 |
} |
| 197 |
|
| 198 |
/** |
| 199 |
* Returns the data attributes as rendered string. |
| 200 |
* |
| 201 |
* @return string data attributes |
| 202 |
*/ |
| 203 |
protected function getDataAttributesAsString(): string { |
| 204 |
$result = ''; |
| 205 |
foreach ($this->dataAttributes as $key => $value) { |
| 206 |
$result .= ' data-' . htmlspecialchars($key) . '="' . htmlspecialchars($value) . '"'; |
| 207 |
} |
| 208 |
return $result; |
| 209 |
} |
| 210 |
|
| 211 |
/** |
| 212 |
* Sets the accessibility label. |
| 213 |
* |
| 214 |
* @param string|null $accessibilityLabel label |
| 215 |
*/ |
| 216 |
public function setAccessibilityLabel(?string $accessibilityLabel): void { |
| 217 |
$this->accessibilityLabel = $accessibilityLabel; |
| 218 |
} |
| 219 |
|
| 220 |
/** |
| 221 |
* Returns the markup for the accessibility data. |
| 222 |
* |
| 223 |
* @return string markup to be included in HTML tag (starting with space) |
| 224 |
*/ |
| 225 |
public function getAccessibilityMarkup(): string { |
| 226 |
if (empty($this->accessibilityLabel)) { |
| 227 |
return ''; |
| 228 |
} |
| 229 |
return ' aria-label="' . htmlspecialchars($this->accessibilityLabel) . '"'; |
| 230 |
} |
| 231 |
|
| 232 |
} |
| 233 |
|
| 234 |
/** |
| 235 |
* Structures elements using a table. |
| 236 |
* |
| 237 |
* @package metaHTML |
| 238 |
*/ |
| 239 |
class htmlTable extends htmlElement { |
| 240 |
|
| 241 |
/** table footer */ |
| 242 |
private const FOOTER = "</table>\n"; |
| 243 |
/** new line */ |
| 244 |
private const NEWLINE = "</tr><tr>\n"; |
| 245 |
|
| 246 |
/** @var array<string|htmlElement> $elements list of subelements */ |
| 247 |
private array $elements = []; |
| 248 |
/** specifies if currently a row is open */ |
| 249 |
private bool $rowOpen = false; |
| 250 |
/** table width */ |
| 251 |
private ?string $width; |
| 252 |
/** HTML ID */ |
| 253 |
private ?string $id; |
| 254 |
|
| 255 |
/** |
| 256 |
* Constructor |
| 257 |
* |
| 258 |
* @param string|null $width table width (e.g. 100%) |
| 259 |
* @param string|null $id id |
| 260 |
* @see htmlElement |
| 261 |
*/ |
| 262 |
public function __construct(?string $width = null, ?string $id = null) { |
| 263 |
$this->width = $width; |
| 264 |
$this->id = $id; |
| 265 |
} |
| 266 |
|
| 267 |
/** |
| 268 |
* Adds an element to the table. |
| 269 |
* |
| 270 |
* @param htmlElement $element htmlElement object or a simple string |
| 271 |
* @param bool $newLine adds a new line after the element (optional, default false) |
| 272 |
* @param bool $isTableHeadElement specifies if this is a head or body element (default: body) |
| 273 |
*/ |
| 274 |
public function addElement(htmlElement $element, bool $newLine = false, bool $isTableHeadElement = false): void { |
| 275 |
// check if a row needs to be opened |
| 276 |
if (!$this->rowOpen) { |
| 277 |
$this->elements[] = "<tr>\n"; |
| 278 |
$this->rowOpen = true; |
| 279 |
} |
| 280 |
// check if alignment option was given |
| 281 |
$align = $element->getAlignmentString(); |
| 282 |
$colspan = $element->getColspanString(); |
| 283 |
$rowspan = $element->getRowspanString(); |
| 284 |
$css = ''; |
| 285 |
if (count($element->getTableCellCSSClasses()) > 0) { |
| 286 |
$css = 'class="' . implode(' ', $element->getTableCellCSSClasses()) . '"'; |
| 287 |
} |
| 288 |
$tagName = 'td'; |
| 289 |
if ($isTableHeadElement) { |
| 290 |
$tagName = 'th'; |
| 291 |
} |
| 292 |
$this->elements[] = "<$tagName $align $colspan $rowspan $css>\n"; |
| 293 |
$this->elements[] = $element; |
| 294 |
$this->elements[] = "</$tagName>\n"; |
| 295 |
if ($newLine) { |
| 296 |
$this->addNewLine(); |
| 297 |
} |
| 298 |
} |
| 299 |
|
| 300 |
/** |
| 301 |
* Adds another line to the table. |
| 302 |
*/ |
| 303 |
public function addNewLine(): void { |
| 304 |
$this->elements[] = $this->rowOpen ? self::NEWLINE : "<tr>\n"; |
| 305 |
} |
| 306 |
|
| 307 |
/** |
| 308 |
* Adds an htmlSpacer with the given width. |
| 309 |
* |
| 310 |
* @param string $width width (e.g. 10px) |
| 311 |
*/ |
| 312 |
public function addSpace(string $width): void { |
| 313 |
$this->addElement(new htmlSpacer($width, null)); |
| 314 |
} |
| 315 |
|
| 316 |
/** |
| 317 |
* Adds an htmlSpacer with the given height and ends the row. |
| 318 |
* |
| 319 |
* @param string $height height (e.g. 10px) |
| 320 |
*/ |
| 321 |
public function addVerticalSpace(string $height): void { |
| 322 |
$this->addElement(new htmlSpacer(null, $height), true); |
| 323 |
} |
| 324 |
|
| 325 |
/** |
| 326 |
* {@inheritDoc} |
| 327 |
*/ |
| 328 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 329 |
$return = []; |
| 330 |
$width = ''; |
| 331 |
if ($this->width != null) { |
| 332 |
$width = ' width="' . htmlspecialchars($this->width) . '"'; |
| 333 |
} |
| 334 |
$id = ''; |
| 335 |
if (!empty($this->id)) { |
| 336 |
$id = ' id="' . $this->id . '"'; |
| 337 |
} |
| 338 |
$classAttr = ''; |
| 339 |
if (count($this->cssClasses) > 0) { |
| 340 |
$classAttr = ' class="' . implode(' ', $this->cssClasses) . '"'; |
| 341 |
} |
| 342 |
echo "<table" . $width . $id . $classAttr . ">\n"; |
| 343 |
// print all contained elements |
| 344 |
for ($i = 0; $i < count($this->elements); $i++) { |
| 345 |
// print htmlElement objects |
| 346 |
if ($this->elements[$i] instanceof htmlElement) { |
| 347 |
$fields = $this->elements[$i]->generateHTML($module, $input, $values, $restricted); |
| 348 |
$return = array_merge($return, $fields); |
| 349 |
} |
| 350 |
elseif ($i !== count($this->elements) - 1 || ($this->elements[$i] != self::NEWLINE)) { |
| 351 |
echo $this->elements[$i]; |
| 352 |
} |
| 353 |
} |
| 354 |
if ($this->rowOpen) { |
| 355 |
echo "</tr>\n"; |
| 356 |
} |
| 357 |
echo self::FOOTER; |
| 358 |
return $return; |
| 359 |
} |
| 360 |
|
| 361 |
/** |
| 362 |
* Merges the content of another htmlTable object into this table. |
| 363 |
* |
| 364 |
* @param htmlTable $table table to get elements |
| 365 |
*/ |
| 366 |
public function mergeTableElements(htmlTable $table): void { |
| 367 |
// remove obsolete new lines at the end |
| 368 |
if ($table->elements[count($table->elements) - 1] == self::NEWLINE) { |
| 369 |
unset($table->elements[count($table->elements) - 1]); |
| 370 |
} |
| 371 |
// close last row of other table if needed |
| 372 |
if ($table->rowOpen) { |
| 373 |
$table->elements[] = "</tr>\n"; |
| 374 |
} |
| 375 |
// close last own row if needed |
| 376 |
if ($this->rowOpen) { |
| 377 |
if ($this->elements[count($this->elements) - 1] == self::NEWLINE) { |
| 378 |
unset($this->elements[count($this->elements) - 1]); |
| 379 |
} |
| 380 |
else { |
| 381 |
$this->elements[] = "</tr>\n"; |
| 382 |
} |
| 383 |
$this->rowOpen = false; |
| 384 |
} |
| 385 |
$this->elements = array_merge($this->elements, $table->elements); |
| 386 |
} |
| 387 |
|
| 388 |
} |
| 389 |
|
| 390 |
/** |
| 391 |
* Table component for client-side controlled data tables. |
| 392 |
*/ |
| 393 |
class htmlDataTable extends htmlElement { |
| 394 |
|
| 395 |
public const DATA_AJAX_URL = 'ajaxurl'; |
| 396 |
public const DATA_TOKEN_NAME = 'tokenname'; |
| 397 |
public const DATA_TOKEN_VALUE = 'tokenvalue'; |
| 398 |
public const DATA_ACTION = 'action'; |
| 399 |
public const DATA_OK_TEXT = 'oktext'; |
| 400 |
public const SORT_ASC = 'asc'; |
| 401 |
public const SORT_DESC = 'desc'; |
| 402 |
|
| 403 |
private string $id; |
| 404 |
private mixed $height; |
| 405 |
/** @var htmlDataTableColumn[] $columns columns */ |
| 406 |
private array $columns; |
| 407 |
private string $searchFieldId = ''; |
| 408 |
private string $onRowClick = ''; |
| 409 |
private ?string $initialSortColumn = null; |
| 410 |
private ?string $initialSortOrder = null; |
| 411 |
|
| 412 |
/** |
| 413 |
* Constructor |
| 414 |
* |
| 415 |
* @param string $id table ID |
| 416 |
* @param htmlDataTableColumn[] $columns columns |
| 417 |
* @param int|string $height table height |
| 418 |
*/ |
| 419 |
public function __construct(string $id, array $columns, mixed $height = 300) { |
| 420 |
$this->id = htmlspecialchars($id); |
| 421 |
$this->height = $height; |
| 422 |
$this->columns = $columns; |
| 423 |
} |
| 424 |
|
| 425 |
/** |
| 426 |
* {@inheritDoc} |
| 427 |
*/ |
| 428 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 429 |
echo '<link href="../../style/tabulator/tabulator.css" rel="stylesheet">'; |
| 430 |
echo '<script type="text/javascript" src="../../templates/lib/extra/tabulator/tabulator.js"></script>'; |
| 431 |
echo '<div id="' . $this->id . '" class="lam-data-table" ' . $this->getDataAttributesAsString() . '></div>'; |
| 432 |
$columnOptions = []; |
| 433 |
foreach ($this->columns as $column) { |
| 434 |
$headerFilter = $column->filterable ? ', headerFilter: "input"' : ''; |
| 435 |
$columnOptions[] = '{ |
| 436 |
title: "' . $column->label . '", |
| 437 |
field: "' . $column->name . '", |
| 438 |
headerTooltip: "' . $column->label . '", |
| 439 |
formatter: "' . $column->getFormatter() . '", |
| 440 |
visible: ' . ($column->visible ? 'true' : 'false') . ', |
| 441 |
formatterParams: ' . json_encode((object) $column->getFormatterOptions()) . ' |
| 442 |
' . $headerFilter . ' |
| 443 |
}'; |
| 444 |
} |
| 445 |
$columnsCode = implode(', ', $columnOptions); |
| 446 |
$searchFilterCode = ''; |
| 447 |
if (!empty($this->searchFieldId)) { |
| 448 |
$searchFilterCode = 'window.lam.datatable.addSearchField("' . $this->id . '", "' . $this->searchFieldId . '");'; |
| 449 |
} |
| 450 |
$onRowClickCode = ''; |
| 451 |
if (!empty($this->onRowClick)) { |
| 452 |
$onRowClickCode = 'window.lam.datatable.tables["' . $this->id . '"].on("rowClick", ' . $this->onRowClick . ');'; |
| 453 |
} |
| 454 |
$initialSortingCode = ''; |
| 455 |
if (!empty($this->initialSortColumn)) { |
| 456 |
$initialSortingCode = 'initialSort: [{column: "' . $this->initialSortColumn . '", dir: "' . $this->initialSortOrder . '"}],'; |
| 457 |
} |
| 458 |
echo '<script type="text/javascript"> |
| 459 |
window.lam.datatable.init("' . $this->id . '", new Tabulator("#' . $this->id . '", { |
| 460 |
height: "' . $this->height . '", |
| 461 |
layout: "fitColumns", |
| 462 |
pagination:"local", |
| 463 |
paginationSize:50, |
| 464 |
paginationSizeSelector:[50, 100, 250, 500], |
| 465 |
columns: [' . $columnsCode . '], |
| 466 |
data: [], |
| 467 |
locale: "en-gb", |
| 468 |
' . $initialSortingCode . ' |
| 469 |
langs: { |
| 470 |
"en-gb": { |
| 471 |
"pagination": { |
| 472 |
"page_size": "", |
| 473 |
"page_title": "", |
| 474 |
"first": "↤", |
| 475 |
"first_title": "", |
| 476 |
"last": "↦", |
| 477 |
"last_title": "", |
| 478 |
"prev": "←", |
| 479 |
"prev_title": "", |
| 480 |
"next": "→", |
| 481 |
"next_title": "" |
| 482 |
} |
| 483 |
} |
| 484 |
} |
| 485 |
})); |
| 486 |
' . $searchFilterCode . ' |
| 487 |
' . $onRowClickCode . ' |
| 488 |
</script>'; |
| 489 |
return []; |
| 490 |
} |
| 491 |
|
| 492 |
/** |
| 493 |
* Sets the search field. |
| 494 |
* |
| 495 |
* @param string $searchFieldId ID of field |
| 496 |
*/ |
| 497 |
public function setSearchField(string $searchFieldId): void { |
| 498 |
$this->searchFieldId = $searchFieldId; |
| 499 |
} |
| 500 |
|
| 501 |
/** |
| 502 |
* Sets the row click handler. |
| 503 |
* |
| 504 |
* @param string $callback callback code |
| 505 |
*/ |
| 506 |
public function setOnRowClick(string $callback): void { |
| 507 |
$this->onRowClick = $callback; |
| 508 |
} |
| 509 |
|
| 510 |
/** |
| 511 |
* Sets the initial sort order. |
| 512 |
* |
| 513 |
* @param string $columnName column name |
| 514 |
* @param string $sortOrder htmlDataTable::SORT_ASC|htmlDataTable::SORT_DESC |
| 515 |
*/ |
| 516 |
public function setInitialSorting(string $columnName, string $sortOrder): void { |
| 517 |
if (in_array($sortOrder, [self::SORT_ASC, self::SORT_DESC])) { |
| 518 |
$this->initialSortColumn = $columnName; |
| 519 |
$this->initialSortOrder = $sortOrder; |
| 520 |
} |
| 521 |
} |
| 522 |
|
| 523 |
} |
| 524 |
|
| 525 |
/** |
| 526 |
* Column for data table. |
| 527 |
*/ |
| 528 |
class htmlDataTableColumn { |
| 529 |
|
| 530 |
public const TYPE_TEXT = 'text'; |
| 531 |
public const TYPE_EMAIL = 'email'; |
| 532 |
public const TYPE_TELEPHONE = 'telephone'; |
| 533 |
public const TYPE_IMAGE = 'image'; |
| 534 |
public const TYPE_HTML = 'html'; |
| 535 |
|
| 536 |
public string $label; |
| 537 |
public string $name; |
| 538 |
public bool $filterable; |
| 539 |
public string $formattingType; |
| 540 |
public bool $visible; |
| 541 |
|
| 542 |
/** |
| 543 |
* @param string $label column label text |
| 544 |
* @param string $name column ID |
| 545 |
* @param bool $filterable can be filtered |
| 546 |
* @param string $formattingType formatting type |
| 547 |
* @param bool $visible column is visible |
| 548 |
*/ |
| 549 |
public function __construct(string $label, string $name, bool $filterable = true, string $formattingType = self::TYPE_TEXT, bool $visible = true) { |
| 550 |
$this->label = htmlspecialchars($label); |
| 551 |
$this->name = htmlspecialchars($name); |
| 552 |
$this->filterable = $filterable; |
| 553 |
$this->formattingType = $formattingType; |
| 554 |
$this->visible = $visible; |
| 555 |
} |
| 556 |
|
| 557 |
/** |
| 558 |
* Returns the Tabulator formatter name. |
| 559 |
* |
| 560 |
* @return string name |
| 561 |
*/ |
| 562 |
public function getFormatter(): string { |
| 563 |
return match ($this->formattingType) { |
| 564 |
self::TYPE_EMAIL, self::TYPE_TELEPHONE => 'link', |
| 565 |
self::TYPE_IMAGE => 'image', |
| 566 |
self::TYPE_HTML => 'html', |
| 567 |
default => 'textarea', |
| 568 |
}; |
| 569 |
} |
| 570 |
|
| 571 |
/** |
| 572 |
* Returns the Tabulator formatter options. |
| 573 |
* |
| 574 |
* @return array<string, string> options |
| 575 |
*/ |
| 576 |
public function getFormatterOptions(): array { |
| 577 |
return match ($this->formattingType) { |
| 578 |
self::TYPE_EMAIL => ['urlPrefix' => 'mailto:', 'target' => '_blank'], |
| 579 |
self::TYPE_TELEPHONE => ['urlPrefix' => 'tel:', 'target' => '_blank'], |
| 580 |
default => [], |
| 581 |
}; |
| 582 |
} |
| 583 |
|
| 584 |
} |
| 585 |
|
| 586 |
/** |
| 587 |
* A standard input field. |
| 588 |
* |
| 589 |
* @package metaHTML |
| 590 |
*/ |
| 591 |
class htmlInputField extends htmlElement { |
| 592 |
|
| 593 |
/** unique field name */ |
| 594 |
protected string $fieldName; |
| 595 |
/** field value */ |
| 596 |
protected ?string $fieldValue = ''; |
| 597 |
/** field size (default 30) */ |
| 598 |
protected ?int $fieldSize = 30; |
| 599 |
/** field max length (default 1000) */ |
| 600 |
protected ?int $fieldMaxLength = 1000; |
| 601 |
/** on keypress event */ |
| 602 |
protected ?string $onKeyPress = null; |
| 603 |
/** on keyupp event */ |
| 604 |
protected ?string $onKeyUp = null; |
| 605 |
/** oninput event */ |
| 606 |
protected ?string $onInput = null; |
| 607 |
/** password field */ |
| 608 |
protected bool $isPassword = false; |
| 609 |
/** check password strength */ |
| 610 |
protected bool $checkPasswordStrength = false; |
| 611 |
/** disables browser autofilling of password fields */ |
| 612 |
protected bool $disableAutoFill = false; |
| 613 |
/** enabled or disabled */ |
| 614 |
protected bool $isEnabled = true; |
| 615 |
/** indicates that the value should be saved in obfuscated form */ |
| 616 |
protected bool $obfuscate = false; |
| 617 |
/** indicates that this field should not automatically be saved in the self-service or server profile */ |
| 618 |
protected bool $transient = false; |
| 619 |
/** required field */ |
| 620 |
protected bool $required = false; |
| 621 |
/** enable autocomplete */ |
| 622 |
protected bool $autocomplete = false; |
| 623 |
/** @var string[] $autocompleteValues autocompletion suggestions */ |
| 624 |
protected array $autocompleteValues = []; |
| 625 |
/** show calendar */ |
| 626 |
protected bool $showCalendar = false; |
| 627 |
/** show DN selection */ |
| 628 |
protected bool $showDnSelection = false; |
| 629 |
/** calendar format */ |
| 630 |
protected string $calendarFormat = ''; |
| 631 |
/** calendar with time */ |
| 632 |
protected bool $calendarFormatWithTime = false; |
| 633 |
/** calendar with seconds */ |
| 634 |
protected bool $calendarFormatWithSeconds = false; |
| 635 |
/** title attribute */ |
| 636 |
protected ?string $title = null; |
| 637 |
/** field ID that needs to have same value (e.g. password field) */ |
| 638 |
protected ?string $sameValueFieldID = null; |
| 639 |
/** marks the input field as auto trimmed (remove spaces at start/end) */ |
| 640 |
protected bool $autoTrim = true; |
| 641 |
/** minimum value */ |
| 642 |
protected ?int $minValue = null; |
| 643 |
/** maximum value */ |
| 644 |
protected ?int $maxValue = null; |
| 645 |
/** step for numeric values */ |
| 646 |
protected ?int $stepValue = null; |
| 647 |
/** id */ |
| 648 |
protected ?string $id = null; |
| 649 |
/** input type */ |
| 650 |
protected string $type = 'text'; |
| 651 |
/** validation pattern */ |
| 652 |
protected ?string $validationPattern = null; |
| 653 |
|
| 654 |
/** |
| 655 |
* Constructor |
| 656 |
* |
| 657 |
* @param string $fieldName unique field name |
| 658 |
* @param string|null $fieldValue value of input field (optional) |
| 659 |
* @param int|null $fieldSize input field length (default 30) |
| 660 |
*/ |
| 661 |
public function __construct(string $fieldName, ?string $fieldValue = null, ?int $fieldSize = null) { |
| 662 |
if (isObfuscatedText($fieldValue)) { |
| 663 |
$fieldValue = deobfuscateText($fieldValue); |
| 664 |
} |
| 665 |
$this->fieldName = htmlspecialchars($fieldName); |
| 666 |
if ($fieldValue !== null) { |
| 667 |
$this->fieldValue = htmlspecialchars($fieldValue); |
| 668 |
} |
| 669 |
if ($fieldSize !== null) { |
| 670 |
$this->fieldSize = $fieldSize; |
| 671 |
} |
| 672 |
} |
| 673 |
|
| 674 |
/** |
| 675 |
* {@inheritDoc} |
| 676 |
*/ |
| 677 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 678 |
if ($this->isAutoTrim()) { |
| 679 |
$this->cssClasses[] = 'lam-autotrim'; |
| 680 |
} |
| 681 |
if (isset($values[$this->fieldName])) { |
| 682 |
if (isObfuscatedText($values[$this->fieldName][0])) { |
| 683 |
$this->fieldValue = htmlspecialchars(deobfuscateText($values[$this->fieldName][0])); |
| 684 |
} |
| 685 |
else { |
| 686 |
$this->fieldValue = htmlspecialchars($values[$this->fieldName][0]); |
| 687 |
} |
| 688 |
} |
| 689 |
$min = ''; |
| 690 |
if ($this->minValue !== null) { |
| 691 |
$min = ' min="' . $this->minValue . '"'; |
| 692 |
} |
| 693 |
$max = ''; |
| 694 |
if ($this->maxValue !== null) { |
| 695 |
$max = ' max="' . $this->maxValue . '"'; |
| 696 |
} |
| 697 |
$step = ''; |
| 698 |
if ($this->stepValue !== null) { |
| 699 |
$step = ' step="' . $this->stepValue . '"'; |
| 700 |
} |
| 701 |
$validationPattern = ''; |
| 702 |
if ($this->validationPattern !== null) { |
| 703 |
$validationPattern = ' pattern="' . $this->validationPattern . '"'; |
| 704 |
} |
| 705 |
// print input field |
| 706 |
$required = ''; |
| 707 |
if ($this->required) { |
| 708 |
$required = ' required'; |
| 709 |
} |
| 710 |
$class = ' class="' . implode(' ', $this->cssClasses) . '"'; |
| 711 |
$name = ' name="' . $this->fieldName . '"'; |
| 712 |
$idValue = $this->id ?? $this->fieldName; |
| 713 |
$id = ' id="' . $idValue . '"'; |
| 714 |
$value = ''; |
| 715 |
if ($this->fieldValue !== null) { |
| 716 |
$value = ' value="' . $this->fieldValue . '"'; |
| 717 |
} |
| 718 |
$maxLength = ''; |
| 719 |
if ($this->fieldMaxLength !== null) { |
| 720 |
$maxLength = ' maxlength="' . $this->fieldMaxLength . '"'; |
| 721 |
} |
| 722 |
$size = ''; |
| 723 |
if ($this->fieldSize !== null) { |
| 724 |
$size = ' size="' . $this->fieldSize . '"'; |
| 725 |
} |
| 726 |
$inputType = $this->type; |
| 727 |
if ($this->isPassword) { |
| 728 |
$inputType = 'password'; |
| 729 |
} |
| 730 |
elseif (($this->minValue !== null) || ($this->maxValue !== null)) { |
| 731 |
$inputType = 'number'; |
| 732 |
} |
| 733 |
$disabled = ''; |
| 734 |
if (!$this->isEnabled) { |
| 735 |
$disabled = ' disabled'; |
| 736 |
} |
| 737 |
$onKeyPress = ''; |
| 738 |
if ($this->onKeyPress != null) { |
| 739 |
$onKeyPress = ' onkeypress="' . $this->onKeyPress . '"'; |
| 740 |
} |
| 741 |
$onKeyUp = ''; |
| 742 |
if ($this->onKeyUp != null) { |
| 743 |
$onKeyUp = ' onkeyup="' . $this->onKeyUp . '"'; |
| 744 |
} |
| 745 |
$onInput = ''; |
| 746 |
if ($this->onInput != null) { |
| 747 |
$onInput = ' oninput="' . $this->onInput . '"'; |
| 748 |
} |
| 749 |
$title = ''; |
| 750 |
if (!empty($this->title)) { |
| 751 |
$title = ' title="' . $this->title . '"'; |
| 752 |
} |
| 753 |
$autoCompleteVal = ''; |
| 754 |
if ($this->disableAutoFill) { |
| 755 |
$autoCompleteVal = ' autocomplete="new-password"'; |
| 756 |
} |
| 757 |
$autoCompleteData = ''; |
| 758 |
if ($this->autocomplete && !empty($idValue)) { |
| 759 |
if (($this->fieldValue !== null) && !in_array($this->fieldValue, $this->autocompleteValues)) { |
| 760 |
array_unshift($this->autocompleteValues, $this->fieldValue); |
| 761 |
} |
| 762 |
echo '<datalist id="datalist_' . $idValue . '" autocomplete="off">'; |
| 763 |
foreach ($this->autocompleteValues as $autocompleteValue) { |
| 764 |
echo '<option value="' . $autocompleteValue . '">'; |
| 765 |
} |
| 766 |
echo '</datalist>'; |
| 767 |
$autoCompleteData = ' list="datalist_' . $idValue . '"'; |
| 768 |
} |
| 769 |
if ($this->showDnSelection) { |
| 770 |
echo '<span class="nowrap">'; |
| 771 |
} |
| 772 |
if ($this->checkPasswordStrength) { |
| 773 |
echo '<div id="' . $idValue . '-pwd-strength-issues" class="lam-password-strength"></div>'; |
| 774 |
} |
| 775 |
echo '<input type="' . $inputType . '"' . $class . $name . $id . $value . $maxLength . $required |
| 776 |
. $min . $max . $step . $validationPattern . $size . $onKeyPress . $onKeyUp |
| 777 |
. $onInput . $title . $disabled . $this->getAccessibilityMarkup() |
| 778 |
. $this->getDataAttributesAsString() . $autoCompleteVal . $autoCompleteData . '>'; |
| 779 |
if ($this->showDnSelection) { |
| 780 |
echo '<img class="align-middle" src="../../graphics/search-color.svg" |
| 781 |
width="16" height="16" title="' . _('Choose entry') . '" |
| 782 |
onclick="window.lam.html.showDnSelection(\'' . $this->fieldName . '\', \'' . _('Choose entry') . '\' |
| 783 |
, \'' . _('Ok') . '\', \'' . _('Cancel') . '\', \'' . getSecurityTokenName() . '\' |
| 784 |
, \'' . getSecurityTokenValue() . '\');">'; |
| 785 |
echo '</span>'; |
| 786 |
} |
| 787 |
// calendar |
| 788 |
if ($this->showCalendar) { |
| 789 |
$locale = 'en'; |
| 790 |
if (!empty($_SESSION['language'])) { |
| 791 |
$sessionLanguage = $_SESSION['language']; |
| 792 |
$sessionLanguage = str_replace('.utf8', '', $sessionLanguage); |
| 793 |
if ($sessionLanguage === 'zh_TW') { |
| 794 |
$locale = 'zh_tw'; |
| 795 |
} |
| 796 |
else { |
| 797 |
$sessionLanguageParts = explode('_', $sessionLanguage); |
| 798 |
$locale = $sessionLanguageParts[0]; |
| 799 |
} |
| 800 |
} |
| 801 |
$calendarWithTime = $this->calendarFormatWithTime ? "enableTime: true, " : ""; |
| 802 |
$calendarWithSeconds = $this->calendarFormatWithSeconds ? "enableSeconds: true, " : ""; |
| 803 |
echo '<script type="text/javascript"> |
| 804 |
flatpickr("#' . $this->fieldName . '", { |
| 805 |
dateFormat: "' . $this->calendarFormat . '", |
| 806 |
hourIncrement: 1, |
| 807 |
minuteIncrement: 1, |
| 808 |
time_24hr: true, |
| 809 |
' . $calendarWithTime . $calendarWithSeconds . ' |
| 810 |
locale: "' . $locale . '" |
| 811 |
}); |
| 812 |
</script> |
| 813 |
'; |
| 814 |
} |
| 815 |
// check value against reference field |
| 816 |
if ($this->sameValueFieldID != null) { |
| 817 |
echo '<script type="text/javascript"> |
| 818 |
checkFieldsHaveSameValues("' . $this->fieldName . '", "' . $this->sameValueFieldID . '"); |
| 819 |
</script> |
| 820 |
'; |
| 821 |
} |
| 822 |
if ($this->checkPasswordStrength) { |
| 823 |
$query = '?admin=1'; |
| 824 |
if (isSelfService()) { |
| 825 |
$query = '?selfservice=1'; |
| 826 |
} |
| 827 |
$ajaxPath = "../templates/misc/ajax.php"; |
| 828 |
if (is_file("../../templates/misc/ajax.php")) { |
| 829 |
$ajaxPath = "../../templates/misc/ajax.php"; |
| 830 |
} |
| 831 |
elseif (is_file("../../../templates/misc/ajax.php")) { |
| 832 |
$ajaxPath = "../../../templates/misc/ajax.php"; |
| 833 |
} |
| 834 |
$ajaxPath .= $query; |
| 835 |
echo '<script type="text/javascript"> |
| 836 |
checkPasswordStrength("' . $this->fieldName . '", "' . $ajaxPath . '", "' . getSecurityTokenName() . '", "' . getSecurityTokenValue() . '"); |
| 837 |
</script> |
| 838 |
'; |
| 839 |
} |
| 840 |
if ($this->transient) { |
| 841 |
return []; |
| 842 |
} |
| 843 |
if ($this->obfuscate) { |
| 844 |
return [$this->fieldName => 'text_obfuscated']; |
| 845 |
} |
| 846 |
else { |
| 847 |
return [$this->fieldName => 'text']; |
| 848 |
} |
| 849 |
} |
| 850 |
|
| 851 |
/** |
| 852 |
* Sets the maximum field length. |
| 853 |
* |
| 854 |
* @param int|null $fieldMaxLength length |
| 855 |
*/ |
| 856 |
public function setFieldMaxLength(?int $fieldMaxLength): void { |
| 857 |
$this->fieldMaxLength = $fieldMaxLength; |
| 858 |
} |
| 859 |
|
| 860 |
/** |
| 861 |
* Sets the field size (default is 30). |
| 862 |
* |
| 863 |
* @param int|null $fieldSize size |
| 864 |
*/ |
| 865 |
public function setFieldSize(?int $fieldSize): void { |
| 866 |
$this->fieldSize = $fieldSize; |
| 867 |
} |
| 868 |
|
| 869 |
/** |
| 870 |
* Specifies if this is a password field. |
| 871 |
* |
| 872 |
* @param bool $isPassword password field |
| 873 |
* @param bool $checkStrength check if matches password policy (default: false) |
| 874 |
* @param bool $disableAutoFill prevent autofilling by browser |
| 875 |
*/ |
| 876 |
public function setIsPassword(bool $isPassword, bool $checkStrength = false, bool $disableAutoFill = false): void { |
| 877 |
$this->isPassword = $isPassword; |
| 878 |
$this->checkPasswordStrength = $checkStrength; |
| 879 |
$this->disableAutoFill = $disableAutoFill; |
| 880 |
} |
| 881 |
|
| 882 |
/** |
| 883 |
* Specifies if this component is enabled and accepts user modification. |
| 884 |
* |
| 885 |
* @param bool $isEnabled enabled if true |
| 886 |
*/ |
| 887 |
public function setIsEnabled(bool $isEnabled): void { |
| 888 |
$this->isEnabled = $isEnabled; |
| 889 |
} |
| 890 |
|
| 891 |
/** |
| 892 |
* Specifies if the value should be saved in obfuscated form (e.g. self-service profile). |
| 893 |
* |
| 894 |
* @param bool $obfuscate obfuscate value |
| 895 |
*/ |
| 896 |
public function setObfuscate(bool $obfuscate): void { |
| 897 |
$this->obfuscate = $obfuscate; |
| 898 |
} |
| 899 |
|
| 900 |
/** |
| 901 |
* Specifies that the value should not be automatically saved when used in self-service or server profile (default: false). |
| 902 |
* |
| 903 |
* @param bool $transient transient field |
| 904 |
*/ |
| 905 |
public function setTransient(bool $transient): void { |
| 906 |
$this->transient = $transient; |
| 907 |
} |
| 908 |
|
| 909 |
/** |
| 910 |
* Specifies if the input field is required. |
| 911 |
* |
| 912 |
* @param bool $required required |
| 913 |
*/ |
| 914 |
public function setRequired(bool $required): void { |
| 915 |
$this->required = $required; |
| 916 |
} |
| 917 |
|
| 918 |
/** |
| 919 |
* Sets the field as number field with minimum and maximum values. |
| 920 |
* |
| 921 |
* @param int $minimum minimum |
| 922 |
* @param int|null $maximum maximum |
| 923 |
* @param int $step step value |
| 924 |
*/ |
| 925 |
public function setMinimumAndMaximumNumber(int $minimum = 0, ?int $maximum = null, int $step = 1): void { |
| 926 |
$this->minValue = $minimum; |
| 927 |
$this->maxValue = $maximum; |
| 928 |
$this->stepValue = $step; |
| 929 |
} |
| 930 |
|
| 931 |
/** |
| 932 |
* Enables autocompletion for this input field. |
| 933 |
* |
| 934 |
* @param string[] $values list of values to suggest |
| 935 |
*/ |
| 936 |
public function enableAutocompletion(array $values): void { |
| 937 |
$this->autocomplete = true; |
| 938 |
$this->autocompleteValues = $values; |
| 939 |
} |
| 940 |
|
| 941 |
/** |
| 942 |
* Sets the JavaScript for the onKeyPress event. |
| 943 |
* |
| 944 |
* @param string $onKeyPress JavaScript code |
| 945 |
*/ |
| 946 |
public function setOnKeyPress(string $onKeyPress): void { |
| 947 |
$this->onKeyPress = $onKeyPress; |
| 948 |
} |
| 949 |
|
| 950 |
/** |
| 951 |
* Sets the JavaScript for the onKeyUp event. |
| 952 |
* |
| 953 |
* @param string $onKeyUp JavaScript code |
| 954 |
*/ |
| 955 |
public function setOnKeyUp(string $onKeyUp): void { |
| 956 |
$this->onKeyUp = $onKeyUp; |
| 957 |
} |
| 958 |
|
| 959 |
/** |
| 960 |
* Sets the JavaScript for the onInput event. |
| 961 |
* |
| 962 |
* @param string $onInput JavaScript code |
| 963 |
*/ |
| 964 |
public function setOnInput(string $onInput): void { |
| 965 |
$this->onInput = $onInput; |
| 966 |
} |
| 967 |
|
| 968 |
/** |
| 969 |
* Shows a calendar when the field is selected. |
| 970 |
* |
| 971 |
* @param string $format calendar format (e.g. "Y-m-d" or "Y-m-d H:i:S") |
| 972 |
* @param bool $withTime activate time selection (default: false) |
| 973 |
* @param bool $withSeconds show seconds (default: false) |
| 974 |
*/ |
| 975 |
public function showCalendar(string $format, bool $withTime = false, bool $withSeconds = false): void { |
| 976 |
$this->showCalendar = true; |
| 977 |
$this->calendarFormatWithTime = $withTime; |
| 978 |
$this->calendarFormatWithSeconds = $withSeconds; |
| 979 |
$format = str_replace('yy', 'Y', $format); |
| 980 |
$format = str_replace('dd', 'd', $format); |
| 981 |
$format = str_replace('mm', 'm', $format); |
| 982 |
$this->calendarFormat = str_replace('\\', '\\\\', $format); |
| 983 |
} |
| 984 |
|
| 985 |
/** |
| 986 |
* Shows a DN selection next to input field. |
| 987 |
*/ |
| 988 |
public function showDnSelection(): void { |
| 989 |
$this->showDnSelection = true; |
| 990 |
} |
| 991 |
|
| 992 |
/** |
| 993 |
* Sets the title for the input field. |
| 994 |
* |
| 995 |
* @param string $title title value |
| 996 |
*/ |
| 997 |
public function setTitle(string $title): void { |
| 998 |
$this->title = htmlspecialchars($title); |
| 999 |
} |
| 1000 |
|
| 1001 |
/** |
| 1002 |
* Specifies the ID of a second field that must have the same value as this field. |
| 1003 |
* This field is marked red if different or green if equal. |
| 1004 |
* |
| 1005 |
* @param string $sameValueFieldID ID of reference field |
| 1006 |
*/ |
| 1007 |
public function setSameValueFieldID(string $sameValueFieldID): void { |
| 1008 |
$this->sameValueFieldID = $sameValueFieldID; |
| 1009 |
} |
| 1010 |
|
| 1011 |
/** |
| 1012 |
* Turns this field into a live filter for a select box. |
| 1013 |
* Cannot be used together with setOnKeyUp(). |
| 1014 |
* |
| 1015 |
* @param string $name select box name |
| 1016 |
*/ |
| 1017 |
public function filterSelectBox(string $name): void { |
| 1018 |
$this->setOnKeyUp('window.lam.filterSelect.activate(\'' . $this->fieldName . '\', \'' . $name . '\', event);'); |
| 1019 |
} |
| 1020 |
|
| 1021 |
/** |
| 1022 |
* Returns if the field content should be auto-trimmed (remove spaces at start/end). |
| 1023 |
* |
| 1024 |
* @return bool auto-trim input |
| 1025 |
*/ |
| 1026 |
protected function isAutoTrim(): bool { |
| 1027 |
return $this->autoTrim && !$this->isPassword; |
| 1028 |
} |
| 1029 |
|
| 1030 |
public function disableAutoTrim(): void { |
| 1031 |
$this->autoTrim = false; |
| 1032 |
} |
| 1033 |
|
| 1034 |
/** |
| 1035 |
* Sets the element ID. |
| 1036 |
* |
| 1037 |
* @param string $id id |
| 1038 |
*/ |
| 1039 |
public function setId(string $id): void { |
| 1040 |
$this->id = $id; |
| 1041 |
} |
| 1042 |
|
| 1043 |
/** |
| 1044 |
* Sets the input type. |
| 1045 |
* |
| 1046 |
* @param string $type type (e.g. number) |
| 1047 |
*/ |
| 1048 |
public function setType(string $type): void { |
| 1049 |
$this->type = $type; |
| 1050 |
} |
| 1051 |
|
| 1052 |
/** |
| 1053 |
* Sets the validation pattern. |
| 1054 |
* |
| 1055 |
* @param string $pattern pattern (e.g. "[0-9]{3}") |
| 1056 |
*/ |
| 1057 |
public function setValidationPattern(string $pattern): void { |
| 1058 |
$this->validationPattern = $pattern; |
| 1059 |
} |
| 1060 |
|
| 1061 |
/** |
| 1062 |
* Sets the step value for number fields. |
| 1063 |
* |
| 1064 |
* @param int $step step value (e.g. 1) |
| 1065 |
*/ |
| 1066 |
public function setStepValue(int $step): void { |
| 1067 |
$this->stepValue = $step; |
| 1068 |
} |
| 1069 |
|
| 1070 |
} |
| 1071 |
|
| 1072 |
/** |
| 1073 |
* Renders a help link. |
| 1074 |
* |
| 1075 |
* @package metaHTML |
| 1076 |
*/ |
| 1077 |
class htmlHelpLink extends htmlElement { |
| 1078 |
|
| 1079 |
/** help ID */ |
| 1080 |
private string $helpID; |
| 1081 |
/** module name if it should be forced */ |
| 1082 |
private ?string $module; |
| 1083 |
|
| 1084 |
/** |
| 1085 |
* Constructor |
| 1086 |
* |
| 1087 |
* @param string $helpID help ID |
| 1088 |
* @param string|null $module module name (optional, only if value from generateHTML() should be overwritten) |
| 1089 |
*/ |
| 1090 |
public function __construct(string $helpID, ?string $module = null) { |
| 1091 |
$this->helpID = $helpID; |
| 1092 |
$this->module = $module; |
| 1093 |
} |
| 1094 |
|
| 1095 |
/** |
| 1096 |
* {@inheritDoc} |
| 1097 |
*/ |
| 1098 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 1099 |
// overwrite module if needed |
| 1100 |
if ($this->module != null) { |
| 1101 |
$module = $this->module; |
| 1102 |
} |
| 1103 |
// print link |
| 1104 |
$helpEntry = getHelp($module, $this->helpID); |
| 1105 |
if (empty($helpEntry)) { |
| 1106 |
return []; |
| 1107 |
} |
| 1108 |
printHelpLink($helpEntry, $this->helpID, $module, $this->cssClasses); |
| 1109 |
return []; |
| 1110 |
} |
| 1111 |
|
| 1112 |
} |
| 1113 |
|
| 1114 |
/** |
| 1115 |
* Simple button. |
| 1116 |
* |
| 1117 |
* @package metaHTML |
| 1118 |
*/ |
| 1119 |
class htmlButton extends htmlElement { |
| 1120 |
|
| 1121 |
/** button name */ |
| 1122 |
protected string $name; |
| 1123 |
/** button text or image */ |
| 1124 |
protected string $value; |
| 1125 |
/** image button or text button */ |
| 1126 |
protected bool $isImageButton; |
| 1127 |
/** title */ |
| 1128 |
private ?string $title = null; |
| 1129 |
/** enabled or disabled */ |
| 1130 |
private bool $isEnabled = true; |
| 1131 |
/** onclick event */ |
| 1132 |
private ?string $onClick = null; |
| 1133 |
/** button type (default: "submit" if no onClick and "button" with onClick) */ |
| 1134 |
private ?string $type = null; |
| 1135 |
/** disable form validation */ |
| 1136 |
private bool $noFormValidation = false; |
| 1137 |
|
| 1138 |
/** |
| 1139 |
* Constructor. |
| 1140 |
* |
| 1141 |
* @param string $name button name |
| 1142 |
* @param string $value button text or image (16x16px, relative to graphics folder) |
| 1143 |
* @param bool $isImageButton image or text button (default text) |
| 1144 |
*/ |
| 1145 |
public function __construct(string $name, string $value, bool $isImageButton = false) { |
| 1146 |
$this->name = htmlspecialchars($name); |
| 1147 |
$this->value = htmlspecialchars($value); |
| 1148 |
$this->isImageButton = $isImageButton; |
| 1149 |
} |
| 1150 |
|
| 1151 |
/** |
| 1152 |
* {@inheritDoc} |
| 1153 |
*/ |
| 1154 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 1155 |
if ($restricted) { |
| 1156 |
// no buttons in restricted mode |
| 1157 |
logNewMessage(LOG_ERR, 'Meta HTML: Requested button in restricted mode.'); |
| 1158 |
return []; |
| 1159 |
} |
| 1160 |
$style = ''; |
| 1161 |
$classList = $this->cssClasses; |
| 1162 |
$class = ''; |
| 1163 |
$title = ''; |
| 1164 |
$name = ' name="' . $this->name . '"'; |
| 1165 |
// image button |
| 1166 |
if ($this->isImageButton) { |
| 1167 |
$classList[] = 'smallImageButton'; |
| 1168 |
$classList[] = 'align-middle'; |
| 1169 |
$style = ' style="background-image: url(../../graphics/' . $this->value . ');"'; |
| 1170 |
} |
| 1171 |
// button with text and icon |
| 1172 |
else { |
| 1173 |
$classList[] = 'margin5'; |
| 1174 |
} |
| 1175 |
$class = ' class="' . implode(' ', $classList) . '"'; |
| 1176 |
if ($this->title != null) { |
| 1177 |
$title = ' title="' . $this->title . '"'; |
| 1178 |
} |
| 1179 |
$disabled = ''; |
| 1180 |
if (!$this->isEnabled) { |
| 1181 |
$disabled = ' disabled'; |
| 1182 |
} |
| 1183 |
$noFormValidation = ''; |
| 1184 |
if ($this->noFormValidation) { |
| 1185 |
$noFormValidation = ' formnovalidate="formnovalidate"'; |
| 1186 |
} |
| 1187 |
$type = $this->type === null ? ' type="submit"' : ' type="' . $this->type . '"'; |
| 1188 |
$onClick = ''; |
| 1189 |
if ($this->onClick !== null) { |
| 1190 |
if ($this->type === null) { |
| 1191 |
$type = ' type="button"'; |
| 1192 |
} |
| 1193 |
$onClick = ' onclick="' . $this->onClick . '"'; |
| 1194 |
} |
| 1195 |
$id = ' id="btn_' . preg_replace('/[^a-zA-Z0-9_-]/', '', $this->name) . '"'; |
| 1196 |
if ($this->isImageButton) { |
| 1197 |
echo '<input type="submit" ' . $id . ' value=" "' . $name . $onClick . $style . $class |
| 1198 |
. $title . $disabled . $noFormValidation . $this->getDataAttributesAsString() . '>'; |
| 1199 |
} |
| 1200 |
else { |
| 1201 |
echo '<button' . $id . $name . $type . $onClick . $style . $class . $title . $disabled |
| 1202 |
. $noFormValidation . $this->getDataAttributesAsString() . '>' . $this->value . '</button>'; |
| 1203 |
} |
| 1204 |
return [$this->name => 'submit']; |
| 1205 |
} |
| 1206 |
|
| 1207 |
/** |
| 1208 |
* Sets the button title (tooltip). |
| 1209 |
* |
| 1210 |
* @param string|null $title title |
| 1211 |
*/ |
| 1212 |
public function setTitle(?string $title): void { |
| 1213 |
if ($title !== null) { |
| 1214 |
$this->title = htmlspecialchars($title); |
| 1215 |
} |
| 1216 |
} |
| 1217 |
|
| 1218 |
/** |
| 1219 |
* Specifies if this component is enabled and accepts user modification. |
| 1220 |
* |
| 1221 |
* @param bool $isEnabled enabled if true |
| 1222 |
*/ |
| 1223 |
public function setIsEnabled(bool $isEnabled): void { |
| 1224 |
$this->isEnabled = $isEnabled; |
| 1225 |
} |
| 1226 |
|
| 1227 |
/** |
| 1228 |
* Sets the onclick event code. |
| 1229 |
* This makes this button a simple button that does not submit a form. |
| 1230 |
* |
| 1231 |
* @param string $onClick JS code |
| 1232 |
*/ |
| 1233 |
public function setOnClick(string $onClick): void { |
| 1234 |
$this->onClick = $onClick; |
| 1235 |
} |
| 1236 |
|
| 1237 |
/** |
| 1238 |
* Allows to override the default button type ("submit" if no onClick and "button" with onClick). |
| 1239 |
* |
| 1240 |
* @param string $type type (e.g. button) |
| 1241 |
*/ |
| 1242 |
public function setType(string $type): void { |
| 1243 |
$this->type = $type; |
| 1244 |
} |
| 1245 |
|
| 1246 |
/** |
| 1247 |
* Disables form validation (e.g. for cancel buttons). |
| 1248 |
*/ |
| 1249 |
public function disableFormValidation(): void { |
| 1250 |
$this->noFormValidation = true; |
| 1251 |
} |
| 1252 |
|
| 1253 |
} |
| 1254 |
|
| 1255 |
/** |
| 1256 |
* Prints a button for the account pages. |
| 1257 |
* |
| 1258 |
* @package metaHTML |
| 1259 |
*/ |
| 1260 |
class htmlAccountPageButton extends htmlButton { |
| 1261 |
|
| 1262 |
/** |
| 1263 |
* Constructor |
| 1264 |
* |
| 1265 |
* @param string $targetModule module name which renders next page |
| 1266 |
* @param string $targetPage name of next page |
| 1267 |
* @param string $identifier identifier for button |
| 1268 |
* @param string $value button text or image (16x16px, relative to graphics folder) |
| 1269 |
* @param bool $isImageButton image or text button (default text) |
| 1270 |
* @param string|null $title title to show |
| 1271 |
*/ |
| 1272 |
public function __construct(string $targetModule, string $targetPage, string $identifier, string $value, bool $isImageButton = false, ?string $title = null) { |
| 1273 |
parent::__construct('form_subpage_' . $targetModule . '_' . $targetPage . '_' . $identifier, $value, $isImageButton); |
| 1274 |
if ($title !== null) { |
| 1275 |
$this->setTitle($title); |
| 1276 |
} |
| 1277 |
} |
| 1278 |
|
| 1279 |
} |
| 1280 |
|
| 1281 |
/** |
| 1282 |
* Represents a select box. |
| 1283 |
* |
| 1284 |
* @package metaHTML |
| 1285 |
*/ |
| 1286 |
class htmlSelect extends htmlElement { |
| 1287 |
|
| 1288 |
/** name of select field */ |
| 1289 |
protected string $name; |
| 1290 |
/** size */ |
| 1291 |
private string $size; |
| 1292 |
/** allows multi-selection */ |
| 1293 |
private bool $multiSelect = false; |
| 1294 |
/** @var string[]|array<string, string>|array<string, string[]|array<string, string>> $elements elements */ |
| 1295 |
private array $elements; |
| 1296 |
/** @var string[] $selectedElements selected elements */ |
| 1297 |
private array $selectedElements = []; |
| 1298 |
/** descriptive elements */ |
| 1299 |
private bool $hasDescriptiveElements = false; |
| 1300 |
/** contains optgroups */ |
| 1301 |
private bool $containsOptgroups = false; |
| 1302 |
/** sorting enabled */ |
| 1303 |
private bool $sortElements = true; |
| 1304 |
/** right to left text direction */ |
| 1305 |
private bool $rightToLeftTextDirection = false; |
| 1306 |
/** enabled or disabled */ |
| 1307 |
private bool $isEnabled = true; |
| 1308 |
/** width of input element */ |
| 1309 |
private string $width = ''; |
| 1310 |
/** transform select boxes with one element to text */ |
| 1311 |
private bool $transformSingleSelect = true; |
| 1312 |
/** onchange event */ |
| 1313 |
private ?string $onchangeEvent = null; |
| 1314 |
/** indicates that this field should not automatically be saved in the self-service or server profile */ |
| 1315 |
private bool $transient = false; |
| 1316 |
/** @var array<string, string[]> $tableRowsToHide list of enclosing table rows to hide when checked */ |
| 1317 |
protected array $tableRowsToHide = []; |
| 1318 |
/** @var array<string, string[]> $tableRowsToShow list of enclosing table rows to show when checked */ |
| 1319 |
protected array $tableRowsToShow = []; |
| 1320 |
/** dynamic scrolling */ |
| 1321 |
private bool $dynamicScrolling = false; |
| 1322 |
/** @var array<string, string> $optionCssClasses CSS classes for values */ |
| 1323 |
private array $optionCssClasses = []; |
| 1324 |
|
| 1325 |
/** |
| 1326 |
* Constructor. |
| 1327 |
* |
| 1328 |
* <br>Examples: |
| 1329 |
* <br> |
| 1330 |
* <br>$select = new htmlSelect('myName', array('value1', 'value2'), array('value1')); |
| 1331 |
* <br> |
| 1332 |
* <br>$select = new htmlSelect('myName', array('label1' => 'value1', 'label2' => 'value2'), array('value1')); |
| 1333 |
* <br>$select->setHasDescriptiveElements(true); |
| 1334 |
* <br> |
| 1335 |
* <br>$select = new htmlSelect('myName', array('optgroupLabel' => array('value1', 'value2')), array('value1')); |
| 1336 |
* <br>$select->setHasDescriptiveElements(true); |
| 1337 |
* <br>$select->setContainsOptgroups(true); |
| 1338 |
* |
| 1339 |
* @param string $name element name |
| 1340 |
* @param string[]|array<string, string>|array<string, string[]|array<string, string>> $elements list of elements array(label => value) or array(value1, value2) or array('optgroup' => array(...)) |
| 1341 |
* @param string[] $selectedElements list of selected elements (optional, default none) |
| 1342 |
* @param int $size size (optional, default = 1) |
| 1343 |
*/ |
| 1344 |
public function __construct(string $name, array $elements, array $selectedElements = [], int $size = 1) { |
| 1345 |
$this->name = htmlspecialchars($name); |
| 1346 |
$this->elements = $elements; |
| 1347 |
if ($selectedElements != null) { |
| 1348 |
$this->selectedElements = $selectedElements; |
| 1349 |
} |
| 1350 |
$this->size = htmlspecialchars((string) $size); |
| 1351 |
} |
| 1352 |
|
| 1353 |
/** |
| 1354 |
* {@inheritDoc} |
| 1355 |
*/ |
| 1356 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 1357 |
if (isset($values[$this->name])) { |
| 1358 |
$this->selectedElements = $values[$this->name]; |
| 1359 |
} |
| 1360 |
$multi = ''; |
| 1361 |
$name = ' name="' . $this->name . '" id="' . $this->name . '"'; |
| 1362 |
if ($this->multiSelect) { |
| 1363 |
$multi = ' multiple'; |
| 1364 |
$name = ' name="' . $this->name . '[]" id="' . $this->name . '"'; |
| 1365 |
} |
| 1366 |
$size = ' size="' . $this->size . '"'; |
| 1367 |
$classList = $this->cssClasses; |
| 1368 |
if ($this->rightToLeftTextDirection) { |
| 1369 |
$classList[] = 'rightToLeftText'; |
| 1370 |
} |
| 1371 |
$class = ' class="' . implode(' ', $classList) . '"'; |
| 1372 |
$disabled = ''; |
| 1373 |
if (!$this->isEnabled) { |
| 1374 |
$disabled = ' disabled'; |
| 1375 |
} |
| 1376 |
$style = ''; |
| 1377 |
if ($this->width !== '') { |
| 1378 |
$style = ' style="width: ' . $this->width . '"'; |
| 1379 |
} |
| 1380 |
$onchange = ''; |
| 1381 |
if ($this->onchangeEvent != null) { |
| 1382 |
$onchange = $this->onchangeEvent; |
| 1383 |
} |
| 1384 |
if (($this->tableRowsToHide != null) || ($this->tableRowsToShow != null)) { |
| 1385 |
$this->printCodeForShowHideTableRows($onchange); |
| 1386 |
} |
| 1387 |
if ($onchange !== '') { |
| 1388 |
$onchange = ' onchange="' . $onchange . '"'; |
| 1389 |
} |
| 1390 |
// hide select boxes that contain less than 2 elements |
| 1391 |
if ((count($this->elements) < 2) && !$this->multiSelect && !$this->containsOptgroups && $this->transformSingleSelect) { |
| 1392 |
echo '<div class="hidden">'; |
| 1393 |
} |
| 1394 |
// print select box |
| 1395 |
echo '<select' . $this->getDataAttributesAsString() . $this->getAccessibilityMarkup() . $class . $style |
| 1396 |
. $name . $size . $multi . $disabled . $onchange . ">\n"; |
| 1397 |
if ($this->containsOptgroups) { |
| 1398 |
foreach ($this->elements as $label => $elements) { |
| 1399 |
if (count($elements) > 0) { |
| 1400 |
echo '<optgroup label="' . $label . '">'; |
| 1401 |
$this->printOptionsHTML($elements); |
| 1402 |
echo '</optgroup>'; |
| 1403 |
} |
| 1404 |
} |
| 1405 |
} |
| 1406 |
else { |
| 1407 |
$this->printOptionsHTML($this->elements); |
| 1408 |
} |
| 1409 |
echo "</select>\n"; |
| 1410 |
// if select box has only one element then show it as text |
| 1411 |
if ((count($this->elements) < 2) && !$this->multiSelect && !$this->containsOptgroups && $this->transformSingleSelect) { |
| 1412 |
echo '</div>'; |
| 1413 |
if (count($this->elements) === 1) { |
| 1414 |
echo ' '; |
| 1415 |
if ($this->hasDescriptiveElements) { |
| 1416 |
$keys = array_keys($this->elements); |
| 1417 |
echo $keys[0]; |
| 1418 |
} |
| 1419 |
else { |
| 1420 |
echo $this->elements[0]; |
| 1421 |
} |
| 1422 |
} |
| 1423 |
} |
| 1424 |
if ($this->transient) { |
| 1425 |
return []; |
| 1426 |
} |
| 1427 |
if ($this->multiSelect) { |
| 1428 |
return [$this->name => 'multiselect']; |
| 1429 |
} |
| 1430 |
else { |
| 1431 |
return [$this->name => 'select']; |
| 1432 |
} |
| 1433 |
} |
| 1434 |
|
| 1435 |
/** |
| 1436 |
* Prints the HTML code of the option tags. |
| 1437 |
* |
| 1438 |
* @param array<string, string> $elements list of options |
| 1439 |
*/ |
| 1440 |
private function printOptionsHTML(array $elements): void { |
| 1441 |
if ($this->dynamicScrolling) { |
| 1442 |
echo "<option value=\"#\">#</option>\n"; |
| 1443 |
return; |
| 1444 |
} |
| 1445 |
// sorting |
| 1446 |
if ($this->sortElements) { |
| 1447 |
if ($this->hasDescriptiveElements) { |
| 1448 |
$labels = array_keys($elements); |
| 1449 |
natcasesort($labels); |
| 1450 |
$newElements = []; |
| 1451 |
foreach ($labels as $label) { |
| 1452 |
$newElements[$label] = $elements[$label]; |
| 1453 |
} |
| 1454 |
$elements = $newElements; |
| 1455 |
} |
| 1456 |
else { |
| 1457 |
natcasesort($elements); |
| 1458 |
} |
| 1459 |
} |
| 1460 |
foreach ($elements as $key => $value) { |
| 1461 |
$selected = ''; |
| 1462 |
$optionClass = ''; |
| 1463 |
if (isset($this->optionCssClasses[$value])) { |
| 1464 |
$optionClass = 'class="' . $this->optionCssClasses[$value] . '"'; |
| 1465 |
} |
| 1466 |
if (in_array($value, $this->selectedElements) || (empty($this->selectedElements) && empty($value))) { |
| 1467 |
$selected = ' selected'; |
| 1468 |
} |
| 1469 |
if ($this->hasDescriptiveElements) { |
| 1470 |
echo "<option value=\"" . htmlspecialchars($value) . "\"$selected $optionClass>" . htmlspecialchars($key) . "</option>\n"; |
| 1471 |
} |
| 1472 |
else { |
| 1473 |
echo "<option$selected $optionClass>" . htmlspecialchars($value) . "</option>\n"; |
| 1474 |
} |
| 1475 |
} |
| 1476 |
} |
| 1477 |
|
| 1478 |
/** |
| 1479 |
* Specifies if the elements are just a simple list or an associative array (default: simple list). |
| 1480 |
* |
| 1481 |
* @param bool $hasDescriptiveElements activates descriptive elements |
| 1482 |
*/ |
| 1483 |
public function setHasDescriptiveElements(bool $hasDescriptiveElements): void { |
| 1484 |
$this->hasDescriptiveElements = $hasDescriptiveElements; |
| 1485 |
} |
| 1486 |
|
| 1487 |
/** |
| 1488 |
* Specifies if the elements are divided into optgroups. |
| 1489 |
* In this case the provided options are an array where the key is the optgroup label and the value is an array containing the options for the optgroup. |
| 1490 |
* |
| 1491 |
* @param bool $containsOptgroups activates optgroups |
| 1492 |
*/ |
| 1493 |
public function setContainsOptgroups(bool $containsOptgroups): void { |
| 1494 |
$this->containsOptgroups = $containsOptgroups; |
| 1495 |
} |
| 1496 |
|
| 1497 |
/** |
| 1498 |
* Specifies if multi-selection is enabled (default: disabled). |
| 1499 |
* |
| 1500 |
* @param bool $multiSelect allows multi-selection |
| 1501 |
*/ |
| 1502 |
public function setMultiSelect(bool $multiSelect): void { |
| 1503 |
$this->multiSelect = $multiSelect; |
| 1504 |
} |
| 1505 |
|
| 1506 |
/** |
| 1507 |
* Specifies if the elements should be sorted (default: sort). |
| 1508 |
* |
| 1509 |
* @param bool $sortElements sort elements |
| 1510 |
*/ |
| 1511 |
public function setSortElements(bool $sortElements): void { |
| 1512 |
$this->sortElements = $sortElements; |
| 1513 |
} |
| 1514 |
|
| 1515 |
/** |
| 1516 |
* Specifies if the text direction should be set to right to left. |
| 1517 |
* |
| 1518 |
* @param bool $rightToLeftTextDirection if true use right to left direction |
| 1519 |
*/ |
| 1520 |
public function setRightToLeftTextDirection(bool $rightToLeftTextDirection): void { |
| 1521 |
$this->rightToLeftTextDirection = $rightToLeftTextDirection; |
| 1522 |
} |
| 1523 |
|
| 1524 |
/** |
| 1525 |
* Specifies if this component is enabled and accepts user modification. |
| 1526 |
* |
| 1527 |
* @param bool $isEnabled enabled if true |
| 1528 |
*/ |
| 1529 |
public function setIsEnabled(bool $isEnabled): void { |
| 1530 |
$this->isEnabled = $isEnabled; |
| 1531 |
} |
| 1532 |
|
| 1533 |
/** |
| 1534 |
* Specifies the width of this selection box. |
| 1535 |
* |
| 1536 |
* @param string $width width (e.g. 20em) |
| 1537 |
*/ |
| 1538 |
public function setWidth(string $width): void { |
| 1539 |
$this->width = htmlspecialchars($width); |
| 1540 |
} |
| 1541 |
|
| 1542 |
/** |
| 1543 |
* Specifies if select boxes that contain only a single element should be transformed to a simple text field. |
| 1544 |
* |
| 1545 |
* @param bool $transformSingleSelect transform single options to text |
| 1546 |
*/ |
| 1547 |
public function setTransformSingleSelect(bool $transformSingleSelect): void { |
| 1548 |
$this->transformSingleSelect = $transformSingleSelect; |
| 1549 |
} |
| 1550 |
|
| 1551 |
/** |
| 1552 |
* Sets the JavaScript code for the onchange event. |
| 1553 |
* |
| 1554 |
* @param string $onchangeEvent onchange event code (e.g. myfunction();) |
| 1555 |
*/ |
| 1556 |
public function setOnchangeEvent(string $onchangeEvent): void { |
| 1557 |
$this->onchangeEvent = htmlspecialchars($onchangeEvent); |
| 1558 |
} |
| 1559 |
|
| 1560 |
/** |
| 1561 |
* Specifies that the value should not be automatically saved when used in self-service or server profile (default: false). |
| 1562 |
* |
| 1563 |
* @param bool $transient transient field |
| 1564 |
*/ |
| 1565 |
public function setTransient(bool $transient): void { |
| 1566 |
$this->transient = $transient; |
| 1567 |
} |
| 1568 |
|
| 1569 |
/** |
| 1570 |
* This will hide the given table rows when the select is changed to the specified value. |
| 1571 |
* The given IDs can be of any e.g. input element. Starting from this element |
| 1572 |
* the first parent "<tr>" element will be used to show/hide. |
| 1573 |
* <br> |
| 1574 |
* <br> |
| 1575 |
* <br>Example: <tr><td><input type="checkbox" id="mycheckbox"></td></tr> |
| 1576 |
* <br> Using "mycheckbox" will use this "tr" to hide/show. |
| 1577 |
* <br> |
| 1578 |
* <br> Example for $tableRowsToHide: |
| 1579 |
* <br> array('yes' => array('option1', 'option2'), 'no' => array('option3')) |
| 1580 |
* |
| 1581 |
* @param array<string, string[]> $tableRowsToHide array of select value => array of IDs of child elements to hide |
| 1582 |
*/ |
| 1583 |
public function setTableRowsToHide(array $tableRowsToHide): void { |
| 1584 |
$this->tableRowsToHide = $tableRowsToHide; |
| 1585 |
} |
| 1586 |
|
| 1587 |
/** |
| 1588 |
* This will show the given table rows when the select is changed to the specified value. |
| 1589 |
* The given IDs can be of any e.g. input element. Starting from this element |
| 1590 |
* the first parent "<tr>" element will be used to show/hide. |
| 1591 |
* <br> |
| 1592 |
* <br> |
| 1593 |
* <br>Example: <tr><td><input type="checkbox" id="mycheckbox"></td></tr> |
| 1594 |
* <br> Using "mycheckbox" will use this "tr" to hide/show. |
| 1595 |
* <br> |
| 1596 |
* <br> Example for $tableRowsToShow: |
| 1597 |
* <br> array('yes' => array('option1', 'option2'), 'no' => array('option3')) |
| 1598 |
* |
| 1599 |
* @param array<string, string[]> $tableRowsToShow array of select value => array of IDs of child elements to show |
| 1600 |
*/ |
| 1601 |
public function setTableRowsToShow(array $tableRowsToShow): void { |
| 1602 |
$this->tableRowsToShow = $tableRowsToShow; |
| 1603 |
} |
| 1604 |
|
| 1605 |
/** |
| 1606 |
* Creates the JavaScript code to hide/show table rows based on the select value. |
| 1607 |
* |
| 1608 |
* @param string $onChange onChange code |
| 1609 |
*/ |
| 1610 |
private function printCodeForShowHideTableRows(string &$onChange): void { |
| 1611 |
if ((count($this->tableRowsToHide) === 0) && (count($this->tableRowsToShow) === 0)) { |
| 1612 |
return; |
| 1613 |
} |
| 1614 |
$values = []; |
| 1615 |
if (!empty($this->tableRowsToHide)) { |
| 1616 |
$values = array_merge($values, array_keys($this->tableRowsToHide)); |
| 1617 |
} |
| 1618 |
if (!empty($this->tableRowsToShow)) { |
| 1619 |
$values = array_merge($values, array_keys($this->tableRowsToShow)); |
| 1620 |
} |
| 1621 |
$values = array_unique($values); |
| 1622 |
$selector = $this->getShowHideSelector(); |
| 1623 |
// build JavaScript to show/hide depending on fields |
| 1624 |
foreach ($values as $val) { |
| 1625 |
// build onChange listener |
| 1626 |
$onChange .= 'if (document.getElementById(\'' . $this->name . '\').value == \'' . $val . '\') {'; |
| 1627 |
if (isset($this->tableRowsToShow[$val])) { |
| 1628 |
for ($i = 0; $i < count($this->tableRowsToShow[$val]); $i++) { |
| 1629 |
$onChange .= 'document.getElementById(\'' . $this->tableRowsToShow[$val][$i] . '\')?.closest(\'' . $selector . '\').classList.remove(\'hidden\');'; |
| 1630 |
} |
| 1631 |
} |
| 1632 |
if (isset($this->tableRowsToHide[$val])) { |
| 1633 |
for ($i = 0; $i < count($this->tableRowsToHide[$val]); $i++) { |
| 1634 |
$onChange .= 'document.getElementById(\'' . $this->tableRowsToHide[$val][$i] . '\')?.closest(\'' . $selector . '\').classList.add(\'hidden\');'; |
| 1635 |
} |
| 1636 |
} |
| 1637 |
$onChange .= '};'; |
| 1638 |
} |
| 1639 |
// build script to set initial state |
| 1640 |
$script = '<script type="text/javascript">window.lam.utility.documentReady(function() {' . "\n"; |
| 1641 |
if (isset($this->tableRowsToShow[$this->selectedElements[0]])) { |
| 1642 |
for ($i = 0; $i < count($this->tableRowsToShow[$this->selectedElements[0]]); $i++) { |
| 1643 |
$classType = 'remove'; |
| 1644 |
$script .= 'document.getElementById(\'' . $this->tableRowsToShow[$this->selectedElements[0]][$i] . '\')?.closest(\'' . $selector . '\').classList.' . $classType . '(\'hidden\');' . "\n"; |
| 1645 |
} |
| 1646 |
} |
| 1647 |
if (isset($this->tableRowsToHide[$this->selectedElements[0]])) { |
| 1648 |
for ($i = 0; $i < count($this->tableRowsToHide[$this->selectedElements[0]]); $i++) { |
| 1649 |
$classType = 'add'; |
| 1650 |
$script .= 'document.getElementById(\'' . $this->tableRowsToHide[$this->selectedElements[0]][$i] . '\')?.closest(\'' . $selector . '\').classList.' . $classType . '(\'hidden\');' . "\n"; |
| 1651 |
} |
| 1652 |
} |
| 1653 |
$script .= '});</script>'; |
| 1654 |
echo $script; |
| 1655 |
} |
| 1656 |
|
| 1657 |
/** |
| 1658 |
* Returns the selector to use to find the show/hide elements. |
| 1659 |
* |
| 1660 |
* @return string selector |
| 1661 |
*/ |
| 1662 |
protected function getShowHideSelector(): string { |
| 1663 |
return 'tr'; |
| 1664 |
} |
| 1665 |
|
| 1666 |
/** |
| 1667 |
* Enable dynamic scrolling. This limits the number of select options to 10000 by dynamically adding/removing options. |
| 1668 |
* This will not be enabled when optgroups are used or the option size is less than 10000. |
| 1669 |
*/ |
| 1670 |
public function enableDynamicScrolling(): void { |
| 1671 |
// not possible for optgroups and smaller option lists |
| 1672 |
if ((count($this->elements) < 10000) || $this->containsOptgroups) { |
| 1673 |
return; |
| 1674 |
} |
| 1675 |
$this->dynamicScrolling = true; |
| 1676 |
$elementData = []; |
| 1677 |
$counter = 0; |
| 1678 |
foreach ($this->elements as $key => $value) { |
| 1679 |
$elementData[] = [ |
| 1680 |
'label' => $key, |
| 1681 |
'value' => $value, |
| 1682 |
'selected' => in_array($value, $this->selectedElements), |
| 1683 |
'index' => $counter]; |
| 1684 |
$counter++; |
| 1685 |
} |
| 1686 |
$this->addDataAttribute('dynamic-options', json_encode($elementData)); |
| 1687 |
$this->cssClasses[] = 'lam-dynamicOptions'; |
| 1688 |
} |
| 1689 |
|
| 1690 |
/** |
| 1691 |
* Sets CSS classes for option values. |
| 1692 |
* |
| 1693 |
* @param array<string, string> $optionCssClasses array('option value' => 'CSS class(es)') |
| 1694 |
*/ |
| 1695 |
public function setOptionCssClasses(array $optionCssClasses): void { |
| 1696 |
$this->optionCssClasses = $optionCssClasses; |
| 1697 |
} |
| 1698 |
|
| 1699 |
} |
| 1700 |
|
| 1701 |
|
| 1702 |
/** |
| 1703 |
* Represents a radio selection. |
| 1704 |
* |
| 1705 |
* @package metaHTML |
| 1706 |
*/ |
| 1707 |
class htmlRadio extends htmlElement { |
| 1708 |
|
| 1709 |
/** name of select field */ |
| 1710 |
private string $name; |
| 1711 |
/** @var array<string, string> $elements elements */ |
| 1712 |
private array $elements; |
| 1713 |
/** selected element */ |
| 1714 |
private ?string $selectedElement = null; |
| 1715 |
/** enabled or disabled */ |
| 1716 |
private bool $isEnabled = true; |
| 1717 |
/** on change code */ |
| 1718 |
private ?string $onchangeEvent = null; |
| 1719 |
/** @var array<string, string[]> $tableRowsToHide list of enclosing table rows to hide when checked */ |
| 1720 |
protected array $tableRowsToHide = []; |
| 1721 |
/** @var array<string, string[]> $tableRowsToShow list of enclosing table rows to show when checked */ |
| 1722 |
protected array $tableRowsToShow = []; |
| 1723 |
|
| 1724 |
/** |
| 1725 |
* Constructor. |
| 1726 |
* |
| 1727 |
* <br>Examples: |
| 1728 |
* <br> |
| 1729 |
* <br>$radio = new htmlRadio('myName', array('label1' => 'value1', 'label2' => 'value2'), array('value1')); |
| 1730 |
* |
| 1731 |
* @param string $name element name |
| 1732 |
* @param array<string, string> $elements list of elements array(label => value) |
| 1733 |
* @param string|null $selectedElement value of selected element (optional, default none) |
| 1734 |
*/ |
| 1735 |
public function __construct(string $name, array $elements, ?string $selectedElement = null) { |
| 1736 |
$this->name = htmlspecialchars($name); |
| 1737 |
$this->elements = $elements; |
| 1738 |
if ($selectedElement != null) { |
| 1739 |
$this->selectedElement = $selectedElement; |
| 1740 |
} |
| 1741 |
} |
| 1742 |
|
| 1743 |
/** |
| 1744 |
* {@inheritDoc} |
| 1745 |
*/ |
| 1746 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 1747 |
if (isset($values[$this->name][0])) { |
| 1748 |
$this->selectedElement = $values[$this->name][0]; |
| 1749 |
} |
| 1750 |
$name = ' name="' . $this->name . '"'; |
| 1751 |
$disabled = ''; |
| 1752 |
if (!$this->isEnabled) { |
| 1753 |
$disabled = ' disabled'; |
| 1754 |
} |
| 1755 |
if (($this->tableRowsToHide != null) || ($this->tableRowsToShow != null)) { |
| 1756 |
$this->printInitialState(); |
| 1757 |
} |
| 1758 |
// print radio list |
| 1759 |
$counter = 0; |
| 1760 |
foreach ($this->elements as $label => $value) { |
| 1761 |
$showHideOnchange = ''; |
| 1762 |
if (($this->tableRowsToHide != null) || ($this->tableRowsToShow != null)) { |
| 1763 |
$showHideOnchange = $this->getOnchangeCodeForShowHideTableRows($counter); |
| 1764 |
} |
| 1765 |
$onchange = ''; |
| 1766 |
if ($this->onchangeEvent != null) { |
| 1767 |
$onchange = ' onchange="' . $this->onchangeEvent . '"'; |
| 1768 |
} |
| 1769 |
elseif (!empty($showHideOnchange)) { |
| 1770 |
$onchange = ' onchange="' . $showHideOnchange . '"'; |
| 1771 |
} |
| 1772 |
echo '<div class="nowrap">'; |
| 1773 |
$selected = ''; |
| 1774 |
if ($value == $this->selectedElement) { |
| 1775 |
$selected = ' checked'; |
| 1776 |
} |
| 1777 |
echo '<input type="radio" id="' . $this->name . $counter . '"' . $name . $disabled . $selected . $onchange . ' value="' . $value . '"> '; |
| 1778 |
echo '<label for="' . $this->name . $counter . '">' . $label . '</label>'; |
| 1779 |
echo '</div>'; |
| 1780 |
$counter++; |
| 1781 |
} |
| 1782 |
return [$this->name => 'select']; |
| 1783 |
} |
| 1784 |
|
| 1785 |
/** |
| 1786 |
* Specifies if this component is enabled and accepts user modification. |
| 1787 |
* |
| 1788 |
* @param bool $isEnabled enabled if true |
| 1789 |
*/ |
| 1790 |
public function setIsEnabled(bool $isEnabled): void { |
| 1791 |
$this->isEnabled = $isEnabled; |
| 1792 |
} |
| 1793 |
|
| 1794 |
/** |
| 1795 |
* Sets the JavaScript code for the onchange event. |
| 1796 |
* |
| 1797 |
* @param string $onchangeEvent onchange event code (e.g. myfunction();) |
| 1798 |
*/ |
| 1799 |
public function setOnchangeEvent(string $onchangeEvent): void { |
| 1800 |
$this->onchangeEvent = htmlspecialchars($onchangeEvent); |
| 1801 |
} |
| 1802 |
|
| 1803 |
/** |
| 1804 |
* Returns the selector to use to find the show/hide elements. |
| 1805 |
* |
| 1806 |
* @return string selector |
| 1807 |
*/ |
| 1808 |
protected function getShowHideSelector(): string { |
| 1809 |
return 'tr'; |
| 1810 |
} |
| 1811 |
|
| 1812 |
/** |
| 1813 |
* Creates the JavaScript code to hide/show table rows based on the select value. |
| 1814 |
* |
| 1815 |
* @param int $counter index |
| 1816 |
* @return string onChange code |
| 1817 |
*/ |
| 1818 |
private function getOnchangeCodeForShowHideTableRows(int $counter): string { |
| 1819 |
$onChange = ''; |
| 1820 |
if ((count($this->tableRowsToHide) === 0) && (count($this->tableRowsToShow) === 0)) { |
| 1821 |
return $onChange; |
| 1822 |
} |
| 1823 |
$values = []; |
| 1824 |
if (!empty($this->tableRowsToHide)) { |
| 1825 |
$values = array_merge($values, array_keys($this->tableRowsToHide)); |
| 1826 |
} |
| 1827 |
if (!empty($this->tableRowsToShow)) { |
| 1828 |
$values = array_merge($values, array_keys($this->tableRowsToShow)); |
| 1829 |
} |
| 1830 |
$values = array_unique($values); |
| 1831 |
$selector = $this->getShowHideSelector(); |
| 1832 |
// build Java script to show/hide depending fields |
| 1833 |
foreach ($values as $val) { |
| 1834 |
// build onChange listener |
| 1835 |
$onChange .= 'if (document.getElementById(\'' . $this->name . $counter . '\').value == \'' . $val . '\') {'; |
| 1836 |
if (isset($this->tableRowsToShow[$val])) { |
| 1837 |
for ($i = 0; $i < count($this->tableRowsToShow[$val]); $i++) { |
| 1838 |
$onChange .= 'document.getElementById(\'' . $this->tableRowsToShow[$val][$i] . '\')?.closest(\'' . $selector . '\').classList.remove(\'hidden\');'; |
| 1839 |
} |
| 1840 |
} |
| 1841 |
if (isset($this->tableRowsToHide[$val])) { |
| 1842 |
for ($i = 0; $i < count($this->tableRowsToHide[$val]); $i++) { |
| 1843 |
$onChange .= 'document.getElementById(\'' . $this->tableRowsToHide[$val][$i] . '\')?.closest(\'' . $selector . '\').classList.add(\'hidden\');'; |
| 1844 |
} |
| 1845 |
} |
| 1846 |
$onChange .= '};'; |
| 1847 |
} |
| 1848 |
return $onChange; |
| 1849 |
} |
| 1850 |
|
| 1851 |
private function printInitialState(): void { |
| 1852 |
$selector = $this->getShowHideSelector(); |
| 1853 |
// build script to set initial state |
| 1854 |
$script = '<script type="text/javascript">window.lam.utility.documentReady(function() {' . "\n"; |
| 1855 |
if (isset($this->tableRowsToShow[$this->selectedElement])) { |
| 1856 |
for ($i = 0; $i < count($this->tableRowsToShow[$this->selectedElement]); $i++) { |
| 1857 |
$script .= 'document.getElementById(\'' . $this->tableRowsToShow[$this->selectedElement][$i] . '\')?.closest(\'' . $selector . '\').classList.remove(\'hidden\');' . "\n"; |
| 1858 |
} |
| 1859 |
} |
| 1860 |
if (isset($this->tableRowsToHide[$this->selectedElement])) { |
| 1861 |
for ($i = 0; $i < count($this->tableRowsToHide[$this->selectedElement]); $i++) { |
| 1862 |
$script .= 'document.getElementById(\'' . $this->tableRowsToHide[$this->selectedElement][$i] . '\')?.closest(\'' . $selector . '\').classList.add(\'hidden\');' . "\n"; |
| 1863 |
} |
| 1864 |
} |
| 1865 |
$script .= '});</script>'; |
| 1866 |
echo $script; |
| 1867 |
} |
| 1868 |
|
| 1869 |
/** |
| 1870 |
* This will hide the given table rows when the radio is changed to the specified value. |
| 1871 |
* The given IDs can be of any e.g. input element. Starting from this element |
| 1872 |
* the first parent "<tr>" element will be used to show/hide. |
| 1873 |
* <br> |
| 1874 |
* <br> |
| 1875 |
* <br> Example for $tableRowsToHide: |
| 1876 |
* <br> array('val1' => array('option1', 'option2'), 'val2' => array('option3')) |
| 1877 |
* |
| 1878 |
* @param array<string, string[]> $tableRowsToHide array of select value => array of IDs of child elements to hide |
| 1879 |
*/ |
| 1880 |
public function setTableRowsToHide(array $tableRowsToHide): void { |
| 1881 |
$this->tableRowsToHide = $tableRowsToHide; |
| 1882 |
} |
| 1883 |
|
| 1884 |
/** |
| 1885 |
* This will show the given table rows when the radio is changed to the specified value. |
| 1886 |
* The given IDs can be of any e.g. input element. Starting from this element |
| 1887 |
* the first parent "<tr>" element will be used to show/hide. |
| 1888 |
* <br> |
| 1889 |
* <br> |
| 1890 |
* <br> Example for $tableRowsToShow: |
| 1891 |
* <br> array('val1' => array('option1', 'option2'), 'val2' => array('option3')) |
| 1892 |
* |
| 1893 |
* @param array<string, string[]> $tableRowsToShow array of select value => array of IDs of child elements to show |
| 1894 |
*/ |
| 1895 |
public function setTableRowsToShow(array $tableRowsToShow): void { |
| 1896 |
$this->tableRowsToShow = $tableRowsToShow; |
| 1897 |
} |
| 1898 |
|
| 1899 |
} |
| 1900 |
|
| 1901 |
/** |
| 1902 |
* Prints the text and escapes contained HTML code by default. |
| 1903 |
* |
| 1904 |
* @package metaHTML |
| 1905 |
*/ |
| 1906 |
class htmlOutputText extends htmlElement { |
| 1907 |
|
| 1908 |
/** the text to print */ |
| 1909 |
private string $string; |
| 1910 |
/** specifies if HTML code should be escaped */ |
| 1911 |
private bool $escapeHTML; |
| 1912 |
/** bold text */ |
| 1913 |
private bool $isBold = false; |
| 1914 |
/** mark as required */ |
| 1915 |
private bool $markAsRequired; |
| 1916 |
/** no wrap */ |
| 1917 |
private bool $noWrap = false; |
| 1918 |
/** preformatted */ |
| 1919 |
private bool $isPreformatted = false; |
| 1920 |
/** title */ |
| 1921 |
private ?string $title = null; |
| 1922 |
|
| 1923 |
/** |
| 1924 |
* Constructor. |
| 1925 |
* |
| 1926 |
* @param string $string output text |
| 1927 |
* @param bool $escapeHTML escape HTML code (default yes) |
| 1928 |
* @param bool $markAsRequired mark text like a required field |
| 1929 |
*/ |
| 1930 |
public function __construct(string $string, bool $escapeHTML = true, bool $markAsRequired = false) { |
| 1931 |
$this->string = $string; |
| 1932 |
$this->escapeHTML = $escapeHTML; |
| 1933 |
$this->markAsRequired = $markAsRequired; |
| 1934 |
} |
| 1935 |
|
| 1936 |
/** |
| 1937 |
* {@inheritDoc} |
| 1938 |
*/ |
| 1939 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 1940 |
$cssClasses = empty($this->cssClasses) ? '' : 'class="' . implode(' ', $this->cssClasses) . '"'; |
| 1941 |
if (!empty($this->title)) { |
| 1942 |
echo '<span title="' . $this->title . '">'; |
| 1943 |
} |
| 1944 |
if ($this->noWrap) { |
| 1945 |
echo "<div class=\"nowrap\">"; |
| 1946 |
} |
| 1947 |
if ($this->isBold) { |
| 1948 |
echo "<b>"; |
| 1949 |
} |
| 1950 |
if ($this->isPreformatted) { |
| 1951 |
echo "<pre $cssClasses>"; |
| 1952 |
} |
| 1953 |
elseif (!empty($cssClasses)) { |
| 1954 |
echo "<span $cssClasses>"; |
| 1955 |
} |
| 1956 |
if ($this->escapeHTML) { |
| 1957 |
echo htmlspecialchars($this->string); |
| 1958 |
} |
| 1959 |
else { |
| 1960 |
echo $this->string; |
| 1961 |
} |
| 1962 |
if ($this->markAsRequired) { |
| 1963 |
echo htmlGetRequiredMarker(); |
| 1964 |
} |
| 1965 |
if ($this->isPreformatted) { |
| 1966 |
echo "</pre>"; |
| 1967 |
} |
| 1968 |
elseif (!empty($cssClasses)) { |
| 1969 |
echo "</span>"; |
| 1970 |
} |
| 1971 |
if ($this->isBold) { |
| 1972 |
echo "</b>"; |
| 1973 |
} |
| 1974 |
if ($this->noWrap) { |
| 1975 |
echo "</div>"; |
| 1976 |
} |
| 1977 |
if (!empty($this->title)) { |
| 1978 |
echo "</span>"; |
| 1979 |
} |
| 1980 |
return []; |
| 1981 |
} |
| 1982 |
|
| 1983 |
/** |
| 1984 |
* Specifies if the whole text should be printed in bold. |
| 1985 |
* |
| 1986 |
* @param bool $isBold bold text |
| 1987 |
*/ |
| 1988 |
public function setIsBold(bool $isBold): void { |
| 1989 |
$this->isBold = $isBold; |
| 1990 |
} |
| 1991 |
|
| 1992 |
/** |
| 1993 |
* Adds a marker that indicates a required field. |
| 1994 |
* |
| 1995 |
* @param bool $markAsRequired add marker |
| 1996 |
*/ |
| 1997 |
public function setMarkAsRequired(bool $markAsRequired): void { |
| 1998 |
$this->markAsRequired = $markAsRequired; |
| 1999 |
} |
| 2000 |
|
| 2001 |
/** |
| 2002 |
* Specifies if word wrap is allowed for this text. |
| 2003 |
* |
| 2004 |
* @param bool $noWrap no wrapping if set to true (default false) |
| 2005 |
*/ |
| 2006 |
public function setNoWrap(bool $noWrap): void { |
| 2007 |
$this->noWrap = $noWrap; |
| 2008 |
} |
| 2009 |
|
| 2010 |
/** |
| 2011 |
* Sets if the text is preformatted. |
| 2012 |
* |
| 2013 |
* @param bool $preformatted is preformatted (default true) |
| 2014 |
*/ |
| 2015 |
public function setPreformatted(bool $preformatted = true): void { |
| 2016 |
$this->isPreformatted = $preformatted; |
| 2017 |
} |
| 2018 |
|
| 2019 |
/** |
| 2020 |
* Sets a title for this text. |
| 2021 |
* |
| 2022 |
* @param string|null $title title |
| 2023 |
*/ |
| 2024 |
public function setTitle(?string $title): void { |
| 2025 |
$this->title = $title; |
| 2026 |
} |
| 2027 |
|
| 2028 |
} |
| 2029 |
|
| 2030 |
/** |
| 2031 |
* Prints the HTML code for a checkbox. |
| 2032 |
* |
| 2033 |
* @package metaHTML |
| 2034 |
*/ |
| 2035 |
class htmlInputCheckbox extends htmlElement { |
| 2036 |
|
| 2037 |
/** unique name of input element */ |
| 2038 |
protected string $name; |
| 2039 |
/** value */ |
| 2040 |
protected bool $checked; |
| 2041 |
/** enabled or disabled */ |
| 2042 |
protected bool $isEnabled = true; |
| 2043 |
/** @var string[] $tableRowsToHide list of enclosing table rows to hide when checked */ |
| 2044 |
protected array $tableRowsToHide = []; |
| 2045 |
/** @var string[] $tableRowsToShow list of enclosing table rows to show when checked */ |
| 2046 |
protected array $tableRowsToShow = []; |
| 2047 |
/** indicates that this field should not automatically be saved in the self-service or server profile */ |
| 2048 |
private bool $transient = false; |
| 2049 |
/** @var string[] $elementsToEnable list of input elements to enable when checked */ |
| 2050 |
protected array $elementsToEnable = []; |
| 2051 |
/** @var string[] $elementsToDisable list of input elements to disable when checked */ |
| 2052 |
protected array $elementsToDisable = []; |
| 2053 |
/** onclick event code */ |
| 2054 |
private ?string $onClick = null; |
| 2055 |
/** title */ |
| 2056 |
private ?string $title = null; |
| 2057 |
|
| 2058 |
|
| 2059 |
/** |
| 2060 |
* Constructor. |
| 2061 |
* |
| 2062 |
* @param string $name unique name |
| 2063 |
* @param bool $checked checked |
| 2064 |
*/ |
| 2065 |
public function __construct(string $name, bool $checked) { |
| 2066 |
$this->name = htmlspecialchars($name); |
| 2067 |
$this->checked = $checked; |
| 2068 |
} |
| 2069 |
|
| 2070 |
/** |
| 2071 |
* {@inheritDoc} |
| 2072 |
*/ |
| 2073 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 2074 |
if (isset($values[$this->name])) { |
| 2075 |
$this->checked = ($values[$this->name][0] == 'true'); |
| 2076 |
} |
| 2077 |
$checked = ''; |
| 2078 |
if ($this->checked) { |
| 2079 |
$checked = ' checked'; |
| 2080 |
} |
| 2081 |
$title = ''; |
| 2082 |
if ($this->title !== null) { |
| 2083 |
$title = ' title="' . $this->title . '"'; |
| 2084 |
} |
| 2085 |
$disabled = ''; |
| 2086 |
if (!$this->isEnabled) { |
| 2087 |
$disabled = ' disabled'; |
| 2088 |
} |
| 2089 |
$classes = ' '; |
| 2090 |
if (!empty($this->cssClasses)) { |
| 2091 |
$classes = ' class="' . implode(' ', $this->cssClasses) . '"'; |
| 2092 |
} |
| 2093 |
// build Java script to show/hide depending fields |
| 2094 |
$onChange = ''; |
| 2095 |
$script = ''; |
| 2096 |
$selector = $this->getShowHideSelector(); |
| 2097 |
if ((count($this->tableRowsToShow) > 0) || (count($this->tableRowsToHide) > 0)) { |
| 2098 |
// build onChange listener |
| 2099 |
$onChange .= 'if (document.querySelector(\'#' . $this->name . ':checked\') !== null) {'; |
| 2100 |
for ($i = 0; $i < count($this->tableRowsToShow); $i++) { |
| 2101 |
$onChange .= 'document.getElementById(\'' . $this->tableRowsToShow[$i] . '\')?.closest(\'' . $selector . '\').classList.remove(\'hidden\');'; |
| 2102 |
} |
| 2103 |
for ($i = 0; $i < count($this->tableRowsToHide); $i++) { |
| 2104 |
$onChange .= 'document.getElementById(\'' . $this->tableRowsToHide[$i] . '\')?.closest(\'' . $selector . '\').classList.add(\'hidden\');'; |
| 2105 |
} |
| 2106 |
$onChange .= '}'; |
| 2107 |
$onChange .= 'else {'; |
| 2108 |
for ($i = 0; $i < count($this->tableRowsToShow); $i++) { |
| 2109 |
$onChange .= 'document.getElementById(\'' . $this->tableRowsToShow[$i] . '\')?.closest(\'' . $selector . '\').classList.add(\'hidden\');'; |
| 2110 |
} |
| 2111 |
for ($i = 0; $i < count($this->tableRowsToHide); $i++) { |
| 2112 |
$onChange .= 'document.getElementById(\'' . $this->tableRowsToHide[$i] . '\')?.closest(\'' . $selector . '\').classList.remove(\'hidden\');'; |
| 2113 |
} |
| 2114 |
$onChange .= '};'; |
| 2115 |
// build script to set initial state |
| 2116 |
$script .= '<script type="text/javascript">window.lam.utility.documentReady(function() {'; |
| 2117 |
for ($i = 0; $i < count($this->tableRowsToShow); $i++) { |
| 2118 |
$classType = 'add'; |
| 2119 |
if ($this->checked) { |
| 2120 |
$classType = 'remove'; |
| 2121 |
} |
| 2122 |
$script .= 'document.getElementById(\'' . $this->tableRowsToShow[$i] . '\')?.closest(\'' . $selector . '\').classList.' . $classType . '(\'hidden\');'; |
| 2123 |
} |
| 2124 |
for ($i = 0; $i < count($this->tableRowsToHide); $i++) { |
| 2125 |
$classType = 'remove'; |
| 2126 |
if ($this->checked) { |
| 2127 |
$classType = 'add'; |
| 2128 |
} |
| 2129 |
$script .= 'document.getElementById(\'' . $this->tableRowsToHide[$i] . '\')?.closest(\'' . $selector . '\').classList.' . $classType . '(\'hidden\');'; |
| 2130 |
} |
| 2131 |
$script .= '});</script>'; |
| 2132 |
} |
| 2133 |
// build Java script to enable/disable elements |
| 2134 |
if ((count($this->elementsToEnable) > 0) || (count($this->elementsToDisable) > 0)) { |
| 2135 |
// build onChange listener |
| 2136 |
$onChange .= 'if (document.querySelector(\'#' . $this->name . ':checked\') !== null) {'; |
| 2137 |
for ($i = 0; $i < count($this->elementsToEnable); $i++) { |
| 2138 |
$onChange .= 'document.getElementById(\'' . $this->elementsToEnable[$i] . '\').disabled = false;'; |
| 2139 |
} |
| 2140 |
for ($i = 0; $i < count($this->elementsToDisable); $i++) { |
| 2141 |
$onChange .= 'document.getElementById(\'' . $this->elementsToDisable[$i] . '\').disabled = true;'; |
| 2142 |
} |
| 2143 |
$onChange .= '}'; |
| 2144 |
$onChange .= 'else {'; |
| 2145 |
for ($i = 0; $i < count($this->elementsToEnable); $i++) { |
| 2146 |
$onChange .= 'document.getElementById(\'' . $this->elementsToEnable[$i] . '\').disabled = true;'; |
| 2147 |
} |
| 2148 |
for ($i = 0; $i < count($this->elementsToDisable); $i++) { |
| 2149 |
$onChange .= 'document.getElementById(\'' . $this->elementsToDisable[$i] . '\').disabled = false;'; |
| 2150 |
} |
| 2151 |
$onChange .= '};'; |
| 2152 |
// build script to set initial state |
| 2153 |
$script .= '<script type="text/javascript">window.lam.utility.documentReady(function() {'; |
| 2154 |
for ($i = 0; $i < count($this->elementsToEnable); $i++) { |
| 2155 |
$classType = 'true'; |
| 2156 |
if ($this->checked) { |
| 2157 |
$classType = 'false'; |
| 2158 |
} |
| 2159 |
$script .= 'document.getElementById(\'' . $this->elementsToEnable[$i] . '\').disabled = ' . $classType . ';'; |
| 2160 |
} |
| 2161 |
for ($i = 0; $i < count($this->elementsToDisable); $i++) { |
| 2162 |
$classType = 'false'; |
| 2163 |
if ($this->checked) { |
| 2164 |
$classType = 'true'; |
| 2165 |
} |
| 2166 |
$script .= 'document.getElementById(\'' . $this->elementsToDisable[$i] . '\').disabled = ' . $classType . ';'; |
| 2167 |
} |
| 2168 |
$script .= '});</script>'; |
| 2169 |
} |
| 2170 |
if (!empty($onChange)) { |
| 2171 |
$onChange = ' onChange="' . $onChange . '"'; |
| 2172 |
} |
| 2173 |
$onClick = ''; |
| 2174 |
if (!empty($this->onClick)) { |
| 2175 |
$onClick = ' onclick="' . $this->onClick . '"'; |
| 2176 |
} |
| 2177 |
echo '<input type="checkbox" id="' . $this->name . '" name="' . $this->name . '"' . $classes |
| 2178 |
. $this->getAccessibilityMarkup() . $this->getDataAttributesAsString() . $onChange . $onClick . $title . $checked . $disabled . '>'; |
| 2179 |
echo $script; |
| 2180 |
if ($this->transient) { |
| 2181 |
return []; |
| 2182 |
} |
| 2183 |
return [$this->name => 'checkbox']; |
| 2184 |
} |
| 2185 |
|
| 2186 |
/** |
| 2187 |
* Specifies if this component is enabled and accepts user modification. |
| 2188 |
* |
| 2189 |
* @param bool $isEnabled enabled if true |
| 2190 |
*/ |
| 2191 |
public function setIsEnabled(bool $isEnabled): void { |
| 2192 |
$this->isEnabled = $isEnabled; |
| 2193 |
} |
| 2194 |
|
| 2195 |
/** |
| 2196 |
* This will hide the given table rows when the checkbox is checked. |
| 2197 |
* The given IDs can be of any e.g. input element. Starting from this element |
| 2198 |
* the first parent "<tr>" element will be used to show/hide. |
| 2199 |
* <br> |
| 2200 |
* <br> |
| 2201 |
* <br>Example: <tr><td><input type="checkbox" id="mycheckbox"></td></tr> |
| 2202 |
* <br> Using "mycheckbox" will use this "tr" to hide/show. |
| 2203 |
* |
| 2204 |
* @param string[] $tableRowsToHide IDs of child elements to hide |
| 2205 |
*/ |
| 2206 |
public function setTableRowsToHide(array $tableRowsToHide): void { |
| 2207 |
$this->tableRowsToHide = $tableRowsToHide; |
| 2208 |
} |
| 2209 |
|
| 2210 |
/** |
| 2211 |
* This will show the given table rows when the checkbox is checked. |
| 2212 |
* The given IDs can be of any e.g. input element. Starting from this element |
| 2213 |
* the first parent "<tr>" element will be used to show/hide. |
| 2214 |
* <br> |
| 2215 |
* <br> |
| 2216 |
* <br>Example: <tr><td><input type="checkbox" id="mycheckbox"></td></tr> |
| 2217 |
* <br> Using "mycheckbox" will use this "tr" to hide/show. |
| 2218 |
* |
| 2219 |
* @param string[] $tableRowsToShow IDs of child elements to show |
| 2220 |
*/ |
| 2221 |
public function setTableRowsToShow(array $tableRowsToShow): void { |
| 2222 |
$this->tableRowsToShow = $tableRowsToShow; |
| 2223 |
} |
| 2224 |
|
| 2225 |
/** |
| 2226 |
* Specifies that the value should not be automatically saved when used in self-service or server profile (default: false). |
| 2227 |
* |
| 2228 |
* @param bool $transient transient field |
| 2229 |
*/ |
| 2230 |
public function setTransient(bool $transient): void { |
| 2231 |
$this->transient = $transient; |
| 2232 |
} |
| 2233 |
|
| 2234 |
/** |
| 2235 |
* This will disable the given input elements when the checkbox is checked. |
| 2236 |
* The given IDs can be of any input element (e.g. select, checkbox, ...). |
| 2237 |
* |
| 2238 |
* @param string[] $elements IDs of elements to disable |
| 2239 |
*/ |
| 2240 |
public function setElementsToDisable(array $elements): void { |
| 2241 |
$this->elementsToDisable = $elements; |
| 2242 |
} |
| 2243 |
|
| 2244 |
/** |
| 2245 |
* This will enable the given input elements when the checkbox is checked. |
| 2246 |
* The given IDs can be of any input element (e.g. select, checkbox, ...). |
| 2247 |
* |
| 2248 |
* @param string[] $elements IDs of elements to enable |
| 2249 |
*/ |
| 2250 |
public function setElementsToEnable(array $elements): void { |
| 2251 |
$this->elementsToEnable = $elements; |
| 2252 |
} |
| 2253 |
|
| 2254 |
/** |
| 2255 |
* Returns the CSS selector to use to find show/hide elements. |
| 2256 |
*/ |
| 2257 |
protected function getShowHideSelector(): string { |
| 2258 |
return 'tr'; |
| 2259 |
} |
| 2260 |
|
| 2261 |
/** |
| 2262 |
* Sets the onclick code. |
| 2263 |
* |
| 2264 |
* @param string $code JS code |
| 2265 |
*/ |
| 2266 |
public function setOnClick(string $code): void { |
| 2267 |
$this->onClick = $code; |
| 2268 |
} |
| 2269 |
|
| 2270 |
/** |
| 2271 |
* Returns the checkbox name. |
| 2272 |
* |
| 2273 |
* @return string name |
| 2274 |
*/ |
| 2275 |
protected function getName(): string { |
| 2276 |
return $this->name; |
| 2277 |
} |
| 2278 |
|
| 2279 |
/** |
| 2280 |
* Sets the title. |
| 2281 |
* |
| 2282 |
* @param string|null $title title |
| 2283 |
*/ |
| 2284 |
public function setTitle(?string $title): void { |
| 2285 |
$this->title = $title; |
| 2286 |
} |
| 2287 |
|
| 2288 |
} |
| 2289 |
|
| 2290 |
/** |
| 2291 |
* Prints the HTML code for a file upload field. |
| 2292 |
* |
| 2293 |
* @package metaHTML |
| 2294 |
*/ |
| 2295 |
class htmlInputFileUpload extends htmlElement { |
| 2296 |
|
| 2297 |
/** unique name of input element */ |
| 2298 |
private string $name; |
| 2299 |
/** enabled or disabled */ |
| 2300 |
private bool $isEnabled = true; |
| 2301 |
/** required */ |
| 2302 |
protected bool $required = false; |
| 2303 |
/** onchange event */ |
| 2304 |
protected string $onChange = ''; |
| 2305 |
|
| 2306 |
/** |
| 2307 |
* Constructor. |
| 2308 |
* |
| 2309 |
* @param string $name unique name |
| 2310 |
*/ |
| 2311 |
public function __construct(string $name) { |
| 2312 |
$this->name = htmlspecialchars($name); |
| 2313 |
} |
| 2314 |
|
| 2315 |
/** |
| 2316 |
* {@inheritDoc} |
| 2317 |
*/ |
| 2318 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 2319 |
$disabled = ''; |
| 2320 |
if (!$this->isEnabled) { |
| 2321 |
$disabled = ' disabled'; |
| 2322 |
} |
| 2323 |
$required = ''; |
| 2324 |
if ($this->required) { |
| 2325 |
$required = ' required="required"'; |
| 2326 |
} |
| 2327 |
$onChange = ''; |
| 2328 |
if (!empty($this->onChange)) { |
| 2329 |
$onChange = ' onchange="' . $this->onChange . '"'; |
| 2330 |
} |
| 2331 |
$classValue = ''; |
| 2332 |
if (!empty($this->cssClasses)) { |
| 2333 |
$classValue = ' class="' . implode(' ', $this->cssClasses) . '"'; |
| 2334 |
} |
| 2335 |
echo '<input type="file" id="' . $this->name . '" name="' . $this->name . '"' . $classValue . |
| 2336 |
$onChange . $disabled . $required . $this->getDataAttributesAsString() . '>'; |
| 2337 |
return [$this->name => 'file']; |
| 2338 |
} |
| 2339 |
|
| 2340 |
/** |
| 2341 |
* Specifies if this component is enabled and accepts user modification. |
| 2342 |
* |
| 2343 |
* @param bool $isEnabled enabled if true |
| 2344 |
*/ |
| 2345 |
public function setIsEnabled(bool $isEnabled): void { |
| 2346 |
$this->isEnabled = $isEnabled; |
| 2347 |
} |
| 2348 |
|
| 2349 |
/** |
| 2350 |
* Sets the field required. |
| 2351 |
* |
| 2352 |
* @param bool $required field is required (default: true) |
| 2353 |
*/ |
| 2354 |
public function setRequired(bool $required = true): void { |
| 2355 |
$this->required = $required; |
| 2356 |
} |
| 2357 |
|
| 2358 |
/** |
| 2359 |
* Sets the onChange event. |
| 2360 |
* |
| 2361 |
* @param string $onChange onChange code |
| 2362 |
*/ |
| 2363 |
public function setOnChange(string $onChange): void { |
| 2364 |
$this->onChange = $onChange; |
| 2365 |
} |
| 2366 |
|
| 2367 |
} |
| 2368 |
|
| 2369 |
/** |
| 2370 |
* Prints the HTML code for a textarea. |
| 2371 |
* |
| 2372 |
* @package metaHTML |
| 2373 |
*/ |
| 2374 |
class htmlInputTextarea extends htmlElement { |
| 2375 |
|
| 2376 |
/** unique name of input element */ |
| 2377 |
protected string $name; |
| 2378 |
/** value */ |
| 2379 |
private string $value; |
| 2380 |
/** column count */ |
| 2381 |
private string $colCount; |
| 2382 |
/** row count */ |
| 2383 |
private string $rowCount; |
| 2384 |
/** enabled or disabled */ |
| 2385 |
private bool $isEnabled = true; |
| 2386 |
/** specifies if LAM should display this field with a WYSIWYG editor */ |
| 2387 |
protected bool $richEdit = false; |
| 2388 |
/** required field */ |
| 2389 |
protected bool $required = false; |
| 2390 |
|
| 2391 |
/** |
| 2392 |
* Constructor. |
| 2393 |
* |
| 2394 |
* @param string $name unique name |
| 2395 |
* @param string $value value |
| 2396 |
* @param int $colCount number of characters per line |
| 2397 |
* @param int $rowCount number of rows |
| 2398 |
*/ |
| 2399 |
public function __construct(string $name, string $value, int $colCount, int $rowCount) { |
| 2400 |
$this->name = htmlspecialchars($name); |
| 2401 |
$this->value = htmlspecialchars($value); |
| 2402 |
$this->colCount = htmlspecialchars((string) $colCount); |
| 2403 |
$this->rowCount = htmlspecialchars((string) $rowCount); |
| 2404 |
} |
| 2405 |
|
| 2406 |
/** |
| 2407 |
* {@inheritDoc} |
| 2408 |
*/ |
| 2409 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 2410 |
if (isset($values[$this->name])) { |
| 2411 |
$this->value = htmlspecialchars(implode("\r\n", $values[$this->name])); |
| 2412 |
} |
| 2413 |
$colCount = ($this->colCount != null) ? ' cols="' . $this->colCount . '"' : ''; |
| 2414 |
$rowCount = ($this->rowCount != null) ? ' rows="' . $this->rowCount . '"' : ''; |
| 2415 |
$disabled = ''; |
| 2416 |
if (!$this->isEnabled) { |
| 2417 |
$disabled = ' disabled'; |
| 2418 |
} |
| 2419 |
$classList = $this->cssClasses; |
| 2420 |
if ($this->richEdit) { |
| 2421 |
$classList[] = 'lam-rich-edit'; |
| 2422 |
} |
| 2423 |
$required = ''; |
| 2424 |
if ($this->required) { |
| 2425 |
$required = ' required'; |
| 2426 |
} |
| 2427 |
$classes = ' class="' . implode(' ', $classList) . '"'; |
| 2428 |
echo '<textarea name="' . $this->name . '" id="' . $this->name . '"' . $classes . $colCount . |
| 2429 |
$rowCount . $this->getDataAttributesAsString() . $this->getAccessibilityMarkup() . $required . $disabled . '>' . |
| 2430 |
$this->value . '</textarea>'; |
| 2431 |
return [$this->name => 'textarea']; |
| 2432 |
} |
| 2433 |
|
| 2434 |
/** |
| 2435 |
* Specifies if this component is enabled and accepts user modification. |
| 2436 |
* |
| 2437 |
* @param bool $isEnabled enabled if true |
| 2438 |
*/ |
| 2439 |
public function setIsEnabled(bool $isEnabled): void { |
| 2440 |
$this->isEnabled = $isEnabled; |
| 2441 |
} |
| 2442 |
|
| 2443 |
/** |
| 2444 |
* Specifies if the textarea should be displayed with a WYSIWYG editor. |
| 2445 |
* <br>This requires that the page which displays the textarea also includes the JS for the rich editing. |
| 2446 |
* <br>Rich editing is disabled by default. |
| 2447 |
* |
| 2448 |
* @param bool $richEdit rich edit or standard |
| 2449 |
*/ |
| 2450 |
public function setIsRichEdit(bool $richEdit): void { |
| 2451 |
$this->richEdit = $richEdit; |
| 2452 |
} |
| 2453 |
|
| 2454 |
/** |
| 2455 |
* Specifies if the input field is required. |
| 2456 |
* |
| 2457 |
* @param bool $required required |
| 2458 |
*/ |
| 2459 |
public function setRequired(bool $required): void { |
| 2460 |
$this->required = $required; |
| 2461 |
} |
| 2462 |
|
| 2463 |
} |
| 2464 |
|
| 2465 |
/** |
| 2466 |
* Prints the HTML code for a color picker field. |
| 2467 |
* |
| 2468 |
* @package metaHTML |
| 2469 |
*/ |
| 2470 |
class htmlInputColorPicker extends htmlElement { |
| 2471 |
|
| 2472 |
/** unique name of input element */ |
| 2473 |
private string $name; |
| 2474 |
/** color value */ |
| 2475 |
private string $color; |
| 2476 |
/** enabled or disabled */ |
| 2477 |
private bool $isEnabled = true; |
| 2478 |
|
| 2479 |
/** |
| 2480 |
* Constructor. |
| 2481 |
* |
| 2482 |
* @param string $name unique name |
| 2483 |
* @param string $colorValue color value (e.g. #000000) |
| 2484 |
*/ |
| 2485 |
public function __construct(string $name, string $colorValue = '#000000') { |
| 2486 |
$this->name = htmlspecialchars($name); |
| 2487 |
$this->color = htmlspecialchars($colorValue); |
| 2488 |
} |
| 2489 |
|
| 2490 |
/** |
| 2491 |
* {@inheritDoc} |
| 2492 |
*/ |
| 2493 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 2494 |
$disabled = ''; |
| 2495 |
if (!$this->isEnabled) { |
| 2496 |
$disabled = ' disabled'; |
| 2497 |
} |
| 2498 |
echo '<input type="color" value="' . $this->color . '" id="' . $this->name . '" name="' . $this->name . '"' . $disabled . '>'; |
| 2499 |
return [$this->name => 'file']; |
| 2500 |
} |
| 2501 |
|
| 2502 |
/** |
| 2503 |
* Specifies if this component is enabled and accepts user modification. |
| 2504 |
* |
| 2505 |
* @param bool $isEnabled enabled if true |
| 2506 |
*/ |
| 2507 |
public function setIsEnabled(bool $isEnabled): void { |
| 2508 |
$this->isEnabled = $isEnabled; |
| 2509 |
} |
| 2510 |
|
| 2511 |
} |
| 2512 |
|
| 2513 |
/** |
| 2514 |
* Color picker with descriptive label and help link. |
| 2515 |
* |
| 2516 |
* @package metaHTML |
| 2517 |
*/ |
| 2518 |
class htmlResponsiveInputColorPicker extends htmlInputColorPicker { |
| 2519 |
|
| 2520 |
/** descriptive label */ |
| 2521 |
private string $label; |
| 2522 |
/** help ID */ |
| 2523 |
private ?string $helpID = null; |
| 2524 |
/** help module */ |
| 2525 |
private ?string $helpModule = null; |
| 2526 |
/** render HTML of parent class */ |
| 2527 |
private bool $renderParentHtml = false; |
| 2528 |
|
| 2529 |
/** |
| 2530 |
* Constructor. |
| 2531 |
* |
| 2532 |
* @param string $name unique name |
| 2533 |
* @param string $colorValue color value (e.g. #000000) |
| 2534 |
* @param string $label descriptive label |
| 2535 |
* @param string[]|string|null $helpID help ID |
| 2536 |
*/ |
| 2537 |
public function __construct($name, $colorValue, string $label, array|string|null $helpID = null) { |
| 2538 |
parent::__construct($name, $colorValue); |
| 2539 |
$this->label = htmlspecialchars($label); |
| 2540 |
if (is_string($helpID)) { |
| 2541 |
$this->helpID = $helpID; |
| 2542 |
} |
| 2543 |
elseif (is_array($helpID)) { |
| 2544 |
$this->helpID = $helpID[0]; |
| 2545 |
$this->helpModule = $helpID[1]; |
| 2546 |
} |
| 2547 |
} |
| 2548 |
|
| 2549 |
/** |
| 2550 |
* {@inheritDoc} |
| 2551 |
*/ |
| 2552 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 2553 |
if ($this->renderParentHtml) { |
| 2554 |
return parent::generateHTML($module, $input, $values, $restricted); |
| 2555 |
} |
| 2556 |
// HTML of parent class is rendered on second call (done by htmlResponsiveRow) |
| 2557 |
$this->renderParentHtml = true; |
| 2558 |
$row = new htmlResponsiveRow(); |
| 2559 |
// label text |
| 2560 |
$labelGroup = new htmlGroup(); |
| 2561 |
$labelGroup->addElement(new htmlOutputText($this->label)); |
| 2562 |
if (!empty($this->helpID)) { |
| 2563 |
$helpLinkLabel = new htmlHelpLink($this->helpID, $this->helpModule); |
| 2564 |
$helpLinkLabel->setCSSClasses(['hide-on-tablet', 'margin-left5']); |
| 2565 |
$labelGroup->addElement($helpLinkLabel); |
| 2566 |
} |
| 2567 |
$row->add($labelGroup, 12, 6, 6, 'responsiveLabel'); |
| 2568 |
// input field |
| 2569 |
$fieldGroup = new htmlGroup(); |
| 2570 |
$fieldGroup->addElement($this); |
| 2571 |
if (!empty($this->helpID)) { |
| 2572 |
$helpLinkField = new htmlHelpLink($this->helpID, $this->helpModule); |
| 2573 |
$helpLinkField->setCSSClasses(['hide-on-mobile']); |
| 2574 |
$fieldGroup->addElement($helpLinkField); |
| 2575 |
} |
| 2576 |
$row->add($fieldGroup, 12, 6, 6, 'responsiveField nowrap'); |
| 2577 |
return $row->generateHTML($module, $input, $values, $restricted); |
| 2578 |
} |
| 2579 |
|
| 2580 |
} |
| 2581 |
|
| 2582 |
/** |
| 2583 |
* Prints the HTML code for an image. |
| 2584 |
* |
| 2585 |
* @package metaHTML |
| 2586 |
*/ |
| 2587 |
class htmlImage extends htmlElement { |
| 2588 |
|
| 2589 |
/** ID value */ |
| 2590 |
private ?string $id = null; |
| 2591 |
/** path to image */ |
| 2592 |
private string $path; |
| 2593 |
/** width */ |
| 2594 |
private ?string $width; |
| 2595 |
/** height */ |
| 2596 |
private ?string $height; |
| 2597 |
/** alt text */ |
| 2598 |
private string $alt; |
| 2599 |
/** title */ |
| 2600 |
private ?string $title; |
| 2601 |
/** onClick event */ |
| 2602 |
private ?string $onClick; |
| 2603 |
/** enable cropping */ |
| 2604 |
private bool $crop = false; |
| 2605 |
/** enable lightbox */ |
| 2606 |
private bool $lightbox = false; |
| 2607 |
/** help popup title */ |
| 2608 |
private ?string $helpTitle = null; |
| 2609 |
/** help popup content */ |
| 2610 |
private ?htmlElement $helpContent = null; |
| 2611 |
|
| 2612 |
/** |
| 2613 |
* Constructor. |
| 2614 |
* |
| 2615 |
* @param string $path image location |
| 2616 |
* @param string|null $width image width (optional, default original size) |
| 2617 |
* @param string|null $height image height (optional, default original size) |
| 2618 |
* @param string $alt alt text (optional) |
| 2619 |
* @param string|null $title title text (optional) |
| 2620 |
* @param string|null $onClick onClick code (optional) |
| 2621 |
*/ |
| 2622 |
public function __construct(string $path, ?string $width = null, ?string $height = null, string $alt = ' ', ?string $title = null, ?string $onClick = null) { |
| 2623 |
$this->path = htmlspecialchars($path); |
| 2624 |
$this->width = $width; |
| 2625 |
$this->height = $height; |
| 2626 |
$this->alt = htmlspecialchars($alt); |
| 2627 |
$this->title = $title; |
| 2628 |
$this->onClick = $onClick; |
| 2629 |
} |
| 2630 |
|
| 2631 |
/** |
| 2632 |
* {@inheritDoc} |
| 2633 |
*/ |
| 2634 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 2635 |
$idValue = ''; |
| 2636 |
if ($this->id != null) { |
| 2637 |
$idValue = ' id="' . $this->id . '"'; |
| 2638 |
} |
| 2639 |
$path = ' src="' . $this->path . '"'; |
| 2640 |
$width = ''; |
| 2641 |
if ($this->width != null) { |
| 2642 |
$width = ' width="' . $this->width . '"'; |
| 2643 |
} |
| 2644 |
$height = ''; |
| 2645 |
if ($this->height != null) { |
| 2646 |
$height = ' height="' . $this->height . '"'; |
| 2647 |
} |
| 2648 |
$alt = ' alt="' . $this->alt . '"'; |
| 2649 |
$title = ''; |
| 2650 |
if (!empty($this->title)) { |
| 2651 |
$title = ' title="' . $this->title . '"'; |
| 2652 |
} |
| 2653 |
if ($this->crop) { |
| 2654 |
$this->cssClasses[] = 'cropperjsImage'; |
| 2655 |
} |
| 2656 |
if ($this->lightbox) { |
| 2657 |
$this->cssClasses[] = 'lam-lightbox'; |
| 2658 |
$this->addDataAttribute('lightbox-label-close', _('Close')); |
| 2659 |
} |
| 2660 |
$classes = ''; |
| 2661 |
if (!empty($this->cssClasses)) { |
| 2662 |
$classes = 'class="' . implode(' ', $this->cssClasses) . '"'; |
| 2663 |
} |
| 2664 |
$onClick = ''; |
| 2665 |
if ($this->onClick != null) { |
| 2666 |
$onClick = ' onclick="' . $this->onClick . '"'; |
| 2667 |
} |
| 2668 |
$helpTitleValue = ''; |
| 2669 |
$helpContentValue = ''; |
| 2670 |
if ($this->helpTitle !== null) { |
| 2671 |
$helpTitleValue = ' helptitle="' . $this->helpTitle . '"'; |
| 2672 |
ob_start(); |
| 2673 |
$this->helpContent->generateHTML($module, $input, $values, $restricted); |
| 2674 |
$helpContentString = ob_get_contents(); |
| 2675 |
ob_end_clean(); |
| 2676 |
$helpContentValue = ' helpdata="' . htmlspecialchars($helpContentString) . '"'; |
| 2677 |
} |
| 2678 |
echo '<img' . $idValue . $path . $width . $height . $alt . $title . $classes . $onClick . $helpTitleValue . $helpContentValue . $this->getDataAttributesAsString() . ">"; |
| 2679 |
if ($this->lightbox) { |
| 2680 |
echo '</a>'; |
| 2681 |
} |
| 2682 |
if ($this->crop) { |
| 2683 |
echo '<script type="text/javascript"> |
| 2684 |
window.lam.html.initCropping(); |
| 2685 |
</script>'; |
| 2686 |
echo '<input id="croppingDataX" type="hidden" name="croppingDataX" value="0"/>'; |
| 2687 |
echo '<input id="croppingDataY" type="hidden" name="croppingDataY" value="0"/>'; |
| 2688 |
echo '<input id="croppingDataWidth" type="hidden" name="croppingDataWidth" value="0"/>'; |
| 2689 |
echo '<input id="croppingDataHeight" type="hidden" name="croppingDataHeight" value="0"/>'; |
| 2690 |
echo '<input id="croppingDataSelectionWidth" type="hidden" name="croppingDataSelectionWidth" value="0"/>'; |
| 2691 |
echo '<input id="croppingDataSelectionHeight" type="hidden" name="croppingDataSelectionHeight" value="0"/>'; |
| 2692 |
} |
| 2693 |
return []; |
| 2694 |
} |
| 2695 |
|
| 2696 |
/** |
| 2697 |
* Enables cropping feature. |
| 2698 |
* This will display a cropping box on the image. The cropping data |
| 2699 |
* can be found in POST data (croppingDataX, croppingDataY, croppingDataWidth, croppingDataHeight). |
| 2700 |
*/ |
| 2701 |
public function enableCropping(): void { |
| 2702 |
$this->crop = true; |
| 2703 |
} |
| 2704 |
|
| 2705 |
/** |
| 2706 |
* Enables lightbox feature. |
| 2707 |
*/ |
| 2708 |
public function enableLightbox(): void { |
| 2709 |
$this->lightbox = true; |
| 2710 |
} |
| 2711 |
|
| 2712 |
/** |
| 2713 |
* Activates the help popup on hover. |
| 2714 |
* |
| 2715 |
* @param string $title title |
| 2716 |
* @param htmlElement $content help content |
| 2717 |
*/ |
| 2718 |
public function setHelpData(string $title, htmlElement $content): void { |
| 2719 |
$this->helpTitle = htmlspecialchars($title); |
| 2720 |
$this->helpContent = $content; |
| 2721 |
} |
| 2722 |
|
| 2723 |
/** |
| 2724 |
* Sets the onClick event code. |
| 2725 |
* |
| 2726 |
* @param string $code JS code |
| 2727 |
*/ |
| 2728 |
public function setOnClick(string $code): void { |
| 2729 |
$this->onClick = $code; |
| 2730 |
} |
| 2731 |
|
| 2732 |
/** |
| 2733 |
* Sets the ID of the image. |
| 2734 |
* |
| 2735 |
* @param string|null $id ID |
| 2736 |
*/ |
| 2737 |
public function setId(?string $id): void { |
| 2738 |
$this->id = $id; |
| 2739 |
} |
| 2740 |
|
| 2741 |
} |
| 2742 |
|
| 2743 |
/** |
| 2744 |
* Adds an empty space with given width and height. |
| 2745 |
* |
| 2746 |
* @package metaHTML |
| 2747 |
*/ |
| 2748 |
class htmlSpacer extends htmlElement { |
| 2749 |
|
| 2750 |
/** width of spacer in px */ |
| 2751 |
private ?string $width = null; |
| 2752 |
/** height of spacer in px */ |
| 2753 |
private ?string $height = null; |
| 2754 |
|
| 2755 |
/** |
| 2756 |
* Constructor. |
| 2757 |
* |
| 2758 |
* @param string|null $width width (e.g. 10px) |
| 2759 |
* @param string|null $height height (e.g. 10px) |
| 2760 |
* @param string[]|null $cssClasses CSS classes |
| 2761 |
*/ |
| 2762 |
public function __construct(?string $width, ?string $height = null, ?array $cssClasses = []) { |
| 2763 |
if ($width !== null) { |
| 2764 |
$this->width = htmlspecialchars($width); |
| 2765 |
} |
| 2766 |
if ($height !== null) { |
| 2767 |
$this->height = htmlspecialchars($height); |
| 2768 |
} |
| 2769 |
if (!empty($cssClasses)) { |
| 2770 |
$this->setCSSClasses($cssClasses); |
| 2771 |
} |
| 2772 |
} |
| 2773 |
|
| 2774 |
/** |
| 2775 |
* {@inheritDoc} |
| 2776 |
*/ |
| 2777 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 2778 |
$width = ''; |
| 2779 |
if ($this->width !== null) { |
| 2780 |
$width = 'width: ' . $this->width . ';'; |
| 2781 |
} |
| 2782 |
$height = ''; |
| 2783 |
if ($this->height !== null) { |
| 2784 |
$height = 'height: ' . $this->height . ';'; |
| 2785 |
} |
| 2786 |
$classes = ''; |
| 2787 |
if (!empty($this->cssClasses)) { |
| 2788 |
$classes = 'class="' . implode(' ', $this->cssClasses) . '"'; |
| 2789 |
} |
| 2790 |
echo "<div $classes style=\"$width $height display: inline-block;\"></div>\n"; |
| 2791 |
return []; |
| 2792 |
} |
| 2793 |
|
| 2794 |
} |
| 2795 |
|
| 2796 |
/** |
| 2797 |
* Prints a status message (e.g. error message). |
| 2798 |
* |
| 2799 |
* @package metaHTML |
| 2800 |
*/ |
| 2801 |
class htmlStatusMessage extends htmlElement { |
| 2802 |
|
| 2803 |
/** message type (e.g. ERROR) */ |
| 2804 |
private string $type; |
| 2805 |
/** message title */ |
| 2806 |
private ?string $title; |
| 2807 |
/** message text */ |
| 2808 |
private ?string $text; |
| 2809 |
/** @var array<string|string[]>|null $params message parameters */ |
| 2810 |
private ?array $params; |
| 2811 |
|
| 2812 |
/** |
| 2813 |
* Constructor. |
| 2814 |
* |
| 2815 |
* @param string $type message type (e.g. ERROR) |
| 2816 |
* @param string|null $title message title |
| 2817 |
* @param string|null $text message (optional) |
| 2818 |
* @param array<string|string[]>|null $params additional message parameters |
| 2819 |
*/ |
| 2820 |
public function __construct(string $type, ?string $title, ?string $text = null, ?array $params = null) { |
| 2821 |
$this->type = $type; |
| 2822 |
$this->title = $title; |
| 2823 |
$this->text = $text; |
| 2824 |
$this->params = $params; |
| 2825 |
} |
| 2826 |
|
| 2827 |
/** |
| 2828 |
* Constructor with parameter array. |
| 2829 |
* |
| 2830 |
* @param array<string|string[]> $params parameters in same order as normal constructor |
| 2831 |
* @return htmlStatusMessage message |
| 2832 |
*/ |
| 2833 |
public static function fromParamArray(array $params): htmlStatusMessage { |
| 2834 |
if (count($params) < 2) { |
| 2835 |
throw new BadMethodCallException("Invalid parameter count"); |
| 2836 |
} |
| 2837 |
|
| 2838 |
$count = count($params); |
| 2839 |
return match ($count) { |
| 2840 |
2 => new htmlStatusMessage($params[0], $params[1]), |
| 2841 |
3 => new htmlStatusMessage($params[0], $params[1], $params[2]), |
| 2842 |
4 => new htmlStatusMessage($params[0], $params[1], $params[2], $params[3]), |
| 2843 |
default => throw new BadMethodCallException("Invalid parameter count"), |
| 2844 |
}; |
| 2845 |
} |
| 2846 |
|
| 2847 |
/** |
| 2848 |
* {@inheritDoc} |
| 2849 |
*/ |
| 2850 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 2851 |
if (!empty($this->cssClasses)) { |
| 2852 |
echo '<div class="' . implode(' ', $this->cssClasses) . '">'; |
| 2853 |
} |
| 2854 |
StatusMessage($this->type, $this->title, $this->text, $this->params); |
| 2855 |
if (!empty($this->cssClasses)) { |
| 2856 |
echo '</div>'; |
| 2857 |
} |
| 2858 |
return []; |
| 2859 |
} |
| 2860 |
|
| 2861 |
/** |
| 2862 |
* Returns the message type. |
| 2863 |
* |
| 2864 |
* @return string type |
| 2865 |
*/ |
| 2866 |
public function getType(): string { |
| 2867 |
return $this->type; |
| 2868 |
} |
| 2869 |
|
| 2870 |
} |
| 2871 |
|
| 2872 |
/** |
| 2873 |
* Generates a title line. This is used for page titles. |
| 2874 |
* |
| 2875 |
* @package metaHTML |
| 2876 |
*/ |
| 2877 |
class htmlTitle extends htmlElement { |
| 2878 |
|
| 2879 |
/** descriptive label */ |
| 2880 |
private string $label; |
| 2881 |
|
| 2882 |
/** |
| 2883 |
* Constructor. |
| 2884 |
* |
| 2885 |
* @param string $label label |
| 2886 |
*/ |
| 2887 |
public function __construct(string $label) { |
| 2888 |
$this->label = htmlspecialchars($label); |
| 2889 |
// the title should not end at a table cell |
| 2890 |
$this->colspan = 100; |
| 2891 |
} |
| 2892 |
|
| 2893 |
/** |
| 2894 |
* {@inheritDoc} |
| 2895 |
*/ |
| 2896 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 2897 |
echo "<div class=\"title\">\n"; |
| 2898 |
echo "<h2 class=\"titleText\">\n"; |
| 2899 |
echo $this->label; |
| 2900 |
echo "</h2>\n"; |
| 2901 |
echo "</div>\n"; |
| 2902 |
return []; |
| 2903 |
} |
| 2904 |
|
| 2905 |
} |
| 2906 |
|
| 2907 |
/** |
| 2908 |
* Generates a subtitle line. This is used to group multiple fields. |
| 2909 |
* |
| 2910 |
* @package metaHTML |
| 2911 |
*/ |
| 2912 |
class htmlSubTitle extends htmlElement { |
| 2913 |
|
| 2914 |
public const H3 = 'h3'; |
| 2915 |
public const H4 = 'h4'; |
| 2916 |
public const H5 = 'h5'; |
| 2917 |
|
| 2918 |
/** descriptive label */ |
| 2919 |
private string $label; |
| 2920 |
/** optional image */ |
| 2921 |
private ?string $image = null; |
| 2922 |
/** optional ID for this element (e.g. to use for JavaScript) */ |
| 2923 |
private ?string $id = null; |
| 2924 |
/** show large icon */ |
| 2925 |
private bool $largeIcon; |
| 2926 |
/** @var string|string[]|null $helpId help ID */ |
| 2927 |
private string|array|null $helpId = null; |
| 2928 |
/** headline type (e.g. h3) */ |
| 2929 |
private string $type; |
| 2930 |
|
| 2931 |
/** |
| 2932 |
* Constructor. |
| 2933 |
* |
| 2934 |
* @param string $label label |
| 2935 |
* @param string|null $image optional image |
| 2936 |
* @param string|null $id optional ID for this element (e.g. to use for JavaScript) |
| 2937 |
* @param bool $largeIcon show large (32x32px) icon instead of small one (16x16px) |
| 2938 |
* @param string $type headline type |
| 2939 |
*/ |
| 2940 |
public function __construct(string $label, ?string $image = null, ?string $id = null, bool $largeIcon = false, string $type = self::H3) { |
| 2941 |
$this->label = htmlspecialchars($label); |
| 2942 |
if ($image !== null) { |
| 2943 |
$this->image = htmlspecialchars($image); |
| 2944 |
} |
| 2945 |
if ($id !== null) { |
| 2946 |
$this->id = htmlspecialchars($id); |
| 2947 |
} |
| 2948 |
// the title should not end at a table cell |
| 2949 |
$this->colspan = 100; |
| 2950 |
$this->largeIcon = $largeIcon; |
| 2951 |
$this->type = htmlspecialchars($type); |
| 2952 |
} |
| 2953 |
|
| 2954 |
/** |
| 2955 |
* {@inheritDoc} |
| 2956 |
*/ |
| 2957 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 2958 |
$idValue = ''; |
| 2959 |
if ($this->id != null) { |
| 2960 |
$idValue = ' id="' . $this->id . '"'; |
| 2961 |
} |
| 2962 |
echo "<div $idValue class=\"subTitle\">\n"; |
| 2963 |
echo "<" . $this->type ." class=\"subTitleText\">\n"; |
| 2964 |
if ($this->image != null) { |
| 2965 |
$size = $this->largeIcon ? 32 : 16; |
| 2966 |
echo '<img height=' . $size . ' width=' . $size . ' src="' . $this->image . '" alt="' . $this->label . '"> '; |
| 2967 |
} |
| 2968 |
echo $this->label; |
| 2969 |
if ($this->helpId !== null) { |
| 2970 |
$spacer = new htmlSpacer('0.5rem', null); |
| 2971 |
$spacer->generateHTML($module, $input, $values, $restricted); |
| 2972 |
$helpLink = new htmlHelpLink($this->helpId); |
| 2973 |
$helpLink->generateHTML($module, $input, $values, $restricted); |
| 2974 |
} |
| 2975 |
echo "</" . $this->type . ">\n"; |
| 2976 |
echo "</div>\n"; |
| 2977 |
return []; |
| 2978 |
} |
| 2979 |
|
| 2980 |
/** |
| 2981 |
* Sets an additional help id. |
| 2982 |
* |
| 2983 |
* @param string|string[] $helpId |
| 2984 |
*/ |
| 2985 |
public function setHelpId(array|string $helpId): void { |
| 2986 |
$this->helpId = $helpId; |
| 2987 |
} |
| 2988 |
|
| 2989 |
} |
| 2990 |
|
| 2991 |
/** |
| 2992 |
* Generates a hidden input field. |
| 2993 |
* |
| 2994 |
* @package metaHTML |
| 2995 |
*/ |
| 2996 |
class htmlHiddenInput extends htmlElement { |
| 2997 |
|
| 2998 |
/** field name */ |
| 2999 |
private string $name; |
| 3000 |
/** field value */ |
| 3001 |
private string $value = ''; |
| 3002 |
|
| 3003 |
/** |
| 3004 |
* Constructor. |
| 3005 |
* |
| 3006 |
* @param string $name input name |
| 3007 |
* @param string|null $value input value |
| 3008 |
*/ |
| 3009 |
public function __construct(string $name, ?string $value = '') { |
| 3010 |
$this->name = htmlspecialchars($name); |
| 3011 |
if ($value !== null) { |
| 3012 |
$this->value = htmlspecialchars($value); |
| 3013 |
} |
| 3014 |
} |
| 3015 |
|
| 3016 |
/** |
| 3017 |
* {@inheritDoc} |
| 3018 |
*/ |
| 3019 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 3020 |
echo '<input type="hidden" name="' . $this->name . '" id="' . $this->name . '" value="' . $this->value . '">'; |
| 3021 |
return [$this->name => 'hidden']; |
| 3022 |
} |
| 3023 |
|
| 3024 |
} |
| 3025 |
|
| 3026 |
/** |
| 3027 |
* Generates a link. |
| 3028 |
* The link can include an optional image in front of the link text. |
| 3029 |
* |
| 3030 |
* @package metaHTML |
| 3031 |
*/ |
| 3032 |
class htmlLink extends htmlElement { |
| 3033 |
|
| 3034 |
/** link text */ |
| 3035 |
private ?string $text = null; |
| 3036 |
/** link target */ |
| 3037 |
protected ?string $target = null; |
| 3038 |
/** optional image */ |
| 3039 |
private ?string $image = null; |
| 3040 |
/** title */ |
| 3041 |
private ?string $title = null; |
| 3042 |
/** target window */ |
| 3043 |
private ?string $targetWindow = null; |
| 3044 |
/** onClick event */ |
| 3045 |
private ?string $onClick = null; |
| 3046 |
/** onMouseOver event */ |
| 3047 |
private ?string $onMouseOver = null; |
| 3048 |
/** link id */ |
| 3049 |
private ?string $id = null; |
| 3050 |
|
| 3051 |
/** |
| 3052 |
* Constructor. |
| 3053 |
* |
| 3054 |
* @param string|null $text label |
| 3055 |
* @param string|null $target target URL |
| 3056 |
* @param string|null $image URL of optional image |
| 3057 |
*/ |
| 3058 |
public function __construct(?string $text, ?string $target, ?string $image = null) { |
| 3059 |
if ($text !== null) { |
| 3060 |
$this->text = htmlspecialchars($text); |
| 3061 |
} |
| 3062 |
if ($target !== null) { |
| 3063 |
$this->target = htmlspecialchars($target); |
| 3064 |
} |
| 3065 |
if ($image !== null) { |
| 3066 |
$this->image = htmlspecialchars($image); |
| 3067 |
} |
| 3068 |
} |
| 3069 |
|
| 3070 |
/** |
| 3071 |
* {@inheritDoc} |
| 3072 |
*/ |
| 3073 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 3074 |
$text = $this->getContent(); |
| 3075 |
$image = ''; |
| 3076 |
if ($this->image != null) { |
| 3077 |
$image = '<img class="align-middle" src="' . $this->image . '" alt="' . $this->getAlt() . '">'; |
| 3078 |
if (!empty($text)) { |
| 3079 |
$image .= ' '; |
| 3080 |
} |
| 3081 |
} |
| 3082 |
$title = ''; |
| 3083 |
if ($this->title != null) { |
| 3084 |
$title = ' title="' . $this->title . '"'; |
| 3085 |
} |
| 3086 |
$targetWindow = ''; |
| 3087 |
if ($this->targetWindow != null) { |
| 3088 |
$targetWindow = ' target="' . $this->targetWindow . '"'; |
| 3089 |
} |
| 3090 |
$onClick = ''; |
| 3091 |
if ($this->onClick != null) { |
| 3092 |
$onClick = ' onclick="' . $this->onClick . '"'; |
| 3093 |
} |
| 3094 |
$onMouseOver = ''; |
| 3095 |
if ($this->onMouseOver != null) { |
| 3096 |
$onMouseOver = ' onmouseover="' . $this->onMouseOver . '"'; |
| 3097 |
} |
| 3098 |
$idAttr = ''; |
| 3099 |
if (!empty($this->id)) { |
| 3100 |
$idAttr = ' id="' . $this->id . '"'; |
| 3101 |
} |
| 3102 |
$classAttr = ''; |
| 3103 |
if (count($this->cssClasses) > 0) { |
| 3104 |
$classAttr = ' class="' . implode(' ', $this->cssClasses) . '"'; |
| 3105 |
} |
| 3106 |
echo '<a href="' . $this->target . '"' . $idAttr . $classAttr . $title . $targetWindow . $onClick . $onMouseOver . $this->getDataAttributesAsString() . '>' . $image . $text . '</a>'; |
| 3107 |
return []; |
| 3108 |
} |
| 3109 |
|
| 3110 |
/** |
| 3111 |
* Returns the value for the alt attribute. |
| 3112 |
* |
| 3113 |
* @return string|null alt value |
| 3114 |
*/ |
| 3115 |
protected function getAlt(): ?string { |
| 3116 |
if (!empty($this->text)) { |
| 3117 |
return $this->text; |
| 3118 |
} |
| 3119 |
return $this->title; |
| 3120 |
} |
| 3121 |
|
| 3122 |
/** |
| 3123 |
* Returns the value for the link content. |
| 3124 |
* |
| 3125 |
* @return string|null content |
| 3126 |
*/ |
| 3127 |
protected function getContent(): ?string { |
| 3128 |
return $this->text; |
| 3129 |
} |
| 3130 |
|
| 3131 |
/** |
| 3132 |
* Sets the link title. |
| 3133 |
* |
| 3134 |
* @param string $title title |
| 3135 |
*/ |
| 3136 |
public function setTitle(string $title): void { |
| 3137 |
$this->title = htmlspecialchars($title); |
| 3138 |
} |
| 3139 |
|
| 3140 |
/** |
| 3141 |
* Sets the target window (e.g. _blank). |
| 3142 |
* |
| 3143 |
* @param string $window target window (e.g. _blank) |
| 3144 |
*/ |
| 3145 |
public function setTargetWindow(string $window): void { |
| 3146 |
$this->targetWindow = htmlspecialchars($window); |
| 3147 |
} |
| 3148 |
|
| 3149 |
/** |
| 3150 |
* Sets the onClick event. |
| 3151 |
* |
| 3152 |
* @param string $event JavaScript code |
| 3153 |
*/ |
| 3154 |
public function setOnClick(string $event): void { |
| 3155 |
$this->onClick = htmlspecialchars($event); |
| 3156 |
} |
| 3157 |
|
| 3158 |
/** |
| 3159 |
* Sets the onMouseOver event. |
| 3160 |
* |
| 3161 |
* @param string $event JavaScript code |
| 3162 |
*/ |
| 3163 |
public function setOnMouseOver(string $event): void { |
| 3164 |
$this->onMouseOver = htmlspecialchars($event); |
| 3165 |
} |
| 3166 |
|
| 3167 |
/** |
| 3168 |
* Sets the element id. |
| 3169 |
* |
| 3170 |
* @param string $id unique id |
| 3171 |
*/ |
| 3172 |
public function setId(string $id): void { |
| 3173 |
$this->id = $id; |
| 3174 |
} |
| 3175 |
|
| 3176 |
} |
| 3177 |
|
| 3178 |
/** |
| 3179 |
* Generates a link around a htmlElement. |
| 3180 |
* |
| 3181 |
* @package metaHTML |
| 3182 |
*/ |
| 3183 |
class htmlContentLink extends htmlLink { |
| 3184 |
|
| 3185 |
private htmlElement $content; |
| 3186 |
private string $contentText = ''; |
| 3187 |
|
| 3188 |
/** |
| 3189 |
* Constructor |
| 3190 |
* |
| 3191 |
* @param htmlElement $content content to link |
| 3192 |
* @param string $target link target |
| 3193 |
*/ |
| 3194 |
public function __construct(htmlElement $content, string $target) { |
| 3195 |
$this->content = $content; |
| 3196 |
$this->target = htmlspecialchars($target); |
| 3197 |
} |
| 3198 |
|
| 3199 |
/** |
| 3200 |
* {@inheritDoc} |
| 3201 |
*/ |
| 3202 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 3203 |
ob_start(); |
| 3204 |
parseHtml($module, $this->content, $values, $restricted); |
| 3205 |
$this->contentText = ob_get_contents(); |
| 3206 |
ob_end_clean(); |
| 3207 |
return parent::generateHTML($module, $input, $values, $restricted); |
| 3208 |
} |
| 3209 |
|
| 3210 |
/** |
| 3211 |
* Returns the value for the alt attribute. |
| 3212 |
* |
| 3213 |
* @return string alt value |
| 3214 |
*/ |
| 3215 |
protected function getAlt(): string { |
| 3216 |
return ''; |
| 3217 |
} |
| 3218 |
|
| 3219 |
/** |
| 3220 |
* Returns the value for the link content. |
| 3221 |
* |
| 3222 |
* @return string content |
| 3223 |
*/ |
| 3224 |
protected function getContent(): string { |
| 3225 |
return $this->contentText; |
| 3226 |
} |
| 3227 |
|
| 3228 |
} |
| 3229 |
|
| 3230 |
/** |
| 3231 |
* Groups multiple htmlElements. |
| 3232 |
* This is useful if multiple elements should be included in a single table cell. |
| 3233 |
* The HTML code of the subelements is printed in the order they were added. No additional code is added. |
| 3234 |
* |
| 3235 |
* @package metaHTML |
| 3236 |
*/ |
| 3237 |
class htmlGroup extends htmlElement { |
| 3238 |
|
| 3239 |
/** @var htmlElement[] $elements elements */ |
| 3240 |
private array $elements = []; |
| 3241 |
|
| 3242 |
/** |
| 3243 |
* Constructor |
| 3244 |
* |
| 3245 |
* @param htmlElement[] $elements elements |
| 3246 |
*/ |
| 3247 |
public function __construct(array $elements = []) { |
| 3248 |
foreach ($elements as $element) { |
| 3249 |
$this->addElement($element); |
| 3250 |
} |
| 3251 |
} |
| 3252 |
|
| 3253 |
/** |
| 3254 |
* {@inheritDoc} |
| 3255 |
*/ |
| 3256 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 3257 |
$return = []; |
| 3258 |
for ($i = 0; $i < count($this->elements); $i++) { |
| 3259 |
$return = array_merge($return, $this->elements[$i]->generateHTML($module, $input, $values, $restricted)); |
| 3260 |
} |
| 3261 |
return $return; |
| 3262 |
} |
| 3263 |
|
| 3264 |
/** |
| 3265 |
* Adds a subelement. |
| 3266 |
* |
| 3267 |
* @param htmlElement $sub element |
| 3268 |
*/ |
| 3269 |
public function addElement(htmlElement $sub): void { |
| 3270 |
$this->elements[] = $sub; |
| 3271 |
} |
| 3272 |
|
| 3273 |
} |
| 3274 |
|
| 3275 |
/** |
| 3276 |
* Prints a horizontal line. |
| 3277 |
* |
| 3278 |
* @package metaHTML |
| 3279 |
*/ |
| 3280 |
class htmlHorizontalLine extends htmlElement { |
| 3281 |
|
| 3282 |
/** |
| 3283 |
* {@inheritDoc} |
| 3284 |
*/ |
| 3285 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 3286 |
$return = []; |
| 3287 |
echo "<hr>"; |
| 3288 |
return $return; |
| 3289 |
} |
| 3290 |
|
| 3291 |
} |
| 3292 |
|
| 3293 |
/** |
| 3294 |
* Creates a simple DIV element. |
| 3295 |
* |
| 3296 |
* @package metaHTML |
| 3297 |
*/ |
| 3298 |
class htmlDiv extends htmlElement { |
| 3299 |
|
| 3300 |
/** unique ID */ |
| 3301 |
private ?string $id = null; |
| 3302 |
/** htmlElement that generates inner content */ |
| 3303 |
private htmlElement $content; |
| 3304 |
|
| 3305 |
/** |
| 3306 |
* Constructor. |
| 3307 |
* |
| 3308 |
* @param string|null $id unique ID |
| 3309 |
* @param htmlElement $content inner content |
| 3310 |
* @param string[]|null $cssClasses CSS classes |
| 3311 |
*/ |
| 3312 |
public function __construct(?string $id, htmlElement $content, ?array $cssClasses = null) { |
| 3313 |
if ($id !== null) { |
| 3314 |
$this->id = htmlspecialchars($id); |
| 3315 |
} |
| 3316 |
$this->content = $content; |
| 3317 |
$this->cssClasses = $cssClasses; |
| 3318 |
} |
| 3319 |
|
| 3320 |
/** |
| 3321 |
* {@inheritDoc} |
| 3322 |
*/ |
| 3323 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 3324 |
$idValue = ''; |
| 3325 |
if ($this->id != null) { |
| 3326 |
$idValue = ' id="' . $this->id . '"'; |
| 3327 |
} |
| 3328 |
$classesValue = ''; |
| 3329 |
if (($this->cssClasses !== null) && (count($this->cssClasses) > 0)) { |
| 3330 |
$classesValue = ' class="' . implode(' ', $this->cssClasses) . '"'; |
| 3331 |
} |
| 3332 |
echo '<div' . $idValue . $classesValue . $this->getDataAttributesAsString() . '>'; |
| 3333 |
$return = $this->content->generateHTML($module, $input, $values, $restricted); |
| 3334 |
echo '</div>'; |
| 3335 |
return $return; |
| 3336 |
} |
| 3337 |
} |
| 3338 |
|
| 3339 |
/** |
| 3340 |
* Creates a simple SPAN element. |
| 3341 |
* |
| 3342 |
* @package metaHTML |
| 3343 |
*/ |
| 3344 |
class htmlSpan extends htmlElement { |
| 3345 |
|
| 3346 |
/** htmlElement that generates inner content */ |
| 3347 |
private htmlElement $content; |
| 3348 |
/** onclick handler */ |
| 3349 |
private ?string $onclick = null; |
| 3350 |
/** title */ |
| 3351 |
private ?string $title = null; |
| 3352 |
|
| 3353 |
/** |
| 3354 |
* Constructor. |
| 3355 |
* |
| 3356 |
* @param htmlElement $content inner content |
| 3357 |
* @param string[]|null $cssClasses CSS classes |
| 3358 |
*/ |
| 3359 |
public function __construct(htmlElement $content, ?array $cssClasses = null) { |
| 3360 |
$this->content = $content; |
| 3361 |
$this->cssClasses = $cssClasses; |
| 3362 |
} |
| 3363 |
|
| 3364 |
/** |
| 3365 |
* {@inheritDoc} |
| 3366 |
*/ |
| 3367 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 3368 |
$classesValue = ''; |
| 3369 |
if (($this->cssClasses !== null) && (count($this->cssClasses) > 0)) { |
| 3370 |
$classesValue = ' class="' . implode(' ', $this->cssClasses) . '"'; |
| 3371 |
} |
| 3372 |
$onclickHandler = ''; |
| 3373 |
if (!empty($this->onclick)) { |
| 3374 |
$onclickHandler = ' onclick="' . $this->onclick . '"'; |
| 3375 |
} |
| 3376 |
$titleCode = ''; |
| 3377 |
if ($this->title !== null) { |
| 3378 |
$titleCode = ' title="' . $this->title . '"'; |
| 3379 |
} |
| 3380 |
echo '<span' . $classesValue . $titleCode . $onclickHandler . '>'; |
| 3381 |
$return = $this->content->generateHTML($module, $input, $values, $restricted); |
| 3382 |
echo '</span>'; |
| 3383 |
return $return; |
| 3384 |
} |
| 3385 |
|
| 3386 |
/** |
| 3387 |
* Sets the onclick event. |
| 3388 |
* |
| 3389 |
* @param string $event event handler code |
| 3390 |
*/ |
| 3391 |
public function setOnclick(string $event): void { |
| 3392 |
$this->onclick = $event; |
| 3393 |
} |
| 3394 |
|
| 3395 |
/** |
| 3396 |
* Sets the title. |
| 3397 |
* |
| 3398 |
* @param string $title title |
| 3399 |
*/ |
| 3400 |
public function setTitle(string $title): void { |
| 3401 |
$this->title = htmlspecialchars($title); |
| 3402 |
} |
| 3403 |
|
| 3404 |
} |
| 3405 |
|
| 3406 |
/** |
| 3407 |
* Creates a JavaScript element. |
| 3408 |
* |
| 3409 |
* @package metaHTML |
| 3410 |
*/ |
| 3411 |
class htmlJavaScript extends htmlElement { |
| 3412 |
|
| 3413 |
/** htmlElement that generates inner content */ |
| 3414 |
private string $content; |
| 3415 |
|
| 3416 |
/** |
| 3417 |
* Constructor. |
| 3418 |
* |
| 3419 |
* @param string $content script |
| 3420 |
*/ |
| 3421 |
public function __construct(string $content) { |
| 3422 |
$this->content = $content; |
| 3423 |
} |
| 3424 |
|
| 3425 |
/** |
| 3426 |
* {@inheritDoc} |
| 3427 |
*/ |
| 3428 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 3429 |
$return = []; |
| 3430 |
echo '<script type="text/javascript">'; |
| 3431 |
echo $this->content; |
| 3432 |
echo '</script>'; |
| 3433 |
return $return; |
| 3434 |
} |
| 3435 |
|
| 3436 |
} |
| 3437 |
|
| 3438 |
/** |
| 3439 |
* Creates a iframe element. |
| 3440 |
* |
| 3441 |
* @package metaHTML |
| 3442 |
*/ |
| 3443 |
class htmlIframe extends htmlElement { |
| 3444 |
|
| 3445 |
/** HTML id */ |
| 3446 |
private ?string $id; |
| 3447 |
|
| 3448 |
/** |
| 3449 |
* Constructor. |
| 3450 |
* |
| 3451 |
* @param string|null $id HTML id |
| 3452 |
*/ |
| 3453 |
public function __construct(?string $id = null) { |
| 3454 |
$this->id = $id; |
| 3455 |
} |
| 3456 |
|
| 3457 |
/** |
| 3458 |
* {@inheritDoc} |
| 3459 |
*/ |
| 3460 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 3461 |
$return = []; |
| 3462 |
$idAttr = ''; |
| 3463 |
if (!empty($this->id)) { |
| 3464 |
$idAttr = ' id="' . $this->id . '"'; |
| 3465 |
} |
| 3466 |
echo '<iframe ' . $idAttr . $this->getDataAttributesAsString() . '>'; |
| 3467 |
echo '</iframe>'; |
| 3468 |
return $return; |
| 3469 |
} |
| 3470 |
|
| 3471 |
} |
| 3472 |
|
| 3473 |
/** |
| 3474 |
* Creates a Script element to integrate external JavaScript files. |
| 3475 |
* |
| 3476 |
* @package metaHTML |
| 3477 |
*/ |
| 3478 |
class htmlScript extends htmlElement { |
| 3479 |
|
| 3480 |
/** src value */ |
| 3481 |
private string $src; |
| 3482 |
/** is async */ |
| 3483 |
private bool $async; |
| 3484 |
/** execute after page is parsed */ |
| 3485 |
private bool $defer; |
| 3486 |
|
| 3487 |
/** |
| 3488 |
* Constructor. |
| 3489 |
* |
| 3490 |
* @param string $src script path |
| 3491 |
* @param boolean $isAsync script will be executed while the page continues the parsing (default true) |
| 3492 |
* @param boolean $isDeferred script is executed when the page has finished parsing (default true) |
| 3493 |
*/ |
| 3494 |
public function __construct(string $src, bool $isAsync = true, bool $isDeferred = true) { |
| 3495 |
$this->src = $src; |
| 3496 |
$this->async = $isAsync; |
| 3497 |
$this->defer = $isDeferred; |
| 3498 |
} |
| 3499 |
|
| 3500 |
/** |
| 3501 |
* {@inheritDoc} |
| 3502 |
*/ |
| 3503 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 3504 |
$return = []; |
| 3505 |
$async = $this->async ? ' async' : ''; |
| 3506 |
$defer = $this->defer ? ' defer="defer"' : ''; |
| 3507 |
echo '<script src="' . $this->src . '"' . $async . $defer . '>'; |
| 3508 |
echo '</script>'; |
| 3509 |
return $return; |
| 3510 |
} |
| 3511 |
|
| 3512 |
} |
| 3513 |
|
| 3514 |
/** |
| 3515 |
* Creates a link element to integrate external CSS files. |
| 3516 |
* |
| 3517 |
* @package metaHTML |
| 3518 |
*/ |
| 3519 |
class htmlLinkCss extends htmlElement { |
| 3520 |
|
| 3521 |
/** src value */ |
| 3522 |
private string $src; |
| 3523 |
|
| 3524 |
/** |
| 3525 |
* Constructor. |
| 3526 |
* |
| 3527 |
* @param string $src script path |
| 3528 |
*/ |
| 3529 |
public function __construct(string $src) { |
| 3530 |
$this->src = $src; |
| 3531 |
} |
| 3532 |
|
| 3533 |
/** |
| 3534 |
* {@inheritDoc} |
| 3535 |
*/ |
| 3536 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 3537 |
$return = []; |
| 3538 |
echo '<link href="' . $this->src . '" type="text/css" rel="stylesheet"/>'; |
| 3539 |
return $return; |
| 3540 |
} |
| 3541 |
|
| 3542 |
} |
| 3543 |
|
| 3544 |
/** |
| 3545 |
* Creates a list of elements that can be sorted by the user via drag'n'drop. |
| 3546 |
* |
| 3547 |
* @package metaHTML |
| 3548 |
*/ |
| 3549 |
class htmlSortableList extends htmlElement { |
| 3550 |
|
| 3551 |
/** @var string[]|htmlElement[] $elements list of elements */ |
| 3552 |
private array $elements; |
| 3553 |
/** HTML ID */ |
| 3554 |
private string $id; |
| 3555 |
/** on update event */ |
| 3556 |
private ?string $onUpdate = null; |
| 3557 |
|
| 3558 |
/** |
| 3559 |
* Constructor. |
| 3560 |
* |
| 3561 |
* @param string[]|htmlElement[] $elements list of elements as text (HTML special chars must be escaped already) or htmlElement |
| 3562 |
* @param string $id HTML ID |
| 3563 |
*/ |
| 3564 |
public function __construct(array $elements, string $id) { |
| 3565 |
$this->elements = $elements; |
| 3566 |
$this->id = htmlspecialchars($id); |
| 3567 |
} |
| 3568 |
|
| 3569 |
/** |
| 3570 |
* {@inheritDoc} |
| 3571 |
*/ |
| 3572 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 3573 |
if (count($this->elements) === 0) { |
| 3574 |
return []; |
| 3575 |
} |
| 3576 |
$return = []; |
| 3577 |
$classesValue = ''; |
| 3578 |
if (!empty($this->cssClasses)) { |
| 3579 |
$classesValue = ' class="' . implode(' ', $this->cssClasses) . '"'; |
| 3580 |
} |
| 3581 |
echo '<ul' . $classesValue . ' id="' . $this->id . '">'; |
| 3582 |
for ($i = 0; $i < count($this->elements); $i++) { |
| 3583 |
$element = $this->elements[$i]; |
| 3584 |
echo '<li data-position-orig="' . $i . '">'; |
| 3585 |
echo '<span class="lam-sortable-list-icon"></span>'; |
| 3586 |
if ($element instanceof htmlElement) { |
| 3587 |
parseHtml($module, $element, $values, $restricted); |
| 3588 |
} |
| 3589 |
else { |
| 3590 |
echo $element; |
| 3591 |
} |
| 3592 |
echo '</li>'; |
| 3593 |
} |
| 3594 |
echo '</ul>'; |
| 3595 |
$onUpdate = ''; |
| 3596 |
if ($this->onUpdate !== null) { |
| 3597 |
$onUpdate = 'onUpdate: ' . $this->onUpdate; |
| 3598 |
} |
| 3599 |
$scriptContent = ' |
| 3600 |
Sortable.create( |
| 3601 |
document.getElementById("' . $this->id . '"), |
| 3602 |
{ |
| 3603 |
' . $onUpdate . ' |
| 3604 |
} |
| 3605 |
);'; |
| 3606 |
$script = new htmlJavaScript($scriptContent); |
| 3607 |
$script->generateHTML($module, $input, $values, $restricted); |
| 3608 |
return $return; |
| 3609 |
} |
| 3610 |
|
| 3611 |
/** |
| 3612 |
* Sets the JS code that is executed when the element order was changed. |
| 3613 |
* |
| 3614 |
* @param string $onUpdate JS code |
| 3615 |
*/ |
| 3616 |
public function setOnUpdate(string $onUpdate): void { |
| 3617 |
$this->onUpdate = $onUpdate; |
| 3618 |
} |
| 3619 |
|
| 3620 |
} |
| 3621 |
|
| 3622 |
/** |
| 3623 |
* Creates a list of content elements in accordion style. |
| 3624 |
* HTML special characters must be escaped before providing to htmlAccordion. |
| 3625 |
*/ |
| 3626 |
class htmlAccordion extends htmlElement { |
| 3627 |
|
| 3628 |
private string $id; |
| 3629 |
/** @var array<string, htmlElement> $elements elements */ |
| 3630 |
private array $elements; |
| 3631 |
/** @var int|false $openInitial initially opened tab */ |
| 3632 |
private mixed $openInitial; |
| 3633 |
private bool $saveState = false; |
| 3634 |
private bool $allowResorting = false; |
| 3635 |
|
| 3636 |
/** |
| 3637 |
* Constructor. |
| 3638 |
* |
| 3639 |
* @param string $id HTML ID |
| 3640 |
* @param array<string, htmlElement> $elements list of content elements array('title' => htmlElement) |
| 3641 |
* @param int|false $openInitial index of element that is initially opened (default: 0), set to 'false' to close all |
| 3642 |
*/ |
| 3643 |
public function __construct(string $id, array $elements, mixed $openInitial = 0) { |
| 3644 |
$this->id = $id; |
| 3645 |
$this->elements = $elements; |
| 3646 |
$this->openInitial = $openInitial; |
| 3647 |
} |
| 3648 |
|
| 3649 |
/** |
| 3650 |
* {@inheritDoc} |
| 3651 |
*/ |
| 3652 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 3653 |
$result = []; |
| 3654 |
if ($this->openInitial !== false) { |
| 3655 |
$this->addDataAttribute('openinitial', (string) $this->openInitial); |
| 3656 |
} |
| 3657 |
$cssClasses = $this->getCSSClasses(); |
| 3658 |
$cssClasses[] = 'lam-accordion-container'; |
| 3659 |
if ($this->saveState) { |
| 3660 |
$this->addDataAttribute('savestate', 'true'); |
| 3661 |
} |
| 3662 |
echo '<div id="' . $this->id . '" class="' . implode(' ', $cssClasses) . '"' . $this->getDataAttributesAsString() . '>'; |
| 3663 |
$contentIndex = 0; |
| 3664 |
foreach ($this->elements as $label => $content) { |
| 3665 |
echo '<button id="' . $this->id . '_' . $contentIndex . '" class="lam-accordion-button" onclick="return false;" data-index="' . $contentIndex . '">'; |
| 3666 |
echo $label; |
| 3667 |
echo '</button>'; |
| 3668 |
echo '<div class="lam-accordion-content" data-index="' . $contentIndex . '">'; |
| 3669 |
echo '<div class="lam-accordion-content-inner">'; |
| 3670 |
$result = array_merge($result, $content->generateHTML($module, $input, $values, $restricted)); |
| 3671 |
echo '</div>'; |
| 3672 |
echo '</div>'; |
| 3673 |
$contentIndex++; |
| 3674 |
} |
| 3675 |
$hiddenIndexId = $this->id . "_index"; |
| 3676 |
echo '<input type="hidden" name="' . $hiddenIndexId . '" id="' . $hiddenIndexId . '" value="false">'; |
| 3677 |
echo '</div>'; |
| 3678 |
if ($this->allowResorting) { |
| 3679 |
$onResorting = 'onUpdate: function() { |
| 3680 |
window.lam.html.updateAccordionSorting("' . $this->id . '"); |
| 3681 |
}'; |
| 3682 |
$scriptContent = ' |
| 3683 |
Sortable.create( |
| 3684 |
document.getElementById("' . $this->id . '"), |
| 3685 |
{ |
| 3686 |
' . $onResorting . ' |
| 3687 |
} |
| 3688 |
);'; |
| 3689 |
$resortingGroup = new htmlGroup(); |
| 3690 |
$script = new htmlJavaScript($scriptContent); |
| 3691 |
$resortingGroup->addElement($script); |
| 3692 |
$resortingGroup->addElement(new htmlHiddenInput($this->id . '_sorting', '')); |
| 3693 |
$resortingGroup->generateHTML($module, $input, $values, $restricted); |
| 3694 |
} |
| 3695 |
return $result; |
| 3696 |
} |
| 3697 |
|
| 3698 |
/** |
| 3699 |
* Saves the state of open/closed items over page reloads. |
| 3700 |
* |
| 3701 |
* @param bool $saveState save state |
| 3702 |
*/ |
| 3703 |
public function saveState(bool $saveState = true): void { |
| 3704 |
$this->saveState = $saveState; |
| 3705 |
} |
| 3706 |
|
| 3707 |
/** |
| 3708 |
* Allows the user to resort the accordion elements. |
| 3709 |
*/ |
| 3710 |
public function allowResorting(): void { |
| 3711 |
$this->allowResorting = true; |
| 3712 |
} |
| 3713 |
|
| 3714 |
} |
| 3715 |
|
| 3716 |
/** |
| 3717 |
* Responsive row with 12 column layout. |
| 3718 |
*/ |
| 3719 |
class htmlResponsiveRow extends htmlElement { |
| 3720 |
|
| 3721 |
/** @var htmlResponsiveCell[] $cells cells */ |
| 3722 |
private array $cells = []; |
| 3723 |
/** HTML ID */ |
| 3724 |
private ?string $id = null; |
| 3725 |
private ?string $onClick = null; |
| 3726 |
|
| 3727 |
/** |
| 3728 |
* Creates a new responsive row. |
| 3729 |
* |
| 3730 |
* @param htmlElement $label label element if this is a simple label+field row |
| 3731 |
* @param htmlElement $field field element if this is a simple label+field row |
| 3732 |
*/ |
| 3733 |
public function __construct($label = null, $field = null) { |
| 3734 |
if ($label != null) { |
| 3735 |
$this->addLabel($label); |
| 3736 |
} |
| 3737 |
if ($field != null) { |
| 3738 |
$this->addField($field); |
| 3739 |
} |
| 3740 |
} |
| 3741 |
|
| 3742 |
/** |
| 3743 |
* Sets the HTML id. |
| 3744 |
* |
| 3745 |
* @param string|null $id ID |
| 3746 |
*/ |
| 3747 |
public function setId(?string $id): void { |
| 3748 |
$this->id = $id; |
| 3749 |
} |
| 3750 |
|
| 3751 |
/** |
| 3752 |
* Adds a responsive cell at the end of the row. |
| 3753 |
* |
| 3754 |
* @param htmlResponsiveCell $cell cell |
| 3755 |
*/ |
| 3756 |
public function addCell(htmlResponsiveCell $cell): void { |
| 3757 |
$this->cells[] = $cell; |
| 3758 |
} |
| 3759 |
|
| 3760 |
/** |
| 3761 |
* Adds a responsive cell at the beginning of the row. |
| 3762 |
* |
| 3763 |
* @param htmlResponsiveCell $cell cell |
| 3764 |
*/ |
| 3765 |
public function addCellAtTheBeginning(htmlResponsiveCell $cell): void { |
| 3766 |
array_unshift($this->cells, $cell); |
| 3767 |
} |
| 3768 |
|
| 3769 |
/** |
| 3770 |
* Adds a cell with the given content and column counts. |
| 3771 |
* |
| 3772 |
* @param htmlElement $content content inside cell |
| 3773 |
* @param int $numMobile number of columns for mobile view |
| 3774 |
* @param int|null $numTablet number of columns for tablet view (set to mobile if null) |
| 3775 |
* @param int|null $numDesktop number of columns for desktop view (set to tablet if null) |
| 3776 |
* @param string $classes CSS classes separated by space |
| 3777 |
*/ |
| 3778 |
public function add(htmlElement $content, int $numMobile = 12, ?int $numTablet = null, ?int $numDesktop = null, string $classes = ''): void { |
| 3779 |
$tabletCols = $numTablet ?? $numMobile; |
| 3780 |
$desktopCols = $numDesktop ?? $tabletCols; |
| 3781 |
$this->addCell(new htmlResponsiveCell($content, $numMobile, $tabletCols, $desktopCols, $classes)); |
| 3782 |
} |
| 3783 |
|
| 3784 |
/** |
| 3785 |
* Adds a cell at the beginning with the given content and column counts. |
| 3786 |
* |
| 3787 |
* @param htmlElement $content content inside cell |
| 3788 |
* @param int $numMobile number of columns for mobile view |
| 3789 |
* @param int|null $numTablet number of columns for tablet view (set to mobile if null) |
| 3790 |
* @param int|null $numDesktop number of columns for desktop view (set to tablet if null) |
| 3791 |
* @param string $classes CSS classes separated by space |
| 3792 |
*/ |
| 3793 |
public function addAtTheBeginning(htmlElement $content, int $numMobile = 12, ?int $numTablet = null, ?int $numDesktop = null, string $classes = ''): void { |
| 3794 |
$tabletCols = $numTablet ?? $numMobile; |
| 3795 |
$desktopCols = $numDesktop ?? $tabletCols; |
| 3796 |
$this->addCellAtTheBeginning(new htmlResponsiveCell($content, $numMobile, $tabletCols, $desktopCols, $classes)); |
| 3797 |
} |
| 3798 |
|
| 3799 |
/** |
| 3800 |
* Adds the content as a typical label with 12/6/6 columns and CSS class "responsiveLabel". |
| 3801 |
* |
| 3802 |
* @param htmlElement $content label |
| 3803 |
* @param string $cssClasses additional CSS classes |
| 3804 |
*/ |
| 3805 |
public function addLabel(htmlElement $content, string $cssClasses = ''): void { |
| 3806 |
$this->add($content, 12, 6, 6, 'responsiveLabel nowrap ' . $cssClasses); |
| 3807 |
} |
| 3808 |
|
| 3809 |
/** |
| 3810 |
* Adds the content as a typical field with 12/6/6 columns and CSS class "responsiveField". |
| 3811 |
* |
| 3812 |
* @param htmlElement $content field |
| 3813 |
* @param string $cssClasses CSS class names separated by space |
| 3814 |
*/ |
| 3815 |
public function addField(htmlElement $content, string $cssClasses = ''): void { |
| 3816 |
$this->add($content, 12, 6, 6, 'responsiveField ' . $cssClasses); |
| 3817 |
} |
| 3818 |
|
| 3819 |
/** |
| 3820 |
* {@inheritDoc} |
| 3821 |
*/ |
| 3822 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 3823 |
$return = []; |
| 3824 |
$cssClasses = implode(' ', $this->cssClasses); |
| 3825 |
$idParam = ''; |
| 3826 |
if ($this->id !== null) { |
| 3827 |
$idParam = ' id="' . $this->id . '"'; |
| 3828 |
} |
| 3829 |
$onClickCode = ''; |
| 3830 |
if (!empty($this->onClick)) { |
| 3831 |
$onClickCode = ' onclick="' . $this->onClick . '"'; |
| 3832 |
} |
| 3833 |
echo '<div class="row ' . $cssClasses . '"' . $this->getDataAttributesAsString() . $idParam . $onClickCode . '>'; |
| 3834 |
foreach ($this->cells as $cell) { |
| 3835 |
$return = array_merge($return, $cell->generateHTML($module, $input, $values, $restricted)); |
| 3836 |
} |
| 3837 |
echo '</div>'; |
| 3838 |
return $return; |
| 3839 |
} |
| 3840 |
|
| 3841 |
/** |
| 3842 |
* Adds a vertical spacer with 12 columns. |
| 3843 |
* |
| 3844 |
* @param string $space space in px or rem |
| 3845 |
*/ |
| 3846 |
public function addVerticalSpacer(string $space): void { |
| 3847 |
$this->add(new htmlSpacer(null, $space)); |
| 3848 |
} |
| 3849 |
|
| 3850 |
/** |
| 3851 |
* Returns the current number of cells. |
| 3852 |
* |
| 3853 |
* @return int cell count |
| 3854 |
*/ |
| 3855 |
public function getCellCount(): int { |
| 3856 |
return count($this->cells); |
| 3857 |
} |
| 3858 |
|
| 3859 |
public function setOnClick(string $code): void { |
| 3860 |
$this->onClick = $code; |
| 3861 |
} |
| 3862 |
|
| 3863 |
} |
| 3864 |
|
| 3865 |
/** |
| 3866 |
* Responsive cell inside htmlResponsiveRow with 12 column layout. |
| 3867 |
*/ |
| 3868 |
class htmlResponsiveCell extends htmlElement { |
| 3869 |
|
| 3870 |
private htmlElement $content; |
| 3871 |
private int $mobile; |
| 3872 |
private ?int $tablet; |
| 3873 |
private ?int $desktop; |
| 3874 |
private string $classes; |
| 3875 |
|
| 3876 |
/** |
| 3877 |
* Constructs a cell inside a responsive row with 12 columns. |
| 3878 |
* |
| 3879 |
* @param htmlElement $content content inside cell |
| 3880 |
* @param int $numMobile number of columns for mobile view |
| 3881 |
* @param int|null $numTablet number of columns for tablet view |
| 3882 |
* @param int|null $numDesktop number of columns for desktop view |
| 3883 |
* @param string $classes CSS classes separated by space |
| 3884 |
*/ |
| 3885 |
public function __construct(htmlElement $content, int $numMobile, ?int $numTablet, ?int $numDesktop, string $classes = '') { |
| 3886 |
$this->content = $content; |
| 3887 |
$this->mobile = $numMobile; |
| 3888 |
$this->tablet = $numTablet; |
| 3889 |
$this->desktop = $numDesktop; |
| 3890 |
$this->classes = $classes; |
| 3891 |
} |
| 3892 |
|
| 3893 |
/** |
| 3894 |
* {@inheritDoc} |
| 3895 |
*/ |
| 3896 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 3897 |
$clMobile = ($this->mobile > 0) ? 'small-' . $this->mobile : 'hide-for-small-only'; |
| 3898 |
$clTablet = ($this->tablet > 0) ? 'medium-' . $this->tablet : 'hide-for-medium-only'; |
| 3899 |
$clDesktop = ($this->desktop > 0) ? 'large-' . $this->desktop : 'hide-for-large-only'; |
| 3900 |
|
| 3901 |
echo '<div class="' . $clMobile . ' ' . $clTablet . ' ' . $clDesktop . ' columns ' . $this->classes . '">'; |
| 3902 |
$return = $this->content->generateHTML($module, $input, $values, $restricted); |
| 3903 |
echo '</div>'; |
| 3904 |
return $return; |
| 3905 |
} |
| 3906 |
|
| 3907 |
} |
| 3908 |
|
| 3909 |
/** |
| 3910 |
* A responsive input field that combines label, input field and help. |
| 3911 |
* |
| 3912 |
* @package metaHTML |
| 3913 |
*/ |
| 3914 |
class htmlResponsiveInputField extends htmlInputField { |
| 3915 |
|
| 3916 |
/** Descriptive label */ |
| 3917 |
private string $label; |
| 3918 |
/** help ID */ |
| 3919 |
private ?string $helpID = null; |
| 3920 |
/** help module name */ |
| 3921 |
private ?string $helpModule = null; |
| 3922 |
/** render HTML of parent class */ |
| 3923 |
private bool $renderParentHtml = false; |
| 3924 |
/** short label */ |
| 3925 |
private bool $shortLabel = false; |
| 3926 |
|
| 3927 |
/** |
| 3928 |
* Constructor |
| 3929 |
* |
| 3930 |
* @param string $label descriptive label |
| 3931 |
* @param string $fieldName unique field name |
| 3932 |
* @param string $fieldValue value of input field (optional) |
| 3933 |
* @param string|string[]|null $helpID help ID or array of help ID + module name (optional) |
| 3934 |
* @param bool $required field is required |
| 3935 |
*/ |
| 3936 |
public function __construct($label, $fieldName, $fieldValue = null, $helpID = null, $required = false) { |
| 3937 |
parent::__construct($fieldName, $fieldValue); |
| 3938 |
$this->label = $label; |
| 3939 |
if (is_string($helpID)) { |
| 3940 |
$this->helpID = $helpID; |
| 3941 |
} |
| 3942 |
elseif (is_array($helpID)) { |
| 3943 |
$this->helpID = $helpID[0]; |
| 3944 |
$this->helpModule = $helpID[1]; |
| 3945 |
} |
| 3946 |
$this->fieldSize = null; |
| 3947 |
$this->required = $required; |
| 3948 |
} |
| 3949 |
|
| 3950 |
/** |
| 3951 |
* {@inheritDoc} |
| 3952 |
*/ |
| 3953 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 3954 |
if ($this->renderParentHtml) { |
| 3955 |
return parent::generateHTML($module, $input, $values, $restricted); |
| 3956 |
} |
| 3957 |
// HTML of parent class is rendered on second call (done by htmlResponsiveRow) |
| 3958 |
$this->renderParentHtml = true; |
| 3959 |
$row = new htmlResponsiveRow(); |
| 3960 |
// label text |
| 3961 |
$labelGroup = new htmlGroup(); |
| 3962 |
$idValue = $this->id ?? $this->fieldName; |
| 3963 |
$labelGroup->addElement(new htmlLabel($idValue, $this->label)); |
| 3964 |
if ($this->required) { |
| 3965 |
$labelGroup->addElement(htmlGetRequiredMarkerElement()); |
| 3966 |
} |
| 3967 |
if (!empty($this->helpID)) { |
| 3968 |
$helpLinkLabel = new htmlHelpLink($this->helpID, $this->helpModule); |
| 3969 |
$helpLinkLabel->setCSSClasses(['hide-on-tablet', 'margin-left5']); |
| 3970 |
$labelGroup->addElement($helpLinkLabel); |
| 3971 |
} |
| 3972 |
$tabletDesktopLabelColumns = $this->shortLabel ? 4 : 6; |
| 3973 |
$row->add($labelGroup, 12, $tabletDesktopLabelColumns, $tabletDesktopLabelColumns, 'responsiveLabel'); |
| 3974 |
// input field |
| 3975 |
$fieldGroup = new htmlGroup(); |
| 3976 |
$fieldGroup->addElement($this); |
| 3977 |
if (!empty($this->helpID)) { |
| 3978 |
$helpLinkField = new htmlHelpLink($this->helpID, $this->helpModule); |
| 3979 |
$helpLinkField->setCSSClasses(['hide-on-mobile']); |
| 3980 |
$fieldGroup->addElement($helpLinkField); |
| 3981 |
} |
| 3982 |
$tabletDesktopFieldColumns = $this->shortLabel ? 8 : 6; |
| 3983 |
$row->add($fieldGroup, 12, $tabletDesktopFieldColumns, $tabletDesktopFieldColumns, 'responsiveField nowrap'); |
| 3984 |
return $row->generateHTML($module, $input, $values, $restricted); |
| 3985 |
} |
| 3986 |
|
| 3987 |
/** |
| 3988 |
* Use a short label (4 columns instead of 6) for tablet/desktop. |
| 3989 |
*/ |
| 3990 |
public function setShortLabel(): void { |
| 3991 |
$this->shortLabel = true; |
| 3992 |
} |
| 3993 |
|
| 3994 |
/** |
| 3995 |
* Sets the help ID. |
| 3996 |
* |
| 3997 |
* @param string|null $helpID help ID |
| 3998 |
*/ |
| 3999 |
public function setHelpId(?string $helpID): void { |
| 4000 |
$this->helpID = $helpID; |
| 4001 |
} |
| 4002 |
|
| 4003 |
/** |
| 4004 |
* Sets the help module. |
| 4005 |
* |
| 4006 |
* @param string|null $helpModule help module name |
| 4007 |
*/ |
| 4008 |
public function setHelpModule(?string $helpModule): void { |
| 4009 |
$this->helpModule = $helpModule; |
| 4010 |
} |
| 4011 |
|
| 4012 |
} |
| 4013 |
|
| 4014 |
/** |
| 4015 |
* File upload with descriptive label and help link. |
| 4016 |
* |
| 4017 |
* @package metaHTML |
| 4018 |
*/ |
| 4019 |
class htmlResponsiveInputFileUpload extends htmlInputFileUpload { |
| 4020 |
|
| 4021 |
/** descriptive label */ |
| 4022 |
private string $label; |
| 4023 |
/** help ID */ |
| 4024 |
private ?string $helpID = null; |
| 4025 |
/** help module */ |
| 4026 |
private ?string $helpModule = null; |
| 4027 |
/** render HTML of parent class */ |
| 4028 |
private bool $renderParentHtml = false; |
| 4029 |
|
| 4030 |
/** |
| 4031 |
* Constructor. |
| 4032 |
* |
| 4033 |
* @param string $name unique name |
| 4034 |
* @param string $label descriptive label |
| 4035 |
* @param string|string[]|null $helpID help ID |
| 4036 |
* @param bool $required required field |
| 4037 |
*/ |
| 4038 |
public function __construct($name, string $label, $helpID = null, $required = false) { |
| 4039 |
parent::__construct($name); |
| 4040 |
$this->label = htmlspecialchars($label); |
| 4041 |
if (is_string($helpID)) { |
| 4042 |
$this->helpID = $helpID; |
| 4043 |
} |
| 4044 |
elseif (is_array($helpID)) { |
| 4045 |
$this->helpID = $helpID[0]; |
| 4046 |
$this->helpModule = $helpID[1]; |
| 4047 |
} |
| 4048 |
$this->required = $required; |
| 4049 |
} |
| 4050 |
|
| 4051 |
/** |
| 4052 |
* {@inheritDoc} |
| 4053 |
*/ |
| 4054 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 4055 |
if ($this->renderParentHtml) { |
| 4056 |
return parent::generateHTML($module, $input, $values, $restricted); |
| 4057 |
} |
| 4058 |
// HTML of parent class is rendered on second call (done by htmlResponsiveRow) |
| 4059 |
$this->renderParentHtml = true; |
| 4060 |
$row = new htmlResponsiveRow(); |
| 4061 |
// label text |
| 4062 |
$labelGroup = new htmlGroup(); |
| 4063 |
$labelGroup->addElement(new htmlOutputText($this->label)); |
| 4064 |
if ($this->required) { |
| 4065 |
$labelGroup->addElement(htmlGetRequiredMarkerElement()); |
| 4066 |
} |
| 4067 |
if (!empty($this->helpID)) { |
| 4068 |
$helpLinkLabel = new htmlHelpLink($this->helpID, $this->helpModule); |
| 4069 |
$helpLinkLabel->setCSSClasses(['hide-on-tablet', 'margin-left5']); |
| 4070 |
$labelGroup->addElement($helpLinkLabel); |
| 4071 |
} |
| 4072 |
$row->add($labelGroup, 12, 6, 6, 'responsiveLabel'); |
| 4073 |
// input field |
| 4074 |
$fieldGroup = new htmlGroup(); |
| 4075 |
$fieldGroup->addElement($this); |
| 4076 |
if (!empty($this->helpID)) { |
| 4077 |
$helpLinkField = new htmlHelpLink($this->helpID, $this->helpModule); |
| 4078 |
$helpLinkField->setCSSClasses(['hide-on-mobile']); |
| 4079 |
$fieldGroup->addElement($helpLinkField); |
| 4080 |
} |
| 4081 |
$row->add($fieldGroup, 12, 6, 6, 'responsiveField nowrap'); |
| 4082 |
return $row->generateHTML($module, $input, $values, $restricted); |
| 4083 |
} |
| 4084 |
|
| 4085 |
} |
| 4086 |
|
| 4087 |
/** |
| 4088 |
* Responsive text area with label and help link. |
| 4089 |
* |
| 4090 |
* @package metaHTML |
| 4091 |
*/ |
| 4092 |
class htmlResponsiveInputTextarea extends htmlInputTextarea { |
| 4093 |
|
| 4094 |
/** descriptive label */ |
| 4095 |
private string $label; |
| 4096 |
/** help ID */ |
| 4097 |
private ?string $helpID = null; |
| 4098 |
/** help module */ |
| 4099 |
private ?string $helpModule = null; |
| 4100 |
/** render HTML of parent class */ |
| 4101 |
private bool $renderParentHtml = false; |
| 4102 |
/** short label */ |
| 4103 |
private bool $shortLabel = false; |
| 4104 |
|
| 4105 |
/** |
| 4106 |
* Constructor. |
| 4107 |
* |
| 4108 |
* @param string $name unique name |
| 4109 |
* @param string $value value |
| 4110 |
* @param int $colCount number of characters per line |
| 4111 |
* @param int $rowCount number of rows |
| 4112 |
* @param string $label descriptive label |
| 4113 |
* @param string|string[] $helpID help ID |
| 4114 |
*/ |
| 4115 |
public function __construct($name, $value, $colCount, $rowCount, string $label, $helpID = null) { |
| 4116 |
parent::__construct($name, $value, $colCount, $rowCount); |
| 4117 |
$this->label = htmlspecialchars($label); |
| 4118 |
if (is_string($helpID)) { |
| 4119 |
$this->helpID = $helpID; |
| 4120 |
} |
| 4121 |
elseif (is_array($helpID)) { |
| 4122 |
$this->helpID = $helpID[0]; |
| 4123 |
$this->helpModule = $helpID[1]; |
| 4124 |
} |
| 4125 |
$this->alignment = htmlElement::ALIGN_TOP; |
| 4126 |
} |
| 4127 |
|
| 4128 |
/** |
| 4129 |
* {@inheritDoc} |
| 4130 |
*/ |
| 4131 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 4132 |
if ($this->renderParentHtml) { |
| 4133 |
return parent::generateHTML($module, $input, $values, $restricted); |
| 4134 |
} |
| 4135 |
// HTML of parent class is rendered on second call (done by htmlResponsiveRow) |
| 4136 |
$this->renderParentHtml = true; |
| 4137 |
$row = new htmlResponsiveRow(); |
| 4138 |
// label text |
| 4139 |
$labelGroup = new htmlGroup(); |
| 4140 |
$labelGroup->addElement(new htmlLabel($this->name, $this->label)); |
| 4141 |
if ($this->required) { |
| 4142 |
$labelGroup->addElement(htmlGetRequiredMarkerElement()); |
| 4143 |
} |
| 4144 |
if (!empty($this->helpID)) { |
| 4145 |
$helpLinkLabel = new htmlHelpLink($this->helpID, $this->helpModule); |
| 4146 |
$helpCssClasses = ['margin-left5']; |
| 4147 |
if (!$this->richEdit) { |
| 4148 |
$helpCssClasses[] = 'hide-on-tablet'; |
| 4149 |
} |
| 4150 |
$helpLinkLabel->setCSSClasses($helpCssClasses); |
| 4151 |
$labelGroup->addElement($helpLinkLabel); |
| 4152 |
} |
| 4153 |
$tabletDesktopLabelColumns = $this->shortLabel ? 4 : 6; |
| 4154 |
$row->add($labelGroup, 12, $tabletDesktopLabelColumns, $tabletDesktopLabelColumns, 'responsiveLabel'); |
| 4155 |
// input field |
| 4156 |
$fieldGroup = new htmlGroup(); |
| 4157 |
$fieldGroup->addElement($this); |
| 4158 |
if (!empty($this->helpID) && !$this->richEdit) { |
| 4159 |
$helpLink = new htmlHelpLink($this->helpID, $this->helpModule); |
| 4160 |
$helpLink->setCSSClasses(['align-top', 'hide-on-mobile']); |
| 4161 |
$fieldGroup->addElement($helpLink); |
| 4162 |
} |
| 4163 |
$tabletDesktopFieldColumns = $this->shortLabel ? 8 : 6; |
| 4164 |
$row->add($fieldGroup, 12, $tabletDesktopFieldColumns, $tabletDesktopFieldColumns, 'responsiveField nowrap'); |
| 4165 |
return $row->generateHTML($module, $input, $values, $restricted); |
| 4166 |
} |
| 4167 |
|
| 4168 |
/** |
| 4169 |
* Use a short label (4 columns instead of 6) for tablet/desktop. |
| 4170 |
*/ |
| 4171 |
public function setShortLabel(): void { |
| 4172 |
$this->shortLabel = true; |
| 4173 |
} |
| 4174 |
|
| 4175 |
/** |
| 4176 |
* Sets the help ID. |
| 4177 |
* |
| 4178 |
* @param string|null $helpID help ID |
| 4179 |
*/ |
| 4180 |
public function setHelpId(?string $helpID): void { |
| 4181 |
$this->helpID = $helpID; |
| 4182 |
} |
| 4183 |
|
| 4184 |
/** |
| 4185 |
* Sets the help module. |
| 4186 |
* |
| 4187 |
* @param string|null $helpModule help module name |
| 4188 |
*/ |
| 4189 |
public function setHelpModule(?string $helpModule): void { |
| 4190 |
$this->helpModule = $helpModule; |
| 4191 |
} |
| 4192 |
|
| 4193 |
} |
| 4194 |
|
| 4195 |
/** |
| 4196 |
* Responsive select with label and help link. |
| 4197 |
* |
| 4198 |
* @package metaHTML |
| 4199 |
*/ |
| 4200 |
class htmlResponsiveSelect extends htmlSelect { |
| 4201 |
|
| 4202 |
/** descriptive label */ |
| 4203 |
private string $label; |
| 4204 |
/** help ID */ |
| 4205 |
private ?string $helpID = null; |
| 4206 |
/** help module name */ |
| 4207 |
private ?string $helpModule = null; |
| 4208 |
/** render HTML of parent class */ |
| 4209 |
private bool $renderParentHtml = false; |
| 4210 |
/** short label */ |
| 4211 |
private bool $shortLabel = false; |
| 4212 |
|
| 4213 |
/** |
| 4214 |
* Constructor. |
| 4215 |
* |
| 4216 |
* @param string $name element name |
| 4217 |
* @param string[]|array<string, string>|array<string, string[]|array<string, string>> $elements list of elements |
| 4218 |
* @param string[] $selectedElements list of selected elements |
| 4219 |
* @param string $label descriptive label |
| 4220 |
* @param string|string[] $helpID help ID or array of help ID + module name (optional) |
| 4221 |
* @param int $size size (optional, default = 1) |
| 4222 |
*/ |
| 4223 |
public function __construct($name, $elements, $selectedElements, string $label, $helpID = null, $size = 1) { |
| 4224 |
parent::__construct($name, $elements, $selectedElements, $size); |
| 4225 |
$this->label = $label; |
| 4226 |
if (is_string($helpID)) { |
| 4227 |
$this->helpID = $helpID; |
| 4228 |
} |
| 4229 |
elseif (is_array($helpID)) { |
| 4230 |
$this->helpID = $helpID[0]; |
| 4231 |
$this->helpModule = $helpID[1]; |
| 4232 |
} |
| 4233 |
} |
| 4234 |
|
| 4235 |
/** |
| 4236 |
* {@inheritDoc} |
| 4237 |
*/ |
| 4238 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 4239 |
if ($this->renderParentHtml) { |
| 4240 |
return parent::generateHTML($module, $input, $values, $restricted); |
| 4241 |
} |
| 4242 |
// HTML of parent class is rendered on second call (done by htmlResponsiveRow) |
| 4243 |
$this->renderParentHtml = true; |
| 4244 |
$row = new htmlResponsiveRow(); |
| 4245 |
// label text |
| 4246 |
$labelGroup = new htmlGroup(); |
| 4247 |
$labelGroup->addElement(new htmlLabel($this->name, $this->label)); |
| 4248 |
if (!empty($this->helpID)) { |
| 4249 |
$helpLinkLabel = new htmlHelpLink($this->helpID, $this->helpModule); |
| 4250 |
$helpLinkLabel->setCSSClasses(['hide-on-tablet', 'margin-left5']); |
| 4251 |
$labelGroup->addElement($helpLinkLabel); |
| 4252 |
} |
| 4253 |
$tabletDesktopLabelColumns = $this->shortLabel ? 4 : 6; |
| 4254 |
$row->add($labelGroup, 12, $tabletDesktopLabelColumns, $tabletDesktopLabelColumns, 'responsiveLabel'); |
| 4255 |
// input field |
| 4256 |
$fieldGroup = new htmlGroup(); |
| 4257 |
$fieldGroup->addElement($this); |
| 4258 |
if (!empty($this->helpID)) { |
| 4259 |
$helpLink = new htmlHelpLink($this->helpID, $this->helpModule); |
| 4260 |
$helpLink->setCSSClasses(['hide-on-mobile']); |
| 4261 |
$fieldGroup->addElement($helpLink); |
| 4262 |
} |
| 4263 |
$tabletDesktopFieldColumns = $this->shortLabel ? 8 : 6; |
| 4264 |
$row->add($fieldGroup, 12, $tabletDesktopFieldColumns, $tabletDesktopFieldColumns, 'responsiveField nowrap'); |
| 4265 |
return $row->generateHTML($module, $input, $values, $restricted); |
| 4266 |
} |
| 4267 |
|
| 4268 |
/** |
| 4269 |
* {@inheritDoc} |
| 4270 |
* @see htmlSelect::getShowHideSelector() |
| 4271 |
*/ |
| 4272 |
protected function getShowHideSelector(): string { |
| 4273 |
return '.row'; |
| 4274 |
} |
| 4275 |
|
| 4276 |
/** |
| 4277 |
* Use a short label (4 columns instead of 6) for tablet/desktop. |
| 4278 |
*/ |
| 4279 |
public function setShortLabel(): void { |
| 4280 |
$this->shortLabel = true; |
| 4281 |
} |
| 4282 |
|
| 4283 |
} |
| 4284 |
|
| 4285 |
/** |
| 4286 |
* Responsive select with label and help link. |
| 4287 |
* |
| 4288 |
* @package metaHTML |
| 4289 |
*/ |
| 4290 |
class htmlResponsiveRadio extends htmlRadio { |
| 4291 |
|
| 4292 |
/** descriptive label */ |
| 4293 |
private string $label; |
| 4294 |
/** help ID */ |
| 4295 |
private ?string $helpID; |
| 4296 |
/** render HTML of parent class */ |
| 4297 |
private bool $renderParentHtml = false; |
| 4298 |
|
| 4299 |
/** |
| 4300 |
* Constructor. |
| 4301 |
* |
| 4302 |
* @param string $label descriptive label |
| 4303 |
* @param string $name element name |
| 4304 |
* @param array<string, string> $elements list of elements |
| 4305 |
* @param string|null $selectedElement list of selected elements |
| 4306 |
* @param string|null $helpID help ID (optional, default none) |
| 4307 |
*/ |
| 4308 |
public function __construct(string $label, $name, $elements, ?string $selectedElement = null, ?string $helpID = null) { |
| 4309 |
parent::__construct($name, $elements, $selectedElement); |
| 4310 |
$this->label = htmlspecialchars($label); |
| 4311 |
$this->helpID = $helpID; |
| 4312 |
} |
| 4313 |
|
| 4314 |
/** |
| 4315 |
* {@inheritDoc} |
| 4316 |
*/ |
| 4317 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 4318 |
if ($this->renderParentHtml) { |
| 4319 |
return parent::generateHTML($module, $input, $values, $restricted); |
| 4320 |
} |
| 4321 |
// HTML of parent class is rendered on second call (done by htmlResponsiveRow) |
| 4322 |
$this->renderParentHtml = true; |
| 4323 |
$row = new htmlResponsiveRow(); |
| 4324 |
// label text |
| 4325 |
$labelGroup = new htmlGroup(); |
| 4326 |
$labelGroup->addElement(new htmlOutputText($this->label)); |
| 4327 |
if (!empty($this->helpID)) { |
| 4328 |
$helpLinkLabel = new htmlHelpLink($this->helpID); |
| 4329 |
$helpLinkLabel->setCSSClasses(['hide-on-tablet', 'margin-left5']); |
| 4330 |
$labelGroup->addElement($helpLinkLabel); |
| 4331 |
} |
| 4332 |
$row->add($labelGroup, 12, 6, 6, 'responsiveLabel'); |
| 4333 |
// input field |
| 4334 |
$fieldGroup = new htmlGroup(); |
| 4335 |
$fieldGroup->addElement(new htmlDiv(null, $this, ['float-left'])); |
| 4336 |
if (!empty($this->helpID)) { |
| 4337 |
$helpLink = new htmlHelpLink($this->helpID); |
| 4338 |
$helpLink->setCSSClasses(['hide-on-mobile']); |
| 4339 |
$fieldGroup->addElement(new htmlDiv(null, $helpLink)); |
| 4340 |
} |
| 4341 |
$row->add($fieldGroup, 12, 6, 6, 'responsiveField nowrap'); |
| 4342 |
return $row->generateHTML($module, $input, $values, $restricted); |
| 4343 |
} |
| 4344 |
|
| 4345 |
/** |
| 4346 |
* Returns the selector to use to find the show/hide elements. |
| 4347 |
* |
| 4348 |
* @return string selector |
| 4349 |
*/ |
| 4350 |
protected function getShowHideSelector(): string { |
| 4351 |
return '.row'; |
| 4352 |
} |
| 4353 |
|
| 4354 |
} |
| 4355 |
|
| 4356 |
/** |
| 4357 |
* Responsive checkbox with descriptive label and help link. |
| 4358 |
* |
| 4359 |
* @package metaHTML |
| 4360 |
*/ |
| 4361 |
class htmlResponsiveInputCheckbox extends htmlInputCheckbox { |
| 4362 |
|
| 4363 |
/** descriptive label */ |
| 4364 |
private string $label; |
| 4365 |
/** help ID */ |
| 4366 |
private ?string $helpID = null; |
| 4367 |
/** help module name */ |
| 4368 |
private ?string $helpModule = null; |
| 4369 |
/** render HTML of parent class */ |
| 4370 |
private bool $renderParentHtml = false; |
| 4371 |
/** long label */ |
| 4372 |
private bool $longLabel; |
| 4373 |
/** label after checkbox */ |
| 4374 |
private bool $labelAfterCheckbox = false; |
| 4375 |
/** short label */ |
| 4376 |
private bool $shortLabel = false; |
| 4377 |
|
| 4378 |
/** |
| 4379 |
* Constructor. |
| 4380 |
* |
| 4381 |
* @param string $name unique name |
| 4382 |
* @param bool $checked checked |
| 4383 |
* @param string $label descriptive label |
| 4384 |
* @param string|string[] $helpID help ID or array of help ID + module name (optional) |
| 4385 |
* @param bool $longLabel more space for label (default: false) |
| 4386 |
*/ |
| 4387 |
public function __construct($name, $checked, string $label, $helpID = null, $longLabel = false) { |
| 4388 |
parent::__construct($name, $checked); |
| 4389 |
$this->label = $label; |
| 4390 |
if (is_string($helpID)) { |
| 4391 |
$this->helpID = $helpID; |
| 4392 |
} |
| 4393 |
elseif (is_array($helpID)) { |
| 4394 |
$this->helpID = $helpID[0]; |
| 4395 |
$this->helpModule = $helpID[1]; |
| 4396 |
} |
| 4397 |
$this->longLabel = $longLabel; |
| 4398 |
} |
| 4399 |
|
| 4400 |
/** |
| 4401 |
* {@inheritDoc} |
| 4402 |
*/ |
| 4403 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 4404 |
if ($this->renderParentHtml) { |
| 4405 |
return parent::generateHTML($module, $input, $values, $restricted); |
| 4406 |
} |
| 4407 |
// HTML of parent class is rendered on second call (done by htmlResponsiveRow) |
| 4408 |
$this->renderParentHtml = true; |
| 4409 |
$row = new htmlResponsiveRow(); |
| 4410 |
$tabletColumnsLabel = 6; |
| 4411 |
$tabletColumnsBox = 6; |
| 4412 |
$mobileColumnsLabel = 10; |
| 4413 |
$mobileColumnsBox = 2; |
| 4414 |
if ($this->longLabel) { |
| 4415 |
$tabletColumnsLabel = 10; |
| 4416 |
$tabletColumnsBox = 2; |
| 4417 |
} |
| 4418 |
if ($this->shortLabel) { |
| 4419 |
$tabletColumnsLabel = 4; |
| 4420 |
$tabletColumnsBox = 8; |
| 4421 |
} |
| 4422 |
// label text |
| 4423 |
$text = new htmlLabel($this->getName(), $this->label); |
| 4424 |
$text->setCSSClasses($this->cssClasses); |
| 4425 |
// input field |
| 4426 |
$fieldGroup = new htmlGroup(); |
| 4427 |
$fieldGroup->addElement($this); |
| 4428 |
if (!empty($this->helpID)) { |
| 4429 |
$helpLink = new htmlHelpLink($this->helpID, $this->helpModule); |
| 4430 |
$helpLink->setCSSClasses(['margin-left5 align-unset-img']); |
| 4431 |
$fieldGroup->addElement($helpLink); |
| 4432 |
} |
| 4433 |
if ($this->labelAfterCheckbox) { |
| 4434 |
$row->add($fieldGroup, $mobileColumnsBox, $tabletColumnsBox, $tabletColumnsBox, 'responsiveLabel nowrap'); |
| 4435 |
$row->add($text, $mobileColumnsLabel, $tabletColumnsLabel, $tabletColumnsLabel, 'responsiveField'); |
| 4436 |
} |
| 4437 |
else { |
| 4438 |
$row->add($text, $mobileColumnsLabel, $tabletColumnsLabel, $tabletColumnsLabel, 'responsiveLabel'); |
| 4439 |
$row->add($fieldGroup, $mobileColumnsBox, $tabletColumnsBox, $tabletColumnsBox, 'responsiveField nowrap'); |
| 4440 |
} |
| 4441 |
return $row->generateHTML($module, $input, $values, $restricted); |
| 4442 |
} |
| 4443 |
|
| 4444 |
/** |
| 4445 |
* {@inheritDoc} |
| 4446 |
* @see htmlInputCheckbox::getShowHideSelector() |
| 4447 |
*/ |
| 4448 |
protected function getShowHideSelector(): string { |
| 4449 |
return '.row'; |
| 4450 |
} |
| 4451 |
|
| 4452 |
/** |
| 4453 |
* Sets if the label should be shown after the checkbox instead before it. |
| 4454 |
* |
| 4455 |
* @param bool $labelAfterCheckbox show label after box |
| 4456 |
*/ |
| 4457 |
public function setLabelAfterCheckbox(bool $labelAfterCheckbox = true): void { |
| 4458 |
$this->labelAfterCheckbox = $labelAfterCheckbox; |
| 4459 |
} |
| 4460 |
|
| 4461 |
/** |
| 4462 |
* Use a short label (4 columns instead of 6) for tablet/desktop. |
| 4463 |
*/ |
| 4464 |
public function setShortLabel(): void { |
| 4465 |
$this->shortLabel = true; |
| 4466 |
} |
| 4467 |
|
| 4468 |
} |
| 4469 |
|
| 4470 |
/** |
| 4471 |
* Responsive table. |
| 4472 |
* |
| 4473 |
* @author roland Gruber |
| 4474 |
*/ |
| 4475 |
class htmlResponsiveTable extends htmlElement { |
| 4476 |
|
| 4477 |
/** @var string[] $titles row titles */ |
| 4478 |
private array $titles; |
| 4479 |
|
| 4480 |
/** @var htmlElement[][] $data data rows */ |
| 4481 |
private array $data; |
| 4482 |
|
| 4483 |
/** @var string[] $widths widths of the columns */ |
| 4484 |
private array $widths = []; |
| 4485 |
|
| 4486 |
/** @var int[] $highlighted highlighted rows */ |
| 4487 |
private array $highlighted = []; |
| 4488 |
/** @var array<int, string> $onClick onclick code (row number => code) */ |
| 4489 |
private array $onClick = []; |
| 4490 |
/** @var array<int, string> $onDoubleClick ondoubleclick code (row number => code) */ |
| 4491 |
private array $onDoubleClick = []; |
| 4492 |
|
| 4493 |
/** |
| 4494 |
* Creates the table. |
| 4495 |
* |
| 4496 |
* @param string[] $titles row titles |
| 4497 |
* @param htmlElement[][] $data data rows |
| 4498 |
* @param int[]|null $highlighted list of row numbers that should be highlighted (starting at 0) |
| 4499 |
*/ |
| 4500 |
public function __construct(array $titles, array $data, ?array $highlighted = null) { |
| 4501 |
$this->titles = $titles; |
| 4502 |
$this->data = $data; |
| 4503 |
if (!empty($highlighted)) { |
| 4504 |
$this->highlighted = $highlighted; |
| 4505 |
} |
| 4506 |
} |
| 4507 |
|
| 4508 |
/** |
| 4509 |
* {@inheritDoc} |
| 4510 |
*/ |
| 4511 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 4512 |
$return = []; |
| 4513 |
$classes = $this->cssClasses; |
| 4514 |
$classes[] = 'responsive-table'; |
| 4515 |
echo '<table class="' . implode(' ', $classes) . '">'; |
| 4516 |
echo '<thead>'; |
| 4517 |
$headClass = empty($this->cssOddRow) ? '' : ' class="' . $this->cssOddRow . '"'; |
| 4518 |
echo '<tr ' . $headClass . '>'; |
| 4519 |
$counter = 0; |
| 4520 |
foreach ($this->titles as $title) { |
| 4521 |
$width = ''; |
| 4522 |
if (isset($this->widths[$counter])) { |
| 4523 |
$width = 'width="' . $this->widths[$counter] . '"'; |
| 4524 |
} |
| 4525 |
echo '<th ' . $width . '>' . htmlspecialchars($title) . '</th>'; |
| 4526 |
$counter++; |
| 4527 |
} |
| 4528 |
echo '</tr>'; |
| 4529 |
echo '</thead>'; |
| 4530 |
echo '<tbody>'; |
| 4531 |
$titleCount = count($this->titles); |
| 4532 |
$counter = 0; |
| 4533 |
foreach ($this->data as $row) { |
| 4534 |
$cssClass = ''; |
| 4535 |
$cssClasses = []; |
| 4536 |
if (in_array($counter, $this->highlighted)) { |
| 4537 |
$cssClasses[] = 'highlighted'; |
| 4538 |
} |
| 4539 |
if (!empty($cssClasses)) { |
| 4540 |
$cssClass = ' class="' . implode(' ', $cssClasses) . '"'; |
| 4541 |
} |
| 4542 |
$onClick = ''; |
| 4543 |
if (!empty($this->onClick[$counter])) { |
| 4544 |
$onClick = ' onclick="' . $this->onClick[$counter] . '"'; |
| 4545 |
} |
| 4546 |
$onDoubleClick = ''; |
| 4547 |
if (!empty($this->onDoubleClick[$counter])) { |
| 4548 |
$onDoubleClick = ' ondblclick="' . $this->onDoubleClick[$counter] . '"'; |
| 4549 |
} |
| 4550 |
echo '<tr ' . $cssClass . $onClick . $onDoubleClick . '>'; |
| 4551 |
for ($i = 0; $i < $titleCount; $i++) { |
| 4552 |
echo '<td data-label="' . $this->titles[$i] . '">'; |
| 4553 |
$ids = parseHtml($module, $row[$i], $values, $restricted); |
| 4554 |
$return = array_merge($return, $ids); |
| 4555 |
echo '</td>'; |
| 4556 |
} |
| 4557 |
echo '</tr>'; |
| 4558 |
$counter++; |
| 4559 |
} |
| 4560 |
echo '</tbody>'; |
| 4561 |
echo '</table>'; |
| 4562 |
return $return; |
| 4563 |
} |
| 4564 |
|
| 4565 |
/** |
| 4566 |
* Sets the width of each column. |
| 4567 |
* |
| 4568 |
* @param string[] $widths widths |
| 4569 |
*/ |
| 4570 |
public function setWidths(array $widths): void { |
| 4571 |
$this->widths = $widths; |
| 4572 |
} |
| 4573 |
|
| 4574 |
/** |
| 4575 |
* Sets the onclick code for the rows. |
| 4576 |
* |
| 4577 |
* @param array<int, string> $calls row number => code |
| 4578 |
*/ |
| 4579 |
public function setOnClickEvents(array $calls): void { |
| 4580 |
$this->onClick = $calls; |
| 4581 |
} |
| 4582 |
|
| 4583 |
/** |
| 4584 |
* Sets the ondoubleclick code for the rows. |
| 4585 |
* |
| 4586 |
* @param array<int, string> $calls row number => code |
| 4587 |
*/ |
| 4588 |
public function setOnDoubleClickEvents(array $calls): void { |
| 4589 |
$this->onDoubleClick = $calls; |
| 4590 |
} |
| 4591 |
|
| 4592 |
} |
| 4593 |
|
| 4594 |
/** |
| 4595 |
* Renders a canvas. |
| 4596 |
* |
| 4597 |
* @author Roland Gruber |
| 4598 |
*/ |
| 4599 |
class htmlCanvas extends htmlElement { |
| 4600 |
|
| 4601 |
private string $id; |
| 4602 |
|
| 4603 |
/** |
| 4604 |
* Constructor |
| 4605 |
* |
| 4606 |
* @param string $id html id |
| 4607 |
*/ |
| 4608 |
public function __construct(string $id) { |
| 4609 |
$this->id = $id; |
| 4610 |
} |
| 4611 |
|
| 4612 |
/** |
| 4613 |
* {@inheritDoc} |
| 4614 |
*/ |
| 4615 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 4616 |
$classesValue = ''; |
| 4617 |
if (!empty($this->cssClasses)) { |
| 4618 |
$classesValue = ' class="' . implode(' ', $this->cssClasses) . '"'; |
| 4619 |
} |
| 4620 |
echo '<canvas id="' . $this->id . '" ' . $classesValue . '>'; |
| 4621 |
echo '</canvas>'; |
| 4622 |
return []; |
| 4623 |
} |
| 4624 |
} |
| 4625 |
|
| 4626 |
/** |
| 4627 |
* Renders a video. |
| 4628 |
* |
| 4629 |
* @author Roland Gruber |
| 4630 |
*/ |
| 4631 |
class htmlVideo extends htmlElement { |
| 4632 |
|
| 4633 |
private string $id; |
| 4634 |
|
| 4635 |
/** |
| 4636 |
* Constructor |
| 4637 |
* |
| 4638 |
* @param string $id html id |
| 4639 |
*/ |
| 4640 |
public function __construct(string $id) { |
| 4641 |
$this->id = $id; |
| 4642 |
} |
| 4643 |
|
| 4644 |
/** |
| 4645 |
* {@inheritDoc} |
| 4646 |
*/ |
| 4647 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 4648 |
$classesValue = ''; |
| 4649 |
if (!empty($this->cssClasses)) { |
| 4650 |
$classesValue = ' class="' . implode(' ', $this->cssClasses) . '"'; |
| 4651 |
} |
| 4652 |
echo '<video id="' . $this->id . '" ' . $classesValue . '>'; |
| 4653 |
echo '</video>'; |
| 4654 |
return []; |
| 4655 |
} |
| 4656 |
} |
| 4657 |
|
| 4658 |
/** |
| 4659 |
* Creates a form element for POST. |
| 4660 |
* |
| 4661 |
* @package metaHTML |
| 4662 |
*/ |
| 4663 |
class htmlForm extends htmlElement { |
| 4664 |
|
| 4665 |
/** form name */ |
| 4666 |
private string $name; |
| 4667 |
/** submit target */ |
| 4668 |
private string $action; |
| 4669 |
/** inner content */ |
| 4670 |
private htmlElement $content; |
| 4671 |
|
| 4672 |
/** |
| 4673 |
* Constructor. |
| 4674 |
* |
| 4675 |
* @param string $name name |
| 4676 |
* @param string $action target URL |
| 4677 |
*/ |
| 4678 |
public function __construct(string $name, string $action, htmlElement $content) { |
| 4679 |
$this->name = $name; |
| 4680 |
$this->action = $action; |
| 4681 |
$this->content = $content; |
| 4682 |
} |
| 4683 |
|
| 4684 |
/** |
| 4685 |
* {@inheritDoc} |
| 4686 |
*/ |
| 4687 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 4688 |
$return = []; |
| 4689 |
echo '<form name="' . $this->name . '" action="' . $this->action . '" method="post" enctype="multipart/form-data">'; |
| 4690 |
$return = $this->content->generateHTML($module, $input, $values, $restricted); |
| 4691 |
echo '</form>'; |
| 4692 |
return $return; |
| 4693 |
} |
| 4694 |
|
| 4695 |
} |
| 4696 |
|
| 4697 |
/** |
| 4698 |
* Represents a (un)ordered list. |
| 4699 |
*/ |
| 4700 |
class htmlList extends htmlElement { |
| 4701 |
|
| 4702 |
/** @var htmlElement[] $elements list elements */ |
| 4703 |
private array $elements; |
| 4704 |
|
| 4705 |
private bool $isOrdered; |
| 4706 |
|
| 4707 |
private ?string $id; |
| 4708 |
|
| 4709 |
/** |
| 4710 |
* Constructor. |
| 4711 |
* |
| 4712 |
* @param htmlElement[] $elements elements to render |
| 4713 |
* @param string|null $id HTML unique id |
| 4714 |
* @param bool|null $isOrdered is an ordered list |
| 4715 |
*/ |
| 4716 |
public function __construct(array $elements, ?string $id = null, ?bool $isOrdered = false) { |
| 4717 |
$this->elements = $elements; |
| 4718 |
$this->id = $id; |
| 4719 |
$this->isOrdered = $isOrdered; |
| 4720 |
} |
| 4721 |
|
| 4722 |
/** |
| 4723 |
* {@inheritDoc} |
| 4724 |
*/ |
| 4725 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 4726 |
$parentTag = $this->isOrdered ? 'ol' : 'ul'; |
| 4727 |
$idValue = empty($this->id) ? '' : ' id="' . $this->id . '"'; |
| 4728 |
$classesValue = ''; |
| 4729 |
if (!empty($this->cssClasses)) { |
| 4730 |
$classesValue = ' class="' . implode(' ', $this->cssClasses) . '"'; |
| 4731 |
} |
| 4732 |
echo '<' . $parentTag . $idValue . $classesValue . '>'; |
| 4733 |
$return = []; |
| 4734 |
foreach ($this->elements as $element) { |
| 4735 |
echo '<li>'; |
| 4736 |
$return = array_merge($return, $element->generateHTML($module, $input, $values, $restricted)); |
| 4737 |
echo '</li>'; |
| 4738 |
} |
| 4739 |
echo '</' . $parentTag . '>'; |
| 4740 |
return $return; |
| 4741 |
} |
| 4742 |
|
| 4743 |
} |
| 4744 |
|
| 4745 |
/** |
| 4746 |
* Represents a label. |
| 4747 |
*/ |
| 4748 |
class htmlLabel extends htmlElement { |
| 4749 |
|
| 4750 |
private string $for; |
| 4751 |
|
| 4752 |
private string $text; |
| 4753 |
|
| 4754 |
/** mark as required */ |
| 4755 |
private bool $markAsRequired = false; |
| 4756 |
|
| 4757 |
/** |
| 4758 |
* Constructor. |
| 4759 |
* |
| 4760 |
* @param string $for target element |
| 4761 |
* @param string $text label text |
| 4762 |
*/ |
| 4763 |
public function __construct(string $for, string $text) { |
| 4764 |
$this->for = htmlspecialchars($for); |
| 4765 |
$this->text = htmlspecialchars($text); |
| 4766 |
} |
| 4767 |
|
| 4768 |
/** |
| 4769 |
* {@inheritDoc} |
| 4770 |
*/ |
| 4771 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 4772 |
$classesValue = ''; |
| 4773 |
if (!empty($this->cssClasses)) { |
| 4774 |
$classesValue = ' class="' . implode(' ', $this->cssClasses) . '"'; |
| 4775 |
} |
| 4776 |
echo '<label for="' . $this->for . '"' . $classesValue . '>'; |
| 4777 |
echo $this->text; |
| 4778 |
echo '</label>'; |
| 4779 |
if ($this->markAsRequired) { |
| 4780 |
echo htmlGetRequiredMarker(); |
| 4781 |
} |
| 4782 |
return []; |
| 4783 |
} |
| 4784 |
|
| 4785 |
/** |
| 4786 |
* Adds a marker that indicates a required field. |
| 4787 |
* |
| 4788 |
* @param bool $markAsRequired add marker |
| 4789 |
*/ |
| 4790 |
public function setMarkAsRequired(bool $markAsRequired = true): void { |
| 4791 |
$this->markAsRequired = $markAsRequired; |
| 4792 |
} |
| 4793 |
|
| 4794 |
} |
| 4795 |
|
| 4796 |
/** |
| 4797 |
* Represents a progress bar. |
| 4798 |
*/ |
| 4799 |
class htmlProgressbar extends htmlElement { |
| 4800 |
|
| 4801 |
private ?string $id = null; |
| 4802 |
private int $progress; |
| 4803 |
|
| 4804 |
/** |
| 4805 |
* Constructor. |
| 4806 |
* |
| 4807 |
* @param ?string $id HTML id |
| 4808 |
* @param int $progress initial progress |
| 4809 |
*/ |
| 4810 |
public function __construct(?string $id = null, int $progress = 0) { |
| 4811 |
if ($id !== null) { |
| 4812 |
$this->id = htmlspecialchars($id); |
| 4813 |
} |
| 4814 |
$this->progress = $progress; |
| 4815 |
} |
| 4816 |
|
| 4817 |
/** |
| 4818 |
* {@inheritDoc} |
| 4819 |
*/ |
| 4820 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 4821 |
$extraClasses = ''; |
| 4822 |
if (!empty($this->cssClasses)) { |
| 4823 |
$extraClasses = implode(' ', $this->cssClasses); |
| 4824 |
} |
| 4825 |
$idValue = ''; |
| 4826 |
if ($this->id !== null) { |
| 4827 |
$idValue = ' id="' . $this->id . '"'; |
| 4828 |
} |
| 4829 |
echo '<div ' . $idValue . ' class="lam-progressbar ' . $extraClasses . '">'; |
| 4830 |
echo '<div class="lam-progressbar-bar" style="width: ' . $this->progress . '%">'; |
| 4831 |
echo '</div>'; |
| 4832 |
echo '</div>'; |
| 4833 |
return []; |
| 4834 |
} |
| 4835 |
|
| 4836 |
} |
| 4837 |
|
| 4838 |
/** |
| 4839 |
* Tab container. |
| 4840 |
*/ |
| 4841 |
class htmlTabContainer extends htmlElement { |
| 4842 |
|
| 4843 |
/** |
| 4844 |
* @var htmlTab[] $tabs tabs |
| 4845 |
*/ |
| 4846 |
private array $tabs; |
| 4847 |
|
| 4848 |
private int $activeTabIndex = 1; |
| 4849 |
|
| 4850 |
/** |
| 4851 |
* Adds a new tab. |
| 4852 |
* |
| 4853 |
* @param htmlTab $tab tab |
| 4854 |
* @param bool $isActive is active tab |
| 4855 |
*/ |
| 4856 |
public function addTab(htmlTab $tab, bool $isActive = false): void { |
| 4857 |
$this->tabs[] = $tab; |
| 4858 |
if ($isActive) { |
| 4859 |
$this->activeTabIndex = count($this->tabs); |
| 4860 |
} |
| 4861 |
} |
| 4862 |
|
| 4863 |
/** |
| 4864 |
* {@inheritDoc} |
| 4865 |
*/ |
| 4866 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 4867 |
echo '<div id="tabs" class="lam-tab-container"> |
| 4868 |
<ul class="lam-tab-navigation">'; |
| 4869 |
foreach ($this->tabs as $tabIndex => $tab) { |
| 4870 |
$tabNumber = $tabIndex + 1; |
| 4871 |
$tabActiveClass = ($this->activeTabIndex === $tabNumber) ? 'lam-tab-active' : ''; |
| 4872 |
$tabImage = ($tab->image !== null) ? '<img alt="" src="../../graphics/' . $tab->image . '">' : ''; |
| 4873 |
echo '<li data-tabid="' . $tabNumber . '" class="lam-tab ' . $tabActiveClass . '"> |
| 4874 |
<a href="#tab' . $tabNumber . '" class="lam-tab-anchor">'; |
| 4875 |
echo $tabImage; |
| 4876 |
$labelClass = ($tab->image !== null) ? 'hide-on-mobile' : ''; |
| 4877 |
echo '<span class="' . $labelClass . '"> ' . $tab->label . ' </span> |
| 4878 |
</a> |
| 4879 |
</li>'; |
| 4880 |
} |
| 4881 |
echo '</ul>'; |
| 4882 |
$return = []; |
| 4883 |
foreach ($this->tabs as $tabIndex => $tab) { |
| 4884 |
$tabNumber = $tabIndex + 1; |
| 4885 |
$tabActiveClass = ($this->activeTabIndex === $tabNumber) ? 'lam-tab-active' : ''; |
| 4886 |
echo '<div id="tab' . $tabNumber . '" class="lam-tab-content ' . $tabActiveClass . '" data-tabid="' . $tabNumber . '">'; |
| 4887 |
$data = parseHtml($module, $tab->content, $values, $restricted); |
| 4888 |
$return = array_merge($return, $data); |
| 4889 |
echo '</div>'; |
| 4890 |
} |
| 4891 |
return $return; |
| 4892 |
} |
| 4893 |
|
| 4894 |
} |
| 4895 |
|
| 4896 |
/** |
| 4897 |
* Tab inside htmlTabContainer. |
| 4898 |
*/ |
| 4899 |
class htmlTab { |
| 4900 |
|
| 4901 |
public string $label; |
| 4902 |
|
| 4903 |
public ?string $image; |
| 4904 |
|
| 4905 |
public htmlElement $content; |
| 4906 |
|
| 4907 |
/** |
| 4908 |
* Constructor. |
| 4909 |
* |
| 4910 |
* @param htmlElement $content tab content |
| 4911 |
* @param string $label tab label text |
| 4912 |
* @param string|null $image tab image |
| 4913 |
*/ |
| 4914 |
public function __construct(htmlElement $content, string $label = '', ?string $image = null) { |
| 4915 |
$this->content = $content; |
| 4916 |
$this->image = $image; |
| 4917 |
$this->label = htmlspecialchars($label); |
| 4918 |
} |
| 4919 |
|
| 4920 |
} |
| 4921 |
|
| 4922 |
/** |
| 4923 |
* Show more link for initially hidden content. |
| 4924 |
*/ |
| 4925 |
class htmlShowMore extends htmlElement { |
| 4926 |
|
| 4927 |
/** root for show more/less */ |
| 4928 |
public const CLASS_SHOW_MORE_ROOT = 'lam-showmore-root'; |
| 4929 |
/** initially hidden content */ |
| 4930 |
public const CLASS_SHOW_MORE = 'lam-showmore-more hidden'; |
| 4931 |
/** content to be shown when show less link is clicked */ |
| 4932 |
public const CLASS_SHOW_LESS = 'lam-showmore-less'; |
| 4933 |
|
| 4934 |
/** default size when to use show more/less */ |
| 4935 |
public const DEFAULT_MAXIMUM_SIZE = 10; |
| 4936 |
|
| 4937 |
/** size when to use show more/less for larger readable lists */ |
| 4938 |
public const MAXIMUM_SIZE_LARGE = 30; |
| 4939 |
|
| 4940 |
/** |
| 4941 |
* @inheritDoc |
| 4942 |
*/ |
| 4943 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 4944 |
echo '<span class="show-pointer ' . self::CLASS_SHOW_LESS . '" onclick="window.lam.showMore.showMore(this)">' . _('Show more...') . '</span>'; |
| 4945 |
return []; |
| 4946 |
} |
| 4947 |
|
| 4948 |
} |
| 4949 |
|
| 4950 |
/** |
| 4951 |
* Show less link for content displayed after show more. |
| 4952 |
*/ |
| 4953 |
class htmlShowLess extends htmlElement { |
| 4954 |
|
| 4955 |
/** |
| 4956 |
* @inheritDoc |
| 4957 |
*/ |
| 4958 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 4959 |
echo '<span class="show-pointer ' . htmlShowMore::CLASS_SHOW_MORE . '" onclick="window.lam.showMore.showLess(this)">' . _('Show less...') . '</span>'; |
| 4960 |
return []; |
| 4961 |
} |
| 4962 |
|
| 4963 |
} |
| 4964 |
|
| 4965 |
/** |
| 4966 |
* Simple line break. |
| 4967 |
*/ |
| 4968 |
class htmlLineBreak extends htmlElement { |
| 4969 |
|
| 4970 |
/** |
| 4971 |
* @inheritDoc |
| 4972 |
*/ |
| 4973 |
public function generateHTML($module, $input, $values, $restricted): array { |
| 4974 |
echo '<br />'; |
| 4975 |
return []; |
| 4976 |
} |
| 4977 |
|
| 4978 |
} |