From 1a1ca1d1b56d9f21e4142100e92862d9210d280c Mon Sep 17 00:00:00 2001 From: msquare Date: Mon, 14 Nov 2016 18:14:23 +0100 Subject: [PATCH] split templates into different files --- includes/engelsystem_provider.php | 1 + includes/sys_form.php | 256 ++++++++++++++++++++++++++++++ 2 files changed, 257 insertions(+) create mode 100644 includes/sys_form.php diff --git a/includes/engelsystem_provider.php b/includes/engelsystem_provider.php index 029c1788..84383bba 100644 --- a/includes/engelsystem_provider.php +++ b/includes/engelsystem_provider.php @@ -5,6 +5,7 @@ require_once realpath(__DIR__ . '/../includes/mysqli_provider.php'); require_once realpath(__DIR__ . '/../includes/sys_auth.php'); +require_once realpath(__DIR__ . '/../includes/sys_form.php'); require_once realpath(__DIR__ . '/../includes/sys_log.php'); require_once realpath(__DIR__ . '/../includes/sys_menu.php'); require_once realpath(__DIR__ . '/../includes/sys_page.php'); diff --git a/includes/sys_form.php b/includes/sys_form.php new file mode 100644 index 00000000..960be401 --- /dev/null +++ b/includes/sys_form.php @@ -0,0 +1,256 @@ +'; +} + +/** + * Rendert ein Zahlenfeld mit Buttons zum verstellen + */ +function form_spinner($name, $label, $value) { + return form_element($label, ' +
+ +
+ + +
+
+ + '); +} + +/** + * Render a bootstrap datepicker + * + * @param string $name + * Name of the parameter + * @param string $label + * Label + * @param int $value + * Unix Timestamp + * @param int $min_date + * Earliest possible date + * @return HTML + */ +function form_date($name, $label, $value, $start_date = '', $end_date = '') { + $dom_id = $name . '-date'; + $value = is_numeric($value) ? date('Y-m-d', $value) : ''; + $start_date = is_numeric($start_date) ? date('Y-m-d', $start_date) : ''; + $end_date = is_numeric($end_date) ? date('Y-m-d', $end_date) : ''; + return form_element($label, ' +
+ ' . glyph('th') . ' +
+ + ', $dom_id); +} + +/** + * Rendert eine Liste von Checkboxen für ein Formular + * + * @param + * name Die Namen der Checkboxen werden aus name_key gebildet + * @param + * label Die Beschriftung der Liste + * @param + * items Array mit den einzelnen Checkboxen + * @param + * selected Array mit den Keys, die ausgewählt sind + */ +function form_checkboxes($name, $label, $items, $selected) { + $html = form_element($label, ''); + foreach ($items as $key => $item) { + $html .= form_checkbox($name . '_' . $key, $item, array_search($key, $selected) !== false); + } + return $html; +} + +/** + * Rendert eine Tabelle von Checkboxen für ein Formular + * + * @param + * names Assoziatives Array mit Namen der Checkboxen als Keys und Überschriften als Values + * @param + * label Die Beschriftung der gesamten Tabelle + * @param + * items Array mit den Beschriftungen der Zeilen + * @param + * selected Mehrdimensionales Array, wobei $selected[foo] ein Array der in der Datenreihe foo markierten Checkboxen ist + * @param + * disabled Wie selected, nur dass die entsprechenden Checkboxen deaktiviert statt markiert sind + */ +function form_multi_checkboxes($names, $label, $items, $selected, $disabled = []) { + $html = ""; + foreach ($names as $title) { + $html .= ""; + } + $html .= ""; + foreach ($items as $key => $item) { + $html .= ""; + foreach ($names as $name => $title) { + $dom_id = $name . '_' . $key; + $sel = array_search($key, $selected[$name]) !== false ? ' checked="checked"' : ""; + if (! empty($disabled) && ! empty($disabled[$name]) && array_search($key, $disabled[$name]) !== false) { + $sel .= ' disabled="disabled"'; + } + $html .= ''; + } + $html .= ''; + } + $html .= "
$title
"; + return form_element($label, $html); +} + +/** + * Rendert eine Checkbox + */ +function form_checkbox($name, $label, $selected, $value = 'checked') { + return '
'; +} + +/** + * Rendert einen Radio + */ +function form_radio($name, $label, $selected, $value) { + return '
'; +} + +/** + * Rendert einen Infotext in das Formular + */ +function form_info($label, $text = "") { + if ($label == "") { + return '' . glyph('info-sign') . $text . ''; + } + if ($text == "") { + return '

' . $label . '

'; + } + return form_element($label, '

' . $text . '

', ''); +} + +/** + * Rendert den Absenden-Button eines Formulars + */ +function form_submit($name, $label) { + return form_element('', ""); +} + +/** + * Rendert ein Formular-Textfeld + */ +function form_text($name, $label, $value, $disabled = false) { + $disabled = $disabled ? ' disabled="disabled"' : ''; + return form_element($label, '', 'form_' . $name); +} + +/** + * Rendert ein Formular-Emailfeld + */ +function form_email($name, $label, $value, $disabled = false) { + $disabled = $disabled ? ' disabled="disabled"' : ''; + return form_element($label, '', 'form_' . $name); +} + +/** + * Rendert ein Formular-Dateifeld + */ +function form_file($name, $label) { + return form_element($label, '', 'form_' . $name); +} + +/** + * Rendert ein Formular-Passwortfeld + */ +function form_password($name, $label, $disabled = false) { + $disabled = $disabled ? ' disabled="disabled"' : ''; + return form_element($label, '', 'form_' . $name); +} + +/** + * Rendert ein Formular-Textfeld + */ +function form_textarea($name, $label, $value, $disabled = false) { + $disabled = $disabled ? ' disabled="disabled"' : ''; + return form_element($label, '', 'form_' . $name); +} + +/** + * Rendert ein Formular-Auswahlfeld + */ +function form_select($name, $label, $values, $selected) { + return form_element($label, html_select_key('form_' . $name, $name, $values, $selected), 'form_' . $name); +} + +/** + * Rendert ein Formular-Element + */ +function form_element($label, $input, $for = "") { + if ($label == '') { + return '
' . $input . '
'; + } + + return '
' . '' . $input . '
'; +} + +/** + * Rendert ein Formular + */ +function form($elements, $action = "") { + return '
' . join($elements) . '
'; +} + +function html_options($name, $options, $selected = "") { + $html = ""; + foreach ($options as $value => $label) { + $html .= ' ' . $label; + } + + return $html; +} + +function html_select_key($dom_id, $name, $rows, $selected) { + $html = ''; + return $html; +} + +?> \ No newline at end of file