fields($Q){$K=array();foreach(get_rows("SHOW FULL COLUMNS FROM ".table($Q))as$L){preg_match('~^([^( ]+)(?:\\((.+)\\))?( unsigned)?( zerofill)?$~',$L["Type"],$B);$K[$L["Field"]]=array("field"=>$L["Field"],"full_type"=>$L["Type"],"type"=>$B[1],"length"=>$B[2],"unsigned"=>ltrim($B[3].$B[4]),"default"=>($L["Default"]!=""||preg_match("~char|set~",$B[1])?$L["Default"]:null),"null"=>($L["Null"]=="YES"),"auto_increment"=>($L["Extra"]=="auto_increment"),"on_update"=>(preg_match('~^on update (.+)~i',$L["Extra"],$B)?$B[1]:""),"collation"=>$L["Collation"],"privileges"=>array_flip(preg_split('~, *~',$L["Privileges"])),"comment"=>$L["Comment"],"primary"=>($L["Key"]=="PRI"),);}return$K;}function
fields($Q){$K=array();foreach(get_rows("SHOW FULL COLUMNS FROM ".table($Q))as$L){preg_match('~^([^( ]+)(?:\\((.+)\\))?( unsigned)?( zerofill)?$~',$L["Type"],$B);$K[$L["Field"]]=array("field"=>$L["Field"],"full_type"=>$L["Type"],"type"=>isset($B[1])?$B[1]:null,"length"=>isset($B[2])?$B[2]:null,"unsigned"=>ltrim((isset($B[3])?$B[3]:'').(isset($B[4])?$B[4]:'')),"default"=>($L["Default"]!=""||preg_match("~char|set~",$B[1])?$L["Default"]:null),"null"=>($L["Null"]=="YES"),"auto_increment"=>($L["Extra"]=="auto_increment"),"on_update"=>(preg_match('~^on update (.+)~i',$L["Extra"],$B)?$B[1]:""),"collation"=>$L["Collation"],"privileges"=>array_flip(preg_split('~, *~',$L["Privileges"])),"comment"=>$L["Comment"],"primary"=>($L["Key"]=="PRI"),);}return$K;}function
indexes($Q,$f=null){$K=array();foreach(get_rows("SHOW INDEX FROM ".table($Q),$f)as$L){$K[$L["Key_name"]]["type"]=($L["Key_name"]=="PRIMARY"?"PRIMARY":($L["Index_type"]=="FULLTEXT"?"FULLTEXT":($L["Non_unique"]?"INDEX":"UNIQUE")));$K[$L["Key_name"]]["columns"][]=$L["Column_name"];$K[$L["Key_name"]]["lengths"][]=$L["Sub_part"];$K[$L["Key_name"]]["descs"][]=null;}return$K;}function
foreign_keys($Q){global$e,$Wd;static$ye='`(?:[^`]|``)+`';$K=array();$kb=$e->result("SHOW CREATE TABLE ".table($Q),1);if($kb){preg_match_all("~CONSTRAINT ($ye) FOREIGN KEY \\(((?:$ye,? ?)+)\\) REFERENCES ($ye)(?:\\.($ye))? \\(((?:$ye,? ?)+)\\)(?: ON DELETE ($Wd))?(?: ON UPDATE ($Wd))?~",$kb,$sd,PREG_SET_ORDER);foreach($sd
as$Uc=>$X){if($X[0]<$ag)unset($Tc[$Uc]);}}$Sc=&$Tc[$b->bruteForceKey()];if(!$Sc)$Sc=array($ag+30*60,0);$Sc[1]++;$tf=serialize($Tc);rewind($o);fwrite($o,$tf);ftruncate($o,strlen($tf));flock($o,LOCK_UN);fclose($o);}$xa=$_POST["auth"];if($xa){$Tc=unserialize(@file_get_contents(get_temp_dir()."/adminer.invalid"));$Sc=$Tc[$b->bruteForceKey()];$Ld=($Sc[1]>30?$Sc[0]-time():0);if($Ld>0)auth_error(lang(array('Too many unsuccessful logins, try again in %d minute.','Too many unsuccessful logins, try again in %d minutes.'),ceil($Ld/60)));session_regenerate_id();$i=$xa["driver"];$O=$xa["server"];$V=$xa["username"];$G=(string)$xa["password"];$h=$xa["db"];set_password($i,$O,$V,$G);$_SESSION["db"][$i][$O][$V][$h]=true;if($xa["permanent"]){$y=base64_encode($i)."-".base64_encode($O)."-".base64_encode($V)."-".base64_encode($h);$Je=$b->permanentLogin(true);$ze[$y]="$y:".base64_encode($Je?encrypt_string($G,$Je):"");cookie("adminer_permanent",implode(" ",$ze));}if(count($_POST)==1||DRIVER!=$i||SERVER!=$O||$_GET["username"]!==$V||DB!=$h)redirect(auth_url($i,$O,$V,$h));}elseif($_POST["logout"]){if($Dc&&!verify_token()){page_header('Logout','Invalid CSRF token. Send the form again.');page_footer("db");exit;}else{foreach(array("pwds","db","dbs","queries")as$y)set_session($y,null);unset_permanent();redirect(substr(preg_replace('~\b(username|db|ns)=[^&]*&~','',ME),0,-1),'Logout successful.');}}elseif($ze&&!$_SESSION["pwds"]){session_regenerate_id();$Je=$b->permanentLogin();foreach($ze
as$Uc=>$X){if($X[0]<$ag)unset($Tc[$Uc]);}}$Sc=&$Tc[$b->bruteForceKey()];if(!$Sc)$Sc=array($ag+30*60,0);$Sc[1]++;$tf=serialize($Tc);rewind($o);fwrite($o,$tf);ftruncate($o,strlen($tf));flock($o,LOCK_UN);fclose($o);}$xa=(isset($_POST["auth"])?$_POST["auth"]:false);if($xa){$Tc=unserialize(@file_get_contents(get_temp_dir()."/adminer.invalid"));$Sc=$Tc[$b->bruteForceKey()];$Ld=($Sc[1]>30?$Sc[0]-time():0);if($Ld>0)auth_error(lang(array('Too many unsuccessful logins, try again in %d minute.','Too many unsuccessful logins, try again in %d minutes.'),ceil($Ld/60)));session_regenerate_id();$i=$xa["driver"];$O=$xa["server"];$V=$xa["username"];$G=(string)$xa["password"];$h=$xa["db"];set_password($i,$O,$V,$G);$_SESSION["db"][$i][$O][$V][$h]=true;if($xa["permanent"]){$y=base64_encode($i)."-".base64_encode($O)."-".base64_encode($V)."-".base64_encode($h);$Je=$b->permanentLogin(true);$ze[$y]="$y:".base64_encode($Je?encrypt_string($G,$Je):"");cookie("adminer_permanent",implode(" ",$ze));}if(count($_POST)==1||DRIVER!=$i||SERVER!=$O||$_GET["username"]!==$V||DB!=$h)redirect(auth_url($i,$O,$V,$h));}elseif(isset($_POST["logout"])?$_POST["logout"]:false){if($Dc&&!verify_token()){page_header('Logout','Invalid CSRF token. Send the form again.');page_footer("db");exit;}else{foreach(array("pwds","db","dbs","queries")as$y)set_session($y,null);unset_permanent();redirect(substr(preg_replace('~\b(username|db|ns)=[^&]*&~','',ME),0,-1),'Logout successful.');}}elseif($ze&&!$_SESSION["pwds"]){session_regenerate_id();$Je=$b->permanentLogin();foreach($ze
as$y=>$X)json_row("sum-$y",format_number($X));json_row("");}elseif($_GET["script"]=="kill")$e->query("KILL ".(+$_POST["kill"]));else{foreach(count_tables($b->databases())as$h=>$X){json_row("tables-$h",$X);json_row("size-$h",db_size($h));}json_row("");}exit;}else{$Tf=array_merge((array)$_POST["tables"],(array)$_POST["views"]);if($Tf&&!$j&&!$_POST["search"]){$J=true;$C="";if($x=="sql"&&count($_POST["tables"])>1&&($_POST["drop"]||$_POST["truncate"]||$_POST["copy"]))queries("SET foreign_key_checks = 0");if($_POST["truncate"]){if($_POST["tables"])$J=truncate_tables($_POST["tables"]);$C='Tables have been truncated.';}elseif($_POST["move"]){$J=move_tables((array)$_POST["tables"],(array)$_POST["views"],$_POST["target"]);$C='Tables have been moved.';}elseif($_POST["copy"]){$J=copy_tables((array)$_POST["tables"],(array)$_POST["views"],$_POST["target"]);$C='Tables have been copied.';}elseif($_POST["drop"]){if($_POST["views"])$J=drop_views($_POST["views"]);if($J&&$_POST["tables"])$J=drop_tables($_POST["tables"]);$C='Tables have been dropped.';}elseif($x!="sql"){$J=($x=="sqlite"?queries("VACUUM"):apply_queries("VACUUM".($_POST["optimize"]?"":" ANALYZE"),$_POST["tables"]));$C='Tables have been optimized.';}elseif(!$_POST["tables"])$C='No tables.';elseif($J=queries(($_POST["optimize"]?"OPTIMIZE":($_POST["check"]?"CHECK":($_POST["repair"]?"REPAIR":"ANALYZE")))." TABLE ".implode(", ",array_map('idf_escape',$_POST["tables"])))){while($L=$J->fetch_assoc())$C.="<b>".h($L["Table"])."</b>: ".h($L["Msg_text"])."<br>";}queries_redirect(substr(ME,0,-1),$C,$J);}page_header(($_GET["ns"]==""?'Database'.": ".h(DB):'Schema'.": ".h($_GET["ns"])),$j,true);if($b->homepage()){if($_GET["ns"]!==""){echo"<h3id='tables-views'>".'Tables and views'."</h3>\n";$Sf=tables_list();if(!$Sf)echo"<pclass='message'>".'No tables.'."\n";else{echo"<formaction=''method='post'>\n";if(support("table")){echo"<fieldset><legend>".'Search data in tables'." <spanid='selected2'></span></legend><div>","<inputtype='search'name='query'value='".h($_POST["query"])."'><inputtype='submit'name='search'value='".'Search'."'>\n","</div></fieldset>\n";if($_POST["search"]&&$_POST["query"]!="")search_tables();}echo"<tablecellspacing='0'class='nowrap checkable'onclick='tableClick(event);'ondblclick='tableClick(event, true);'>\n",'<thead><trclass="wrap"><td><inputid="check-all"type="checkbox"onclick="formCheck(this, /^(tables|views)\[/);">','<th>'.'Table','<td>'.'Engine','<td>'.'Collation','<td>'.'Data Length','<td>'.'Index Length','<td>'.'Data Free','<td>'.'Auto Increment','<td>'.'Rows',(support("comment")?'<td>'.'Comment':''),"</thead>\n";$S=0;foreach($Sf
as$y=>$X)json_row("sum-$y",format_number($X));json_row("");}elseif($_GET["script"]=="kill")$e->query("KILL ".(+$_POST["kill"]));else{foreach(count_tables($b->databases())as$h=>$X){json_row("tables-$h",$X);json_row("size-$h",db_size($h));}json_row("");}exit;}else{$Tf=array_merge((array)(isset($_POST["tables"])?$_POST["tables"]:null),(array)(isset($_POST["views"])?$_POST["views"]:null));if($Tf&&!$j&&!$_POST["search"]){$J=true;$C="";if($x=="sql"&&count($_POST["tables"])>1&&($_POST["drop"]||$_POST["truncate"]||$_POST["copy"]))queries("SET foreign_key_checks = 0");if($_POST["truncate"]){if($_POST["tables"])$J=truncate_tables($_POST["tables"]);$C='Tables have been truncated.';}elseif($_POST["move"]){$J=move_tables((array)$_POST["tables"],(array)$_POST["views"],$_POST["target"]);$C='Tables have been moved.';}elseif($_POST["copy"]){$J=copy_tables((array)$_POST["tables"],(array)$_POST["views"],$_POST["target"]);$C='Tables have been copied.';}elseif($_POST["drop"]){if($_POST["views"])$J=drop_views($_POST["views"]);if($J&&$_POST["tables"])$J=drop_tables($_POST["tables"]);$C='Tables have been dropped.';}elseif($x!="sql"){$J=($x=="sqlite"?queries("VACUUM"):apply_queries("VACUUM".($_POST["optimize"]?"":" ANALYZE"),$_POST["tables"]));$C='Tables have been optimized.';}elseif(!$_POST["tables"])$C='No tables.';elseif($J=queries(($_POST["optimize"]?"OPTIMIZE":($_POST["check"]?"CHECK":($_POST["repair"]?"REPAIR":"ANALYZE")))." TABLE ".implode(", ",array_map('idf_escape',$_POST["tables"])))){while($L=$J->fetch_assoc())$C.="<b>".h($L["Table"])."</b>: ".h($L["Msg_text"])."<br>";}queries_redirect(substr(ME,0,-1),$C,$J);}page_header((empty($_GET["ns"])?'Database'.": ".h(DB):'Schema'.": ".h(empty($_GET["ns"])?null:$_GET["ns"])),$j,true);if($b->homepage()){if((isset($_GET["ns"])?$_GET["ns"]:null)!==""){echo"<h3id='tables-views'>".'Tables and views'."</h3>\n";$Sf=tables_list();if(!$Sf)echo"<pclass='message'>".'No tables.'."\n";else{echo"<formaction=''method='post'>\n";if(support("table")){echo"<fieldset><legend>".'Search data in tables'." <spanid='selected2'></span></legend><div>","<inputtype='search'name='query'value='".h($_POST["query"])."'><inputtype='submit'name='search'value='".'Search'."'>\n","</div></fieldset>\n";if($_POST["search"]&&$_POST["query"]!="")search_tables();}echo"<tablecellspacing='0'class='nowrap checkable'onclick='tableClick(event);'ondblclick='tableClick(event, true);'>\n",'<thead><trclass="wrap"><td><inputid="check-all"type="checkbox"onclick="formCheck(this, /^(tables|views)\[/);">','<th>'.'Table','<td>'.'Engine','<td>'.'Collation','<td>'.'Data Length','<td>'.'Index Length','<td>'.'Data Free','<td>'.'Auto Increment','<td>'.'Rows',(support("comment")?'<td>'.'Comment':''),"</thead>\n";$S=0;foreach($Sf
as$E=>$U){$Jg=($U!==null&&!preg_match('~table~i',$U));echo'<tr'.odd().'><td>'.checkbox(($Jg?"views[]":"tables[]"),$E,in_array($E,$Tf,true),"","formUncheck('check-all');"),'<th>'.(support("table")||support("indexes")?'<ahref="'.h(ME).'table='.urlencode($E).'"title="'.'Show structure'.'">'.h($E).'</a>':h($E));if($Jg){echo'<tdcolspan="6"><ahref="'.h(ME)."view=".urlencode($E).'"title="'.'Alter view'.'">'.'View'.'</a>','<tdalign="right"><ahref="'.h(ME)."select=".urlencode($E).'"title="'.'Select data'.'">?</a>';}else{foreach(array("Engine"=>array(),"Collation"=>array(),"Data_length"=>array("create",'Alter table'),"Index_length"=>array("indexes",'Alter indexes'),"Data_free"=>array("edit",'New item'),"Auto_increment"=>array("auto_increment=1&create",'Alter table'),"Rows"=>array("select",'Select data'),)as$y=>$_){$t=" id='$y-".h($E)."'";echo($_?"<tdalign='right'>".(support("table")||$y=="Rows"||(support("indexes")&&$y!="Data_length")?"<ahref='".h(ME."$_[0]=").urlencode($E)."'$ttitle='$_[1]'>?</a>":"<span$t>?</span>"):"<tdid='$y-".h($E)."'> ");}$S++;}echo(support("comment")?"<tdid='Comment-".h($E)."'> ":"");}echo"<tr><td> <th>".sprintf('%d in total',count($Sf)),"<td>".nbsp($x=="sql"?$e->result("SELECT @@storage_engine"):""),"<td>".nbsp(db_collation(DB,collations()));foreach(array("Data_length","Index_length","Data_free")as$y)echo"<tdalign='right'id='sum-$y'> ";echo"</table>\n";if(!information_schema(DB)){$Fg="<inputtype='submit'value='".'Vacuum'."'".on_help("'VACUUM'")."> ";$be="<inputtype='submit'name='optimize'value='".'Optimize'."'".on_help($x=="sql"?"'OPTIMIZETABLE'":"'VACUUMOPTIMIZE'")."> ";echo"<fieldset><legend>".'Selected'." <spanid='selected'></span></legend><div>".($x=="sqlite"?$Fg:($x=="pgsql"?$Fg.$be:($x=="sql"?"<inputtype='submit'value='".'Analyze'."'".on_help("'ANALYZETABLE'")."> ".$be."<inputtype='submit'name='check'value='".'Check'."'".on_help("'CHECKTABLE'")."> "."<inputtype='submit'name='repair'value='".'Repair'."'".on_help("'REPAIRTABLE'")."> ":"")))."<inputtype='submit'name='truncate'value='".'Truncate'."'".confirm().on_help($x=="sqlite"?"'DELETE'":"'TRUNCATE".($x=="pgsql"?"'":"TABLE'"))."> "."<inputtype='submit'name='drop'value='".'Drop'."'".confirm().on_help("'DROPTABLE'").">\n";$g=(support("scheme")?$b->schemas():$b->databases());if(count($g)!=1&&$x!="sqlite"){$h=(isset($_POST["target"])?$_POST["target"]:(support("scheme")?$_GET["ns"]:DB));echo"<p>".'Move to other database'.": ",($g?html_select("target",$g,$h):'<inputname="target"value="'.h($h).'"autocapitalize="off">')," <inputtype='submit'name='move'value='".'Move'."'>",(support("copy")?" <inputtype='submit'name='copy'value='".'Copy'."'>":""),"\n";}echo"<inputtype='hidden'name='all'value=''onclick=\"selectCount('selected',formChecked(this,/^(tables|views)\[/));".(support("table")?"selectCount('selected2',formChecked(this,/^tables\[/)||$S);":"")."\">\n";echo"<inputtype='hidden'name='token'value='$T'>\n","</div></fieldset>\n";}echo"</form>\n","<scripttype='text/javascript'>tableCheck();</script>\n";}echo'<pclass="links"><ahref="'.h(ME).'create=">'.'Create table'."</a>\n",(support("view")?'<ahref="'.h(ME).'view=">'.'Create view'."</a>\n":"");if(support("routine")){echo"<h3id='routines'>".'Routines'."</h3>\n";$kf=routines();if($kf){echo"<tablecellspacing='0'>\n",'<thead><tr><th>'.'Name'.'<td>'.'Type'.'<td>'.'Return type'."<td> </thead>\n";odd('');foreach($kf