allow CSS for tables and extended htmlHelpLink

This commit is contained in:
Roland Gruber 2010-12-05 13:28:24 +00:00
parent 652a48e420
commit 336709544f
1 changed files with 50 additions and 9 deletions

View File

@ -126,8 +126,6 @@ abstract class htmlElement {
*/ */
class htmlTable extends htmlElement { class htmlTable extends htmlElement {
/** table header */
const header = "<table>\n";
/** table footer */ /** table footer */
const footer = "</table>\n"; const footer = "</table>\n";
/** new line */ /** new line */
@ -137,15 +135,17 @@ class htmlTable extends htmlElement {
private $elements = array(); private $elements = array();
/** specifies if currently a row is open */ /** specifies if currently a row is open */
private $rowOpen = false; private $rowOpen = false;
/** additional CSS classes */
private $CSSClasses = '';
/** /**
* Adds an element to the table. The element may be a htmlElement object or a simple String. * 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 * @param mixed $element htmlElement object or a simple String
* @param boolean $newLine adds a new line after the element (optional, default false) * @param boolean $newLine adds a new line after the element (optional, default false)
* @param array $options list of options (e.g. htmlElement::OPTION_ALIGN => htmlElement::ALIGN_TOP) * @param boolean $isTableHeadElement specifies if this is a head or body element (default: body)
*/ */
public function addElement($element, $newLine = false) { public function addElement($element, $newLine = false, $isTableHeadElement = false) {
// add row element // add row element
if ($element instanceof htmlTableRow) { if ($element instanceof htmlTableRow) {
// check if a row needs to be closed // check if a row needs to be closed
@ -166,9 +166,13 @@ class htmlTable extends htmlElement {
$align = $element->getAlignmentString(); $align = $element->getAlignmentString();
$colspan = $element->getColspanString(); $colspan = $element->getColspanString();
$rowspan = $element->getRowspanString(); $rowspan = $element->getRowspanString();
$this->elements[] = "<td $align $colspan $rowspan>\n"; $tagName = 'td';
if ($isTableHeadElement) {
$tagName = 'th';
}
$this->elements[] = "<$tagName $align $colspan $rowspan>\n";
$this->elements[] = $element; $this->elements[] = $element;
$this->elements[] = "</td>\n"; $this->elements[] = "</$tagName>\n";
if ($newLine) { if ($newLine) {
$this->addNewLine(); $this->addNewLine();
} }
@ -203,7 +207,7 @@ class htmlTable extends htmlElement {
*/ */
public function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) { public function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
$return = array(); $return = array();
echo htmlTable::header; echo "<table $this->CSSClasses>\n";
// print all contained elements // print all contained elements
for ($i = 0; $i < sizeof($this->elements); $i++) { for ($i = 0; $i < sizeof($this->elements); $i++) {
// print htmlElement objects // print htmlElement objects
@ -255,6 +259,15 @@ class htmlTable extends htmlElement {
$this->elements = array_merge($this->elements, $table->elements); $this->elements = array_merge($this->elements, $table->elements);
} }
/**
* Sets the CSS classes for the table.
*
* @param String $CSSClasses CSS class names (e.g. "userlist smallPadding")
*/
public function setCSSClasses($CSSClasses) {
$this->CSSClasses = 'class="' . htmlspecialchars($CSSClasses) . '"';
}
} }
/** /**
@ -266,6 +279,8 @@ class htmlTable extends htmlElement {
class htmlTableRow extends htmlElement { class htmlTableRow extends htmlElement {
private $cells; private $cells;
/** additional CSS classes */
private $CSSClasses = '';
/** /**
* Constructor * Constructor
@ -290,7 +305,7 @@ class htmlTableRow extends htmlElement {
*/ */
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) { function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
$types = array(); $types = array();
echo "<tr>\n"; echo "<tr $this->CSSClasses>\n";
for ($i = 0; $i < sizeof($this->cells); $i++) { for ($i = 0; $i < sizeof($this->cells); $i++) {
// check if alignment option was given // check if alignment option was given
$align = $this->cells[$i]->getAlignmentString(); $align = $this->cells[$i]->getAlignmentString();
@ -304,6 +319,15 @@ class htmlTableRow extends htmlElement {
return $types; return $types;
} }
/**
* Sets the CSS classes for the table.
*
* @param String $CSSClasses CSS class names (e.g. "userlist smallPadding")
*/
public function setCSSClasses($CSSClasses) {
$this->CSSClasses = 'class="' . htmlspecialchars($CSSClasses) . '"';
}
} }
/** /**
@ -492,14 +516,22 @@ class htmlHelpLink extends htmlElement {
/** help ID */ /** help ID */
private $helpID; private $helpID;
/** module name if it should be forced */
private $module;
/** account type if it should be forced */
private $scope;
/** /**
* Constructor * Constructor
* *
* @param String $helpID help ID * @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)
*/ */
function __construct($helpID) { function __construct($helpID, $module = null, $scope = null) {
$this->helpID = $helpID; $this->helpID = $helpID;
$this->module = $module;
$this->scope = $scope;
} }
/** /**
@ -514,6 +546,14 @@ class htmlHelpLink extends htmlElement {
* @return array List of input field names and their type (name => type) * @return array List of input field names and their type (name => type)
*/ */
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) { function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
// overwrite module and scop if needed
if ($this->module != null) {
$module = $this->module;
}
if ($this->scope != null) {
$scope = $this->scope;
}
// print link
$helpEntry = getHelp($module, $this->helpID, $scope); $helpEntry = getHelp($module, $this->helpID, $scope);
printHelpLink($helpEntry, $this->helpID, $module, $scope); printHelpLink($helpEntry, $this->helpID, $module, $scope);
return array(); return array();
@ -1804,6 +1844,7 @@ class htmlSubTitle extends htmlElement {
* Constructor. * Constructor.
* *
* @param String $label label * @param String $label label
* @param String $image optional image
*/ */
function __construct($label, $image = null) { function __construct($label, $image = null) {
$this->label = htmlspecialchars($label); $this->label = htmlspecialchars($label);