Merge pull request #25607 from lamrani002/updateDictInMB
NEW functionnality for edit name of dictionnary and delete it in MB
This commit is contained in:
commit
f797a1cdcc
1 changed files with 164 additions and 38 deletions
|
|
@ -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);
|
||||
|
|
@ -2015,7 +2022,45 @@ if ($dirins && $action == 'confirm_deletedictionary' && $dicname) {
|
|||
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);
|
||||
|
||||
|
|
@ -4193,7 +4238,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 '<span class="opacitymedium">';
|
||||
|
|
@ -4260,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 '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
|
||||
print '<input type="hidden" name="token" value="'.newToken().'">';
|
||||
|
|
@ -4283,55 +4341,123 @@ 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 "</tr>\n";
|
||||
|
||||
if (!empty($dicts) && is_array($dicts) && !empty($dicts['tabname']) && is_array($dicts['tabname'])) {
|
||||
$i = 0;
|
||||
$maxi = count($dicts['tabname']);
|
||||
while ($i < $maxi) {
|
||||
print '<tr class="oddeven">';
|
||||
if ($action == 'editdict' && $i == (int) GETPOST('dictionnarykey', 'int')-1) {
|
||||
print '<tr class="oddeven">';
|
||||
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
|
||||
print '<input type="hidden" name="token" value="'.newToken().'">';
|
||||
print '<input type="hidden" name="tab" value="dictionaries">';
|
||||
print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
|
||||
print '<input type="hidden" name="action" value="updatedictionary">';
|
||||
print '<input type="hidden" name="dictionnarykey" value="'.($i+1).'">';
|
||||
|
||||
print '<td class="tdsticky tdstickygray">';
|
||||
print ($i + 1);
|
||||
print '</td>';
|
||||
print '<td class="tdsticky tdstickygray">';
|
||||
print ($i + 1);
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
print $dicts['tabname'][$i];
|
||||
print '</td>';
|
||||
print '<td>';
|
||||
print '<input type="text" name="tabname" value="'.$dicts['tabname'][$i].'" readonly class="tdstickygray">';
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
print $dicts['tablib'][$i];
|
||||
print '</td>';
|
||||
print '<td>';
|
||||
print '<input type="text" name="tablib" value="'.$dicts['tablib'][$i].'">';
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
print $dicts['tabsql'][$i];
|
||||
print '</td>';
|
||||
print '<td>';
|
||||
print '<input type="text" name="tabsql" value="'.$dicts['tabsql'][$i].'" readonly class="tdstickygray">';
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
print $dicts['tabsqlsort'][$i];
|
||||
print '</td>';
|
||||
print '<td>';
|
||||
print '<select name="tabsqlsort">';
|
||||
print '<option value="'.dol_escape_htmltag($dicts['tabsqlsort'][$i]).'">'.$dicts['tabsqlsort'][$i].'</option>';
|
||||
print '</select>';
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
print $dicts['tabfield'][$i];
|
||||
print '</td>';
|
||||
print '<td><select name="tabfield" >';
|
||||
print '<option value="'.dol_escape_htmltag($dicts['tabfield'][$i]).'">'.$dicts['tabfield'][$i].'</option>';
|
||||
print '</select></td>';
|
||||
|
||||
print '<td>';
|
||||
print $dicts['tabfieldvalue'][$i];
|
||||
print '</td>';
|
||||
print '<td><select name="tabfieldvalue" >';
|
||||
print '<option value="'.dol_escape_htmltag($dicts['tabfieldvalue'][$i]).'">'.$dicts['tabfieldvalue'][$i].'</option>';
|
||||
print '</select></td>';
|
||||
|
||||
print '<td>';
|
||||
print $dicts['tabfieldinsert'][$i];
|
||||
print '</td>';
|
||||
print '<td><select name="tabfieldinsert" >';
|
||||
print '<option value="'.dol_escape_htmltag($dicts['tabfieldinsert'][$i]).'">'.$dicts['tabfieldinsert'][$i].'</option>';
|
||||
print '</select></td>';
|
||||
|
||||
print '<td >';
|
||||
print $dicts['tabrowid'][$i];
|
||||
print '</td>';
|
||||
print '<td>';
|
||||
print '<input type="text" name="tabrowid" value="'.dol_escape_htmltag($dicts['tabrowid'][$i]).'" readonly class="tdstickygray">';
|
||||
print '</td>';
|
||||
|
||||
print '<td >';
|
||||
print $dicts['tabcond'][$i];
|
||||
print '</td>';
|
||||
print '<td>';
|
||||
print '<input type="text" name="tabcond" value="'.dol_escape_htmltag((empty($dicts['tabcond'][$i]) ? 'disabled' : 'enabled')).'" readonly class="tdstickygray">';
|
||||
print '</td>';
|
||||
|
||||
print '</tr>';
|
||||
print '<td class="center tdstickyright tdstickyghostwhite">';
|
||||
print '<input id ="updatedict" class="reposition button smallpaddingimp" type="submit" name="updatedict" value="'.$langs->trans("Modify").'"/>';
|
||||
print '<br>';
|
||||
print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"/>';
|
||||
print '</td>';
|
||||
|
||||
print '</form>';
|
||||
print '</tr>';
|
||||
} else {
|
||||
print '<tr class="oddeven">';
|
||||
|
||||
print '<td class="tdsticky tdstickygray">';
|
||||
print ($i + 1);
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
print $dicts['tabname'][$i];
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
print $dicts['tablib'][$i];
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
print $dicts['tabsql'][$i];
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
print $dicts['tabsqlsort'][$i];
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
print $dicts['tabfield'][$i];
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
print $dicts['tabfieldvalue'][$i];
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
print $dicts['tabfieldinsert'][$i];
|
||||
print '</td>';
|
||||
|
||||
print '<td >';
|
||||
print $dicts['tabrowid'][$i];
|
||||
print '</td>';
|
||||
|
||||
print '<td >';
|
||||
print $dicts['tabcond'][$i];
|
||||
print '</td>';
|
||||
|
||||
print '<td class="center tdstickyright tdstickyghostwhite">';
|
||||
print '<a class="editfielda reposition marginleftonly marginrighttonly paddingright paddingleft" href="'.$_SERVER["PHP_SELF"].'?action=editdict&token='.newToken().'&dictionnarykey='.urlencode($i+1).'&tab='.urlencode($tab).'&module='.urlencode($module).'">'.img_edit().'</a>';
|
||||
print '<a class="marginleftonly marginrighttonly paddingright paddingleft" href="'.$_SERVER["PHP_SELF"].'?action=deletedict&token='.newToken().'&dictionnarykey='.urlencode($i+1).'&tab='.urlencode($tab).'&module='.urlencode($module).'">'.img_delete().'</a>';
|
||||
print '</td>';
|
||||
|
||||
print '</tr>';
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in a new issue