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 ;
2008-05-07 11:22:08 +00:00
if ( $_POST && ! $error && ! $_POST [ " add " ] && ! $_POST [ " drop_col " ] && ! $_POST [ " up " ] && ! $_POST [ " down " ]) {
2008-09-02 12:39:04 +00:00
if ( strlen ( $_GET [ " procedure " ])) {
$dropped = query_redirect ( " DROP $routine " . idf_escape ( $_GET [ " procedure " ]), substr ( $SELF , 0 , - 1 ), lang ( 'Routine has been dropped.' ), $_POST [ " drop " ], ! $_POST [ " dropped " ]);
2007-07-16 23:08:24 +00:00
}
if ( ! $_POST [ " drop " ]) {
$set = array ();
2009-06-30 11:10:56 +00:00
$fields = ( array ) $_POST [ " fields " ];
2009-06-21 23:20:32 +00:00
ksort ( $fields ); // enforce fields order
2007-07-17 09:12:15 +00:00
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
}
2008-09-02 08:42:14 +00:00
query_redirect ( " CREATE $routine " . idf_escape ( $_POST [ " name " ])
2007-07-16 23:08:24 +00:00
. " ( " . implode ( " , " , $set ) . " ) "
2008-09-02 08:42:14 +00:00
. ( isset ( $_GET [ " function " ]) ? " RETURNS " . process_type ( $_POST [ " returns " ], " CHARACTER SET " ) : " " )
2009-06-05 08:30:21 +00:00
. " \n $_POST[definition] "
2008-09-02 08:42:14 +00:00
, 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
}
}
2009-07-20 12:12:55 +00:00
2008-04-10 14:37:10 +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' ))), $error );
2007-07-17 09:12:15 +00:00
$collations = get_vals ( " SHOW CHARACTER SET " );
2009-06-29 10:10:59 +00:00
sort ( $collations );
2008-07-10 15:39:24 +00:00
$row = array ( " fields " => array ());
2007-07-17 09:12:15 +00:00
if ( $_POST ) {
$row = $_POST ;
$row [ " fields " ] = ( array ) $row [ " fields " ];
2008-05-07 11:22:08 +00:00
process_fields ( $row [ " fields " ]);
2007-07-17 09:12:15 +00:00
} elseif ( strlen ( $_GET [ " procedure " ])) {
$row = routine ( $_GET [ " procedure " ], $routine );
$row [ " name " ] = $_GET [ " procedure " ];
}
2007-07-16 23:08:24 +00:00
?>
2007-07-17 09:12:15 +00:00
< form action = " " method = " post " id = " form " >
2009-05-01 10:41:33 +00:00
< table cellspacing = " 0 " >
2008-03-20 16:38:21 +00:00
< ? php edit_fields ( $row [ " fields " ], $collations , $routine ); ?>
2009-07-11 20:30:40 +00:00
< ? php if ( isset ( $_GET [ " function " ])) { ?> <tr><td><?php echo lang('Return type'); ?><?php echo edit_type("returns", $row["returns"], $collations); ?><?php } ?>
2007-07-16 23:08:24 +00:00
</ table >
2009-07-11 20:30:40 +00:00
< p >< textarea name = " definition " rows = " 10 " cols = " 80 " style = " width: 98%; " >< ? php echo htmlspecialchars ( $row [ " definition " ]); ?> </textarea>
2007-07-17 09:12:15 +00:00
< p >
2009-07-11 20:30:40 +00:00
< input type = " hidden " name = " token " value = " <?php echo $token ; ?> " >
< ? php if ( $dropped ) { ?> <input type="hidden" name="dropped" value="1"><?php } ?>
< ? php echo lang ( 'Name' ); ?> : <input name="name" value="<?php echo htmlspecialchars($row["name"]); ?>" maxlength="64">
< input type = " submit " value = " <?php echo lang('Save'); ?> " >
< ? php if ( strlen ( $_GET [ " procedure " ])) { ?> <input type="submit" name="drop" value="<?php echo lang('Drop'); ?>"<?php echo $confirm; ?>><?php } ?>
2007-07-17 09:12:15 +00:00
</ form >