auto-format all files; add table-definitions to test-bootstrap file
Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
@@ -14,14 +14,16 @@
|
||||
* @package Classes
|
||||
*
|
||||
*/
|
||||
|
||||
class htmlform
|
||||
{
|
||||
|
||||
/**
|
||||
* internal tmp-variable to store form
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private static $_form = '';
|
||||
|
||||
private static $_filename = '';
|
||||
|
||||
public static function genHTMLForm($data = array())
|
||||
@@ -31,46 +33,43 @@ class htmlform
|
||||
|
||||
self::$_form = '';
|
||||
|
||||
foreach($data as $fdata)
|
||||
{
|
||||
foreach ($data as $fdata) {
|
||||
$sections = $fdata['sections'];
|
||||
|
||||
foreach($sections as $section)
|
||||
{
|
||||
foreach ($sections as $section) {
|
||||
/*
|
||||
* here be section title & image
|
||||
*/
|
||||
*/
|
||||
$title = $section['title'];
|
||||
$image = $section['image'];
|
||||
|
||||
if(isset($section['visible']) && $section['visible'] === false)
|
||||
{
|
||||
if (isset($section['visible']) && $section['visible'] === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isset($section['nobuttons']) || $section['nobuttons'] == false) {
|
||||
if (! isset($section['nobuttons']) || $section['nobuttons'] == false) {
|
||||
eval("self::\$_form .= \"" . getTemplate("misc/form/table_section", "1") . "\";");
|
||||
} else {
|
||||
$nob = true;
|
||||
}
|
||||
|
||||
$nexto = false;
|
||||
foreach($section['fields'] as $fieldname => $fielddata)
|
||||
{
|
||||
if(isset($fielddata['visible']) && $fielddata['visible'] === false)
|
||||
{
|
||||
foreach ($section['fields'] as $fieldname => $fielddata) {
|
||||
if (isset($fielddata['visible']) && $fielddata['visible'] === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($nexto === false || (isset($fielddata['next_to']) && $nexto['field'] != $fielddata['next_to'])) {
|
||||
$label = $fielddata['label'];
|
||||
$desc = (isset($fielddata['desc']) ? $fielddata['desc'] : '');
|
||||
$style = (isset($fielddata['style']) ? ' class="'.$fielddata['style'].'"' : '');
|
||||
$style = (isset($fielddata['style']) ? ' class="' . $fielddata['style'] . '"' : '');
|
||||
$mandatory = self::_getMandatoryFlag($fielddata);
|
||||
$data_field = self::_parseDataField($fieldname, $fielddata);
|
||||
if (isset($fielddata['has_nextto'])) {
|
||||
$nexto = array('field' => $fieldname);
|
||||
$data_field.='{NEXTTOFIELD_'.$fieldname.'}';
|
||||
$nexto = array(
|
||||
'field' => $fieldname
|
||||
);
|
||||
$data_field .= '{NEXTTOFIELD_' . $fieldname . '}';
|
||||
} else {
|
||||
$nexto = false;
|
||||
}
|
||||
@@ -78,12 +77,8 @@ class htmlform
|
||||
} else {
|
||||
$data_field = self::_parseDataField($fieldname, $fielddata);
|
||||
$data_field = str_replace("\t", "", $data_field);
|
||||
$data_field = $fielddata['next_to_prefix'].$data_field;
|
||||
self::$_form = str_replace(
|
||||
'{NEXTTOFIELD_'.$fielddata['next_to'].'}',
|
||||
$data_field,
|
||||
self::$_form
|
||||
);
|
||||
$data_field = $fielddata['next_to_prefix'] . $data_field;
|
||||
self::$_form = str_replace('{NEXTTOFIELD_' . $fielddata['next_to'] . '}', $data_field, self::$_form);
|
||||
$nexto = false;
|
||||
}
|
||||
}
|
||||
@@ -91,7 +86,7 @@ class htmlform
|
||||
}
|
||||
|
||||
// add save/reset buttons at the end of the form
|
||||
if (!$nob) {
|
||||
if (! $nob) {
|
||||
eval("self::\$_form .= \"" . getTemplate("misc/form/table_end", "1") . "\";");
|
||||
}
|
||||
|
||||
@@ -100,41 +95,48 @@ class htmlform
|
||||
|
||||
private static function _parseDataField($fieldname, $data = array())
|
||||
{
|
||||
switch($data['type'])
|
||||
{
|
||||
switch ($data['type']) {
|
||||
case 'text':
|
||||
return self::_textBox($fieldname, $data); break;
|
||||
return self::_textBox($fieldname, $data);
|
||||
break;
|
||||
case 'textul':
|
||||
return self::_textBox($fieldname, $data, 'text', true); break;
|
||||
return self::_textBox($fieldname, $data, 'text', true);
|
||||
break;
|
||||
case 'password':
|
||||
return self::_textBox($fieldname, $data, 'password'); break;
|
||||
return self::_textBox($fieldname, $data, 'password');
|
||||
break;
|
||||
case 'hidden':
|
||||
return self::_textBox($fieldname, $data, 'hidden'); break;
|
||||
return self::_textBox($fieldname, $data, 'hidden');
|
||||
break;
|
||||
case 'yesno':
|
||||
return self::_yesnoBox($data); break;
|
||||
return self::_yesnoBox($data);
|
||||
break;
|
||||
case 'select':
|
||||
return self::_selectBox($fieldname, $data); break;
|
||||
return self::_selectBox($fieldname, $data);
|
||||
break;
|
||||
case 'label':
|
||||
return self::_labelField($data); break;
|
||||
return self::_labelField($data);
|
||||
break;
|
||||
case 'textarea':
|
||||
return self::_textArea($fieldname, $data); break;
|
||||
return self::_textArea($fieldname, $data);
|
||||
break;
|
||||
case 'checkbox':
|
||||
return self::_checkbox($fieldname, $data); break;
|
||||
return self::_checkbox($fieldname, $data);
|
||||
break;
|
||||
case 'file':
|
||||
return self::_file($fieldname, $data); break;
|
||||
return self::_file($fieldname, $data);
|
||||
break;
|
||||
case 'int':
|
||||
return self::_int($fieldname, $data); break;
|
||||
return self::_int($fieldname, $data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static function _getMandatoryFlag($data = array())
|
||||
{
|
||||
if(isset($data['mandatory']))
|
||||
{
|
||||
if (isset($data['mandatory'])) {
|
||||
return ' <span class="red">*</span>';
|
||||
}
|
||||
elseif(isset($data['mandatory_ex']))
|
||||
{
|
||||
} elseif (isset($data['mandatory_ex'])) {
|
||||
return ' <span class="red">**</span>';
|
||||
}
|
||||
return '';
|
||||
@@ -144,14 +146,14 @@ class htmlform
|
||||
{
|
||||
$return = '';
|
||||
$extras = '';
|
||||
if(isset($data['maxlength'])) {
|
||||
$extras .= ' maxlength="'.$data['maxlength'].'"';
|
||||
if (isset($data['maxlength'])) {
|
||||
$extras .= ' maxlength="' . $data['maxlength'] . '"';
|
||||
}
|
||||
if(isset($data['size'])) {
|
||||
$extras .= ' size="'.$data['size'].'"';
|
||||
if (isset($data['size'])) {
|
||||
$extras .= ' size="' . $data['size'] . '"';
|
||||
}
|
||||
if(isset($data['autocomplete'])) {
|
||||
$extras .= ' autocomplete="'.$data['autocomplete'].'"';
|
||||
if (isset($data['autocomplete'])) {
|
||||
$extras .= ' autocomplete="' . $data['autocomplete'] . '"';
|
||||
}
|
||||
|
||||
// add support to save reloaded forms
|
||||
@@ -163,10 +165,9 @@ class htmlform
|
||||
$value = '';
|
||||
}
|
||||
|
||||
$ulfield = ($unlimited == true ? ' '.$data['ul_field'] : '');
|
||||
if(isset($data['display']) && $data['display'] != '')
|
||||
{
|
||||
$ulfield = '<strong>'.$data['display'].'</strong>';
|
||||
$ulfield = ($unlimited == true ? ' ' . $data['ul_field'] : '');
|
||||
if (isset($data['display']) && $data['display'] != '') {
|
||||
$ulfield = '<strong>' . $data['display'] . '</strong>';
|
||||
}
|
||||
|
||||
eval("\$return = \"" . getTemplate("misc/form/input_text", "1") . "\";");
|
||||
@@ -177,11 +178,11 @@ class htmlform
|
||||
{
|
||||
$return = '';
|
||||
$extras = '';
|
||||
if(isset($data['cols'])) {
|
||||
$extras .= ' cols="'.$data['cols'].'"';
|
||||
if (isset($data['cols'])) {
|
||||
$extras .= ' cols="' . $data['cols'] . '"';
|
||||
}
|
||||
if(isset($data['rows'])) {
|
||||
$extras .= ' rows="'.$data['rows'].'"';
|
||||
if (isset($data['rows'])) {
|
||||
$extras .= ' rows="' . $data['rows'] . '"';
|
||||
}
|
||||
|
||||
// add support to save reloaded forms
|
||||
@@ -220,12 +221,10 @@ class htmlform
|
||||
}
|
||||
|
||||
return '<select
|
||||
id="'.$fieldname.'"
|
||||
name="'.$fieldname.'"
|
||||
'.(isset($data['class']) ? ' class="'.$data['class'] .'" ' : '').'
|
||||
>'
|
||||
.$select_var.
|
||||
'</select>';
|
||||
id="' . $fieldname . '"
|
||||
name="' . $fieldname . '"
|
||||
' . (isset($data['class']) ? ' class="' . $data['class'] . '" ' : '') . '
|
||||
>' . $select_var . '</select>';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -233,32 +232,36 @@ class htmlform
|
||||
*
|
||||
* <code>
|
||||
* $data = array(
|
||||
* 'label' => $lng['customer']['email_imap'],
|
||||
* 'type' => 'checkbox',
|
||||
* 'values' => array(
|
||||
* array( 'label' => 'active',
|
||||
* 'value' => '1'
|
||||
* )
|
||||
* ),
|
||||
* 'value' => array('1'),
|
||||
* 'mandatory' => true
|
||||
* )
|
||||
* 'label' => $lng['customer']['email_imap'],
|
||||
* 'type' => 'checkbox',
|
||||
* 'values' => array(
|
||||
* array( 'label' => 'active',
|
||||
* 'value' => '1'
|
||||
* )
|
||||
* ),
|
||||
* 'value' => array('1'),
|
||||
* 'mandatory' => true
|
||||
* )
|
||||
* </code>
|
||||
*
|
||||
* @param string $fieldname contains the fieldname
|
||||
* @param array $data contains the data array
|
||||
* @param string $fieldname
|
||||
* contains the fieldname
|
||||
* @param array $data
|
||||
* contains the data array
|
||||
*/
|
||||
public static function _checkbox($fieldname = '', $data = array()) {
|
||||
public static function _checkbox($fieldname = '', $data = array())
|
||||
{
|
||||
// $data['value'] contains checked items
|
||||
|
||||
$checked = array();
|
||||
if (isset($data['value'])) {
|
||||
$checked = $data['value'];
|
||||
}
|
||||
|
||||
if (isset($_SESSION['requestData'])) {
|
||||
if(isset($_SESSION['requestData'][$fieldname])) {
|
||||
$checked = array($_SESSION['requestData'][$fieldname]);
|
||||
if (isset($_SESSION['requestData'][$fieldname])) {
|
||||
$checked = array(
|
||||
$_SESSION['requestData'][$fieldname]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,12 +274,12 @@ class htmlform
|
||||
|
||||
// will contain the output
|
||||
$output = "";
|
||||
foreach($data['values'] as $val) {
|
||||
foreach ($data['values'] as $val) {
|
||||
$key = $val['label'];
|
||||
// is this box checked?
|
||||
$isChecked = '';
|
||||
if (is_array($checked) && count($checked) > 0) {
|
||||
foreach($checked as $tmp) {
|
||||
foreach ($checked as $tmp) {
|
||||
if ($tmp == $val['value']) {
|
||||
$isChecked = ' checked="checked" ';
|
||||
break;
|
||||
@@ -285,10 +288,10 @@ class htmlform
|
||||
}
|
||||
$output .= '<label>';
|
||||
if (empty($isArray)) {
|
||||
$output .= '<input type="hidden" name="'.$fieldname.'" value="0" />';
|
||||
$output .= '<input type="hidden" name="' . $fieldname . '" value="0" />';
|
||||
}
|
||||
$output .= '<input type="checkbox" name="'.$fieldname.$isArray.'" value="'.$val['value'].'" '.$isChecked.'/>';
|
||||
$output .= $key.'</label>';
|
||||
$output .= '<input type="checkbox" name="' . $fieldname . $isArray . '" value="' . $val['value'] . '" ' . $isChecked . '/>';
|
||||
$output .= $key . '</label>';
|
||||
}
|
||||
|
||||
return $output;
|
||||
@@ -298,8 +301,8 @@ class htmlform
|
||||
{
|
||||
$return = '';
|
||||
$extras = '';
|
||||
if(isset($data['maxlength'])) {
|
||||
$extras .= ' maxlength="'.$data['maxlength'].'"';
|
||||
if (isset($data['maxlength'])) {
|
||||
$extras .= ' maxlength="' . $data['maxlength'] . '"';
|
||||
}
|
||||
|
||||
// add support to save reloaded forms
|
||||
@@ -311,9 +314,8 @@ class htmlform
|
||||
$value = '';
|
||||
}
|
||||
|
||||
if(isset($data['display']) && $data['display'] != '')
|
||||
{
|
||||
$ulfield = '<strong>'.$data['display'].'</strong>';
|
||||
if (isset($data['display']) && $data['display'] != '') {
|
||||
$ulfield = '<strong>' . $data['display'] . '</strong>';
|
||||
}
|
||||
|
||||
eval("\$return = \"" . getTemplate("misc/form/input_file", "1") . "\";");
|
||||
@@ -324,11 +326,11 @@ class htmlform
|
||||
{
|
||||
$return = '';
|
||||
$extras = '';
|
||||
if(isset($data['int_min'])) {
|
||||
$extras .= ' min="'.$data['int_min'].'"';
|
||||
if (isset($data['int_min'])) {
|
||||
$extras .= ' min="' . $data['int_min'] . '"';
|
||||
}
|
||||
if(isset($data['int_max'])) {
|
||||
$extras .= ' max="'.$data['int_max'].'"';
|
||||
if (isset($data['int_max'])) {
|
||||
$extras .= ' max="' . $data['int_max'] . '"';
|
||||
}
|
||||
|
||||
// add support to save reloaded forms
|
||||
|
||||
Reference in New Issue
Block a user