Translated using Weblate (Korean)
[phpmyadmin.git] / libraries / browse_foreigners.lib.php
blobb83296d581dee4806ec93b736001262d556068cf
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 */
9 /**
10 * Function to get html for one relational key
12 * @param integer $horizontal_count the current horizontal count
13 * @param string $header table header
14 * @param boolean $odd_row for the row background color
15 * @param array $keys all the keys
16 * @param integer $indexByKeyname index by keyname
17 * @param array $descriptions descriptions
18 * @param integer $indexByDescription index by description
19 * @param string $current_value current value on the edit form
21 * @return string $html the generated html
23 function PMA_getHtmlForOneKey($horizontal_count, $header, $odd_row, $keys,
24 $indexByKeyname, $descriptions, $indexByDescription, $current_value
25 ) {
26 $horizontal_count++;
27 $output = '';
29 // whether the key name corresponds to the selected value in the form
30 $rightKeynameIsSelected = false;
31 $leftKeynameIsSelected = false;
33 if ($GLOBALS['cfg']['RepeatCells'] > 0
34 && $horizontal_count > $GLOBALS['cfg']['RepeatCells']
35 ) {
36 $output .= $header;
37 $horizontal_count = 0;
38 $odd_row = true;
41 // key names and descriptions for the left section,
42 // sorted by key names
43 $leftKeyname = $keys[$indexByKeyname];
44 list(
45 $leftDescription,
46 $leftDescriptionTitle
47 ) = PMA_getDescriptionAndTitle($descriptions[$indexByKeyname]);
49 // key names and descriptions for the right section,
50 // sorted by descriptions
51 $rightKeyname = $keys[$indexByDescription];
52 list(
53 $rightDescription,
54 $rightDescriptionTitle
55 ) = PMA_getDescriptionAndTitle($descriptions[$indexByDescription]);
57 $indexByDescription++;
59 if (! empty($current_value)) {
60 $rightKeynameIsSelected = $rightKeyname == $current_value;
61 $leftKeynameIsSelected = $leftKeyname == $current_value;
64 $output .= '<tr class="noclick ' . ($odd_row ? 'odd' : 'even') . '">';
65 $odd_row = ! $odd_row;
67 $output .= PMA_getHtmlForColumnElement(
68 'class="nowrap"', $leftKeynameIsSelected,
69 $leftKeyname, $leftDescription,
70 $leftDescriptionTitle
73 $output .= PMA_getHtmlForColumnElement(
74 '', $leftKeynameIsSelected, $leftKeyname,
75 $leftDescription, $leftDescriptionTitle
78 $output .= '<td width="20%">'
79 . '<img src="' . $GLOBALS['pmaThemeImage'] . 'spacer.png" alt=""'
80 . ' width="1" height="1" /></td>';
82 $output .= PMA_getHtmlForColumnElement(
83 '', $rightKeynameIsSelected, $rightKeyname,
84 $rightDescription, $rightDescriptionTitle
87 $output .= PMA_getHtmlForColumnElement(
88 'class="nowrap"', $rightKeynameIsSelected,
89 $rightKeyname, $rightDescription,
90 $rightDescriptionTitle
92 $output .= '</tr>';
94 return array($output, $horizontal_count, $odd_row, $indexByDescription);
97 /**
98 * Function to get html for relational field selection
100 * @param string $db current database
101 * @param string $table current table
102 * @param string $field field
103 * @param array $foreignData foreign column data
104 * @param string $fieldkey field key
105 * @param string $current_value current columns's value
107 * @return string
109 function PMA_getHtmlForRelationalFieldSelection($db, $table, $field, $foreignData,
110 $fieldkey, $current_value
112 $gotopage = PMA_getHtmlForGotoPage($foreignData);
113 $showall = PMA_getHtmlForShowAll($foreignData);
115 $output = '<form class="ajax" '
116 . 'id="browse_foreign_form" name="browse_foreign_from" '
117 . 'action="browse_foreigners.php" method="post">'
118 . '<fieldset>'
119 . PMA_URL_getHiddenInputs($db, $table)
120 . '<input type="hidden" name="field" value="' . htmlspecialchars($field)
121 . '" />'
122 . '<input type="hidden" name="fieldkey" value="'
123 . (isset($fieldkey) ? htmlspecialchars($fieldkey) : '') . '" />';
125 if (isset($_REQUEST['rownumber'])) {
126 $output .= '<input type="hidden" name="rownumber" value="'
127 . htmlspecialchars($_REQUEST['rownumber']) . '" />';
129 $filter_value = (isset($_REQUEST['foreign_filter'])
130 ? htmlspecialchars($_REQUEST['foreign_filter'])
131 : '');
132 $output .= '<span class="formelement">'
133 . '<label for="input_foreign_filter">' . __('Search:') . '</label>'
134 . '<input type="text" name="foreign_filter" '
135 . 'id="input_foreign_filter" '
136 . 'value="' . $filter_value . '" data-old="' . $filter_value . '" '
137 . '/>'
138 . '<input type="submit" name="submit_foreign_filter" value="'
139 . __('Go') . '" />'
140 . '</span>'
141 . '<span class="formelement">' . $gotopage . '</span>'
142 . '<span class="formelement">' . $showall . '</span>'
143 . '</fieldset>'
144 . '</form>';
146 $output .= '<table width="100%" id="browse_foreign_table">';
148 if (!is_array($foreignData['disp_row'])) {
149 $output .= '</tbody>'
150 . '</table>';
152 return $output;
155 $header = '<tr>
156 <th>' . __('Keyname') . '</th>
157 <th>' . __('Description') . '</th>
158 <td width="20%"></td>
159 <th>' . __('Description') . '</th>
160 <th>' . __('Keyname') . '</th>
161 </tr>';
163 $output .= '<thead>' . $header . '</thead>' . "\n"
164 . '<tfoot>' . $header . '</tfoot>' . "\n"
165 . '<tbody>' . "\n";
167 $descriptions = array();
168 $keys = array();
169 foreach ($foreignData['disp_row'] as $relrow) {
170 if ($foreignData['foreign_display'] != false) {
171 $descriptions[] = $relrow[$foreignData['foreign_display']];
172 } else {
173 $descriptions[] = '';
176 $keys[] = $relrow[$foreignData['foreign_field']];
179 asort($keys);
181 $horizontal_count = 0;
182 $odd_row = true;
183 $indexByDescription = 0;
185 foreach ($keys as $indexByKeyname => $value) {
186 list(
187 $html,
188 $horizontal_count,
189 $odd_row,
190 $indexByDescription
191 ) = PMA_getHtmlForOneKey(
192 $horizontal_count, $header, $odd_row, $keys, $indexByKeyname,
193 $descriptions, $indexByDescription, $current_value
195 $output .= $html;
198 $output .= '</tbody>'
199 . '</table>';
201 return $output;
205 * Get the description (possibly truncated) and the title
207 * @param string $description the key name's description
209 * @return array the new description and title
211 function PMA_getDescriptionAndTitle($description)
213 $limitChars = $GLOBALS['cfg']['LimitChars'];
214 if (mb_strlen($description) <= $limitChars) {
215 $description = htmlspecialchars(
216 $description
218 $descriptionTitle = '';
219 } else {
220 $descriptionTitle = htmlspecialchars(
221 $description
223 $description = htmlspecialchars(
224 mb_substr(
225 $description, 0, $limitChars
227 . '...'
230 return array($description, $descriptionTitle);
234 * Function to get html for each column element
236 * @param string $cssClass class="nowrap" or ''
237 * @param bool $isSelected whether current equals form's value
238 * @param string $keyname current key
239 * @param string $description current value
240 * @param string $title current title
242 * @return string
244 function PMA_getHtmlForColumnElement($cssClass, $isSelected, $keyname,
245 $description, $title
247 $keyname = htmlspecialchars($keyname);
248 $output = '<td';
249 if (! empty($cssClass)) {
250 $output .= ' ' . $cssClass;
252 $output .= '>'
253 . ($isSelected ? '<strong>' : '')
254 . '<a class="foreign_value" data-key="' . $keyname . '" '
255 . 'href="#" title="' . __('Use this value')
256 . ($title != ''
257 ? ': ' . $title
258 : '')
259 . '">';
260 if ($cssClass !== '') {
261 $output .= $keyname;
262 } else {
263 $output .= $description;
266 $output .= '</a>' . ($isSelected ? '</strong>' : '') . '</td>';
268 return $output;
272 * Function to get html for show all case
274 * @param array $foreignData foreign data
276 * @return string
278 function PMA_getHtmlForShowAll($foreignData)
280 $showall = '';
281 if (is_array($foreignData['disp_row'])) {
282 if ($GLOBALS['cfg']['ShowAll']
283 && ($foreignData['the_total'] > $GLOBALS['cfg']['MaxRows'])
285 $showall = '<input type="submit" id="foreign_showAll" '
286 . 'name="foreign_showAll" '
287 . 'value="' . __('Show all') . '" />';
291 return $showall;
295 * Function to get html for the goto page option
297 * @param array $foreignData foreign data
299 * @return string
301 function PMA_getHtmlForGotoPage($foreignData)
303 $gotopage = '';
304 isset($_REQUEST['pos']) ? $pos = $_REQUEST['pos'] : $pos = 0;
305 if (!is_array($foreignData['disp_row'])) {
306 return $gotopage;
309 $session_max_rows = $GLOBALS['cfg']['MaxRows'];
310 $pageNow = @floor($pos / $session_max_rows) + 1;
311 $nbTotalPage = @ceil($foreignData['the_total'] / $session_max_rows);
313 if ($foreignData['the_total'] > $GLOBALS['cfg']['MaxRows']) {
314 $gotopage = PMA\libraries\Util::pageselector(
315 'pos',
316 $session_max_rows,
317 $pageNow,
318 $nbTotalPage,
319 200,
324 __('Page number:')
328 return $gotopage;
332 * Function to get foreign limit
334 * @param string $foreign_showAll foreign navigation
336 * @return string
338 function PMA_getForeignLimit($foreign_showAll)
340 if (isset($foreign_showAll) && $foreign_showAll == __('Show all')) {
341 return null;
343 isset($_REQUEST['pos']) ? $pos = $_REQUEST['pos'] : $pos = 0;
344 return 'LIMIT ' . $pos . ', ' . intval($GLOBALS['cfg']['MaxRows']) . ' ';