From 91833f2debe321072b24a89716e13885f67d6c8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Chapeaux?= Date: Thu, 11 Jul 2002 21:27:16 +0000 Subject: [PATCH] Coding standards --- ChangeLog | 7 + libraries/charset_conversion.lib.php3 | 19 +- libraries/common.lib.php3 | 12 +- libraries/display_tbl.lib.php3 | 2 +- libraries/relation.lib.php3 | 252 +++++++++++++++----------- pdf_schema.php3 | 47 +++-- tbl_printview.php3 | 4 +- tbl_properties_links.php3 | 1 - tbl_properties_operations.php3 | 2 +- tbl_relation.php3 | 14 +- 10 files changed, 202 insertions(+), 158 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5bb924f91..7183ad73b 100755 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,13 @@ phpMyAdmin - Changelog $Id$ $Source$ +2002-07-11 Loïc Chapeaux + * pdf_schema.php3; tbl_printview.php3; tbl_properties_links.php3; + tbl_properties_operations.php3; tbl_relation.php3; + libraries/charset_conversion.lib.php3; libraries/display_tbl.lib.php3; + libraries/relation.lib.php3: coding standards. + * libraries/common.lib.php3: coding standards and a little display bug. + 2002-07-11 Alexander M. Turek * libraries/common.lib.php3: PHP3 compatibility. * read_dump.php3: Fixed bug #579968, thanks to Alvar Soome (finsoft). diff --git a/libraries/charset_conversion.lib.php3 b/libraries/charset_conversion.lib.php3 index f57f2bd02..b39a54723 100644 --- a/libraries/charset_conversion.lib.php3 +++ b/libraries/charset_conversion.lib.php3 @@ -13,21 +13,21 @@ if (!defined('PMA_CHARSET_CONVERSION_LIB_INCLUDED')){ /** * Loads the recode or iconv extensions if any of it is not loaded yet */ - if ( isset($cfg['AllowAnywhereRecoding']) - && $cfg['AllowAnywhereRecoding'] - && $allow_recoding - && ((PMA_PHP_INT_VERSION >= 40000 && !@ini_get('safe_mode') && @ini_get('enable_dl')) - || (PMA_PHP_INT_VERSION > 30009 && !@get_cfg_var('safe_mode'))) - && @function_exists('dl')) { - if (!(@extension_loaded('recode')||@extension_loaded('iconv'))) { + if (isset($cfg['AllowAnywhereRecoding']) + && $cfg['AllowAnywhereRecoding'] + && $allow_recoding + && ((PMA_PHP_INT_VERSION >= 40000 && !@ini_get('safe_mode') && @ini_get('enable_dl')) + || (PMA_PHP_INT_VERSION > 30009 && !@get_cfg_var('safe_mode'))) + && @function_exists('dl')) { + if (!(@extension_loaded('recode') || @extension_loaded('iconv'))) { if (PMA_IS_WINDOWS) { $suffix = '.dll'; } else { $suffix = '.so'; } - @dl('recode'.$suffix); + @dl('recode' . $suffix); if (!@extension_loaded('recode')) { - @dl('iconv'.$suffix); + @dl('iconv' . $suffix); if (!@extension_loaded('iconv')) { echo $strCantLoadRecodeIconv; exit(); @@ -35,7 +35,6 @@ if (!defined('PMA_CHARSET_CONVERSION_LIB_INCLUDED')){ } } } // end load mysql extension - // if allowed recoding, we should try to load extensions for it... /** diff --git a/libraries/common.lib.php3 b/libraries/common.lib.php3 index f6ebab1ac..bdc493c0b 100644 --- a/libraries/common.lib.php3 +++ b/libraries/common.lib.php3 @@ -522,7 +522,7 @@ h1 {font-family: sans-serif; font-size: large; font-weight: bold} // work anyway, but display a big warning on the main.php3 // page. if (empty($cfg['PmaAbsoluteUri'])) { - $port_in_HTTP_HOST = strpos($HTTP_SERVER_VARS['HTTP_HOST'], ':') > 0; + $port_in_HTTP_HOST = (strpos($HTTP_SERVER_VARS['HTTP_HOST'], ':') > 0); $cfg['PmaAbsoluteUri'] = (!empty($HTTP_SERVER_VARS['HTTPS']) ? 'https' : 'http') . '://' . $HTTP_SERVER_VARS['HTTP_HOST'] . ((!empty($HTTP_SERVER_VARS['SERVER_PORT']) && !$port_in_HTTP_HOST) ? ':' . $HTTP_SERVER_VARS['SERVER_PORT'] : '') @@ -1400,8 +1400,14 @@ if (typeof(document.getElementById) != 'undefined' global $PHP_SELF; global $db_details_links_count_tabs; - $bgcolor = (basename($PHP_SELF) == $link) ? 'silver' : '#DFDFDF'; - $db_details_links_count_tabs++; + if (basename($PHP_SELF) == $link + && ($text != $GLOBALS['strEmpty'] && $text != $GLOBALS['strDrop'])) { + $bgcolor = 'silver'; + } else { + $bgcolor = '#DFDFDF'; + } + + $db_details_links_count_tabs++; if (!empty($attr)) { $attr = ' ' . $attr; } diff --git a/libraries/display_tbl.lib.php3 b/libraries/display_tbl.lib.php3 index 2c982b257..3ca471e2b 100644 --- a/libraries/display_tbl.lib.php3 +++ b/libraries/display_tbl.lib.php3 @@ -1411,7 +1411,7 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')){ while ($rel = PMA_mysql_fetch_row($result)) { // check for display field? if ($cfgRelation['displaywork']) { - $display_field = getDisplayField($db, $rel[2]); + $display_field = PMA_getDisplayField($db, $rel[2]); } // end if $map[$rel[0]] = array($rel[2], $rel[3], $display_field); } // end while diff --git a/libraries/relation.lib.php3 b/libraries/relation.lib.php3 index 079315dfd..10d9e4123 100644 --- a/libraries/relation.lib.php3 +++ b/libraries/relation.lib.php3 @@ -1,45 +1,56 @@ * @access public + * + * @author Mike Beck */ - function PMA_query_as_cu($sql,$showerror=TRUE) { + function PMA_query_as_cu($sql, $show_error = TRUE) { global $err_url_0, $db, $dbh, $cfgRelation; if (isset($dbh)) { - PMA_mysql_select_db($cfgRelation['db'],$dbh); + PMA_mysql_select_db($cfgRelation['db'], $dbh); $result = @PMA_mysql_query($sql, $dbh); - if(!$result && $showerror==TRUE){ + if (!$result && $show_error == TRUE) { PMA_mysqlDie(mysql_error($dbh), $sql, '', $err_url_0); } - PMA_mysql_select_db($db,$dbh); + PMA_mysql_select_db($db, $dbh); } else { PMA_mysql_select_db($cfgRelation['db']); $result = @PMA_mysql_query($sql); - if($result && $showerror==TRUE){ + if ($result && $show_error == TRUE) { PMA_mysqlDie('', $sql, '', $err_url_0); } PMA_mysql_select_db($db); - } - if($result){ + } // end if... else... + + if ($result) { return $result; } else { return FALSE; } - } + } // end of the "PMA_query_as_cu()" function /** @@ -49,168 +60,191 @@ if (!defined('PMA_RELATION_LIB_INCLUDED')){ * * @return array the relation parameters for the current user * - * @global array the list of settings for the current server + * @global array the list of settings for servers * @global integer the id of the current server - * @author Mike Beck + * @global string the URL of the page to show in case of error + * @global string the name of the current db + * @global string the name of the current table * * @access public + * + * @author Mike Beck */ function PMA_getRelationsParam() { - global $server, $err_url_0, $db, $table,$cfg; - $cfgRelation = ''; + global $cfg, $server, $err_url_0, $db, $table; + $cfgRelation = ''; $cfgRelation['relwork'] = FALSE; $cfgRelation['displaywork'] = FALSE; $cfgRelation['pdfwork'] = FALSE; $cfgRelation['commwork'] = FALSE; // No server selected -> no bookmark table - if ($server == 0 - || !isset($GLOBALS['cfg']['Server']['pmadb']) - || empty($GLOBALS['cfg']['Server']['pmadb'])) { + if ($server == 0 + || empty($cfg['Server']) + || empty($cfg['Server']['pmadb'])) { return ''; } - // check if pmadb exists - $tab_query = 'SHOW DATABASES like \'' . $GLOBALS['cfg']['Server']['pmadb'] . '\''; - $tab_rs = PMA_query_as_cu($tab_query); + $cfgRelation['user'] = $cfg['Server']['user']; + $cfgRelation['db'] = $cfg['Server']['pmadb']; - while ($curr_db = @PMA_mysql_fetch_array($tab_rs)) { - if($curr_db[0] == $cfg['Server']['pmadb']) { - $cfgRelation['db'] = $GLOBALS['cfg']['Server']['pmadb']; - } - } - if(!isset($cfgRelation['db'])){ - $GLOBALS['cfg']['Server']['pmadb'] = FALSE; - return; - } - $cfgRelation['user'] = $GLOBALS['cfg']['Server']['user']; - $cfgRelation['db'] = $GLOBALS['cfg']['Server']['pmadb']; - - // now i just check if all tables that i need are present - // so i can for example enable relations but not pdf... - // i was thinking of checking if they have all required columns - // but i fear it might be too slow + // Now I just check if all tables that i need are present so I can for + // example enable relations but not pdf... + // I was thinking of checking if they have all required columns but I + // fear it might be too slow // PMA_mysql_select_db($cfgRelation['db']); - $tab_query = 'SHOW TABLES FROM ' . PMA_backquote($cfgRelation['db']); - $tab_rs = PMA_query_as_cu($tab_query); + $tab_query = 'SHOW TABLES FROM ' . PMA_backquote($cfgRelation['db']); + $tab_rs = PMA_query_as_cu($tab_query, FALSE); - //while ($curr_table = @PMA_mysql_fetch_array($tab_rs)) { while ($curr_table = @PMA_mysql_fetch_array($tab_rs)) { - if($curr_table[0] == $cfg['Server']['bookmarktable']) { + if ($curr_table[0] == $cfg['Server']['bookmarktable']) { continue; - } else if ($curr_table[0] == $GLOBALS['cfg']['Server']['relation']) { + } else if ($curr_table[0] == $cfg['Server']['relation']) { $cfgRelation['relation'] = $curr_table[0]; - } else if ($curr_table[0] == $GLOBALS['cfg']['Server']['table_info']) { + } else if ($curr_table[0] == $cfg['Server']['table_info']) { $cfgRelation['table_info'] = $curr_table[0]; - } else if ($curr_table[0] == $GLOBALS['cfg']['Server']['table_coords']) { + } else if ($curr_table[0] == $cfg['Server']['table_coords']) { $cfgRelation['table_coords'] = $curr_table[0]; - } else if ($curr_table[0] == $GLOBALS['cfg']['Server']['column_comments']) { + } else if ($curr_table[0] == $cfg['Server']['column_comments']) { $cfgRelation['column_comments'] = $curr_table[0]; - } else if ($curr_table[0] == $GLOBALS['cfg']['Server']['pdf_pages']) { + } else if ($curr_table[0] == $cfg['Server']['pdf_pages']) { $cfgRelation['pdf_pages'] = $curr_table[0]; } - } - if(isset($cfgRelation['relation'])) { - $cfgRelation['relwork'] = TRUE; - if(isset($cfgRelation['table_info'])) { + } // end while + if (isset($cfgRelation['relation'])) { + $cfgRelation['relwork'] = TRUE; + if (isset($cfgRelation['table_info'])) { $cfgRelation['displaywork'] = TRUE; } - if(isset($cfgRelation['table_coords']) && isset($cfgRelation['pdf_pages'])) { - $cfgRelation['pdfwork'] = TRUE; + if (isset($cfgRelation['table_coords']) && isset($cfgRelation['pdf_pages'])) { + $cfgRelation['pdfwork'] = TRUE; } - if(isset($cfgRelation['column_comments'])) { - $cfgRelation['commwork'] = TRUE; + if (isset($cfgRelation['column_comments'])) { + $cfgRelation['commwork'] = TRUE; } + } // end if + + if ($tab_rs) { + mysql_free_result($tab_rs); + } else { + $cfg['Server']['pmadb'] = FALSE; } - mysql_free_result($tab_rs); + return $cfgRelation; } // end of the 'PMA_getRelationsParam()' function /** - * Get all Relations to foreign tables for a given table - * or optionally a given column in a table + * Gets all Relations to foreign tables for a given table or + * optionally a given column in a table + * + * @param string the name of the db to check for + * @param string the name of the table to check for + * @param string the name of the column to check for * * @return array db,table,column * - * @global array the list of Relationsettings + * @global array the list of relations settings + * @global string the URL of the page to show in case of error * * @access public + * * @author Mike Beck */ - function getForeigners($db,$table,$column=FALSE) { + function PMA_getForeigners($db, $table, $column = '') { global $cfgRelation, $err_url_0; - $_rel_query = 'SELECT master_field, foreign_db,foreign_table,foreign_field' - . ' FROM ' . PMA_backquote($cfgRelation['relation']) - . ' WHERE master_db = \'' . $db . '\' ' - . ' AND master_table = \'' . $table . '\' '; - if(!empty($column)){ - $_rel_query .= ' AND master_field = \'' . $column . '\''; + $rel_query = 'SELECT master_field, foreign_db, foreign_table, foreign_field' + . ' FROM ' . PMA_backquote($cfgRelation['relation']) + . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\' ' + . ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\' '; + if (!empty($column)) { + $rel_query .= ' AND master_field = \'' . PMA_sqlAddslashes($column) . '\''; } - $_relations = PMA_query_as_cu($_rel_query); - $i=0; - while ($relrow = @PMA_mysql_fetch_array($_relations)) { - $field = $relrow['master_field']; - $foreign[$field]['foreign_db'] = $relrow['foreign_db']; - $foreign[$field]['foreign_table'] = $relrow['foreign_table']; - $foreign[$field]['foreign_field'] = $relrow['foreign_field']; + $relations = PMA_query_as_cu($rel_query); + $i = 0; + while ($relrow = @PMA_mysql_fetch_array($relations)) { + $field = $relrow['master_field']; + $foreign[$field]['foreign_db'] = $relrow['foreign_db']; + $foreign[$field]['foreign_table'] = $relrow['foreign_table']; + $foreign[$field]['foreign_field'] = $relrow['foreign_field']; $i++; } // end while - if( isset($foreign) && is_array($foreign) ) { + + if (isset($foreign) && is_array($foreign)) { return $foreign; } else { return FALSE; } - } // End function getForeigners + } // end of the 'PMA_getForeigners()' function + /** - * Get the displayfield of a table - * @return string fieldname - * @global array the list of Relationsettings - * @access public - * @author Mike Beck + * Gets the display field of a table + * + * @param string the name of the db to check for + * @param string the name of the table to check for + * + * @return string field name + * + * @global array the list of relations settings + * + * @access public + * + * @author Mike Beck */ - function getDisplayField($db,$table) { + function PMA_getDisplayField($db, $table) { global $cfgRelation; - $_disp_query = 'SELECT display_field FROM ' . PMA_backquote($cfgRelation['table_info']) + + $disp_query = 'SELECT display_field FROM ' . PMA_backquote($cfgRelation['table_info']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''; - $_disp_res = PMA_query_as_cu($_disp_query); - $row = ($_disp_res ? PMA_mysql_fetch_array($_disp_res) : ''); + $disp_res = PMA_query_as_cu($disp_query); + $row = ($disp_res ? PMA_mysql_fetch_array($disp_res) : ''); if (isset($row['display_field'])) { return $row['display_field']; } else { return FALSE; } - } - /** - * Get the comments for all rows of a table - * @return arry [field_name] = comment - * @global array the list of Relationsettings - * @access public - * @author Mike Beck - */ - function getComments($db,$table) { - global $cfgRelation; - $_com_qry = 'SELECT column_name,comment FROM ' . PMA_backquote($cfgRelation['column_comments']) - . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' - . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''; - $_com_rs = PMA_query_as_cu($_com_qry); - while ($row = @PMA_mysql_fetch_array($_com_rs)) { - $col = $row['column_name']; - $comment[$col] = $row['comment']; - } // end while + } // end of the 'PMA_getDisplayField()' function - if( isset($comment) && is_array($comment) ) { + + /** + * Gets the comments for all rows of a table + * + * @param string the name of the db to check for + * @param string the name of the table to check for + * + * @return array [field_name] = comment + * + * @global array the list of relations settings + * + * @access public + * + * @author Mike Beck + */ + function PMA_getComments($db, $table) { + global $cfgRelation; + + $com_qry = 'SELECT column_name, comment FROM ' . PMA_backquote($cfgRelation['column_comments']) + . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' + . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''; + $com_rs = PMA_query_as_cu($com_qry); + + while ($row = @PMA_mysql_fetch_array($com_rs)) { + $col = $row['column_name']; + $comment[$col] = $row['comment']; + } // end while + + if (isset($comment) && is_array($comment)) { return $comment; } else { return FALSE; } - } // end function getComments -} // $__PMA_RELATION_LIB__INCLUDED + } // end of the 'PMA_getComments()' function +} // $__PMA_RELATION_LIB__ ?> diff --git a/pdf_schema.php3 b/pdf_schema.php3 index efe7d7071..ad066fbe5 100644 --- a/pdf_schema.php3 +++ b/pdf_schema.php3 @@ -482,7 +482,7 @@ class PMA_RT_Table $this->y = (double) $this->y; // displayfield - $this->displayfield = getDisplayField($db, $table_name); + $this->displayfield = PMA_getDisplayField($db, $table_name); // index $sql = 'SHOW index FROM ' . PMA_backquote($table_name); @@ -852,8 +852,8 @@ class PMA_RT . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND pdf_page_number = ' . $which_rel; $tab_rs = PMA_query_as_cu($tab_sql); - if(!mysql_num_rows($tab_rs)>0){ - die('no tables'); + if (!mysql_num_rows($tab_rs) > 0) { + die('No tables'); } while ($curr_table = @PMA_mysql_fetch_array($tab_rs)) { $alltables[] = PMA_sqlAddslashes($curr_table['table_name']); @@ -867,25 +867,24 @@ class PMA_RT . ' AND foreign_table IN (' . $intable . ')'; $result = PMA_query_as_cu($sql); - /* - mikebeck: maybe we can show tables without relations if i comment that out - if (!$result || !mysql_num_rows($result)) { - $pdf->PMA_PDF_die($GLOBALS['strPdfInvalidPageNum']); - } - */ - if(isset($result) && $result && mysql_num_rows($result)>0){ - while ($row = PMA_mysql_fetch_array($result)) { - $this->PMA_RT_addRelation($row['master_table'] , $row['master_field'], $row['foreign_table'], $row['foreign_field']); - } - $norelations=FALSE; - }else{ - reset ($alltables); - while (list(, $table) = each ($alltables)) { - $this->tables[$table] = new PMA_RT_Table($table, $this->ff); - $this->PMA_RT_setMinMax($this->tables[$table]); - } - $norelations=TRUE; - } + // mikebeck: maybe we can show tables without relations if i comment + // that out +// if (!$result || !mysql_num_rows($result)) { +// $pdf->PMA_PDF_die($GLOBALS['strPdfInvalidPageNum']); +// } + if (isset($result) && $result && mysql_num_rows($result) > 0) { + while ($row = PMA_mysql_fetch_array($result)) { + $this->PMA_RT_addRelation($row['master_table'] , $row['master_field'], $row['foreign_table'], $row['foreign_field']); + } + $norelations = FALSE; + } else { + reset ($alltables); + while (list(, $table) = each ($alltables)) { + $this->tables[$table] = new PMA_RT_Table($table, $this->ff); + $this->PMA_RT_setMinMax($this->tables[$table]); + } + $norelations = TRUE; + } // end if... else... // Defines the scale factor if ($scale == 'auto') { @@ -904,8 +903,8 @@ class PMA_RT $this->PMA_RT_strokeGrid(); } $pdf->PMA_PDF_setFontSizeScale(14); - if($norelations==FALSE){ - $this->PMA_RT_drawRelations($change_color); + if ($norelations == FALSE) { + $this->PMA_RT_drawRelations($change_color); } $this->PMA_RT_drawTables($show_info); diff --git a/tbl_printview.php3 b/tbl_printview.php3 index cbf1926c0..e2d3688c4 100755 --- a/tbl_printview.php3 +++ b/tbl_printview.php3 @@ -17,7 +17,7 @@ if (!isset($selected_tbl)) { require('./libraries/relation.lib.php3'); $cfgRelation = PMA_getRelationsParam(); if ($cfgRelation['commwork']) { - $comments = getComments($db, $table); + $comments = PMA_getComments($db, $table); } @@ -158,7 +158,7 @@ while (list($key, $table) = each($the_tables)) { if ($cfgRelation['relation']) { // Find which tables are related with the current one and write it in // an array - $res_rel = getForeigners($db, $table); + $res_rel = PMA_getForeigners($db, $table); if (count($res_rel) > 0) { $have_rel = TRUE; diff --git a/tbl_properties_links.php3 b/tbl_properties_links.php3 index 2bdb29317..bd1237265 100755 --- a/tbl_properties_links.php3 +++ b/tbl_properties_links.php3 @@ -37,7 +37,6 @@ if ($table_info_num_rows > 0) { $att6 = ''; } -$lnk7 = "sql.php3"; $arg7 = ereg_replace('tbl_properties.php3$', 'db_details.php3', $url_query) . '&back=tbl_properties' . $sub_part . '.php3&reload=1&sql_query= ' . urlencode('DROP TABLE ' . PMA_backquote($table) ) . '&zero_rows=' . urlencode(sprintf($strTableHasBeenDropped, htmlspecialchars($table))); $att7 = 'class="drop" onclick="return confirmLink(this, \'DROP TABLE ' . PMA_jsFormat($table) . '\')"'; diff --git a/tbl_properties_operations.php3 b/tbl_properties_operations.php3 index 1e32fc491..99cc89467 100755 --- a/tbl_properties_operations.php3 +++ b/tbl_properties_operations.php3 @@ -296,7 +296,7 @@ if ($cfgRelation['relwork']) { // and $db is not the last of the list, because PMA_availableDatabases() // has made a PMA_mysql_select_db() on the last one PMA_mysql_select_db($db); - $foreign = getForeigners($db, $table); + $foreign = PMA_getForeigners($db, $table); if ($foreign) { ?> diff --git a/tbl_relation.php3 b/tbl_relation.php3 index 0a0eba1c5..cee342769 100644 --- a/tbl_relation.php3 +++ b/tbl_relation.php3 @@ -22,10 +22,10 @@ $cfgRelation = PMA_getRelationsParam(); * Updates */ if ($cfgRelation['relwork']) { - $existrel = getForeigners($db, $table); + $existrel = PMA_getForeigners($db, $table); } if ($cfgRelation['displaywork']) { - $disp = getDisplayField($db, $table); + $disp = PMA_getDisplayField($db, $table); } if ($cfgRelation['relwork'] && isset($submit_rel) && $submit_rel == 'true') { @@ -124,13 +124,13 @@ if ($cfgRelation['commwork'] // Now that we might have changed we have to see again if ($cfgRelation['relwork']) { - $existrel = getForeigners($db, $table); + $existrel = PMA_getForeigners($db, $table); } if ($cfgRelation['displaywork']) { - $disp = getDisplayField($db, $table); + $disp = PMA_getDisplayField($db, $table); } if ($cfgRelation['commwork']) { - $comments = getComments($db, $table); + $comments = PMA_getComments($db, $table); } @@ -168,7 +168,7 @@ if ($cfgRelation['relwork']) { } // end while // Create array of relations (Mike Beck) - $rel_dest = getForeigners($db, $table); + $rel_dest = PMA_getForeigners($db, $table); } // end if // Now find out the columns of our $table @@ -241,7 +241,7 @@ if ($col_rs && mysql_num_rows($col_rs) > 0) {