LDAPAccountManager/lam/lib/html.inc

3653 lines
109 KiB
PHP
Raw Normal View History

2010-05-23 10:35:33 +00:00
<?php
/*
$Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
2017-05-06 13:21:37 +00:00
Copyright (C) 2010 - 2017 Roland Gruber
2010-05-23 10:35:33 +00:00
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* Interface between modules and other parts of LAM.
*
2010-06-06 18:15:35 +00:00
* @package metaHTML
2010-05-23 10:35:33 +00:00
* @author Roland Gruber
*/
/**
* Represents a HTML element.
* This is used to build HTML code by using objects.
2015-07-29 19:14:10 +00:00
*
2010-06-06 18:15:35 +00:00
* @package metaHTML
2010-05-23 10:35:33 +00:00
*/
2010-06-13 12:34:52 +00:00
abstract class htmlElement {
2015-07-29 19:14:10 +00:00
2011-10-16 12:06:00 +00:00
/** align to top */
2010-06-06 18:15:35 +00:00
const ALIGN_TOP = 0;
2011-10-16 12:06:00 +00:00
/** align to left */
2010-06-06 18:15:35 +00:00
const ALIGN_LEFT = 1;
2011-10-16 12:06:00 +00:00
/** align to right */
2010-06-06 18:15:35 +00:00
const ALIGN_RIGHT = 2;
2011-10-16 12:06:00 +00:00
/** align to bottom */
2010-06-06 18:15:35 +00:00
const ALIGN_BOTTOM = 3;
2011-10-16 12:06:00 +00:00
/** align to center */
2010-09-29 16:47:08 +00:00
const ALIGN_CENTER = 4;
2015-07-29 19:14:10 +00:00
2011-10-16 12:06:00 +00:00
/** validation rule to allow only numbers ([0-9]+) */
const VALIDATE_NUMERIC = 'numeric';
2013-08-22 16:43:47 +00:00
/** validation rule to allow positive/negative numbers ([-]?[0-9]+) */
const VALIDATE_NUMERIC_WITH_NEGATIVE = 'numericWithNegative';
2015-07-29 19:14:10 +00:00
2010-08-02 19:23:39 +00:00
/** alignment when inside a table */
2010-06-13 12:34:52 +00:00
public $alignment = null;
2010-08-02 19:23:39 +00:00
/** colspan if inside a table */
public $colspan = null;
/** rowspan if inside a table */
public $rowspan = null;
2012-11-30 19:21:47 +00:00
/** CSS classes */
protected $cssClasses = array();
2013-01-12 11:26:34 +00:00
/** table cell CSS classes */
protected $tableCellCssClasses = array();
2015-07-29 19:14:10 +00:00
2010-05-23 10:35:33 +00:00
/**
* Prints the HTML code for this element.
2015-07-29 19:14:10 +00:00
*
2010-05-23 10:35:33 +00:00
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
2010-06-13 12:34:52 +00:00
abstract function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope);
2015-07-29 19:14:10 +00:00
2010-08-02 19:23:39 +00:00
/**
* Returns the HTML attributes for the alignment.
2015-07-29 19:14:10 +00:00
*
2010-08-02 19:23:39 +00:00
* @return String alignment HTML attributes (e.g. align="right" valign="top")
*/
public function getAlignmentString() {
$align = '';
if ($this->alignment !== null) {
switch ($this->alignment) {
case htmlElement::ALIGN_BOTTOM:
$align = 'valign="bottom"';
break;
case htmlElement::ALIGN_TOP:
$align = 'valign="top"';
break;
case htmlElement::ALIGN_LEFT:
$align = 'align="left"';
break;
case htmlElement::ALIGN_RIGHT:
$align = 'align="right"';
break;
2010-09-29 16:47:08 +00:00
case htmlElement::ALIGN_CENTER:
$align = 'align="center"';
break;
2010-08-02 19:23:39 +00:00
}
}
return $align;
}
/**
* Returns the HTML attribute for the colspan.
2015-07-29 19:14:10 +00:00
*
2010-08-02 19:23:39 +00:00
* @return String colspan HTML attribute (e.g. colspan=3)
*/
public function getColspanString() {
if ($this->colspan == null) {
return '';
}
else return 'colspan="' . $this->colspan . '"';
}
2015-07-29 19:14:10 +00:00
2010-08-02 19:23:39 +00:00
/**
* Returns the HTML attribute for the rowspan.
2015-07-29 19:14:10 +00:00
*
2010-08-02 19:23:39 +00:00
* @return String rowspan HTML attribute (e.g. rowspan=3)
*/
public function getRowspanString() {
if ($this->rowspan == null) {
return '';
}
else return 'rowspan="' . $this->rowspan . '"';
}
2010-05-23 10:35:33 +00:00
2012-11-30 19:21:47 +00:00
/**
2013-01-12 11:26:34 +00:00
* Adds CSS classes to this element.
2015-07-29 19:14:10 +00:00
*
2012-11-30 19:21:47 +00:00
* @param array $classes CSS class names
*/
public function setCSSClasses($classes) {
$this->cssClasses = $classes;
}
2013-01-12 11:26:34 +00:00
/**
* Adds CSS classes to the surrounding table cell for this element.
2015-07-29 19:14:10 +00:00
*
2013-01-12 11:26:34 +00:00
* @param array $classes CSS class names
*/
public function setTableCellCSSClasses($classes) {
$this->tableCellCssClasses = $classes;
}
2015-07-29 19:14:10 +00:00
2013-01-12 11:26:34 +00:00
/**
* Returns the CSS classes of the surrounding table cell for this element.
2015-07-29 19:14:10 +00:00
*
2013-01-12 11:26:34 +00:00
* @return array CSS classes
*/
public function getTableCellCSSClasses() {
return $this->tableCellCssClasses;
}
2010-05-23 10:35:33 +00:00
}
2010-06-06 18:15:35 +00:00
/**
* Structures elements using a table.
*
* @package metaHTML
*/
2010-06-13 12:34:52 +00:00
class htmlTable extends htmlElement {
2010-06-06 18:15:35 +00:00
/** table footer */
2010-06-21 16:23:44 +00:00
const footer = "</table>\n";
2010-06-12 19:38:26 +00:00
/** new line */
const newLine = "</tr><tr>\n";
2015-07-29 19:14:10 +00:00
2010-06-13 12:34:52 +00:00
/** list of subelements */
2010-06-06 18:15:35 +00:00
private $elements = array();
2010-06-21 16:23:44 +00:00
/** specifies if currently a row is open */
private $rowOpen = false;
2012-09-09 13:59:31 +00:00
/** table width */
private $width = null;
2013-08-11 10:50:21 +00:00
/** HTML ID */
private $id = null;
2015-07-29 19:14:10 +00:00
2012-09-09 13:59:31 +00:00
/**
* Constructor
2015-07-29 19:14:10 +00:00
*
2012-09-09 13:59:31 +00:00
* @param String $width table width (e.g. 100%)
* @see htmlElement
*/
2013-08-11 10:50:21 +00:00
function __construct($width = null, $id = null) {
2012-09-09 13:59:31 +00:00
$this->width = $width;
2013-08-11 10:50:21 +00:00
$this->id = $id;
2012-09-09 13:59:31 +00:00
}
2010-06-06 18:15:35 +00:00
/**
* Adds an element to the table. The element may be a htmlElement object or a simple String.
*
* @param mixed $element htmlElement object or a simple String
2010-06-10 15:37:58 +00:00
* @param boolean $newLine adds a new line after the element (optional, default false)
* @param boolean $isTableHeadElement specifies if this is a head or body element (default: body)
2010-06-06 18:15:35 +00:00
*/
public function addElement($element, $newLine = false, $isTableHeadElement = false) {
2010-06-21 16:23:44 +00:00
// add row element
if ($element instanceof htmlTableRow) {
// check if a row needs to be closed
if ($this->rowOpen) {
$this->elements[] = "</tr>\n";
$this->rowOpen = false;
}
$this->elements[] = $element;
}
// add cell element
elseif ($element instanceof htmlElement) {
// check if a row needs to be opened
if (!$this->rowOpen) {
$this->elements[] = "<tr>\n";
$this->rowOpen = true;
}
2010-06-13 12:34:52 +00:00
// check if alignment option was given
2010-08-02 19:23:39 +00:00
$align = $element->getAlignmentString();
$colspan = $element->getColspanString();
$rowspan = $element->getRowspanString();
2013-01-12 11:26:34 +00:00
$css = '';
if (sizeof($element->getTableCellCSSClasses()) > 0) {
$css = 'class="' . implode(' ', $element->getTableCellCSSClasses()) . '"';
}
$tagName = 'td';
if ($isTableHeadElement) {
$tagName = 'th';
}
2013-01-12 11:26:34 +00:00
$this->elements[] = "<$tagName $align $colspan $rowspan $css>\n";
2010-06-06 18:15:35 +00:00
$this->elements[] = $element;
$this->elements[] = "</$tagName>\n";
2010-06-10 15:37:58 +00:00
if ($newLine) {
$this->addNewLine();
}
2010-06-06 18:15:35 +00:00
}
else {
StatusMessage('ERROR', 'Invalid element', print_r($element, true));
}
}
2015-07-29 19:14:10 +00:00
2010-06-06 18:15:35 +00:00
/**
* Adds another line to the table.
*/
public function addNewLine() {
2010-06-21 16:23:44 +00:00
if (!$this->rowOpen) {
$this->elements[] = "<tr>\n";
}
else {
$this->elements[] = htmlTable::newLine;
}
2010-06-06 18:15:35 +00:00
}
2015-07-29 19:14:10 +00:00
2013-11-01 15:54:49 +00:00
/**
* Adds an htmlSpacer with the given width.
2015-07-29 19:14:10 +00:00
*
2013-11-01 15:54:49 +00:00
* @param String $width width (e.g. 10px)
*/
public function addSpace($width) {
$this->addElement(new htmlSpacer($width, null));
}
2015-07-29 19:14:10 +00:00
2013-11-03 20:00:12 +00:00
/**
* Adds an htmlSpacer with the given height and ends the row.
2015-07-29 19:14:10 +00:00
*
2013-11-03 20:00:12 +00:00
* @param String $height height (e.g. 10px)
*/
public function addVerticalSpace($height) {
$this->addElement(new htmlSpacer(null, $height), true);
}
2015-07-29 19:14:10 +00:00
2010-06-06 18:15:35 +00:00
/**
* Prints the HTML code for this element.
2015-07-29 19:14:10 +00:00
*
2010-06-06 18:15:35 +00:00
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
2010-09-25 14:28:37 +00:00
public function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
2010-06-06 18:15:35 +00:00
$return = array();
2012-09-09 13:59:31 +00:00
$width = '';
if ($this->width != null) {
$width = ' width="' . htmlspecialchars($this->width) . '"';
}
2013-08-11 10:50:21 +00:00
$id = '';
if (!empty($this->id)) {
$id = ' id="' . $this->id . '"';
}
2012-11-30 19:21:47 +00:00
$classAttr = '';
if (sizeof($this->cssClasses) > 0) {
$classAttr = ' class="' . implode(' ', $this->cssClasses) . '"';
}
2013-08-11 10:50:21 +00:00
echo "<table" . $width . $id . $classAttr . ">\n";
2010-06-06 18:15:35 +00:00
// print all contained elements
for ($i = 0; $i < sizeof($this->elements); $i++) {
// print htmlElement objects
if ($this->elements[$i] instanceof htmlElement) {
$fields = $this->elements[$i]->generateHTML($module, $input, $values, $restricted, $tabindex, $scope);
$return = array_merge($return, $fields);
}
// print simple Strings
else {
2010-06-12 19:38:26 +00:00
if ($i != (sizeof($this->elements) - 1) || !($this->elements[$i] == htmlTable::newLine) ) {
echo $this->elements[$i];
}
2010-06-06 18:15:35 +00:00
}
}
2010-06-21 16:23:44 +00:00
if ($this->rowOpen) {
echo "</tr>\n";
}
2010-06-06 18:15:35 +00:00
echo htmlTable::footer;
return $return;
}
2015-07-29 19:14:10 +00:00
2010-09-25 14:28:37 +00:00
/**
* Merges the content of another htmlTable object into this table.
2015-07-29 19:14:10 +00:00
*
2010-09-25 14:28:37 +00:00
* @param $table table to get elements
*/
public function mergeTableElements($table) {
if (is_null($table) || !($table instanceof htmlTable)) {
return;
}
2010-09-26 11:10:28 +00:00
// remove obsolete new lines at the end
if ($table->elements[sizeof($table->elements) - 1] == htmlTable::newLine) {
unset($table->elements[sizeof($table->elements) - 1]);
}
// close last row of other table if needed
if ($table->rowOpen) {
$table->elements[] = "</tr>\n";
}
// close last own row if needed
if ($this->rowOpen) {
if ($this->elements[sizeof($this->elements) - 1] == htmlTable::newLine) {
unset($this->elements[sizeof($this->elements) - 1]);
}
else {
$this->elements[] = "</tr>\n";
}
$this->rowOpen = false;
}
2010-09-25 14:28:37 +00:00
$this->elements = array_merge($this->elements, $table->elements);
}
2010-06-06 18:15:35 +00:00
}
2010-06-21 16:23:44 +00:00
/**
* A row inside a htmlTable.
2015-07-29 19:14:10 +00:00
*
2010-06-21 16:23:44 +00:00
* @see htmlTable
* @package metaHTML
*/
class htmlTableRow extends htmlElement {
2012-07-15 12:05:47 +00:00
/** table cells */
2010-06-21 16:23:44 +00:00
private $cells;
2015-07-29 19:14:10 +00:00
2010-06-21 16:23:44 +00:00
/**
* Constructor
2015-07-29 19:14:10 +00:00
*
2010-06-21 16:23:44 +00:00
* @param array $cells list of htmlElements
* @see htmlElement
*/
function __construct($cells) {
$this->cells = $cells;
}
/**
* Prints the HTML code for this element.
2015-07-29 19:14:10 +00:00
*
2010-06-21 16:23:44 +00:00
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
$types = array();
2012-11-30 19:21:47 +00:00
$classAttr = '';
if (sizeof($this->cssClasses) > 0) {
$classAttr = ' class="' . implode(' ', $this->cssClasses) . '"';
}
echo "<tr" . $classAttr . ">\n";
2010-06-21 16:23:44 +00:00
for ($i = 0; $i < sizeof($this->cells); $i++) {
2010-07-03 12:31:34 +00:00
// check if alignment option was given
2010-08-02 19:23:39 +00:00
$align = $this->cells[$i]->getAlignmentString();
$colspan = $this->cells[$i]->getColspanString();
$rowspan = $this->cells[$i]->getRowspanString();
echo "<td $align $colspan $rowspan>\n";
2010-06-21 16:23:44 +00:00
$types = array_merge($types, $this->cells[$i]->generateHTML($module, $input, $values, $restricted, $tabindex, $scope));
echo "</td>\n";
}
echo "</tr>";
return $types;
}
}
2010-06-06 18:15:35 +00:00
/**
2010-07-03 12:31:34 +00:00
* A standard input field.
2015-07-29 19:14:10 +00:00
*
2010-06-06 18:15:35 +00:00
* @package metaHTML
*/
2010-07-03 12:31:34 +00:00
class htmlInputField extends htmlElement {
2010-06-06 18:15:35 +00:00
/** unique field name */
2013-02-09 13:59:17 +00:00
protected $fieldName;
2010-06-06 18:15:35 +00:00
/** field value */
2013-02-09 13:59:17 +00:00
protected $fieldValue;
2010-06-06 18:15:35 +00:00
/** field size (default 30) */
2013-02-09 13:59:17 +00:00
protected $fieldSize = 30;
2010-06-06 18:15:35 +00:00
/** field max length (default 255) */
2013-02-09 13:59:17 +00:00
protected $fieldMaxLength = 255;
2012-10-08 18:01:55 +00:00
/** on keypress event */
2013-02-09 13:59:17 +00:00
protected $onKeyPress = null;
2015-05-31 08:03:00 +00:00
/** on keyupp event */
protected $onKeyUp = null;
2010-07-03 13:16:30 +00:00
/** password field */
2013-02-09 13:59:17 +00:00
protected $isPassword = false;
/** check password strength */
protected $checkPasswordStrength = false;
2010-09-13 19:30:57 +00:00
/** enabled or disabled */
2013-02-09 13:59:17 +00:00
protected $isEnabled = true;
2011-07-23 15:01:20 +00:00
/** indicates that the value should be saved in obfuscated form */
2013-02-09 13:59:17 +00:00
protected $obfuscate = false;
2012-04-22 19:32:36 +00:00
/** indicates that this field should not automatically be saved in the self service or server profile */
2013-02-09 13:59:17 +00:00
protected $transient = false;
2011-10-16 12:06:00 +00:00
/** required field */
protected $required = false;
/** validation rule */
2013-02-09 13:59:17 +00:00
protected $validationRule = null;
2012-08-13 17:44:42 +00:00
/** enable autocomplete */
2013-02-09 13:59:17 +00:00
protected $autocomplete = false;
/** multiple values in one field */
2013-02-09 13:59:17 +00:00
protected $autocompleteMultiValue = false;
/** separator expression for multiple values in one field */
2013-02-09 13:59:17 +00:00
protected $autocompleteMultiValueSeparatorExp = null;
/** separator for multiple values in one field */
2013-02-09 13:59:17 +00:00
protected $autocompleteMultiValueSeparator = null;
2012-08-13 17:44:42 +00:00
/** autocompletion suggestions */
2013-02-09 13:59:17 +00:00
protected $autocompleteValues = array();
2012-08-13 17:44:42 +00:00
/** autocomplete start at this input length */
2013-02-09 13:59:17 +00:00
protected $autocompleteMinLength = 1;
/** show calendar */
protected $showCalendar = false;
/** calendar format */
protected $calendarFormat = '';
2013-08-20 18:56:52 +00:00
/** title attribute */
protected $title = null;
/** field ID that needs to have same value (e.g. password field) */
protected $sameValueFieldID = null;
2015-07-29 19:14:10 +00:00
2010-06-06 18:15:35 +00:00
/**
* Constructor
*
* @param String $fieldName unique field name
* @param String $fieldValue value of input field (optional)
2014-02-08 15:05:15 +00:00
* @param String $fieldSize input field length (default 30)
2010-06-06 18:15:35 +00:00
*/
2011-05-17 18:55:20 +00:00
function __construct($fieldName, $fieldValue = null, $fieldSize = null) {
2011-07-23 15:01:20 +00:00
if (isObfuscatedText($fieldValue)) {
$fieldValue = deobfuscateText($fieldValue);
}
2010-06-06 18:15:35 +00:00
$this->fieldName = htmlspecialchars($fieldName);
$this->fieldValue = htmlspecialchars($fieldValue);
2011-05-17 18:55:20 +00:00
if ($fieldSize != null) {
$this->fieldSize = $fieldSize;
}
2010-06-06 18:15:35 +00:00
}
2015-07-29 19:14:10 +00:00
2010-06-06 18:15:35 +00:00
/**
* Prints the HTML code for this element.
2015-07-29 19:14:10 +00:00
*
2010-06-06 18:15:35 +00:00
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
2013-01-12 11:26:34 +00:00
$this->cssClasses[] = 'ui-corner-all';
2010-06-10 15:37:58 +00:00
if (isset($values[$this->fieldName])) {
2011-07-23 15:01:20 +00:00
if (isObfuscatedText($values[$this->fieldName][0])) {
$this->fieldValue = deobfuscateText($values[$this->fieldName][0]);
}
else {
$this->fieldValue = $values[$this->fieldName][0];
}
2010-06-10 15:37:58 +00:00
}
2011-10-16 12:06:00 +00:00
$validators = array();
if ($this->required) {
$validators[] = 'required';
}
if ($this->validationRule != null) {
$validators[] = 'custom[' . $this->validationRule . ']';
}
2010-06-06 18:15:35 +00:00
// print input field
2011-10-16 12:06:00 +00:00
$class = '';
if (sizeof($validators) > 0) {
2012-11-30 19:21:47 +00:00
$class = ' class="validate[' . implode(',', $validators) . '] ' . implode(' ', $this->cssClasses) . '"';
}
2013-01-12 11:26:34 +00:00
else {
2012-11-30 19:21:47 +00:00
$class = ' class="' . implode(' ', $this->cssClasses) . '"';
2011-10-16 12:06:00 +00:00
}
2010-06-06 18:15:35 +00:00
$name = ' name="' . $this->fieldName . '"';
$id = ' id="' . $this->fieldName . '"';
2010-06-06 18:15:35 +00:00
$value = '';
if ($this->fieldValue != null) {
$value = ' value="' . $this->fieldValue . '"';
}
$maxLength = '';
if ($this->fieldMaxLength != null) {
$maxLength = ' maxlength="' . $this->fieldMaxLength . '"';
}
2012-11-30 19:21:47 +00:00
$size = '';
if ($this->fieldSize != null) {
$size = ' size="' . $this->fieldSize . '"';
}
2010-06-06 18:15:35 +00:00
$fieldTabIndex = ' tabindex="' . $tabindex . '"';
$tabindex++;
2010-07-03 13:16:30 +00:00
$inputType = 'text';
if ($this->isPassword) {
$inputType = 'password';
}
2010-09-13 19:30:57 +00:00
$disabled = '';
if (!$this->isEnabled) {
$disabled = ' disabled';
}
2012-10-08 18:01:55 +00:00
$onKeyPress = '';
if ($this->onKeyPress != null) {
$onKeyPress = ' onkeypress="' . $this->onKeyPress . '"';
}
2015-05-31 08:03:00 +00:00
$onKeyUp = '';
if ($this->onKeyUp != null) {
$onKeyUp = ' onkeyup="' . $this->onKeyUp . '"';
}
2013-08-20 18:56:52 +00:00
$title = '';
if (!empty($this->title)) {
$title = ' title="' . $this->title . '"';
}
2015-05-31 08:03:00 +00:00
echo '<input type="' . $inputType . '"' . $class . $name . $id . $value . $maxLength . $size . $fieldTabIndex . $onKeyPress . $onKeyUp . $title . $disabled . '>';
2012-08-13 17:44:42 +00:00
// autocompletion
if ($this->autocomplete) {
echo "<script type=\"text/javascript\">\n";
echo 'jQuery(function() {';
echo 'var availableTags' . $this->fieldName . ' = [' . implode(',', $this->autocompleteValues) . '];';
if (!$this->autocompleteMultiValue) {
echo 'jQuery( "#' . $this->fieldName . '" ).autocomplete({ source: availableTags' . $this->fieldName . ', minLength: ' . $this->autocompleteMinLength . '});';
}
else {
echo 'function split' . $this->fieldName . '(val) {return val.split( /' . $this->autocompleteMultiValueSeparatorExp . '/ );}';
echo 'function extractLast' . $this->fieldName . '(term) {return split' . $this->fieldName . '(term).pop();}';
echo 'jQuery( "#' . $this->fieldName . '" ).bind("keydown", function(event) {
if (event.keyCode === jQuery.ui.keyCode.TAB && jQuery(this).data("autocomplete").menu.active ) {
event.preventDefault();
}
})';
echo '.autocomplete({
source: function(request, response) {response(jQuery.ui.autocomplete.filter(
availableTags' . $this->fieldName . ', extractLast' . $this->fieldName . '(request.term)));
},
minLength: ' . $this->autocompleteMinLength . ',
focus: function() {return false;},
select: function(event,ui) {
var terms = split' . $this->fieldName . '(this.value);
terms.pop();
terms.push(ui.item.value);
terms.push("");
this.value = terms.join("' . $this->autocompleteMultiValueSeparator . '");return false;
}
});';
}
echo '});';
2012-08-13 17:44:42 +00:00
echo "</script\n>";
}
// calendar
2013-02-09 13:59:17 +00:00
if ($this->showCalendar) {
echo '<script type="text/javascript">
jQuery(function() {
$("#' . $this->fieldName . '").datepicker({ dateFormat: "' . $this->calendarFormat . '"});
});
</script>
';
}
// check value against reference field
if ($this->sameValueFieldID != null) {
echo '<script type="text/javascript">
checkFieldsHaveSameValues("' . $this->fieldName . '", "' . $this->sameValueFieldID . '");
</script>
';
}
if ($this->checkPasswordStrength) {
2015-05-14 09:18:45 +00:00
$tokenSuffix = '?' . getSecurityTokenName() . '=' . getSecurityTokenValue();
if (isSelfService()) {
$tokenSuffix .= '&selfservice=1';
}
$ajaxPath = "../templates/misc/ajax.php" . $tokenSuffix;
if (is_file("../../templates/misc/ajax.php")) {
2015-05-14 09:18:45 +00:00
$ajaxPath = "../../templates/misc/ajax.php" . $tokenSuffix;
}
elseif (is_file("../../../templates/misc/ajax.php")) {
2015-05-14 09:18:45 +00:00
$ajaxPath = "../../../templates/misc/ajax.php" . $tokenSuffix;
}
echo '<script type="text/javascript">
checkPasswordStrength("' . $this->fieldName . '", "' . $ajaxPath . '");
</script>
';
}
2012-04-22 19:32:36 +00:00
if ($this->transient) {
return array();
}
2011-07-23 15:01:20 +00:00
if ($this->obfuscate) {
return array($this->fieldName => 'text_obfuscated');
}
else {
return array($this->fieldName => 'text');
}
2010-07-03 12:31:34 +00:00
}
/**
* Sets the maximum field length.
2015-07-29 19:14:10 +00:00
*
2010-07-03 12:31:34 +00:00
* @param int $fieldMaxLength length
*/
public function setFieldMaxLength($fieldMaxLength) {
$this->fieldMaxLength = $fieldMaxLength;
}
2015-07-29 19:14:10 +00:00
2010-07-03 12:31:34 +00:00
/**
2014-09-13 14:43:44 +00:00
* Sets the field size (default is 30).
2015-07-29 19:14:10 +00:00
*
2010-07-03 12:31:34 +00:00
* @param int $fieldSize size
*/
public function setFieldSize($fieldSize) {
$this->fieldSize = $fieldSize;
}
2010-07-03 13:16:30 +00:00
/**
* Specifies if this is a password field.
2015-07-29 19:14:10 +00:00
*
2010-07-03 13:16:30 +00:00
* @param boolean $isPassword password field
* @param boolean $checkStrength check if matches password policy (default: false)
2010-07-03 13:16:30 +00:00
*/
public function setIsPassword($isPassword, $checkStrength = false) {
2010-07-03 13:16:30 +00:00
$this->isPassword = $isPassword;
$this->checkPasswordStrength = $checkStrength;
2010-07-03 13:16:30 +00:00
}
2010-09-13 19:30:57 +00:00
/**
* Specifies if this component is enabled and accepts user modification.
2015-07-29 19:14:10 +00:00
*
2010-09-13 19:30:57 +00:00
* @param boolean $isEnabled enabled if true
*/
public function setIsEnabled($isEnabled) {
$this->isEnabled = $isEnabled;
}
2011-07-23 15:01:20 +00:00
/**
* Specifies if the value should be saved in obfuscated form (e.g. self service profile).
2015-07-29 19:14:10 +00:00
*
2011-07-23 15:01:20 +00:00
* @param boolean $obfuscate obfuscate value
*/
public function setObfuscate($obfuscate) {
$this->obfuscate = $obfuscate;
}
2012-04-22 19:32:36 +00:00
/**
* Specifies that the value should not be automatically saved when used in self service or server profile (default: false).
2015-07-29 19:14:10 +00:00
*
2012-04-22 19:32:36 +00:00
* @param boolean $transient transient field
*/
public function setTransient($transient) {
$this->transient = $transient;
}
2011-10-16 12:06:00 +00:00
/**
* Specifies if the input field is required.
2015-07-29 19:14:10 +00:00
*
2011-10-16 12:06:00 +00:00
* @param boolean $required required
*/
public function setRequired($required) {
$this->required = $required;
}
/**
* Specifies the validation rule (e.g. htmlElement::VALIDATE_NUMERIC) for this field.
* This rule is checked on client side when the input field looses focus.
2015-07-29 19:14:10 +00:00
*
2011-10-16 12:06:00 +00:00
* @param boolean $rule rule name
*/
public function setValidationRule($rule) {
$this->validationRule = $rule;
}
2015-07-29 19:14:10 +00:00
2012-08-13 17:44:42 +00:00
/**
* Enables autocompletion for this input field.
2015-07-29 19:14:10 +00:00
*
2012-08-13 17:44:42 +00:00
* @param array $values list of values to suggest
* @param int $minLength autocompletion starts after this number of caracters entered (default 1; 0 means immediate start)
2013-05-24 18:31:20 +00:00
* @param boolean $multiValue allow multiple autocompletion values in the same fields (default: false)
* @param String $multiSeparator separator expression if multiple autocompletion values are allowed (default ",\s*")
* @param String $multiSeparator separator for two values (default ", ")
2012-08-13 17:44:42 +00:00
*/
public function enableAutocompletion($values, $minLength = 1, $multiValue = false, $multiSeparatorExp = ',\s*', $multiSeparator = ', ') {
2012-08-13 17:44:42 +00:00
for ($i = 0; $i < sizeof($values); $i++) {
$values[$i] = '"' . htmlspecialchars(str_replace(array('"', "\r", "\n"), array('', '', ''), $values[$i])) . '"';
2012-08-13 17:44:42 +00:00
}
$this->autocomplete = true;
$this->autocompleteValues = $values;
$this->autocompleteMinLength = $minLength;
$this->autocompleteMultiValue = $multiValue;
$this->autocompleteMultiValueSeparatorExp = $multiSeparatorExp;
$this->autocompleteMultiValueSeparator = $multiSeparator;
2012-08-13 17:44:42 +00:00
}
2015-07-29 19:14:10 +00:00
2012-10-08 18:01:55 +00:00
/**
* Sets the JavaScript for the onKeyPress event.
2015-07-29 19:14:10 +00:00
*
2012-10-08 18:01:55 +00:00
* @param String $onKeyPress JavaScript code
*/
public function setOnKeyPress($onKeyPress) {
$this->onKeyPress = $onKeyPress;
}
2015-07-29 19:14:10 +00:00
2015-05-31 08:03:00 +00:00
/**
* Sets the JavaScript for the onKeyUp event.
2015-07-29 19:14:10 +00:00
*
2015-05-31 08:03:00 +00:00
* @param String $onKeyUp JavaScript code
*/
public function setOnKeyUp($onKeyUp) {
$this->onKeyUp = $onKeyUp;
}
2015-07-29 19:14:10 +00:00
2013-02-09 13:59:17 +00:00
/**
* Shows a calendar when the field is selected.
2015-07-29 19:14:10 +00:00
*
2013-02-09 13:59:17 +00:00
* @param String $format calendar format (e.g. yyyy-mm-dd)
*/
public function showCalendar($format) {
$this->showCalendar = true;
$this->calendarFormat = $format;
}
2011-10-16 12:06:00 +00:00
2013-08-20 18:56:52 +00:00
/**
* Sets the title for the input field.
2015-07-29 19:14:10 +00:00
*
2013-08-20 18:56:52 +00:00
* @param String $title title value
*/
public function setTitle($title) {
$this->title = htmlspecialchars($title);
}
2015-07-29 19:14:10 +00:00
/**
* Specifies the ID of a second field that must have the same value as this field.
* This field is marked red if different or green if equal.
2015-07-29 19:14:10 +00:00
*
* @param String $sameValueFieldID ID of reference field
*/
public function setSameValueFieldID($sameValueFieldID) {
$this->sameValueFieldID = $sameValueFieldID;
}
2015-07-29 19:14:10 +00:00
2016-03-19 09:06:53 +00:00
/**
* Turns this field into a live filter for a select box.
* Cannot be used together with setOnKeyUp().
*
* @param String $name select box name
*/
public function filterSelectBox($name) {
$this->setOnKeyUp('filterSelect(\'' . $this->fieldName . '\', \'' . $name . '\', event);');
}
2010-07-03 12:31:34 +00:00
}
/**
* An extended input field that combines label, input field and help.
2015-07-29 19:14:10 +00:00
*
2010-07-03 12:31:34 +00:00
* @package metaHTML
*/
class htmlTableExtendedInputField extends htmlInputField {
/** Descriptive label */
private $label;
/** help ID */
private $helpID;
2015-07-29 19:14:10 +00:00
2010-07-03 12:31:34 +00:00
/**
* Constructor
*
* @param String $label descriptive label
* @param String $fieldName unique field name
* @param String $fieldValue value of input field (optional)
* @param String $helpID help ID (optional)
2017-05-25 09:00:58 +00:00
* @param boolean $required input required
2010-07-03 12:31:34 +00:00
*/
2017-05-25 09:00:58 +00:00
function __construct($label, $fieldName, $fieldValue = null, $helpID = null, $required = false) {
2010-07-03 12:31:34 +00:00
parent::__construct($fieldName, $fieldValue);
$this->label = htmlspecialchars($label);
$this->helpID = $helpID;
2017-05-25 09:00:58 +00:00
$this->required = $required;
2010-07-03 12:31:34 +00:00
}
2015-07-29 19:14:10 +00:00
2010-07-03 12:31:34 +00:00
/**
* Prints the HTML code for this element.
2015-07-29 19:14:10 +00:00
*
2010-07-03 12:31:34 +00:00
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
// print label text
echo '<div class="nowrap">';
2010-07-03 12:31:34 +00:00
echo $this->label;
if ($this->required) {
$graphicsPath = "../../graphics";
if (is_dir("../graphics")) $graphicsPath = "../graphics";
echo '<img src="' . $graphicsPath . '/required.png" alt="required" width=16 height=16 title="' . _('required') . '">';
2010-07-03 12:31:34 +00:00
}
echo '</div>';
2010-07-03 12:31:34 +00:00
echo "\n</td>\n<td>\n";
// print input field
$return = parent::generateHTML($module, $input, $values, $restricted, $tabindex, $scope);
2010-06-06 18:15:35 +00:00
// print help link
if ($this->helpID != null) {
echo "\n</td>\n<td>\n";
$helpLink = new htmlHelpLink($this->helpID);
$helpLink->generateHTML($module, $input, $values, $restricted, $tabindex, $scope);
}
2010-07-03 12:31:34 +00:00
return $return;
2010-06-06 18:15:35 +00:00
}
}
/**
* Renders a help link.
2015-07-29 19:14:10 +00:00
*
2010-06-06 18:15:35 +00:00
* @package metaHTML
*/
2010-06-13 12:34:52 +00:00
class htmlHelpLink extends htmlElement {
2015-07-29 19:14:10 +00:00
2010-06-06 18:15:35 +00:00
/** help ID */
private $helpID;
/** module name if it should be forced */
private $module;
/** account type if it should be forced */
private $scope;
2015-07-29 19:14:10 +00:00
2010-06-06 18:15:35 +00:00
/**
* Constructor
*
* @param String $helpID help ID
* @param String $module module name (optional, only if value from generateHTML() should be overwritten)
* @param String $scope account type (e.g. user) (optional, only if value from generateHTML() should be overwritten)
2010-06-06 18:15:35 +00:00
*/
function __construct($helpID, $module = null, $scope = null) {
2010-06-06 18:15:35 +00:00
$this->helpID = $helpID;
$this->module = $module;
$this->scope = $scope;
2010-06-06 18:15:35 +00:00
}
2015-07-29 19:14:10 +00:00
2010-06-06 18:15:35 +00:00
/**
* Prints the HTML code for this element.
2015-07-29 19:14:10 +00:00
*
2010-06-06 18:15:35 +00:00
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
2014-02-06 17:29:04 +00:00
// overwrite module and scope if needed
if ($this->module != null) {
$module = $this->module;
}
if ($this->scope != null) {
$scope = $this->scope;
}
// print link
2010-06-06 18:15:35 +00:00
$helpEntry = getHelp($module, $this->helpID, $scope);
2017-05-20 09:46:26 +00:00
if (empty($helpEntry)) {
return array();
}
2015-08-09 13:18:04 +00:00
printHelpLink($helpEntry, $this->helpID, $module, $scope, $this->cssClasses);
2010-06-06 18:15:35 +00:00
return array();
}
}
/**
* Simple button.
*
* @package metaHTML
*/
2010-06-13 12:34:52 +00:00
class htmlButton extends htmlElement {
2015-07-29 19:14:10 +00:00
2010-06-06 18:15:35 +00:00
/** button name */
protected $name;
/** button text or image */
protected $value;
/** image button or text button */
protected $isImageButton;
2010-09-07 18:11:33 +00:00
/** title */
private $title = null;
2010-09-13 19:30:57 +00:00
/** enabled or disabled */
private $isEnabled = true;
2010-11-14 20:35:34 +00:00
/** icon class (CSS) for buttons with icon + text */
private $iconClass = null;
2012-01-14 13:21:14 +00:00
/** onclick event */
private $onClick = null;
/** button type (default: "submit" if no onClick and "button" with onClick) */
private $type = null;
2015-07-29 19:14:10 +00:00
2010-06-06 18:15:35 +00:00
/**
* Constructor.
*
* @param String $name button name
* @param String $value button text or image (16x16px, relative to graphics folder)
* @param String $isImageButton image or text button (default text)
*/
function __construct($name, $value, $isImageButton = false) {
$this->name = htmlspecialchars($name);
$this->value = htmlspecialchars($value);
$this->isImageButton = $isImageButton;
}
2015-07-29 19:14:10 +00:00
2010-06-06 18:15:35 +00:00
/**
* Prints the HTML code for this element.
2015-07-29 19:14:10 +00:00
*
2010-06-06 18:15:35 +00:00
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
2010-09-15 20:03:59 +00:00
if ($restricted) {
// no buttons in restricted mode
logNewMessage(LOG_ERR, 'Meta HTML: Requested button in restricted mode.');
return array();
}
2012-01-14 13:21:14 +00:00
$fieldTabIndex = ' tabindex="' . $tabindex . '"';
$tabindex++;
2010-06-06 18:15:35 +00:00
$style = '';
$classList = $this->cssClasses;
2010-06-06 18:15:35 +00:00
$class = '';
2010-09-07 18:11:33 +00:00
$title = '';
2010-06-06 18:15:35 +00:00
$name = ' name="' . $this->name . '"';
// image button
if ($this->isImageButton) {
$classList[] = 'smallImageButton';
$classList[] = 'align-middle';
2012-04-22 19:32:36 +00:00
$style = ' style="background-image: url(../../graphics/' . $this->value . '); background-color: transparent;"';
2010-06-06 18:15:35 +00:00
}
// text button
2010-11-14 20:35:34 +00:00
elseif ($this->iconClass == null) {
$classList[] = 'smallPadding';
}
2015-08-04 18:41:12 +00:00
// button with text and icon
else {
$classList[] = 'margin5';
}
if (sizeof($classList) > 0) {
$class = ' class="' . implode(' ', $classList) . '"';
2010-06-06 18:15:35 +00:00
}
2010-09-07 18:11:33 +00:00
if ($this->title != null) {
$title = ' title="' . $this->title . '"';
}
2010-09-13 19:30:57 +00:00
$disabled = '';
if (!$this->isEnabled) {
$disabled = ' disabled';
}
if ($this->type == null) {
$type = ' type="submit"';
}
else {
$type = ' type="' . $this->type . '"';
}
2012-01-14 13:21:14 +00:00
$onClick = '';
if ($this->onClick != null) {
if ($this->type == null) {
$type = ' type="button"';
}
2012-01-14 13:21:14 +00:00
$onClick = ' onclick="' . $this->onClick . '"';
2012-10-08 18:01:55 +00:00
}
$id = ' id="btn_' . preg_replace('/[^a-zA-Z0-9_-]/', '', $this->name) . '"';
2010-09-17 18:39:53 +00:00
if ($this->isImageButton) {
2015-06-16 18:59:56 +00:00
echo '<input type="submit" ' . $id . ' value=" "' . $name . $onClick . $fieldTabIndex . $style . $class . $title . $disabled . '>';
2010-09-17 18:39:53 +00:00
}
else {
2012-10-08 18:01:55 +00:00
echo '<button' . $id . $name . $fieldTabIndex . $type . $onClick . $style . $class . $title . $disabled . '>' . $this->value . '</button>';
2010-09-17 18:27:05 +00:00
// text buttons get JQuery style
2010-11-14 20:35:34 +00:00
$icon = '';
if ($this->iconClass != null) {
$icon = '{ icons: { primary: \'' . $this->iconClass . '\' } }';
}
2010-09-17 18:27:05 +00:00
echo '<script type="text/javascript">';
2010-11-14 20:35:34 +00:00
echo "jQuery('#btn_" . $this->name . "').button(" . $icon . ");";
2010-09-17 18:27:05 +00:00
echo '</script>';
}
2010-06-12 18:01:55 +00:00
return array($this->name => 'submit');
2010-06-06 18:15:35 +00:00
}
2015-07-29 19:14:10 +00:00
2010-09-07 18:11:33 +00:00
/**
* Sets the button title (tooltip).
2015-07-29 19:14:10 +00:00
*
2010-09-07 18:11:33 +00:00
* @param String $title title
*/
public function setTitle($title) {
$this->title = htmlspecialchars($title);
}
2010-09-13 19:30:57 +00:00
/**
* Specifies if this component is enabled and accepts user modification.
2015-07-29 19:14:10 +00:00
*
2010-09-13 19:30:57 +00:00
* @param boolean $isEnabled enabled if true
*/
public function setIsEnabled($isEnabled) {
$this->isEnabled = $isEnabled;
}
2010-11-14 20:35:34 +00:00
/**
* Sets an additional icon for a text button.
* The icon class is a CSS class that specifies the icon image (e.g. "deleteButton" in layout.css).
2015-07-29 19:14:10 +00:00
*
2010-11-14 20:35:34 +00:00
* @param String $iconClass icon class
*/
public function setIconClass($iconClass) {
$this->iconClass = htmlspecialchars($iconClass);
}
2015-07-29 19:14:10 +00:00
2012-01-14 13:21:14 +00:00
/**
* Sets the onclick event code.
* This makes this button a simple button that does not submit a form.
2015-07-29 19:14:10 +00:00
*
2012-01-14 13:21:14 +00:00
* @param String $onClick JS code
*/
public function setOnClick($onClick) {
$this->onClick = $onClick;
}
/**
* Allows to override the default button type ("submit" if no onClick and "button" with onClick).
*/
public function setType($type) {
$this->type = $type;
}
2015-07-29 19:14:10 +00:00
2010-06-06 18:15:35 +00:00
}
/**
* Prints a button for the account pages.
*
* @package metaHTML
*/
2010-06-13 12:34:52 +00:00
class htmlAccountPageButton extends htmlButton {
2015-07-29 19:14:10 +00:00
2010-06-06 18:15:35 +00:00
/**
* Constructor
*
* @param String $targetModule module name which renders next page
* @param String $targetPage name of next page
* @param String $identifier identifier for button
* @param String $value button text or image (16x16px, relative to graphics folder)
* @param String $isImageButton image or text button (default text)
2015-06-02 19:31:46 +00:00
* @param String $title title to show
2010-06-06 18:15:35 +00:00
*/
2014-01-14 18:51:36 +00:00
function __construct($targetModule, $targetPage, $identifier, $value, $isImageButton = false, $title = null) {
2010-06-06 18:15:35 +00:00
$this->name = htmlspecialchars('form_subpage_' . $targetModule . '_' . $targetPage . '_' . $identifier);
$this->value = $value;
$this->isImageButton = $isImageButton;
2014-01-14 18:51:36 +00:00
if ($title != null) {
$this->setTitle($title);
}
2010-06-06 18:15:35 +00:00
}
2015-07-29 19:14:10 +00:00
2010-06-06 18:15:35 +00:00
}
/**
* Represents a select box.
*
* @package metaHTML
*/
2010-06-13 12:34:52 +00:00
class htmlSelect extends htmlElement {
2015-07-29 19:14:10 +00:00
2010-06-06 18:15:35 +00:00
/** name of select field */
private $name;
/** size */
private $size;
/** allows multi-selection */
private $multiSelect = false;
/** elements */
private $elements;
/** selected elements */
2010-10-28 18:56:03 +00:00
private $selectedElements = array();
2010-06-06 18:15:35 +00:00
/** descriptive elements */
private $hasDescriptiveElements = false;
2010-10-12 17:47:20 +00:00
/** contains optgroups */
private $containsOptgroups = false;
2010-06-06 18:15:35 +00:00
/** sorting enabled */
private $sortElements = true;
2010-08-23 19:21:50 +00:00
/** right to left text direction */
private $rightToLeftTextDirection = false;
2010-09-13 19:30:57 +00:00
/** enabled or disabled */
private $isEnabled = true;
2010-10-18 19:45:35 +00:00
/** width of input element */
private $width = '';
2010-11-14 20:35:34 +00:00
/** transform select boxes with one element to text */
private $transformSingleSelect = true;
2011-01-02 13:56:37 +00:00
/** onchange event */
private $onchangeEvent = null;
2012-04-22 19:32:36 +00:00
/** indicates that this field should not automatically be saved in the self service or server profile */
private $transient = false;
/** list of enclosing table rows to hide when checked */
protected $tableRowsToHide = array();
/** list of enclosing table rows to show when checked */
protected $tableRowsToShow = array();
2015-07-29 19:14:10 +00:00
2010-06-06 18:15:35 +00:00
/**
* Constructor.
2015-07-29 19:14:10 +00:00
*
2010-10-12 17:47:20 +00:00
* <br>Examples:
* <br>
* <br>$select = new htmlSelect('myName', array('value1', 'value2'), array('value1'));
* <br>
* <br>$select = new htmlSelect('myName', array('label1' => 'value1', 'label2' => 'value2'), array('value1'));
* <br>$select->setHasDescriptiveElements(true);
* <br>
* <br>$select = new htmlSelect('myName', array('optgroupLabel' => array('value1', 'value2')), array('value1'));
* <br>$select->setHasDescriptiveElements(true);
* <br>$select->setContainsOptgroups(true);
2015-07-29 19:14:10 +00:00
*
2010-06-06 18:15:35 +00:00
* @param String $name element name
2010-10-12 17:47:20 +00:00
* @param array $elements list of elements array(label => value) or array(value1, value2) or array('optgroup' => array(...))
2010-07-03 13:16:30 +00:00
* @param array $selectedElements list of selected elements (optional, default none)
2010-06-06 18:15:35 +00:00
* @param int $size size (optional, default = 1)
*/
2010-07-03 13:16:30 +00:00
function __construct($name, $elements, $selectedElements = array(), $size = 1) {
2010-06-06 18:15:35 +00:00
$this->name = htmlspecialchars($name);
$this->elements = $elements;
2010-10-28 18:56:03 +00:00
if ($selectedElements != null) {
$this->selectedElements = $selectedElements;
}
2010-06-06 18:15:35 +00:00
$this->size = htmlspecialchars($size);
}
2015-07-29 19:14:10 +00:00
2010-06-06 18:15:35 +00:00
/**
* Prints the HTML code for this element.
2015-07-29 19:14:10 +00:00
*
2010-06-06 18:15:35 +00:00
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
2013-01-12 11:26:34 +00:00
$this->cssClasses[] = 'ui-corner-all';
2010-06-10 15:37:58 +00:00
if (isset($values[$this->name])) {
$this->selectedElements = $values[$this->name];
}
2010-06-06 18:15:35 +00:00
$multi = '';
$name = ' name="' . $this->name . '" id="' . $this->name . '"';
2010-06-06 18:15:35 +00:00
if ($this->multiSelect) {
$multi = ' multiple';
2012-10-28 14:37:54 +00:00
$name = ' name="' . $this->name . '[]" id="' . $this->name . '"';
2010-06-06 18:15:35 +00:00
}
2010-06-12 17:54:37 +00:00
$size = ' size="' . $this->size . '"';
2010-08-23 19:21:50 +00:00
$class = '';
$classList = $this->cssClasses;
2010-08-23 19:21:50 +00:00
if ($this->rightToLeftTextDirection) {
$classList[] = 'rightToLeftText';
}
2013-01-12 11:26:34 +00:00
$class = ' class="' . implode(' ', $classList) . '"';
2010-09-13 19:30:57 +00:00
$disabled = '';
if (!$this->isEnabled) {
$disabled = ' disabled';
}
2010-10-18 19:45:35 +00:00
$style = '';
if ($this->width != '') {
$style = ' style="width: ' . $this->width . '"';
}
2011-01-02 13:56:37 +00:00
$onchange = '';
if ($this->onchangeEvent != null) {
$onchange = $this->onchangeEvent;
}
if (($this->tableRowsToHide != null) || ($this->tableRowsToShow != null)) {
$this->printCodeForShowHideTableRows($onchange);
}
if ($onchange != '') {
$onchange = ' onchange="' . $onchange . '"';
2011-01-02 13:56:37 +00:00
}
// hide select boxes that contain less than 2 elements
if ((sizeof($this->elements) < 2) && !$this->multiSelect && $this->transformSingleSelect) {
echo '<div class="hidden">';
}
// print select box
2011-01-02 13:56:37 +00:00
echo '<select' . $class . $style . $name . $size . $multi . $disabled . $onchange . ' tabindex="' . $tabindex . "\">\n";
2010-06-06 18:15:35 +00:00
$tabindex++;
2010-10-12 17:47:20 +00:00
if ($this->containsOptgroups) {
foreach ($this->elements as $label => $elements) {
if (sizeof($elements) > 0) {
echo '<optgroup label="' . $label . '">';
$this->printOptionsHTML($elements);
echo '</optgroup>';
}
}
}
else {
$this->printOptionsHTML($this->elements);
}
echo "</select>\n";
// if select box has only one element then show it as text
if ((sizeof($this->elements) == 1) && !$this->multiSelect && $this->transformSingleSelect) {
echo '</div>';
if ($this->hasDescriptiveElements) {
$keys = array_keys($this->elements);
echo $keys[0];
}
else {
echo $this->elements[0];
}
2012-11-11 11:35:30 +00:00
echo '&nbsp;';
}
2010-11-14 20:35:34 +00:00
elseif (sizeof($this->elements) == 0) {
echo '</div>';
}
2012-04-22 19:32:36 +00:00
if ($this->transient) {
return array();
}
2010-10-12 17:47:20 +00:00
if ($this->multiSelect) {
return array($this->name => 'multiselect');
}
else {
return array($this->name => 'select');
}
}
2015-07-29 19:14:10 +00:00
2010-10-12 17:47:20 +00:00
/**
* Prints the HTML code of the option tags.
*
* @param array $elements list of options
*/
private function printOptionsHTML($elements) {
2010-06-06 18:15:35 +00:00
// sorting
if ($this->sortElements) {
if ($this->hasDescriptiveElements) {
2010-10-12 17:47:20 +00:00
$labels = array_keys($elements);
2010-06-06 18:15:35 +00:00
natcasesort($labels);
$newElements = array();
foreach ($labels as $label) {
2010-10-12 17:47:20 +00:00
$newElements[$label] = $elements[$label];
2010-06-06 18:15:35 +00:00
}
2010-10-12 17:47:20 +00:00
$elements = $newElements;
2010-06-06 18:15:35 +00:00
}
else {
2010-10-12 17:47:20 +00:00
natcasesort($elements);
2010-06-06 18:15:35 +00:00
}
}
2010-10-12 17:47:20 +00:00
foreach ($elements as $key => $value) {
2010-06-06 18:15:35 +00:00
$selected = '';
if ($this->hasDescriptiveElements) {
2017-05-25 07:49:05 +00:00
if (in_array($value, $this->selectedElements) || (empty($this->selectedElements) && empty($value))) {
2010-06-06 18:15:35 +00:00
$selected = ' selected';
}
echo "<option value=\"" . htmlspecialchars($value) . "\"$selected>" . htmlspecialchars($key) . "</option>\n";
}
else {
2017-05-25 07:49:05 +00:00
if (in_array($value, $this->selectedElements) || (empty($this->selectedElements) && empty($value))) {
2010-06-06 18:15:35 +00:00
$selected = ' selected';
}
echo "<option$selected>" . htmlspecialchars($value) . "</option>\n";
}
}
}
2015-07-29 19:14:10 +00:00
2010-06-06 18:15:35 +00:00
/**
2015-07-29 19:14:10 +00:00
* Specifies if the elements are just a simple list or an assoziative array (default: simple list).
*
2010-06-06 18:15:35 +00:00
* @param boolean $hasDescriptiveElements activates descriptive elements
*/
public function setHasDescriptiveElements($hasDescriptiveElements) {
$this->hasDescriptiveElements = $hasDescriptiveElements;
}
2015-07-29 19:14:10 +00:00
2010-10-12 17:47:20 +00:00
/**
2014-12-25 07:31:04 +00:00
* Specifies if the elements are divided into optgroups.
* In this case the provided options are an array where the key is the optgroup label and the value is an array containing the options for the optgroup.
2015-07-29 19:14:10 +00:00
*
2010-10-12 17:47:20 +00:00
* @param boolean $containsOptgroups activates optgroups
*/
public function setContainsOptgroups($containsOptgroups) {
$this->containsOptgroups = $containsOptgroups;
}
2015-07-29 19:14:10 +00:00
2010-06-06 18:15:35 +00:00
/**
* Specifies if multi-selection is enabled (default: disabled).
2015-07-29 19:14:10 +00:00
*
2010-06-06 18:15:35 +00:00
* @param boolean $multiSelect allows multi-selection
*/
public function setMultiSelect($multiSelect) {
$this->multiSelect = $multiSelect;
}
2015-07-29 19:14:10 +00:00
2010-06-06 18:15:35 +00:00
/**
* Specifies if the elemets should be sorted (default: sort).
2015-07-29 19:14:10 +00:00
*
2010-06-10 15:37:58 +00:00
* @param boolean $sortElements sort elements
2010-06-06 18:15:35 +00:00
*/
public function setSortElements($sortElements) {
$this->sortElements = $sortElements;
}
2010-08-23 19:21:50 +00:00
/**
* Specifies if the text direction should be set to right to left.
2015-07-29 19:14:10 +00:00
*
2010-08-23 19:21:50 +00:00
* @param boolean $rightToLeftTextDirection if true use right to left direction
*/
public function setRightToLeftTextDirection($rightToLeftTextDirection) {
$this->rightToLeftTextDirection = $rightToLeftTextDirection;
}
2015-07-29 19:14:10 +00:00
2010-09-13 19:30:57 +00:00
/**
* Specifies if this component is enabled and accepts user modification.
2015-07-29 19:14:10 +00:00
*
2010-09-13 19:30:57 +00:00
* @param boolean $isEnabled enabled if true
*/
public function setIsEnabled($isEnabled) {
$this->isEnabled = $isEnabled;
}
2010-10-18 19:45:35 +00:00
/**
* Specifies the width of this selection box.
2015-07-29 19:14:10 +00:00
*
2010-10-18 19:45:35 +00:00
* @param String $width width (e.g. 20em)
*/
public function setWidth($width) {
$this->width = htmlspecialchars($width);
}
2010-11-14 20:35:34 +00:00
/**
* Specifies if select boxes that contain only a single element should be transformed to a simple text field.
2015-07-29 19:14:10 +00:00
*
2010-11-14 20:35:34 +00:00
* @param boolean $transformSingleSelect transform single options to text
*/
public function setTransformSingleSelect($transformSingleSelect) {
$this->transformSingleSelect = $transformSingleSelect;
}
2011-01-02 13:56:37 +00:00
/**
* Sets the JavaScript code for the onchange event.
2015-07-29 19:14:10 +00:00
*
2011-01-02 13:56:37 +00:00
* @param String $onchangeEvent onchange event code (e.g. myfunction();)
*/
public function setOnchangeEvent($onchangeEvent) {
$this->onchangeEvent = htmlspecialchars($onchangeEvent);
}
2012-04-22 19:32:36 +00:00
/**
* Specifies that the value should not be automatically saved when used in self service or server profile (default: false).
2015-07-29 19:14:10 +00:00
*
2012-04-22 19:32:36 +00:00
* @param boolean $transient transient field
*/
public function setTransient($transient) {
$this->transient = $transient;
}
/**
* This will hide the given table rows when the select is changed to the specified value.
* The given IDs can be of any e.g. input element. Starting from this element
* the first parent "<tr>" element will be used to show/hide.
* <br>
* <br>
* <br>Example: <tr><td><input type="checkbox" id="mycheckbox"></td></tr>
* <br> Using "mycheckbox" will use this "tr" to hide/show.
* <br>
* <br> Example for $tableRowsToHide:
* <br> array('yes' => array('option1', 'option2'), 'no' => array('option3'))
2015-07-29 19:14:10 +00:00
*
* @param array $tableRowsToHide array of select value => array of IDs of child elements to hide
*/
public function setTableRowsToHide($tableRowsToHide) {
$this->tableRowsToHide = $tableRowsToHide;
}
/**
* This will show the given table rows when the select is changed to the specified value.
* The given IDs can be of any e.g. input element. Starting from this element
* the first parent "<tr>" element will be used to show/hide.
* <br>
* <br>
* <br>Example: <tr><td><input type="checkbox" id="mycheckbox"></td></tr>
* <br> Using "mycheckbox" will use this "tr" to hide/show.
* <br>
* <br> Example for $tableRowsToShow:
* <br> array('yes' => array('option1', 'option2'), 'no' => array('option3'))
2015-07-29 19:14:10 +00:00
*
* @param array $tableRowsToShow array of select value => array of IDs of child elements to show
*/
public function setTableRowsToShow($tableRowsToShow) {
$this->tableRowsToShow = $tableRowsToShow;
}
2015-07-29 19:14:10 +00:00
/**
* Creates the JavaScript code to hide/show table rows based on the select value.
2015-07-29 19:14:10 +00:00
*
* @param String $onChange onChange code
*/
private function printCodeForShowHideTableRows(&$onChange) {
if ((sizeof($this->tableRowsToHide) == 0) && (sizeof($this->tableRowsToShow) == 0)) {
return;
}
$values = array();
if (!empty($this->tableRowsToHide)) {
$values = array_merge($values, array_keys($this->tableRowsToHide));
}
if (!empty($this->tableRowsToShow)) {
$values = array_merge($values, array_keys($this->tableRowsToShow));
}
// build Java script to show/hide depending fields
foreach ($values as $val) {
// build onChange listener
$onChange .= 'if (jQuery(\'#' . $this->name . '\').val() == \'' . $val . '\') {';
if (isset($this->tableRowsToShow[$val])) {
for ($i = 0; $i < sizeof($this->tableRowsToShow[$val]); $i++) {
$onChange .= 'jQuery(\'#' . $this->tableRowsToShow[$val][$i] . '\').closest(\'tr\').removeClass(\'hidden\');';
}
}
if (isset($this->tableRowsToHide[$val])) {
for ($i = 0; $i < sizeof($this->tableRowsToHide[$val]); $i++) {
$onChange .= 'jQuery(\'#' . $this->tableRowsToHide[$val][$i] . '\').closest(\'tr\').addClass(\'hidden\');';
}
}
$onChange .= '};';
}
// build script to set initial state
$script = '<script type="text/javascript">jQuery(document).ready(function() {' . "\n";
if (isset($this->tableRowsToShow[$this->selectedElements[0]])) {
for ($i = 0; $i < sizeof($this->tableRowsToShow[$this->selectedElements[0]]); $i++) {
$classType = 'removeClass';
$script .= 'jQuery(\'#' . $this->tableRowsToShow[$this->selectedElements[0]][$i] . '\').closest(\'tr\').' . $classType . '(\'hidden\');' . "\n";
}
}
if (isset($this->tableRowsToHide[$this->selectedElements[0]])) {
for ($i = 0; $i < sizeof($this->tableRowsToHide[$this->selectedElements[0]]); $i++) {
$classType = 'addClass';
$script .= 'jQuery(\'#' . $this->tableRowsToHide[$this->selectedElements[0]][$i] . '\').closest(\'tr\').' . $classType . '(\'hidden\');' . "\n";
}
}
$script .= '});</script>';
echo $script;
}
2010-06-06 18:15:35 +00:00
}
2010-05-23 10:35:33 +00:00
2010-06-11 19:40:26 +00:00
/**
* Select with label and help link.
2015-07-29 19:14:10 +00:00
*
2010-06-11 19:40:26 +00:00
* @package metaHTML
*/
class htmlTableExtendedSelect extends htmlSelect {
/** descriptive label */
private $label;
/** help ID */
private $helpID;
2015-07-29 19:14:10 +00:00
2010-06-11 19:40:26 +00:00
/**
* Constructor.
2015-07-29 19:14:10 +00:00
*
2010-06-11 19:40:26 +00:00
* @param String $name element name
* @param array $elements list of elememts
* @param array $selectedElements list of selected elements
* @param String $label descriptive label
* @param String $helpID help ID (optional, default none)
* @param int $size size (optional, default = 1)
*/
function __construct($name, $elements, $selectedElements, $label, $helpID = null, $size = 1) {
parent::__construct($name, $elements, $selectedElements, $size);
$this->label = htmlspecialchars($label);
$this->helpID = $helpID;
}
/**
* Prints the HTML code for this element.
2015-07-29 19:14:10 +00:00
*
2010-06-11 19:40:26 +00:00
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
echo '<div class="nowrap">';
2010-06-11 19:40:26 +00:00
echo $this->label;
echo '</div>';
2010-06-11 19:40:26 +00:00
echo "\n</td>\n<td>\n";
$return = parent::generateHTML($module, $input, $values, $restricted, $tabindex, $scope);
// print help link
if ($this->helpID != null) {
echo "\n</td>\n<td>\n";
$helpLink = new htmlHelpLink($this->helpID);
$helpLink->generateHTML($module, $input, $values, $restricted, $tabindex, $scope);
}
return $return;
}
2015-07-29 19:14:10 +00:00
2010-06-11 19:40:26 +00:00
}
2010-11-06 09:38:47 +00:00
/**
* Represents a radio selection.
*
* @package metaHTML
*/
class htmlRadio extends htmlElement {
2015-07-29 19:14:10 +00:00
2010-11-06 09:38:47 +00:00
/** name of select field */
private $name;
/** elements */
private $elements;
/** selected element */
private $selectedElement = null;
/** enabled or disabled */
private $isEnabled = true;
2013-01-12 18:29:00 +00:00
/** on change code */
private $onchangeEvent = null;
2015-07-29 19:14:10 +00:00
2010-11-06 09:38:47 +00:00
/**
* Constructor.
2015-07-29 19:14:10 +00:00
*
2010-11-06 09:38:47 +00:00
* <br>Examples:
* <br>
* <br>$radio = new htmlRadio('myName', array('label1' => 'value1', 'label2' => 'value2'), array('value1'));
2015-07-29 19:14:10 +00:00
*
2010-11-06 09:38:47 +00:00
* @param String $name element name
* @param array $elements list of elements array(label => value)
2012-02-24 19:41:20 +00:00
* @param String $selectedElement value of selected element (optional, default none)
2010-11-06 09:38:47 +00:00
*/
function __construct($name, $elements, $selectedElement = null) {
$this->name = htmlspecialchars($name);
$this->elements = $elements;
if ($selectedElement != null) {
$this->selectedElement = $selectedElement;
}
}
2015-07-29 19:14:10 +00:00
2010-11-06 09:38:47 +00:00
/**
* Prints the HTML code for this element.
2015-07-29 19:14:10 +00:00
*
2010-11-06 09:38:47 +00:00
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
if (isset($values[$this->name][0])) {
$this->selectedElement = $values[$this->name][0];
}
$name = ' name="' . $this->name . '"';
$disabled = '';
if (!$this->isEnabled) {
$disabled = ' disabled';
}
2013-01-12 18:29:00 +00:00
$onchange = '';
if ($this->onchangeEvent != null) {
$onchange = ' onchange="' . $this->onchangeEvent . '"';
}
2010-11-06 09:38:47 +00:00
// print radio list
$counter = 0;
2010-11-06 09:38:47 +00:00
foreach ($this->elements as $label => $value) {
2013-01-12 18:29:00 +00:00
$onClick = 'onClick="
2013-02-22 19:30:43 +00:00
jQuery(\'input[name=' . $this->name . ']\').prop(\'checked\', false);
jQuery(\'#' . $this->name . $counter . '\').prop(\'checked\', true);
2013-01-12 18:29:00 +00:00
jQuery(\'#' . $this->name . $counter . '\').trigger(\'change\');
"';
if ($this->isEnabled === false) {
$onClick = '';
}
echo '<div class="nowrap" ' . $onClick . '>';
2010-11-06 09:38:47 +00:00
$selected = '';
if ($value == $this->selectedElement) {
$selected = ' checked';
}
2013-01-12 18:29:00 +00:00
echo '<input type="radio" id="' . $this->name . $counter . '"' . $name . $disabled . $selected . $onchange . ' value="' . $value . '" tabindex="' . $tabindex . '"> ' . $label;
echo '</div>';
2010-11-06 09:38:47 +00:00
$tabindex++;
$counter++;
2010-11-06 09:38:47 +00:00
}
return array($this->name => 'select');
}
2015-07-29 19:14:10 +00:00
2010-11-06 09:38:47 +00:00
/**
* Specifies if this component is enabled and accepts user modification.
2015-07-29 19:14:10 +00:00
*
2010-11-06 09:38:47 +00:00
* @param boolean $isEnabled enabled if true
*/
public function setIsEnabled($isEnabled) {
$this->isEnabled = $isEnabled;
}
2013-01-12 18:29:00 +00:00
/**
* Sets the JavaScript code for the onchange event.
2015-07-29 19:14:10 +00:00
*
2013-01-12 18:29:00 +00:00
* @param String $onchangeEvent onchange event code (e.g. myfunction();)
*/
public function setOnchangeEvent($onchangeEvent) {
$this->onchangeEvent = htmlspecialchars($onchangeEvent);
}
2010-11-06 09:38:47 +00:00
}
2010-11-18 19:29:24 +00:00
/**
* Radio list with descriptive label and help link.
2015-07-29 19:14:10 +00:00
*
2010-11-18 19:29:24 +00:00
* @package metaHTML
*/
class htmlTableExtendedRadio extends htmlRadio {
/** descriptive label */
private $label;
/** help ID */
private $helpID;
2015-07-29 19:14:10 +00:00
2010-11-18 19:29:24 +00:00
/**
* Constructor.
2015-07-29 19:14:10 +00:00
*
2010-11-18 19:29:24 +00:00
* @param String $label descriptive label
* @param String $name element name
* @param array $elements list of elements array(label => value)
2012-02-24 19:41:20 +00:00
* @param String $selectedElement value of selected element (optional, default none)
2010-11-18 19:29:24 +00:00
* @param String $helpID help ID
*/
function __construct($label, $name, $elements, $selectedElement = null, $helpID = null) {
parent::__construct($name, $elements, $selectedElement);
$this->label = htmlspecialchars($label);
$this->helpID = $helpID;
2012-05-17 08:40:32 +00:00
$this->alignment = htmlElement::ALIGN_TOP;
2010-11-18 19:29:24 +00:00
}
/**
* Prints the HTML code for this element.
2015-07-29 19:14:10 +00:00
*
2010-11-18 19:29:24 +00:00
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
2012-02-24 19:41:20 +00:00
if ($this->label != null) {
echo '<div class="nowrap">';
echo $this->label;
echo '</div>';
echo "\n</td>\n<td>\n";
}
2010-11-18 19:29:24 +00:00
$return = parent::generateHTML($module, $input, $values, $restricted, $tabindex, $scope);
// print help link
if ($this->helpID != null) {
2012-02-24 19:41:20 +00:00
echo "\n</td>\n<td valign=\"top\">\n";
2010-11-18 19:29:24 +00:00
$helpLink = new htmlHelpLink($this->helpID);
$helpLink->generateHTML($module, $input, $values, $restricted, $tabindex, $scope);
}
return $return;
}
2015-07-29 19:14:10 +00:00
2010-11-18 19:29:24 +00:00
}
2010-06-10 15:37:58 +00:00
/**
* Prints the text and escapes contained HTML code by default.
2015-07-29 19:14:10 +00:00
*
2010-06-10 15:37:58 +00:00
* @package metaHTML
*/
2010-06-13 12:34:52 +00:00
class htmlOutputText extends htmlElement {
2010-06-10 15:37:58 +00:00
/** the text to print */
private $string;
/** specifies if HTML code should be escaped */
private $escapeHTML;
2010-11-14 20:35:34 +00:00
/** bold text */
private $isBold = false;
/** mark as required */
private $markAsRequired = false;
2011-05-20 17:43:31 +00:00
/** no wrap */
private $noWrap = false;
2010-06-10 15:37:58 +00:00
/**
* Constructor.
2015-07-29 19:14:10 +00:00
*
2010-06-10 15:37:58 +00:00
* @param String $string output text
* @param boolean $escapeHTML escape HTML code (default yes)
* @param boolean $markAsRequired mark text like a required field
2010-06-10 15:37:58 +00:00
*/
function __construct($string, $escapeHTML = true, $markAsRequired = false) {
2010-06-10 15:37:58 +00:00
$this->string = $string;
$this->escapeHTML = $escapeHTML;
$this->markAsRequired = $markAsRequired;
2010-06-10 15:37:58 +00:00
}
/**
* Prints the HTML code for this element.
2015-07-29 19:14:10 +00:00
*
2010-06-10 15:37:58 +00:00
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
2011-05-20 17:43:31 +00:00
if ($this->noWrap) {
echo "<div class=\"nowrap\">";
}
2010-11-14 20:35:34 +00:00
if ($this->isBold) {
echo "<b>";
}
2010-06-10 15:37:58 +00:00
if ($this->escapeHTML) {
echo htmlspecialchars($this->string);
}
else {
echo $this->string;
}
if ($this->markAsRequired) {
$graphicsPath = "../../graphics";
if (is_dir("../graphics")) $graphicsPath = "../graphics";
echo '<img src="' . $graphicsPath . '/required.png" alt="required" width=16 height=16 title="' . _('required') . '">';
}
2010-11-14 20:35:34 +00:00
if ($this->isBold) {
echo "</b>";
}
2011-05-20 17:43:31 +00:00
if ($this->noWrap) {
echo "</div>";
}
2010-06-10 15:37:58 +00:00
return array();
}
2010-11-14 20:35:34 +00:00
/**
* Specifies if the whole text should be printed in bold.
2015-07-29 19:14:10 +00:00
*
2010-11-14 20:35:34 +00:00
* @param boolean $isBold bold text
*/
public function setIsBold($isBold) {
$this->isBold = $isBold;
}
/**
* Adds a marker that indicates a required field.
2015-07-29 19:14:10 +00:00
*
* @param boolean $markAsRequired add marker
*/
public function setMarkAsRequired($markAsRequired) {
$this->markAsRequired = $markAsRequired;
2011-05-20 17:43:31 +00:00
}
/**
* Specifies if word wrap is allowed for this text.
2015-07-29 19:14:10 +00:00
*
2011-05-20 17:43:31 +00:00
* @param boolean $noWrap no wrapping if set to true (default false)
*/
public function setNoWrap($noWrap) {
$this->noWrap = $noWrap;
}
2010-06-10 15:37:58 +00:00
}
/**
* Prints the HTML code for a checkbox.
2015-07-29 19:14:10 +00:00
*
2010-06-10 15:37:58 +00:00
* @package metaHTML
*/
2010-06-13 12:34:52 +00:00
class htmlInputCheckbox extends htmlElement {
2015-07-29 19:14:10 +00:00
2010-06-10 15:37:58 +00:00
/** unique name of input element */
protected $name;
2010-06-10 15:37:58 +00:00
/** value */
protected $checked;
2010-09-13 19:30:57 +00:00
/** enabled or disabled */
protected $isEnabled = true;
/** list of enclosing table rows to hide when checked */
protected $tableRowsToHide = array();
/** list of enclosing table rows to show when checked */
protected $tableRowsToShow = array();
2012-05-30 19:00:25 +00:00
/** indicates that this field should not automatically be saved in the self service or server profile */
private $transient = false;
/** list of input elements to enable when checked */
protected $elementsToEnable = array();
/** list of input elements to disable when checked */
protected $elementsToDisable = array();
2015-07-29 19:14:10 +00:00
2010-06-10 15:37:58 +00:00
/**
* Constructor.
2015-07-29 19:14:10 +00:00
*
2010-06-10 15:37:58 +00:00
* @param String $name unique name
2015-07-29 19:14:10 +00:00
* @param boolean $checked checked
2010-06-10 15:37:58 +00:00
*/
function __construct($name, $checked) {
$this->name = htmlspecialchars($name);
$this->checked = $checked;
}
/**
* Prints the HTML code for this element.
2015-07-29 19:14:10 +00:00
*
2010-06-10 15:37:58 +00:00
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
if (isset($values[$this->name])) {
if ($values[$this->name][0] == 'true') {
$this->checked = true;
}
else {
$this->checked = false;
}
}
$checked = '';
if ($this->checked) {
$checked = ' checked';
}
$tabindexValue = ' tabindex="' . $tabindex . '"';
$tabindex++;
2010-09-13 19:30:57 +00:00
$disabled = '';
if (!$this->isEnabled) {
$disabled = ' disabled';
}
// build Java script to show/hide depending fields
$onChange = '';
$script = '';
if ((sizeof($this->tableRowsToShow) > 0) || (sizeof($this->tableRowsToHide) > 0)) {
// build onChange listener
$onChange .= 'if (jQuery(\'#' . $this->name . ':checked\').val() !== undefined) {';
for ($i = 0; $i < sizeof($this->tableRowsToShow); $i++) {
$onChange .= 'jQuery(\'#' . $this->tableRowsToShow[$i] . '\').closest(\'tr\').removeClass(\'hidden\');';
}
for ($i = 0; $i < sizeof($this->tableRowsToHide); $i++) {
$onChange .= 'jQuery(\'#' . $this->tableRowsToHide[$i] . '\').closest(\'tr\').addClass(\'hidden\');';
}
$onChange .= '}';
$onChange .= 'else {';
for ($i = 0; $i < sizeof($this->tableRowsToShow); $i++) {
$onChange .= 'jQuery(\'#' . $this->tableRowsToShow[$i] . '\').closest(\'tr\').addClass(\'hidden\');';
}
for ($i = 0; $i < sizeof($this->tableRowsToHide); $i++) {
$onChange .= 'jQuery(\'#' . $this->tableRowsToHide[$i] . '\').closest(\'tr\').removeClass(\'hidden\');';
}
$onChange .= '};';
// build script to set initial state
$script = '<script type="text/javascript">jQuery(document).ready(function() {';
for ($i = 0; $i < sizeof($this->tableRowsToShow); $i++) {
$classType = 'addClass';
if ($this->checked) {
$classType = 'removeClass';
}
$script .= 'jQuery(\'#' . $this->tableRowsToShow[$i] . '\').closest(\'tr\').' . $classType . '(\'hidden\');';
}
for ($i = 0; $i < sizeof($this->tableRowsToHide); $i++) {
$classType = 'removeClass';
if ($this->checked) {
$classType = 'addClass';
}
$script .= 'jQuery(\'#' . $this->tableRowsToHide[$i] . '\').closest(\'tr\').' . $classType . '(\'hidden\');';
}
$script .= '});</script>';
}
// build Java script to enable/disable elements
if ((sizeof($this->elementsToEnable) > 0) || (sizeof($this->elementsToDisable) > 0)) {
// build onChange listener
$onChange .= 'if (jQuery(\'#' . $this->name . ':checked\').val() !== undefined) {';
for ($i = 0; $i < sizeof($this->elementsToEnable); $i++) {
$onChange .= 'jQuery(\'#' . $this->elementsToEnable[$i] . '\').prop(\'disabled\', false);';
}
for ($i = 0; $i < sizeof($this->elementsToDisable); $i++) {
$onChange .= 'jQuery(\'#' . $this->elementsToDisable[$i] . '\').prop(\'disabled\', true);';
}
$onChange .= '}';
$onChange .= 'else {';
for ($i = 0; $i < sizeof($this->elementsToEnable); $i++) {
$onChange .= 'jQuery(\'#' . $this->elementsToEnable[$i] . '\').prop(\'disabled\', true);';
}
for ($i = 0; $i < sizeof($this->elementsToDisable); $i++) {
$onChange .= 'jQuery(\'#' . $this->elementsToDisable[$i] . '\').prop(\'disabled\', false);';
}
$onChange .= '};';
// build script to set initial state
$script = '<script type="text/javascript">jQuery(document).ready(function() {';
for ($i = 0; $i < sizeof($this->elementsToEnable); $i++) {
$classType = 'true';
if ($this->checked) {
$classType = 'false';
}
$script .= 'jQuery(\'#' . $this->elementsToEnable[$i] . '\').prop(\'disabled\', ' . $classType . ');';
}
for ($i = 0; $i < sizeof($this->elementsToDisable); $i++) {
$classType = 'false';
if ($this->checked) {
$classType = 'true';
}
$script .= 'jQuery(\'#' . $this->elementsToDisable[$i] . '\').prop(\'disabled\', ' . $classType . ');';
}
$script .= '});</script>';
}
if (!empty($onChange)) {
$onChange = ' onChange="' . $onChange . '"';
}
echo '<input type="checkbox" id="' . $this->name . '" name="' . $this->name . '"' . $tabindexValue . $onChange . $checked . $disabled . '>';
echo $script;
2012-05-30 19:00:25 +00:00
if ($this->transient) {
return array();
}
2010-06-10 15:37:58 +00:00
return array($this->name => 'checkbox');
}
2010-09-13 19:30:57 +00:00
/**
* Specifies if this component is enabled and accepts user modification.
2015-07-29 19:14:10 +00:00
*
2010-09-13 19:30:57 +00:00
* @param boolean $isEnabled enabled if true
*/
public function setIsEnabled($isEnabled) {
$this->isEnabled = $isEnabled;
}
2015-07-29 19:14:10 +00:00
/**
* This will hide the given table rows when the checkbox is checked.
* The given IDs can be of any e.g. input element. Starting from this element
* the first parent "<tr>" element will be used to show/hide.
* <br>
* <br>
* <br>Example: <tr><td><input type="checkbox" id="mycheckbox"></td></tr>
* <br> Using "mycheckbox" will use this "tr" to hide/show.
2015-07-29 19:14:10 +00:00
*
* @param array $tableRowsToHide IDs of child elements to hide
*/
public function setTableRowsToHide($tableRowsToHide) {
$this->tableRowsToHide = $tableRowsToHide;
}
/**
* This will show the given table rows when the checkbox is checked.
* The given IDs can be of any e.g. input element. Starting from this element
* the first parent "<tr>" element will be used to show/hide.
* <br>
* <br>
* <br>Example: <tr><td><input type="checkbox" id="mycheckbox"></td></tr>
* <br> Using "mycheckbox" will use this "tr" to hide/show.
2015-07-29 19:14:10 +00:00
*
* @param array $tableRowsToShow IDs of child elements to show
*/
public function setTableRowsToShow($tableRowsToShow) {
$this->tableRowsToShow = $tableRowsToShow;
}
2012-05-30 19:00:25 +00:00
/**
* Specifies that the value should not be automatically saved when used in self service or server profile (default: false).
2015-07-29 19:14:10 +00:00
*
2012-05-30 19:00:25 +00:00
* @param boolean $transient transient field
*/
public function setTransient($transient) {
$this->transient = $transient;
}
2010-09-13 19:30:57 +00:00
/**
* This will disable the given input elements when the checkbox is checked.
* The given IDs can be of any input element (e.g. select, checkbox, ...).
2015-07-29 19:14:10 +00:00
*
* @param array $elements IDs of elements to disable
*/
public function setElementsToDisable($elements) {
$this->elementsToDisable = $elements;
}
2015-07-29 19:14:10 +00:00
/**
* This will enable the given input elements when the checkbox is checked.
* The given IDs can be of any input element (e.g. select, checkbox, ...).
2015-07-29 19:14:10 +00:00
*
* @param array $elements IDs of elements to enable
*/
public function setElementsToEnable($elements) {
$this->elementsToEnable = $elements;
}
2010-06-10 15:37:58 +00:00
}
/**
* Checkbox with descriptive label and help link.
2015-07-29 19:14:10 +00:00
*
2010-06-10 15:37:58 +00:00
* @package metaHTML
*/
class htmlTableExtendedInputCheckbox extends htmlInputCheckbox {
/** descriptive label */
private $label;
/** help ID */
private $helpID;
2010-06-11 19:40:26 +00:00
/** specifies if label is printed before the checkbox */
private $labelFirst;
2015-07-29 19:14:10 +00:00
2010-06-10 15:37:58 +00:00
/**
* Constructor.
2015-07-29 19:14:10 +00:00
*
2010-06-10 15:37:58 +00:00
* @param String $name unique name
2015-07-29 19:14:10 +00:00
* @param boolean $checked checked
2010-06-10 15:37:58 +00:00
* @param String $label descriptive label
* @param String $helpID help ID
2010-06-21 16:23:44 +00:00
* @param boolean $labelFirst specifies if the label is at the beginning or at the end (optional, default beginning)
2010-06-10 15:37:58 +00:00
*/
2010-06-11 19:40:26 +00:00
function __construct($name, $checked, $label, $helpID = null, $labelFirst = true) {
2010-06-10 15:37:58 +00:00
parent::__construct($name, $checked);
$this->label = htmlspecialchars($label);
$this->helpID = $helpID;
2010-06-11 19:40:26 +00:00
$this->labelFirst = $labelFirst;
2010-06-10 15:37:58 +00:00
}
/**
* Prints the HTML code for this element.
2015-07-29 19:14:10 +00:00
*
2010-06-10 15:37:58 +00:00
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
2013-03-16 14:35:41 +00:00
$onClick = 'onClick="jQuery(\'#' . $this->name . '\').prop(\'checked\',!jQuery(\'#' . $this->name . '\').prop(\'checked\')); jQuery(\'#' . $this->name . '\').change();"';
2010-06-11 19:40:26 +00:00
if ($this->labelFirst) {
echo '<div class="nowrap" ' . $onClick . '>';
2010-06-11 19:40:26 +00:00
echo $this->label;
echo '</div>';
2010-06-11 19:40:26 +00:00
echo "\n</td>\n<td>\n";
$return = parent::generateHTML($module, $input, $values, $restricted, $tabindex, $scope);
}
else {
$return = parent::generateHTML($module, $input, $values, $restricted, $tabindex, $scope);
echo "\n</td>\n<td>\n";
echo '<div class="nowrap" ' . $onClick . '>';
2010-06-11 19:40:26 +00:00
echo $this->label;
echo '</div>';
2010-06-11 19:40:26 +00:00
}
2010-06-10 15:37:58 +00:00
// print help link
if ($this->helpID != null) {
echo "\n</td>\n<td>\n";
$helpLink = new htmlHelpLink($this->helpID);
$helpLink->generateHTML($module, $input, $values, $restricted, $tabindex, $scope);
}
return $return;
}
2015-07-29 19:14:10 +00:00
2010-06-10 15:37:58 +00:00
}
2010-06-21 16:23:44 +00:00
/**
* Prints the HTML code for a file upload field.
2015-07-29 19:14:10 +00:00
*
2010-06-21 16:23:44 +00:00
* @package metaHTML
*/
class htmlInputFileUpload extends htmlElement {
2015-07-29 19:14:10 +00:00
2010-06-21 16:23:44 +00:00
/** unique name of input element */
private $name;
2010-09-13 19:30:57 +00:00
/** enabled or disabled */
private $isEnabled = true;
2015-07-29 19:14:10 +00:00
2010-06-21 16:23:44 +00:00
/**
* Constructor.
2015-07-29 19:14:10 +00:00
*
2010-06-21 16:23:44 +00:00
* @param String $name unique name
*/
function __construct($name) {
$this->name = htmlspecialchars($name);
}
/**
* Prints the HTML code for this element.
2015-07-29 19:14:10 +00:00
*
2010-06-21 16:23:44 +00:00
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
$tabindexValue = ' tabindex="' . $tabindex . '"';
$tabindex++;
2010-09-13 19:30:57 +00:00
$disabled = '';
if (!$this->isEnabled) {
$disabled = ' disabled';
}
echo '<input type="file" name="' . $this->name . '"' . $tabindexValue . $disabled . '>';
2010-06-21 16:23:44 +00:00
return array($this->name => 'file');
}
2010-09-13 19:30:57 +00:00
/**
* Specifies if this component is enabled and accepts user modification.
2015-07-29 19:14:10 +00:00
*
2010-09-13 19:30:57 +00:00
* @param boolean $isEnabled enabled if true
*/
public function setIsEnabled($isEnabled) {
$this->isEnabled = $isEnabled;
}
2010-06-21 16:23:44 +00:00
}
/**
* File upload with descriptive label and help link.
2015-07-29 19:14:10 +00:00
*
2010-06-21 16:23:44 +00:00
* @package metaHTML
*/
class htmlTableExtendedInputFileUpload extends htmlInputFileUpload {
/** descriptive label */
private $label;
/** help ID */
private $helpID;
2015-07-29 19:14:10 +00:00
2010-06-21 16:23:44 +00:00
/**
* Constructor.
2015-07-29 19:14:10 +00:00
*
2010-06-21 16:23:44 +00:00
* @param String $name unique name
* @param String $label descriptive label
* @param String $helpID help ID
*/
function __construct($name, $label, $helpID = null) {
parent::__construct($name);
$this->label = htmlspecialchars($label);
$this->helpID = $helpID;
}
/**
* Prints the HTML code for this element.
2015-07-29 19:14:10 +00:00
*
2010-06-21 16:23:44 +00:00
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
echo '<div class="nowrap">';
2010-06-21 16:23:44 +00:00
echo $this->label;
echo '</div>';
2010-06-21 16:23:44 +00:00
echo "\n</td>\n<td>\n";
$return = parent::generateHTML($module, $input, $values, $restricted, $tabindex, $scope);
// print help link
if ($this->helpID != null) {
echo "\n</td>\n<td>\n";
$helpLink = new htmlHelpLink($this->helpID);
$helpLink->generateHTML($module, $input, $values, $restricted, $tabindex, $scope);
}
return $return;
}
2015-07-29 19:14:10 +00:00
2010-06-21 16:23:44 +00:00
}
2010-06-10 15:37:58 +00:00
/**
* Prints the HTML code for a textarea.
2015-07-29 19:14:10 +00:00
*
2010-06-10 15:37:58 +00:00
* @package metaHTML
*/
2010-06-13 12:34:52 +00:00
class htmlInputTextarea extends htmlElement {
2015-07-29 19:14:10 +00:00
2010-06-10 15:37:58 +00:00
/** unique name of input element */
private $name;
/** value */
private $value;
/** column count */
private $colCount;
/** row count */
private $rowCount;
2010-09-13 19:30:57 +00:00
/** enabled or disabled */
private $isEnabled = true;
2012-01-06 13:11:48 +00:00
/** specifies if LAM should display this field whith a WYSIWYG editor */
private $richEdit = false;
2015-07-29 19:14:10 +00:00
2010-06-10 15:37:58 +00:00
/**
* Constructor.
2015-07-29 19:14:10 +00:00
*
2010-06-10 15:37:58 +00:00
* @param String $name unique name
2015-07-29 19:14:10 +00:00
* @param String $value value
2010-06-10 15:37:58 +00:00
* @param int $colCount number of characters per line
* @param int $rowCount number of rows
*/
function __construct($name, $value, $colCount, $rowCount) {
$this->name = htmlspecialchars($name);
$this->value = htmlspecialchars($value);
2012-05-17 08:40:32 +00:00
$this->colCount = htmlspecialchars($colCount);
$this->rowCount = htmlspecialchars($rowCount);
2010-06-10 15:37:58 +00:00
}
/**
* Prints the HTML code for this element.
2015-07-29 19:14:10 +00:00
*
2010-06-10 15:37:58 +00:00
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
2013-01-12 11:26:34 +00:00
$this->cssClasses[] = 'ui-corner-all';
2010-06-10 15:37:58 +00:00
if (isset($values[$this->name])) {
$this->value = implode("\r\n", $values[$this->name]);
}
2015-08-04 18:41:12 +00:00
$colCount = ($this->colCount != null) ? ' cols="' . $this->colCount . '"' : '';
$rowCount = ($this->rowCount != null) ? ' rows="' . $this->rowCount . '"' : '';
2010-06-10 15:37:58 +00:00
$tabindexValue = ' tabindex="' . $tabindex . '"';
$tabindex++;
2010-09-13 19:30:57 +00:00
$disabled = '';
if (!$this->isEnabled) {
$disabled = ' disabled';
}
2012-12-10 20:58:20 +00:00
$classList = $this->cssClasses;
2012-01-06 13:11:48 +00:00
$classes = '';
if ($this->richEdit) {
2012-12-10 20:58:20 +00:00
$classList[] = 'ckeditor';
}
2013-01-12 11:26:34 +00:00
$classes = ' class="' . implode(' ', $classList) . '"';
2012-01-06 13:11:48 +00:00
echo '<textarea name="' . $this->name . '" id="' . $this->name . '"' . $tabindexValue . $classes . $colCount . $rowCount . $disabled . '>' . $this->value . '</textarea>';
2010-06-10 15:37:58 +00:00
return array($this->name => 'textarea');
}
2010-09-13 19:30:57 +00:00
/**
* Specifies if this component is enabled and accepts user modification.
2015-07-29 19:14:10 +00:00
*
2010-09-13 19:30:57 +00:00
* @param boolean $isEnabled enabled if true
*/
public function setIsEnabled($isEnabled) {
$this->isEnabled = $isEnabled;
}
2015-07-29 19:14:10 +00:00
2012-01-06 13:11:48 +00:00
/**
* Specifies if the textarea should be displayed whith a WYSIWYG editor.
* <br>This requires that the page which displays the textarea also includes the ckeditor JS.
* <br>Rich editing is disabled by default.
2015-07-29 19:14:10 +00:00
*
2012-01-06 13:11:48 +00:00
* @param boolean $richEdit rich edit or standard
*/
public function setIsRichEdit($richEdit) {
$this->richEdit = $richEdit;
}
2010-09-13 19:30:57 +00:00
2010-06-10 15:37:58 +00:00
}
/**
* Text area with label and help link.
2015-07-29 19:14:10 +00:00
*
2010-06-10 15:37:58 +00:00
* @package metaHTML
*/
class htmlTableExtendedInputTextarea extends htmlInputTextarea {
/** descriptive label */
private $label;
/** help ID */
private $helpID;
/** required field */
private $required = false;
2015-07-29 19:14:10 +00:00
2010-06-10 15:37:58 +00:00
/**
* Constructor.
2015-07-29 19:14:10 +00:00
*
2010-06-10 15:37:58 +00:00
* @param String $name unique name
2015-07-29 19:14:10 +00:00
* @param String $value value
2010-06-10 15:37:58 +00:00
* @param int $colCount number of characters per line
* @param int $rowCount number of rows
* @param String $label descriptive label
* @param String $helpID help ID
*/
function __construct($name, $value, $colCount, $rowCount, $label, $helpID = null) {
2010-06-10 15:37:58 +00:00
parent::__construct($name, $value, $colCount, $rowCount);
$this->label = htmlspecialchars($label);
$this->helpID = $helpID;
2012-05-17 10:04:54 +00:00
$this->alignment = htmlElement::ALIGN_TOP;
2010-06-10 15:37:58 +00:00
}
/**
* Prints the HTML code for this element.
2015-07-29 19:14:10 +00:00
*
2010-06-10 15:37:58 +00:00
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
echo '<div class="nowrap">';
2010-06-10 15:37:58 +00:00
echo $this->label;
if ($this->required) {
$graphicsPath = "../../graphics";
if (is_dir("../graphics")) $graphicsPath = "../graphics";
echo '<img src="' . $graphicsPath . '/required.png" alt="required" width=16 height=16 title="' . _('required') . '">';
2010-06-10 15:37:58 +00:00
}
echo '</div>';
2010-06-10 15:37:58 +00:00
echo "\n</td>\n<td>\n";
$return = parent::generateHTML($module, $input, $values, $restricted, $tabindex, $scope);
// print help link
if ($this->helpID != null) {
2013-02-05 19:10:34 +00:00
echo "\n</td>\n<td valign=\"top\">\n";
2010-06-10 15:37:58 +00:00
$helpLink = new htmlHelpLink($this->helpID);
$helpLink->generateHTML($module, $input, $values, $restricted, $tabindex, $scope);
}
return $return;
}
2015-07-29 19:14:10 +00:00
2010-06-10 15:37:58 +00:00
/**
* Specifies if this input field must be filled.
2015-07-29 19:14:10 +00:00
*
2010-06-10 15:37:58 +00:00
* @param boolean $required required or not
*/
public function setRequired($required) {
$this->required = $required;
}
}
2010-06-11 19:40:26 +00:00
/**
* Prints the HTML code for an image.
2015-07-29 19:14:10 +00:00
*
2010-06-11 19:40:26 +00:00
* @package metaHTML
*/
2010-06-13 12:34:52 +00:00
class htmlImage extends htmlElement {
2015-07-29 19:14:10 +00:00
2010-06-11 19:40:26 +00:00
/** path to image */
private $path;
/** width */
private $width;
/** height */
private $height;
/** alt text */
private $alt;
2015-08-02 17:33:53 +00:00
/** title */
private $title;
2015-10-10 09:02:00 +00:00
/** onClick event */
private $onClick = null;
2015-07-29 19:14:10 +00:00
2010-06-11 19:40:26 +00:00
/**
* Constructor.
2015-07-29 19:14:10 +00:00
*
2010-06-11 19:40:26 +00:00
* @param String $path image location
2015-07-29 19:14:10 +00:00
* @param int $width image width (optional, default original size)
2010-06-11 19:40:26 +00:00
* @param int $height image height (optional, default original size)
* @param String $alt alt text (optional)
2015-10-10 09:02:00 +00:00
* @param String $onClick onClick code (optional)
2010-06-11 19:40:26 +00:00
*/
2015-10-10 09:02:00 +00:00
function __construct($path, $width = null, $height = null, $alt = ' ', $title = null, $onClick = null) {
2010-06-11 19:40:26 +00:00
$this->path = htmlspecialchars($path);
$this->width = $width;
$this->height = $height;
$this->alt = htmlspecialchars($alt);
2015-08-02 17:33:53 +00:00
$this->title = $title;
2015-10-10 09:02:00 +00:00
$this->onClick = $onClick;
2010-06-11 19:40:26 +00:00
}
/**
* Prints the HTML code for this element.
2015-07-29 19:14:10 +00:00
*
2010-06-11 19:40:26 +00:00
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
$path = ' src="' . $this->path . '"';
$width = '';
if ($this->width != null) {
$width = ' width="' . $this->width . '"';
}
$height = '';
if ($this->height != null) {
$height = ' height="' . $this->height . '"';
}
$alt = ' alt="' . $this->alt . '"';
2015-08-02 17:33:53 +00:00
$title = '';
if (!empty($this->title)) {
$title = ' title="' . $this->title . '"';
}
2014-10-25 13:13:44 +00:00
$classes = '';
if (!empty($this->cssClasses)) {
$classes = 'class="' . implode(' ', $this->cssClasses) . '"';
}
2015-10-10 09:02:00 +00:00
$onClick = '';
if ($this->onClick != null) {
$onClick = ' onclick="' . $this->onClick . '"';
}
echo '<img' . $path . $width . $height . $alt . $title . $classes . $onClick . ">\n";
2010-06-11 19:40:26 +00:00
return array();
}
}
2010-06-13 12:34:52 +00:00
/**
* Adds an empty space with given width and height.
*
* @package metaHTML
*/
class htmlSpacer extends htmlElement {
2015-07-29 19:14:10 +00:00
2012-07-15 12:05:47 +00:00
/** width of spacer in px */
2010-06-13 12:34:52 +00:00
private $width;
2012-07-15 12:05:47 +00:00
/** height of spacer in px */
2010-06-13 12:34:52 +00:00
private $height;
2015-07-29 19:14:10 +00:00
2010-06-13 12:34:52 +00:00
/**
* Constructor.
*
* @param String $width width (e.g. 10px)
* @param String $height height (e.g. 10px)
*/
function __construct($width, $height) {
$this->width = htmlspecialchars($width);
$this->height = htmlspecialchars($height);
}
2015-07-29 19:14:10 +00:00
2010-06-13 12:34:52 +00:00
/**
* Prints the HTML code for this element.
2015-07-29 19:14:10 +00:00
*
2010-06-13 12:34:52 +00:00
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
$width = '';
if ($this->width != null) {
$width = 'width: ' . $this->width . ';';
}
$height = '';
if ($this->height != null) {
$height = 'height: ' . $this->height . ';';
}
2012-09-09 13:59:31 +00:00
echo "<div style=\"$width $height display: inline-block;\"></div>\n";
2010-06-13 12:34:52 +00:00
return array();
}
2015-07-29 19:14:10 +00:00
2010-06-13 12:34:52 +00:00
}
2010-08-20 13:23:29 +00:00
/**
* Prints a status message (e.g. error message).
*
* @package metaHTML
*/
class htmlStatusMessage extends htmlElement {
2015-07-29 19:14:10 +00:00
2012-07-15 12:05:47 +00:00
/** message type (e.g. ERROR) */
2010-08-20 13:23:29 +00:00
private $type;
2012-07-15 12:05:47 +00:00
/** message title */
2010-08-20 13:23:29 +00:00
private $title;
2012-07-15 12:05:47 +00:00
/** message text */
2010-08-20 13:23:29 +00:00
private $text;
2012-07-15 12:05:47 +00:00
/** message parameters */
2010-09-20 17:36:42 +00:00
private $params;
2015-07-29 19:14:10 +00:00
2010-08-20 13:23:29 +00:00
/**
* Constructor.
*
* @param String $type message type (e.g. ERROR)
* @param String $title message title
* @param String $text message (optional)
2012-07-15 12:05:47 +00:00
* @param array $params additional message parameters
2010-08-20 13:23:29 +00:00
*/
2010-09-20 17:36:42 +00:00
function __construct($type, $title, $text = null, $params = null) {
2010-08-20 13:23:29 +00:00
$this->type = $type;
$this->title = $title;
$this->text = $text;
2010-09-20 17:36:42 +00:00
$this->params = $params;
2010-08-20 13:23:29 +00:00
}
2015-07-29 19:14:10 +00:00
2010-08-20 13:23:29 +00:00
/**
* Prints the HTML code for this element.
2015-07-29 19:14:10 +00:00
*
2010-08-20 13:23:29 +00:00
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
2010-09-20 17:36:42 +00:00
StatusMessage($this->type, $this->title, $this->text, $this->params);
2010-08-20 13:23:29 +00:00
return array();
}
2010-08-29 16:02:27 +00:00
}
2015-07-29 19:14:10 +00:00
2010-08-29 16:02:27 +00:00
/**
2010-09-04 12:40:42 +00:00
* Generates a fieldset.
2015-07-29 19:14:10 +00:00
*
2010-08-29 16:02:27 +00:00
* @package metaHTML
*/
class htmlFieldset extends htmlElement {
/** fieldset content */
private $content;
/** descriptive label */
private $label = null;
/** label image */
private $labelImage = null;
2015-07-29 19:14:10 +00:00
2010-08-29 16:02:27 +00:00
/**
* Constructor.
2015-07-29 19:14:10 +00:00
*
2010-08-29 16:02:27 +00:00
* @param htmlElement $content content to display inside fieldset
* @param String $label label
2015-07-29 19:14:10 +00:00
* @param String $labelImage image to put before label
2010-08-29 16:02:27 +00:00
*/
function __construct($content, $label = null, $labelImage = null) {
$this->content = $content;
$this->label = htmlspecialchars($label);
$this->labelImage = htmlspecialchars($labelImage);
}
/**
* Prints the HTML code for this element.
2015-07-29 19:14:10 +00:00
*
2010-08-29 16:02:27 +00:00
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
2016-08-27 08:40:05 +00:00
$classes = $this->cssClasses;
$classes[] = 'ui-corner-all';
if ($scope != null) {
2016-08-27 08:40:05 +00:00
$classes[] = $scope . '-border';
$classes[] = $scope . '-bright';
}
2016-08-27 08:40:05 +00:00
$class = implode(' ', $classes);
echo "<fieldset class=\"$class\">\n";
2010-08-29 16:02:27 +00:00
// generate legend
if (($this->label != null) || ($this->labelImage != null)) {
echo "<legend>";
if ($this->labelImage != null) {
echo "<img align=\"middle\" src=\"" . $this->labelImage . "\" alt=\"\"> ";
}
if ($this->label != null) {
echo $this->label;
}
echo "</legend>\n";
}
$return = $this->content->generateHTML($module, $input, $values, $restricted, $tabindex, $scope);
echo "</fieldset>\n";
return $return;
}
2015-07-29 19:14:10 +00:00
2010-08-20 13:23:29 +00:00
}
2010-10-17 13:37:22 +00:00
/**
* Generates a title line. This is used for page titles.
2015-07-29 19:14:10 +00:00
*
2010-10-17 13:37:22 +00:00
* @package metaHTML
*/
class htmlTitle extends htmlElement {
/** descriptive label */
private $label = null;
2015-07-29 19:14:10 +00:00
2010-10-17 13:37:22 +00:00
/**
* Constructor.
2015-07-29 19:14:10 +00:00
*
2010-10-17 13:37:22 +00:00
* @param String $label label
*/
function __construct($label) {
$this->label = htmlspecialchars($label);
// the title should not end at a table cell
$this->colspan = 100;
}
/**
* Prints the HTML code for this element.
2015-07-29 19:14:10 +00:00
*
2010-10-17 13:37:22 +00:00
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
echo "<div class=\"title\">\n";
echo "<h2 class=\"titleText\">\n";
echo $this->label;
echo "</h2>\n";
echo "</div>\n";
return array();
}
2015-07-29 19:14:10 +00:00
2010-10-17 13:37:22 +00:00
}
2010-09-04 12:40:42 +00:00
/**
* Generates a subtitle line. This is used to group multiple fields.
2015-07-29 19:14:10 +00:00
*
2010-09-04 12:40:42 +00:00
* @package metaHTML
*/
class htmlSubTitle extends htmlElement {
/** descriptive label */
private $label = null;
2010-11-14 20:35:34 +00:00
/** optional image */
private $image = null;
2012-06-02 17:49:20 +00:00
/** optional ID for this element (e.g. to use for JavaScript) */
private $id = null;
2015-07-29 19:14:10 +00:00
2010-09-04 12:40:42 +00:00
/**
* Constructor.
2015-07-29 19:14:10 +00:00
*
2010-09-04 12:40:42 +00:00
* @param String $label label
* @param String $image optional image
2012-06-02 17:49:20 +00:00
* @param String $id optional ID for this element (e.g. to use for JavaScript)
2010-09-04 12:40:42 +00:00
*/
2012-06-02 17:49:20 +00:00
function __construct($label, $image = null, $id = null) {
2010-09-04 12:40:42 +00:00
$this->label = htmlspecialchars($label);
2010-11-14 20:35:34 +00:00
$this->image = htmlspecialchars($image);
2012-06-02 17:49:20 +00:00
$this->id = htmlspecialchars($id);
2010-09-04 12:40:42 +00:00
// the title should not end at a table cell
$this->colspan = 100;
}
/**
* Prints the HTML code for this element.
2015-07-29 19:14:10 +00:00
*
2010-09-04 12:40:42 +00:00
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
2012-06-02 17:49:20 +00:00
$idValue = '';
if ($this->id != null) {
$idValue = ' id="' . $this->id . '"';
}
echo "<div $idValue class=\"subTitle\">\n";
2010-10-17 13:37:22 +00:00
echo "<h4 class=\"subTitleText\">\n";
2010-11-14 20:35:34 +00:00
if ($this->image != null) {
2016-07-16 12:34:53 +00:00
echo '<img height=16 width=16 src="' . $this->image . '" alt="' . $this->label . '">&nbsp;';
2010-11-14 20:35:34 +00:00
}
2010-09-04 12:40:42 +00:00
echo $this->label;
2010-10-17 13:37:22 +00:00
echo "</h4>\n";
2010-09-04 12:40:42 +00:00
echo "</div>\n";
return array();
}
2015-07-29 19:14:10 +00:00
2010-09-04 12:40:42 +00:00
}
2010-09-18 11:36:57 +00:00
/**
* Generates a hidden input field.
2015-07-29 19:14:10 +00:00
*
2010-09-18 11:36:57 +00:00
* @package metaHTML
*/
class htmlHiddenInput extends htmlElement {
/** field name */
private $name = null;
/** field value */
private $value = null;
2015-07-29 19:14:10 +00:00
2010-09-18 11:36:57 +00:00
/**
* Constructor.
2015-07-29 19:14:10 +00:00
*
2010-10-16 16:55:31 +00:00
* @param String $name input name
* @param String $value input value
2010-09-18 11:36:57 +00:00
*/
function __construct($name, $value) {
2010-10-16 16:55:31 +00:00
$this->name = htmlspecialchars($name);
$this->value = htmlspecialchars($value);
2010-09-18 11:36:57 +00:00
}
/**
* Prints the HTML code for this element.
2015-07-29 19:14:10 +00:00
*
2010-09-18 11:36:57 +00:00
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
2012-12-01 19:38:41 +00:00
echo '<input type="hidden" name="' . $this->name . '" id="' . $this->name . '" value="' . $this->value . '">';
return array($this->name => 'hidden');
2010-09-18 11:36:57 +00:00
}
2015-07-29 19:14:10 +00:00
2010-09-18 11:36:57 +00:00
}
2010-10-16 16:55:31 +00:00
/**
* Generates a link.
* The link can include an optional image in front of the link text.
2015-07-29 19:14:10 +00:00
*
2010-10-16 16:55:31 +00:00
* @package metaHTML
*/
class htmlLink extends htmlElement {
/** link text */
private $text = null;
/** link target */
2016-07-16 12:34:53 +00:00
protected $target = null;
2010-10-16 16:55:31 +00:00
/** optional image */
private $image = null;
/** title */
private $title = null;
/** target window */
private $targetWindow = null;
2011-04-25 17:47:52 +00:00
/** onClick event */
private $onClick = null;
2012-11-03 17:21:29 +00:00
/** show as button */
private $showAsButton = false;
2015-07-29 19:14:10 +00:00
2010-10-16 16:55:31 +00:00
/**
* Constructor.
2015-07-29 19:14:10 +00:00
*
2010-12-03 21:06:36 +00:00
* @param String $text label
* @param String $target target URL
* @param String $image URL of optional image
2012-11-03 17:21:29 +00:00
* @param boolean $showAsButton shows this like as a button
2010-10-16 16:55:31 +00:00
*/
2012-11-03 17:21:29 +00:00
function __construct($text, $target, $image = null, $showAsButton = false) {
2010-10-16 16:55:31 +00:00
$this->text = htmlspecialchars($text);
$this->target = htmlspecialchars($target);
$this->image = htmlspecialchars($image);
2012-11-03 17:21:29 +00:00
$this->showAsButton = $showAsButton;
2010-10-16 16:55:31 +00:00
}
/**
* Prints the HTML code for this element.
2015-07-29 19:14:10 +00:00
*
2010-10-16 16:55:31 +00:00
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
$image = '';
if ($this->image != null) {
2016-07-16 12:34:53 +00:00
$image = '<img class="align-middle" src="' . $this->image . '" alt="' . $this->getAlt() . '">&nbsp;';
2010-10-16 16:55:31 +00:00
}
$title = '';
if ($this->title != null) {
$title = ' title="' . $this->title . '"';
}
$targetWindow = '';
if ($this->targetWindow != null) {
$targetWindow = ' target="' . $this->targetWindow . '"';
}
2011-04-25 17:47:52 +00:00
$onClick = '';
if ($this->onClick != null) {
$onClick = ' onclick="' . $this->onClick . '"';
}
2012-11-03 17:21:29 +00:00
$idAttr = '';
if ($this->showAsButton) {
$id = 'a_' . preg_replace('/[^a-zA-Z0-9_]+/', '_', $this->target);
$idAttr = ' id="' . $id . '"';
}
2012-11-03 17:34:18 +00:00
$classAttr = '';
if (sizeof($this->cssClasses) > 0) {
$classAttr = ' class="' . implode(' ', $this->cssClasses) . '"';
}
2016-07-16 12:34:53 +00:00
echo '<a href="' . $this->target . '"' . $idAttr . $classAttr . $title . $targetWindow . $onClick . '>' . $image . $this->getContent() . '</a>';
2012-11-03 17:21:29 +00:00
if ($this->showAsButton) {
echo '<script type="text/javascript">';
echo ' jQuery(document).ready(function() {';
echo "jQuery('#" . $id . "').button();";
echo '});';
echo '</script>';
}
2010-10-16 16:55:31 +00:00
return array();
}
2016-07-16 12:34:53 +00:00
/**
* Returns the value for the alt attribute.
*
* @return string alt value
*/
protected function getAlt() {
return $this->text;
}
/**
* Returns the value for the link content.
*
* @return string content
*/
protected function getContent() {
return $this->text;
}
/**
* Sets the link title.
2015-07-29 19:14:10 +00:00
*
* @param String $title title
*/
public function setTitle($title) {
$this->title = htmlspecialchars($title);
}
/**
* Sets the target window (e.g. _blank).
2015-07-29 19:14:10 +00:00
*
* @param String $window target window (e.g. _blank)
*/
public function setTargetWindow($window) {
$this->targetWindow = htmlspecialchars($window);
}
2011-04-25 17:47:52 +00:00
/**
* Sets the onClick event.
2015-07-29 19:14:10 +00:00
*
2011-04-25 17:47:52 +00:00
* @param String $event JavaScript code
*/
public function setOnClick($event) {
$this->onClick = htmlspecialchars($event);
}
2015-07-29 19:14:10 +00:00
}
2016-07-16 12:34:53 +00:00
/**
* Generates a link arround a htmlElement.
*
* @package metaHTML
*/
class htmlContentLink extends htmlLink {
private $content = null;
private $contentText = '';
/**
* Constructor
*
* @param htmlElement $content content to link
* @param String $target link target
* @param boolean $highlightOnHover higlight content on hover
*/
function __construct($content, $target) {
$this->content = $content;
$this->target = htmlspecialchars($target);
}
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
ob_start();
parseHtml($module, $this->content, $values, $restricted, $tabindex, $scope);
$this->contentText = ob_get_contents();
ob_end_clean();
2017-05-06 13:21:37 +00:00
return parent::generateHTML($module, $input, $values, $restricted, $tabindex, $scope);
2016-07-16 12:34:53 +00:00
}
/**
* Returns the value for the alt attribute.
*
* @return string alt value
*/
protected function getAlt() {
return '';
}
/**
* Returns the value for the link content.
*
* @return string content
*/
protected function getContent() {
return $this->contentText;
}
}
/**
* Groups multiple htmlElements.
* This is useful if multiple elements should be included in a single table cell.
* The HTML code of the subelements is printed in the order they were added. No additional code is added.
2015-07-29 19:14:10 +00:00
*
* @package metaHTML
*/
class htmlGroup extends htmlElement {
/** link text */
private $subelements = array();
2015-07-29 19:14:10 +00:00
/**
* Prints the HTML code for this element.
2015-07-29 19:14:10 +00:00
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
$return = array();
for ($i = 0; $i < sizeof($this->subelements); $i++) {
2015-07-29 19:14:10 +00:00
$return = array_merge($return, $this->subelements[$i]->generateHTML($module, $input, $values, $restricted, $tabindex, $scope));
}
return $return;
}
/**
* Adds a subelement.
2015-07-29 19:14:10 +00:00
*
* @param htmlElement $sub subelement
*/
public function addElement($sub) {
$this->subelements[] = $sub;
}
2010-10-16 16:55:31 +00:00
}
/**
* Prints a horizontal line.
2015-07-29 19:14:10 +00:00
*
* @package metaHTML
*/
class htmlHorizontalLine extends htmlElement {
/**
* Prints the HTML code for this element.
2015-07-29 19:14:10 +00:00
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
$return = array();
echo "<hr>";
return $return;
}
2012-09-13 20:10:48 +00:00
}
/**
* Creates a simple DIV element.
2015-07-29 19:14:10 +00:00
*
2012-09-13 20:10:48 +00:00
* @package metaHTML
*/
class htmlDiv extends htmlElement {
2015-07-29 19:14:10 +00:00
2012-09-13 20:10:48 +00:00
/** unique ID */
private $id = null;
/** htmlElement that generates inner content */
private $content = null;
2015-07-29 19:14:10 +00:00
2012-09-13 20:10:48 +00:00
/**
* Constructor.
2015-07-29 19:14:10 +00:00
*
2012-09-13 20:10:48 +00:00
* @param String $id unique ID
* @param htmlElement $content inner content
* @param array $classes CSS classes
*/
2012-11-30 19:21:47 +00:00
function __construct($id, $content) {
2012-09-13 20:10:48 +00:00
$this->id = htmlspecialchars($id);
$this->content = $content;
}
2015-07-29 19:14:10 +00:00
2012-09-13 20:10:48 +00:00
/**
* Prints the HTML code for this element.
2015-07-29 19:14:10 +00:00
*
2012-09-13 20:10:48 +00:00
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
$return = array();
$idValue = '';
if ($this->id != null) {
$idValue = ' id="' . $this->id . '"';
}
$classesValue = '';
2012-11-30 19:21:47 +00:00
if (($this->cssClasses != null) && (sizeof($this->cssClasses) > 0)) {
$classesValue = ' class="' . implode(' ', $this->cssClasses) . '"';
2012-09-13 20:10:48 +00:00
}
echo '<div' . $idValue . $classesValue . '>';
if ($this->content != null) {
$return = $this->content->generateHTML($module, $input, $values, $restricted, $tabindex, $scope);
}
echo '</div>';
return $return;
}
2012-10-28 14:37:54 +00:00
}
2012-09-13 20:10:48 +00:00
2012-10-28 14:37:54 +00:00
/**
* Creates a JavaScript element.
2015-07-29 19:14:10 +00:00
*
2012-10-28 14:37:54 +00:00
* @package metaHTML
*/
class htmlJavaScript extends htmlElement {
2015-07-29 19:14:10 +00:00
2012-10-28 14:37:54 +00:00
/** htmlElement that generates inner content */
private $content = null;
2015-07-29 19:14:10 +00:00
2012-10-28 14:37:54 +00:00
/**
* Constructor.
2015-07-29 19:14:10 +00:00
*
2012-10-28 14:37:54 +00:00
* @param String $content script
*/
function __construct($content) {
$this->content = $content;
}
2015-07-29 19:14:10 +00:00
2012-10-28 14:37:54 +00:00
/**
* Prints the HTML code for this element.
2015-07-29 19:14:10 +00:00
*
2012-10-28 14:37:54 +00:00
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
$return = array();
echo '<script type="text/javascript">';
echo $this->content;
echo '</script>';
return $return;
}
2015-07-29 19:14:10 +00:00
}
2016-04-02 11:30:06 +00:00
/**
* Creates a Script element to integrate external JavaScript files.
*
* @package metaHTML
*/
class htmlScript extends htmlElement {
/** src value */
private $src = null;
/** is async */
private $async = false;
/** execute after page is parsed */
private $defer = false;
/**
* Constructor.
*
* @param String $src script path
* @param boolean $isAsync script will be executed while the page continues the parsing (default true)
* @param boolean $isDeferred script is executed when the page has finished parsing (default true)
*/
function __construct($src, $isAsync = true, $isDeferred = true) {
$this->src = $src;
$this->async = $isAsync;
$this->defer = $isDeferred;
}
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
$return = array();
$async = $this->async ? ' async' : '';
$defer = $this->defer ? ' defer="defer"' : '';
echo '<script src="' . $this->src . '"' . $async . $defer . '>';
echo '</script>';
return $return;
}
}
2012-11-25 10:59:32 +00:00
/**
* Sets all given elements to the same width.
2015-07-29 19:14:10 +00:00
*
2012-11-25 10:59:32 +00:00
* @package metaHTML
*/
class htmlEqualWidth extends htmlElement {
2015-07-29 19:14:10 +00:00
2012-11-25 10:59:32 +00:00
/** list of element IDs */
private $elements = array();
2015-07-29 19:14:10 +00:00
2012-11-25 10:59:32 +00:00
/**
* Constructor.
2015-07-29 19:14:10 +00:00
*
2012-11-25 10:59:32 +00:00
* @param array $elements list of element IDs
*/
function __construct($elements) {
foreach ($elements as $element) {
$this->elements[] = htmlspecialchars($element);
}
}
2015-07-29 19:14:10 +00:00
2012-11-25 10:59:32 +00:00
/**
* Prints the HTML code for this element.
2015-07-29 19:14:10 +00:00
*
2012-11-25 10:59:32 +00:00
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
if (sizeof($this->elements) == 0) {
return array();
}
$return = array();
$listContent = "'#" . $this->elements[0] . "'";
for ($i = 1; $i < sizeof($this->elements); $i++) {
$listContent .= ", '#" . $this->elements[$i] . "'";
}
echo '<script type="text/javascript">';
echo ' jQuery(document).ready(function() {';
echo ' var equalWidthElements = new Array(' . $listContent . ');';
echo ' equalWidth(equalWidthElements);';
echo ' });';
echo '</script>';
return $return;
}
2015-07-29 19:14:10 +00:00
2012-11-25 10:59:32 +00:00
}
2013-03-24 11:23:02 +00:00
/**
* Sets all given elements to the same height.
2015-07-29 19:14:10 +00:00
*
2013-03-24 11:23:02 +00:00
* @package metaHTML
*/
class htmlEqualHeight extends htmlElement {
2015-07-29 19:14:10 +00:00
2013-03-24 11:23:02 +00:00
/** list of element IDs */
private $elements = array();
2015-07-29 19:14:10 +00:00
2013-03-24 11:23:02 +00:00
/**
* Constructor.
2015-07-29 19:14:10 +00:00
*
2013-03-24 11:23:02 +00:00
* @param array $elements list of element IDs
*/
function __construct($elements) {
foreach ($elements as $element) {
$this->elements[] = htmlspecialchars($element);
}
}
2015-07-29 19:14:10 +00:00
2013-03-24 11:23:02 +00:00
/**
* Prints the HTML code for this element.
2015-07-29 19:14:10 +00:00
*
2013-03-24 11:23:02 +00:00
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
if (sizeof($this->elements) == 0) {
return array();
}
$return = array();
$listContent = "'#" . $this->elements[0] . "'";
for ($i = 1; $i < sizeof($this->elements); $i++) {
$listContent .= ", '#" . $this->elements[$i] . "'";
}
echo '<script type="text/javascript">';
echo ' jQuery(document).ready(function() {';
echo ' var equalHeightElements = new Array(' . $listContent . ');';
echo ' equalHeight(equalHeightElements);';
echo ' });';
echo '</script>';
return $return;
}
2015-07-29 19:14:10 +00:00
2013-03-24 11:23:02 +00:00
}
2013-02-10 16:01:41 +00:00
/**
* Creates a list of elements that can be sorted by the user via drag'n'drop.
2015-07-29 19:14:10 +00:00
*
2013-02-10 16:01:41 +00:00
* @package metaHTML
*/
class htmlSortableList extends htmlElement {
2015-07-29 19:14:10 +00:00
2013-02-10 16:01:41 +00:00
/** list of elements */
private $elements = array();
/** HTML ID */
private $id = '';
/** element width */
private $elementWidth = '';
2013-02-14 22:38:50 +00:00
/** on update event */
private $onUpdate = null;
2015-07-29 19:14:10 +00:00
2013-02-10 16:01:41 +00:00
/**
* Constructor.
2015-07-29 19:14:10 +00:00
*
* @param array $elements list of elements as text (HTML special chars must be escaped already) or htmlElement
2013-02-10 16:01:41 +00:00
* @param String HTML ID
* @param String $elementWidth width of elements (default 250px)
*/
function __construct($elements, $id, $elementWidth='250px') {
$this->elements = $elements;
$this->id = htmlspecialchars($id);
$this->elementWidth = $elementWidth;
}
2015-07-29 19:14:10 +00:00
2013-02-10 16:01:41 +00:00
/**
* Prints the HTML code for this element.
2015-07-29 19:14:10 +00:00
*
2013-02-10 16:01:41 +00:00
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
if (sizeof($this->elements) == 0) {
return array();
}
$return = array();
echo '<ul style="width:' . $this->elementWidth . ';" class="sortableList" id="' . $this->id . '">';
foreach ($this->elements as $element) {
echo '<li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>';
if ($element instanceof htmlElement) {
parseHtml($module, $element, $values, $restricted, $tabindex, $scope);
}
else {
echo $element;
}
2013-02-10 16:01:41 +00:00
echo '</li>';
}
echo '</ul>';
2013-02-14 22:38:50 +00:00
$onUpdate = '';
if ($this->onUpdate != null) {
$onUpdate = '{
update: function(event, ui) {' . $this->onUpdate . '},
start: function(event, ui) {
var posOrig = ui.item.index();
ui.item.data(\'posOrig\', posOrig);
}
}';
}
2013-02-10 16:01:41 +00:00
$scriptContent = '
jQuery(function() {
2013-02-14 22:38:50 +00:00
$("#' . $this->id . '").sortable(' . $onUpdate . ');
2013-02-10 16:01:41 +00:00
$("#' . $this->id . '").disableSelection();
});';
$script = new htmlJavaScript($scriptContent);
$script->generateHTML($module, $input, $values, $restricted, $tabindex, $scope);
return $return;
}
2015-07-29 19:14:10 +00:00
2013-02-14 22:38:50 +00:00
/**
* Sets the JS code that is executed when the element order was changed.
* The code can access the variables event and ui. See JQueryUI docs for details.
* ui.item.data('posOrig') will contain the original position of the moved element.
2015-07-29 19:14:10 +00:00
*
2013-02-14 22:38:50 +00:00
* @param String $onUpdate JS code
*/
public function setOnUpdate($onUpdate) {
$this->onUpdate = $onUpdate;
}
2013-02-10 16:01:41 +00:00
}
/**
* Creates a list of content elements in accordion style.
* HTML special characters must be escaped before providing to htmlAccordion.
*/
class htmlAccordion extends htmlElement {
private $id = null;
private $elements = null;
private $openInitial = '1';
private $collapsible = false;
2015-07-29 19:14:10 +00:00
/**
* Constructor.
2015-07-29 19:14:10 +00:00
*
* @param String $id HTML ID
* @param array $elements list of content elements array('title' => htmlElement)
* @param String $openInitial index of element that is initially opened (default: 0), set to 'false' to close all
* @param boolean $collapsible specifies if all elements may be closed at the same time (default: false, true if $openInitial is false)
*/
function __construct($id, $elements, $openInitial = '0', $collapsible = false) {
$this->id = $id;
$this->elements = $elements;
$this->openInitial = $openInitial;
if (($openInitial === 'false') || ($openInitial === false)) {
$this->collapsible = true;
}
else {
$this->collapsible = $collapsible;
}
}
2015-07-29 19:14:10 +00:00
/**
* Prints the HTML code for this element.
2015-07-29 19:14:10 +00:00
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
$result = array();
$collapsible = 'false';
if ($this->collapsible) {
$collapsible = 'true';
}
$active = 'false';
if ($this->openInitial !== false) {
$active = $this->openInitial;
}
echo '<div id="' . $this->id . '">';
foreach ($this->elements as $label => $content) {
echo '<h3>' . $label . '</h3>';
echo '<div>';
$result = array_merge($result, $content->generateHTML($module, $input, $values, $restricted, $tabindex, $scope));
echo '</div>';
}
echo '</div>';
$script = 'jQuery(function() {
$( "#' . $this->id . '" ).accordion({
collapsible: ' . $collapsible . ',
active: ' . $active . '
});
});';
$js = new htmlJavaScript($script);
$js->generateHTML($module, $input, $values, $restricted, $tabindex, $scope);
return $result;
}
}
2016-04-02 11:30:06 +00:00
/**
* Creates a Google reCAPTCHA element.
*
* @package metaHTML
*/
class htmlReCAPTCHA extends htmlElement {
/** site key */
private $key = null;
/**
* Constructor.
*
* @param String $key site key
*/
function __construct($key) {
$this->key = htmlspecialchars($key);
}
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
$script = new htmlScript('https://www.google.com/recaptcha/api.js');
$script->generateHTML($module, $input, $values, $restricted, $tabindex, $scope);
echo '<div class="g-recaptcha" data-sitekey="' . $this->key . '"></div>';
return array();
}
}
2015-07-29 19:14:10 +00:00
/**
* Responsive row with 12 column layout.
*/
class htmlResponsiveRow extends htmlElement {
private $cells = array();
2015-08-09 09:00:38 +00:00
/**
* Creates a new responsive row.
*
* @param htmlElement $label label element if this is a simple label+field row
* @param htmlElement $field field element if this is a simple label+field row
*/
public function __construct($label = null, $field = null) {
$this->cells = array();
if ($label != null) {
$this->addLabel($label);
}
if ($field != null) {
$this->addField($field);
}
}
2015-07-29 19:14:10 +00:00
/**
* Adds a responsive cell to the row.
*
* @param htmlResponsiveCell $cell cell
*/
public function addCell($cell) {
$this->cells[] = $cell;
}
/**
* Adds a cell with the given content and column counts.
*
* @param htmlElement $content content inside cell
* @param int $numMobile number of columns for mobile view
2015-08-02 17:33:53 +00:00
* @param int $numTablet number of columns for tablet view (set to mobile if null)
* @param int $numDesktop number of columns for desktop view (set to tablet if null)
2015-07-29 19:14:10 +00:00
* @param String $classes CSS classes separated by space
*/
2015-08-02 17:33:53 +00:00
public function add($content, $numMobile, $numTablet = null, $numDesktop = null, $classes = '') {
$tabletCols = ($numTablet == null) ? $numMobile : $numTablet;
$desktopCols = ($numDesktop == null) ? $tabletCols : $numDesktop;
$this->addCell(new htmlResponsiveCell($content, $numMobile, $tabletCols, $tabletCols, $classes));
2015-07-29 19:14:10 +00:00
}
2015-08-09 07:57:56 +00:00
/**
* Adds the content as a typical label with 12/6/6 columns and CSS class "responsiveLabel".
*
* @param htmlElement $content label
*/
public function addLabel($content) {
$this->add($content, 12, 6, 6, 'responsiveLabel');
}
/**
* Adds the content as a typical field with 12/6/6 columns and CSS class "responsiveField".
*
* @param htmlElement $content field
2015-08-09 13:18:04 +00:00
* @param $cssClasses CSS class names separated by space
2015-08-09 07:57:56 +00:00
*/
2015-08-09 13:18:04 +00:00
public function addField($content, $cssClasses = '') {
$this->add($content, 12, 6, 6, 'responsiveField ' . $cssClasses);
2015-08-09 07:57:56 +00:00
}
2015-07-29 19:14:10 +00:00
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
public function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
2015-08-02 17:33:53 +00:00
$return = array();
2015-07-29 19:14:10 +00:00
echo '<div class="row">';
foreach ($this->cells as $cell) {
2015-08-02 17:33:53 +00:00
$return = array_merge($return, $cell->generateHTML($module, $input, $values, $restricted, $tabindex, $scope));
2015-07-29 19:14:10 +00:00
}
echo '</div>';
2015-08-02 17:33:53 +00:00
return $return;
2015-07-29 19:14:10 +00:00
}
}
/**
* Responsive cell inside htmlResponsiveRow with 12 column layout.
*/
class htmlResponsiveCell extends htmlElement {
private $content = null;
private $mobile = null;
private $tablet = null;
private $desktop = null;
private $classes = '';
/**
* Constructs a cell inside a responsive row with 12 columns.
*
* @param htmlElement $content content inside cell
* @param int $numMobile number of columns for mobile view
* @param int $numTablet number of columns for tablet view
* @param int $numDesktop number of columns for desktop view
* @param String $classes CSS classes separated by space
*/
public function __construct($content, $numMobile, $numTablet, $numDesktop, $classes = '') {
$this->content = $content;
$this->mobile = $numMobile;
$this->tablet = $numTablet;
$this->desktop = $numDesktop;
$this->classes = $classes;
}
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
public function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
$clMobile = ($this->mobile > 0) ? 'small-' . $this->mobile : 'hide-for-small-only';
$clTablet = ($this->tablet > 0) ? 'medium-' . $this->tablet : 'hide-for-medium-only';
$clDesktop = ($this->desktop > 0) ? 'large-' . $this->desktop : 'hide-for-large-only';
echo '<div class="' . $clMobile . ' ' . $clTablet . ' ' . $clDesktop . ' columns ' . $this->classes . '">';
2015-08-02 17:33:53 +00:00
$return = $this->content->generateHTML($module, $input, $values, $restricted, $tabindex, $scope);
2015-07-29 19:14:10 +00:00
echo '</div>';
2015-08-02 17:33:53 +00:00
return $return;
}
}
/**
* A responsive input field that combines label, input field and help.
*
* @package metaHTML
*/
class htmlResponsiveInputField extends htmlInputField {
/** Descriptive label */
private $label;
/** help ID */
private $helpID;
/** generate HTML of parent class */
private $generateParent = false;
/**
* Constructor
*
* @param String $label descriptive label
* @param String $fieldName unique field name
* @param String $fieldValue value of input field (optional)
* @param String $helpID help ID (optional)
*/
function __construct($label, $fieldName, $fieldValue = null, $helpID = null) {
parent::__construct($fieldName, $fieldValue);
$this->label = $label;
$this->helpID = $helpID;
$this->fieldSize = null;
}
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
if ($this->generateParent) {
return parent::generateHTML($module, $input, $values, $restricted, $tabindex, $scope);
}
$this->generateParent = true;
$row = new htmlResponsiveRow();
// label text
$labelGroup = new htmlGroup();
$labelGroup->addElement(new htmlOutputText($this->label));
if ($this->required) {
$graphicsPath = "../../graphics";
if (is_dir("../graphics")) $graphicsPath = "../graphics";
$labelGroup->addElement(new htmlImage($graphicsPath . '/required.png', 16, 16, _('required'), _('required')));
}
2015-08-05 17:03:32 +00:00
$row->add($labelGroup, 12, 6, 6, 'responsiveLabel');
2015-08-02 17:33:53 +00:00
// input field
$fieldGroup = new htmlGroup();
$fieldGroup->addElement($this);
if (!empty($this->helpID)) {
$fieldGroup->addElement(new htmlHelpLink($this->helpID));
}
2015-08-05 17:03:32 +00:00
$row->add($fieldGroup, 12, 6, 6, 'responsiveField');
2015-08-02 17:33:53 +00:00
return $row->generateHTML($module, $input, $values, $restricted, $tabindex, $scope);
2015-07-29 19:14:10 +00:00
}
}
2010-06-13 12:34:52 +00:00
?>