From 28269b1a0aa874cc22caec468b1b1cad0301d2ab Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 15 Mar 2024 20:26:22 +0100 Subject: [PATCH] Clean code for #28785 --- htdocs/admin/eventorganization.php | 35 -- htdocs/admin/hrm.php | 58 ++-- htdocs/admin/knowledgemanagement.php | 57 ++-- htdocs/admin/webhook.php | 298 ------------------ htdocs/admin/workstation.php | 60 ++-- htdocs/ai/admin/setup.php | 35 -- htdocs/asset/admin/setup.php | 58 ++-- htdocs/bookcal/admin/setup.php | 35 -- htdocs/cron/class/cronjob.class.php | 2 +- htdocs/don/admin/donation.php | 2 +- htdocs/modulebuilder/template/admin/setup.php | 65 ++-- 11 files changed, 159 insertions(+), 546 deletions(-) diff --git a/htdocs/admin/eventorganization.php b/htdocs/admin/eventorganization.php index 983a93a9c02..f6e6361fa34 100644 --- a/htdocs/admin/eventorganization.php +++ b/htdocs/admin/eventorganization.php @@ -102,41 +102,6 @@ if ($action == 'updateMask') { } else { setEventMessages($langs->trans("Error"), null, 'errors'); } -} elseif ($action == 'specimen') { - $modele = GETPOST('module', 'alpha'); - $tmpobjectkey = GETPOST('object'); - - $tmpobject = new $tmpobjectkey($db); - $tmpobject->initAsSpecimen(); - - // Search template files - $file = ''; - $classname = ''; - $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); - foreach ($dirmodels as $reldir) { - $file = dol_buildpath($reldir."core/modules/eventorganization/doc/pdf_".$modele."_".strtolower($tmpobjectkey).".modules.php", 0); - if (file_exists($file)) { - $classname = "pdf_".$modele; - break; - } - } - - if ($classname !== '') { - require_once $file; - - $module = new $classname($db); - - if ($module->write_file($tmpobject, $langs) > 0) { - header("Location: ".DOL_URL_ROOT."/document.php?modulepart=".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf"); - return; - } else { - setEventMessages($module->error, null, 'errors'); - dol_syslog($module->error, LOG_ERR); - } - } else { - setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors'); - dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR); - } } elseif ($action == 'setmod') { // TODO Check if numbering module chosen can be activated by calling method canBeActivated $tmpobjectkey = GETPOST('object'); diff --git a/htdocs/admin/hrm.php b/htdocs/admin/hrm.php index df883799b2b..c057181dd25 100644 --- a/htdocs/admin/hrm.php +++ b/htdocs/admin/hrm.php @@ -66,6 +66,11 @@ $setupnotempty = 0; $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); +$moduledir = 'hrm'; +$myTmpObjects = array(); +// TODO Scan list of objects to fill this array +$myTmpObjects['evaluation'] = array('label' => 'Evaluation', 'includerefgeneration' => 1, 'includedocgeneration' => 0); + /* * Actions @@ -109,38 +114,40 @@ if ($action == 'update') { } } elseif ($action == 'specimen') { $modele = GETPOST('module', 'alpha'); - $tmpobjectkey = GETPOST('object'); + $tmpobjectkey = GETPOST('object', 'aZ09'); - $tmpobject = new $tmpobjectkey($db); - $tmpobject->initAsSpecimen(); + if (in_array($tmpobjectkey, $myTmpObjects)) { + $tmpobject = new $tmpobjectkey($db); + $tmpobject->initAsSpecimen(); - // Search template files - $file = ''; - $classname = ''; - $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); - foreach ($dirmodels as $reldir) { - $file = dol_buildpath($reldir."core/modules/hrm/doc/pdf_".$modele."_".strtolower($tmpobjectkey).".modules.php", 0); - if (file_exists($file)) { - $classname = "pdf_".$modele; - break; + // Search template files + $file = ''; + $classname = ''; + $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); + foreach ($dirmodels as $reldir) { + $file = dol_buildpath($reldir."core/modules/hrm/doc/pdf_".$modele."_".strtolower($tmpobjectkey).".modules.php", 0); + if (file_exists($file)) { + $classname = "pdf_".$modele; + break; + } } - } - if ($classname !== '') { - require_once $file; + if ($classname !== '') { + require_once $file; - $module = new $classname($db); + $module = new $classname($db); - if ($module->write_file($tmpobject, $langs) > 0) { - header("Location: ".DOL_URL_ROOT."/document.php?modulepart=".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf"); - return; + if ($module->write_file($tmpobject, $langs) > 0) { + header("Location: ".DOL_URL_ROOT."/document.php?modulepart=".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf"); + return; + } else { + setEventMessages($module->error, null, 'errors'); + dol_syslog($module->error, LOG_ERR); + } } else { - setEventMessages($module->error, null, 'errors'); - dol_syslog($module->error, LOG_ERR); + setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors'); + dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR); } - } else { - setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors'); - dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR); } } elseif ($action == 'setmod') { // TODO Check if numbering module chosen can be activated by calling method canBeActivated @@ -209,9 +216,6 @@ print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup'); $head = hrmAdminPrepareHead(); print dol_get_fiche_head($head, 'settings', $langs->trans($page_name), -1, "hrm"); -$moduledir = 'hrm'; -$myTmpObjects = array(); -$myTmpObjects['evaluation'] = array('label' => 'Evaluation', 'includerefgeneration' => 1, 'includedocgeneration' => 0); foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) { if ($myTmpObjectKey != $type) { diff --git a/htdocs/admin/knowledgemanagement.php b/htdocs/admin/knowledgemanagement.php index 1f79f506c89..c3b7a4be39c 100644 --- a/htdocs/admin/knowledgemanagement.php +++ b/htdocs/admin/knowledgemanagement.php @@ -46,7 +46,7 @@ $scandir = GETPOST('scan_dir', 'alpha'); $type = 'knowledgemanagement'; $arrayofparameters = array( - 'KNOWLEDGEMANAGEMENT_MYPARAM1' => array('type' => 'string', 'css' => 'minwidth500' ,'enabled' => 0), + //'KNOWLEDGEMANAGEMENT_MYPARAM1' => array('type' => 'string', 'css' => 'minwidth500' ,'enabled' => 0), //'KNOWLEDGEMANAGEMENT_MYPARAM2'=>array('type'=>'textarea','enabled'=>1), //'KNOWLEDGEMANAGEMENT_MYPARAM3'=>array('type'=>'category:'.Categorie::TYPE_CUSTOMER, 'enabled'=>1), //'KNOWLEDGEMANAGEMENT_MYPARAM4'=>array('type'=>'emailtemplate:thirdparty', 'enabled'=>1), @@ -62,6 +62,11 @@ if (!$user->admin) { accessforbidden(); } +$moduledir = 'knowledgemanagement'; +$myTmpObjects = array(); +// TODO Scan list of objects to fill this array +$myTmpObjects['knowledgemanagement'] = array('label'=>'KnowledgeManagement', 'includerefgeneration'=>0, 'includedocgeneration'=>0, 'class'=>'KnowledgeManagement'); + /* * Actions @@ -87,38 +92,40 @@ if ($action == 'updateMask') { } } elseif ($action == 'specimen') { $modele = GETPOST('module', 'alpha'); - $tmpobjectkey = GETPOST('object'); + $tmpobjectkey = GETPOST('object', 'aZ09'); - $tmpobject = new $tmpobjectkey($db); - $tmpobject->initAsSpecimen(); + if (in_array($tmpobjectkey, $myTmpObjects)) { + $tmpobject = new $tmpobjectkey($db); + $tmpobject->initAsSpecimen(); - // Search template files - $file = ''; - $classname = ''; - $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); - foreach ($dirmodels as $reldir) { - $file = dol_buildpath($reldir."core/modules/knowledgemanagement/doc/pdf_".$modele."_".strtolower($tmpobjectkey).".modules.php", 0); - if (file_exists($file)) { - $classname = "pdf_".$modele; - break; + // Search template files + $file = ''; + $classname = ''; + $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); + foreach ($dirmodels as $reldir) { + $file = dol_buildpath($reldir."core/modules/knowledgemanagement/doc/pdf_".$modele."_".strtolower($tmpobjectkey).".modules.php", 0); + if (file_exists($file)) { + $classname = "pdf_".$modele; + break; + } } - } - if ($classname !== '') { - require_once $file; + if ($classname !== '') { + require_once $file; - $module = new $classname($db); + $module = new $classname($db); - if ($module->write_file($tmpobject, $langs) > 0) { - header("Location: ".DOL_URL_ROOT."/document.php?modulepart=".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf"); - return; + if ($module->write_file($tmpobject, $langs) > 0) { + header("Location: ".DOL_URL_ROOT."/document.php?modulepart=".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf"); + return; + } else { + setEventMessages($module->error, null, 'errors'); + dol_syslog($module->error, LOG_ERR); + } } else { - setEventMessages($module->error, null, 'errors'); - dol_syslog($module->error, LOG_ERR); + setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors'); + dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR); } - } else { - setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors'); - dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR); } } elseif ($action == 'setmod') { // TODO Check if numbering module chosen can be activated by calling method canBeActivated diff --git a/htdocs/admin/webhook.php b/htdocs/admin/webhook.php index 4758220503d..879c17af00d 100644 --- a/htdocs/admin/webhook.php +++ b/htdocs/admin/webhook.php @@ -90,41 +90,6 @@ if ($action == 'updateMask') { } else { setEventMessages($langs->trans("Error"), null, 'errors'); } -} elseif ($action == 'specimen') { - $modele = GETPOST('module', 'alpha'); - $tmpobjectkey = GETPOST('object'); - - $tmpobject = new $tmpobjectkey($db); - $tmpobject->initAsSpecimen(); - - // Search template files - $file = ''; - $classname = ''; - $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); - foreach ($dirmodels as $reldir) { - $file = dol_buildpath($reldir."core/modules/webhook/doc/pdf_".$modele."_".strtolower($tmpobjectkey).".modules.php", 0); - if (file_exists($file)) { - $classname = "pdf_".$modele."_".strtolower($tmpobjectkey); - break; - } - } - - if ($classname !== '') { - require_once $file; - - $module = new $classname($db); - - if ($module->write_file($tmpobject, $langs) > 0) { - header("Location: ".DOL_URL_ROOT."/document.php?modulepart=webhook-".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf"); - return; - } else { - setEventMessages($module->error, null, 'errors'); - dol_syslog($module->error, LOG_ERR); - } - } else { - setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors'); - dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR); - } } elseif ($action == 'setmod') { // TODO Check if numbering module chosen can be activated by calling method canBeActivated $tmpobjectkey = GETPOST('object'); @@ -375,269 +340,6 @@ if ($action == 'edit') { } -$moduledir = 'webhook'; -$myTmpObjects = array(); -$myTmpObjects['MyObject'] = array('includerefgeneration' => 0, 'includedocgeneration' => 0); - - -foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) { - if ($myTmpObjectKey == 'MyObject') { - continue; - } - if ($myTmpObjectArray['includerefgeneration']) { - /* - * Orders Numbering model - */ - $setupnotempty++; - - print load_fiche_titre($langs->trans("NumberingModules", $myTmpObjectKey), '', ''); - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''."\n"; - - clearstatcache(); - - foreach ($dirmodels as $reldir) { - $dir = dol_buildpath($reldir."core/modules/".$moduledir); - - if (is_dir($dir)) { - $handle = opendir($dir); - if (is_resource($handle)) { - while (($file = readdir($handle)) !== false) { - 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); - - // Show modules according to features level - if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) { - continue; - } - if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) { - continue; - } - - if ($module->isEnabled()) { - dol_include_once('/'.$moduledir.'/class/'.strtolower($myTmpObjectKey).'.class.php'); - - print ''; - - // Show example of numbering model - print ''."\n"; - - print ''; - - $mytmpinstance = new $myTmpObjectKey($db); - $mytmpinstance->initAsSpecimen(); - - // Info - $htmltooltip = ''; - $htmltooltip .= ''.$langs->trans("Version").': '.$module->getVersion().'
'; - - $nextval = $module->getNextValue($mytmpinstance); - if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval - $htmltooltip .= ''.$langs->trans("NextValue").': '; - if ($nextval) { - if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') { - $nextval = $langs->trans($nextval); - } - $htmltooltip .= $nextval.'
'; - } else { - $htmltooltip .= $langs->trans($module->error).'
'; - } - } - - print ''; - - print "\n"; - } - } - } - closedir($handle); - } - } - } - print "
'.$langs->trans("Name").''.$langs->trans("Description").''.$langs->trans("Example").''.$langs->trans("Status").''.$langs->trans("ShortInfo").'
'.$module->name."\n"; - print $module->info($langs); - print ''; - $tmp = $module->getExample(); - if (preg_match('/^Error/', $tmp)) { - $langs->load("errors"); - print '
'.$langs->trans($tmp).'
'; - } elseif ($tmp == 'NotConfigured') { - print $langs->trans($tmp); - } else { - print $tmp; - } - print '
'; - $constforvar = 'WEBHOOK_'.strtoupper($myTmpObjectKey).'_ADDON'; - if (getDolGlobalString($constforvar) == $file) { - print img_picto($langs->trans("Activated"), 'switch_on'); - } else { - print ''; - print img_picto($langs->trans("Disabled"), 'switch_off'); - print ''; - } - print ''; - print $form->textwithpicto('', $htmltooltip, 1, 0); - print '

\n"; - } - - if ($myTmpObjectArray['includedocgeneration']) { - /* - * Document templates generators - */ - $setupnotempty++; - $type = strtolower($myTmpObjectKey); - - print load_fiche_titre($langs->trans("DocumentModules", $myTmpObjectKey), '', ''); - - // Load array def with activated templates - $def = array(); - $sql = "SELECT nom"; - $sql .= " FROM ".MAIN_DB_PREFIX."document_model"; - $sql .= " WHERE type = '".$db->escape($type)."'"; - $sql .= " AND entity = ".$conf->entity; - $resql = $db->query($sql); - if ($resql) { - $i = 0; - $num_rows = $db->num_rows($resql); - while ($i < $num_rows) { - $array = $db->fetch_array($resql); - array_push($def, $array[0]); - $i++; - } - } else { - dol_print_error($db); - } - - print "\n"; - print "\n"; - print ''; - print ''; - print '\n"; - print '\n"; - print ''; - print ''; - print "\n"; - - clearstatcache(); - - foreach ($dirmodels as $reldir) { - foreach (array('', '/doc') as $valdir) { - $realpath = $reldir."core/modules/".$moduledir.$valdir; - $dir = dol_buildpath($realpath); - - if (is_dir($dir)) { - $handle = opendir($dir); - if (is_resource($handle)) { - $filelist = array(); - while (($file = readdir($handle)) !== false) { - $filelist[] = $file; - } - closedir($handle); - arsort($filelist); - - foreach ($filelist as $file) { - if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) { - if (file_exists($dir.'/'.$file)) { - $name = substr($file, 4, dol_strlen($file) - 16); - $classname = substr($file, 0, dol_strlen($file) - 12); - - require_once $dir.'/'.$file; - $module = new $classname($db); - - $modulequalified = 1; - if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) { - $modulequalified = 0; - } - if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) { - $modulequalified = 0; - } - - if ($modulequalified) { - print ''; - - // Active - if (in_array($name, $def)) { - print ''; - } else { - print '"; - } - - // Default - print ''; - - // Info - $htmltooltip = ''.$langs->trans("Name").': '.$module->name; - $htmltooltip .= '
'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown")); - if ($module->type == 'pdf') { - $htmltooltip .= '
'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur; - } - $htmltooltip .= '
'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file; - - $htmltooltip .= '

'.$langs->trans("FeaturesSupported").':'; - $htmltooltip .= '
'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1); - $htmltooltip .= '
'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1); - - print ''; - - // Preview - print ''; - - print "\n"; - } - } - } - } - } - } - } - } - - print '
'.$langs->trans("Name").''.$langs->trans("Description").''.$langs->trans("Status")."'.$langs->trans("Default")."'.$langs->trans("ShortInfo").''.$langs->trans("Preview").'
'; - print(empty($module->name) ? $name : $module->name); - print "\n"; - if (method_exists($module, 'info')) { - print $module->info($langs); - } else { - print $module->description; - } - print ''."\n"; - print ''; - print img_picto($langs->trans("Enabled"), 'switch_on'); - print ''; - print ''."\n"; - print 'scandir).'&label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"), 'switch_off').''; - print "'; - $constforvar = 'WEBHOOK_'.strtoupper($myTmpObjectKey).'_ADDON'; - if (getDolGlobalString($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 ''; - print $form->textwithpicto('', $htmltooltip, 1, 0); - print ''; - if ($module->type == 'pdf') { - print ''.img_object($langs->trans("Preview"), 'pdf').''; - } else { - print img_object($langs->trans("PreviewNotAvailable"), 'generic'); - } - print '
'; - } -} - if (empty($setupnotempty)) { print '
'.$langs->trans("NothingToSetup"); } diff --git a/htdocs/admin/workstation.php b/htdocs/admin/workstation.php index 78084737c6e..78715860e12 100644 --- a/htdocs/admin/workstation.php +++ b/htdocs/admin/workstation.php @@ -51,6 +51,11 @@ if (!$user->admin) { accessforbidden(); } +$moduledir = 'workstation'; +$myTmpObjects = array(); +$myTmpObjects['workstation'] = array('includerefgeneration' => 1, 'includedocgeneration' => 0); + + /* * Actions @@ -77,38 +82,40 @@ if ($action == 'updateMask') { } } elseif ($action == 'specimen') { $modele = GETPOST('module', 'alpha'); - $tmpobjectkey = GETPOST('object'); + $tmpobjectkey = GETPOST('object', 'aZ09'); - $tmpobject = new $tmpobjectkey($db); - $tmpobject->initAsSpecimen(); + if (in_array($tmpobjectkey, $myTmpObjects)) { + $tmpobject = new $tmpobjectkey($db); + $tmpobject->initAsSpecimen(); - // Search template files - $file = ''; - $classname = ''; - $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); - foreach ($dirmodels as $reldir) { - $file = dol_buildpath($reldir."core/modules/workstation/doc/pdf_".$modele."_".strtolower($tmpobjectkey).".modules.php", 0); - if (file_exists($file)) { - $classname = "pdf_".$modele; - break; + // Search template files + $file = ''; + $classname = ''; + $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); + foreach ($dirmodels as $reldir) { + $file = dol_buildpath($reldir."core/modules/workstation/doc/pdf_".$modele."_".strtolower($tmpobjectkey).".modules.php", 0); + if (file_exists($file)) { + $classname = "pdf_".$modele; + break; + } } - } - if ($classname !== '') { - require_once $file; + if ($classname !== '') { + require_once $file; - $module = new $classname($db); + $module = new $classname($db); - if ($module->write_file($tmpobject, $langs) > 0) { - header("Location: ".DOL_URL_ROOT."/document.php?modulepart=".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf"); - return; + if ($module->write_file($tmpobject, $langs) > 0) { + header("Location: ".DOL_URL_ROOT."/document.php?modulepart=".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf"); + return; + } else { + setEventMessages($module->error, null, 'errors'); + dol_syslog($module->error, LOG_ERR); + } } else { - setEventMessages($module->error, null, 'errors'); - dol_syslog($module->error, LOG_ERR); + setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors'); + dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR); } - } else { - setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors'); - dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR); } } elseif ($action == 'set') { // Activate a model @@ -219,11 +226,6 @@ if ($action == 'edit') { } -$moduledir = 'workstation'; -$myTmpObjects = array(); -$myTmpObjects['workstation'] = array('includerefgeneration' => 1, 'includedocgeneration' => 0); - - foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) { if ($myTmpObjectKey == 'MyObject') { continue; diff --git a/htdocs/ai/admin/setup.php b/htdocs/ai/admin/setup.php index 9459b501b84..02ecda6a727 100644 --- a/htdocs/ai/admin/setup.php +++ b/htdocs/ai/admin/setup.php @@ -104,41 +104,6 @@ if ($action == 'updateMask') { } else { setEventMessages($langs->trans("Error"), null, 'errors'); } -} elseif ($action == 'specimen') { - $modele = GETPOST('module', 'alpha'); - $tmpobjectkey = GETPOST('object'); - - $tmpobject = new $tmpobjectkey($db); - $tmpobject->initAsSpecimen(); - - // Search template files - $file = ''; - $classname = ''; - $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); - foreach ($dirmodels as $reldir) { - $file = dol_buildpath($reldir."core/modules/ai/doc/pdf_".$modele."_".strtolower($tmpobjectkey).".modules.php", 0); - if (file_exists($file)) { - $classname = "pdf_".$modele."_".strtolower($tmpobjectkey); - break; - } - } - - if ($classname !== '') { - require_once $file; - - $module = new $classname($db); - - if ($module->write_file($tmpobject, $langs) > 0) { - header("Location: ".DOL_URL_ROOT."/document.php?modulepart=bookcal-".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf"); - return; - } else { - setEventMessages($module->error, null, 'errors'); - dol_syslog($module->error, LOG_ERR); - } - } else { - setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors'); - dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR); - } } elseif ($action == 'setmod') { // TODO Check if numbering module chosen can be activated by calling method canBeActivated $tmpobjectkey = GETPOST('object'); diff --git a/htdocs/asset/admin/setup.php b/htdocs/asset/admin/setup.php index 40e37464e90..0297cce5031 100644 --- a/htdocs/asset/admin/setup.php +++ b/htdocs/asset/admin/setup.php @@ -64,6 +64,10 @@ $setupnotempty = 0; $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); +$moduledir = 'asset'; +$myTmpObjects = array(); +$myTmpObjects['Asset'] = array('includerefgeneration' => 1, 'includedocgeneration' => 0); + /* * Actions @@ -89,38 +93,40 @@ if ($action == 'updateMask') { } } elseif ($action == 'specimen') { $modele = GETPOST('module', 'alpha'); - $tmpobjectkey = GETPOST('object'); + $tmpobjectkey = GETPOST('object', 'aZ09'); - $tmpobject = new $tmpobjectkey($db); - $tmpobject->initAsSpecimen(); + if (in_array($tmpobjectkey, $myTmpObjects)) { + $tmpobject = new $tmpobjectkey($db); + $tmpobject->initAsSpecimen(); - // Search template files - $file = ''; - $classname = ''; - $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); - foreach ($dirmodels as $reldir) { - $file = dol_buildpath($reldir."core/modules/asset/doc/pdf_".$modele."_".strtolower($tmpobjectkey).".modules.php", 0); - if (file_exists($file)) { - $classname = "pdf_".$modele; - break; + // Search template files + $file = ''; + $classname = ''; + $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); + foreach ($dirmodels as $reldir) { + $file = dol_buildpath($reldir."core/modules/asset/doc/pdf_".$modele."_".strtolower($tmpobjectkey).".modules.php", 0); + if (file_exists($file)) { + $classname = "pdf_".$modele; + break; + } } - } - if ($classname !== '') { - require_once $file; + if ($classname !== '') { + require_once $file; - $module = new $classname($db); + $module = new $classname($db); - if ($module->write_file($tmpobject, $langs) > 0) { - header("Location: ".DOL_URL_ROOT."/document.php?modulepart=".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf"); - return; + if ($module->write_file($tmpobject, $langs) > 0) { + header("Location: ".DOL_URL_ROOT."/document.php?modulepart=".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf"); + return; + } else { + setEventMessages($module->error, null, 'errors'); + dol_syslog($module->error, LOG_ERR); + } } else { - setEventMessages($module->error, null, 'errors'); - dol_syslog($module->error, LOG_ERR); + setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors'); + dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR); } - } else { - setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors'); - dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR); } } elseif ($action == 'setmod') { // TODO Check if numbering module chosen can be activated by calling method canBeActivated @@ -194,10 +200,6 @@ print dol_get_fiche_head($head, 'settings', $langs->trans($page_name), -1, "asse echo ''.$langs->trans("AssetSetupPage").''; -$moduledir = 'asset'; -$myTmpObjects = array(); -$myTmpObjects['Asset'] = array('includerefgeneration' => 1, 'includedocgeneration' => 0); - foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) { if ($myTmpObjectKey == 'MyObject') { diff --git a/htdocs/bookcal/admin/setup.php b/htdocs/bookcal/admin/setup.php index 1b445686550..737ad9558a8 100644 --- a/htdocs/bookcal/admin/setup.php +++ b/htdocs/bookcal/admin/setup.php @@ -136,41 +136,6 @@ if ($action == 'updateMask') { } else { setEventMessages($langs->trans("Error"), null, 'errors'); } -} elseif ($action == 'specimen') { - $modele = GETPOST('module', 'alpha'); - $tmpobjectkey = GETPOST('object'); - - $tmpobject = new $tmpobjectkey($db); - $tmpobject->initAsSpecimen(); - - // Search template files - $file = ''; - $classname = ''; - $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); - foreach ($dirmodels as $reldir) { - $file = dol_buildpath($reldir."core/modules/bookcal/doc/pdf_".$modele."_".strtolower($tmpobjectkey).".modules.php", 0); - if (file_exists($file)) { - $classname = "pdf_".$modele."_".strtolower($tmpobjectkey); - break; - } - } - - if ($classname !== '') { - require_once $file; - - $module = new $classname($db); - - if ($module->write_file($tmpobject, $langs) > 0) { - header("Location: ".DOL_URL_ROOT."/document.php?modulepart=bookcal-".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf"); - return; - } else { - setEventMessages($module->error, null, 'errors'); - dol_syslog($module->error, LOG_ERR); - } - } else { - setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors'); - dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR); - } } elseif ($action == 'setmod') { // TODO Check if numbering module chosen can be activated by calling method canBeActivated $tmpobjectkey = GETPOST('object'); diff --git a/htdocs/cron/class/cronjob.class.php b/htdocs/cron/class/cronjob.class.php index 621de20afa6..a761b7ffd4a 100644 --- a/htdocs/cron/class/cronjob.class.php +++ b/htdocs/cron/class/cronjob.class.php @@ -1297,7 +1297,7 @@ class Cronjob extends CommonObject dol_syslog(get_class($this)."::run_jobs START ".$this->objectname."->".$this->methodename."(".$this->params."); (Note: Log for cron jobs may be into a different log file)", LOG_DEBUG); // Create Object for the called module - $nameofclass = $this->objectname; + $nameofclass = (string) $this->objectname; $object = new $nameofclass($this->db); if ($this->entity > 0) { $object->entity = $this->entity; // We work on a dedicated entity diff --git a/htdocs/don/admin/donation.php b/htdocs/don/admin/donation.php index 3a0854cb103..b88040c2ed7 100644 --- a/htdocs/don/admin/donation.php +++ b/htdocs/don/admin/donation.php @@ -64,9 +64,9 @@ if ($action == 'specimen') { $dir = DOL_DOCUMENT_ROOT."/core/modules/dons/"; $file = $modele.".modules.php"; if ($modele !== '' && file_exists($dir.$file)) { - $classname = $modele; require_once $dir.$file; + $classname = (string) $modele; $obj = new $classname($db); if ($obj->write_file($don, $langs) > 0) { diff --git a/htdocs/modulebuilder/template/admin/setup.php b/htdocs/modulebuilder/template/admin/setup.php index 3fce4970731..d0ceb430554 100644 --- a/htdocs/modulebuilder/template/admin/setup.php +++ b/htdocs/modulebuilder/template/admin/setup.php @@ -171,6 +171,11 @@ $setupnotempty += count($formSetup->items); $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); +$moduledir = 'mymodule'; +$myTmpObjects = array(); +// TODO Scan list of objects to fill this array +$myTmpObjects['myobject'] = array('label'=>'MyObject', 'includerefgeneration'=>0, 'includedocgeneration'=>0, 'class'=>'MyObject'); + /* * Actions @@ -201,40 +206,42 @@ if ($action == 'updateMask') { } } elseif ($action == 'specimen') { $modele = GETPOST('module', 'alpha'); - $tmpobjectkey = GETPOST('object'); + $tmpobjectkey = GETPOST('object', 'aZ09'); - $tmpobject = new $tmpobjectkey($db); - $tmpobject->initAsSpecimen(); + if (in_array($tmpobjectkey, $myTmpObjects)) { + $tmpobject = new $tmpobjectkey($db); + $tmpobject->initAsSpecimen(); - // Search template files - $file = ''; - $classname = ''; - $filefound = 0; - $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); - foreach ($dirmodels as $reldir) { - $file = dol_buildpath($reldir."core/modules/mymodule/doc/pdf_".$modele."_".strtolower($tmpobjectkey).".modules.php", 0); - if (file_exists($file)) { - $filefound = 1; - $classname = "pdf_".$modele."_".strtolower($tmpobjectkey); - break; + // Search template files + $file = ''; + $classname = ''; + $filefound = 0; + $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); + foreach ($dirmodels as $reldir) { + $file = dol_buildpath($reldir."core/modules/mymodule/doc/pdf_".$modele."_".strtolower($tmpobjectkey).".modules.php", 0); + if (file_exists($file)) { + $filefound = 1; + $classname = "pdf_".$modele."_".strtolower($tmpobjectkey); + break; + } } - } - if ($filefound) { - require_once $file; + if ($filefound) { + require_once $file; - $module = new $classname($db); + $module = new $classname($db); - if ($module->write_file($tmpobject, $langs) > 0) { - header("Location: ".DOL_URL_ROOT."/document.php?modulepart=mymodule-".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf"); - return; + if ($module->write_file($tmpobject, $langs) > 0) { + header("Location: ".DOL_URL_ROOT."/document.php?modulepart=mymodule-".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf"); + return; + } else { + setEventMessages($module->error, null, 'errors'); + dol_syslog($module->error, LOG_ERR); + } } else { - setEventMessages($module->error, null, 'errors'); - dol_syslog($module->error, LOG_ERR); + setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors'); + dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR); } - } else { - setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors'); - dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR); } } elseif ($action == 'setmod') { // TODO Check if numbering module chosen can be activated by calling method canBeActivated @@ -327,12 +334,6 @@ if (!empty($formSetup->items)) { } -$moduledir = 'mymodule'; -$myTmpObjects = array(); -// TODO Scan list of objects -$myTmpObjects['myobject'] = array('label'=>'MyObject', 'includerefgeneration'=>0, 'includedocgeneration'=>0, 'class'=>'MyObject'); - - foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) { if ($myTmpObjectArray['includerefgeneration']) { /*