25 require
'../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formadmin.class.php';
31 $langs->loadLangs(array(
"companies",
"products",
"admin",
"sms",
"other",
"errors"));
36 $action =
GETPOST(
'action',
'aZ09');
38 $langcode =
GETPOST(
'langcode',
'alphanohtml');
39 $transkey =
GETPOST(
'transkey',
'alphanohtml');
40 $transvalue =
GETPOST(
'transvalue',
'restricthtml');
43 $mode =
GETPOST(
'mode',
'aZ09') ?
GETPOST(
'mode',
'aZ09') :
'searchkey';
45 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
46 $sortfield =
GETPOST(
"sortfield",
'alpha');
47 $sortorder =
GETPOST(
"sortorder",
'alpha');
49 if (empty($page) || $page == -1) { $page = 0; }
50 $offset = $limit * $page;
51 $pageprev = $page - 1;
52 $pagenext = $page + 1;
53 if (!$sortfield) $sortfield =
'lang,transkey';
54 if (!$sortorder) $sortorder =
'ASC';
57 $hookmanager->initHooks(array(
'admintranslation',
'globaladmin'));
64 if (
GETPOST(
'cancel',
'alpha')) { $action =
'list'; $massaction =
''; }
65 if (!
GETPOST(
'confirmmassaction',
'alpha') && $massaction !=
'presend' && $massaction !=
'confirm_presend') { $massaction =
''; }
67 $parameters = array(
'socid'=>$socid);
68 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
69 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
71 include DOL_DOCUMENT_ROOT.
'/core/actions_changeselectedfields.inc.php';
74 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha'))
79 $search_array_options = array();
82 if ($action ==
'setMAIN_ENABLE_OVERWRITE_TRANSLATION')
85 else dolibarr_set_const($db,
'MAIN_ENABLE_OVERWRITE_TRANSLATION', 0,
'chaine', 0,
'', $conf->entity);
88 if ($action ==
'update')
90 if ($transvalue ==
'')
92 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"NewTranslationStringToShow")), null,
'errors');
99 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"overwrite_trans set transvalue = '".$db->escape($transvalue).
"' WHERE rowid = ".
GETPOST(
'rowid',
'int');
100 $result = $db->query($sql);
110 if ($db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS')
112 setEventMessages($langs->trans(
"WarningAnEntryAlreadyExistForTransKey"), null,
'warnings');
121 if ($action ==
'add')
125 if (empty($langcode))
127 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Language")), null,
'errors');
132 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Key")), null,
'errors');
135 if ($transvalue ==
'')
137 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"NewTranslationStringToShow")), null,
'errors');
144 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"overwrite_trans(lang, transkey, transvalue, entity) VALUES ('".$db->escape($langcode).
"','".$db->escape($transkey).
"','".$db->escape($transvalue).
"', ".$db->escape($conf->entity).
")";
145 $result = $db->query($sql);
155 if ($db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS')
157 setEventMessages($langs->trans(
"WarningAnEntryAlreadyExistForTransKey"), null,
'warnings');
167 if ($action ==
'delete')
169 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"overwrite_trans WHERE rowid = ".$db->escape($id);
170 $result = $db->query($sql);
187 $form =
new Form($db);
190 $wikihelp =
'EN:Setup Translation|FR:Paramétrage traduction|ES:Configuración';
193 $param =
'&mode='.urlencode($mode);
195 $enabledisablehtml =
'';
196 $enabledisablehtml .= $langs->trans(
"EnableOverwriteTranslation").
' ';
197 if (empty($conf->global->MAIN_ENABLE_OVERWRITE_TRANSLATION))
200 $enabledisablehtml .=
'<a class="reposition valignmiddle" href="'.$_SERVER[
"PHP_SELF"].
'?action=setMAIN_ENABLE_OVERWRITE_TRANSLATION&token='.
newToken().
'&value=1'.$param.
'">';
201 $enabledisablehtml .=
img_picto($langs->trans(
"Disabled"),
'switch_off');
202 $enabledisablehtml .=
'</a>';
205 $enabledisablehtml .=
'<a class="reposition valignmiddle" href="'.$_SERVER[
"PHP_SELF"].
'?action=setMAIN_ENABLE_OVERWRITE_TRANSLATION&token='.
newToken().
'&value=0'.$param.
'">';
206 $enabledisablehtml .=
img_picto($langs->trans(
"Activated"),
'switch_on');
207 $enabledisablehtml .=
'</a>';
212 $current_language_code = $langs->defaultlang;
214 print $form->textwithpicto(
'<span class="opacitymedium">'.$langs->trans(
"CurrentUserLanguage").
':</span> <strong>'.$s.
' '.$current_language_code.
'</strong>', $langs->trans(
"TranslationDesc")).
'</span><br>';
218 if (!empty($contextpage) && $contextpage !=
$_SERVER[
"PHP_SELF"]) $param .=
'&contextpage='.urlencode($contextpage);
219 if ($limit > 0 && $limit != $conf->liste_limit) $param .=
'&limit='.urlencode($limit);
220 if ($optioncss !=
'') $param .=
'&optioncss='.urlencode($optioncss);
221 if ($langcode) $param .=
'&langcode='.urlencode($langcode);
222 if ($transkey) $param .=
'&transkey='.urlencode($transkey);
223 if ($transvalue) $param .=
'&transvalue='.urlencode($transvalue);
226 print '<form action="'.$_SERVER[
"PHP_SELF"].((empty($user->entity) && $debug) ?
'?debug=1' :
'').
'" method="POST">';
227 if ($optioncss !=
'')
print '<input type="hidden" name="optioncss" value="'.$optioncss.
'">';
228 print '<input type="hidden" name="token" value="'.newToken().
'">';
229 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
230 print '<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
231 print '<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
237 if ($mode ==
'overwrite')
239 print '<input type="hidden" name="page" value="'.$page.
'">';
242 if ($action ==
'edit' || empty($conf->global->MAIN_ENABLE_OVERWRITE_TRANSLATION)) $disabled =
' disabled="disabled"';
244 if ($action ==
'edit' || empty($conf->global->MAIN_ENABLE_OVERWRITE_TRANSLATION)) $disablededit =
' disabled';
246 print '<div class="justify"><span class="opacitymedium">';
247 print img_info().
' '.$langs->trans(
"SomeTranslationAreUncomplete");
248 $urlwikitranslatordoc =
'https://wiki.dolibarr.org/index.php/Translator_documentation';
249 print ' ('.str_replace(
'{s1}',
'<a href="'.$urlwikitranslatordoc.
'" target="_blank">'.$langs->trans(
"Here").
'</a>', $langs->trans(
"SeeAlso",
'{s1}')).
')<br>';
250 print $langs->trans(
"TranslationOverwriteDesc", $langs->transnoentitiesnoconv(
"Language"), $langs->transnoentitiesnoconv(
"Key"), $langs->transnoentitiesnoconv(
"NewTranslationStringToShow")).
"\n";
251 print ' ('.$langs->trans(
"TranslationOverwriteDesc2").
').'.
"<br>\n";
252 print '</span></div>';
257 print '<input type="hidden" name="action" value="'.($action ==
'edit' ?
'update' :
'add').
'">';
258 print '<input type="hidden" id="mode" name="mode" value="'.$mode.
'">';
260 print '<div class="div-table-responsive-no-min">';
261 print '<table class="noborder centpercent">';
262 print '<tr class="liste_titre">';
267 print '<td align="center"></td>';
274 print '<tr class="oddeven"><td>';
275 print $formadmin->select_language(
GETPOST(
'langcode'),
'langcode', 0, null, 1, 0, $disablededit ? 1 : 0,
'maxwidthonsmartphone', 1);
278 print '<input type="text" class="flat maxwidthonsmartphone"'.$disablededit.
' name="transkey" id="transkey" value="'.(!empty($transkey) ? $transkey :
"").
'">';
280 print '<input type="text" class="quatrevingtpercent"'.$disablededit.
' name="transvalue" id="transvalue" value="'.(!empty($transvalue) ? $transvalue :
"").
'">';
292 print '<td class="center">';
293 print '<input type="hidden" name="entity" value="'.$conf->entity.
'">';
295 print '<input type="submit" class="button"'.$disabled.
' value="'.$langs->trans(
"Add").
'" name="add" title="'.
dol_escape_htmltag($langs->trans(
"YouMustEnabledTranslationOverwriteBefore")).
'">';
301 $sql =
"SELECT rowid, entity, lang, transkey, transvalue";
302 $sql .=
" FROM ".MAIN_DB_PREFIX.
"overwrite_trans";
303 $sql .=
" WHERE 1 = 1";
304 $sql .=
" AND entity IN (".getEntity(
'overwrite_trans').
")";
305 $sql .= $db->order($sortfield, $sortorder);
307 dol_syslog(
"translation::select from table", LOG_DEBUG);
308 $result = $db->query($sql);
311 $num = $db->num_rows($result);
316 $obj = $db->fetch_object($result);
320 print
'<tr class="oddeven">';
322 print
'<td>'.$obj->lang.
'</td>'.
"\n";
323 print
'<td>'.$obj->transkey.
'</td>'.
"\n";
332 if ($action ==
'edit' && $obj->rowid ==
GETPOST(
'rowid',
'int'))
334 print
'<input type="text" class="quatrevingtpercent" name="transvalue" value="'.dol_escape_htmltag($obj->transvalue).
'">';
340 print
'<td class="center">';
341 if ($action ==
'edit' && $obj->rowid ==
GETPOST(
'rowid',
'int')) {
342 print
'<input type="hidden" class="button" name="rowid" value="'.$obj->rowid.
'">';
343 print
'<input type="submit" class="button buttongen button-save" name="save" value="'.dol_escape_htmltag($langs->trans(
"Save")).
'">';
345 print
'<input type="submit" class="button buttongen button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans(
"Cancel")).
'">';
347 print
'<a class="reposition editfielda paddingrightonly" href="'.$_SERVER[
'PHP_SELF'].
'?rowid='.$obj->rowid.
'&entity='.$obj->entity.
'&mode='.urlencode($mode).
'&action=edit'.((empty($user->entity) && $debug) ?
'&debug=1' :
'').
'">'.
img_edit().
'</a>';
349 print
'<a class="reposition" href="'.$_SERVER[
'PHP_SELF'].
'?rowid='.$obj->rowid.
'&entity='.$obj->entity.
'&mode='.urlencode($mode).
'&action=delete&token='.
newToken().((empty($user->entity) && $debug) ?
'&debug=1' :
'').
'">'.
img_delete().
'</a>';
363 if ($mode ==
'searchkey')
368 $newlang->setDefaultLang($langcode);
370 $newlangfileonly =
new Translate(
'', $conf);
371 $newlangfileonly->setDefaultLang($langcode);
373 $recordtoshow = array();
383 if (empty($langcode) || $langcode ==
'-1') $nbempty++;
384 if (empty($transkey)) $nbempty++;
385 if (empty($transvalue)) $nbempty++;
386 if ($action ==
'search' && ($nbempty > 999)) {
387 setEventMessages($langs->trans(
"WarningAtLeastKeyOrTranslationRequired"), null,
'warnings');
391 foreach ($modulesdir as $keydir => $tmpsearchdir)
393 $searchdir = $tmpsearchdir;
396 $dir_lang = dirname(dirname($searchdir)).
"/langs/".$langcode;
399 $filearray =
dol_dir_list($dir_lang_osencoded,
'files', 0,
'',
'', $sortfield, (strtolower($sortorder) ==
'asc' ?SORT_ASC:SORT_DESC), 1);
400 foreach ($filearray as $file)
402 $tmpfile = preg_replace(
'/.lang/i',
'', basename($file[
'name']));
403 $moduledirname = (basename(dirname(dirname($dir_lang))));
406 if ($i > 0) $langkey .=
'@'.$moduledirname;
409 $result = $newlang->load($langkey, 0, 0,
'', 0);
410 $result = $newlangfileonly->load($langkey, 0, 0,
'', 1);
411 if ($result < 0) print
'Failed to load language file '.$tmpfile.
'<br>'.
"\n";
412 else $nbtotaloffiles++;
419 foreach ($newlang->tab_translate as $key => $val)
421 if ($transkey && !preg_match(
'/'.preg_quote($transkey,
'/').
'/i', $key))
continue;
422 if ($transvalue && !preg_match(
'/'.preg_quote($transvalue,
'/').
'/i', $val))
continue;
423 $recordtoshow[$key] = $val;
428 $nbtotalofrecordswithoutfilters = count($newlang->tab_translate);
429 $nbtotalofrecords = count($recordtoshow);
431 if (($offset + $num) > $nbtotalofrecords) $num = $limit;
434 $title = $langs->trans(
"TranslationKeySearch");
435 if ($nbtotalofrecords > 0) $title .=
' <span class="opacitymedium colorblack paddingleft">('.$nbtotalofrecords.
' / '.$nbtotalofrecordswithoutfilters.
' - '.$nbtotaloffiles.
' '.$langs->trans(
"Files").
')</span>';
436 print_barre_liste($title, $page,
$_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder,
'', $num, -1 * $nbtotalofrecords,
'', 0,
'',
'', $limit, 0, 0, 1);
438 print
'<input type="hidden" id="action" name="action" value="search">';
439 print
'<input type="hidden" id="mode" name="mode" value="'.$mode.
'">';
441 print
'<div class="div-table-responsive-no-min">';
442 print
'<table class="noborder centpercent">';
443 print
'<tr class="liste_titre">';
448 print
'<td align="center"></td>';
454 print
'<tr class="oddeven"><td>';
456 print $formadmin->select_language($langcode,
'langcode', 0, null, 0, 0, 0,
'maxwidthonsmartphone', 1);
459 print
'<input type="text" class="flat maxwidthonsmartphone" name="transkey" value="'.$transkey.
'">';
461 print
'<input type="text" class="quatrevingtpercent" name="transvalue" value="'.$transvalue.
'">';
470 print
'<input type="hidden" name="entitysearch" value="'.$conf->entity.
'">';
474 print
'<td class="nowrap right">';
475 $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0,
'checkforselect', 1);
480 if ($sortfield ==
'transkey' && strtolower($sortorder) ==
'asc') ksort($recordtoshow);
481 if ($sortfield ==
'transkey' && strtolower($sortorder) ==
'desc') krsort($recordtoshow);
482 if ($sortfield ==
'transvalue' && strtolower($sortorder) ==
'asc') asort($recordtoshow);
483 if ($sortfield ==
'transvalue' && strtolower($sortorder) ==
'desc') arsort($recordtoshow);
487 foreach ($recordtoshow as $key => $val)
490 if ($i <= $offset)
continue;
491 if ($i > ($offset + $limit))
break;
492 print
'<tr class="oddeven"><td>'.$langcode.
'</td><td>'.$key.
'</td><td>';
494 print
'</td><td class="right nowraponall">';
495 if (!empty($newlangfileonly->tab_translate[$key])) {
496 if ($val != $newlangfileonly->tab_translate[$key]) {
498 $sql =
"SELECT rowid";
499 $sql .=
" FROM ".MAIN_DB_PREFIX.
"overwrite_trans";
500 $sql .=
" WHERE transkey = '".$db->escape($key).
"'";
501 $sql .=
" AND entity IN (".getEntity(
'overwrite_trans').
")";
502 dol_syslog(
"translation::select from table", LOG_DEBUG);
503 $result = $db->query($sql);
506 $obj = $db->fetch_object($result);
508 print
'<a class="editfielda reposition marginrightonly" href="'.$_SERVER[
'PHP_SELF'].
'?rowid='.$obj->rowid.
'&entity='.$conf->entity.
'&mode=overwrite&action=edit">'.
img_edit().
'</a>';
510 print
'<a class="marginleftonly marginrightonly" href="'.$_SERVER[
'PHP_SELF'].
'?rowid='.$obj->rowid.
'&entity='.$conf->entity.
'&mode='.urlencode($mode).
'&action=delete&mode='.urlencode($mode).
'&token='.
newToken().
'">'.
img_delete().
'</a>';
511 print
' ';
512 $htmltext = $langs->trans(
"OriginalValueWas",
'<i>'.$newlangfileonly->tab_translate[$key].
'</i>');
513 print $form->textwithpicto(
'', $htmltext, 1,
'info');
514 } elseif (!empty($conf->global->MAIN_ENABLE_OVERWRITE_TRANSLATION)) {
516 print
'<a class="reposition paddingrightonly" href="'.$_SERVER[
'PHP_SELF'].
'?mode=overwrite&langcode='.urlencode($langcode).
'&transkey='.urlencode($key).
'">'.
img_edit_add($langs->trans(
"Overwrite")).
'</a>';
519 if (!empty($conf->global->MAIN_FEATURES_LEVEL))
521 $transifexlangfile =
'$';
523 $transifexurl =
'https://www.transifex.com/dolibarr-association/dolibarr/translate/#'.$langcode.
'/'.$transifexlangfile.
'?q=key%3A'.$key;
525 print
' <a href="'.$transifexurl.
'" target="transifex">'.
img_picto($langs->trans(
'FixOnTransifex'),
'globe').
'</a>';
528 $htmltext = $langs->trans(
"TransKeyWithoutOriginalValue", $key);
529 print $form->textwithpicto(
'', $htmltext, 1,
'warning');
535 print
'</td></tr>'.
"\n";
546 if (!empty($langcode))
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
dolGetModulesDirs($subdir= '')
Return list of modules directories.
dolibarr_set_const($db, $name, $value, $type= 'chaine', $visible=0, $note= '', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
translation_prepare_head()
Prepare array with list of tabs.
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save"&&empty($cancel)) $wikihelp
View.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
print_barre_liste($titre, $page, $file, $options= '', $sortfield= '', $sortorder= '', $morehtmlcenter= '', $num=-1, $totalnboflines= '', $picto= 'generic', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow= '')
Print a title with navigation controls for pagination.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage translations.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
print $_SERVER["PHP_SELF"]
Edit parameters.
img_edit_add($titlealt= 'default', $other= '')
Show logo +.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_info($titlealt= 'default')
Show info logo.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
img_delete($titlealt= 'default', $other= 'class="pictodelete"', $morecss= '')
Show delete logo.
dol_set_focus($selector)
Set focus onto field with selector (similar behaviour of 'autofocus' HTML5 tag)
picto_from_langcode($codelang, $moreatt= '')
Return img flag of country for a language code or country code.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...