PHP3 fixes, optimization & coding standards

This commit is contained in:
Loïc Chapeaux
2002-09-27 08:37:52 +00:00
parent f1235dfd0f
commit 4a71ee52e1
3 changed files with 95 additions and 52 deletions

View File

@@ -5,6 +5,11 @@ phpMyAdmin - Changelog
$Id$ $Id$
$Source$ $Source$
2002-09-27 Lo<4C>c Chapeaux <lolo@phpheaven.net>
* db_details_qbe.php3: PHP3 fixes & coding standards.
* db_details_importdocsql.php3: optimization, xhtml fixes & coding
standards.
2002-09-26 Marc Delisle <lem9@users.sourceforge.net> 2002-09-26 Marc Delisle <lem9@users.sourceforge.net>
* config.inc.php3, libraries/config_import.lib.php3: let UploadDir * config.inc.php3, libraries/config_import.lib.php3: let UploadDir
empty because this means to not use the feature, thanks to Lo<4C>c empty because this means to not use the feature, thanks to Lo<4C>c

View File

@@ -12,29 +12,29 @@
* the headers * the headers
*/ */
require('./libraries/grab_globals.lib.php3'); require('./libraries/grab_globals.lib.php3');
require('./libraries/common.lib.php3'); require('./header.inc.php3');
require('./libraries/relation.lib.php3');
/** /**
* Gets the relation settings * Executes import if required
*/ */
$cfgRelation = PMA_getRelationsParam();
if (isset($do) && $do == 'import') { if (isset($do) && $do == 'import') {
// echo '<h1>Starting Import</h1>'; // echo '<h1>Starting Import</h1>';
if (substr($docpath, strlen($docpath) - 2, 1) != '/') { if (substr($docpath, strlen($docpath) - 2, 1) != '/') {
$docpath = $docpath . '/'; $docpath = $docpath . '/';
} }
if (is_dir($docpath)) { if (is_dir($docpath)) {
$handle = opendir($docpath); // Get relation settings
while ($file = @readdir ($handle)) { include('./libraries/relation.lib.php3');
$_filename = basename($file); $cfgRelation = PMA_getRelationsParam();
// echo '<p>Working on file ' . $filename . '</p>';
if (strpos($_filename,"_field_comment.txt")!=false) // Do the work
{ $handle = opendir($docpath);
$_tab = substr($_filename,0,strlen($_filename)-strlen("_field_comment.txt")); while ($file = @readdir($handle)) {
$filename = basename($file);
// echo '<p>Working on file ' . $filename . '</p>';
if (strpos(' ' . $filename, '_field_comment.txt')) {
$tab = substr($filename, 0, strlen($filename) - strlen('_field_comment.txt'));
//echo '<h1>Working on Table ' . $_tab . '</h1>'; //echo '<h1>Working on Table ' . $_tab . '</h1>';
$fd = fopen($docpath . $file, 'r'); $fd = fopen($docpath . $file, 'r');
if ($fd) { if ($fd) {
@@ -47,11 +47,11 @@ if (isset($do) && $do == 'import') {
. ' (db_name, table_name, column_name, comment) ' . ' (db_name, table_name, column_name, comment) '
. ' VALUES(' . ' VALUES('
. '\'' . PMA_sqlAddslashes($db) . '\',' . '\'' . PMA_sqlAddslashes($db) . '\','
. '\'' . PMA_sqlAddslashes(trim($_tab)) . '\',' . '\'' . PMA_sqlAddslashes(trim($tab)) . '\','
. '\'' . PMA_sqlAddslashes(trim($inf[0])) . '\',' . '\'' . PMA_sqlAddslashes(trim($inf[0])) . '\','
. '\'' . PMA_sqlAddslashes(trim($inf[1])) . '\')'; . '\'' . PMA_sqlAddslashes(trim($inf[1])) . '\')';
if (PMA_query_as_cu($qry)) { if (PMA_query_as_cu($qry)) {
echo '<p>Added comment for column ' . htmlspecialchars($_tab) . '.' . htmlspecialchars($inf[0]) . '</p>'; echo '<p>Added comment for column ' . htmlspecialchars($tab) . '.' . htmlspecialchars($inf[0]) . '</p>';
} else { } else {
echo '<p>Writing of comment not possible</p>'; echo '<p>Writing of comment not possible</p>';
} }
@@ -63,13 +63,13 @@ if (isset($do) && $do == 'import') {
. '(master_db, master_table, master_field, foreign_db, foreign_table, foreign_field)' . '(master_db, master_table, master_field, foreign_db, foreign_table, foreign_field)'
. ' VALUES(' . ' VALUES('
. '\'' . PMA_sqlAddslashes($db) . '\', ' . '\'' . PMA_sqlAddslashes($db) . '\', '
. '\'' . PMA_sqlAddslashes(trim($_tab)) . '\', ' . '\'' . PMA_sqlAddslashes(trim($tab)) . '\', '
. '\'' . PMA_sqlAddslashes(trim($inf[0])) . '\', ' . '\'' . PMA_sqlAddslashes(trim($inf[0])) . '\', '
. '\'' . PMA_sqlAddslashes($db) . '\', ' . '\'' . PMA_sqlAddslashes($db) . '\', '
. '\'' . PMA_sqlAddslashes(trim($for[0])) . '\',' . '\'' . PMA_sqlAddslashes(trim($for[0])) . '\','
. '\'' . PMA_sqlAddslashes(trim($for[1])) . '\')'; . '\'' . PMA_sqlAddslashes(trim($for[1])) . '\')';
if (PMA_query_as_cu($qry)) { if (PMA_query_as_cu($qry)) {
echo '<p>Added relation for column ' . htmlspecialchars($_tab) . '.' . htmlspecialchars($inf[0]) . ' to ' . htmlspecialchars($for) . '</p>'; echo '<p>Added relation for column ' . htmlspecialchars($tab) . '.' . htmlspecialchars($inf[0]) . ' to ' . htmlspecialchars($for) . '</p>';
} else { } else {
echo "<p>writing of Relation not possible</p>"; echo "<p>writing of Relation not possible</p>";
} }
@@ -88,6 +88,37 @@ if (isset($do) && $do == 'import') {
echo 'This was not a Directory' . "\n"; echo 'This was not a Directory' . "\n";
} }
} }
/**
* Try to get the "$DOCUMENT_ROOT" variable whatever is the register_globals
* value
*/
if (empty($DOCUMENT_ROOT)) {
if (!empty($_SERVER) && isset($_SERVER['DOCUMENT_ROOT'])) {
$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
}
else if (!empty($HTTP_SERVER_VARS) && isset($HTTP_SERVER_VARS['DOCUMENT_ROOT'])) {
$DOCUMENT_ROOT = $HTTP_SERVER_VARS['DOCUMENT_ROOT'];
}
else if (!empty($_ENV) && isset($_ENV['DOCUMENT_ROOT'])) {
$DOCUMENT_ROOT = $_ENV['DOCUMENT_ROOT'];
}
else if (!empty($HTTP_ENV_VARS) && isset($HTTP_ENV_VARS['DOCUMENT_ROOT'])) {
$DOCUMENT_ROOT = $HTTP_ENV_VARS['DOCUMENT_ROOT'];
}
else if (@getenv('DOCUMENT_ROOT')) {
$DOCUMENT_ROOT = getenv('DOCUMENT_ROOT');
}
else {
$DOCUMENT_ROOT = '';
}
} // end if
/**
* Displays the form
*/
?> ?>
<form method="post" action="db_details_importdocsql.php3"> <form method="post" action="db_details_importdocsql.php3">
@@ -96,12 +127,16 @@ if (isset($do) && $do == 'import') {
<input type="hidden" name="db" value="<?php echo $db; ?>" /> <input type="hidden" name="db" value="<?php echo $db; ?>" />
<input type="hidden" name="submit_show" value="true" /> <input type="hidden" name="submit_show" value="true" />
<input type="hidden" name="do" value="import" /> <input type="hidden" name="do" value="import" />
<table> <b>Please enter absolute path on webserver to docSQL Directory:</b>
<tr><th colspan="2">Used Database: <?php echo htmlspecialchars($db); ?></th></tr> <br /><br />
<tr> &nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="docpath" size="50" value="<?php echo htmlspecialchars($DOCUMENT_ROOT); ?>" />
<th>Please enter absolute path on webserver to docSQL Directory:</th> &nbsp;<input type="submit" value="Import files" />
<td><input type="text" name="docpath" size="50" value="<?php if(isset($DOCUMENT_ROOT)) {echo $DOCUMENT_ROOT;} ?>" /></td> </form>
</tr>
<tr><th colspan="2"><input type="submit" value="Import files" /></th></tr> <?php
</table> /**
</form> * Displays the footer
*/
echo "\n";
require('./footer.inc.php3');
?>

View File

@@ -759,32 +759,35 @@ if (isset($Field) && count($Field) > 0) {
} }
} // end while } // end while
// echo "check whereclauses\n"; // echo "check where clauses\n";
if ($cfgRelation['relwork'] && count($tab_all) > 0) { if ($cfgRelation['relwork'] && count($tab_all) > 0) {
// Now we need all tables that we have in the whereclause // Now we need all tables that we have in the where clause
for ($x = 0; $x < count($Criteria); $x++) { $crit_cnt = count($Criteria);
$_currtab = explode('.', urldecode($Field[$x])); for ($x = 0; $x < $crit_cnt; $x++) {
if (!empty($_currtab[0]) && !empty($_currtab[1])) { $curr_tab = explode('.', urldecode($Field[$x]));
$tab_raw = urldecode($_currtab[0]); if (!empty($curr_tab[0]) && !empty($curr_tab[1])) {
$tab_raw = urldecode($curr_tab[0]);
$tab = str_replace('`', '', $tab_raw); $tab = str_replace('`', '', $tab_raw);
$col_raw = urldecode($_currtab[1]); $col_raw = urldecode($curr_tab[1]);
$_col = str_replace('`', '', $col_raw); $col1 = str_replace('`', '', $col_raw);
$_col = $tab . '.' . $_col; $col1 = $tab . '.' . $col1;
// Now we know that our array has the same numbers as $Criteria // Now we know that our array has the same numbers as $Criteria
// we can check which of our columns has a whereclause // we can check which of our columns has a where clause
if (!empty($Criteria[$x])) { if (!empty($Criteria[$x])) {
if (substr($Criteria[$x],0,1) == '=' || eregi('is', $Criteria[$x])) { if (substr($Criteria[$x], 0, 1) == '=' || eregi('is', $Criteria[$x])) {
$col_where[$col] = $_col; $col_where[$col] = $col1;
$tab_wher[$tab] = $tab; $tab_wher[$tab] = $tab;
// echo 'new Whereclause: ' . $tab_wher[$tab] . "||\n"; // echo 'new where clause: ' . $tab_wher[$tab] . "||\n";
} }
} } // end if
} } // end if
} // end for } // end for
// Cleans temp vars w/o further use // Cleans temp vars w/o further use
unset($tab_raw, $col_raw); unset($tab_raw);
unset($col_raw);
unset($col1);
if (count($tab_wher) == 1) { if (count($tab_wher) == 1) {
// If there is exactly one column that has a decent where-clause // If there is exactly one column that has a decent where-clause
@@ -798,20 +801,20 @@ if (isset($Field) && count($Field) > 0) {
$ind_qry = 'SHOW INDEX FROM ' . PMA_backquote($tab); $ind_qry = 'SHOW INDEX FROM ' . PMA_backquote($tab);
$ind_rs = PMA_mysql_query($ind_qry); $ind_rs = PMA_mysql_query($ind_qry);
while ($ind = PMA_mysql_fetch_array($ind_rs)) { while ($ind = PMA_mysql_fetch_array($ind_rs)) {
$_col = $tab . '.' . $ind['Column_name']; $col1 = $tab . '.' . $ind['Column_name'];
if (isset($col_all[$_col])) { if (isset($col_all[$col1])) {
if ($ind['non_unique'] == 0) { if ($ind['non_unique'] == 0) {
if (isset($col_where[$_col])) { if (isset($col_where[$col1])) {
$col_unique[$_col] = 'Y'; $col_unique[$col1] = 'Y';
} else { } else {
$col_unique[$_col] = 'N'; $col_unique[$col1] = 'N';
} }
//echo 'neuen unique index gefunden: ' . $col . "\n"; //echo 'neuen unique index gefunden: ' . $col . "\n";
} else { } else {
if (isset($col_where[$_col])) { if (isset($col_where[$col1])) {
$col_index[$_col] = 'Y'; $col_index[$col1] = 'Y';
} else { } else {
$col_index[$_col] = 'N'; $col_index[$col1] = 'N';
} }
//echo 'neuen index gefunden: ' . $col . "\n"; //echo 'neuen index gefunden: ' . $col . "\n";
} }
@@ -914,7 +917,7 @@ if (isset($Field) && count($Field) > 0) {
$reta[$k] = $v; $reta[$k] = $v;
} }
} }
if (!isset($reta)){ if (!isset($reta)) {
$reta = array(); $reta = array();
} }
@@ -1029,7 +1032,7 @@ for ($x = 0; $x < $col; $x++) {
if ($criteria_cnt > 1) { if ($criteria_cnt > 1) {
$qry_where = '(' . $qry_where . ')'; $qry_where = '(' . $qry_where . ')';
} }
// OR rows ${"cur".$or}[$x] // OR rows ${'cur' . $or}[$x]
if (!isset($curAndOrRow)) { if (!isset($curAndOrRow)) {
$curAndOrRow = array(); $curAndOrRow = array();
} }