|
|
|
@ -50,6 +50,8 @@ |
|
|
|
|
define('HTML_QUICKFORM_ADVMULTISELECT_ERROR_INVALID_INPUT', 1); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @todo clean class to use only with the multiselect.js library |
|
|
|
|
* |
|
|
|
|
* Element for HTML_QuickForm that emulate a multi-select. |
|
|
|
|
* |
|
|
|
|
* The HTML_QuickForm_advmultiselect package adds an element to the |
|
|
|
@ -67,24 +69,6 @@ define('HTML_QUICKFORM_ADVMULTISELECT_ERROR_INVALID_INPUT', 1); |
|
|
|
|
*/ |
|
|
|
|
class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
{ |
|
|
|
|
/** |
|
|
|
|
* Prefix function name in javascript move selections |
|
|
|
|
* |
|
|
|
|
* @var string |
|
|
|
|
* @access private |
|
|
|
|
* @since 0.4.0 |
|
|
|
|
*/ |
|
|
|
|
var $_jsPrefix; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Postfix function name in javascript move selections |
|
|
|
|
* |
|
|
|
|
* @var string |
|
|
|
|
* @access private |
|
|
|
|
* @since 0.4.0 |
|
|
|
|
*/ |
|
|
|
|
var $_jsPostfix; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Associative array of the multi select container attributes |
|
|
|
|
* |
|
|
|
@ -92,7 +76,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
* @access private |
|
|
|
|
* @since 0.4.0 |
|
|
|
|
*/ |
|
|
|
|
var $_tableAttributes; |
|
|
|
|
public $_tableAttributes; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Associative array of the add button attributes |
|
|
|
@ -101,7 +85,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
* @access private |
|
|
|
|
* @since 0.4.0 |
|
|
|
|
*/ |
|
|
|
|
var $_addButtonAttributes; |
|
|
|
|
public $_addButtonAttributes; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Associative array of the remove button attributes |
|
|
|
@ -110,7 +94,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
* @access private |
|
|
|
|
* @since 0.4.0 |
|
|
|
|
*/ |
|
|
|
|
var $_removeButtonAttributes; |
|
|
|
|
public $_removeButtonAttributes; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Associative array of the select all button attributes |
|
|
|
@ -119,7 +103,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
* @access private |
|
|
|
|
* @since 1.1.0 |
|
|
|
|
*/ |
|
|
|
|
var $_allButtonAttributes; |
|
|
|
|
public $_allButtonAttributes; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Associative array of the select none button attributes |
|
|
|
@ -128,7 +112,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
* @access private |
|
|
|
|
* @since 1.1.0 |
|
|
|
|
*/ |
|
|
|
|
var $_noneButtonAttributes; |
|
|
|
|
public $_noneButtonAttributes; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Associative array of the toggle selection button attributes |
|
|
|
@ -137,7 +121,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
* @access private |
|
|
|
|
* @since 1.1.0 |
|
|
|
|
*/ |
|
|
|
|
var $_toggleButtonAttributes; |
|
|
|
|
public $_toggleButtonAttributes; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Associative array of the move up button attributes |
|
|
|
@ -146,7 +130,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
* @access private |
|
|
|
|
* @since 0.5.0 |
|
|
|
|
*/ |
|
|
|
|
var $_upButtonAttributes; |
|
|
|
|
public $_upButtonAttributes; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Associative array of the move up button attributes |
|
|
|
@ -155,7 +139,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
* @access private |
|
|
|
|
* @since 0.5.0 |
|
|
|
|
*/ |
|
|
|
|
var $_downButtonAttributes; |
|
|
|
|
public $_downButtonAttributes; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Associative array of the move top button attributes |
|
|
|
@ -164,7 +148,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
* @access private |
|
|
|
|
* @since 1.5.0 |
|
|
|
|
*/ |
|
|
|
|
var $_topButtonAttributes; |
|
|
|
|
public $_topButtonAttributes; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Associative array of the move bottom button attributes |
|
|
|
@ -173,7 +157,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
* @access private |
|
|
|
|
* @since 1.5.0 |
|
|
|
|
*/ |
|
|
|
|
var $_bottomButtonAttributes; |
|
|
|
|
public $_bottomButtonAttributes; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Defines if both list (unselected, selected) will have their elements be |
|
|
|
@ -187,7 +171,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
* @access private |
|
|
|
|
* @since 0.5.0 |
|
|
|
|
*/ |
|
|
|
|
var $_sort; |
|
|
|
|
public $_sort; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Associative array of the unselected item box attributes |
|
|
|
@ -196,7 +180,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
* @access private |
|
|
|
|
* @since 0.4.0 |
|
|
|
|
*/ |
|
|
|
|
var $_attributesUnselected; |
|
|
|
|
public $_attributesUnselected; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Associative array of the selected item box attributes |
|
|
|
@ -205,7 +189,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
* @access private |
|
|
|
|
* @since 0.4.0 |
|
|
|
|
*/ |
|
|
|
|
var $_attributesSelected; |
|
|
|
|
public $_attributesSelected; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Associative array of the internal hidden box attributes |
|
|
|
@ -214,8 +198,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
* @access private |
|
|
|
|
* @since 0.4.0 |
|
|
|
|
*/ |
|
|
|
|
var $_attributesHidden; |
|
|
|
|
|
|
|
|
|
public $_attributesHidden; |
|
|
|
|
public $selectAllCheckBox = false; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -225,7 +208,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
* @access private |
|
|
|
|
* @since 0.4.0 |
|
|
|
|
*/ |
|
|
|
|
var $_elementTemplate; |
|
|
|
|
public $_elementTemplate; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Default Element stylesheet string |
|
|
|
@ -234,15 +217,11 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
* @access private |
|
|
|
|
* @since 0.4.0 |
|
|
|
|
*/ |
|
|
|
|
var $_elementCSS = ''; |
|
|
|
|
public $_elementCSS = ''; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Class constructor |
|
|
|
|
* |
|
|
|
|
* Class constructors : |
|
|
|
|
* Zend Engine 1 uses HTML_QuickForm_advmultiselect, while |
|
|
|
|
* Zend Engine 2 uses __construct |
|
|
|
|
* |
|
|
|
|
* @param string $elementName Dual Select name attribute |
|
|
|
|
* @param mixed $elementLabel Label(s) for the select boxes |
|
|
|
|
* @param mixed $options Data to be used to populate options |
|
|
|
@ -267,7 +246,6 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
$options = null; // prevent to use the default select element load options |
|
|
|
|
|
|
|
|
|
parent::__construct($elementName, $elementLabel, $options, $attributes); |
|
|
|
|
|
|
|
|
|
$this->selectAllCheckBox = isset($attributes['select_all_checkbox']) ? $attributes['select_all_checkbox'] : false; |
|
|
|
|
|
|
|
|
|
// allow to load options at once and take care of fancy attributes |
|
|
|
@ -284,16 +262,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
// default width of each select box |
|
|
|
|
$this->updateAttributes(array('class' => 'form-control')); |
|
|
|
|
} |
|
|
|
|
/* $this->_tableAttributes = $this->getAttribute('class'); |
|
|
|
|
$attr = null; |
|
|
|
|
if (is_null($this->_tableAttributes)) { |
|
|
|
|
$this->updateAttributes(array('class' => 'col-md-4')); |
|
|
|
|
} else { |
|
|
|
|
$attr = array('class' => $this->_tableAttributes); |
|
|
|
|
$this->_removeAttr('class', $this->_attributes); |
|
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
//$this->_tableAttributes = $this->_getAttrString($attr); |
|
|
|
|
$this->removeAttribute('class'); |
|
|
|
|
$this->setAttribute('class','form-control'); |
|
|
|
|
|
|
|
|
@ -315,9 +284,6 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
$this->setButtonAttributes('movetop'); |
|
|
|
|
// set default move bottom button attributes |
|
|
|
|
$this->setButtonAttributes('movebottom'); |
|
|
|
|
// defines javascript functions names |
|
|
|
|
$this->_jsPrefix = 'QFAMS.'; |
|
|
|
|
$this->_jsPostfix = 'moveSelection'; |
|
|
|
|
|
|
|
|
|
// set select boxes sort order (none by default) |
|
|
|
|
if (!isset($sort)) { |
|
|
|
@ -381,7 +347,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
* @link http://www.laurent-laville.org/img/qfams/screenshot/custom1.png |
|
|
|
|
* Custom example 1: screenshot |
|
|
|
|
*/ |
|
|
|
|
function setButtonAttributes($button, $attributes = null) |
|
|
|
|
public function setButtonAttributes($button, $attributes = null) |
|
|
|
|
{ |
|
|
|
|
if (!is_string($button)) { |
|
|
|
|
return PEAR::throwError('Argument 1 of HTML_QuickForm_advmultiselect::' . |
|
|
|
@ -509,13 +475,13 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
* Sets element template |
|
|
|
|
* |
|
|
|
|
* @param string $html (optional) The HTML surrounding select boxes and buttons |
|
|
|
|
* @param string $js (optional) if we need to include qfams javascript handler |
|
|
|
|
* @param bool $js (optional) if we need to include qfams javascript handler |
|
|
|
|
* |
|
|
|
|
* @access public |
|
|
|
|
* @return string |
|
|
|
|
* @since version 0.4.0 (2005-06-25) |
|
|
|
|
*/ |
|
|
|
|
function setElementTemplate($html = null, $js = true) |
|
|
|
|
public function setElementTemplate($html = null, $js = true) |
|
|
|
|
{ |
|
|
|
|
$oldTemplate = $this->_elementTemplate; |
|
|
|
|
|
|
|
|
@ -531,7 +497,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
</div> |
|
|
|
|
'; |
|
|
|
|
} |
|
|
|
|
if ($js == false) { |
|
|
|
|
if ($js === false) { |
|
|
|
|
$this->_elementTemplate = str_replace('{javascript}', '', |
|
|
|
|
$this->_elementTemplate); |
|
|
|
|
} |
|
|
|
@ -558,7 +524,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
* @link http://www.laurent-laville.org/img/qfams/screenshot/custom4.png |
|
|
|
|
* Custom example 4: screenshot |
|
|
|
|
*/ |
|
|
|
|
function getElementCss($raw = true) |
|
|
|
|
public function getElementCss($raw = true) |
|
|
|
|
{ |
|
|
|
|
$id = $this->getAttribute('name'); |
|
|
|
|
$css = str_replace('{id}', $id, $this->_elementCSS); |
|
|
|
@ -587,17 +553,17 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
$tabs = $this->_getTabs(); |
|
|
|
|
$tab = $this->_getTab(); |
|
|
|
|
|
|
|
|
|
$selectId = $this->getName(); |
|
|
|
|
$selectName = $this->getName() . '[]'; |
|
|
|
|
$selectNameFrom = $this->getName() . '-f[]'; |
|
|
|
|
$selectNameTo = $this->getName() . '-t[]'; |
|
|
|
|
$selectId = $this->getName(); |
|
|
|
|
$selectName = $this->getName().'[]'; |
|
|
|
|
$selectNameFrom = $this->getName().'-f[]'; |
|
|
|
|
$selectNameTo = $this->getName().'[]'; |
|
|
|
|
$selected_count = 0; |
|
|
|
|
$rightAll = ''; |
|
|
|
|
$leftAll = ''; |
|
|
|
|
|
|
|
|
|
// placeholder {unselected} existence determines if we will render |
|
|
|
|
if (strpos($this->_elementTemplate, '{unselected}') === false) { |
|
|
|
|
// ... a single multi-select with checkboxes |
|
|
|
|
$this->_jsPostfix = 'editSelection'; |
|
|
|
|
|
|
|
|
|
$id = $this->getAttribute('name'); |
|
|
|
|
|
|
|
|
|
$strHtmlSelected = $tab . '<div id="qfams_'.$id.'">' . PHP_EOL; |
|
|
|
@ -615,8 +581,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (is_array($this->_values) |
|
|
|
|
&& in_array((string)$option['attr']['value'], $this->_values)) { |
|
|
|
|
if (is_array($this->_values) && in_array((string)$option['attr']['value'], $this->_values)) { |
|
|
|
|
// The items is *selected* |
|
|
|
|
$checked = ' checked="checked"'; |
|
|
|
|
$selected_count++; |
|
|
|
@ -626,89 +591,75 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
} |
|
|
|
|
$checkbox_id_suffix++; |
|
|
|
|
$strHtmlSelected .= $tab |
|
|
|
|
. '<label' |
|
|
|
|
. $this->_getAttrString($labelAttributes) .'>' |
|
|
|
|
. '<input type="checkbox"' |
|
|
|
|
. ' id="'.$selectId . $checkbox_id_suffix.'"' |
|
|
|
|
. ' name="'.$selectName.'"' |
|
|
|
|
. $checked |
|
|
|
|
. $this->_getAttrString($option['attr']) |
|
|
|
|
. ' />' . $option['text'] . '</label>' |
|
|
|
|
. PHP_EOL; |
|
|
|
|
.'<label' |
|
|
|
|
.$this->_getAttrString($labelAttributes).'>' |
|
|
|
|
.'<input type="checkbox"' |
|
|
|
|
.' id="'.$selectId.$checkbox_id_suffix.'"' |
|
|
|
|
.' name="'.$selectName.'"' |
|
|
|
|
.$checked.$this->_getAttrString($option['attr']) |
|
|
|
|
.' />'.$option['text'].'</label>' |
|
|
|
|
.PHP_EOL; |
|
|
|
|
} |
|
|
|
|
$strHtmlSelected .= $tab . '</div>'. PHP_EOL; |
|
|
|
|
|
|
|
|
|
$strHtmlHidden = ''; |
|
|
|
|
$strHtmlHidden = ''; |
|
|
|
|
$strHtmlUnselected = ''; |
|
|
|
|
$strHtmlAdd = ''; |
|
|
|
|
$strHtmlRemove = ''; |
|
|
|
|
$strHtmlAdd = ''; |
|
|
|
|
$strHtmlRemove = ''; |
|
|
|
|
|
|
|
|
|
// build the select all button with all its attributes |
|
|
|
|
$jsName = $this->_jsPrefix . $this->_jsPostfix; |
|
|
|
|
$attributes = array('onclick' => $jsName ."('". $selectId ."', 1);"); |
|
|
|
|
$attributes = []; |
|
|
|
|
$this->_allButtonAttributes = array_merge($this->_allButtonAttributes, $attributes); |
|
|
|
|
$attrStrAll = $this->_getAttrString($this->_allButtonAttributes); |
|
|
|
|
$strHtmlAll = "<input$attrStrAll />". PHP_EOL; |
|
|
|
|
|
|
|
|
|
// build the select none button with all its attributes |
|
|
|
|
$attributes = array('onclick' => $jsName ."('". $selectId ."', 0);"); |
|
|
|
|
$attributes = []; |
|
|
|
|
$this->_noneButtonAttributes |
|
|
|
|
= array_merge($this->_noneButtonAttributes, $attributes); |
|
|
|
|
$attrStrNone = $this->_getAttrString($this->_noneButtonAttributes); |
|
|
|
|
$strHtmlNone = "<input$attrStrNone />". PHP_EOL; |
|
|
|
|
|
|
|
|
|
// build the toggle selection button with all its attributes |
|
|
|
|
$attributes = array('onclick' => $jsName . |
|
|
|
|
"('". $selectId ."', 2);"); |
|
|
|
|
$attributes = []; |
|
|
|
|
$this->_toggleButtonAttributes = array_merge($this->_toggleButtonAttributes, $attributes); |
|
|
|
|
$attrStrToggle = $this->_getAttrString($this->_toggleButtonAttributes); |
|
|
|
|
$strHtmlToggle = "<input$attrStrToggle />". PHP_EOL; |
|
|
|
|
|
|
|
|
|
$strHtmlMoveUp = ''; |
|
|
|
|
$strHtmlMoveDown = ''; |
|
|
|
|
$strHtmlMoveTop = ''; |
|
|
|
|
$strHtmlMoveBottom = ''; |
|
|
|
|
$strHtmlMoveUp = ''; |
|
|
|
|
$strHtmlMoveDown = ''; |
|
|
|
|
$strHtmlMoveTop = ''; |
|
|
|
|
$strHtmlMoveBottom = ''; |
|
|
|
|
|
|
|
|
|
// default selection counters |
|
|
|
|
$strHtmlSelectedCount = $selected_count . '/' . $unselected_count; |
|
|
|
|
} else { |
|
|
|
|
// ... or a dual multi-select |
|
|
|
|
$this->_jsPostfix = 'moveSelection'; |
|
|
|
|
$jsName = $this->_jsPrefix . $this->_jsPostfix; |
|
|
|
|
|
|
|
|
|
// set name of Select From Box |
|
|
|
|
$this->_attributesUnselected |
|
|
|
|
= array('id' => $selectId . '-f', |
|
|
|
|
= array( |
|
|
|
|
'id' => $selectId.'', |
|
|
|
|
'name' => $selectNameFrom, |
|
|
|
|
'ondblclick' => $jsName . |
|
|
|
|
"('{$selectId}', ". |
|
|
|
|
"this.form.elements['" . $selectNameFrom . "'], " . |
|
|
|
|
"this.form.elements['" . $selectNameTo . "'], " . |
|
|
|
|
"this.form.elements['" . $selectName . "'], " . |
|
|
|
|
"'add', '{$this->_sort}')"); |
|
|
|
|
); |
|
|
|
|
$this->_attributesUnselected |
|
|
|
|
= array_merge($this->_attributes, $this->_attributesUnselected); |
|
|
|
|
$attrUnselected = $this->_getAttrString($this->_attributesUnselected); |
|
|
|
|
|
|
|
|
|
// set name of Select To Box |
|
|
|
|
$this->_attributesSelected |
|
|
|
|
= array('id' => $selectId . '-t', |
|
|
|
|
= array( |
|
|
|
|
'id' => $selectId.'_to', |
|
|
|
|
'name' => $selectNameTo, |
|
|
|
|
'ondblclick' => $jsName . |
|
|
|
|
"('{$selectId}', " . |
|
|
|
|
"this.form.elements['" . $selectNameFrom . "'], " . |
|
|
|
|
"this.form.elements['" . $selectNameTo . "'], ". |
|
|
|
|
"this.form.elements['" . $selectName . "'], " . |
|
|
|
|
"'remove', '{$this->_sort}')"); |
|
|
|
|
); |
|
|
|
|
$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;'); |
|
|
|
|
= 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); |
|
|
|
@ -721,18 +672,17 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
$arrHtmlSelected = array(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$options = count($this->_options); |
|
|
|
|
$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)) { |
|
|
|
|
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); |
|
|
|
|
$key = array_search( |
|
|
|
|
$option['attr']['value'], |
|
|
|
|
$this->_values |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
/** The items is *selected* so we want to put it |
|
|
|
|
in the 'selected' multi-select */ |
|
|
|
@ -753,40 +703,29 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
$append++; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
$arrHtmlHidden = array(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// The 'unselected' multi-select which appears on the left |
|
|
|
|
$unselected_count = count($arrHtmlUnselected); |
|
|
|
|
|
|
|
|
|
if ($unselected_count == 0) { |
|
|
|
|
$this->_attributesUnselected['disabled'] = 'disabled'; |
|
|
|
|
$this->_attributesUnselected |
|
|
|
|
= array_merge($this->_attributes, $this->_attributesUnselected); |
|
|
|
|
$this->_attributesUnselected = array_merge($this->_attributes, $this->_attributesUnselected); |
|
|
|
|
$attrUnselected = $this->_getAttrString($this->_attributesUnselected); |
|
|
|
|
} |
|
|
|
|
$strHtmlUnselected = "<select$attrUnselected>". PHP_EOL; |
|
|
|
|
if ($unselected_count > 0) { |
|
|
|
|
foreach ($arrHtmlUnselected as $data) { |
|
|
|
|
$strHtmlUnselected |
|
|
|
|
.= $tabs . $tab |
|
|
|
|
. '<option' . $this->_getAttrString($data['attr']) . '>' |
|
|
|
|
. $data['text'] . '</option>' . PHP_EOL; |
|
|
|
|
.= $tabs.$tab |
|
|
|
|
.'<option'.$this->_getAttrString($data['attr']).'>' |
|
|
|
|
.$data['text'].'</option>'.PHP_EOL; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
$strHtmlUnselected .= '<option value=""> </option>'; |
|
|
|
|
} |
|
|
|
|
$strHtmlUnselected .= '</select>'; |
|
|
|
|
|
|
|
|
|
$strHtmlUnselected = '<input placeholder="'.get_lang('Search').'" id="'.$selectId.'-f-filter" type="text" class="form-control search-query select_class_filter"><br />'.$strHtmlUnselected; |
|
|
|
|
// The 'selected' multi-select which appears on the right |
|
|
|
|
$selected_count = count($arrHtmlSelected); |
|
|
|
|
|
|
|
|
|
if ($selected_count == 0) { |
|
|
|
|
$this->_attributesSelected['disabled'] = 'disabled'; |
|
|
|
|
$this->_attributesSelected |
|
|
|
|
= array_merge($this->_attributes, $this->_attributesSelected); |
|
|
|
|
$this->_attributesSelected = array_merge($this->_attributes, $this->_attributesSelected); |
|
|
|
|
$attrSelected = $this->_getAttrString($this->_attributesSelected); |
|
|
|
|
} |
|
|
|
|
$strHtmlSelected = "<select$attrSelected>"; |
|
|
|
@ -802,139 +741,77 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
$text = $data['text']; |
|
|
|
|
} |
|
|
|
|
$strHtmlSelected |
|
|
|
|
.= $tabs . $tab |
|
|
|
|
. '<option' . $attribute. '>' |
|
|
|
|
. $text . '</option>'; |
|
|
|
|
.= $tabs.$tab |
|
|
|
|
.'<option'.$attribute.'>' |
|
|
|
|
.$text.'</option>'; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
$strHtmlSelected .= '<option value=""> </option>'; |
|
|
|
|
} |
|
|
|
|
$strHtmlSelected .= '</select>'; |
|
|
|
|
|
|
|
|
|
$strHtmlSelected = '<input placeholder="'.get_lang('Search').'" id="'.$selectId.'-t-filter" type="text" class="form-control search-query select_class_filter"><br />'.$strHtmlSelected; |
|
|
|
|
|
|
|
|
|
// The 'hidden' multi-select |
|
|
|
|
$strHtmlHidden = "<select$attrHidden>". PHP_EOL; |
|
|
|
|
if (count($arrHtmlHidden) > 0) { |
|
|
|
|
foreach ($arrHtmlHidden as $data) { |
|
|
|
|
$attribute = null; |
|
|
|
|
if (isset($data['attr'])) { |
|
|
|
|
$attribute = $this->_getAttrString($data['attr']); |
|
|
|
|
} |
|
|
|
|
$text = null; |
|
|
|
|
if (isset($data['text'])) { |
|
|
|
|
$text = $data['text']; |
|
|
|
|
} |
|
|
|
|
$strHtmlHidden |
|
|
|
|
.= $tabs . $tab |
|
|
|
|
. '<option' . $attribute . '>' |
|
|
|
|
. $text . '</option>' . PHP_EOL; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$strHtmlHidden .= '</select>'; |
|
|
|
|
|
|
|
|
|
// build the remove button with all its attributes |
|
|
|
|
$attributes |
|
|
|
|
= array('onclick' => $jsName . |
|
|
|
|
"('{$selectId}', " . |
|
|
|
|
"this.form.elements['" . $selectNameFrom . "'], " . |
|
|
|
|
"this.form.elements['" . $selectNameTo . "'], " . |
|
|
|
|
"this.form.elements['" . $selectName . "'], " . |
|
|
|
|
"'remove', '{$this->_sort}'); return false;"); |
|
|
|
|
$strHtmlHidden = ''; |
|
|
|
|
$attributes = array('id' => $selectId.'_leftSelected'); |
|
|
|
|
$this->_removeButtonAttributes |
|
|
|
|
= array_merge($this->_removeButtonAttributes, $attributes); |
|
|
|
|
$attrStrRemove = $this->_getAttrString($this->_removeButtonAttributes); |
|
|
|
|
$strHtmlRemove = "<button $attrStrRemove /> <em class='fa fa-arrow-left'></em></button>"; |
|
|
|
|
|
|
|
|
|
// build the add button with all its attributes |
|
|
|
|
$attributes |
|
|
|
|
= array('onclick' => $jsName . |
|
|
|
|
"('{$selectId}', " . |
|
|
|
|
"this.form.elements['" . $selectNameFrom . "'], " . |
|
|
|
|
"this.form.elements['" . $selectNameTo . "'], " . |
|
|
|
|
"this.form.elements['" . $selectName . "'], " . |
|
|
|
|
"'add', '{$this->_sort}'); return false;"); |
|
|
|
|
$attributes = array('id' => $selectId.'_rightSelected'); |
|
|
|
|
$this->_addButtonAttributes = array_merge($this->_addButtonAttributes, $attributes); |
|
|
|
|
$attrStrAdd = $this->_getAttrString($this->_addButtonAttributes); |
|
|
|
|
$strHtmlAdd = "<button $attrStrAdd /> <em class='fa fa-arrow-right'></em></button><br /><br />"; |
|
|
|
|
|
|
|
|
|
if ($this->selectAllCheckBox) { |
|
|
|
|
$attributes = array('id' => $selectId.'_rightAll'); |
|
|
|
|
$this->_addButtonAttributes = array_merge($this->_addButtonAttributes, $attributes); |
|
|
|
|
$attrStrAdd = $this->_getAttrString($this->_addButtonAttributes); |
|
|
|
|
$rightAll = "<button $attrStrAdd /> <em class='fa fa-forward'></em></button><br /><br />"; |
|
|
|
|
|
|
|
|
|
$attributes = array('id' => $selectId.'_leftAll'); |
|
|
|
|
$this->_addButtonAttributes = array_merge($this->_addButtonAttributes, $attributes); |
|
|
|
|
$attrStrAdd = $this->_getAttrString($this->_addButtonAttributes); |
|
|
|
|
$leftAll = "<br /><br /><button $attrStrAdd /> <em class='fa fa-backward'></em></button>"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// build the select all button with all its attributes |
|
|
|
|
$attributes |
|
|
|
|
= array('onclick' => $jsName . |
|
|
|
|
"('{$selectId}', " . |
|
|
|
|
"this.form.elements['" . $selectNameFrom . "'], " . |
|
|
|
|
"this.form.elements['" . $selectNameTo . "'], " . |
|
|
|
|
"this.form.elements['" . $selectName . "'], " . |
|
|
|
|
"'all', '{$this->_sort}'); return false;"); |
|
|
|
|
$this->_allButtonAttributes = array_merge($this->_allButtonAttributes, $attributes); |
|
|
|
|
$attrStrAll = $this->_getAttrString($this->_allButtonAttributes); |
|
|
|
|
$strHtmlAll = "<input$attrStrAll />". PHP_EOL; |
|
|
|
|
$strHtmlAll = ''; |
|
|
|
|
|
|
|
|
|
// build the select none button with all its attributes |
|
|
|
|
$attributes |
|
|
|
|
= array('onclick' => $jsName . |
|
|
|
|
"('{$selectId}', " . |
|
|
|
|
"this.form.elements['" . $selectNameFrom . "'], " . |
|
|
|
|
"this.form.elements['" . $selectNameTo . "'], " . |
|
|
|
|
"this.form.elements['" . $selectName . "'], " . |
|
|
|
|
"'none', '{$this->_sort}'); return false;"); |
|
|
|
|
$attributes = []; |
|
|
|
|
$this->_noneButtonAttributes |
|
|
|
|
= array_merge($this->_noneButtonAttributes, $attributes); |
|
|
|
|
$attrStrNone = $this->_getAttrString($this->_noneButtonAttributes); |
|
|
|
|
$strHtmlNone = "<input$attrStrNone />". PHP_EOL; |
|
|
|
|
|
|
|
|
|
// build the toggle button with all its attributes |
|
|
|
|
$attributes |
|
|
|
|
= array('onclick' => $jsName . |
|
|
|
|
"('{$selectId}', " . |
|
|
|
|
"this.form.elements['" . $selectNameFrom . "'], " . |
|
|
|
|
"this.form.elements['" . $selectNameTo . "'], " . |
|
|
|
|
"this.form.elements['" . $selectName . "'], " . |
|
|
|
|
"'toggle', '{$this->_sort}'); return false;"); |
|
|
|
|
$attributes = []; |
|
|
|
|
$this->_toggleButtonAttributes |
|
|
|
|
= array_merge($this->_toggleButtonAttributes, $attributes); |
|
|
|
|
$attrStrToggle = $this->_getAttrString($this->_toggleButtonAttributes); |
|
|
|
|
$strHtmlToggle = "<input$attrStrToggle />". PHP_EOL; |
|
|
|
|
|
|
|
|
|
// build the move up button with all its attributes |
|
|
|
|
$attributes |
|
|
|
|
= array('onclick' => "{$this->_jsPrefix}moveUp" . |
|
|
|
|
"(this.form.elements['" . $selectNameTo . "'], " . |
|
|
|
|
"this.form.elements['" . $selectName . "']); " . |
|
|
|
|
"return false;"); |
|
|
|
|
$attributes = []; |
|
|
|
|
$this->_upButtonAttributes |
|
|
|
|
= array_merge($this->_upButtonAttributes, $attributes); |
|
|
|
|
$attrStrUp = $this->_getAttrString($this->_upButtonAttributes); |
|
|
|
|
$strHtmlMoveUp = "<input$attrStrUp />". PHP_EOL; |
|
|
|
|
|
|
|
|
|
// build the move down button with all its attributes |
|
|
|
|
$attributes |
|
|
|
|
= array('onclick' => "{$this->_jsPrefix}moveDown" . |
|
|
|
|
"(this.form.elements['" . $selectNameTo . "'], " . |
|
|
|
|
"this.form.elements['" . $selectName . "']); " . |
|
|
|
|
"return false;"); |
|
|
|
|
$attributes = []; |
|
|
|
|
$this->_downButtonAttributes |
|
|
|
|
= array_merge($this->_downButtonAttributes, $attributes); |
|
|
|
|
$attrStrDown = $this->_getAttrString($this->_downButtonAttributes); |
|
|
|
|
$strHtmlMoveDown = "<input$attrStrDown />". PHP_EOL; |
|
|
|
|
|
|
|
|
|
// build the move top button with all its attributes |
|
|
|
|
$attributes |
|
|
|
|
= array('onclick' => "{$this->_jsPrefix}moveTop" . |
|
|
|
|
"(this.form.elements['" . $selectNameTo . "'], " . |
|
|
|
|
"this.form.elements['" . $selectName . "']); " . |
|
|
|
|
"return false;"); |
|
|
|
|
$attributes = []; |
|
|
|
|
$this->_topButtonAttributes |
|
|
|
|
= array_merge($this->_topButtonAttributes, $attributes); |
|
|
|
|
$attrStrTop = $this->_getAttrString($this->_topButtonAttributes); |
|
|
|
|
$strHtmlMoveTop = "<input$attrStrTop />". PHP_EOL; |
|
|
|
|
|
|
|
|
|
// build the move bottom button with all its attributes |
|
|
|
|
$attributes |
|
|
|
|
= array('onclick' => "{$this->_jsPrefix}moveBottom" . |
|
|
|
|
"(this.form.elements['" . $selectNameTo . "'], " . |
|
|
|
|
"this.form.elements['" . $selectName . "']); " . |
|
|
|
|
"return false;"); |
|
|
|
|
$attributes = []; |
|
|
|
|
$this->_bottomButtonAttributes |
|
|
|
|
= array_merge($this->_bottomButtonAttributes, $attributes); |
|
|
|
|
$attrStrBottom = $this->_getAttrString($this->_bottomButtonAttributes); |
|
|
|
@ -944,7 +821,6 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
$strHtmlSelectedCount = $selected_count; |
|
|
|
|
} |
|
|
|
|
$strHtmlUnselectedCount = $unselected_count; |
|
|
|
|
|
|
|
|
|
$strHtmlSelectedCountId = $selectId .'_selected'; |
|
|
|
|
$strHtmlUnselectedCountId = $selectId .'_unselected'; |
|
|
|
|
|
|
|
|
@ -959,7 +835,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
// render extra labels, if any |
|
|
|
|
if (is_array($labels)) { |
|
|
|
|
foreach ($labels as $key => $text) { |
|
|
|
|
$key = is_int($key)? $key + 2: $key; |
|
|
|
|
$key = is_int($key) ? $key + 2 : $key; |
|
|
|
|
$strHtml = str_replace("{label_{$key}}", $text, $strHtml); |
|
|
|
|
$strHtml = str_replace("<!-- BEGIN label_{$key} -->", '', $strHtml); |
|
|
|
|
$strHtml = str_replace("<!-- END label_{$key} -->", '', $strHtml); |
|
|
|
@ -1003,8 +879,8 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
$strHtmlSelectedCount, |
|
|
|
|
$strHtmlUnselected, |
|
|
|
|
$strHtmlSelected.$strHtmlHidden, |
|
|
|
|
$strHtmlAdd, |
|
|
|
|
$strHtmlRemove, |
|
|
|
|
$rightAll.$strHtmlAdd, |
|
|
|
|
$strHtmlRemove.$leftAll, |
|
|
|
|
$strHtmlAll, |
|
|
|
|
$strHtmlNone, |
|
|
|
|
$strHtmlToggle, |
|
|
|
@ -1014,14 +890,6 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
$strHtmlMoveBottom, |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
if ($this->selectAllCheckBox) { |
|
|
|
|
$strHtml .= '<div class="col-sm-8"> |
|
|
|
|
<label >'.get_lang('SelectAll').' |
|
|
|
|
<input type="checkbox" class="advmultiselect_checkbox" id="'.$selectId.'_select_all'.'"> |
|
|
|
|
</label> |
|
|
|
|
</div>'; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$strHtml = str_replace($placeHolders, $htmlElements, $strHtml); |
|
|
|
|
$comment = $this->getComment(); |
|
|
|
|
|
|
|
|
@ -1029,7 +897,6 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
$strHtml = $tabs . '<!-- ' . $comment . " //-->" . PHP_EOL . $strHtml; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $strHtml; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1043,20 +910,26 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
* @return string |
|
|
|
|
* @since version 0.4.0 (2005-06-25) |
|
|
|
|
*/ |
|
|
|
|
function getElementJs($raw = true, $min = true) |
|
|
|
|
public function getElementJs($raw = true, $min = true) |
|
|
|
|
{ |
|
|
|
|
$js = api_get_path(LIBRARY_PATH).'javascript'.DIRECTORY_SEPARATOR.'pear'.DIRECTORY_SEPARATOR; |
|
|
|
|
$js .= 'qfamsHandler.js'; |
|
|
|
|
|
|
|
|
|
if (file_exists($js)) { |
|
|
|
|
$js = file_get_contents($js); |
|
|
|
|
} else { |
|
|
|
|
$js = ''; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($raw !== true) { |
|
|
|
|
$js = '<script>'.PHP_EOL.$js.PHP_EOL.'</script>'.PHP_EOL; |
|
|
|
|
} |
|
|
|
|
$name = $this->getName(); |
|
|
|
|
$js = api_get_asset('multiselect-two-sides/dist/js/multiselect.js'); |
|
|
|
|
$search = |
|
|
|
|
'<input type="text" name="q" class="form-control" placeholder="'.addslashes(get_lang('Search')).'" /><br />'; |
|
|
|
|
|
|
|
|
|
$js .= '<script> |
|
|
|
|
$(document).ready(function() { |
|
|
|
|
$(\'#'.$name.'\').multiselect({ |
|
|
|
|
search: { |
|
|
|
|
left: \''.$search.'\', |
|
|
|
|
right: \''.$search.'\' |
|
|
|
|
}, |
|
|
|
|
fireSearch: function(value) { |
|
|
|
|
return value.length > 2; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
</script>'.PHP_EOL; |
|
|
|
|
|
|
|
|
|
return $js; |
|
|
|
|
} |
|
|
|
@ -1079,7 +952,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
* @throws PEAR_Error |
|
|
|
|
* @see loadArray() |
|
|
|
|
*/ |
|
|
|
|
function load(&$options, |
|
|
|
|
public function load(&$options, |
|
|
|
|
$param1 = null, $param2 = null, $param3 = null, $param4 = null) |
|
|
|
|
{ |
|
|
|
|
if (is_array($options)) { |
|
|
|
@ -1105,7 +978,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
* @throws PEAR_Error |
|
|
|
|
* @see load() |
|
|
|
|
*/ |
|
|
|
|
function loadArray($arr, $values = null) |
|
|
|
|
public function loadArray($arr, $values = null) |
|
|
|
|
{ |
|
|
|
|
if (!is_array($arr)) { |
|
|
|
|
return PEAR::throwError('Argument 1 of HTML_QuickForm_advmultiselect::' . |
|
|
|
@ -1127,71 +1000,4 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Sets which items should be persistant |
|
|
|
|
* |
|
|
|
|
* Sets which items should have the disabled attribute |
|
|
|
|
* to keep it persistant |
|
|
|
|
* |
|
|
|
|
* @param mixed $optionValues Options (key-values) that should be persistant |
|
|
|
|
* @param bool $persistant (optional) TRUE if persistant, FALSE otherwise |
|
|
|
|
* |
|
|
|
|
* @since version 1.5.0 (2009-02-15) |
|
|
|
|
* @access public |
|
|
|
|
* @return PEAR_Error on error and TRUE on success |
|
|
|
|
* @throws PEAR_Error |
|
|
|
|
*/ |
|
|
|
|
function setPersistantOptions($optionValues, $persistant = true) |
|
|
|
|
{ |
|
|
|
|
if (!is_bool($persistant)) { |
|
|
|
|
return PEAR::throwError('Argument 2 of HTML_QuickForm_advmultiselect::' . |
|
|
|
|
'setPersistantOptions is not a boolean', |
|
|
|
|
HTML_QUICKFORM_ADVMULTISELECT_ERROR_INVALID_INPUT, |
|
|
|
|
array('level' => 'exception')); |
|
|
|
|
} |
|
|
|
|
if (is_string($optionValues)) { |
|
|
|
|
$optionValues = array($optionValues); |
|
|
|
|
} |
|
|
|
|
if (!is_array($optionValues)) { |
|
|
|
|
return PEAR::throwError('Argument 1 of HTML_QuickForm_advmultiselect::' . |
|
|
|
|
'setPersistantOptions is not a valid array', |
|
|
|
|
HTML_QUICKFORM_ADVMULTISELECT_ERROR_INVALID_INPUT, |
|
|
|
|
array('level' => 'exception')); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
foreach ($this->_options as $k => $v) { |
|
|
|
|
if (in_array($v['attr']['value'], $optionValues)) { |
|
|
|
|
if ($persistant) { |
|
|
|
|
$this->_options[$k]['attr']['disabled'] = 'disabled'; |
|
|
|
|
} else { |
|
|
|
|
unset($this->_options[$k]['attr']['disabled']); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns list of persistant options |
|
|
|
|
* |
|
|
|
|
* Returns list of persistant options (key-values) that could not |
|
|
|
|
* be selected or unselected. |
|
|
|
|
* |
|
|
|
|
* @since version 1.5.0 (2009-02-15) |
|
|
|
|
* @access public |
|
|
|
|
* @return array |
|
|
|
|
*/ |
|
|
|
|
function getPersistantOptions() |
|
|
|
|
{ |
|
|
|
|
$options = array(); |
|
|
|
|
|
|
|
|
|
foreach ($this->_options as $k => $v) { |
|
|
|
|
if (isset($v['attr']['disabled'])) { |
|
|
|
|
$options[] = $this->_options[$k]['attr']['value']; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $options; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|