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';
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');
26 $cfgRelation = PMA_getRelationsParam();
27 $foreigners = ($cfgRelation['relwork'] ?
PMA_getForeigners($db, $table) : false);
29 $override_total = true;
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 = '&rownumber=' . urlencode($rownumber);
48 $rownumber_param = '';
54 if (is_array($foreignData['disp_row'])) {
57 && ($foreignData['the_total'] > $GLOBALS['cfg']['MaxRows'])
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(
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";
90 $element_name = "var element_name = field + '[]'";
92 $error = PMA_jsFormat(
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)) {
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')
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);
123 if (opener && opener.document && opener.document.insertForm) {
124 var field = 'fields';
125 var field_null = 'fields_null';
129 var element_name_alt = field + '[$fieldkey]';
131 if (opener.document.insertForm.elements[element_name]) {
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;
139 } else if (opener.document.insertForm.elements[element_name_alt]) {
141 opener.document.insertForm.elements[element_name_alt].value = key;
151 $header->getScripts()->addCode($code);
154 $output = '<form action="browse_foreigners.php" method="post">'
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="'
172 . '<span class="formelement">' . $gotopage . '</span>'
173 . '<span class="formelement">' . $showall . '</span>'
177 $output .= '<table width="100%">';
179 if (is_array($foreignData['disp_row'])) {
181 <th>' . __('Keyname') . '</th>
182 <th>' . __('Description') . '</th>
183 <td width="20%"></td>
184 <th>' . __('Description') . '</th>
185 <th>' . __('Keyname') . '</th>
188 $output .= '<thead>' . $header . '</thead>' . "\n"
189 . '<tfoot>' . $header . '</tfoot>' . "\n"
194 foreach ($foreignData['disp_row'] as $relrow) {
195 if ($foreignData['foreign_display'] != false) {
196 $values[] = $relrow[$foreignData['foreign_display']];
201 $keys[] = $relrow[$foreignData['foreign_field']];
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) {
214 if ($cfg['RepeatCells'] > 0 && $hcount > $cfg['RepeatCells']) {
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 = '';
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'])
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 = '';
248 $key_ordered_current_val_title = htmlspecialchars(
249 $key_ordered_current_val
251 $key_ordered_current_val = htmlspecialchars(
253 $key_ordered_current_val, 0, $cfg['LimitChars']
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
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>' : '')
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>' : '')
290 $output .= '<td width="20%">'
291 . '<img src="' . $GLOBALS['pmaThemeImage'] . 'spacer.png" alt=""'
292 . ' width="1" height="1" /></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>' : '')
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>' : '')
320 $output .= '</tbody>'
323 $response->addHtml($output);