diff --git a/lib.inc.php3 b/lib.inc.php3 index dad623acd..634b63b81 100755 --- a/lib.inc.php3 +++ b/lib.inc.php3 @@ -56,9 +56,9 @@ if (!defined('__LIB_INC__')){ */ function auth() { - header('status: 401 Unauthorized'); + header('WWW-Authenticate: Basic realm="phpMyAdmin ' . trim($GLOBALS['strRunning']) . ' ' . $GLOBALS['cfgServer']['host'] . '"'); header('HTTP/1.0 401 Unauthorized'); - header('WWW-authenticate: basic realm="phpMyAdmin on ' . $GLOBALS['cfgServer']['host'] . '"'); + header('status: 401 Unauthorized'); ?> @@ -523,7 +523,7 @@ if (!defined('__LIB_INC__')){ function js_format($a_string = '', $add_backquotes = TRUE) { $a_string = str_replace('"', '"', $a_string); - $a_string = addslashes($a_string); + $a_string = str_replace('#', '\\#', addslashes($a_string)); return (($add_backquotes) ? backquote($a_string) : $a_string); } // end of the 'sql_addslashes()' function @@ -798,9 +798,10 @@ window.parent.frames['nav'].location.replace(''); } ?> - + + 0) { @@ -895,13 +896,15 @@ window.parent.frames['nav'].location.replace(''); + + - - -
   
@@ -912,38 +915,16 @@ window.parent.frames['nav'].location.replace(''); - - + +
-     - -
- - - - - - - - - - -
-
- '); * @global string the current sql query * @global string the url to go back in case of errors * @global integer the total number of rows returned by the sql query + * @global array the list of fields properties + * @global integer the total number of fields returned by the sql query */ function display_table($dt_result, $is_simple = FALSE) { global $lang, $server, $db, $table; global $sql_query, $goto, $pos; global $SelectNumRows, $dontlimitchars; + global $fields_meta, $fields_cnt; - // Gets the number of rows per page + // 1. ----- Prepares the work ----- + + // 1.1 Gets the number of rows per page if (isset($GLOBALS['sessionMaxRows'])) { $GLOBALS['cfgMaxRows'] = $GLOBALS['sessionMaxRows']; } else { $GLOBALS['sessionMaxRows'] = $GLOBALS['cfgMaxRows']; } - // Counts the number of rows in the table if required + // 1.2 Counts the number of rows in the table if required if (isset($SelectNumRows) && $SelectNumRows != '') { $total = $SelectNumRows; } else if (!$is_simple && !empty($table) && !empty($db)) { $local_query = 'SELECT COUNT(*) as total FROM ' . backquote($db) . '.' . backquote($table); $result = mysql_query($local_query) or mysql_die('', $local_query); - $row = mysql_fetch_array($result); - $total = $row['total']; + $total = mysql_result($result, 0, 'total'); } // end if - // Defines offsets for the next and previous pages + // 1.3 Defines offsets for the next and previous pages if (!$is_simple) { if (!isset($pos)) { $pos = 0; @@ -1002,7 +987,9 @@ window.parent.frames['nav'].location.replace(''); } } // end if - // Displays a messages with position informations + // 2. ----- Displays the top of the page ----- + + // 2.1 Displays a messages with position informations if (isset($total) && $total > 1 && isset($pos_next)) { if (isset($SelectNumRows) && $SelectNumRows != $total) { $selectstring = ', ' . $SelectNumRows . ' ' . $GLOBALS['strSelectNumRows']; @@ -1015,12 +1002,10 @@ window.parent.frames['nav'].location.replace(''); show_message($GLOBALS['strSQLQuery']); } - // Displays the navigation bars - $field = mysql_fetch_field($dt_result); + // 2.2 Displays the navigation bars if (!isset($table) || strlen(trim($table)) == 0) { - $table = $field->table; + $table = $fields_meta[0]->table; } - mysql_field_seek($dt_result, 0); if (!$is_simple && (!isset($SelectNumRows) || $SelectNumRows > 1)) { show_table_navigation($pos_next, $pos_prev, $dt_result); @@ -1028,24 +1013,28 @@ window.parent.frames['nav'].location.replace(''); echo "\n" . '

' . "\n"; } - // Displays the results + // 3. ----- Displays the results table head ----- + $is_show_processlist = eregi("^[ \n\r]*show[ \n\r]*processlist[ \n\r]*$", $sql_query); ?> + '; } echo "\n"; - while ($field = mysql_fetch_field($dt_result)) { + // 3.2 Displays the fields' name + for ($i = 0; $i < $fields_cnt; $i++) { // Result is more than one row long if (@mysql_num_rows($dt_result) > 1 && !$is_simple) { // Defines the url used to append/modify a sorting order - // 1. Checks if an hard coded 'order by' clause exists + // 3.2.1 Checks if an hard coded 'order by' clause exists if (eregi('(.*)( ORDER BY (.*))', $sql_query, $regs1)) { if (eregi('((.*)( ASC| DESC)( |$))(.*)', $regs1[2], $regs2)) { $unsorted_sql_query = trim($regs1[1] . ' ' . $regs2[5]); @@ -1061,28 +1050,28 @@ window.parent.frames['nav'].location.replace(''); } else { $unsorted_sql_query = $sql_query; } - // 2. Checks if the current column is used to sort the result + // 3.2.2 Checks if the current column is used to sort the result if (empty($sql_order)) { $is_in_sort = FALSE; } else { - $is_in_sort = eregi(' (`?)' . str_replace('\\', '\\\\', $field->name) . '(`?)[ ,$]', $sql_order); + $is_in_sort = eregi(' (`?)' . str_replace('\\', '\\\\', $fields_meta[$i]->name) . '(`?)[ ,$]', $sql_order); } - // 3. Do define the sorting url + // 3.2.3 Do define the sorting url if (!$is_in_sort) { // loic1: patch #455484 ("Smart" order) $cfgOrder = strtoupper($GLOBALS['cfgOrder']); if ($cfgOrder == 'SMART') { - $cfgOrder = (eregi('time|date', $field->type)) ? 'DESC' : 'ASC'; + $cfgOrder = (eregi('time|date', $fields_meta[$i]->type)) ? 'DESC' : 'ASC'; } - $sort_order = ' ORDER BY ' . backquote($field->name) . ' ' . $cfgOrder; + $sort_order = ' ORDER BY ' . backquote($fields_meta[$i]->name) . ' ' . $cfgOrder; $order_img = ''; } else if (substr($sql_order, -3) == 'ASC' && $is_in_sort) { - $sort_order = ' ORDER BY ' . backquote($field->name) . ' DESC'; + $sort_order = ' ORDER BY ' . backquote($fields_meta[$i]->name) . ' DESC'; $order_img = ' ASC'; } else if (substr($sql_order, -4) == 'DESC' && $is_in_sort) { - $sort_order = ' ORDER BY ' . backquote($field->name) . ' ASC'; + $sort_order = ' ORDER BY ' . backquote($fields_meta[$i]->name) . ' ASC'; $order_img = ' DESC'; } if (eregi('(.*)( LIMIT (.*)| PROCEDURE (.*)| FOR UPDATE| LOCK IN SHARE MODE)', $unsorted_sql_query, $regs3)) { @@ -1099,7 +1088,7 @@ window.parent.frames['nav'].location.replace(''); ?> '); echo "\n"; ?> '; @@ -1126,6 +1116,9 @@ window.parent.frames['nav'].location.replace(''); '); // delete/edit options correctly for tables without keys. while ($row = mysql_fetch_row($dt_result)) { + + // 4.1 Prepares the row (gets primary keys to use) + $primary_key = ''; $uva_nonprimary_condition = ''; $bgcolor = ($foo % 2) ? $GLOBALS['cfgBgcolorOne'] : $GLOBALS['cfgBgcolorTwo']; - + ?> name) . ' '; if (!isset($row[$i])) { $row[$i] = ''; @@ -1178,7 +1173,7 @@ window.parent.frames['nav'].location.replace(''); $uva_condition = $uva_nonprimary_condition; } $uva_condition = urlencode(ereg_replace(' ?AND$', '', $uva_condition)); - + $url_query = 'lang=' . $lang . '&server=' . $server . '&db=' . urlencode($db) @@ -1228,12 +1223,12 @@ window.parent.frames['nav'].location.replace(''); echo "\n"; } // end if - $fields_cnt = mysql_num_fields($dt_result); + // 4.3 Displays the rows' values for ($i = 0; $i < $fields_cnt; ++$i) { if (!isset($row[$i])) { $row[$i] = ''; } - $primary = mysql_fetch_field($dt_result, $i); + $primary = $fields_meta[$i]; if ($primary->numeric == 1) { if ($row[$i] != '') { echo ' ' . "\n"; @@ -1276,8 +1271,8 @@ window.parent.frames['nav'].location.replace(''); } } } // end for - // Possibility to have the modify/delete button on the left added - // Benjamin Gandon -- 2000-08-29 + + // 4.4 Displays the modify/delete links on the right if required if ($GLOBALS['cfgModifyDeleteAtRight'] && !$is_simple) { ?>
- name); ?> + name); ?> - name) . "\n"; ?> + name) . "\n"; ?>
' . $row[$i] . ' @@ -1312,6 +1307,8 @@ window.parent.frames['nav'].location.replace('');
1)) { diff --git a/sql.php3 b/sql.php3 index ea57a5f1d..5bad040f7 100755 --- a/sql.php3 +++ b/sql.php3 @@ -293,10 +293,16 @@ else { } } - // Defines wether to display the full/partial text button or not - $show_text_btn = FALSE; + // Gets the list of fields properties while ($field = mysql_fetch_field($result)) { - if (eregi('BLOB', $field->type)) { + $fields_meta[] = $field; + } + $fields_cnt = count($fields_meta); + + // Defines wether to display the full/partial text button or not + $show_text_btn = FALSE; + for ($i = 0; $i < $fields_cnt; $i++) { + if (eregi('BLOB', $fields_meta[$i]->type)) { $show_text_btn = TRUE; if ($display == 'simple' || $display == 'bkmOnly') { break; @@ -304,7 +310,7 @@ else { } // loic1: maybe the fix for the second alias bug? if (($display != 'simple' && $display != 'bkmOnly') - && $field->table == '') { + && $fields_meta[$i]->table == '') { $display = 'simple'; } } // end while