5 * Displays an confirmation box beforme to submit a "DROP/DELETE/ALTER" query.
6 * This function is called while clicking links
8 * @param object the link
9 * @param object the sql query to submit
11 * @return boolean whether to run the query or not
13 function confirmLink(theLink, theSqlQuery)
15 // Confirmation is not required in the configuration file
16 // or browser is Opera (crappy js implementation)
17 if (confirmMsg == '' || typeof(window.opera) != 'undefined') {
21 var is_confirmed = confirm(confirmMsg + ' :\n' + theSqlQuery);
23 theLink.href += '&is_js_confirmed=1';
27 } // end of the 'confirmLink()' function
31 * Displays an error message if a "DROP DATABASE" statement is submitted
32 * while it isn't allowed, else confirms a "DROP/DELETE/ALTER" query before
33 * sumitting it if required.
34 * This function is called by the 'checkSqlQuery()' js function.
36 * @param object the form
37 * @param object the sql query textarea
39 * @return boolean whether to run the query or not
41 * @see checkSqlQuery()
43 function confirmQuery(theForm1, sqlQuery1)
45 // Confirmation is not required in the configuration file
46 if (confirmMsg == '') {
50 // The replace function (js1.2) isn't supported
51 else if (typeof(sqlQuery1.value.replace) == 'undefined') {
55 // js1.2+ -> validation with regular expressions
57 // "DROP DATABASE" statement isn't allowed
58 if (noDropDbMsg != '') {
59 var drop_re = new RegExp('DROP\\s+(IF EXISTS\\s+)?DATABASE\\s', 'i');
60 if (drop_re.test(sqlQuery1.value)) {
68 // Confirms a "DROP/DELETE/ALTER" statement
70 // TODO: find a way (if possible) to use the parser-analyser
71 // for this kind of verification
72 // For now, I just added a ^ to check for the statement at
73 // beginning of expression
75 //var do_confirm_re_0 = new RegExp('DROP\\s+(IF EXISTS\\s+)?(TABLE|DATABASE)\\s', 'i');
76 //var do_confirm_re_1 = new RegExp('ALTER\\s+TABLE\\s+((`[^`]+`)|([A-Za-z0-9_$]+))\\s+DROP\\s', 'i');
77 //var do_confirm_re_2 = new RegExp('DELETE\\s+FROM\\s', 'i');
78 var do_confirm_re_0 = new RegExp('^DROP\\s+(IF EXISTS\\s+)?(TABLE|DATABASE)\\s', 'i');
79 var do_confirm_re_1 = new RegExp('^ALTER\\s+TABLE\\s+((`[^`]+`)|([A-Za-z0-9_$]+))\\s+DROP\\s', 'i');
80 var do_confirm_re_2 = new RegExp('^DELETE\\s+FROM\\s', 'i');
81 if (do_confirm_re_0.test(sqlQuery1.value)
82 || do_confirm_re_1.test(sqlQuery1.value)
83 || do_confirm_re_2.test(sqlQuery1.value)) {
84 var message = (sqlQuery1.value.length > 100)
85 ? sqlQuery1.value.substr(0, 100) + '\n ...'
87 var is_confirmed = confirm(confirmMsg + ' :\n' + message);
88 // drop/delete/alter statement is confirmed -> update the
89 // "is_js_confirmed" form field so the confirm test won't be
90 // run on the server side and allows to submit the form
92 theForm1.elements['is_js_confirmed'].value = 1;
95 // "DROP/DELETE/ALTER" statement is rejected -> do not submit
101 } // end if (handle confirm box result)
102 } // end if (display confirm box)
103 } // end confirmation stuff
106 } // end of the 'confirmQuery()' function
110 * Displays an error message if the user submitted the sql query form with no
111 * sql query, else checks for "DROP/DELETE/ALTER" statements
113 * @param object the form
115 * @return boolean always false
117 * @see confirmQuery()
119 function checkSqlQuery(theForm)
121 var sqlQuery = theForm.elements['sql_query'];
124 // The replace function (js1.2) isn't supported -> basic tests
125 if (typeof(sqlQuery.value.replace) == 'undefined') {
126 isEmpty = (sqlQuery.value == '') ? 1 : 0;
127 if (isEmpty && typeof(theForm.elements['sql_file']) != 'undefined') {
128 isEmpty = (theForm.elements['sql_file'].value == '') ? 1 : 0;
130 if (isEmpty && typeof(theForm.elements['sql_localfile']) != 'undefined') {
131 isEmpty = (theForm.elements['sql_localfile'].value == '') ? 1 : 0;
133 if (isEmpty && typeof(theForm.elements['id_bookmark']) != 'undefined') {
134 isEmpty = (theForm.elements['id_bookmark'].value == null || theForm.elements['id_bookmark'].value == '');
137 // js1.2+ -> validation with regular expressions
139 var space_re = new RegExp('\\s+');
140 if (typeof(theForm.elements['sql_file']) != 'undefined' &&
141 theForm.elements['sql_file'].value.replace(space_re, '') != '') {
144 if (typeof(theForm.elements['sql_localfile']) != 'undefined' &&
145 theForm.elements['sql_localfile'].value.replace(space_re, '') != '') {
148 if (isEmpty && typeof(theForm.elements['id_bookmark']) != 'undefined' &&
149 (theForm.elements['id_bookmark'].value != null || theForm.elements['id_bookmark'].value != '') &&
150 theForm.elements['id_bookmark'].selectedIndex != 0
154 // Checks for "DROP/DELETE/ALTER" statements
155 if (sqlQuery.value.replace(space_re, '') != '') {
156 if (confirmQuery(theForm, sqlQuery)) {
174 } // end of the 'checkSqlQuery()' function
178 * Displays an error message if an element of a form hasn't been completed and
181 * @param object the form
182 * @param string the name of the form field to put the focus on
184 * @return boolean whether the form field is empty or not
186 function emptyFormElements(theForm, theFieldName)
189 var theField = theForm.elements[theFieldName];
190 // Whether the replace function (js1.2) is supported or not
191 var isRegExp = (typeof(theField.value.replace) != 'undefined');
194 isEmpty = (theField.value == '') ? 1 : 0;
196 var space_re = new RegExp('\\s+');
197 isEmpty = (theField.value.replace(space_re, '') == '') ? 1 : 0;
208 } // end of the 'emptyFormElements()' function
212 * Ensures a value submitted in a form is numeric and is in a range
214 * @param object the form
215 * @param string the name of the form field to check
216 * @param integer the minimum authorized value
217 * @param integer the maximum authorized value
219 * @return boolean whether a valid number has been submitted or not
221 function checkFormElementInRange(theForm, theFieldName, min, max)
223 var theField = theForm.elements[theFieldName];
224 var val = parseInt(theField.value);
226 if (typeof(min) == 'undefined') {
229 if (typeof(max) == 'undefined') {
230 max = Number.MAX_VALUE;
240 // It's a number but it is not between min and max
241 else if (val < min || val > max) {
243 alert(val + errorMsg2);
247 // It's a valid number
249 theField.value = val;
253 } // end of the 'checkFormElementInRange()' function
255 function checkTableEditForm(theForm, fieldsCnt)
257 for (i=0; i<fieldsCnt; i++)
259 var id = "field_" + i + "_2";
260 var elm = getElement(id);
261 if (elm.value == 'VARCHAR' || elm.value == 'CHAR') {
262 elm2 = getElement("field_" + i + "_3");
263 val = parseInt(elm2.value);
264 elm3 = getElement("field_" + i + "_1");
265 if (isNaN(val) && elm3.value != "") {
274 } // enf of the 'checkTableEditForm()' function
278 * Ensures the choice between 'transmit', 'zipped', 'gzipped' and 'bzipped'
279 * checkboxes is consistant
281 * @param object the form
282 * @param string a code for the action that causes this function to be run
284 * @return boolean always true
286 function checkTransmitDump(theForm, theAction)
288 var formElts = theForm.elements;
290 // 'zipped' option has been checked
291 if (theAction == 'zip' && formElts['zip'].checked) {
292 if (!formElts['asfile'].checked) {
293 theForm.elements['asfile'].checked = true;
295 if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) {
296 theForm.elements['gzip'].checked = false;
298 if (typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked) {
299 theForm.elements['bzip'].checked = false;
302 // 'gzipped' option has been checked
303 else if (theAction == 'gzip' && formElts['gzip'].checked) {
304 if (!formElts['asfile'].checked) {
305 theForm.elements['asfile'].checked = true;
307 if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
308 theForm.elements['zip'].checked = false;
310 if (typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked) {
311 theForm.elements['bzip'].checked = false;
314 // 'bzipped' option has been checked
315 else if (theAction == 'bzip' && formElts['bzip'].checked) {
316 if (!formElts['asfile'].checked) {
317 theForm.elements['asfile'].checked = true;
319 if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
320 theForm.elements['zip'].checked = false;
322 if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) {
323 theForm.elements['gzip'].checked = false;
326 // 'transmit' option has been unchecked
327 else if (theAction == 'transmit' && !formElts['asfile'].checked) {
328 if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
329 theForm.elements['zip'].checked = false;
331 if ((typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked)) {
332 theForm.elements['gzip'].checked = false;
334 if ((typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked)) {
335 theForm.elements['bzip'].checked = false;
340 } // end of the 'checkTransmitDump()' function
344 * This array is used to remember mark status of rows in browse mode
346 var marked_row = new Array;
350 * Sets/unsets the pointer and marker in browse mode
352 * @param object the table row
353 * @param interger the row number
354 * @param string the action calling this script (over, out or click)
355 * @param string the default background color
356 * @param string the color to use for mouseover
357 * @param string the color to use for marking a row
359 * @return boolean whether pointer is set or not
361 function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
365 // 1. Pointer and mark feature are disabled or the browser can't get the
367 if ((thePointerColor == '' && theMarkColor == '')
368 || typeof(theRow.style) == 'undefined') {
372 // 2. Gets the current row and exits if the browser can't get it
373 if (typeof(document.getElementsByTagName) != 'undefined') {
374 theCells = theRow.getElementsByTagName('td');
376 else if (typeof(theRow.cells) != 'undefined') {
377 theCells = theRow.cells;
383 // 3. Gets the current color...
384 var rowCellsCnt = theCells.length;
385 var domDetect = null;
386 var currentColor = null;
388 // 3.1 ... with DOM compatible browsers except Opera that does not return
389 // valid values with "getAttribute"
390 if (typeof(window.opera) == 'undefined'
391 && typeof(theCells[0].getAttribute) != 'undefined') {
392 currentColor = theCells[0].getAttribute('bgcolor');
395 // 3.2 ... with other browsers
397 currentColor = theCells[0].style.backgroundColor;
401 // 4. Defines the new color
402 // 4.1 Current color is the default one
403 if (currentColor == ''
404 || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
405 if (theAction == 'over' && thePointerColor != '') {
406 newColor = thePointerColor;
408 else if (theAction == 'click' && theMarkColor != '') {
409 newColor = theMarkColor;
410 marked_row[theRowNum] = true;
413 // 4.1.2 Current color is the pointer one
414 else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
415 && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
416 if (theAction == 'out') {
417 newColor = theDefaultColor;
419 else if (theAction == 'click' && theMarkColor != '') {
420 newColor = theMarkColor;
421 marked_row[theRowNum] = true;
424 // 4.1.3 Current color is the marker one
425 else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
426 if (theAction == 'click') {
427 newColor = (thePointerColor != '')
430 marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
436 // 5. Sets the new color...
439 // 5.1 ... with DOM compatible browsers except Opera
441 for (c = 0; c < rowCellsCnt; c++) {
442 theCells[c].setAttribute('bgcolor', newColor, 0);
445 // 5.2 ... with other browsers
447 for (c = 0; c < rowCellsCnt; c++) {
448 theCells[c].style.backgroundColor = newColor;
454 } // end of the 'setPointer()' function
457 * Sets/unsets the pointer and marker in vertical browse mode
459 * @param object the table row
460 * @param interger the row number
461 * @param string the action calling this script (over, out or click)
462 * @param string the default background color
463 * @param string the color to use for mouseover
464 * @param string the color to use for marking a row
466 * @return boolean whether pointer is set or not
468 * @author Garvin Hicking <me@supergarv.de> (rewrite of setPointer.)
470 function setVerticalPointer(theRow, theRowNum, theAction, theDefaultColor1, theDefaultColor2, thePointerColor, theMarkColor) {
473 // 1. Pointer and mark feature are disabled or the browser can't get the
475 if ((thePointerColor == '' && theMarkColor == '')
476 || typeof(theRow.style) == 'undefined') {
480 // 2. Gets the current row and exits if the browser can't get it
481 if (typeof(document.getElementsByTagName) != 'undefined') {
482 theCells = theRow.getElementsByTagName('td');
484 else if (typeof(theRow.cells) != 'undefined') {
485 theCells = theRow.cells;
491 // 3. Gets the current color...
492 var rowCellsCnt = theCells.length;
493 var domDetect = null;
494 var currentColor = null;
497 // 3.1 ... with DOM compatible browsers except Opera that does not return
498 // valid values with "getAttribute"
499 if (typeof(window.opera) == 'undefined'
500 && typeof(theCells[0].getAttribute) != 'undefined') {
501 currentColor = theCells[0].getAttribute('bgcolor');
504 // 3.2 ... with other browsers
510 // 5.1 ... with DOM compatible browsers except Opera
511 for (c = 0; c < rowCellsCnt; c++) {
513 currentColor = theCells[c].getAttribute('bgcolor');
515 currentColor = theCells[c].style.backgroundColor;
518 // 4. Defines the new color
519 // 4.1 Current color is the default one
520 if (currentColor == ''
521 || currentColor.toLowerCase() == theDefaultColor1.toLowerCase()
522 || currentColor.toLowerCase() == theDefaultColor2.toLowerCase()) {
523 if (theAction == 'over' && thePointerColor != '') {
524 newColor = thePointerColor;
525 } else if (theAction == 'click' && theMarkColor != '') {
526 newColor = theMarkColor;
527 marked_row[theRowNum] = true;
530 // 4.1.2 Current color is the pointer one
531 else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
532 && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
533 if (theAction == 'out') {
535 newColor = theDefaultColor1;
537 newColor = theDefaultColor2;
540 else if (theAction == 'click' && theMarkColor != '') {
541 newColor = theMarkColor;
542 marked_row[theRowNum] = true;
545 // 4.1.3 Current color is the marker one
546 else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
547 if (theAction == 'click') {
548 newColor = (thePointerColor != '')
550 : ((c % 2) ? theDefaultColor1 : theDefaultColor2);
551 marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
557 // 5. Sets the new color...
560 theCells[c].setAttribute('bgcolor', newColor, 0);
562 // 5.2 ... with other browsers
564 theCells[c].style.backgroundColor = newColor;
570 } // end of the 'setVerticalPointer()' function
573 * Checks/unchecks all tables
575 * @param string the form name
576 * @param boolean whether to check or to uncheck the element
578 * @return boolean always true
580 function setCheckboxes(the_form, do_check)
582 var elts = (typeof(document.forms[the_form].elements['selected_db[]']) != 'undefined')
583 ? document.forms[the_form].elements['selected_db[]']
584 : (typeof(document.forms[the_form].elements['selected_tbl[]']) != 'undefined')
585 ? document.forms[the_form].elements['selected_tbl[]']
586 : document.forms[the_form].elements['selected_fld[]'];
587 var elts_cnt = (typeof(elts.length) != 'undefined')
592 for (var i = 0; i < elts_cnt; i++) {
593 elts[i].checked = do_check;
596 elts.checked = do_check;
600 } // end of the 'setCheckboxes()' function
604 * Checks/unchecks all options of a <select> element
606 * @param string the form name
607 * @param string the element name
608 * @param boolean whether to check or to uncheck the element
610 * @return boolean always true
612 function setSelectOptions(the_form, the_select, do_check)
614 var selectObject = document.forms[the_form].elements[the_select];
615 var selectCount = selectObject.length;
617 for (var i = 0; i < selectCount; i++) {
618 selectObject.options[i].selected = do_check;
622 } // end of the 'setSelectOptions()' function
625 * Allows moving around inputs/select by Ctrl+arrows
627 * @param object event data
629 function onKeyDownArrowsHandler(e) {
631 var o = (e.srcElement||e.target);
633 if (o.tagName != "TEXTAREA" && o.tagName != "INPUT" && o.tagName != "SELECT") return;
634 if (!e.ctrlKey) return;
637 var pos = o.id.split("_");
638 if (pos[0] != "field" || typeof pos[2] == "undefined") return;
640 var x = pos[2], y=pos[1];
642 // skip non existent fields
646 case 38: y--; break; // up
647 case 40: y++; break; // down
648 case 37: x--; break; // left
649 case 39: x++; break; // right
653 var id = "field_" + y + "_" + x;
654 var nO = document.getElementById(id);
660 if (nO.tagName != 'SELECT') {
663 e.returnValue = false;
667 * Inserts multiple fields.
670 function insertValueQuery() {
671 var myQuery = document.sqlform.sql_query;
672 var myListBox = document.sqlform.dummy;
674 if(myListBox.options.length > 0) {
677 for(var i=0; i<myListBox.options.length; i++) {
678 if (myListBox.options[i].selected){
682 chaineAj += myListBox.options[i].value;
687 if (document.selection) {
689 sel = document.selection.createRange();
691 document.sqlform.insert.focus();
693 //MOZILLA/NETSCAPE support
694 else if (document.sqlform.sql_query.selectionStart || document.sqlform.sql_query.selectionStart == "0") {
695 var startPos = document.sqlform.sql_query.selectionStart;
696 var endPos = document.sqlform.sql_query.selectionEnd;
697 var chaineSql = document.sqlform.sql_query.value;
699 myQuery.value = chaineSql.substring(0, startPos) + chaineAj + chaineSql.substring(endPos, chaineSql.length);
701 myQuery.value += chaineAj;
707 * listbox redirection
709 function goToUrl(selObj, goToLocation){
710 eval("document.location.href = '" + goToLocation + "pos=" + selObj.options[selObj.selectedIndex].value + "'");
716 function getElement(e,f){
719 if(f.document.layers[e]) {
720 return f.document.layers[e];
722 for(W=0;i<f.document.layers.length;W++) {
723 return(getElement(e,fdocument.layers[W]));
727 return document.all[e];
729 return document.getElementById(e);
733 * Refresh the WYSIWYG-PDF scratchboard after changes have been made
735 function refreshDragOption(e) {
736 myid = getElement(e);
737 if (myid.style.visibility == 'visible') {
743 * Refresh/resize the WYSIWYG-PDF scratchboard
745 function refreshLayout() {
746 myid = getElement('pdflayout');
748 if (document.pdfoptions.orientation.value == 'P') {
756 myid.style.width = pdfPaperSize(document.pdfoptions.paper.value, posa) + 'px';
757 myid.style.height = pdfPaperSize(document.pdfoptions.paper.value, posb) + 'px';
761 * Show/hide the WYSIWYG-PDF scratchboard
763 function ToggleDragDrop(e) {
764 myid = getElement(e);
766 if (myid.style.visibility == 'hidden') {
768 myid.style.visibility = 'visible';
769 myid.style.display = 'block';
770 document.edcoord.showwysiwyg.value = '1';
772 myid.style.visibility = 'hidden';
773 myid.style.display = 'none';
774 document.edcoord.showwysiwyg.value = '0';
779 * PDF scratchboard: When a position is entered manually, update
780 * the fields inside the scratchboard.
782 function dragPlace(no, axis, value) {
784 getElement("table_" + no).style.left = value + 'px';
786 getElement("table_" + no).style.top = value + 'px';
791 * Returns paper sizes for a given format
793 function pdfPaperSize(format, axis) {
796 if (axis == 'x') return 4767.87; else return 6740.79;
799 if (axis == 'x') return 3370.39; else return 4767.87;
802 if (axis == 'x') return 2383.94; else return 3370.39;
805 if (axis == 'x') return 1683.78; else return 2383.94;
808 if (axis == 'x') return 1190.55; else return 1683.78;
811 if (axis == 'x') return 841.89; else return 1190.55;
814 if (axis == 'x') return 595.28; else return 841.89;
817 if (axis == 'x') return 419.53; else return 595.28;
820 if (axis == 'x') return 297.64; else return 419.53;
823 if (axis == 'x') return 209.76; else return 297.64;
826 if (axis == 'x') return 147.40; else return 209.76;
829 if (axis == 'x') return 104.88; else return 147.40;
832 if (axis == 'x') return 73.70; else return 104.88;
835 if (axis == 'x') return 2834.65; else return 4008.19;
838 if (axis == 'x') return 2004.09; else return 2834.65;
841 if (axis == 'x') return 1417.32; else return 2004.09;
844 if (axis == 'x') return 1000.63; else return 1417.32;
847 if (axis == 'x') return 708.66; else return 1000.63;
850 if (axis == 'x') return 498.90; else return 708.66;
853 if (axis == 'x') return 354.33; else return 498.90;
856 if (axis == 'x') return 249.45; else return 354.33;
859 if (axis == 'x') return 175.75; else return 249.45;
862 if (axis == 'x') return 124.72; else return 175.75;
865 if (axis == 'x') return 87.87; else return 124.72;
868 if (axis == 'x') return 2599.37; else return 3676.54;
871 if (axis == 'x') return 1836.85; else return 2599.37;
874 if (axis == 'x') return 1298.27; else return 1836.85;
877 if (axis == 'x') return 918.43; else return 1298.27;
880 if (axis == 'x') return 649.13; else return 918.43;
883 if (axis == 'x') return 459.21; else return 649.13;
886 if (axis == 'x') return 323.15; else return 459.21;
889 if (axis == 'x') return 229.61; else return 323.15;
892 if (axis == 'x') return 161.57; else return 229.61;
895 if (axis == 'x') return 113.39; else return 161.57;
898 if (axis == 'x') return 79.37; else return 113.39;
901 if (axis == 'x') return 2437.80; else return 3458.27;
904 if (axis == 'x') return 1729.13; else return 2437.80;
907 if (axis == 'x') return 1218.90; else return 1729.13;
910 if (axis == 'x') return 864.57; else return 1218.90;
913 if (axis == 'x') return 609.45; else return 864.57;
916 if (axis == 'x') return 2551.18; else return 3628.35;
919 if (axis == 'x') return 1814.17; else return 2551.18;
922 if (axis == 'x') return 1275.59; else return 1814.17;
925 if (axis == 'x') return 907.09; else return 1275.59;
928 if (axis == 'x') return 637.80; else return 907.09;
931 if (axis == 'x') return 612.00; else return 792.00;
934 if (axis == 'x') return 612.00; else return 1008.00;
937 if (axis == 'x') return 521.86; else return 756.00;
940 if (axis == 'x') return 612.00; else return 936.00;