List of fields to add, divided into categories
[phpmyadmin.git] / browse_foreigners.php
blob714d8676d3818c59d90a63476c89d5fb7841c563
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * display selection for relational field values
6 * @version $Id$
7 * @package phpMyAdmin
8 */
10 /**
11 * Gets a core script and starts output buffering work
13 require_once './libraries/common.inc.php';
15 PMA_checkParameters(array('db', 'table', 'field'));
17 require_once './libraries/ob.lib.php';
18 PMA_outBufferPre();
20 require_once './libraries/header_http.inc.php';
22 /**
23 * Displays the frame
25 $per_page = 200;
26 require_once './libraries/relation.lib.php'; // foreign keys
27 require_once './libraries/transformations.lib.php'; // Transformations
28 $cfgRelation = PMA_getRelationsParam();
29 $foreigners = ($cfgRelation['relwork'] ? PMA_getForeigners($db, $table) : FALSE);
31 $override_total = TRUE;
33 if (!isset($pos)) {
34 $pos = 0;
37 $foreign_limit = 'LIMIT ' . $pos . ', ' . $per_page . ' ';
38 if (isset($foreign_navig) && $foreign_navig == __('Show all')) {
39 unset($foreign_limit);
42 $foreignData = PMA_getForeignData($foreigners, $field, $override_total, isset($foreign_filter) ? $foreign_filter : '', $foreign_limit);
44 if (isset($pk)) {
45 $pk_uri = '&amp;pk=' . urlencode($pk);
47 <input type="hidden" name="pk" value="<?php echo htmlspecialchars($pk); ?>" />
48 <?php
49 } else {
50 $pk_uri = '';
53 $gotopage = '';
54 $showall = '';
56 if (is_array($foreignData['disp_row'])) {
58 if ($cfg['ShowAll'] && ($foreignData['the_total'] > $per_page)) {
59 $showall = '<input type="submit" name="foreign_navig" value="' . __('Show all') . '" />';
62 $session_max_rows = $per_page;
63 $pageNow = @floor($pos / $session_max_rows) + 1;
64 $nbTotalPage = @ceil($foreignData['the_total'] / $session_max_rows);
66 if ($foreignData['the_total'] > $per_page) {
67 $gotopage = PMA_pageselector(
68 'browse_foreigners.php?field=' . urlencode($field) .
69 '&amp;' . PMA_generate_common_url($db, $table)
70 . $pk_uri .
71 '&amp;fieldkey=' . (isset($fieldkey) ? urlencode($fieldkey) : '') .
72 '&amp;foreign_filter=' . (isset($foreign_filter) ? urlencode($foreign_filter) : '') .
73 '&amp;',
74 $session_max_rows,
75 $pageNow,
76 $nbTotalPage,
77 200,
80 20,
81 10,
82 __('Page number:')
87 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
88 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
89 <html xmlns="http://www.w3.org/1999/xhtml"
90 xml:lang="<?php echo $available_languages[$lang][1]; ?>"
91 lang="<?php echo $available_languages[$lang][1]; ?>"
92 dir="<?php echo $text_dir; ?>">
94 <head>
95 <title>phpMyAdmin</title>
96 <meta http-equiv="Content-Type" content="text/html; charset=<?php echo $charset; ?>" />
97 <link rel="stylesheet" type="text/css"
98 href="phpmyadmin.css.php?<?php echo PMA_generate_common_url('', ''); ?>&amp;js_frame=right&amp;nocache=<?php echo $GLOBALS['PMA_Config']->getThemeUniqueValue(); ?>" />
99 <script src="./js/functions.js" type="text/javascript"></script>
100 <script type="text/javascript">
101 //<![CDATA[
102 self.focus();
103 function formupdate(field, key) {
104 if (opener && opener.document && opener.document.insertForm) {
105 var field = 'field_' + field;
107 <?php if (isset($pk)) { ?>
108 var element_name = field + '[multi_edit][<?php echo htmlspecialchars($pk); ?>][]';
109 <?php } else { ?>
110 var element_name = field + '[]';
111 <?php } ?>
113 <?php if (isset($fieldkey) && is_numeric($fieldkey)) { ?>
114 var element_name_alt = field + '[<?php echo $fieldkey; ?>]';
115 <?php } else { ?>
116 var element_name_alt = field + '[0]';
117 <?php } ?>
119 if (opener.document.insertForm.elements[element_name]) {
120 // Edit/Insert form
121 opener.document.insertForm.elements[element_name].value = key;
122 self.close();
123 return false;
124 } else if (opener.document.insertForm.elements[element_name_alt]) {
125 // Search form
126 opener.document.insertForm.elements[element_name_alt].value = key;
127 self.close();
128 return false;
132 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.')); ?>');
134 //]]>
135 </script>
136 </head>
138 <body id="body_browse_foreigners">
140 <form action="browse_foreigners.php" method="post">
141 <fieldset>
142 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
143 <input type="hidden" name="field" value="<?php echo htmlspecialchars($field); ?>" />
144 <input type="hidden" name="fieldkey"
145 value="<?php echo isset($fieldkey) ? htmlspecialchars($fieldkey) : ''; ?>" />
146 <?php if (isset($pk)) { ?>
147 <input type="hidden" name="pk" value="<?php echo htmlspecialchars($pk); ?>" />
148 <?php } ?>
149 <span class="formelement">
150 <label for="input_foreign_filter"><?php echo __('Search') . ':'; ?></label>
151 <input type="text" name="foreign_filter" id="input_foreign_filter"
152 value="<?php echo isset($foreign_filter) ? htmlspecialchars($foreign_filter) : ''; ?>" />
153 <input type="submit" name="submit_foreign_filter" value="<?php echo __('Go');?>" />
154 </span>
155 <span class="formelement">
156 <?php echo $gotopage; ?>
157 </span>
158 <span class="formelement">
159 <?php echo $showall; ?>
160 </span>
161 </fieldset>
162 </form>
164 <table width="100%">
165 <?php
166 if (is_array($foreignData['disp_row'])) {
167 $header = '<tr>
168 <th>' . __('Keyname') . '</th>
169 <th>' . __('Description') . '</th>
170 <td width="20%"></td>
171 <th>' . __('Description') . '</th>
172 <th>' . __('Keyname') . '</th>
173 </tr>';
175 echo '<thead>' . $header . '</thead>' . "\n"
176 .'<tfoot>' . $header . '</tfoot>' . "\n"
177 .'<tbody>' . "\n";
179 $values = array();
180 $keys = array();
181 foreach ($foreignData['disp_row'] as $relrow) {
182 if ($foreignData['foreign_display'] != FALSE) {
183 $values[] = $relrow[$foreignData['foreign_display']];
184 } else {
185 $values[] = '';
188 $keys[] = $relrow[$foreignData['foreign_field']];
191 asort($keys);
193 $hcount = 0;
194 $odd_row = true;
195 $val_ordered_current_row = 0;
196 $val_ordered_current_equals_data = false;
197 $key_ordered_current_equals_data = false;
198 foreach ($keys as $key_ordered_current_row => $value) {
199 //for ($i = 0; $i < $count; $i++) {
200 $hcount++;
202 if ($cfg['RepeatCells'] > 0 && $hcount > $cfg['RepeatCells']) {
203 echo $header;
204 $hcount = 0;
205 $odd_row = true;
208 $key_ordered_current_key = $keys[$key_ordered_current_row];
209 $key_ordered_current_val = $values[$key_ordered_current_row];
211 $val_ordered_current_key = $keys[$val_ordered_current_row];
212 $val_ordered_current_val = $values[$val_ordered_current_row];
214 $val_ordered_current_row++;
216 if (PMA_strlen($val_ordered_current_val) <= $cfg['LimitChars']) {
217 $val_ordered_current_val = htmlspecialchars($val_ordered_current_val);
218 $val_ordered_current_val_title = '';
219 } else {
220 $val_ordered_current_val_title =
221 htmlspecialchars($val_ordered_current_val);
222 $val_ordered_current_val =
223 htmlspecialchars(PMA_substr($val_ordered_current_val, 0,
224 $cfg['LimitChars']) . '...');
226 if (PMA_strlen($key_ordered_current_val) <= $cfg['LimitChars']) {
227 $key_ordered_current_val = htmlspecialchars($key_ordered_current_val);
228 $key_ordered_current_val_title = '';
229 } else {
230 $key_ordered_current_val_title =
231 htmlspecialchars($key_ordered_current_val);
232 $key_ordered_current_val =
233 htmlspecialchars(PMA_substr($key_ordered_current_val, 0,
234 $cfg['LimitChars']) . '...');
237 if (! empty($data)) {
238 $val_ordered_current_equals_data = $val_ordered_current_key == $data;
239 $key_ordered_current_equals_data = $key_ordered_current_key == $data;
243 <tr class="<?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
244 <td nowrap="nowrap">
245 <?php
246 echo ($key_ordered_current_equals_data ? '<strong>' : '')
247 .'<a href="#" title="' . __('Use this value')
248 . ($key_ordered_current_val_title != '' ? ': ' . $key_ordered_current_val_title : '') . '"'
249 .' onclick="formupdate(\'' . md5($field) . '\', \''
250 . PMA_jsFormat($key_ordered_current_key, false) . '\'); return false;">'
251 .htmlspecialchars($key_ordered_current_key) . '</a>' . ($key_ordered_current_equals_data ? '</strong>' : '');
252 ?></td>
253 <td>
254 <?php
255 echo ($key_ordered_current_equals_data ? '<strong>' : '')
256 . '<a href="#" title="' . __('Use this value') . ($key_ordered_current_val_title != '' ? ': '
257 . $key_ordered_current_val_title : '') . '" onclick="formupdate(\''
258 . md5($field) . '\', \'' . PMA_jsFormat($key_ordered_current_key, false) . '\'); return false;">'
259 . $key_ordered_current_val . '</a>' . ($key_ordered_current_equals_data ? '</strong>' : '');
260 ?></td>
261 <td width="20%">
262 <img src="<?php echo $GLOBALS['pmaThemeImage'] . 'spacer.png'; ?>"
263 alt="" width="1" height="1"></td>
265 <td>
266 <?php
267 echo ($val_ordered_current_equals_data ? '<strong>' : '')
268 . '<a href="#" title="' . __('Use this value') . ($val_ordered_current_val_title != '' ? ': '
269 . $val_ordered_current_val_title : '') . '" onclick="formupdate(\'' . md5($field)
270 . '\', \'' . PMA_jsFormat($val_ordered_current_key, false) . '\'); return false;">'
271 . $val_ordered_current_val . '</a>' . ($val_ordered_current_equals_data ? '</strong>' : '');
272 ?></td>
273 <td nowrap="nowrap">
274 <?php
275 echo ($val_ordered_current_equals_data ? '<strong>' : '') . '<a href="#" title="'
276 . __('Use this value') . ($val_ordered_current_val_title != '' ? ': ' . $val_ordered_current_val_title : '')
277 . '" onclick="formupdate(\'' . md5($field) . '\', \''
278 . PMA_jsFormat($val_ordered_current_key, false) . '\'); return false;">' . htmlspecialchars($val_ordered_current_key)
279 . '</a>' . ($val_ordered_current_equals_data ? '</strong>' : '');
280 ?></td>
281 </tr>
282 <?php
283 } // end while
286 </tbody>
287 </table>
289 </body>
290 </html>