Translation update done using Pootle.
[phpmyadmin/sankalp_k.git] / pmd / scripts / move.js
blobb2f99ee431064a18a593bdb5a7b6286f996caf2c
1 /* vim: set expandtab sw=4 ts=4 sts=4: */
2 /**
3 * @package phpMyAdmin-Designer
4 */
6 /**
7 * init
8 */
9 var dx, dy, dy2;
10 var cur_click;
11 // update in Main()
12 var sm_x = 2, sm_y = 2;
13 var sm_s = 0;
14 var sm_add = 10;
15 var s_left = 0;
16 var s_right = 0;
17 var ON_relation = 0;
18 var ON_grid = 0;
19 var ON_display_field = 0;
20 // relation_style: 0 - angular 1 - direct
21 var ON_angular_direct = 1;
22 var click_field = 0;
23 var link_relation = "";
24 var id_hint;
25 var canvas_width = 0;
26 var canvas_height = 0;
27 var osn_tab_width = 0;
28 var osn_tab_height = 0;
29 var height_field = 7;
30 var Glob_X, Glob_Y;
31 var timeoutID;
32 var layer_menu_cur_click = 0;
33 var step = 10;
34 var old_class;
35 var from_array = [];
36 var downer;
38 //------------------------------------------------------------------------------
39 //------------------------------------------------------------------------------
40 //------------------------------------------------------------------------------
43 //window.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP);
44 //---CROSS
45 document.onmousedown = MouseDown;
46 document.onmouseup = MouseUp;
47 document.onmousemove = MouseMove;
49 var isIE = document.all && !window.opera;
50 var isNN = !document.all && document.getElementById;
51 var isN4 = document.layers;
53 if (isIE) {
54 window.onscroll = General_scroll;
55 document.onselectstart = function () {return false;};
58 //document.onmouseup = function(){General_scroll_end();}
59 function MouseDown(e)
61 var offsetx, offsety;
62 if (cur_click != null) {
63 offsetx = isIE ? event.clientX + document.body.scrollLeft : e.pageX;
64 offsety = isIE ? event.clientY + document.body.scrollTop : e.pageY;
65 dx = offsetx - parseInt(cur_click.style.left);
66 dy = offsety - parseInt(cur_click.style.top);
67 //alert(" dx = " + dx + " dy = " +dy);
68 document.getElementById("canvas").style.visibility = 'hidden';
70 var left = parseInt(cur_click.style.left);
71 var top = parseInt(cur_click.style.top);
72 dx = e.pageX - left;
73 dy = e.pageY - top;
75 alert(" dx = " + dx + " dy = " +dy);
77 cur_click.style.zIndex = 2;
79 if (layer_menu_cur_click) {
80 offsetx = isIE ? event.clientX + document.body.scrollLeft : e.pageX;
81 dx = offsetx - parseInt(document.getElementById("layer_menu").style.width);
85 function MouseMove(e)
87 //Glob_X = e.pageX;
88 //Glob_Y = e.pageY;
89 Glob_X = isIE ? event.clientX + document.body.scrollLeft : e.pageX;
90 Glob_Y = isIE ? event.clientY + document.body.scrollTop : e.pageY;
92 //mouseX = (bw.ns4||bw.ns6)? e.pageX: bw.ie&&bw.win&&!bw.ie4? (event.clientX-2)+document.body.scrollLeft : event.clientX+document.body.scrollLeft;
93 //mouseY = (bw.ns4||bw.ns6)? e.pageY: bw.ie&&bw.win&&!bw.ie4? (event.clientY-2)+document.body.scrollTop : event.clientY+document.body.scrollTop;
95 //window.status = "X = "+ Glob_X + " Y = "+ Glob_Y;
97 if (cur_click != null) {
98 var mGx = Glob_X - dx;
99 var mGy = Glob_Y - dy;
100 mGx = mGx > 0 ? mGx : 0;
101 mGy = mGy > 0 ? mGy : 0;
103 if (ON_grid) {
104 mGx = mGx % step < step / 2 ? mGx - mGx % step : mGx - mGx % step + step;
105 mGy = mGy % step < step / 2 ? mGy - mGy % step : mGy - mGy % step + step;
108 cur_click.style.left = mGx + 'px';
109 cur_click.style.top = mGy + 'px';
112 if (ON_relation || ON_display_field) {
113 document.getElementById('hint').style.left = (Glob_X + 20) + 'px';
114 document.getElementById('hint').style.top = (Glob_Y + 20) + 'px';
117 if (layer_menu_cur_click) {
118 document.getElementById("layer_menu").style.width = ((Glob_X - dx) >= 150 ? Glob_X - dx : 150) + 'px';
119 //document.getElementById("layer_menu").style.height = Glob_Y - dy>=200?Glob_Y - dy:200;
120 //document.getElementById("id_scroll_tab").style.height = Glob_Y - dy2;
124 function MouseUp(e)
126 if (cur_click != null) {
127 document.getElementById("canvas").style.visibility = 'visible';
128 Re_load();
129 cur_click.style.zIndex = 1;
130 cur_click = null;
132 layer_menu_cur_click = 0;
133 //window.releaseEvents(Event.MOUSEMOVE);
135 //------------------------------------------------------------------------------
136 //------------------------------------------------------------------------------
137 //------------------------------------------------------------------------------
140 //function ToInt(s)
142 // return s.substring(0,s.length-2)*1; //re = /(\d+)\w*/; newstr = str.replace(re, "$1");
145 function Canvas_pos()
147 canvas_width = document.getElementById('canvas').width = osn_tab_width - 3;
148 canvas_height = document.getElementById('canvas').height = osn_tab_height - 3;
150 if (isIE) {
151 document.getElementById('canvas').style.width = ((osn_tab_width - 3)?(osn_tab_width - 3):0) + 'px';
152 document.getElementById('canvas').style.height = ((osn_tab_height - 3)?(osn_tab_height - 3):0) + 'px';
156 function Osn_tab_pos()
158 osn_tab_width = parseInt(document.getElementById('osn_tab').style.width);
159 osn_tab_height = parseInt(document.getElementById('osn_tab').style.height);
163 function Main()
165 //alert( document.getElementById('osn_tab').offsetTop);
166 //---CROSS
167 if (isIE) {
168 document.getElementById('top_menu').style.position = 'absolute';
169 document.getElementById('layer_menu').style.position = 'absolute';
172 document.getElementById("layer_menu").style.top = -1000 + 'px'; //fast scroll
173 sm_x += document.getElementById('osn_tab').offsetLeft;
174 sm_y += document.getElementById('osn_tab').offsetTop;
175 Osn_tab_pos();
176 Canvas_pos();
177 Small_tab_refresh();
178 Re_load();
179 id_hint = document.getElementById('hint');
180 if (isIE) {
181 General_scroll();
186 //-------------------------------- new -----------------------------------------
187 function Rezize_osn_tab()
189 var max_X = 0;
190 var max_Y = 0;
191 for (key in j_tabs) {
192 var k_x = parseInt(document.getElementById(key).style.left) + document.getElementById(key).offsetWidth;
193 var k_y = parseInt(document.getElementById(key).style.top) + document.getElementById(key).offsetHeight;
194 max_X = max_X < k_x ? k_x : max_X;
195 max_Y = max_Y < k_y ? k_y : max_Y;
198 osn_tab_width = max_X + 50;
199 osn_tab_height = max_Y + 50;
200 Canvas_pos();
201 document.getElementById('osn_tab').style.width = osn_tab_width + 'px';
202 document.getElementById('osn_tab').style.height = osn_tab_height + 'px';
204 //------------------------------------------------------------------------------
207 * refreshes display, must be called after state changes
209 function Re_load()
211 Rezize_osn_tab();
212 var n;
213 var x1;
214 var x2;
215 var a = new Array();
216 Clear();
217 for (K in contr)
218 for (key in contr[K]) // contr name
219 for (key2 in contr[K][key]) // table name
220 for (key3 in contr[K][key][key2]) // field name
222 if (!document.getElementById("check_vis_" + key2).checked ||
223 !document.getElementById("check_vis_" + contr[K][key][key2][key3][0]).checked) {
224 // if hide
225 continue;
227 var x1_left = document.getElementById(key2).offsetLeft+1;
228 var x1_right = x1_left + document.getElementById(key2).offsetWidth;
229 var x2_left = document.getElementById(contr[K][key][key2][key3][0]).offsetLeft;
230 var x2_right = x2_left + document.getElementById(contr[K][key][key2][key3][0]).offsetWidth;
231 a[0] = Math.abs(x1_left - x2_left);
232 a[1] = Math.abs(x1_left - x2_right);
233 a[2] = Math.abs(x1_right - x2_left);
234 a[3] = Math.abs(x1_right - x2_right);
235 n = s_left = s_right = 0;
236 for (var i = 1; i < 4; i++) {
237 if (a[n] > a[i]) {
238 n = i;
241 if (n == 1) {
242 x1 = x1_left - sm_s;
243 x2 = x2_right + sm_s;
244 if (x1 < x2) {
245 n = 0;
248 if (n == 2) {
249 x1 = x1_right + sm_s;
250 x2 = x2_left - sm_s;
251 if (x1 > x2) {
252 n = 0;
255 if (n == 3) {
256 x1 = x1_right + sm_s;
257 x2 = x2_right + sm_s;
258 s_right = 1;
260 if (n == 0) {
261 x1 = x1_left - sm_s;
262 x2 = x2_left - sm_s;
263 s_left = 1;
265 //alert(key2 + "." + key3);
267 var row_offset_top = 0;
268 //alert('id_tbody_' + key2);
269 //alert(document.getElementById('id_hide_tbody_' + key2));
270 var tab_hide_button = document.getElementById('id_hide_tbody_' + key2);
272 //alert(tab_hide_button.innerHTML);
273 if (tab_hide_button.innerHTML == 'v') {
274 row_offset_top = document.getElementById(key2 + "." + key3).offsetTop;
277 var y1 = document.getElementById(key2).offsetTop
278 + row_offset_top
279 + height_field;
280 //alert(1);
282 row_offset_top = 0;
283 var tab_hide_button = document.getElementById('id_hide_tbody_' + contr[K][key][key2][key3][0]);
284 if (tab_hide_button.innerHTML == 'v') {
285 row_offset_top = document.getElementById(contr[K][key][key2][key3][0]
286 + '.' + contr[K][key][key2][key3][1]).offsetTop;
289 var y2 =
290 document.getElementById(contr[K][key][key2][key3][0]).offsetTop
291 + row_offset_top
292 + height_field;
294 //alert(y1 + ' - ' + key2 + "." + key3);
295 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] ) );
300 * draws a line from x1:y1 to x2:y2 with color
302 function Line(x1, y1, x2, y2, color_line)
304 var canvas = document.getElementById("canvas");
305 var ctx = canvas.getContext("2d");
306 ctx.strokeStyle = color_line;
307 ctx.lineWidth = 1;
308 ctx.beginPath();
309 ctx.moveTo(x1, y1);
310 ctx.lineTo(x2, y2);
311 ctx.stroke();
315 * draws a relation/constraint line, whether angular or not
317 function Line0(x1, y1, x2, y2, color_line)
319 Circle(x1, y1, 3, 3, color_line);
320 Rect(x2 - 1, y2 - 2, 4, 4, color_line);
322 if (ON_angular_direct) {
323 Line2(x1, y1, x2, y2, color_line);
324 } else {
325 Line3(x1, y1, x2, y2, color_line);
330 * draws a angualr relation/constraint line
332 function Line2(x1, y1, x2, y2, color_line)
334 var x1_ = x1;
335 var x2_ = x2;
337 if (s_right) {
338 x1_ += sm_add;
339 x2_ += sm_add;
340 } else if (s_left) {
341 x1_ -= sm_add;
342 x2_ -= sm_add;
343 } else if (x1 < x2) {
344 x1_ += sm_add;
345 x2_ -= sm_add;
346 } else {
347 x1_ -= sm_add;
348 x2_ += sm_add;
351 Line(x1, y1, x1_, y1, color_line);
352 Line(x2, y2, x2_, y2, color_line);
353 Line(x1_, y1, x2_, y2, color_line);
357 * draws a relation/constraint line
359 function Line3(x1, y1, x2, y2, color_line)
361 var x1_ = x1;
362 var x2_ = x2;
364 if (s_right) {
365 if (x1 < x2) {
366 x1_ += x2 - x1 + sm_add;
367 x2_ += sm_add;
368 } else {
369 x2_ += x1 - x2 + sm_add;
370 x1_ += sm_add;
373 Line(x1, y1, x1_, y1, color_line);
374 Line(x2, y2, x2_, y2, color_line);
375 Line(x1_, y1, x2_, y2, color_line);
376 return;
378 if (s_left) {
379 if (x1 < x2) {
380 x2_ -= x2 - x1 + sm_add;
381 x1_ -= sm_add;
382 } else {
383 x1_ -= x1 - x2 + sm_add;
384 x2_ -= sm_add;
387 Line(x1, y1, x1_, y1, color_line);
388 Line(x2, y2, x2_, y2, color_line);
389 Line(x1_, y1, x2_, y2, color_line);
390 return;
393 var x_s = (x1 + x2) / 2;
394 Line(x1, y1, x_s, y1, color_line);
395 Line(x_s, y2, x2, y2, color_line);
396 Line(x_s, y1, x_s, y2, color_line);
399 function Circle(x, y, r, w, color)
401 var ctx = document.getElementById('canvas').getContext('2d');
402 ctx.beginPath();
403 ctx.moveTo(x, y);
404 ctx.lineWidth = w;
405 ctx.strokeStyle = color;
406 ctx.arc(x, y, r, 0, 2 * Math.PI, true);
407 ctx.stroke();
410 function Clear()
412 var canvas = document.getElementById("canvas");
413 var ctx = canvas.getContext("2d");
414 ctx.clearRect(0, 0, canvas_width, canvas_height);
417 function Rect(x1, y1, w, h, color)
419 var ctx = document.getElementById('canvas').getContext('2d');
420 ctx.fillStyle = color;
421 ctx.fillRect(x1, y1, w, h);
424 //------------------------------ SAVE ------------------------------------------
425 function Save(url) // (del?) no for pdf
427 for (key in j_tabs) {
428 document.getElementById('t_x_' + key + '_').value = parseInt(document.getElementById(key).style.left);
429 document.getElementById('t_y_' + key + '_').value = parseInt(document.getElementById(key).style.top);
430 document.getElementById('t_v_' + key + '_').value = document.getElementById('id_tbody_' + key).style.display == 'none' ? 0 : 1;
431 document.getElementById('t_h_' + key + '_').value = document.getElementById('check_vis_' + key).checked ? 1 : 0;
433 document.form1.action = url;
434 document.form1.submit();
437 function Get_url_pos()
439 var poststr = '';
440 for (key in j_tabs) {
441 poststr += '&t_x[' + key + ']=' + parseInt(document.getElementById(key).style.left);
442 poststr += '&t_y[' + key + ']=' + parseInt(document.getElementById(key).style.top);
443 poststr += '&t_v[' + key + ']=' + (document.getElementById('id_tbody_' + key).style.display == 'none' ? 0 : 1);
444 poststr += '&t_h[' + key + ']=' + (document.getElementById('check_vis_' + key).checked ? 1 : 0);
446 return poststr;
449 function Save2()
451 var poststr = 'IS_AJAX=1&server='+server+'&db=' + db + '&token=' + token + '&die_save_pos=1';
452 poststr += Get_url_pos();
453 makeRequest('pmd_save_pos.php', poststr);
456 function Grid()
458 if (!ON_grid) {
459 ON_grid = 1;
460 document.getElementById('grid_button').className = 'M_butt_Selected_down';
461 } else {
462 document.getElementById('grid_button').className = 'M_butt';
463 ON_grid = 0;
467 function Angular_direct()
469 if (ON_angular_direct) {
470 ON_angular_direct = 0;
471 document.getElementById('angular_direct_button').className = 'M_butt_Selected_down';
472 } else {
473 ON_angular_direct = 1;
474 document.getElementById('angular_direct_button').className = 'M_butt';
476 Re_load();
478 //++++++++++++++++++++++++++++++ RELATION ++++++++++++++++++++++++++++++++++++++
479 function Start_relation()
481 if (ON_display_field) {
482 return;
485 if (!ON_relation) {
486 document.getElementById('foreign_relation').style.display = '';
487 ON_relation = 1;
488 document.getElementById('hint').innerHTML = PMA_messages['strSelectReferencedKey'];
489 document.getElementById('hint').style.visibility = "visible";
490 document.getElementById('rel_button').className = 'M_butt_Selected_down';
491 } else {
492 document.getElementById('hint').innerHTML = "";
493 document.getElementById('hint').style.visibility = "hidden";
494 document.getElementById('rel_button').className = 'M_butt';
495 click_field = 0;
496 ON_relation = 0;
500 function Click_field(T, f, PK) // table field
502 if (ON_relation) {
503 if (!click_field) {
504 //.style.display=='none' .style.visibility = "hidden"
505 if (!PK) {
506 alert(PMA_messages['strPleaseSelectPrimaryOrUniqueKey']);
507 return;// 0;
508 }//PK
509 if (j_tabs[db + '.' + T] != '1') {
510 document.getElementById('foreign_relation').style.display = 'none';
512 click_field = 1;
513 link_relation = "T1=" + T + "&F1=" + f;
514 document.getElementById('hint').innerHTML = PMA_messages['strSelectForeignKey'];
515 } else {
516 Start_relation(); // hidden hint...
517 if (j_tabs[db + '.' + T] != '1' || !PK) {
518 document.getElementById('foreign_relation').style.display = 'none';
520 var left = Glob_X - (document.getElementById('layer_new_relation').offsetWidth>>1);
521 document.getElementById('layer_new_relation').style.left = left + 'px';
522 var top = Glob_Y - document.getElementById('layer_new_relation').offsetHeight + 40;
523 document.getElementById('layer_new_relation').style.top = top + 'px';
524 document.getElementById('layer_new_relation').style.visibility = "visible";
525 link_relation += '&T2=' + T + '&F2=' + f;
529 if (ON_display_field) {
530 // if is display field
531 if (display_field[T] == f) {
532 //alert(T);
533 //s = '';for(k in display_field)s += k + ' = ' + display_field[k] + ',';alert(s);
534 old_class = 'tab_field';
535 //display_field.splice(T, 1);
536 delete display_field[T];
537 //s = '';for(k in display_field)s += k + ' = ' + display_field[k] + ', ';alert(s);
538 //n = 0;for(k in display_field)n++;alert(n);
539 } else {
540 old_class = 'tab_field_3';
541 if (display_field[T]) {
542 document.getElementById('id_tr_' + T + '.' + display_field[T]).className = 'tab_field';
543 //display_field.splice(T, 1);
544 delete display_field[T];
546 display_field[T] = f;
548 ON_display_field = 0;
549 document.getElementById('hint').innerHTML = "";
550 document.getElementById('hint').style.visibility = "hidden";
551 document.getElementById('display_field_button').className = 'M_butt';
552 makeRequest('pmd_display_field.php', 'T=' + T + '&F=' + f + '&server=' + server + '&db=' + db + '&token=' + token);
556 function New_relation()
558 document.getElementById('layer_new_relation').style.visibility = 'hidden';
559 link_relation += '&server=' + server + '&db=' + db + '&token=' + token + '&die_save_pos=0';
560 link_relation += '&on_delete=' + document.getElementById('on_delete').value + '&on_update=' + document.getElementById('on_update').value;
561 link_relation += Get_url_pos();
563 //alert(link_relation);
564 makeRequest('pmd_relation_new.php', link_relation);
567 //-------------------------- create tables -------------------------------------
569 function Start_table_new()
571 window.location.href = 'tbl_create.php?server=' + server + '&db=' + db + '&token=' + token;
574 function Start_tab_upd(table)
576 window.location.href = 'tbl_structure.php?server=' + server + '&db=' + db + '&token=' + token + '&table=' + table;
578 //--------------------------- hide tables --------------------------------------
580 function Small_tab_all(id_this) // max/min all tables
582 if (id_this.alt == "v") {
583 for (key in j_tabs) {
584 if (document.getElementById('id_hide_tbody_'+key).innerHTML == "v") {
585 Small_tab(key, 0);
588 id_this.alt = ">";
589 id_this.src = "pmd/images/rightarrow1.png";
590 } else {
591 for (key in j_tabs) {
592 if (document.getElementById('id_hide_tbody_'+key).innerHTML != "v") {
593 Small_tab(key, 0);
596 id_this.alt = "v";
597 id_this.src = "pmd/images/downarrow1.png";
599 Re_load();
602 function Small_tab_invert() // invert max/min all tables
604 for (key in j_tabs) {
605 Small_tab(key, 0);
607 Re_load();
610 function Small_tab_refresh()
612 for (key in j_tabs) {
613 if(document.getElementById('id_hide_tbody_'+key).innerHTML != "v") {
614 Small_tab(key, 0);
615 Small_tab(key, 0);
620 function Small_tab(t, re_load)
622 var id = document.getElementById('id_tbody_' + t);
623 var id_this = document.getElementById('id_hide_tbody_' + t);
624 var id_t = document.getElementById(t);
625 id_t.style.width = id_t.offsetWidth + 'px';
626 if (id_this.innerHTML == "v") {
627 //---CROSS
628 id.style.display = 'none';
629 id_this.innerHTML = '>';
630 } else {
631 id.style.display = '';
632 id_this.innerHTML = 'v';
634 if (re_load) {
635 Re_load();
638 //------------------------------------------------------------------------------
639 function Select_tab(t)
641 var id_zag = document.getElementById('id_zag_' + t);
642 if (id_zag.className != 'tab_zag_3') {
643 document.getElementById('id_zag_' + t).className = 'tab_zag_2';
644 } else {
645 document.getElementById('id_zag_' + t).className = 'tab_zag';
647 //----------
648 var id_t = document.getElementById(t);
649 window.scrollTo(parseInt(id_t.style.left) - 300, parseInt(id_t.style.top) - 300);
650 setTimeout(function(){document.getElementById('id_zag_' + t).className = 'tab_zag';}, 800);
652 //------------------------------------------------------------------------------
654 function Canvas_click(id)
656 var n = 0;
657 var relation_name = 0;
658 var selected = 0;
659 var a = new Array();
660 var Key0, Key1, Key2, Key3, Key, x1, x2;
661 Clear();
662 for (K in contr)
663 for (key in contr[K])
664 for (key2 in contr[K][key])
665 for (key3 in contr[K][key][key2]) {
666 if (!document.getElementById("check_vis_"+key2).checked ||
667 !document.getElementById("check_vis_"+contr[K][key][key2][key3][0]).checked) continue; // if hide
668 var x1_left = document.getElementById(key2).offsetLeft + 1;//document.getElementById(key2+"."+key3).offsetLeft;
669 var x1_right = x1_left + document.getElementById(key2).offsetWidth;
670 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
671 var x2_right = x2_left + document.getElementById(contr[K][key][key2][key3][0]).offsetWidth;
672 a[0] = Math.abs(x1_left - x2_left);
673 a[1] = Math.abs(x1_left - x2_right);
674 a[2] = Math.abs(x1_right - x2_left);
675 a[3] = Math.abs(x1_right - x2_right);
676 n = s_left = s_right = 0;
677 for (var i = 1; i < 4; i++) {
678 if (a[n] > a[i]) {
679 n = i;
682 if (n == 1) {
683 x1 = x1_left - sm_s;
684 x2 = x2_right + sm_s;
685 if (x1 < x2) {
686 n = 0;
689 if (n == 2) {
690 x1 = x1_right + sm_s;
691 x2 = x2_left - sm_s;
692 if (x1 > x2) {
693 n = 0;
696 if (n == 3) {
697 x1 = x1_right + sm_s;
698 x2 = x2_right + sm_s;
699 s_right = 1;
701 if (n == 0) {
702 x1 = x1_left - sm_s;
703 x2 = x2_left - sm_s;
704 s_left = 1;
707 var y1 = document.getElementById(key2).offsetTop + document.getElementById(key2+"."+key3).offsetTop + height_field;
708 var y2 = document.getElementById(contr[K][key][key2][key3][0]).offsetTop +
709 document.getElementById(contr[K][key][key2][key3][0]+"."+contr[K][key][key2][key3][1]).offsetTop + height_field;
710 if (!selected && Glob_X > x1 - 10 && Glob_X < x1 + 10 && Glob_Y > y1 - 7 && Glob_Y < y1 + 7) {
711 Line0(x1 - sm_x, y1 - sm_y, x2 - sm_x, y2 - sm_y, "rgba(255,0,0,1)");
712 selected = 1; // Rect(x1-sm_x,y1-sm_y,10,10,"rgba(0,255,0,1)");
713 relation_name = key; //
714 Key0 = contr[K][key][key2][key3][0];
715 Key1 = contr[K][key][key2][key3][1];
716 Key2 = key2; Key3 = key3;
717 Key = K;
718 } else {
719 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] ));
722 if (selected) {
723 // select relations
724 //alert(Key0+' - '+Key1+' - '+Key2+' - '+Key3);
725 var left = Glob_X - (document.getElementById('layer_upd_relation').offsetWidth>>1);
726 document.getElementById('layer_upd_relation').style.left = left + 'px';
727 var top = Glob_Y - document.getElementById('layer_upd_relation').offsetHeight - 10;
728 document.getElementById('layer_upd_relation').style.top = top + 'px';
729 document.getElementById('layer_upd_relation').style.visibility = 'visible';
730 link_relation = 'T1=' + Key0 + '&F1=' + Key1 + '&T2=' + Key2 + '&F2=' + Key3 + '&K=' + Key;
734 function Upd_relation()
736 document.getElementById('layer_upd_relation').style.visibility = 'hidden';
737 link_relation += '&server=' + server + '&db=' + db + '&token=' + token + '&die_save_pos=0';
738 link_relation += Get_url_pos();
739 makeRequest('pmd_relation_upd.php', link_relation);
742 function VisibleTab(id, t_n)
744 if (id.checked) {
745 document.getElementById(t_n).style.visibility = 'visible';
746 } else {
747 document.getElementById(t_n).style.visibility = 'hidden';
749 Re_load();
752 function Hide_tab_all(id_this) // max/min all tables
754 if (id_this.alt == 'v') {
755 id_this.alt = '>';
756 id_this.src = "pmd/images/rightarrow1.png";
757 } else {
758 id_this.alt = 'v';
759 id_this.src = "pmd/images/downarrow1.png";
761 var E = document.form1;
762 for (i = 0; i < E.elements.length; i++) {
763 if (E.elements[i].type == "checkbox" && E.elements[i].id.substring(0, 10) == 'check_vis_') {
764 if (id_this.alt == 'v') {
765 E.elements[i].checked = true;
766 document.getElementById(E.elements[i].value).style.visibility = 'visible';
767 } else {
768 E.elements[i].checked = false;
769 document.getElementById(E.elements[i].value).style.visibility = 'hidden';
773 Re_load();
776 function in_array_k(x, m)
778 var b = 0;
779 for (u in m) {
780 if (x == u) {
781 b=1;
782 break;
785 return b;
788 function No_have_constr(id_this)
790 var a = new Array();
791 for (K in contr)
792 for (key in contr[K]) // contr name
793 for (key2 in contr[K][key]) // table name
794 for (key3 in contr[K][key][key2]) // field name
795 a[key2] = a[contr[K][key][key2][key3][0]] = 1; // exist constr
798 if (id_this.alt == 'v') {
799 id_this.alt = '>';
800 id_this.src = "pmd/images/rightarrow2.png";
801 } else {
802 id_this.alt = 'v';
803 id_this.src = "pmd/images/downarrow2.png";
805 var E = document.form1;
806 for (i = 0; i < E.elements.length; i++) {
807 if (E.elements[i].type == "checkbox" && E.elements[i].id.substring(0, 10) == 'check_vis_')
809 if (!in_array_k(E.elements[i].value, a))
810 if (id_this.alt == 'v') {
811 E.elements[i].checked = true;
812 document.getElementById(E.elements[i].value).style.visibility = 'visible';
813 } else {
814 E.elements[i].checked = false;
815 document.getElementById(E.elements[i].value).style.visibility = 'hidden';
821 function Help()
823 var WinHelp = window.open("pmd_help.php", "wind1", "top=200,left=400,width=300,height=200,resizable=yes,scrollbars=yes,menubar=no");
826 function PDF_save()
828 // var WinPDF =
829 // window.open("pmd_pdf.php?token="+token+"&db="+db,"wind1", "top=200,left=200,width=200,height=100,resizable=yes,scrollbars=yes,menubar=no");
830 Save('pmd_pdf.php?server=' + server + '&token=' + token + '&db=' + db);
833 function General_scroll()
836 if (!document.getElementById('show_relation_olways').checked) {
837 document.getElementById("canvas").style.visibility = 'hidden';
838 clearTimeout(timeoutID);
839 timeoutID = setTimeout(General_scroll_end, 500);
842 //if (timeoutID)
843 clearTimeout(timeoutID);
844 timeoutID = setTimeout
846 function()
848 document.getElementById('top_menu').style.left = document.body.scrollLeft + 'px';
849 document.getElementById('top_menu').style.top = document.body.scrollTop + 'px';
850 document.getElementById('layer_menu').style.left = document.body.scrollLeft + 'px';
851 document.getElementById('layer_menu').style.top = (document.body.scrollTop + document.getElementById('top_menu').offsetHeight) + 'px';
853 ,200
858 function General_scroll_end()
860 document.getElementById('layer_menu').style.left = document.body.scrollLeft;
861 document.getElementById('layer_menu').style.top = document.body.scrollTop + document.getElementById('top_menu').offsetHeight;
862 if (isIE) {
863 document.getElementById('layer_menu').style.left = document.body.scrollLeft;
864 document.getElementById('layer_menu').style.top = document.body.scrollTop + document.getElementById('top_menu').offsetHeight;
866 document.getElementById("canvas").style.visibility = 'visible';
870 function Show_left_menu(id_this) // max/min all tables
872 if (id_this.alt == "v") {
873 document.getElementById("layer_menu").style.top = document.getElementById('top_menu').offsetHeight + 'px';
874 document.getElementById("layer_menu").style.visibility = 'visible';
875 id_this.alt = ">";
876 id_this.src = "pmd/images/uparrow2_m.png";
877 if (isIE) {
878 General_scroll();
880 } else {
881 document.getElementById("layer_menu").style.top = -1000 + 'px'; //fast scroll
882 document.getElementById("layer_menu").style.visibility = 'hidden';
883 id_this.alt = "v";
884 id_this.src = "pmd/images/downarrow2_m.png";
887 //------------------------------------------------------------------------------
888 function Top_menu_right(id_this)
890 if (id_this.alt == ">") {
891 document.getElementById('top_menu').style.marginLeft = document.getElementById('top_menu').offsetWidth + 'px'; // = 350
892 id_this.alt = "<";
893 id_this.src = "pmd/images/2leftarrow_m.png";
894 } else {
895 document.getElementById('top_menu').style.marginLeft = 0;
896 id_this.alt = ">";
897 id_this.src = "pmd/images/2rightarrow_m.png";
900 //------------------------------------------------------------------------------
901 function Start_display_field()
903 if (ON_relation) {
904 return;
906 if (!ON_display_field) {
907 ON_display_field = 1;
908 document.getElementById('hint').innerHTML = PMA_messages['strChangeDisplay'];
909 document.getElementById('hint').style.visibility = "visible";
910 document.getElementById('display_field_button').className = 'M_butt_Selected_down';//'#FFEE99';gray #AAAAAA
912 if (isIE) { // correct for IE
913 document.getElementById('display_field_button').className = 'M_butt_Selected_down_IE';
915 } else {
916 document.getElementById('hint').innerHTML = "";
917 document.getElementById('hint').style.visibility = "hidden";
918 document.getElementById('display_field_button').className = 'M_butt';
919 ON_display_field = 0;
922 //------------------------------------------------------------------------------
923 var TargetColors = new Array();
924 function getColorByTarget( target )
926 var color = ''; //"rgba(0,100,150,1)";
928 for (i in TargetColors)
929 if (TargetColors[i][0]==target) {
930 color = TargetColors[i][1];
931 break;
935 if (color.length==0)
937 var i = TargetColors.length+1;
938 var d = i % 6;
939 var j = (i - d) / 6;
940 j = j % 4;
941 j++;
942 var color_case = new Array(
943 new Array(1, 0, 0),
944 new Array(0, 1, 0),
945 new Array(0, 0, 1),
946 new Array(1, 1, 0),
947 new Array(1, 0, 1),
948 new Array(0, 1, 1)
950 var a = color_case[d][0];
951 var b = color_case[d][1];
952 var c = color_case[d][2];
953 e = (1 - (j - 1) / 6);
955 var r = Math.round(a * 200 * e);
956 var g = Math.round(b * 200 * e);
957 var b = Math.round(c * 200 * e);
958 var color = "rgba("+r+","+g+","+b+",1)";
960 TargetColors.push( new Array(target, color) );
965 return color;
968 function Click_option(id_this,column_name,table_name)
970 var left = Glob_X - (document.getElementById(id_this).offsetWidth>>1);
971 document.getElementById(id_this).style.left = left + 'px';
972 // var top = Glob_Y - document.getElementById(id_this).offsetHeight - 10;
973 document.getElementById(id_this).style.top = (screen.height / 4) + 'px';
974 document.getElementById(id_this).style.visibility = "visible";
975 document.getElementById('option_col_name').innerHTML = '<strong>' + PMA_messages['strAddOption'] +'"' +column_name+ '"</strong>';
976 col_name = column_name;
977 tab_name = table_name;
980 function Close_option()
982 document.getElementById('pmd_optionse').style.visibility = "hidden";
985 function Select_all(id_this,owner)
987 var parent= document.form1;
988 downer =owner;
989 var i;
990 var tab = [];
991 for(i = 0; i < parent.elements.length; i++) {
992 if (parent.elements[i].type == "checkbox" && parent.elements[i].id.substring(0,(9 + id_this.length)) == 'select_' + id_this + '._') {
993 if(document.getElementById('select_all_' + id_this).checked == true) {
994 parent.elements[i].checked = true;
995 parent.elements[i].disabled = true;
996 var temp = '`' + id_this.substring(owner.length +1) + '`.*';
998 else {
999 parent.elements[i].checked = false;
1000 parent.elements[i].disabled = false;
1004 if(document.getElementById('select_all_' + id_this).checked == true) {
1005 select_field.push('`' + id_this.substring(owner.length +1) + '`.*');
1006 tab = id_this.split(".");
1007 from_array.push(tab[1]);
1009 else {
1010 for (i =0; i < select_field.length; i++) {
1011 if (select_field[i] == ('`' + id_this.substring(owner.length +1) + '`.*')) {
1012 select_field.splice(i,1);
1015 for(k =0 ;k < from_array.length;k++){
1016 if(from_array[k] == id_this){
1017 from_array.splice(k,1);
1018 break;
1022 Re_load();
1025 function Table_onover(id_this,val,buil)
1027 if(!val) {
1028 document.getElementById("id_zag_" + id_this).className="tab_zag_2";
1029 if(buil) {
1030 document.getElementById("id_zag_" + id_this + "_2").className="tab_zag_2";
1033 else {
1034 document.getElementById("id_zag_" + id_this).className="tab_zag";
1035 if(buil) {
1036 document.getElementById("id_zag_" + id_this + "_2").className="tab_zag";
1041 /* This function stores selected column information in select_field[]
1042 * In case column is checked it add else it deletes
1045 function store_column(id_this,owner,col) {
1046 var i = 0;
1047 var k = 0;
1048 if (document.getElementById('select_' + owner + '.' + id_this + '._' + col).checked == true) {
1049 select_field.push('`' + id_this + '`.`' + col +'`');
1050 from_array.push(id_this);
1052 else {
1053 for(i; i < select_field.length ;i++) {
1054 if (select_field[i] == ('`' + id_this + '`.`' + col +'`')) {
1055 select_field.splice(i,1);
1056 break;
1059 for(k =0 ;k < from_array.length;k++){
1060 if(from_array[k] == id_this){
1061 from_array.splice(k,1);
1062 break;
1069 * This function builds object and adds them to history_array
1070 * first it does a few checks on each object, then makes an object(where,rename,groupby,aggregate,orderby)
1071 * then a new history object is made and finally all these history objects are addded to history_array[]
1073 * @uses where()
1074 * @uses history()
1075 * @uses aggregate()
1076 * @uses rename()
1077 * @uses panel()
1078 * @uses display()
1081 function add_object() {
1082 var rel = document.getElementById('rel_opt');
1083 var sum = 0;
1084 var init = history_array.length;
1085 if (rel.value != '--') {
1086 if (document.getElementById('Query').value == "") {
1087 document.getElementById('hint').innerHTML = "value/subQuery is empty" ;
1088 document.getElementById('hint').style.visibility = "visible";
1089 return;
1091 var p = document.getElementById('Query');
1092 var where_obj = new where(rel.value,p.value);//make where object
1093 history_array.push(new history(col_name,where_obj,tab_name,h_tabs[downer + '.' + tab_name],"Where"));
1094 sum = sum + 1;
1095 rel.value = '--';
1096 p.value = "";
1098 if (document.getElementById('new_name').value !="") {
1099 var rename_obj = new rename(document.getElementById('new_name').value);//make Rename object
1100 history_array.push(new history(col_name,rename_obj,tab_name,h_tabs[downer + '.' + tab_name],"Rename"));
1101 sum = sum + 1;
1102 document.getElementById('new_name').value = "" ;
1104 if (document.getElementById('operator').value != '---') {
1105 var aggregate_obj = new aggregate(document.getElementById('operator').value) ;
1106 history_array.push(new history(col_name,aggregate_obj,tab_name,h_tabs[downer + '.' + tab_name],"Aggregate"));
1107 sum = sum + 1;
1108 document.getElementById('operator').value = '---';
1109 //make aggregate operator
1111 if (document.getElementById('groupby').checked == true ) {
1112 history_array.push(new history(col_name,'GroupBy',tab_name,h_tabs[downer + '.' +tab_name],"GroupBy"));
1113 sum = sum + 1;
1114 document.getElementById('groupby').checked = false;
1115 //make groupby
1117 if (document.getElementById('h_rel_opt').value != '--') {
1118 if (document.getElementById('having').value == "") {
1119 document.getElementById('hint').innerHTML = "value/subQuery is empty" ;
1120 document.getElementById('hint').style.visibility = "visible";
1121 return;
1123 var p = document.getElementById('having');
1124 var where_obj = new having(document.getElementById('h_rel_opt').value,p.value,document.getElementById('h_operator').value);//make where object
1125 history_array.push(new history(col_name,where_obj,tab_name,h_tabs[downer + '.' + tab_name],"Having"));
1126 sum = sum + 1;
1127 document.getElementById('h_rel_opt').value = '--';
1128 document.getElementById('h_operator').value = '---';
1129 p.value = ""; //make having
1131 if (document.getElementById('orderby').checked == true) {
1132 history_array.push(new history(col_name,'OrderBy',tab_name,h_tabs[downer + '.' + tab_name],"OrderBy"));
1133 sum = sum + 1;
1134 document.getElementById('orderby').checked = false;
1135 //make orderby
1137 document.getElementById('hint').innerHTML = sum + "object created" ;
1138 document.getElementById('hint').style.visibility = "visible";
1139 //output sum new objects created
1140 var existingDiv = document.getElementById('ab');
1141 existingDiv.innerHTML = display(init,history_array.length);
1142 Close_option();
1143 panel(0);