From a75ae6a8cfd3a2526fc1fee9fa45b08262497680 Mon Sep 17 00:00:00 2001 From: ATM john Date: Sun, 28 Nov 2021 12:11:03 +0100 Subject: [PATCH 1/9] Fix missing formsetup elements --- htdocs/core/class/html.formsetup.class.php | 144 +++++++++++++++++- htdocs/modulebuilder/template/admin/setup.php | 85 ++++++----- 2 files changed, 189 insertions(+), 40 deletions(-) diff --git a/htdocs/core/class/html.formsetup.class.php b/htdocs/core/class/html.formsetup.class.php index 6f2ec2acfb6..a8ed08587ed 100644 --- a/htdocs/core/class/html.formsetup.class.php +++ b/htdocs/core/class/html.formsetup.class.php @@ -44,6 +44,47 @@ class FormSetup /** @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(); + + + /** + * the value of action attribute of form + * @var string + */ + public $formAction; + /** * Constructor * @@ -55,6 +96,11 @@ class FormSetup 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; @@ -63,6 +109,38 @@ class FormSetup } } + /** + * a quick method to sanitize html attributes + * @param string $var the string to sanitize + * @return string + */ + static public function sanitizeHtmlAttribute($var) + { + $var = preg_replace("/\r|\n/", "", $var); + return htmlspecialchars($var, ENT_QUOTES); + } + + /** + * Generae an attributes string form an input array + * @param array $attributes an array of attributes keys and values, + * @return 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.'="'.self::sanitizeHtmlAttribute($value).'"'; + } + } + + return !empty($Aattr)?implode(' ', $Aattr):''; + } + + /** * @param bool $editMode true will display output on edit mod * @return string @@ -83,12 +161,70 @@ class FormSetup if ($reshook > 0) { return $hookmanager->resPrint; } else { - $out = ''; + $out = ''; + $out.= $this->htmlBeforeOutputForm; + if ($editMode) { - $out .= ''; + $out.= '
formAttributes) . ' >'; + + // generate hidden values from $this->formHiddenInputs + if (!empty($this->formHiddenInputs) && is_array($this->formHiddenInputs)) { + foreach ($this->formHiddenInputs as $hiddenKey => $hiddenValue) { + $out.= ''; + } + } } - $out .= ''; + // generate output table + $out .= $this->generateTableOutput($editMode); + + + $reshook = $hookmanager->executeHooks('formSetupBeforeGenerateOutputButton', $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; + } elseif ($editMode) { + $out .= '
'; // Todo : remove this
by adding style to form-setup-button-container css class in all themes + $out .= '
'; // Todo : remove .center by adding style to form-setup-button-container css class in all themes + $out.= $this->htmlOutputMoreButton; + $out .= ''; // Todo fix dolibarr style for
'; $out .= ''; $out .= ''; $out .= ' '; @@ -247,7 +383,7 @@ class FormSetup public function exportItemsAsParamsArray() { $arrayofparameters = array(); - foreach ($this->items as $key => $item) { + foreach ($this->items as $item) { $arrayofparameters[$item->confKey] = array( 'type' => $item->getType(), 'enabled' => $item->enabled diff --git a/htdocs/modulebuilder/template/admin/setup.php b/htdocs/modulebuilder/template/admin/setup.php index 5690d18678b..6836585285c 100644 --- a/htdocs/modulebuilder/template/admin/setup.php +++ b/htdocs/modulebuilder/template/admin/setup.php @@ -88,6 +88,9 @@ $arrayofparameters = array( //'MYMODULE_MYPARAM7'=>array('type'=>'product', 'enabled'=>1), ); +$error = 0; +$setupnotempty = 0; + // Set this to 1 to use the factory to manage constants. Warning, the generated module will be compatible with version v15+ only $useFormSetup = 0; // Convert arrayofparameter into a formSetup object @@ -95,35 +98,44 @@ if (!empty($arrayofparameters) && $useFormSetup && (float) DOL_VERSION >= 15) { require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsetup.class.php'; $formSetup = new FormSetup($db); - foreach ($arrayofparameters as $key => $val) { - if ($val['enabled']) { - $item = $formSetup->newItem($key); + // you can use the param convertor + $formSetup->addItemsFromParamsArray($arrayofparameters); - if ($val['type'] == 'string') { - $item->fieldOverride = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $_SERVER['HTTP_HOST']; - $item->cssClass = $val['css']; - } - if ($val['type'] == 'thirdparty_type') { - $item->setAsThirdpartyType(); - } - if ($val['type'] == 'yesno') { - $formSetup->newItem($key)->setAsYesNo(); - } - if ($val['type'] == 'emailtemplate:thirdparty') { - $formSetup->newItem($key)->setAsEmailTemplate('thirdparty'); - } - if ($val['type'] == 'securekey') { - $formSetup->newItem($key)->setAsSecureKey()->enabled = 0; // disabled - } - if ($val['type'] == 'product') { - $formSetup->newItem($key)->setAsProduct(); - } - } - } + // or use the new system see exemple as follow (or use both because you can ;-) ) + + /* + // Hôte + $item = $formSetup->newItem('NO_PARAM_JUST_TEXT'); + $item->fieldOverride = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $_SERVER['HTTP_HOST']; + $item->cssClass = 'minwidth500'; + + // Setup conf MYMODULE_MYPARAM1 as a simple string input + $item = $formSetup->newItem('MYMODULE_MYPARAM1'); + + // Setup conf MYMODULE_MYPARAM1 as a simple textarea input but we replace the text of field title + $item = $formSetup->newItem('MYMODULE_MYPARAM2'); + $item->nameText = $item->getNameText().' more html text '; + + // Setup conf MYMODULE_MYPARAM3 + $item = $formSetup->newItem('MYMODULE_MYPARAM3'); + $item->setAsThirdpartyType(); + + // Setup conf MYMODULE_MYPARAM4 : exemple of quick define write style + $formSetup->newItem('MYMODULE_MYPARAM4')->setAsYesNo(); + + // Setup conf MYMODULE_MYPARAM5 + $formSetup->newItem('MYMODULE_MYPARAM5')->setAsEmailTemplate('thirdparty'); + + // Setup conf MYMODULE_MYPARAM6 + $formSetup->newItem('MYMODULE_MYPARAM6')->setAsSecureKey()->enabled = 0; // disabled + + // Setup conf MYMODULE_MYPARAM7 + $formSetup->newItem('MYMODULE_MYPARAM7')->setAsProduct(); + */ + + $setupnotempty = count($formSetup->items); } -$error = 0; -$setupnotempty = 0; $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); @@ -258,13 +270,13 @@ echo ''.$langs->trans("MyModuleSetupPage").'< if ($action == 'edit') { - print ''; - print ''; - print ''; - if ($useFormSetup && (float) DOL_VERSION >= 15) { print $formSetup->generateOutput(true); } else { + print ''; + print ''; + print ''; + print '
' . $this->langs->trans("Parameter") . '
'; print ''; @@ -350,18 +362,19 @@ if ($action == 'edit') { } } print '
'.$langs->trans("Parameter").''.$langs->trans("Value").'
'; - } - print '
'; - print ''; - print '
'; - print '
'; + print '
'; + print ''; + print '
'; + + print ''; + } + print '
'; } else { if ($useFormSetup && (float) DOL_VERSION >= 15) { if (!empty($formSetup->items)) { print $formSetup->generateOutput(); - $setupnotempty = count($formSetup->items); } } else { if (!empty($arrayofparameters)) { From 29437a22b9364314cafd4021547f885a2ab51c54 Mon Sep 17 00:00:00 2001 From: ATM john Date: Sun, 28 Nov 2021 12:15:31 +0100 Subject: [PATCH 2/9] Fix comment and remove not use global --- htdocs/core/class/html.formsetup.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/class/html.formsetup.class.php b/htdocs/core/class/html.formsetup.class.php index a8ed08587ed..149e416fd81 100644 --- a/htdocs/core/class/html.formsetup.class.php +++ b/htdocs/core/class/html.formsetup.class.php @@ -121,7 +121,7 @@ class FormSetup } /** - * Generae an attributes string form an input array + * Generate an attributes string form an input array * @param array $attributes an array of attributes keys and values, * @return string */ @@ -690,7 +690,7 @@ class FormSetupItem */ public function generateInputField() { - global $conf, $user; + global $conf; if (!empty($this->fieldOverride)) { return $this->fieldOverride; From e97e0e4f17d315c989d07ab1fd640febab4fb921 Mon Sep 17 00:00:00 2001 From: ATM john Date: Sun, 28 Nov 2021 12:18:09 +0100 Subject: [PATCH 3/9] Fix remove not used propertie --- htdocs/core/class/html.formsetup.class.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/htdocs/core/class/html.formsetup.class.php b/htdocs/core/class/html.formsetup.class.php index 149e416fd81..13dd3a8694c 100644 --- a/htdocs/core/class/html.formsetup.class.php +++ b/htdocs/core/class/html.formsetup.class.php @@ -79,12 +79,6 @@ class FormSetup public $formHiddenInputs = array(); - /** - * the value of action attribute of form - * @var string - */ - public $formAction; - /** * Constructor * From c0d00a859f1f9883c85abdeb1d22055ab798dee6 Mon Sep 17 00:00:00 2001 From: John BOTELLA Date: Wed, 1 Dec 2021 16:59:30 +0100 Subject: [PATCH 4/9] use dol_escape_htmltag --- htdocs/core/class/html.formsetup.class.php | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/htdocs/core/class/html.formsetup.class.php b/htdocs/core/class/html.formsetup.class.php index 13dd3a8694c..1778b46995e 100644 --- a/htdocs/core/class/html.formsetup.class.php +++ b/htdocs/core/class/html.formsetup.class.php @@ -103,17 +103,6 @@ class FormSetup } } - /** - * a quick method to sanitize html attributes - * @param string $var the string to sanitize - * @return string - */ - static public function sanitizeHtmlAttribute($var) - { - $var = preg_replace("/\r|\n/", "", $var); - return htmlspecialchars($var, ENT_QUOTES); - } - /** * Generate an attributes string form an input array * @param array $attributes an array of attributes keys and values, @@ -127,7 +116,7 @@ class FormSetup if (is_array($value) || is_object($value)) { continue; } - $Aattr[] = $attribute.'="'.self::sanitizeHtmlAttribute($value).'"'; + $Aattr[] = $attribute.'="'.dol_escape_htmltag($value).'"'; } } @@ -164,7 +153,7 @@ class FormSetup // generate hidden values from $this->formHiddenInputs if (!empty($this->formHiddenInputs) && is_array($this->formHiddenInputs)) { foreach ($this->formHiddenInputs as $hiddenKey => $hiddenValue) { - $out.= ''; + $out.= ''; } } } From 1e845434e05569dc88d8b228a4b7d51547f42cf4 Mon Sep 17 00:00:00 2001 From: mbinformatique68 Date: Fri, 3 Dec 2021 09:42:50 +0100 Subject: [PATCH 5/9] Get societe terms of payment if getpost terms of payment is 0 --- htdocs/comm/propal/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php index 2d8887c7929..66191110de2 100644 --- a/htdocs/comm/propal/card.php +++ b/htdocs/comm/propal/card.php @@ -1646,7 +1646,7 @@ if ($action == 'create') { // Terms of payment print ''.$langs->trans('PaymentConditionsShort').''; print img_picto('', 'paiment'); - $form->select_conditions_paiements((GETPOSTISSET('cond_reglement_id') ? GETPOST('cond_reglement_id', 'int') : $soc->cond_reglement_id), 'cond_reglement_id', -1, 1); + $form->select_conditions_paiements((GETPOSTISSET('cond_reglement_id') && GETPOST('cond_reglement_id') != 0) ? GETPOST('cond_reglement_id', 'int') : $soc->cond_reglement_id, 'cond_reglement_id', -1, 1); print ''; // Mode of payment From 611bae4c3a2faf41a03fc3ebb474104a6926fe94 Mon Sep 17 00:00:00 2001 From: fr69400 <82267780+fr69400@users.noreply.github.com> Date: Fri, 10 Dec 2021 14:20:04 +0100 Subject: [PATCH 6/9] FIX - unasigned variable $action given to hook printOriginObjectSubLine --- htdocs/core/class/commonobject.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index f2471d122af..03a9d518021 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -4855,7 +4855,7 @@ abstract class CommonObject */ public function printOriginLinesList($restrictlist = '', $selectedLines = array()) { - global $langs, $hookmanager, $conf, $form; + global $langs, $hookmanager, $conf, $form, $action; print ''; print ''.$langs->trans('Ref').''; From 2419784bdb743efe197745e1876eeb2578cbeb29 Mon Sep 17 00:00:00 2001 From: fr69400 <82267780+fr69400@users.noreply.github.com> Date: Mon, 13 Dec 2021 16:54:42 +0100 Subject: [PATCH 7/9] Update commonobject.class.php --- htdocs/core/class/commonobject.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 03a9d518021..85fc0922913 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -4881,7 +4881,7 @@ abstract class CommonObject if (is_object($hookmanager)) { // Old code is commented on preceding line. $parameters = array('line'=>$line, 'i'=>$i, 'restrictlist'=>$restrictlist, 'selectedLines'=> $selectedLines); if (!empty($line->fk_parent_line)) { $parameters['fk_parent_line'] = $line->fk_parent_line; } - $reshook = $hookmanager->executeHooks('printOriginObjectSubLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks + $reshook = $hookmanager->executeHooks('printOriginObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks } if (empty($reshook)) { $this->printOriginLine($line, '', $restrictlist, '/core/tpl', $selectedLines); From 1d8cf297de0d115a07c1b50f77c4e7594f912e96 Mon Sep 17 00:00:00 2001 From: John BOTELLA Date: Tue, 14 Dec 2021 12:10:09 +0100 Subject: [PATCH 8/9] Update html.formsetup.class.php --- htdocs/core/class/html.formsetup.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/html.formsetup.class.php b/htdocs/core/class/html.formsetup.class.php index 1778b46995e..a3f8a58d88e 100644 --- a/htdocs/core/class/html.formsetup.class.php +++ b/htdocs/core/class/html.formsetup.class.php @@ -45,7 +45,7 @@ class FormSetup protected $maxItemRank; /** - * this is an html string display before output form + * this is an html string display before output form * @var string */ public $htmlBeforeOutputForm = ''; From 66c486c8788b6c65e496542461db39343d0056ad Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Tue, 14 Dec 2021 11:12:54 +0000 Subject: [PATCH 9/9] Fixing style errors. --- htdocs/core/class/html.formsetup.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/html.formsetup.class.php b/htdocs/core/class/html.formsetup.class.php index a3f8a58d88e..1778b46995e 100644 --- a/htdocs/core/class/html.formsetup.class.php +++ b/htdocs/core/class/html.formsetup.class.php @@ -45,7 +45,7 @@ class FormSetup protected $maxItemRank; /** - * this is an html string display before output form + * this is an html string display before output form * @var string */ public $htmlBeforeOutputForm = '';