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=? AND constant_name = ? LIMIT 1";
36 $res = sqlStatementNoLog($sql,array($lang_id,$constant));
37 $row = SqlFetchArray($res);
38 $string = $row['definition'];
39 if ($string == '') { $string = "$constant"; }
41 // remove dangerous characters and remove comments
42 $patterns = array ('/\n/','/\r/','/"/',"/'/",'/\{\{.*\}\}/');
43 $replace = array (' ','','`','`','');
44 $string = preg_replace($patterns, $replace, $string);
47 $string = "$prepend" . "$string" . "$append";
55 // ----------- xl() function wrappers ------------------------------
57 // Use above xl() function the majority of time for translations. The
58 // below wrappers are only for specific situations in order to support
59 // granular control of translations in certain parts of OpenEMR.
65 // xl_document_category()
68 // Added 5-09 by BM for translation of list labels (when applicable)
69 // Only translates if the $GLOBALS['translate_lists'] is set to true.
70 function xl_list_label($constant,$mode='r',$prepend='',$append='') {
71 if ($GLOBALS['translate_lists']) {
74 xl($constant,$mode,$prepend,$append);
77 return xl($constant,$mode,$prepend,$append);
83 echo $prepend.$constant.$append;
86 return $prepend.$constant.$append;
90 // Added 5-09 by BM for translation of layout labels (when applicable)
91 // Only translates if the $GLOBALS['translate_layout'] is set to true.
92 function xl_layout_label($constant,$mode='r',$prepend='',$append='') {
93 if ($GLOBALS['translate_layout']) {
96 xl($constant,$mode,$prepend,$append);
99 return xl($constant,$mode,$prepend,$append);
105 echo $prepend.$constant.$append;
108 return $prepend.$constant.$append;
112 // Added 6-2009 by BM for translation of access control group labels
114 // Only translates if the $GLOBALS['translate_gacl_groups'] is set to true.
115 function xl_gacl_group($constant,$mode='r',$prepend='',$append='') {
116 if ($GLOBALS['translate_gacl_groups']) {
119 xl($constant,$mode,$prepend,$append);
122 return xl($constant,$mode,$prepend,$append);
128 echo $prepend.$constant.$append;
131 return $prepend.$constant.$append;
135 // Added 6-2009 by BM for translation of patient form (notes) titles
137 // Only translates if the $GLOBALS['translate_form_titles'] is set to true.
138 function xl_form_title($constant,$mode='r',$prepend='',$append='') {
139 if ($GLOBALS['translate_form_titles']) {
142 xl($constant,$mode,$prepend,$append);
145 return xl($constant,$mode,$prepend,$append);
151 echo $prepend.$constant.$append;
154 return $prepend.$constant.$append;
159 // Added 6-2009 by BM for translation of document categories
161 // Only translates if the $GLOBALS['translate_document_categories'] is set to true.
162 function xl_document_category($constant,$mode='r',$prepend='',$append='') {
163 if ($GLOBALS['translate_document_categories']) {
166 xl($constant,$mode,$prepend,$append);
169 return xl($constant,$mode,$prepend,$append);
175 echo $prepend.$constant.$append;
178 return $prepend.$constant.$append;
183 // Added 6-2009 by BM for translation of appointment categories
185 // Only translates if the $GLOBALS['translate_appt_categories'] is set to true.
186 function xl_appt_category($constant,$mode='r',$prepend='',$append='') {
187 if ($GLOBALS['translate_appt_categories']) {
190 xl($constant,$mode,$prepend,$append);
193 return xl($constant,$mode,$prepend,$append);
199 echo $prepend.$constant.$append;
202 return $prepend.$constant.$append;
206 // ---------------------------------------------------------------------------
208 // ---------------------------------
209 // Miscellaneous language translation functions
211 // Function to return the title of a language from the id
212 // @param integer (language id)
213 // return string (language title)
214 function getLanguageTitle($val) {
216 // validate language id
224 // get language title
225 $res = sqlStatement("select lang_description from lang_languages where lang_id =?",array($lang_id));
226 for ($iter = 0;$row = sqlFetchArray($res);$iter++
) $result[$iter] = $row;
227 $languageTitle = $result[0]{"lang_description"};
228 return $languageTitle;
235 * Returns language directionality as string 'rtl' or 'ltr'
236 * @param int $lang_id language code
237 * @return string 'ltr' 'rtl'
238 * @author Amiel <amielel@matrix.co.il>
240 function getLanguageDir($lang_id) {
241 // validate language id
242 $lang_id = empty($lang_id) ?
1 : $lang_id;
244 $row = sqlQuery('SELECT * FROM lang_languages WHERE lang_id = ?', array($lang_id));
246 return !empty($row['lang_is_rtl']) ?
'rtl' : 'ltr';
249 //----------------------------------
251 // ----------------------------------------------------------------------------
255 shows some informations for pages html header
260 function html_header_show() {
262 // Below line was commented by the UTF-8 project on 05-2009 by BM.
263 // We commented this out since we are now standardizing encoding
264 // in the globals.php file.
265 // echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> '."\n";
269 // ----------------------------------------------------------------------------
271 * Returns a string padded to a certain length with another string.
273 * This method behaves exactly like str_pad but is multibyte safe.
275 * @param string $input The string to be padded.
276 * @param int $length The length of the resulting string.
277 * @param string $pad The string to pad the input string with. Must
278 * be in the same charset like the input string.
279 * @param const $type The padding type. One of STR_PAD_LEFT,
280 * STR_PAD_RIGHT, or STR_PAD_BOTH.
281 * @param string $charset The charset of the input and the padding
284 * @return string The padded string.
286 function mb_strpad($input, $length, $pad = ' ', $type = STR_PAD_RIGHT
, $charset = 'UTF-8') {
287 mb_internal_encoding($charset);
288 $mb_length = mb_strlen($input, $charset);
289 $sb_length = strlen($input);
290 $pad_length = mb_strlen($pad, $charset);
292 /* Return if we already have the length. */
293 if ($mb_length >= $length) {
297 /* Shortcut for single byte strings. */
298 if ($mb_length == $sb_length && $pad_length == strlen($pad)) {
299 return str_pad($input, $length, $pad, $type);
304 $left = $length - $mb_length;
305 $output = mb_substr(str_repeat($pad, ceil($left / $pad_length)), 0, $left, $charset) . $input;
308 $left = floor(($length - $mb_length) / 2);
309 $right = ceil(($length - $mb_length) / 2);
310 $output = mb_substr(str_repeat($pad, ceil($left / $pad_length)), 0, $left, $charset) .
312 mb_substr(str_repeat($pad, ceil($right / $pad_length)), 0, $right, $charset);
315 $right = $length - $mb_length;
316 $output = $input . mb_substr(str_repeat($pad, ceil($right / $pad_length)), 0, $right, $charset);