2 include_once(dirname(__FILE__
) . '/sql.inc'); // fixes vulnerability with register_globals
3 require_once(dirname(__FILE__
) . '/formdata.inc.php');
5 // Translation function
6 // This is the translation engine
7 // Note that it is recommended to no longer use the mode, prepend, or append
8 // parameters, since this is not compatible with the htmlspecialchars() php
10 function xl($constant,$mode='r',$prepend='',$append='') {
12 if (!empty($_SESSION['language_choice'])) {
13 $lang_id = $_SESSION['language_choice'];
19 if ($lang_id == 1 && !empty($GLOBALS['skip_english_translation'])) {
20 // language id = 1, so no need to translate
22 $string = preg_replace('/\{\{.*\}\}/', '', $constant);
27 // convert new lines to spaces and remove windows end of lines
28 $patterns = array ('/\n/','/\r/');
29 $replace = array (' ','');
30 $constant = preg_replace($patterns, $replace, $constant);
32 // second, attempt translation
33 $sql="SELECT * FROM lang_definitions JOIN lang_constants ON " .
34 "lang_definitions.cons_id = lang_constants.cons_id WHERE " .
35 "lang_id='$lang_id' AND constant_name = '" .
36 add_escape_custom($constant) . "' LIMIT 1";
37 $res = sqlStatementNoLog($sql);
38 $row = SqlFetchArray($res);
39 $string = $row['definition'];
40 if ($string == '') { $string = "$constant"; }
42 // remove dangerous characters and remove comments
43 $patterns = array ('/\n/','/\r/','/"/',"/'/",'/\{\{.*\}\}/');
44 $replace = array (' ','','`','`','');
45 $string = preg_replace($patterns, $replace, $string);
48 $string = "$prepend" . "$string" . "$append";
56 // ----------- xl() function wrappers ------------------------------
58 // Use above xl() function the majority of time for translations. The
59 // below wrappers are only for specific situations in order to support
60 // granular control of translations in certain parts of OpenEMR.
66 // xl_document_category()
69 // Added 5-09 by BM for translation of list labels (when applicable)
70 // Only translates if the $GLOBALS['translate_lists'] is set to true.
71 function xl_list_label($constant,$mode='r',$prepend='',$append='') {
72 if ($GLOBALS['translate_lists']) {
75 xl($constant,$mode,$prepend,$append);
78 return xl($constant,$mode,$prepend,$append);
84 echo $prepend.$constant.$append;
87 return $prepend.$constant.$append;
91 // Added 5-09 by BM for translation of layout labels (when applicable)
92 // Only translates if the $GLOBALS['translate_layout'] is set to true.
93 function xl_layout_label($constant,$mode='r',$prepend='',$append='') {
94 if ($GLOBALS['translate_layout']) {
97 xl($constant,$mode,$prepend,$append);
100 return xl($constant,$mode,$prepend,$append);
106 echo $prepend.$constant.$append;
109 return $prepend.$constant.$append;
113 // Added 6-2009 by BM for translation of access control group labels
115 // Only translates if the $GLOBALS['translate_gacl_groups'] is set to true.
116 function xl_gacl_group($constant,$mode='r',$prepend='',$append='') {
117 if ($GLOBALS['translate_gacl_groups']) {
120 xl($constant,$mode,$prepend,$append);
123 return xl($constant,$mode,$prepend,$append);
129 echo $prepend.$constant.$append;
132 return $prepend.$constant.$append;
136 // Added 6-2009 by BM for translation of patient form (notes) titles
138 // Only translates if the $GLOBALS['translate_form_titles'] is set to true.
139 function xl_form_title($constant,$mode='r',$prepend='',$append='') {
140 if ($GLOBALS['translate_form_titles']) {
143 xl($constant,$mode,$prepend,$append);
146 return xl($constant,$mode,$prepend,$append);
152 echo $prepend.$constant.$append;
155 return $prepend.$constant.$append;
160 // Added 6-2009 by BM for translation of document categories
162 // Only translates if the $GLOBALS['translate_document_categories'] is set to true.
163 function xl_document_category($constant,$mode='r',$prepend='',$append='') {
164 if ($GLOBALS['translate_document_categories']) {
167 xl($constant,$mode,$prepend,$append);
170 return xl($constant,$mode,$prepend,$append);
176 echo $prepend.$constant.$append;
179 return $prepend.$constant.$append;
184 // Added 6-2009 by BM for translation of appointment categories
186 // Only translates if the $GLOBALS['translate_appt_categories'] is set to true.
187 function xl_appt_category($constant,$mode='r',$prepend='',$append='') {
188 if ($GLOBALS['translate_appt_categories']) {
191 xl($constant,$mode,$prepend,$append);
194 return xl($constant,$mode,$prepend,$append);
200 echo $prepend.$constant.$append;
203 return $prepend.$constant.$append;
207 // ---------------------------------------------------------------------------
209 // ---------------------------------
210 // Miscellaneous language translation functions
212 // Function to return the title of a language from the id
213 // @param integer (language id)
214 // return string (language title)
215 function getLanguageTitle($val) {
217 // validate language id
225 // get language title
226 $res = sqlStatement("select lang_description from lang_languages where lang_id = '".$lang_id."'");
227 for ($iter = 0;$row = sqlFetchArray($res);$iter++
) $result[$iter] = $row;
228 $languageTitle = $result[0]{"lang_description"};
229 return $languageTitle;
232 //----------------------------------
234 // ----------------------------------------------------------------------------
238 shows some informations for pages html header
243 function html_header_show() {
245 // Below line was commented by the UTF-8 project on 05-2009 by BM.
246 // We commented this out since we are now standardizing encoding
247 // in the globals.php file.
248 // echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> '."\n";
252 // ----------------------------------------------------------------------------
254 * Returns a string padded to a certain length with another string.
256 * This method behaves exactly like str_pad but is multibyte safe.
258 * @param string $input The string to be padded.
259 * @param int $length The length of the resulting string.
260 * @param string $pad The string to pad the input string with. Must
261 * be in the same charset like the input string.
262 * @param const $type The padding type. One of STR_PAD_LEFT,
263 * STR_PAD_RIGHT, or STR_PAD_BOTH.
264 * @param string $charset The charset of the input and the padding
267 * @return string The padded string.
269 function mb_strpad($input, $length, $pad = ' ', $type = STR_PAD_RIGHT
, $charset = 'UTF-8') {
270 mb_internal_encoding($charset);
271 $mb_length = mb_strlen($input, $charset);
272 $sb_length = strlen($input);
273 $pad_length = mb_strlen($pad, $charset);
275 /* Return if we already have the length. */
276 if ($mb_length >= $length) {
280 /* Shortcut for single byte strings. */
281 if ($mb_length == $sb_length && $pad_length == strlen($pad)) {
282 return str_pad($input, $length, $pad, $type);
287 $left = $length - $mb_length;
288 $output = mb_substr(str_repeat($pad, ceil($left / $pad_length)), 0, $left, $charset) . $input;
291 $left = floor(($length - $mb_length) / 2);
292 $right = ceil(($length - $mb_length) / 2);
293 $output = mb_substr(str_repeat($pad, ceil($left / $pad_length)), 0, $left, $charset) .
295 mb_substr(str_repeat($pad, ceil($right / $pad_length)), 0, $right, $charset);
298 $right = $length - $mb_length;
299 $output = $input . mb_substr(str_repeat($pad, ceil($right / $pad_length)), 0, $right, $charset);