*
* 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 3 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, see .
*/
/**
* This class help you create setup render
*/
class FormSetup
{
/**
* @var DoliDB Database handler.
*/
public $db;
/** @var FormSetupItem[] */
public $items = array();
/**
* @var int
*/
public $setupNotEmpty = 0;
/** @var Translate */
public $langs;
/** @var Form */
public $form;
/** @var int */
protected $maxItemRank;
/**
* this is an html string display before output form
* @var string
*/
public $htmlBeforeOutputForm = '';
/**
* this is an html string display after output form
* @var string
*/
public $htmlAfterOutputForm = '';
/**
* this is an html string display on buttons zone
* @var string
*/
public $htmlOutputMoreButton = '';
/**
*
* @var array
*/
public $formAttributes = array(
'action' => '', // set in __construct
'method' => 'POST'
);
/**
* an list of hidden inputs used only in edit mode
* @var array
*/
public $formHiddenInputs = array();
/**
* Constructor
*
* @param DoliDB $db Database handler
* @param Translate $outputLangs if needed can use another lang
*/
public function __construct($db, $outputLangs = false)
{
global $langs;
$this->db = $db;
$this->form = new Form($this->db);
$this->formAttributes['action'] = $_SERVER["PHP_SELF"];
$this->formHiddenInputs['token'] = newToken();
$this->formHiddenInputs['action'] = 'update';
if ($outputLangs) {
$this->langs = $outputLangs;
} else {
$this->langs = $langs;
}
}
/**
* Generate an attributes string form an input array
*
* @param array $attributes an array of attributes keys and values,
* @return string attribute string
*/
static public function generateAttributesStringFromArray($attributes)
{
$Aattr = array();
if (is_array($attributes)) {
foreach ($attributes as $attribute => $value) {
if (is_array($value) || is_object($value)) {
continue;
}
$Aattr[] = $attribute.'="'.dol_escape_htmltag($value).'"';
}
}
return !empty($Aattr)?implode(' ', $Aattr):'';
}
/**
* generateOutput
*
* @param bool $editMode true will display output on edit mod
* @return string html output
*/
public function generateOutput($editMode = false)
{
global $hookmanager, $action;
require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
$parameters = array(
'editMode' => $editMode
);
$reshook = $hookmanager->executeHooks('formSetupBeforeGenerateOutput', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
if ($reshook > 0) {
return $hookmanager->resPrint;
} else {
$out = '';
$out.= $this->htmlBeforeOutputForm;
if ($editMode) {
$out.= '