HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/PvdBoogaard/indoorski.nl/backup/oude-site/cms/api/form/class.field.multiselect.php
<?php

/**
 * This file contains the iwp_field_multiselect class
 *
 * @version $Id$
 * 
 *
 * @package IWP
 * @subpackage IWP_FormFields
 */

/**
 * MultiSelect Field Class
 * This class is used by the api form class to generate a select list using the ISSelectReplacement library
 * It takes a list of options and outputs a select list.
 *
 * @package IWP
 * @subpackage IWP_FormFields
 */

class iwp_field_multiselect extends iwp_field {
	/**
	 * This is the form field type of the field
	 *
	 * @var string
	 */
	public $type = 'multiselect';
	public $height = 200;
	public $width= 350;
	protected $showLabel = false;

	/**
	 * __construct
	 * The constructor which calls the parent constructor that sets up the field name if it is passed in during the initialization
	 *
	 * @var string
	 */
	public function __construct($name=null){
		parent::__construct($name);
	}

	/**
	 * Overriding the Value function to allow for multiple selections
	 *
	 * @param Mixed $val The value to append to be selected
	**/
	public function Value($val, $key=null) {
		if($key === null){
			$this->FieldValue[] = $val;
		}else{
			$this->FieldValue[$key] = $val;
		}
	}

	/**
	 * GetFieldOutput
	 * Returns the HTML for this field. It generates the relevant parts, assigns them to template variables and returns a parse template file.
	 *
	 * @return string Returns the field HTML
	 */
	public function GetFieldOutput($setOnly=false){
		$inputField = $this->Prepend.'<select id="'. iwp_htmlspecialchars($this->FieldName) .'"  class="ISSelectReplacement" multiple="multiple" style="height: '.(int)$this->height.'px; width: '.(int)$this->width.'px;" name="'. iwp_htmlspecialchars($this->FieldName) .'" ';
		$inputField .= $this->GetAttributes();
		$inputField .= '>';
		if(is_array($this->FieldOptions)){
			foreach($this->FieldOptions as $k=>$v){
				$inputField .= '<option value="'. iwp_htmlspecialchars($k) .'" ';
				if(is_array($this->FieldValue)){
					if(in_array($k, $this->FieldValue)){
						$inputField .= ' selected';
					}
				}else{
					if($this->FieldValue == $k){
						$inputField .= ' selected';
					}
				}

				$valueHTML = iwp_htmlspecialchars($v);

				//	special case for selects, allow repeated spaces at the beginning of items to be treated as indentation
				$valueHTML = preg_replace('#^(\s{2,})#e', 'str_repeat("&nbsp;", strlen("$1"))', $valueHTML);

				$inputField .= '>'. $valueHTML .'</option>';
			}
		}
		$inputField .= '</select>'.$this->Append;

		parent::GetFieldOutput();

		$this->template->Assign('inputField', $inputField);
		$this->template->Assign('FieldName', $this->FieldName);

		if(!$setOnly){
			return $this->template->ParseTemplate('form.field', true);
		}
		return '';
	}

	/**
	 * LoadValue
	 * This is takes an array of data and picks of the value for this specific field and stores in in the FieldValue variable
	 *
	 * @return void Doesn't return anything
	 */
	public function LoadValue($arrData){
		if(isset($arrData[$this->FieldName])){
			$this->FieldValue = CleanArray(explode(',', $arrData[$this->FieldName]));
		}
	}

	/**
	 * Validate
	 * This is the function that data for this field is passed to to ensure it was submitted properly.
	 *
	 * @return string|boolean If the data is not valid, it will return false, if it is valid it will return a value
	 */
	public function Validate($arrData){
		return $arrData['ISelector_'.$this->FieldName];
	}

	/**
	 * Gets the key used in the Post data. For this field its prepended by different text
	 *
	 * @return void
	 *
	 * @see FieldValue
	 **/
	public function PostFieldName(){
		return 'ISelector_'.$this->FieldName;
	}

}