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;
231 //----------------------------------
233 // ----------------------------------------------------------------------------
237 shows some informations for pages html header
242 function html_header_show() {
244 // Below line was commented by the UTF-8 project on 05-2009 by BM.
245 // We commented this out since we are now standardizing encoding
246 // in the globals.php file.
247 // echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> '."\n";
251 // ----------------------------------------------------------------------------
253 * Returns a string padded to a certain length with another string.
255 * This method behaves exactly like str_pad but is multibyte safe.
257 * @param string $input The string to be padded.
258 * @param int $length The length of the resulting string.
259 * @param string $pad The string to pad the input string with. Must
260 * be in the same charset like the input string.
261 * @param const $type The padding type. One of STR_PAD_LEFT,
262 * STR_PAD_RIGHT, or STR_PAD_BOTH.
263 * @param string $charset The charset of the input and the padding
266 * @return string The padded string.
268 function mb_strpad($input, $length, $pad = ' ', $type = STR_PAD_RIGHT
, $charset = 'UTF-8') {
269 mb_internal_encoding($charset);
270 $mb_length = mb_strlen($input, $charset);
271 $sb_length = strlen($input);
272 $pad_length = mb_strlen($pad, $charset);
274 /* Return if we already have the length. */
275 if ($mb_length >= $length) {
279 /* Shortcut for single byte strings. */
280 if ($mb_length == $sb_length && $pad_length == strlen($pad)) {
281 return str_pad($input, $length, $pad, $type);
286 $left = $length - $mb_length;
287 $output = mb_substr(str_repeat($pad, ceil($left / $pad_length)), 0, $left, $charset) . $input;
290 $left = floor(($length - $mb_length) / 2);
291 $right = ceil(($length - $mb_length) / 2);
292 $output = mb_substr(str_repeat($pad, ceil($left / $pad_length)), 0, $left, $charset) .
294 mb_substr(str_repeat($pad, ceil($right / $pad_length)), 0, $right, $charset);
297 $right = $length - $mb_length;
298 $output = $input . mb_substr(str_repeat($pad, ceil($right / $pad_length)), 0, $right, $charset);