fixed: bugID = 3112614
[phpmyadmin/adnan.git] / browse_foreigners.php
blob4cfa543e8f52f2cf167bfba991be9c2c21514f88
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 /**
10 * Gets a core script and starts output buffering work
12 require_once './libraries/common.inc.php';
14 PMA_checkParameters(array('db', 'table', 'field'));
16 require_once './libraries/ob.lib.php';
17 PMA_outBufferPre();
19 require_once './libraries/header_http.inc.php';
21 /**
22 * Displays the frame
24 $per_page = 200;
25 require_once './libraries/transformations.lib.php'; // Transformations
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 . ', ' . $per_page . ' ';
36 if (isset($foreign_navig) && $foreign_navig == __('Show all')) {
37 unset($foreign_limit);
40 $foreignData = PMA_getForeignData($foreigners, $field, $override_total, isset($foreign_filter) ? $foreign_filter : '', $foreign_limit);
42 if (isset($pk)) {
43 $pk_uri = '&amp;pk=' . urlencode($pk);
45 <input type="hidden" name="pk" value="<?php echo htmlspecialchars($pk); ?>" />
46 <?php
47 } else {
48 $pk_uri = '';
51 $gotopage = '';
52 $showall = '';
54 if (is_array($foreignData['disp_row'])) {
56 if ($cfg['ShowAll'] && ($foreignData['the_total'] > $per_page)) {
57 $showall = '<input type="submit" name="foreign_navig" value="' . __('Show all') . '" />';
60 $session_max_rows = $per_page;
61 $pageNow = @floor($pos / $session_max_rows) + 1;
62 $nbTotalPage = @ceil($foreignData['the_total'] / $session_max_rows);
64 if ($foreignData['the_total'] > $per_page) {
65 $gotopage = PMA_pageselector(
66 'browse_foreigners.php?field=' . urlencode($field) .
67 '&amp;' . PMA_generate_common_url($db, $table)
68 . $pk_uri .
69 '&amp;fieldkey=' . (isset($fieldkey) ? urlencode($fieldkey) : '') .
70 '&amp;foreign_filter=' . (isset($foreign_filter) ? urlencode($foreign_filter) : '') .
71 '&amp;',
72 $session_max_rows,
73 $pageNow,
74 $nbTotalPage,
75 200,
78 20,
79 10,
80 __('Page number:')
85 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
86 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
87 <html xmlns="http://www.w3.org/1999/xhtml"
88 xml:lang="<?php echo $available_languages[$lang][1]; ?>"
89 lang="<?php echo $available_languages[$lang][1]; ?>"
90 dir="<?php echo $text_dir; ?>">
92 <head>
93 <title>phpMyAdmin</title>
94 <meta http-equiv="Content-Type" content="text/html; charset=<?php echo $charset; ?>" />
95 <link rel="stylesheet" type="text/css"
96 href="phpmyadmin.css.php?<?php echo PMA_generate_common_url('', ''); ?>&amp;js_frame=right&amp;nocache=<?php echo $GLOBALS['PMA_Config']->getThemeUniqueValue(); ?>" />
97 <script src="./js/functions.js" type="text/javascript"></script>
98 <script type="text/javascript">
99 //<![CDATA[
100 self.focus();
101 function formupdate(field, key) {
102 if (opener && opener.document && opener.document.insertForm) {
103 var field = 'field_' + field;
105 <?php if (isset($pk)) { ?>
106 var element_name = field + '[multi_edit][<?php echo htmlspecialchars($pk); ?>][]';
107 <?php } else { ?>
108 var element_name = field + '[]';
109 <?php } ?>
111 <?php if (isset($fieldkey) && is_numeric($fieldkey)) { ?>
112 var element_name_alt = field + '[<?php echo $fieldkey; ?>]';
113 <?php } else { ?>
114 var element_name_alt = field + '[0]';
115 <?php } ?>
117 if (opener.document.insertForm.elements[element_name]) {
118 // Edit/Insert form
119 opener.document.insertForm.elements[element_name].value = key;
120 self.close();
121 return false;
122 } else if (opener.document.insertForm.elements[element_name_alt]) {
123 // Search form
124 opener.document.insertForm.elements[element_name_alt].value = key;
125 self.close();
126 return false;
130 alert('<?php echo PMA_jsFormat(__('The target browser window could not be updated. Maybe you have closed the parent window, or your browser\'s security settings are configured to block cross-window updates.')); ?>');
132 //]]>
133 </script>
134 </head>
136 <body id="body_browse_foreigners">
138 <form action="browse_foreigners.php" method="post">
139 <fieldset>
140 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
141 <input type="hidden" name="field" value="<?php echo htmlspecialchars($field); ?>" />
142 <input type="hidden" name="fieldkey"
143 value="<?php echo isset($fieldkey) ? htmlspecialchars($fieldkey) : ''; ?>" />
144 <?php if (isset($pk)) { ?>
145 <input type="hidden" name="pk" value="<?php echo htmlspecialchars($pk); ?>" />
146 <?php } ?>
147 <span class="formelement">
148 <label for="input_foreign_filter"><?php echo __('Search') . ':'; ?></label>
149 <input type="text" name="foreign_filter" id="input_foreign_filter"
150 value="<?php echo isset($foreign_filter) ? htmlspecialchars($foreign_filter) : ''; ?>" />
151 <input type="submit" name="submit_foreign_filter" value="<?php echo __('Go');?>" />
152 </span>
153 <span class="formelement">
154 <?php echo $gotopage; ?>
155 </span>
156 <span class="formelement">
157 <?php echo $showall; ?>
158 </span>
159 </fieldset>
160 </form>
162 <table width="100%">
163 <?php
164 if (is_array($foreignData['disp_row'])) {
165 $header = '<tr>
166 <th>' . __('Keyname') . '</th>
167 <th>' . __('Description') . '</th>
168 <td width="20%"></td>
169 <th>' . __('Description') . '</th>
170 <th>' . __('Keyname') . '</th>
171 </tr>';
173 echo '<thead>' . $header . '</thead>' . "\n"
174 .'<tfoot>' . $header . '</tfoot>' . "\n"
175 .'<tbody>' . "\n";
177 $values = array();
178 $keys = array();
179 foreach ($foreignData['disp_row'] as $relrow) {
180 if ($foreignData['foreign_display'] != FALSE) {
181 $values[] = $relrow[$foreignData['foreign_display']];
182 } else {
183 $values[] = '';
186 $keys[] = $relrow[$foreignData['foreign_field']];
189 asort($keys);
191 $hcount = 0;
192 $odd_row = true;
193 $val_ordered_current_row = 0;
194 $val_ordered_current_equals_data = false;
195 $key_ordered_current_equals_data = false;
196 foreach ($keys as $key_ordered_current_row => $value) {
197 //for ($i = 0; $i < $count; $i++) {
198 $hcount++;
200 if ($cfg['RepeatCells'] > 0 && $hcount > $cfg['RepeatCells']) {
201 echo $header;
202 $hcount = 0;
203 $odd_row = true;
206 $key_ordered_current_key = $keys[$key_ordered_current_row];
207 $key_ordered_current_val = $values[$key_ordered_current_row];
209 $val_ordered_current_key = $keys[$val_ordered_current_row];
210 $val_ordered_current_val = $values[$val_ordered_current_row];
212 $val_ordered_current_row++;
214 if (PMA_strlen($val_ordered_current_val) <= $cfg['LimitChars']) {
215 $val_ordered_current_val = htmlspecialchars($val_ordered_current_val);
216 $val_ordered_current_val_title = '';
217 } else {
218 $val_ordered_current_val_title =
219 htmlspecialchars($val_ordered_current_val);
220 $val_ordered_current_val =
221 htmlspecialchars(PMA_substr($val_ordered_current_val, 0,
222 $cfg['LimitChars']) . '...');
224 if (PMA_strlen($key_ordered_current_val) <= $cfg['LimitChars']) {
225 $key_ordered_current_val = htmlspecialchars($key_ordered_current_val);
226 $key_ordered_current_val_title = '';
227 } else {
228 $key_ordered_current_val_title =
229 htmlspecialchars($key_ordered_current_val);
230 $key_ordered_current_val =
231 htmlspecialchars(PMA_substr($key_ordered_current_val, 0,
232 $cfg['LimitChars']) . '...');
235 if (! empty($data)) {
236 $val_ordered_current_equals_data = $val_ordered_current_key == $data;
237 $key_ordered_current_equals_data = $key_ordered_current_key == $data;
241 <tr class="<?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
242 <td nowrap="nowrap">
243 <?php
244 echo ($key_ordered_current_equals_data ? '<strong>' : '')
245 .'<a href="#" title="' . __('Use this value')
246 . ($key_ordered_current_val_title != '' ? ': ' . $key_ordered_current_val_title : '') . '"'
247 .' onclick="formupdate(\'' . md5($field) . '\', \''
248 . PMA_jsFormat($key_ordered_current_key, false) . '\'); return false;">'
249 .htmlspecialchars($key_ordered_current_key) . '</a>' . ($key_ordered_current_equals_data ? '</strong>' : '');
250 ?></td>
251 <td>
252 <?php
253 echo ($key_ordered_current_equals_data ? '<strong>' : '')
254 . '<a href="#" title="' . __('Use this value') . ($key_ordered_current_val_title != '' ? ': '
255 . $key_ordered_current_val_title : '') . '" onclick="formupdate(\''
256 . md5($field) . '\', \'' . PMA_jsFormat($key_ordered_current_key, false) . '\'); return false;">'
257 . $key_ordered_current_val . '</a>' . ($key_ordered_current_equals_data ? '</strong>' : '');
258 ?></td>
259 <td width="20%">
260 <img src="<?php echo $GLOBALS['pmaThemeImage'] . 'spacer.png'; ?>"
261 alt="" width="1" height="1"></td>
263 <td>
264 <?php
265 echo ($val_ordered_current_equals_data ? '<strong>' : '')
266 . '<a href="#" title="' . __('Use this value') . ($val_ordered_current_val_title != '' ? ': '
267 . $val_ordered_current_val_title : '') . '" onclick="formupdate(\'' . md5($field)
268 . '\', \'' . PMA_jsFormat($val_ordered_current_key, false) . '\'); return false;">'
269 . $val_ordered_current_val . '</a>' . ($val_ordered_current_equals_data ? '</strong>' : '');
270 ?></td>
271 <td nowrap="nowrap">
272 <?php
273 echo ($val_ordered_current_equals_data ? '<strong>' : '') . '<a href="#" title="'
274 . __('Use this value') . ($val_ordered_current_val_title != '' ? ': ' . $val_ordered_current_val_title : '')
275 . '" onclick="formupdate(\'' . md5($field) . '\', \''
276 . PMA_jsFormat($val_ordered_current_key, false) . '\'); return false;">' . htmlspecialchars($val_ordered_current_key)
277 . '</a>' . ($val_ordered_current_equals_data ? '</strong>' : '');
278 ?></td>
279 </tr>
280 <?php
281 } // end while
284 </tbody>
285 </table>
287 </body>
288 </html>