From b4a9a0cafb202def9797bdf44f3d938bb362a8cb Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Tue, 8 Sep 2015 13:07:13 +0200 Subject: [PATCH 1/6] Allow contact definition on additionnal modules If additionnal module use contactelement feature, the module is referenced on element list on contact type --- htdocs/admin/dict.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php index f9137a06acf..6fb9454ce58 100644 --- a/htdocs/admin/dict.php +++ b/htdocs/admin/dict.php @@ -464,6 +464,9 @@ if ($id == 11) 'fichinter' => $langs->trans('InterventionCard') ); if (! empty($conf->global->MAIN_SUPPORT_SHARED_CONTACT_BETWEEN_THIRDPARTIES)) $elementList["societe"] = $langs->trans('ThirdParty'); + + complete_elementList_with_modules($elementList); + asort($elementList); $sourceList = array( 'internal' => $langs->trans('Internal'), From e2a738bf5428f96cc074a1756720f2a928cd9611 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Tue, 8 Sep 2015 13:11:26 +0200 Subject: [PATCH 2/6] New fonction complete_elementList_with_modules if contactelement is defined on module definition, add module on definition type of contact --- htdocs/core/lib/admin.lib.php | 121 ++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/htdocs/core/lib/admin.lib.php b/htdocs/core/lib/admin.lib.php index 7469777fa89..571e24bf38a 100644 --- a/htdocs/core/lib/admin.lib.php +++ b/htdocs/core/lib/admin.lib.php @@ -1019,6 +1019,127 @@ function complete_dictionary_with_modules(&$taborder,&$tabname,&$tablib,&$tabsql return 1; } +/** + * Add external modules to list of contact element + * + * @param array $elementList elementList + * @return int 1 + */ +function complete_elementList_with_modules(&$elementList) +{ + global $db, $modules, $conf, $langs; + + // Search modules + $filename = array(); + $modules = array(); + $orders = array(); + $categ = array(); + $dirmod = array(); + $modulesdir = array(); + $i = 0; // is a sequencer of modules found + $j = 0; // j is module number. Automatically affected if module number not defined. + + foreach ($conf->file->dol_document_root as $type => $dirroot) + { + $modulesdir[$dirroot . '/core/modules/'] = $dirroot . '/core/modules/'; + + $handle=@opendir($dirroot); + if (is_resource($handle)) + { + while (($file = readdir($handle))!==false) + { + if (is_dir($dirroot.'/'.$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS' && $file != 'includes') + { + if (is_dir($dirroot . '/' . $file . '/core/modules/')) + { + $modulesdir[$dirroot . '/' . $file . '/core/modules/'] = $dirroot . '/' . $file . '/core/modules/'; + } + } + } + closedir($handle); + } + } + + foreach ($modulesdir as $dir) + { + // Load modules attributes in arrays (name, numero, orders) from dir directory + //print $dir."\n
"; + dol_syslog("Scan directory ".$dir." for modules"); + $handle=@opendir(dol_osencode($dir)); + if (is_resource($handle)) + { + while (($file = readdir($handle))!==false) + { + //print "$i ".$file."\n
"; + if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php') + { + $modName = substr($file, 0, dol_strlen($file) - 10); + + if ($modName) + { + include_once $dir.$file; + $objMod = new $modName($db); + + if ($objMod->numero > 0) + { + $j = $objMod->numero; + } + else + { + $j = 1000 + $i; + } + + $modulequalified=1; + + // We discard modules according to features level (PS: if module is activated we always show it) + $const_name = 'MAIN_MODULE_'.strtoupper(preg_replace('/^mod/i','',get_class($objMod))); + if ($objMod->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2 && ! $conf->global->$const_name) $modulequalified=0; + if ($objMod->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1 && ! $conf->global->$const_name) $modulequalified=0; + //If module is not activated disqualified + if (empty($conf->global->$const_name)) $modulequalified=0; + + if ($modulequalified) + { + // Load languages files of module + if (isset($objMod->langfiles) && is_array($objMod->langfiles)) + { + foreach($objMod->langfiles as $langfile) + { + $langs->load($langfile); + } + } + + $modules[$i] = $objMod; + $filename[$i]= $modName; + $orders[$i] = $objMod->family."_".$j; // Tri par famille puis numero module + //print "x".$modName." ".$orders[$i]."\n
"; + if (isset($categ[$objMod->special])) $categ[$objMod->special]++; // Array of all different modules categories + else $categ[$objMod->special]=1; + $dirmod[$i] = $dirroot; + + if (! empty($objMod->contactelement)) + { + $elementList[$objMod->name] = $langs->trans($objMod->name); + //exit; + } + + $j++; + $i++; + } + else dol_syslog("Module ".get_class($objMod)." not qualified"); + } + } + } + closedir($handle); + } + else + { + dol_syslog("htdocs/admin/modules.php: Failed to open directory ".$dir.". See permission and open_basedir option.", LOG_WARNING); + } + } + + return 1; +} /** * Show array with constants to edit From 4f519b57475ec7a88ffbdbaea61205d81040b8d8 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Wed, 21 Oct 2015 05:06:19 +0200 Subject: [PATCH 3/6] Update admin.lib.php --- htdocs/core/lib/admin.lib.php | 109 +++++----------------------------- 1 file changed, 15 insertions(+), 94 deletions(-) diff --git a/htdocs/core/lib/admin.lib.php b/htdocs/core/lib/admin.lib.php index 571e24bf38a..66823ab5d18 100644 --- a/htdocs/core/lib/admin.lib.php +++ b/htdocs/core/lib/admin.lib.php @@ -678,27 +678,7 @@ function activateModule($value,$withdeps=1) $modFile = $modName . ".class.php"; // Loop on each directory to fill $modulesdir - $modulesdir = array(); - foreach ($conf->file->dol_document_root as $type => $dirroot) - { - $modulesdir[] = $dirroot."/core/modules/"; - - $handle=@opendir(dol_osencode($dirroot)); - if (is_resource($handle)) - { - while (($file = readdir($handle))!==false) - { - if (is_dir($dirroot.'/'.$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS' && $file != 'includes') - { - if (is_dir($dirroot . '/' . $file . '/core/modules/')) - { - $modulesdir[] = $dirroot . '/' . $file . '/core/modules/'; - } - } - } - closedir($handle); - } - } + $modulesdir = dolGetModulesDirs(); // Loop on each directory $found=false; @@ -797,27 +777,7 @@ function unActivateModule($value, $requiredby=1) $modFile = $modName . ".class.php"; // Loop on each directory to fill $modulesdir - $modulesdir = array(); - foreach ($conf->file->dol_document_root as $type => $dirroot) - { - $modulesdir[] = $dirroot."/core/modules/"; - - $handle=@opendir(dol_osencode($dirroot)); - if (is_resource($handle)) - { - while (($file = readdir($handle))!==false) - { - if (is_dir($dirroot.'/'.$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS' && $file != 'includes') - { - if (is_dir($dirroot . '/' . $file . '/core/modules/')) - { - $modulesdir[] = $dirroot . '/' . $file . '/core/modules/'; - } - } - } - closedir($handle); - } - } + $modulesdir = dolGetModulesDirs(); // Loop on each directory $found=false; @@ -889,31 +849,11 @@ function complete_dictionary_with_modules(&$taborder,&$tabname,&$tablib,&$tabsql $orders = array(); $categ = array(); $dirmod = array(); - $modulesdir = array(); + $i = 0; // is a sequencer of modules found $j = 0; // j is module number. Automatically affected if module number not defined. - foreach ($conf->file->dol_document_root as $type => $dirroot) - { - $modulesdir[$dirroot . '/core/modules/'] = $dirroot . '/core/modules/'; - - $handle=@opendir($dirroot); - if (is_resource($handle)) - { - while (($file = readdir($handle))!==false) - { - if (is_dir($dirroot.'/'.$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS' && $file != 'includes') - { - if (is_dir($dirroot . '/' . $file . '/core/modules/')) - { - $modulesdir[$dirroot . '/' . $file . '/core/modules/'] = $dirroot . '/' . $file . '/core/modules/'; - } - } - } - closedir($handle); - } - } - + $modulesdir = dolGetModulesDirs(); foreach ($modulesdir as $dir) { // Load modules attributes in arrays (name, numero, orders) from dir directory @@ -955,13 +895,13 @@ function complete_dictionary_with_modules(&$taborder,&$tabname,&$tablib,&$tabsql if ($modulequalified) { // Load languages files of module - if (isset($objMod->langfiles) && is_array($objMod->langfiles)) - { - foreach($objMod->langfiles as $langfile) - { - $langs->load($langfile); - } - } + if (isset($objMod->langfiles) && is_array($objMod->langfiles)) + { + foreach($objMod->langfiles as $langfile) + { + $langs->load($langfile); + } + } $modules[$i] = $objMod; $filename[$i]= $modName; @@ -1035,30 +975,11 @@ function complete_elementList_with_modules(&$elementList) $orders = array(); $categ = array(); $dirmod = array(); - $modulesdir = array(); + $i = 0; // is a sequencer of modules found $j = 0; // j is module number. Automatically affected if module number not defined. - foreach ($conf->file->dol_document_root as $type => $dirroot) - { - $modulesdir[$dirroot . '/core/modules/'] = $dirroot . '/core/modules/'; - - $handle=@opendir($dirroot); - if (is_resource($handle)) - { - while (($file = readdir($handle))!==false) - { - if (is_dir($dirroot.'/'.$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS' && $file != 'includes') - { - if (is_dir($dirroot . '/' . $file . '/core/modules/')) - { - $modulesdir[$dirroot . '/' . $file . '/core/modules/'] = $dirroot . '/' . $file . '/core/modules/'; - } - } - } - closedir($handle); - } - } + $modulesdir = dolGetModulesDirs(); foreach ($modulesdir as $dir) { @@ -1116,8 +1037,8 @@ function complete_elementList_with_modules(&$elementList) if (isset($categ[$objMod->special])) $categ[$objMod->special]++; // Array of all different modules categories else $categ[$objMod->special]=1; $dirmod[$i] = $dirroot; - - if (! empty($objMod->contactelement)) + $objMod->module_parts['contactelement'] + if (! empty($objMod->module_parts['contactelement'])) { $elementList[$objMod->name] = $langs->trans($objMod->name); //exit; From ec9955986ff25ae89611e4071ad0f6a3fcfc0033 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Wed, 21 Oct 2015 05:07:13 +0200 Subject: [PATCH 4/6] Update admin.lib.php --- htdocs/core/lib/admin.lib.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/core/lib/admin.lib.php b/htdocs/core/lib/admin.lib.php index 66823ab5d18..7edf33c89ee 100644 --- a/htdocs/core/lib/admin.lib.php +++ b/htdocs/core/lib/admin.lib.php @@ -1037,7 +1037,6 @@ function complete_elementList_with_modules(&$elementList) if (isset($categ[$objMod->special])) $categ[$objMod->special]++; // Array of all different modules categories else $categ[$objMod->special]=1; $dirmod[$i] = $dirroot; - $objMod->module_parts['contactelement'] if (! empty($objMod->module_parts['contactelement'])) { $elementList[$objMod->name] = $langs->trans($objMod->name); From 88ca8d2ace84f336e61466a8091552e1179b1b29 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Wed, 21 Oct 2015 05:22:33 +0200 Subject: [PATCH 5/6] Update dict.php --- htdocs/admin/dict.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php index 6fb9454ce58..b90514fc61c 100644 --- a/htdocs/admin/dict.php +++ b/htdocs/admin/dict.php @@ -34,6 +34,7 @@ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/function2.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; $langs->load("errors"); From ef79bb3b6759c339916667e684f17676ec05a2c1 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Wed, 21 Oct 2015 05:23:49 +0200 Subject: [PATCH 6/6] Update dict.php --- htdocs/admin/dict.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php index b90514fc61c..889b2e8f4ce 100644 --- a/htdocs/admin/dict.php +++ b/htdocs/admin/dict.php @@ -34,7 +34,7 @@ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/function2.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; $langs->load("errors");