From df7f18d4d29218253a05b5f18408e7b7147c8268 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Fri, 5 Feb 2021 13:33:48 +0100 Subject: [PATCH 1/4] add hook to add directory into ECM auto files --- htdocs/core/class/hookmanager.class.php | 1 + htdocs/ecm/index_auto.php | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/htdocs/core/class/hookmanager.class.php b/htdocs/core/class/hookmanager.class.php index d610203b3ad..9ecd6a659a1 100644 --- a/htdocs/core/class/hookmanager.class.php +++ b/htdocs/core/class/hookmanager.class.php @@ -161,6 +161,7 @@ class HookManager 'addMoreMassActions', 'addSearchEntry', 'addStatisticLine', + 'addSectionECMAuto', 'createDictionaryFieldlist', 'editDictionaryFieldlist', 'getFormMail', diff --git a/htdocs/ecm/index_auto.php b/htdocs/ecm/index_auto.php index 452f06efb0a..cb5fb4852ea 100644 --- a/htdocs/ecm/index_auto.php +++ b/htdocs/ecm/index_auto.php @@ -81,6 +81,9 @@ $error = 0; * Actions */ +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context +$hookmanager->initHooks(array('ecmautocard', 'globalcard')); + // Purge search criteria if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers { @@ -327,6 +330,15 @@ if (!empty($conf->global->ECM_AUTO_TREE_ENABLED)) if (!empty($conf->mrp->enabled)) { $langs->load("mrp"); $rowspan++; $sectionauto[] = array('level'=>1, 'module'=>'mrp-mo', 'test'=>$conf->mrp->enabled, 'label'=>$langs->trans("MOs"), 'desc'=>$langs->trans("ECMDocsBy", $langs->transnoentitiesnoconv("ManufacturingOrders"))); } if (!empty($conf->recruitment->enabled)) { $langs->load("recruitment"); $rowspan++; $sectionauto[] = array('level'=>1, 'module'=>'recruitment-recruitmentcandidature', 'test'=>$conf->recruitment->enabled, 'label'=>$langs->trans("Candidatures"), 'desc'=>$langs->trans("ECMDocsBy", $langs->transnoentitiesnoconv("JobApplications"))); } $rowspan++; $sectionauto[] = array('level'=>1, 'module'=>'user', 'test'=>1, 'label'=>$langs->trans("Users"), 'desc'=>$langs->trans("ECMDocsBy", $langs->transnoentitiesnoconv("Users"))); + + $parameters = array(); + $reshook = $hookmanager->executeHooks('addSectionECMAuto', $parameters); + if ($reshook > 0 && is_array($hookmanager->resArray) && count($hookmanager->resArray)>0) + { + $sectionauto[]=$hookmanager->resArray; + $rowspan += count($hookmanager->resArray); + } + } $head = ecm_prepare_dasboard_head(''); From 3b4f8c32f7124e39618973ade270387fa3731e20 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Sat, 6 Feb 2021 13:21:16 +0100 Subject: [PATCH 2/4] add hook to custom directory into automatic file ECM --- htdocs/core/ajax/ajaxdirpreview.php | 14 +++++++++++ htdocs/core/class/html.formfile.class.php | 25 +++++++++++++++++++ htdocs/core/modules/DolibarrModules.class.php | 2 +- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/htdocs/core/ajax/ajaxdirpreview.php b/htdocs/core/ajax/ajaxdirpreview.php index 41e23819266..9575208f485 100644 --- a/htdocs/core/ajax/ajaxdirpreview.php +++ b/htdocs/core/ajax/ajaxdirpreview.php @@ -201,6 +201,13 @@ if ($type == 'directory') 'mrp-mo' ); + $parameters = array('modulepart'=>$module); + $reshook = $hookmanager->executeHooks('addSectionECMAuto', $parameters); + if ($reshook > 0 && is_array($hookmanager->resArray) && count($hookmanager->resArray)>0) + { + $automodules[]=$hookmanager->resArray['module']; + } + // TODO change for multicompany sharing if ($module == 'company') $upload_dir = $conf->societe->dir_output; elseif ($module == 'invoice') $upload_dir = $conf->facture->dir_output; @@ -220,6 +227,13 @@ if ($type == 'directory') elseif ($module == 'recruitment-recruitmentcandidature') $upload_dir = $conf->recruitment->dir_output.'/recruitmentcandidature'; elseif ($module == 'banque') $upload_dir = $conf->bank->dir_output; elseif ($module == 'mrp-mo') $upload_dir = $conf->mrp->dir_output.'/mo'; + else { + $parameters = array('modulepart'=>$module); + $reshook = $hookmanager->executeHooks('addSectionECMAuto', $parameters); + if ($reshook > 0 && is_array($hookmanager->resArray) && count($hookmanager->resArray) > 0) { + $upload_dir = $hookmanager->resArray['directory']; + } + } // Automatic list if (in_array($module, $automodules)) diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 6f31f0ff8de..c00318b4790 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -1570,6 +1570,20 @@ class FormFile { include_once DOL_DOCUMENT_ROOT.'/mrp/class/mo.class.php'; $object_instance = new Mo($this->db); + } else { + $parameters = array('modulepart'=>$modulepart); + $reshook = $hookmanager->executeHooks('addSectionECMAuto', $parameters); + if ($reshook > 0 && is_array($hookmanager->resArray) && count($hookmanager->resArray)>0) + { + if (array_key_exists('classpath', $hookmanager->resArray) && !empty($hookmanager->resArray['classpath'])) { + dol_include_once($hookmanager->resArray['classpath']); + if (array_key_exists('classname', $hookmanager->resArray) && !empty($hookmanager->resArray['classname'])) { + if (class_exists($hookmanager->resArray['classname'])) { + $object_instance = new ${$hookmanager->resArray['classname']}($this->db); + } + } + } + } } //var_dump($filearray); @@ -1623,6 +1637,17 @@ class FormFile 'banque'))) { preg_match('/(.*)\/[^\/]+$/', $relativefile, $reg); $ref = (isset($reg[1]) ? $reg[1] : ''); } else { + $parameters = array('modulepart'=>$modulepart,'fullname'=>$file['fullname']); + $reshook = $hookmanager->executeHooks('addSectionECMAuto', $parameters); + if ($reshook > 0 && is_array($hookmanager->resArray) && count($hookmanager->resArray)>0) + { + if (array_key_exists('ref', $hookmanager->resArray) && !empty($hookmanager->resArray['ref'])) { + $ref = $hookmanager->resArray['ref']; + } + if (array_key_exists('id', $hookmanager->resArray) && !empty($hookmanager->resArray['id'])) { + $id = $hookmanager->resArray['id']; + } + } //print 'Error: Value for modulepart = '.$modulepart.' is not yet implemented in function list_of_autoecmfiles'."\n"; } diff --git a/htdocs/core/modules/DolibarrModules.class.php b/htdocs/core/modules/DolibarrModules.class.php index da1e64ac56e..bbc9a1f801a 100644 --- a/htdocs/core/modules/DolibarrModules.class.php +++ b/htdocs/core/modules/DolibarrModules.class.php @@ -1867,7 +1867,7 @@ class DolibarrModules // Can not be abstract, because we need to instantiate it $menu->mainmenu = isset($this->menu[$key]['mainmenu']) ? $this->menu[$key]['mainmenu'] : (isset($menu->fk_mainmenu) ? $menu->fk_mainmenu : ''); $menu->leftmenu = isset($this->menu[$key]['leftmenu']) ? $this->menu[$key]['leftmenu'] : ''; $menu->title = $this->menu[$key]['titre']; - $menu->prefix = $this->menu[$key]['prefix']; + if (array_key_exists('prefix', $this->menu[$key])) $menu->prefix = $this->menu[$key]['prefix']; $menu->url = $this->menu[$key]['url']; $menu->langs = $this->menu[$key]['langs']; $menu->position = $this->menu[$key]['position']; From 377427da1dd513642da843135f29543154ed1988 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Sat, 6 Feb 2021 13:25:35 +0100 Subject: [PATCH 3/4] add hook to custom directory into automatic file ECM --- htdocs/core/class/html.formfile.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index c00318b4790..c9c895148bf 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -1637,7 +1637,7 @@ class FormFile 'banque'))) { preg_match('/(.*)\/[^\/]+$/', $relativefile, $reg); $ref = (isset($reg[1]) ? $reg[1] : ''); } else { - $parameters = array('modulepart'=>$modulepart,'fullname'=>$file['fullname']); + $parameters = array('modulepart'=>$modulepart,'fileinfo'=>$file); $reshook = $hookmanager->executeHooks('addSectionECMAuto', $parameters); if ($reshook > 0 && is_array($hookmanager->resArray) && count($hookmanager->resArray)>0) { From cc6fd7952c53ec29e4e5296abd079a4a6b804e91 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Sat, 6 Feb 2021 12:28:00 +0000 Subject: [PATCH 4/4] Fixing style errors. --- htdocs/ecm/index_auto.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/ecm/index_auto.php b/htdocs/ecm/index_auto.php index cb5fb4852ea..ae7aa840ab9 100644 --- a/htdocs/ecm/index_auto.php +++ b/htdocs/ecm/index_auto.php @@ -338,7 +338,6 @@ if (!empty($conf->global->ECM_AUTO_TREE_ENABLED)) $sectionauto[]=$hookmanager->resArray; $rowspan += count($hookmanager->resArray); } - } $head = ecm_prepare_dasboard_head('');