coding standards

This commit is contained in:
Loïc Chapeaux
2002-07-05 12:01:00 +00:00
parent 60985e8bdf
commit a967a579fc
2 changed files with 156 additions and 135 deletions

View File

@@ -10,8 +10,13 @@ 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
*/
$cfgRelation = PMA_getRelationsParam(); $cfgRelation = PMA_getRelationsParam();
/** /**
* A query has been submitted -> execute it, else display the headers * A query has been submitted -> execute it, else display the headers
*/ */
@@ -33,6 +38,8 @@ if (isset($submit_sql) && eregi('^SELECT',$encoded_sql_query)) {
if (isset($submit_sql) && !eregi('^SELECT', $encoded_sql_query)) { if (isset($submit_sql) && !eregi('^SELECT', $encoded_sql_query)) {
echo '<p class="warning">' . $strHaveToShow . '</p>'; echo '<p class="warning">' . $strHaveToShow . '</p>';
} }
/** /**
* Initialize some variables * Initialize some variables
*/ */
@@ -115,8 +122,8 @@ $k = 0;
// The tables list sent by a previously submitted form // The tables list sent by a previously submitted form
if (!empty($TableList)) { if (!empty($TableList)) {
for ($x = 0; $x < sizeof($TableList); $x++) { for ($x = 0; $x < count($TableList); $x++) {
$tbl_names[$TableList[$x]] = ' selected="selected"'; $tbl_names[urldecode($TableList[$x])] = ' selected="selected"';
} }
} // end if } // end if
@@ -261,7 +268,7 @@ for ($x = 0; $x < $col; $x++) {
<?php <?php
echo "\n"; echo "\n";
// if they have chosen all fields using the * selector, // If they have chosen all fields using the * selector,
// then sorting is not available // then sorting is not available
// Robbat2 - Fix for Bug #570698 // Robbat2 - Fix for Bug #570698
if (isset($Sort[$x]) && isset($Field[$x]) && (substr(urldecode($Field[$x]),-2) == '.*')) { if (isset($Sort[$x]) && isset($Field[$x]) && (substr(urldecode($Field[$x]),-2) == '.*')) {
@@ -632,7 +639,7 @@ for ($x = 0; $x < $col; $x++) {
<?php <?php
while (list($key, $val) = each($tbl_names)) { while (list($key, $val) = each($tbl_names)) {
echo ' '; echo ' ';
echo '<option value="' . $key . '"' . $val . '>' . htmlspecialchars($key) . '</option>' . "\n"; echo '<option value="' . urlencode($key) . '"' . $val . '>' . htmlspecialchars($key) . '</option>' . "\n";
} }
?> ?>
</select> </select>
@@ -778,19 +785,19 @@ 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' $rel_query = 'SELECT master_table AS wer, COUNT(foreign_table) AS hits'
. ' FROM ' . PMA_backquote($cfgRelation['relation']) . ' FROM ' . PMA_backquote($cfgRelation['relation'])
. ' WHERE master_db = \'' . $db . '\'' . ' WHERE master_db = \'' . $db . '\''
. ' AND foreign_db = \'' . $db . '\'' . ' AND foreign_db = \'' . $db . '\''
. ' AND master_table IN ' . $incrit . ' AND master_table IN ' . $incrit
. ' AND foreign_table IN ' . $incrit . ' AND foreign_table IN ' . $incrit;
. ' GROUP BY master_table ORDER BY hits DESC';
if (!empty($column)) { if (!empty($column)) {
$_rel_query .= ' AND master_field = \'' . $column . '\''; $rel_query .= ' AND master_field = \'' . $column . '\'';
} }
$rel_query .= ' GROUP BY master_table ORDER BY hits DESC'
$_relations = PMA_query_as_cu($_rel_query); $relations = PMA_query_as_cu($rel_query);
while ($row = PMA_mysql_fetch_array($_relations)) { while ($row = PMA_mysql_fetch_array($relations)) {
// 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)) {
@@ -818,27 +825,28 @@ 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($cfgRelation['relation']) . ' FROM ' . PMA_backquote($cfgRelation['relation'])
. ' WHERE master_db = \'' . $db . '\'' . ' WHERE master_db = \'' . $db . '\''
. ' AND foreign_db = \'' . $db . '\'' . ' AND foreign_db = \'' . $db . '\''
. ' AND master_table IN ' . $incrit . ' AND master_table IN ' . $incrit
. ' AND foreign_table IN ' . $incrit_s . ' AND foreign_table IN ' . $incrit_s;
. ' ORDER BY foreign_table, master_table';
if (!empty($column)) { if (!empty($column)) {
$_rel_query .= ' AND master_field = \'' . $column . '\''; $rel_query .= ' AND master_field = \'' . $column . '\'';
} }
$rel_query .= ' ORDER BY foreign_table, master_table';
if (isset($dbh)) { if (isset($dbh)) {
PMA_mysql_select_db($cfgRelation['db'], $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); $relations = @PMA_mysql_query($rel_query, $dbh) or PMA_mysqlDie(mysql_error($dbh), $rel_query, '', $err_url_0);
PMA_mysql_select_db($db, $dbh); PMA_mysql_select_db($db, $dbh);
} else { } else {
PMA_mysql_select_db($cfgRelation['db']); 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); PMA_mysql_select_db($db);
} }
while ($row = PMA_mysql_fetch_array($_relations)) { while ($row = PMA_mysql_fetch_array($relations)) {
$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 master table we don't // if we already found a link to the master table we don't
@@ -870,27 +878,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 *' $rel_query = 'SELECT *'
. ' FROM ' . PMA_backquote($cfgRelation['relation']) . ' FROM ' . PMA_backquote($cfgRelation['relation'])
. ' WHERE master_db = \'' . $db . '\'' . ' WHERE master_db = \'' . $db . '\''
. ' AND foreign_db = \'' . $db . '\'' . ' AND foreign_db = \'' . $db . '\''
. ' AND master_table IN ' . $incrit_s . ' AND master_table IN ' . $incrit_s
. ' AND foreign_table IN ' . $incrit_d . ' AND foreign_table IN ' . $incrit_d;
. ' ORDER BY master_table, foreign_table';
if (!empty($column)) { if (!empty($column)) {
$_rel_query .= ' AND master_field = \'' . $column . '\''; $rel_query .= ' AND master_field = \'' . $column . '\'';
} }
$rel_query .= ' ORDER BY master_table, foreign_table';
if (isset($dbh)) { if (isset($dbh)) {
PMA_mysql_select_db($cfgRelation['db'], $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); $relations = @PMA_mysql_query($rel_query, $dbh) or PMA_mysqlDie(mysql_error($dbh), $rel_query, '', $err_url_0);
PMA_mysql_select_db($db, $dbh); PMA_mysql_select_db($db, $dbh);
} else { } else {
PMA_mysql_select_db($cfgRelation['db']); 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); PMA_mysql_select_db($db);
} }
while ($row = PMA_mysql_fetch_array($_relations)) { 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
@@ -939,16 +947,17 @@ 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
$_temp = array(); $temp = array();
while (list($k, $v) = each($alltabs)) { while (list($k, $v) = each($alltabs)) {
$_temp[$v] = 1; $temp[$v] = 1;
} }
unset($alltabs); unset($alltabs);
$alltabs = array(); $alltabs = array();
while (list($k, $v) = each ($_temp)) { while (list($k, $v) = each($temp)) {
$alltabs[] = $k; $alltabs[] = $k;
} }
$qry_from = implode(', ', PMA_backquote($alltabs)); $qry_from = implode(', ', PMA_backquote($alltabs));
@@ -1027,8 +1036,8 @@ for ($x = 0; $x < $col; $x++) {
// if they have chosen all fields using the * selector, // if they have chosen all fields using the * selector,
// then sorting is not available // then sorting is not available
// Robbat2 - Fix for Bug #570698 // Robbat2 - Fix for Bug #570698
if(substr($curField[$x],-2) != '.*') if (substr($curField[$x], -2) != '.*') {
{ $qry_orderby .= $curField[$x] . ' ' . $curSort[$x]; $qry_orderby .= $curField[$x] . ' ' . $curSort[$x];
$last_orderby = 1; $last_orderby = 1;
} }
} }

View File

@@ -11,8 +11,13 @@ require('./tbl_properties_common.php3');
require('./tbl_properties_table_info.php3'); require('./tbl_properties_table_info.php3');
require('./libraries/relation.lib.php3'); require('./libraries/relation.lib.php3');
/**
* Gets the relation settings
*/
$cfgRelation = PMA_getRelationsParam(); $cfgRelation = PMA_getRelationsParam();
/** /**
* Updates * Updates
*/ */
@@ -89,7 +94,7 @@ if($cfgRelation['commwork']
. ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
. ' AND column_name = \'' . PMA_sqlAddslashes($key) . '\''; . ' AND column_name = \'' . PMA_sqlAddslashes($key) . '\'';
$test_rs = PMA_query_as_cu($test_qry); $test_rs = PMA_query_as_cu($test_qry);
if(mysql_num_rows($test_rs)>0) { if ($test_rs && mysql_num_rows($test_rs) > 0) {
if (strlen($value) > 0) { if (strlen($value) > 0) {
$upd_query = 'UPDATE ' . PMA_backquote($cfgRelation['column_comments']) $upd_query = 'UPDATE ' . PMA_backquote($cfgRelation['column_comments'])
. ' SET comment = \'' . PMA_sqlAddslashes($value) . '\'' . ' SET comment = \'' . PMA_sqlAddslashes($value) . '\''
@@ -105,7 +110,8 @@ if($cfgRelation['commwork']
} else if (strlen($value) > 0) { } else if (strlen($value) > 0) {
$upd_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['column_comments']) $upd_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['column_comments'])
. ' (db_name, table_name, column_name, comment) ' . ' (db_name, table_name, column_name, comment) '
. ' VALUES(\'' . PMA_sqlAddslashes($db) . '\',' . ' VALUES('
. '\'' . PMA_sqlAddslashes($db) . '\','
. '\'' . PMA_sqlAddslashes($table) . '\',' . '\'' . PMA_sqlAddslashes($table) . '\','
. '\'' . PMA_sqlAddslashes($key) . '\',' . '\'' . PMA_sqlAddslashes($key) . '\','
. '\'' . PMA_sqlAddslashes($value) . '\')'; . '\'' . PMA_sqlAddslashes($value) . '\')';
@@ -116,7 +122,7 @@ if($cfgRelation['commwork']
} // end while (transferred data) } // end while (transferred data)
} // end if (commwork) } // 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']) { if ($cfgRelation['relwork']) {
$existrel = getForeigners($db, $table); $existrel = getForeigners($db, $table);
} }
@@ -126,12 +132,14 @@ if ($cfgRelation['displaywork']) {
if ($cfgRelation['commwork']) { if ($cfgRelation['commwork']) {
$comments = getComments($db, $table); $comments = getComments($db, $table);
} }
/** /**
* Dialog * Dialog
*/ */
if ($cfgRelation['relwork']) { 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_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'] = '--';
@@ -159,15 +167,20 @@ if ($cfgRelation['relwork']) {
} }
} // end while } // end while
// create Array of Relations (Mike Beck) // Create array of relations (Mike Beck)
$rel_dest = getForeigners($db, $table); $rel_dest = getForeigners($db, $table);
} // end if } // 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_query = 'SHOW COLUMNS FROM ' . PMA_backquote($table);
$col_rs = PMA_mysql_query($col_query) or PMA_mysqlDie('', $col_query, '', $err_url_0); $col_rs = PMA_mysql_query($col_query) or PMA_mysqlDie('', $col_query, '', $err_url_0);
if ($col_rs && mysql_num_rows($col_rs) > 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);
?> ?>
<form method="post" action="tbl_relation.php3"> <form method="post" action="tbl_relation.php3">
<input type="hidden" name="lang" value="<?php echo $lang; ?>" /> <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
@@ -178,14 +191,10 @@ if ($col_rs && mysql_num_rows($col_rs) > 0) {
<table> <table>
<tr> <tr>
<th colspan=2 align="center"><b><?php echo $strLinksTo; ?></b></th> <th colspan="2" align="center"><b><?php echo $strLinksTo; ?></b></th>
</tr> </tr>
<?php <?php
for ($i = 0; $i < $saved_row_cnt; $i++) {
while ($row = PMA_mysql_fetch_array($col_rs)) {
$save_row[] = $row;
}
for ($i=0;$i<count($save_row);$i++){
echo "\n"; echo "\n";
?> ?>
<tr> <tr>
@@ -261,7 +270,10 @@ if ($col_rs && mysql_num_rows($col_rs) > 0) {
</form> </form>
<?php <?php
} // end if (displayworks) } // end if (displayworks)
if ($cfgRelation['commwork']) { if ($cfgRelation['commwork']) {
echo "\n";
?> ?>
<form method="post" action="tbl_relation.php3"> <form method="post" action="tbl_relation.php3">
<input type="hidden" name="lang" value="<?php echo $lang; ?>" /> <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
@@ -272,10 +284,10 @@ if ($col_rs && mysql_num_rows($col_rs) > 0) {
<table> <table>
<tr> <tr>
<th colspan=2 align="center"><b><?php echo $strComments; ?></b></th> <th colspan="2" align="center"><b><?php echo $strComments; ?></b></th>
</tr> </tr>
<?php <?php
for ($i=0;$i<count($save_row);$i++){ for ($i = 0; $i < $saved_row_cnt; $i++) {
$field = $save_row[$i]['Field']; $field = $save_row[$i]['Field'];
echo "\n"; echo "\n";
?> ?>