2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * display selection for relational field values
9 require_once 'libraries/common.inc.php';
10 require_once 'libraries/transformations.lib.php';
13 * Sets globals from $_REQUEST
15 $request_params = array(
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');
37 $cfgRelation = PMA_getRelationsParam();
38 $foreigners = ($cfgRelation['relwork'] ?
PMA_getForeigners($db, $table) : false);
40 $override_total = true;
42 if (! isset($_REQUEST['pos'])) {
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']
63 if (is_array($foreignData['disp_row'])) {
66 && ($foreignData['the_total'] > $GLOBALS['cfg']['MaxRows'])
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(
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";
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";
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'])) {
122 $fieldkey = $_REQUEST['fieldkey'];
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')
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);
142 if (opener && opener.document && opener.document.insertForm) {
143 var field = 'fields';
144 var field_null = 'fields_null';
148 var element_name_alt = field + '[$fieldkey]';
150 if (opener.document.insertForm.elements[element_name]) {
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;
158 } else if (opener.document.insertForm.elements[element_name_alt]) {
160 opener.document.insertForm.elements[element_name_alt].value = key;
170 $header->getScripts()->addCode($code);
173 $output = '<form action="browse_foreigners.php" method="post">'
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'])
191 . '<input type="submit" name="submit_foreign_filter" value="'
194 . '<span class="formelement">' . $gotopage . '</span>'
195 . '<span class="formelement">' . $showall . '</span>'
199 $output .= '<table width="100%">';
201 if (is_array($foreignData['disp_row'])) {
203 <th>' . __('Keyname') . '</th>
204 <th>' . __('Description') . '</th>
205 <td width="20%"></td>
206 <th>' . __('Description') . '</th>
207 <th>' . __('Keyname') . '</th>
210 $output .= '<thead>' . $header . '</thead>' . "\n"
211 . '<tfoot>' . $header . '</tfoot>' . "\n"
216 foreach ($foreignData['disp_row'] as $relrow) {
217 if ($foreignData['foreign_display'] != false) {
218 $values[] = $relrow[$foreignData['foreign_display']];
223 $keys[] = $relrow[$foreignData['foreign_field']];
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) {
236 if ($cfg['RepeatCells'] > 0 && $hcount > $cfg['RepeatCells']) {
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 = '';
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'])
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 = '';
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']
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
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>' : '')
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>' : '')
312 $output .= '<td width="20%">'
313 . '<img src="' . $GLOBALS['pmaThemeImage'] . 'spacer.png" alt=""'
314 . ' width="1" height="1" /></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>' : '')
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>' : '')
342 $output .= '</tbody>'
345 $response->addHtml($output);