2009-07-03 04:40:48 +00:00
< ? php
2009-07-27 11:25:37 +00:00
class Adminer {
2010-04-21 12:01:32 +00:00
/** @var array operators used in select, null for all operators */
var $operators ;
2009-07-27 11:25:37 +00:00
/** Name in title and navigation
* @ return string
*/
function name () {
2009-08-25 15:42:43 +00:00
return " Adminer " ;
2009-07-27 11:25:37 +00:00
}
/** Connection parameters
* @ return array ( $server , $username , $password )
*/
function credentials () {
2010-10-15 08:58:08 +00:00
return array ( SERVER , $_GET [ " username " ], get_session ( " pwds " ));
2009-07-27 11:25:37 +00:00
}
2009-12-18 17:39:48 +00:00
/** Get key used for permanent login
* @ return string cryptic string which gets combined with password
*/
function permanentLogin () {
2010-05-06 13:45:34 +00:00
return password_file ();
2009-12-18 17:39:48 +00:00
}
2009-07-27 11:25:37 +00:00
/** Identifier of selected database
* @ return string
*/
function database () {
2009-08-29 13:54:25 +00:00
// should be used everywhere instead of DB
return DB ;
2009-07-27 11:25:37 +00:00
}
2010-10-17 20:13:32 +00:00
/** Headers to send before HTML output
* @ return null
*/
function headers () {
header ( " X-Frame-Options: deny " ); // ClickJacking protection in IE8, Safari 4, Chrome 2, Firefox NoScript plugin
}
2009-07-27 11:25:37 +00:00
/** Print login form
* @ return null
*/
2010-04-21 12:01:32 +00:00
function loginForm () {
2010-10-13 15:53:59 +00:00
global $drivers ;
2009-07-21 12:19:25 +00:00
?>
2009-07-21 15:25:05 +00:00
< table cellspacing = " 0 " >
2010-05-28 09:13:37 +00:00
< tr >< th >< ? php echo lang ( 'System' ); ?> <td><?php echo html_select("driver", $drivers, DRIVER); ?>
2010-04-21 12:01:32 +00:00
< tr >< th >< ? php echo lang ( 'Server' ); ?> <td><input name="server" value="<?php echo h(SERVER); ?>">
2010-04-26 16:21:28 +00:00
< tr >< th >< ? php echo lang ( 'Username' ); ?> <td><input id="username" name="username" value="<?php echo h($_GET["username"]); ?>">
2009-07-21 15:25:05 +00:00
< tr >< th >< ? php echo lang ( 'Password' ); ?> <td><input type="password" name="password">
</ table >
2010-04-26 16:21:28 +00:00
< script type = " text/javascript " >
document . getElementById ( 'username' ) . focus ();
</ script >
2009-07-21 12:19:25 +00:00
< ? php
2009-12-18 17:49:21 +00:00
echo " <p><input type='submit' value=' " . lang ( 'Login' ) . " '> \n " ;
2010-05-06 13:45:34 +00:00
echo checkbox ( " permanent " , 1 , $_COOKIE [ " adminer_permanent " ], lang ( 'Permanent login' )) . " \n " ;
2009-07-21 12:19:25 +00:00
}
2009-07-27 11:25:37 +00:00
/** Authorize the user
* @ param string
* @ param string
* @ return bool
*/
function login ( $login , $password ) {
return true ;
2009-07-24 10:14:36 +00:00
}
2009-07-27 11:25:37 +00:00
/** Table caption used in navigation and headings
* @ param array result of SHOW TABLE STATUS
* @ return string
*/
function tableName ( $tableStatus ) {
2009-07-28 16:20:50 +00:00
return h ( $tableStatus [ " Name " ]);
2009-07-27 11:25:37 +00:00
}
/** Field caption used in select and edit
* @ param array single field returned from fields ()
2009-07-27 16:51:40 +00:00
* @ param int order of column in select
2009-07-27 11:25:37 +00:00
* @ return string
*/
2009-07-27 16:51:40 +00:00
function fieldName ( $field , $order = 0 ) {
2009-07-28 16:20:50 +00:00
return '<span title="' . h ( $field [ " full_type " ]) . '">' . h ( $field [ " field " ]) . '</span>' ;
2009-07-27 11:25:37 +00:00
}
2009-09-20 07:31:46 +00:00
/** Print links after select heading
2009-07-27 11:25:37 +00:00
* @ param array result of SHOW TABLE STATUS
2009-11-24 09:44:28 +00:00
* @ param string new item options , NULL for no new item
2009-09-20 07:31:46 +00:00
* @ return null
2009-07-27 11:25:37 +00:00
*/
2009-09-20 07:31:46 +00:00
function selectLinks ( $tableStatus , $set = " " ) {
2009-11-24 09:44:28 +00:00
echo '<p class="tabs">' ;
2009-11-27 13:44:44 +00:00
$links = array ( " select " => lang ( 'Select data' ), " table " => lang ( 'Show structure' ));
2010-05-27 11:31:08 +00:00
if ( is_view ( $tableStatus )) {
2009-11-24 09:44:28 +00:00
$links [ " view " ] = lang ( 'Alter view' );
2010-04-21 12:01:32 +00:00
} else {
$links [ " create " ] = lang ( 'Alter table' );
2009-09-20 07:31:46 +00:00
}
if ( isset ( $set )) {
2009-11-24 09:44:28 +00:00
$links [ " edit " ] = lang ( 'New item' );
}
foreach ( $links as $key => $val ) {
2009-11-26 12:14:39 +00:00
echo " <a href=' " . h ( ME ) . " $key = " . urlencode ( $tableStatus [ " Name " ]) . ( $key == " edit " ? $set : " " ) . " '> " . bold ( $val , isset ( $_GET [ $key ])) . " </a> " ;
2009-09-20 07:31:46 +00:00
}
echo " \n " ;
2009-07-27 11:25:37 +00:00
}
/** Find backward keys for table
* @ param string
2009-09-23 14:28:06 +00:00
* @ param string
* @ return array $return [ $target_table ][ " keys " ][ $key_name ][ $target_column ] = $source_column ; $return [ $target_table ][ " name " ] = $this -> tableName ( $target_table );
2009-07-27 11:25:37 +00:00
*/
2009-09-23 14:28:06 +00:00
function backwardKeys ( $table , $tableName ) {
2009-07-27 11:25:37 +00:00
return array ();
}
2009-09-23 14:28:06 +00:00
/** Print backward keys for row
* @ param array result of $this -> backwardKeys ()
* @ param array
* @ return null
*/
function backwardKeysPrint ( $backwardKeys , $row ) {
}
2009-07-27 11:25:37 +00:00
/** Query printed in select before execution
* @ param string query to be executed
* @ return string
*/
function selectQuery ( $query ) {
2010-05-07 13:44:22 +00:00
global $jush ;
2010-10-18 20:39:17 +00:00
return " <p><a href=' " . h ( remove_from_uri ( " page " )) . " &page=last' title=' " . lang ( 'Page' ) . " : " . lang ( 'last' ) . " ' onclick='return !ajaxMain(this.href);'>>></a> <code class='jush- $jush '> " . h ( str_replace ( " \n " , " " , $query )) . " </code> <a href=' " . h ( ME ) . " sql= " . urlencode ( $query ) . " '> " . lang ( 'Edit' ) . " </a> " . ( is_ajax () ? " <a href=' " . h ( $_SERVER [ " REQUEST_URI " ]) . " '>#</a> " : " " ) . " \n " ;
2009-07-27 11:25:37 +00:00
}
/** Description of a row in a table
* @ param string
* @ return string SQL expression , empty string for no description
*/
function rowDescription ( $table ) {
return " " ;
}
/** Get descriptions of selected data
* @ param array all data to print
* @ param array
* @ return array
*/
function rowDescriptions ( $rows , $foreignKeys ) {
return $rows ;
}
/** Value printed in select table
2009-07-27 16:32:56 +00:00
* @ param string HTML - escaped value to print
2009-07-27 11:25:37 +00:00
* @ param string link to foreign key
* @ param array single field returned from fields ()
* @ return string
*/
function selectVal ( $val , $link , $field ) {
2010-09-28 08:02:55 +00:00
$return = ( $val != " <i>NULL</i> " && ereg ( " ^char|binary " , $field [ " type " ]) ? " <code> $val </code> " : $val );
if ( ereg ( 'blob|bytea|raw|file' , $field [ " type " ]) && ! is_utf8 ( $val )) {
2010-09-27 15:05:45 +00:00
$return = lang ( '%d byte(s)' , strlen ( html_entity_decode ( $val , ENT_QUOTES )));
2009-07-23 11:31:08 +00:00
}
2009-07-30 14:55:09 +00:00
return ( $link ? " <a href=' $link '> $return </a> " : $return );
2009-07-27 11:25:37 +00:00
}
2009-07-27 16:32:56 +00:00
/** Value conversion used in select and edit
* @ param string
* @ param array single field returned from fields ()
2009-07-28 09:27:00 +00:00
* @ return string
2009-07-27 16:32:56 +00:00
*/
function editVal ( $val , $field ) {
2010-09-28 08:02:55 +00:00
return ( ereg ( " binary " , $field [ " type " ]) ? reset ( unpack ( " H* " , $val )) : $val );
2009-07-27 16:32:56 +00:00
}
2009-07-27 14:40:55 +00:00
/** Print columns box in select
* @ param array result of selectColumnsProcess ()
* @ param array selectable columns
* @ return null
*/
function selectColumnsPrint ( $select , $columns ) {
2010-04-21 12:01:32 +00:00
global $functions , $grouping ;
2009-09-11 19:26:27 +00:00
print_fieldset ( " select " , lang ( 'Select' ), $select );
2009-07-27 14:40:55 +00:00
$i = 0 ;
2010-04-21 12:01:32 +00:00
$fun_group = array ( lang ( 'Functions' ) => $functions , lang ( 'Aggregation' ) => $grouping );
2009-07-27 14:40:55 +00:00
foreach ( $select as $key => $val ) {
$val = $_GET [ " columns " ][ $key ];
2009-10-02 13:21:34 +00:00
echo " <div> " . html_select ( " columns[ $i ][fun] " , array ( - 1 => " " ) + $fun_group , $val [ " fun " ]);
2010-04-21 12:01:32 +00:00
echo " (<select name='columns[ $i ][col]'><option> " . optionlist ( $columns , $val [ " col " ], true ) . " </select>)</div> \n " ;
2009-07-27 14:40:55 +00:00
$i ++ ;
}
2010-04-21 12:01:32 +00:00
echo " <div> " . html_select ( " columns[ $i ][fun] " , array ( - 1 => " " ) + $fun_group , " " , " this.nextSibling.nextSibling.onchange(); " );
echo " (<select name='columns[ $i ][col]' onchange='selectAddRow(this);'><option> " . optionlist ( $columns , null , true ) . " </select>)</div> \n " ;
2009-07-27 14:40:55 +00:00
echo " </div></fieldset> \n " ;
}
/** Print search box in select
* @ param array result of selectSearchProcess ()
* @ param array selectable columns
* @ param array
* @ return null
*/
function selectSearchPrint ( $where , $columns , $indexes ) {
2009-09-11 19:26:27 +00:00
print_fieldset ( " search " , lang ( 'Search' ), $where );
2009-07-27 14:40:55 +00:00
foreach ( $indexes as $i => $index ) {
if ( $index [ " type " ] == " FULLTEXT " ) {
2009-07-28 16:20:50 +00:00
echo " (<i> " . implode ( " </i>, <i> " , array_map ( 'h' , $index [ " columns " ])) . " </i>) AGAINST " ;
echo " <input name='fulltext[ $i ]' value=' " . h ( $_GET [ " fulltext " ][ $i ]) . " '> " ;
2009-09-25 12:03:30 +00:00
echo checkbox ( " boolean[ $i ] " , 1 , isset ( $_GET [ " boolean " ][ $i ]), " BOOL " );
2009-07-27 14:40:55 +00:00
echo " <br> \n " ;
}
}
$i = 0 ;
foreach (( array ) $_GET [ " where " ] as $val ) {
2010-01-09 23:33:41 +00:00
if ( " $val[col] $val[val] " != " " && in_array ( $val [ " op " ], $this -> operators )) {
2010-04-21 12:01:32 +00:00
echo " <div><select name='where[ $i ][col]'><option value=''>( " . lang ( 'anywhere' ) . " ) " . optionlist ( $columns , $val [ " col " ], true ) . " </select> " ;
2009-10-02 13:21:34 +00:00
echo html_select ( " where[ $i ][op] " , $this -> operators , $val [ " op " ]);
2009-07-28 16:20:50 +00:00
echo " <input name='where[ $i ][val]' value=' " . h ( $val [ " val " ]) . " '></div> \n " ;
2009-07-27 14:40:55 +00:00
$i ++ ;
}
}
2010-04-21 12:01:32 +00:00
echo " <div><select name='where[ $i ][col]' onchange='selectAddRow(this);'><option value=''>( " . lang ( 'anywhere' ) . " ) " . optionlist ( $columns , null , true ) . " </select> " ;
2009-10-02 13:21:34 +00:00
echo html_select ( " where[ $i ][op] " , $this -> operators );
2009-07-27 14:40:55 +00:00
echo " <input name='where[ $i ][val]'></div> \n " ;
echo " </div></fieldset> \n " ;
}
/** Print order box in select
* @ param array result of selectOrderProcess ()
* @ param array selectable columns
* @ param array
* @ return null
*/
function selectOrderPrint ( $order , $columns , $indexes ) {
2009-09-11 19:26:27 +00:00
print_fieldset ( " sort " , lang ( 'Sort' ), $order );
2009-07-27 14:40:55 +00:00
$i = 0 ;
foreach (( array ) $_GET [ " order " ] as $key => $val ) {
if ( isset ( $columns [ $val ])) {
echo " <div><select name='order[ $i ]'><option> " . optionlist ( $columns , $val , true ) . " </select> " ;
2009-09-25 12:03:30 +00:00
echo checkbox ( " desc[ $i ] " , 1 , isset ( $_GET [ " desc " ][ $key ]), lang ( 'descending' )) . " </div> \n " ;
2009-07-27 14:40:55 +00:00
$i ++ ;
}
}
2009-12-17 13:22:28 +00:00
echo " <div><select name='order[ $i ]' onchange='selectAddRow(this);'><option> " . optionlist ( $columns , null , true ) . " </select> " ;
2009-09-25 12:03:30 +00:00
echo checkbox ( " desc[ $i ] " , 1 , 0 , lang ( 'descending' )) . " </div> \n " ;
2009-07-27 14:40:55 +00:00
echo " </div></fieldset> \n " ;
}
/** Print limit box in select
* @ param string result of selectLimitProcess ()
* @ return null
*/
function selectLimitPrint ( $limit ) {
echo " <fieldset><legend> " . lang ( 'Limit' ) . " </legend><div> " ; // <div> for easy styling
2009-07-28 16:20:50 +00:00
echo " <input name='limit' size='3' value=' " . h ( $limit ) . " '> " ;
2009-07-27 14:40:55 +00:00
echo " </div></fieldset> \n " ;
}
/** Print text length box in select
* @ param string result of selectLengthProcess ()
* @ return null
*/
function selectLengthPrint ( $text_length ) {
if ( isset ( $text_length )) {
echo " <fieldset><legend> " . lang ( 'Text length' ) . " </legend><div> " ;
2009-07-28 16:20:50 +00:00
echo '<input name="text_length" size="3" value="' . h ( $text_length ) . '">' ;
2009-07-27 14:40:55 +00:00
echo " </div></fieldset> \n " ;
}
}
/** Print action box in select
* @ return null
*/
function selectActionPrint () {
echo " <fieldset><legend> " . lang ( 'Action' ) . " </legend><div> " ;
echo " <input type='submit' value=' " . lang ( 'Select' ) . " '> " ;
echo " </div></fieldset> \n " ;
}
2009-07-28 11:18:08 +00:00
/** Print extra text in the end of a select form
* @ param array fields holding e - mails
2009-09-09 20:47:42 +00:00
* @ param array selectable columns
2009-07-28 11:18:08 +00:00
* @ return null
*/
2009-09-09 20:47:42 +00:00
function selectEmailPrint ( $emailFields , $columns ) {
2009-07-28 11:18:08 +00:00
}
2009-07-27 14:40:55 +00:00
/** Process columns box in select
* @ param array selectable columns
2009-09-09 20:47:42 +00:00
* @ param array
2009-07-27 14:40:55 +00:00
* @ return array ( array ( select_expressions ), array ( group_expressions ))
*/
function selectColumnsProcess ( $columns , $indexes ) {
2010-04-21 12:01:32 +00:00
global $functions , $grouping ;
2009-07-27 14:40:55 +00:00
$select = array (); // select expressions, empty for *
$group = array (); // expressions without aggregation - will be used for GROUP BY if an aggregation function is used
foreach (( array ) $_GET [ " columns " ] as $key => $val ) {
2010-04-21 12:01:32 +00:00
if ( $val [ " fun " ] == " count " || ( isset ( $columns [ $val [ " col " ]]) && ( ! $val [ " fun " ] || in_array ( $val [ " fun " ], $functions ) || in_array ( $val [ " fun " ], $grouping )))) {
2009-07-27 14:40:55 +00:00
$select [ $key ] = apply_sql_function ( $val [ " fun " ], ( isset ( $columns [ $val [ " col " ]]) ? idf_escape ( $val [ " col " ]) : " * " ));
2010-04-21 12:01:32 +00:00
if ( ! in_array ( $val [ " fun " ], $grouping )) {
2009-07-27 14:40:55 +00:00
$group [] = $select [ $key ];
}
}
}
return array ( $select , $group );
}
/** Process search box in select
* @ param array
* @ param array
* @ return array expressions to join by AND
*/
2009-07-28 14:21:05 +00:00
function selectSearchProcess ( $fields , $indexes ) {
2010-10-13 16:04:40 +00:00
global $jush ;
2009-07-27 14:40:55 +00:00
$return = array ();
foreach ( $indexes as $i => $index ) {
2010-01-09 23:33:41 +00:00
if ( $index [ " type " ] == " FULLTEXT " && $_GET [ " fulltext " ][ $i ] != " " ) {
2010-10-13 16:04:40 +00:00
$return [] = " MATCH ( " . implode ( " , " , array_map ( 'idf_escape' , $index [ " columns " ])) . " ) AGAINST ( " . q ( $_GET [ " fulltext " ][ $i ]) . ( isset ( $_GET [ " boolean " ][ $i ]) ? " IN BOOLEAN MODE " : " " ) . " ) " ;
2009-07-27 14:40:55 +00:00
}
}
foreach (( array ) $_GET [ " where " ] as $val ) {
2010-01-09 23:33:41 +00:00
if ( " $val[col] $val[val] " != " " && in_array ( $val [ " op " ], $this -> operators )) {
2010-04-21 12:01:32 +00:00
$cond = " $val[op] " ;
if ( ereg ( 'IN$' , $val [ " op " ])) {
$in = process_length ( $val [ " val " ]);
$cond .= " ( " . ( $in != " " ? $in : " NULL " ) . " ) " ;
} elseif ( $val [ " op " ] == " LIKE %% " ) {
$cond = " LIKE " . $this -> processInput ( $fields [ $val [ " col " ]], " % $val[val] % " );
} elseif ( ! ereg ( 'NULL$' , $val [ " op " ])) {
$cond .= " " . $this -> processInput ( $fields [ $val [ " col " ]], $val [ " val " ]);
}
2010-01-09 23:33:41 +00:00
if ( $val [ " col " ] != " " ) {
2009-07-28 13:43:38 +00:00
$return [] = idf_escape ( $val [ " col " ]) . $cond ;
2009-07-27 14:40:55 +00:00
} else {
2009-07-28 13:43:38 +00:00
// find anywhere
$cols = array ();
foreach ( $fields as $name => $field ) {
if ( is_numeric ( $val [ " val " ]) || ! ereg ( 'int|float|double|decimal' , $field [ " type " ])) {
2010-01-15 13:58:29 +00:00
$name = idf_escape ( $name );
2010-05-27 14:10:17 +00:00
$cols [] = ( $jush == " sql " && ereg ( 'char|text|enum|set' , $field [ " type " ]) && ! ereg ( '^utf8' , $field [ " collation " ]) ? " CONVERT( $name USING utf8) " : $name );
2009-07-27 14:40:55 +00:00
}
}
2010-01-15 13:58:29 +00:00
$return [] = ( $cols ? " ( " . implode ( " $cond OR " , $cols ) . " $cond ) " : " 0 " );
2009-07-27 14:40:55 +00:00
}
}
}
return $return ;
}
/** Process order box in select
* @ param array
* @ param array
* @ return array expressions to join by comma
*/
2009-07-28 14:21:05 +00:00
function selectOrderProcess ( $fields , $indexes ) {
2009-07-27 14:40:55 +00:00
$return = array ();
foreach (( array ) $_GET [ " order " ] as $key => $val ) {
2010-04-21 12:01:32 +00:00
if ( isset ( $fields [ $val ]) || preg_match ( '~^((COUNT\\(DISTINCT |[A-Z0-9_]+\\()(`(?:[^`]|``)+`|"(?:[^"]|"")+")\\)|COUNT\\(\\*\\))$~' , $val )) { //! MS SQL uses []
$return [] = ( isset ( $fields [ $val ]) ? idf_escape ( $val ) : $val ) . ( isset ( $_GET [ " desc " ][ $key ]) ? " DESC " : " " );
2009-07-27 14:40:55 +00:00
}
}
return $return ;
}
/** Process limit box in select
* @ return string expression to use in LIMIT , will be escaped
*/
function selectLimitProcess () {
return ( isset ( $_GET [ " limit " ]) ? $_GET [ " limit " ] : " 30 " );
}
/** Process length box in select
* @ return string number of characters to shorten texts , will be escaped
*/
function selectLengthProcess () {
return ( isset ( $_GET [ " text_length " ]) ? $_GET [ " text_length " ] : " 100 " );
}
2009-07-27 11:25:37 +00:00
/** Process extras in select form
* @ param array AND conditions
2009-09-09 20:19:27 +00:00
* @ param array
2009-07-27 11:25:37 +00:00
* @ return bool true if processed , false to process other parts of form
*/
2009-09-09 20:19:27 +00:00
function selectEmailProcess ( $where , $foreignKeys ) {
2009-07-27 11:25:37 +00:00
return false ;
}
/** Query printed after execution in the message
* @ param string executed query
* @ return string
*/
function messageQuery ( $query ) {
2010-05-07 13:44:22 +00:00
global $jush ;
2009-11-03 10:55:57 +00:00
restart_session ();
2009-07-27 11:25:37 +00:00
$id = " sql- " . count ( $_SESSION [ " messages " ]);
2010-10-15 08:58:08 +00:00
$history = & get_session ( " queries " );
2010-05-12 16:23:40 +00:00
$history [ $_GET [ " db " ]][] = ( strlen ( $query ) > 1e6 // not DB - reset in drop database
? ereg_replace ( '[\x80-\xFF]+$' , '' , substr ( $query , 0 , 1e6 )) . " \n ... " // [\x80-\xFF] - valid UTF-8, \n - can end by one-line comment
: $query
); //! respect $_GET["ns"]
return " <a href='# $id ' onclick= \" return !toggle(' $id '); \" > " . lang ( 'SQL command' ) . " </a><div id=' $id ' class='hidden'><pre class='jush- $jush '> " . shorten_utf8 ( $query , 1000 ) . '</pre><p><a href="' . h ( str_replace ( " db= " . urlencode ( DB ), " db= " . urlencode ( $_GET [ " db " ]), ME ) . 'sql=&history=' . ( count ( $history [ $_GET [ " db " ]]) - 1 )) . '">' . lang ( 'Edit' ) . '</a></div>' ;
2009-07-27 11:25:37 +00:00
}
/** Functions displayed in edit form
* @ param array single field from fields ()
* @ return array
*/
function editFunctions ( $field ) {
2010-04-21 12:01:32 +00:00
global $edit_functions ;
2010-04-22 00:33:46 +00:00
$return = ( $field [ " null " ] ? " NULL/ " : " " );
2010-04-21 12:01:32 +00:00
foreach ( $edit_functions as $key => $functions ) {
if ( ! $key || ( ! isset ( $_GET [ " call " ]) && ( isset ( $_GET [ " select " ]) || where ( $_GET )))) { // relative functions
foreach ( $functions as $pattern => $val ) {
if ( ! $pattern || ereg ( $pattern , $field [ " type " ])) {
$return .= " / $val " ;
}
}
2009-08-28 14:09:53 +00:00
}
2009-07-23 11:31:08 +00:00
}
2010-04-21 12:01:32 +00:00
return explode ( " / " , $return );
2009-07-23 11:31:08 +00:00
}
2009-07-27 11:25:37 +00:00
/** Get options to display edit field
* @ param string table name
* @ param array single field from fields ()
2009-07-28 10:09:05 +00:00
* @ param string attributes to use inside the tag
* @ param string
* @ return string custom input field or empty string for default
2009-07-27 11:25:37 +00:00
*/
2009-07-28 10:09:05 +00:00
function editInput ( $table , $field , $attrs , $value ) {
2009-11-12 15:25:21 +00:00
if ( $field [ " type " ] == " enum " ) {
2010-05-20 21:05:25 +00:00
return ( $field [ " null " ] ? " <label><input type='radio' $attrs value='' " . ( isset ( $value ) || isset ( $_GET [ " select " ]) ? " " : " checked " ) . " ><i>NULL</i></label> " : " " )
. " <label><input type='radio' $attrs value='0' " . ( $value === 0 ? " checked " : " " ) . " ><i> " . lang ( 'empty' ) . " </i></label> "
2009-11-12 15:25:21 +00:00
;
}
return " " ;
2009-07-23 11:31:08 +00:00
}
2009-07-27 11:25:37 +00:00
/** Process sent input
* @ param array single field from fields ()
2009-07-27 16:32:56 +00:00
* @ param string
* @ param string
2009-07-27 11:25:37 +00:00
* @ return string expression to use in a query
*/
2009-07-27 16:32:56 +00:00
function processInput ( $field , $value , $function = " " ) {
$name = $field [ " field " ];
2010-10-13 16:04:40 +00:00
$return = q ( $value );
2010-04-21 12:01:32 +00:00
if ( ereg ( '^(now|getdate|uuid)$' , $function )) {
2009-07-27 11:25:37 +00:00
$return = " $function () " ;
2010-05-17 22:49:37 +00:00
} elseif ( ereg ( '^current_(date|timestamp)$' , $function )) {
$return = $function ;
2010-04-21 12:01:32 +00:00
} elseif ( ereg ( '^([+-]|\\|\\|)$' , $function )) {
2009-07-27 11:25:37 +00:00
$return = idf_escape ( $name ) . " $function $return " ;
} elseif ( ereg ( '^[+-] interval$' , $function )) {
$return = idf_escape ( $name ) . " $function " . ( preg_match ( " ~^([0-9]+|'[0-9.: -]') [A-Z_]+ $ ~i " , $value ) ? $value : $return );
2009-08-28 14:09:53 +00:00
} elseif ( ereg ( '^(addtime|subtime|concat)$' , $function )) {
2009-07-27 11:25:37 +00:00
$return = " $function ( " . idf_escape ( $name ) . " , $return ) " ;
2010-09-28 08:02:55 +00:00
} elseif ( ereg ( '^(md5|sha1|password|encrypt|hex)$' , $function )) {
2009-07-27 11:25:37 +00:00
$return = " $function ( $return ) " ;
}
2010-09-28 08:02:55 +00:00
if ( ereg ( " binary " , $field [ " type " ])) {
$return = " unhex( $return ) " ;
}
2009-07-27 11:25:37 +00:00
return $return ;
2009-07-23 16:22:50 +00:00
}
2009-07-27 11:25:37 +00:00
2009-10-02 12:21:55 +00:00
/** Returns export output options
* @ param bool generate select ( otherwise radio )
2010-04-21 12:01:32 +00:00
* @ param string
2009-10-02 12:21:55 +00:00
* @ return string
*/
2010-04-21 12:01:32 +00:00
function dumpOutput ( $select , $value = " " ) {
2009-10-02 12:21:55 +00:00
$return = array ( 'text' => lang ( 'open' ), 'file' => lang ( 'save' ));
if ( function_exists ( 'gzencode' )) {
$return [ 'gz' ] = 'gzip' ;
}
if ( function_exists ( 'bzcompress' )) {
$return [ 'bz2' ] = 'bzip2' ;
}
// ZipArchive requires temporary file, ZIP can be created by gzcompress - see PEAR File_Archive
2010-04-21 12:01:32 +00:00
return html_select ( " output " , $return , $value , $select );
2009-10-02 12:21:55 +00:00
}
/** Returns export format options
* @ param bool generate select ( otherwise radio )
2010-04-21 12:01:32 +00:00
* @ param string
2009-10-02 12:21:55 +00:00
* @ return string
*/
2010-04-21 12:01:32 +00:00
function dumpFormat ( $select , $value = " " ) {
return html_select ( " format " , array ( 'sql' => 'SQL' , 'csv' => 'CSV,' , 'csv;' => 'CSV;' ), $value , $select );
2009-10-02 12:21:55 +00:00
}
2009-07-27 11:25:37 +00:00
/** Prints navigation after Adminer title
2010-10-18 00:15:58 +00:00
* @ param string can be " auth " if there is no database connection , " db " if there is no database selected , " ns " with invalid schema
2009-07-27 11:25:37 +00:00
* @ return null
*/
function navigation ( $missing ) {
2010-05-07 13:44:22 +00:00
global $VERSION , $connection , $token , $jush , $drivers ;
2009-09-19 20:16:15 +00:00
?>
< h1 >
< a href = " http://www.adminer.org/ " id = " h1 " >< ? php echo $this -> name (); ?> </a>
< span class = " version " >< ? php echo $VERSION ; ?> </span>
< a href = " http://www.adminer.org/#download " id = " version " >< ? php echo ( version_compare ( $VERSION , $_COOKIE [ " adminer_version " ]) < 0 ? h ( $_COOKIE [ " adminer_version " ]) : " " ); ?> </a>
</ h1 >
< ? php
2010-05-06 12:21:22 +00:00
if ( $missing == " auth " ) {
$first = true ;
2010-10-15 08:58:08 +00:00
foreach (( array ) $_SESSION [ " pwds " ] as $driver => $servers ) {
2010-05-06 12:21:22 +00:00
foreach ( $servers as $server => $usernames ) {
foreach ( $usernames as $username => $password ) {
if ( isset ( $password )) {
if ( $first ) {
echo " <p> \n " ;
$first = false ;
}
2010-05-07 13:44:22 +00:00
echo " <a href=' " . h ( auth_url ( $driver , $server , $username )) . " '>( $drivers[$driver] ) " . h ( $username . ( $server != " " ? " @ $server " : " " )) . " </a><br> \n " ;
2010-05-06 12:21:22 +00:00
}
}
}
}
} else {
2009-07-27 11:25:37 +00:00
$databases = get_databases ();
?>
2009-07-03 06:26:01 +00:00
< form action = " " method = " post " >
2009-10-28 12:21:21 +00:00
< p class = " logout " >
2010-10-18 05:38:23 +00:00
< ? php
if ( DB == " " || ! $missing ) {
echo " <a href=' " . h ( ME ) . " sql='> " . bold ( lang ( 'SQL command' ), isset ( $_GET [ " sql " ])) . " </a> \n " ;
if ( support ( " dump " )) {
echo " <a href=' " . h ( ME ) . " dump= " . urlencode ( isset ( $_GET [ " table " ]) ? $_GET [ " table " ] : $_GET [ " select " ]) . " '> " . bold ( lang ( 'Dump' ), isset ( $_GET [ " dump " ])) . " </a> \n " ;
}
}
?>
2010-04-21 12:01:32 +00:00
< input type = " hidden " name = " token " value = " <?php echo $token ; ?> " >
2009-07-11 20:30:40 +00:00
< input type = " submit " name = " logout " value = " <?php echo lang('Logout'); ?> " >
2009-07-14 11:09:39 +00:00
</ p >
2009-07-03 06:26:01 +00:00
</ form >
< form action = " " >
2009-08-30 22:21:36 +00:00
< p >
2010-04-21 12:01:32 +00:00
< ? php hidden_fields_get (); ?>
2009-10-02 13:21:34 +00:00
< ? php echo ( $databases ? html_select ( " db " , array ( " " => " ( " . lang ( 'database' ) . " ) " ) + $databases , DB , " this.form.submit(); " ) : '<input name="db" value="' . h ( DB ) . '">' ); ?>
2010-04-21 12:01:32 +00:00
< input type = " submit " value = " <?php echo lang('Use'); ?> " < ? php echo ( $databases ? " class='hidden' " : " " ); ?> >
2009-07-03 06:26:01 +00:00
< ? php
2010-01-09 23:33:41 +00:00
if ( $missing != " db " && DB != " " && $connection -> select_db ( DB )) {
2010-05-05 16:30:55 +00:00
if ( support ( " scheme " )) {
echo " <br> " . html_select ( " ns " , array ( " " => " ( " . lang ( 'schema' ) . " ) " ) + schemas (), $_GET [ " ns " ], " this.form.submit(); " );
if ( $_GET [ " ns " ] != " " ) {
set_schema ( $_GET [ " ns " ]);
2010-05-02 21:37:05 +00:00
}
2010-05-05 16:30:55 +00:00
}
2010-10-18 05:38:23 +00:00
if ( $_GET [ " ns " ] !== " " && ! $missing ) {
2010-05-05 16:30:55 +00:00
$tables = tables_list ();
if ( ! $tables ) {
echo " <p class='message'> " . lang ( 'No tables.' ) . " \n " ;
} else {
$this -> tablesPrint ( $tables );
$links = array ();
foreach ( $tables as $table => $type ) {
$links [] = preg_quote ( $table , '/' );
}
echo " <script type='text/javascript'> \n " ;
2010-05-07 13:44:22 +00:00
echo " var jushLinks = { $jush : [ ' " . addcslashes ( h ( ME ), " \\ '/ " ) . " table= \$ &', / \\ b( " . implode ( " | " , $links ) . " ) \\ b/g ] }; \n " ;
2010-05-05 16:30:55 +00:00
foreach ( array ( " bac " , " bra " , " sqlite_quo " , " mssql_bra " ) as $val ) {
2010-05-07 13:44:22 +00:00
echo " jushLinks. $val = jushLinks. $jush ; \n " ;
2010-05-05 16:30:55 +00:00
}
echo " </script> \n " ;
2010-05-03 16:09:43 +00:00
}
2010-05-05 16:30:55 +00:00
echo '<p><a href="' . h ( ME ) . 'create=">' . bold ( lang ( 'Create new table' ), $_GET [ " create " ] === " " ) . " </a> \n " ;
2009-09-23 15:01:17 +00:00
}
}
2010-05-05 16:30:55 +00:00
echo ( isset ( $_GET [ " sql " ]) ? '<input type="hidden" name="sql" value="">'
: ( isset ( $_GET [ " schema " ]) ? '<input type="hidden" name="schema" value="">'
: ( isset ( $_GET [ " dump " ]) ? '<input type="hidden" name="dump" value="">'
: " " )));
2010-05-11 14:45:04 +00:00
echo " </p></form> \n " ;
2009-09-19 20:16:15 +00:00
}
}
/** Prints table list in menu
2009-09-23 15:01:17 +00:00
* @ param array
2009-09-19 20:16:15 +00:00
* @ return null
*/
2009-09-23 15:01:17 +00:00
function tablesPrint ( $tables ) {
echo " <p id='tables'> \n " ;
2010-04-21 12:01:32 +00:00
foreach ( $tables as $table => $type ) {
2009-11-26 12:14:39 +00:00
echo '<a href="' . h ( ME ) . 'select=' . urlencode ( $table ) . '">' . bold ( lang ( 'select' ), $_GET [ " select " ] == $table ) . '</a> ' ;
echo '<a href="' . h ( ME ) . 'table=' . urlencode ( $table ) . '">' . bold ( $this -> tableName ( array ( " Name " => $table )), $_GET [ " table " ] == $table ) . " </a><br> \n " ; //! Adminer::tableName may work with full table status
2009-07-03 06:26:01 +00:00
}
}
2009-07-27 11:25:37 +00:00
2009-07-03 04:40:48 +00:00
}
2009-09-09 11:03:03 +00:00
$adminer = ( function_exists ( 'adminer_object' ) ? adminer_object () : new Adminer );
2010-04-21 12:01:32 +00:00
if ( ! isset ( $adminer -> operators )) {
$adminer -> operators = $operators ;
}