diff --git a/tbl_qbe.php3 b/tbl_qbe.php3 index 062e5d3c6..f509980b5 100755 --- a/tbl_qbe.php3 +++ b/tbl_qbe.php3 @@ -10,12 +10,17 @@ require('./libraries/grab_globals.lib.php3'); require('./libraries/common.lib.php3'); require('./libraries/relation.lib.php3'); + +/** + * Gets the relation settings + */ $cfgRelation = PMA_getRelationsParam(); + /** * A query has been submitted -> execute it, else display the headers */ -if (isset($submit_sql) && eregi('^SELECT',$encoded_sql_query)) { +if (isset($submit_sql) && eregi('^SELECT', $encoded_sql_query)) { $goto = 'db_details.php3'; $zero_rows = htmlspecialchars($strSuccess); $sql_query = urldecode($encoded_sql_query); @@ -30,9 +35,11 @@ if (isset($submit_sql) && eregi('^SELECT',$encoded_sql_query)) { require('./db_details_db_info.php3'); } -if(isset($submit_sql) && !eregi('^SELECT',$encoded_sql_query)) { +if (isset($submit_sql) && !eregi('^SELECT', $encoded_sql_query)) { echo '

' . $strHaveToShow . '

'; } + + /** * Initialize some variables */ @@ -115,8 +122,8 @@ $k = 0; // The tables list sent by a previously submitted form if (!empty($TableList)) { - for ($x = 0; $x < sizeof($TableList); $x++) { - $tbl_names[$TableList[$x]] = ' selected="selected"'; + for ($x = 0; $x < count($TableList); $x++) { + $tbl_names[urldecode($TableList[$x])] = ' selected="selected"'; } } // end if @@ -261,7 +268,7 @@ for ($x = 0; $x < $col; $x++) { ' . htmlspecialchars($key) . '' . "\n"; + echo '' . "\n"; } ?> @@ -778,19 +785,19 @@ 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($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 . '\''; + $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; + if (!empty($column)) { + $rel_query .= ' AND master_field = \'' . $column . '\''; } + $rel_query .= ' GROUP BY master_table ORDER BY hits DESC' - $_relations = PMA_query_as_cu($_rel_query); - while ($row = PMA_mysql_fetch_array($_relations)) { + $relations = PMA_query_as_cu($rel_query); + 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)) { @@ -816,32 +823,33 @@ if (isset($Field) && count($Field) > 0) { } } // end while - // now we only use everything but the first table + // now we only use everything but the first table $incrit_s = '(\'' . implode('\', \'', $reltabs) . '\')'; - $_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 . '\''; + $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; + if (!empty($column)) { + $rel_query .= ' AND master_field = \'' . $column . '\''; } + $rel_query .= ' ORDER BY foreign_table, master_table'; + 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); + PMA_mysql_select_db($cfgRelation['db'], $dbh); + $relations = @PMA_mysql_query($rel_query, $dbh) or PMA_mysqlDie(mysql_error($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); + $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($_relations)) { + 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 + // if we already found a link to the master table we don't // want another otherwise we take whatever we get $rel[$foreign_table]['link'] = ' LEFT JOIN ' . PMA_backquote($foreign_table) . ' ON ' . PMA_backquote($row['master_table']) . '.' . PMA_backquote($row['master_field']) @@ -870,27 +878,27 @@ if (isset($Field) && count($Field) > 0) { $incrit_d = '(\'' . implode('\', \'', $found) . '\')'; $incrit_s = '(\'' . implode('\', \'', $rest) . '\')'; - $_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'; - if(!empty($column)){ - $_rel_query .= ' AND master_field = \'' . $column . '\''; + $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; + if (!empty($column)) { + $rel_query .= ' AND master_field = \'' . $column . '\''; } + $rel_query .= ' ORDER BY master_table, foreign_table'; 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); + PMA_mysql_select_db($cfgRelation['db'], $dbh); + $relations = @PMA_mysql_query($rel_query, $dbh) or PMA_mysqlDie(mysql_error($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); + $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($_relations)) { + 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 @@ -939,16 +947,17 @@ 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 + // 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 - $_temp = array(); - while (list($k, $v) = each ($alltabs)) { - $_temp[$v] = 1; + $temp = array(); + while (list($k, $v) = each($alltabs)) { + $temp[$v] = 1; } unset($alltabs); $alltabs = array(); - while (list($k, $v) = each ($_temp)) { + while (list($k, $v) = each($temp)) { $alltabs[] = $k; } $qry_from = implode(', ', PMA_backquote($alltabs)); @@ -1027,10 +1036,10 @@ for ($x = 0; $x < $col; $x++) { // if they have chosen all fields using the * selector, // then sorting is not available // Robbat2 - Fix for Bug #570698 - if(substr($curField[$x],-2) != '.*') - { $qry_orderby .= $curField[$x] . ' ' . $curSort[$x]; + if (substr($curField[$x], -2) != '.*') { + $qry_orderby .= $curField[$x] . ' ' . $curSort[$x]; $last_orderby = 1; - } + } } } // end for if (!empty($qry_orderby)) { diff --git a/tbl_relation.php3 b/tbl_relation.php3 index b020ec680..0a0eba1c5 100644 --- a/tbl_relation.php3 +++ b/tbl_relation.php3 @@ -11,50 +11,55 @@ require('./tbl_properties_common.php3'); require('./tbl_properties_table_info.php3'); require('./libraries/relation.lib.php3'); + +/** + * Gets the relation settings + */ $cfgRelation = PMA_getRelationsParam(); + /** * Updates */ if ($cfgRelation['relwork']) { - $existrel = getForeigners($db,$table); + $existrel = getForeigners($db, $table); } if ($cfgRelation['displaywork']) { - $disp = getDisplayField($db,$table); + $disp = getDisplayField($db, $table); } if ($cfgRelation['relwork'] && isset($submit_rel) && $submit_rel == 'true') { while (list($key, $value) = each($destination)) { if ($value != 'nix') { - $for = explode('.', $value); + $for = explode('.', $value); if (!isset($existrel[$key])) { $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($key) . '\', ' . '\'' . PMA_sqlAddslashes($for[0]) . '\', ' . '\'' . PMA_sqlAddslashes($for[1]) . '\',' . '\'' . PMA_sqlAddslashes($for[2]) . '\')'; } else if ($existrel[$key] != $value) { $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) . '\''; + . ' 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])) { $upd_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['relation']) - . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\'' + . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\'' - . ' AND master_field = \'' . PMA_sqlAddslashes($key) . '\''; + . ' AND master_field = \'' . PMA_sqlAddslashes($key) . '\''; } // end if... else.... - if(isset($upd_query)){ - $upd_rs = PMA_query_as_cu($upd_query); + if (isset($upd_query)) { + $upd_rs = PMA_query_as_cu($upd_query); unset($upd_query); } } // end while @@ -64,74 +69,77 @@ if ($cfgRelation['displaywork'] && isset($submit_show) && $submit_show == 'true') { if ($disp) { - $upd_query = 'UPDATE ' . PMA_backquote($cfgRelation['table_info']) + $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 { - $upd_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['table_info']) - . '(db_name,table_name,display_field) ' + $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) .'\')'; + . '\'' . PMA_sqlAddslashes($display_field) . '\')'; } - if(isset($upd_query)){ - $upd_rs = PMA_query_as_cu($upd_query); + if (isset($upd_query)) { + $upd_rs = PMA_query_as_cu($upd_query); } } // end if -if($cfgRelation['commwork'] +if ($cfgRelation['commwork'] && isset($submit_comm) && $submit_comm == 'true') { - while (list($key,$value) = each($comment)) { - $test_qry = 'SELECT comment FROM ' . PMA_backquote($cfgRelation['column_comments']) + while (list($key, $value) = each($comment)) { + $test_qry = 'SELECT comment FROM ' . PMA_backquote($cfgRelation['column_comments']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'' . ' AND column_name = \'' . PMA_sqlAddslashes($key) . '\''; $test_rs = PMA_query_as_cu($test_qry); - if(mysql_num_rows($test_rs)>0) { - if(strlen($value)>0){ - $upd_query = 'UPDATE ' . PMA_backquote($cfgRelation['column_comments']) + if ($test_rs && mysql_num_rows($test_rs) > 0) { + if (strlen($value) > 0) { + $upd_query = 'UPDATE ' . PMA_backquote($cfgRelation['column_comments']) . ' SET comment = \'' . PMA_sqlAddslashes($value) . '\'' . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'' . ' AND column_name = \'' . PMA_sqlAddslashes($key) . '\''; } else { - $upd_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['column_comments']) + $upd_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['column_comments']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'' . ' AND column_name = \'' . PMA_sqlAddslashes($key) . '\''; } - } else if (strlen($value)>0){ - $upd_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['column_comments']) - . ' (db_name,table_name,column_name,comment) ' - . ' VALUES(\'' . PMA_sqlAddslashes($db) . '\',' + } else if (strlen($value) > 0) { + $upd_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['column_comments']) + . ' (db_name, table_name, column_name, comment) ' + . ' VALUES(' + . '\'' . PMA_sqlAddslashes($db) . '\',' . '\'' . PMA_sqlAddslashes($table) . '\',' . '\'' . PMA_sqlAddslashes($key) . '\',' . '\'' . PMA_sqlAddslashes($value) . '\')'; } - if(isset($upd_query)){ - $upd_rs = PMA_query_as_cu($upd_query); + if (isset($upd_query)){ + $upd_rs = PMA_query_as_cu($upd_query); } } // end while (transferred data) } // end if (commwork) -// now that we might have changed we have to see again +// Now that we might have changed we have to see again if ($cfgRelation['relwork']) { - $existrel = getForeigners($db,$table); + $existrel = getForeigners($db, $table); } if ($cfgRelation['displaywork']) { - $disp = getDisplayField($db,$table); + $disp = getDisplayField($db, $table); } if ($cfgRelation['commwork']) { - $comments = getComments($db,$table); + $comments = getComments($db, $table); } + + /** * Dialog */ if ($cfgRelation['relwork']) { - // to choose Relations we first need all tablenames in current db + // To choose relations we first need all tables names 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'] = '--'; @@ -159,15 +167,20 @@ if ($cfgRelation['relwork']) { } } // end while - // create Array of Relations (Mike Beck) - $rel_dest = getForeigners($db,$table); + // Create array of relations (Mike Beck) + $rel_dest = getForeigners($db, $table); } // end if -// now find out the columns of our $table +// Now find out the columns of our $table $col_query = 'SHOW COLUMNS FROM ' . PMA_backquote($table); $col_rs = PMA_mysql_query($col_query) or PMA_mysqlDie('', $col_query, '', $err_url_0); if ($col_rs && mysql_num_rows($col_rs) > 0) { + while ($row = PMA_mysql_fetch_array($col_rs)) { + $save_row[] = $row; + } + $saved_row_cnt = count($save_row); + ?>
@@ -178,15 +191,11 @@ if ($col_rs && mysql_num_rows($col_rs) > 0) { - + @@ -198,7 +207,7 @@ if ($col_rs && mysql_num_rows($col_rs) > 0) { reset($selectboxall); while (list($key, $value) = each($selectboxall)) { $myfield = $save_row[$i]['Field']; - if(isset($existrel[$myfield])){ + if (isset($existrel[$myfield])) { $test = $existrel[$myfield]['foreign_db'] . '.' . $existrel[$myfield]['foreign_table'] . '.' . $existrel[$myfield]['foreign_field']; @@ -207,7 +216,7 @@ if ($col_rs && mysql_num_rows($col_rs) > 0) { } echo ' ' . ''. "\n"; @@ -232,7 +241,7 @@ if ($col_rs && mysql_num_rows($col_rs) > 0) { @@ -261,42 +270,45 @@ if ($col_rs && mysql_num_rows($col_rs) > 0) { - - - - - - -
- - - + if ($cfgRelation['commwork']) { + + echo "\n"; + ?> + + + + + + + +
+ + + - - - - + + + + - - - -
- -
+ +
- -
- + ?> + + + + + + +