2 include_once(dirname(__FILE__
) . '/sql.inc'); // fixes vulnerability with register_globals
4 // Translation function
5 // This is the translation engine
6 // Note that it is recommended to no longer use the mode, prepend, or append
7 // parameters, since this is not compatible with the htmlspecialchars() php
9 function xl($constant,$mode='r',$prepend='',$append='') {
11 if (!empty($_SESSION['language_choice'])) {
12 $lang_id = $_SESSION['language_choice'];
18 if ($lang_id == 1 && !empty($GLOBALS['skip_english_translation'])) {
19 // language id = 1, so no need to translate
21 $string = preg_replace('/\{\{.*\}\}/', '', $constant);
26 // convert new lines to spaces and remove windows end of lines
27 $patterns = array ('/\n/','/\r/');
28 $replace = array (' ','');
29 $constant = preg_replace($patterns, $replace, $constant);
31 // second, attempt translation
32 $sql="SELECT * FROM lang_definitions JOIN lang_constants ON " .
33 "lang_definitions.cons_id = lang_constants.cons_id WHERE " .
34 "lang_id=? AND constant_name = ? LIMIT 1";
35 $res = sqlStatementNoLog($sql,array($lang_id,$constant));
36 $row = SqlFetchArray($res);
37 $string = $row['definition'];
38 if ($string == '') { $string = "$constant"; }
40 // remove dangerous characters and remove comments
41 $patterns = array ('/\n/','/\r/','/"/',"/'/",'/\{\{.*\}\}/');
42 $replace = array (' ','','`','`','');
43 $string = preg_replace($patterns, $replace, $string);
46 $string = "$prepend" . "$string" . "$append";
54 // ----------- xl() function wrappers ------------------------------
56 // Use above xl() function the majority of time for translations. The
57 // below wrappers are only for specific situations in order to support
58 // granular control of translations in certain parts of OpenEMR.
64 // xl_document_category()
67 // Added 5-09 by BM for translation of list labels (when applicable)
68 // Only translates if the $GLOBALS['translate_lists'] is set to true.
69 function xl_list_label($constant,$mode='r',$prepend='',$append='') {
70 if ($GLOBALS['translate_lists']) {
73 xl($constant,$mode,$prepend,$append);
76 return xl($constant,$mode,$prepend,$append);
82 echo $prepend.$constant.$append;
85 return $prepend.$constant.$append;
89 // Added 5-09 by BM for translation of layout labels (when applicable)
90 // Only translates if the $GLOBALS['translate_layout'] is set to true.
91 function xl_layout_label($constant,$mode='r',$prepend='',$append='') {
92 if ($GLOBALS['translate_layout']) {
95 xl($constant,$mode,$prepend,$append);
98 return xl($constant,$mode,$prepend,$append);
104 echo $prepend.$constant.$append;
107 return $prepend.$constant.$append;
111 // Added 6-2009 by BM for translation of access control group labels
113 // Only translates if the $GLOBALS['translate_gacl_groups'] is set to true.
114 function xl_gacl_group($constant,$mode='r',$prepend='',$append='') {
115 if ($GLOBALS['translate_gacl_groups']) {
118 xl($constant,$mode,$prepend,$append);
121 return xl($constant,$mode,$prepend,$append);
127 echo $prepend.$constant.$append;
130 return $prepend.$constant.$append;
134 // Added 6-2009 by BM for translation of patient form (notes) titles
136 // Only translates if the $GLOBALS['translate_form_titles'] is set to true.
137 function xl_form_title($constant,$mode='r',$prepend='',$append='') {
138 if ($GLOBALS['translate_form_titles']) {
141 xl($constant,$mode,$prepend,$append);
144 return xl($constant,$mode,$prepend,$append);
150 echo $prepend.$constant.$append;
153 return $prepend.$constant.$append;
158 // Added 6-2009 by BM for translation of document categories
160 // Only translates if the $GLOBALS['translate_document_categories'] is set to true.
161 function xl_document_category($constant,$mode='r',$prepend='',$append='') {
162 if ($GLOBALS['translate_document_categories']) {
165 xl($constant,$mode,$prepend,$append);
168 return xl($constant,$mode,$prepend,$append);
174 echo $prepend.$constant.$append;
177 return $prepend.$constant.$append;
182 // Added 6-2009 by BM for translation of appointment categories
184 // Only translates if the $GLOBALS['translate_appt_categories'] is set to true.
185 function xl_appt_category($constant,$mode='r',$prepend='',$append='') {
186 if ($GLOBALS['translate_appt_categories']) {
189 xl($constant,$mode,$prepend,$append);
192 return xl($constant,$mode,$prepend,$append);
198 echo $prepend.$constant.$append;
201 return $prepend.$constant.$append;
205 // ---------------------------------------------------------------------------
207 // ---------------------------------
208 // Miscellaneous language translation functions
210 // Function to return the title of a language from the id
211 // @param integer (language id)
212 // return string (language title)
213 function getLanguageTitle($val) {
215 // validate language id
223 // get language title
224 $res = sqlStatement("select lang_description from lang_languages where lang_id =?",array($lang_id));
225 for ($iter = 0;$row = sqlFetchArray($res);$iter++
) $result[$iter] = $row;
226 $languageTitle = $result[0]{"lang_description"};
227 return $languageTitle;
234 * Returns language directionality as string 'rtl' or 'ltr'
235 * @param int $lang_id language code
236 * @return string 'ltr' 'rtl'
237 * @author Amiel <amielel@matrix.co.il>
239 function getLanguageDir($lang_id) {
240 // validate language id
241 $lang_id = empty($lang_id) ?
1 : $lang_id;
243 $row = sqlQuery('SELECT * FROM lang_languages WHERE lang_id = ?', array($lang_id));
245 return !empty($row['lang_is_rtl']) ?
'rtl' : 'ltr';
248 //----------------------------------
250 // ----------------------------------------------------------------------------
254 shows some informations for pages html header
259 function html_header_show() {
261 // Below line was commented by the UTF-8 project on 05-2009 by BM.
262 // We commented this out since we are now standardizing encoding
263 // in the globals.php file.
264 // echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> '."\n";
266 // Keeping this function, since it may prove useful for user interface improvements