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 // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
402 if (currentColor.indexOf("rgb") >= 0)
404 var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
405 currentColor.indexOf(')'));
406 var rgbValues = rgbStr.split(",");
408 var hexChars = "0123456789ABCDEF";
409 for (var i = 0; i < 3; i++)
411 var v = rgbValues[i].valueOf();
412 currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
416 // 4. Defines the new color
417 // 4.1 Current color is the default one
418 if (currentColor == ''
419 || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
420 if (theAction == 'over' && thePointerColor != '') {
421 newColor = thePointerColor;
423 else if (theAction == 'click' && theMarkColor != '') {
424 newColor = theMarkColor;
425 marked_row[theRowNum] = true;
428 // 4.1.2 Current color is the pointer one
429 else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
430 && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
431 if (theAction == 'out') {
432 newColor = theDefaultColor;
434 else if (theAction == 'click' && theMarkColor != '') {
435 newColor = theMarkColor;
436 marked_row[theRowNum] = true;
439 // 4.1.3 Current color is the marker one
440 else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
441 if (theAction == 'click') {
442 newColor = (thePointerColor != '')
445 marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
451 // 5. Sets the new color...
454 // 5.1 ... with DOM compatible browsers except Opera
456 for (c = 0; c < rowCellsCnt; c++) {
457 theCells[c].setAttribute('bgcolor', newColor, 0);
460 // 5.2 ... with other browsers
462 for (c = 0; c < rowCellsCnt; c++) {
463 theCells[c].style.backgroundColor = newColor;
469 } // end of the 'setPointer()' function
472 * Sets/unsets the pointer and marker in vertical browse mode
474 * @param object the table row
475 * @param interger the row number
476 * @param string the action calling this script (over, out or click)
477 * @param string the default background color
478 * @param string the color to use for mouseover
479 * @param string the color to use for marking a row
481 * @return boolean whether pointer is set or not
483 * @author Garvin Hicking <me@supergarv.de> (rewrite of setPointer.)
485 function setVerticalPointer(theRow, theRowNum, theAction, theDefaultColor1, theDefaultColor2, thePointerColor, theMarkColor) {
488 // 1. Pointer and mark feature are disabled or the browser can't get the
490 if ((thePointerColor == '' && theMarkColor == '')
491 || typeof(theRow.style) == 'undefined') {
495 // 2. Gets the current row and exits if the browser can't get it
496 if (typeof(document.getElementsByTagName) != 'undefined') {
497 theCells = theRow.getElementsByTagName('td');
499 else if (typeof(theRow.cells) != 'undefined') {
500 theCells = theRow.cells;
506 // 3. Gets the current color...
507 var rowCellsCnt = theCells.length;
508 var domDetect = null;
509 var currentColor = null;
512 // 3.1 ... with DOM compatible browsers except Opera that does not return
513 // valid values with "getAttribute"
514 if (typeof(window.opera) == 'undefined'
515 && typeof(theCells[0].getAttribute) != 'undefined') {
516 currentColor = theCells[0].getAttribute('bgcolor');
519 // 3.2 ... with other browsers
525 // 5.1 ... with DOM compatible browsers except Opera
526 for (c = 0; c < rowCellsCnt; c++) {
528 currentColor = theCells[c].getAttribute('bgcolor');
530 currentColor = theCells[c].style.backgroundColor;
533 // 4. Defines the new color
534 // 4.1 Current color is the default one
535 if (currentColor == ''
536 || currentColor.toLowerCase() == theDefaultColor1.toLowerCase()
537 || currentColor.toLowerCase() == theDefaultColor2.toLowerCase()) {
538 if (theAction == 'over' && thePointerColor != '') {
539 newColor = thePointerColor;
540 } else if (theAction == 'click' && theMarkColor != '') {
541 newColor = theMarkColor;
542 marked_row[theRowNum] = true;
545 // 4.1.2 Current color is the pointer one
546 else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
547 && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
548 if (theAction == 'out') {
550 newColor = theDefaultColor1;
552 newColor = theDefaultColor2;
555 else if (theAction == 'click' && theMarkColor != '') {
556 newColor = theMarkColor;
557 marked_row[theRowNum] = true;
560 // 4.1.3 Current color is the marker one
561 else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
562 if (theAction == 'click') {
563 newColor = (thePointerColor != '')
565 : ((c % 2) ? theDefaultColor1 : theDefaultColor2);
566 marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
572 // 5. Sets the new color...
575 theCells[c].setAttribute('bgcolor', newColor, 0);
577 // 5.2 ... with other browsers
579 theCells[c].style.backgroundColor = newColor;
585 } // end of the 'setVerticalPointer()' function
588 * Checks/unchecks all tables
590 * @param string the form name
591 * @param boolean whether to check or to uncheck the element
593 * @return boolean always true
595 function setCheckboxes(the_form, do_check)
597 var elts = (typeof(document.forms[the_form].elements['selected_db[]']) != 'undefined')
598 ? document.forms[the_form].elements['selected_db[]']
599 : (typeof(document.forms[the_form].elements['selected_tbl[]']) != 'undefined')
600 ? document.forms[the_form].elements['selected_tbl[]']
601 : document.forms[the_form].elements['selected_fld[]'];
602 var elts_cnt = (typeof(elts.length) != 'undefined')
607 for (var i = 0; i < elts_cnt; i++) {
608 elts[i].checked = do_check;
611 elts.checked = do_check;
615 } // end of the 'setCheckboxes()' function
619 * Checks/unchecks all options of a <select> element
621 * @param string the form name
622 * @param string the element name
623 * @param boolean whether to check or to uncheck the element
625 * @return boolean always true
627 function setSelectOptions(the_form, the_select, do_check)
629 var selectObject = document.forms[the_form].elements[the_select];
630 var selectCount = selectObject.length;
632 for (var i = 0; i < selectCount; i++) {
633 selectObject.options[i].selected = do_check;
637 } // end of the 'setSelectOptions()' function
640 * Allows moving around inputs/select by Ctrl+arrows
642 * @param object event data
644 function onKeyDownArrowsHandler(e) {
646 var o = (e.srcElement||e.target);
648 if (o.tagName != "TEXTAREA" && o.tagName != "INPUT" && o.tagName != "SELECT") return;
649 if (!e.ctrlKey) return;
652 var pos = o.id.split("_");
653 if (pos[0] != "field" || typeof pos[2] == "undefined") return;
655 var x = pos[2], y=pos[1];
657 // skip non existent fields
661 case 38: y--; break; // up
662 case 40: y++; break; // down
663 case 37: x--; break; // left
664 case 39: x++; break; // right
668 var id = "field_" + y + "_" + x;
669 var nO = document.getElementById(id);
675 if (nO.tagName != 'SELECT') {
678 e.returnValue = false;
682 * Inserts multiple fields.
685 function insertValueQuery() {
686 var myQuery = document.sqlform.sql_query;
687 var myListBox = document.sqlform.dummy;
689 if(myListBox.options.length > 0) {
692 for(var i=0; i<myListBox.options.length; i++) {
693 if (myListBox.options[i].selected){
697 chaineAj += myListBox.options[i].value;
702 if (document.selection) {
704 sel = document.selection.createRange();
706 document.sqlform.insert.focus();
708 //MOZILLA/NETSCAPE support
709 else if (document.sqlform.sql_query.selectionStart || document.sqlform.sql_query.selectionStart == "0") {
710 var startPos = document.sqlform.sql_query.selectionStart;
711 var endPos = document.sqlform.sql_query.selectionEnd;
712 var chaineSql = document.sqlform.sql_query.value;
714 myQuery.value = chaineSql.substring(0, startPos) + chaineAj + chaineSql.substring(endPos, chaineSql.length);
716 myQuery.value += chaineAj;
722 * listbox redirection
724 function goToUrl(selObj, goToLocation){
725 eval("document.location.href = '" + goToLocation + "pos=" + selObj.options[selObj.selectedIndex].value + "'");
731 function getElement(e,f){
734 if(f.document.layers[e]) {
735 return f.document.layers[e];
737 for(W=0;i<f.document.layers.length;W++) {
738 return(getElement(e,fdocument.layers[W]));
742 return document.all[e];
744 return document.getElementById(e);
748 * Refresh the WYSIWYG-PDF scratchboard after changes have been made
750 function refreshDragOption(e) {
751 myid = getElement(e);
752 if (myid.style.visibility == 'visible') {
758 * Refresh/resize the WYSIWYG-PDF scratchboard
760 function refreshLayout() {
761 myid = getElement('pdflayout');
763 if (document.pdfoptions.orientation.value == 'P') {
771 myid.style.width = pdfPaperSize(document.pdfoptions.paper.value, posa) + 'px';
772 myid.style.height = pdfPaperSize(document.pdfoptions.paper.value, posb) + 'px';
776 * Show/hide the WYSIWYG-PDF scratchboard
778 function ToggleDragDrop(e) {
779 myid = getElement(e);
781 if (myid.style.visibility == 'hidden') {
783 myid.style.visibility = 'visible';
784 myid.style.display = 'block';
785 document.edcoord.showwysiwyg.value = '1';
787 myid.style.visibility = 'hidden';
788 myid.style.display = 'none';
789 document.edcoord.showwysiwyg.value = '0';
794 * PDF scratchboard: When a position is entered manually, update
795 * the fields inside the scratchboard.
797 function dragPlace(no, axis, value) {
799 getElement("table_" + no).style.left = value + 'px';
801 getElement("table_" + no).style.top = value + 'px';
806 * Returns paper sizes for a given format
808 function pdfPaperSize(format, axis) {
809 switch (format.toUpperCase()) {
811 if (axis == 'x') return 4767.87; else return 6740.79;
814 if (axis == 'x') return 3370.39; else return 4767.87;
817 if (axis == 'x') return 2383.94; else return 3370.39;
820 if (axis == 'x') return 1683.78; else return 2383.94;
823 if (axis == 'x') return 1190.55; else return 1683.78;
826 if (axis == 'x') return 841.89; else return 1190.55;
829 if (axis == 'x') return 595.28; else return 841.89;
832 if (axis == 'x') return 419.53; else return 595.28;
835 if (axis == 'x') return 297.64; else return 419.53;
838 if (axis == 'x') return 209.76; else return 297.64;
841 if (axis == 'x') return 147.40; else return 209.76;
844 if (axis == 'x') return 104.88; else return 147.40;
847 if (axis == 'x') return 73.70; else return 104.88;
850 if (axis == 'x') return 2834.65; else return 4008.19;
853 if (axis == 'x') return 2004.09; else return 2834.65;
856 if (axis == 'x') return 1417.32; else return 2004.09;
859 if (axis == 'x') return 1000.63; else return 1417.32;
862 if (axis == 'x') return 708.66; else return 1000.63;
865 if (axis == 'x') return 498.90; else return 708.66;
868 if (axis == 'x') return 354.33; else return 498.90;
871 if (axis == 'x') return 249.45; else return 354.33;
874 if (axis == 'x') return 175.75; else return 249.45;
877 if (axis == 'x') return 124.72; else return 175.75;
880 if (axis == 'x') return 87.87; else return 124.72;
883 if (axis == 'x') return 2599.37; else return 3676.54;
886 if (axis == 'x') return 1836.85; else return 2599.37;
889 if (axis == 'x') return 1298.27; else return 1836.85;
892 if (axis == 'x') return 918.43; else return 1298.27;
895 if (axis == 'x') return 649.13; else return 918.43;
898 if (axis == 'x') return 459.21; else return 649.13;
901 if (axis == 'x') return 323.15; else return 459.21;
904 if (axis == 'x') return 229.61; else return 323.15;
907 if (axis == 'x') return 161.57; else return 229.61;
910 if (axis == 'x') return 113.39; else return 161.57;
913 if (axis == 'x') return 79.37; else return 113.39;
916 if (axis == 'x') return 2437.80; else return 3458.27;
919 if (axis == 'x') return 1729.13; else return 2437.80;
922 if (axis == 'x') return 1218.90; else return 1729.13;
925 if (axis == 'x') return 864.57; else return 1218.90;
928 if (axis == 'x') return 609.45; else return 864.57;
931 if (axis == 'x') return 2551.18; else return 3628.35;
934 if (axis == 'x') return 1814.17; else return 2551.18;
937 if (axis == 'x') return 1275.59; else return 1814.17;
940 if (axis == 'x') return 907.09; else return 1275.59;
943 if (axis == 'x') return 637.80; else return 907.09;
946 if (axis == 'x') return 612.00; else return 792.00;
949 if (axis == 'x') return 612.00; else return 1008.00;
952 if (axis == 'x') return 521.86; else return 756.00;
955 if (axis == 'x') return 612.00; else return 936.00;