PageRenderTime 50ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/phpMyAdmin/browse_foreigners.php

https://bitbucket.org/izubizarreta/https-bitbucket.org-bityvip
PHP | 302 lines | 241 code | 38 blank | 23 comment | 42 complexity | 28c65f7c0b9ac8c81fa454da4b070506 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.0, JSON, GPL-2.0, BSD-3-Clause, LGPL-2.1, MIT
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * display selection for relational field values
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. /**
  9. * Gets a core script and starts output buffering work
  10. */
  11. require_once './libraries/common.inc.php';
  12. PMA_checkParameters(array('db', 'table', 'field'));
  13. require_once './libraries/ob.lib.php';
  14. PMA_outBufferPre();
  15. require_once './libraries/header_http.inc.php';
  16. /**
  17. * Displays the frame
  18. */
  19. require_once './libraries/transformations.lib.php'; // Transformations
  20. $cfgRelation = PMA_getRelationsParam();
  21. $foreigners = ($cfgRelation['relwork'] ? PMA_getForeigners($db, $table) : false);
  22. $override_total = true;
  23. if (! isset($pos)) {
  24. $pos = 0;
  25. }
  26. $foreign_limit = 'LIMIT ' . $pos . ', ' . $GLOBALS['cfg']['MaxRows'] . ' ';
  27. if (isset($foreign_navig) && $foreign_navig == __('Show all')) {
  28. unset($foreign_limit);
  29. }
  30. $foreignData = PMA_getForeignData($foreigners, $field, $override_total, isset($foreign_filter) ? $foreign_filter : '', $foreign_limit);
  31. if (isset($rownumber)) {
  32. $rownumber_param = '&amp;rownumber=' . urlencode($rownumber);
  33. } else {
  34. $rownumber_param = '';
  35. }
  36. $gotopage = '';
  37. $showall = '';
  38. if (is_array($foreignData['disp_row'])) {
  39. if ($cfg['ShowAll'] && ($foreignData['the_total'] > $GLOBALS['cfg']['MaxRows'])) {
  40. $showall = '<input type="submit" name="foreign_navig" value="' . __('Show all') . '" />';
  41. }
  42. $session_max_rows = $GLOBALS['cfg']['MaxRows'];
  43. $pageNow = @floor($pos / $session_max_rows) + 1;
  44. $nbTotalPage = @ceil($foreignData['the_total'] / $session_max_rows);
  45. if ($foreignData['the_total'] > $GLOBALS['cfg']['MaxRows']) {
  46. $gotopage = PMA_pageselector(
  47. $session_max_rows,
  48. $pageNow,
  49. $nbTotalPage,
  50. 200,
  51. 5,
  52. 5,
  53. 20,
  54. 10,
  55. __('Page number:')
  56. );
  57. }
  58. }
  59. ?>
  60. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  61. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  62. <html xmlns="http://www.w3.org/1999/xhtml"
  63. xml:lang="<?php echo $available_languages[$lang][1]; ?>"
  64. lang="<?php echo $available_languages[$lang][1]; ?>"
  65. dir="<?php echo $text_dir; ?>">
  66. <head>
  67. <title>phpMyAdmin</title>
  68. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  69. <link rel="stylesheet" type="text/css"
  70. href="phpmyadmin.css.php?<?php echo PMA_generate_common_url('', ''); ?>&amp;js_frame=right&amp;nocache=<?php echo $GLOBALS['PMA_Config']->getThemeUniqueValue(); ?>" />
  71. <?php
  72. // includes everything asked for by libraries/common.inc.php
  73. require_once './libraries/header_scripts.inc.php';
  74. ?>
  75. <script type="text/javascript">
  76. //<![CDATA[
  77. self.focus();
  78. function formupdate(fieldmd5, key) {
  79. var $inline = window.opener.jQuery('.browse_foreign_clicked');
  80. if ($inline.length != 0) {
  81. $inline.removeClass('browse_foreign_clicked')
  82. // for grid editing,
  83. // puts new value in the previous element which is
  84. // a span with class curr_value
  85. .prev('.curr_value').text(key);
  86. // for zoom-search editing, puts new value in the previous
  87. // element which is an input field
  88. $inline.prev('input[type=text]').val(key);
  89. self.close();
  90. return false;
  91. }
  92. if (opener && opener.document && opener.document.insertForm) {
  93. var field = 'fields';
  94. var field_null = 'fields_null';
  95. <?php if (isset($rownumber)) { ?>
  96. var element_name = field + '[multi_edit][<?php echo htmlspecialchars($rownumber); ?>][' + fieldmd5 + ']';
  97. var null_name = field_null + '[multi_edit][<?php echo htmlspecialchars($rownumber); ?>][' + fieldmd5 + ']';
  98. <?php } else { ?>
  99. var element_name = field + '[]';
  100. <?php } ?>
  101. <?php if (isset($fieldkey) && is_numeric($fieldkey)) { ?>
  102. var element_name_alt = field + '[<?php echo $fieldkey; ?>]';
  103. <?php } else { ?>
  104. var element_name_alt = field + '[0]';
  105. <?php } ?>
  106. if (opener.document.insertForm.elements[element_name]) {
  107. // Edit/Insert form
  108. opener.document.insertForm.elements[element_name].value = key;
  109. if (opener.document.insertForm.elements[null_name]) {
  110. opener.document.insertForm.elements[null_name].checked = false;
  111. }
  112. self.close();
  113. return false;
  114. } else if (opener.document.insertForm.elements[element_name_alt]) {
  115. // Search form
  116. opener.document.insertForm.elements[element_name_alt].value = key;
  117. self.close();
  118. return false;
  119. }
  120. }
  121. 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.')); ?>');
  122. }
  123. //]]>
  124. </script>
  125. </head>
  126. <body id="body_browse_foreigners">
  127. <form action="browse_foreigners.php" method="post">
  128. <fieldset>
  129. <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
  130. <input type="hidden" name="field" value="<?php echo htmlspecialchars($field); ?>" />
  131. <input type="hidden" name="fieldkey"
  132. value="<?php echo isset($fieldkey) ? htmlspecialchars($fieldkey) : ''; ?>" />
  133. <?php if (isset($rownumber)) { ?>
  134. <input type="hidden" name="rownumber" value="<?php echo htmlspecialchars($rownumber); ?>" />
  135. <?php } ?>
  136. <span class="formelement">
  137. <label for="input_foreign_filter"><?php echo __('Search') . ':'; ?></label>
  138. <input type="text" name="foreign_filter" id="input_foreign_filter"
  139. value="<?php echo isset($foreign_filter) ? htmlspecialchars($foreign_filter) : ''; ?>" />
  140. <input type="submit" name="submit_foreign_filter" value="<?php echo __('Go');?>" />
  141. </span>
  142. <span class="formelement">
  143. <?php echo $gotopage; ?>
  144. </span>
  145. <span class="formelement">
  146. <?php echo $showall; ?>
  147. </span>
  148. </fieldset>
  149. </form>
  150. <table width="100%">
  151. <?php
  152. if (is_array($foreignData['disp_row'])) {
  153. $header = '<tr>
  154. <th>' . __('Keyname') . '</th>
  155. <th>' . __('Description') . '</th>
  156. <td width="20%"></td>
  157. <th>' . __('Description') . '</th>
  158. <th>' . __('Keyname') . '</th>
  159. </tr>';
  160. echo '<thead>' . $header . '</thead>' . "\n"
  161. .'<tfoot>' . $header . '</tfoot>' . "\n"
  162. .'<tbody>' . "\n";
  163. $values = array();
  164. $keys = array();
  165. foreach ($foreignData['disp_row'] as $relrow) {
  166. if ($foreignData['foreign_display'] != false) {
  167. $values[] = $relrow[$foreignData['foreign_display']];
  168. } else {
  169. $values[] = '';
  170. }
  171. $keys[] = $relrow[$foreignData['foreign_field']];
  172. }
  173. asort($keys);
  174. $hcount = 0;
  175. $odd_row = true;
  176. $val_ordered_current_row = 0;
  177. $val_ordered_current_equals_data = false;
  178. $key_ordered_current_equals_data = false;
  179. foreach ($keys as $key_ordered_current_row => $value) {
  180. //for ($i = 0; $i < $count; $i++) {
  181. $hcount++;
  182. if ($cfg['RepeatCells'] > 0 && $hcount > $cfg['RepeatCells']) {
  183. echo $header;
  184. $hcount = 0;
  185. $odd_row = true;
  186. }
  187. $key_ordered_current_key = $keys[$key_ordered_current_row];
  188. $key_ordered_current_val = $values[$key_ordered_current_row];
  189. $val_ordered_current_key = $keys[$val_ordered_current_row];
  190. $val_ordered_current_val = $values[$val_ordered_current_row];
  191. $val_ordered_current_row++;
  192. if (PMA_strlen($val_ordered_current_val) <= $cfg['LimitChars']) {
  193. $val_ordered_current_val = htmlspecialchars($val_ordered_current_val);
  194. $val_ordered_current_val_title = '';
  195. } else {
  196. $val_ordered_current_val_title
  197. = htmlspecialchars($val_ordered_current_val);
  198. $val_ordered_current_val = htmlspecialchars(
  199. PMA_substr($val_ordered_current_val, 0, $cfg['LimitChars'])
  200. . '...'
  201. );
  202. }
  203. if (PMA_strlen($key_ordered_current_val) <= $cfg['LimitChars']) {
  204. $key_ordered_current_val = htmlspecialchars($key_ordered_current_val);
  205. $key_ordered_current_val_title = '';
  206. } else {
  207. $key_ordered_current_val_title
  208. = htmlspecialchars($key_ordered_current_val);
  209. $key_ordered_current_val
  210. = htmlspecialchars(
  211. PMA_substr($key_ordered_current_val, 0, $cfg['LimitChars']) . '...'
  212. );
  213. }
  214. if (! empty($data)) {
  215. $val_ordered_current_equals_data = $val_ordered_current_key == $data;
  216. $key_ordered_current_equals_data = $key_ordered_current_key == $data;
  217. }
  218. ?>
  219. <tr class="noclick <?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
  220. <td nowrap="nowrap">
  221. <?php
  222. echo ($key_ordered_current_equals_data ? '<strong>' : '')
  223. .'<a href="#" title="' . __('Use this value')
  224. . ($key_ordered_current_val_title != '' ? ': ' . $key_ordered_current_val_title : '') . '"'
  225. .' onclick="formupdate(\'' . md5($field) . '\', \''
  226. . PMA_jsFormat($key_ordered_current_key, false) . '\'); return false;">'
  227. .htmlspecialchars($key_ordered_current_key) . '</a>' . ($key_ordered_current_equals_data ? '</strong>' : '');
  228. ?></td>
  229. <td>
  230. <?php
  231. echo ($key_ordered_current_equals_data ? '<strong>' : '')
  232. . '<a href="#" title="' . __('Use this value') . ($key_ordered_current_val_title != '' ? ': '
  233. . $key_ordered_current_val_title : '') . '" onclick="formupdate(\''
  234. . md5($field) . '\', \'' . PMA_jsFormat($key_ordered_current_key, false) . '\'); return false;">'
  235. . $key_ordered_current_val . '</a>' . ($key_ordered_current_equals_data ? '</strong>' : '');
  236. ?></td>
  237. <td width="20%">
  238. <img src="<?php echo $GLOBALS['pmaThemeImage'] . 'spacer.png'; ?>"
  239. alt="" width="1" height="1" /></td>
  240. <td>
  241. <?php
  242. echo ($val_ordered_current_equals_data ? '<strong>' : '')
  243. . '<a href="#" title="' . __('Use this value') . ($val_ordered_current_val_title != '' ? ': '
  244. . $val_ordered_current_val_title : '') . '" onclick="formupdate(\'' . md5($field)
  245. . '\', \'' . PMA_jsFormat($val_ordered_current_key, false) . '\'); return false;">'
  246. . $val_ordered_current_val . '</a>' . ($val_ordered_current_equals_data ? '</strong>' : '');
  247. ?></td>
  248. <td nowrap="nowrap">
  249. <?php
  250. echo ($val_ordered_current_equals_data ? '<strong>' : '') . '<a href="#" title="'
  251. . __('Use this value') . ($val_ordered_current_val_title != '' ? ': ' . $val_ordered_current_val_title : '')
  252. . '" onclick="formupdate(\'' . md5($field) . '\', \''
  253. . PMA_jsFormat($val_ordered_current_key, false) . '\'); return false;">' . htmlspecialchars($val_ordered_current_key)
  254. . '</a>' . ($val_ordered_current_equals_data ? '</strong>' : '');
  255. ?></td>
  256. </tr>
  257. <?php
  258. } // end while
  259. }
  260. ?>
  261. </tbody>
  262. </table>
  263. </body>
  264. </html>