function = $info['function']; if (array_key_exists('id', $info)) $this->id = $info['id']; if (array_key_exists('title', $info)) $this->title = $info['title']; if (array_key_exists('default', $info)) $this->default = $info['default']; if (array_key_exists('selected', $info)) $this->selected = $info['selected']; if (array_key_exists('options', $info)) { if (is_array($info['options'])) { foreach ($info['options'] as $option) { if (is_array($option)) $this->options[] = array($option[0], $option[1]); else $this->options[] = array($option, $option); } } elseif (is_string($info['options'])) { $this->loadOptions($info['options']); } else throw new Exception('Unknown options type'); } } protected function loadOptions($sql) { global $db; foreach ($db->fetchObjectList($sql) as $row) $this->options[] = array($row->id, $row->text); } public function toString() { $attr = array(); if ($this->id) $attr[] = sprintf('id="%s"', $this->id); if ($this->title) $attr[] = sprintf('title="%s"', $this->title); if ($this->function) $attr[] = sprintf('onchange="%s(event, this)"', $this->function); $code = array(); $code[] = sprintf(''; return implode('', $code); } }