2012-03-07 14:27:17 +01:00
< ? php
2017-06-16 17:01:43 +02:00
/* Copyright ( C ) 2007 - 2016 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2009 - 2017 Regis Houssin < regis . houssin @ capnetworks . com >
2017-10-16 21:22:13 +02:00
* Copyright ( C ) 2017 Frédéric France < frederic . france @ free . fr >
2012-03-07 14:27:17 +01:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2012-03-07 14:27:17 +01:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http :// www . gnu . org / licenses />.
*/
/**
* \file htdocs / admin / translation . php
* \brief Page to show translation information
*/
2012-08-22 23:24:21 +02:00
require '../main.inc.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php' ;
2016-09-04 14:45:43 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2016-03-29 18:05:03 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formadmin.class.php' ;
2012-03-07 14:27:17 +01:00
2018-05-26 18:52:14 +02:00
// Load translation files required by the page
2017-11-25 22:51:44 +01:00
$langs -> loadLangs ( array ( " companies " , " products " , " admin " , " sms " , " other " , " errors " ));
2012-03-07 14:27:17 +01:00
if ( ! $user -> admin ) accessforbidden ();
2016-01-16 00:48:14 +01:00
$id = GETPOST ( 'rowid' , 'int' );
$action = GETPOST ( 'action' , 'alpha' );
2016-09-04 14:45:43 +02:00
2016-01-16 00:48:14 +01:00
$langcode = GETPOST ( 'langcode' , 'alpha' );
$transkey = GETPOST ( 'transkey' , 'alpha' );
$transvalue = GETPOST ( 'transvalue' , 'alpha' );
2012-03-07 14:27:17 +01:00
2016-09-04 14:45:43 +02:00
2018-07-09 15:25:14 +02:00
$mode = GETPOST ( 'mode' , 'aZ09' ) ? GETPOST ( 'mode' , 'aZ09' ) : 'overwrite' ;
2016-09-03 18:47:04 +02:00
2017-06-08 14:55:12 +02:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2016-08-28 22:45:32 +02:00
$sortfield = GETPOST ( " sortfield " , 'alpha' );
$sortorder = GETPOST ( " sortorder " , 'alpha' );
$page = GETPOST ( " page " , 'int' );
2017-06-06 10:53:53 +02:00
if ( empty ( $page ) || $page == - 1 ) { $page = 0 ; } // If $page is not defined, or '' or -1
2016-08-28 22:45:32 +02:00
$offset = $limit * $page ;
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
if ( ! $sortfield ) $sortfield = 'lang,transkey' ;
if ( ! $sortorder ) $sortorder = 'ASC' ;
2017-06-16 17:01:43 +02:00
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager -> initHooks ( array ( 'admintranslation' , 'globaladmin' ));
2012-03-07 14:27:17 +01:00
2016-09-04 15:06:34 +02:00
/*
* Actions
*/
2017-09-15 10:50:50 +02:00
if ( GETPOST ( 'cancel' , 'alpha' )) { $action = 'list' ; $massaction = '' ; }
if ( ! GETPOST ( 'confirmmassaction' , 'alpha' ) && $massaction != 'presend' && $massaction != 'confirm_presend' ) { $massaction = '' ; }
2016-09-04 15:06:34 +02:00
$parameters = array ( 'socid' => $socid );
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
if ( $reshook < 0 ) setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
include DOL_DOCUMENT_ROOT . '/core/actions_changeselectedfields.inc.php' ;
// Purge search criteria
2017-07-13 00:35:10 +02:00
if ( GETPOST ( 'button_removefilter_x' , 'alpha' ) || GETPOST ( 'button_removefilter.x' , 'alpha' ) || GETPOST ( 'button_removefilter' , 'alpha' )) // All tests are required to be compatible with all browsers
2016-09-04 15:06:34 +02:00
{
$transkey = '' ;
$transvalue = '' ;
$toselect = '' ;
$search_array_options = array ();
}
2017-05-09 10:08:04 +02:00
if ( $action == 'setMAIN_ENABLE_OVERWRITE_TRANSLATION' )
{
if ( GETPOST ( 'value' )) dolibarr_set_const ( $db , 'MAIN_ENABLE_OVERWRITE_TRANSLATION' , 1 , 'chaine' , 0 , '' , $conf -> entity );
else dolibarr_set_const ( $db , 'MAIN_ENABLE_OVERWRITE_TRANSLATION' , 0 , 'chaine' , 0 , '' , $conf -> entity );
}
2017-09-10 22:46:08 +02:00
if ( $action == 'update' )
{
if ( $transvalue == '' )
{
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " NewTranslationStringToShow " )), null , 'errors' );
$error ++ ;
}
if ( ! $error )
{
$db -> begin ();
$sql = " UPDATE " . MAIN_DB_PREFIX . " overwrite_trans set transvalue = ' " . $db -> escape ( $transvalue ) . " ' WHERE rowid = " . GETPOST ( 'rowid' , 'int' );
$result = $db -> query ( $sql );
if ( $result > 0 )
{
$db -> commit ();
setEventMessages ( $langs -> trans ( " RecordSaved " ), null , 'mesgs' );
$action = " " ;
$transkey = " " ;
$transvalue = " " ;
}
else
{
$db -> rollback ();
if ( $db -> lasterrno () == 'DB_ERROR_RECORD_ALREADY_EXISTS' )
{
setEventMessages ( $langs -> trans ( " WarningAnEntryAlreadyExistForTransKey " ), null , 'warnings' );
}
else
{
setEventMessages ( $db -> lasterror (), null , 'errors' );
}
$action = '' ;
}
}
}
if ( $action == 'add' )
2016-01-16 00:48:14 +01:00
{
$error = 0 ;
if ( empty ( $langcode ))
{
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Language " )), null , 'errors' );
$error ++ ;
}
if ( $transkey == '' )
{
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Key " )), null , 'errors' );
$error ++ ;
}
if ( $transvalue == '' )
{
2016-08-28 22:45:32 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " NewTranslationStringToShow " )), null , 'errors' );
2016-01-16 00:48:14 +01:00
$error ++ ;
}
if ( ! $error )
{
2017-04-14 11:22:48 +02:00
$db -> begin ();
2017-06-10 00:05:47 +02:00
2017-04-14 11:22:48 +02:00
$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 ) . " ) " ;
2016-01-16 00:48:14 +01:00
$result = $db -> query ( $sql );
if ( $result > 0 )
{
2017-04-14 11:22:48 +02:00
$db -> commit ();
setEventMessages ( $langs -> trans ( " RecordSaved " ), null , 'mesgs' );
2016-01-16 00:48:14 +01:00
$action = " " ;
$transkey = " " ;
$transvalue = " " ;
}
else
{
2017-04-27 17:20:40 +02:00
$db -> rollback ();
2017-04-27 12:48:13 +02:00
if ( $db -> lasterrno () == 'DB_ERROR_RECORD_ALREADY_EXISTS' )
{
setEventMessages ( $langs -> trans ( " WarningAnEntryAlreadyExistForTransKey " ), null , 'warnings' );
}
2017-06-10 00:05:47 +02:00
else
2017-04-27 17:20:40 +02:00
{
setEventMessages ( $db -> lasterror (), null , 'errors' );
2017-10-16 21:22:13 +02:00
}
2016-01-16 00:48:14 +01:00
$action = '' ;
}
}
}
// Delete line from delete picto
if ( $action == 'delete' )
{
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " overwrite_trans WHERE rowid = " . $db -> escape ( $id );
$result = $db -> query ( $sql );
if ( $result >= 0 )
{
setEventMessages ( $langs -> trans ( " RecordDeleted " ), null , 'mesgs' );
}
else
{
dol_print_error ( $db );
}
}
2012-03-07 14:27:17 +01:00
/*
* View
*/
2017-09-08 10:09:22 +02:00
$form = new Form ( $db );
2016-03-29 18:05:03 +02:00
$formadmin = new FormAdmin ( $db );
2012-03-07 14:27:17 +01:00
$wikihelp = 'EN:Setup|FR:Paramétrage|ES:Configuración' ;
llxHeader ( '' , $langs -> trans ( " Setup " ), $wikihelp );
2017-06-10 00:05:47 +02:00
$param = '&mode=' . $mode ;
2012-03-07 14:27:17 +01:00
2017-10-17 14:03:22 +02:00
$enabledisablehtml = '' ;
2017-10-31 12:25:06 +01:00
$enabledisablehtml .= $langs -> trans ( " EnableOverwriteTranslation " ) . ' ' ;
2017-05-09 10:08:04 +02:00
if ( empty ( $conf -> global -> MAIN_ENABLE_OVERWRITE_TRANSLATION ))
{
// Button off, click to enable
2017-06-10 00:05:47 +02:00
$enabledisablehtml .= '<a class="reposition" href="' . $_SERVER [ " PHP_SELF " ] . '?action=setMAIN_ENABLE_OVERWRITE_TRANSLATION&value=1' . $param . '">' ;
2017-10-20 21:39:19 +02:00
$enabledisablehtml .= img_picto ( $langs -> trans ( " Disabled " ), 'switch_off' );
2017-06-10 00:05:47 +02:00
$enabledisablehtml .= '</a>' ;
2017-05-09 10:08:04 +02:00
}
else
{
// Button on, click to disable
2017-06-10 00:05:47 +02:00
$enabledisablehtml .= '<a class="reposition" href="' . $_SERVER [ " PHP_SELF " ] . '?action=setMAIN_ENABLE_OVERWRITE_TRANSLATION&value=0' . $param . '">' ;
2017-10-20 21:39:19 +02:00
$enabledisablehtml .= img_picto ( $langs -> trans ( " Activated " ), 'switch_on' );
2017-06-10 00:05:47 +02:00
$enabledisablehtml .= '</a>' ;
2017-05-09 10:08:04 +02:00
}
2017-06-10 00:05:47 +02:00
print load_fiche_titre ( $langs -> trans ( " Translation " ), $enabledisablehtml , 'title_setup' );
2017-10-17 13:05:55 +02:00
//print '<span class="opacitymedium">';
2017-06-10 00:05:47 +02:00
print $langs -> trans ( " TranslationDesc " ) . " <br> \n " ;
2017-10-17 13:05:55 +02:00
//print '</span>';
2017-06-10 00:05:47 +02:00
print " <br> \n " ;
$current_language_code = $langs -> defaultlang ;
$s = picto_from_langcode ( $current_language_code );
print $langs -> trans ( " CurrentUserLanguage " ) . ': <strong>' . $s . ' ' . $current_language_code . '</strong><br>' ;
print '<br>' ;
2017-05-09 10:08:04 +02:00
2016-09-04 14:45:43 +02:00
if ( ! empty ( $contextpage ) && $contextpage != $_SERVER [ " PHP_SELF " ]) $param .= '&contextpage=' . $contextpage ;
if ( $limit > 0 && $limit != $conf -> liste_limit ) $param .= '&limit=' . $limit ;
if ( $optioncss != '' ) $param .= '&optioncss=' . $optioncss ;
if ( $langcode ) $param .= '&langcode=' . urlencode ( $langcode );
if ( $transkey ) $param .= '&transkey=' . urlencode ( $transkey );
if ( $transvalue ) $param .= '&transvalue=' . urlencode ( $transvalue );
2016-09-03 18:47:04 +02:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . (( empty ( $user -> entity ) && $debug ) ? '?debug=1' : '' ) . '" method="POST">' ;
2016-09-04 14:45:43 +02:00
if ( $optioncss != '' ) print '<input type="hidden" name="optioncss" value="' . $optioncss . '">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">' ;
print '<input type="hidden" name="sortfield" value="' . $sortfield . '">' ;
print '<input type="hidden" name="sortorder" value="' . $sortorder . '">' ;
2017-05-21 02:43:51 +02:00
print '<input type="hidden" name="page" value="' . $page . '">' ;
2016-09-03 18:47:04 +02:00
$head = translation_prepare_head ();
2017-03-23 10:59:13 +01:00
dol_fiche_head ( $head , $mode , '' , - 1 , '' );
2016-09-03 18:47:04 +02:00
if ( $mode == 'overwrite' )
2016-01-16 00:48:14 +01:00
{
2016-09-03 18:47:04 +02:00
//print load_fiche_titre($langs->trans("TranslationOverwriteKey"), '', '')."\n";
2016-09-04 14:45:43 +02:00
2017-11-23 09:49:15 +01:00
$disabled = '' ;
if ( $action == 'edit' || empty ( $conf -> global -> MAIN_ENABLE_OVERWRITE_TRANSLATION )) $disabled = ' disabled="disabled"' ;
$disablededit = '' ;
if ( $action == 'edit' || empty ( $conf -> global -> MAIN_ENABLE_OVERWRITE_TRANSLATION )) $disablededit = ' disabled' ;
2017-10-17 14:03:22 +02:00
print '<div class="justify"><span class="opacitymedium">' ;
2016-09-04 14:45:43 +02:00
print img_info () . ' ' . $langs -> trans ( " SomeTranslationAreUncomplete " );
$urlwikitranslatordoc = 'https://wiki.dolibarr.org/index.php/Translator_documentation' ;
2018-04-08 10:49:59 +02:00
print ' (' . $langs -> trans ( " SeeAlso " , '<a href="' . $urlwikitranslatordoc . '" target="_blank">' . $langs -> trans ( " Here " ) . '</a>' ) . ')<br>' ;
2016-09-04 14:45:43 +02:00
print $langs -> trans ( " TranslationOverwriteDesc " , $langs -> transnoentitiesnoconv ( " Language " ), $langs -> transnoentitiesnoconv ( " Key " ), $langs -> transnoentitiesnoconv ( " NewTranslationStringToShow " )) . " \n " ;
print ' (' . $langs -> trans ( " TranslationOverwriteDesc2 " ) . ').' . " <br> \n " ;
2017-10-17 14:03:22 +02:00
print '</span></div>' ;
2016-09-04 14:45:43 +02:00
print '<br>' ;
2017-06-10 00:05:47 +02:00
2017-09-10 22:46:08 +02:00
print '<input type="hidden" name="action" value="' . ( $action == 'edit' ? 'update' : 'add' ) . '">' ;
2016-09-03 18:47:04 +02:00
print '<input type="hidden" id="mode" name="mode" value="' . $mode . '">' ;
2017-06-10 00:05:47 +02:00
2017-09-08 10:09:22 +02:00
print '<div class="div-table-responsive-no-min">' ;
2016-09-03 18:47:04 +02:00
print '<table class="noborder" width="100%">' ;
print '<tr class="liste_titre">' ;
2017-08-02 13:31:53 +02:00
print_liste_field_titre ( $langs -> trans ( " Language " ) . ' (en_US, es_MX, ...)' , $_SERVER [ " PHP_SELF " ], 'lang,transkey' , '' , $param , '' , $sortfield , $sortorder );
print_liste_field_titre ( " Key " , $_SERVER [ " PHP_SELF " ], 'transkey' , '' , $param , '' , $sortfield , $sortorder );
print_liste_field_titre ( " NewTranslationStringToShow " , $_SERVER [ " PHP_SELF " ], 'transvalue' , '' , $param , '' , $sortfield , $sortorder );
//if (! empty($conf->multicompany->enabled) && !$user->entity) print_liste_field_titre("Entity"),$_SERVER["PHP_SELF"],'entity,transkey','',$param,'',$sortfield,$sortorder);
2016-09-03 18:47:04 +02:00
print '<td align="center"></td>' ;
print " </tr> \n " ;
2017-06-10 00:05:47 +02:00
2016-09-03 18:47:04 +02:00
// Line to add new record
print " \n " ;
2017-06-10 00:05:47 +02:00
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven"><td>' ;
2017-09-10 22:46:08 +02:00
print $formadmin -> select_language ( GETPOST ( 'langcode' ), 'langcode' , 0 , null , 1 , 0 , $disablededit ? 1 : 0 , 'maxwidthonsmartphone' , 1 );
2016-09-03 18:47:04 +02:00
print '</td>' . " \n " ;
print '<td>' ;
2017-11-02 16:14:24 +01:00
print '<input type="text" class="flat maxwidthonsmartphone"' . $disablededit . ' name="transkey" id="transkey" value="' . ( ! empty ( $transkey ) ? $transkey : " " ) . '">' ;
2016-09-03 18:47:04 +02:00
print '</td><td>' ;
2017-11-02 16:14:24 +01:00
print '<input type="text" class="quatrevingtpercent"' . $disablededit . ' name="transvalue" id="transvalue" value="' . ( ! empty ( $transvalue ) ? $transvalue : " " ) . '">' ;
2016-09-03 18:47:04 +02:00
print '</td>' ;
// Limit to superadmin
2016-10-28 22:47:37 +02:00
/* if ( ! empty ( $conf -> multicompany -> enabled ) && ! $user -> entity )
2016-09-03 18:47:04 +02:00
{
print '<td>' ;
print '<input type="text" class="flat" size="1" name="entity" value="' . $conf -> entity . '">' ;
print '</td>' ;
print '<td align="center">' ;
}
else
2016-10-28 22:47:37 +02:00
{ */
2016-09-03 18:47:04 +02:00
print '<td align="center">' ;
print '<input type="hidden" name="entity" value="' . $conf -> entity . '">' ;
2016-10-28 22:47:37 +02:00
//}
2017-11-23 09:49:15 +01:00
print '<input type="submit" class="button"' . $disabled . ' value="' . $langs -> trans ( " Add " ) . '" name="add" title="' . dol_escape_htmltag ( $langs -> trans ( " YouMustEnabledTranslationOverwriteBefore " )) . '">' ;
2016-09-03 18:47:04 +02:00
print " </td> \n " ;
print '</tr>' ;
2017-06-10 00:05:47 +02:00
2016-09-03 18:47:04 +02:00
// Show constants
2017-04-14 11:22:48 +02:00
$sql = " SELECT rowid, entity, lang, transkey, transvalue " ;
2016-09-03 18:47:04 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " overwrite_trans " ;
$sql .= " WHERE 1 = 1 " ;
2017-10-17 13:05:55 +02:00
$sql .= " AND entity IN ( " . getEntity ( 'overwrite_trans' ) . " ) " ;
2016-09-03 18:47:04 +02:00
$sql .= $db -> order ( $sortfield , $sortorder );
2017-06-10 00:05:47 +02:00
2016-09-03 18:47:04 +02:00
dol_syslog ( " translation::select from table " , LOG_DEBUG );
$result = $db -> query ( $sql );
if ( $result )
{
$num = $db -> num_rows ( $result );
$i = 0 ;
2017-06-10 00:05:47 +02:00
2016-09-03 18:47:04 +02:00
while ( $i < $num )
{
$obj = $db -> fetch_object ( $result );
2017-06-10 00:05:47 +02:00
2016-09-03 18:47:04 +02:00
print " \n " ;
2017-06-10 00:05:47 +02:00
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2017-06-10 00:05:47 +02:00
2016-09-03 18:47:04 +02:00
print '<td>' . $obj -> lang . '</td>' . " \n " ;
print '<td>' . $obj -> transkey . '</td>' . " \n " ;
2017-06-10 00:05:47 +02:00
2016-09-03 18:47:04 +02:00
// Value
print '<td>' ;
/* print '<input type="hidden" name="const[' . $i . '][rowid]" value="' . $obj -> rowid . '">' ;
print '<input type="hidden" name="const[' . $i . '][lang]" value="' . $obj -> lang . '">' ;
print '<input type="hidden" name="const[' . $i . '][name]" value="' . $obj -> transkey . '">' ;
print '<input type="text" id="value_' . $i . '" class="flat inputforupdate" size="30" name="const[' . $i . '][value]" value="' . dol_escape_htmltag ( $obj -> transvalue ) . '">' ;
*/
2017-09-10 22:46:08 +02:00
if ( $action == 'edit' && $obj -> rowid == GETPOST ( 'rowid' , 'int' ))
{
print '<input type="text" class="quatrevingtpercent" name="transvalue" value="' . $obj -> transvalue . '">' ;
}
else
{
print $obj -> transvalue ;
}
2016-09-03 18:47:04 +02:00
print '</td>' ;
2017-06-10 00:05:47 +02:00
2016-09-03 18:47:04 +02:00
print '<td align="center">' ;
2017-09-10 22:46:08 +02:00
if ( $action == 'edit' && $obj -> rowid == GETPOST ( 'rowid' , 'int' ))
{
print '<input type="hidden" class="button" name="rowid" value="' . $obj -> rowid . '">' ;
print '<input type="submit" class="button" name="save" value="' . dol_escape_htmltag ( $langs -> trans ( " Save " )) . '">' ;
print ' ' ;
print '<input type="submit" class="button" name="cancel" value="' . dol_escape_htmltag ( $langs -> trans ( " Cancel " )) . '">' ;
}
else
{
print '<a href="' . $_SERVER [ 'PHP_SELF' ] . '?rowid=' . $obj -> rowid . '&entity=' . $obj -> entity . '&action=edit' . (( empty ( $user -> entity ) && $debug ) ? '&debug=1' : '' ) . '">' . img_edit () . '</a>' ;
print ' ' ;
print '<a href="' . $_SERVER [ 'PHP_SELF' ] . '?rowid=' . $obj -> rowid . '&entity=' . $obj -> entity . '&action=delete' . (( empty ( $user -> entity ) && $debug ) ? '&debug=1' : '' ) . '">' . img_delete () . '</a>' ;
}
2016-09-03 18:47:04 +02:00
print '</td>' ;
2017-06-10 00:05:47 +02:00
2016-09-03 18:47:04 +02:00
print " </tr> \n " ;
print " \n " ;
$i ++ ;
}
}
2017-06-10 00:05:47 +02:00
2016-09-03 18:47:04 +02:00
print '</table>' ;
2017-09-08 10:09:22 +02:00
print '</div>' ;
2016-01-16 00:48:14 +01:00
}
2016-09-04 14:45:43 +02:00
if ( $mode == 'searchkey' )
{
2016-09-04 14:58:58 +02:00
$langcode = GETPOST ( 'langcode' ) ? GETPOST ( 'langcode' ) : $langs -> defaultlang ;
2017-06-10 00:05:47 +02:00
2016-09-04 14:58:58 +02:00
$newlang = new Translate ( '' , $conf );
$newlang -> setDefaultLang ( $langcode );
$newlangfileonly = new Translate ( '' , $conf );
$newlangfileonly -> setDefaultLang ( $langcode );
2017-06-10 00:05:47 +02:00
2016-09-04 14:45:43 +02:00
$recordtoshow = array ();
2017-06-10 00:05:47 +02:00
2017-11-01 19:58:46 +01:00
// Search modules dirs
$modulesdir = dolGetModulesDirs ();
2017-11-25 22:51:44 +01:00
$nbtotaloffiles = 0 ;
2016-09-04 14:45:43 +02:00
$nbempty = 0 ;
/* var_dump ( $langcode );
var_dump ( $transkey );
var_dump ( $transvalue ); */
if ( empty ( $langcode ) || $langcode == '-1' ) $nbempty ++ ;
if ( empty ( $transkey )) $nbempty ++ ;
if ( empty ( $transvalue )) $nbempty ++ ;
2016-09-04 15:06:34 +02:00
if ( $action == 'search' && ( $nbempty > 999 )) // 999 to disable this
2016-09-04 14:45:43 +02:00
{
setEventMessages ( $langs -> trans ( " WarningAtLeastKeyOrTranslationRequired " ), null , 'warnings' );
}
else
{
2017-11-01 19:58:46 +01:00
// Search into dir of modules (the $modulesdir is already a list that loop on $conf->file->dol_document_root)
2017-11-25 22:51:44 +01:00
$i = 0 ;
2017-11-01 19:58:46 +01:00
foreach ( $modulesdir as $keydir => $tmpsearchdir )
2016-09-04 14:45:43 +02:00
{
2017-11-01 19:58:46 +01:00
$searchdir = $tmpsearchdir ; // $searchdir can be '.../htdocs/core/modules/' or '.../htdocs/custom/mymodule/core/modules/'
// Directory of translation files
$dir_lang = dirname ( dirname ( $searchdir )) . " /langs/ " . $langcode ; // The 2 dirname is to go up in dir for 2 levels
$dir_lang_osencoded = dol_osencode ( $dir_lang );
$filearray = dol_dir_list ( $dir_lang_osencoded , 'files' , 0 , '' , '' , $sortfield ,( strtolower ( $sortorder ) == 'asc' ? SORT_ASC : SORT_DESC ), 1 );
foreach ( $filearray as $file )
{
2018-01-11 01:14:20 +01:00
$tmpfile = preg_replace ( '/.lang/i' , '' , basename ( $file [ 'name' ]));
$moduledirname = ( basename ( dirname ( dirname ( $dir_lang ))));
2017-11-25 22:51:44 +01:00
2018-01-11 01:14:20 +01:00
$langkey = $tmpfile ;
if ( $i > 0 ) $langkey .= '@' . $moduledirname ;
//var_dump($i.' - '.$keydir.' - '.$dir_lang_osencoded.' -> '.$moduledirname . ' / ' . $tmpfile.' -> '.$langkey);
2017-11-25 22:51:44 +01:00
2018-01-11 01:14:20 +01:00
$result = $newlang -> load ( $langkey , 0 , 0 , '' , 0 ); // Load translation files + database overwrite
2017-11-25 22:51:44 +01:00
$result = $newlangfileonly -> load ( $langkey , 0 , 0 , '' , 1 ); // Load translation files only
if ( $result < 0 ) print 'Failed to load language file ' . $tmpfile . '<br>' . " \n " ;
else $nbtotaloffiles ++ ;
//print 'After loading lang '.$langkey.', newlang has '.count($newlang->tab_translate).' records<br>'."\n";
2017-11-01 19:58:46 +01:00
}
2017-11-25 22:51:44 +01:00
$i ++ ;
2016-09-04 14:45:43 +02:00
}
2017-06-10 00:05:47 +02:00
2016-09-04 14:45:43 +02:00
// Now search into translation array
foreach ( $newlang -> tab_translate as $key => $val )
{
2018-01-10 10:42:36 +01:00
if ( $transkey && ! preg_match ( '/' . preg_quote ( $transkey , '/' ) . '/i' , $key )) continue ;
if ( $transvalue && ! preg_match ( '/' . preg_quote ( $transvalue , '/' ) . '/i' , $val )) continue ;
2016-09-04 14:45:43 +02:00
$recordtoshow [ $key ] = $val ;
}
}
2017-06-10 00:05:47 +02:00
2016-09-04 14:45:43 +02:00
//print '<br>';
$nbtotalofrecordswithoutfilters = count ( $newlang -> tab_translate );
$nbtotalofrecords = count ( $recordtoshow );
$num = $limit + 1 ;
if (( $offset + $num ) > $nbtotalofrecords ) $num = $limit ;
2017-06-10 00:05:47 +02:00
2016-09-04 14:45:43 +02:00
//print 'param='.$param.' $_SERVER["PHP_SELF"]='.$_SERVER["PHP_SELF"].' num='.$num.' page='.$page.' nbtotalofrecords='.$nbtotalofrecords." sortfield=".$sortfield." sortorder=".$sortorder;
$title = $langs -> trans ( " TranslationKeySearch " );
2017-11-25 22:51:44 +01:00
if ( $nbtotalofrecords > 0 ) $title .= ' (' . $nbtotalofrecords . ' / ' . $nbtotalofrecordswithoutfilters . ' - ' . $nbtotaloffiles . ' ' . $langs -> trans ( " Files " ) . ')' ;
2016-09-04 14:45:43 +02:00
print print_barre_liste ( $title , $page , $_SERVER [ " PHP_SELF " ], $param , $sortfield , $sortorder , '' , $num , - 1 * $nbtotalofrecords , '' , 0 , '' , '' , $limit ) . " \n " ;
print '<input type="hidden" id="action" name="action" value="search">' ;
print '<input type="hidden" id="mode" name="mode" value="' . $mode . '">' ;
2017-09-08 10:09:22 +02:00
print '<div class="div-table-responsive-no-min">' ;
2016-09-04 14:45:43 +02:00
print '<table class="noborder" width="100%">' ;
print '<tr class="liste_titre">' ;
2017-08-02 13:31:53 +02:00
print_liste_field_titre ( $langs -> trans ( " Language " ) . ' (en_US, es_MX, ...)' , $_SERVER [ " PHP_SELF " ], 'lang,transkey' , '' , $param , '' , $sortfield , $sortorder ) . '</td>' ;
print_liste_field_titre ( " Key " , $_SERVER [ " PHP_SELF " ], 'transkey' , '' , $param , '' , $sortfield , $sortorder );
print_liste_field_titre ( " CurrentTranslationString " , $_SERVER [ " PHP_SELF " ], 'transvalue' , '' , $param , '' , $sortfield , $sortorder );
//if (! empty($conf->multicompany->enabled) && !$user->entity) print_liste_field_titre("Entity",$_SERVER["PHP_SELF"],'entity,transkey','',$param,'',$sortfield,$sortorder);
2016-09-04 14:45:43 +02:00
print '<td align="center"></td>' ;
print " </tr> \n " ;
// Line to search new record
print " \n " ;
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven"><td>' ;
2016-09-04 14:45:43 +02:00
//print $formadmin->select_language($langcode,'langcode',0,null,$langs->trans("All"),0,0,'',1);
print $formadmin -> select_language ( $langcode , 'langcode' , 0 , null , 0 , 0 , 0 , 'maxwidthonsmartphone' , 1 );
print '</td>' . " \n " ;
print '<td>' ;
print '<input type="text" class="flat maxwidthonsmartphone" name="transkey" value="' . $transkey . '">' ;
print '</td><td>' ;
print '<input type="text" class="quatrevingtpercent" name="transvalue" value="' . $transvalue . '">' ;
// Limit to superadmin
2016-10-28 22:47:37 +02:00
/* if ( ! empty ( $conf -> multicompany -> enabled ) && ! $user -> entity )
2016-09-04 14:45:43 +02:00
{
2016-09-04 15:06:34 +02:00
print '</td><td>' ;
2016-09-04 14:45:43 +02:00
print '<input type="text" class="flat" size="1" name="entitysearch" value="' . $conf -> entity . '">' ;
}
else
2016-10-28 22:47:37 +02:00
{ */
2016-09-04 14:45:43 +02:00
print '<input type="hidden" name="entitysearch" value="' . $conf -> entity . '">' ;
2016-10-28 22:47:37 +02:00
//}
2017-06-10 00:05:47 +02:00
print '</td>' ;
2016-09-04 15:06:34 +02:00
// Action column
2017-10-16 21:22:13 +02:00
print '<td class="nowrap" align="right">' ;
2017-05-14 21:06:33 +02:00
$searchpicto = $form -> showFilterAndCheckAddButtons ( $massactionbutton ? 1 : 0 , 'checkforselect' , 1 );
print $searchpicto ;
2016-09-04 15:06:34 +02:00
print '</td>' ;
2016-09-04 14:45:43 +02:00
print '</tr>' ;
2017-06-10 00:05:47 +02:00
2016-09-04 14:45:43 +02:00
if ( $sortfield == 'transkey' && strtolower ( $sortorder ) == 'asc' ) ksort ( $recordtoshow );
if ( $sortfield == 'transkey' && strtolower ( $sortorder ) == 'desc' ) krsort ( $recordtoshow );
if ( $sortfield == 'transvalue' && strtolower ( $sortorder ) == 'asc' ) asort ( $recordtoshow );
if ( $sortfield == 'transvalue' && strtolower ( $sortorder ) == 'desc' ) arsort ( $recordtoshow );
2017-06-10 00:05:47 +02:00
2016-09-04 14:45:43 +02:00
// Show result
$i = 0 ;
foreach ( $recordtoshow as $key => $val )
{
$i ++ ;
if ( $i <= $offset ) continue ;
if ( $i > ( $offset + $limit )) break ;
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven"><td>' . $langcode . '</td><td>' . $key . '</td><td>' ;
2016-09-04 14:45:43 +02:00
print dol_escape_htmltag ( $val );
2016-09-04 14:58:58 +02:00
print '</td><td align="right">' ;
2017-04-27 12:48:13 +02:00
if ( ! empty ( $newlangfileonly -> tab_translate [ $key ]))
2016-09-04 14:58:58 +02:00
{
2017-06-10 00:05:47 +02:00
if ( $val != $newlangfileonly -> tab_translate [ $key ])
2017-04-27 12:48:13 +02:00
{
2017-10-16 21:22:13 +02:00
// retrieve rowid
$sql = " SELECT rowid " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " overwrite_trans " ;
$sql .= " WHERE transkey = ' " . $key . " ' " ;
2017-10-17 13:05:55 +02:00
$sql .= " AND entity IN ( " . getEntity ( 'overwrite_trans' ) . " ) " ;
2017-10-16 21:22:13 +02:00
dol_syslog ( " translation::select from table " , LOG_DEBUG );
$result = $db -> query ( $sql );
if ( $result )
{
$obj = $db -> fetch_object ( $result );
}
print '<a href="' . $_SERVER [ 'PHP_SELF' ] . '?rowid=' . $obj -> rowid . '&entity=' . $conf -> entity . '&action=edit">' . img_edit () . '</a>' ;
print ' ' ;
print '<a href="' . $_SERVER [ 'PHP_SELF' ] . '?rowid=' . $obj -> rowid . '&entity=' . $conf -> entity . '&action=delete">' . img_delete () . '</a>' ;
print ' ' ;
2017-04-27 12:48:13 +02:00
$htmltext = $langs -> trans ( " OriginalValueWas " , $newlangfileonly -> tab_translate [ $key ]);
print $form -> textwithpicto ( '' , $htmltext , 1 , 'info' );
}
2017-10-16 21:22:13 +02:00
else if ( ! empty ( $conf -> global -> MAIN_ENABLE_OVERWRITE_TRANSLATION ))
{
2017-10-17 13:05:55 +02:00
//print $key.'-'.$val;
print '<a href="' . $_SERVER [ 'PHP_SELF' ] . '?mode=overwrite&langcode=' . $langcode . '&transkey=' . $key . '">' . img_edit_add ( $langs -> trans ( " Overwrite " )) . '</a>' ;
}
if ( ! empty ( $conf -> global -> MAIN_FEATURES_LEVEL ))
{
$transifexlangfile = '$' ; // $ means 'All'
2018-04-09 13:57:09 +02:00
//$transifexurl = 'https://www.transifex.com/dolibarr-association/dolibarr/translate/#'.$langcode.'/'.$transifexlangfile.'?key='.$key;
$transifexurl = 'https://www.transifex.com/dolibarr-association/dolibarr/translate/#' . $langcode . '/' . $transifexlangfile . '?q=key%3A' . $key ;
2017-10-17 13:05:55 +02:00
print ' <a href="' . $transifexurl . '" target="transifex">' . img_picto ( 'FixOnTransifex' , 'object_globe' ) . '</a>' ;
2017-10-16 21:22:13 +02:00
}
2017-04-27 12:48:13 +02:00
}
else
2016-09-04 14:58:58 +02:00
{
2017-04-27 12:48:13 +02:00
$htmltext = $langs -> trans ( " TransKeyWithoutOriginalValue " , $key );
2016-09-04 14:58:58 +02:00
print $form -> textwithpicto ( '' , $htmltext , 1 , 'warning' );
}
2016-10-29 16:18:39 +02:00
/* if ( ! empty ( $conf -> multicompany -> enabled ) && ! $user -> entity )
2016-10-28 22:47:37 +02:00
{
2017-04-14 11:22:48 +02:00
print '<td>' . $val . '</td>' ;
2016-10-29 16:18:39 +02:00
} */
2016-09-04 14:45:43 +02:00
print '</td></tr>' . " \n " ;
}
print '</table>' ;
2017-09-08 10:09:22 +02:00
print '</div>' ;
2016-09-04 14:45:43 +02:00
}
2016-09-03 18:47:04 +02:00
dol_fiche_end ();
2016-01-16 00:48:14 +01:00
print " </form> \n " ;
2017-11-02 16:14:24 +01:00
if ( ! empty ( $langcode ))
{
dol_set_focus ( '#transvalue' );
}
2012-03-07 14:27:17 +01:00
llxFooter ();
$db -> close ();