',($U=="PROCEDURE"?"".html_select("fields[$t][inout]",explode("|",$Md),$p["inout"]):""),' | ';if($ac){echo'',script("qsl('input').oninput = function () { editingNameChange.call(this);".($p["field"]!=""||count($q)>1?"":" editingAddRow.call(this);")." };","");}echo'
';edit_type("fields[$t]",$p,$qb,$dd);if($U=="TABLE"){echo' | ',checkbox("fields[$t][null]",1,$p["null"],"","","block","label-null"),' | | ',checkbox("fields[$t][has_default]",1,$p["has_default"],"","","","label-default"),'',(support("comment")?" | ":"");}echo" | ",(support("move_col")?" "." "." ":""),($xf==""||support("drop_col")?"":"");}}function
process_fields(&$q){$E=0;if($_POST["up"]){$je=0;foreach($q
as$z=>$p){if(key($_POST["up"])==$z){unset($q[$z]);array_splice($q,$je,0,array($p));break;}if(isset($p["field"]))$je=$E;$E++;}}elseif($_POST["down"]){$fd=false;foreach($q
as$z=>$p){if(isset($p["field"])&&$fd){unset($q[key($_POST["down"])]);array_splice($q,$E,0,array($fd));break;}if(key($_POST["down"])==$z)$fd=$p;$E++;}}elseif($_POST["add"]){$q=array_values($q);array_splice($q,key($_POST["add"]),0,array(array()));}elseif(!$_POST["drop_col"])return
false;return
true;}function
normalize_enum($C){return"'".str_replace("'","''",addcslashes(stripcslashes(str_replace($C[0][0].$C[0][0],$C[0][0],substr($C[0],1,-1))),'\\'))."'";}function
grant($kd,$ig,$e,$if){if(!$ig)return
true;if($ig==array("ALL PRIVILEGES","GRANT OPTION"))return($kd=="GRANT"?queries("$kd ALL PRIVILEGES$if WITH GRANT OPTION"):queries("$kd ALL PRIVILEGES$if")&&queries("$kd GRANT OPTION$if"));return
queries("$kd ".preg_replace('~(GRANT OPTION)\\([^)]*\\)~','\\1',implode("$e, ",$ig).$e).$if);}function
drop_create($fc,$i,$gc,$Th,$ic,$B,$Je,$He,$Ie,$ff,$Ue){if($_POST["drop"])query_redirect($fc,$B,$Je);elseif($ff=="")query_redirect($i,$B,$Ie);elseif($ff!=$Ue){$Gb=queries($i);queries_redirect($B,$He,$Gb&&queries($fc));if($Gb)queries($gc);}else
queries_redirect($B,$He,queries($Th)&&queries($ic)&&queries($fc)&&queries($i));}function
create_trigger($if,$K){global$y;$Yh=" $K[Timing] $K[Event]".($K["Event"]=="UPDATE OF"?" ".idf_escape($K["Of"]):"");return"CREATE TRIGGER ".idf_escape($K["Trigger"]).($y=="mssql"?$if.$Yh:$Yh.$if).rtrim(" $K[Type]\n$K[Statement]",";").";";}function
create_routine($Ng,$K){global$Md,$y;$P=array();$q=(array)$K["fields"];ksort($q);foreach($q
as$p){if($p["field"]!="")$P[]=(preg_match("~^($Md)\$~",$p["inout"])?"$p[inout] ":"").idf_escape($p["field"]).process_type($p,"CHARACTER SET");}$Tb=rtrim("\n$K[definition]",";");return"CREATE $Ng ".idf_escape(trim($K["name"]))." (".implode(", ",$P).")".(isset($_GET["function"])?" RETURNS".process_type($K["returns"],"CHARACTER SET"):"").($K["language"]?" LANGUAGE $K[language]":"").($y=="pgsql"?" AS ".q($Tb):"$Tb;");}function
remove_definer($H){return
preg_replace('~^([A-Z =]+) DEFINER=`'.preg_replace('~@(.*)~','`@`(%|\\1)',logged_user()).'`~','\\1',$H);}function
format_foreign_key($r){global$jf;return" FOREIGN KEY (".implode(", ",array_map('idf_escape',$r["source"])).") REFERENCES ".table($r["table"])." (".implode(", ",array_map('idf_escape',$r["target"])).")".(preg_match("~^($jf)\$~",$r["on_delete"])?" ON DELETE $r[on_delete]":"").(preg_match("~^($jf)\$~",$r["on_update"])?" ON UPDATE $r[on_update]":"");}function
tar_file($Uc,$di){$J=pack("a100a8a8a8a12a12",$Uc,644,0,0,decoct($di->size),decoct(time()));$hb=8*32;for($t=0;$tsend();echo
str_repeat("\0",511-($di->size+511)%512);}function
ini_bytes($Ld){$X=ini_get($Ld);switch(strtolower(substr($X,-1))){case'g':$X*=1024;case'm':$X*=1024;case'k':$X*=1024;}return$X;}function
doc_link($Sf,$Uh="?"){global$y,$g;$eh=$g->server_info;$Qi=preg_replace('~^(\\d\\.?\\d).*~s','\\1',$eh);$Gi=array('sql'=>"https://dev.mysql.com/doc/refman/$Qi/en/",'sqlite'=>"https://www.sqlite.org/",'pgsql'=>"https://www.postgresql.org/docs/$Qi/static/",'mssql'=>"https://msdn.microsoft.com/library/",'oracle'=>"https://download.oracle.com/docs/cd/B19306_01/server.102/b14200/",);if(preg_match('~MariaDB~',$eh)){$Gi['sql']="https://mariadb.com/kb/en/library/";$Sf['sql']=(isset($Sf['mariadb'])?$Sf['mariadb']:str_replace(".html","/",$Sf['sql']));}return($Sf[$y]?"$Uh":"");}function
ob_gzencode($Q){return
gzencode($Q);}function
db_size($m){global$g;if(!$g->select_db($m))return"?";$J=0;foreach(table_status()as$S)$J+=$S["Data_length"]+$S["Index_length"];return
format_number($J);}function
set_utf8mb4($i){global$g;static$P=false;if(!$P&&preg_match('~\butf8mb4~i',$i)){$P=true;echo"SET NAMES ".charset($g).";\n\n";}}function
connect_error(){global$b,$g,$gi,$o,$ec;if(DB!=""){header("HTTP/1.1 404 Not Found");page_header(lang(35).": ".h(DB),lang(108),true);}else{if($_POST["db"]&&!$o)queries_redirect(substr(ME,0,-1),lang(109),drop_databases($_POST["db"]));page_header(lang(110),$o,false);echo" \n";foreach(array('database'=>lang(111),'privileges'=>lang(69),'processlist'=>lang(112),'variables'=>lang(113),'status'=>lang(114),)as$z=>$X){if(support($z))echo"$X\n";}echo" ".lang(115,$ec[DRIVER],"".h($g->server_info)."","$g->extension")."\n"," ".lang(116,"".h(logged_user())."")."\n";$l=$b->databases();if($l){$Ug=support("scheme");$qb=collations();echo" \n",script("tableCheck();");}}page_footer("db");}if(isset($_GET["status"]))$_GET["variables"]=$_GET["status"];if(isset($_GET["import"]))$_GET["sql"]=$_GET["import"];if(!(DB!=""?$g->select_db(DB):isset($_GET["sql"])||isset($_GET["dump"])||isset($_GET["database"])||isset($_GET["processlist"])||isset($_GET["privileges"])||isset($_GET["user"])||isset($_GET["variables"])||$_GET["script"]=="connect"||$_GET["script"]=="kill")){if(DB!=""||$_GET["refresh"]){restart_session();set_session("dbs",null);}connect_error();exit;}if(support("scheme")&&DB!=""&&$_GET["ns"]!==""){if(!isset($_GET["ns"]))redirect(preg_replace('~ns=[^&]*&~','',ME)."ns=".get_schema());if(!set_schema($_GET["ns"])){header("HTTP/1.1 404 Not Found");page_header(lang(75).": ".h($_GET["ns"]),lang(124),true);page_footer("ns");exit;}}$jf="RESTRICT|NO ACTION|CASCADE|SET NULL|SET DEFAULT";class
TmpFile{var$handler;var$size;function
__construct(){$this->handler=tmpfile();}function
write($Ab){$this->size+=strlen($Ab);fwrite($this->handler,$Ab);}function
send(){fseek($this->handler,0);fpassthru($this->handler);fclose($this->handler);}}$wc="'(?:''|[^'\\\\]|\\\\.)*'";$Md="IN|OUT|INOUT";if(isset($_GET["select"])&&($_POST["edit"]||$_POST["clone"])&&!$_POST["save"])$_GET["edit"]=$_GET["select"];if(isset($_GET["callf"]))$_GET["call"]=$_GET["callf"];if(isset($_GET["function"]))$_GET["procedure"]=$_GET["function"];if(isset($_GET["download"])){$a=$_GET["download"];$q=fields($a);header("Content-Type: application/octet-stream");header("Content-Disposition: attachment; filename=".friendly_url("$a-".implode("_",$_GET["where"])).".".friendly_url($_GET["field"]));$M=array(idf_escape($_GET["field"]));$I=$n->select($a,$M,array(where($_GET,$q)),$M);$K=($I?$I->fetch_row():array());echo$n->value($K[0],$q[$_GET["field"]]);exit;}elseif(isset($_GET["table"])){$a=$_GET["table"];$q=fields($a);if(!$q)$o=error();$S=table_status1($a,true);$D=$b->tableName($S);page_header(($q&&is_view($S)?$S['Engine']=='materialized view'?lang(125):lang(126):lang(127)).": ".($D!=""?$D:h($a)),$o);$b->selectLinks($S);$vb=$S["Comment"];if($vb!="")echo"".lang(48).": ".h($vb)."\n";if($q)$b->tableStructurePrint($q);if(!is_view($S)){if(support("indexes")){echo" ".lang(128)."\n";$x=indexes($a);if($x)$b->tableIndexesPrint($x);echo''.lang(129)."\n";}if(fk_support($S)){echo" ".lang(96)."\n";$dd=foreign_keys($a);if($dd){echo"\n","".lang(130)." | ".lang(131)." | ".lang(99)." | ".lang(98)." | | \n";foreach($dd
as$D=>$r){echo"","".implode(", ",array_map('h',$r["source"])).""," | ".($r["db"]!=""?"".h($r["db"]).".":"").($r["ns"]!=""?"".h($r["ns"]).".":"").h($r["table"])."","(".implode(", ",array_map('h',$r["target"])).")"," | ".nbsp($r["on_delete"])."\n"," | ".nbsp($r["on_update"])."\n",' | '.lang(132).'';}echo" | \n";}echo''.lang(133)."\n";}}if(support(is_view($S)?"view_trigger":"trigger")){echo" ".lang(134)."\n";$si=triggers($a);if($si){echo"\n";foreach($si
as$z=>$X)echo"".h($X[0])." | ".h($X[1])." | ".h($z)." | ".lang(132)."\n";echo" |
---|
\n";}echo''.lang(135)."\n";}}elseif(isset($_GET["schema"])){page_header(lang(68),"",array(),h(DB.($_GET["ns"]?".$_GET[ns]":"")));$Jh=array();$Kh=array();$ea=($_GET["schema"]?$_GET["schema"]:$_COOKIE["adminer_schema-".str_replace(".","_",DB)]);preg_match_all('~([^:]+):([-0-9.]+)x([-0-9.]+)(_|$)~',$ea,$ze,PREG_SET_ORDER);foreach($ze
as$t=>$C){$Jh[$C[1]]=array($C[2],$C[3]);$Kh[]="\n\t'".js_escape($C[1])."': [ $C[2], $C[3] ]";}$hi=0;$Ra=-1;$Tg=array();$zg=array();$ne=array();foreach(table_status('',true)as$R=>$S){if(is_view($S))continue;$Xf=0;$Tg[$R]["fields"]=array();foreach(fields($R)as$D=>$p){$Xf+=1.25;$p["pos"]=$Xf;$Tg[$R]["fields"][$D]=$p;}$Tg[$R]["pos"]=($Jh[$R]?$Jh[$R]:array($hi,0));foreach($b->foreignKeys($R)as$X){if(!$X["db"]){$le=$Ra;if($Jh[$R][1]||$Jh[$X["table"]][1])$le=min(floatval($Jh[$R][1]),floatval($Jh[$X["table"]][1]))-1;else$Ra-=.1;while($ne[(string)$le])$le-=.0001;$Tg[$R]["references"][$X["table"]][(string)$le]=array($X["source"],$X["target"]);$zg[$X["table"]][$R][(string)$le]=$X["target"];$ne[(string)$le]=true;}}$hi=max($hi,$Tg[$R]["pos"][0]+2.5+$Xf);}echo'
';foreach($Tg
as$D=>$R){echo" ",' '.h($D)."",script("qsl('div').onmousedown = schemaMousedown;");foreach($R["fields"]as$p){$X=' '.h($p["field"]).'';echo" ".($p["primary"]?" $X":$X);}foreach((array)$R["references"]as$Qh=>$_g){foreach($_g
as$le=>$wg){$me=$le-$Jh[$D][1];$t=0;foreach($wg[0]as$nh)echo"\n ";}}foreach((array)$zg[$D]as$Qh=>$_g){foreach($_g
as$le=>$e){$me=$le-$Jh[$D][1];$t=0;foreach($e
as$Ph)echo"\n ";}}echo"\n \n";}foreach($Tg
as$D=>$R){foreach((array)$R["references"]as$Qh=>$_g){foreach($_g
as$le=>$wg){$Ne=$hi;$Ce=-10;foreach($wg[0]as$z=>$nh){$Yf=$R["pos"][0]+$R["fields"][$nh]["pos"];$Zf=$Tg[$Qh]["pos"][0]+$Tg[$Qh]["fields"][$wg[1][$z]]["pos"];$Ne=min($Ne,$Yf,$Zf);$Ce=max($Ce,$Yf,$Zf);}echo" \n";}}}echo'
',lang(136),'
';}elseif(isset($_GET["dump"])){$a=$_GET["dump"];if($_POST&&!$o){$Db="";foreach(array("output","format","db_style","routines","events","table_style","auto_increment","triggers","data_style")as$z)$Db.="&$z=".urlencode($_POST[$z]);cookie("adminer_export",substr($Db,1));$T=array_flip((array)$_POST["tables"])+array_flip((array)$_POST["data"]);$Ic=dump_headers((count($T)==1?key($T):DB),(DB==""||count($T)>1));$Ud=preg_match('~sql~',$_POST["format"]);if($Ud){echo"-- Adminer $ia ".$ec[DRIVER]." dump\n\n";if($y=="sql"){echo"SET NAMES utf8;
SET time_zone = '+00:00';
".($_POST["data_style"]?"SET foreign_key_checks = 0;
SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
":"")."
";$g->query("SET time_zone = '+00:00';");}}$Ah=$_POST["db_style"];$l=array(DB);if(DB==""){$l=$_POST["databases"];if(is_string($l))$l=explode("\n",rtrim(str_replace("\r","",$l),"\n"));}foreach((array)$l
as$m){$b->dumpDatabase($m);if($g->select_db($m)){if($Ud&&preg_match('~CREATE~',$Ah)&&($i=$g->result("SHOW CREATE DATABASE ".idf_escape($m),1))){set_utf8mb4($i);if($Ah=="DROP+CREATE")echo"DROP DATABASE IF EXISTS ".idf_escape($m).";\n";echo"$i;\n";}if($Ud){if($Ah)echo
use_sql($m).";\n\n";$Cf="";if($_POST["routines"]){foreach(array("FUNCTION","PROCEDURE")as$Ng){foreach(get_rows("SHOW $Ng STATUS WHERE Db = ".q($m),null,"-- ")as$K){$i=remove_definer($g->result("SHOW CREATE $Ng ".idf_escape($K["Name"]),2));set_utf8mb4($i);$Cf.=($Ah!='DROP+CREATE'?"DROP $Ng IF EXISTS ".idf_escape($K["Name"]).";;\n":"")."$i;;\n\n";}}}if($_POST["events"]){foreach(get_rows("SHOW EVENTS",null,"-- ")as$K){$i=remove_definer($g->result("SHOW CREATE EVENT ".idf_escape($K["Name"]),3));set_utf8mb4($i);$Cf.=($Ah!='DROP+CREATE'?"DROP EVENT IF EXISTS ".idf_escape($K["Name"]).";;\n":"")."$i;;\n\n";}}if($Cf)echo"DELIMITER ;;\n\n$Cf"."DELIMITER ;\n\n";}if($_POST["table_style"]||$_POST["data_style"]){$Si=array();foreach(table_status('',true)as$D=>$S){$R=(DB==""||in_array($D,(array)$_POST["tables"]));$Lb=(DB==""||in_array($D,(array)$_POST["data"]));if($R||$Lb){if($Ic=="tar"){$di=new
TmpFile;ob_start(array($di,'write'),1e5);}$b->dumpTable($D,($R?$_POST["table_style"]:""),(is_view($S)?2:0));if(is_view($S))$Si[]=$D;elseif($Lb){$q=fields($D);$b->dumpData($D,$_POST["data_style"],"SELECT *".convert_fields($q,$q)." FROM ".table($D));}if($Ud&&$_POST["triggers"]&&$R&&($si=trigger_sql($D)))echo"\nDELIMITER ;;\n$si\nDELIMITER ;\n";if($Ic=="tar"){ob_end_flush();tar_file((DB!=""?"":"$m/")."$D.csv",$di);}elseif($Ud)echo"\n";}}foreach($Si
as$Ri)$b->dumpTable($Ri,$_POST["table_style"],1);if($Ic=="tar")echo
pack("x512");}}}if($Ud)echo"-- ".$g->result("SELECT NOW()")."\n";exit;}page_header(lang(71),$o,($_GET["export"]!=""?array("table"=>$_GET["export"]):array()),h(DB));echo'
';$Wc=true;foreach($cg
as$z=>$X){if($z!=""&&$X>1){echo($Wc?"":" ")."".h($z)."";$Wc=false;}}}elseif(isset($_GET["privileges"])){page_header(lang(69));echo' '.lang(142)."";$I=$g->query("SELECT User, Host FROM mysql.".(DB==""?"user":"db WHERE ".q(DB)." LIKE Db")." ORDER BY Host, User");$kd=$I;if(!$I)$I=$g->query("SELECT SUBSTRING_INDEX(CURRENT_USER, '@', 1) AS User, SUBSTRING_INDEX(CURRENT_USER, '@', -1) AS Host");echo" \n";}elseif(isset($_GET["sql"])){if(!$o&&$_POST["export"]){dump_headers("sql");$b->dumpTable("","");$b->dumpData("","table",$_POST["query"]);exit;}restart_session();$wd=&get_session("queries");$vd=&$wd[DB];if(!$o&&$_POST["clear"]){$vd=array();redirect(remove_from_uri("history"));}page_header((isset($_GET["import"])?lang(70):lang(62)),$o);if(!$o&&$_POST){$hd=false;if(!isset($_GET["import"]))$H=$_POST["query"];elseif($_POST["webfile"]){$rh=$b->importServerPath();$hd=@fopen((file_exists($rh)?$rh:"compress.zlib://$rh.gz"),"rb");$H=($hd?fread($hd,1e6):false);}else$H=get_file("sql_file",true);if(is_string($H)){if(function_exists('memory_get_usage'))@ini_set("memory_limit",max(ini_bytes("memory_limit"),2*strlen($H)+memory_get_usage()+8e6));if($H!=""&&strlen($H)<1e6){$ng=$H.(preg_match("~;[ \t\r\n]*\$~",$H)?"":";");if(!$vd||reset(end($vd))!=$ng){restart_session();$vd[]=array($ng,time());set_session("queries",$wd);stop_session();}}$oh="(?:\\s|/\\*[\s\S]*?\\*/|(?:#|-- )[^\n]*\n?|--\r?\n)";$Vb=";";$E=0;$tc=true;$h=connect();if(is_object($h)&&DB!="")$h->select_db(DB);$ub=0;$yc=array();$Jf='[\'"'.($y=="sql"?'`#':($y=="sqlite"?'`[':($y=="mssql"?'[':''))).']|/\\*|-- |$'.($y=="pgsql"?'|\\$[^$]*\\$':'');$ii=microtime(true);parse_str($_COOKIE["adminer_export"],$ya);$kc=$b->dumpFormat();unset($kc["sql"]);while($H!=""){if(!$E&&preg_match("~^$oh*+DELIMITER\\s+(\\S+)~i",$H,$C)){$Vb=$C[1];$H=substr($H,strlen($C[0]));}else{preg_match('('.preg_quote($Vb)."\\s*|$Jf)",$H,$C,PREG_OFFSET_CAPTURE,$E);list($fd,$Xf)=$C[0];if(!$fd&&$hd&&!feof($hd))$H.=fread($hd,1e5);else{if(!$fd&&rtrim($H)=="")break;$E=$Xf+strlen($fd);if($fd&&rtrim($fd)!=$Vb){while(preg_match('('.($fd=='/*'?'\\*/':($fd=='['?']':(preg_match('~^-- |^#~',$fd)?"\n":preg_quote($fd)."|\\\\."))).'|$)s',$H,$C,PREG_OFFSET_CAPTURE,$E)){$Rg=$C[0][0];if(!$Rg&&$hd&&!feof($hd))$H.=fread($hd,1e5);else{$E=$C[0][1]+strlen($Rg);if($Rg[0]!="\\")break;}}}else{$tc=false;$ng=substr($H,0,$Xf);$ub++;$fg="".$b->sqlCommandQuery($ng)." \n";if($y=="sqlite"&&preg_match("~^$oh*+ATTACH\\b~i",$ng,$C)){echo$fg,"".lang(143)."\n";$yc[]=" $ub";if($_POST["error_stops"])break;}else{if(!$_POST["only_errors"]){echo$fg;ob_flush();flush();}$vh=microtime(true);if($g->multi_query($ng)&&is_object($h)&&preg_match("~^$oh*+USE\\b~i",$ng))$h->query($ng);do{$I=$g->store_result();if($g->error){echo($_POST["only_errors"]?$fg:"")," ".lang(144).($g->errno?" ($g->errno)":"").": ".error()."\n";$yc[]=" $ub";if($_POST["error_stops"])break
2;}else{$Wh=" (".format_time($vh).")".(strlen($ng)<1000?" ".lang(10)."":"");$_a=$g->affected_rows;$Vi=($_POST["only_errors"]?"":$n->warnings());$Wi="warnings-$ub";if($Vi)$Wh.=", ".lang(44)."".script("qsl('a').onclick = partial(toggle, '$Wi');","");$Fc=null;$Gc="explain-$ub";if(is_object($I)){$_=$_POST["limit"];$wf=select($I,$h,array(),$_);if(!$_POST["only_errors"]){echo" \n";}}else{if(preg_match("~^$oh*+(CREATE|DROP|ALTER)$oh++(DATABASE|SCHEMA)\\b~i",$ng)){restart_session();set_session("dbs",null);stop_session();}if(!$_POST["only_errors"])echo"".lang(147,$_a)."$Wh\n";}echo($Vi?" \n$Vi \n":"");if($Fc){echo"\n";select($Fc,$h,$wf);echo" \n";}}$vh=microtime(true);}while($g->next_result());}$H=substr($H,$E);$E=0;}}}}if($tc)echo"".lang(148)."\n";elseif($_POST["only_errors"]){echo" ".lang(149,$ub-count($yc))," (".format_time($ii).")\n";}elseif($yc&&$ub>1)echo" ".lang(144).": ".implode("",$yc)."\n";}else
echo" ".upload_error($H)."\n";}echo'
';}elseif(isset($_GET["edit"])){$a=$_GET["edit"];$q=fields($a);$Z=(isset($_GET["select"])?($_POST["check"]&&count($_POST["check"])==1?where_check($_POST["check"][0],$q):""):where($_GET,$q));$Ci=(isset($_GET["select"])?$_POST["edit"]:$Z);foreach($q
as$D=>$p){if(!isset($p["privileges"][$Ci?"update":"insert"])||$b->fieldName($p)=="")unset($q[$D]);}if($_POST&&!$o&&!isset($_GET["select"])){$B=$_POST["referer"];if($_POST["insert"])$B=($Ci?null:$_SERVER["REQUEST_URI"]);elseif(!preg_match('~^.+&select=.+$~',$B))$B=ME."select=".urlencode($a);$x=indexes($a);$yi=unique_array($_GET["where"],$x);$qg="\nWHERE $Z";if(isset($_POST["delete"]))queries_redirect($B,lang(162),$n->delete($a,$qg,!$yi));else{$P=array();foreach($q
as$D=>$p){$X=process_input($p);if($X!==false&&$X!==null)$P[idf_escape($D)]=$X;}if($Ci){if(!$P)redirect($B);queries_redirect($B,lang(163),$n->update($a,$P,$qg,!$yi));if(is_ajax()){page_headers();page_messages($o);exit;}}else{$I=$n->insert($a,$P);$ke=($I?last_id():0);queries_redirect($B,lang(164,($ke?" $ke":"")),$I);}}}$K=null;if($_POST["save"])$K=(array)$_POST["fields"];elseif($Z){$M=array();foreach($q
as$D=>$p){if(isset($p["privileges"]["select"])){$Ha=convert_field($p);if($_POST["clone"]&&$p["auto_increment"])$Ha="''";if($y=="sql"&&preg_match("~enum|set~",$p["type"]))$Ha="1*".idf_escape($D);$M[]=($Ha?"$Ha AS ":"").idf_escape($D);}}$K=array();if(!support("table"))$M=array("*");if($M){$I=$n->select($a,$M,array($Z),$M,array(),(isset($_GET["select"])?2:1));if(!$I)$o=error();else{$K=$I->fetch_assoc();if(!$K)$K=false;}if(isset($_GET["select"])&&(!$K||$I->fetch_assoc()))$K=null;}}if(!support("table")&&!$q){if(!$Z){$I=$n->select($a,array("*"),$Z,array("*"));$K=($I?$I->fetch_assoc():false);if(!$K)$K=array($n->primary=>"");}if($K){foreach($K
as$z=>$X){if(!$Z)$K[$z]=null;$q[$z]=array("field"=>$z,"null"=>($z!=$n->primary),"auto_increment"=>($z==$n->primary));}}}edit_form($a,$q,$K,$Ci);}elseif(isset($_GET["create"])){$a=$_GET["create"];$Lf=array();foreach(array('HASH','LINEAR HASH','KEY','LINEAR KEY','RANGE','LIST')as$z)$Lf[$z]=$z;$yg=referencable_primary($a);$dd=array();foreach($yg
as$Hh=>$p)$dd[str_replace("`","``",$Hh)."`".str_replace("`","``",$p["field"])]=$Hh;$zf=array();$S=array();if($a!=""){$zf=fields($a);$S=table_status($a);if(!$S)$o=lang(9);}$K=$_POST;$K["fields"]=(array)$K["fields"];if($K["auto_increment_col"])$K["fields"][$K["auto_increment_col"]]["auto_increment"]=true;if($_POST&&!process_fields($K["fields"])&&!$o){if($_POST["drop"])queries_redirect(substr(ME,0,-1),lang(165),drop_tables(array($a)));else{$q=array();$Ea=array();$Hi=false;$bd=array();$yf=reset($zf);$Ba=" FIRST";foreach($K["fields"]as$z=>$p){$r=$dd[$p["type"]];$ti=($r!==null?$yg[$r]:$p);if($p["field"]!=""){if(!$p["has_default"])$p["default"]=null;if($z==$K["auto_increment_col"])$p["auto_increment"]=true;$kg=process_field($p,$ti);$Ea[]=array($p["orig"],$kg,$Ba);if($kg!=process_field($yf,$yf)){$q[]=array($p["orig"],$kg,$Ba);if($p["orig"]!=""||$Ba)$Hi=true;}if($r!==null)$bd[idf_escape($p["field"])]=($a!=""&&$y!="sqlite"?"ADD":" ").format_foreign_key(array('table'=>$dd[$p["type"]],'source'=>array($p["field"]),'target'=>array($ti["field"]),'on_delete'=>$p["on_delete"],));$Ba=" AFTER ".idf_escape($p["field"]);}elseif($p["orig"]!=""){$Hi=true;$q[]=array($p["orig"]);}if($p["orig"]!=""){$yf=next($zf);if(!$yf)$Ba="";}}$Nf="";if($Lf[$K["partition_by"]]){$Of=array();if($K["partition_by"]=='RANGE'||$K["partition_by"]=='LIST'){foreach(array_filter($K["partition_names"])as$z=>$X){$Y=$K["partition_values"][$z];$Of[]="\n PARTITION ".idf_escape($X)." VALUES ".($K["partition_by"]=='RANGE'?"LESS THAN":"IN").($Y!=""?" ($Y)":" MAXVALUE");}}$Nf.="\nPARTITION BY $K[partition_by]($K[partition])".($Of?" (".implode(",",$Of)."\n)":($K["partitions"]?" PARTITIONS ".(+$K["partitions"]):""));}elseif(support("partitioning")&&preg_match("~partitioned~",$S["Create_options"]))$Nf.="\nREMOVE PARTITIONING";$Ge=lang(166);if($a==""){cookie("adminer_engine",$K["Engine"]);$Ge=lang(167);}$D=trim($K["name"]);queries_redirect(ME.(support("table")?"table=":"select=").urlencode($D),$Ge,alter_table($a,$D,($y=="sqlite"&&($Hi||$bd)?$Ea:$q),$bd,($K["Comment"]!=$S["Comment"]?$K["Comment"]:null),($K["Engine"]&&$K["Engine"]!=$S["Engine"]?$K["Engine"]:""),($K["Collation"]&&$K["Collation"]!=$S["Collation"]?$K["Collation"]:""),($K["Auto_increment"]!=""?number($K["Auto_increment"]):""),$Nf));}}page_header(($a!=""?lang(42):lang(72)),$o,array("table"=>$a),h($a));if(!$_POST){$K=array("Engine"=>$_COOKIE["adminer_engine"],"fields"=>array(array("field"=>"","type"=>(isset($vi["int"])?"int":(isset($vi["integer"])?"integer":"")),"on_update"=>"")),"partition_names"=>array(""),);if($a!=""){$K=$S;$K["name"]=$a;$K["fields"]=array();if(!$_GET["auto_increment"])$K["Auto_increment"]="";foreach($zf
as$p){$p["has_default"]=isset($p["default"]);$K["fields"][]=$p;}if(support("partitioning")){$id="FROM information_schema.PARTITIONS WHERE TABLE_SCHEMA = ".q(DB)." AND TABLE_NAME = ".q($a);$I=$g->query("SELECT PARTITION_METHOD, PARTITION_ORDINAL_POSITION, PARTITION_EXPRESSION $id ORDER BY PARTITION_ORDINAL_POSITION DESC LIMIT 1");list($K["partition_by"],$K["partitions"],$K["partition"])=$I->fetch_row();$Of=get_key_vals("SELECT PARTITION_NAME, PARTITION_DESCRIPTION $id AND PARTITION_NAME != '' ORDER BY PARTITION_ORDINAL_POSITION");$Of[""]="";$K["partition_names"]=array_keys($Of);$K["partition_values"]=array_values($Of);}}}$qb=collations();$vc=engines();foreach($vc
as$uc){if(!strcasecmp($uc,$K["Engine"])){$K["Engine"]=$uc;break;}}echo'
',script("qs('#form')['defaults'].onclick();".(support("comment")?" editingCommentsClick.call(qs('#form')['comments']);":""));}elseif(isset($_GET["indexes"])){$a=$_GET["indexes"];$Ed=array("PRIMARY","UNIQUE","INDEX");$S=table_status($a,true);if(preg_match('~MyISAM|M?aria'.(min_version(5.6,'10.0.5')?'|InnoDB':'').'~i',$S["Engine"]))$Ed[]="FULLTEXT";if(preg_match('~MyISAM|M?aria'.(min_version(5.7,'10.2.2')?'|InnoDB':'').'~i',$S["Engine"]))$Ed[]="SPATIAL";$x=indexes($a);$dg=array();if($y=="mongo"){$dg=$x["_id_"];unset($Ed[0]);unset($x["_id_"]);}$K=$_POST;if($_POST&&!$o&&!$_POST["add"]&&!$_POST["drop_col"]){$c=array();foreach($K["indexes"]as$w){$D=$w["name"];if(in_array($w["type"],$Ed)){$e=array();$qe=array();$Xb=array();$P=array();ksort($w["columns"]);foreach($w["columns"]as$z=>$d){if($d!=""){$pe=$w["lengths"][$z];$Wb=$w["descs"][$z];$P[]=idf_escape($d).($pe?"(".(+$pe).")":"").($Wb?" DESC":"");$e[]=$d;$qe[]=($pe?$pe:null);$Xb[]=$Wb;}}if($e){$Dc=$x[$D];if($Dc){ksort($Dc["columns"]);ksort($Dc["lengths"]);ksort($Dc["descs"]);if($w["type"]==$Dc["type"]&&array_values($Dc["columns"])===$e&&(!$Dc["lengths"]||array_values($Dc["lengths"])===$qe)&&array_values($Dc["descs"])===$Xb){unset($x[$D]);continue;}}$c[]=array($w["type"],$D,$P);}}}foreach($x
as$D=>$Dc)$c[]=array($Dc["type"],$D,"DROP");if(!$c)redirect(ME."table=".urlencode($a));queries_redirect(ME."table=".urlencode($a),lang(176),alter_indexes($a,$c));}page_header(lang(128),$o,array("table"=>$a),h($a));$q=array_keys(fields($a));if($_POST["add"]){foreach($K["indexes"]as$z=>$w){if($w["columns"][count($w["columns"])]!="")$K["indexes"][$z]["columns"][]="";}$w=end($K["indexes"]);if($w["type"]||array_filter($w["columns"],'strlen'))$K["indexes"][]=array("columns"=>array(1=>""));}if(!$K){foreach($x
as$z=>$w){$x[$z]["name"]=$z;$x[$z]["columns"][]="";}$x[]=array("columns"=>array(1=>""));$K["indexes"]=$x;}echo'
';}elseif(isset($_GET["database"])){$K=$_POST;if($_POST&&!$o&&!isset($_POST["add_x"])){$D=trim($K["name"]);if($_POST["drop"]){$_GET["db"]="";queries_redirect(remove_from_uri("db|database"),lang(180),drop_databases(array(DB)));}elseif(DB!==$D){if(DB!=""){$_GET["db"]=$D;queries_redirect(preg_replace('~\bdb=[^&]*&~','',ME)."db=".urlencode($D),lang(181),rename_database($D,$K["collation"]));}else{$l=explode("\n",str_replace("\r","",$D));$Bh=true;$je="";foreach($l
as$m){if(count($l)==1||$m!=""){if(!create_database($m,$K["collation"]))$Bh=false;$je=$m;}}restart_session();set_session("dbs",null);queries_redirect(ME."db=".urlencode($je),lang(182),$Bh);}}else{if(!$K["collation"])redirect(substr(ME,0,-1));query_redirect("ALTER DATABASE ".idf_escape($D).(preg_match('~^[a-z0-9_]+$~i',$K["collation"])?" COLLATE $K[collation]":""),substr(ME,0,-1),lang(183));}}page_header(DB!=""?lang(65):lang(111),$o,array(),h(DB));$qb=collations();$D=DB;if($_POST)$D=$K["name"];elseif(DB!="")$K["collation"]=db_collation(DB,$qb);elseif($y=="sql"){foreach(get_vals("SHOW GRANTS")as$kd){if(preg_match('~ ON (`(([^\\\\`]|``|\\\\.)*)%`\\.\\*)?~',$kd,$C)&&$C[1]){$D=stripcslashes(idf_unescape("`$C[2]`"));break;}}}echo'
';}elseif(isset($_GET["scheme"])){$K=$_POST;if($_POST&&!$o){$A=preg_replace('~ns=[^&]*&~','',ME)."ns=";if($_POST["drop"])query_redirect("DROP SCHEMA ".idf_escape($_GET["ns"]),$A,lang(184));else{$D=trim($K["name"]);$A.=urlencode($D);if($_GET["ns"]=="")query_redirect("CREATE SCHEMA ".idf_escape($D),$A,lang(185));elseif($_GET["ns"]!=$D)query_redirect("ALTER SCHEMA ".idf_escape($_GET["ns"])." RENAME TO ".idf_escape($D),$A,lang(186));else
redirect($A);}}page_header($_GET["ns"]!=""?lang(66):lang(67),$o);if(!$K)$K["name"]=$_GET["ns"];echo'
';}elseif(isset($_GET["call"])){$da=($_GET["name"]?$_GET["name"]:$_GET["call"]);page_header(lang(187).": ".h($da),$o);$Ng=routine($_GET["call"],(isset($_GET["callf"])?"FUNCTION":"PROCEDURE"));$Cd=array();$Cf=array();foreach($Ng["fields"]as$t=>$p){if(substr($p["inout"],-3)=="OUT")$Cf[$t]="@".idf_escape($p["field"])." AS ".idf_escape($p["field"]);if(!$p["inout"]||substr($p["inout"],0,2)=="IN")$Cd[]=$t;}if(!$o&&$_POST){$ab=array();foreach($Ng["fields"]as$z=>$p){if(in_array($z,$Cd)){$X=process_input($p);if($X===false)$X="''";if(isset($Cf[$z]))$g->query("SET @".idf_escape($p["field"])." = $X");}$ab[]=(isset($Cf[$z])?"@".idf_escape($p["field"]):$X);}$H=(isset($_GET["callf"])?"SELECT":"CALL")." ".table($da)."(".implode(", ",$ab).")";$vh=microtime(true);$I=$g->multi_query($H);$_a=$g->affected_rows;echo$b->selectQuery($H,$vh,!$I);if(!$I)echo"".error()."\n";else{$h=connect();if(is_object($h))$h->select_db(DB);do{$I=$g->store_result();if(is_object($I))select($I,$h);else
echo" ".lang(188,$_a)."\n";}while($g->next_result());if($Cf)select($g->query("SELECT ".implode(", ",$Cf)));}}echo'
';}elseif(isset($_GET["foreign"])){$a=$_GET["foreign"];$D=$_GET["name"];$K=$_POST;if($_POST&&!$o&&!$_POST["add"]&&!$_POST["change"]&&!$_POST["change-js"]){$Ge=($_POST["drop"]?lang(189):($D!=""?lang(190):lang(191)));$B=ME."table=".urlencode($a);if(!$_POST["drop"]){$K["source"]=array_filter($K["source"],'strlen');ksort($K["source"]);$Ph=array();foreach($K["source"]as$z=>$X)$Ph[$z]=$K["target"][$z];$K["target"]=$Ph;}if($y=="sqlite")queries_redirect($B,$Ge,recreate_table($a,$a,array(),array(),array(" $D"=>($_POST["drop"]?"":" ".format_foreign_key($K)))));else{$c="ALTER TABLE ".table($a);$fc="\nDROP ".($y=="sql"?"FOREIGN KEY ":"CONSTRAINT ").idf_escape($D);if($_POST["drop"])query_redirect($c.$fc,$B,$Ge);else{query_redirect($c.($D!=""?"$fc,":"")."\nADD".format_foreign_key($K),$B,$Ge);$o=lang(192)." $o";}}}page_header(lang(193),$o,array("table"=>$a),h($a));if($_POST){ksort($K["source"]);if($_POST["add"])$K["source"][]="";elseif($_POST["change"]||$_POST["change-js"])$K["target"]=array();}elseif($D!=""){$dd=foreign_keys($a);$K=$dd[$D];$K["source"][]="";}else{$K["table"]=$a;$K["source"]=array("");}$nh=array_keys(fields($a));$Ph=($a===$K["table"]?$nh:array_keys(fields($K["table"])));$xg=array_keys(array_filter(table_status('',true),'fk_support'));echo'
';}elseif(isset($_GET["view"])){$a=$_GET["view"];$K=$_POST;$_f="VIEW";if($y=="pgsql"&&$a!=""){$xh=table_status($a);$_f=strtoupper($xh["Engine"]);}if($_POST&&!$o){$D=trim($K["name"]);$Ha=" AS\n$K[select]";$B=ME."table=".urlencode($D);$Ge=lang(197);$U=($_POST["materialized"]?"MATERIALIZED VIEW":"VIEW");if(!$_POST["drop"]&&$a==$D&&$y!="sqlite"&&$U=="VIEW"&&$_f=="VIEW")query_redirect(($y=="mssql"?"ALTER":"CREATE OR REPLACE")." VIEW ".table($D).$Ha,$B,$Ge);else{$Rh=$D."_adminer_".uniqid();drop_create("DROP $_f ".table($a),"CREATE $U ".table($D).$Ha,"DROP $U ".table($D),"CREATE $U ".table($Rh).$Ha,"DROP $U ".table($Rh),($_POST["drop"]?substr(ME,0,-1):$B),lang(198),$Ge,lang(199),$a,$D);}}if(!$_POST&&$a!=""){$K=view($a);$K["name"]=$a;$K["materialized"]=($_f!="VIEW");if(!$o)$o=error();}page_header(($a!=""?lang(41):lang(200)),$o,array("table"=>$a),h($a));echo'
';}elseif(isset($_GET["event"])){$aa=$_GET["event"];$Pd=array("YEAR","QUARTER","MONTH","DAY","HOUR","MINUTE","WEEK","SECOND","YEAR_MONTH","DAY_HOUR","DAY_MINUTE","DAY_SECOND","HOUR_MINUTE","HOUR_SECOND","MINUTE_SECOND");$yh=array("ENABLED"=>"ENABLE","DISABLED"=>"DISABLE","SLAVESIDE_DISABLED"=>"DISABLE ON SLAVE");$K=$_POST;if($_POST&&!$o){if($_POST["drop"])query_redirect("DROP EVENT ".idf_escape($aa),substr(ME,0,-1),lang(201));elseif(in_array($K["INTERVAL_FIELD"],$Pd)&&isset($yh[$K["STATUS"]])){$Sg="\nON SCHEDULE ".($K["INTERVAL_VALUE"]?"EVERY ".q($K["INTERVAL_VALUE"])." $K[INTERVAL_FIELD]".($K["STARTS"]?" STARTS ".q($K["STARTS"]):"").($K["ENDS"]?" ENDS ".q($K["ENDS"]):""):"AT ".q($K["STARTS"]))." ON COMPLETION".($K["ON_COMPLETION"]?"":" NOT")." PRESERVE";queries_redirect(substr(ME,0,-1),($aa!=""?lang(202):lang(203)),queries(($aa!=""?"ALTER EVENT ".idf_escape($aa).$Sg.($aa!=$K["EVENT_NAME"]?"\nRENAME TO ".idf_escape($K["EVENT_NAME"]):""):"CREATE EVENT ".idf_escape($K["EVENT_NAME"]).$Sg)."\n".$yh[$K["STATUS"]]." COMMENT ".q($K["EVENT_COMMENT"]).rtrim(" DO\n$K[EVENT_DEFINITION]",";").";"));}}page_header(($aa!=""?lang(204).": ".h($aa):lang(205)),$o);if(!$K&&$aa!=""){$L=get_rows("SELECT * FROM information_schema.EVENTS WHERE EVENT_SCHEMA = ".q(DB)." AND EVENT_NAME = ".q($aa));$K=reset($L);}echo'
';}elseif(isset($_GET["procedure"])){$da=($_GET["name"]?$_GET["name"]:$_GET["procedure"]);$Ng=(isset($_GET["function"])?"FUNCTION":"PROCEDURE");$K=$_POST;$K["fields"]=(array)$K["fields"];if($_POST&&!process_fields($K["fields"])&&!$o){$xf=routine($_GET["procedure"],$Ng);$Rh="$K[name]_adminer_".uniqid();drop_create("DROP $Ng ".routine_id($da,$xf),create_routine($Ng,$K),"DROP $Ng ".routine_id($K["name"],$K),create_routine($Ng,array("name"=>$Rh)+$K),"DROP $Ng ".routine_id($Rh,$K),substr(ME,0,-1),lang(210),lang(211),lang(212),$da,$K["name"]);}page_header(($da!=""?(isset($_GET["function"])?lang(213):lang(214)).": ".h($da):(isset($_GET["function"])?lang(215):lang(216))),$o);if(!$_POST&&$da!=""){$K=routine($_GET["procedure"],$Ng);$K["name"]=$da;}$qb=get_vals("SHOW CHARACTER SET");sort($qb);$Og=routine_languages();echo'
';}elseif(isset($_GET["sequence"])){$fa=$_GET["sequence"];$K=$_POST;if($_POST&&!$o){$A=substr(ME,0,-1);$D=trim($K["name"]);if($_POST["drop"])query_redirect("DROP SEQUENCE ".idf_escape($fa),$A,lang(218));elseif($fa=="")query_redirect("CREATE SEQUENCE ".idf_escape($D),$A,lang(219));elseif($fa!=$D)query_redirect("ALTER SEQUENCE ".idf_escape($fa)." RENAME TO ".idf_escape($D),$A,lang(220));else
redirect($A);}page_header($fa!=""?lang(221).": ".h($fa):lang(222),$o);if(!$K)$K["name"]=$fa;echo'
';}elseif(isset($_GET["type"])){$ga=$_GET["type"];$K=$_POST;if($_POST&&!$o){$A=substr(ME,0,-1);if($_POST["drop"])query_redirect("DROP TYPE ".idf_escape($ga),$A,lang(223));else
query_redirect("CREATE TYPE ".idf_escape(trim($K["name"]))." $K[as]",$A,lang(224));}page_header($ga!=""?lang(225).": ".h($ga):lang(226),$o);if(!$K)$K["as"]="AS ";echo'
';}elseif(isset($_GET["trigger"])){$a=$_GET["trigger"];$D=$_GET["name"];$ri=trigger_options();$K=(array)trigger($D)+array("Trigger"=>$a."_bi");if($_POST){if(!$o&&in_array($_POST["Timing"],$ri["Timing"])&&in_array($_POST["Event"],$ri["Event"])&&in_array($_POST["Type"],$ri["Type"])){$if=" ON ".table($a);$fc="DROP TRIGGER ".idf_escape($D).($y=="pgsql"?$if:"");$B=ME."table=".urlencode($a);if($_POST["drop"])query_redirect($fc,$B,lang(227));else{if($D!="")queries($fc);queries_redirect($B,($D!=""?lang(228):lang(229)),queries(create_trigger($if,$_POST)));if($D!="")queries(create_trigger($if,$K+array("Type"=>reset($ri["Type"]))));}}$K=$_POST;}page_header(($D!=""?lang(230).": ".h($D):lang(231)),$o,array("table"=>$a));echo'
';}elseif(isset($_GET["user"])){$ha=$_GET["user"];$ig=array(""=>array("All privileges"=>""));foreach(get_rows("SHOW PRIVILEGES")as$K){foreach(explode(",",($K["Privilege"]=="Grant option"?"":$K["Context"]))as$Bb)$ig[$Bb][$K["Privilege"]]=$K["Comment"];}$ig["Server Admin"]+=$ig["File access on server"];$ig["Databases"]["Create routine"]=$ig["Procedures"]["Create routine"];unset($ig["Procedures"]["Create routine"]);$ig["Columns"]=array();foreach(array("Select","Insert","Update","References")as$X)$ig["Columns"][$X]=$ig["Tables"][$X];unset($ig["Server Admin"]["Usage"]);foreach($ig["Tables"]as$z=>$X)unset($ig["Databases"][$z]);$Te=array();if($_POST){foreach($_POST["objects"]as$z=>$X)$Te[$X]=(array)$Te[$X]+(array)$_POST["grants"][$z];}$ld=array();$gf="";if(isset($_GET["host"])&&($I=$g->query("SHOW GRANTS FOR ".q($ha)."@".q($_GET["host"])))){while($K=$I->fetch_row()){if(preg_match('~GRANT (.*) ON (.*) TO ~',$K[0],$C)&&preg_match_all('~ *([^(,]*[^ ,(])( *\\([^)]+\\))?~',$C[1],$ze,PREG_SET_ORDER)){foreach($ze
as$X){if($X[1]!="USAGE")$ld["$C[2]$X[2]"][$X[1]]=true;if(preg_match('~ WITH GRANT OPTION~',$K[0]))$ld["$C[2]$X[2]"]["GRANT OPTION"]=true;}}if(preg_match("~ IDENTIFIED BY PASSWORD '([^']+)~",$K[0],$C))$gf=$C[1];}}if($_POST&&!$o){$hf=(isset($_GET["host"])?q($ha)."@".q($_GET["host"]):"''");if($_POST["drop"])query_redirect("DROP USER $hf",ME."privileges=",lang(234));else{$Ve=q($_POST["user"])."@".q($_POST["host"]);$Qf=$_POST["pass"];if($Qf!=''&&!$_POST["hashed"]){$Qf=$g->result("SELECT PASSWORD(".q($Qf).")");$o=!$Qf;}$Gb=false;if(!$o){if($hf!=$Ve){$Gb=queries((min_version(5)?"CREATE USER":"GRANT USAGE ON *.* TO")." $Ve IDENTIFIED BY PASSWORD ".q($Qf));$o=!$Gb;}elseif($Qf!=$gf)queries("SET PASSWORD FOR $Ve = ".q($Qf));}if(!$o){$Kg=array();foreach($Te
as$bf=>$kd){if(isset($_GET["grant"]))$kd=array_filter($kd);$kd=array_keys($kd);if(isset($_GET["grant"]))$Kg=array_diff(array_keys(array_filter($Te[$bf],'strlen')),$kd);elseif($hf==$Ve){$ef=array_keys((array)$ld[$bf]);$Kg=array_diff($ef,$kd);$kd=array_diff($kd,$ef);unset($ld[$bf]);}if(preg_match('~^(.+)\\s*(\\(.*\\))?$~U',$bf,$C)&&(!grant("REVOKE",$Kg,$C[2]," ON $C[1] FROM $Ve")||!grant("GRANT",$kd,$C[2]," ON $C[1] TO $Ve"))){$o=true;break;}}}if(!$o&&isset($_GET["host"])){if($hf!=$Ve)queries("DROP USER $hf");elseif(!isset($_GET["grant"])){foreach($ld
as$bf=>$Kg){if(preg_match('~^(.+)(\\(.*\\))?$~U',$bf,$C))grant("REVOKE",array_keys($Kg),$C[2]," ON $C[1] FROM $Ve");}}}queries_redirect(ME."privileges=",(isset($_GET["host"])?lang(235):lang(236)),!$o);if($Gb)$g->query("DROP USER $Ve");}}page_header((isset($_GET["host"])?lang(33).": ".h("$ha@$_GET[host]"):lang(142)),$o,array("privileges"=>array('',lang(69))));if($_POST){$K=$_POST;$ld=$Te;}else{$K=$_GET+array("host"=>$g->result("SELECT SUBSTRING_INDEX(CURRENT_USER, '@', -1)"));$K["pass"]=$gf;if($gf!="")$K["hashed"]=true;$ld[(DB==""||$ld?"":idf_escape(addcslashes(DB,"%_\\"))).".*"]=array();}echo'
';}elseif(isset($_GET["processlist"])){if(support("kill")&&$_POST&&!$o){$ee=0;foreach((array)$_POST["kill"]as$X){if(kill_process($X))$ee++;}queries_redirect(ME."processlist=",lang(241,$ee),$ee||!$_POST["kill"]);}page_header(lang(112),$o);echo'
',script("tableCheck();");}elseif(isset($_GET["select"])){$a=$_GET["select"];$S=table_status1($a);$x=indexes($a);$q=fields($a);$dd=column_foreign_keys($a);$df=$S["Oid"];parse_str($_COOKIE["adminer_import"],$za);$Lg=array();$e=array();$Vh=null;foreach($q
as$z=>$p){$D=$b->fieldName($p);if(isset($p["privileges"]["select"])&&$D!=""){$e[$z]=html_entity_decode(strip_tags($D),ENT_QUOTES);if(is_shortable($p))$Vh=$b->selectLengthProcess();}$Lg+=$p["privileges"];}list($M,$md)=$b->selectColumnsProcess($e,$x);$Td=count($md)selectSearchProcess($q,$x);$tf=$b->selectOrderProcess($q,$x);$_=$b->selectLimitProcess();if($_GET["val"]&&is_ajax()){header("Content-Type: text/plain; charset=utf-8");foreach($_GET["val"]as$zi=>$K){$Ha=convert_field($q[key($K)]);$M=array($Ha?$Ha:idf_escape(key($K)));$Z[]=where_check($zi,$q);$J=$n->select($a,$M,$Z,$M);if($J)echo
reset($J->fetch_row());}exit;}$dg=$Ai=null;foreach($x
as$w){if($w["type"]=="PRIMARY"){$dg=array_flip($w["columns"]);$Ai=($M?$dg:array());foreach($Ai
as$z=>$X){if(in_array(idf_escape($z),$M))unset($Ai[$z]);}break;}}if($df&&!$dg){$dg=$Ai=array($df=>0);$x[]=array("type"=>"PRIMARY","columns"=>array($df));}if($_POST&&!$o){$bj=$Z;if(!$_POST["all"]&&is_array($_POST["check"])){$gb=array();foreach($_POST["check"]as$db)$gb[]=where_check($db,$q);$bj[]="((".implode(") OR (",$gb)."))";}$bj=($bj?"\nWHERE ".implode(" AND ",$bj):"");if($_POST["export"]){cookie("adminer_import","output=".urlencode($_POST["output"])."&format=".urlencode($_POST["format"]));dump_headers($a);$b->dumpTable($a,"");$id=($M?implode(", ",$M):"*").convert_fields($e,$q,$M)."\nFROM ".table($a);$od=($md&&$Td?"\nGROUP BY ".implode(", ",$md):"").($tf?"\nORDER BY ".implode(", ",$tf):"");if(!is_array($_POST["check"])||$dg)$H="SELECT $id$bj$od";else{$xi=array();foreach($_POST["check"]as$X)$xi[]="(SELECT".limit($id,"\nWHERE ".($Z?implode(" AND ",$Z)." AND ":"").where_check($X,$q).$od,1).")";$H=implode(" UNION ALL ",$xi);}$b->dumpData($a,"table",$H);exit;}if(!$b->selectEmailProcess($Z,$dd)){if($_POST["save"]||$_POST["delete"]){$I=true;$_a=0;$P=array();if(!$_POST["delete"]){foreach($e
as$D=>$X){$X=process_input($q[$D]);if($X!==null&&($_POST["clone"]||$X!==false))$P[idf_escape($D)]=($X!==false?$X:idf_escape($D));}}if($_POST["delete"]||$P){if($_POST["clone"])$H="INTO ".table($a)." (".implode(", ",array_keys($P)).")\nSELECT ".implode(", ",$P)."\nFROM ".table($a);if($_POST["all"]||($dg&&is_array($_POST["check"]))||$Td){$I=($_POST["delete"]?$n->delete($a,$bj):($_POST["clone"]?queries("INSERT $H$bj"):$n->update($a,$P,$bj)));$_a=$g->affected_rows;}else{foreach((array)$_POST["check"]as$X){$Xi="\nWHERE ".($Z?implode(" AND ",$Z)." AND ":"").where_check($X,$q);$I=($_POST["delete"]?$n->delete($a,$Xi,1):($_POST["clone"]?queries("INSERT".limit1($a,$H,$Xi)):$n->update($a,$P,$Xi,1)));if(!$I)break;$_a+=$g->affected_rows;}}}$Ge=lang(245,$_a);if($_POST["clone"]&&$I&&$_a==1){$ke=last_id();if($ke)$Ge=lang(164," $ke");}queries_redirect(remove_from_uri($_POST["all"]&&$_POST["delete"]?"page":""),$Ge,$I);if(!$_POST["delete"]){edit_form($a,$q,(array)$_POST["fields"],!$_POST["clone"]);page_footer();exit;}}elseif(!$_POST["import"]){if(!$_POST["val"])$o=lang(246);else{$I=true;$_a=0;foreach($_POST["val"]as$zi=>$K){$P=array();foreach($K
as$z=>$X){$z=bracket_escape($z,1);$P[idf_escape($z)]=(preg_match('~char|text~',$q[$z]["type"])||$X!=""?$b->processInput($q[$z],$X):"NULL");}$I=$n->update($a,$P," WHERE ".($Z?implode(" AND ",$Z)." AND ":"").where_check($zi,$q),!$Td&&!$dg," ");if(!$I)break;$_a+=$g->affected_rows;}queries_redirect(remove_from_uri(),lang(245,$_a),$I);}}elseif(!is_string($Tc=get_file("csv_file",true)))$o=upload_error($Tc);elseif(!preg_match('~~u',$Tc))$o=lang(247);else{cookie("adminer_import","output=".urlencode($za["output"])."&format=".urlencode($_POST["separator"]));$I=true;$sb=array_keys($q);preg_match_all('~(?>"[^"]*"|[^"\\r\\n]+)+~',$Tc,$ze);$_a=count($ze[0]);$n->begin();$N=($_POST["separator"]=="csv"?",":($_POST["separator"]=="tsv"?"\t":";"));$L=array();foreach($ze[0]as$z=>$X){preg_match_all("~((?>\"[^\"]*\")+|[^$N]*)$N~",$X.$N,$_e);if(!$z&&!array_diff($_e[1],$sb)){$sb=$_e[1];$_a--;}else{$P=array();foreach($_e[1]as$t=>$nb)$P[idf_escape($sb[$t])]=($nb==""&&$q[$sb[$t]]["null"]?"NULL":q(str_replace('""','"',preg_replace('~^"|"$~','',$nb))));$L[]=$P;}}$I=(!$L||$n->insertUpdate($a,$L,$dg));if($I)$I=$n->commit();queries_redirect(remove_from_uri("page"),lang(248,$_a),$I);$n->rollback();}}}$Hh=$b->tableName($S);if(is_ajax()){page_headers();ob_start();}else
page_header(lang(51).": $Hh",$o);$P=null;if(isset($Lg["insert"])||!support("table")){$P="";foreach((array)$_GET["where"]as$X){if($dd[$X["col"]]&&count($dd[$X["col"]])==1&&($X["op"]=="="||(!$X["op"]&&!preg_match('~[_%]~',$X["val"]))))$P.="&set".urlencode("[".bracket_escape($X["col"])."]")."=".urlencode($X["val"]);}}$b->selectLinks($S,$P);if(!$e&&support("table"))echo"".lang(249).($q?".":": ".error())."\n";else{echo" \n";$F=$_GET["page"];if($F=="last"){$gd=$g->result(count_rows($a,$Z,$Td,$md));$F=floor(max(0,$gd-1)/$_);}$Xg=$M;$nd=$md;if(!$Xg){$Xg[]="*";$Cb=convert_fields($e,$q,$M);if($Cb)$Xg[]=substr($Cb,2);}foreach($M
as$z=>$X){$p=$q[idf_unescape($X)];if($p&&($Ha=convert_field($p)))$Xg[$z]="$Ha AS $X";}if(!$Td&&$Ai){foreach($Ai
as$z=>$X){$Xg[]=idf_escape($z);if($nd)$nd[]=idf_escape($z);}}$I=$n->select($a,$Xg,$Z,$nd,$tf,$_,$F,true);if(!$I)echo"".error()."\n";else{if($y=="mssql"&&$F)$I->seek($_*$F);$sc=array();echo" \n",(!$md&&$M?"":script("tableCheck();"));}}}if(is_ajax()){ob_end_clean();exit;}}elseif(isset($_GET["variables"])){$xh=isset($_GET["status"]);page_header($xh?lang(114):lang(113));$Oi=($xh?show_status():show_variables());if(!$Oi)echo"".lang(12)."\n";else{echo" \n";foreach($Oi
as$z=>$X){echo"","".h($z)." "," | ".nbsp($X);}echo" | \n";}}elseif(isset($_GET["script"])){header("Content-Type: text/javascript; charset=utf-8");if($_GET["script"]=="db"){$Eh=array("Data_length"=>0,"Index_length"=>0,"Data_free"=>0);foreach(table_status()as$D=>$S){json_row("Comment-$D",nbsp($S["Comment"]));if(!is_view($S)){foreach(array("Engine","Collation")as$z)json_row("$z-$D",nbsp($S[$z]));foreach($Eh+array("Auto_increment"=>0,"Rows"=>0)as$z=>$X){if($S[$z]!=""){$X=format_number($S[$z]);json_row("$z-$D",($z=="Rows"&&$X&&$S["Engine"]==($qh=="pgsql"?"table":"InnoDB")?"~ $X":$X));if(isset($Eh[$z]))$Eh[$z]+=($S["Engine"]!="InnoDB"||$z!="Data_free"?$S[$z]:0);}elseif(array_key_exists($z,$S))json_row("$z-$D");}}}foreach($Eh
as$z=>$X)json_row("sum-$z",format_number($X));json_row("");}elseif($_GET["script"]=="kill")$g->query("KILL ".number($_POST["kill"]));else{foreach(count_tables($b->databases())as$m=>$X){json_row("tables-$m",$X);json_row("size-$m",db_size($m));}json_row("");}exit;}else{$Nh=array_merge((array)$_POST["tables"],(array)$_POST["views"]);if($Nh&&!$o&&!$_POST["search"]){$I=true;$Ge="";if($y=="sql"&&$_POST["tables"]&&count($_POST["tables"])>1&&($_POST["drop"]||$_POST["truncate"]||$_POST["copy"]))queries("SET foreign_key_checks = 0");if($_POST["truncate"]){if($_POST["tables"])$I=truncate_tables($_POST["tables"]);$Ge=lang(259);}elseif($_POST["move"]){$I=move_tables((array)$_POST["tables"],(array)$_POST["views"],$_POST["target"]);$Ge=lang(260);}elseif($_POST["copy"]){$I=copy_tables((array)$_POST["tables"],(array)$_POST["views"],$_POST["target"]);$Ge=lang(261);}elseif($_POST["drop"]){if($_POST["views"])$I=drop_views($_POST["views"]);if($I&&$_POST["tables"])$I=drop_tables($_POST["tables"]);$Ge=lang(262);}elseif($y!="sql"){$I=($y=="sqlite"?queries("VACUUM"):apply_queries("VACUUM".($_POST["optimize"]?"":" ANALYZE"),$_POST["tables"]));$Ge=lang(263);}elseif(!$_POST["tables"])$Ge=lang(9);elseif($I=queries(($_POST["optimize"]?"OPTIMIZE":($_POST["check"]?"CHECK":($_POST["repair"]?"REPAIR":"ANALYZE")))." TABLE ".implode(", ",array_map('idf_escape',$_POST["tables"])))){while($K=$I->fetch_assoc())$Ge.="".h($K["Table"]).": ".h($K["Msg_text"])." ";}queries_redirect(substr(ME,0,-1),$Ge,$I);}page_header(($_GET["ns"]==""?lang(35).": ".h(DB):lang(75).": ".h($_GET["ns"])),$o,true);if($b->homepage()){if($_GET["ns"]!==""){echo"".lang(264)."\n";$Mh=tables_list();if(!$Mh)echo"".lang(9)."\n";else{echo" \n",script("tableCheck();");}echo''.lang(72)."\n",(support("view")?''.lang(200)."\n":"");if(support("routine")){echo" ".lang(139)."\n";$Pg=routines();if($Pg){echo"\n",''.lang(179).' | '.lang(47).' | '.lang(217)." | | \n";odd('');foreach($Pg
as$K){$D=($K["SPECIFIC_NAME"]==$K["ROUTINE_NAME"]?"":"&name=".urlencode($K["ROUTINE_NAME"]));echo'',''.h($K["ROUTINE_NAME"]).'',' | '.h($K["ROUTINE_TYPE"]),' | '.h($K["DTD_IDENTIFIER"]),' | '.lang(132)."";}echo" | \n";}echo''.(support("procedure")?''.lang(216).'':'').''.lang(215)."\n";}if(support("sequence")){echo" ".lang(280)."\n";$dh=get_vals("SELECT sequence_name FROM information_schema.sequences WHERE sequence_schema = current_schema() ORDER BY sequence_name");if($dh){echo"\n","".lang(179)." | \n";odd('');foreach($dh
as$X)echo"".h($X)."\n";echo" |
---|
\n";}echo"".lang(222)."\n";}if(support("type")){echo" ".lang(24)."\n";$Ji=types();if($Ji){echo"\n","".lang(179)." | \n";odd('');foreach($Ji
as$X)echo"".h($X)."\n";echo" |
---|
\n";}echo"".lang(226)."\n";}if(support("event")){echo" ".lang(140)."\n";$L=get_rows("SHOW EVENTS");if($L){echo"\n","".lang(179)." | ".lang(281)." | ".lang(206)." | ".lang(207)." | | \n";foreach($L
as$K){echo"","".h($K["Name"])," | ".($K["Execute at"]?lang(282)." | ".$K["Execute at"]:lang(208)." ".$K["Interval value"]." ".$K["Interval field"]." | $K[Starts]")," | $K[Ends]",' | '.lang(132).'';}echo" | \n";$_c=$g->result("SELECT @@event_scheduler");if($_c&&$_c!="ON")echo"event_scheduler : ".h($_c)."\n";}echo'
'.lang(205)."\n";}if($Mh)echo
script("ajaxSetHtml('".js_escape(ME)."script=db');");}}}page_footer(); |