From 85a450cdd270425f87398c04d66574962f3de462 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Sun, 14 Feb 2021 15:02:05 +0100 Subject: [PATCH 1/3] setup page feature --- htdocs/modulebuilder/template/admin/setup.php | 65 +++++++++++++++++-- 1 file changed, 58 insertions(+), 7 deletions(-) diff --git a/htdocs/modulebuilder/template/admin/setup.php b/htdocs/modulebuilder/template/admin/setup.php index e93b8686d79..72239ff3d1b 100644 --- a/htdocs/modulebuilder/template/admin/setup.php +++ b/htdocs/modulebuilder/template/admin/setup.php @@ -61,8 +61,11 @@ $scandir = GETPOST('scan_dir', 'alpha'); $type = 'myobject'; $arrayofparameters = array( - 'MYMODULE_MYPARAM1'=>array('css'=>'minwidth200', 'enabled'=>1), - 'MYMODULE_MYPARAM2'=>array('css'=>'minwidth500', 'enabled'=>1) + 'MYMODULE_MYPARAM1'=>array('type'=>'string', 'css'=>'minwidth500' ,'enabled'=>1), + 'MYMODULE_MYPARAM2'=>array('type'=>'textarea','enabled'=>1), + //'MYMODULE_MYPARAM3'=>array('type'=>'category:'.Categorie::TYPE_CUSTOMER, 'enabled'=>1), + //'MYMODULE_MYPARAM4'=>array('type'=>'emailtemplate:thirdparty', 'enabled'=>1), + //'MYMODULE_MYPARAM5'=>array('type'=>'yesno', 'enabled'=>1), ); $error = 0; @@ -208,11 +211,59 @@ if ($action == 'edit') { print ''; print ''; - foreach ($arrayofparameters as $key => $val) { - print ''; + foreach ($arrayofparameters as $constname => $val) { + if ($val['enabled']==1) { + $setupnotempty++; + print ''; + } } print '
'.$langs->trans("Parameter").''.$langs->trans("Value").'
'; - $tooltiphelp = (($langs->trans($key.'Tooltip') != $key.'Tooltip') ? $langs->trans($key.'Tooltip') : ''); - print $form->textwithpicto($langs->trans($key), $tooltiphelp); - print '
'; + $tooltiphelp = (($langs->trans($constname . 'Tooltip') != $constname . 'Tooltip') ? $langs->trans($constname . 'Tooltip') : ''); + print '' . $form->textwithpicto($langs->trans($constname), $tooltiphelp, 1, 'info', '', 0, 3, 'tootips' . $constname) . ''; + print ''; + + if ($val['type'] == 'textarea') { + print '\n"; + } elseif ($val['type'] == 'html') { + require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php'; + $doleditor = new DolEditor($constname, $conf->global->{$constname}, '', 160, 'dolibarr_notes', '', false, false, $conf->fckeditor->enabled, ROWS_5, '90%'); + $doleditor->Create(); + } elseif ($val['type'] == 'yesno') { + print $form->selectyesno($constname, $conf->global->{$constname}, 1); + } elseif (preg_match('/emailtemplate:/', $val['type'])) { + include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php'; + $formmail = new FormMail($db); + + $tmp = explode(':', $val['type']); + + $nboftemplates = $formmail->fetchAllEMailTemplate($tmp[1], $user, null, -1); // We set lang=null to get in priority record with no lang + //$arraydefaultmessage = $formmail->getEMailTemplate($db, $tmp[1], $user, null, 0, 1, ''); + $arrayofmessagename = array(); + if (is_array($formmail->lines_model)) { + foreach ($formmail->lines_model as $modelmail) { + //var_dump($modelmail); + $moreonlabel = ''; + if (!empty($arrayofmessagename[$modelmail->label])) { + $moreonlabel = ' (' . $langs->trans("SeveralLangugeVariatFound") . ')'; + } + // The 'label' is the key that is unique if we exclude the language + $arrayofmessagename[$modelmail->label . ':' . $tmp[1]] = $langs->trans(preg_replace('/\(|\)/', '', $modelmail->label)) . $moreonlabel; + } + } + print $form->selectarray($constname, $arrayofmessagename, $conf->global->{$constname}, 'None', 0, 0, '', 0, 0, 0, '', '', 1); + } elseif (preg_match('/category:/', $val['type'])) { + require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'; + require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php'; + $formother = new FormOther($db); + + $tmp = explode(':', $val['type']); + print img_picto('', 'category', 'class="pictofixedwidth"'); + print $formother->select_categories('customer', $conf->global->{$constname}, $constname, 0, $langs->trans('CustomersProspectsCategoriesShort')); + + } else { + print ''; + } + print '
'; From 5c8e7b224f3994223a7b576c3502920d47d8ecfa Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Sun, 14 Feb 2021 16:44:42 +0100 Subject: [PATCH 2/3] add feature to setup pages --- htdocs/modulebuilder/template/admin/setup.php | 69 ++++++++++++++----- 1 file changed, 52 insertions(+), 17 deletions(-) diff --git a/htdocs/modulebuilder/template/admin/setup.php b/htdocs/modulebuilder/template/admin/setup.php index 72239ff3d1b..a204436eabf 100644 --- a/htdocs/modulebuilder/template/admin/setup.php +++ b/htdocs/modulebuilder/template/admin/setup.php @@ -216,14 +216,14 @@ if ($action == 'edit') { $setupnotempty++; print ''; $tooltiphelp = (($langs->trans($constname . 'Tooltip') != $constname . 'Tooltip') ? $langs->trans($constname . 'Tooltip') : ''); - print '' . $form->textwithpicto($langs->trans($constname), $tooltiphelp, 1, 'info', '', 0, 3, 'tootips' . $constname) . ''; + print ''.$form->textwithpicto($langs->trans($constname), $tooltiphelp,1,'info','',0,3,'tootips'.$constname).''; print ''; if ($val['type'] == 'textarea') { - print '\n"; - } elseif ($val['type'] == 'html') { + } elseif ($val['type']== 'html') { require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php'; $doleditor = new DolEditor($constname, $conf->global->{$constname}, '', 160, 'dolibarr_notes', '', false, false, $conf->fckeditor->enabled, ROWS_5, '90%'); $doleditor->Create(); @@ -234,8 +234,7 @@ if ($action == 'edit') { $formmail = new FormMail($db); $tmp = explode(':', $val['type']); - - $nboftemplates = $formmail->fetchAllEMailTemplate($tmp[1], $user, null, -1); // We set lang=null to get in priority record with no lang + $nboftemplates = $formmail->fetchAllEMailTemplate($tmp[1], $user, null, 1); // We set lang=null to get in priority record with no lang //$arraydefaultmessage = $formmail->getEMailTemplate($db, $tmp[1], $user, null, 0, 1, ''); $arrayofmessagename = array(); if (is_array($formmail->lines_model)) { @@ -246,21 +245,22 @@ if ($action == 'edit') { $moreonlabel = ' (' . $langs->trans("SeveralLangugeVariatFound") . ')'; } // The 'label' is the key that is unique if we exclude the language - $arrayofmessagename[$modelmail->label . ':' . $tmp[1]] = $langs->trans(preg_replace('/\(|\)/', '', $modelmail->label)) . $moreonlabel; + $arrayofmessagename[$modelmail->id] = $langs->trans(preg_replace('/\(|\)/', '', $modelmail->label)) . $moreonlabel; } } print $form->selectarray($constname, $arrayofmessagename, $conf->global->{$constname}, 'None', 0, 0, '', 0, 0, 0, '', '', 1); } elseif (preg_match('/category:/', $val['type'])) { - require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'; - require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php'; + require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; + require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; $formother = new FormOther($db); $tmp = explode(':', $val['type']); print img_picto('', 'category', 'class="pictofixedwidth"'); - print $formother->select_categories('customer', $conf->global->{$constname}, $constname, 0, $langs->trans('CustomersProspectsCategoriesShort')); + print $formother->select_categories($tmp[1], $conf->global->{$constname}, $constname, 0, $langs->trans('CustomersProspectsCategoriesShort')); - } else { - print ''; + } else + { + print ''; } print ''; } @@ -278,13 +278,48 @@ if ($action == 'edit') { print ''; print ''; - foreach ($arrayofparameters as $key => $val) { - $setupnotempty++; + foreach ($arrayofparameters as $constname => $val) { + if ($val['enabled']==1) { + $setupnotempty++; + print ''; + if ($val['type'] == 'textarea') { + print dol_nl2br($conf->global->{$constname}); + } elseif ($val['type']== 'html') { + print $conf->global->{$constname}; + } elseif ($val['type'] == 'yesno') { + print ajax_constantonoff($constname); + } elseif (preg_match('/emailtemplate:/', $val['type'])) { + include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php'; + $formmail = new FormMail($db); + + $tmp = explode(':', $val['type']); + + $template = $formmail->getEMailTemplate($db, $tmp[1], $user, $langs, $conf->global->{$constname}); + if ($template<0) { + setEventMessages(null, $formmail->errors, 'errors'); + } + print $langs->trans($template->label); + } elseif (preg_match('/category:/', $val['type'])) { + $c = new Categorie($db); + $result = $c->fetch($conf->global->{$constname}); + if ($result < 0) { + setEventMessages(null, $c->errors, 'errors'); + } + $ways = $c->print_all_ways(' >> ', 'none', 0, 1); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formated text + $toprint = array(); + foreach ($ways as $way) { + $toprint[] = '
  • color ? ' style="background: #' . $c->color . ';"' : ' style="background: #bbb"') . '>' . $way . '
  • '; + } + print '
      ' . implode(' ', $toprint) . '
    '; + } else { + print $conf->global->{$constname}; + } + print ''; + } } print '
    '.$langs->trans("Parameter").''.$langs->trans("Value").'
    '; + $tooltiphelp = (($langs->trans($constname . 'Tooltip') != $constname . 'Tooltip') ? $langs->trans($constname . 'Tooltip') : ''); + print $form->textwithpicto($langs->trans($constname), $tooltiphelp); + print ''; - print '
    '; - $tooltiphelp = (($langs->trans($key.'Tooltip') != $key.'Tooltip') ? $langs->trans($key.'Tooltip') : ''); - print $form->textwithpicto($langs->trans($key), $tooltiphelp); - print ''.$conf->global->$key.'
    '; From d636aa6cfa9b4ba51a61914d4e5b126e66cd800d Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Sun, 14 Feb 2021 15:48:44 +0000 Subject: [PATCH 3/3] Fixing style errors. --- htdocs/modulebuilder/template/admin/setup.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/htdocs/modulebuilder/template/admin/setup.php b/htdocs/modulebuilder/template/admin/setup.php index a204436eabf..93bbc8a6612 100644 --- a/htdocs/modulebuilder/template/admin/setup.php +++ b/htdocs/modulebuilder/template/admin/setup.php @@ -216,7 +216,7 @@ if ($action == 'edit') { $setupnotempty++; print ''; $tooltiphelp = (($langs->trans($constname . 'Tooltip') != $constname . 'Tooltip') ? $langs->trans($constname . 'Tooltip') : ''); - print ''.$form->textwithpicto($langs->trans($constname), $tooltiphelp,1,'info','',0,3,'tootips'.$constname).''; + print ''.$form->textwithpicto($langs->trans($constname), $tooltiphelp, 1, 'info', '', 0, 3, 'tootips'.$constname).''; print ''; if ($val['type'] == 'textarea') { @@ -257,9 +257,7 @@ if ($action == 'edit') { $tmp = explode(':', $val['type']); print img_picto('', 'category', 'class="pictofixedwidth"'); print $formother->select_categories($tmp[1], $conf->global->{$constname}, $constname, 0, $langs->trans('CustomersProspectsCategoriesShort')); - - } else - { + } else { print ''; } print '';