2007-07-02 05:51:26 +00:00
|
|
|
<?php
|
2007-07-04 14:39:45 +00:00
|
|
|
$types = types();
|
|
|
|
if ($_POST && !$_POST["add"]) {
|
2007-07-02 16:21:04 +00:00
|
|
|
if ($_POST["drop"]) {
|
|
|
|
$query = "DROP TABLE " . idf_escape($_GET["create"]);
|
|
|
|
$message = lang('Table has been dropped.');
|
|
|
|
} else {
|
|
|
|
$fields = array();
|
|
|
|
ksort($_POST["fields"]);
|
|
|
|
foreach ($_POST["fields"] as $key => $field) {
|
2007-07-04 14:39:45 +00:00
|
|
|
if (strlen($field["field"]) && isset($types[$field["type"]])) {
|
2007-07-04 16:57:24 +00:00
|
|
|
$fields[] = (!strlen($_GET["create"]) ? "" : (strlen($field["orig"]) ? "CHANGE " . idf_escape($field["orig"]) . " " : "ADD ")) . idf_escape($field["field"]) . " $field[type]" . ($field["length"] ? "($field[length])" : "") . ($field["null"] ? "" : " NOT NULL") . ($field["extra"] == "auto_increment" ? " AUTO_INCREMENT PRIMARY KEY" : "");
|
2007-07-04 14:39:45 +00:00
|
|
|
} elseif (strlen($field["orig"])) {
|
|
|
|
$fields[] = "DROP " . idf_escape($field["orig"]);
|
2007-07-02 16:21:04 +00:00
|
|
|
}
|
2007-07-02 05:51:26 +00:00
|
|
|
}
|
2007-07-02 16:21:04 +00:00
|
|
|
$status = ($_POST["Engine"] ? " ENGINE='" . mysql_real_escape_string($_POST["Engine"]) . "'" : "") . ($_POST["Collation"] ? " COLLATE '" . mysql_real_escape_string($_POST["Collation"]) . "'" : "");
|
|
|
|
if (strlen($_GET["create"])) {
|
2007-07-04 14:39:45 +00:00
|
|
|
$query = "ALTER TABLE " . idf_escape($_GET["create"]) . " " . implode(", ", $fields) . ", RENAME TO " . idf_escape($_POST["name"]) . ", $status";
|
2007-07-02 16:21:04 +00:00
|
|
|
$message = lang('Table has been altered.');
|
|
|
|
} else {
|
|
|
|
$query = "CREATE TABLE " . idf_escape($_POST["name"]) . " (" . implode(", ", $fields) . ")$status";
|
|
|
|
$message = lang('Table has been created.');
|
2007-07-02 10:49:36 +00:00
|
|
|
}
|
2007-07-02 16:21:04 +00:00
|
|
|
}
|
|
|
|
if (mysql_query($query)) {
|
2007-07-03 06:48:18 +00:00
|
|
|
redirect(($_POST["drop"] ? substr($SELF, 0, -1) : $SELF . "table=" . urlencode($_POST["name"])), $message);
|
2007-07-02 05:51:26 +00:00
|
|
|
}
|
2007-07-02 16:21:04 +00:00
|
|
|
$error = mysql_error();
|
2007-07-02 05:51:26 +00:00
|
|
|
}
|
2007-07-02 15:49:46 +00:00
|
|
|
page_header(strlen($_GET["create"]) ? lang('Alter table') . ': ' . htmlspecialchars($_GET["create"]) : lang('Create table'));
|
|
|
|
echo "<h2>" . (strlen($_GET["create"]) ? lang('Alter table') . ': ' . htmlspecialchars($_GET["create"]) : lang('Create table')) . "</h2>\n";
|
2007-07-02 05:51:26 +00:00
|
|
|
|
|
|
|
if ($_POST) {
|
2007-07-04 14:39:45 +00:00
|
|
|
if (!$_POST["add"]) {
|
|
|
|
echo "<p class='error'>" . lang('Unable to operate table') . ": " . htmlspecialchars($error) . "</p>\n";
|
|
|
|
}
|
2007-07-02 16:21:04 +00:00
|
|
|
$row = $_POST;
|
2007-07-02 05:51:26 +00:00
|
|
|
} elseif (strlen($_GET["create"])) {
|
|
|
|
$row = mysql_fetch_assoc(mysql_query("SHOW TABLE STATUS LIKE '" . mysql_real_escape_string($_GET["create"]) . "'"));
|
2007-07-02 16:21:04 +00:00
|
|
|
$row["name"] = $_GET["create"];
|
2007-07-03 07:39:03 +00:00
|
|
|
$row["fields"] = fields($_GET["create"]);
|
2007-07-03 07:21:43 +00:00
|
|
|
} else {
|
|
|
|
$row = array("fields" => array());
|
2007-07-02 05:51:26 +00:00
|
|
|
}
|
2007-07-04 17:16:44 +00:00
|
|
|
//! collate columns, references, unsigned, zerofill, default
|
2007-07-02 05:51:26 +00:00
|
|
|
?>
|
|
|
|
<form action="" method="post">
|
|
|
|
<p>
|
2007-07-02 16:21:04 +00:00
|
|
|
<?php echo lang('Table name'); ?>: <input name="name" maxlength="64" value="<?php echo htmlspecialchars($row["name"]); ?>" />
|
|
|
|
<select name="Engine"><option value="">(<?php echo lang('engine'); ?>)</option><?php echo optionlist(engines(), $row["Engine"], "not_vals"); ?></select>
|
|
|
|
<select name="Collation"><option value="">(<?php echo lang('collation'); ?>)</option><?php echo optionlist(collations(), $row["Collation"], "not_vals"); ?></select>
|
2007-07-02 05:51:26 +00:00
|
|
|
</p>
|
|
|
|
<table border="0" cellspacing="0" cellpadding="2">
|
2007-07-03 07:21:43 +00:00
|
|
|
<thead><tr><th><?php echo lang('Name'); ?></th><td><?php echo lang('Type'); ?></td><td><?php echo lang('Length'); ?></td><td><?php echo lang('NULL'); ?></td><td><?php echo lang('Auto-increment'); ?></td></tr></thead>
|
|
|
|
<?php
|
2007-07-03 07:39:03 +00:00
|
|
|
$i=0;
|
|
|
|
foreach ($row["fields"] as $field) {
|
|
|
|
if (strlen($field["field"])) {
|
2007-07-03 07:21:43 +00:00
|
|
|
?>
|
|
|
|
<tr>
|
2007-07-04 14:39:45 +00:00
|
|
|
<th><input type="hidden" name="fields[<?php echo $i; ?>][orig]" value="<?php echo htmlspecialchars($field["field"]); ?>" /><input name="fields[<?php echo $i; ?>][field]" value="<?php echo htmlspecialchars($field["field"]); ?>" maxlength="64" /></th>
|
|
|
|
<td><select name="fields[<?php echo $i; ?>][type]"><?php echo optionlist(array_keys($types), $field["type"], "not_vals"); ?></select></td>
|
2007-07-03 07:39:03 +00:00
|
|
|
<td><input name="fields[<?php echo $i; ?>][length]" value="<?php echo htmlspecialchars($field["length"]); ?>" size="3" /></td>
|
|
|
|
<td><input type="checkbox" name="fields[<?php echo $i; ?>][null]" value="1"<?php if ($field["null"]) { ?> checked="checked"<?php } ?> /></td>
|
|
|
|
<td><input type="checkbox" name="fields[<?php echo $i; ?>][extra]" value="auto_increment"<?php if ($field["extra"] == "auto_increment") { ?> checked="checked"<?php } ?> /></td>
|
2007-07-03 07:21:43 +00:00
|
|
|
</tr>
|
|
|
|
<?php
|
2007-07-03 07:39:03 +00:00
|
|
|
$i++;
|
2007-07-03 07:21:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//! JavaScript for next rows
|
|
|
|
?>
|
2007-07-02 05:51:26 +00:00
|
|
|
<tr>
|
2007-07-03 07:39:03 +00:00
|
|
|
<th><input name="fields[<?php echo $i; ?>][field]" maxlength="64" /></th>
|
2007-07-04 14:39:45 +00:00
|
|
|
<td><select name="fields[<?php echo $i; ?>][type]"><?php echo optionlist(array_keys($types), array(), "not_vals"); ?></select></td>
|
2007-07-03 07:39:03 +00:00
|
|
|
<td><input name="fields[<?php echo $i; ?>][length]" size="3" /></td>
|
|
|
|
<td><input type="checkbox" name="fields[<?php echo $i; ?>][null]" value="1" /></td>
|
|
|
|
<td><input type="checkbox" name="fields[<?php echo $i; ?>][extra]" value="auto_increment" /></td>
|
2007-07-02 05:51:26 +00:00
|
|
|
</tr>
|
|
|
|
</table>
|
2007-07-04 14:39:45 +00:00
|
|
|
<p><input type="submit" name="add" value="<?php echo lang('Add row'); ?>" /></p>
|
2007-07-02 05:51:26 +00:00
|
|
|
<p>
|
2007-07-02 10:49:36 +00:00
|
|
|
<input type="submit" value="<?php echo lang('Save'); ?>" />
|
2007-07-02 05:51:26 +00:00
|
|
|
<?php if (strlen($_GET["create"])) { ?><input type="submit" name="drop" value="<?php echo lang('Drop'); ?>" /><?php } ?>
|
|
|
|
</p>
|
|
|
|
</form>
|