PageRenderTime 47ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/pma/browse_foreigners.php

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