changes to use new central db for relation and bookmark tables

This commit is contained in:
Mike Beck
2002-06-15 01:37:31 +00:00
parent 591d2972f2
commit 153e8f52bf
6 changed files with 293 additions and 203 deletions

View File

@@ -5,6 +5,27 @@ phpMyAdmin - Changelog
$Id$ $Id$
$Source$ $Source$
2002-06-15 Mike Beck <mikebeck@users.sourceforge.net>
started putting the relationtables in a central db
with the bookmarktable
* config.inc.php3
- renamed $cfg['Servers'][$i]['bookmarkdb'] to
$cfg['Servers'][$i]['pmadb']
- allready added $cfg['Servers'][$i]['column_comments']
* tbl_relation.lib.php3 new file
- PMA_getRelationsParam(): get and test config
- getForeigners() get an array of tables/fields
related to the one you supply
- getDisplayField() get the tables display column
- PMA_query_as_cu() query the pmadb using the controluser
if possible, otherwise normal user
changes to use new place of tables are allready finished for
those files:
* tbl_relation.php3
* db_details_structure.php3
* pdf_pages.php3
* tbl_qbe.php3
2002-06-14 Alexander M. Turek <rabus@users.sourceforge.net> 2002-06-14 Alexander M. Turek <rabus@users.sourceforge.net>
* lang/german.inc.php3: Updates. * lang/german.inc.php3: Updates.
* libraries/select_lang.lib.php3, lang/german-utf8.inc.php3: * libraries/select_lang.lib.php3, lang/german-utf8.inc.php3:

View File

@@ -62,7 +62,7 @@ $cfg['Servers'][$i]['table_info'] = ''; // table to describe the dis
$cfg['Servers'][$i]['table_coords'] = ''; // table to describe the tables position for the PDF $cfg['Servers'][$i]['table_coords'] = ''; // table to describe the tables position for the PDF
// schema - leave blank for no PDF schema support // schema - leave blank for no PDF schema support
$cfg['Servers'][$i]['column_comments']=''; // table to store columncomments $cfg['Servers'][$i]['column_comments']=''; // table to store columncomments
// - leave blank if you don't want to use this // - leave blank if you don't want to use this
$cfg['Servers'][$i]['pdf_pages'] = ''; // table to describe pages of relationpdf $cfg['Servers'][$i]['pdf_pages'] = ''; // table to describe pages of relationpdf
$cfg['Servers'][$i]['AllowDeny']['order'] // Host authentication order, leave blank to not use $cfg['Servers'][$i]['AllowDeny']['order'] // Host authentication order, leave blank to not use
= ''; = '';
@@ -71,50 +71,52 @@ $cfg['Servers'][$i]['AllowDeny']['rules'] // Host authentication rules
$i++; $i++;
$cfg['Servers'][$i]['host'] = ''; $cfg['Servers'][$i]['host'] = '';
$cfg['Servers'][$i]['port'] = ''; $cfg['Servers'][$i]['port'] = '';
$cfg['Servers'][$i]['socket'] = ''; $cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp'; $cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['controluser'] = ''; $cfg['Servers'][$i]['controluser'] = '';
$cfg['Servers'][$i]['controlpass'] = ''; $cfg['Servers'][$i]['controlpass'] = '';
$cfg['Servers'][$i]['auth_type'] = 'config'; $cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root'; $cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = ''; $cfg['Servers'][$i]['password'] = '';
$cfg['Servers'][$i]['only_db'] = ''; $cfg['Servers'][$i]['only_db'] = '';
$cfg['Servers'][$i]['verbose'] = ''; $cfg['Servers'][$i]['verbose'] = '';
$cfg['Servers'][$i]['bookmarkdb'] = ''; $cfg['Servers'][$i]['pmadb'] = '';
$cfg['Servers'][$i]['bookmarktable'] = ''; $cfg['Servers'][$i]['bookmarktable'] = '';
$cfg['Servers'][$i]['relation'] = ''; $cfg['Servers'][$i]['relation'] = '';
$cfg['Servers'][$i]['table_info'] = ''; $cfg['Servers'][$i]['table_info'] = '';
$cfg['Servers'][$i]['table_coords'] = ''; $cfg['Servers'][$i]['table_coords'] = '';
$cfg['Servers'][$i]['pdf_pages'] = ''; $cfg['Servers'][$i]['column_comments'] ='';
$cfg['Servers'][$i]['pdf_pages'] = '';
$cfg['Servers'][$i]['AllowDeny']['order'] $cfg['Servers'][$i]['AllowDeny']['order']
= ''; = '';
$cfg['Servers'][$i]['AllowDeny']['rules'] $cfg['Servers'][$i]['AllowDeny']['rules']
= array(); = array();
$i++; $i++;
$cfg['Servers'][$i]['host'] = ''; $cfg['Servers'][$i]['host'] = '';
$cfg['Servers'][$i]['port'] = ''; $cfg['Servers'][$i]['port'] = '';
$cfg['Servers'][$i]['socket'] = ''; $cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp'; $cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['controluser'] = ''; $cfg['Servers'][$i]['controluser'] = '';
$cfg['Servers'][$i]['controlpass'] = ''; $cfg['Servers'][$i]['controlpass'] = '';
$cfg['Servers'][$i]['auth_type'] = 'config'; $cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root'; $cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = ''; $cfg['Servers'][$i]['password'] = '';
$cfg['Servers'][$i]['only_db'] = ''; $cfg['Servers'][$i]['only_db'] = '';
$cfg['Servers'][$i]['verbose'] = ''; $cfg['Servers'][$i]['verbose'] = '';
$cfg['Servers'][$i]['bookmarkdb'] = ''; $cfg['Servers'][$i]['pmadb'] = '';
$cfg['Servers'][$i]['bookmarktable'] = ''; $cfg['Servers'][$i]['bookmarktable'] = '';
$cfg['Servers'][$i]['relation'] = ''; $cfg['Servers'][$i]['relation'] = '';
$cfg['Servers'][$i]['table_info'] = ''; $cfg['Servers'][$i]['table_info'] = '';
$cfg['Servers'][$i]['table_coords'] = ''; $cfg['Servers'][$i]['table_coords'] = '';
$cfg['Servers'][$i]['pdf_pages'] = ''; $cfg['Servers'][$i]['column_comments'] ='';
$cfg['Servers'][$i]['pdf_pages'] = '';
$cfg['Servers'][$i]['AllowDeny']['order'] $cfg['Servers'][$i]['AllowDeny']['order']
= ''; = '';
$cfg['Servers'][$i]['AllowDeny']['rules'] $cfg['Servers'][$i]['AllowDeny']['rules']
= array(); = array();
// If you have more than one server configured, you can set $cfg['ServerDefault'] // If you have more than one server configured, you can set $cfg['ServerDefault']
// to any one of them to autoconnect to that server when phpMyAdmin is started, // to any one of them to autoconnect to that server when phpMyAdmin is started,

View File

@@ -22,6 +22,11 @@ if (empty($is_info)) {
include('./db_details_db_info.php3'); include('./db_details_db_info.php3');
echo "\n"; echo "\n";
} }
/**
* Settings for Relationstuff
*/
require('./libraries/relation.lib.php3');
$cfgRelation = PMA_getRelationsParam();
/** /**
@@ -442,22 +447,22 @@ echo ' ' . '&nbsp;<input type="submit" value="' . $strGo . '" />' . "\n";
<?php <?php
// is this OK to check for 'class' support? // is this OK to check for 'class' support?
if (!empty($cfg['Server']['table_coords']) if ($cfgRelation['pdfwork'] && $num_tables > 0) {
&& $num_tables > 0) {
?> ?>
<!-- Work on PDF Pages --> <!-- Work on PDF Pages -->
<li> <li>
<?php <?php
$takeaway = $url_query . '&amp;table=' . urlencode($cfg['Server']['pdf_pages']); $takeaway = $url_query . '&amp;table=' . urlencode($table);
?> ?>
<a href="pdf_pages.php3?<?php echo $takeaway; ?>"><?php echo $strEditPDFPages ;?></a> <a href="pdf_pages.php3?<?php echo $takeaway; ?>"><?php echo $strEditPDFPages ;?></a>
</li> </li>
<!-- PDF schema --> <!-- PDF schema -->
<?php <?php
// We only show this if we find something in the new pdf_pages table // We only show this if we find something in the new pdf_pages table
@PMA_mysql_select_db($db);
$test_query = 'SELECT * FROM ' . PMA_backquote($cfg['Server']['pdf_pages']); $test_query = 'SELECT * FROM ' . PMA_backquote($cfgRelation['pdf_pages'])
$test_rs = PMA_mysql_query($test_query) or PMA_mysqlDie('', $test_query, '', $err_url_0); . ' WHERE db_name = \'' . $db . '\'';
$test_rs = PMA_query_as_cu($test_query);
if(mysql_num_rows($test_rs) > 0){ if(mysql_num_rows($test_rs) > 0){
?> ?>
<li> <li>
@@ -497,4 +502,3 @@ echo "\n" . '</ul>';
echo "\n"; echo "\n";
require('./footer.inc.php3'); require('./footer.inc.php3');
?> ?>

View File

@@ -3,63 +3,47 @@
* pdf_pages.php3 mikebeck 2002-05-23 * pdf_pages.php3 mikebeck 2002-05-23
* create and edit the pages to output in pdf * create and edit the pages to output in pdf
* *
* requires a separate table:
* CREATE TABLE `PMA_pdf_pages` (
* `page_nr` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
* `page_descr` VARCHAR(50) NOT NULL
* ) TYPE = MYISAM
* COMMENT = 'PDF Relationpages for PMA';
*
* also requires a new variable in config.inc.php3:
* $cfg['Servers'][$i]['pdf_pages'] = 'PMA_pdf_pages'; // table to describe pages of relationpdf
*/ */
/** /**
* Gets some core libraries * Gets some core libraries
*/ */
require('./libraries/grab_globals.lib.php3'); require('./libraries/grab_globals.lib.php3');
require('./libraries/common.lib.php3'); require('./libraries/common.lib.php3');
require('./tbl_properties_common.php3'); include('./db_details_common.php3');
require('./tbl_properties_table_info.php3');
/** /**
* Select page: * Settings for Relationstuff
*/
require('./libraries/relation.lib.php3');
$cfgRelation = PMA_getRelationsParam();
/**
* now in ./libraries/relation.lib.php3 we check for all tables
* that we need, but if we don't find them we are quiet about it
* so people can work without.
* this page is absolutely useless if you didn't set up your tables
* correctly, so it is a good place to see which tables we can and
* complain ;-)
*/ */
if (!empty($cfg['Server']['pdf_pages'])){ if(!$cfgRelation['relwork']) {
// First we get all tables in the current db echo sprintf($strNotSet,'relation','config.inc.php3') . '<br /><a href="Documentation.html#relation" target="documentation">' . $strDocu . '</a>';
$tab_query = 'SHOW TABLES FROM ' . PMA_backquote($db); die();
$tab_rs = PMA_mysql_query($tab_query) or PMA_mysqlDie('', $tab_query, '', $err_url_0); }
$selectboxall[] = '--'; if(!$cfgRelation['displaywork']) {
while ($curr_table = @PMA_mysql_fetch_array($tab_rs)) { echo sprintf($strNotSet,'table_info','config.inc.php3') . '<br /><a href="Documentation.html#table_info" target="documentation">' . $strDocu . '</a>';
// i'd like to check if all required tables are present die();
// and otherwise give some hint }
if($curr_table[0] == $cfg['Server']['relation']){$relex =1;}else{ if(!isset($cfgRelation['table_coords'])){
if($curr_table[0] == $cfg['Server']['table_info']){$info =1;}else{ echo sprintf($strNotSet,'table_coords','config.inc.php3') . '<br /><a href="Documentation.html#table_coords" target="documentation">' . $strDocu . '</a>';
if($curr_table[0] == $cfg['Server']['table_coords']){$coords =1;}else{ die();
// if it is not one of the PMA tables add it to the }
// selectbox if(!isset($cfgRelation['pdf_pages'])) {
$selectboxall[] = $curr_table[0]; echo sprintf($strNotSet,'pdf_page','config.inc.php3') . '<br /><a href="Documentation.html#pdf_pages" target="documentation">' . $strDocu . '</a>';
} die();
} }
}
}
// now check if we found all required tables
// this will fail if either the variable was not set or the table does not
// exist
//
if(!isset($relex)){
echo sprintf($strNotSet,'relation','config.inc.php3') . '<br /><a href="Documentation.html#relation" target="documentation">' . $strDocu . '</a>';
die();
}
if(!isset($info)) {
echo sprintf($strNotSet,'table_info','config.inc.php3') . '<br /><a href="Documentation.html#table_info" target="documentation">' . $strDocu . '</a>';
die();
}
if(!isset($coords)){
echo sprintf($strNotSet,'table_coords','config.inc.php3') . '<br /><a href="Documentation.html#table_coords" target="documentation">' . $strDocu . '</a>';
die();
}
if ($cfgRelation['pdfwork']){
// now is the time to work on all changes // now is the time to work on all changes
if(isset($do)){ if(isset($do)){
switch($do){ switch($do){
@@ -67,44 +51,61 @@ if (!empty($cfg['Server']['pdf_pages'])){
if(!isset($newpage) || $newpage==''){ if(!isset($newpage) || $newpage==''){
$newpage = $strNoDescription; $newpage = $strNoDescription;
} }
$ins_query = 'INSERT INTO ' . PMA_backquote($cfg['Server']['pdf_pages']) . $ins_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['pdf_pages'])
' (page_descr) VALUES (\'' . $newpage . '\')'; . ' (db_name,page_descr) '
PMA_mysql_query($ins_query) or PMA_mysqlDie('', $ins_query, '', $err_url_0); . ' VALUES (\'' . $db . '\',\'' . $newpage . '\')';
PMA_query_as_cu($ins_query);
break; break;
case 'edcoord': case 'edcoord':
while (list($key,$arrvalue) = each($ctable)) { while (list($key,$arrvalue) = each($ctable)) {
if(!isset($arrvalue['x']) || $arrvalue['x'] == ''){$arrvalue['x']=0;} if(!isset($arrvalue['x']) || $arrvalue['x'] == ''){$arrvalue['x']=0;}
if(!isset($arrvalue['y']) || $arrvalue['y'] == ''){$arrvalue['y']=0;} if(!isset($arrvalue['y']) || $arrvalue['y'] == ''){$arrvalue['y']=0;}
if(isset($arrvalue['name']) && $arrvalue['name'] != '--'){ if(isset($arrvalue['name']) && $arrvalue['name'] != '--'){
$test_query = 'SELECT * FROM '.PMA_backquote($cfg['Server']['table_coords']) .
' WHERE table_name = \''.$arrvalue['name'] . '\'' . $test_query = 'SELECT * FROM '.PMA_backquote($cfgRelation['table_coords'])
. ' WHERE db_name = \'' . $db . '\''
. ' AND table_name = \'' . $arrvalue['name'] . '\'' .
' AND pdf_page_number = '.$chpage; ' AND pdf_page_number = '.$chpage;
$test_rs = PMA_mysql_query($test_query) or PMA_mysqlDie('', $test_query, '', $err_url_0); $test_rs = PMA_query_as_cu($test_query);
if(mysql_num_rows($test_rs)>0){ if(mysql_num_rows($test_rs)>0){
if($arrvalue['delete'] == 'y'){ if($arrvalue['delete'] == 'y'){
$ch_query = 'DELETE FROM '.PMA_backquote($cfg['Server']['table_coords']) . $ch_query = 'DELETE FROM '.PMA_backquote($cfgRelation['table_coords'])
' WHERE table_name = \''.$arrvalue['name'] . '\'' . . ' WHERE db_name = \'' . $db . '\''
' AND pdf_page_number = '.$chpage; . ' AND table_name = \''.$arrvalue['name'] . '\''
. ' AND pdf_page_number = '.$chpage;
}else{ }else{
$ch_query = 'UPDATE '.PMA_backquote($cfg['Server']['table_coords']) . $ch_query = 'UPDATE '.PMA_backquote($cfgRelation['table_coords'])
' SET x='.$arrvalue['x'] . ', y= '. $arrvalue['y'] . . ' SET x='.$arrvalue['x'] . ', y= '. $arrvalue['y']
' WHERE table_name = \''.$arrvalue['name'] . '\'' . . ' WHERE db_name = \'' . $db . '\''
' AND pdf_page_number = '.$chpage; . ' AND table_name = \''.$arrvalue['name'] . '\''
. ' AND pdf_page_number = '.$chpage;
} }
}else{ }else{
$ch_query = 'INSERT INTO '.PMA_backquote($cfg['Server']['table_coords']) . $ch_query = 'INSERT INTO '.PMA_backquote($cfgRelation['table_coords'])
' VALUES (\''.$arrvalue['name'].'\','.$chpage.','. . ' (db_name,table_name,pdf_page_number,x,y) '
$arrvalue['x'].','.$arrvalue['y'].')'; . ' VALUES (\'' . $db . '\',\''.$arrvalue['name'].'\','
. $chpage.','
. $arrvalue['x'].','.$arrvalue['y'].')';
} }
PMA_mysql_query($ch_query) or PMA_mysqlDie('', $ch_query, '', $err_url_0); PMA_query_as_cu($ch_query);
} }
} }
break; break;
} }
} // End if (isset($do))
// we will need an array of all tables in this db
$selectboxall[] = '--';
$alltab_qry = 'SHOW TABLES FROM ' . PMA_backquote($db);
$alltab_rs = @PMA_mysql_query($alltab_qry) or PMA_mysqlDie('', $alltab_qry, '', $err_url_0);
while (list($table) = @PMA_mysql_fetch_array($alltab_rs)) {
$selectboxall[] = $table;
} }
// now first show some possibility to choose a page for the pdf // now first show some possibility to choose a page for the pdf
$page_query = 'SELECT * FROM ' .PMA_backquote($cfg['Server']['pdf_pages']); $page_query = 'SELECT * FROM ' . PMA_backquote($cfgRelation['pdf_pages'])
$page_rs = PMA_mysql_query($page_query) or PMA_mysqlDie('', $page_query, '', $err_url_0); . ' WHERE db_name = \'' . $db . '\'';
$page_rs = PMA_query_as_cu($page_query);
if(mysql_num_rows($page_rs)>0){ if(mysql_num_rows($page_rs)>0){
?> ?>
<form action="pdf_pages.php3" method="post" name="selpage"> <form action="pdf_pages.php3" method="post" name="selpage">
@@ -159,9 +160,12 @@ if (!empty($cfg['Server']['pdf_pages'])){
<tr><th><?php echo $strTable;?></th><th><?php echo $strDelete;?></th><th>X</th><th>Y</th></tr> <tr><th><?php echo $strTable;?></th><th><?php echo $strDelete;?></th><th>X</th><th>Y</th></tr>
<?php <?php
if(isset($ctable)){unset($ctable);} if(isset($ctable)){unset($ctable);}
$page_query = 'SELECT * FROM' . PMA_backquote($cfg['Server']['table_coords']) .
' WHERE pdf_page_number='.$chpage; $page_query = 'SELECT * FROM ' . PMA_backquote($cfgRelation['table_coords'])
$page_rs = PMA_mysql_query($page_query) or PMA_mysqlDie('', $page_query, '', $err_url_0); . ' WHERE db_name = \'' . $db . '\''
. ' AND pdf_page_number=' . $chpage;
$page_rs = PMA_query_as_cu($page_query);
$i=0; $i=0;
while ($sh_page = @PMA_mysql_fetch_array($page_rs)) { while ($sh_page = @PMA_mysql_fetch_array($page_rs)) {
echo '<tr '; echo '<tr ';

View File

@@ -8,7 +8,9 @@
*/ */
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');
$cfgRelation = PMA_getRelationsParam();
/** /**
* A query has been submitted -> executes it, else displays the headers * A query has been submitted -> executes it, else displays the headers
@@ -719,7 +721,6 @@ if (isset($Field) && count($Field) > 0) {
$rel = array(); $rel = array();
$rest = array(); $rest = array();
$found = array(); $found = array();
$rel_work = FALSE;
// 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
while (list(, $value) = each($Field)) { while (list(, $value) = each($Field)) {
@@ -728,11 +729,8 @@ if (isset($Field) && count($Field) > 0) {
$alltabs[] = substr(urldecode($parts[0]), 1, strlen(urldecode($parts[0])) - 2); $alltabs[] = substr(urldecode($parts[0]), 1, strlen(urldecode($parts[0])) - 2);
} }
} // end while } // end while
if ($cfg['Server']['relation']) {
$tables = @PMA_mysql_query('SELECT COUNT(*) AS count FROM ' . PMA_backquote($cfg['Server']['relation'])); if ($cfgRelation['relwork'] && count($alltabs) > 0) {
$rel_work = ($tables) ? PMA_mysql_result($tables, 0, 'count') : FALSE;
} // end if
if ($rel_work && count($alltabs) > 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++) {
@@ -770,14 +768,27 @@ if (isset($Field) && count($Field) > 0) {
// We will need this a few times: // We will need this a few times:
$incrit = '(\'' . implode('\', \'', $alltabs) . '\')'; $incrit = '(\'' . implode('\', \'', $alltabs) . '\')';
$rel_query = 'SELECT master_table AS wer, COUNT(foreign_table) AS hits FROM ' . PMA_backquote($cfg['Server']['relation']) $_rel_query = 'SELECT master_table AS wer, COUNT(foreign_table) AS hits'
. ' WHERE master_table IN ' . $incrit . ' AND foreign_table IN ' . $incrit . ' FROM ' . PMA_backquote($cfgRelation['relation'])
. ' WHERE master_db = \'' . $db . '\' '
. ' AND foreign_db = \'' . $db . '\' '
. ' AND master_table IN ' . $incrit
. ' AND foreign_table IN ' . $incrit
. ' GROUP BY master_table ORDER BY hits DESC'; . ' GROUP BY master_table ORDER BY hits DESC';
if(!empty($column)){
$_rel_query .= ' AND master_field = \'' . $column . '\'';
}
if (isset($dbh)) {
PMA_mysql_select_db($cfgRelation['db'],$dbh);
$_relations = @PMA_mysql_query($_rel_query, $GLOBALS['dbh']) or PMA_mysqlDie(mysql_error($GLOBALS['dbh']), $_rel_query, '', $err_url_0);
PMA_mysql_select_db($db,$dbh);
} else {
PMA_mysql_select_db($cfgRelation['db']);
$_relations = @PMA_mysql_query($_rel_query) or PMA_mysqlDie('', $_rel_query, '', $err_url_0);
PMA_mysql_select_db($db);
}
$rel_id = @PMA_mysql_query($rel_query) or PMA_mysqlDie('', $rel_query, '', $err_url); while ($row = PMA_mysql_fetch_array($_relations)) {
// if we don't find anything we try the other way round
while ($row = PMA_mysql_fetch_array($rel_id)) {
// we want the first one (highest number of hits) or the first one // we want the first one (highest number of hits) or the first one
// that is in the WHERE clause // that is in the WHERE clause
if (!isset($master)) { if (!isset($master)) {
@@ -805,14 +816,27 @@ if (isset($Field) && count($Field) > 0) {
// now we only use everything but the first table // now we only use everything but the first table
$incrit_s = '(\'' . implode('\', \'', $reltabs) . '\')'; $incrit_s = '(\'' . implode('\', \'', $reltabs) . '\')';
$_rel_query = 'SELECT *'
$rel_query = 'SELECT * FROM ' . PMA_backquote($cfg['Server']['relation']) . ' FROM ' . PMA_backquote($cfgRelation['relation'])
. ' WHERE master_table IN ' . $incrit . ' AND foreign_table IN ' . $incrit_s . ' WHERE master_db = \'' . $db . '\' '
. ' AND foreign_db = \'' . $db . '\' '
. ' AND master_table IN ' . $incrit
. ' AND foreign_table IN ' . $incrit_s
. ' ORDER BY foreign_table, master_table'; . ' ORDER BY foreign_table, master_table';
if(!empty($column)){
$_rel_query .= ' AND master_field = \'' . $column . '\'';
}
if (isset($dbh)) {
PMA_mysql_select_db($cfgRelation['db'],$dbh);
$_relations = @PMA_mysql_query($_rel_query, $GLOBALS['dbh']) or PMA_mysqlDie(mysql_error($GLOBALS['dbh']), $_rel_query, '', $err_url_0);
PMA_mysql_select_db($db,$dbh);
} else {
PMA_mysql_select_db($cfgRelation['db']);
$_relations = @PMA_mysql_query($_rel_query) or PMA_mysqlDie('', $_rel_query, '', $err_url_0);
PMA_mysql_select_db($db);
}
$rel_id = @PMA_mysql_query($rel_query) or PMA_mysqlDie('', $rel_query, '', $err_url); while ($row = PMA_mysql_fetch_array($_relations)) {
while ($row = PMA_mysql_fetch_array($rel_id)) {
$foreign_table = $row['foreign_table']; $foreign_table = $row['foreign_table'];
if ($rel[$foreign_table]['mcon'] == 0) { if ($rel[$foreign_table]['mcon'] == 0) {
// if we already found a link to the mastertable we don't // if we already found a link to the mastertable we don't
@@ -844,12 +868,27 @@ if (isset($Field) && count($Field) > 0) {
$incrit_d = '(\'' . implode('\', \'', $found) . '\')'; $incrit_d = '(\'' . implode('\', \'', $found) . '\')';
$incrit_s = '(\'' . implode('\', \'', $rest) . '\')'; $incrit_s = '(\'' . implode('\', \'', $rest) . '\')';
$rel_query = 'SELECT * FROM ' . PMA_backquote($cfg['Server']['relation']) $_rel_query = 'SELECT *'
. ' WHERE master_table IN ' . $incrit_s . ' AND foreign_table IN ' . $incrit_d . ' FROM ' . PMA_backquote($cfgRelation['relation'])
. ' WHERE master_db = \'' . $db . '\' '
. ' AND foreign_db = \'' . $db . '\' '
. ' AND master_table IN ' . $incrit_s
. ' AND foreign_table IN ' . $incrit_d
. ' ORDER BY master_table, foreign_table'; . ' ORDER BY master_table, foreign_table';
$rel_id = @PMA_mysql_query($rel_query) or PMA_mysqlDie('', $rel_query, '', $err_url); if(!empty($column)){
$_rel_query .= ' AND master_field = \'' . $column . '\'';
}
if (isset($dbh)) {
PMA_mysql_select_db($cfgRelation['db'],$dbh);
$_relations = @PMA_mysql_query($_rel_query, $GLOBALS['dbh']) or PMA_mysqlDie(mysql_error($GLOBALS['dbh']), $_rel_query, '', $err_url_0);
PMA_mysql_select_db($db,$dbh);
} else {
PMA_mysql_select_db($cfgRelation['db']);
$_relations = @PMA_mysql_query($_rel_query) or PMA_mysqlDie('', $_rel_query, '', $err_url_0);
PMA_mysql_select_db($db);
}
while ($row = PMA_mysql_fetch_array($rel_id)) { while ($row = PMA_mysql_fetch_array($_relations)) {
$found_table = $row['master_table']; $found_table = $row['master_table'];
if ($rel[$found_table]['mcon'] == 0) { if ($rel[$found_table]['mcon'] == 0) {
// if we allready found a link to the mastertable we // if we allready found a link to the mastertable we
@@ -882,12 +921,13 @@ if (isset($Field) && count($Field) > 0) {
$qry_from .= ', '; $qry_from .= ', ';
} }
$qry_from .= PMA_backquote($key); $qry_from .= PMA_backquote($key);
// debug echo "add ". $key . ": " . PMA_backquote($key) . "\n";
} else if ($varr['mcon'] == 0) { } else if ($varr['mcon'] == 0) {
// those that have no link with the mastertable we will // those that have no link with the mastertable we will
// show at the end // show at the end
$lj .= PMA_backquote($varr['link']); $lj .= $varr['link'];
} else { } else {
$ljm .= PMA_backquote($varr['link']); $ljm .= $varr['link'];
} }
} // end while } // end while
@@ -897,7 +937,6 @@ if (isset($Field) && count($Field) > 0) {
$qry_from .= $ljm . $lj; $qry_from .= $ljm . $lj;
} // end if ($master != '') } // end if ($master != '')
} // end rel work and $alltabs > 0 } // end rel work and $alltabs > 0
if (empty($qry_from) && count($alltabs)) { if (empty($qry_from) && count($alltabs)) {
// there might be more than one mentioning of the table in here // there might be more than one mentioning of the table in here
// as array_unique is only PHP4 we have to do this by hand // as array_unique is only PHP4 we have to do this by hand

View File

@@ -9,74 +9,106 @@ require('./libraries/grab_globals.lib.php3');
require('./libraries/common.lib.php3'); require('./libraries/common.lib.php3');
require('./tbl_properties_common.php3'); require('./tbl_properties_common.php3');
require('./tbl_properties_table_info.php3'); require('./tbl_properties_table_info.php3');
require('./libraries/relation.lib.php3');
$cfgRelation = PMA_getRelationsParam();
/** /**
* Updates * Updates
*/ */
if (!empty($cfg['Server']['relation']) if ($cfgRelation['relwork']) {
$existrel = getForeigners($db,$table);
}
if ($cfgRelation['displaywork']) {
$disp = getDisplayField($db,$table);
}
if ($cfgRelation['relwork']
&& isset($submit_rel) && $submit_rel == 'true') { && isset($submit_rel) && $submit_rel == 'true') {
// first check if there is a entry allready
$upd_query = 'SELECT master_field, foreign_table, foreign_field FROM ' . PMA_backquote($cfg['Server']['relation'])
. ' WHERE master_table = \'' . PMA_sqlAddslashes($table) . '\'';
$upd_rs = PMA_mysql_query($upd_query) or PMA_mysqlDie('', $upd_query, '', $err_url_0);
while ($foundrel = @PMA_mysql_fetch_array($upd_rs)) {
$currfield = $foundrel['master_field'];
$existrel[$currfield] = $foundrel['foreign_table'] . '.' . $foundrel['foreign_field'];
}
while (list($key, $value) = each($destination)) { while (list($key, $value) = each($destination)) {
if ($value != 'nix') { if ($value != 'nix') {
$for = explode('.', $value);
if (!isset($existrel[$key])) { if (!isset($existrel[$key])) {
$for = explode('.', $destination[$key]); $upd_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['relation'])
$upd_query = 'INSERT INTO ' . PMA_backquote($cfg['Server']['relation']) . '(master_db, master_table, master_field, foreign_db, foreign_table, foreign_field)'
. '(master_table, master_field, foreign_table, foreign_field)'
. ' values(' . ' values('
. '\'' . PMA_sqlAddslashes($db) . '\', '
. '\'' . PMA_sqlAddslashes($table) . '\', ' . '\'' . PMA_sqlAddslashes($table) . '\', '
. '\'' . PMA_sqlAddslashes($key) . '\', ' . '\'' . PMA_sqlAddslashes($key) . '\', '
. '\'' . PMA_sqlAddslashes($for[0]) . '\', ' . '\'' . PMA_sqlAddslashes($for[0]) . '\', '
. '\'' . PMA_sqlAddslashes($for[1]) . '\')'; . '\'' . PMA_sqlAddslashes($for[1]) . '\','
$upd_rs = PMA_mysql_query($upd_query) or PMA_mysqlDie('', $upd_query, '', $err_url_0); . '\'' . PMA_sqlAddslashes($for[2]) . '\')';
} else if ($existrel[$key] != $value) { } else if ($existrel[$key] != $value) {
$for = explode('.', $destination[$key]); $upd_query = 'UPDATE ' . PMA_backquote($cfgRelation['relation']) . ' SET'
$upd_query = 'UPDATE ' . PMA_backquote($cfg['Server']['relation']) . ' SET' . ' foreign_db = \'' . PMA_sqlAddslashes($for[0]) .'\', '
. ' foreign_table = \'' . PMA_sqlAddslashes($for[0]) . '\', foreign_field = \'' . PMA_sqlAddslashes($for[1]) . '\' ' . ' foreign_table = \'' . PMA_sqlAddslashes($for[1]) .'\', '
. ' WHERE master_table = \'' . PMA_sqlAddslashes($table) . '\' AND master_field = \'' . PMA_sqlAddslashes($key) . '\''; . ' foreign_field = \'' . PMA_sqlAddslashes($for[2]) .'\' '
$upd_rs = PMA_mysql_query($upd_query) or PMA_mysqlDie('', $upd_query, '', $err_url_0); . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\''
. ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\''
. ' AND master_field = \'' . PMA_sqlAddslashes($key) . '\'';
} // end if... else.... } // end if... else....
} else if (isset($existrel[$key])) { } else if (isset($existrel[$key])) {
$for = explode('.', $destination[$key]); $upd_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['relation'])
$upd_query = 'DELETE FROM ' . PMA_backquote($cfg['Server']['relation']) . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\''
. ' WHERE master_table = \'' . PMA_sqlAddslashes($table) . '\' AND master_field = \'' . PMA_sqlAddslashes($key) . '\''; . ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\''
$upd_rs = PMA_mysql_query($upd_query) or PMA_mysqlDie('', $upd_query, '', $err_url_0); . ' AND master_field = \'' . PMA_sqlAddslashes($key) . '\'';
} // end if... else.... } // end if... else....
if(isset($upd_query)){
if (isset($dbh)) {
mysql_select_db($cfgRelation['db'],$dbh);
$upd_rs = PMA_mysql_query($upd_query, $dbh) or PMA_mysqlDie(mysql_error($dbh), $upd_query, '', $err_url_0);
mysql_select_db($db,$dbh);
} else {
mysql_select_db($cfgRelation['db']);
$upd_rs = PMA_mysql_query($upd_query, $GLOBALS['dbh']) or PMA_mysqlDie('', $upd_query, '', $err_url_0);
mysql_select_db($db);
}
}
} // end while } // end while
} // end if } // end if
if (!empty($cfg['Server']['table_info']) if ($cfgRelation['displaywork']
&& isset($submit_show) && $submit_show == 'true') { && isset($submit_show) && $submit_show == 'true') {
$test_query = 'SELECT display_field FROM ' . PMA_backquote($cfg['Server']['table_info'])
. ' WHERE table_name = \'' . PMA_sqlAddslashes($table) . '\''; if ($disp) {
$test_rs = PMA_mysql_query($test_query) or PMA_mysqlDie('', $test_query, '', $err_url_0); $upd_query = 'UPDATE ' . PMA_backquote($cfgRelation['table_info'])
if ($test_rs && mysql_num_rows($test_rs) > 0) { . ' SET display_field = \'' . PMA_sqlAddslashes($display_field) . '\''
$upd_query = 'UPDATE ' . PMA_backquote($cfg['Server']['table_info']) . ' SET' . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
. ' display_field = \'' . PMA_sqlAddslashes($display_field) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'';
. ' WHERE table_name = \'' . PMA_sqlAddslashes($table) . '\'';
$upd_rs = PMA_mysql_query($upd_query) or PMA_mysqlDie('', $upd_query, '', $err_url_0);
} else { } else {
$ins_query = 'INSERT INTO ' . PMA_backquote($cfg['Server']['table_info']) . ' (table_name, display_field)' $upd_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['table_info'])
. ' VALUES(\'' . PMA_sqlAddslashes($table) . '\', \'' . PMA_sqlAddslashes($display_field) .'\')'; . '(db_name,table_name,display_field) '
$ins_rs = PMA_mysql_query($ins_query) or PMA_mysqlDie('', $ins_query, '', $err_url_0); . ' VALUES('
. '\'' . PMA_sqlAddslashes($db) . '\','
. '\'' . PMA_sqlAddslashes($table) . '\','
. '\'' . PMA_sqlAddslashes($display_field) .'\')';
}
if(isset($upd_query)){
if (isset($dbh)) {
mysql_select_db($cfgRelation['db'],$dbh);
$upd_rs = PMA_mysql_query($upd_query, $dbh) or PMA_mysqlDie(mysql_error($dbh), $upd_query, '', $err_url_0);
mysql_select_db($db,$dbh);
} else {
mysql_select_db($cfgRelation['db']);
$upd_rs = PMA_mysql_query($upd_query, $GLOBALS['dbh']) or PMA_mysqlDie('', $upd_query, '', $err_url_0);
mysql_select_db($db);
}
} }
} // end if } // end if
// now that we might have changed we have to see again
if ($cfgRelation['relwork']) {
$existrel = getForeigners($db,$table);
}
if ($cfgRelation['displaywork']) {
$disp = getDisplayField($db,$table);
}
/** /**
* Dialog * Dialog
*/ */
if ($cfg['Server']['relation']) { if ($cfgRelation['relwork']) {
$rel_work = FALSE;
// Mike Beck: get all Table-Fields to choose relation // to choose Relations we first need all tablenames in current db
$tab_query = 'SHOW TABLES FROM ' . PMA_backquote($db); $tab_query = 'SHOW TABLES FROM ' . PMA_backquote($db);
$tab_rs = PMA_mysql_query($tab_query) or PMA_mysqlDie('', $tab_query, '', $err_url_0); $tab_rs = PMA_mysql_query($tab_query) or PMA_mysqlDie('', $tab_query, '', $err_url_0);
$selectboxall['nix'] = '--'; $selectboxall['nix'] = '--';
@@ -87,12 +119,12 @@ if ($cfg['Server']['relation']) {
if ($fi_rs && mysql_num_rows($fi_rs) > 0) { if ($fi_rs && mysql_num_rows($fi_rs) > 0) {
while ($curr_field = PMA_mysql_fetch_array($fi_rs)) { while ($curr_field = PMA_mysql_fetch_array($fi_rs)) {
if (isset($curr_field['Key_name']) && $curr_field['Key_name'] == 'PRIMARY') { if (isset($curr_field['Key_name']) && $curr_field['Key_name'] == 'PRIMARY') {
$field_full = $curr_field['Table'] . '.' . $curr_field['Column_name']; $field_full = $db . '.' .$curr_field['Table'] . '.' . $curr_field['Column_name'];
$field_v = $curr_field['Table'] . '->' . $curr_field['Column_name']; $field_v = $curr_field['Table'] . '->' . $curr_field['Column_name'];
break; break;
} else if (isset($curr_field['non_unique']) && $curr_field['non_unique'] == 0) { } else if (isset($curr_field['non_unique']) && $curr_field['non_unique'] == 0) {
// if we can't find a primary key we take any unique one // if we can't find a primary key we take any unique one
$field_full = $curr_field['Table'] . '.' . $curr_field['Column_name']; $field_full = $db . '.' . $curr_field['Table'] . '.' . $curr_field['Column_name'];
$field_v = $curr_field['Table'] . '->' . $curr_field['Column_name']; $field_v = $curr_field['Table'] . '->' . $curr_field['Column_name'];
} // end if } // end if
} // end while } // end while
@@ -102,23 +134,10 @@ if ($cfg['Server']['relation']) {
} }
} // end if (mysql_num_rows) } // end if (mysql_num_rows)
} }
if ($curr_table[0] == $cfg['Server']['relation']) {
$rel_work = TRUE;
}
} // end while } // end while
// create Array of Relations (Mike Beck) // create Array of Relations (Mike Beck)
if ($rel_work) { $rel_dest = getForeigners($db,$table);
$rel_query = 'SELECT master_field, concat(foreign_table, \'.\', foreign_field) AS rel'
. ' FROM ' . PMA_backquote($cfg['Server']['relation'])
. ' WHERE master_table = \'' . PMA_sqlAddslashes($table) . '\'';
$relations = @PMA_mysql_query($rel_query) or PMA_mysqlDie('', $rel_query, '', $err_url);
while ($relrow = @PMA_mysql_fetch_array($relations)) {
$rel_col = $relrow['master_field'];
$rel_dest[$rel_col] = $relrow['rel'];
} // end while
} // end if
} // end if } // end if
// now find out the columns of our $table // now find out the columns of our $table
@@ -154,9 +173,16 @@ if ($col_rs && mysql_num_rows($col_rs) > 0) {
reset($selectboxall); reset($selectboxall);
while (list($key, $value) = each($selectboxall)) { while (list($key, $value) = each($selectboxall)) {
$myfield = $row['Field']; $myfield = $row['Field'];
if(isset($existrel[$myfield])){
$test = $existrel[$myfield]['foreign_db'] . '.'
. $existrel[$myfield]['foreign_table'] . '.'
. $existrel[$myfield]['foreign_field'];
} else {
$test = FALSE;
}
echo ' ' echo ' '
. '<option value="' . htmlspecialchars($key) . '"'; . '<option value="' . htmlspecialchars($key) . '"';
if (isset($rel_dest[$myfield]) && $key == $rel_dest[$myfield]) { if ( $test && $key == $test) {
echo ' selected="selected"'; echo ' selected="selected"';
} }
echo '>' . $value . '</option>'. "\n"; echo '>' . $value . '</option>'. "\n";
@@ -179,15 +205,9 @@ if ($col_rs && mysql_num_rows($col_rs) > 0) {
</form> </form>
<?php <?php
if (!empty($cfg['Server']['table_info'])) { if ($cfgRelation['displaywork']) {
// Get "display_filed" infos // Get "display_filed" infos
$disp_query = 'SELECT display_field FROM ' . PMA_backquote($cfg['Server']['table_info']) $disp = getDisplayField($db,$table);
. ' WHERE table_name = \'' . PMA_sqlAddslashes($table) . '\'';
$disp_rs = PMA_mysql_query($disp_query) or PMA_mysqlDie('', $disp_query, '', $err_url_0);
$row = ($disp_rs ? PMA_mysql_fetch_array($disp_rs) : '');
if (isset($row['display_field'])) {
$disp = $row['display_field'];
}
echo "\n"; echo "\n";
?> ?>