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$
$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>
* lang/german.inc.php3: Updates.
* 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
// schema - leave blank for no PDF schema support
$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]['AllowDeny']['order'] // Host authentication order, leave blank to not use
= '';
@@ -71,50 +71,52 @@ $cfg['Servers'][$i]['AllowDeny']['rules'] // Host authentication rules
$i++;
$cfg['Servers'][$i]['host'] = '';
$cfg['Servers'][$i]['port'] = '';
$cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['controluser'] = '';
$cfg['Servers'][$i]['controlpass'] = '';
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '';
$cfg['Servers'][$i]['only_db'] = '';
$cfg['Servers'][$i]['verbose'] = '';
$cfg['Servers'][$i]['bookmarkdb'] = '';
$cfg['Servers'][$i]['bookmarktable'] = '';
$cfg['Servers'][$i]['relation'] = '';
$cfg['Servers'][$i]['table_info'] = '';
$cfg['Servers'][$i]['table_coords'] = '';
$cfg['Servers'][$i]['pdf_pages'] = '';
$cfg['Servers'][$i]['host'] = '';
$cfg['Servers'][$i]['port'] = '';
$cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['controluser'] = '';
$cfg['Servers'][$i]['controlpass'] = '';
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '';
$cfg['Servers'][$i]['only_db'] = '';
$cfg['Servers'][$i]['verbose'] = '';
$cfg['Servers'][$i]['pmadb'] = '';
$cfg['Servers'][$i]['bookmarktable'] = '';
$cfg['Servers'][$i]['relation'] = '';
$cfg['Servers'][$i]['table_info'] = '';
$cfg['Servers'][$i]['table_coords'] = '';
$cfg['Servers'][$i]['column_comments'] ='';
$cfg['Servers'][$i]['pdf_pages'] = '';
$cfg['Servers'][$i]['AllowDeny']['order']
= '';
= '';
$cfg['Servers'][$i]['AllowDeny']['rules']
= array();
= array();
$i++;
$cfg['Servers'][$i]['host'] = '';
$cfg['Servers'][$i]['port'] = '';
$cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['controluser'] = '';
$cfg['Servers'][$i]['controlpass'] = '';
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '';
$cfg['Servers'][$i]['only_db'] = '';
$cfg['Servers'][$i]['verbose'] = '';
$cfg['Servers'][$i]['bookmarkdb'] = '';
$cfg['Servers'][$i]['bookmarktable'] = '';
$cfg['Servers'][$i]['relation'] = '';
$cfg['Servers'][$i]['table_info'] = '';
$cfg['Servers'][$i]['table_coords'] = '';
$cfg['Servers'][$i]['pdf_pages'] = '';
$cfg['Servers'][$i]['host'] = '';
$cfg['Servers'][$i]['port'] = '';
$cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['controluser'] = '';
$cfg['Servers'][$i]['controlpass'] = '';
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '';
$cfg['Servers'][$i]['only_db'] = '';
$cfg['Servers'][$i]['verbose'] = '';
$cfg['Servers'][$i]['pmadb'] = '';
$cfg['Servers'][$i]['bookmarktable'] = '';
$cfg['Servers'][$i]['relation'] = '';
$cfg['Servers'][$i]['table_info'] = '';
$cfg['Servers'][$i]['table_coords'] = '';
$cfg['Servers'][$i]['column_comments'] ='';
$cfg['Servers'][$i]['pdf_pages'] = '';
$cfg['Servers'][$i]['AllowDeny']['order']
= '';
= '';
$cfg['Servers'][$i]['AllowDeny']['rules']
= array();
= array();
// 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,

View File

@@ -22,6 +22,11 @@ if (empty($is_info)) {
include('./db_details_db_info.php3');
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
// is this OK to check for 'class' support?
if (!empty($cfg['Server']['table_coords'])
&& $num_tables > 0) {
if ($cfgRelation['pdfwork'] && $num_tables > 0) {
?>
<!-- Work on PDF Pages -->
<li>
<?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>
</li>
<!-- PDF schema -->
<?php
// 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_rs = PMA_mysql_query($test_query) or PMA_mysqlDie('', $test_query, '', $err_url_0);
$test_query = 'SELECT * FROM ' . PMA_backquote($cfgRelation['pdf_pages'])
. ' WHERE db_name = \'' . $db . '\'';
$test_rs = PMA_query_as_cu($test_query);
if(mysql_num_rows($test_rs) > 0){
?>
<li>
@@ -497,4 +502,3 @@ echo "\n" . '</ul>';
echo "\n";
require('./footer.inc.php3');
?>

View File

@@ -3,63 +3,47 @@
* pdf_pages.php3 mikebeck 2002-05-23
* 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
*/
require('./libraries/grab_globals.lib.php3');
require('./libraries/common.lib.php3');
require('./tbl_properties_common.php3');
require('./tbl_properties_table_info.php3');
include('./db_details_common.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'])){
// First we get all tables in the current db
$tab_query = 'SHOW TABLES FROM ' . PMA_backquote($db);
$tab_rs = PMA_mysql_query($tab_query) or PMA_mysqlDie('', $tab_query, '', $err_url_0);
$selectboxall[] = '--';
while ($curr_table = @PMA_mysql_fetch_array($tab_rs)) {
// i'd like to check if all required tables are present
// and otherwise give some hint
if($curr_table[0] == $cfg['Server']['relation']){$relex =1;}else{
if($curr_table[0] == $cfg['Server']['table_info']){$info =1;}else{
if($curr_table[0] == $cfg['Server']['table_coords']){$coords =1;}else{
// if it is not one of the PMA tables add it to the
// selectbox
$selectboxall[] = $curr_table[0];
}
}
}
}
// 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['relwork']) {
echo sprintf($strNotSet,'relation','config.inc.php3') . '<br /><a href="Documentation.html#relation" target="documentation">' . $strDocu . '</a>';
die();
}
if(!$cfgRelation['displaywork']) {
echo sprintf($strNotSet,'table_info','config.inc.php3') . '<br /><a href="Documentation.html#table_info" target="documentation">' . $strDocu . '</a>';
die();
}
if(!isset($cfgRelation['table_coords'])){
echo sprintf($strNotSet,'table_coords','config.inc.php3') . '<br /><a href="Documentation.html#table_coords" target="documentation">' . $strDocu . '</a>';
die();
}
if(!isset($cfgRelation['pdf_pages'])) {
echo sprintf($strNotSet,'pdf_page','config.inc.php3') . '<br /><a href="Documentation.html#pdf_pages" target="documentation">' . $strDocu . '</a>';
die();
}
if ($cfgRelation['pdfwork']){
// now is the time to work on all changes
if(isset($do)){
switch($do){
@@ -67,44 +51,61 @@ if (!empty($cfg['Server']['pdf_pages'])){
if(!isset($newpage) || $newpage==''){
$newpage = $strNoDescription;
}
$ins_query = 'INSERT INTO ' . PMA_backquote($cfg['Server']['pdf_pages']) .
' (page_descr) VALUES (\'' . $newpage . '\')';
PMA_mysql_query($ins_query) or PMA_mysqlDie('', $ins_query, '', $err_url_0);
$ins_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['pdf_pages'])
. ' (db_name,page_descr) '
. ' VALUES (\'' . $db . '\',\'' . $newpage . '\')';
PMA_query_as_cu($ins_query);
break;
case 'edcoord':
while (list($key,$arrvalue) = each($ctable)) {
if(!isset($arrvalue['x']) || $arrvalue['x'] == ''){$arrvalue['x']=0;}
if(!isset($arrvalue['y']) || $arrvalue['y'] == ''){$arrvalue['y']=0;}
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;
$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($arrvalue['delete'] == 'y'){
$ch_query = 'DELETE FROM '.PMA_backquote($cfg['Server']['table_coords']) .
' WHERE table_name = \''.$arrvalue['name'] . '\'' .
' AND pdf_page_number = '.$chpage;
$ch_query = 'DELETE FROM '.PMA_backquote($cfgRelation['table_coords'])
. ' WHERE db_name = \'' . $db . '\''
. ' AND table_name = \''.$arrvalue['name'] . '\''
. ' AND pdf_page_number = '.$chpage;
}else{
$ch_query = 'UPDATE '.PMA_backquote($cfg['Server']['table_coords']) .
' SET x='.$arrvalue['x'] . ', y= '. $arrvalue['y'] .
' WHERE table_name = \''.$arrvalue['name'] . '\'' .
' AND pdf_page_number = '.$chpage;
$ch_query = 'UPDATE '.PMA_backquote($cfgRelation['table_coords'])
. ' SET x='.$arrvalue['x'] . ', y= '. $arrvalue['y']
. ' WHERE db_name = \'' . $db . '\''
. ' AND table_name = \''.$arrvalue['name'] . '\''
. ' AND pdf_page_number = '.$chpage;
}
}else{
$ch_query = 'INSERT INTO '.PMA_backquote($cfg['Server']['table_coords']) .
' VALUES (\''.$arrvalue['name'].'\','.$chpage.','.
$arrvalue['x'].','.$arrvalue['y'].')';
$ch_query = 'INSERT INTO '.PMA_backquote($cfgRelation['table_coords'])
. ' (db_name,table_name,pdf_page_number,x,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;
}
} // 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
$page_query = 'SELECT * FROM ' .PMA_backquote($cfg['Server']['pdf_pages']);
$page_rs = PMA_mysql_query($page_query) or PMA_mysqlDie('', $page_query, '', $err_url_0);
$page_query = 'SELECT * FROM ' . PMA_backquote($cfgRelation['pdf_pages'])
. ' WHERE db_name = \'' . $db . '\'';
$page_rs = PMA_query_as_cu($page_query);
if(mysql_num_rows($page_rs)>0){
?>
<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>
<?php
if(isset($ctable)){unset($ctable);}
$page_query = 'SELECT * FROM' . PMA_backquote($cfg['Server']['table_coords']) .
' WHERE pdf_page_number='.$chpage;
$page_rs = PMA_mysql_query($page_query) or PMA_mysqlDie('', $page_query, '', $err_url_0);
$page_query = 'SELECT * FROM ' . PMA_backquote($cfgRelation['table_coords'])
. ' WHERE db_name = \'' . $db . '\''
. ' AND pdf_page_number=' . $chpage;
$page_rs = PMA_query_as_cu($page_query);
$i=0;
while ($sh_page = @PMA_mysql_fetch_array($page_rs)) {
echo '<tr ';

View File

@@ -8,7 +8,9 @@
*/
require('./libraries/grab_globals.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
@@ -719,7 +721,6 @@ if (isset($Field) && count($Field) > 0) {
$rel = array();
$rest = array();
$found = array();
$rel_work = FALSE;
// we only start this if we have fields, otherwise it would be dumb
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);
}
} // end while
if ($cfg['Server']['relation']) {
$tables = @PMA_mysql_query('SELECT COUNT(*) AS count FROM ' . PMA_backquote($cfg['Server']['relation']));
$rel_work = ($tables) ? PMA_mysql_result($tables, 0, 'count') : FALSE;
} // end if
if ($rel_work && count($alltabs) > 0) {
if ($cfgRelation['relwork'] && count($alltabs) > 0) {
// now we need all tables that we have in the whereclause
for ($x = 0; $x < count($Criteria); $x++) {
@@ -770,14 +768,27 @@ if (isset($Field) && count($Field) > 0) {
// We will need this a few times:
$incrit = '(\'' . implode('\', \'', $alltabs) . '\')';
$rel_query = 'SELECT master_table AS wer, COUNT(foreign_table) AS hits FROM ' . PMA_backquote($cfg['Server']['relation'])
. ' WHERE master_table IN ' . $incrit . ' AND foreign_table IN ' . $incrit
$_rel_query = 'SELECT master_table AS wer, COUNT(foreign_table) AS hits'
. ' 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';
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);
// if we don't find anything we try the other way round
while ($row = PMA_mysql_fetch_array($rel_id)) {
while ($row = PMA_mysql_fetch_array($_relations)) {
// we want the first one (highest number of hits) or the first one
// that is in the WHERE clause
if (!isset($master)) {
@@ -805,14 +816,27 @@ if (isset($Field) && count($Field) > 0) {
// now we only use everything but the first table
$incrit_s = '(\'' . implode('\', \'', $reltabs) . '\')';
$rel_query = 'SELECT * FROM ' . PMA_backquote($cfg['Server']['relation'])
. ' WHERE master_table IN ' . $incrit . ' AND foreign_table IN ' . $incrit_s
$_rel_query = 'SELECT *'
. ' FROM ' . PMA_backquote($cfgRelation['relation'])
. ' 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';
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($rel_id)) {
while ($row = PMA_mysql_fetch_array($_relations)) {
$foreign_table = $row['foreign_table'];
if ($rel[$foreign_table]['mcon'] == 0) {
// 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_s = '(\'' . implode('\', \'', $rest) . '\')';
$rel_query = 'SELECT * FROM ' . PMA_backquote($cfg['Server']['relation'])
. ' WHERE master_table IN ' . $incrit_s . ' AND foreign_table IN ' . $incrit_d
$_rel_query = 'SELECT *'
. ' 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';
$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'];
if ($rel[$found_table]['mcon'] == 0) {
// if we allready found a link to the mastertable we
@@ -882,12 +921,13 @@ if (isset($Field) && count($Field) > 0) {
$qry_from .= ', ';
}
$qry_from .= PMA_backquote($key);
// debug echo "add ". $key . ": " . PMA_backquote($key) . "\n";
} else if ($varr['mcon'] == 0) {
// those that have no link with the mastertable we will
// show at the end
$lj .= PMA_backquote($varr['link']);
$lj .= $varr['link'];
} else {
$ljm .= PMA_backquote($varr['link']);
$ljm .= $varr['link'];
}
} // end while
@@ -897,7 +937,6 @@ if (isset($Field) && count($Field) > 0) {
$qry_from .= $ljm . $lj;
} // end if ($master != '')
} // end rel work and $alltabs > 0
if (empty($qry_from) && count($alltabs)) {
// 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

View File

@@ -9,74 +9,106 @@ require('./libraries/grab_globals.lib.php3');
require('./libraries/common.lib.php3');
require('./tbl_properties_common.php3');
require('./tbl_properties_table_info.php3');
require('./libraries/relation.lib.php3');
$cfgRelation = PMA_getRelationsParam();
/**
* 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') {
// 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)) {
if ($value != 'nix') {
$for = explode('.', $value);
if (!isset($existrel[$key])) {
$for = explode('.', $destination[$key]);
$upd_query = 'INSERT INTO ' . PMA_backquote($cfg['Server']['relation'])
. '(master_table, master_field, foreign_table, foreign_field)'
$upd_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['relation'])
. '(master_db, master_table, master_field, foreign_db, foreign_table, foreign_field)'
. ' values('
. '\'' . PMA_sqlAddslashes($db) . '\', '
. '\'' . PMA_sqlAddslashes($table) . '\', '
. '\'' . PMA_sqlAddslashes($key) . '\', '
. '\'' . PMA_sqlAddslashes($for[0]) . '\', '
. '\'' . PMA_sqlAddslashes($for[1]) . '\')';
$upd_rs = PMA_mysql_query($upd_query) or PMA_mysqlDie('', $upd_query, '', $err_url_0);
. '\'' . PMA_sqlAddslashes($for[1]) . '\','
. '\'' . PMA_sqlAddslashes($for[2]) . '\')';
} else if ($existrel[$key] != $value) {
$for = explode('.', $destination[$key]);
$upd_query = 'UPDATE ' . PMA_backquote($cfg['Server']['relation']) . ' SET'
. ' foreign_table = \'' . PMA_sqlAddslashes($for[0]) . '\', foreign_field = \'' . PMA_sqlAddslashes($for[1]) . '\' '
. ' WHERE master_table = \'' . PMA_sqlAddslashes($table) . '\' AND master_field = \'' . PMA_sqlAddslashes($key) . '\'';
$upd_rs = PMA_mysql_query($upd_query) or PMA_mysqlDie('', $upd_query, '', $err_url_0);
$upd_query = 'UPDATE ' . PMA_backquote($cfgRelation['relation']) . ' SET'
. ' foreign_db = \'' . PMA_sqlAddslashes($for[0]) .'\', '
. ' foreign_table = \'' . PMA_sqlAddslashes($for[1]) .'\', '
. ' foreign_field = \'' . PMA_sqlAddslashes($for[2]) .'\' '
. ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\''
. ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\''
. ' AND master_field = \'' . PMA_sqlAddslashes($key) . '\'';
} // end if... else....
} else if (isset($existrel[$key])) {
$for = explode('.', $destination[$key]);
$upd_query = 'DELETE FROM ' . PMA_backquote($cfg['Server']['relation'])
. ' WHERE master_table = \'' . PMA_sqlAddslashes($table) . '\' AND master_field = \'' . PMA_sqlAddslashes($key) . '\'';
$upd_rs = PMA_mysql_query($upd_query) or PMA_mysqlDie('', $upd_query, '', $err_url_0);
$upd_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['relation'])
. ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\''
. ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\''
. ' AND master_field = \'' . PMA_sqlAddslashes($key) . '\'';
} // 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 if
if (!empty($cfg['Server']['table_info'])
if ($cfgRelation['displaywork']
&& isset($submit_show) && $submit_show == 'true') {
$test_query = 'SELECT display_field FROM ' . PMA_backquote($cfg['Server']['table_info'])
. ' WHERE table_name = \'' . PMA_sqlAddslashes($table) . '\'';
$test_rs = PMA_mysql_query($test_query) or PMA_mysqlDie('', $test_query, '', $err_url_0);
if ($test_rs && mysql_num_rows($test_rs) > 0) {
$upd_query = 'UPDATE ' . PMA_backquote($cfg['Server']['table_info']) . ' SET'
. ' display_field = \'' . PMA_sqlAddslashes($display_field) . '\''
. ' WHERE table_name = \'' . PMA_sqlAddslashes($table) . '\'';
$upd_rs = PMA_mysql_query($upd_query) or PMA_mysqlDie('', $upd_query, '', $err_url_0);
if ($disp) {
$upd_query = 'UPDATE ' . PMA_backquote($cfgRelation['table_info'])
. ' SET display_field = \'' . PMA_sqlAddslashes($display_field) . '\''
. ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
. ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'';
} else {
$ins_query = 'INSERT INTO ' . PMA_backquote($cfg['Server']['table_info']) . ' (table_name, display_field)'
. ' VALUES(\'' . PMA_sqlAddslashes($table) . '\', \'' . PMA_sqlAddslashes($display_field) .'\')';
$ins_rs = PMA_mysql_query($ins_query) or PMA_mysqlDie('', $ins_query, '', $err_url_0);
$upd_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['table_info'])
. '(db_name,table_name,display_field) '
. ' 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
// 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
*/
if ($cfg['Server']['relation']) {
$rel_work = FALSE;
// Mike Beck: get all Table-Fields to choose relation
if ($cfgRelation['relwork']) {
// to choose Relations we first need all tablenames in current db
$tab_query = 'SHOW TABLES FROM ' . PMA_backquote($db);
$tab_rs = PMA_mysql_query($tab_query) or PMA_mysqlDie('', $tab_query, '', $err_url_0);
$selectboxall['nix'] = '--';
@@ -87,12 +119,12 @@ if ($cfg['Server']['relation']) {
if ($fi_rs && mysql_num_rows($fi_rs) > 0) {
while ($curr_field = PMA_mysql_fetch_array($fi_rs)) {
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'];
break;
} 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
$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'];
} // end if
} // end while
@@ -102,23 +134,10 @@ if ($cfg['Server']['relation']) {
}
} // end if (mysql_num_rows)
}
if ($curr_table[0] == $cfg['Server']['relation']) {
$rel_work = TRUE;
}
} // end while
// create Array of Relations (Mike Beck)
if ($rel_work) {
$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
$rel_dest = getForeigners($db,$table);
} // end if
// now find out the columns of our $table
@@ -154,9 +173,16 @@ if ($col_rs && mysql_num_rows($col_rs) > 0) {
reset($selectboxall);
while (list($key, $value) = each($selectboxall)) {
$myfield = $row['Field'];
if(isset($existrel[$myfield])){
$test = $existrel[$myfield]['foreign_db'] . '.'
. $existrel[$myfield]['foreign_table'] . '.'
. $existrel[$myfield]['foreign_field'];
} else {
$test = FALSE;
}
echo ' '
. '<option value="' . htmlspecialchars($key) . '"';
if (isset($rel_dest[$myfield]) && $key == $rel_dest[$myfield]) {
if ( $test && $key == $test) {
echo ' selected="selected"';
}
echo '>' . $value . '</option>'. "\n";
@@ -179,15 +205,9 @@ if ($col_rs && mysql_num_rows($col_rs) > 0) {
</form>
<?php
if (!empty($cfg['Server']['table_info'])) {
if ($cfgRelation['displaywork']) {
// Get "display_filed" infos
$disp_query = 'SELECT display_field FROM ' . PMA_backquote($cfg['Server']['table_info'])
. ' 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'];
}
$disp = getDisplayField($db,$table);
echo "\n";
?>