finish removal of get_foreign.lib.php

This commit is contained in:
Marc Delisle
2007-09-19 17:25:17 +00:00
parent 5c70b88927
commit 874e16fc45
3 changed files with 16 additions and 99 deletions

View File

@@ -38,7 +38,7 @@ if (isset($foreign_navig) && $foreign_navig == $strShowAll) {
unset($foreign_limit); unset($foreign_limit);
} }
require './libraries/get_foreign.lib.php'; $foreignData = PMA_getForeignData($foreigners, $field, $override_total, isset($foreign_filter) ? $foreign_filter : '', $foreign_limit);
if (isset($pk)) { if (isset($pk)) {
$pk_uri = '&pk=' . urlencode($pk); $pk_uri = '&pk=' . urlencode($pk);
@@ -51,19 +51,18 @@ if (isset($pk)) {
$gotopage = ''; $gotopage = '';
$showall = ''; $showall = '';
// $the_total comes from get_foreign.lib.php
if (isset($disp_row) && is_array($disp_row)) { if (is_array($foreignData['disp_row'])) {
if ($cfg['ShowAll'] && ($the_total > $per_page)) { if ($cfg['ShowAll'] && ($foreignData['the_total'] > $per_page)) {
$showall = '<input type="submit" name="foreign_navig" value="' . $strShowAll . '" />'; $showall = '<input type="submit" name="foreign_navig" value="' . $strShowAll . '" />';
} }
$session_max_rows = $per_page; $session_max_rows = $per_page;
$pageNow = @floor($pos / $session_max_rows) + 1; $pageNow = @floor($pos / $session_max_rows) + 1;
$nbTotalPage = @ceil($the_total / $session_max_rows); $nbTotalPage = @ceil($foreignData['the_total'] / $session_max_rows);
if ($the_total > $per_page) { if ($foreignData['the_total'] > $per_page) {
$gotopage = PMA_pageselector( $gotopage = PMA_pageselector(
'browse_foreigners.php?field=' . urlencode($field) . 'browse_foreigners.php?field=' . urlencode($field) .
'&amp;' . PMA_generate_common_url($db, $table) '&amp;' . PMA_generate_common_url($db, $table)
@@ -163,7 +162,7 @@ if (isset($disp_row) && is_array($disp_row)) {
<table width="100%"> <table width="100%">
<?php <?php
if (isset($disp_row) && is_array($disp_row)) { if (is_array($foreignData['disp_row'])) {
$header = '<tr> $header = '<tr>
<th>' . $strKeyname . '</th> <th>' . $strKeyname . '</th>
<th>' . $strDescription . '</th> <th>' . $strDescription . '</th>
@@ -178,14 +177,14 @@ if (isset($disp_row) && is_array($disp_row)) {
$values = array(); $values = array();
$keys = array(); $keys = array();
foreach ($disp_row as $relrow) { foreach ($foreignData['disp_row'] as $relrow) {
if ($foreign_display != FALSE) { if ($foreignData['foreign_display'] != FALSE) {
$values[] = $relrow[$foreign_display]; $values[] = $relrow[$foreignData['foreign_display']];
} else { } else {
$values[] = ''; $values[] = '';
} }
$keys[] = $relrow[$foreign_field]; $keys[] = $relrow[$foreignData['foreign_field']];
} }
asort($keys); asort($keys);

View File

@@ -1,80 +0,0 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
*
* @version $Id$
*/
/**
*
*/
require_once './libraries/Table.class.php';
/**
* Gets foreign keys in preparation for a drop-down selector
* Thanks to <markus@noga.de>
*/
// lem9: we always show the foreign field in the drop-down; if a display
// field is defined, we show it besides the foreign field
$foreign_link = false;
if ($foreigners && isset($foreigners[$field])) {
$foreigner = $foreigners[$field];
$foreign_db = $foreigner['foreign_db'];
$foreign_table = $foreigner['foreign_table'];
$foreign_field = $foreigner['foreign_field'];
// Count number of rows in the foreign table. Currently we do
// not use a drop-down if more than 200 rows in the foreign table,
// for speed reasons and because we need a better interface for this.
//
// We could also do the SELECT anyway, with a LIMIT, and ensure that
// the current value of the field is one of the choices.
$the_total = PMA_Table::countRecords($foreign_db, $foreign_table, TRUE);
if ((isset($override_total) && $override_total == true) || $the_total < $cfg['ForeignKeyMaxLimit']) {
// foreign_display can be FALSE if no display field defined:
$foreign_display = PMA_getDisplayField($foreign_db, $foreign_table);
$f_query_main = 'SELECT ' . PMA_backquote($foreign_field)
. (($foreign_display == FALSE) ? '' : ', ' . PMA_backquote($foreign_display));
$f_query_from = ' FROM ' . PMA_backquote($foreign_db) . '.' . PMA_backquote($foreign_table);
$f_query_filter = empty($foreign_filter) ? '' : ' WHERE ' . PMA_backquote($foreign_field)
. ' LIKE "%' . PMA_sqlAddslashes($foreign_filter, TRUE) . '%"'
. (($foreign_display == FALSE) ? '' : ' OR ' . PMA_backquote($foreign_display)
. ' LIKE "%' . PMA_sqlAddslashes($foreign_filter, TRUE) . '%"'
);
$f_query_order = ($foreign_display == FALSE) ? '' :' ORDER BY ' . PMA_backquote($foreign_table) . '.' . PMA_backquote($foreign_display);
$f_query_limit = isset($foreign_limit) ? $foreign_limit : '';
if (!empty($foreign_filter)) {
$res = PMA_DBI_query('SELECT COUNT(*)' . $f_query_from . $f_query_filter);
if ($res) {
$the_total = PMA_DBI_fetch_value($res);
@PMA_DBI_free_result($res);
} else {
$the_total = 0;
}
}
$disp = PMA_DBI_query($f_query_main . $f_query_from . $f_query_filter . $f_query_order . $f_query_limit);
if ($disp && PMA_DBI_num_rows($disp) > 0) {
// garvin: If a resultset has been created, pre-cache it in the $disp_row array
// This helps us from not needing to use mysql_data_seek by accessing a pre-cached
// PHP array. Usually those resultsets are not that big, so a performance hit should
// not be expected.
$disp_row = array();
while ($single_disp_row = @PMA_DBI_fetch_assoc($disp)) {
$disp_row[] = $single_disp_row;
}
@PMA_DBI_free_result($disp);
}
} else {
unset($disp_row);
$foreign_link = true;
}
} // end if $foreigners
?>

View File

@@ -241,13 +241,9 @@ while (list($operator) = each($GLOBALS['cfg']['UnaryOperators'])) {
// <markus@noga.de> // <markus@noga.de>
$field = $fields_list[$i]; $field = $fields_list[$i];
// do not use require_once here $foreignData = PMA_getForeignData($foreigners, $field, false, '', '');
require './libraries/get_foreign.lib.php';
// we got a bug report: in some cases, even if $disp is true, if ($foreigners && isset($foreigners[$field]) && is_array($foreignData['disp_row'])) {
// there are no rows, so we add a fetch_array
if ($foreigners && isset($foreigners[$field]) && isset($disp_row) && is_array($disp_row)) {
// f o r e i g n k e y s // f o r e i g n k e y s
echo ' <select name="fields[' . $i . ']">' . "\n"; echo ' <select name="fields[' . $i . ']">' . "\n";
// go back to first row // go back to first row
@@ -255,10 +251,12 @@ while (list($operator) = each($GLOBALS['cfg']['UnaryOperators'])) {
// here, the 4th parameter is empty because there is no current // here, the 4th parameter is empty because there is no current
// value of data for the dropdown (the search page initial values // value of data for the dropdown (the search page initial values
// are displayed empty) // are displayed empty)
echo PMA_foreignDropdown($disp_row, $foreign_field, $foreign_display, echo PMA_foreignDropdown($foreignData['disp_row'],
$foreignData['foreign_field'],
$foreignData['foreign_display'],
'', $GLOBALS['cfg']['ForeignKeyMaxLimit']); '', $GLOBALS['cfg']['ForeignKeyMaxLimit']);
echo ' </select>' . "\n"; echo ' </select>' . "\n";
} elseif (isset($foreign_link) && $foreign_link == true) { } elseif ($foreignData['foreign_link'] == true) {
?> ?>
<input type="text" name="fields[<?php echo $i; ?>]" <input type="text" name="fields[<?php echo $i; ?>]"
id="field_<?php echo md5($field); ?>[<?php echo $i; ?>]" id="field_<?php echo md5($field); ?>[<?php echo $i; ?>]"