Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add entity in custom translation with multicompany #31953

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 52 additions & 5 deletions htdocs/admin/translation.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
$transvalue = GETPOST('transvalue', 'restricthtml');
}

$entity = $conf->entity;
if (isModEnabled('multicompany') && !$user->entity) {
$entity = GETPOST('entity', 'int');
}

// Load variable for pagination
$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'aZ09comma');
Expand Down Expand Up @@ -128,10 +133,19 @@
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NewTranslationStringToShow")), null, 'errors');
$error++;
}
if ($entity == '') {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Entity")), null, 'errors');
$error++;
}
if (!$error) {
$db->begin();

$sql = "UPDATE ".MAIN_DB_PREFIX."overwrite_trans set transkey = '".$db->escape($transkey)."', transvalue = '".$db->escape($transvalue)."' WHERE rowid = ".(GETPOSTINT('rowid'));
$sql = "UPDATE " . MAIN_DB_PREFIX . "overwrite_trans set transkey = '" . $db->escape(
$transkey
) . "', transvalue = '" . $db->escape($transvalue) . "', entity = '" . $db->escape(
$entity
) . "' WHERE rowid = " . ((int) GETPOST('rowid', 'int'));

$result = $db->query($sql);
if ($result) {
$db->commit();
Expand Down Expand Up @@ -368,29 +382,46 @@
print_liste_field_titre("Language_en_US_es_MX_etc", $_SERVER["PHP_SELF"], 'lang,transkey', '', $param, '', $sortfield, $sortorder);
print_liste_field_titre("TranslationKey", $_SERVER["PHP_SELF"], 'transkey', '', $param, '', $sortfield, $sortorder);
print_liste_field_titre("NewTranslationStringToShow", $_SERVER["PHP_SELF"], 'transvalue', '', $param, '', $sortfield, $sortorder);
//if (isModEnabled('multicompany') && !$user->entity) print_liste_field_titre("Entity", $_SERVER["PHP_SELF"], 'entity,transkey', '', $param, '', $sortfield, $sortorder);
if (isModEnabled('multicompany') && !$user->entity) {
print_liste_field_titre("Entity", $_SERVER["PHP_SELF"], 'Entity', '', $param, '', $sortfield, $sortorder);
}
print '<td align="center"></td>';
print "</tr>\n";


// Line to add new record
print "\n";

print '<tr class="oddeven"><td>';
print '<tr class="oddeven">';

// Lang
print '<td>';
print $formadmin->select_language(GETPOST('langcode'), 'langcode', 0, array(), 1, 0, $disablededit ? 1 : 0, 'maxwidth250', 1);
print '</td>'."\n";

// Trans key
print '<td>';
print '<input type="text" class="flat maxwidthonsmartphone"'.$disablededit.' name="transkey" id="transkey" value="'.(!empty($transkey) ? $transkey : "").'">';
print '</td><td>';
print '</td>';

// Value
print '<td>';
print '<input type="text" class="quatrevingtpercent"'.$disablededit.' name="transvalue" id="transvalue" value="'.(!empty($transvalue) ? $transvalue : "").'">';
print '</td>';

// Multi company
if (isModEnabled('multicompany') && !$user->entity) {
print '<td>';
print '<input type="text" class="quatrevingtpercent"' . $disablededit . ' name="entity" id="entity" value="' . (!empty($entity) ? $entity : "") . '">';
print '</td>';
}

print '<td class="center">';
print '<input type="hidden" name="entity" value="'.$conf->entity.'">';
print '<input type="submit" class="button"'.$disabled.' value="'.$langs->trans("Add").'" name="add" title="'.dol_escape_htmltag($langs->trans("YouMustEnableTranslationOverwriteBefore")).'">';
print "</td>\n";
print '</tr>';


// Show constants
$sql = "SELECT rowid, entity, lang, transkey, transvalue";
$sql .= " FROM ".MAIN_DB_PREFIX."overwrite_trans";
Expand All @@ -411,7 +442,10 @@

print '<tr class="oddeven">';

// Lang
print '<td>'.dol_escape_htmltag($obj->lang).'</td>'."\n";

// Trans key
print '<td>';
if ($action == 'edit' && $obj->rowid == GETPOSTINT('rowid')) {
print '<input type="text" class="quatrevingtpercent" name="transkey" value="'.dol_escape_htmltag($obj->transkey).'">';
Expand Down Expand Up @@ -441,6 +475,19 @@
}
print '</td>';

// Entity limit to superadmin
if (isModEnabled('multicompany') && empty($user->entity)) {
print '<td>';
if ($action == 'edit' && $obj->rowid == GETPOSTINT('rowid')) {
print '<input type="text" class="flat" size="1" name="entity" value="' . ((int) $obj->entity) . '">';
} else {
print dol_escape_htmltag($obj->entity);
}
print '</td>';
} else {
print '<input type="hidden" name="const[' . $i . '][entity]" value="' . ((int) $obj->entity) . '">';
}

print '<td class="center">';
if ($action == 'edit' && $obj->rowid == GETPOSTINT('rowid')) {
print '<input type="hidden" class="button" name="rowid" value="'.$obj->rowid.'">';
Expand Down
Loading