Commit f5f3f9af authored by Carsten  Rose's avatar Carsten Rose
Browse files

BuildForm.php, Form.ph: Class 'BuildFormPlain' renamed to BuildElements

parent aabfc75b
......@@ -39,8 +39,10 @@ class FormBuildPlain {
$this->wrap[WRAP_SETUP_TITLE][WRAP_SETUP_START] = '<h3>';
$this->wrap[WRAP_SETUP_TITLE][WRAP_SETUP_END] = '</h3>';
$this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_START] = '<p>';
$this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_END] = '</p>';
$this->wrap[WRAP_SETUP_LABEL][WRAP_SETUP_START] = '';
$this->wrap[WRAP_SETUP_LABEL][WRAP_SETUP_END] = '';
$this->wrap[WRAP_SETUP_INPUT][WRAP_SETUP_START] = '';
......@@ -50,8 +52,8 @@ class FormBuildPlain {
$this->buildElementFunctionName = [
'checkbox' => 'Checkbox',
'dateJQW' => 'dateJQW',
'datetimeJQW' => 'dateJQW',
'dateJQW' => 'DateJQW',
'datetimeJQW' => 'DateJQW',
'email' => 'Input',
'gridJQW' => 'GridJQW',
'hidden' => 'Hidden',
......@@ -60,7 +62,7 @@ class FormBuildPlain {
'password' => 'Input',
'radio' => 'Radio',
'select' => 'Select',
'subrecord' => 'subrecord',
'subrecord' => 'Subrecord',
'upload' => 'File',
'url' => 'Input'
];
......@@ -131,8 +133,10 @@ class FormBuildPlain {
$html = '';
// get current data record
$row = $this->db->sql("SELECT * FROM `" . $this->formSpec['tableName'] . "` WHERE id = ?", ROW_REGULAR, array($recordId));
$this->store->setVarArray($row, STORE_RECORD);
if ($recordId > 0) {
$row = $this->db->sql("SELECT * FROM `" . $this->formSpec['tableName'] . "` WHERE id = ?", ROW_REGULAR, array($recordId));
$this->store->setVarArray($row[0], STORE_RECORD);
}
// Iterate over all FormElements
foreach ($this->feSpecNative as $fe) {
......@@ -217,11 +221,10 @@ class FormBuildPlain {
$attribute .= $this->getAttribute('rows', $colsRows[1]);
} else {
$attribute .= $this->getAttribute('type', $formElement['type']);
$attribute .= $this->getAttribute('size', $formElement['size']);
$attribute .= $this->getAttributeList($formElement, ['type', 'size', 'maxLength']);
}
// 'maxLength' needs an upper 'L': naming convention for DB tables!
$attribute .= $this->getAttributeList($formElement, ['autocomplete', 'autofocus', 'maxLength', 'placeholder']);
$attribute .= $this->getAttributeList($formElement, ['autocomplete', 'autofocus', 'placeholder']);
if ($formElement['type'] === 'email' && $formElement['checkType'] === '')
$formElement['checkType'] = 'email';
......@@ -230,7 +233,7 @@ class FormBuildPlain {
$attribute .= $this->getAttributeMode($formElement);
$attribute .= $this->getAttribute('value', addslashes($value), false);
$attribute .= $this->getAttribute('value', htmlentities($value), false);
return "$htmlTag $attribute>$htmlTagClosing";
}
......@@ -399,9 +402,21 @@ class FormBuildPlain {
$itemValue = $this->getItemsForEnumOrSet($formElement['name'], $fieldType);
if (is_array($formElement['sql1'])) {
$itemValue = array_column($formElement['sql1'], 'label');
$keys = array_keys($formElement['sql1'][0]);
$itemKey = array_column($formElement['sql1'], 'id');
// If there is no column 'id' and at least two columns in total
if (count($itemKey) === 0 && count($keys) >= 2) {
$itemKey = array_column($formElement['sql1'], $keys[0]);
}
$itemValue = array_column($formElement['sql1'], 'label');
// If there is no column 'label' (e.g.: SHOW tables)
if (count($itemValue) === 0) {
$idx = count($keys) == 1 ? 0 : 1;
$itemValue = array_column($formElement['sql1'], $keys[$idx]);
}
} elseif (isset($formElement['itemList'])) {
$arr = qfq\helper\KeyValueStringParser::parse($formElement['itemList'], ':', ',', IF_VALUE_EMPTY_COPY_KEY);
$itemValue = array_values($arr);
......@@ -409,7 +424,7 @@ class FormBuildPlain {
} elseif ($fieldType === 'enum' || $fieldType === 'set') {
// already done at the beginning with '$this->getItemsForEnumOrSet($formElement['name'], $fieldType);'
} else {
throw new UserException("Missing definition (nothing in 'sql1', 'parameter:itemValues, 'enum-' or 'set-definition')", ERROR_MISSING_ITEM_VALUES);
throw new UserException("Missing definition (- nothing found in 'sql1', 'parameter:itemValues', 'enum-' or 'set-definition'", ERROR_MISSING_ITEM_VALUES);
}
if (count($itemKey) === 0) {
......@@ -525,7 +540,7 @@ class FormBuildPlain {
* @return string
*/
private function buildHidden(array $formElement, $htmlFormElementId, $value) {
return '<input type="hidden" name="' . $htmlFormElementId . '" value="' . addslashes($value) . '">';
return '<input type="hidden" name="' . $htmlFormElementId . '" value="' . htmlentities($value) . '">';
}
/**
......@@ -679,14 +694,16 @@ class FormBuildPlain {
* @throws UserException
*/
private function buildSubrecord(array $formElement, $htmlFormElementId, $value) {
$html = '';
if (!is_array($formElement['sql1'])) {
throw new UserException('Missing \'sql1\' Query', ERROR_MISSING_SQL1);
}
// construct column attributes
$control = $this->getSubrecordColumnControl(array_keys($formElement['sql1'][0]));
$html = '<b>' . $formElement['label'] . '</b>';
$html .= '<table>';
// $html .= '<b>' . $formElement['label'] . '</b>';
$html .= '<table border="1">';
$html .= '<tr><th>' . implode('</th><th>', $control['title']) . '</th></tr>';
foreach ($formElement['sql1'] as $row) {
$html .= '<tr>';
......@@ -703,7 +720,7 @@ class FormBuildPlain {
}
$html .= '</table>';
return "<p>$html</p>";
return $html;
}
/**
......@@ -731,6 +748,8 @@ class FormBuildPlain {
}
$control[$attribute][$col] = $value;
}
// Limit title length
$control['title'][$col] = substr($control['title'][$col], 0, $control['width'][$col]);
}
return $control;
}
......
......@@ -25,7 +25,7 @@ require_once(__DIR__ . '/../qfq/exceptions/CodeException.php');
require_once(__DIR__ . '/../qfq/exceptions/DbException.php');
require_once(__DIR__ . '/../qfq/Database.php');
require_once(__DIR__ . '/../qfq/Evaluate.php');
require_once(__DIR__ . '/../qfq/FormBuildPlain.php');
require_once(__DIR__ . '/../qfq/BuildForm.php');
/*
* Form will be called
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment