home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / browse_foreigners.php < prev    next >
Encoding:
PHP Script  |  2004-01-05  |  8.5 KB  |  247 lines

  1. <?php
  2. /* $Id: browse_foreigners.php,v 2.6 2004/01/05 16:56:46 garvinhicking Exp $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4.  
  5. /**
  6.  * Get the variables sent or posted to this script and displays the header
  7.  */
  8. require_once('./libraries/grab_globals.lib.php');
  9.  
  10. /**
  11.  * Gets a core script and starts output buffering work
  12.  */
  13. require_once('./libraries/common.lib.php');
  14.  
  15. PMA_checkParameters(array('db', 'table', 'field'));
  16.  
  17. require_once('./libraries/ob.lib.php');
  18. if ($cfg['OBGzip']) {
  19.     $ob_mode = PMA_outBufferModeGet();
  20.     if ($ob_mode) {
  21.         PMA_outBufferPre($ob_mode);
  22.     }
  23. }
  24. require_once('./libraries/header_http.inc.php');
  25. $field = urldecode($field);
  26.  
  27. /**
  28.  * Displays the frame
  29.  */
  30. // Gets the font sizes to use
  31. PMA_setFontSizes();
  32. ?>
  33. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  34.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  35. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $available_languages[$lang][2]; ?>" lang="<?php echo $available_languages[$lang][2]; ?>" dir="<?php echo $text_dir; ?>">
  36.  
  37. <head>
  38.     <title>phpMyAdmin</title>
  39.     <meta http-equiv="Content-Type" content="text/html; charset=<?php echo $charset; ?>" />
  40.     <base<?php if (!empty($cfg['PmaAbsoluteUri'])) echo ' href="' . $cfg['PmaAbsoluteUri'] . '"'; ?> />
  41.     <link rel="stylesheet" type="text/css" href="./css/phpmyadmin.css.php?lang=<?php echo $lang; ?>&js_frame=right" />
  42.     <script src="libraries/functions.js" type="text/javascript" language="javascript"></script>
  43.     <script type="text/javascript" language="javascript">
  44.     self.focus();
  45.     function formupdate(field, key) {
  46.         if (opener && opener.document && opener.document.insertForm && opener.document.insertForm.elements['field_' + field + '<?php echo (isset($pk) ? '[multi_edit][' . $pk . ']' : ''); ?>[]']) {
  47.             opener.document.insertForm.elements['field_' + field + '<?php echo (isset($pk) ? '[multi_edit][' . $pk . ']' : ''); ?>[]'].value = key;
  48.             self.close();
  49.         } else {
  50.             alert('<?php echo PMA_jsFormat($strWindowNotFound); ?>');
  51.         }
  52.     }
  53.     </script>
  54. </head>
  55.  
  56. <body bgcolor="<?php echo $cfg['LeftBgColor']; ?>" style="margin-left: 5px; margin-top: 5px; margin-right: 5px; margin-bottom: 0px">
  57. <?php
  58. $per_page = 200;
  59. require_once('./libraries/relation.lib.php'); // foreign keys
  60. require_once('./libraries/transformations.lib.php'); // Transformations
  61. $cfgRelation = PMA_getRelationsParam();
  62. $foreigners  = ($cfgRelation['relwork'] ? PMA_getForeigners($db, $table) : FALSE);
  63.  
  64. $override_total = TRUE;
  65.  
  66. if (!isset($pos)) {
  67.     $pos = 0;
  68. }
  69.  
  70. $foreign_limit = 'LIMIT ' . $pos . ', ' . $per_page . ' ';
  71. if (isset($foreign_navig) && $foreign_navig == $strShowAll) {
  72.     unset($foreign_limit);
  73. }
  74.  
  75. require('./libraries/get_foreign.lib.php');
  76. ?>
  77.  
  78. <form action="browse_foreigners.php" method="post">
  79. <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
  80. <input type="hidden" name="field" value="<?php echo urlencode($field); ?>" />
  81. <?php
  82. if (isset($pk)) {
  83.     $pk_uri = '&pk=' . $pk;
  84. ?>
  85. <input type="hidden" name="pk" value="<?php echo $pk; ?>" />
  86. <?php
  87. } else {
  88.     $pk_uri = '&';
  89. }
  90. ?>
  91.  
  92. <table width="100%">
  93. <?php
  94. if ($cfg['ShowAll'] && ($the_total > $per_page)) {
  95.     $showall = '<input type="submit" name="foreign_navig" value="' . $strShowAll . '" />';
  96. } else {
  97.     $showall = '';
  98. }
  99.  
  100. $session_max_rows = $per_page;
  101. $pageNow = @floor($pos / $session_max_rows) + 1;
  102. $nbTotalPage = @ceil($the_total / $session_max_rows);
  103.  
  104. if ($the_total > $per_page) {
  105.     $gotopage = '<br />' . $GLOBALS['strPageNumber']
  106.               . '<select name="goToPage" onChange="goToUrl(this, \'browse_foreigners.php?field=' . urlencode($field) . '&' . PMA_generate_common_url($db, $table) . $pk_uri . '\');">';
  107.     if ($nbTotalPage < 200) {
  108.         $firstPage = 1;
  109.         $lastPage  = $nbTotalPage;
  110.     } else {
  111.         $range = 20;
  112.         $firstPage = ($pageNow - $range < 1 ? 1 : $pageNow - $range);
  113.         $lastPage  = ($pageNow + $range > $nbTotalPage ? $nbTotalPage : $pageNow + $range);
  114.     }
  115.  
  116.     for ($i=$firstPage; $i<=$lastPage; $i++){
  117.         if ($i == $pageNow) {
  118.             $selected = 'selected="selected"';
  119.         } else {
  120.             $selected = '';
  121.         }
  122.         $gotopage .= '                <option ' . $selected . ' value="' . (($i - 1) * $session_max_rows) . '">' . $i . '</option>' . "\n";
  123.     }
  124. } else {
  125.     $gotopage = '';
  126. }
  127.  
  128. $header = '    <tr>
  129.     <th align="left" nowrap="nowrap">' . $strKeyname . '</th>
  130.     <th>' . $strDescription . '</th>
  131.     <td align="center" width="20%" valign="top">
  132.         ' . $showall . '
  133.         ' . $gotopage . '
  134.     </td>
  135.     <th>' . $strDescription . '</th>
  136.     <th align="left" nowrap="nowrap">' . $strKeyname . '</th>
  137. </tr>';
  138.  
  139. echo $header;
  140.  
  141. if (isset($disp) && $disp) {
  142.     function dimsort($arrayA, $arrayB) {
  143.         $keyA = key($arrayA);
  144.         $keyB = key($arrayB);
  145.         
  146.         if ($arrayA[$keyA] == $arrayB[$keyB]) {
  147.             return 0;
  148.         }
  149.         
  150.         return ($arrayA[$keyA] < $arrayB[$keyB]) ? -1 : 1;
  151.     }
  152.  
  153.     $mysql_key_relrow = array();
  154.     $mysql_val_relrow = array();
  155.     $count = 0;
  156.     while ($relrow = @PMA_mysql_fetch_array($disp)) {
  157.         if ($foreign_display != FALSE) {
  158.             $val = $relrow[$foreign_display];
  159.         } else {
  160.             $val = '';
  161.         }
  162.         
  163.         $mysql_key_relrow[$count] = array($relrow[$foreign_field]   => $val);
  164.         $mysql_val_relrow[$count] = array($val                      => $relrow[$foreign_field]);
  165.         $count++;
  166.     }
  167.     
  168.     usort($mysql_val_relrow, 'dimsort');
  169.     
  170.     $hcount = 0;
  171.     for ($i = 0; $i < $count; $i++) {
  172.         $hcount++;
  173.         $bgcolor = ($hcount % 2) ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
  174.  
  175.         if ($cfg['RepeatCells'] > 0 && $hcount > $cfg['RepeatCells']) {
  176.             echo $header;
  177.             $hcount = -1;
  178.         }
  179.  
  180.  
  181.         $val   = key($mysql_val_relrow[$i]);
  182.         $key   = $mysql_val_relrow[$i][$val];
  183.  
  184.         if (strlen($val) <= $cfg['LimitChars']) {
  185.             $value  = htmlspecialchars($val);
  186.             $vtitle = '';
  187.         } else {
  188.             $vtitle = htmlspecialchars($val);
  189.             $value  = htmlspecialchars(substr($val, 0, $cfg['LimitChars']) . '...');
  190.         }
  191.  
  192.         $key_equals_data = isset($data) && $key == $data;
  193. ?>
  194.     <tr>
  195.         <td nowrap="nowrap" bgcolor="<?php echo $bgcolor; ?>"><?php echo ($key_equals_data ? '<b>' : '') . '<a href="#" title="' . $strUseThisValue . ($vtitle != '' ? ': ' . $vtitle : '') . '" onclick="formupdate(\'' . md5($field) . '\', \'' . htmlspecialchars($key) . '\'); return false;">' . htmlspecialchars($key) . '</a>' . ($key_equals_data ? '</b>' : ''); ?></td>
  196.         <td bgcolor="<?php echo $bgcolor; ?>"><?php echo ($key_equals_data ? '<b>' : '') .                 '<a href="#" title="' . $strUseThisValue . ($vtitle != '' ? ': ' . $vtitle : '') . '" onclick="formupdate(\'' . md5($field) . '\', \'' . htmlspecialchars($key) . '\'); return false;">' . $value . '</a>' . ($key_equals_data ? '</b>' : ''); ?></td>
  197.         <td width="20%"><img src="images/spacer.gif" alt="" width="1" height="1"></td>
  198. <?php
  199.         $key   = key($mysql_key_relrow[$i]);
  200.         $val   = $mysql_key_relrow[$i][$key];
  201.         if (strlen($val) <= $cfg['LimitChars']) {
  202.             $value  = htmlspecialchars($val);
  203.             $vtitle = '';
  204.         } else {
  205.             $vtitle = htmlspecialchars($val);
  206.             $value  = htmlspecialchars(substr($val, 0, $cfg['LimitChars']) . '...');
  207.         }
  208.  
  209.         $key_equals_data = isset($data) && $key == $data;
  210. ?>
  211.         <td bgcolor="<?php echo $bgcolor; ?>"><?php echo ($key_equals_data ? '<b>' : '') .                 '<a href="#" title="' . $strUseThisValue .  ($vtitle != '' ? ': ' . $vtitle : '') . '" onclick="formupdate(\'' . md5($field) . '\', \'' . htmlspecialchars($key) . '\'); return false;">' . $value . '</a>' . ($key_equals_data ? '</b>' : ''); ?></td>
  212.         <td nowrap="nowrap" bgcolor="<?php echo $bgcolor; ?>"><?php echo ($key_equals_data ? '<b>' : '') . '<a href="#" title="' . $strUseThisValue .  ($vtitle != '' ? ': ' . $vtitle : '') . '" onclick="formupdate(\'' . md5($field) . '\', \'' . htmlspecialchars($key) . '\'); return false;">' . htmlspecialchars($key) . '</a>' . ($key_equals_data ? '</b>' : ''); ?></td>
  213.     </tr>
  214. <?php
  215.         unset($key_equals_data);
  216.     } // end while
  217. }
  218.  
  219. echo $header;
  220. ?>
  221. </table>
  222. </form>
  223.  
  224. </body>
  225. </html>
  226.  
  227. <?php
  228. /**
  229.  * Close MySql connections
  230.  */
  231. if (isset($dbh) && $dbh) {
  232.     @mysql_close($dbh);
  233. }
  234. if (isset($userlink) && $userlink) {
  235.     @mysql_close($userlink);
  236. }
  237.  
  238.  
  239. /**
  240.  * Sends bufferized data
  241.  */
  242. if (isset($cfg['OBGzip']) && $cfg['OBGzip']
  243.     && isset($ob_mode) && $ob_mode) {
  244.      PMA_outBufferPost($ob_mode);
  245. }
  246. ?>
  247.