commit 2d959f6ddd57542d4b82adb0c72d7ee119cdb488
parent 053b8119128e8a27a7a590b7702e9236df74b2fb
Author: Jan Dankert <devnull@localhost>
Date: Sun, 3 Dec 2017 01:14:26 +0100
Komponente "select" umgestellt auf eine Klasse.
Diffstat:
3 files changed, 133 insertions(+), 58 deletions(-)
diff --git a/themes/default/include/html/selectbox/Selectbox.class.php b/themes/default/include/html/selectbox/Selectbox.class.php
@@ -0,0 +1,88 @@
+<?php
+
+class SelectboxComponent extends Component
+{
+
+ public $list;
+
+ public $name;
+
+ public $default;
+
+ /**
+ * Titel
+ * @var unknown
+ */
+ public $title;
+
+ /**
+ * Style-Klasse
+ */
+ public $class;
+
+ /**
+ * Leere Auswahlmöglichkeit hinzufügen.
+ * @var string
+ */
+ public $addempty = false;
+
+ /**
+ * Mehrfachauswahl möglich?
+ * @var string
+ */
+ public $multiple = false;
+
+ /**
+ * Größe des Eingabefeldes
+ * @var integer
+ */
+ public $size = 1;
+
+ /**
+ * Ob es sich bei den Option-Werten um Sprachschlüssel handelt.
+ * @var string
+ */
+ public $lang = false;
+
+
+ public function begin()
+ {
+ $this->include( 'selectbox/component-select-box.php');
+
+ echo '<div class="inputholder">';
+ echo '<select ';
+ echo ' id="'.'<?php echo REQUEST_ID ?>_'.$this->htmlvalue($this->name).'"';
+ echo ' name="'.$this->htmlvalue($this->name).($this->multiple?'[]':'').'"';
+ echo ' title="'.$this->htmlvalue($this->title).'"';
+ echo ' class="'.$this->htmlvalue($this->class).'"';
+
+ echo '<?php if (count($'.$this->varname($this->list).')<=1)'." echo ' disabled=\"disabled\"'; ?>";
+
+
+ if($this->multiple)
+ echo ' multiple="multiple"';
+
+ echo ' size='.$this->htmlvalue($this->size).'"';
+ echo '>';
+
+ if ( isset($this->default))
+ $value = $this->value($this->default);
+ else
+ $value = '$'.$this->varname($this->name);
+
+ echo '<?php component_select_option_list($'.$this->varname($this->list).','.$value.','.intval(boolval($this->addempty)).','.intval(boolval($this->lang)).') ?>';
+
+ // Keine Einträge in der Liste, wir benötigen ein verstecktes Feld.
+ echo '<?php if (count($'.$this->varname($this->list).')==0) { ?>'.'<input type="hidden" name="'.$this->htmlvalue($this->name).'" value="" />'.'<?php } ?>';
+ // Nur 1 Eintrag in Liste, da die Selectbox 'disabled' ist, muss ein hidden-Feld her.
+ echo '<?php if (count($'.$this->varname($this->list).')==1) { ?>'.'<input type="hidden" name="'.$this->htmlvalue($this->name).'" value="'.'<?php echo array_keys($'.$this->varname($this->list).')[0] ?>'.'" />'.'<?php } ?>';
+ }
+
+ public function end()
+ {
+ echo '</select>';
+ echo '</div>';
+ }
+}
+
+?>+
\ No newline at end of file
diff --git a/themes/default/include/html/selectbox/component-select-box.php b/themes/default/include/html/selectbox/component-select-box.php
@@ -0,0 +1,43 @@
+<?php
+
+/**
+ * Create Option List for a HTML select box.
+ * @param unknown $values
+ * @param unknown $value
+ * @param unknown $addEmptyOption
+ * @param unknown $valuesAreLanguageKeys
+ */
+function component_select_option_list($values, $value, $addEmptyOption, $valuesAreLanguageKeys)
+{
+ if ($addEmptyOption)
+ $values = array(
+ '' => lang('LIST_ENTRY_EMPTY')
+ ) + $values;
+
+ foreach ($values as $box_key => $box_value)
+ {
+ if (is_array($box_value))
+ {
+ $box_key = $box_value['key'];
+ $box_title = $box_value['title'];
+ $box_value = $box_value['value'];
+ }
+ elseif ($valuesAreLanguageKeys)
+ {
+ $box_title = lang($box_value . '_DESC');
+ $box_value = lang($box_value);
+ }
+ else
+ {
+ $box_title = '';
+ }
+ echo '<option value="' . $box_key . '" title="' . $box_title . '"';
+
+ if ((string) $box_key == $value)
+ echo ' selected="selected"';
+
+ echo '>' . $box_value . '</option>';
+ }
+}
+
+?>+
\ No newline at end of file
diff --git a/themes/default/include/html/selectbox/selectbox-begin.inc.php b/themes/default/include/html/selectbox/selectbox-begin.inc.php
@@ -1,57 +0,0 @@
-<?php
-$attr_readonly=false;
-$attr_tmp_list = $$attr_list;
-if ($this->isEditable() && !$this->isEditMode())
-{
- echo empty($$attr_name)?'- '.lang('EMPTY').' -':$attr_tmp_list[$$attr_name];
-}
-else
-{
-if ( $attr_addempty!==FALSE )
-{
- if ($attr_addempty===TRUE)
- $attr_tmp_list = array(''=>lang('LIST_ENTRY_EMPTY'))+$attr_tmp_list;
- else
- $attr_tmp_list = array(''=>'- '.lang($attr_addempty).' -')+$attr_tmp_list;
-}
-?><div class="inputholder"><select<?php if ($attr_readonly) echo ' disabled="disabled"' ?> id="<?php echo REQUEST_ID ?>_<?php echo $attr_name ?>" name="<?php echo $attr_name; if ($attr_multiple) echo '[]'; ?>" onchange="<?php echo $attr_onchange ?>" title="<?php echo $attr_title ?>" class="<?php echo $attr_class ?>"<?php
-if (count($$attr_list)<=1) echo ' disabled="disabled"';
-if ($attr_multiple) echo ' multiple="multiple"';
-echo ' size="'.intval($attr_size).'"';
-?>><?php
- if ( isset($$attr_name) && isset($attr_tmp_list[$$attr_name]) )
- $attr_tmp_default = $$attr_name;
- elseif ( isset($attr_default) )
- $attr_tmp_default = $attr_default;
- else
- $attr_tmp_default = '';
-
- foreach( $attr_tmp_list as $box_key=>$box_value )
- {
- if ( is_array($box_value) )
- {
- $box_key = $box_value['key' ];
- $box_title = $box_value['title'];
- $box_value = $box_value['value'];
- }
- elseif( $attr_lang )
- {
- $box_title = lang( $box_value.'_DESC');
- $box_value = lang( $box_value );
- }
- else
- {
- $box_title = '';
- }
- echo '<option class="'.$attr_class.'" value="'.$box_key.'" title="'.$box_title.'"';
-
- if ((string)$box_key==$attr_tmp_default)
- echo ' selected="selected"';
-
- echo '>'.$box_value.'</option>';
- }
-?></select></div><?php
-if (count($$attr_list)==0) echo '<input type="hidden" name="'.$attr_name.'" value="" />';
-if (count($$attr_list)==1) echo '<input type="hidden" name="'.$attr_name.'" value="'.$box_key.'" />';
-}
-?>-
\ No newline at end of file