summaryrefslogtreecommitdiff
path: root/hugo/js/pmd
diff options
context:
space:
mode:
Diffstat (limited to 'hugo/js/pmd')
-rw-r--r--hugo/js/pmd/ajax.js60
-rw-r--r--hugo/js/pmd/history.js784
-rw-r--r--hugo/js/pmd/iecanvas.js151
-rw-r--r--hugo/js/pmd/init.js31
-rw-r--r--hugo/js/pmd/move.js1264
5 files changed, 2290 insertions, 0 deletions
diff --git a/hugo/js/pmd/ajax.js b/hugo/js/pmd/ajax.js
new file mode 100644
index 0000000..766c3dd
--- /dev/null
+++ b/hugo/js/pmd/ajax.js
@@ -0,0 +1,60 @@
+/* vim: set expandtab sw=4 ts=4 sts=4: */
+/**
+ *
+ * @package PhpMyAdmin-Designer
+ */
+
+/**
+ *
+ */
+function makeRequest(url, parameters)
+{
+ var $msg = PMA_ajaxShowMessage();
+ $.post(url, parameters, function (data) {
+ PMA_ajaxRemoveMessage($msg);
+ PrintXML(data);
+ });
+ return true;
+}
+
+/**
+ *
+ */
+function PrintXML(data)
+{
+ var $root = $(data).find('root');
+ if ($root.length == 0) {
+ // error
+ var myWin=window.open('','Report','width=400, height=250, resizable=1, scrollbars=1, status=1');
+ var tmp = myWin.document;
+ tmp.write(data);
+ tmp.close();
+ } else {
+ // success
+ if ($root.attr('act') == 'save_pos') {
+ PMA_ajaxShowMessage($root.attr('return'));
+ } else if ($root.attr('act') == 'relation_upd') {
+ PMA_ajaxShowMessage($root.attr('return'));
+ if ($root.attr('b') == '1') {
+ contr.splice($root.attr('K'), 1);
+ Re_load();
+ }
+ } else if ($root.attr('act') == 'relation_new') {
+ PMA_ajaxShowMessage($root.attr('return'));
+ if ($root.attr('b') == '1') {
+ var i = contr.length;
+ var t1 = $root.attr('DB1') + '.' + $root.attr('T1');
+ var f1 = $root.attr('F1');
+ var t2 = $root.attr('DB2') + '.' + $root.attr('T2');
+ var f2 = $root.attr('F2');
+ contr[i] = [];
+ contr[i][''] = [];
+ contr[i][''][t2] = [];
+ contr[i][''][t2][f2] = [];
+ contr[i][''][t2][f2][0] = t1;
+ contr[i][''][t2][f2][1] = f1;
+ Re_load();
+ }
+ }
+ }
+}
diff --git a/hugo/js/pmd/history.js b/hugo/js/pmd/history.js
new file mode 100644
index 0000000..3df4746
--- /dev/null
+++ b/hugo/js/pmd/history.js
@@ -0,0 +1,784 @@
+/* vim: set expandtab sw=4 ts=4 sts=4: */
+/**
+ * @fileoverview function used in this file builds history tab and generates query.
+ *
+ * @requires jQuery
+ * @requires moves.js
+ * @version $Id$
+ */
+
+var history_array = []; // Global array to store history objects
+var select_field = []; // Global array to store informaation for columns which are used in select clause
+var g_index;
+
+/**
+ * function for panel, hides and shows toggle_container <div>,which is for history elements uses {@link JQuery}.
+ *
+ * @param index has value 1 or 0,decides wheter to hide toggle_container on load.
+**/
+
+function panel(index)
+{
+ if (!index) {
+ $(".toggle_container").hide();
+ }
+ $("h2.tiger").click(function() {
+ $(this).toggleClass("active").next().slideToggle("slow");
+ });
+}
+
+/**
+ * Sorts history_array[] first,using table name as the key and then generates the HTML code for history tab,
+ * clubbing all objects of same tables together
+ * This function is called whenever changes are made in history_array[]
+ *
+ *
+ * @param {int} init starting index of unsorted array
+ * @param {int} finit last index of unsorted array
+ *
+**/
+
+function display(init,finit)
+{
+ var str,i,j,k,sto;
+ // this part sorts the history array based on table name,this is needed for clubbing all object of same name together.
+ for (i = init; i < finit; i++) {
+ sto = history_array[i];
+ var temp = history_array[i].get_tab() ;//+ '.' + history_array[i].get_obj_no(); for Self JOINS
+ for (j = 0; j < i; j++) {
+ if (temp > (history_array[j].get_tab())) {//+ '.' + history_array[j].get_obj_no())) { //for Self JOINS
+ for (k = i; k > j; k--) {
+ history_array[k] = history_array[k-1];
+ }
+ history_array[j] = sto;
+ break;
+ }
+ }
+ }
+ // this part generates HTML code for history tab.adds delete,edit,and/or and detail features with objects.
+ str =''; // string to store Html code for history tab
+ for (var i=0; i < history_array.length; i++) {
+ var temp = history_array[i].get_tab(); //+ '.' + history_array[i].get_obj_no(); for Self JOIN
+ str += '<h2 class="tiger"><a href="#">' + temp + '</a></h2>';
+ str += '<div class="toggle_container">\n';
+ while ((history_array[i].get_tab()) == temp) { //+ '.' + history_array[i].get_obj_no()) == temp) {
+ str +='<div class="block"> <table width ="250">';
+ str += '<thead><tr><td>';
+ if (history_array[i].get_and_or()) {
+ str +='<img src="' + pmaThemeImage + 'pmd/or_icon.png" onclick="and_or('+i+')" title="OR"/></td>';
+ } else {
+ str +='<img src="' + pmaThemeImage + 'pmd/and_icon.png" onclick="and_or('+i+')" title="AND"/></td>';
+ }
+ str +='<td style="padding-left: 5px;" class="right">' + PMA_getImage('b_sbrowse.png', 'column name') + '</td><td width="175" style="padding-left: 5px">' + history_array[i].get_column_name();
+ if (history_array[i].get_type() == "GroupBy" || history_array[i].get_type() == "OrderBy") {
+ str += '</td><td class="center">' + PMA_getImage('b_info.png', detail(i)) + '<td title="' + detail(i) +'">' + history_array[i].get_type() + '</td></td><td onmouseover="this.className=\'history_table\';" onmouseout="this.className=\'history_table2\'" onclick=history_delete('+ i +')>' + PMA_getImage('b_drop.png', 'Delete') + '</td></tr></thead>';
+ } else {
+ str += '</td><td class="center">' + PMA_getImage('b_info.png', detail(i)) + '</td><td title="' + detail(i) +'">' + history_array[i]. get_type() + '</td><td <td onmouseover="this.className=\'history_table\';" onmouseout="this.className=\'history_table2\'" onclick=history_edit('+ i +')>' + PMA_getImage('b_edit.png', PMA_messages['strEdit']) + '</td><td onmouseover="this.className=\'history_table\';" onmouseout="this.className=\'history_table2\'" onclick=history_delete('+ i +')><img src="themes/original/img/b_drop.png" title="Delete"></td></tr></thead>';
+ }
+ i++;
+ if (i >= history_array.length) {
+ break;
+ }
+ str += '</table></div><br/>';
+ }
+ i--;
+ str += '</div><br/>';
+ }
+ return str;
+}
+
+/**
+ * To change And/Or relation in history tab
+ *
+ *
+ * @param {int} index of history_array where change is to be made
+ *
+**/
+
+function and_or(index)
+{
+ if (history_array[index].get_and_or()) {
+ history_array[index].set_and_or(0);
+ } else {
+ history_array[index].set_and_or(1);
+ }
+ var existingDiv = document.getElementById('ab');
+ existingDiv.innerHTML = display(0,0);
+ panel(1);
+}
+
+/**
+ * To display details of obects(where,rename,Having,aggregate,groupby,orderby,having)
+ *
+ * @param index index of history_array where change is to be made
+ *
+**/
+
+function detail (index)
+{
+ var type = history_array[index].get_type();
+ var str;
+ if (type == "Where") {
+ str = 'Where ' + history_array[index].get_column_name() + history_array[index].get_obj().getrelation_operator() + history_array[index].get_obj().getquery();
+ }
+ if (type == "Rename") {
+ str = 'Rename ' + history_array[index].get_column_name() + ' To ' + history_array[index].get_obj().getrename_to();
+ }
+ if (type == "Aggregate") {
+ str = 'Select ' + history_array[index].get_obj().get_operator() + '( ' + history_array[index].get_column_name() + ' )';
+ }
+ if (type == "GroupBy") {
+ str = 'GroupBy ' + history_array[index].get_column_name() ;
+ }
+ if (type == "OrderBy") {
+ str = 'OrderBy ' + history_array[index].get_column_name() ;
+ }
+ if (type == "Having") {
+ str = 'Having ';
+ if (history_array[index].get_obj().get_operator() != 'None') {
+ str += history_array[index].get_obj().get_operator() + '( ' + history_array[index].get_column_name() + ' )';
+ str += history_array[index].get_obj().getrelation_operator() + history_array[index].get_obj().getquery();
+ } else {
+ str = 'Having ' + history_array[index].get_column_name() + history_array[index].get_obj().getrelation_operator() + history_array[index].get_obj().getquery();
+ }
+ }
+ return str;
+}
+
+/**
+ * Deletes entry in history_array
+ *
+ * @param index index of history_array[] which is to be deleted
+ *
+**/
+
+function history_delete(index)
+{
+ for (var k = 0; k < from_array.length; k++) {
+ if (from_array[k] == history_array[index].get_tab()) {
+ from_array.splice(k,1);
+ break;
+ }
+ }
+ history_array.splice(index,1);
+ var existingDiv = document.getElementById('ab');
+ existingDiv.innerHTML = display(0,0);
+ panel(1);
+}
+
+/**
+ * To show where,rename,aggregate,having forms to edit a object
+ *
+ * @param{int} index index of history_array where change is to be made
+ *
+**/
+
+function history_edit(index)
+{
+ g_index = index;
+ var type = history_array[index].get_type();
+ if (type == "Where") {
+ document.getElementById('eQuery').value = history_array[index].get_obj().getquery();
+ document.getElementById('erel_opt').value = history_array[index].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 (type == "Having") {
+ document.getElementById('hQuery').value = history_array[index].get_obj().getquery();
+ document.getElementById('hrel_opt').value = history_array[index].get_obj().getrelation_operator();
+ document.getElementById('hoperator').value = history_array[index].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 (type == "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 (type == "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';
+ }
+}
+
+/**
+ * Make changes in history_array when Edit button is clicked
+ * checks for the type of object and then sets the new value
+ *
+ * @param index index of history_array where change is to be made
+**/
+
+function edit(type)
+{
+ if (type == "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 (type == "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 (type == "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 (type == "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 existingDiv = document.getElementById('ab');
+ existingDiv.innerHTML = display(0,0);
+ panel(1);
+}
+
+/**
+ * history object closure
+ *
+ * @param ncolumn_name name of the column on which conditions are put
+ * @param nobj object details(where,rename,orderby,groupby,aggregate)
+ * @param ntab table name of the column on which conditions are applied
+ * @param nobj_no object no used for inner join
+ * @param ntype type of object
+ *
+**/
+
+function history(ncolumn_name,nobj,ntab,nobj_no,ntype)
+{
+ var and_or;
+ var obj;
+ var tab;
+ var column_name;
+ var obj_no;
+ var type;
+ this.set_column_name = function (ncolumn_name) {
+ column_name = ncolumn_name;
+ };
+ this.get_column_name = function() {
+ return column_name;
+ };
+ this.set_and_or = function(nand_or) {
+ and_or = nand_or;
+ };
+ this.get_and_or = function() {
+ return and_or;
+ };
+ this.get_relation = function() {
+ return and_or;
+ };
+ this.set_obj = function(nobj) {
+ obj = nobj;
+ };
+ this.get_obj = function() {
+ return obj;
+ };
+ this.set_tab = function(ntab) {
+ tab = ntab;
+ };
+ this.get_tab = function() {
+ return tab;
+ };
+ this.set_obj_no = function(nobj_no) {
+ obj_no = nobj_no;
+ };
+ this.get_obj_no = function() {
+ return obj_no;
+ };
+ this.set_type = function(ntype) {
+ type = ntype;
+ };
+ this.get_type = function() {
+ return type;
+ };
+ this.set_obj_no(nobj_no);
+ this.set_tab(ntab);
+ this.set_and_or(0);
+ this.set_obj(nobj);
+ this.set_column_name(ncolumn_name);
+ this.set_type(ntype);
+}
+
+/**
+ * where object closure, makes an object with all information of where
+ *
+ * @param nrelation_operator type of relation operator to be applied
+ * @param nquery stores value of value/sub-query
+ *
+**/
+
+
+var where = function (nrelation_operator,nquery) {
+ var relation_operator;
+ var query;
+ this.setrelation_operator = function(nrelation_operator) {
+ relation_operator = nrelation_operator;
+ };
+ this.setquery = function(nquery) {
+ query = nquery;
+ };
+ this.getquery = function() {
+ return query;
+ };
+ this.getrelation_operator = function() {
+ return relation_operator;
+ };
+ this.setquery(nquery);
+ this.setrelation_operator(nrelation_operator);
+};
+
+
+/**
+ * Having object closure, makes an object with all information of where
+ *
+ * @param nrelation_operator type of relation operator to be applied
+ * @param nquery stores value of value/sub-query
+ *
+**/
+
+var having = function (nrelation_operator,nquery,noperator) {
+ var relation_operator;
+ var query;
+ var operator;
+ this.set_operator = function(noperator) {
+ operator = noperator;
+ };
+ this.setrelation_operator = function(nrelation_operator) {
+ relation_operator = nrelation_operator;
+ };
+ this.setquery = function(nquery) {
+ query = nquery;
+ };
+ this.getquery = function() {
+ return query;
+ };
+ this.getrelation_operator = function() {
+ return relation_operator;
+ };
+ this.get_operator = function() {
+ return operator;
+ };
+ this.setquery(nquery);
+ this.setrelation_operator(nrelation_operator);
+ this.set_operator(noperator);
+};
+
+/**
+ * rename object closure,makes an object with all information of rename
+ *
+ * @param nrename_to new name information
+ *
+**/
+
+var rename = function(nrename_to) {
+ var rename_to;
+ this.setrename_to = function(nrename_to) {
+ rename_to = nrename_to;
+ };
+ this.getrename_to =function() {
+ return rename_to;
+ };
+ this.setrename_to(nrename_to);
+};
+
+/**
+ * aggregate object closure
+ *
+ * @param noperator aggregte operator
+ *
+**/
+
+var aggregate = function(noperator) {
+ var operator;
+ this.set_operator = function(noperator) {
+ operator = noperator;
+ };
+ this.get_operator = function() {
+ return operator;
+ };
+ this.set_operator(noperator);
+};
+
+/**
+ * This function returns unique element from an array
+ *
+ * @param arraName array from which duplicate elem are to be removed.
+ * @return unique array
+ */
+
+function unique(arrayName)
+{
+ var newArray=[];
+ label:for (var i=0; i<arrayName.length; i++ )
+ {
+ for (var j=0; j<newArray.length; j++ )
+ {
+ if (newArray[j]==arrayName[i]) {
+ continue label;
+ }
+ }
+ newArray[newArray.length] = arrayName[i];
+ }
+ return newArray;
+}
+
+/**
+ * This function takes in array and a value as input and returns 1 if values is present in array
+ * else returns -1
+ *
+ * @param arrayName array
+ * @param value value which is to be searched in the array
+ */
+
+function found(arrayName,value)
+{
+ for (var i=0; i<arrayName.length; i++) {
+ if (arrayName[i] == value) { return 1;}
+ }
+ return -1;
+}
+
+/**
+ * This function is the main function for query building.
+ * uses history object details for this.
+ *
+ * @ uses query_where()
+ * @ uses query_groupby()
+ * @ uses query_having()
+ * @ uses query_orderby()
+ *
+ * @param formtitle title for the form
+ * @param fadin
+ */
+
+function build_query(formtitle, fadin)
+{
+ var q_select = "SELECT ";
+ var temp;
+ for (var i = 0;i < select_field.length; i++) {
+ temp = check_aggregate(select_field[i]);
+ if (temp != "") {
+ q_select += temp;
+ temp = check_rename(select_field[i]);
+ q_select += temp + ",";
+ } else {
+ temp = check_rename(select_field[i]);
+ q_select += select_field[i] + temp +",";
+ }
+ }
+ q_select = q_select.substring(0,q_select.length - 1);
+ q_select += " FROM " + query_from();
+ if (query_where() != "") {
+ q_select +="\n WHERE";
+ q_select += query_where();
+ }
+ if (query_groupby() != "") { q_select += "\nGROUP BY " + query_groupby(); }
+ if (query_having() != "") { q_select += "\nHAVING " + query_having(); }
+ if (query_orderby() != "") { q_select += "\nORDER BY " + query_orderby(); }
+ var box = document.getElementById('box');
+ document.getElementById('filter').style.display='block';
+ var btitle = document.getElementById('boxtitle');
+ btitle.innerHTML = 'SELECT';//formtitle;
+ if (fadin) {
+ gradient("box", 0);
+ fadein("box");
+ } else{
+ box.style.display='block';
+ }
+ document.getElementById('textSqlquery').innerHTML = q_select;
+}
+ /**
+ * This function builds from clause of query
+ * makes automatic joins.
+ *
+ *
+ */
+
+
+function query_from()
+{
+ var i;
+ var tab_left = [];
+ var tab_used = [];
+ var t_tab_used = [];
+ var t_tab_left = [];
+ var temp;
+ var query = "";
+ var quer = "";
+ var parts = [];
+ var t_array = [];
+ t_array = from_array;
+ var K = 0;
+ var k;
+ var key;
+ var key2;
+ var key3;
+ var parts1;
+ for (i = 0; i < history_array.length ; i++) {
+ from_array.push(history_array[i].get_tab());
+ }
+ from_array = unique( from_array );
+ tab_left = from_array;
+ temp = tab_left.shift();
+ quer = temp;
+ tab_used.push(temp);
+ // if master table (key2) matches with tab used get all keys and check if tab_left matches
+ // after this check if master table (key2) matches with tab left then check if any foreign matches with master .
+ for (i =0; i<2 ; i++) {
+ for (K in contr) {
+ for (key in contr[K]) {// contr name
+ for (key2 in contr[K][key]) {// table name
+ parts = key2.split(".");
+ if (found(tab_used,parts[1]) > 0) {
+ for (key3 in contr[K][key][key2]) {
+ parts1 = contr[K][key][key2][key3][0].split(".");
+ if (found(tab_left,parts1[1]) > 0) {
+ query += "\n" + 'LEFT JOIN ';
+ query += '`' + parts1[0] + '`.`' + parts1[1] + '` ON ' ;
+ query += '`' + parts[1] +'`.`' + key3 + '` = ';
+ query += '`' + parts1[1] + '`.`' + contr[K][key][key2][key3][1] + '` ';
+ t_tab_left.push(parts1[1]);
+ }
+ }
+ }
+ }
+ }
+ }
+ K = 0;
+ t_tab_left = unique (t_tab_left);
+ tab_used = add_array(t_tab_left,tab_used);
+ tab_left = remove_array(t_tab_left,tab_left);
+ t_tab_left = [];
+ for (K in contr) {
+ for (key in contr[K]) {
+ for (key2 in contr[K][key]) {// table name
+ parts = key2.split(".");
+ if (found(tab_left,parts[1]) > 0) {
+ for (key3 in contr[K][key][key2]) {
+ parts1 = contr[K][key][key2][key3][0].split(".");
+ if (found(tab_used,parts1[1]) > 0) {
+ query += "\n" + 'LEFT JOIN ';
+ query += '`' + parts[0] + '`.`' + parts[1] + '` ON ' ;
+ query += '`' + parts1[1] + '`.`' + contr[K][key][key2][key3][1] + '` = ';
+ query += '`' + parts[1] + '`.`' + key3 + '` ';
+ t_tab_left.push(parts[1]);
+ }
+ }
+ }
+ }
+ }
+ }
+ t_tab_left = unique (t_tab_left);
+ tab_used = add_array(t_tab_left,tab_used);
+ tab_left = remove_array(t_tab_left,tab_left);
+ t_tab_left = [];
+ }
+ for (k in tab_left) {
+ quer += " , `" + tab_left[k] + "`";
+ }
+ query = quer + query;
+ from_array = t_array;
+ return query;
+}
+
+/**
+ * This function concatenates two array
+ *
+ * @params add array elements of which are pushed in
+ * @params arr array in which elemnets are added
+ */
+function add_array(add,arr)
+{
+ for (var i=0; i<add.length; i++) {
+ arr.push(add[i]);
+ }
+ return arr;
+}
+
+/* This fucntion removes all elements present in one array from the other.
+ *
+ * @params rem array from which each element is removed from other array.
+ * @params arr array from which elements are removed.
+ *
+ */
+function remove_array(rem,arr)
+{
+ for (var i=0; i<rem.length; i++) {
+ for (var j=0; j<arr.length; j++) {
+ if (rem[i] == arr[j]) {
+ arr.splice(j,1);
+ }
+ }
+ }
+ return arr;
+}
+
+/**
+ * This function builds the groupby clause from history object
+ *
+ */
+
+function query_groupby()
+{
+ var i;
+ var str = "";
+ for (i = 0; i < history_array.length;i++) {
+ if (history_array[i].get_type() == "GroupBy") { str +=history_array[i].get_column_name() + ", ";}
+ }
+ str = str.substr(0,str.length -1);
+ return str;
+}
+
+/**
+ * This function builds the Having clause from the history object.
+ *
+ */
+
+function query_having()
+{
+ var i;
+ var and = "(";
+ for (i = 0; i < history_array.length;i++) {
+ if (history_array[i].get_type() == "Having") {
+ if (history_array[i].get_obj().get_operator() != 'None') {
+ and += history_array[i].get_obj().get_operator() + "(" + history_array[i].get_column_name() + " ) " + history_array[i].get_obj().getrelation_operator();
+ and += " " + history_array[i].get_obj().getquery() + ", " ;
+ } else {
+ and += history_array[i].get_column_name() + " " + history_array[i].get_obj().getrelation_operator() + " " + history_array[i].get_obj().getquery() + ", ";
+ }
+ }
+ }
+ if (and =="(") {
+ and = "" ;
+ } else {
+ and = and.substr(0,and.length -2) + ")";
+ }
+ return and;
+}
+
+
+/**
+ * This function builds the orderby clause from the history object.
+ *
+ */
+
+function query_orderby()
+{
+ var i;
+ var str = "" ;
+ for (i = 0; i < history_array.length;i++) {
+ if (history_array[i].get_type() == "OrderBy") { str += history_array[i].get_column_name() + " , "; }
+ }
+ str = str.substr(0,str.length -1);
+ return str;
+}
+
+
+/**
+ * This function builds the Where clause from the history object.
+ *
+ */
+
+function query_where()
+{
+ var i;
+ var and = "(";
+ var or = "(";
+ for (i = 0; i < history_array.length;i++) {
+ if (history_array[i].get_type() == "Where") {
+ if (history_array[i].get_and_or() == 0) {
+ and += "( " + history_array[i].get_column_name() + " " + history_array[i].get_obj().getrelation_operator() +" " + history_array[i].get_obj().getquery() + ")"; and += " AND ";
+ } else {
+ or +="( " + history_array[i].get_column_name() + " " + history_array[i].get_obj().getrelation_operator() + " " + history_array[i].get_obj().getquery() +")";
+ or +=" OR " ;
+ }
+ }
+ }
+ if (or != "(") {
+ or = or.substring(0,(or.length - 4 )) + ")";
+ } else {
+ or = "" ;
+ }
+ if (and !="(") {
+ and = and.substring(0,(and.length - 5)) + ")";
+ } else {
+ and = "" ;
+ }
+ if (or != "" ) {
+ and = and + " OR " + or + " )";
+ }
+ return and;
+}
+
+function check_aggregate(id_this)
+{
+ var i;
+ for (i = 0;i < history_array.length;i++) {
+ var temp = '`' + history_array[i].get_tab() + '`.`' +history_array[i].get_column_name() +'`';
+ if (temp == id_this && history_array[i].get_type() == "Aggregate") {
+ return history_array[i].get_obj().get_operator() + '(' + id_this +')';
+ }
+ }
+ return "";
+}
+
+function check_rename(id_this)
+{
+ var i;
+ for (i = 0;i < history_array.length;i++) {
+ var temp = '`' + history_array[i].get_tab() + '`.`' +history_array[i].get_column_name() +'`';
+ if (temp == id_this && history_array[i].get_type() == "Rename") {
+ return " AS `" + history_array[i].get_obj().getrename_to() +"`";
+ }
+ }
+ return "";
+}
+
+function gradient(id, level)
+{
+ var box = document.getElementById(id);
+ box.style.opacity = level;
+ box.style.MozOpacity = level;
+ box.style.KhtmlOpacity = level;
+ box.style.filter = "alpha(opacity=" + level * 100 + ")";
+ box.style.display="block";
+ return;
+}
+
+
+function fadein(id)
+{
+ var level = 0;
+ while (level <= 1) {
+ setTimeout( "gradient('" + id + "'," + level + ")", (level* 1000) + 10);
+ level += 0.01;
+ }
+}
+
+function closebox()
+{
+ document.getElementById('box').style.display='none';
+ document.getElementById('filter').style.display='none';
+}
diff --git a/hugo/js/pmd/iecanvas.js b/hugo/js/pmd/iecanvas.js
new file mode 100644
index 0000000..90e1cae
--- /dev/null
+++ b/hugo/js/pmd/iecanvas.js
@@ -0,0 +1,151 @@
+/* vim: set expandtab sw=4 ts=4 sts=4: */
+/**
+ *
+ * @package PhpMyAdmin-Designer
+ */
+
+/**
+ *
+ */
+if (!window.all) // if IE
+{
+ document.attachEvent("onreadystatechange", // document load
+ function () {
+ if (document.readyState == "complete") {
+ var el = document.getElementById("canvas");
+ var outerHTML = el.outerHTML;
+ var newEl = document.createElement(outerHTML);
+ el.parentNode.replaceChild(newEl, el);
+ el = newEl;
+ el.getContext = function () {
+ if (this.cont) {
+ return this.cont;
+ }
+ return this.cont = new PMD_2D(this);
+ };
+
+ el.style.width = el.attributes.width.nodeValue + "px";
+ el.style.height = el.attributes.height.nodeValue + "px";
+ }
+ }
+ );
+
+//*****************************************************************************************************
+
+ function convert_style(str) {
+ var m = [];
+ m = str.match(/.*\((\d*),(\d*),(\d*),(\d*)\)/);
+ for (var i = 1; i<=3; i++) {
+ m[i] = (m[i]*1).toString(16).length < 2 ? '0' + (m[i]*1).toString(16) : (m[i]*1).toString(16);
+ }
+ return ['#' + m[1] + m[2] + m[3], 1];
+ }
+//------------------------------------------------------------------------------
+ function PMD_2D(th) {
+ this.element_ = th;
+ this.pmd_arr = [];
+ this.strokeStyle;
+ this.fillStyle;
+ this.lineWidth;
+
+ this.closePath = function() {
+ this.pmd_arr.push({type: "close"});
+ };
+
+ this.clearRect = function() {
+ this.element_.innerHTML = "";
+ this.pmd_arr = [];
+ };
+
+ this.beginPath = function() {
+ this.pmd_arr = [];
+ };
+
+ this.moveTo = function(aX, aY) {
+ this.pmd_arr.push({type: "moveTo", x: aX, y: aY});
+ };
+
+ this.lineTo = function(aX, aY) {
+ this.pmd_arr.push({type: "lineTo", x: aX, y: aY});
+ };
+
+ this.arc = function(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
+ if (!aClockwise) {
+ var t = aStartAngle;
+ aStartAngle = aEndAngle;
+ aEndAngle = t;
+ }
+
+ var xStart = aX + (Math.cos(aStartAngle) * aRadius);
+ var yStart = aY + (Math.sin(aStartAngle) * aRadius);
+
+ var xEnd = aX + (Math.cos(aEndAngle) * aRadius);
+ var yEnd = aY + (Math.sin(aEndAngle) * aRadius);
+
+ this.pmd_arr.push({type: "arc", x: aX, y: aY,
+ radius: aRadius, xStart: xStart, yStart: yStart, xEnd: xEnd, yEnd: yEnd});
+ };
+
+ this.rect = function(aX, aY, aW, aH) {
+ this.moveTo(aX, aY);
+ this.lineTo(aX + aW, aY);
+ this.lineTo(aX + aW, aY + aH);
+ this.lineTo(aX, aY + aH);
+ this.closePath();
+ };
+
+ this.fillRect = function(aX, aY, aW, aH) {
+ this.beginPath();
+ this.moveTo(aX, aY);
+ this.lineTo(aX + aW, aY);
+ this.lineTo(aX + aW, aY + aH);
+ this.lineTo(aX, aY + aH);
+ this.closePath();
+ this.stroke(true);
+ };
+
+ this.stroke = function(aFill) {
+ var Str = [];
+ var a = convert_style(aFill ? this.fillStyle : this.strokeStyle);
+ var color = a[0];
+
+ Str.push('<v:shape',
+ ' fillcolor="', color, '"',
+ ' filled="', Boolean(aFill), '"',
+ ' style="position:absolute;width:10;height:10;"',
+ ' coordorigin="0 0" coordsize="10 10"',
+ ' stroked="', !aFill, '"',
+ ' strokeweight="', this.lineWidth, '"',
+ ' strokecolor="', color, '"',
+ ' path="');
+
+ for (var i = 0; i < this.pmd_arr.length; i++) {
+ var p = this.pmd_arr[i];
+
+ if (p.type == "moveTo") {
+ Str.push(" m ");
+ Str.push(Math.floor(p.x), ",",Math.floor(p.y));
+ } else if (p.type == "lineTo") {
+ Str.push(" l ");
+ Str.push(Math.floor(p.x), ",",Math.floor(p.y));
+ } else if (p.type == "close") {
+ Str.push(" x ");
+ } else if (p.type == "arc") {
+ Str.push(" ar ");
+ Str.push(Math.floor(p.x - p.radius), ",",
+ Math.floor(p.y - p.radius), " ",
+ Math.floor(p.x + p.radius), ",",
+ Math.floor(p.y + p.radius), " ",
+ Math.floor(p.xStart), ",", Math.floor(p.yStart), " ",
+ Math.floor(p.xEnd), ",", Math.floor(p.yEnd));
+ }
+ }
+
+ Str.push(' ">');
+ Str.push("</v:shape>");
+
+ this.element_.insertAdjacentHTML("beforeEnd", Str.join(""));
+ this.pmd_arr = [];
+ }
+ }
+}
diff --git a/hugo/js/pmd/init.js b/hugo/js/pmd/init.js
new file mode 100644
index 0000000..00b09b9
--- /dev/null
+++ b/hugo/js/pmd/init.js
@@ -0,0 +1,31 @@
+/* vim: set expandtab sw=4 ts=4 sts=4: */
+/**
+ * Initialises the data required to run PMD, then fires it up.
+ */
+
+var j_tabs, h_tabs, contr, server, db, token;
+
+AJAX.registerTeardown('pmd/init.js', function() {
+ $(".trigger").unbind('click');
+});
+
+AJAX.registerOnload('pmd/init.js', function() {
+ $(".trigger").click(function() {
+ $(".panel").toggle("fast");
+ $(this).toggleClass("active");
+ return false;
+ });
+
+ var tables_data = $.parseJSON($("#script_tables").html());
+
+ j_tabs = tables_data.j_tabs;
+ h_tabs = tables_data.h_tabs;
+ contr = $.parseJSON($("#script_contr").html());
+ display_field = $.parseJSON($("#script_display_field").html());
+
+ server = $("#script_server").html();
+ db = $("#script_db").html();
+ token = $("#script_token").html();
+
+ Main();
+});
diff --git a/hugo/js/pmd/move.js b/hugo/js/pmd/move.js
new file mode 100644
index 0000000..eed06f8
--- /dev/null
+++ b/hugo/js/pmd/move.js
@@ -0,0 +1,1264 @@
+/* vim: set expandtab sw=4 ts=4 sts=4: */
+/**
+ * @package PhpMyAdmin-Designer
+ */
+
+/**
+ * init
+ */
+
+
+ var _change = 0; // variable to track any change in designer layout.
+ var _staying = 0; // variable to check if the user stayed after seeing the confirmation prompt.
+ var show_relation_lines = true;
+
+AJAX.registerTeardown('pmd/move.js', function() {
+ if ($.FullScreen.supported) {
+ $(document).unbind($.FullScreen.prefix + 'fullscreenchange');
+ }
+});
+
+AJAX.registerOnload('pmd/move.js', function() {
+ $('#page_content').css({'margin-left': '3px'});
+ $('#exitFullscreen').hide();
+ if ($.FullScreen.supported) {
+ $(document).fullScreenChange(function() {
+ if (! $.FullScreen.isFullScreen()) {
+ $('#page_content').removeClass('content_fullscreen')
+ .css({'width': 'auto', 'height': 'auto'});
+ $('#enterFullscreen').show();
+ $('#exitFullscreen').hide();
+ Top_menu_reposition($('#key_Left_Right')[0]);
+ }
+ });
+ } else {
+ $('#enterFullscreen').hide();
+ }
+});
+
+// Below is the function to bind onbeforeunload events with the content_frame as well as the top window.
+
+/*
+FIXME: we can't register the beforeonload event because it will persist between pageloads
+
+AJAX.registerOnload('pmd/move.js', function(){
+ $(window).bind('beforeunload', function() { // onbeforeunload for the frame window.
+ if (_change == 1 && _staying == 0) {
+ return PMA_messages['strLeavingDesigner'];
+ } else if (_change == 1 && _staying == 1) {
+ _staying = 0;
+ }
+ });
+ $(window).unload(function() {
+ _change = 0;
+ });
+ window.top.onbeforeunload = function() { // onbeforeunload for the browser main window.
+ if (_change == 1 && _staying == 0) {
+ _staying = 1; // Helps if the user stays on the page as there
+ setTimeout('make_zero();', 100); // is no other way of knowing whether the user stayed or not.
+ return PMA_messages['strLeavingDesigner'];
+ }
+ };
+});*/
+
+function make_zero() { // Function called if the user stays after seeing the confirmation prompt.
+ _staying = 0;
+}
+
+
+var dx, dy, dy2;
+var cur_click;
+// update in Main()
+var sm_x = 2, sm_y = 2;
+var sm_s = 0;
+var sm_add = 10;
+var s_left = 0;
+var s_right = 0;
+var ON_relation = 0;
+var ON_grid = 0;
+var ON_display_field = 0;
+// relation_style: 0 - angular 1 - direct
+var ON_angular_direct = 1;
+var click_field = 0;
+var link_relation = "";
+var id_hint;
+var canvas_width = 0;
+var canvas_height = 0;
+var osn_tab_width = 0;
+var osn_tab_height = 0;
+var height_field = 7;
+var Glob_X, Glob_Y;
+var timeoutID;
+var layer_menu_cur_click = 0;
+var step = 10;
+var old_class;
+var from_array = [];
+var downer;
+
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+
+
+//window.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP);
+//---CROSS
+document.onmousedown = MouseDown;
+document.onmouseup = MouseUp;
+document.onmousemove = MouseMove;
+
+var isIE = document.all && !window.opera;
+var isNN = !document.all && document.getElementById;
+var isN4 = document.layers;
+
+if (isIE) {
+ window.onscroll = General_scroll;
+ document.onselectstart = function () {return false;};
+}
+
+//document.onmouseup = function(){General_scroll_end();}
+function MouseDown(e)
+{
+ var offsetx, offsety;
+ if (cur_click != null) {
+ offsetx = isIE ? event.clientX + document.body.scrollLeft : e.pageX;
+ offsety = isIE ? event.clientY + document.body.scrollTop : e.pageY;
+ dx = offsetx - parseInt(cur_click.style.left);
+ dy = offsety - parseInt(cur_click.style.top);
+ //alert(" dx = " + dx + " dy = " +dy);
+ document.getElementById("canvas").style.display = 'none';
+ /*
+ var left = parseInt(cur_click.style.left);
+ var top = parseInt(cur_click.style.top);
+ dx = e.pageX - left;
+ dy = e.pageY - top;
+
+ alert(" dx = " + dx + " dy = " +dy);
+ */
+ cur_click.style.zIndex = 2;
+ }
+ if (layer_menu_cur_click) {
+ offsetx = e.pageX;
+ dx = offsetx - parseInt(document.getElementById("layer_menu").style.width);
+ }
+}
+
+function MouseMove(e)
+{
+ //Glob_X = e.pageX;
+ //Glob_Y = e.pageY;
+ Glob_X = isIE ? event.clientX + document.body.scrollLeft : e.pageX;
+ Glob_Y = isIE ? event.clientY + document.body.scrollTop : e.pageY;
+
+ //mouseX = (bw.ns4||bw.ns6)? e.pageX: bw.ie&&bw.win&&!bw.ie4? (event.clientX-2)+document.body.scrollLeft : event.clientX+document.body.scrollLeft;
+ //mouseY = (bw.ns4||bw.ns6)? e.pageY: bw.ie&&bw.win&&!bw.ie4? (event.clientY-2)+document.body.scrollTop : event.clientY+document.body.scrollTop;
+
+ //window.status = "X = "+ Glob_X + " Y = "+ Glob_Y;
+
+ if (cur_click != null) {
+ _change = 1;
+ var mGx = Glob_X - dx;
+ var mGy = Glob_Y - dy;
+ mGx = mGx > 0 ? mGx : 0;
+ mGy = mGy > 0 ? mGy : 0;
+
+ if (ON_grid) {
+ mGx = mGx % step < step / 2 ? mGx - mGx % step : mGx - mGx % step + step;
+ mGy = mGy % step < step / 2 ? mGy - mGy % step : mGy - mGy % step + step;
+ }
+
+ cur_click.style.left = mGx + 'px';
+ cur_click.style.top = mGy + 'px';
+ }
+
+ if (ON_relation || ON_display_field) {
+ document.getElementById('pmd_hint').style.left = (Glob_X + 20) + 'px';
+ document.getElementById('pmd_hint').style.top = (Glob_Y + 20) + 'px';
+ }
+
+ if (layer_menu_cur_click) {
+ document.getElementById("layer_menu").style.width = ((Glob_X - dx) >= 150 ? Glob_X - dx : 150) + 'px';
+ //document.getElementById("layer_menu").style.height = Glob_Y - dy>=200?Glob_Y - dy:200;
+ //document.getElementById("id_scroll_tab").style.height = Glob_Y - dy2;
+ }
+}
+
+function MouseUp(e)
+{
+ if (cur_click != null) {
+ document.getElementById("canvas").style.display = 'inline-block';
+ Re_load();
+ cur_click.style.zIndex = 1;
+ cur_click = null;
+ }
+ layer_menu_cur_click = 0;
+ //window.releaseEvents(Event.MOUSEMOVE);
+}
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+
+
+//function ToInt(s)
+//{
+// return s.substring(0,s.length-2)*1; //re = /(\d+)\w*/; newstr = str.replace(re, "$1");
+//}
+
+function Canvas_pos()
+{
+ canvas_width = document.getElementById('canvas').width = osn_tab_width - 3;
+ canvas_height = document.getElementById('canvas').height = osn_tab_height - 3;
+
+ if (isIE) {
+ document.getElementById('canvas').style.width = ((osn_tab_width - 3)?(osn_tab_width - 3):0) + 'px';
+ document.getElementById('canvas').style.height = ((osn_tab_height - 3)?(osn_tab_height - 3):0) + 'px';
+ }
+}
+
+function Osn_tab_pos()
+{
+ osn_tab_width = parseInt(document.getElementById('osn_tab').style.width);
+ osn_tab_height = parseInt(document.getElementById('osn_tab').style.height);
+}
+
+
+function Main()
+{
+ //alert( document.getElementById('osn_tab').offsetTop);
+ //---CROSS
+
+ document.getElementById("layer_menu").style.top = -1000 + 'px'; //fast scroll
+ sm_x += document.getElementById('osn_tab').offsetLeft;
+ sm_y += document.getElementById('osn_tab').offsetTop;
+ Osn_tab_pos();
+ Canvas_pos();
+ Small_tab_refresh();
+ Re_load();
+ id_hint = document.getElementById('pmd_hint');
+ if (isIE) {
+ General_scroll();
+ }
+}
+
+
+//-------------------------------- new -----------------------------------------
+function Rezize_osn_tab()
+{
+ var max_X = 0;
+ var max_Y = 0;
+ for (var key in j_tabs) {
+ var k_x = parseInt(document.getElementById(key).style.left) + document.getElementById(key).offsetWidth;
+ var k_y = parseInt(document.getElementById(key).style.top) + document.getElementById(key).offsetHeight;
+ max_X = max_X < k_x ? k_x : max_X;
+ max_Y = max_Y < k_y ? k_y : max_Y;
+ }
+
+ osn_tab_width = max_X + 50;
+ osn_tab_height = max_Y + 50;
+ Canvas_pos();
+ document.getElementById('osn_tab').style.width = osn_tab_width + 'px';
+ document.getElementById('osn_tab').style.height = osn_tab_height + 'px';
+}
+//------------------------------------------------------------------------------
+
+/**
+ * refreshes display, must be called after state changes
+ */
+function Re_load()
+{
+ Rezize_osn_tab();
+ var n;
+ var x1;
+ var x2;
+ var a = [];
+ var K;
+ var key;
+ var key2;
+ var key3;
+ Clear();
+ for (K in contr) {
+ for (key in contr[K]) {
+ // contr name
+ for (key2 in contr[K][key]) {
+ // table name
+ for (key3 in contr[K][key][key2]) {
+ // field name
+ if (!document.getElementById("check_vis_" + key2).checked ||
+ !document.getElementById("check_vis_" + contr[K][key][key2][key3][0]).checked) {
+ // if hide
+ continue;
+ }
+ var x1_left = document.getElementById(key2).offsetLeft+1;
+ var x1_right = x1_left + document.getElementById(key2).offsetWidth;
+ var x2_left = document.getElementById(contr[K][key][key2][key3][0]).offsetLeft;
+ var x2_right = x2_left + document.getElementById(contr[K][key][key2][key3][0]).offsetWidth;
+ a[0] = Math.abs(x1_left - x2_left);
+ a[1] = Math.abs(x1_left - x2_right);
+ a[2] = Math.abs(x1_right - x2_left);
+ a[3] = Math.abs(x1_right - x2_right);
+ n = s_left = s_right = 0;
+ for (var i = 1; i < 4; i++) {
+ if (a[n] > a[i]) {
+ n = i;
+ }
+ }
+ if (n == 1) {
+ x1 = x1_left - sm_s;
+ x2 = x2_right + sm_s;
+ if (x1 < x2) {
+ n = 0;
+ }
+ }
+ if (n == 2) {
+ x1 = x1_right + sm_s;
+ x2 = x2_left - sm_s;
+ if (x1 > x2) {
+ n = 0;
+ }
+ }
+ if (n == 3) {
+ x1 = x1_right + sm_s;
+ x2 = x2_right + sm_s;
+ s_right = 1;
+ }
+ if (n == 0) {
+ x1 = x1_left - sm_s;
+ x2 = x2_left - sm_s;
+ s_left = 1;
+ }
+ //alert(key2 + "." + key3);
+
+ var row_offset_top = 0;
+ //alert('id_tbody_' + key2);
+ //alert(document.getElementById('id_hide_tbody_' + key2));
+ var tab_hide_button = document.getElementById('id_hide_tbody_' + key2);
+
+ //alert(tab_hide_button.innerHTML);
+ if (tab_hide_button.innerHTML == 'v') {
+ row_offset_top = document.getElementById(key2 + "." + key3).offsetTop;
+ }
+
+ var y1 = document.getElementById(key2).offsetTop
+ + row_offset_top
+ + height_field;
+ //alert(1);
+
+ row_offset_top = 0;
+ var tab_hide_button = document.getElementById('id_hide_tbody_' + contr[K][key][key2][key3][0]);
+ if (tab_hide_button.innerHTML == 'v') {
+ row_offset_top = document.getElementById(contr[K][key][key2][key3][0]
+ + '.' + contr[K][key][key2][key3][1]).offsetTop;
+ }
+
+ var y2 =
+ document.getElementById(contr[K][key][key2][key3][0]).offsetTop
+ + row_offset_top
+ + height_field;
+
+ //alert(y1 + ' - ' + key2 + "." + key3);
+ Line0(x1 - sm_x, y1 - sm_y, x2 - sm_x, y2 - sm_y, getColorByTarget( contr[K][key][key2][key3][0]+'.'+contr[K][key][key2][key3][1] ) );
+ }
+ }
+ }
+ }
+}
+
+/**
+ * draws a line from x1:y1 to x2:y2 with color
+ */
+function Line(x1, y1, x2, y2, color_line)
+{
+ var canvas = document.getElementById("canvas");
+ var ctx = canvas.getContext("2d");
+ ctx.strokeStyle = color_line;
+ ctx.lineWidth = 1;
+ ctx.beginPath();
+ ctx.moveTo(x1, y1);
+ ctx.lineTo(x2, y2);
+ ctx.stroke();
+}
+
+/**
+ * draws a relation/constraint line, whether angular or not
+ */
+function Line0(x1, y1, x2, y2, color_line)
+{
+ if (! show_relation_lines) {
+ return;
+ }
+ Circle(x1, y1, 3, 3, color_line);
+ Rect(x2 - 1, y2 - 2, 4, 4, color_line);
+
+ if (ON_angular_direct) {
+ Line2(x1, y1, x2, y2, color_line);
+ } else {
+ Line3(x1, y1, x2, y2, color_line);
+ }
+}
+
+/**
+ * draws a angualr relation/constraint line
+ */
+function Line2(x1, y1, x2, y2, color_line)
+{
+ var x1_ = x1;
+ var x2_ = x2;
+
+ if (s_right) {
+ x1_ += sm_add;
+ x2_ += sm_add;
+ } else if (s_left) {
+ x1_ -= sm_add;
+ x2_ -= sm_add;
+ } else if (x1 < x2) {
+ x1_ += sm_add;
+ x2_ -= sm_add;
+ } else {
+ x1_ -= sm_add;
+ x2_ += sm_add;
+ }
+
+ Line(x1, y1, x1_, y1, color_line);
+ Line(x2, y2, x2_, y2, color_line);
+ Line(x1_, y1, x2_, y2, color_line);
+}
+
+/**
+ * draws a relation/constraint line
+ */
+function Line3(x1, y1, x2, y2, color_line)
+{
+ var x1_ = x1;
+ var x2_ = x2;
+
+ if (s_right) {
+ if (x1 < x2) {
+ x1_ += x2 - x1 + sm_add;
+ x2_ += sm_add;
+ } else {
+ x2_ += x1 - x2 + sm_add;
+ x1_ += sm_add;
+ }
+
+ Line(x1, y1, x1_, y1, color_line);
+ Line(x2, y2, x2_, y2, color_line);
+ Line(x1_, y1, x2_, y2, color_line);
+ return;
+ }
+ if (s_left) {
+ if (x1 < x2) {
+ x2_ -= x2 - x1 + sm_add;
+ x1_ -= sm_add;
+ } else {
+ x1_ -= x1 - x2 + sm_add;
+ x2_ -= sm_add;
+ }
+
+ Line(x1, y1, x1_, y1, color_line);
+ Line(x2, y2, x2_, y2, color_line);
+ Line(x1_, y1, x2_, y2, color_line);
+ return;
+ }
+
+ var x_s = (x1 + x2) / 2;
+ Line(x1, y1, x_s, y1, color_line);
+ Line(x_s, y2, x2, y2, color_line);
+ Line(x_s, y1, x_s, y2, color_line);
+}
+
+function Circle(x, y, r, w, color)
+{
+ var ctx = document.getElementById('canvas').getContext('2d');
+ ctx.beginPath();
+ ctx.moveTo(x, y);
+ ctx.lineWidth = w;
+ ctx.strokeStyle = color;
+ ctx.arc(x, y, r, 0, 2 * Math.PI, true);
+ ctx.stroke();
+}
+
+function Clear()
+{
+ var canvas = document.getElementById("canvas");
+ var ctx = canvas.getContext("2d");
+ ctx.clearRect(0, 0, canvas_width, canvas_height);
+}
+
+function Rect(x1, y1, w, h, color)
+{
+ var ctx = document.getElementById('canvas').getContext('2d');
+ ctx.fillStyle = color;
+ ctx.fillRect(x1, y1, w, h);
+}
+//--------------------------- FULLSCREEN -------------------------------------
+function Enter_fullscreen()
+{
+ if (! $.FullScreen.isFullScreen()) {
+ $('#enterFullscreen').hide();
+ $('#exitFullscreen').show();
+ $('#page_content')
+ .addClass('content_fullscreen')
+ .css({'width': screen.width - 5, 'height': screen.height - 5})
+ .requestFullScreen();
+ Top_menu_reposition($('#key_Left_Right')[0]);
+ }
+}
+
+function Exit_fullscreen()
+{
+ if ($.FullScreen.isFullScreen()) {
+ $.FullScreen.cancelFullScreen();
+ }
+}
+//------------------------------ SAVE ------------------------------------------
+function Save(url) // (del?) no for pdf
+{
+ for (var key in j_tabs) {
+ document.getElementById('t_x_' + key + '_').value = parseInt(document.getElementById(key).style.left);
+ document.getElementById('t_y_' + key + '_').value = parseInt(document.getElementById(key).style.top);
+ document.getElementById('t_v_' + key + '_').value = document.getElementById('id_tbody_' + key).style.display == 'none' ? 0 : 1;
+ document.getElementById('t_h_' + key + '_').value = document.getElementById('check_vis_' + key).checked ? 1 : 0;
+ }
+ document.form1.action = url;
+ $(document.form1).submit();
+}
+
+function Get_url_pos()
+{
+ var poststr = '';
+ for (var key in j_tabs) {
+ poststr += '&t_x[' + key + ']=' + parseInt(document.getElementById(key).style.left);
+ poststr += '&t_y[' + key + ']=' + parseInt(document.getElementById(key).style.top);
+ poststr += '&t_v[' + key + ']=' + (document.getElementById('id_tbody_' + key).style.display == 'none' ? 0 : 1);
+ poststr += '&t_h[' + key + ']=' + (document.getElementById('check_vis_' + key).checked ? 1 : 0);
+ }
+ return poststr;
+}
+
+function Save2()
+{
+ _change = 0;
+ var poststr = 'IS_AJAX=1&server='+server+'&db=' + db + '&token=' + token + '&die_save_pos=1';
+ poststr += Get_url_pos();
+ makeRequest('pmd_save_pos.php', poststr);
+}
+
+function Grid()
+{
+ if (!ON_grid) {
+ ON_grid = 1;
+ document.getElementById('grid_button').className = 'M_butt_Selected_down';
+ } else {
+ document.getElementById('grid_button').className = 'M_butt';
+ ON_grid = 0;
+ }
+}
+
+function Angular_direct()
+{
+ if (ON_angular_direct) {
+ ON_angular_direct = 0;
+ document.getElementById('angular_direct_button').className = 'M_butt_Selected_down';
+ } else {
+ ON_angular_direct = 1;
+ document.getElementById('angular_direct_button').className = 'M_butt';
+ }
+ Re_load();
+}
+//++++++++++++++++++++++++++++++ RELATION ++++++++++++++++++++++++++++++++++++++
+function Start_relation()
+{
+ if (ON_display_field) {
+ return;
+ }
+
+ if (!ON_relation) {
+ document.getElementById('foreign_relation').style.display = '';
+ ON_relation = 1;
+ document.getElementById('pmd_hint').innerHTML = PMA_messages['strSelectReferencedKey'];
+ document.getElementById('pmd_hint').style.display = 'block';
+ document.getElementById('rel_button').className = 'M_butt_Selected_down';
+ } else {
+ document.getElementById('pmd_hint').innerHTML = "";
+ document.getElementById('pmd_hint').style.display = 'none';
+ document.getElementById('rel_button').className = 'M_butt';
+ click_field = 0;
+ ON_relation = 0;
+ }
+}
+
+function Click_field(T, f, PK) // table field
+{
+ if (ON_relation) {
+ if (!click_field) {
+ //.style.display=='none' .style.display = 'none'
+ if (!PK) {
+ alert(PMA_messages['strPleaseSelectPrimaryOrUniqueKey']);
+ return;// 0;
+ }//PK
+ if (j_tabs[db + '.' + T] != '1') {
+ document.getElementById('foreign_relation').style.display = 'none';
+ }
+ click_field = 1;
+ link_relation = "T1=" + T + "&F1=" + f;
+ document.getElementById('pmd_hint').innerHTML = PMA_messages['strSelectForeignKey'];
+ } else {
+ Start_relation(); // hidden hint...
+ if (j_tabs[db + '.' + T] != '1' || !PK) {
+ document.getElementById('foreign_relation').style.display = 'none';
+ }
+ var left = Glob_X - (document.getElementById('layer_new_relation').offsetWidth>>1);
+ document.getElementById('layer_new_relation').style.left = left + 'px';
+ var top = Glob_Y - document.getElementById('layer_new_relation').offsetHeight;
+ document.getElementById('layer_new_relation').style.top = top + 'px';
+ document.getElementById('layer_new_relation').style.display = 'block';
+ link_relation += '&T2=' + T + '&F2=' + f;
+ }
+ }
+
+ if (ON_display_field) {
+ // if is display field
+ if (display_field[T] == f) {
+ //alert(T);
+ //s = '';for(k in display_field)s += k + ' = ' + display_field[k] + ',';alert(s);
+ old_class = 'tab_field';
+ //display_field.splice(T, 1);
+ delete display_field[T];
+ //s = '';for(k in display_field)s += k + ' = ' + display_field[k] + ', ';alert(s);
+ //n = 0;for(k in display_field)n++;alert(n);
+ } else {
+ old_class = 'tab_field_3';
+ if (display_field[T]) {
+ document.getElementById('id_tr_' + T + '.' + display_field[T]).className = 'tab_field';
+ //display_field.splice(T, 1);
+ delete display_field[T];
+ }
+ display_field[T] = f;
+ }
+ ON_display_field = 0;
+ document.getElementById('pmd_hint').innerHTML = "";
+ document.getElementById('pmd_hint').style.display = 'none';
+ document.getElementById('display_field_button').className = 'M_butt';
+ makeRequest('pmd_display_field.php', 'T=' + T + '&F=' + f + '&server=' + server + '&db=' + db + '&token=' + token);
+ }
+}
+
+function New_relation()
+{
+ document.getElementById('layer_new_relation').style.display = 'none';
+ link_relation += '&server=' + server + '&db=' + db + '&token=' + token + '&die_save_pos=0';
+ link_relation += '&on_delete=' + document.getElementById('on_delete').value + '&on_update=' + document.getElementById('on_update').value;
+ link_relation += Get_url_pos();
+
+ //alert(link_relation);
+ makeRequest('pmd_relation_new.php', link_relation);
+}
+
+//-------------------------- create tables -------------------------------------
+
+function Start_table_new()
+{
+ PMA_commonParams.set('table', '');
+ PMA_commonActions.refreshMain('tbl_create.php');
+}
+
+function Start_tab_upd(table)
+{
+ PMA_commonParams.set('table', table);
+ PMA_commonActions.refreshMain('tbl_structure.php');
+}
+//--------------------------- hide tables --------------------------------------
+
+function Small_tab_all(id_this) // max/min all tables
+{
+ if (id_this.alt == "v") {
+ for (var key in j_tabs) {
+ if (document.getElementById('id_hide_tbody_'+key).innerHTML == "v") {
+ Small_tab(key, 0);
+ }
+ }
+ id_this.alt = ">";
+ id_this.src = pmaThemeImage + "pmd/rightarrow1.png";
+ } else {
+ for (var key in j_tabs) {
+ if (document.getElementById('id_hide_tbody_'+key).innerHTML != "v") {
+ Small_tab(key, 0);
+ }
+ }
+ id_this.alt = "v";
+ id_this.src = pmaThemeImage + "pmd/downarrow1.png";
+ }
+ Re_load();
+}
+
+function Small_tab_invert() // invert max/min all tables
+{
+ for (var key in j_tabs) {
+ Small_tab(key, 0);
+ }
+ Re_load();
+}
+
+function Relation_lines_invert()
+{
+ show_relation_lines = ! show_relation_lines;
+ Re_load();
+}
+
+function Small_tab_refresh()
+{
+ for (var key in j_tabs) {
+ if(document.getElementById('id_hide_tbody_'+key).innerHTML != "v") {
+ Small_tab(key, 0);
+ Small_tab(key, 0);
+ }
+ }
+}
+
+function Small_tab(t, re_load)
+{
+ var id = document.getElementById('id_tbody_' + t);
+ var id_this = document.getElementById('id_hide_tbody_' + t);
+ var id_t = document.getElementById(t);
+ id_t.style.width = id_t.offsetWidth + 'px';
+ if (id_this.innerHTML == "v") {
+ //---CROSS
+ id.style.display = 'none';
+ id_this.innerHTML = '>';
+ } else {
+ id.style.display = '';
+ id_this.innerHTML = 'v';
+ }
+ if (re_load) {
+ Re_load();
+ }
+}
+//------------------------------------------------------------------------------
+function Select_tab(t)
+{
+ var id_zag = document.getElementById('id_zag_' + t);
+ if (id_zag.className != 'tab_zag_3') {
+ document.getElementById('id_zag_' + t).className = 'tab_zag_2';
+ } else {
+ document.getElementById('id_zag_' + t).className = 'tab_zag';
+ }
+ //----------
+ var id_t = document.getElementById(t);
+ window.scrollTo(parseInt(id_t.style.left) - 300, parseInt(id_t.style.top) - 300);
+ setTimeout(function(){document.getElementById('id_zag_' + t).className = 'tab_zag';}, 800);
+}
+//------------------------------------------------------------------------------
+
+function Canvas_click(id)
+{
+ var n = 0;
+ var relation_name = 0;
+ var selected = 0;
+ var a = [];
+ var Key0, Key1, Key2, Key3, Key, x1, x2;
+ var K, key, key2, key3;
+ var Local_X = $.FullScreen.isFullScreen() ? Glob_X : Glob_X - document.getElementById("canvas_outer").offsetLeft;
+ var Local_Y = Glob_Y - document.getElementById("canvas_outer").offsetTop;
+ Clear();
+ for (K in contr) {
+ for (key in contr[K]) {
+ for (key2 in contr[K][key]) {
+ for (key3 in contr[K][key][key2]) {
+ if (!document.getElementById("check_vis_"+key2).checked
+ || !document.getElementById("check_vis_"+contr[K][key][key2][key3][0]).checked) {
+ continue; // if hide
+ }
+ var x1_left = document.getElementById(key2).offsetLeft + 1;//document.getElementById(key2+"."+key3).offsetLeft;
+ var x1_right = x1_left + document.getElementById(key2).offsetWidth;
+ var x2_left = document.getElementById(contr[K][key][key2][key3][0]).offsetLeft;//+document.getElementById(contr[K][key2][key3][0]+"."+contr[K][key2][key3][1]).offsetLeft
+ var x2_right = x2_left + document.getElementById(contr[K][key][key2][key3][0]).offsetWidth;
+ a[0] = Math.abs(x1_left - x2_left);
+ a[1] = Math.abs(x1_left - x2_right);
+ a[2] = Math.abs(x1_right - x2_left);
+ a[3] = Math.abs(x1_right - x2_right);
+ n = s_left = s_right = 0;
+ for (var i = 1; i < 4; i++) {
+ if (a[n] > a[i]) {
+ n = i;
+ }
+ }
+ if (n == 1) {
+ x1 = x1_left - sm_s;
+ x2 = x2_right + sm_s;
+ if (x1 < x2) {
+ n = 0;
+ }
+ }
+ if (n == 2) {
+ x1 = x1_right + sm_s;
+ x2 = x2_left - sm_s;
+ if (x1 > x2) {
+ n = 0;
+ }
+ }
+ if (n == 3) {
+ x1 = x1_right + sm_s;
+ x2 = x2_right + sm_s;
+ s_right = 1;
+ }
+ if (n == 0) {
+ x1 = x1_left - sm_s;
+ x2 = x2_left - sm_s;
+ s_left = 1;
+ }
+
+ var y1 = document.getElementById(key2).offsetTop + document.getElementById(key2+"."+key3).offsetTop + height_field;
+ var y2 = document.getElementById(contr[K][key][key2][key3][0]).offsetTop +
+ document.getElementById(contr[K][key][key2][key3][0]+"."+contr[K][key][key2][key3][1]).offsetTop + height_field;
+ if (!selected && Local_X > x1 - 10 && Local_X < x1 + 10 && Local_Y > y1 - 7 && Local_Y < y1 + 7) {
+ Line0(x1 - sm_x, y1 - sm_y, x2 - sm_x, y2 - sm_y, "rgba(255,0,0,1)");
+ selected = 1; // Rect(x1-sm_x,y1-sm_y,10,10,"rgba(0,255,0,1)");
+ relation_name = key; //
+ Key0 = contr[K][key][key2][key3][0];
+ Key1 = contr[K][key][key2][key3][1];
+ Key2 = key2; Key3 = key3;
+ Key = K;
+ } else {
+ Line0(x1 - sm_x, y1 - sm_y, x2 - sm_x, y2 - sm_y, getColorByTarget( contr[K][key][key2][key3][0]+'.'+contr[K][key][key2][key3][1] ));
+ }
+ }
+ }
+ }
+ }
+ if (selected) {
+ // select relations
+ //alert(Key0+' - '+Key1+' - '+Key2+' - '+Key3);
+ var left = Glob_X - (document.getElementById('layer_upd_relation').offsetWidth>>1);
+ document.getElementById('layer_upd_relation').style.left = left + 'px';
+ var top = Glob_Y - document.getElementById('layer_upd_relation').offsetHeight - 10;
+ document.getElementById('layer_upd_relation').style.top = top + 'px';
+ document.getElementById('layer_upd_relation').style.display = 'block';
+ link_relation = 'T1=' + Key0 + '&F1=' + Key1 + '&T2=' + Key2 + '&F2=' + Key3 + '&K=' + Key;
+ }
+}
+
+function Upd_relation()
+{
+ document.getElementById('layer_upd_relation').style.display = 'none';
+ link_relation += '&server=' + server + '&db=' + db + '&token=' + token + '&die_save_pos=0';
+ link_relation += Get_url_pos();
+ makeRequest('pmd_relation_upd.php', link_relation);
+}
+
+function VisibleTab(id, t_n)
+{
+ if (id.checked) {
+ document.getElementById(t_n).style.display = 'block';
+ } else {
+ document.getElementById(t_n).style.display = 'none';
+ }
+ Re_load();
+}
+
+function Hide_tab_all(id_this) // max/min all tables
+{
+ if (id_this.alt == 'v') {
+ id_this.alt = '>';
+ id_this.src = pmaThemeImage + "pmd/rightarrow1.png";
+ } else {
+ id_this.alt = 'v';
+ id_this.src = pmaThemeImage + "pmd/downarrow1.png";
+ }
+ var E = document.form1;
+ for (var i = 0; i < E.elements.length; i++) {
+ if (E.elements[i].type == "checkbox" && E.elements[i].id.substring(0, 10) == 'check_vis_') {
+ if (id_this.alt == 'v') {
+ E.elements[i].checked = true;
+ document.getElementById(E.elements[i].value).style.display = '';
+ } else {
+ E.elements[i].checked = false;
+ document.getElementById(E.elements[i].value).style.display = 'none';
+ }
+ }
+ }
+ Re_load();
+}
+
+function in_array_k(x, m)
+{
+ var b = 0;
+ for (var u in m) {
+ if (x == u) {
+ b=1;
+ break;
+ }
+ }
+ return b;
+}
+
+function No_have_constr(id_this)
+{
+ var a = [];
+ var K, key, key2, key3;
+ for (K in contr) {
+ for (key in contr[K]) {
+ // contr name
+ for (key2 in contr[K][key]) {
+ // table name
+ for (key3 in contr[K][key][key2]) {
+ // field name
+ a[key2] = a[contr[K][key][key2][key3][0]] = 1; // exist constr
+ }
+ }
+ }
+ }
+
+ if (id_this.alt == 'v') {
+ id_this.alt = '>';
+ id_this.src = pmaThemeImage + "pmd/rightarrow2.png";
+ } else {
+ id_this.alt = 'v';
+ id_this.src = pmaThemeImage + "pmd/downarrow2.png";
+ }
+ var E = document.form1;
+ for (var i = 0; i < E.elements.length; i++) {
+ if (E.elements[i].type == "checkbox" && E.elements[i].id.substring(0, 10) == 'check_vis_') {
+ if (!in_array_k(E.elements[i].value, a)) {
+ if (id_this.alt == 'v') {
+ E.elements[i].checked = true;
+ document.getElementById(E.elements[i].value).style.display = '';
+ } else {
+ E.elements[i].checked = false;
+ document.getElementById(E.elements[i].value).style.display = 'none';
+ }
+ }
+ }
+ }
+}
+
+function PDF_save()
+{
+ // var WinPDF =
+ // window.open("pmd_pdf.php?token="+token+"&db="+db,"wind1", "top=200,left=200,width=200,height=100,resizable=yes,scrollbars=yes,menubar=no");
+ Save('pmd_pdf.php?server=' + server + '&token=' + token + '&db=' + db);
+}
+
+function General_scroll()
+{
+ /*
+ if (!document.getElementById('show_relation_olways').checked) {
+ document.getElementById("canvas").style.display = 'none';
+ clearTimeout(timeoutID);
+ timeoutID = setTimeout(General_scroll_end, 500);
+ }
+ */
+ //if (timeoutID)
+ clearTimeout(timeoutID);
+ timeoutID = setTimeout
+ (
+ function()
+ {
+ document.getElementById('top_menu').style.left = document.body.scrollLeft + 'px';
+ document.getElementById('top_menu').style.top = document.body.scrollTop + 'px';
+ }
+ ,200
+ );
+}
+
+/*
+function General_scroll_end()
+{
+ document.getElementById('layer_menu').style.left = document.body.scrollLeft;
+ document.getElementById('layer_menu').style.top = document.body.scrollTop + document.getElementById('top_menu').offsetHeight;
+ if (isIE) {
+ document.getElementById('layer_menu').style.left = document.body.scrollLeft;
+ document.getElementById('layer_menu').style.top = document.body.scrollTop + document.getElementById('top_menu').offsetHeight;
+ }
+ document.getElementById("canvas").style.display = 'block';
+}
+*/
+
+function Show_left_menu(id_this) // max/min all tables
+{
+ if (id_this.alt == "v") {
+ var pos = $("#top_menu").offset();
+ var height = $("#top_menu").height();
+ document.getElementById("layer_menu").style.top = '0px';
+ document.getElementById("layer_menu").style.display = 'block';
+ id_this.alt = ">";
+ id_this.src = pmaThemeImage + "pmd/uparrow2_m.png";
+ if (isIE) {
+ General_scroll();
+ }
+ } else {
+ document.getElementById("layer_menu").style.top = -1000 + 'px'; //fast scroll
+ document.getElementById("layer_menu").style.display = 'none';
+ id_this.alt = "v";
+ id_this.src = pmaThemeImage + "pmd/downarrow2_m.png";
+ }
+}
+//------------------------------------------------------------------------------
+function Top_menu_right(id_this)
+{
+ if (id_this.alt == ">") {
+ moveTopMenuToRight(id_this);
+ id_this.alt = "<";
+ id_this.src = pmaThemeImage + "pmd/2leftarrow_m.png";
+ } else {
+ document.getElementById('top_menu').style.paddingLeft = 0;
+ id_this.alt = ">";
+ id_this.src = pmaThemeImage + "pmd/2rightarrow_m.png";
+ }
+}
+
+function Top_menu_reposition(id_this)
+{
+ if (id_this.alt == "<") {
+ moveTopMenuToRight(id_this);
+ }
+}
+
+function moveTopMenuToRight(id_this)
+{
+ var top_menu_width = 10;
+ $('#top_menu').children().each(function () {
+ top_menu_width += $(this).outerWidth(true);
+ });
+ var offset = parseInt(document.getElementById('canvas_outer').offsetWidth - top_menu_width, 10);
+ document.getElementById('top_menu').style.paddingLeft = offset + 'px';
+}
+//------------------------------------------------------------------------------
+function Start_display_field()
+{
+ if (ON_relation) {
+ return;
+ }
+ if (!ON_display_field) {
+ ON_display_field = 1;
+ document.getElementById('pmd_hint').innerHTML = PMA_messages['strChangeDisplay'];
+ document.getElementById('pmd_hint').style.display = 'block';
+ document.getElementById('display_field_button').className = 'M_butt_Selected_down';//'#FFEE99';gray #AAAAAA
+
+ if (isIE) { // correct for IE
+ document.getElementById('display_field_button').className = 'M_butt_Selected_down_IE';
+ }
+ } else {
+ document.getElementById('pmd_hint').innerHTML = "";
+ document.getElementById('pmd_hint').style.display = 'none';
+ document.getElementById('display_field_button').className = 'M_butt';
+ ON_display_field = 0;
+ }
+}
+//------------------------------------------------------------------------------
+var TargetColors = [];
+function getColorByTarget( target )
+{
+ var color = ''; //"rgba(0,100,150,1)";
+
+ for (var i in TargetColors) {
+ if (TargetColors[i][0]==target) {
+ color = TargetColors[i][1];
+ break;
+ }
+ }
+
+
+ if (color.length==0) {
+ var i = TargetColors.length+1;
+ var d = i % 6;
+ var j = (i - d) / 6;
+ j = j % 4;
+ j++;
+ var color_case = new Array(
+ new Array(1, 0, 0),
+ new Array(0, 1, 0),
+ new Array(0, 0, 1),
+ new Array(1, 1, 0),
+ new Array(1, 0, 1),
+ new Array(0, 1, 1)
+ );
+ var a = color_case[d][0];
+ var b = color_case[d][1];
+ var c = color_case[d][2];
+ var e = (1 - (j - 1) / 6);
+
+ var r = Math.round(a * 200 * e);
+ var g = Math.round(b * 200 * e);
+ var b = Math.round(c * 200 * e);
+ var color = "rgba("+r+","+g+","+b+",1)";
+
+ TargetColors.push( new Array(target, color) );
+
+
+ }
+
+ return color;
+}
+
+function Click_option(id_this,column_name,table_name)
+{
+ var left = Glob_X - (document.getElementById(id_this).offsetWidth>>1);
+ document.getElementById(id_this).style.left = left + 'px';
+ // var top = Glob_Y - document.getElementById(id_this).offsetHeight - 10;
+ document.getElementById(id_this).style.top = (screen.height / 4) + 'px';
+ document.getElementById(id_this).style.display = 'block';
+ document.getElementById('option_col_name').innerHTML = '<strong>' + PMA_messages['strAddOption'] +'"' +column_name+ '"</strong>';
+ col_name = column_name;
+ tab_name = table_name;
+}
+
+function Close_option()
+{
+ document.getElementById('pmd_optionse').style.display = 'none';
+}
+
+function Select_all(id_this,owner)
+{
+ var parent= document.form1;
+ downer =owner;
+ var i;
+ var k;
+ var tab = [];
+ for (i = 0; i < parent.elements.length; i++) {
+ if (parent.elements[i].type == "checkbox" && parent.elements[i].id.substring(0,(9 + id_this.length)) == 'select_' + id_this + '._') {
+ if(document.getElementById('select_all_' + id_this).checked == true) {
+ parent.elements[i].checked = true;
+ parent.elements[i].disabled = true;
+ var temp = '`' + id_this.substring(owner.length +1) + '`.*';
+ }
+ else {
+ parent.elements[i].checked = false;
+ parent.elements[i].disabled = false;
+ }
+ }
+ }
+ if (document.getElementById('select_all_' + id_this).checked == true) {
+ select_field.push('`' + id_this.substring(owner.length +1) + '`.*');
+ tab = id_this.split(".");
+ from_array.push(tab[1]);
+ }
+ else {
+ for (i =0; i < select_field.length; i++) {
+ if (select_field[i] == ('`' + id_this.substring(owner.length +1) + '`.*')) {
+ select_field.splice(i,1);
+ }
+ }
+ for (k =0 ;k < from_array.length; k++){
+ if (from_array[k] == id_this){
+ from_array.splice(k,1);
+ break;
+ }
+ }
+ }
+ Re_load();
+}
+
+function Table_onover(id_this,val,buil)
+{
+ if(!val) {
+ document.getElementById("id_zag_" + id_this).className="tab_zag_2";
+ if(buil) {
+ document.getElementById("id_zag_" + id_this + "_2").className="tab_zag_2";
+ }
+ }
+ else {
+ document.getElementById("id_zag_" + id_this).className="tab_zag";
+ if(buil) {
+ document.getElementById("id_zag_" + id_this + "_2").className="tab_zag";
+ }
+ }
+}
+
+/* This function stores selected column information in select_field[]
+ * In case column is checked it add else it deletes
+ *
+ */
+function store_column(id_this,owner,col)
+{
+ var i;
+ var k;
+ if (document.getElementById('select_' + owner + '.' + id_this + '._' + col).checked == true) {
+ select_field.push('`' + id_this + '`.`' + col +'`');
+ from_array.push(id_this);
+ }
+ else {
+ for (i = 0; i < select_field.length ;i++) {
+ if (select_field[i] == ('`' + id_this + '`.`' + col +'`')) {
+ select_field.splice(i,1);
+ break;
+ }
+ }
+ for (k = 0 ;k < from_array.length;k++){
+ if(from_array[k] == id_this){
+ from_array.splice(k,1);
+ break;
+ }
+ }
+ }
+}
+
+/**
+ * This function builds object and adds them to history_array
+ * first it does a few checks on each object, then makes an object(where,rename,groupby,aggregate,orderby)
+ * then a new history object is made and finally all these history objects are addded to history_array[]
+ *
+**/
+
+function add_object()
+{
+ var rel = document.getElementById('rel_opt');
+ var sum = 0;
+ var init = history_array.length;
+ if (rel.value != '--') {
+ if (document.getElementById('Query').value == "") {
+ document.getElementById('pmd_hint').innerHTML = "value/subQuery is empty" ;
+ document.getElementById('pmd_hint').style.display = 'block';
+ return;
+ }
+ var p = document.getElementById('Query');
+ var where_obj = new where(rel.value,p.value);//make where object
+ history_array.push(new history(col_name,where_obj,tab_name,h_tabs[downer + '.' + tab_name],"Where"));
+ sum = sum + 1;
+ rel.value = '--';
+ p.value = "";
+ }
+ if (document.getElementById('new_name').value !="") {
+ var rename_obj = new rename(document.getElementById('new_name').value);//make Rename object
+ history_array.push(new history(col_name,rename_obj,tab_name,h_tabs[downer + '.' + tab_name],"Rename"));
+ sum = sum + 1;
+ document.getElementById('new_name').value = "" ;
+ }
+ if (document.getElementById('operator').value != '---') {
+ var aggregate_obj = new aggregate(document.getElementById('operator').value) ;
+ history_array.push(new history(col_name,aggregate_obj,tab_name,h_tabs[downer + '.' + tab_name],"Aggregate"));
+ sum = sum + 1;
+ document.getElementById('operator').value = '---';
+ //make aggregate operator
+ }
+ if (document.getElementById('groupby').checked == true ) {
+ history_array.push(new history(col_name,'GroupBy',tab_name,h_tabs[downer + '.' +tab_name],"GroupBy"));
+ sum = sum + 1;
+ document.getElementById('groupby').checked = false;
+ //make groupby
+ }
+ if (document.getElementById('h_rel_opt').value != '--') {
+ if (document.getElementById('having').value == "") {
+ document.getElementById('pmd_hint').innerHTML = "value/subQuery is empty" ;
+ document.getElementById('pmd_hint').style.display = 'block';
+ return;
+ }
+ var p = document.getElementById('having');
+ var where_obj = new having(document.getElementById('h_rel_opt').value,p.value,document.getElementById('h_operator').value);//make where object
+ history_array.push(new history(col_name,where_obj,tab_name,h_tabs[downer + '.' + tab_name],"Having"));
+ sum = sum + 1;
+ document.getElementById('h_rel_opt').value = '--';
+ document.getElementById('h_operator').value = '---';
+ p.value = ""; //make having
+ }
+ if (document.getElementById('orderby').checked == true) {
+ history_array.push(new history(col_name,'OrderBy',tab_name,h_tabs[downer + '.' + tab_name],"OrderBy"));
+ sum = sum + 1;
+ document.getElementById('orderby').checked = false;
+ //make orderby
+ }
+ PMA_ajaxShowMessage($.sprintf(PMA_messages['strObjectsCreated'], sum));
+ //output sum new objects created
+ var existingDiv = document.getElementById('ab');
+ existingDiv.innerHTML = display(init,history_array.length);
+ Close_option();
+ panel(0);
+}