2007-07-02 20:21:30 +00:00
< ? php
2009-06-21 23:20:32 +00:00
if ( $_POST && ! $error && ! isset ( $_POST [ " add_x " ])) { // add is an image and PHP changes add.x to add_x
2010-03-01 22:59:08 +00:00
restart_session ();
if ( $_POST [ " drop " ]) {
2010-05-12 16:23:40 +00:00
$_GET [ " db " ] = " " ; // to save in global history
2010-04-22 23:02:28 +00:00
queries_redirect ( remove_from_uri ( " db|database " ), lang ( 'Database has been dropped.' ), drop_databases ( array ( DB )));
2010-03-01 22:59:08 +00:00
} elseif ( DB !== $_POST [ " name " ]) {
2009-06-21 23:20:32 +00:00
// create or rename database
2010-04-21 12:01:32 +00:00
if ( DB != " " ) {
2010-05-12 16:23:40 +00:00
$_GET [ " db " ] = $_POST [ " name " ];
2010-04-21 12:01:32 +00:00
queries_redirect ( preg_replace ( '~db=[^&]*&~' , '' , ME ) . " db= " . urlencode ( $_POST [ " name " ]), lang ( 'Database has been renamed.' ), rename_database ( $_POST [ " name " ], $_POST [ " collation " ]));
} else {
2010-10-15 08:58:08 +00:00
$databases = explode ( " \n " , str_replace ( " \r " , " " , $_POST [ " name " ]));
2010-04-21 12:01:32 +00:00
$success = true ;
$last = " " ;
2010-10-15 08:58:08 +00:00
foreach ( $databases as $db ) {
if ( count ( $databases ) == 1 || $db != " " ) { // ignore empty lines but always try to create single database
2010-04-22 23:02:28 +00:00
if ( ! create_database ( $db , $_POST [ " collation " ])) {
2010-04-21 12:01:32 +00:00
$success = false ;
}
$last = $db ;
2009-06-11 11:13:45 +00:00
}
}
2010-04-21 12:01:32 +00:00
queries_redirect ( ME . " db= " . urlencode ( $last ), lang ( 'Database has been created.' ), $success );
2007-07-02 20:21:30 +00:00
}
2008-09-02 08:42:14 +00:00
} else {
2009-06-21 23:20:32 +00:00
// alter database
2008-09-02 08:42:14 +00:00
if ( ! $_POST [ " collation " ]) {
2009-07-30 08:12:54 +00:00
redirect ( substr ( ME , 0 , - 1 ));
2008-09-02 08:42:14 +00:00
}
2010-10-17 19:58:02 +00:00
query_redirect ( " ALTER DATABASE " . idf_escape ( $_POST [ " name " ]) . ( eregi ( '^[a-z0-9_]+$' , $_POST [ " collation " ]) ? " COLLATE $_POST[collation] " : " " ), substr ( ME , 0 , - 1 ), lang ( 'Database has been altered.' ));
2007-07-02 20:21:30 +00:00
}
}
2009-07-20 12:12:55 +00:00
2010-01-09 23:33:41 +00:00
page_header ( DB != " " ? lang ( 'Alter database' ) : lang ( 'Create database' ), $error , array (), DB );
2007-07-02 20:21:30 +00:00
2008-03-18 10:29:20 +00:00
$collations = collations ();
2009-08-29 13:54:25 +00:00
$name = DB ;
2009-10-18 09:29:01 +00:00
$collate = null ;
2008-03-18 10:29:20 +00:00
if ( $_POST ) {
2007-07-02 20:21:30 +00:00
$name = $_POST [ " name " ];
2007-07-06 13:00:58 +00:00
$collate = $_POST [ " collation " ];
2010-04-21 12:01:32 +00:00
} elseif ( DB != " " ) {
$collate = db_collation ( DB , $collations );
2010-05-07 13:44:22 +00:00
} elseif ( $jush == " sql " ) {
2009-06-21 23:20:32 +00:00
// propose database name with limited privileges
2010-04-21 12:01:32 +00:00
foreach ( get_vals ( " SHOW GRANTS " ) as $grant ) {
if ( preg_match ( '~ ON (`(([^\\\\`]|``|\\\\.)*)%`\\.\\*)?~' , $grant , $match ) && $match [ 1 ]) {
$name = stripcslashes ( idf_unescape ( " ` $match[2] ` " ));
2009-06-21 23:20:32 +00:00
break ;
2007-07-26 11:11:58 +00:00
}
2007-07-06 13:00:58 +00:00
}
2007-07-02 20:21:30 +00:00
}
?>
2007-07-09 14:47:46 +00:00
2007-07-11 21:06:19 +00:00
< form action = " " method = " post " >
< p >
2010-04-22 23:02:28 +00:00
< ? php
echo ( $_POST [ " add_x " ] || strpos ( $name , " \n " )
2010-10-17 05:16:32 +00:00
? '<textarea name="name" rows="10" cols="40" onkeydown="return textareaKeydown(this, event);">' . h ( $name ) . '</textarea><br>'
2009-07-28 16:20:50 +00:00
: '<input name="name" value="' . h ( $name ) . '" maxlength="64">'
2010-05-12 12:42:29 +00:00
) . " \n " . ( $collations ? html_select ( " collation " , array ( " " => " ( " . lang ( 'collation' ) . " ) " ) + $collations , $collate ) : " " );
2010-04-22 23:02:28 +00:00
?>
2009-07-11 20:30:40 +00:00
< input type = " hidden " name = " token " value = " <?php echo $token ; ?> " >
2010-02-26 14:58:58 +00:00
< input type = " submit " value = " <?php echo lang('Save'); ?> " >
2009-06-15 09:50:00 +00:00
< ? php
2010-05-05 16:30:55 +00:00
if ( DB != " " ) {
2010-03-01 22:59:08 +00:00
echo " <input type='submit' name='drop' value=' " . lang ( 'Drop' ) . " ' $confirm > \n " ;
} elseif ( ! $_POST [ " add_x " ] && $_GET [ " db " ] == " " ) {
2009-09-23 09:56:07 +00:00
echo " <input type='image' name='add' src='../adminer/static/plus.gif' alt='+' title=' " . lang ( 'Add next' ) . " '> \n " ;
2009-06-15 09:50:00 +00:00
}
?>
2007-07-11 21:06:19 +00:00
</ form >