7 * @link http://www.open-emr.org
8 * @author bradymiller <bradymiller>
9 * @author sunsetsystems <sunsetsystems>
10 * @author andres_paglayan <andres_paglayan>
11 * @author Wakie87 <scott@npclinics.com.au>
12 * @author Robert Down <robertdown@live.com>
13 * @copyright Copyright (c) 2010-2018 bradymiller <bradymiller>
14 * @copyright Copyright (c) 2008-2009, 2022 sunsetsystems <sunsetsystems>
15 * @copyright Copyright (c) 2005 andres_paglayan <andres_paglayan>
16 * @copyright Copyright (c) 2016 Wakie87 <scott@npclinics.com.au>
17 * @copyright Copyright (c) 2017-2023 Robert Down <robertdown@live.com>
18 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
21 use OpenEMR\Common\Acl\AclMain
;
22 use OpenEMR\Common\Csrf\CsrfUtils
;
24 // Ensure this script is not called separately
25 if ($langModuleFlag !== true) {
26 die(function_exists('xlt') ?
xlt('Authentication Error') : 'Authentication Error');
30 $thisauth = AclMain
::aclCheckCore('admin', 'language');
32 echo "<html>\n<body>\n";
33 echo "<p>" . xlt('You are not authorized for this.') . "</p>\n";
34 echo "</body>\n</html>\n";
40 <form name
='filterform' id
='filterform' method
='post'
41 action
='?m=definition&csrf_token_form=<?php echo attr_url(CsrfUtils::collectCsrfToken()); ?>'
42 onsubmit
="return top.restoreSession()">
43 <input type
="hidden" name
="csrf_token_form" value
="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
44 <!-- Filter
for Constants
-->
45 <div
class="form-group">
46 <label
for="filterForConstants"><?php
echo xlt('Filter for Constants'); ?
>:</label
>
47 <input type
='text' class="form-control" id
="filterForConstants" name
='filter_cons'
48 size
='8' value
='<?php echo attr($_POST['filter_cons
'] ?? ''); ?>' />
49 <small
class="form-text text-muted">
50 <?php
echo xlt('(% matches any string, _ matches any character)'); ?
>
53 <!-- Filter
for Definitions
-->
54 <div
class="form-group">
55 <label
for="filterForDefinitions"><?php
echo xlt('Filter for Definitions'); ?
>:</label
>
56 <input type
='text' class="form-control" id
="filterForDefinitions" name
='filter_def'
57 size
='8' value
='<?php echo attr($_POST['filter_def
'] ?? ''); ?>' />
58 <small
class="form-text text-muted">
59 <?php
echo xlt('(% matches any string, _ matches any character)'); ?
>
62 <!-- Select Language
-->
63 <div
class="form-group">
64 <label
for="selectLanguage"><?php
echo xlt('Select Language') . ":"; ?
></label
>
65 <select
class="form-control" name
='language_select' id
="selectLanguage">
67 // sorting order of language titles depends on language translation options.
68 $mainLangID = empty($_SESSION['language_choice']) ?
'1' : $_SESSION['language_choice'];
69 // Use and sort by the translated language name.
70 $sql = "SELECT ll.lang_id, " .
71 "IF(LENGTH(ld.definition),ld.definition,ll.lang_description) AS lang_description " .
72 "FROM lang_languages AS ll " .
73 "LEFT JOIN lang_constants AS lc ON lc.constant_name = ll.lang_description " .
74 "LEFT JOIN lang_definitions AS ld ON ld.cons_id = lc.cons_id AND " .
76 "ORDER BY IF(LENGTH(ld.definition),ld.definition,ll.lang_description), ll.lang_id";
77 $res = SqlStatement($sql, array($mainLangID));
79 // collect the default selected language id, and then display list
80 $tempLangID = isset($_POST['language_select']) ?
$_POST['language_select'] : $mainLangID;
81 while ($row = SqlFetchArray($res)) {
82 if ($tempLangID == $row['lang_id']) {
83 echo "<option value='" . attr($row['lang_id']) . "' selected>" .
84 text($row['lang_description']) . "</option>";
86 echo "<option value='" . attr($row['lang_id']) . "'>" .
87 text($row['lang_description']) . "</option>";
93 <!-- Submit Button
-->
94 <div
class="form-group">
95 <input type
="submit" class="btn btn-primary" name
="edit" value
="<?php echo xla('Search'); ?>">
101 // set up the mysql collation string to ensure case is sensitive (or insensitive) in the mysql queries
102 if (!$disable_utf8_flag) {
103 if (!empty($sqlconf["db_encoding"]) && ($sqlconf["db_encoding"] == "utf8mb4")) {
104 $case_sensitive_collation = "COLLATE utf8mb4_bin";
105 $case_insensitive_collation = "COLLATE utf8mb4_general_ci";
107 $case_sensitive_collation = "COLLATE utf8_bin";
108 $case_insensitive_collation = "COLLATE utf8_general_ci";
111 $case_sensitive_collation = "COLLATE latin1_bin";
112 $case_insensitive_collation = "COLLATE latin1_swedish_ci";
115 if (!empty($_POST['load'])) {
116 if (!CsrfUtils
::verifyCsrfToken($_POST["csrf_token_form"])) {
117 CsrfUtils
::csrfNotVerified();
120 // query for entering new definitions it picks the cons_id because is existant.
121 if (!empty($_POST['cons_id'])) {
122 foreach ($_POST['cons_id'] as $key => $value) {
123 $value = trim($value);
125 // do not create new blank definitions
130 // insert into the main language tables
131 $sql = "INSERT INTO lang_definitions (`cons_id`,`lang_id`,`definition`) VALUES (?,?,?)";
132 SqlStatement($sql, array($key, $_POST['lang_id'], $value));
134 // insert each entry into the log table - to allow persistant customizations
135 $sql = "SELECT lang_description, lang_code FROM lang_languages WHERE lang_id=? LIMIT 1";
136 $res = SqlStatement($sql, array($_POST['lang_id']));
137 $row_l = SqlFetchArray($res);
138 $sql = "SELECT constant_name FROM lang_constants WHERE cons_id=? LIMIT 1";
139 $res = SqlStatement($sql, array($key));
140 $row_c = SqlFetchArray($res);
141 insert_language_log($row_l['lang_description'], $row_l['lang_code'], $row_c['constant_name'], $value);
147 // query for updating preexistant definitions uses def_id because there is no def yet.
148 // echo ('<pre>'); print_r($_POST['def_id']); echo ('</pre>');
149 if (!empty($_POST['def_id'])) {
150 foreach ($_POST['def_id'] as $key => $value) {
151 $value = trim($value);
153 // only continue if the definition is new
154 $sql = "SELECT * FROM lang_definitions WHERE def_id=? AND definition " . $case_sensitive_collation . " =?";
155 $res_test = SqlStatement($sql, array($key, $value));
156 if (!SqlFetchArray($res_test)) {
157 // insert into the main language tables
158 $sql = "UPDATE `lang_definitions` SET `definition`=? WHERE `def_id`=? LIMIT 1";
159 SqlStatement($sql, array($value, $key));
161 // insert each entry into the log table - to allow persistant customizations
162 $sql = "SELECT ll.lang_description, ll.lang_code, lc.constant_name ";
163 $sql .= "FROM lang_definitions AS ld, lang_languages AS ll, lang_constants AS lc ";
164 $sql .= "WHERE ld.def_id=? ";
165 $sql .= "AND ll.lang_id = ld.lang_id AND lc.cons_id = ld.cons_id LIMIT 1";
166 $res = SqlStatement($sql, array($key));
167 $row = SqlFetchArray($res);
168 insert_language_log($row['lang_description'], $row['lang_code'], $row['constant_name'], $value);
176 echo xlt("New Definition set added");
180 if (!empty($_POST['edit'])) {
181 if (!CsrfUtils
::verifyCsrfToken($_POST["csrf_token_form"])) {
182 CsrfUtils
::csrfNotVerified();
185 if ($_POST['language_select'] == '') {
186 exit(xlt("Please select a language"));
189 $lang_id = isset($_POST['language_select']) ?
$_POST['language_select'] : '';
190 $lang_id = (int)$lang_id;
192 $lang_filter = isset($_POST['filter_cons']) ?
$_POST['filter_cons'] : '';
194 $lang_filter_def = isset($_POST['filter_def']) ?
$_POST['filter_def'] : '';
195 $lang_filter_def .= '%';
197 $bind_sql_array = array();
198 array_push($bind_sql_array, $lang_filter);
199 $sql = "SELECT lc.cons_id, lc.constant_name, ld.def_id, ld.definition, ld.lang_id " .
200 "FROM lang_definitions AS ld " .
201 "RIGHT JOIN ( lang_constants AS lc, lang_languages AS ll ) ON " .
202 "( lc.cons_id = ld.cons_id AND ll.lang_id = ld.lang_id ) " .
203 "WHERE lc.constant_name " . $case_insensitive_collation . " LIKE ? AND ( ll.lang_id = 1 ";
205 array_push($bind_sql_array, $lang_id);
206 $sql .= "OR ll.lang_id=? ";
207 $what = "SELECT * from lang_languages where lang_id=? LIMIT 1";
208 $res = SqlStatement($what, array($lang_id));
209 $row = SqlFetchArray($res);
210 $lang_name = $row['lang_description'];
213 // Sort same case together and English/null before other languages.
214 $sql .= ") ORDER BY lc.constant_name, BINARY lc.constant_name, ld.lang_id " . $case_insensitive_collation;
216 $res = SqlStatement($sql, $bind_sql_array);
218 $isResults = false; //flag to record whether there are any results
219 echo ('<table><form method="post" action="?m=definition&csrf_token_form='
220 . attr_url(CsrfUtils
::collectCsrfToken()) . '" onsubmit="return top.restoreSession()">');
221 echo ('<input type="hidden" name="csrf_token_form" value="' . attr(CsrfUtils
::collectCsrfToken()) . '" />');
222 // only english definitions
224 while ($row = SqlFetchArray($res)) {
225 $isShow = false; //flag if passes the definition filter
226 $stringTemp = '<tr><td>' . text($row['constant_name']) . '</td>';
227 // if there is no definition
228 if (empty($row['def_id'])) {
229 $cons_name = "cons_id[" . $row['cons_id'] . "]";
230 if ($lang_filter_def == '%') {
234 // if there is a previous definition
236 $cons_name = "def_id[" . $row['def_id'] . "]";
237 $sql = "SELECT definition FROM lang_definitions WHERE def_id=? AND definition LIKE ?";
238 $res2 = SqlStatement($sql, array($row['def_id'], $lang_filter_def));
239 if (SqlFetchArray($res2)) {
244 $stringTemp .= '<td><input type="text" size="50" NAME="' . attr($cons_name) .
245 '" value="' . attr($row['definition']) . '">';
246 $stringTemp .= '</td><td></td></tr>';
248 //definition filter passed, so show
254 echo ('<input type="hidden" name="lang_id" value="' . attr($lang_id) . '">');
255 // english plus the other
257 while ($row = SqlFetchArray($res)) {
258 if (!empty($row['lang_id']) && $row['lang_id'] != '1') {
259 // This should not happen, if it does that must mean that this
260 // constant has more than one definition for the same language!
264 $isShow = false; //flag if passes the definition filter
265 $stringTemp = '<tr><td>' . text($row['constant_name']) . '</td>';
266 if ($row['definition'] == '' or $row['definition'] == 'NULL') {
269 $def = $row['definition'];
272 $stringTemp .= '<td>' . text($def) . '</td>';
273 $row = SqlFetchArray($res); // jump one to get the second language selected
274 if ($row['def_id'] == '' or $row['def_id'] == 'NULL') {
275 $cons_name = "cons_id[" . $row['cons_id'] . "]";
276 if ($lang_filter_def == '%') {
280 // if there is a previous definition
282 $cons_name = "def_id[" . $row['def_id'] . "]";
284 $sql = "SELECT definition FROM lang_definitions WHERE def_id=? AND definition LIKE ?";
285 $res2 = SqlStatement($sql, array($row['def_id'], $lang_filter_def));
286 if (SqlFetchArray($res2)) {
291 $stringTemp .= '<td><input type="text" size="50" name="' . attr($cons_name) . '" value="' .
292 attr($row['definition']) . '">';
293 $stringTemp .= '</td></tr>';
295 //definition filter passed, so show
301 echo ('<input type="hidden" name="lang_id" value="' . attr($lang_id) . '">');
305 echo ('<tr><td colspan=3><input type="submit" name="load" Value="' .
306 xla('Load Definitions') . '"></td></tr>');
308 <input type
="hidden" name
="filter_cons" value
="<?php echo attr($_POST['filter_cons']); ?>">
309 <input type
="hidden" name
="filter_def" value
="<?php echo attr($_POST['filter_def']); ?>">
310 <input type
="hidden" name
="language_select" value
="<?php echo attr($_POST['language_select']); ?>">
313 echo xlt('No Results Found For Search');
316 echo ('</form></table>');
321 <?php
echo activate_lang_tab('definition-link'); ?
>