diff --git a/htdocs/admin/supplier_invoice.php b/htdocs/admin/supplier_invoice.php
index 8df357df07e..86faa655687 100644
--- a/htdocs/admin/supplier_invoice.php
+++ b/htdocs/admin/supplier_invoice.php
@@ -146,8 +146,7 @@ elseif ($action == 'setdoc')
{
$ret = addDocumentModel($value, $type, $label, $scandir);
}
-} elseif ($action == 'unsetdoc')
-{
+} elseif ($action == 'unsetdoc') {
dolibarr_del_const($db, "INVOICE_SUPPLIER_ADDON_PDF", $conf->entity);
}
diff --git a/htdocs/core/actions_addupdatedelete.inc.php b/htdocs/core/actions_addupdatedelete.inc.php
index 80f16cb037d..5a93a6ded0b 100644
--- a/htdocs/core/actions_addupdatedelete.inc.php
+++ b/htdocs/core/actions_addupdatedelete.inc.php
@@ -315,11 +315,15 @@ if ($action == 'confirm_validate' && $confirm == 'yes' && $permissiontoadd)
$outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
- $model = $object->model_pdf;
$ret = $object->fetch($id); // Reload to get new records
- $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
+ $model = $object->model_pdf;
+
+ $retgen = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
+ if ($retgen < 0) {
+ setEventMessages($object->error, $object->errors, 'warnings');
+ }
}
}
} else {
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index ef1bd4eb7b7..dec15e4db83 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -4557,6 +4557,11 @@ abstract class CommonObject
{
dol_syslog("commonGenerateDocument modele=".$modele." outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang : 'null'));
+ if (empty($modele)) {
+ $this->error = 'BadValueForParameterModele';
+ return -1;
+ }
+
// Increase limit for PDF build
$err = error_reporting();
error_reporting(0);
diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang
index 23b3b5462c9..b0a302fb80e 100644
--- a/htdocs/langs/en_US/admin.lang
+++ b/htdocs/langs/en_US/admin.lang
@@ -375,7 +375,7 @@ ExamplesWithCurrentSetup=Examples with current configuration
ListOfDirectories=List of OpenDocument templates directories
ListOfDirectoriesForModelGenODT=List of directories containing templates files with OpenDocument format.
Put here full path of directories.
Add a carriage return between eah directory.
To add a directory of the GED module, add here DOL_DATA_ROOT/ecm/yourdirectoryname.
Files in those directories must end with .odt or .ods.
NumberOfModelFilesFound=Number of ODT/ODS template files found in these directories
-ExampleOfDirectoriesForModelGen=Examples of syntax:
c:\\mydir
/home/mydir
DOL_DATA_ROOT/ecm/ecmdir
+ExampleOfDirectoriesForModelGen=Examples of syntax:
c:\\myapp\\mydocumentdir\\mysubdir
/home/myapp/mydocumentdir/mysubdir
DOL_DATA_ROOT/ecm/ecmdir
FollowingSubstitutionKeysCanBeUsed=
To know how to create your odt document templates, before storing them in those directories, read wiki documentation:
FullListOnOnlineDocumentation=http://wiki.dolibarr.org/index.php/Create_an_ODT_document_template
FirstnameNamePosition=Position of Name/Lastname
diff --git a/htdocs/modulebuilder/template/admin/setup.php b/htdocs/modulebuilder/template/admin/setup.php
index 420eb13940d..c7cc61171a7 100644
--- a/htdocs/modulebuilder/template/admin/setup.php
+++ b/htdocs/modulebuilder/template/admin/setup.php
@@ -54,6 +54,9 @@ $action = GETPOST('action', 'aZ09');
$backtopage = GETPOST('backtopage', 'alpha');
$value = GETPOST('value', 'alpha');
+$label = GETPOST('label', 'alpha');
+$scandir = GETPOST('scan_dir', 'alpha');
+$type = 'myobject';
$arrayofparameters = array(
'MYMODULE_MYPARAM1'=>array('css'=>'minwidth200', 'enabled'=>1),
@@ -130,47 +133,52 @@ if ($action == 'updateMask')
}
}
-// Activate a model
-elseif ($action == 'set')
-{
- $ret = addDocumentModel($value, $type, $label, $scandir);
-} elseif ($action == 'del')
-{
+elseif ($action == 'setmod') {
+ // TODO Check if numbering module chosen can be activated by calling method canBeActivated
$tmpobjectkey = GETPOST('object');
-
- $ret = delDocumentModel($value, $type);
- if ($ret > 0)
- {
- $constforval = strtoupper($tmpobjectkey).'_ADDON_PDF';
- if ($conf->global->$constforval == "$value") dolibarr_del_const($db, $constforval, $conf->entity);
+ if (!empty($tmpobjectkey)) {
+ $constforval = 'MYMODULE_'.strtoupper($tmpobjectkey)."_ADDON";
+ dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity);
}
}
-// Set default model
-elseif ($action == 'setdoc')
-{
- $tmpobjectkey = GETPOST('object');
- $constforval = strtoupper($tmpobjectkey).'_ADDON_PDF';
- if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity))
- {
- // The constant that was read before the new set
- // We therefore requires a variable to have a coherent view
- $conf->global->$constforval = $value;
- }
-
- // On active le modele
+// Activate a model
+elseif ($action == 'set') {
+ $ret = addDocumentModel($value, $type, $label, $scandir);
+} elseif ($action == 'del') {
$ret = delDocumentModel($value, $type);
- if ($ret > 0)
- {
- $ret = addDocumentModel($value, $type, $label, $scandir);
+ if ($ret > 0) {
+ $tmpobjectkey = GETPOST('object');
+ if (!empty($tmpobjectkey)) {
+ $constforval = 'MYMODULE_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
+ if ($conf->global->$constforval == "$value") dolibarr_del_const($db, $constforval, $conf->entity);
+ }
}
-} elseif ($action == 'setmod')
-{
- // TODO Check if numbering module chosen can be activated
- // by calling method canBeActivated
+}
+
+// Set or unset default model
+elseif ($action == 'setdoc') {
$tmpobjectkey = GETPOST('object');
- $constforval = 'MYMODULE_'.strtoupper($tmpobjectkey)."_ADDON";
- dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity);
+ if (!empty($tmpobjectkey)) {
+ $constforval = 'MYMODULE_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
+ if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity)) {
+ // The constant that was read before the new set
+ // We therefore requires a variable to have a coherent view
+ $conf->global->$constforval = $value;
+ }
+
+ // We disable/enable the document template (into llx_document_model table)
+ $ret = delDocumentModel($value, $type);
+ if ($ret > 0) {
+ $ret = addDocumentModel($value, $type, $label, $scandir);
+ }
+ }
+} elseif ($action == 'unsetdoc') {
+ $tmpobjectkey = GETPOST('object');
+ if (!empty($tmpobjectkey)) {
+ $constforval = 'MYMODULE_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
+ dolibarr_del_const($db, $constforval, $conf->entity);
+ }
}
@@ -459,18 +467,19 @@ foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
print '';
} else {
print '
'."\n";
- print 'scandir.'&label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"), 'switch_off').'';
+ print 'scandir).'&label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"), 'switch_off').'';
print " | ";
}
// Default
print '';
$constforvar = 'MYMODULE_'.strtoupper($myTmpObjectKey).'_ADDON';
- if ($conf->global->$constforvar == $name)
- {
- print img_picto($langs->trans("Default"), 'on');
+ if ($conf->global->$constforvar == $name) {
+ //print img_picto($langs->trans("Default"), 'on');
+ // Even if choice is the default value, we allow to disable it. Replace this with previous line if you need to disable unset
+ print 'scandir.'&label='.urlencode($module->name).'&type='.urlencode($type).'" alt="'.$langs->trans("Disable").'">'.img_picto($langs->trans("Enabled"), 'on').'';
} else {
- print 'scandir.'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'';
+ print 'scandir).'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'';
}
print ' | ';
diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php
index 76aeabf2c2b..a8bed45c46a 100644
--- a/htdocs/modulebuilder/template/class/myobject.class.php
+++ b/htdocs/modulebuilder/template/class/myobject.class.php
@@ -1028,7 +1028,7 @@ class MyObject extends CommonObject
if (!dol_strlen($modele)) {
$modele = 'standard_myobject';
- if ($this->model_pdf) {
+ if (!empty($this->model_pdf)) {
$modele = $this->model_pdf;
} elseif (!empty($conf->global->MYOBJECT_ADDON_PDF)) {
$modele = $conf->global->MYOBJECT_ADDON_PDF;
@@ -1037,7 +1037,7 @@ class MyObject extends CommonObject
$modelpath = "core/modules/mymodule/doc/";
- if ($includedocgeneration) {
+ if ($includedocgeneration && !empty($modele)) {
$result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
}
diff --git a/htdocs/recruitment/admin/setup.php b/htdocs/recruitment/admin/setup.php
index fdd4d83e223..342d32840c5 100644
--- a/htdocs/recruitment/admin/setup.php
+++ b/htdocs/recruitment/admin/setup.php
@@ -54,6 +54,9 @@ $action = GETPOST('action', 'aZ09');
$backtopage = GETPOST('backtopage', 'alpha');
$value = GETPOST('value', 'alpha');
+$label = GETPOST('label', 'alpha');
+$scandir = GETPOST('scan_dir', 'alpha');
+$type = 'recruitmentjobposition';
$arrayofparameters = array(
// 'RECRUITMENT_MYPARAM1'=>array('css'=>'minwidth200', 'enabled'=>1),
@@ -131,47 +134,52 @@ if ($action == 'updateMask')
}
// Activate a model
-elseif ($action == 'set')
-{
+elseif ($action == 'set') {
$ret = addDocumentModel($value, $type, $label, $scandir);
-} elseif ($action == 'del')
-{
- $tmpobjectkey = GETPOST('object');
-
+} elseif ($action == 'del') {
$ret = delDocumentModel($value, $type);
- if ($ret > 0)
- {
- $constforval = strtoupper($tmpobjectkey).'_ADDON_PDF';
- if ($conf->global->$constforval == "$value") dolibarr_del_const($db, $constforval, $conf->entity);
+ if ($ret > 0) {
+ $tmpobjectkey = GETPOST('object');
+ if (!empty($tmpobjectkey)) {
+ $constforval = 'RECRUITMENT_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
+ if ($conf->global->$constforval == "$value") dolibarr_del_const($db, $constforval, $conf->entity);
+ }
+ }
+}
+
+elseif ($action == 'setmod') {
+ // TODO Check if numbering module chosen can be activated by calling method canBeActivated
+ $tmpobjectkey = GETPOST('object');
+ if (!empty($tmpobjectkey)) {
+ $constforval = 'RECRUITMENT_'.strtoupper($tmpobjectkey)."_ADDON";
+
+ dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity);
}
}
// Set default model
-elseif ($action == 'setdoc')
-{
+elseif ($action == 'setdoc') {
$tmpobjectkey = GETPOST('object');
- $constforval = strtoupper($tmpobjectkey).'_ADDON_PDF';
- if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity))
- {
- // The constant that was read before the new set
- // We therefore requires a variable to have a coherent view
- $conf->global->$constforval = $value;
- }
+ if (!empty($tmpobjectkey)) {
+ $constforval = 'RECRUITMENT_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
+ if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity)) {
+ // The constant that was read before the new set
+ // We therefore requires a variable to have a coherent view
+ $conf->global->$constforval = $value;
+ }
- // On active le modele
- $ret = delDocumentModel($value, $type);
- if ($ret > 0)
- {
- $ret = addDocumentModel($value, $type, $label, $scandir);
+ // We disable/enable the document template (into llx_document_model table)
+ $ret = delDocumentModel($value, $type);
+ if ($ret > 0) {
+ $ret = addDocumentModel($value, $type, $label, $scandir);
+ }
}
-} elseif ($action == 'setmod')
-{
- // TODO Check if numbering module chosen can be activated
- // by calling method canBeActivated
+} elseif ($action == 'unsetdoc') {
$tmpobjectkey = GETPOST('object');
- $constforval = 'RECRUITMENT_'.strtoupper($tmpobjectkey)."_ADDON";
-
- dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity);
+ if (!empty($tmpobjectkey)) {
+ $constforval = 'RECRUITMENT_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
+ dolibarr_del_const($db, $constforval, $conf->entity);
+ }
}
@@ -288,7 +296,6 @@ foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
if (strpos($file, 'mod_'.strtolower($myTmpObjectKey).'_') === 0 && substr($file, dol_strlen($file) - 3, 3) == 'php')
{
$file = substr($file, 0, dol_strlen($file) - 4);
-
require_once $dir.'/'.$file.'.php';
$module = new $file($db);
@@ -377,8 +384,7 @@ foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
$sql .= " WHERE type = '".$db->escape($type)."'";
$sql .= " AND entity = ".$conf->entity;
$resql = $db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$i = 0;
$num_rows = $db->num_rows($resql);
while ($i < $num_rows)
@@ -464,12 +470,13 @@ foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
// Default
print '';
- $constforvar = 'RECRUITMENT_'.strtoupper($myTmpObjectKey).'_ADDON';
- if ($conf->global->$constforvar == $name)
- {
- print img_picto($langs->trans("Default"), 'on');
+ $constforvar = 'RECRUITMENT_'.strtoupper($myTmpObjectKey).'_ADDON_PDF';
+ if ($conf->global->$constforvar == $name) {
+ //print img_picto($langs->trans("Default"), 'on');
+ // Even if choice is the default value, we allow to disable it. Replace this with previous line if you need to disable unset
+ print 'scandir.'&label='.urlencode($module->name).'&type='.urlencode($type).'" alt="'.$langs->trans("Disable").'">'.img_picto($langs->trans("Enabled"), 'on').'';
} else {
- print 'scandir.'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'';
+ print 'scandir).'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'';
}
print ' | ';
diff --git a/htdocs/recruitment/admin/setup_candidatures.php b/htdocs/recruitment/admin/setup_candidatures.php
index ef4454974e7..818e1479f0a 100644
--- a/htdocs/recruitment/admin/setup_candidatures.php
+++ b/htdocs/recruitment/admin/setup_candidatures.php
@@ -54,6 +54,9 @@ $action = GETPOST('action', 'aZ09');
$backtopage = GETPOST('backtopage', 'alpha');
$value = GETPOST('value', 'alpha');
+$label = GETPOST('label', 'alpha');
+$scandir = GETPOST('scan_dir', 'alpha');
+$type = 'recruitmentcandidature';
$arrayofparameters = array(
// 'RECRUITMENT_MYPARAM1'=>array('css'=>'minwidth200', 'enabled'=>1),
@@ -131,47 +134,49 @@ if ($action == 'updateMask')
}
// Activate a model
-elseif ($action == 'set')
-{
+elseif ($action == 'set') {
$ret = addDocumentModel($value, $type, $label, $scandir);
-} elseif ($action == 'del')
-{
+} elseif ($action == 'del') {
$tmpobjectkey = GETPOST('object');
$ret = delDocumentModel($value, $type);
- if ($ret > 0)
- {
- $constforval = strtoupper($tmpobjectkey).'_ADDON_PDF';
+ if ($ret > 0) {
+ $constforval = 'RECRUITMENT_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
if ($conf->global->$constforval == "$value") dolibarr_del_const($db, $constforval, $conf->entity);
}
}
-// Set default model
-elseif ($action == 'setdoc')
-{
+elseif ($action == 'setmod') {
+ // TODO Check if numbering module chosen can be activated by calling method canBeActivated
$tmpobjectkey = GETPOST('object');
- $constforval = strtoupper($tmpobjectkey).'_ADDON_PDF';
- if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity))
- {
+ if (!empty($tmpobjectkey)) {
+ $constforval = 'RECRUITMENT_'.strtoupper($tmpobjectkey)."_ADDON";
+
+ dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity);
+ }
+}
+
+// Set default model
+elseif ($action == 'setdoc') {
+ $tmpobjectkey = GETPOST('object');
+ $constforval = 'RECRUITMENT_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
+ if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity)) {
// The constant that was read before the new set
// We therefore requires a variable to have a coherent view
$conf->global->$constforval = $value;
}
- // On active le modele
+ // We disable/enable the document template (into llx_document_model table)
$ret = delDocumentModel($value, $type);
- if ($ret > 0)
- {
+ if ($ret > 0) {
$ret = addDocumentModel($value, $type, $label, $scandir);
}
-} elseif ($action == 'setmod')
-{
- // TODO Check if numbering module chosen can be activated
- // by calling method canBeActivated
+} elseif ($action == 'unsetdoc') {
$tmpobjectkey = GETPOST('object');
- $constforval = 'RECRUITMENT_'.strtoupper($tmpobjectkey)."_ADDON";
-
- dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity);
+ if (!empty($tmpobjectkey)) {
+ $constforval = 'RECRUITMENT_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
+ dolibarr_del_const($db, $constforval, $conf->entity);
+ }
}
@@ -465,11 +470,12 @@ foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
// Default
print '';
$constforvar = 'RECRUITMENT_'.strtoupper($myTmpObjectKey).'_ADDON';
- if ($conf->global->$constforvar == $name)
- {
- print img_picto($langs->trans("Default"), 'on');
+ if ($conf->global->$constforvar == $name) {
+ //print img_picto($langs->trans("Default"), 'on');
+ // Even if choice is the default value, we allow to disable it. Replace this with previous line if you need to disable unset
+ print 'scandir.'&label='.urlencode($module->name).'&type='.urlencode($type).'" alt="'.$langs->trans("Disable").'">'.img_picto($langs->trans("Enabled"), 'on').'';
} else {
- print 'scandir.'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'';
+ print 'scandir).'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'';
}
print ' | ';
diff --git a/htdocs/recruitment/class/recruitmentcandidature.class.php b/htdocs/recruitment/class/recruitmentcandidature.class.php
index 5dad53212c6..3049f83a053 100644
--- a/htdocs/recruitment/class/recruitmentcandidature.class.php
+++ b/htdocs/recruitment/class/recruitmentcandidature.class.php
@@ -982,7 +982,7 @@ class RecruitmentCandidature extends CommonObject
$modelpath = "core/modules/recruitment/doc/";
- if ($includedocgeneration) {
+ if ($includedocgeneration && !empty($modele)) {
$result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
}
diff --git a/htdocs/recruitment/class/recruitmentjobposition.class.php b/htdocs/recruitment/class/recruitmentjobposition.class.php
index 2421f87ce50..c202a523e58 100644
--- a/htdocs/recruitment/class/recruitmentjobposition.class.php
+++ b/htdocs/recruitment/class/recruitmentjobposition.class.php
@@ -1059,8 +1059,7 @@ class RecruitmentJobPosition extends CommonObject
$langs->load("recruitment");
if (!dol_strlen($modele)) {
- if (!empty($conf->global->RECRUITMENTJOBPOSITION_ADDON_PDF))
- {
+ if (!empty($conf->global->RECRUITMENTJOBPOSITION_ADDON_PDF)) {
$modele = $conf->global->RECRUITMENTJOBPOSITION_ADDON_PDF;
} else {
$modele = ''; // No default value. For job position, we allow to disable all PDF generation
@@ -1069,7 +1068,7 @@ class RecruitmentJobPosition extends CommonObject
$modelpath = "core/modules/recruitment/doc/";
- if ($includedocgeneration) {
+ if ($includedocgeneration && !empty($modele)) {
$result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
}
diff --git a/htdocs/recruitment/core/modules/recruitment/doc/doc_generic_recruitmentjobposition_odt.modules.php b/htdocs/recruitment/core/modules/recruitment/doc/doc_generic_recruitmentjobposition_odt.modules.php
index be36b96682c..59ea51466b6 100644
--- a/htdocs/recruitment/core/modules/recruitment/doc/doc_generic_recruitmentjobposition_odt.modules.php
+++ b/htdocs/recruitment/core/modules/recruitment/doc/doc_generic_recruitmentjobposition_odt.modules.php
@@ -181,7 +181,7 @@ class doc_generic_recruitmentjobposition_odt extends ModelePDFRecruitmentJobPosi
$texte .= '';
$texte .= '';
- $texte .= $langs->trans("ExampleOfDirectoriesForModelGen");
+ $texte .= ''.$langs->trans("ExampleOfDirectoriesForModelGen").'';
$texte .= ' | ';
$texte .= '';