Translated using Weblate (Bulgarian)
[phpmyadmin.git] / browse_foreigners.php
blob87a214f4e36fe5dbda661f03726cb2621c17cefe
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 $field = $_REQUEST['field'];
14 PMA_Util::checkParameters(array('db', 'table', 'field'));
16 $response = PMA_Response::getInstance();
17 $response->getFooter()->setMinimal();
18 $header = $response->getHeader();
19 $header->disableMenu();
20 $header->setBodyId('body_browse_foreigners');
22 /**
23 * Displays the frame
26 $cfgRelation = PMA_getRelationsParam();
27 $foreigners = ($cfgRelation['relwork'] ? PMA_getForeigners($db, $table) : false);
29 $override_total = true;
31 if (! isset($pos)) {
32 $pos = 0;
35 $foreign_limit = 'LIMIT ' . $pos . ', ' . $GLOBALS['cfg']['MaxRows'] . ' ';
36 if (isset($foreign_navig) && $foreign_navig == __('Show all')) {
37 unset($foreign_limit);
40 $foreignData = PMA_getForeignData(
41 $foreigners, $field, $override_total,
42 isset($foreign_filter) ? $foreign_filter : '', $foreign_limit
45 if (isset($rownumber)) {
46 $rownumber_param = '&amp;rownumber=' . urlencode($rownumber);
47 } else {
48 $rownumber_param = '';
51 $gotopage = '';
52 $showall = '';
54 if (is_array($foreignData['disp_row'])) {
56 if ($cfg['ShowAll']
57 && ($foreignData['the_total'] > $GLOBALS['cfg']['MaxRows'])
58 ) {
59 $showall = '<input type="submit" name="foreign_navig" value="'
60 . __('Show all') . '" />';
63 $session_max_rows = $GLOBALS['cfg']['MaxRows'];
64 $pageNow = @floor($pos / $session_max_rows) + 1;
65 $nbTotalPage = @ceil($foreignData['the_total'] / $session_max_rows);
67 if ($foreignData['the_total'] > $GLOBALS['cfg']['MaxRows']) {
68 $gotopage = PMA_Util::pageselector(
69 $session_max_rows,
70 $pageNow,
71 $nbTotalPage,
72 200,
75 20,
76 10,
77 __('Page number:')
84 if (isset($rownumber)) {
85 $element_name = " var element_name = field + '[multi_edit]["
86 . htmlspecialchars($rownumber) . "][' + fieldmd5 + ']';\n"
87 . " var null_name = field_null + '[multi_edit]["
88 . htmlspecialchars($rownumber) . "][' + fieldmd5 + ']';\n";
89 } else {
90 $element_name = "var element_name = field + '[]'";
92 $error = PMA_jsFormat(
93 __(
94 'The target browser window could not be updated. '
95 . 'Maybe you have closed the parent window, or '
96 . 'your browser\'s security settings are '
97 . 'configured to block cross-window updates.'
102 if (! isset($fieldkey) || ! is_numeric($fieldkey)) {
103 $fieldkey = 0;
106 $code = <<<EOC
107 self.focus();
108 function formupdate(fieldmd5, key) {
109 var \$inline = window.opener.jQuery('.browse_foreign_clicked');
110 if (\$inline.length != 0) {
111 \$inline.removeClass('browse_foreign_clicked')
112 // for grid editing,
113 // puts new value in the previous element which is
114 // a span with class curr_value, and trigger .change()
115 .prev('.curr_value').text(key).change();
116 // for zoom-search editing, puts new value in the previous
117 // element which is an input field
118 \$inline.prev('input[type=text]').val(key);
119 self.close();
120 return false;
123 if (opener && opener.document && opener.document.insertForm) {
124 var field = 'fields';
125 var field_null = 'fields_null';
127 $element_name
129 var element_name_alt = field + '[$fieldkey]';
131 if (opener.document.insertForm.elements[element_name]) {
132 // Edit/Insert form
133 opener.document.insertForm.elements[element_name].value = key;
134 if (opener.document.insertForm.elements[null_name]) {
135 opener.document.insertForm.elements[null_name].checked = false;
137 self.close();
138 return false;
139 } else if (opener.document.insertForm.elements[element_name_alt]) {
140 // Search form
141 opener.document.insertForm.elements[element_name_alt].value = key;
142 self.close();
143 return false;
147 alert('$error');
149 EOC;
151 $header->getScripts()->addCode($code);
153 // HTML output
154 $output = '<form action="browse_foreigners.php" method="post">'
155 . '<fieldset>'
156 . PMA_generate_common_hidden_inputs($db, $table)
157 . '<input type="hidden" name="field" value="' . htmlspecialchars($field) . '" />'
158 . '<input type="hidden" name="fieldkey" value="'
159 . (isset($fieldkey) ? htmlspecialchars($fieldkey) : '') . '" />';
161 if (isset($rownumber)) {
162 $output .= '<input type="hidden" name="rownumber" value="'
163 . htmlspecialchars($rownumber) . '" />';
165 $output .= '<span class="formelement">'
166 . '<label for="input_foreign_filter">' . __('Search:') . '</label>'
167 . '<input type="text" name="foreign_filter" id="input_foreign_filter" value="'
168 . (isset($foreign_filter) ? htmlspecialchars($foreign_filter) : '') . '" />'
169 . '<input type="submit" name="submit_foreign_filter" value="'
170 . __('Go') . '" />'
171 . '</span>'
172 . '<span class="formelement">' . $gotopage . '</span>'
173 . '<span class="formelement">' . $showall . '</span>'
174 . '</fieldset>'
175 . '</form>';
177 $output .= '<table width="100%">';
179 if (is_array($foreignData['disp_row'])) {
180 $header = '<tr>
181 <th>' . __('Keyname') . '</th>
182 <th>' . __('Description') . '</th>
183 <td width="20%"></td>
184 <th>' . __('Description') . '</th>
185 <th>' . __('Keyname') . '</th>
186 </tr>';
188 $output .= '<thead>' . $header . '</thead>' . "\n"
189 . '<tfoot>' . $header . '</tfoot>' . "\n"
190 . '<tbody>' . "\n";
192 $values = array();
193 $keys = array();
194 foreach ($foreignData['disp_row'] as $relrow) {
195 if ($foreignData['foreign_display'] != false) {
196 $values[] = $relrow[$foreignData['foreign_display']];
197 } else {
198 $values[] = '';
201 $keys[] = $relrow[$foreignData['foreign_field']];
204 asort($keys);
206 $hcount = 0;
207 $odd_row = true;
208 $val_ordered_current_row = 0;
209 $val_ordered_current_equals_data = false;
210 $key_ordered_current_equals_data = false;
211 foreach ($keys as $key_ordered_current_row => $value) {
212 $hcount++;
214 if ($cfg['RepeatCells'] > 0 && $hcount > $cfg['RepeatCells']) {
215 $output .= $header;
216 $hcount = 0;
217 $odd_row = true;
220 $key_ordered_current_key = $keys[$key_ordered_current_row];
221 $key_ordered_current_val = $values[$key_ordered_current_row];
223 $val_ordered_current_key = $keys[$val_ordered_current_row];
224 $val_ordered_current_val = $values[$val_ordered_current_row];
226 $val_ordered_current_row++;
228 if (PMA_strlen($val_ordered_current_val) <= $cfg['LimitChars']) {
229 $val_ordered_current_val = htmlspecialchars(
230 $val_ordered_current_val
232 $val_ordered_current_val_title = '';
233 } else {
234 $val_ordered_current_val_title = htmlspecialchars(
235 $val_ordered_current_val
237 $val_ordered_current_val = htmlspecialchars(
238 PMA_substr($val_ordered_current_val, 0, $cfg['LimitChars'])
239 . '...'
242 if (PMA_strlen($key_ordered_current_val) <= $cfg['LimitChars']) {
243 $key_ordered_current_val = htmlspecialchars(
244 $key_ordered_current_val
246 $key_ordered_current_val_title = '';
247 } else {
248 $key_ordered_current_val_title = htmlspecialchars(
249 $key_ordered_current_val
251 $key_ordered_current_val = htmlspecialchars(
252 PMA_substr(
253 $key_ordered_current_val, 0, $cfg['LimitChars']
254 ) . '...'
258 if (! empty($data)) {
259 $val_ordered_current_equals_data = $val_ordered_current_key == $data;
260 $key_ordered_current_equals_data = $key_ordered_current_key == $data;
263 $output .= '<tr class="noclick ' . ($odd_row ? 'odd' : 'even') . '">';
264 $odd_row = ! $odd_row;
266 $output .= '<td class="nowrap">'
267 . ($key_ordered_current_equals_data ? '<strong>' : '')
268 . '<a href="#" title="' . __('Use this value')
269 . ($key_ordered_current_val_title != ''
270 ? ': ' . $key_ordered_current_val_title
271 : '') . '"'
272 . ' onclick="formupdate(\'' . md5($field) . '\', \''
273 . PMA_jsFormat($key_ordered_current_key, false) . '\'); return false;">'
274 . htmlspecialchars($key_ordered_current_key)
275 . '</a>' . ($key_ordered_current_equals_data ? '</strong>' : '')
276 . '</td>';
278 $output .= '<td>'
279 . ($key_ordered_current_equals_data ? '<strong>' : '')
280 . '<a href="#" title="' . __('Use this value')
281 . ($key_ordered_current_val_title != '' ? ': '
282 . $key_ordered_current_val_title : '') . '" onclick="formupdate(\''
283 . md5($field) . '\', \''
284 . PMA_jsFormat($key_ordered_current_key, false)
285 . '\'); return false;">'
286 . $key_ordered_current_val . '</a>'
287 . ($key_ordered_current_equals_data ? '</strong>' : '')
288 . '</td>';
290 $output .= '<td width="20%">'
291 . '<img src="' . $GLOBALS['pmaThemeImage'] . 'spacer.png" alt=""'
292 . ' width="1" height="1" /></td>';
294 $output .= '<td>'
295 . ($val_ordered_current_equals_data ? '<strong>' : '')
296 . '<a href="#" title="' . __('Use this value')
297 . ($val_ordered_current_val_title != '' ? ': '
298 . $val_ordered_current_val_title : '') . '" onclick="formupdate(\''
299 . md5($field) . '\', \''
300 . PMA_jsFormat($val_ordered_current_key, false)
301 . '\'); return false;">'
302 . $val_ordered_current_val . '</a>'
303 . ($val_ordered_current_equals_data ? '</strong>' : '')
304 . '</td>';
306 $output .= '<td class="nowrap">'
307 . ($val_ordered_current_equals_data ? '<strong>' : '')
308 . '<a href="#" title="' . __('Use this value')
309 . ($val_ordered_current_val_title != ''
310 ? ': ' . $val_ordered_current_val_title : '')
311 . '" onclick="formupdate(\'' . md5($field) . '\', \''
312 . PMA_jsFormat($val_ordered_current_key, false) . '\'); return false;">'
313 . htmlspecialchars($val_ordered_current_key)
314 . '</a>' . ($val_ordered_current_equals_data ? '</strong>' : '')
315 . '</td>';
316 $output .= '</tr>';
317 } // end while
320 $output .= '</tbody>'
321 . '</table>';
323 $response->addHtml($output);