',($T=="PROCEDURE"?"".html_select("fields[$s][inout]",explode("|",$Ld),$o["inout"]):""),' | ';if($Zb){echo'',script("qsl('input').oninput = function () { editingNameChange.call(this);".($o["field"]!=""||count($p)>1?"":" editingAddRow.call(this);")." };","");}echo'
';edit_type("fields[$s]",$o,$qb,$cd);if($T=="TABLE"){echo' | ',checkbox("fields[$s][null]",1,$o["null"],"","","block","label-null"),' | | ',checkbox("fields[$s][has_default]",1,$o["has_default"],"","","","label-default"),'',script("qsl('input').oninput = function () { this.previousSibling.checked = true; }",""),(support("comment")?" | ":"");}echo" | ",(support("move_col")?" ".script("qsl('input').onclick = partial(editingAddRow, 1);","")." ".script("qsl('input').onclick = partial(editingMoveRow, 1);","")." ".script("qsl('input').onclick = partial(editingMoveRow, 0);",""):""),($vf==""||support("drop_col")?"".script("qsl('input').onclick = partial(editingRemoveRow, 'fields\$1[field]');"):"");}}function
process_fields(&$p){$D=0;if($_POST["up"]){$je=0;foreach($p
as$y=>$o){if(key($_POST["up"])==$y){unset($p[$y]);array_splice($p,$je,0,array($o));break;}if(isset($o["field"]))$je=$D;$D++;}}elseif($_POST["down"]){$ed=false;foreach($p
as$y=>$o){if(isset($o["field"])&&$ed){unset($p[key($_POST["down"])]);array_splice($p,$D,0,array($ed));break;}if(key($_POST["down"])==$y)$ed=$o;$D++;}}elseif($_POST["add"]){$p=array_values($p);array_splice($p,key($_POST["add"]),0,array(array()));}elseif(!$_POST["drop_col"])return
false;return
true;}function
normalize_enum($B){return"'".str_replace("'","''",addcslashes(stripcslashes(str_replace($B[0][0].$B[0][0],$B[0][0],substr($B[0],1,-1))),'\\'))."'";}function
grant($kd,$fg,$e,$gf){if(!$fg)return
true;if($fg==array("ALL PRIVILEGES","GRANT OPTION"))return($kd=="GRANT"?queries("$kd ALL PRIVILEGES$gf WITH GRANT OPTION"):queries("$kd ALL PRIVILEGES$gf")&&queries("$kd GRANT OPTION$gf"));return
queries("$kd ".preg_replace('~(GRANT OPTION)\\([^)]*\\)~','\\1',implode("$e, ",$fg).$e).$gf);}function
drop_create($fc,$i,$gc,$Ph,$ic,$A,$He,$Fe,$Ge,$df,$Se){if($_POST["drop"])query_redirect($fc,$A,$He);elseif($df=="")query_redirect($i,$A,$Ge);elseif($df!=$Se){$Gb=queries($i);queries_redirect($A,$Fe,$Gb&&queries($fc));if($Gb)queries($gc);}else
queries_redirect($A,$Fe,queries($Ph)&&queries($ic)&&queries($fc)&&queries($i));}function
create_trigger($gf,$J){global$x;$Uh=" $J[Timing] $J[Event]".($J["Event"]=="UPDATE OF"?" ".idf_escape($J["Of"]):"");return"CREATE TRIGGER ".idf_escape($J["Trigger"]).($x=="mssql"?$gf.$Uh:$Uh.$gf).rtrim(" $J[Type]\n$J[Statement]",";").";";}function
create_routine($Lg,$J){global$Ld;$N=array();$p=(array)$J["fields"];ksort($p);foreach($p
as$o){if($o["field"]!="")$N[]=(preg_match("~^($Ld)\$~",$o["inout"])?"$o[inout] ":"").idf_escape($o["field"]).process_type($o,"CHARACTER SET");}return"CREATE $Lg ".idf_escape(trim($J["name"]))." (".implode(", ",$N).")".(isset($_GET["function"])?" RETURNS".process_type($J["returns"],"CHARACTER SET"):"").($J["language"]?" LANGUAGE $J[language]":"").rtrim("\n$J[definition]",";").";";}function
remove_definer($G){return
preg_replace('~^([A-Z =]+) DEFINER=`'.preg_replace('~@(.*)~','`@`(%|\\1)',logged_user()).'`~','\\1',$G);}function
format_foreign_key($q){global$hf;return" FOREIGN KEY (".implode(", ",array_map('idf_escape',$q["source"])).") REFERENCES ".table($q["table"])." (".implode(", ",array_map('idf_escape',$q["target"])).")".(preg_match("~^($hf)\$~",$q["on_delete"])?" ON DELETE $q[on_delete]":"").(preg_match("~^($hf)\$~",$q["on_update"])?" ON UPDATE $q[on_update]":"");}function
tar_file($Tc,$Zh){$I=pack("a100a8a8a8a12a12",$Tc,644,0,0,decoct($Zh->size),decoct(time()));$hb=8*32;for($s=0;$ssend();echo
str_repeat("\0",511-($Zh->size+511)%512);}function
ini_bytes($Kd){$X=ini_get($Kd);switch(strtolower(substr($X,-1))){case'g':$X*=1024;case'm':$X*=1024;case'k':$X*=1024;}return$X;}function
doc_link($Pf){global$x,$g;$Bi=array('sql'=>"https://dev.mysql.com/doc/refman/".substr($g->server_info,0,3)."/en/",'sqlite'=>"https://www.sqlite.org/",'pgsql'=>"https://www.postgresql.org/docs/".substr($g->server_info,0,3)."/static/",'mssql'=>"https://msdn.microsoft.com/library/",'oracle'=>"https://download.oracle.com/docs/cd/B19306_01/server.102/b14200/",);return($Pf[$x]?"?":"");}function
ob_gzencode($P){return
gzencode($P);}function
db_size($m){global$g;if(!$g->select_db($m))return"?";$I=0;foreach(table_status()as$R)$I+=$R["Data_length"]+$R["Index_length"];return
format_number($I);}function
set_utf8mb4($i){global$g;static$N=false;if(!$N&&preg_match('~\butf8mb4~i',$i)){$N=true;echo"SET NAMES ".charset($g).";\n\n";}}function
connect_error(){global$b,$g,$ci,$n,$ec;if(DB!=""){header("HTTP/1.1 404 Not Found");page_header(lang(35).": ".h(DB),lang(105),true);}else{if($_POST["db"]&&!$n)queries_redirect(substr(ME,0,-1),lang(106),drop_databases($_POST["db"]));page_header(lang(107),$n,false);echo" \n";foreach(array('database'=>lang(108),'privileges'=>lang(68),'processlist'=>lang(109),'variables'=>lang(110),'status'=>lang(111),)as$y=>$X){if(support($y))echo"$X\n";}echo" ".lang(112,$ec[DRIVER],"".h($g->server_info)."","$g->extension")."\n"," ".lang(113,"".h(logged_user())."")."\n";$l=$b->databases();if($l){$Sg=support("scheme");$qb=collations();echo" \n";}}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(73).": ".h($_GET["ns"]),lang(121),true);page_footer("ns");exit;}}$hf="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="'(?:''|[^'\\\\]|\\\\.)*'";$Ld="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"];$p=fields($a);header("Content-Type: application/octet-stream");header("Content-Disposition: attachment; filename=".friendly_url("$a-".implode("_",$_GET["where"])).".".friendly_url($_GET["field"]));$L=array(idf_escape($_GET["field"]));$H=$dc->select($a,$L,array(where($_GET,$p)),$L);$J=($H?$H->fetch_row():array());echo$J[0];exit;}elseif(isset($_GET["table"])){$a=$_GET["table"];$p=fields($a);if(!$p)$n=error();$R=table_status1($a,true);page_header(($p&&is_view($R)?$R['Engine']=='materialized view'?lang(122):lang(123):lang(124)).": ".h($a),$n);$b->selectLinks($R);$vb=$R["Comment"];if($vb!="")echo"".lang(47).": ".h($vb)."\n";if($p)$b->tableStructurePrint($p);if(!is_view($R)){if(support("indexes")){echo" ".lang(125)."\n";$w=indexes($a);if($w)$b->tableIndexesPrint($w);echo''.lang(126)."\n";}if(fk_support($R)){echo" ".lang(93)."\n";$cd=foreign_keys($a);if($cd){echo"\n","".lang(127)." | ".lang(128)." | ".lang(96)." | ".lang(95)." | | \n";foreach($cd
as$C=>$q){echo"","".implode(", ",array_map('h',$q["source"])).""," | ".($q["db"]!=""?"".h($q["db"]).".":"").($q["ns"]!=""?"".h($q["ns"]).".":"").h($q["table"])."","(".implode(", ",array_map('h',$q["target"])).")"," | ".nbsp($q["on_delete"])."\n"," | ".nbsp($q["on_update"])."\n",' | '.lang(129).'';}echo" | \n";}echo''.lang(130)."\n";}}if(support(is_view($R)?"view_trigger":"trigger")){echo" ".lang(131)."\n";$oi=triggers($a);if($oi){echo"\n";foreach($oi
as$y=>$X)echo"".h($X[0])." | ".h($X[1])." | ".h($y)." | ".lang(129)."\n";echo" |
---|
\n";}echo''.lang(132)."\n";}}elseif(isset($_GET["schema"])){page_header(lang(67),"",array(),h(DB.($_GET["ns"]?".$_GET[ns]":"")));$Fh=array();$Gh=array();$ea=($_GET["schema"]?$_GET["schema"]:$_COOKIE["adminer_schema-".str_replace(".","_",DB)]);preg_match_all('~([^:]+):([-0-9.]+)x([-0-9.]+)(_|$)~',$ea,$xe,PREG_SET_ORDER);foreach($xe
as$s=>$B){$Fh[$B[1]]=array($B[2],$B[3]);$Gh[]="\n\t'".js_escape($B[1])."': [ $B[2], $B[3] ]";}$di=0;$Ra=-1;$Rg=array();$xg=array();$ne=array();foreach(table_status('',true)as$Q=>$R){if(is_view($R))continue;$Uf=0;$Rg[$Q]["fields"]=array();foreach(fields($Q)as$C=>$o){$Uf+=1.25;$o["pos"]=$Uf;$Rg[$Q]["fields"][$C]=$o;}$Rg[$Q]["pos"]=($Fh[$Q]?$Fh[$Q]:array($di,0));foreach($b->foreignKeys($Q)as$X){if(!$X["db"]){$le=$Ra;if($Fh[$Q][1]||$Fh[$X["table"]][1])$le=min(floatval($Fh[$Q][1]),floatval($Fh[$X["table"]][1]))-1;else$Ra-=.1;while($ne[(string)$le])$le-=.0001;$Rg[$Q]["references"][$X["table"]][(string)$le]=array($X["source"],$X["target"]);$xg[$X["table"]][$Q][(string)$le]=$X["target"];$ne[(string)$le]=true;}}$di=max($di,$Rg[$Q]["pos"][0]+2.5+$Uf);}echo'
';foreach($Rg
as$C=>$Q){echo" ",' '.h($C)."",script("qsl('div').onmousedown = schemaMousedown;");foreach($Q["fields"]as$o){$X=' '.h($o["field"]).'';echo" ".($o["primary"]?" $X":$X);}foreach((array)$Q["references"]as$Mh=>$yg){foreach($yg
as$le=>$ug){$me=$le-$Fh[$C][1];$s=0;foreach($ug[0]as$lh)echo"\n ";}}foreach((array)$xg[$C]as$Mh=>$yg){foreach($yg
as$le=>$e){$me=$le-$Fh[$C][1];$s=0;foreach($e
as$Lh)echo"\n ";}}echo"\n \n";}foreach($Rg
as$C=>$Q){foreach((array)$Q["references"]as$Mh=>$yg){foreach($yg
as$le=>$ug){$Le=$di;$Ae=-10;foreach($ug[0]as$y=>$lh){$Vf=$Q["pos"][0]+$Q["fields"][$lh]["pos"];$Wf=$Rg[$Mh]["pos"][0]+$Rg[$Mh]["fields"][$ug[1][$y]]["pos"];$Le=min($Le,$Vf,$Wf);$Ae=max($Ae,$Vf,$Wf);}echo" \n";}}}echo'
',lang(133),'
';}elseif(isset($_GET["dump"])){$a=$_GET["dump"];if($_POST&&!$n){$Db="";foreach(array("output","format","db_style","routines","events","table_style","auto_increment","triggers","data_style")as$y)$Db.="&$y=".urlencode($_POST[$y]);cookie("adminer_export",substr($Db,1));$S=array_flip((array)$_POST["tables"])+array_flip((array)$_POST["data"]);$Ic=dump_headers((count($S)==1?key($S):DB),(DB==""||count($S)>1));$Td=preg_match('~sql~',$_POST["format"]);if($Td){echo"-- Adminer $ia ".$ec[DRIVER]." dump\n\n";if($x=="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';");}}$xh=$_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($Td&&preg_match('~CREATE~',$xh)&&($i=$g->result("SHOW CREATE DATABASE ".idf_escape($m),1))){set_utf8mb4($i);if($xh=="DROP+CREATE")echo"DROP DATABASE IF EXISTS ".idf_escape($m).";\n";echo"$i;\n";}if($Td){if($xh)echo
use_sql($m).";\n\n";$Af="";if($_POST["routines"]){foreach(array("FUNCTION","PROCEDURE")as$Lg){foreach(get_rows("SHOW $Lg STATUS WHERE Db = ".q($m),null,"-- ")as$J){$i=remove_definer($g->result("SHOW CREATE $Lg ".idf_escape($J["Name"]),2));set_utf8mb4($i);$Af.=($xh!='DROP+CREATE'?"DROP $Lg IF EXISTS ".idf_escape($J["Name"]).";;\n":"")."$i;;\n\n";}}}if($_POST["events"]){foreach(get_rows("SHOW EVENTS",null,"-- ")as$J){$i=remove_definer($g->result("SHOW CREATE EVENT ".idf_escape($J["Name"]),3));set_utf8mb4($i);$Af.=($xh!='DROP+CREATE'?"DROP EVENT IF EXISTS ".idf_escape($J["Name"]).";;\n":"")."$i;;\n\n";}}if($Af)echo"DELIMITER ;;\n\n$Af"."DELIMITER ;\n\n";}if($_POST["table_style"]||$_POST["data_style"]){$Ni=array();foreach(table_status('',true)as$C=>$R){$Q=(DB==""||in_array($C,(array)$_POST["tables"]));$Lb=(DB==""||in_array($C,(array)$_POST["data"]));if($Q||$Lb){if($Ic=="tar"){$Zh=new
TmpFile;ob_start(array($Zh,'write'),1e5);}$b->dumpTable($C,($Q?$_POST["table_style"]:""),(is_view($R)?2:0));if(is_view($R))$Ni[]=$C;elseif($Lb){$p=fields($C);$b->dumpData($C,$_POST["data_style"],"SELECT *".convert_fields($p,$p)." FROM ".table($C));}if($Td&&$_POST["triggers"]&&$Q&&($oi=trigger_sql($C)))echo"\nDELIMITER ;;\n$oi\nDELIMITER ;\n";if($Ic=="tar"){ob_end_flush();tar_file((DB!=""?"":"$m/")."$C.csv",$Zh);}elseif($Td)echo"\n";}}foreach($Ni
as$Mi)$b->dumpTable($Mi,$_POST["table_style"],1);if($Ic=="tar")echo
pack("x512");}}}if($Td)echo"-- ".$g->result("SELECT NOW()")."\n";exit;}page_header(lang(70),$n,($_GET["export"]!=""?array("table"=>$_GET["export"]):array()),h(DB));echo'
';$Vc=true;foreach($Zf
as$y=>$X){if($y!=""&&$X>1){echo($Vc?"":" ")."".h($y)."";$Vc=false;}}}elseif(isset($_GET["privileges"])){page_header(lang(68));echo' '.lang(139)."";$H=$g->query("SELECT User, Host FROM mysql.".(DB==""?"user":"db WHERE ".q(DB)." LIKE Db")." ORDER BY Host, User");$kd=$H;if(!$H)$H=$g->query("SELECT SUBSTRING_INDEX(CURRENT_USER, '@', 1) AS User, SUBSTRING_INDEX(CURRENT_USER, '@', -1) AS Host");echo" \n";}elseif(isset($_GET["sql"])){if(!$n&&$_POST["export"]){dump_headers("sql");$b->dumpTable("","");$b->dumpData("","table",$_POST["query"]);exit;}restart_session();$vd=&get_session("queries");$ud=&$vd[DB];if(!$n&&$_POST["clear"]){$ud=array();redirect(remove_from_uri("history"));}page_header((isset($_GET["import"])?lang(69):lang(61)),$n);if(!$n&&$_POST){$gd=false;if(!isset($_GET["import"]))$G=$_POST["query"];elseif($_POST["webfile"]){$qh=$b->importServerPath();$gd=@fopen((file_exists($qh)?$qh:"compress.zlib://$qh.gz"),"rb");$G=($gd?fread($gd,1e6):false);}else$G=get_file("sql_file",true);if(is_string($G)){if(function_exists('memory_get_usage'))@ini_set("memory_limit",max(ini_bytes("memory_limit"),2*strlen($G)+memory_get_usage()+8e6));if($G!=""&&strlen($G)<1e6){$lg=$G.(preg_match("~;[ \t\r\n]*\$~",$G)?"":";");if(!$ud||reset(end($ud))!=$lg){restart_session();$ud[]=array($lg,time());set_session("queries",$vd);stop_session();}}$mh="(?:\\s|/\\*[\s\S]*?\\*/|(?:#|-- )[^\n]*\n?|--\r?\n)";$Ub=";";$D=0;$tc=true;$h=connect();if(is_object($h)&&DB!="")$h->select_db(DB);$ub=0;$yc=array();$Gf='[\'"'.($x=="sql"?'`#':($x=="sqlite"?'`[':($x=="mssql"?'[':''))).']|/\\*|-- |$'.($x=="pgsql"?'|\\$[^$]*\\$':'');$ei=microtime(true);parse_str($_COOKIE["adminer_export"],$ya);$kc=$b->dumpFormat();unset($kc["sql"]);while($G!=""){if(!$D&&preg_match("~^$mh*+DELIMITER\\s+(\\S+)~i",$G,$B)){$Ub=$B[1];$G=substr($G,strlen($B[0]));}else{preg_match('('.preg_quote($Ub)."\\s*|$Gf)",$G,$B,PREG_OFFSET_CAPTURE,$D);list($ed,$Uf)=$B[0];if(!$ed&&$gd&&!feof($gd))$G.=fread($gd,1e5);else{if(!$ed&&rtrim($G)=="")break;$D=$Uf+strlen($ed);if($ed&&rtrim($ed)!=$Ub){while(preg_match('('.($ed=='/*'?'\\*/':($ed=='['?']':(preg_match('~^-- |^#~',$ed)?"\n":preg_quote($ed)."|\\\\."))).'|$)s',$G,$B,PREG_OFFSET_CAPTURE,$D)){$Pg=$B[0][0];if(!$Pg&&$gd&&!feof($gd))$G.=fread($gd,1e5);else{$D=$B[0][1]+strlen($Pg);if($Pg[0]!="\\")break;}}}else{$tc=false;$lg=substr($G,0,$Uf);$ub++;$cg="".$b->sqlCommandQuery($lg)." \n";if($x=="sqlite"&&preg_match("~^$mh*+ATTACH\\b~i",$lg,$B)){echo$cg,"".lang(140)."\n";$yc[]=" $ub";if($_POST["error_stops"])break;}else{if(!$_POST["only_errors"]){echo$cg;ob_flush();flush();}$sh=microtime(true);if($g->multi_query($lg)&&is_object($h)&&preg_match("~^$mh*+USE\\b~i",$lg))$h->query($lg);do{$H=$g->store_result();$Sh=" (".format_time($sh).")".(strlen($lg)<1000?" ".lang(10)."":"");if($g->error){echo($_POST["only_errors"]?$cg:"")," ".lang(141).($g->errno?" ($g->errno)":"").": ".error()."\n";$yc[]=" $ub";if($_POST["error_stops"])break
2;}elseif(is_object($H)){$z=$_POST["limit"];$uf=select($H,$h,array(),$z);if(!$_POST["only_errors"]){echo" \n";}}else{if(preg_match("~^$mh*+(CREATE|DROP|ALTER)$mh++(DATABASE|SCHEMA)\\b~i",$lg)){restart_session();set_session("dbs",null);stop_session();}if(!$_POST["only_errors"])echo"".lang(144,$g->affected_rows)."$Sh\n";}$sh=microtime(true);}while($g->next_result());}$G=substr($G,$D);$D=0;}}}}if($tc)echo" ".lang(145)."\n";elseif($_POST["only_errors"]){echo" ".lang(146,$ub-count($yc))," (".format_time($ei).")\n";}elseif($yc&&$ub>1)echo" ".lang(141).": ".implode("",$yc)."\n";}else
echo" ".upload_error($G)."\n";}echo'
';}elseif(isset($_GET["edit"])){$a=$_GET["edit"];$p=fields($a);$Z=(isset($_GET["select"])?($_POST["check"]&&count($_POST["check"])==1?where_check($_POST["check"][0],$p):""):where($_GET,$p));$yi=(isset($_GET["select"])?$_POST["edit"]:$Z);foreach($p
as$C=>$o){if(!isset($o["privileges"][$yi?"update":"insert"])||$b->fieldName($o)=="")unset($p[$C]);}if($_POST&&!$n&&!isset($_GET["select"])){$A=$_POST["referer"];if($_POST["insert"])$A=($yi?null:$_SERVER["REQUEST_URI"]);elseif(!preg_match('~^.+&select=.+$~',$A))$A=ME."select=".urlencode($a);$w=indexes($a);$ti=unique_array($_GET["where"],$w);$og="\nWHERE $Z";if(isset($_POST["delete"]))queries_redirect($A,lang(159),$dc->delete($a,$og,!$ti));else{$N=array();foreach($p
as$C=>$o){$X=process_input($o);if($X!==false&&$X!==null)$N[idf_escape($C)]=$X;}if($yi){if(!$N)redirect($A);queries_redirect($A,lang(160),$dc->update($a,$N,$og,!$ti));if(is_ajax()){page_headers();page_messages($n);exit;}}else{$H=$dc->insert($a,$N);$ke=($H?last_id():0);queries_redirect($A,lang(161,($ke?" $ke":"")),$H);}}}$J=null;if($_POST["save"])$J=(array)$_POST["fields"];elseif($Z){$L=array();foreach($p
as$C=>$o){if(isset($o["privileges"]["select"])){$Ha=convert_field($o);if($_POST["clone"]&&$o["auto_increment"])$Ha="''";if($x=="sql"&&preg_match("~enum|set~",$o["type"]))$Ha="1*".idf_escape($C);$L[]=($Ha?"$Ha AS ":"").idf_escape($C);}}$J=array();if(!support("table"))$L=array("*");if($L){$H=$dc->select($a,$L,array($Z),$L,array(),(isset($_GET["select"])?2:1));if(!$H)$n=error();else{$J=$H->fetch_assoc();if(!$J)$J=false;}if(isset($_GET["select"])&&(!$J||$H->fetch_assoc()))$J=null;}}if(!support("table")&&!$p){if(!$Z){$H=$dc->select($a,array("*"),$Z,array("*"));$J=($H?$H->fetch_assoc():false);if(!$J)$J=array($dc->primary=>"");}if($J){foreach($J
as$y=>$X){if(!$Z)$J[$y]=null;$p[$y]=array("field"=>$y,"null"=>($y!=$dc->primary),"auto_increment"=>($y==$dc->primary));}}}edit_form($a,$p,$J,$yi);}elseif(isset($_GET["create"])){$a=$_GET["create"];$If=array();foreach(array('HASH','LINEAR HASH','KEY','LINEAR KEY','RANGE','LIST')as$y)$If[$y]=$y;$wg=referencable_primary($a);$cd=array();foreach($wg
as$Dh=>$o)$cd[str_replace("`","``",$Dh)."`".str_replace("`","``",$o["field"])]=$Dh;$xf=array();$R=array();if($a!=""){$xf=fields($a);$R=table_status($a);if(!$R)$n=lang(9);}$J=$_POST;$J["fields"]=(array)$J["fields"];if($J["auto_increment_col"])$J["fields"][$J["auto_increment_col"]]["auto_increment"]=true;if($_POST&&!process_fields($J["fields"])&&!$n){if($_POST["drop"])queries_redirect(substr(ME,0,-1),lang(162),drop_tables(array($a)));else{$p=array();$Ea=array();$Ci=false;$ad=array();$wf=reset($xf);$Ba=" FIRST";foreach($J["fields"]as$y=>$o){$q=$cd[$o["type"]];$pi=($q!==null?$wg[$q]:$o);if($o["field"]!=""){if(!$o["has_default"])$o["default"]=null;if($y==$J["auto_increment_col"])$o["auto_increment"]=true;$hg=process_field($o,$pi);$Ea[]=array($o["orig"],$hg,$Ba);if($hg!=process_field($wf,$wf)){$p[]=array($o["orig"],$hg,$Ba);if($o["orig"]!=""||$Ba)$Ci=true;}if($q!==null)$ad[idf_escape($o["field"])]=($a!=""&&$x!="sqlite"?"ADD":" ").format_foreign_key(array('table'=>$cd[$o["type"]],'source'=>array($o["field"]),'target'=>array($pi["field"]),'on_delete'=>$o["on_delete"],));$Ba=" AFTER ".idf_escape($o["field"]);}elseif($o["orig"]!=""){$Ci=true;$p[]=array($o["orig"]);}if($o["orig"]!=""){$wf=next($xf);if(!$wf)$Ba="";}}$Kf="";if($If[$J["partition_by"]]){$Lf=array();if($J["partition_by"]=='RANGE'||$J["partition_by"]=='LIST'){foreach(array_filter($J["partition_names"])as$y=>$X){$Y=$J["partition_values"][$y];$Lf[]="\n PARTITION ".idf_escape($X)." VALUES ".($J["partition_by"]=='RANGE'?"LESS THAN":"IN").($Y!=""?" ($Y)":" MAXVALUE");}}$Kf.="\nPARTITION BY $J[partition_by]($J[partition])".($Lf?" (".implode(",",$Lf)."\n)":($J["partitions"]?" PARTITIONS ".(+$J["partitions"]):""));}elseif(support("partitioning")&&preg_match("~partitioned~",$R["Create_options"]))$Kf.="\nREMOVE PARTITIONING";$Ee=lang(163);if($a==""){cookie("adminer_engine",$J["Engine"]);$Ee=lang(164);}$C=trim($J["name"]);queries_redirect(ME.(support("table")?"table=":"select=").urlencode($C),$Ee,alter_table($a,$C,($x=="sqlite"&&($Ci||$ad)?$Ea:$p),$ad,($J["Comment"]!=$R["Comment"]?$J["Comment"]:null),($J["Engine"]&&$J["Engine"]!=$R["Engine"]?$J["Engine"]:""),($J["Collation"]&&$J["Collation"]!=$R["Collation"]?$J["Collation"]:""),($J["Auto_increment"]!=""?number($J["Auto_increment"]):""),$Kf));}}page_header(($a!=""?lang(42):lang(71)),$n,array("table"=>$a),h($a));if(!$_POST){$J=array("Engine"=>$_COOKIE["adminer_engine"],"fields"=>array(array("field"=>"","type"=>(isset($U["int"])?"int":(isset($U["integer"])?"integer":"")))),"partition_names"=>array(""),);if($a!=""){$J=$R;$J["name"]=$a;$J["fields"]=array();if(!$_GET["auto_increment"])$J["Auto_increment"]="";foreach($xf
as$o){$o["has_default"]=isset($o["default"]);$J["fields"][]=$o;}if(support("partitioning")){$hd="FROM information_schema.PARTITIONS WHERE TABLE_SCHEMA = ".q(DB)." AND TABLE_NAME = ".q($a);$H=$g->query("SELECT PARTITION_METHOD, PARTITION_ORDINAL_POSITION, PARTITION_EXPRESSION $hd ORDER BY PARTITION_ORDINAL_POSITION DESC LIMIT 1");list($J["partition_by"],$J["partitions"],$J["partition"])=$H->fetch_row();$Lf=get_key_vals("SELECT PARTITION_NAME, PARTITION_DESCRIPTION $hd AND PARTITION_NAME != '' ORDER BY PARTITION_ORDINAL_POSITION");$Lf[""]="";$J["partition_names"]=array_keys($Lf);$J["partition_values"]=array_values($Lf);}}}$qb=collations();$vc=engines();foreach($vc
as$uc){if(!strcasecmp($uc,$J["Engine"])){$J["Engine"]=$uc;break;}}echo'
';}elseif(isset($_GET["indexes"])){$a=$_GET["indexes"];$Dd=array("PRIMARY","UNIQUE","INDEX");$R=table_status($a,true);$ch=$g->server_info;$id=($ch>=5.6);$nh=($ch>=5.7);if(preg_match('~([\d.]+)-MariaDB~',$ch,$B)){$ch=$B[1];$id=(version_compare($ch,'10.0.5')>=0);$nh=(version_compare($ch,'10.2.2')>=0);}if(preg_match('~MyISAM|M?aria'.($id?'|InnoDB':'').'~i',$R["Engine"]))$Dd[]="FULLTEXT";if(preg_match('~MyISAM|M?aria'.($nh?'|InnoDB':'').'~i',$R["Engine"]))$Dd[]="SPATIAL";$w=indexes($a);$ag=array();if($x=="mongo"){$ag=$w["_id_"];unset($Dd[0]);unset($w["_id_"]);}$J=$_POST;if($_POST&&!$n&&!$_POST["add"]&&!$_POST["drop_col"]){$c=array();foreach($J["indexes"]as$v){$C=$v["name"];if(in_array($v["type"],$Dd)){$e=array();$qe=array();$Wb=array();$N=array();ksort($v["columns"]);foreach($v["columns"]as$y=>$d){if($d!=""){$pe=$v["lengths"][$y];$Vb=$v["descs"][$y];$N[]=idf_escape($d).($pe?"(".(+$pe).")":"").($Vb?" DESC":"");$e[]=$d;$qe[]=($pe?$pe:null);$Wb[]=$Vb;}}if($e){$Dc=$w[$C];if($Dc){ksort($Dc["columns"]);ksort($Dc["lengths"]);ksort($Dc["descs"]);if($v["type"]==$Dc["type"]&&array_values($Dc["columns"])===$e&&(!$Dc["lengths"]||array_values($Dc["lengths"])===$qe)&&array_values($Dc["descs"])===$Wb){unset($w[$C]);continue;}}$c[]=array($v["type"],$C,$N);}}}foreach($w
as$C=>$Dc)$c[]=array($Dc["type"],$C,"DROP");if(!$c)redirect(ME."table=".urlencode($a));queries_redirect(ME."table=".urlencode($a),lang(173),alter_indexes($a,$c));}page_header(lang(125),$n,array("table"=>$a),h($a));$p=array_keys(fields($a));if($_POST["add"]){foreach($J["indexes"]as$y=>$v){if($v["columns"][count($v["columns"])]!="")$J["indexes"][$y]["columns"][]="";}$v=end($J["indexes"]);if($v["type"]||array_filter($v["columns"],'strlen'))$J["indexes"][]=array("columns"=>array(1=>""));}if(!$J){foreach($w
as$y=>$v){$w[$y]["name"]=$y;$w[$y]["columns"][]="";}$w[]=array("columns"=>array(1=>""));$J["indexes"]=$w;}echo'
';}elseif(isset($_GET["database"])){$J=$_POST;if($_POST&&!$n&&!isset($_POST["add_x"])){$C=trim($J["name"]);if($_POST["drop"]){$_GET["db"]="";queries_redirect(remove_from_uri("db|database"),lang(177),drop_databases(array(DB)));}elseif(DB!==$C){if(DB!=""){$_GET["db"]=$C;queries_redirect(preg_replace('~\bdb=[^&]*&~','',ME)."db=".urlencode($C),lang(178),rename_database($C,$J["collation"]));}else{$l=explode("\n",str_replace("\r","",$C));$yh=true;$je="";foreach($l
as$m){if(count($l)==1||$m!=""){if(!create_database($m,$J["collation"]))$yh=false;$je=$m;}}restart_session();set_session("dbs",null);queries_redirect(ME."db=".urlencode($je),lang(179),$yh);}}else{if(!$J["collation"])redirect(substr(ME,0,-1));query_redirect("ALTER DATABASE ".idf_escape($C).(preg_match('~^[a-z0-9_]+$~i',$J["collation"])?" COLLATE $J[collation]":""),substr(ME,0,-1),lang(180));}}page_header(DB!=""?lang(64):lang(108),$n,array(),h(DB));$qb=collations();$C=DB;if($_POST)$C=$J["name"];elseif(DB!="")$J["collation"]=db_collation(DB,$qb);elseif($x=="sql"){foreach(get_vals("SHOW GRANTS")as$kd){if(preg_match('~ ON (`(([^\\\\`]|``|\\\\.)*)%`\\.\\*)?~',$kd,$B)&&$B[1]){$C=stripcslashes(idf_unescape("`$B[2]`"));break;}}}echo'
';}elseif(isset($_GET["scheme"])){$J=$_POST;if($_POST&&!$n){$_=preg_replace('~ns=[^&]*&~','',ME)."ns=";if($_POST["drop"])query_redirect("DROP SCHEMA ".idf_escape($_GET["ns"]),$_,lang(181));else{$C=trim($J["name"]);$_.=urlencode($C);if($_GET["ns"]=="")query_redirect("CREATE SCHEMA ".idf_escape($C),$_,lang(182));elseif($_GET["ns"]!=$C)query_redirect("ALTER SCHEMA ".idf_escape($_GET["ns"])." RENAME TO ".idf_escape($C),$_,lang(183));else
redirect($_);}}page_header($_GET["ns"]!=""?lang(65):lang(66),$n);if(!$J)$J["name"]=$_GET["ns"];echo'
';}elseif(isset($_GET["call"])){$da=$_GET["call"];page_header(lang(184).": ".h($da),$n);$Lg=routine($da,(isset($_GET["callf"])?"FUNCTION":"PROCEDURE"));$Bd=array();$Af=array();foreach($Lg["fields"]as$s=>$o){if(substr($o["inout"],-3)=="OUT")$Af[$s]="@".idf_escape($o["field"])." AS ".idf_escape($o["field"]);if(!$o["inout"]||substr($o["inout"],0,2)=="IN")$Bd[]=$s;}if(!$n&&$_POST){$ab=array();foreach($Lg["fields"]as$y=>$o){if(in_array($y,$Bd)){$X=process_input($o);if($X===false)$X="''";if(isset($Af[$y]))$g->query("SET @".idf_escape($o["field"])." = $X");}$ab[]=(isset($Af[$y])?"@".idf_escape($o["field"]):$X);}$G=(isset($_GET["callf"])?"SELECT":"CALL")." ".table($da)."(".implode(", ",$ab).")";echo"".h($G)." ".lang(10)."\n";if(!$g->multi_query($G))echo"
".error()."\n";else{$h=connect();if(is_object($h))$h->select_db(DB);do{$H=$g->store_result();if(is_object($H))select($H,$h);else
echo" ".lang(185,$g->affected_rows)."\n";}while($g->next_result());if($Af)select($g->query("SELECT ".implode(", ",$Af)));}}echo'
';}elseif(isset($_GET["foreign"])){$a=$_GET["foreign"];$C=$_GET["name"];$J=$_POST;if($_POST&&!$n&&!$_POST["add"]&&!$_POST["change"]&&!$_POST["change-js"]){$Ee=($_POST["drop"]?lang(186):($C!=""?lang(187):lang(188)));$A=ME."table=".urlencode($a);if(!$_POST["drop"]){$J["source"]=array_filter($J["source"],'strlen');ksort($J["source"]);$Lh=array();foreach($J["source"]as$y=>$X)$Lh[$y]=$J["target"][$y];$J["target"]=$Lh;}if($x=="sqlite")queries_redirect($A,$Ee,recreate_table($a,$a,array(),array(),array(" $C"=>($_POST["drop"]?"":" ".format_foreign_key($J)))));else{$c="ALTER TABLE ".table($a);$fc="\nDROP ".($x=="sql"?"FOREIGN KEY ":"CONSTRAINT ").idf_escape($C);if($_POST["drop"])query_redirect($c.$fc,$A,$Ee);else{query_redirect($c.($C!=""?"$fc,":"")."\nADD".format_foreign_key($J),$A,$Ee);$n=lang(189)." $n";}}}page_header(lang(190),$n,array("table"=>$a),h($a));if($_POST){ksort($J["source"]);if($_POST["add"])$J["source"][]="";elseif($_POST["change"]||$_POST["change-js"])$J["target"]=array();}elseif($C!=""){$cd=foreign_keys($a);$J=$cd[$C];$J["source"][]="";}else{$J["table"]=$a;$J["source"]=array("");}$lh=array_keys(fields($a));$Lh=($a===$J["table"]?$lh:array_keys(fields($J["table"])));$vg=array_keys(array_filter(table_status('',true),'fk_support'));echo'
';}elseif(isset($_GET["view"])){$a=$_GET["view"];$J=$_POST;$yf="VIEW";if($x=="pgsql"&&$a!=""){$O=table_status($a);$yf=strtoupper($O["Engine"]);}if($_POST&&!$n){$C=trim($J["name"]);$Ha=" AS\n$J[select]";$A=ME."table=".urlencode($C);$Ee=lang(194);$T=($_POST["materialized"]?"MATERIALIZED VIEW":"VIEW");if(!$_POST["drop"]&&$a==$C&&$x!="sqlite"&&$T=="VIEW"&&$yf=="VIEW")query_redirect(($x=="mssql"?"ALTER":"CREATE OR REPLACE")." VIEW ".table($C).$Ha,$A,$Ee);else{$Nh=$C."_adminer_".uniqid();drop_create("DROP $yf ".table($a),"CREATE $T ".table($C).$Ha,"DROP $T ".table($C),"CREATE $T ".table($Nh).$Ha,"DROP $T ".table($Nh),($_POST["drop"]?substr(ME,0,-1):$A),lang(195),$Ee,lang(196),$a,$C);}}if(!$_POST&&$a!=""){$J=view($a);$J["name"]=$a;$J["materialized"]=($yf!="VIEW");if(!$n)$n=error();}page_header(($a!=""?lang(41):lang(197)),$n,array("table"=>$a),h($a));echo'
';}elseif(isset($_GET["event"])){$aa=$_GET["event"];$Od=array("YEAR","QUARTER","MONTH","DAY","HOUR","MINUTE","WEEK","SECOND","YEAR_MONTH","DAY_HOUR","DAY_MINUTE","DAY_SECOND","HOUR_MINUTE","HOUR_SECOND","MINUTE_SECOND");$uh=array("ENABLED"=>"ENABLE","DISABLED"=>"DISABLE","SLAVESIDE_DISABLED"=>"DISABLE ON SLAVE");$J=$_POST;if($_POST&&!$n){if($_POST["drop"])query_redirect("DROP EVENT ".idf_escape($aa),substr(ME,0,-1),lang(198));elseif(in_array($J["INTERVAL_FIELD"],$Od)&&isset($uh[$J["STATUS"]])){$Qg="\nON SCHEDULE ".($J["INTERVAL_VALUE"]?"EVERY ".q($J["INTERVAL_VALUE"])." $J[INTERVAL_FIELD]".($J["STARTS"]?" STARTS ".q($J["STARTS"]):"").($J["ENDS"]?" ENDS ".q($J["ENDS"]):""):"AT ".q($J["STARTS"]))." ON COMPLETION".($J["ON_COMPLETION"]?"":" NOT")." PRESERVE";queries_redirect(substr(ME,0,-1),($aa!=""?lang(199):lang(200)),queries(($aa!=""?"ALTER EVENT ".idf_escape($aa).$Qg.($aa!=$J["EVENT_NAME"]?"\nRENAME TO ".idf_escape($J["EVENT_NAME"]):""):"CREATE EVENT ".idf_escape($J["EVENT_NAME"]).$Qg)."\n".$uh[$J["STATUS"]]." COMMENT ".q($J["EVENT_COMMENT"]).rtrim(" DO\n$J[EVENT_DEFINITION]",";").";"));}}page_header(($aa!=""?lang(201).": ".h($aa):lang(202)),$n);if(!$J&&$aa!=""){$K=get_rows("SELECT * FROM information_schema.EVENTS WHERE EVENT_SCHEMA = ".q(DB)." AND EVENT_NAME = ".q($aa));$J=reset($K);}echo'
';}elseif(isset($_GET["procedure"])){$da=$_GET["procedure"];$Lg=(isset($_GET["function"])?"FUNCTION":"PROCEDURE");$J=$_POST;$J["fields"]=(array)$J["fields"];if($_POST&&!process_fields($J["fields"])&&!$n){$Nh="$J[name]_adminer_".uniqid();drop_create("DROP $Lg ".idf_escape($da),create_routine($Lg,$J),"DROP $Lg ".idf_escape($J["name"]),create_routine($Lg,array("name"=>$Nh)+$J),"DROP $Lg ".idf_escape($Nh),substr(ME,0,-1),lang(207),lang(208),lang(209),$da,$J["name"]);}page_header(($da!=""?(isset($_GET["function"])?lang(210):lang(211)).": ".h($da):(isset($_GET["function"])?lang(212):lang(213))),$n);if(!$_POST&&$da!=""){$J=routine($da,$Lg);$J["name"]=$da;}$qb=get_vals("SHOW CHARACTER SET");sort($qb);$Mg=routine_languages();echo'
';}elseif(isset($_GET["sequence"])){$fa=$_GET["sequence"];$J=$_POST;if($_POST&&!$n){$_=substr(ME,0,-1);$C=trim($J["name"]);if($_POST["drop"])query_redirect("DROP SEQUENCE ".idf_escape($fa),$_,lang(215));elseif($fa=="")query_redirect("CREATE SEQUENCE ".idf_escape($C),$_,lang(216));elseif($fa!=$C)query_redirect("ALTER SEQUENCE ".idf_escape($fa)." RENAME TO ".idf_escape($C),$_,lang(217));else
redirect($_);}page_header($fa!=""?lang(218).": ".h($fa):lang(219),$n);if(!$J)$J["name"]=$fa;echo'
';}elseif(isset($_GET["type"])){$ga=$_GET["type"];$J=$_POST;if($_POST&&!$n){$_=substr(ME,0,-1);if($_POST["drop"])query_redirect("DROP TYPE ".idf_escape($ga),$_,lang(220));else
query_redirect("CREATE TYPE ".idf_escape(trim($J["name"]))." $J[as]",$_,lang(221));}page_header($ga!=""?lang(222).": ".h($ga):lang(223),$n);if(!$J)$J["as"]="AS ";echo'
';}elseif(isset($_GET["trigger"])){$a=$_GET["trigger"];$C=$_GET["name"];$ni=trigger_options();$J=(array)trigger($C)+array("Trigger"=>$a."_bi");if($_POST){if(!$n&&in_array($_POST["Timing"],$ni["Timing"])&&in_array($_POST["Event"],$ni["Event"])&&in_array($_POST["Type"],$ni["Type"])){$gf=" ON ".table($a);$fc="DROP TRIGGER ".idf_escape($C).($x=="pgsql"?$gf:"");$A=ME."table=".urlencode($a);if($_POST["drop"])query_redirect($fc,$A,lang(224));else{if($C!="")queries($fc);queries_redirect($A,($C!=""?lang(225):lang(226)),queries(create_trigger($gf,$_POST)));if($C!="")queries(create_trigger($gf,$J+array("Type"=>reset($ni["Type"]))));}}$J=$_POST;}page_header(($C!=""?lang(227).": ".h($C):lang(228)),$n,array("table"=>$a));echo'
';}elseif(isset($_GET["user"])){$ha=$_GET["user"];$fg=array(""=>array("All privileges"=>""));foreach(get_rows("SHOW PRIVILEGES")as$J){foreach(explode(",",($J["Privilege"]=="Grant option"?"":$J["Context"]))as$Bb)$fg[$Bb][$J["Privilege"]]=$J["Comment"];}$fg["Server Admin"]+=$fg["File access on server"];$fg["Databases"]["Create routine"]=$fg["Procedures"]["Create routine"];unset($fg["Procedures"]["Create routine"]);$fg["Columns"]=array();foreach(array("Select","Insert","Update","References")as$X)$fg["Columns"][$X]=$fg["Tables"][$X];unset($fg["Server Admin"]["Usage"]);foreach($fg["Tables"]as$y=>$X)unset($fg["Databases"][$y]);$Re=array();if($_POST){foreach($_POST["objects"]as$y=>$X)$Re[$X]=(array)$Re[$X]+(array)$_POST["grants"][$y];}$ld=array();$ef="";if(isset($_GET["host"])&&($H=$g->query("SHOW GRANTS FOR ".q($ha)."@".q($_GET["host"])))){while($J=$H->fetch_row()){if(preg_match('~GRANT (.*) ON (.*) TO ~',$J[0],$B)&&preg_match_all('~ *([^(,]*[^ ,(])( *\\([^)]+\\))?~',$B[1],$xe,PREG_SET_ORDER)){foreach($xe
as$X){if($X[1]!="USAGE")$ld["$B[2]$X[2]"][$X[1]]=true;if(preg_match('~ WITH GRANT OPTION~',$J[0]))$ld["$B[2]$X[2]"]["GRANT OPTION"]=true;}}if(preg_match("~ IDENTIFIED BY PASSWORD '([^']+)~",$J[0],$B))$ef=$B[1];}}if($_POST&&!$n){$ff=(isset($_GET["host"])?q($ha)."@".q($_GET["host"]):"''");if($_POST["drop"])query_redirect("DROP USER $ff",ME."privileges=",lang(231));else{$Te=q($_POST["user"])."@".q($_POST["host"]);$Nf=$_POST["pass"];if($Nf!=''&&!$_POST["hashed"]){$Nf=$g->result("SELECT PASSWORD(".q($Nf).")");$n=!$Nf;}$Gb=false;if(!$n){if($ff!=$Te){$Gb=queries(($g->server_info<5?"GRANT USAGE ON *.* TO":"CREATE USER")." $Te IDENTIFIED BY PASSWORD ".q($Nf));$n=!$Gb;}elseif($Nf!=$ef)queries("SET PASSWORD FOR $Te = ".q($Nf));}if(!$n){$Ig=array();foreach($Re
as$Ze=>$kd){if(isset($_GET["grant"]))$kd=array_filter($kd);$kd=array_keys($kd);if(isset($_GET["grant"]))$Ig=array_diff(array_keys(array_filter($Re[$Ze],'strlen')),$kd);elseif($ff==$Te){$cf=array_keys((array)$ld[$Ze]);$Ig=array_diff($cf,$kd);$kd=array_diff($kd,$cf);unset($ld[$Ze]);}if(preg_match('~^(.+)\\s*(\\(.*\\))?$~U',$Ze,$B)&&(!grant("REVOKE",$Ig,$B[2]," ON $B[1] FROM $Te")||!grant("GRANT",$kd,$B[2]," ON $B[1] TO $Te"))){$n=true;break;}}}if(!$n&&isset($_GET["host"])){if($ff!=$Te)queries("DROP USER $ff");elseif(!isset($_GET["grant"])){foreach($ld
as$Ze=>$Ig){if(preg_match('~^(.+)(\\(.*\\))?$~U',$Ze,$B))grant("REVOKE",array_keys($Ig),$B[2]," ON $B[1] FROM $Te");}}}queries_redirect(ME."privileges=",(isset($_GET["host"])?lang(232):lang(233)),!$n);if($Gb)$g->query("DROP USER $Te");}}page_header((isset($_GET["host"])?lang(33).": ".h("$ha@$_GET[host]"):lang(139)),$n,array("privileges"=>array('',lang(68))));if($_POST){$J=$_POST;$ld=$Re;}else{$J=$_GET+array("host"=>$g->result("SELECT SUBSTRING_INDEX(CURRENT_USER, '@', -1)"));$J["pass"]=$ef;if($ef!="")$J["hashed"]=true;$ld[(DB==""||$ld?"":idf_escape(addcslashes(DB,"%_\\"))).".*"]=array();}echo'
';}elseif(isset($_GET["processlist"])){if(support("kill")&&$_POST&&!$n){$ee=0;foreach((array)$_POST["kill"]as$X){if(kill_process($X))$ee++;}queries_redirect(ME."processlist=",lang(238,$ee),$ee||!$_POST["kill"]);}page_header(lang(109),$n);echo'
';}elseif(isset($_GET["select"])){$a=$_GET["select"];$R=table_status1($a);$w=indexes($a);$p=fields($a);$cd=column_foreign_keys($a);$bf="";if($R["Oid"]){$bf=($x=="sqlite"?"rowid":"oid");$w[]=array("type"=>"PRIMARY","columns"=>array($bf));}parse_str($_COOKIE["adminer_import"],$za);$Jg=array();$e=array();$Rh=null;foreach($p
as$y=>$o){$C=$b->fieldName($o);if(isset($o["privileges"]["select"])&&$C!=""){$e[$y]=html_entity_decode(strip_tags($C),ENT_QUOTES);if(is_shortable($o))$Rh=$b->selectLengthProcess();}$Jg+=$o["privileges"];}list($L,$md)=$b->selectColumnsProcess($e,$w);$Sd=count($md)selectSearchProcess($p,$w);$rf=$b->selectOrderProcess($p,$w);$z=$b->selectLimitProcess();$hd=($L?implode(", ",$L):"*".($bf?", $bf":"")).convert_fields($e,$p,$L)."\nFROM ".table($a);$nd=($md&&$Sd?"\nGROUP BY ".implode(", ",$md):"").($rf?"\nORDER BY ".implode(", ",$rf):"");if($_GET["val"]&&is_ajax()){header("Content-Type: text/plain; charset=utf-8");foreach($_GET["val"]as$ui=>$J){$Ha=convert_field($p[key($J)]);$L=array($Ha?$Ha:idf_escape(key($J)));$Z[]=where_check($ui,$p);$I=$dc->select($a,$L,$Z,$L);if($I)echo
reset($I->fetch_row());}exit;}if($_POST&&!$n){$Ui=$Z;if(!$_POST["all"]&&is_array($_POST["check"])){$gb=array();foreach($_POST["check"]as$db)$gb[]=where_check($db,$p);$Ui[]="((".implode(") OR (",$gb)."))";}$Ui=($Ui?"\nWHERE ".implode(" AND ",$Ui):"");$ag=$wi=null;foreach($w
as$v){if($v["type"]=="PRIMARY"){$ag=array_flip($v["columns"]);$wi=($L?$ag:array());break;}}foreach((array)$wi
as$y=>$X){if(in_array(idf_escape($y),$L))unset($wi[$y]);}if($_POST["export"]){cookie("adminer_import","output=".urlencode($_POST["output"])."&format=".urlencode($_POST["format"]));dump_headers($a);$b->dumpTable($a,"");if(!is_array($_POST["check"])||$wi===array())$G="SELECT $hd$Ui$nd";else{$si=array();foreach($_POST["check"]as$X)$si[]="(SELECT".limit($hd,"\nWHERE ".($Z?implode(" AND ",$Z)." AND ":"").where_check($X,$p).$nd,1).")";$G=implode(" UNION ALL ",$si);}$b->dumpData($a,"table",$G);exit;}if(!$b->selectEmailProcess($Z,$cd)){if($_POST["save"]||$_POST["delete"]){$H=true;$_a=0;$N=array();if(!$_POST["delete"]){foreach($e
as$C=>$X){$X=process_input($p[$C]);if($X!==null&&($_POST["clone"]||$X!==false))$N[idf_escape($C)]=($X!==false?$X:idf_escape($C));}}if($_POST["delete"]||$N){if($_POST["clone"])$G="INTO ".table($a)." (".implode(", ",array_keys($N)).")\nSELECT ".implode(", ",$N)."\nFROM ".table($a);if($_POST["all"]||($wi===array()&&is_array($_POST["check"]))||$Sd){$H=($_POST["delete"]?$dc->delete($a,$Ui):($_POST["clone"]?queries("INSERT $G$Ui"):$dc->update($a,$N,$Ui)));$_a=$g->affected_rows;}else{foreach((array)$_POST["check"]as$X){$Qi="\nWHERE ".($Z?implode(" AND ",$Z)." AND ":"").where_check($X,$p);$H=($_POST["delete"]?$dc->delete($a,$Qi,1):($_POST["clone"]?queries("INSERT".limit1($G,$Qi)):$dc->update($a,$N,$Qi)));if(!$H)break;$_a+=$g->affected_rows;}}}$Ee=lang(242,$_a);if($_POST["clone"]&&$H&&$_a==1){$ke=last_id();if($ke)$Ee=lang(161," $ke");}queries_redirect(remove_from_uri($_POST["all"]&&$_POST["delete"]?"page":""),$Ee,$H);if(!$_POST["delete"]){edit_form($a,$p,(array)$_POST["fields"],!$_POST["clone"]);page_footer();exit;}}elseif(!$_POST["import"]){if(!$_POST["val"])$n=lang(243);else{$H=true;$_a=0;foreach($_POST["val"]as$ui=>$J){$N=array();foreach($J
as$y=>$X){$y=bracket_escape($y,1);$N[idf_escape($y)]=(preg_match('~char|text~',$p[$y]["type"])||$X!=""?$b->processInput($p[$y],$X):"NULL");}$H=$dc->update($a,$N," WHERE ".($Z?implode(" AND ",$Z)." AND ":"").where_check($ui,$p),!($Sd||$wi===array())," ");if(!$H)break;$_a+=$g->affected_rows;}queries_redirect(remove_from_uri(),lang(242,$_a),$H);}}elseif(!is_string($Sc=get_file("csv_file",true)))$n=upload_error($Sc);elseif(!preg_match('~~u',$Sc))$n=lang(244);else{cookie("adminer_import","output=".urlencode($za["output"])."&format=".urlencode($_POST["separator"]));$H=true;$sb=array_keys($p);preg_match_all('~(?>"[^"]*"|[^"\\r\\n]+)+~',$Sc,$xe);$_a=count($xe[0]);$dc->begin();$Zg=($_POST["separator"]=="csv"?",":($_POST["separator"]=="tsv"?"\t":";"));$K=array();foreach($xe[0]as$y=>$X){preg_match_all("~((?>\"[^\"]*\")+|[^$Zg]*)$Zg~",$X.$Zg,$ye);if(!$y&&!array_diff($ye[1],$sb)){$sb=$ye[1];$_a--;}else{$N=array();foreach($ye[1]as$s=>$nb)$N[idf_escape($sb[$s])]=($nb==""&&$p[$sb[$s]]["null"]?"NULL":q(str_replace('""','"',preg_replace('~^"|"$~','',$nb))));$K[]=$N;}}$H=(!$K||$dc->insertUpdate($a,$K,$ag));if($H)$H=$dc->commit();queries_redirect(remove_from_uri("page"),lang(245,$_a),$H);$dc->rollback();}}}$Dh=$b->tableName($R);if(is_ajax()){page_headers();ob_start();}else
page_header(lang(50).": $Dh",$n);$N=null;if(isset($Jg["insert"])||!support("table")){$N="";foreach((array)$_GET["where"]as$X){if($cd[$X["col"]]&&count($cd[$X["col"]])==1&&($X["op"]=="="||(!$X["op"]&&!preg_match('~[_%]~',$X["val"]))))$N.="&set".urlencode("[".bracket_escape($X["col"])."]")."=".urlencode($X["val"]);}}$b->selectLinks($R,$N);if(!$e&&support("table"))echo"".lang(246).($p?".":": ".error())."\n";else{echo" \n";$E=$_GET["page"];if($E=="last"){$fd=$g->result(count_rows($a,$Z,$Sd,$md));$E=floor(max(0,$fd-1)/$z);}$Vg=$L;if(!$Vg){$Vg[]="*";if($bf)$Vg[]=$bf;}$Cb=convert_fields($e,$p,$L);if($Cb)$Vg[]=substr($Cb,2);$H=$dc->select($a,$Vg,$Z,$md,$rf,$z,$E,true);if(!$H)echo"".error()."\n";else{if($x=="mssql"&&$E)$H->seek($z*$E);$sc=array();echo" \n";}}if(is_ajax()){ob_end_clean();exit;}}elseif(isset($_GET["variables"])){$O=isset($_GET["status"]);page_header($O?lang(111):lang(110));$Ji=($O?show_status():show_variables());if(!$Ji)echo"".lang(12)."\n";else{echo" \n";foreach($Ji
as$y=>$X){echo"","".h($y)." "," | ".nbsp($X);}echo" | \n";}}elseif(isset($_GET["script"])){header("Content-Type: text/javascript; charset=utf-8");if($_GET["script"]=="db"){$Ah=array("Data_length"=>0,"Index_length"=>0,"Data_free"=>0);foreach(table_status()as$C=>$R){json_row("Comment-$C",nbsp($R["Comment"]));if(!is_view($R)){foreach(array("Engine","Collation")as$y)json_row("$y-$C",nbsp($R[$y]));foreach($Ah+array("Auto_increment"=>0,"Rows"=>0)as$y=>$X){if($R[$y]!=""){$X=format_number($R[$y]);json_row("$y-$C",($y=="Rows"&&$X&&$R["Engine"]==($ph=="pgsql"?"table":"InnoDB")?"~ $X":$X));if(isset($Ah[$y]))$Ah[$y]+=($R["Engine"]!="InnoDB"||$y!="Data_free"?$R[$y]:0);}elseif(array_key_exists($y,$R))json_row("$y-$C");}}}foreach($Ah
as$y=>$X)json_row("sum-$y",format_number($X));json_row("");}elseif($_GET["script"]=="kill")$g->query("KILL ".number($_POST["kill"]));elseif($_GET["script"]=="version"){$gd=file_open_lock(get_temp_dir()."/adminer.version");if($gd)file_write_unlock($gd,serialize(array("signature"=>$_POST["signature"],"version"=>$_POST["version"])));}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{$Jh=array_merge((array)$_POST["tables"],(array)$_POST["views"]);if($Jh&&!$n&&!$_POST["search"]){$H=true;$Ee="";if($x=="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"])$H=truncate_tables($_POST["tables"]);$Ee=lang(256);}elseif($_POST["move"]){$H=move_tables((array)$_POST["tables"],(array)$_POST["views"],$_POST["target"]);$Ee=lang(257);}elseif($_POST["copy"]){$H=copy_tables((array)$_POST["tables"],(array)$_POST["views"],$_POST["target"]);$Ee=lang(258);}elseif($_POST["drop"]){if($_POST["views"])$H=drop_views($_POST["views"]);if($H&&$_POST["tables"])$H=drop_tables($_POST["tables"]);$Ee=lang(259);}elseif($x!="sql"){$H=($x=="sqlite"?queries("VACUUM"):apply_queries("VACUUM".($_POST["optimize"]?"":" ANALYZE"),$_POST["tables"]));$Ee=lang(260);}elseif(!$_POST["tables"])$Ee=lang(9);elseif($H=queries(($_POST["optimize"]?"OPTIMIZE":($_POST["check"]?"CHECK":($_POST["repair"]?"REPAIR":"ANALYZE")))." TABLE ".implode(", ",array_map('idf_escape',$_POST["tables"])))){while($J=$H->fetch_assoc())$Ee.="".h($J["Table"]).": ".h($J["Msg_text"])." ";}queries_redirect(substr(ME,0,-1),$Ee,$H);}page_header(($_GET["ns"]==""?lang(35).": ".h(DB):lang(73).": ".h($_GET["ns"])),$n,true);if($b->homepage()){if($_GET["ns"]!==""){echo"".lang(261)."\n";$Ih=tables_list();if(!$Ih)echo"".lang(9)."\n";else{echo" \n",script("tableCheck();");}echo''.lang(71)."\n",(support("view")?''.lang(197)."\n":"");if(support("routine")){echo" ".lang(136)."\n";$Ng=routines();if($Ng){echo"\n";}echo''.(support("procedure")?''.lang(213).'':'').''.lang(212)."\n";}if(support("sequence")){echo" ".lang(277)."\n";$bh=get_vals("SELECT sequence_name FROM information_schema.sequences WHERE sequence_schema = current_schema() ORDER BY sequence_name");if($bh){echo"\n","".lang(176)." | \n";odd('');foreach($bh
as$X)echo"".h($X)."\n";echo" |
---|
\n";}echo"".lang(219)."\n";}if(support("type")){echo" ".lang(24)."\n";$Ei=types();if($Ei){echo"\n","".lang(176)." | \n";odd('');foreach($Ei
as$X)echo"".h($X)."\n";echo" |
---|
\n";}echo"".lang(223)."\n";}if(support("event")){echo" ".lang(137)."\n";$K=get_rows("SHOW EVENTS");if($K){echo"\n","".lang(176)." | ".lang(278)." | ".lang(203)." | ".lang(204)." | | \n";foreach($K
as$J){echo"","".h($J["Name"])," | ".($J["Execute at"]?lang(279)." | ".$J["Execute at"]:lang(205)." ".$J["Interval value"]." ".$J["Interval field"]." | $J[Starts]")," | $J[Ends]",' | '.lang(129).'';}echo" | \n";$_c=$g->result("SELECT @@event_scheduler");if($_c&&$_c!="ON")echo"event_scheduler : ".h($_c)."\n";}echo'
'.lang(202)."\n";}if($Ih)echo
script("ajaxSetHtml('".js_escape(ME)."script=db');");}}}page_footer(); |