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 function xl($constant,$mode='r',$prepend='',$append='') {
9 if (!empty($_SESSION['language_choice'])) {
10 $lang_id = $_SESSION['language_choice'];
16 if ($lang_id == 1 && !empty($GLOBALS['skip_english_translation'])) {
17 // language id = 1, so no need to translate
23 // convert new lines to spaces and remove windows end of lines
24 $patterns = array ('/\n/','/\r/');
25 $replace = array (' ','');
26 $constant = preg_replace($patterns, $replace, $constant);
28 // second, attempt translation
29 $sql="SELECT * FROM lang_definitions JOIN lang_constants ON " .
30 "lang_definitions.cons_id = lang_constants.cons_id WHERE " .
31 "lang_id='$lang_id' AND constant_name = '" .
32 add_escape_custom($constant) . "' LIMIT 1";
33 $res = SqlStatement($sql);
34 $row = SqlFetchArray($res);
35 $string = $row['definition'];
36 if ($string == '') { $string = "$constant"; }
38 // remove dangerous characters
39 $patterns = array ('/\n/','/\r/','/"/',"/'/");
40 $replace = array (' ','','`','`');
41 $string = preg_replace($patterns, $replace, $string);
44 $string = "$prepend" . "$string" . "$append";
52 // ----------- xl() function wrappers ------------------------------
54 // Use above xl() function the majority of time for translations. The
55 // below wrappers are only for specific situations in order to support
56 // granular control of translations in certain parts of OpenEMR.
62 // xl_document_category()
65 // Added 5-09 by BM for translation of list labels (when applicable)
66 // Only translates if the $GLOBALS['translate_lists'] is set to true.
67 function xl_list_label($constant,$mode='r',$prepend='',$append='') {
68 if ($GLOBALS['translate_lists']) {
71 xl($constant,$mode,$prepend,$append);
74 return xl($constant,$mode,$prepend,$append);
80 echo $prepend.$constant.$append;
83 return $prepend.$constant.$append;
87 // Added 5-09 by BM for translation of layout labels (when applicable)
88 // Only translates if the $GLOBALS['translate_layout'] is set to true.
89 function xl_layout_label($constant,$mode='r',$prepend='',$append='') {
90 if ($GLOBALS['translate_layout']) {
93 xl($constant,$mode,$prepend,$append);
96 return xl($constant,$mode,$prepend,$append);
102 echo $prepend.$constant.$append;
105 return $prepend.$constant.$append;
109 // Added 6-2009 by BM for translation of access control group labels
111 // Only translates if the $GLOBALS['translate_gacl_groups'] is set to true.
112 function xl_gacl_group($constant,$mode='r',$prepend='',$append='') {
113 if ($GLOBALS['translate_gacl_groups']) {
116 xl($constant,$mode,$prepend,$append);
119 return xl($constant,$mode,$prepend,$append);
125 echo $prepend.$constant.$append;
128 return $prepend.$constant.$append;
132 // Added 6-2009 by BM for translation of patient form (notes) titles
134 // Only translates if the $GLOBALS['translate_form_titles'] is set to true.
135 function xl_form_title($constant,$mode='r',$prepend='',$append='') {
136 if ($GLOBALS['translate_form_titles']) {
139 xl($constant,$mode,$prepend,$append);
142 return xl($constant,$mode,$prepend,$append);
148 echo $prepend.$constant.$append;
151 return $prepend.$constant.$append;
156 // Added 6-2009 by BM for translation of document categories
158 // Only translates if the $GLOBALS['translate_document_categories'] is set to true.
159 function xl_document_category($constant,$mode='r',$prepend='',$append='') {
160 if ($GLOBALS['translate_document_categories']) {
163 xl($constant,$mode,$prepend,$append);
166 return xl($constant,$mode,$prepend,$append);
172 echo $prepend.$constant.$append;
175 return $prepend.$constant.$append;
180 // Added 6-2009 by BM for translation of appointment categories
182 // Only translates if the $GLOBALS['translate_appt_categories'] is set to true.
183 function xl_appt_category($constant,$mode='r',$prepend='',$append='') {
184 if ($GLOBALS['translate_appt_categories']) {
187 xl($constant,$mode,$prepend,$append);
190 return xl($constant,$mode,$prepend,$append);
196 echo $prepend.$constant.$append;
199 return $prepend.$constant.$append;
203 // ---------------------------------------------------------------------------
205 // ---------------------------------
206 // Miscellaneous language translation functions
208 // Function to return the title of a language from the id
209 // @param integer (language id)
210 // return string (language title)
211 function getLanguageTitle($val) {
213 // validate language id
221 // get language title
222 $res = sqlStatement("select lang_description from lang_languages where lang_id = '".$lang_id."'");
223 for ($iter = 0;$row = sqlFetchArray($res);$iter++
) $result[$iter] = $row;
224 $languageTitle = $result[0]{"lang_description"};
225 return $languageTitle;
228 //----------------------------------
230 // ----------------------------------------------------------------------------
234 shows some informations for pages html header
239 function html_header_show() {
241 // Below line was commented by the UTF-8 project on 05-2009 by BM.
242 // We commented this out since we are now standardizing encoding
243 // in the globals.php file.
244 // echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> '."\n";
248 // ----------------------------------------------------------------------------
250 * Returns a string padded to a certain length with another string.
252 * This method behaves exactly like str_pad but is multibyte safe.
254 * @param string $input The string to be padded.
255 * @param int $length The length of the resulting string.
256 * @param string $pad The string to pad the input string with. Must
257 * be in the same charset like the input string.
258 * @param const $type The padding type. One of STR_PAD_LEFT,
259 * STR_PAD_RIGHT, or STR_PAD_BOTH.
260 * @param string $charset The charset of the input and the padding
263 * @return string The padded string.
265 function mb_strpad($input, $length, $pad = ' ', $type = STR_PAD_RIGHT
, $charset = 'UTF-8') {
266 mb_internal_encoding($charset);
267 $mb_length = mb_strlen($input, $charset);
268 $sb_length = strlen($input);
269 $pad_length = mb_strlen($pad, $charset);
271 /* Return if we already have the length. */
272 if ($mb_length >= $length) {
276 /* Shortcut for single byte strings. */
277 if ($mb_length == $sb_length && $pad_length == strlen($pad)) {
278 return str_pad($input, $length, $pad, $type);
283 $left = $length - $mb_length;
284 $output = mb_substr(str_repeat($pad, ceil($left / $pad_length)), 0, $left, $charset) . $input;
287 $left = floor(($length - $mb_length) / 2);
288 $right = ceil(($length - $mb_length) / 2);
289 $output = mb_substr(str_repeat($pad, ceil($left / $pad_length)), 0, $left, $charset) .
291 mb_substr(str_repeat($pad, ceil($right / $pad_length)), 0, $right, $charset);
294 $right = $length - $mb_length;
295 $output = $input . mb_substr(str_repeat($pad, ceil($right / $pad_length)), 0, $right, $charset);