Upgraded phpmyadmin to 4.0.4 (All Languages) - No modifications yet
[openemr.git] / phpmyadmin / js / pmd / history.js
blob0024d40a6934c2cb04305d8f3aa3649ecfe00400
1 var history_array=[];var select_field=[];var g_index;function panel(a){if(!a){$(".toggle_container").hide()}$("h2.tiger").click(function(){$(this).toggleClass("active").next().slideToggle("slow")})}function display(h,f){var g,e,d,c,a;for(e=h;e<f;e++){a=history_array[e];var b=history_array[e].get_tab();for(d=0;d<e;d++){if(b>(history_array[d].get_tab())){for(c=e;c>d;c--){history_array[c]=history_array[c-1]}history_array[d]=a;break}}}g="";for(var e=0;e<history_array.length;e++){var b=history_array[e].get_tab();g+='<h2 class="tiger"><a href="#">'+b+"</a></h2>";g+='<div class="toggle_container">\n';while((history_array[e].get_tab())==b){g+='<div class="block"> <table width ="250">';g+="<thead><tr><td>";if(history_array[e].get_and_or()){g+='<img src="'+pmaThemeImage+'pmd/or_icon.png" onclick="and_or('+e+')" title="OR"/></td>'}else{g+='<img src="'+pmaThemeImage+'pmd/and_icon.png" onclick="and_or('+e+')" title="AND"/></td>'}g+='<td style="padding-left: 5px;" class="right">'+PMA_getImage("b_sbrowse.png","column name")+'</td><td width="175" style="padding-left: 5px">'+history_array[e].get_column_name();if(history_array[e].get_type()=="GroupBy"||history_array[e].get_type()=="OrderBy"){g+='</td><td class="center">'+PMA_getImage("b_info.png",detail(e))+'<td title="'+detail(e)+'">'+history_array[e].get_type()+"</td></td><td onmouseover=\"this.className='history_table';\" onmouseout=\"this.className='history_table2'\" onclick=history_delete("+e+")>"+PMA_getImage("b_drop.png","Delete")+"</td></tr></thead>"}else{g+='</td><td class="center">'+PMA_getImage("b_info.png",detail(e))+'</td><td title="'+detail(e)+'">'+history_array[e].get_type()+"</td><td <td onmouseover=\"this.className='history_table';\" onmouseout=\"this.className='history_table2'\" onclick=history_edit("+e+")>"+PMA_getImage("b_edit.png",PMA_messages.strEdit)+"</td><td onmouseover=\"this.className='history_table';\" onmouseout=\"this.className='history_table2'\"               onclick=history_delete("+e+')><img src="themes/original/img/b_drop.png" title="Delete"></td></tr></thead>'}e++;if(e>=history_array.length){break}g+="</table></div><br/>"}e--;g+="</div><br/>"}return g}function and_or(a){if(history_array[a].get_and_or()){history_array[a].set_and_or(0)}else{history_array[a].set_and_or(1)}var b=document.getElementById("ab");b.innerHTML=display(0,0);panel(1)}function detail(a){var b=history_array[a].get_type();var c;if(b=="Where"){c="Where "+history_array[a].get_column_name()+history_array[a].get_obj().getrelation_operator()+history_array[a].get_obj().getquery()}if(b=="Rename"){c="Rename "+history_array[a].get_column_name()+" To "+history_array[a].get_obj().getrename_to()}if(b=="Aggregate"){c="Select "+history_array[a].get_obj().get_operator()+"( "+history_array[a].get_column_name()+" )"}if(b=="GroupBy"){c="GroupBy "+history_array[a].get_column_name()}if(b=="OrderBy"){c="OrderBy "+history_array[a].get_column_name()}if(b=="Having"){c="Having ";if(history_array[a].get_obj().get_operator()!="None"){c+=history_array[a].get_obj().get_operator()+"( "+history_array[a].get_column_name()+" )";c+=history_array[a].get_obj().getrelation_operator()+history_array[a].get_obj().getquery()}else{c="Having "+history_array[a].get_column_name()+history_array[a].get_obj().getrelation_operator()+history_array[a].get_obj().getquery()}}return c}function history_delete(b){for(var a=0;a<from_array.length;a++){if(from_array[a]==history_array[b].get_tab()){from_array.splice(a,1);break}}history_array.splice(b,1);var c=document.getElementById("ab");c.innerHTML=display(0,0);panel(1)}function history_edit(a){g_index=a;var b=history_array[a].get_type();if(b=="Where"){document.getElementById("eQuery").value=history_array[a].get_obj().getquery();document.getElementById("erel_opt").value=history_array[a].get_obj().getrelation_operator();document.getElementById("query_where").style.left="530px";document.getElementById("query_where").style.top="130px";document.getElementById("query_where").style.position="absolute";document.getElementById("query_where").style.zIndex="9";document.getElementById("query_where").style.visibility="visible"}if(b=="Having"){document.getElementById("hQuery").value=history_array[a].get_obj().getquery();document.getElementById("hrel_opt").value=history_array[a].get_obj().getrelation_operator();document.getElementById("hoperator").value=history_array[a].get_obj().get_operator();document.getElementById("query_having").style.left="530px";document.getElementById("query_having").style.top="130px";document.getElementById("query_having").style.position="absolute";document.getElementById("query_having").style.zIndex="9";document.getElementById("query_having").style.visibility="visible"}if(b=="Rename"){document.getElementById("query_rename_to").style.left="530px";document.getElementById("query_rename_to").style.top="130px";document.getElementById("query_rename_to").style.position="absolute";document.getElementById("query_rename_to").style.zIndex="9";document.getElementById("query_rename_to").style.visibility="visible"}if(b=="Aggregate"){document.getElementById("query_Aggregate").style.left="530px";document.getElementById("query_Aggregate").style.top="130px";document.getElementById("query_Aggregate").style.position="absolute";document.getElementById("query_Aggregate").style.zIndex="9";document.getElementById("query_Aggregate").style.visibility="visible"}}function edit(a){if(a=="Rename"){if(document.getElementById("e_rename").value!=""){history_array[g_index].get_obj().setrename_to(document.getElementById("e_rename").value);document.getElementById("e_rename").value=""}document.getElementById("query_rename_to").style.visibility="hidden"}if(a=="Aggregate"){if(document.getElementById("e_operator").value!="---"){history_array[g_index].get_obj().set_operator(document.getElementById("e_operator").value);document.getElementById("e_operator").value="---"}document.getElementById("query_Aggregate").style.visibility="hidden"}if(a=="Where"){if(document.getElementById("erel_opt").value!="--"&&document.getElementById("eQuery").value!=""){history_array[g_index].get_obj().setquery(document.getElementById("eQuery").value);history_array[g_index].get_obj().setrelation_operator(document.getElementById("erel_opt").value)}document.getElementById("query_where").style.visibility="hidden"}if(a=="Having"){if(document.getElementById("hrel_opt").value!="--"&&document.getElementById("hQuery").value!=""){history_array[g_index].get_obj().setquery(document.getElementById("hQuery").value);history_array[g_index].get_obj().setrelation_operator(document.getElementById("hrel_opt").value);history_array[g_index].get_obj().set_operator(document.getElementById("hoperator").value)}document.getElementById("query_having").style.visibility="hidden"}var b=document.getElementById("ab");b.innerHTML=display(0,0);panel(1)}function history(h,j,g,k,b){var d;var f;var c;var a;var e;var i;this.set_column_name=function(l){a=l};this.get_column_name=function(){return a};this.set_and_or=function(l){d=l};this.get_and_or=function(){return d};this.get_relation=function(){return d};this.set_obj=function(l){f=l};this.get_obj=function(){return f};this.set_tab=function(l){c=l};this.get_tab=function(){return c};this.set_obj_no=function(l){e=l};this.get_obj_no=function(){return e};this.set_type=function(l){i=l};this.get_type=function(){return i};this.set_obj_no(k);this.set_tab(g);this.set_and_or(0);this.set_obj(j);this.set_column_name(h);this.set_type(b)}var where=function(a,d){var b;var c;this.setrelation_operator=function(e){b=e};this.setquery=function(e){c=e};this.getquery=function(){return c};this.getrelation_operator=function(){return b};this.setquery(d);this.setrelation_operator(a)};var having=function(a,f,d){var c;var e;var b;this.set_operator=function(g){b=g};this.setrelation_operator=function(g){c=g};this.setquery=function(g){e=g};this.getquery=function(){return e};this.getrelation_operator=function(){return c};this.get_operator=function(){return b};this.setquery(f);this.setrelation_operator(a);this.set_operator(d)};var rename=function(b){var a;this.setrename_to=function(c){a=c};this.getrename_to=function(){return a};this.setrename_to(b)};var aggregate=function(b){var a;this.set_operator=function(c){a=c};this.get_operator=function(){return a};this.set_operator(b)};function unique(d){var a=[];label:for(var c=0;c<d.length;c++){for(var b=0;b<a.length;b++){if(a[b]==d[c]){continue label}}a[a.length]=d[c]}return a}function found(c,b){for(var a=0;a<c.length;a++){if(c[a]==b){return 1}}return -1}function build_query(c,g){var f="SELECT ";var b;for(var d=0;d<select_field.length;d++){b=check_aggregate(select_field[d]);if(b!=""){f+=b;b=check_rename(select_field[d]);f+=b+","}else{b=check_rename(select_field[d]);f+=select_field[d]+b+","}}f=f.substring(0,f.length-1);f+=" FROM "+query_from();if(query_where()!=""){f+="\n WHERE";f+=query_where()}if(query_groupby()!=""){f+="\nGROUP BY "+query_groupby()}if(query_having()!=""){f+="\nHAVING "+query_having()}if(query_orderby()!=""){f+="\nORDER BY "+query_orderby()}var e=document.getElementById("box");document.getElementById("filter").style.display="block";var a=document.getElementById("boxtitle");a.innerHTML="SELECT";if(g){gradient("box",0);fadein("box")}else{e.style.display="block"}document.getElementById("textSqlquery").innerHTML=f}function query_from(){var d;var o=[];var f=[];var e=[];var m=[];var r;var g="";var q="";var c=[];var l=[];l=from_array;var j=0;var b;var p;var n;var h;var a;for(d=0;d<history_array.length;d++){from_array.push(history_array[d].get_tab())}from_array=unique(from_array);o=from_array;r=o.shift();q=r;f.push(r);for(d=0;d<2;d++){for(j in contr){for(p in contr[j]){for(n in contr[j][p]){c=n.split(".");if(found(f,c[1])>0){for(h in contr[j][p][n]){a=contr[j][p][n][h][0].split(".");if(found(o,a[1])>0){g+="\nLEFT JOIN ";g+="`"+a[0]+"`.`"+a[1]+"` ON ";g+="`"+c[1]+"`.`"+h+"` = ";g+="`"+a[1]+"`.`"+contr[j][p][n][h][1]+"` ";m.push(a[1])}}}}}}j=0;m=unique(m);f=add_array(m,f);o=remove_array(m,o);m=[];for(j in contr){for(p in contr[j]){for(n in contr[j][p]){c=n.split(".");if(found(o,c[1])>0){for(h in contr[j][p][n]){a=contr[j][p][n][h][0].split(".");if(found(f,a[1])>0){g+="\nLEFT JOIN ";g+="`"+c[0]+"`.`"+c[1]+"` ON ";g+="`"+a[1]+"`.`"+contr[j][p][n][h][1]+"` = ";g+="`"+c[1]+"`.`"+h+"` ";m.push(c[1])}}}}}}m=unique(m);f=add_array(m,f);o=remove_array(m,o);m=[]}for(b in o){q+=" , `"+o[b]+"`"}g=q+g;from_array=l;return g}function add_array(c,a){for(var b=0;b<c.length;b++){a.push(c[b])}return a}function remove_array(d,a){for(var c=0;c<d.length;c++){for(var b=0;b<a.length;b++){if(d[c]==a[b]){a.splice(b,1)}}}return a}function query_groupby(){var a;var b="";for(a=0;a<history_array.length;a++){if(history_array[a].get_type()=="GroupBy"){b+=history_array[a].get_column_name()+", "}}b=b.substr(0,b.length-1);return b}function query_having(){var a;var b="(";for(a=0;a<history_array.length;a++){if(history_array[a].get_type()=="Having"){if(history_array[a].get_obj().get_operator()!="None"){b+=history_array[a].get_obj().get_operator()+"("+history_array[a].get_column_name()+" ) "+history_array[a].get_obj().getrelation_operator();b+=" "+history_array[a].get_obj().getquery()+", "}else{b+=history_array[a].get_column_name()+" "+history_array[a].get_obj().getrelation_operator()+" "+history_array[a].get_obj().getquery()+", "}}}if(b=="("){b=""}else{b=b.substr(0,b.length-2)+")"}return b}function query_orderby(){var a;var b="";for(a=0;a<history_array.length;a++){if(history_array[a].get_type()=="OrderBy"){b+=history_array[a].get_column_name()+" , "}}b=b.substr(0,b.length-1);return b}function query_where(){var a;var b="(";var c="(";for(a=0;a<history_array.length;a++){if(history_array[a].get_type()=="Where"){if(history_array[a].get_and_or()==0){b+="( "+history_array[a].get_column_name()+" "+history_array[a].get_obj().getrelation_operator()+" "+history_array[a].get_obj().getquery()+")";b+=" AND "}else{c+="( "+history_array[a].get_column_name()+" "+history_array[a].get_obj().getrelation_operator()+" "+history_array[a].get_obj().getquery()+")";c+=" OR "}}}if(c!="("){c=c.substring(0,(c.length-4))+")"}else{c=""}if(b!="("){b=b.substring(0,(b.length-5))+")"}else{b=""}if(c!=""){b=b+" OR "+c+" )"}return b}function check_aggregate(c){var b;for(b=0;b<history_array.length;b++){var a="`"+history_array[b].get_tab()+"`.`"+history_array[b].get_column_name()+"`";if(a==c&&history_array[b].get_type()=="Aggregate"){return history_array[b].get_obj().get_operator()+"("+c+")"}}return""}function check_rename(c){var b;for(b=0;b<history_array.length;b++){var a="`"+history_array[b].get_tab()+"`.`"+history_array[b].get_column_name()+"`";if(a==c&&history_array[b].get_type()=="Rename"){return" AS `"+history_array[b].get_obj().getrename_to()+"`"}}return""}function gradient(c,b){var a=document.getElementById(c);a.style.opacity=b;a.style.MozOpacity=b;a.style.KhtmlOpacity=b;a.style.filter="alpha(opacity="+b*100+")";a.style.display="block";return}function fadein(b){var a=0;while(a<=1){setTimeout("gradient('"+b+"',"+a+")",(a*1000)+10);a+=0.01}}function closebox(){document.getElementById("box").style.display="none";document.getElementById("filter").style.display="none"};