From 5adf2ccf5b5678a1fac6b2985e896e847327c2c8 Mon Sep 17 00:00:00 2001 From: Lamrani Abdel Date: Fri, 8 Sep 2023 12:11:52 +0200 Subject: [PATCH] fix problem --- htdocs/core/lib/modulebuilder.lib.php | 3 +- htdocs/modulebuilder/index.php | 378 +++++++++++++++----------- 2 files changed, 214 insertions(+), 167 deletions(-) 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 ''; - print ''; - print ''; - print ''; - print ''; + if ($tabdic != 'newdictionary') { + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; - print '
'; - print ''; + print '
'; + print '
'; - print ''; - print_liste_field_titre("#", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'thsticky thstickygrey '); - print_liste_field_titre("Table", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder); - print_liste_field_titre("Label", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder); - print_liste_field_titre("SQL", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder); - print_liste_field_titre("SQLSort", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder); - print_liste_field_titre("FieldsView", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder); - print_liste_field_titre("FieldsEdit", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder); - print_liste_field_titre("FieldsInsert", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder); - print_liste_field_titre("Rowid", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder); - print_liste_field_titre("Condition", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder); - print_liste_field_titre("", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder); + print ''; + print_liste_field_titre("#", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'thsticky thstickygrey '); + print_liste_field_titre("Table", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder); + print_liste_field_titre("Label", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder); + print_liste_field_titre("SQL", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder); + print_liste_field_titre("SQLSort", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder); + print_liste_field_titre("FieldsView", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder); + print_liste_field_titre("FieldsEdit", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder); + print_liste_field_titre("FieldsInsert", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder); + print_liste_field_titre("Rowid", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder); + print_liste_field_titre("Condition", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder); + print_liste_field_titre("", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder); - print "\n"; + print "\n"; - if (!empty($dicts) && is_array($dicts) && !empty($dicts['tabname']) && is_array($dicts['tabname'])) { - $i = 0; - $maxi = count($dicts['tabname']); - while ($i < $maxi) { - if ($action == 'editdict' && $i == (int) GETPOST('dictionnarykey', 'int')-1) { - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; + if (!empty($dicts) && is_array($dicts) && !empty($dicts['tabname']) && is_array($dicts['tabname'])) { + $i = 0; + $maxi = count($dicts['tabname']); + while ($i < $maxi) { + if ($action == 'editdict' && $i == (int) GETPOST('dictionnarykey', 'int')-1) { + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; - print ''; + print ''; - print ''; + print ''; - print ''; + print ''; - print ''; + print ''; - print ''; + print ''; - print ''; + print ''; - print ''; + print ''; - print ''; + print ''; - print ''; + print ''; - print ''; + print ''; - print ''; + print ''; - print ''; - print ''; - } else { - print ''; + print ''; + print ''; + } else { + print ''; - print ''; + print ''; - print ''; + print ''; - print ''; + print ''; - print ''; + print ''; - print ''; + print ''; - print ''; + print ''; - print ''; + print ''; - print ''; + print ''; - print ''; + print ''; - print ''; + print ''; - print ''; + print ''; - print ''; + print ''; + } + $i++; } - $i++; + } else { + print ''; } - } else { - print ''; + + print '
'; - print ($i + 1); - print ''; + print ($i + 1); + print ''; - print ''; - print ''; + print ''; + print ''; - print ''; - print ''; + print ''; + print ''; - print ''; - print ''; + print ''; + print ''; - print ''; - print ''; + print ''; + print ''; - print ''; - print ''; + print ''; + print ''; - print ''; - print ''; + print ''; + print ''; - print ''; - print '
'; - print ''; - print '
'; + print ''; + print '
'; + print ''; + print '
'; - print ($i + 1); - print ''; + print ($i + 1); + print ''; - print $dicts['tabname'][$i]; - print ''; + print $dicts['tabname'][$i]; + print ''; - print $dicts['tablib'][$i]; - print ''; + print $dicts['tablib'][$i]; + print ''; - print $dicts['tabsql'][$i]; - print ''; + print $dicts['tabsql'][$i]; + print ''; - print $dicts['tabsqlsort'][$i]; - print ''; + print $dicts['tabsqlsort'][$i]; + print ''; - print $dicts['tabfield'][$i]; - print ''; + print $dicts['tabfield'][$i]; + print ''; - print $dicts['tabfieldvalue'][$i]; - print ''; + print $dicts['tabfieldvalue'][$i]; + print ''; - print $dicts['tabfieldinsert'][$i]; - print ''; + print $dicts['tabfieldinsert'][$i]; + print ''; - print $dicts['tabrowid'][$i]; - print ''; + print $dicts['tabrowid'][$i]; + print ''; - print $dicts['tabcond'][$i]; - print ''; + print $dicts['tabcond'][$i]; + print ''; - print ''.img_edit().''; - print ''.img_delete().''; - print ''; + print ''.img_edit().''; + print ''.img_delete().''; + print '
'.$langs->trans("None").'
'.$langs->trans("None").'
'; + print '
'; + + print ''; } - print ''; - print ''; - - print ''; - - print dol_get_fiche_head($head3, $tabdic, '', -1, ''); // Level 3 - if ($tabdic == 'newdictionary') { // New dic tab print '
'; print ''; print ''; print ''; + print ''; + print ''; print ''.$langs->trans("EnterNameOfDictionaryDesc").'

'; - print '
'; - // print '
'; - // print '
'; - print ''; + print dol_get_fiche_head(''); + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print '
'.$langs->trans("Table").'
'.$langs->trans("Label").'
'.$langs->trans("SQL").'
'.$langs->trans("SQLSort").'
'.$langs->trans("FieldsView").'
'.$langs->trans("FieldsEdit").'
'.$langs->trans("FieldsInsert").'
'.$langs->trans("Rowid").'
'; + print ''; + print ''; + print dol_get_fiche_end(); + print '
'; + print ''; + /*print '
'; print '
'; print '
'; @@ -4731,7 +4780,6 @@ if ($module == 'initmodule') { print ''; print '
'; */ - print ''; } elseif ($tabdic == 'deletedictionary') { // Delete dic tab print '
'; @@ -4745,8 +4793,6 @@ if ($module == 'initmodule') { print ''; print ''; print '
'; - } else { - print $langs->trans("FeatureNotYetAvailable"); } print dol_get_fiche_end(); @@ -5138,7 +5184,7 @@ if ($module == 'initmodule') { } }); }); - '; + '; // display permissions for each object } else {