Merged part 2 of patch #458014: multi-column editing

This commit is contained in:
Loïc Chapeaux
2001-09-06 22:12:09 +00:00
parent ebb0edbc48
commit bbef63ff34
6 changed files with 220 additions and 62 deletions

View File

@@ -31,7 +31,7 @@ window.parent.frames['nav'].location.replace('./left.php3?lang=<?php echo $lang;
*/ */
if (!empty($submit_mult) || isset($btnDrop)) { if (!empty($submit_mult) || isset($btnDrop)) {
$action = 'db_details.php3'; $action = 'db_details.php3';
include('./mult_drops.inc.php3'); include('./mult_submits.inc.php3');
} }

View File

@@ -14,7 +14,7 @@ require('./header.inc.php3');
if (!empty($submit_mult) || isset($btnDrop)) { if (!empty($submit_mult) || isset($btnDrop)) {
$action = 'db_stats.php3'; $action = 'db_stats.php3';
$show_query = 'y'; $show_query = 'y';
include('./mult_drops.inc.php3'); include('./mult_submits.inc.php3');
} }

138
mult_submits.inc.php3 Normal file
View File

@@ -0,0 +1,138 @@
<?php
/* $Id$ */
/**
* Confirmation form
*/
if (!empty($submit_mult)
&& (!empty($selected_db) || !empty($selected_tbl) || !empty($selected_fld))) {
if (get_magic_quotes_gpc()) {
$submit_mult = stripslashes($submit_mult);
}
if (!empty($selected_db)) {
$selected = $selected_db;
$what = 'drop_db';
} else if (!empty($selected_tbl)) {
$selected = $selected_tbl;
$what = (($submit_mult == $strDrop) ? 'drop_tbl' : 'empty_tbl');
} else {
$selected = $selected_fld;
if ($submit_mult == $strDrop) {
$what = 'drop_fld';
} else {
include('./tbl_alter.php3');
exit();
}
}
// Builds the query
$full_query = '';
$selected_cnt = count($selected);
for ($i = 0; $i < $selected_cnt; $i++) {
switch ($what) {
case 'drop_db':
$full_query .= 'DROP DATABASE '
. backquote(htmlspecialchars(urldecode($selected[$i])))
. ';<br />';
break;
case 'drop_tbl':
$full_query .= 'DROP TABLE '
. backquote(htmlspecialchars(urldecode($selected[$i])))
. ';<br />';
break;
case 'empty_tbl':
$full_query .= 'DELETE FROM '
. backquote(htmlspecialchars(urldecode($selected[$i])))
. ';<br />';
break;
case 'drop_fld':
$full_query .= 'ALTER TABLE '
. backquote(htmlspecialchars($table))
. ' DROP '
. backquote(htmlspecialchars(urldecode($selected[$i])))
. ';<br />';
break;
} // end switch
}
// Displays the form
echo $strDoYouReally . '&nbsp;:<br />' . "\n";
echo '<tt>' . $full_query . '</tt>&nbsp;?<br/>' . "\n";
?>
<form action="<?php echo $action; ?>" method="post">
<input type="hidden" name="lang" value="<?php echo $lang; ?>" />
<input type="hidden" name="server" value="<?php echo $server; ?>" />
<?php
echo "\n";
if ($action == 'db_details.php3') {
echo ' <input type="hidden" name="db" value="' . $db . '" />' . "\n";
} else if ($action == 'tbl_properties.php3') {
echo ' <input type="hidden" name="db" value="' . $db . '" />' . "\n";
echo ' <input type="hidden" name="table" value="' . $table . '" />' . "\n";
}
for ($i = 0; $i < $selected_cnt; $i++) {
echo ' <input type="hidden" name="selected[]" value="' . $selected[$i] . '" />' . "\n";
}
?>
<input type="hidden" name="query_type" value="<?php echo $what; ?>" />
<input type="submit" name="btnDrop" value="<?php echo $strYes; ?>" />
<input type="submit" name="btnDrop" value="<?php echo $strNo; ?>" />
</form>
<?php
echo"\n";
include('./footer.inc.php3');
exit();
}
/**
* Executes the query
*/
else if ((get_magic_quotes_gpc() && stripslashes($btnDrop) == $strYes)
|| $btnDrop == $strYes) {
$sql_query = '';
$selected_cnt = count($selected);
for ($i = 0; $i < $selected_cnt; $i++) {
switch ($query_type) {
case 'drop_db':
$a_query = 'DROP DATABASE '
. backquote(urldecode($selected[$i]));
$reload = 'true';
break;
case 'drop_tbl':
$a_query = 'DROP TABLE '
. backquote(urldecode($selected[$i]));
$reload = 'true';
break;
case 'empty_tbl':
$a_query = 'DELETE FROM '
. backquote(urldecode($selected[$i]));
break;
case 'drop_fld':
$a_query = 'ALTER TABLE '
. backquote($table)
. ' DROP '
. backquote(urldecode($selected[$i]));
break;
} // end switch
$sql_query .= $a_query . ';' . "\n";
if ($query_type != 'drop_db') {
mysql_select_db($db);
}
$result = @mysql_query($a_query) or mysql_die('', $a_query, FALSE);
} // end for
show_message($strSuccess);
}
?>

View File

@@ -6,65 +6,72 @@
* Gets some core libraries * Gets some core libraries
*/ */
require('./grab_globals.inc.php3'); require('./grab_globals.inc.php3');
if (isset($submit)) { if (!isset($submit_mult)) {
if (isset($submit)) {
$js_to_run = 'functions.js'; $js_to_run = 'functions.js';
}
include('./header.inc.php3');
} }
require('./header.inc.php3');
/** /**
* Modifications have been submitted -> updates the table * Modifications have been submitted -> updates the table
*/ */
if (isset($submit)) { if (isset($submit)) {
$field_cnt = count($field_orig);
for ($i = 0; $i < $field_cnt; $i++) {
if (get_magic_quotes_gpc()) { if (get_magic_quotes_gpc()) {
$field_name[0] = stripslashes($field_name[0]); $field_name[$i] = stripslashes($field_name[$i]);
$field_default[0] = stripslashes($field_default[0]); $field_default[$i] = stripslashes($field_default[$i]);
$field_length[0] = stripslashes($field_length[0]); $field_length[$i] = stripslashes($field_length[$i]);
} }
if (MYSQL_INT_VERSION < 32306) { if (MYSQL_INT_VERSION < 32306) {
check_reserved_words($field_name[0]); check_reserved_words($field_name[$i]);
} }
// Some fields have been urlencoded or double quotes have been translated // Some fields have been urlencoded or double quotes have been translated
// to "&quot;" in tbl_properties.php3 // to "&quot;" in tbl_properties.php3
$field_orig[0] = urldecode($field_orig[0]); $field_orig[$i] = urldecode($field_orig[$i]);
if (str_replace('"', '&quot;', $field_orig[0]) == $field_name[0]) { if (str_replace('"', '&quot;', $field_orig[$i]) == $field_name[$i]) {
$field_name[0] = $field_orig[0]; $field_name[$i] = $field_orig[$i];
} }
$field_default_orig[0] = urldecode($field_default_orig[0]); $field_default_orig[$i] = urldecode($field_default_orig[$i]);
if (str_replace('"', '&quot;', $field_default_orig[0]) == $field_default[0]) { if (str_replace('"', '&quot;', $field_default_orig[$i]) == $field_default[$i]) {
$field_default[0] = $field_default_orig[0]; $field_default[$i] = $field_default_orig[$i];
} }
$field_length_orig[0] = urldecode($field_length_orig[0]); $field_length_orig[$i] = urldecode($field_length_orig[$i]);
if (str_replace('"', '&quot;', $field_length_orig[0]) == $field_length[0]) { if (str_replace('"', '&quot;', $field_length_orig[$i]) == $field_length[$i]) {
$field_length[0] = $field_length_orig[0]; $field_length[$i] = $field_length_orig[$i];
} }
if (!isset($query)) { if (!isset($query)) {
$query = ''; $query = '';
} else {
$query .= ', CHANGE ';
} }
$query .= ' ' . backquote($field_orig[0]) . ' ' . backquote($field_name[0]) . ' ' . $field_type[0]; $query .= backquote($field_orig[$i]) . ' ' . backquote($field_name[$i]) . ' ' . $field_type[$i];
// Some field types shouldn't have lengths // Some field types shouldn't have lengths
if ($field_length[0] != '' if ($field_length[$i] != ''
&& !eregi('^(DATE|DATETIME|TIME|TINYBLOB|TINYTEXT|BLOB|TEXT|MEDIUMBLOB|MEDIUMTEXT|LONGBLOB|LONGTEXT)$', $field_type[0])) { && !eregi('^(DATE|DATETIME|TIME|TINYBLOB|TINYTEXT|BLOB|TEXT|MEDIUMBLOB|MEDIUMTEXT|LONGBLOB|LONGTEXT)$', $field_type[$i])) {
$query .= '(' . $field_length[0] . ')'; $query .= '(' . $field_length[$i] . ')';
} }
if ($field_attribute[0] != '') { if ($field_attribute[$i] != '') {
$query .= ' ' . $field_attribute[0]; $query .= ' ' . $field_attribute[$i];
} }
if ($field_default[0] != '') { if ($field_default[$i] != '') {
if (strtoupper($field_default[0]) == 'NULL') { if (strtoupper($field_default[$i]) == 'NULL') {
$query .= ' DEFAULT NULL'; $query .= ' DEFAULT NULL';
} else { } else {
$query .= ' DEFAULT \'' . sql_addslashes($field_default[0]) . '\''; $query .= ' DEFAULT \'' . sql_addslashes($field_default[$i]) . '\'';
} }
} }
if ($field_null[0] != '') { if ($field_null[$i] != '') {
$query .= ' ' . $field_null[0]; $query .= ' ' . $field_null[$i];
} }
if ($field_extra[0] != '') { if ($field_extra[$i] != '') {
$query .= ' ' . $field_extra[0]; $query .= ' ' . $field_extra[$i];
} }
} // end for
// Optimization fix - 2 May 2001 - Robbat2 // Optimization fix - 2 May 2001 - Robbat2
$sql_query = 'ALTER TABLE ' . backquote($db) . '.' . backquote($table) . ' CHANGE ' . $query; $sql_query = 'ALTER TABLE ' . backquote($db) . '.' . backquote($table) . ' CHANGE ' . $query;
@@ -79,14 +86,27 @@ if (isset($submit)) {
* No modifications yet required -> displays the table fields * No modifications yet required -> displays the table fields
*/ */
else { else {
if (get_magic_quotes_gpc()) { if (!isset($selected)) {
$field = sql_addslashes(stripslashes($field), TRUE); $selected[] = $field;
$selected_cnt = 1;
} else { } else {
$field = sql_addslashes($field, TRUE); $selected_cnt = count($selected);
}
// TODO: optimize in case of multiple fields to modify
for ($i = 0; $i < $selected_cnt; $i++) {
if (get_magic_quotes_gpc()) {
$field = sql_addslashes(stripslashes($selected[$i]), TRUE);
} else {
$field = sql_addslashes($selected[$i], TRUE);
} }
$local_query = 'SHOW FIELDS FROM ' . backquote($db) . '.' . backquote($table) . " LIKE '$field'"; $local_query = 'SHOW FIELDS FROM ' . backquote($db) . '.' . backquote($table) . " LIKE '$field'";
$result = mysql_query($local_query) or mysql_die('', $local_query); $result = mysql_query($local_query) or mysql_die('', $local_query);
$num_fields = mysql_num_rows($result); $fields_meta[] = mysql_fetch_array($result);
mysql_free_result($result);
}
$num_fields = count($fields_meta);
$action = 'tbl_alter.php3'; $action = 'tbl_alter.php3';
include('./tbl_properties.inc.php3'); include('./tbl_properties.inc.php3');
} }

View File

@@ -51,8 +51,8 @@ if (!$is_backup) {
<?php <?php
for ($i = 0 ; $i < $num_fields; $i++) { for ($i = 0 ; $i < $num_fields; $i++) {
if (isset($result)) { if (isset($fields_meta)) {
$row = mysql_fetch_array($result); $row = $fields_meta[$i];
} }
$bgcolor = ($i % 2) ? $cfgBgcolorOne : $cfgBgcolorTwo; $bgcolor = ($i % 2) ? $cfgBgcolorOne : $cfgBgcolorTwo;
?> ?>

View File

@@ -20,7 +20,7 @@ if (!isset($message)) {
*/ */
if (!empty($submit_mult) || isset($btnDrop)) { if (!empty($submit_mult) || isset($btnDrop)) {
$action = 'tbl_properties.php3'; $action = 'tbl_properties.php3';
include('./mult_drops.inc.php3'); include('./mult_submits.inc.php3');
} }