Coding Standards (thanx to Loic)
and some further mistake in db_details_qb
This commit is contained in:
@@ -1,99 +1,106 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This script imports relation infos from docSQL (www.databay.de)
|
* This script imports relation infos from docSQL (www.databay.de)
|
||||||
**/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the values of the variables posted or sent to this script and display
|
* Get the values of the variables posted or sent to this script and display
|
||||||
* the headers
|
* the headers
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require('./libraries/grab_globals.lib.php3');
|
require('./libraries/grab_globals.lib.php3');
|
||||||
require('./libraries/common.lib.php3');
|
require('./libraries/common.lib.php3');
|
||||||
require('./libraries/relation.lib.php3');
|
require('./libraries/relation.lib.php3');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the relation settings
|
* Gets the relation settings
|
||||||
*/
|
*/
|
||||||
$cfgRelation = PMA_getRelationsParam();
|
$cfgRelation = PMA_getRelationsParam();
|
||||||
|
|
||||||
if (isset($do) && $do == 'import') {
|
if (isset($do) && $do == 'import') {
|
||||||
// echo "<h1>Starting Import</h1>";
|
// echo '<h1>Starting Import</h1>';
|
||||||
if (substr($docpath, strlen($docpath) - 2, 1) != '/') {
|
if (substr($docpath, strlen($docpath) - 2, 1) != '/') {
|
||||||
$docpath = $docpath . '/';
|
$docpath = $docpath . '/';
|
||||||
}
|
}
|
||||||
if (is_dir($docpath)) {
|
if (is_dir($docpath)) {
|
||||||
$handle = opendir($docpath);
|
$handle = opendir($docpath);
|
||||||
while ($file = @readdir ($handle)) {
|
while ($file = @readdir ($handle)) {
|
||||||
$_filename=basename($file);
|
$filename = basename($file);
|
||||||
// echo "<p>Working on file " . $_filename . "</p>";
|
// echo '<p>Working on file ' . $filename . '</p>';
|
||||||
$_parts = explode('_',$_filename);
|
$parts = explode('_', $filename);
|
||||||
if (count($_parts)==3 && $_parts[1] == 'field' && $_parts[2] == 'comment.txt') {
|
if (count($parts) == 3 && $parts[1] == 'field' && $parts[2] == 'comment.txt') {
|
||||||
$_tab = $_parts[0];
|
$tab = $parts[0];
|
||||||
//echo "<H1>Working on Table " . $_tab . "</h1>";
|
//echo '<h1>Working on Table ' . $tab . '</h1>';
|
||||||
$fd = fopen($docpath . $file, "r");
|
$fd = fopen($docpath . $file, 'r');
|
||||||
if ($fd) {
|
if ($fd) {
|
||||||
while (!feof($fd)) {
|
while (!feof($fd)) {
|
||||||
$_line = fgets($fd, 4096);
|
$line = fgets($fd, 4096);
|
||||||
//echo "<p>" . $_line . "</p>";
|
//echo '<p>' . $line . '</p>';
|
||||||
$_inf = explode('|',$_line);
|
$inf = explode('|',$line);
|
||||||
if(!empty($_inf[1]) && strlen(trim($_inf[1]))>0){
|
if (!empty($inf[1]) && strlen(trim($inf[1])) > 0) {
|
||||||
$qry = 'INSERT INTO ' . PMA_backquote($cfgRelation['column_comments'])
|
$qry = 'INSERT INTO ' . PMA_backquote($cfgRelation['column_comments'])
|
||||||
. ' (db_name, table_name, column_name, comment) '
|
. ' (db_name, table_name, column_name, comment) '
|
||||||
. ' VALUES('
|
. ' VALUES('
|
||||||
. '\'' . PMA_sqlAddslashes($db) . '\','
|
. '\'' . PMA_sqlAddslashes($db) . '\','
|
||||||
. '\'' . PMA_sqlAddslashes(trim($_tab)) . '\','
|
. '\'' . PMA_sqlAddslashes(trim($tab)) . '\','
|
||||||
. '\'' . PMA_sqlAddslashes(trim($_inf[0])) . '\','
|
. '\'' . PMA_sqlAddslashes(trim($inf[0])) . '\','
|
||||||
. '\'' . PMA_sqlAddslashes(trim($_inf[1])) . '\')';
|
. '\'' . PMA_sqlAddslashes(trim($inf[1])) . '\')';
|
||||||
if (PMA_query_as_cu($qry)) {
|
if (PMA_query_as_cu($qry)) {
|
||||||
echo "<p>added Comment for Column " . $_tab . '.' . $_inf[0] . "</p>";
|
echo '<p>Added comment for column ' . htmlspecialchars($tab) . '.' . htmlspecialchars($inf[0]) . '</p>';
|
||||||
} else {
|
} else {
|
||||||
echo "<p>writing of Comment not possible</p>";
|
echo '<p>Writing of comment not possible</p>';
|
||||||
}
|
}
|
||||||
}
|
echo "\n";
|
||||||
if (!empty($_inf[2]) && strlen(trim($_inf[2]))>0) {
|
} // end inf[1] exists
|
||||||
$_for = explode('->',$_inf[2]);
|
if (!empty($inf[2]) && strlen(trim($inf[2])) > 0) {
|
||||||
|
$for = explode('->', $inf[2]);
|
||||||
$qry = 'INSERT INTO ' . PMA_backquote($cfgRelation['relation'])
|
$qry = 'INSERT INTO ' . PMA_backquote($cfgRelation['relation'])
|
||||||
. '(master_db, master_table, master_field, foreign_db, foreign_table, foreign_field)'
|
. '(master_db, master_table, master_field, foreign_db, foreign_table, foreign_field)'
|
||||||
. ' values('
|
. ' VALUES('
|
||||||
. '\'' . PMA_sqlAddslashes($db) . '\', '
|
. '\'' . PMA_sqlAddslashes($db) . '\', '
|
||||||
. '\'' . PMA_sqlAddslashes(trim($_tab)) . '\', '
|
. '\'' . PMA_sqlAddslashes(trim($tab)) . '\', '
|
||||||
. '\'' . PMA_sqlAddslashes(trim($_inf[0])) . '\', '
|
. '\'' . PMA_sqlAddslashes(trim($inf[0])) . '\', '
|
||||||
. '\'' . PMA_sqlAddslashes($db) . '\', '
|
. '\'' . PMA_sqlAddslashes($db) . '\', '
|
||||||
. '\'' . PMA_sqlAddslashes(trim($_for[0])) . '\','
|
. '\'' . PMA_sqlAddslashes(trim($for[0])) . '\','
|
||||||
. '\'' . PMA_sqlAddslashes(trim($_for[1])) . '\')';
|
. '\'' . PMA_sqlAddslashes(trim($for[1])) . '\')';
|
||||||
if (PMA_query_as_cu($qry)) {
|
if (PMA_query_as_cu($qry)) {
|
||||||
echo "<p>added Relation for Column " . $_tab . '.' . $_inf[0] . " to " . $_for . "</p>";
|
echo '<p>Added relation for column ' . htmlspecialchars($tab) . '.' . htmlspecialchars($inf[0]) . ' to ' . htmlspecialchars($for) . '</p>';
|
||||||
} else {
|
} else {
|
||||||
echo "<p>writing of Relation not possible</p>";
|
echo "<p>writing of Relation not possible</p>";
|
||||||
}
|
}
|
||||||
|
echo "\n";
|
||||||
|
} // end inf[2] exists
|
||||||
}
|
}
|
||||||
}
|
echo '<p><font color="green">Import finished</font></p>' . "\n";
|
||||||
echo '<p><font color="green">Import finished</font></p>';
|
|
||||||
} else {
|
} else {
|
||||||
echo "<p><font color=\"red\">File could not be read</font></p>";
|
echo '<p><font color="red">File could not be read</font></p>' . "\n";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
echo "<p><font color=\"yellow\">Ignoring File $file</font></p>";
|
echo '<p><font color="yellow">Ignoring file ' . $file . '</font></p>' . "\n";
|
||||||
}
|
} // end working on table
|
||||||
}
|
} // end while
|
||||||
} else {
|
} else {
|
||||||
echo "This was not a Directory";
|
echo 'This was not a Directory' . "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<form action="db_details_importdocsql.php3">
|
|
||||||
|
<form method="post" action="db_details_importdocsql.php3">
|
||||||
<input type="hidden" name="lang" value="<?php echo $lang; ?>" />
|
<input type="hidden" name="lang" value="<?php echo $lang; ?>" />
|
||||||
<input type="hidden" name="server" value="<?php echo $server; ?>" />
|
<input type="hidden" name="server" value="<?php echo $server; ?>" />
|
||||||
<input type="hidden" name="db" value="<?php echo $db; ?>" />
|
<input type="hidden" name="db" value="<?php echo $db; ?>" />
|
||||||
<input type="hidden" name="submit_show" value="true" />
|
<input type="hidden" name="submit_show" value="true" />
|
||||||
<input type="hidden" name="do" value="import" />
|
<input type="hidden" name="do" value="import" />
|
||||||
<table>
|
<table>
|
||||||
<tr><th colspan=2>Used Database: <?php echo $db;?></th></th>
|
<tr><th colspan="2">Used Database: <?php echo htmlspecialchars($db); ?></th></tr>
|
||||||
<tr><th>Please enter absolute path on webserver to docSQL Directory:</th>
|
<tr>
|
||||||
|
<th>Please enter absolute path on webserver to docSQL Directory:</th>
|
||||||
<td><input type="text" name="docpath" size="50" value="<?php if(isset($DOCUMENT_ROOT)) {echo $DOCUMENT_ROOT;} ?>" /></td>
|
<td><input type="text" name="docpath" size="50" value="<?php if(isset($DOCUMENT_ROOT)) {echo $DOCUMENT_ROOT;} ?>" /></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr><th colspan=2><input type="submit" value="import files" /></th></tr>
|
<tr><th colspan="2"><input type="submit" value="Import files" /></th></tr>
|
||||||
</table>
|
</table>
|
||||||
</form>
|
</form>
|
@@ -726,130 +726,129 @@ if (!empty($qry_select)) {
|
|||||||
|
|
||||||
// Create LEFT JOINS out of Relations
|
// Create LEFT JOINS out of Relations
|
||||||
// Code originally by Mike Beck <mike.beck@ibmiller.de>
|
// Code originally by Mike Beck <mike.beck@ibmiller.de>
|
||||||
// If we can use Relations we could make some left joins
|
// If we can use Relations we could make some left joins.
|
||||||
// First find out if relations are available in this database
|
// First find out if relations are available in this database.
|
||||||
|
|
||||||
// Debugging:
|
// Debugging:
|
||||||
//echo "</textarea><pre style=\"background-color:white;\">";
|
//echo '</textarea><pre style="background-color: white;">';
|
||||||
// First we need the really needed Tables - those in TableList might
|
// First we need the really needed Tables - those in TableList might still be
|
||||||
// still be all Tables.
|
// all Tables.
|
||||||
if (isset($Field) && count($Field) > 0) {
|
if (isset($Field) && count($Field) > 0) {
|
||||||
|
|
||||||
// Initialize some variables
|
// Initialize some variables
|
||||||
$tab_all = array();
|
$tab_all = array();
|
||||||
$col_all = array();
|
$col_all = array();
|
||||||
|
$tab_wher = array();
|
||||||
$tab_know = array();
|
$tab_know = array();
|
||||||
$tab_left = array();
|
$tab_left = array();
|
||||||
$col_where = array();
|
$col_where = array();
|
||||||
$fromclause = '';
|
$fromclause = '';
|
||||||
|
|
||||||
// we only start this if we have fields, otherwise it would be dumb
|
// We only start this if we have fields, otherwise it would be dumb
|
||||||
//echo "get everything\n";
|
//echo "get everything\n";
|
||||||
while (list(, $value) = each($Field)) {
|
while (list(, $value) = each($Field)) {
|
||||||
$_parts = explode('.', $value);
|
$parts = explode('.', $value);
|
||||||
if (!empty($_parts[0]) && !empty($_parts[1])) {
|
if (!empty($parts[0]) && !empty($parts[1])) {
|
||||||
$_tab_raw = urldecode($_parts[0]);
|
$tab_raw = urldecode($parts[0]);
|
||||||
$_tab = str_replace('`', '', $_tab_raw);
|
$tab = str_replace('`', '', $tab_raw);
|
||||||
//echo "new Tab: " . $_tab . "\n";
|
//echo 'new Tab: ' . $tab . "\n";
|
||||||
$tab_all[$_tab] = $_tab;
|
$tab_all[$tab] = $tab;
|
||||||
$_col_raw = urldecode($_parts[1]);
|
$col_raw = urldecode($parts[1]);
|
||||||
$col_all[] = $_tab . '.' . str_replace('`', '', $_col_raw);
|
$col_all[] = $tab . '.' . str_replace('`', '', $col_raw);
|
||||||
//echo "new col:" . $_tab . '.' . str_replace('`', '', $_col_raw) . "\n";
|
//echo 'new col: ' . $tab . '.' . str_replace('`', '', $col_raw) . "\n";
|
||||||
}
|
}
|
||||||
} // end while
|
} // end while
|
||||||
|
|
||||||
//echo "check whereclauses\n";
|
//echo "check whereclauses\n";
|
||||||
if ($cfgRelation['relwork'] && count($tab_all) > 0) {
|
if ($cfgRelation['relwork'] && count($tab_all) > 0) {
|
||||||
// now we need all tables that we have in the whereclause
|
// Now we need all tables that we have in the whereclause
|
||||||
for ($x = 0; $x < count($Criteria); $x++) {
|
for ($x = 0; $x < count($Criteria); $x++) {
|
||||||
$_tab_wher = explode('.', urldecode($Field[$x]));
|
$tab_wher = explode('.', urldecode($Field[$x]));
|
||||||
if(!empty($_tab_wher[0]) && !empty($_tab_wher[1])) {
|
if (!empty($tab_wher[0]) && !empty($tab_wher[1])) {
|
||||||
$_tab_raw = urldecode($_tab_wher[0]);
|
$tab_raw = urldecode($tab_wher[0]);
|
||||||
$_tab = str_replace('`', '', $_tab_raw);
|
$tab = str_replace('`', '', $tab_raw);
|
||||||
|
|
||||||
$_col_raw = urldecode($_tab_wher[1]);
|
$col_raw = urldecode($tab_wher[1]);
|
||||||
$_col = str_replace('`', '', $_col_raw);
|
$col = str_replace('`', '', $col_raw);
|
||||||
$_col = $_tab . '.' . $_col;
|
$col = $tab . '.' . $col;
|
||||||
// now we know that our array has the same numbers as $Criteria
|
// Now we know that our array has the same numbers as $Criteria
|
||||||
// we can check which of our columns has a whereclause
|
// we can check which of our columns has a whereclause
|
||||||
if (!empty($Criteria[$x])) {
|
if (!empty($Criteria[$x])) {
|
||||||
if (substr($Criteria[$x],0,1) == '=' || eregi('is', $Criteria[$x])) {
|
if (substr($Criteria[$x],0,1) == '=' || eregi('is', $Criteria[$x])) {
|
||||||
$col_where[$_col] = $_col;
|
$col_where[$col] = $col;
|
||||||
$tab_where[$_tab] = $_tab;
|
$tab_wher[$tab] = $tab;
|
||||||
// echo "new Whereclause:".$_tab."\n";
|
//echo 'new Whereclause: ' . $tab . "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // end for
|
} // end for
|
||||||
|
|
||||||
// clean temp vars w/o further use
|
// Cleans temp vars w/o further use
|
||||||
unset($_tab_raw,$_col_raw);
|
unset($tab_raw, $col_raw);
|
||||||
|
|
||||||
|
if (count($tab_wher) == 1) {
|
||||||
if (count($tab_where) == 1) {
|
// If there is exactly one column that has a decent where-clause
|
||||||
// if there is exactly one column that has a decent where-clause
|
|
||||||
// we will just use this
|
// we will just use this
|
||||||
$master = key($tab_where);
|
$master = key($tab_wher);
|
||||||
// echo "nur ein where: master =".$master . "\n";
|
//echo 'nur ein where: master = ' . $master . "\n";
|
||||||
} else {
|
} else {
|
||||||
// now let's find out which of the tables has an index
|
// Now let's find out which of the tables has an index
|
||||||
//echo "pr<70>fe indexe:\n";
|
//echo "pr<70>fe indexe:\n";
|
||||||
while (list(, $_tab) = each($tab_all)) {
|
while (list(, $tab) = each($tab_all)) {
|
||||||
$ind_qry = 'SHOW INDEX FROM ' . PMA_backquote($_tab);
|
$ind_qry = 'SHOW INDEX FROM ' . PMA_backquote($tab);
|
||||||
$ind_rs = PMA_mysql_query($ind_qry);
|
$ind_rs = PMA_mysql_query($ind_qry);
|
||||||
while ($ind = PMA_mysql_fetch_array($ind_rs)) {
|
while ($ind = PMA_mysql_fetch_array($ind_rs)) {
|
||||||
$_col = $_tab . '.' . $ind['Column_name'];
|
$col = $tab . '.' . $ind['Column_name'];
|
||||||
if (isset($col_all[$_col])) {
|
if (isset($col_all[$col])) {
|
||||||
if ($ind['non_unique'] == 0) {
|
if ($ind['non_unique'] == 0) {
|
||||||
if (isset($col_where[$_col])) {
|
if (isset($col_where[$col])) {
|
||||||
$col_unique[$_col] = 'Y';
|
$col_unique[$col] = 'Y';
|
||||||
} else {
|
} else {
|
||||||
$col_unique[$_col] = 'N';
|
$col_unique[$col] = 'N';
|
||||||
}
|
}
|
||||||
//echo "neuen unique index gefunden:".$_col."\n";
|
//echo 'neuen unique index gefunden: ' . $col . "\n";
|
||||||
} else {
|
} else {
|
||||||
if (isset($col_where[$_col])) {
|
if (isset($col_where[$col])) {
|
||||||
$col_index[$_col] = 'Y';
|
$col_index[$col] = 'Y';
|
||||||
} else {
|
} else {
|
||||||
$col_index[$_col] = 'N';
|
$col_index[$col] = 'N';
|
||||||
}
|
}
|
||||||
//echo "neuen index gefunden:".$_col."\n";
|
//echo 'neuen index gefunden: ' . $col . "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // End while (each col of tab)
|
} // end while (each col of tab)
|
||||||
} // End while (each tab)
|
} // end while (each tab)
|
||||||
// now we want to find the best.
|
// now we want to find the best.
|
||||||
if (isset($col_unique) && count($col_unique) > 0) {
|
if (isset($col_unique) && count($col_unique) > 0) {
|
||||||
$col_cand = $col_unique;
|
$col_cand = $col_unique;
|
||||||
//echo "Kandidaten sind jetzt alle mit unique index\n";
|
//echo "Kandidaten sind jetzt alle mit unique index\n";
|
||||||
$_needsort= 1;
|
$needsort = 1;
|
||||||
} else if (isset($col_index) && count($col_index) > 0) {
|
} else if (isset($col_index) && count($col_index) > 0) {
|
||||||
$col_cand = $col_index;
|
$col_cand = $col_index;
|
||||||
$_needsort= 1;
|
$needsort = 1;
|
||||||
//echo "Kandidaten sind jetzt alle mit index\n";
|
//echo "Kandidaten sind jetzt alle mit index\n";
|
||||||
} else if (isset($col_where) && count($col_where) > 0) {
|
} else if (isset($col_where) && count($col_where) > 0) {
|
||||||
$col_cand = $tab_where;
|
$col_cand = $tab_wher;
|
||||||
//echo "Kandidaten sind jetzt alle im whereclause\n";
|
//echo "Kandidaten sind jetzt alle im whereclause\n";
|
||||||
$_needsort= 0;
|
$needsort = 0;
|
||||||
} else {
|
} else {
|
||||||
$col_cand = $tab_all;
|
$col_cand = $tab_all;
|
||||||
$_needsort= 0;
|
$needsort = 0;
|
||||||
//echo "Kandidaten sind jetzt alle \n";
|
//echo "Kandidaten sind jetzt alle \n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we came up with $col_unique (very good) or
|
// If we came up with $col_unique (very good) or $col_index (still
|
||||||
// $col_index (still good) as $col_cand we want to check
|
// good) as $col_cand we want to check if we have any 'Y' there
|
||||||
// if we have any 'Y' there (that would mean that
|
// (that would mean that they were also found in the whereclauses
|
||||||
// they were also found in the whereclauses which would be
|
// which would be great). if yes, we take only those
|
||||||
// great). if yes, we take only those
|
if ($needsort == 1) {
|
||||||
if ($_needsort == 1) {
|
while (list($col, $is_where) = each($col_cand)) {
|
||||||
while (list($_col,$_iswhere) = each($col_cand)) {
|
$tab = explode('.', $col);
|
||||||
$_tab = explode('.',$_col);
|
$tab = $tab[0];
|
||||||
$_tab = $_tab[0];
|
if ($is_where == 'Y') {
|
||||||
if ($_iswhere == 'Y') {
|
$vg[$col] = $tab;
|
||||||
$_vg[$_col] = $_tab;
|
|
||||||
} else {
|
} else {
|
||||||
$_sg[$_col] = $_tab;
|
$sg[$col] = $tab;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isset($vg)) {
|
if (isset($vg)) {
|
||||||
@@ -861,46 +860,54 @@ if (isset($Field) && count($Field) > 0) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if our array of candidates has more than one member
|
// If our array of candidates has more than one member we'll just
|
||||||
// we'll just find the smallest table.
|
// find the smallest table.
|
||||||
// of course the actual query would be faster if we check
|
// Of course the actual query would be faster if we check for
|
||||||
// for the Criteria which gives the smallest resultset
|
// the Criteria which gives the smallest result set in its table,
|
||||||
// in its table, but it would take too much time to check this
|
// but it would take too much time to check this
|
||||||
|
|
||||||
if (count($col_cand) > 1) {
|
if (count($col_cand) > 1) {
|
||||||
//echo "wir haben immer noch mehr als einen Kandidaten. Pr<50>fe Gr<47><72>e\n";
|
//echo "wir haben immer noch mehr als einen Kandidaten. Pr<50>fe Gr<47><72>e\n";
|
||||||
// of course we only want to check each table once
|
// Of course we only want to check each table once
|
||||||
$_checked_tables = $col_cand;
|
$checked_tables = $col_cand;
|
||||||
while (list(, $_tab) = each($col_cand)) {
|
while (list(, $tab) = each($col_cand)) {
|
||||||
if ($_checked_tables[$_tab] != 1 ) {
|
if ($checked_tables[$tab] != 1 ) {
|
||||||
//echo "pr<EFBFBD>fe jetzt: Tabelle ".$_tab. "\n";
|
//echo 'pr<EFBFBD>fe jetzt: Tabelle ' . $tab . "\n";
|
||||||
$rows_qry = 'SELECT count(1) as anz '
|
$rows_qry = 'SELECT COUNT(1) AS anz '
|
||||||
. 'FROM ' . PMA_backquote($_tab);
|
. 'FROM ' . PMA_backquote($tab);
|
||||||
$rows_rs = PMA_mysql_query($rows_qry);
|
$rows_rs = PMA_mysql_query($rows_qry);
|
||||||
while ($res = PMA_mysql_fetch_array($rows_rs)) {
|
while ($res = PMA_mysql_fetch_array($rows_rs)) {
|
||||||
$_tsize[$_tab] = $res['anz'];
|
$tsize[$tab] = $res['anz'];
|
||||||
//echo "$_tab hat:" .$_tsize[$_tab]."\n";
|
//echo "$tab hat: " . $tsize[$tab] . "\n";
|
||||||
}
|
}
|
||||||
$_checked_tables[$_tab] =1;
|
$checked_tables[$tab] = 1;
|
||||||
}
|
}
|
||||||
$_csize[$_tab] = $_tsize[$_tab];
|
$csize[$tab] = $tsize[$tab];
|
||||||
//echo "erster csize: ".$_csize[$_tab]."\n";
|
//echo 'erster csize: ' . $csize[$tab] . "\n";
|
||||||
}
|
}
|
||||||
asort($_csize);
|
asort($csize);
|
||||||
reset($_csize);
|
reset($csize);
|
||||||
$master = key($_csize);
|
$master = key($csize);
|
||||||
//echo "kleinste Datei: " . $master . "\n";
|
//echo 'kleinste Datei: ' . $master . "\n";
|
||||||
} else {
|
} else {
|
||||||
$master = $col_cand[0];
|
$master = $col_cand[0];
|
||||||
//echo "master ist der einzige Kandidat: " . $master . "\n";
|
//echo 'master ist der einzige Kandidat: ' . $master . "\n";
|
||||||
}
|
}
|
||||||
} // end if (exactly one where clause)
|
} // end if (exactly one where clause)
|
||||||
//echo "ich habe mich entschieden: " . $master;
|
//echo 'ich habe mich entschieden: ' . $master;
|
||||||
//die;
|
//die;
|
||||||
|
|
||||||
// i will need something to remove unwanted entries from
|
|
||||||
// arrays which works with php3
|
/**
|
||||||
function array_short($array,$key)
|
* Removes unwanted entries from an array (PHP3 compliant)
|
||||||
|
*
|
||||||
|
* @param array the array to work with
|
||||||
|
* @param array the list of keys to remove
|
||||||
|
*
|
||||||
|
* @return array the cleaned up array
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
function PMA_arrayShort($array, $key)
|
||||||
{
|
{
|
||||||
while (list($k, $v) = each($array)) {
|
while (list($k, $v) = each($array)) {
|
||||||
if ($k != $key) {
|
if ($k != $key) {
|
||||||
@@ -910,22 +917,30 @@ if (isset($Field) && count($Field) > 0) {
|
|||||||
if (!isset($reta)){
|
if (!isset($reta)){
|
||||||
$reta = array();
|
$reta = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $reta;
|
return $reta;
|
||||||
}
|
} // end of the "PMA_arrayShort()" function
|
||||||
|
|
||||||
// now we will often need a function to find all
|
|
||||||
// related tables. what we will have is an array
|
|
||||||
// of allready connected tables $tab_know and one
|
|
||||||
// of tables that we still couldn't connect $tab_left
|
|
||||||
// all we start with is $tab_all and the knowledge of
|
|
||||||
// our $master
|
|
||||||
// as we need to work with php3 we cannot give the variables
|
|
||||||
// by & so i need to make them global ;-(
|
|
||||||
// the only thing we give is wether to go from
|
|
||||||
// master to foreign or vice versa
|
|
||||||
|
|
||||||
function getrelatives($from) {
|
/**
|
||||||
global $tab_left,$tab_know,$fromclause,$db,$cfgRelation,$dbh;
|
* Finds all related tables
|
||||||
|
*
|
||||||
|
* @param string wether to go from master to foreign or vice versa
|
||||||
|
*
|
||||||
|
* @return boolean always TRUE
|
||||||
|
*
|
||||||
|
* @global array the list of tables that we still couldn't connect
|
||||||
|
* @global array the list of allready connected tables
|
||||||
|
* @global string the current databse name
|
||||||
|
* @global string the super user connection id
|
||||||
|
* @global array the list of relation settings
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
function PMA_getRelatives($from) {
|
||||||
|
global $tab_left, $tab_know, $fromclause;
|
||||||
|
global $dbh, $db, $cfgRelation;
|
||||||
|
|
||||||
if ($from == 'master') {
|
if ($from == 'master') {
|
||||||
$to = 'foreign';
|
$to = 'foreign';
|
||||||
} else {
|
} else {
|
||||||
@@ -936,8 +951,8 @@ if (isset($Field) && count($Field) > 0) {
|
|||||||
|
|
||||||
$rel_query = 'SELECT *'
|
$rel_query = 'SELECT *'
|
||||||
. ' FROM ' . PMA_backquote($cfgRelation['relation'])
|
. ' FROM ' . PMA_backquote($cfgRelation['relation'])
|
||||||
. ' WHERE ' . $from . '_db = \'' . $db . '\''
|
. ' WHERE ' . $from . '_db = \'' . PMA_sqlAddslashes($db) . '\''
|
||||||
. ' AND ' . $to . '_db = \'' . $db . '\''
|
. ' AND ' . $to . '_db = \'' . PMA_sqlAddslashes($db) . '\''
|
||||||
. ' AND ' . $from . '_table IN ' . $in_know
|
. ' AND ' . $from . '_table IN ' . $in_know
|
||||||
. ' AND ' . $to . '_table IN ' . $in_left;
|
. ' AND ' . $to . '_table IN ' . $in_left;
|
||||||
if (isset($dbh)) {
|
if (isset($dbh)) {
|
||||||
@@ -952,44 +967,47 @@ if (isset($Field) && count($Field) > 0) {
|
|||||||
while ($row = PMA_mysql_fetch_array($relations)) {
|
while ($row = PMA_mysql_fetch_array($relations)) {
|
||||||
$found_table = $row[$to . '_table'];
|
$found_table = $row[$to . '_table'];
|
||||||
if (isset($tab_left[$found_table])) {
|
if (isset($tab_left[$found_table])) {
|
||||||
$fromclause .= "\n LEFT JOIN "
|
$fromclause .= "\n" . ' LEFT JOIN '
|
||||||
. PMA_backquote($row[$to . '_table']) . ' ON '
|
. PMA_backquote($row[$to . '_table']) . ' ON '
|
||||||
. PMA_backquote($row[$from . '_table']) . '.'
|
. PMA_backquote($row[$from . '_table']) . '.'
|
||||||
. PMA_backquote($row[$from . '_field']) . ' = '
|
. PMA_backquote($row[$from . '_field']) . ' = '
|
||||||
. PMA_backquote($row[$to . '_table']) . '.'
|
. PMA_backquote($row[$to . '_table']) . '.'
|
||||||
. PMA_backquote($row[$to . '_field']) . ' ';
|
. PMA_backquote($row[$to . '_field']) . ' ';
|
||||||
$tab_know[$found_table] = $found_table;
|
$tab_know[$found_table] = $found_table;
|
||||||
$tab_left = array_short($tab_left,$found_table);
|
$tab_left = PMA_arrayShort($tab_left, $found_table);
|
||||||
}
|
}
|
||||||
} // end while
|
} // end while
|
||||||
} // End of Function
|
|
||||||
|
return TRUE;
|
||||||
|
} // end of the "PMA_getRelatives()" function
|
||||||
|
|
||||||
|
|
||||||
$tab_left = array_short($tab_all,$master);
|
$tab_left = PMA_arrayShort($tab_all, $master);
|
||||||
$tab_know[$master] = $master;
|
$tab_know[$master] = $master;
|
||||||
|
|
||||||
$run=0;$emerg='';
|
$run = 0;
|
||||||
|
$emerg = '';
|
||||||
while (count($tab_left) > 0) {
|
while (count($tab_left) > 0) {
|
||||||
if ($run % 2 == 0) {
|
if ($run % 2 == 0) {
|
||||||
getrelatives('master');
|
PMA_getRelatives('master');
|
||||||
} else {
|
} else {
|
||||||
getrelatives('foreign');
|
PMA_getRelatives('foreign');
|
||||||
}
|
}
|
||||||
$run++;
|
$run++;
|
||||||
if ($run > 5) {
|
if ($run > 5) {
|
||||||
|
|
||||||
while ( list(,$_tab) = each($tab_left)) {
|
while (list(, $tab) = each($tab_left)) {
|
||||||
$emerg .= ', '.$_tab;
|
$emerg .= ', ' . $tab;
|
||||||
$tab_left=array_short($tab_left,$_tab);
|
$tab_left = PMA_arrayShort($tab_left, $tab);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} // end while
|
||||||
$qry_from = $master . $emerg . $fromclause;
|
$qry_from = $master . $emerg . $fromclause;
|
||||||
}
|
} // end if ($cfgRelation['relwork'] && count($tab_all) > 0)
|
||||||
|
|
||||||
} // end count($Field) > 0
|
} // end count($Field) > 0
|
||||||
|
|
||||||
// now let's see what we got
|
// Now let's see what we got
|
||||||
if (!empty($qry_from)) {
|
if (!empty($qry_from)) {
|
||||||
$encoded_qry .= urlencode('FROM ' . $qry_from . "\n");
|
$encoded_qry .= urlencode('FROM ' . $qry_from . "\n");
|
||||||
echo 'FROM ' . htmlspecialchars($qry_from) . "\n";
|
echo 'FROM ' . htmlspecialchars($qry_from) . "\n";
|
||||||
|
@@ -512,13 +512,15 @@ if ($cfgRelation['pdfwork'] && $num_tables > 0) {
|
|||||||
<?php
|
<?php
|
||||||
} // end if
|
} // end if
|
||||||
} // end if
|
} // end if
|
||||||
|
|
||||||
if ($num_tables > 0
|
if ($num_tables > 0
|
||||||
&& $cfgRelation['relwork'] && $cfgRelation['commwork']) {
|
&& $cfgRelation['relwork'] && $cfgRelation['commwork']) {
|
||||||
?>
|
?>
|
||||||
<!-- import docSQL files -->
|
<!-- import docSQL files -->
|
||||||
<li>
|
<li>
|
||||||
<div style="margin-bottom: 10px"><a href="db_details_importdocsql.php3?<?php echo $takeaway; ?>"><?php echo $strImportDocSQL;?></a></div>
|
<div style="margin-bottom: 10px"><a href="db_details_importdocsql.php3?<?php echo $takeaway . '">' . $strImportDocSQL; ?></a></div>
|
||||||
</li><?php
|
</li>
|
||||||
|
<?php
|
||||||
}
|
}
|
||||||
echo "\n" . '</ul>';
|
echo "\n" . '</ul>';
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user