Translated using Weblate (Portuguese)
[phpmyadmin.git] / browse_foreigners.php
blob946c1ce2f2daefa2e348c8c5963b1e804ea5bf0c
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * display selection for relational field values
6 * @package PhpMyAdmin
7 */
9 require_once 'libraries/common.inc.php';
10 require_once 'libraries/transformations.lib.php';
12 /**
13 * Sets globals from $_REQUEST
15 $request_params = array(
16 'field'
19 foreach ($request_params as $one_request_param) {
20 if (isset($_REQUEST[$one_request_param])) {
21 $GLOBALS[$one_request_param] = $_REQUEST[$one_request_param];
25 PMA_Util::checkParameters(array('db', 'table', 'field'));
27 $response = PMA_Response::getInstance();
28 $response->getFooter()->setMinimal();
29 $header = $response->getHeader();
30 $header->disableMenu();
31 $header->setBodyId('body_browse_foreigners');
33 /**
34 * Displays the frame
37 $cfgRelation = PMA_getRelationsParam();
38 $foreigners = ($cfgRelation['relwork'] ? PMA_getForeigners($db, $table) : false);
40 $override_total = true;
42 if (! isset($_REQUEST['pos'])) {
43 $pos = 0;
44 } else {
45 $pos = $_REQUEST['pos'];
48 $foreign_limit = 'LIMIT ' . $pos . ', ' . $GLOBALS['cfg']['MaxRows'] . ' ';
49 if (isset($foreign_navig) && $foreign_navig == __('Show all')) {
50 unset($foreign_limit);
53 $foreignData = PMA_getForeignData(
54 $foreigners, $field, $override_total,
55 isset($_REQUEST['foreign_filter'])
56 ? $_REQUEST['foreign_filter']
57 : '', $foreign_limit
60 $gotopage = '';
61 $showall = '';
63 if (is_array($foreignData['disp_row'])) {
65 if ($cfg['ShowAll']
66 && ($foreignData['the_total'] > $GLOBALS['cfg']['MaxRows'])
67 ) {
68 $showall = '<input type="submit" name="foreign_navig" value="'
69 . __('Show all') . '" />';
72 $session_max_rows = $GLOBALS['cfg']['MaxRows'];
73 $pageNow = @floor($pos / $session_max_rows) + 1;
74 $nbTotalPage = @ceil($foreignData['the_total'] / $session_max_rows);
76 if ($foreignData['the_total'] > $GLOBALS['cfg']['MaxRows']) {
77 $gotopage = PMA_Util::pageselector(
78 'pos',
79 $session_max_rows,
80 $pageNow,
81 $nbTotalPage,
82 200,
85 20,
86 10,
87 __('Page number:')
92 // When coming from Table/Zoom search
93 if (isset($_REQUEST['fromsearch'])) {
94 // In table or zoom search, input fields are named "criteriaValues"
95 $element_name = " var field = 'criteriaValues';\n";
96 } else {
97 // In insert/edit, input fields are named "fields"
98 $element_name = " var field = 'fields';\n";
101 if (isset($_REQUEST['rownumber'])) {
102 $element_name .= " var element_name = field + '[multi_edit]["
103 . htmlspecialchars($_REQUEST['rownumber']) . "][' + fieldmd5 + ']';\n"
104 . " var null_name = field_null + '[multi_edit]["
105 . htmlspecialchars($_REQUEST['rownumber']) . "][' + fieldmd5 + ']';\n";
106 } else {
107 $element_name .= "var element_name = field + '[]'";
109 $error = PMA_jsFormat(
111 'The target browser window could not be updated. '
112 . 'Maybe you have closed the parent window, or '
113 . 'your browser\'s security settings are '
114 . 'configured to block cross-window updates.'
119 if (! isset($_REQUEST['fieldkey']) || ! is_numeric($_REQUEST['fieldkey'])) {
120 $fieldkey = 0;
121 } else {
122 $fieldkey = $_REQUEST['fieldkey'];
125 $code = <<<EOC
126 self.focus();
127 function formupdate(fieldmd5, key) {
128 var \$inline = window.opener.jQuery('.browse_foreign_clicked');
129 if (\$inline.length != 0) {
130 \$inline.removeClass('browse_foreign_clicked')
131 // for grid editing,
132 // puts new value in the previous element which is
133 // a span with class curr_value, and trigger .change()
134 .prev('.curr_value').text(key).change();
135 // for zoom-search editing, puts new value in the previous
136 // element which is an input field
137 \$inline.prev('input[type=text]').val(key);
138 self.close();
139 return false;
142 if (opener && opener.document && opener.document.insertForm) {
143 var field = 'fields';
144 var field_null = 'fields_null';
146 $element_name
148 var element_name_alt = field + '[$fieldkey]';
150 if (opener.document.insertForm.elements[element_name]) {
151 // Edit/Insert form
152 opener.document.insertForm.elements[element_name].value = key;
153 if (opener.document.insertForm.elements[null_name]) {
154 opener.document.insertForm.elements[null_name].checked = false;
156 self.close();
157 return false;
158 } else if (opener.document.insertForm.elements[element_name_alt]) {
159 // Search form
160 opener.document.insertForm.elements[element_name_alt].value = key;
161 self.close();
162 return false;
166 alert('$error');
168 EOC;
170 $header->getScripts()->addCode($code);
172 // HTML output
173 $output = '<form action="browse_foreigners.php" method="post">'
174 . '<fieldset>'
175 . PMA_URL_getHiddenInputs($db, $table)
176 . '<input type="hidden" name="field" value="' . htmlspecialchars($field) . '" />'
177 . '<input type="hidden" name="fieldkey" value="'
178 . (isset($fieldkey) ? htmlspecialchars($fieldkey) : '') . '" />';
180 if (isset($_REQUEST['rownumber'])) {
181 $output .= '<input type="hidden" name="rownumber" value="'
182 . htmlspecialchars($_REQUEST['rownumber']) . '" />';
184 $output .= '<span class="formelement">'
185 . '<label for="input_foreign_filter">' . __('Search:') . '</label>'
186 . '<input type="text" name="foreign_filter" id="input_foreign_filter" value="'
187 . (isset($_REQUEST['foreign_filter'])
188 ? htmlspecialchars($_REQUEST['foreign_filter'])
189 : '')
190 . '" />'
191 . '<input type="submit" name="submit_foreign_filter" value="'
192 . __('Go') . '" />'
193 . '</span>'
194 . '<span class="formelement">' . $gotopage . '</span>'
195 . '<span class="formelement">' . $showall . '</span>'
196 . '</fieldset>'
197 . '</form>';
199 $output .= '<table width="100%">';
201 if (is_array($foreignData['disp_row'])) {
202 $header = '<tr>
203 <th>' . __('Keyname') . '</th>
204 <th>' . __('Description') . '</th>
205 <td width="20%"></td>
206 <th>' . __('Description') . '</th>
207 <th>' . __('Keyname') . '</th>
208 </tr>';
210 $output .= '<thead>' . $header . '</thead>' . "\n"
211 . '<tfoot>' . $header . '</tfoot>' . "\n"
212 . '<tbody>' . "\n";
214 $values = array();
215 $keys = array();
216 foreach ($foreignData['disp_row'] as $relrow) {
217 if ($foreignData['foreign_display'] != false) {
218 $values[] = $relrow[$foreignData['foreign_display']];
219 } else {
220 $values[] = '';
223 $keys[] = $relrow[$foreignData['foreign_field']];
226 asort($keys);
228 $hcount = 0;
229 $odd_row = true;
230 $val_ordered_current_row = 0;
231 $val_ordered_current_equals_data = false;
232 $key_ordered_current_equals_data = false;
233 foreach ($keys as $key_ordered_current_row => $value) {
234 $hcount++;
236 if ($cfg['RepeatCells'] > 0 && $hcount > $cfg['RepeatCells']) {
237 $output .= $header;
238 $hcount = 0;
239 $odd_row = true;
242 $key_ordered_current_key = $keys[$key_ordered_current_row];
243 $key_ordered_current_val = $values[$key_ordered_current_row];
245 $val_ordered_current_key = $keys[$val_ordered_current_row];
246 $val_ordered_current_val = $values[$val_ordered_current_row];
248 $val_ordered_current_row++;
250 if ($GLOBALS['PMA_String']->strlen($val_ordered_current_val) <= $cfg['LimitChars']) {
251 $val_ordered_current_val = htmlspecialchars(
252 $val_ordered_current_val
254 $val_ordered_current_val_title = '';
255 } else {
256 $val_ordered_current_val_title = htmlspecialchars(
257 $val_ordered_current_val
259 $val_ordered_current_val = htmlspecialchars(
260 $GLOBALS['PMA_String']->substr($val_ordered_current_val, 0, $cfg['LimitChars'])
261 . '...'
264 if ($GLOBALS['PMA_String']->strlen($key_ordered_current_val) <= $cfg['LimitChars']) {
265 $key_ordered_current_val = htmlspecialchars(
266 $key_ordered_current_val
268 $key_ordered_current_val_title = '';
269 } else {
270 $key_ordered_current_val_title = htmlspecialchars(
271 $key_ordered_current_val
273 $key_ordered_current_val = htmlspecialchars(
274 $GLOBALS['PMA_String']->substr(
275 $key_ordered_current_val, 0, $cfg['LimitChars']
276 ) . '...'
280 if (! empty($data)) {
281 $val_ordered_current_equals_data = $val_ordered_current_key == $data;
282 $key_ordered_current_equals_data = $key_ordered_current_key == $data;
285 $output .= '<tr class="noclick ' . ($odd_row ? 'odd' : 'even') . '">';
286 $odd_row = ! $odd_row;
288 $output .= '<td class="nowrap">'
289 . ($key_ordered_current_equals_data ? '<strong>' : '')
290 . '<a href="#" title="' . __('Use this value')
291 . ($key_ordered_current_val_title != ''
292 ? ': ' . $key_ordered_current_val_title
293 : '') . '"'
294 . ' onclick="formupdate(\'' . md5($field) . '\', \''
295 . PMA_jsFormat($key_ordered_current_key, false) . '\'); return false;">'
296 . htmlspecialchars($key_ordered_current_key)
297 . '</a>' . ($key_ordered_current_equals_data ? '</strong>' : '')
298 . '</td>';
300 $output .= '<td>'
301 . ($key_ordered_current_equals_data ? '<strong>' : '')
302 . '<a href="#" title="' . __('Use this value')
303 . ($key_ordered_current_val_title != '' ? ': '
304 . $key_ordered_current_val_title : '') . '" onclick="formupdate(\''
305 . md5($field) . '\', \''
306 . PMA_jsFormat($key_ordered_current_key, false)
307 . '\'); return false;">'
308 . $key_ordered_current_val . '</a>'
309 . ($key_ordered_current_equals_data ? '</strong>' : '')
310 . '</td>';
312 $output .= '<td width="20%">'
313 . '<img src="' . $GLOBALS['pmaThemeImage'] . 'spacer.png" alt=""'
314 . ' width="1" height="1" /></td>';
316 $output .= '<td>'
317 . ($val_ordered_current_equals_data ? '<strong>' : '')
318 . '<a href="#" title="' . __('Use this value')
319 . ($val_ordered_current_val_title != '' ? ': '
320 . $val_ordered_current_val_title : '') . '" onclick="formupdate(\''
321 . md5($field) . '\', \''
322 . PMA_jsFormat($val_ordered_current_key, false)
323 . '\'); return false;">'
324 . $val_ordered_current_val . '</a>'
325 . ($val_ordered_current_equals_data ? '</strong>' : '')
326 . '</td>';
328 $output .= '<td class="nowrap">'
329 . ($val_ordered_current_equals_data ? '<strong>' : '')
330 . '<a href="#" title="' . __('Use this value')
331 . ($val_ordered_current_val_title != ''
332 ? ': ' . $val_ordered_current_val_title : '')
333 . '" onclick="formupdate(\'' . md5($field) . '\', \''
334 . PMA_jsFormat($val_ordered_current_key, false) . '\'); return false;">'
335 . htmlspecialchars($val_ordered_current_key)
336 . '</a>' . ($val_ordered_current_equals_data ? '</strong>' : '')
337 . '</td>';
338 $output .= '</tr>';
339 } // end while
342 $output .= '</tbody>'
343 . '</table>';
345 $response->addHtml($output);