DBC Dutch System
[openemr.git] / library / translation.inc.php
blob4f8cfe539dddf6e168e50bf3b8e0106da30b4e51
1 <?php
2 // include_once($GLOBALS['srcdir'] . '/sql.inc');
3 include_once(dirname(__FILE__) . '/sql.inc'); // fixes vulnerability with register_globals
5 // this function is related to the interface/language module.
7 function xl($constant,$mode='r',$prepend='',$append='') {
8 $lang_id=LANGUAGE;
9 $sql="SELECT * FROM lang_definitions JOIN lang_constants ON " .
10 "lang_definitions.cons_id = lang_constants.cons_id WHERE " .
11 "lang_id='$lang_id' AND constant_name = '" .
12 addslashes($constant) . "' LIMIT 1";
13 $res=SqlStatement($sql);
14 $row=SqlFetchArray($res);
15 $string=$row['definition'];
16 if ($string=='') { $string="$constant"; }
17 $string="$prepend"."$string"."$append";
18 if ($mode=='e'){
19 echo $string;
20 } else {
21 return $string;
26 // ----------------------------------------------------------------------------
27 /**
28 HEADER HTML
30 shows some informations for pages html header
32 @param none
33 @return void
35 function html_header_show() {
36 echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> '."\n";
40 // ----------------------------------------------------------------------------
41 /**
42 * Returns a string padded to a certain length with another string.
44 * This method behaves exactly like str_pad but is multibyte safe.
46 * @param string $input The string to be padded.
47 * @param int $length The length of the resulting string.
48 * @param string $pad The string to pad the input string with. Must
49 * be in the same charset like the input string.
50 * @param const $type The padding type. One of STR_PAD_LEFT,
51 * STR_PAD_RIGHT, or STR_PAD_BOTH.
52 * @param string $charset The charset of the input and the padding
53 * strings.
55 * @return string The padded string.
57 function mb_strpad($input, $length, $pad = ' ', $type = STR_PAD_RIGHT, $charset = 'UTF-8') {
58 mb_internal_encoding($charset);
59 $mb_length = mb_strlen($input, $charset);
60 $sb_length = strlen($input);
61 $pad_length = mb_strlen($pad, $charset);
63 /* Return if we already have the length. */
64 if ($mb_length >= $length) {
65 return $input;
68 /* Shortcut for single byte strings. */
69 if ($mb_length == $sb_length && $pad_length == strlen($pad)) {
70 return str_pad($input, $length, $pad, $type);
73 switch ($type) {
74 case STR_PAD_LEFT:
75 $left = $length - $mb_length;
76 $output = mb_substr(str_repeat($pad, ceil($left / $pad_length)), 0, $left, $charset) . $input;
77 break;
78 case STR_PAD_BOTH:
79 $left = floor(($length - $mb_length) / 2);
80 $right = ceil(($length - $mb_length) / 2);
81 $output = mb_substr(str_repeat($pad, ceil($left / $pad_length)), 0, $left, $charset) .
82 $input .
83 mb_substr(str_repeat($pad, ceil($right / $pad_length)), 0, $right, $charset);
84 break;
85 case STR_PAD_RIGHT:
86 $right = $length - $mb_length;
87 $output = $input . mb_substr(str_repeat($pad, ceil($right / $pad_length)), 0, $right, $charset);
88 break;
91 return $output;