55session_start ();
66$ bg =2 ;
77$ step =20 ;
8- $ version ="3.21 " ;
8+ $ version ="3.22 " ;
99$ bbs =['False ' ,'True ' ];
1010$ deny =['mysql ' ,'information_schema ' ,'performance_schema ' ,'sys ' ];
1111class DBT {
@@ -600,7 +600,7 @@ public function create_ro($db,$pn) {
600600}
601601$ ed =new ED ;
602602$ head ='<!DOCTYPE html><html lang="en"><head>
603- <title>EdMyAdmin</title>< meta charset="utf-8">
603+ <meta charset="utf-8"><title>EdMyAdmin</title >
604604<style>
605605*{margin:0;padding:0;font-size:14px;color:#333;font-family:Arial}
606606html{-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;background:#fff}
@@ -630,7 +630,7 @@ public function create_ro($db,$pn) {
630630textarea,select[multiple]{min-height:90px}
631631textarea{white-space:pre-wrap}
632632.msg{position:absolute;top:0;right:0;z-index:9}
633- .ok,.err{padding:8px;font-weight:bold;font-size:14px }
633+ .ok,.err{padding:8px;font-weight:bold}
634634.ok{background:#efe;color:#080;border-bottom:2px solid #080}
635635.err{background:#fee;color:#f00;border-bottom:2px solid #f00}
636636.l1,th,button{background:#9be}
@@ -647,11 +647,10 @@ public function create_ro($db,$pn) {
647647.l3.auto select{border:0;padding:0;background:#fe3}
648648.l1,.l2,.l3,.wi{width:100%}
649649.msg,.a,.bb{cursor:pointer}
650- .handle{font:1.25rem/.75rem Arial;font-weight:bold;vertical-align:middle}
650+ .handle,.bb * {font:1.5rem/1rem Arial;font-weight:bold;vertical-align:middle}
651651.handle:hover{cursor:move}
652652tr.dragging{opacity:0.5}
653653tr.drag-over{background:#9be}
654- .bb *{font:22px/18px Arial}
655654.upr{list-style:none;overflow:auto;overflow-x:hidden;height:90px}
656655</style>
657656</head><body> ' .(empty ($ _SESSION ['ok ' ])?'' :'<div class="msg ok"> ' .$ _SESSION ['ok ' ].'</div> ' ).(empty ($ _SESSION ['err ' ])?'' :'<div class="msg err"> ' .$ _SESSION ['err ' ].'</div> ' ).'<div class="l1"><b><a href="https://github.com/edmondsql/edmyadmin">EdMyAdmin ' .$ version .'</a></b> ' .(isset ($ ed ->sg [0 ]) && $ ed ->sg [0 ]==50 ? "" :'<ul class="mn m1"><li>More <small>▼</small><ul><li><a href=" ' .$ ed ->path .'60">Info</a></li><li><a href=" ' .$ ed ->path .'60/var">Variables</a></li><li><a href=" ' .$ ed ->path .'60/status">Status</a></li><li><a href=" ' .$ ed ->path .'60/process">Processes</a></li></ul></li><li><a href=" ' .$ ed ->path .'52">Users</a></li><li><a href=" ' .$ ed ->path .'51">Logout [ ' .(isset ($ _SESSION ['user ' ]) ? $ _SESSION ['user ' ]:"" ).']</a></li></ul> ' ).'</div> ' ;
@@ -2220,16 +2219,19 @@ public function create_ro($db,$pn) {
22202219 } else {
22212220 $ ph =$ ed ->sg [7 ];$ nu1 =" AND ` " .$ ed ->sg [5 ]."`=' " .base64_decode ($ ed ->sg [6 ])."' " ;
22222221 }
2223- $ q_ph =$ ed ->con ->query ("SELECT $ ph FROM ` $ tb` WHERE ` $ nu`=' $ id' $ nu1 LIMIT 1 " )->fetch ();
2224- $ len =strlen ($ q_ph [0 ]);
2225- if ($ len >=2 && $ q_ph [0 ][0 ]==chr (0xff ) && $ q_ph [0 ][1 ]==chr (0xd8 )) {$ tp ='image/jpeg ' ;$ xt ='.jpg ' ;}
2226- elseif ($ len >=3 && substr ($ q_ph [0 ],0 ,3 )=='GIF ' ) {$ tp ='image/gif ' ;$ xt ='.gif ' ;}
2227- elseif ($ len >=4 && substr ($ q_ph [0 ],0 ,4 )=="\x89PNG " ) {$ tp ='image/png ' ;$ xt ='.png ' ;}
2228- else {$ tp ='application/octet-stream ' ;$ xt ='.bin ' ;$ q_ph [0 ]=addslashes ($ q_ph [0 ]);}
2222+ $ r_ph =$ ed ->con ->query ("SELECT $ ph FROM ` $ tb` WHERE ` $ nu`=' $ id' $ nu1 LIMIT 1 " )->fetch ();
2223+ $ r_ph =$ r_ph [0 ];$ len =strlen ($ r_ph );
2224+ $ tp ='application/octet-stream ' ;$ xt ='bin ' ;
2225+ if ($ len >3 ){
2226+ if (substr ($ r_ph ,0 ,3 )=="\xFF\xD8\xFF" ){$ tp ='image/jpg ' ;$ xt ='jpg ' ;}
2227+ elseif (substr ($ r_ph ,0 ,3 )=="GIF " ){$ tp ='image/gif ' ;$ xt ='gif ' ;}
2228+ elseif (substr ($ r_ph ,0 ,4 )=="\x89PNG " ){$ tp ='image/png ' ;$ xt ='png ' ;}
2229+ elseif (substr ($ r_ph ,0 ,4 )=="RIFF " ){$ tp ='image/webp ' ;$ xt ='webp ' ;}
2230+ }
22292231 header ("Content-type: $ tp " );
22302232 header ("Content-Length: $ len " );
2231- header ("Content-Disposition: attachment; filename= {$ tb }-blob {$ xt }" );
2232- die ($ q_ph [ 0 ] );
2233+ header ("Content-Disposition: attachment; filename= {$ tb }-blob. {$ xt }" );
2234+ die ($ r_ph );
22332235break ;
22342236
22352237case "40 " ://view
@@ -2409,7 +2411,7 @@ public function create_ro($db,$pn) {
24092411 }
24102412 echo "</select><select class='pa2' name='rop2[]'> " .$ swcl ;
24112413 foreach ($ q_swcl as $ r_rocl ) echo "<option value=' " .$ r_rocl [0 ]."' " .(!empty ($ pre [4 ]) && $ pre [4 ]==$ r_rocl [0 ]?" selected " :"" )."> " .$ r_rocl [0 ]."</option> " ;
2412- echo "</select></td><td class='bb'><span onclick='plus(this)'>+</span> <span onclick= \"minus(this) \">- </span></td></tr> " ;
2414+ echo "</select></td><td class='bb'><span onclick='plus(this)'>+</span> <span onclick= \"minus(this) \">– </span></td></tr> " ;
24132415 ++$ p ;
24142416 }
24152417 echo "</table></td></tr><tr class='rou2 auto'><td>Return type</td><td><select id='pty2' name='rorty'> " .($ retrn [0 ]!="" ?$ ed ->fieldtypes (strtoupper ($ retrn [0 ])):$ ed ->fieldtypes ())."</select>
@@ -2913,34 +2915,13 @@ public function create_ro($db,$pn) {
29132915unset($ _POST ,$ _SESSION ["ok " ],$ _SESSION ["err " ]);
29142916?> </div></div><div class="l1 ce"><a href="http://edmondsql.github.io">edmondsql</a></div>
29152917<script>
2916- function byId(n){
2917- return document.getElementById(n);
2918- }
2919- function byName(n){
2920- return document.getElementsByName(n);
2921- }
2922- function bySel(n){
2923- return document.querySelector(n);
2924- }
2925- function byAll(n){
2926- return document.querySelectorAll(n);
2927- }
2928- function byClass(n){
2929- return document.getElementsByClassName(n);
2930- }
2931- function createEl(n){
2932- return document.createElement(n);
2933- }
2934- Element.prototype.show=function(ty=null){
2935- if(ty=='b'){
2936- this.style.display='inline-block';
2937- }else{
2938- this.style.display='';
2939- }
2940- };
2941- Element.prototype.hide=function(){
2942- this.style.display='none';
2943- };
2918+ const $=(s)=>document.querySelector(s);
2919+ const $$=(s)=>document.querySelectorAll(s);
2920+ const $n=(s)=>document.getElementsByName(s);
2921+ const $cn=(s)=>document.getElementsByClassName(s);
2922+ const $c=(s)=>document.createElement(s);
2923+ Element.prototype.show=function(ty=null){this.style.display=(ty=='b')?'inline-block':'';}
2924+ Element.prototype.hide=function(){this.style.display='none';}
29442925HTMLCollection.prototype.showAll=function(){
29452926for(let i=0; i < this.length;i++){
29462927this[i].style.display='';
@@ -2951,15 +2932,15 @@ function createEl(n){
29512932this[i].style.display='none';
29522933}
29532934};
2954- var host=byId(" host");
2935+ const host=$("# host");
29552936if(host)host.focus();
29562937
2957- let msg=byAll (".msg");
2958- byAll (".del").forEach(d=>{
2938+ let msg=$$ (".msg");
2939+ $$ (".del").forEach(d=>{
29592940d.addEventListener('click',(e)=>{
29602941e.preventDefault();
29612942msg.forEach(m=>m.remove());
2962- let hrf=e.target.getAttribute("href"),nMsg=createEl ("div"),nOk=createEl ("div"),nEr=createEl ("div");
2943+ let hrf=e.target.getAttribute("href"),nMsg=$c ("div"),nOk=$c ("div"),nEr=$c ("div");
29632944nMsg.className='msg';
29642945nOk.className='ok';nOk.innerText='Yes';
29652946nEr.className='err';nEr.innerText='No';
@@ -2976,59 +2957,59 @@ function createEl(n){
29762957});
29772958msg.forEach(m=>{if(m.innerText!="")setTimeout(()=>{m.remove()},7000);m.addEventListener('dblclick',()=>m.remove())});
29782959
2979- if(byId(' one')){
2980- if(byId(' one').checked==true){byId(' every').hide();byId(' evend').hide()}else{byId(' every').show();byId(' evend').show()}
2981- byId(" one").addEventListener("click",function(){if(byId(' one').checked==true){byId(' every').hide();byId(' evend').hide()}else{byId(' every').show();byId(' evend').show()}});//add event
2960+ if($('# one')){
2961+ if($('# one').checked==true){$('# every').hide();$('# evend').hide()}else{$('# every').show();$('# evend').show()}
2962+ $("# one").addEventListener("click",function(){if($('# one').checked==true){$('# every').hide();$('# evend').hide()}else{$('# every').show();$('# evend').show()}});//add event
29822963}
2983- if(byId(" rou")){
2984- if(byId(" rou").value=="FUNCTION"){byClass ("rou1").hideAll();byClass ("rou2").showAll();}else{byClass ("rou1").showAll();byClass ("rou2").hideAll();}
2985- byId(" rou").addEventListener("change",function(){//routine
2986- if(this.value=="FUNCTION"){byClass ("rou1").hideAll();byClass ("rou2").showAll();}else{byClass ("rou1").showAll();byClass ("rou2").hideAll();}
2964+ if($("# rou")){
2965+ if($("# rou").value=="FUNCTION"){$cn ("rou1").hideAll();$cn ("rou2").showAll();}else{$cn ("rou1").showAll();$cn ("rou2").hideAll();}
2966+ $("# rou").addEventListener("change",function(){//routine
2967+ if(this.value=="FUNCTION"){$cn ("rou1").hideAll();$cn ("rou2").showAll();}else{$cn ("rou1").showAll();$cn ("rou2").hideAll();}
29872968});
29882969}
29892970//param rows
2990- var a,i,rou_p=byAll ('[id^="pty_"]').length;
2971+ let a,i,rou_p=$$ ('[id^="pty_"]').length;
29912972for(i=1;i <=rou_p;i++) routine(i);
29922973//priv all
29932974for(a=1;a<5;a++){
2994- if(byId(" fi"+a)){
2995- let fc=byId(" fi"+a).options.length,fs=(byId(" fi"+a).selectedOptions||'').length;
2996- if(fc==fs) byId(" fi"+a).parentNode.querySelector("[type=checkbox]").checked=true;
2975+ if($("# fi"+a)){
2976+ let fc=$("# fi"+a).options.length,fs=($("# fi"+a).selectedOptions||'').length;
2977+ if(fc==fs) $("# fi"+a).parentNode.querySelector("[type=checkbox]").checked=true;
29972978}
29982979}
29992980function minus(el){//routine remove row
3000- let crr=byAll ('[id^="rr_"]').length;
2981+ let crr=$$ ('[id^="rr_"]').length;
30012982if(crr>1) el.closest("tr").remove();
30022983}
30032984function plus(el){//routine clone row
3004- let cid=el.closest("tr").getAttribute("id"),cnt=byAll ('[id^="rr_"]').length + 1;
3005- let cl=byId( cid).cloneNode(true);byId( cid).after(cl);cl.setAttribute("id","rr_"+cnt);
3006- byId(" rr_"+cnt).querySelector('[id^="pty_"]').setAttribute("id","pty_"+cnt);
3007- byAll ('[id^="rr_"]').forEach(function(t,i){t.setAttribute("id","rr_"+(i+1));});
3008- byAll ('[id^="pty_"]').forEach(function(t,i){t.setAttribute("id","pty_"+(i+1));});
2985+ let cid=el.closest("tr").getAttribute("id"),cnt=$$ ('[id^="rr_"]').length + 1;
2986+ let cl=$('#'+ cid).cloneNode(true);$('#'+ cid).after(cl);cl.setAttribute("id","rr_"+cnt);
2987+ $("# rr_"+cnt).querySelector('[id^="pty_"]').setAttribute("id","pty_"+cnt);
2988+ $$ ('[id^="rr_"]').forEach(function(t,i){t.setAttribute("id","rr_"+(i+1));});
2989+ $$ ('[id^="pty_"]').forEach(function(t,i){t.setAttribute("id","pty_"+(i+1));});
30092990routine(cnt);
30102991}
30112992function routine(id){
30122993const ar1=["INT","TINYINT","SMALLINT","MEDIUMINT","BIGINT","DOUBLE","DECIMAL","FLOAT"],ar2=["VARCHAR","CHAR","TEXT","TINYTEXT","MEDIUMTEXT","LONGTEXT"];
30132994//function returns
3014- let ej=byId(" pty2"),ej1=byId(" px1"),ej2=byId(" px2");
2995+ let ej=$("# pty2"),ej1=$("# px1"),ej2=$("# px2");
30152996function routin2(){
30162997if(ar1.includes(ej.value)){ej1.show('b');ej2.hide();}else if(ar2.includes(ej.value)){ej1.hide();ej2.show('b');}else{ej1.hide();ej2.hide();}
30172998}
30182999routin2();
30193000ej.addEventListener("change",function(){routin2();});
30203001//options
30213002function routin1(ix){
3022- let el=byId(" pty_"+ix).value,el1=bySel ("#rr_"+ix+" .pa1"),el2=bySel ("#rr_"+ix+" .pa2");
3003+ let el=$("# pty_"+ix)?$("#pty_"+ix) .value:'' ,el1=$ ("#rr_"+ix+" .pa1"),el2=$ ("#rr_"+ix+" .pa2");
30233004if(ar1.includes(el)){el1.show('b');el2.hide();}else if(ar2.includes(el)){el1.hide();el2.show('b');}else{el1.hide();el2.hide();}
30243005}
30253006if(id===undefined) id=0;
30263007routin1(id);
3027- byId(" pty_"+id).addEventListener("change",function(){routin1(id);});
3008+ $("# pty_"+id).addEventListener("change",function(){routin1(id);});
30283009}
30293010
30303011(function(){
3031- let draggedItem=null,tbody=bySel ('.sort');
3012+ let draggedItem=null,tbody=$ ('.sort');
30323013function handleDragStart(e){
30333014if(!e.target.classList.contains('handle')){
30343015e.preventDefault();
@@ -3059,14 +3040,14 @@ function handleDragEnd(e){
30593040draggedItem.classList.remove('dragging');
30603041Array.from(draggedItem.parentNode.children).forEach(child => child.classList.remove('drag-over'));
30613042}
3062- var xhr=new window.XMLHttpRequest();
3043+ const xhr=new window.XMLHttpRequest();
30633044xhr.open("POST","<?= $ ed ->path .'9/ ' .(empty ($ ed ->sg [1 ])?'' :$ ed ->sg [1 ].'/ ' ).(empty ($ ed ->sg [2 ])?'' :$ ed ->sg [2 ])?> ");
30643045xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
30653046xhr.onload=function(){
30663047(xhr.readyState == 4 && xhr.status == 200) ? location.reload() : alert('Error: ' + xhr.status);
30673048}
30683049pre="x";
3069- if(draggedItem.previousElementSibling.nodeName=="TR") pre=draggedItem.previousElementSibling.getAttribute("id");
3050+ if(draggedItem.previousElementSibling && draggedItem.previousElementSibling .nodeName=="TR") pre=draggedItem.previousElementSibling.getAttribute("id");
30703051xhr.send("n1="+draggedItem.getAttribute("id")+"&n2="+pre);
30713052draggedItem=null;
30723053}
@@ -3084,18 +3065,18 @@ function addDragAndDrop(){
30843065addDragAndDrop();
30853066})();
30863067function selectall(cb,lb) {
3087- let i,multi=byId( lb);
3068+ let i,multi=$('#'+ lb);
30883069if(cb.checked) {for(i=0;i<multi.options.length;i++) multi.options[i].selected=true;
30893070}else{multi.selectedIndex=-1;}
30903071}
30913072function toggle(cb,el){
3092- let i,cbox=byName (el);
3073+ let i,cbox=$n (el);
30933074for(i=0;i<cbox.length;i++) cbox[i].checked=cb.checked;
30943075}
30953076function fmt(){
3096- let j,opt=byName ("fopt[]"),ff=byName ("ffmt[]"),to=opt.length,ch="",ft=byName ("ftype")[0];
3077+ let j,opt=$n ("fopt[]"),ff=$n ("ffmt[]"),to=opt.length,ch="",ft=$n ("ftype")[0];
30973078for(j=0; ff[j]; ++j){if(ff[j].checked) ch=ff[j].value;}
3098- if(byId(' tbs'))dbx('tbs');
3079+ if($('# tbs'))dbx('tbs');
30993080if(ch=="sql"){
31003081for(let k=0;k<to;k++) opt[k].parentElement.show();
31013082}else if(ch=="doc"||ch=="xml"){
@@ -3107,11 +3088,11 @@ function fmt(){
31073088}
31083089}
31093090function dbx(el='dbs'){
3110- let j,ch="",ft=byName ("ftype")[0],ff=byName ("ffmt[]"),db=byAll ("#"+el+" option:checked").length,dbs=byId(' dbs'),arr=["json","csv1","csv2"];
3091+ let j,ch="",ft=$n ("ftype")[0],ff=$n ("ffmt[]"),db=$$ ("#"+el+" option:checked").length,dbs=$('# dbs'),arr=["json","csv1","csv2"];
31113092for(j=0;ff[j];++j){if(ff[j].checked) ch=ff[j].value;}
31123093if(ft[0].value!="plain"){
31133094if((db<2 && (dbs||arr.indexOf(ch)>-1))||(db>1 && (dbs||arr.indexOf(ch)==-1))){
3114- let op=createEl ("option");
3095+ let op=$c ("option");
31153096op.value="plain";op.text="None";
31163097ft.options.add(op,0);
31173098ft.options[0].selected=true;
0 commit comments