1. Check existence of mb_string, mysql and xml extensions before installation.
[openemr.git] / phpmyadmin / libraries / browse_foreigners.lib.php
blobf4a1e8687764cd7555bae9489ee0f80273627ab0
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Contains functions used by browse_foreigners.php
6 * @package PhpMyAdmin
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 /**
13 * Function to get html for one relational key
15 * @param integer $horizontal_count the current horizontal count
16 * @param string $header table header
17 * @param boolean $odd_row for the row background color
18 * @param array $keys all the keys
19 * @param integer $indexByKeyname index by keyname
20 * @param array $descriptions descriptions
21 * @param integer $indexByDescription index by description
22 * @param string $current_value current value on the edit form
24 * @return string $html the generated html
26 function PMA_getHtmlForOneKey($horizontal_count, $header, $odd_row, $keys,
27 $indexByKeyname, $descriptions, $indexByDescription, $current_value
28 ) {
29 $horizontal_count++;
30 $output = '';
32 // whether the key name corresponds to the selected value in the form
33 $rightKeynameIsSelected = false;
34 $leftKeynameIsSelected = false;
36 if ($GLOBALS['cfg']['RepeatCells'] > 0
37 && $horizontal_count > $GLOBALS['cfg']['RepeatCells']
38 ) {
39 $output .= $header;
40 $horizontal_count = 0;
41 $odd_row = true;
44 // key names and descriptions for the left section,
45 // sorted by key names
46 $leftKeyname = $keys[$indexByKeyname];
47 list(
48 $leftDescription,
49 $leftDescriptionTitle
50 ) = PMA_getDescriptionAndTitle($descriptions[$indexByKeyname]);
52 // key names and descriptions for the right section,
53 // sorted by descriptions
54 $rightKeyname = $keys[$indexByDescription];
55 list(
56 $rightDescription,
57 $rightDescriptionTitle
58 ) = PMA_getDescriptionAndTitle($descriptions[$indexByDescription]);
60 $indexByDescription++;
62 if (! empty($current_value)) {
63 $rightKeynameIsSelected = $rightKeyname == $current_value;
64 $leftKeynameIsSelected = $leftKeyname == $current_value;
67 $output .= '<tr class="noclick ' . ($odd_row ? 'odd' : 'even') . '">';
68 $odd_row = ! $odd_row;
70 $output .= PMA_getHtmlForColumnElement(
71 'class="nowrap"', $leftKeynameIsSelected,
72 $leftKeyname, $leftDescription,
73 $leftDescriptionTitle
76 $output .= PMA_getHtmlForColumnElement(
77 '', $leftKeynameIsSelected, $leftKeyname,
78 $leftDescription, $leftDescriptionTitle
81 $output .= '<td width="20%">'
82 . '<img src="' . $GLOBALS['pmaThemeImage'] . 'spacer.png" alt=""'
83 . ' width="1" height="1" /></td>';
85 $output .= PMA_getHtmlForColumnElement(
86 '', $rightKeynameIsSelected, $rightKeyname,
87 $rightDescription, $rightDescriptionTitle
90 $output .= PMA_getHtmlForColumnElement(
91 'class="nowrap"', $rightKeynameIsSelected,
92 $rightKeyname, $rightDescription,
93 $rightDescriptionTitle
95 $output .= '</tr>';
97 return array($output, $horizontal_count, $odd_row, $indexByDescription);
101 * Function to get html for relational field selection
103 * @param string $db current database
104 * @param string $table current table
105 * @param string $field field
106 * @param array $foreignData foreign column data
107 * @param string $fieldkey field key
108 * @param string $current_value current columns's value
110 * @return string
112 function PMA_getHtmlForRelationalFieldSelection($db, $table, $field, $foreignData,
113 $fieldkey, $current_value
115 $gotopage = PMA_getHtmlForGotoPage($foreignData);
116 $showall = PMA_getHtmlForShowAll($foreignData);
118 $output = '<form class="ajax" '
119 . 'id="browse_foreign_form" name="browse_foreign_from" '
120 . 'action="browse_foreigners.php" method="post">'
121 . '<fieldset>'
122 . PMA_URL_getHiddenInputs($db, $table)
123 . '<input type="hidden" name="field" value="' . htmlspecialchars($field)
124 . '" />'
125 . '<input type="hidden" name="fieldkey" value="'
126 . (isset($fieldkey) ? htmlspecialchars($fieldkey) : '') . '" />';
128 if (isset($_REQUEST['rownumber'])) {
129 $output .= '<input type="hidden" name="rownumber" value="'
130 . htmlspecialchars($_REQUEST['rownumber']) . '" />';
132 $filter_value = (isset($_REQUEST['foreign_filter'])
133 ? htmlspecialchars($_REQUEST['foreign_filter'])
134 : '');
135 $output .= '<span class="formelement">'
136 . '<label for="input_foreign_filter">' . __('Search:') . '</label>'
137 . '<input type="text" name="foreign_filter" '
138 . 'id="input_foreign_filter" '
139 . 'value="' . $filter_value . '" data-old="' . $filter_value . '" '
140 . '/>'
141 . '<input type="submit" name="submit_foreign_filter" value="'
142 . __('Go') . '" />'
143 . '</span>'
144 . '<span class="formelement">' . $gotopage . '</span>'
145 . '<span class="formelement">' . $showall . '</span>'
146 . '</fieldset>'
147 . '</form>';
149 $output .= '<table width="100%" id="browse_foreign_table">';
151 if (!is_array($foreignData['disp_row'])) {
152 $output .= '</tbody>'
153 . '</table>';
155 return $output;
158 $header = '<tr>
159 <th>' . __('Keyname') . '</th>
160 <th>' . __('Description') . '</th>
161 <td width="20%"></td>
162 <th>' . __('Description') . '</th>
163 <th>' . __('Keyname') . '</th>
164 </tr>';
166 $output .= '<thead>' . $header . '</thead>' . "\n"
167 . '<tfoot>' . $header . '</tfoot>' . "\n"
168 . '<tbody>' . "\n";
170 $descriptions = array();
171 $keys = array();
172 foreach ($foreignData['disp_row'] as $relrow) {
173 if ($foreignData['foreign_display'] != false) {
174 $descriptions[] = $relrow[$foreignData['foreign_display']];
175 } else {
176 $descriptions[] = '';
179 $keys[] = $relrow[$foreignData['foreign_field']];
182 asort($keys);
184 $horizontal_count = 0;
185 $odd_row = true;
186 $indexByDescription = 0;
188 foreach ($keys as $indexByKeyname => $value) {
189 list(
190 $html,
191 $horizontal_count,
192 $odd_row,
193 $indexByDescription
194 ) = PMA_getHtmlForOneKey(
195 $horizontal_count, $header, $odd_row, $keys, $indexByKeyname,
196 $descriptions, $indexByDescription, $current_value
198 $output .= $html;
201 $output .= '</tbody>'
202 . '</table>';
204 return $output;
208 * Get the description (possibly truncated) and the title
210 * @param string $description the key name's description
212 * @return array the new description and title
214 function PMA_getDescriptionAndTitle($description)
216 $limitChars = $GLOBALS['cfg']['LimitChars'];
217 if (/*overload*/mb_strlen($description) <= $limitChars) {
218 $description = htmlspecialchars(
219 $description
221 $descriptionTitle = '';
222 } else {
223 $descriptionTitle = htmlspecialchars(
224 $description
226 $description = htmlspecialchars(
227 /*overload*/mb_substr(
228 $description, 0, $limitChars
230 . '...'
233 return array($description, $descriptionTitle);
237 * Function to get html for each column element
239 * @param string $cssClass class="nowrap" or ''
240 * @param bool $isSelected whether current equals form's value
241 * @param string $keyname current key
242 * @param string $description current value
243 * @param string $title current title
245 * @return string
247 function PMA_getHtmlForColumnElement($cssClass, $isSelected, $keyname,
248 $description, $title
250 $keyname = htmlspecialchars($keyname);
251 $output = '<td';
252 if (! empty($cssClass)) {
253 $output .= ' ' . $cssClass;
255 $output .= '>'
256 . ($isSelected ? '<strong>' : '')
257 . '<a class="foreign_value" data-key="' . $keyname . '" '
258 . 'href="#" title="' . __('Use this value')
259 . ($title != ''
260 ? ': ' . $title
261 : '')
262 . '">';
263 if ($cssClass !== '') {
264 $output .= $keyname;
265 } else {
266 $output .= $description;
269 $output .= '</a>' . ($isSelected ? '</strong>' : '') . '</td>';
271 return $output;
275 * Function to get html for show all case
277 * @param array $foreignData foreign data
279 * @return string
281 function PMA_getHtmlForShowAll($foreignData)
283 $showall = '';
284 if (is_array($foreignData['disp_row'])) {
285 if ($GLOBALS['cfg']['ShowAll']
286 && ($foreignData['the_total'] > $GLOBALS['cfg']['MaxRows'])
288 $showall = '<input type="submit" id="foreign_showAll" '
289 . 'name="foreign_showAll" '
290 . 'value="' . __('Show all') . '" />';
294 return $showall;
298 * Function to get html for the goto page option
300 * @param array $foreignData foreign data
302 * @return string
304 function PMA_getHtmlForGotoPage($foreignData)
306 $gotopage = '';
307 isset($_REQUEST['pos']) ? $pos = $_REQUEST['pos'] : $pos = 0;
308 if (!is_array($foreignData['disp_row'])) {
309 return $gotopage;
312 $session_max_rows = $GLOBALS['cfg']['MaxRows'];
313 $pageNow = @floor($pos / $session_max_rows) + 1;
314 $nbTotalPage = @ceil($foreignData['the_total'] / $session_max_rows);
316 if ($foreignData['the_total'] > $GLOBALS['cfg']['MaxRows']) {
317 $gotopage = PMA_Util::pageselector(
318 'pos',
319 $session_max_rows,
320 $pageNow,
321 $nbTotalPage,
322 200,
327 __('Page number:')
331 return $gotopage;
335 * Function to get foreign limit
337 * @param string $foreign_showAll foreign navigation
339 * @return string
341 function PMA_getForeignLimit($foreign_showAll)
343 if (isset($foreign_showAll) && $foreign_showAll == __('Show all')) {
344 return null;
346 isset($_REQUEST['pos']) ? $pos = $_REQUEST['pos'] : $pos = 0;
347 return 'LIMIT ' . $pos . ', ' . $GLOBALS['cfg']['MaxRows'] . ' ';