2 // +----------------------------------------------------------------------+
3 // | Anuko Time Tracker
4 // +----------------------------------------------------------------------+
5 // | Copyright (c) Anuko International Ltd. (https://www.anuko.com)
6 // +----------------------------------------------------------------------+
7 // | LIBERAL FREEWARE LICENSE: This source code document may be used
8 // | by anyone for any purpose, and freely redistributed alone or in
9 // | combination with other software, provided that the license is obeyed.
11 // | There are only two ways to violate the license:
13 // | 1. To redistribute this code in source form, with the copyright
14 // | notice or license removed or altered. (Distributing in compiled
15 // | forms without embedded copyright notices is permitted).
17 // | 2. To redistribute modified versions of this code in *any* form
18 // | that bears insufficient indications that the modifications are
19 // | not the work of the original author(s).
21 // | This license applies to this document only, not any other software
22 // | that it may be combined with.
24 // +----------------------------------------------------------------------+
26 // | https://www.anuko.com/time_tracker/credits.htm
27 // +----------------------------------------------------------------------+
29 import('form.FormElement');
31 // name CDATA #IMPLIED -- field name --
32 // size NUMBER #IMPLIED -- rows visible --
33 // multiple (multiple) #IMPLIED -- default is single selection --
34 // disabled (disabled) #IMPLIED -- unavailable in this context --
35 // tabindex NUMBER #IMPLIED -- position in tabbing order --
36 // onfocus %Script; #IMPLIED -- the element got the focus --
37 // onblur %Script; #IMPLIED -- the element lost the focus --
38 // onchange %Script; #IMPLIED -- the element value was changed --
40 class Combobox extends FormElement {
41 var $mMultiple = false;
42 var $mOptions = array();
43 var $mOptionsEmpty = array();
44 var $mCompareOn = "key"; // or "value"
46 var $mDataKeys = array();
48 function __construct($name, $value = '') {
49 $this->class = 'Combobox';
51 $this->value = $value;
54 function setMultiple($value) { $this->mMultiple = $value; }
55 function isMultiple() { return $this->mMultiple; }
57 function setData($value) { $this->mOptions = $value; }
58 function getData() { return $this->mOptions; }
60 function setDataDefault($value) { $this->mOptionsEmpty = $value; }
61 function getDataDefault() { return $this->mOptionsEmpty; }
63 function setDataKeys($keys) { $this->mDataKeys = $keys; $this->mDataDeep = 2; }
64 function getDataKeys() { return $this->mDataKeys; }
69 if ($this->id=="") $this->id = $this->name;
71 $html = "\n\t<select";
72 $html .= " name=\"$this->name\" id=\"$this->id\"";
75 $html .= " size=\"$this->size\"";
80 if ($this->on_change!="")
81 $html .= " onchange=\"$this->on_change\"";
84 $html .= " style=\"$this->style\"";
86 if (!$this->isEnabled())
90 if (is_array($this->mOptionsEmpty) && (count($this->mOptionsEmpty) > 0))
91 foreach ($this->mOptionsEmpty as $key=>$value) {
92 $html .= "<option value=\"".$key."\"";
93 if (($this->value == $value) && ($this->value != '')) $html .= " selected";
94 $html .= ">".$value."</option>\n";
96 if (is_array($this->mOptions) && (count($this->mOptions) > 0))
97 foreach ($this->mOptions as $key=>$value) {
99 if ($this->mDataDeep>1) {
100 $key = $value[$this->mDataKeys[0]];
101 $value = $value[$this->mDataKeys[1]];
103 $html .= "<option value=\"".$key."\"";
104 if (($this->value == $key) && ($this->value != '')) $html .= " selected";
105 $html .= ">".htmlspecialchars($value)."</option>\n";
108 $html .= "</select>";