diff --git a/htdocs/core/lib/modulebuilder.lib.php b/htdocs/core/lib/modulebuilder.lib.php index 32fd00752b6..0742ad15368 100644 --- a/htdocs/core/lib/modulebuilder.lib.php +++ b/htdocs/core/lib/modulebuilder.lib.php @@ -1203,7 +1203,7 @@ function createNewDictionnary($modulename, $file, $namedic, $dictionnaires = nul $modulename = strtolower($modulename); if (empty($dictionnaires)) { - $dictionnaires = array('tabname' => array(), 'tablib' => array(), 'tabsql' => array(), 'tabsqlsort' => array(), 'tabfield' => array(), 'tabfieldvalue' => array(), 'tabfieldinsert' => array(), 'tabrowid' => array(), 'tabcond' => array(), 'tabhelp' => array()); + $dictionnaires = array('langs' => '', 'tabname' => array(), 'tablib' => array(), 'tabsql' => array(), 'tabsqlsort' => array(), 'tabfield' => array(), 'tabfieldvalue' => array(), 'tabfieldinsert' => array(), 'tabrowid' => array(), 'tabcond' => array(), 'tabhelp' => array()); } $columns = array( @@ -1243,6 +1243,7 @@ function createNewDictionnary($modulename, $file, $namedic, $dictionnaires = nul } // rewrite dictionnary if + $dictionnaires['langs'] = $modulename.'@'.$modulename; $dictionnaires['tabname'][] = strtolower($namedic); $dictionnaires['tablib'][] = ucfirst(substr($namedic, 2)); $dictionnaires['tabsql'][] = 'SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.strtolower($namedic).' as f'; diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 668991818b5..f77a82cfd3b 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -1568,11 +1568,19 @@ if ($dirins && $action == 'initobject' && $module && $objectname) { } // Add a dictionary -if ($dirins && $action == 'initdic' && $module && $dicname) { +if ($dirins && $action == 'initdic' && $module && empty($cancel)) { $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath']; $destdir = $dirins.'/'.strtolower($module); $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php'; + if (!GETPOST('dicname')) { + $error++; + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Table")), null, 'errors'); + } + if (!GETPOST('label')) { + $error++; + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Lable")), null, 'errors'); + } if (!$error) { $newdicname = $dicname; if (!preg_match('/^c_/', $newdicname)) { @@ -2051,16 +2059,13 @@ if (($dirins && $action == 'confirm_deletedictionary' && $dicname) || ($dirins & $result = updateDictionaryInFile($module, $moduledescriptorfile, $dicts); if ($result > 0) { setEventMessages($langs->trans("DictionaryDeleted", ucfirst(substr($newdicname, 2))), null); - } elseif (!$result) { - setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Dictionaries"), "mod".$module."class.php"), null, 'warnings'); - } else { - if (function_exists('opcache_invalidate')) { - opcache_reset(); // remove the include cache hell ! - } - clearstatcache(true); - header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : '')); - exit; } + if (function_exists('opcache_invalidate')) { + opcache_reset(); // remove the include cache hell ! + } + clearstatcache(true); + header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : '')); + exit; } } if ($dirins && $action == 'updatedictionary' && GETPOST('dictionnarykey')) { @@ -3265,7 +3270,7 @@ if ($module == 'initmodule') { $objects = dolGetListOfObjectClasses($destdir); $diroflang = dol_buildpath($modulelowercase, 0)."/langs"; $countLangs = countItemsInDirectory($diroflang, 2); - $countDictionaries = count($moduleobj->dictionaries['tabname']); + $countDictionaries = (!empty($moduleobj->dictionaries) ? count($moduleobj->dictionaries['tabname']) : 0); $countRights = count($moduleobj->rights); $countMenus = count($moduleobj->menu); $countTriggers = countItemsInDirectory(dol_buildpath($modulelowercase, 0)."/core/triggers"); @@ -3274,7 +3279,7 @@ if ($module == 'initmodule') { $countJs = countItemsInDirectory(dol_buildpath($modulelowercase, 0)."/js"); $countCLI = countItemsInDirectory(dol_buildpath($modulelowercase, 0)."/scripts"); $hasDoc = countItemsInDirectory(dol_buildpath($modulelowercase, 0)."/doc"); - + //var_dump($moduleobj->dictionaries);exit; $head2 = array(); $h = 0; @@ -3294,7 +3299,7 @@ if ($module == 'initmodule') { $h++; $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : ''); - $head2[$h][1] = ($countDictionaries <= 0 ? $langs->trans("Dictionaries") : $langs->trans('Dictionaries')." (".$countDictionaries.")"); + $head2[$h][1] = ($countDictionaries == 0 ? $langs->trans("Dictionaries") : $langs->trans('Dictionaries')." (".$countDictionaries.")"); $head2[$h][2] = 'dictionaries'; $h++; @@ -4519,206 +4524,250 @@ if ($module == 'initmodule') { //$listofobject = dol_dir_list($dir, 'files', 0, '\.class\.php$'); $firstdicname = ''; - if (!empty($dicts['tabname'])) { - foreach ($dicts['tabname'] as $key => $dic) { - $dicname = $dic; - $diclabel = $dicts['tablib'][$key]; + // if (!empty($dicts['tabname'])) { + // foreach ($dicts['tabname'] as $key => $dic) { + // $dicname = $dic; + // $diclabel = $dicts['tablib'][$key]; - if (empty($firstdicname)) { - $firstdicname = $dicname; - } + // if (empty($firstdicname)) { + // $firstdicname = $dicname; + // } - $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabdic='.$dicname; - $head3[$h][1] = $diclabel; - $head3[$h][2] = $dicname; - $h++; - } - } + // $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabdic='.$dicname; + // $head3[$h][1] = $diclabel; + // $head3[$h][2] = $dicname; + // $h++; + // } + // } - if ($h > 1) { - $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabdic=deletedictionary'; - $head3[$h][1] = $langs->trans("DangerZone"); - $head3[$h][2] = 'deletedictionary'; - $h++; - } + // if ($h > 1) { + // $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabdic=deletedictionary'; + // $head3[$h][1] = $langs->trans("DangerZone"); + // $head3[$h][2] = 'deletedictionary'; + // $h++; + // } // If tabobj was not defined, then we check if there is one obj. If yes, we force on it, if no, we will show tab to create new objects. - if ($tabdic == 'newdicifnodic') { - if ($firstdicname) { - $tabdic = $firstdicname; - } else { - $tabdic = 'newdictionary'; - } - } + // if ($tabdic == 'newdicifnodic') { + // if ($firstdicname) { + // $tabdic = $firstdicname; + // } else { + // $tabdic = 'newdictionary'; + // } + // } + //print dol_get_fiche_head($head3, $tabdic, '', -1, ''); // Level 3 + $newdict = dolGetButtonTitle($langs->trans('NewDictionary'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/modulebuilder/index.php?tab=dictionaries&module='.urlencode($module).'&tabdic=newdictionary'); print_barre_liste($langs->trans("ListOfDictionariesEntries"), '', $_SERVER["PHP_SELF"], '', '', '', '', '', '', '', 0, $newdict, '', '', 0, 0, 1); - print '
'; - - print dol_get_fiche_head($head3, $tabdic, '', -1, ''); // Level 3 - if ($tabdic == 'newdictionary') { // New dic tab print '| '.$langs->trans("Table").' | '; + print ' |
| '.$langs->trans("Label").' | |
| '.$langs->trans("SQL").' | |
| '.$langs->trans("SQLSort").' | |
| '.$langs->trans("FieldsView").' | |
| '.$langs->trans("FieldsEdit").' | |
| '.$langs->trans("FieldsInsert").' | |
| '.$langs->trans("Rowid").' | |