2007-07-02 05:51:26 +00:00
< ? php
2009-07-28 12:56:38 +00:00
$where = ( isset ( $_GET [ " select " ]) ? " " : where ( $_GET ));
$update = ( $where || $_POST [ " edit " ]);
2007-07-25 15:18:59 +00:00
$fields = fields ( $_GET [ " edit " ]);
foreach ( $fields as $name => $field ) {
2009-08-21 16:54:10 +00:00
if ( ! isset ( $field [ " privileges " ][ $update ? " update " : " insert " ]) || ! strlen ( $adminer -> fieldName ( $field ))) {
2007-07-25 15:18:59 +00:00
unset ( $fields [ $name ]);
2007-07-09 06:12:22 +00:00
}
2007-07-05 10:41:53 +00:00
}
2008-10-01 11:39:13 +00:00
if ( $_POST && ! $error && ! isset ( $_GET [ " select " ])) {
2009-08-03 13:37:29 +00:00
$location = $_SERVER [ " REQUEST_URI " ]; // continue edit or insert
if ( ! $_POST [ " insert " ]) {
2009-08-21 16:54:10 +00:00
$location = ME . " select= " . urlencode ( $_GET [ " edit " ]);
2009-08-03 13:37:29 +00:00
$i = 0 ; // append &set converted to &where
foreach (( array ) $_GET [ " set " ] as $key => $val ) {
if ( $val == $_POST [ " fields " ][ $key ]) {
$location .= where_link ( $i ++ , bracket_escape ( $key , " back " ), $val );
}
}
}
2009-07-23 16:31:28 +00:00
$set = array ();
foreach ( $fields as $name => $field ) {
2009-07-27 16:32:56 +00:00
$val = process_input ( $field );
2009-08-21 16:54:10 +00:00
if ( $val !== false || ! $update ) {
$set [] = " \n " . idf_escape ( $name ) . " = " . ( $val !== false ? $val : " '' " );
2007-07-02 05:51:26 +00:00
}
}
2009-07-23 16:31:28 +00:00
if ( ! $set ) {
redirect ( $location );
}
2009-08-21 16:54:10 +00:00
if ( $update ) {
2009-07-23 16:31:28 +00:00
query_redirect ( " UPDATE " . idf_escape ( $_GET [ " edit " ]) . " SET " . implode ( " , " , $set ) . " \n WHERE $where\nLIMIT 1 " , $location , lang ( 'Item has been updated.' ));
} else {
query_redirect ( " INSERT INTO " . idf_escape ( $_GET [ " edit " ]) . " SET " . implode ( " , " , $set ), $location , lang ( 'Item has been inserted.' ));
}
2007-07-02 05:51:26 +00:00
}
2009-07-11 19:45:57 +00:00
2009-07-27 11:25:37 +00:00
$table_name = $adminer -> tableName ( table_status ( $_GET [ " edit " ]));
2009-07-11 19:45:57 +00:00
page_header (
2009-08-21 16:54:10 +00:00
( $update ? lang ( 'Edit' ) : lang ( 'Insert' )),
2009-07-11 19:45:57 +00:00
$error ,
2009-08-21 16:54:10 +00:00
array ( " select " => array ( $_GET [ " edit " ], $table_name )),
2009-07-11 19:45:57 +00:00
$table_name
);
2007-07-02 05:51:26 +00:00
2008-07-10 15:39:24 +00:00
unset ( $row );
2009-06-07 23:53:51 +00:00
if ( $_POST [ " save " ]) {
2007-07-16 14:01:28 +00:00
$row = ( array ) $_POST [ " fields " ];
2007-07-02 05:51:26 +00:00
} elseif ( $where ) {
2007-07-06 13:48:25 +00:00
$select = array ();
2007-07-02 05:51:26 +00:00
foreach ( $fields as $name => $field ) {
2009-06-13 17:00:48 +00:00
if ( isset ( $field [ " privileges " ][ " select " ])) {
$select [] = ( $_POST [ " clone " ] && $field [ " auto_increment " ] ? " '' AS " : ( $field [ " type " ] == " enum " || $field [ " type " ] == " set " ? " 1* " . idf_escape ( $name ) . " AS " : " " )) . idf_escape ( $name );
2007-07-02 05:51:26 +00:00
}
}
2008-10-09 13:23:54 +00:00
$row = array ();
2007-07-10 13:30:42 +00:00
if ( $select ) {
2009-07-11 19:45:57 +00:00
$result = $dbh -> query ( " SELECT " . implode ( " , " , $select ) . " FROM " . idf_escape ( $_GET [ " edit " ]) . " WHERE $where LIMIT 1 " );
2007-07-16 14:01:28 +00:00
$row = $result -> fetch_assoc ();
2008-09-01 16:09:04 +00:00
$result -> free ();
2007-07-10 13:30:42 +00:00
}
2007-07-02 05:51:26 +00:00
}
?>
2007-07-09 14:45:11 +00:00
2007-07-09 06:12:22 +00:00
< form action = " " method = " post " enctype = " multipart/form-data " >
2007-07-02 05:51:26 +00:00
< ? php
2007-07-10 20:26:17 +00:00
if ( $fields ) {
2007-07-25 17:10:03 +00:00
unset ( $create );
2009-05-01 10:41:33 +00:00
echo " <table cellspacing='0'> \n " ;
2007-07-10 20:26:17 +00:00
foreach ( $fields as $name => $field ) {
2009-07-27 11:25:37 +00:00
echo " <tr><th> " . $adminer -> fieldName ( $field );
2009-07-30 08:12:54 +00:00
$default = $_GET [ " set " ][ bracket_escape ( $name )];
2009-06-30 10:27:12 +00:00
$value = ( isset ( $row )
? ( strlen ( $row [ $name ]) && ( $field [ " type " ] == " enum " || $field [ " type " ] == " set " ) ? intval ( $row [ $name ]) : $row [ $name ])
2009-07-30 08:12:54 +00:00
: ( $_POST [ " clone " ] && $field [ " auto_increment " ] ? " " : ( isset ( $_GET [ " select " ]) ? false : ( isset ( $default ) ? $default : $field [ " default " ])))
2009-06-07 23:53:51 +00:00
);
2009-07-27 16:32:56 +00:00
if ( ! $_POST [ " save " ] && is_string ( $value )) {
$value = $adminer -> editVal ( $value , $field );
}
2009-07-17 14:06:30 +00:00
$function = ( $_POST [ " save " ] ? ( string ) $_POST [ " function " ][ $name ] : ( $where && $field [ " on_update " ] == " CURRENT_TIMESTAMP " ? " now " : ( $value === false ? null : ( isset ( $value ) ? '' : 'NULL' ))));
2009-07-23 14:42:38 +00:00
input ( $field , $value , $function );
2009-07-11 20:30:40 +00:00
echo " \n " ;
2007-07-02 05:51:26 +00:00
}
2007-07-10 20:26:17 +00:00
echo " </table> \n " ;
2007-07-02 05:51:26 +00:00
}
?>
2007-07-09 06:12:22 +00:00
< p >
2009-07-11 20:30:40 +00:00
< input type = " hidden " name = " token " value = " <?php echo $token ; ?> " >
< input type = " hidden " name = " save " value = " 1 " >
2008-10-01 11:39:13 +00:00
< ? php
if ( isset ( $_GET [ " select " ])) {
2008-10-09 13:23:54 +00:00
hidden_fields ( array ( " check " => ( array ) $_POST [ " check " ], " clone " => $_POST [ " clone " ], " all " => $_POST [ " all " ]));
2008-10-01 11:39:13 +00:00
}
if ( $fields ) {
2009-07-11 20:30:40 +00:00
echo " <input type='submit' value=' " . lang ( 'Save' ) . " '> \n " ;
2009-08-21 16:54:10 +00:00
if ( ! isset ( $_GET [ " select " ])) {
2009-07-11 20:30:40 +00:00
echo " <input type='submit' name='insert' value=' " . ( $update ? lang ( 'Save and continue edit' ) : lang ( 'Save and insert next' )) . " '> \n " ;
2009-06-07 23:24:37 +00:00
}
}
?>
2007-07-02 05:51:26 +00:00
</ form >