_flagFrozen) {
return $this->getFrozenHtml();
}
$tabs = $this->_getTabs();
$tab = $this->_getTab();
$strHtml = '';
if ($this->getComment() != '') {
$strHtml .= $tabs . '" . PHP_EOL;
}
$selectName = $this->getName() . '[]';
// placeholder {unselected} existence determines if we will render
if (strpos($this->_elementTemplate, '{unselected}') === FALSE) {
// ... a single multi-select with checkboxes
$id = $this->getAttribute('id');
$strHtmlSelected = $tab . '
' . PHP_EOL;
foreach ($this->_options as $option) {
$_labelAttributes = array('style', 'class', 'onmouseover', 'onmouseout');
$labelAttributes = array();
foreach ($_labelAttributes as $attr) {
if (isset($option['attr'][$attr])) {
$labelAttributes[$attr] = $option['attr'][$attr];
unset($option['attr'][$attr]);
}
}
if (is_array($this->_values) && in_array((string) $option['attr']['value'], $this->_values)) {
// The items is *selected*
$checked = ' checked="checked"';
}
else {
// The item is *unselected* so we want to put it
$checked = '';
}
$strHtmlSelected .= $tab . '' . PHP_EOL;
}
$strHtmlSelected .= $tab . '
' . PHP_EOL;
$strHtmlHidden = '';
$strHtmlUnselected = '';
$strHtmlAdd = '';
$strHtmlRemove = '';
// build the select all button with all its attributes
$attributes = array('onclick' => "{$this->_jsPrefix}{$this->_jsPostfix}('" . $this->getName() . "', 1);");
$this->_allButtonAttributes = array_merge($this->_allButtonAttributes, $attributes);
$attrStrAll = $this->_getAttrString($this->_allButtonAttributes);
$strHtmlAll = "" . PHP_EOL;
// build the select none button with all its attributes
$attributes = array('onclick' => "{$this->_jsPrefix}{$this->_jsPostfix}('" . $this->getName() . "', 0);");
$this->_noneButtonAttributes = array_merge($this->_noneButtonAttributes, $attributes);
$attrStrNone = $this->_getAttrString($this->_noneButtonAttributes);
$strHtmlNone = "" . PHP_EOL;
// build the toggle selection button with all its attributes
$attributes = array('onclick' => "{$this->_jsPrefix}{$this->_jsPostfix}('" . $this->getName() . "', 2);");
$this->_toggleButtonAttributes = array_merge($this->_toggleButtonAttributes, $attributes);
$attrStrToggle = $this->_getAttrString($this->_toggleButtonAttributes);
$strHtmlToggle = "" . PHP_EOL;
$strHtmlMoveUp = '';
$strHtmlMoveDown = '';
}
else {
// ... or a dual multi-select
// set name of Select From Box
$this->_attributesUnselected = array(
'name' => '__' . $selectName,
'ondblclick' => "{$this->_jsPrefix}{$this->_jsPostfix}(this.form.elements['__" . $selectName . "'], this.form.elements['_" . $selectName . "'], this.form.elements['" . $selectName . "'], 'add')",
);
$this->_attributesUnselected = array_merge($this->_attributes, $this->_attributesUnselected);
$attrUnselected = $this->_getAttrString($this->_attributesUnselected);
// set name of Select To Box
$this->_attributesSelected = array(
'name' => '_' . $selectName,
'ondblclick' => "{$this->_jsPrefix}{$this->_jsPostfix}(this.form.elements['__" . $selectName . "'], this.form.elements['_" . $selectName . "'], this.form.elements['" . $selectName . "'], 'remove')",
);
$this->_attributesSelected = array_merge($this->_attributes, $this->_attributesSelected);
$attrSelected = $this->_getAttrString($this->_attributesSelected);
// set name of Select hidden Box
$this->_attributesHidden = array(
'name' => $selectName,
'style' => 'overflow: hidden; visibility: hidden; width: 1px; height: 0;',
);
$this->_attributesHidden = array_merge($this->_attributes, $this->_attributesHidden);
$attrHidden = $this->_getAttrString($this->_attributesHidden);
// prepare option tables to be displayed as in POST order
$append = count($this->_values);
if ($append > 0) {
$arrHtmlSelected = array_fill(0, $append, ' ');
}
else {
$arrHtmlSelected = array();
}
$options = count($this->_options);
$arrHtmlUnselected = array();
if ($options > 0) {
$arrHtmlHidden = array_fill(0, $options, ' ');
foreach ($this->_options as $option) {
if (is_array($this->_values) &&
in_array((string) $option['attr']['value'], $this->_values)
) {
// Get the post order
$key = array_search($option['attr']['value'], $this->_values);
// The items is *selected* so we want to put it in the 'selected' multi-select
$arrHtmlSelected[$key] = $option;
// Add it to the 'hidden' multi-select and set it as 'selected'
$option['attr']['selected'] = 'selected';
$arrHtmlHidden[$key] = $option;
}
else {
// The item is *unselected* so we want to put it in the 'unselected' multi-select
$arrHtmlUnselected[] = $option;
// Add it to the hidden multi-select as 'unselected'
$arrHtmlHidden[$append] = $option;
$append++;
}
}
}
else {
$arrHtmlHidden = array();
}
// The 'unselected' multi-select which appears on the left
$strHtmlUnselected = "';
// The 'selected' multi-select which appears on the right
$strHtmlSelected = "';
// The 'hidden' multi-select
$strHtmlHidden = "';
// build the remove button with all its attributes
$attributes = array('onclick' => "{$this->_jsPrefix}{$this->_jsPostfix}(this.form.elements['__" . $selectName . "'], this.form.elements['_" . $selectName . "'], this.form.elements['" . $selectName . "'], 'remove'); return false;");
$this->_removeButtonAttributes = array_merge($this->_removeButtonAttributes, $attributes);
$attrStrRemove = $this->_getAttrString($this->_removeButtonAttributes);
$strHtmlRemove = "" . PHP_EOL;
// build the add button with all its attributes
$attributes = array('onclick' => "{$this->_jsPrefix}{$this->_jsPostfix}(this.form.elements['__" . $selectName . "'], this.form.elements['_" . $selectName . "'], this.form.elements['" . $selectName . "'], 'add'); return false;");
$this->_addButtonAttributes = array_merge($this->_addButtonAttributes, $attributes);
$attrStrAdd = $this->_getAttrString($this->_addButtonAttributes);
$strHtmlAdd = "" . PHP_EOL;
// build the select all button with all its attributes
$attributes = array('onclick' => "{$this->_jsPrefix}{$this->_jsPostfix}(this.form.elements['__" . $selectName . "'], this.form.elements['_" . $selectName . "'], this.form.elements['" . $selectName . "'], 'all'); return false;");
$this->_allButtonAttributes = array_merge($this->_allButtonAttributes, $attributes);
$attrStrAll = $this->_getAttrString($this->_allButtonAttributes);
$strHtmlAll = "" . PHP_EOL;
// build the select none button with all its attributes
$attributes = array('onclick' => "{$this->_jsPrefix}{$this->_jsPostfix}(this.form.elements['__" . $selectName . "'], this.form.elements['_" . $selectName . "'], this.form.elements['" . $selectName . "'], 'none'); return false;");
$this->_noneButtonAttributes = array_merge($this->_noneButtonAttributes, $attributes);
$attrStrNone = $this->_getAttrString($this->_noneButtonAttributes);
$strHtmlNone = "" . PHP_EOL;
// build the toggle button with all its attributes
$attributes = array('onclick' => "{$this->_jsPrefix}{$this->_jsPostfix}(this.form.elements['__" . $selectName . "'], this.form.elements['_" . $selectName . "'], this.form.elements['" . $selectName . "'], 'toggle'); return false;");
$this->_toggleButtonAttributes = array_merge($this->_toggleButtonAttributes, $attributes);
$attrStrToggle = $this->_getAttrString($this->_toggleButtonAttributes);
$strHtmlToggle = "" . PHP_EOL;
// build the move up button with all its attributes
$attributes = array('onclick' => "{$this->_jsPrefix}moveUp(this.form.elements['_" . $selectName . "'], this.form.elements['" . $selectName . "']); return false;");
$this->_upButtonAttributes = array_merge($this->_upButtonAttributes, $attributes);
$attrStrUp = $this->_getAttrString($this->_upButtonAttributes);
$strHtmlMoveUp = "" . PHP_EOL;
// build the move down button with all its attributes
$attributes = array('onclick' => "{$this->_jsPrefix}moveDown(this.form.elements['_" . $selectName . "'], this.form.elements['" . $selectName . "']); return false;");
$this->_downButtonAttributes = array_merge($this->_downButtonAttributes, $attributes);
$attrStrDown = $this->_getAttrString($this->_downButtonAttributes);
$strHtmlMoveDown = "" . PHP_EOL;
}
// render all part of the multi select component with the template
$strHtml = $this->_elementTemplate;
// Prepare multiple labels
$labels = $this->getLabel();
if (is_array($labels)) {
array_shift($labels);
}
// render extra labels, if any
if (is_array($labels)) {
foreach ($labels as $key => $text) {
$key = is_int($key) ? $key + 2 : $key;
$strHtml = str_replace("{label_{$key}}", $text, $strHtml);
$strHtml = str_replace("", '', $strHtml);
$strHtml = str_replace("", '', $strHtml);
}
}
// clean up useless label tags
if (strpos($strHtml, '{label_')) {
$strHtml = preg_replace('/\s*.*\s*/i', '', $strHtml);
}
$placeHolders = array(
'{stylesheet}',
'{javascript}',
'{class}',
'{unselected}',
'{selected}',
'{add}',
'{remove}',
'{all}',
'{none}',
'{toggle}',
'{moveup}',
'{movedown}',
);
$htmlElements = array(
$this->getElementCss(FALSE),
$this->getElementJs(FALSE),
$this->_tableAttributes,
$strHtmlUnselected,
$strHtmlSelected . $strHtmlHidden,
$strHtmlAdd,
$strHtmlRemove,
$strHtmlAll,
$strHtmlNone,
$strHtmlToggle,
$strHtmlMoveUp,
$strHtmlMoveDown,
);
$strHtml = str_replace($placeHolders, $htmlElements, $strHtml);
return $strHtml;
}
}