2007-07-16 23:08:24 +00:00
|
|
|
<?php
|
|
|
|
$routine = (isset($_GET["function"]) ? "FUNCTION" : "PROCEDURE");
|
|
|
|
|
2007-08-04 19:39:18 +00:00
|
|
|
$dropped = false;
|
2007-07-26 09:18:58 +00:00
|
|
|
if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"]) {
|
2007-08-09 09:17:44 +00:00
|
|
|
if (strlen($_GET["procedure"]) && ($_POST["dropped"] || $mysql->query("DROP $routine " . idf_escape($_GET["procedure"])))) {
|
2007-08-04 19:39:18 +00:00
|
|
|
if ($_POST["drop"]) {
|
|
|
|
redirect(substr($SELF, 0, -1), lang('Routine has been dropped.'));
|
|
|
|
}
|
|
|
|
$dropped = true;
|
2007-07-16 23:08:24 +00:00
|
|
|
}
|
|
|
|
if (!$_POST["drop"]) {
|
|
|
|
$set = array();
|
2007-07-17 09:12:15 +00:00
|
|
|
$fields = array_filter((array) $_POST["fields"], 'strlen');
|
|
|
|
ksort($fields);
|
|
|
|
foreach ($fields as $field) {
|
2007-08-13 08:44:44 +00:00
|
|
|
if (strlen($field["field"])) {
|
|
|
|
$set[] = (in_array($field["inout"], $inout) ? "$field[inout] " : "") . idf_escape($field["field"]) . process_type($field, "CHARACTER SET");
|
|
|
|
}
|
2007-07-16 23:08:24 +00:00
|
|
|
}
|
|
|
|
if ($mysql->query(
|
|
|
|
"CREATE $routine " . idf_escape($_POST["name"])
|
|
|
|
. " (" . implode(", ", $set) . ")"
|
2007-07-17 05:31:45 +00:00
|
|
|
. (isset($_GET["function"]) ? " RETURNS" . process_type($_POST["returns"], "CHARACTER SET") : "") . "
|
2007-07-16 23:08:24 +00:00
|
|
|
$_POST[definition]"
|
|
|
|
)) {
|
2007-07-17 09:12:15 +00:00
|
|
|
redirect(substr($SELF, 0, -1), (strlen($_GET["procedure"]) ? lang('Routine has been altered.') : lang('Routine has been created.')));
|
2007-07-16 23:08:24 +00:00
|
|
|
}
|
|
|
|
}
|
2007-07-17 09:12:15 +00:00
|
|
|
$error = $mysql->error;
|
2007-07-16 23:08:24 +00:00
|
|
|
}
|
|
|
|
|
2007-07-17 09:12:15 +00:00
|
|
|
page_header(strlen($_GET["procedure"])
|
|
|
|
? (isset($_GET["function"]) ? lang('Alter function') : lang('Alter procedure')) . ": " . htmlspecialchars($_GET["procedure"])
|
|
|
|
: (isset($_GET["function"]) ? lang('Create function') : lang('Create procedure'))
|
|
|
|
);
|
|
|
|
|
|
|
|
$collations = get_vals("SHOW CHARACTER SET");
|
|
|
|
if ($_POST) {
|
|
|
|
$row = $_POST;
|
|
|
|
$row["fields"] = (array) $row["fields"];
|
|
|
|
ksort($row["fields"]);
|
2007-07-26 09:18:58 +00:00
|
|
|
$row["fields"] = array_values($row["fields"]);
|
|
|
|
if ($_POST["add"]) {
|
2007-07-17 09:12:15 +00:00
|
|
|
array_splice($row["fields"], key($_POST["add"]), 0, array(array()));
|
2007-07-26 09:18:58 +00:00
|
|
|
} elseif (!$_POST["drop_col"]) {
|
|
|
|
echo "<p class='error'>" . lang('Unable to operate routine') . ": " . htmlspecialchars($error) . "</p>\n";
|
2007-07-17 09:12:15 +00:00
|
|
|
}
|
|
|
|
} elseif (strlen($_GET["procedure"])) {
|
|
|
|
$row = routine($_GET["procedure"], $routine);
|
|
|
|
$row["name"] = $_GET["procedure"];
|
|
|
|
} else {
|
|
|
|
$row = array("fields" => array());
|
|
|
|
}
|
2007-07-16 23:08:24 +00:00
|
|
|
?>
|
2007-07-17 09:12:15 +00:00
|
|
|
|
|
|
|
<form action="" method="post" id="form">
|
2007-07-16 23:08:24 +00:00
|
|
|
<table border="0" cellspacing="0" cellpadding="2">
|
2007-07-17 09:12:15 +00:00
|
|
|
<?php edit_fields($row["fields"], get_vals("SHOW CHARACTER SET"), $routine); ?>
|
2007-07-23 15:14:19 +00:00
|
|
|
<?php if (isset($_GET["function"])) { ?><tr><td><?php echo lang('Return type'); ?></td><?php echo edit_type("returns", $row["returns"], $collations); ?></tr><?php } ?>
|
2007-07-16 23:08:24 +00:00
|
|
|
</table>
|
|
|
|
<?php echo type_change(count($row["fields"])); ?>
|
|
|
|
<?php if (isset($_GET["function"])) { ?>
|
|
|
|
<script type="text/javascript">
|
|
|
|
document.getElementById('form')['returns[type]'].onchange();
|
|
|
|
</script>
|
|
|
|
<?php } ?>
|
2007-07-17 09:12:15 +00:00
|
|
|
<p><textarea name="definition" rows="10" cols="80" style="width: 98%;"><?php echo htmlspecialchars($row["definition"]); ?></textarea></p>
|
|
|
|
<p>
|
|
|
|
<input type="hidden" name="token" value="<?php echo $token; ?>" />
|
2007-08-04 19:39:18 +00:00
|
|
|
<?php if ($dropped) { ?><input type="hidden" name="dropped" value="1" /><?php } ?>
|
2007-07-17 09:12:15 +00:00
|
|
|
<?php echo lang('Name'); ?>: <input name="name" value="<?php echo htmlspecialchars($row["name"]); ?>" maxlength="64" />
|
|
|
|
<input type="submit" value="<?php echo lang('Save'); ?>" />
|
2007-07-26 11:16:17 +00:00
|
|
|
<?php if (strlen($_GET["procedure"])) { ?><input type="submit" name="drop" value="<?php echo lang('Drop'); ?>" onclick="return confirm('<?php echo lang('Are you sure?'); ?>');" /><?php } ?>
|
2007-07-17 09:12:15 +00:00
|
|
|
</p>
|
|
|
|
</form>
|