2009-06-11 16:53:28 +00:00
< ? php
2009-06-11 17:19:06 +00:00
$tables_views = array_merge (( array ) $_POST [ " tables " ], ( array ) $_POST [ " views " ]);
2010-02-16 14:35:32 +00:00
if ( $tables_views && ! $error && ! $_POST [ " search " ]) {
2009-06-11 16:53:28 +00:00
$result = true ;
$message = " " ;
2018-01-16 15:22:24 +00:00
if ( $jush == " sql " && $_POST [ " tables " ] && count ( $_POST [ " tables " ]) > 1 && ( $_POST [ " drop " ] || $_POST [ " truncate " ] || $_POST [ " copy " ])) {
2009-07-20 14:31:05 +00:00
queries ( " SET foreign_key_checks = 0 " ); // allows to truncate or drop several tables at once
2009-06-21 23:45:42 +00:00
}
2013-07-24 23:26:41 +00:00
2010-04-21 12:01:32 +00:00
if ( $_POST [ " truncate " ]) {
if ( $_POST [ " tables " ]) {
$result = truncate_tables ( $_POST [ " tables " ]);
2009-06-11 16:53:28 +00:00
}
2009-09-23 12:21:14 +00:00
$message = lang ( 'Tables have been truncated.' );
2010-04-21 12:01:32 +00:00
} elseif ( $_POST [ " move " ]) {
2010-05-05 20:11:24 +00:00
$result = move_tables (( array ) $_POST [ " tables " ], ( array ) $_POST [ " views " ], $_POST [ " target " ]);
2009-06-11 16:53:28 +00:00
$message = lang ( 'Tables have been moved.' );
2011-02-01 13:12:22 +00:00
} elseif ( $_POST [ " copy " ]) {
$result = copy_tables (( array ) $_POST [ " tables " ], ( array ) $_POST [ " views " ], $_POST [ " target " ]);
$message = lang ( 'Tables have been copied.' );
2010-04-21 12:01:32 +00:00
} elseif ( $_POST [ " drop " ]) {
if ( $_POST [ " views " ]) {
$result = drop_views ( $_POST [ " views " ]);
}
if ( $result && $_POST [ " tables " ]) {
$result = drop_tables ( $_POST [ " tables " ]);
}
$message = lang ( 'Tables have been dropped.' );
2012-03-01 09:14:55 +00:00
} elseif ( $jush != " sql " ) {
$result = ( $jush == " sqlite "
? queries ( " VACUUM " )
: apply_queries ( " VACUUM " . ( $_POST [ " optimize " ] ? " " : " ANALYZE " ), $_POST [ " tables " ])
);
2012-02-29 18:49:17 +00:00
$message = lang ( 'Tables have been optimized.' );
2013-01-31 05:55:25 +00:00
} elseif ( ! $_POST [ " tables " ]) {
$message = lang ( 'No tables.' );
} elseif ( $result = queries (( $_POST [ " optimize " ] ? " OPTIMIZE " : ( $_POST [ " check " ] ? " CHECK " : ( $_POST [ " repair " ] ? " REPAIR " : " ANALYZE " ))) . " TABLE " . implode ( " , " , array_map ( 'idf_escape' , $_POST [ " tables " ])))) {
2010-04-21 12:01:32 +00:00
while ( $row = $result -> fetch_assoc ()) {
2010-04-22 09:22:19 +00:00
$message .= " <b> " . h ( $row [ " Table " ]) . " </b>: " . h ( $row [ " Msg_text " ]) . " <br> " ;
2009-06-11 16:53:28 +00:00
}
}
2013-07-24 23:26:41 +00:00
2009-10-13 20:01:52 +00:00
queries_redirect ( substr ( ME , 0 , - 1 ), $message , $result );
2009-06-11 16:53:28 +00:00
}
2010-05-05 16:30:55 +00:00
page_header (( $_GET [ " ns " ] == " " ? lang ( 'Database' ) . " : " . h ( DB ) : lang ( 'Schema' ) . " : " . h ( $_GET [ " ns " ])), $error , true );
2011-01-06 08:30:07 +00:00
if ( $adminer -> homepage ()) {
if ( $_GET [ " ns " ] !== " " ) {
2013-04-28 06:17:07 +00:00
echo " <h3 id='tables-views'> " . lang ( 'Tables and views' ) . " </h3> \n " ;
2011-01-06 08:30:07 +00:00
$tables_list = tables_list ();
if ( ! $tables_list ) {
echo " <p class='message'> " . lang ( 'No tables.' ) . " \n " ;
} else {
echo " <form action='' method='post'> \n " ;
2013-07-12 00:47:28 +00:00
if ( support ( " table " )) {
echo " <fieldset><legend> " . lang ( 'Search data in tables' ) . " <span id='selected2'></span></legend><div> " ;
2018-01-12 15:54:50 +00:00
echo " <input type='search' name='query' value=' " . h ( $_POST [ " query " ]) . " '> " ;
echo script ( " qsl('input').onkeydown = partialArg(bodyKeydown, 'search'); " , " " );
echo " <input type='submit' name='search' value=' " . lang ( 'Search' ) . " '> \n " ;
2013-07-12 00:47:28 +00:00
echo " </div></fieldset> \n " ;
if ( $_POST [ " search " ] && $_POST [ " query " ] != " " ) {
search_tables ();
}
2011-01-06 08:30:07 +00:00
}
2017-02-22 10:49:25 +00:00
$doc_link = doc_link ( array ( 'sql' => 'show-table-status.html' ));
2018-01-12 12:54:08 +00:00
echo " <table cellspacing='0' class='nowrap checkable'> \n " ;
2018-01-12 14:27:44 +00:00
echo script ( " mixin(qsl('table'), { onclick: tableClick, ondblclick: partialArg(tableClick, true)}); " );
2018-01-12 17:34:19 +00:00
echo '<thead><tr class="wrap">' ;
echo '<td><input id="check-all" type="checkbox" class="jsonly">' . script ( " qs('#check-all').onclick = partial(formCheck, /^(tables|views) \ [/); " , " " );
2011-08-09 11:14:24 +00:00
echo '<th>' . lang ( 'Table' );
2014-11-04 17:48:21 +00:00
echo '<td>' . lang ( 'Engine' ) . doc_link ( array ( 'sql' => 'storage-engines.html' ));
echo '<td>' . lang ( 'Collation' ) . doc_link ( array ( 'sql' => 'charset-mysql.html' ));
echo '<td>' . lang ( 'Data Length' ) . $doc_link ;
echo '<td>' . lang ( 'Index Length' ) . $doc_link ;
echo '<td>' . lang ( 'Data Free' ) . $doc_link ;
echo '<td>' . lang ( 'Auto Increment' ) . doc_link ( array ( 'sql' => 'example-auto-increment.html' ));
echo '<td>' . lang ( 'Rows' ) . $doc_link ;
echo ( support ( " comment " ) ? '<td>' . lang ( 'Comment' ) . $doc_link : '' );
2011-08-09 11:14:24 +00:00
echo " </thead> \n " ;
2013-07-24 23:26:41 +00:00
2013-07-10 17:20:12 +00:00
$tables = 0 ;
2011-01-06 08:30:07 +00:00
foreach ( $tables_list as $name => $type ) {
2013-07-24 23:26:41 +00:00
$view = ( $type !== null && ! preg_match ( '~table~i' , $type ));
2017-01-23 22:05:47 +00:00
$id = h ( " Table- " . $name );
echo '<tr' . odd () . '><td>' . checkbox (( $view ? " views[] " : " tables[] " ), $name , in_array ( $name , $tables_views , true ), " " , " formUncheck('check-all'); " , " " , $id );
echo '<th>' . ( support ( " table " ) || support ( " indexes " ) ? " <a href=' " . h ( ME ) . " table= " . urlencode ( $name ) . " ' title=' " . lang ( 'Show structure' ) . " ' id=' $id '> " . h ( $name ) . '</a>' : h ( $name ));
2011-01-06 08:30:07 +00:00
if ( $view ) {
2017-02-20 11:13:09 +00:00
echo '<td colspan="6"><a href="' . h ( ME ) . " view= " . urlencode ( $name ) . '" title="' . lang ( 'Alter view' ) . '">' . ( preg_match ( '~materialized~i' , $type ) ? lang ( 'Materialized view' ) : lang ( 'View' )) . '</a>' ;
2011-08-09 11:14:24 +00:00
echo '<td align="right"><a href="' . h ( ME ) . " select= " . urlencode ( $name ) . '" title="' . lang ( 'Select data' ) . '">?</a>' ;
2011-01-06 08:30:07 +00:00
} else {
2011-08-09 11:14:24 +00:00
foreach ( array (
" Engine " => array (),
" Collation " => array (),
" Data_length " => array ( " create " , lang ( 'Alter table' )),
" Index_length " => array ( " indexes " , lang ( 'Alter indexes' )),
" Data_free " => array ( " edit " , lang ( 'New item' )),
" Auto_increment " => array ( " auto_increment=1&create " , lang ( 'Alter table' )),
" Rows " => array ( " select " , lang ( 'Select data' )),
) as $key => $link ) {
2013-07-06 17:31:21 +00:00
$id = " id=' $key - " . h ( $name ) . " ' " ;
2014-01-09 08:06:59 +00:00
echo ( $link ? " <td align='right'> " . ( support ( " table " ) || $key == " Rows " || ( support ( " indexes " ) && $key != " Data_length " )
2013-07-06 17:31:21 +00:00
? " <a href=' " . h ( ME . " $link[0] = " ) . urlencode ( $name ) . " ' $id title=' $link[1] '>?</a> "
: " <span $id >?</span> "
) : " <td id=' $key - " . h ( $name ) . " '> " );
2011-01-06 08:30:07 +00:00
}
2013-07-10 17:20:12 +00:00
$tables ++ ;
2010-05-05 16:30:55 +00:00
}
2011-01-06 08:30:07 +00:00
echo ( support ( " comment " ) ? " <td id='Comment- " . h ( $name ) . " '> " : " " );
2010-04-21 12:01:32 +00:00
}
2013-07-24 23:26:41 +00:00
2011-01-06 08:30:07 +00:00
echo " <tr><td> <th> " . lang ( '%d in total' , count ( $tables_list ));
2011-03-11 10:49:38 +00:00
echo " <td> " . nbsp ( $jush == " sql " ? $connection -> result ( " SELECT @@storage_engine " ) : " " );
2011-01-06 08:30:07 +00:00
echo " <td> " . nbsp ( db_collation ( DB , collations ()));
foreach ( array ( " Data_length " , " Index_length " , " Data_free " ) as $key ) {
echo " <td align='right' id='sum- $key '> " ;
2010-05-05 16:30:55 +00:00
}
2013-07-24 23:26:41 +00:00
2011-01-06 08:30:07 +00:00
echo " </table> \n " ;
if ( ! information_schema ( DB )) {
2018-01-12 17:11:00 +00:00
$vacuum = " <input type='submit' value=' " . lang ( 'Vacuum' ) . " '> " . on_help ( " 'VACUUM' " );
$optimize = " <input type='submit' name='optimize' value=' " . lang ( 'Optimize' ) . " '> " . on_help ( $jush == " sql " ? " 'OPTIMIZE TABLE' " : " 'VACUUM OPTIMIZE' " );
2013-07-09 19:06:53 +00:00
echo " <fieldset><legend> " . lang ( 'Selected' ) . " <span id='selected'></span></legend><div> "
2013-07-19 17:35:31 +00:00
. ( $jush == " sqlite " ? $vacuum
: ( $jush == " pgsql " ? $vacuum . $optimize
2018-01-12 17:11:00 +00:00
: ( $jush == " sql " ? " <input type='submit' value=' " . lang ( 'Analyze' ) . " '> " . on_help ( " 'ANALYZE TABLE' " ) . $optimize
. " <input type='submit' name='check' value=' " . lang ( 'Check' ) . " '> " . on_help ( " 'CHECK TABLE' " )
. " <input type='submit' name='repair' value=' " . lang ( 'Repair' ) . " '> " . on_help ( " 'REPAIR TABLE' " )
2013-07-17 01:37:33 +00:00
: " " )))
2018-01-12 17:11:00 +00:00
. " <input type='submit' name='truncate' value=' " . lang ( 'Truncate' ) . " '> " . on_help ( $jush == " sqlite " ? " 'DELETE' " : " 'TRUNCATE " . ( $jush == " pgsql " ? " ' " : " TABLE' " )) . confirm ()
. " <input type='submit' name='drop' value=' " . lang ( 'Drop' ) . " '> " . on_help ( " 'DROP TABLE' " ) . confirm () . " \n " ;
2013-10-25 05:16:24 +00:00
$databases = ( support ( " scheme " ) ? $adminer -> schemas () : $adminer -> databases ());
2011-01-06 08:30:07 +00:00
if ( count ( $databases ) != 1 && $jush != " sqlite " ) {
$db = ( isset ( $_POST [ " target " ]) ? $_POST [ " target " ] : ( support ( " scheme " ) ? $_GET [ " ns " ] : DB ));
2011-02-01 09:16:31 +00:00
echo " <p> " . lang ( 'Move to other database' ) . " : " ;
2013-01-31 05:35:51 +00:00
echo ( $databases ? html_select ( " target " , $databases , $db ) : '<input name="target" value="' . h ( $db ) . '" autocapitalize="off">' );
2012-05-14 09:16:10 +00:00
echo " <input type='submit' name='move' value=' " . lang ( 'Move' ) . " '> " ;
echo ( support ( " copy " ) ? " <input type='submit' name='copy' value=' " . lang ( 'Copy' ) . " '> " : " " );
2011-02-01 13:12:22 +00:00
echo " \n " ;
2011-01-06 08:30:07 +00:00
}
2018-01-12 15:29:18 +00:00
echo " <input type='hidden' name='all' value=''> " ; // used by trCheck()
echo script ( " qsl('input').onclick = function () { selectCount('selected', formChecked(this, /^(tables|views) \ [/)); " . ( support ( " table " ) ? " selectCount('selected2', formChecked(this, /^tables \ [/) || $tables ); " : " " ) . " } " );
2011-03-08 12:43:05 +00:00
echo " <input type='hidden' name='token' value=' $token '> \n " ;
2013-07-09 19:06:53 +00:00
echo " </div></fieldset> \n " ;
2011-01-06 08:30:07 +00:00
}
echo " </form> \n " ;
2018-01-12 14:27:44 +00:00
echo script ( " tableCheck(); " );
2011-01-06 08:30:07 +00:00
}
2013-07-24 23:26:41 +00:00
2013-07-09 06:51:50 +00:00
echo '<p class="links"><a href="' . h ( ME ) . 'create=">' . lang ( 'Create table' ) . " </a> \n " ;
echo ( support ( " view " ) ? '<a href="' . h ( ME ) . 'view=">' . lang ( 'Create view' ) . " </a> \n " : " " );
2013-07-24 23:26:41 +00:00
2011-01-06 08:30:07 +00:00
if ( support ( " routine " )) {
2013-04-28 06:17:07 +00:00
echo " <h3 id='routines'> " . lang ( 'Routines' ) . " </h3> \n " ;
2011-01-06 08:30:07 +00:00
$routines = routines ();
if ( $routines ) {
echo " <table cellspacing='0'> \n " ;
echo '<thead><tr><th>' . lang ( 'Name' ) . '<td>' . lang ( 'Type' ) . '<td>' . lang ( 'Return type' ) . " <td> </thead> \n " ;
odd ( '' );
foreach ( $routines as $row ) {
2018-01-30 14:18:26 +00:00
$name = ( $row [ " SPECIFIC_NAME " ] == $row [ " ROUTINE_NAME " ] ? " " : " &name= " . urlencode ( $row [ " ROUTINE_NAME " ])); // not computed on the pages to be able to print the header first
2011-01-06 08:30:07 +00:00
echo '<tr' . odd () . '>' ;
2018-01-30 14:18:26 +00:00
echo '<th><a href="' . h ( ME . ( $row [ " ROUTINE_TYPE " ] != " PROCEDURE " ? 'callf=' : 'call=' ) . urlencode ( $row [ " SPECIFIC_NAME " ]) . $name ) . '">' . h ( $row [ " ROUTINE_NAME " ]) . '</a>' ;
2011-01-06 08:30:07 +00:00
echo '<td>' . h ( $row [ " ROUTINE_TYPE " ]);
echo '<td>' . h ( $row [ " DTD_IDENTIFIER " ]);
2018-01-30 14:18:26 +00:00
echo '<td><a href="' . h ( ME . ( $row [ " ROUTINE_TYPE " ] != " PROCEDURE " ? 'function=' : 'procedure=' ) . urlencode ( $row [ " SPECIFIC_NAME " ]) . $name ) . '">' . lang ( 'Alter' ) . " </a> " ;
2011-01-06 08:30:07 +00:00
}
echo " </table> \n " ;
2010-05-05 16:30:55 +00:00
}
2013-07-09 06:51:50 +00:00
echo '<p class="links">'
. ( support ( " procedure " ) ? '<a href="' . h ( ME ) . 'procedure=">' . lang ( 'Create procedure' ) . '</a>' : '' )
. '<a href="' . h ( ME ) . 'function=">' . lang ( 'Create function' ) . " </a> \n "
;
2009-06-11 16:53:28 +00:00
}
2013-07-24 23:26:41 +00:00
2011-01-06 08:30:07 +00:00
if ( support ( " sequence " )) {
2013-04-28 06:17:07 +00:00
echo " <h3 id='sequences'> " . lang ( 'Sequences' ) . " </h3> \n " ;
2015-01-06 15:00:14 +00:00
$sequences = get_vals ( " SELECT sequence_name FROM information_schema.sequences WHERE sequence_schema = current_schema() ORDER BY sequence_name " );
2011-01-06 08:30:07 +00:00
if ( $sequences ) {
echo " <table cellspacing='0'> \n " ;
echo " <thead><tr><th> " . lang ( 'Name' ) . " </thead> \n " ;
odd ( '' );
foreach ( $sequences as $val ) {
echo " <tr " . odd () . " ><th><a href=' " . h ( ME ) . " sequence= " . urlencode ( $val ) . " '> " . h ( $val ) . " </a> \n " ;
}
echo " </table> \n " ;
2010-05-05 21:01:57 +00:00
}
2013-07-09 23:44:00 +00:00
echo " <p class='links'><a href=' " . h ( ME ) . " sequence='> " . lang ( 'Create sequence' ) . " </a> \n " ;
2010-05-05 21:01:57 +00:00
}
2013-07-24 23:26:41 +00:00
2011-01-06 08:30:07 +00:00
if ( support ( " type " )) {
2013-04-28 06:17:07 +00:00
echo " <h3 id='user-types'> " . lang ( 'User types' ) . " </h3> \n " ;
2013-02-20 00:46:29 +00:00
$user_types = types ();
if ( $user_types ) {
2011-01-06 08:30:07 +00:00
echo " <table cellspacing='0'> \n " ;
echo " <thead><tr><th> " . lang ( 'Name' ) . " </thead> \n " ;
odd ( '' );
2013-02-20 00:46:29 +00:00
foreach ( $user_types as $val ) {
2011-01-06 08:30:07 +00:00
echo " <tr " . odd () . " ><th><a href=' " . h ( ME ) . " type= " . urlencode ( $val ) . " '> " . h ( $val ) . " </a> \n " ;
}
echo " </table> \n " ;
2010-05-21 14:07:22 +00:00
}
2013-07-09 23:44:00 +00:00
echo " <p class='links'><a href=' " . h ( ME ) . " type='> " . lang ( 'Create type' ) . " </a> \n " ;
2010-05-21 14:07:22 +00:00
}
2013-07-24 23:26:41 +00:00
2011-01-06 08:30:07 +00:00
if ( support ( " event " )) {
2013-04-28 06:17:07 +00:00
echo " <h3 id='events'> " . lang ( 'Events' ) . " </h3> \n " ;
2011-01-06 08:30:07 +00:00
$rows = get_rows ( " SHOW EVENTS " );
if ( $rows ) {
echo " <table cellspacing='0'> \n " ;
2013-01-31 07:46:55 +00:00
echo " <thead><tr><th> " . lang ( 'Name' ) . " <td> " . lang ( 'Schedule' ) . " <td> " . lang ( 'Start' ) . " <td> " . lang ( 'End' ) . " <td></thead> \n " ;
2011-01-06 08:30:07 +00:00
foreach ( $rows as $row ) {
echo " <tr> " ;
2013-01-31 07:46:55 +00:00
echo " <th> " . h ( $row [ " Name " ]);
2011-01-06 08:30:07 +00:00
echo " <td> " . ( $row [ " Execute at " ] ? lang ( 'At given time' ) . " <td> " . $row [ " Execute at " ] : lang ( 'Every' ) . " " . $row [ " Interval value " ] . " " . $row [ " Interval field " ] . " <td> $row[Starts] " );
echo " <td> $row[Ends] " ;
2013-01-31 07:46:55 +00:00
echo '<td><a href="' . h ( ME ) . 'event=' . urlencode ( $row [ " Name " ]) . '">' . lang ( 'Alter' ) . '</a>' ;
2011-01-06 08:30:07 +00:00
}
echo " </table> \n " ;
2012-05-14 00:40:36 +00:00
$event_scheduler = $connection -> result ( " SELECT @@event_scheduler " );
if ( $event_scheduler && $event_scheduler != " ON " ) {
echo " <p class='error'><code class='jush-sqlset'>event_scheduler</code>: " . h ( $event_scheduler ) . " \n " ;
}
2010-04-21 12:01:32 +00:00
}
2013-07-09 23:44:00 +00:00
echo '<p class="links"><a href="' . h ( ME ) . 'event=">' . lang ( 'Create event' ) . " </a> \n " ;
2011-01-06 08:30:07 +00:00
}
2013-07-24 23:26:41 +00:00
2011-01-06 08:30:07 +00:00
if ( $tables_list ) {
2018-01-12 14:27:44 +00:00
echo script ( " ajaxSetHtml(' " . js_escape ( ME ) . " script=db'); " );
2010-05-05 16:30:55 +00:00
}
2010-10-18 00:15:13 +00:00
}
2010-04-21 12:01:32 +00:00
}