From d963d0cd67f6a808a555d4c6773730e83df756ab Mon Sep 17 00:00:00 2001 From: Lamrani Abdel Date: Thu, 10 Aug 2023 10:04:17 +0200 Subject: [PATCH 1/2] add edit/delete on dicionary list --- htdocs/modulebuilder/index.php | 162 +++++++++++++++++++++++++-------- 1 file changed, 125 insertions(+), 37 deletions(-) diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 5e6ea71a22f..16f664a8cd6 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -1935,7 +1935,7 @@ if ($dirins && $action == 'confirm_deleteobject' && $objectname) { } } -if ($dirins && $action == 'confirm_deletedictionary' && $dicname) { +if (($dirins && $action == 'confirm_deletedictionary' && $dicname) || ($dirins && $action == 'confirm_deletedictionary' && GETPOST('dictionnarykey'))) { $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath']; $destdir = $dirins.'/'.strtolower($module); $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php'; @@ -1945,9 +1945,11 @@ if ($dirins && $action == 'confirm_deletedictionary' && $dicname) { setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors'); } - $newdicname = $dicname; - if (!preg_match('/^c_/', $newdicname)) { - $newdicname = 'c_'.strtolower($dicname); + if (!empty($dicname)) { + $newdicname = $dicname; + if (!preg_match('/^c_/', $newdicname)) { + $newdicname = 'c_'.strtolower($dicname); + } } dol_include_once($pathtofile); @@ -1966,8 +1968,13 @@ if ($dirins && $action == 'confirm_deletedictionary' && $dicname) { dol_print_error($db, $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module)); exit; } + $dicts = $moduleobj->dictionaries; + if (!empty(GETPOST('dictionnarykey'))) { + $newdicname = $dicts['tabname'][GETPOST('dictionnarykey')-1]; + } + //chercher la table dicname $query = "SHOW TABLES LIKE '" . MAIN_DB_PREFIX.strtolower($newdicname) . "'"; $checkTable = $db->query($query); @@ -4193,7 +4200,19 @@ if ($module == 'initmodule') { $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath']; $dicts = $moduleobj->dictionaries; - //var_dump($dicts);exit; + + if ($action == 'deletedict') { + $formconfirm = $form->formconfirm( + $_SERVER["PHP_SELF"].'?dictionnarykey='.urlencode(GETPOST('dictionnarykey', 'int')).'&tab='.urlencode($tab).'&module='.urlencode($module), + $langs->trans('Delete'), + $langs->trans('Confirm Delete Dictionnary', GETPOST('dictionnarykey', 'alpha')), + 'confirm_deletedictionary', + '', + 0, + 1 + ); + print $formconfirm; + } if ($action != 'editfile' || empty($file)) { print ''; @@ -4283,55 +4302,124 @@ if ($module == 'initmodule') { 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"; if (!empty($dicts) && is_array($dicts) && !empty($dicts['tabname']) && is_array($dicts['tabname'])) { $i = 0; $maxi = count($dicts['tabname']); while ($i < $maxi) { - print ''; + if ($action == 'editdict' && array_search($dicts['tabname'][$i], $dicts['tabname']) == (int) GETPOST('dictionnarykey', 'int')) { + print ''; + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; - print ''; - print ($i + 1); - print ''; - print ''; - print $dicts['tabname'][$i]; - print ''; + print ''; + print ($i + 1); + print ''; - print ''; - print $dicts['tablib'][$i]; - print ''; + print ''; + print ''; + print ''; - print ''; - print $dicts['tabsql'][$i]; - print ''; + print ''; + print ''; + print ''; - print ''; - print $dicts['tabsqlsort'][$i]; - print ''; + print ''; + print ''; + print ''; - print ''; - print $dicts['tabfield'][$i]; - print ''; + print ''; + print ''; + print ''; - print ''; - print $dicts['tabfieldvalue'][$i]; - print ''; + print ''; - print ''; - print $dicts['tabfieldinsert'][$i]; - print ''; + print ''; - print ''; - print $dicts['tabrowid'][$i]; - print ''; + print ''; - print ''; - print $dicts['tabcond'][$i]; - print ''; + print ''; + print ''; + print ''; - print ''; + print ''; + print ''; + print ''; + + print ''; + print ''; + print '
'; + print ''; + print ''; + + print '
'; + print ''; + } else { + print ''; + + print ''; + print ($i + 1); + print ''; + + print ''; + print $dicts['tabname'][$i]; + print ''; + + print ''; + print $dicts['tablib'][$i]; + print ''; + + print ''; + print $dicts['tabsql'][$i]; + print ''; + + print ''; + print $dicts['tabsqlsort'][$i]; + print ''; + + print ''; + print $dicts['tabfield'][$i]; + print ''; + + print ''; + print $dicts['tabfieldvalue'][$i]; + print ''; + + print ''; + print $dicts['tabfieldinsert'][$i]; + print ''; + + print ''; + print $dicts['tabrowid'][$i]; + print ''; + + print ''; + print $dicts['tabcond'][$i]; + print ''; + + print ''; + print ''.img_edit().''; + print ''.img_delete().''; + print ''; + + print ''; + } $i++; } } else { From 77a9388aedcd75a5907be14d571bb7ef8dc8c5e9 Mon Sep 17 00:00:00 2001 From: Lamrani Abdel Date: Thu, 10 Aug 2023 10:41:58 +0200 Subject: [PATCH 2/2] add button on top --- htdocs/modulebuilder/index.php | 50 ++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 16f664a8cd6..fdfa386f5e9 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -2022,7 +2022,45 @@ if (($dirins && $action == 'confirm_deletedictionary' && $dicname) || ($dirins & exit; } } +if ($dirins && $action == 'updatedictionary' && GETPOST('dictionnarykey')) { + $keydict = GETPOST('dictionnarykey') - 1 ; + $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath']; + $destdir = $dirins.'/'.strtolower($module); + $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php'; + dol_include_once($pathtofile); + $class = 'mod'.$module; + + if (class_exists($class)) { + try { + $moduleobj = new $class($db); + } catch (Exception $e) { + $error++; + dol_print_error($db, $e->getMessage()); + } + } else { + $error++; + $langs->load("errors"); + dol_print_error($db, $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module)); + exit; + } + + $dicts = $moduleobj->dictionaries; + if (!empty(GETPOST('tablib')) && GETPOST('tablib') !== $dicts['tablib'][$keydict]) { + $dicts['tablib'][$keydict] = ucfirst(strtolower(GETPOST('tablib'))); + $updateDict = updateDictionaryInFile($module, $moduledescriptorfile, $dicts); + if ($updateDict > 0) { + setEventMessages($langs->trans("DictionaryNameUpdated", ucfirst(GETPOST('tablib'))), null); + } + 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; + } + //var_dump(GETPOST('tablib'));exit; +} if ($dirins && $action == 'generatedoc') { $modulelowercase = strtolower($module); @@ -4279,7 +4317,8 @@ if ($module == 'initmodule') { } } - print load_fiche_titre($langs->trans("ListOfDictionariesEntries"), '', ''); + $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 ''; @@ -4310,15 +4349,14 @@ if ($module == 'initmodule') { $i = 0; $maxi = count($dicts['tabname']); while ($i < $maxi) { - if ($action == 'editdict' && array_search($dicts['tabname'][$i], $dicts['tabname']) == (int) GETPOST('dictionnarykey', 'int')) { + if ($action == 'editdict' && $i == (int) GETPOST('dictionnarykey', 'int')-1) { print ''; print ''; print ''; print ''; print ''; - print ''; - print ''; - + print ''; + print ''; print ''; print ($i + 1); @@ -4414,7 +4452,7 @@ if ($module == 'initmodule') { print ''; print ''; - print ''.img_edit().''; + print ''.img_edit().''; print ''.img_delete().''; print '';