Added access controls for encounter categories
[openemr.git] / library / translation.inc.php
blobbae7916d9d7f760a5a9e493e163d76e7536db723
1 <?php
3 // Translation function
4 // This is the translation engine
5 // Note that it is recommended to no longer use the mode, prepend, or append
6 // parameters, since this is not compatible with the htmlspecialchars() php
7 // function.
8 //
9 // Note there are cases in installation where this function has already been
10 // declared, so check to ensure has not been declared yet.
12 if (!(function_exists('xl'))) {
13 function xl($constant,$mode='r',$prepend='',$append='')
15 // set language id
16 if (!empty($_SESSION['language_choice'])) {
17 $lang_id = $_SESSION['language_choice'];
19 else {
20 $lang_id = 1;
23 if ($lang_id == 1 && !empty($GLOBALS['skip_english_translation'])) {
24 // language id = 1, so no need to translate
25 // -- remove comments
26 $string = preg_replace('/\{\{.*\}\}/', '', $constant);
28 else {
29 // TRANSLATE
30 // first, clean lines
31 // convert new lines to spaces and remove windows end of lines
32 $patterns = array ('/\n/','/\r/');
33 $replace = array (' ','');
34 $constant = preg_replace($patterns, $replace, $constant);
36 // second, attempt translation
37 $sql="SELECT * FROM lang_definitions JOIN lang_constants ON " .
38 "lang_definitions.cons_id = lang_constants.cons_id WHERE " .
39 "lang_id=? AND constant_name = ? LIMIT 1";
40 $res = sqlStatementNoLog($sql,array($lang_id,$constant));
41 $row = SqlFetchArray($res);
42 $string = $row['definition'];
43 if ($string == '') { $string = "$constant"; }
45 // remove dangerous characters and remove comments
46 if ($GLOBALS['translate_no_safe_apostrophe']) {
47 $patterns = array ('/\n/','/\r/','/\{\{.*\}\}/');
48 $replace = array (' ','','');
49 $string = preg_replace($patterns, $replace, $string);
51 else {
52 // convert apostrophes and quotes to safe apostrophe
53 $patterns = array ('/\n/','/\r/','/"/',"/'/",'/\{\{.*\}\}/');
54 $replace = array (' ','','`','`','');
55 $string = preg_replace($patterns, $replace, $string);
59 $string = "$prepend" . "$string" . "$append";
60 if ($mode=='e') {
61 echo $string;
62 } else {
63 return $string;
68 // ----------- xl() function wrappers ------------------------------
70 // Use above xl() function the majority of time for translations. The
71 // below wrappers are only for specific situations in order to support
72 // granular control of translations in certain parts of OpenEMR.
73 // Wrappers:
74 // xl_list_label()
75 // xl_layout_label()
76 // xl_gacl_group()
77 // xl_form_title()
78 // xl_document_category()
79 // xl_appt_category()
81 // Added 5-09 by BM for translation of list labels (when applicable)
82 // Only translates if the $GLOBALS['translate_lists'] is set to true.
83 function xl_list_label($constant,$mode='r',$prepend='',$append='')
85 if ($GLOBALS['translate_lists']) {
86 // TRANSLATE
87 if ($mode == "e") {
88 xl($constant,$mode,$prepend,$append);
90 else {
91 return xl($constant,$mode,$prepend,$append);
94 else {
95 // DO NOT TRANSLATE
96 if ($mode == "e") {
97 echo $prepend.$constant.$append;
99 else {
100 return $prepend.$constant.$append;
104 // Added 5-09 by BM for translation of layout labels (when applicable)
105 // Only translates if the $GLOBALS['translate_layout'] is set to true.
106 function xl_layout_label($constant,$mode='r',$prepend='',$append='')
108 if ($GLOBALS['translate_layout']) {
109 // TRANSLATE
110 if ($mode == "e") {
111 xl($constant,$mode,$prepend,$append);
113 else {
114 return xl($constant,$mode,$prepend,$append);
117 else {
118 // DO NOT TRANSLATE
119 if ($mode == "e") {
120 echo $prepend.$constant.$append;
122 else {
123 return $prepend.$constant.$append;
127 // Added 6-2009 by BM for translation of access control group labels
128 // (when applicable)
129 // Only translates if the $GLOBALS['translate_gacl_groups'] is set to true.
130 function xl_gacl_group($constant,$mode='r',$prepend='',$append='')
132 if ($GLOBALS['translate_gacl_groups']) {
133 // TRANSLATE
134 if ($mode == "e") {
135 xl($constant,$mode,$prepend,$append);
137 else {
138 return xl($constant,$mode,$prepend,$append);
141 else {
142 // DO NOT TRANSLATE
143 if ($mode == "e") {
144 echo $prepend.$constant.$append;
146 else {
147 return $prepend.$constant.$append;
151 // Added 6-2009 by BM for translation of patient form (notes) titles
152 // (when applicable)
153 // Only translates if the $GLOBALS['translate_form_titles'] is set to true.
154 function xl_form_title($constant,$mode='r',$prepend='',$append='')
156 if ($GLOBALS['translate_form_titles']) {
157 // TRANSLATE
158 if ($mode == "e") {
159 xl($constant,$mode,$prepend,$append);
161 else {
162 return xl($constant,$mode,$prepend,$append);
165 else {
166 // DO NOT TRANSLATE
167 if ($mode == "e") {
168 echo $prepend.$constant.$append;
170 else {
171 return $prepend.$constant.$append;
176 // Added 6-2009 by BM for translation of document categories
177 // (when applicable)
178 // Only translates if the $GLOBALS['translate_document_categories'] is set to true.
179 function xl_document_category($constant,$mode='r',$prepend='',$append='')
181 if ($GLOBALS['translate_document_categories']) {
182 // TRANSLATE
183 if ($mode == "e") {
184 xl($constant,$mode,$prepend,$append);
186 else {
187 return xl($constant,$mode,$prepend,$append);
190 else {
191 // DO NOT TRANSLATE
192 if ($mode == "e") {
193 echo $prepend.$constant.$append;
195 else {
196 return $prepend.$constant.$append;
201 // Added 6-2009 by BM for translation of appointment categories
202 // (when applicable)
203 // Only translates if the $GLOBALS['translate_appt_categories'] is set to true.
204 function xl_appt_category($constant,$mode='r',$prepend='',$append='')
206 if ($GLOBALS['translate_appt_categories']) {
207 // TRANSLATE
208 if ($mode == "e") {
209 xl($constant,$mode,$prepend,$append);
211 else {
212 return xl($constant,$mode,$prepend,$append);
215 else {
216 // DO NOT TRANSLATE
217 if ($mode == "e") {
218 echo $prepend.$constant.$append;
220 else {
221 return $prepend.$constant.$append;
225 // ---------------------------------------------------------------------------
227 // ---------------------------------
228 // Miscellaneous language translation functions
230 // Function to return the title of a language from the id
231 // @param integer (language id)
232 // return string (language title)
233 function getLanguageTitle($val)
236 // validate language id
237 if (!empty($val)) {
238 $lang_id = $val;
240 else {
241 $lang_id = 1;
244 // get language title
245 $res = sqlStatement("select lang_description from lang_languages where lang_id =?",array($lang_id));
246 for ($iter = 0;$row = sqlFetchArray($res);
247 $iter++) $result[$iter] = $row;
248 $languageTitle = $result[0]{"lang_description"};
249 return $languageTitle;
256 * Returns language directionality as string 'rtl' or 'ltr'
257 * @param int $lang_id language code
258 * @return string 'ltr' 'rtl'
259 * @author Amiel <amielel@matrix.co.il>
261 function getLanguageDir($lang_id)
263 // validate language id
264 $lang_id = empty($lang_id) ? 1 : $lang_id;
265 // get language code
266 $row = sqlQuery('SELECT * FROM lang_languages WHERE lang_id = ?', array($lang_id));
268 return !empty($row['lang_is_rtl']) ? 'rtl' : 'ltr';
271 //----------------------------------
273 // ----------------------------------------------------------------------------
275 HEADER HTML
277 shows some informations for pages html header
279 @param none
280 @return void
282 function html_header_show()
285 // Below line was commented by the UTF-8 project on 05-2009 by BM.
286 // We commented this out since we are now standardizing encoding
287 // in the globals.php file.
288 // echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> '."\n";
290 // Keeping this function, since it may prove useful for user interface improvements