added an option to force the new issue type, and an option to link the issue to an...
[openemr.git] / library / translation.inc.php
blob0efe589c0a46707a1c3296d1480e72acfb61f9c2
1 <?php
2 // include_once($GLOBALS['srcdir'] . '/sql.inc');
3 include_once(dirname(__FILE__) . '/sql.inc'); // fixes vulnerability with register_globals
5 // Translation function
6 // This is the translation engine
7 function xl($constant,$mode='r',$prepend='',$append='') {
8 // set language id
9 if (isset($_SESSION['language_choice'])) {
10 $lang_id=$_SESSION['language_choice'];
12 else {
13 $lang_id=1;
16 if ($lang_id == 1) {
17 // language id = 1, so no need to translate
18 $string=$constant;
20 else {
21 //TRANSLATE
23 // first, clean lines
24 // convert new lines to spaces and remove windows end of lines
25 $patterns = array ('/\n/','/\r/');
26 $replace = array (' ','');
27 $constant = preg_replace($patterns, $replace, $constant);
29 // second, attempt translation
30 $sql="SELECT * FROM lang_definitions JOIN lang_constants ON " .
31 "lang_definitions.cons_id = lang_constants.cons_id WHERE " .
32 "lang_id='$lang_id' AND constant_name = '" .
33 addslashes($constant) . "' LIMIT 1";
34 $res=SqlStatement($sql);
35 $row=SqlFetchArray($res);
36 $string=$row['definition'];
37 if ($string=='') { $string="$constant"; }
40 $string="$prepend"."$string"."$append";
41 if ($mode=='e'){
42 echo $string;
43 } else {
44 return $string;
49 // Added 5-09 by BM for translation of list labels (when applicable)
50 // Wrapper for the above translation function xl()
52 // Only translates if the $GLOBALS['translate_lists'] is set to true.
54 function xl_list_label($constant,$mode='r',$prepend='',$append='') {
55 if ($GLOBALS['translate_lists']) {
56 // TRANSLATE
57 if ($mode == "e") {
58 xl($constant,$mode,$prepend,$append);
60 else {
61 return xl($constant,$mode,$prepend,$append);
64 else {
65 // DO NOT TRANSLATE
66 if ($mode == "e") {
67 echo $prepend.$constant.$append;
69 else {
70 return $prepend.$constant.$append;
75 // Added 5-09 by BM for translation of layout labels (when applicable)
76 // Wrapper for the translation function xl()
78 // Only translates if the $GLOBALS['translate_layout'] is set to true.
80 function xl_layout_label($constant,$mode='r',$prepend='',$append='') {
81 if ($GLOBALS['translate_layout']) {
82 // TRANSLATE
83 if ($mode == "e") {
84 xl($constant,$mode,$prepend,$append);
86 else {
87 return xl($constant,$mode,$prepend,$append);
90 else {
91 // DO NOT TRANSLATE
92 if ($mode == "e") {
93 echo $prepend.$constant.$append;
95 else {
96 return $prepend.$constant.$append;
101 // Added 6-2009 by BM for translation of access control group labels
102 // (when applicable)
103 // Wrapper for the translation function xl()
105 // Only translates if the $GLOBALS['translate_gacl_groups'] is set to true.
107 function xl_gacl_group($constant,$mode='r',$prepend='',$append='') {
108 if ($GLOBALS['translate_gacl_groups']) {
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;
128 // ----------------------------------------------------------------------------
130 HEADER HTML
132 shows some informations for pages html header
134 @param none
135 @return void
137 function html_header_show() {
139 // Below line was commented by the UTF-8 project on 05-2009 by BM.
140 // We commented this out since we are now standardizing encoding
141 // in the globals.php file.
142 // echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> '."\n";
146 // ----------------------------------------------------------------------------
148 * Returns a string padded to a certain length with another string.
150 * This method behaves exactly like str_pad but is multibyte safe.
152 * @param string $input The string to be padded.
153 * @param int $length The length of the resulting string.
154 * @param string $pad The string to pad the input string with. Must
155 * be in the same charset like the input string.
156 * @param const $type The padding type. One of STR_PAD_LEFT,
157 * STR_PAD_RIGHT, or STR_PAD_BOTH.
158 * @param string $charset The charset of the input and the padding
159 * strings.
161 * @return string The padded string.
163 function mb_strpad($input, $length, $pad = ' ', $type = STR_PAD_RIGHT, $charset = 'UTF-8') {
164 mb_internal_encoding($charset);
165 $mb_length = mb_strlen($input, $charset);
166 $sb_length = strlen($input);
167 $pad_length = mb_strlen($pad, $charset);
169 /* Return if we already have the length. */
170 if ($mb_length >= $length) {
171 return $input;
174 /* Shortcut for single byte strings. */
175 if ($mb_length == $sb_length && $pad_length == strlen($pad)) {
176 return str_pad($input, $length, $pad, $type);
179 switch ($type) {
180 case STR_PAD_LEFT:
181 $left = $length - $mb_length;
182 $output = mb_substr(str_repeat($pad, ceil($left / $pad_length)), 0, $left, $charset) . $input;
183 break;
184 case STR_PAD_BOTH:
185 $left = floor(($length - $mb_length) / 2);
186 $right = ceil(($length - $mb_length) / 2);
187 $output = mb_substr(str_repeat($pad, ceil($left / $pad_length)), 0, $left, $charset) .
188 $input .
189 mb_substr(str_repeat($pad, ceil($right / $pad_length)), 0, $right, $charset);
190 break;
191 case STR_PAD_RIGHT:
192 $right = $length - $mb_length;
193 $output = $input . mb_substr(str_repeat($pad, ceil($right / $pad_length)), 0, $right, $charset);
194 break;
197 return $output;