2 include_once(dirname(__FILE__
) . '/sql.inc'); // fixes vulnerability with register_globals
4 // Translation function
5 // This is the translation engine
6 function xl($constant,$mode='r',$prepend='',$append='') {
8 if (!empty($_SESSION['language_choice'])) {
9 $lang_id = $_SESSION['language_choice'];
15 if ($lang_id == 1 && !empty($GLOBALS['skip_english_translation'])) {
16 // language id = 1, so no need to translate
22 // convert new lines to spaces and remove windows end of lines
23 $patterns = array ('/\n/','/\r/');
24 $replace = array (' ','');
25 $constant = preg_replace($patterns, $replace, $constant);
27 // second, attempt translation
28 $sql="SELECT * FROM lang_definitions JOIN lang_constants ON " .
29 "lang_definitions.cons_id = lang_constants.cons_id WHERE " .
30 "lang_id='$lang_id' AND constant_name = '" .
31 addslashes($constant) . "' LIMIT 1";
32 $res = SqlStatement($sql);
33 $row = SqlFetchArray($res);
34 $string = $row['definition'];
35 if ($string == '') { $string = "$constant"; }
37 // remove dangerous characters
38 $patterns = array ('/\n/','/\r/','/"/',"/'/");
39 $replace = array (' ','','`','`');
40 $string = preg_replace($patterns, $replace, $string);
43 $string = "$prepend" . "$string" . "$append";
51 // ----------- xl() function wrappers ------------------------------
53 // Use above xl() function the majority of time for translations. The
54 // below wrappers are only for specific situations in order to support
55 // granular control of translations in certain parts of OpenEMR.
61 // xl_document_category()
64 // Added 5-09 by BM for translation of list labels (when applicable)
65 // Only translates if the $GLOBALS['translate_lists'] is set to true.
66 function xl_list_label($constant,$mode='r',$prepend='',$append='') {
67 if ($GLOBALS['translate_lists']) {
70 xl($constant,$mode,$prepend,$append);
73 return xl($constant,$mode,$prepend,$append);
79 echo $prepend.$constant.$append;
82 return $prepend.$constant.$append;
86 // Added 5-09 by BM for translation of layout labels (when applicable)
87 // Only translates if the $GLOBALS['translate_layout'] is set to true.
88 function xl_layout_label($constant,$mode='r',$prepend='',$append='') {
89 if ($GLOBALS['translate_layout']) {
92 xl($constant,$mode,$prepend,$append);
95 return xl($constant,$mode,$prepend,$append);
101 echo $prepend.$constant.$append;
104 return $prepend.$constant.$append;
108 // Added 6-2009 by BM for translation of access control group labels
110 // Only translates if the $GLOBALS['translate_gacl_groups'] is set to true.
111 function xl_gacl_group($constant,$mode='r',$prepend='',$append='') {
112 if ($GLOBALS['translate_gacl_groups']) {
115 xl($constant,$mode,$prepend,$append);
118 return xl($constant,$mode,$prepend,$append);
124 echo $prepend.$constant.$append;
127 return $prepend.$constant.$append;
131 // Added 6-2009 by BM for translation of patient form (notes) titles
133 // Only translates if the $GLOBALS['translate_form_titles'] is set to true.
134 function xl_form_title($constant,$mode='r',$prepend='',$append='') {
135 if ($GLOBALS['translate_form_titles']) {
138 xl($constant,$mode,$prepend,$append);
141 return xl($constant,$mode,$prepend,$append);
147 echo $prepend.$constant.$append;
150 return $prepend.$constant.$append;
155 // Added 6-2009 by BM for translation of document categories
157 // Only translates if the $GLOBALS['translate_document_categories'] is set to true.
158 function xl_document_category($constant,$mode='r',$prepend='',$append='') {
159 if ($GLOBALS['translate_document_categories']) {
162 xl($constant,$mode,$prepend,$append);
165 return xl($constant,$mode,$prepend,$append);
171 echo $prepend.$constant.$append;
174 return $prepend.$constant.$append;
179 // Added 6-2009 by BM for translation of appointment categories
181 // Only translates if the $GLOBALS['translate_appt_categories'] is set to true.
182 function xl_appt_category($constant,$mode='r',$prepend='',$append='') {
183 if ($GLOBALS['translate_appt_categories']) {
186 xl($constant,$mode,$prepend,$append);
189 return xl($constant,$mode,$prepend,$append);
195 echo $prepend.$constant.$append;
198 return $prepend.$constant.$append;
202 // ---------------------------------------------------------------------------
204 // ---------------------------------
205 // Miscellaneous language translation functions
207 // Function to return the title of a language from the id
208 // @param integer (language id)
209 // return string (language title)
210 function getLanguageTitle($val) {
212 // validate language id
220 // get language title
221 $res = sqlStatement("select lang_description from lang_languages where lang_id = '".$lang_id."'");
222 for ($iter = 0;$row = sqlFetchArray($res);$iter++
) $result[$iter] = $row;
223 $languageTitle = $result[0]{"lang_description"};
224 return $languageTitle;
227 //----------------------------------
229 // ----------------------------------------------------------------------------
233 shows some informations for pages html header
238 function html_header_show() {
240 // Below line was commented by the UTF-8 project on 05-2009 by BM.
241 // We commented this out since we are now standardizing encoding
242 // in the globals.php file.
243 // echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> '."\n";
247 // ----------------------------------------------------------------------------
249 * Returns a string padded to a certain length with another string.
251 * This method behaves exactly like str_pad but is multibyte safe.
253 * @param string $input The string to be padded.
254 * @param int $length The length of the resulting string.
255 * @param string $pad The string to pad the input string with. Must
256 * be in the same charset like the input string.
257 * @param const $type The padding type. One of STR_PAD_LEFT,
258 * STR_PAD_RIGHT, or STR_PAD_BOTH.
259 * @param string $charset The charset of the input and the padding
262 * @return string The padded string.
264 function mb_strpad($input, $length, $pad = ' ', $type = STR_PAD_RIGHT
, $charset = 'UTF-8') {
265 mb_internal_encoding($charset);
266 $mb_length = mb_strlen($input, $charset);
267 $sb_length = strlen($input);
268 $pad_length = mb_strlen($pad, $charset);
270 /* Return if we already have the length. */
271 if ($mb_length >= $length) {
275 /* Shortcut for single byte strings. */
276 if ($mb_length == $sb_length && $pad_length == strlen($pad)) {
277 return str_pad($input, $length, $pad, $type);
282 $left = $length - $mb_length;
283 $output = mb_substr(str_repeat($pad, ceil($left / $pad_length)), 0, $left, $charset) . $input;
286 $left = floor(($length - $mb_length) / 2);
287 $right = ceil(($length - $mb_length) / 2);
288 $output = mb_substr(str_repeat($pad, ceil($left / $pad_length)), 0, $left, $charset) .
290 mb_substr(str_repeat($pad, ceil($right / $pad_length)), 0, $right, $charset);
293 $right = $length - $mb_length;
294 $output = $input . mb_substr(str_repeat($pad, ceil($right / $pad_length)), 0, $right, $charset);