home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / functions.js < prev    next >
Encoding:
JavaScript  |  2004-01-05  |  31.6 KB  |  966 lines

  1. /* $Id: functions.js,v 2.2 2004/01/05 16:10:15 garvinhicking Exp $ */
  2.  
  3.  
  4. /**
  5.  * Displays an confirmation box beforme to submit a "DROP/DELETE/ALTER" query.
  6.  * This function is called while clicking links
  7.  *
  8.  * @param   object   the link
  9.  * @param   object   the sql query to submit
  10.  *
  11.  * @return  boolean  whether to run the query or not
  12.  */
  13. function confirmLink(theLink, theSqlQuery)
  14. {
  15.     // Confirmation is not required in the configuration file
  16.     // or browser is Opera (crappy js implementation)
  17.     if (confirmMsg == '' || typeof(window.opera) != 'undefined') {
  18.         return true;
  19.     }
  20.  
  21.     var is_confirmed = confirm(confirmMsg + ' :\n' + theSqlQuery);
  22.     if (is_confirmed) {
  23.         theLink.href += '&is_js_confirmed=1';
  24.     }
  25.  
  26.     return is_confirmed;
  27. } // end of the 'confirmLink()' function
  28.  
  29.  
  30. /**
  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.
  35.  *
  36.  * @param   object   the form
  37.  * @param   object   the sql query textarea
  38.  *
  39.  * @return  boolean  whether to run the query or not
  40.  *
  41.  * @see     checkSqlQuery()
  42.  */
  43. function confirmQuery(theForm1, sqlQuery1)
  44. {
  45.     // Confirmation is not required in the configuration file
  46.     if (confirmMsg == '') {
  47.         return true;
  48.     }
  49.  
  50.     // The replace function (js1.2) isn't supported
  51.     else if (typeof(sqlQuery1.value.replace) == 'undefined') {
  52.         return true;
  53.     }
  54.  
  55.     // js1.2+ -> validation with regular expressions
  56.     else {
  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)) {
  61.                 alert(noDropDbMsg);
  62.                 theForm1.reset();
  63.                 sqlQuery1.focus();
  64.                 return false;
  65.             } // end if
  66.         } // end if
  67.  
  68.         // Confirms a "DROP/DELETE/ALTER" statement
  69.         //
  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
  74.  
  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    ...'
  86.                              : sqlQuery1.value;
  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
  91.             if (is_confirmed) {
  92.                 theForm1.elements['is_js_confirmed'].value = 1;
  93.                 return true;
  94.             }
  95.             // "DROP/DELETE/ALTER" statement is rejected -> do not submit
  96.             // the form
  97.             else {
  98.                 window.focus();
  99.                 sqlQuery1.focus();
  100.                 return false;
  101.             } // end if (handle confirm box result)
  102.         } // end if (display confirm box)
  103.     } // end confirmation stuff
  104.  
  105.     return true;
  106. } // end of the 'confirmQuery()' function
  107.  
  108.  
  109. /**
  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
  112.  *
  113.  * @param   object   the form
  114.  *
  115.  * @return  boolean  always false
  116.  *
  117.  * @see     confirmQuery()
  118.  */
  119. function checkSqlQuery(theForm)
  120. {
  121.     var sqlQuery = theForm.elements['sql_query'];
  122.     var isEmpty  = 1;
  123.  
  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;
  129.         }
  130.         if (isEmpty && typeof(theForm.elements['sql_localfile']) != 'undefined') {
  131.             isEmpty  = (theForm.elements['sql_localfile'].value == '') ? 1 : 0;
  132.         }
  133.         if (isEmpty && typeof(theForm.elements['id_bookmark']) != 'undefined') {
  134.             isEmpty  = (theForm.elements['id_bookmark'].value == null || theForm.elements['id_bookmark'].value == '');
  135.         }
  136.     }
  137.     // js1.2+ -> validation with regular expressions
  138.     else {
  139.         var space_re = new RegExp('\\s+');
  140.         if (typeof(theForm.elements['sql_file']) != 'undefined' &&
  141.                 theForm.elements['sql_file'].value.replace(space_re, '') != '') {
  142.             return true;
  143.         }
  144.         if (typeof(theForm.elements['sql_localfile']) != 'undefined' &&
  145.                 theForm.elements['sql_localfile'].value.replace(space_re, '') != '') {
  146.             return true;
  147.         }
  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
  151.                 ) {
  152.             return true;
  153.         }
  154.         // Checks for "DROP/DELETE/ALTER" statements
  155.         if (sqlQuery.value.replace(space_re, '') != '') {
  156.             if (confirmQuery(theForm, sqlQuery)) {
  157.                 return true;
  158.             } else {
  159.                 return false;
  160.             }
  161.         }
  162.         theForm.reset();
  163.         isEmpty = 1;
  164.     }
  165.  
  166.     if (isEmpty) {
  167.         sqlQuery.select();
  168.         alert(errorMsg0);
  169.         sqlQuery.focus();
  170.         return false;
  171.     }
  172.  
  173.     return true;
  174. } // end of the 'checkSqlQuery()' function
  175.  
  176.  
  177. /**
  178.  * Displays an error message if an element of a form hasn't been completed and
  179.  * should be
  180.  *
  181.  * @param   object   the form
  182.  * @param   string   the name of the form field to put the focus on
  183.  *
  184.  * @return  boolean  whether the form field is empty or not
  185.  */
  186. function emptyFormElements(theForm, theFieldName)
  187. {
  188.     var isEmpty  = 1;
  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');
  192.  
  193.     if (!isRegExp) {
  194.         isEmpty      = (theField.value == '') ? 1 : 0;
  195.     } else {
  196.         var space_re = new RegExp('\\s+');
  197.         isEmpty      = (theField.value.replace(space_re, '') == '') ? 1 : 0;
  198.     }
  199.     if (isEmpty) {
  200.         theForm.reset();
  201.         theField.select();
  202.         alert(errorMsg0);
  203.         theField.focus();
  204.         return false;
  205.     }
  206.  
  207.     return true;
  208. } // end of the 'emptyFormElements()' function
  209.  
  210.  
  211. /**
  212.  * Ensures a value submitted in a form is numeric and is in a range
  213.  *
  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
  218.  *
  219.  * @return  boolean  whether a valid number has been submitted or not
  220.  */
  221. function checkFormElementInRange(theForm, theFieldName, min, max)
  222. {
  223.     var theField         = theForm.elements[theFieldName];
  224.     var val              = parseInt(theField.value);
  225.  
  226.     if (typeof(min) == 'undefined') {
  227.         min = 0;
  228.     }
  229.     if (typeof(max) == 'undefined') {
  230.         max = Number.MAX_VALUE;
  231.     }
  232.  
  233.     // It's not a number
  234.     if (isNaN(val)) {
  235.         theField.select();
  236.         alert(errorMsg1);
  237.         theField.focus();
  238.         return false;
  239.     }
  240.     // It's a number but it is not between min and max
  241.     else if (val < min || val > max) {
  242.         theField.select();
  243.         alert(val + errorMsg2);
  244.         theField.focus();
  245.         return false;
  246.     }
  247.     // It's a valid number
  248.     else {
  249.         theField.value = val;
  250.     }
  251.  
  252.     return true;
  253. } // end of the 'checkFormElementInRange()' function
  254.  
  255. function checkTableEditForm(theForm, fieldsCnt)
  256. {
  257.     for (i=0; i<fieldsCnt; i++)
  258.     {
  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 != "") {
  266.                 elm2.select();
  267.                 alert(errorMsg1);
  268.                 elm2.focus();
  269.                 return false;
  270.             }
  271.         }
  272.     }
  273.     return true;
  274. } // enf of the 'checkTableEditForm()' function
  275.  
  276.  
  277. /**
  278.  * Ensures the choice between 'transmit', 'zipped', 'gzipped' and 'bzipped'
  279.  * checkboxes is consistant
  280.  *
  281.  * @param   object   the form
  282.  * @param   string   a code for the action that causes this function to be run
  283.  *
  284.  * @return  boolean  always true
  285.  */
  286. function checkTransmitDump(theForm, theAction)
  287. {
  288.     var formElts = theForm.elements;
  289.  
  290.     // 'zipped' option has been checked
  291.     if (theAction == 'zip' && formElts['zip'].checked) {
  292.         if (!formElts['asfile'].checked) {
  293.             theForm.elements['asfile'].checked = true;
  294.         }
  295.         if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) {
  296.             theForm.elements['gzip'].checked = false;
  297.         }
  298.         if (typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked) {
  299.             theForm.elements['bzip'].checked = false;
  300.         }
  301.     }
  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;
  306.         }
  307.         if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
  308.             theForm.elements['zip'].checked = false;
  309.         }
  310.         if (typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked) {
  311.             theForm.elements['bzip'].checked = false;
  312.         }
  313.     }
  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;
  318.         }
  319.         if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
  320.             theForm.elements['zip'].checked = false;
  321.         }
  322.         if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) {
  323.             theForm.elements['gzip'].checked = false;
  324.         }
  325.     }
  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;
  330.         }
  331.         if ((typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked)) {
  332.             theForm.elements['gzip'].checked = false;
  333.         }
  334.         if ((typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked)) {
  335.             theForm.elements['bzip'].checked = false;
  336.         }
  337.     }
  338.  
  339.     return true;
  340. } // end of the 'checkTransmitDump()' function
  341.  
  342.  
  343. /**
  344.  * This array is used to remember mark status of rows in browse mode
  345.  */
  346. var marked_row = new Array;
  347.  
  348.  
  349. /**
  350.  * Sets/unsets the pointer and marker in browse mode
  351.  *
  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
  358.  *
  359.  * @return  boolean  whether pointer is set or not
  360.  */
  361. function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
  362. {
  363.     var theCells = null;
  364.  
  365.     // 1. Pointer and mark feature are disabled or the browser can't get the
  366.     //    row -> exits
  367.     if ((thePointerColor == '' && theMarkColor == '')
  368.         || typeof(theRow.style) == 'undefined') {
  369.         return false;
  370.     }
  371.  
  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');
  375.     }
  376.     else if (typeof(theRow.cells) != 'undefined') {
  377.         theCells = theRow.cells;
  378.     }
  379.     else {
  380.         return false;
  381.     }
  382.  
  383.     // 3. Gets the current color...
  384.     var rowCellsCnt  = theCells.length;
  385.     var domDetect    = null;
  386.     var currentColor = null;
  387.     var newColor     = 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');
  393.         domDetect    = true;
  394.     }
  395.     // 3.2 ... with other browsers
  396.     else {
  397.         currentColor = theCells[0].style.backgroundColor;
  398.         domDetect    = false;
  399.     } // end 3
  400.  
  401.     // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
  402.     if (currentColor.indexOf("rgb") >= 0) 
  403.     {
  404.         var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
  405.                                      currentColor.indexOf(')'));
  406.         var rgbValues = rgbStr.split(",");
  407.         currentColor = "#";
  408.         var hexChars = "0123456789ABCDEF";
  409.         for (var i = 0; i < 3; i++)
  410.         {
  411.             var v = rgbValues[i].valueOf();
  412.             currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
  413.         }
  414.     }
  415.  
  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;
  422.         }
  423.         else if (theAction == 'click' && theMarkColor != '') {
  424.             newColor              = theMarkColor;
  425.             marked_row[theRowNum] = true;
  426.             // Garvin: deactivated onclick marking of the checkbox because it's also executed
  427.             // when an action (like edit/delete) on a single item is performed. Then the checkbox
  428.             // would get deactived, even though we need it activated. Maybe there is a way
  429.             // to detect if the row was clicked, and not an item therein...
  430.             // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
  431.         }
  432.     }
  433.     // 4.1.2 Current color is the pointer one
  434.     else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
  435.              && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
  436.         if (theAction == 'out') {
  437.             newColor              = theDefaultColor;
  438.         }
  439.         else if (theAction == 'click' && theMarkColor != '') {
  440.             newColor              = theMarkColor;
  441.             marked_row[theRowNum] = true;
  442.             // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
  443.         }
  444.     }
  445.     // 4.1.3 Current color is the marker one
  446.     else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
  447.         if (theAction == 'click') {
  448.             newColor              = (thePointerColor != '')
  449.                                   ? thePointerColor
  450.                                   : theDefaultColor;
  451.             marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
  452.                                   ? true
  453.                                   : null;
  454.             // document.getElementById('id_rows_to_delete' + theRowNum).checked = false;
  455.         }
  456.     } // end 4
  457.  
  458.     // 5. Sets the new color...
  459.     if (newColor) {
  460.         var c = null;
  461.         // 5.1 ... with DOM compatible browsers except Opera
  462.         if (domDetect) {
  463.             for (c = 0; c < rowCellsCnt; c++) {
  464.                 theCells[c].setAttribute('bgcolor', newColor, 0);
  465.             } // end for
  466.         }
  467.         // 5.2 ... with other browsers
  468.         else {
  469.             for (c = 0; c < rowCellsCnt; c++) {
  470.                 theCells[c].style.backgroundColor = newColor;
  471.             }
  472.         }
  473.     } // end 5
  474.  
  475.     return true;
  476. } // end of the 'setPointer()' function
  477.  
  478. /*
  479.  * Sets/unsets the pointer and marker in vertical browse mode
  480.  *
  481.  * @param   object    the table row
  482.  * @param   interger  the row number
  483.  * @param   string    the action calling this script (over, out or click)
  484.  * @param   string    the default background color
  485.  * @param   string    the color to use for mouseover
  486.  * @param   string    the color to use for marking a row
  487.  *
  488.  * @return  boolean  whether pointer is set or not
  489.  *
  490.  * @author Garvin Hicking <me@supergarv.de> (rewrite of setPointer.)
  491.  */
  492. function setVerticalPointer(theRow, theRowNum, theAction, theDefaultColor1, theDefaultColor2, thePointerColor, theMarkColor) {
  493.     var theCells = null;
  494.  
  495.     // 1. Pointer and mark feature are disabled or the browser can't get the
  496.     //    row -> exits
  497.     if ((thePointerColor == '' && theMarkColor == '')
  498.         || typeof(theRow.style) == 'undefined') {
  499.         return false;
  500.     }
  501.  
  502.     // 2. Gets the current row and exits if the browser can't get it
  503.     if (typeof(document.getElementsByTagName) != 'undefined') {
  504.         theCells = theRow.getElementsByTagName('td');
  505.     }
  506.     else if (typeof(theRow.cells) != 'undefined') {
  507.         theCells = theRow.cells;
  508.     }
  509.     else {
  510.         return false;
  511.     }
  512.  
  513.     // 3. Gets the current color...
  514.     var rowCellsCnt  = theCells.length;
  515.     var domDetect    = null;
  516.     var currentColor = null;
  517.     var newColor     = null;
  518.  
  519.     // 3.1 ... with DOM compatible browsers except Opera that does not return
  520.     //         valid values with "getAttribute"
  521.     if (typeof(window.opera) == 'undefined'
  522.         && typeof(theCells[0].getAttribute) != 'undefined') {
  523.         currentColor = theCells[0].getAttribute('bgcolor');
  524.         domDetect    = true;
  525.     }
  526.     // 3.2 ... with other browsers
  527.     else {
  528.         domDetect    = false;
  529.     } // end 3
  530.  
  531.     var c = null;
  532.     // 5.1 ... with DOM compatible browsers except Opera
  533.     for (c = 0; c < rowCellsCnt; c++) {
  534.         if (domDetect) {
  535.             currentColor = theCells[c].getAttribute('bgcolor');
  536.         } else {
  537.             currentColor = theCells[c].style.backgroundColor;
  538.         }
  539.  
  540.         // 4. Defines the new color
  541.         // 4.1 Current color is the default one
  542.         if (currentColor == ''
  543.             || currentColor.toLowerCase() == theDefaultColor1.toLowerCase()
  544.             || currentColor.toLowerCase() == theDefaultColor2.toLowerCase()) {
  545.             if (theAction == 'over' && thePointerColor != '') {
  546.                 newColor              = thePointerColor;
  547.             } else if (theAction == 'click' && theMarkColor != '') {
  548.                 newColor              = theMarkColor;
  549.                 marked_row[theRowNum] = true;
  550.             }
  551.         }
  552.         // 4.1.2 Current color is the pointer one
  553.         else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
  554.                  && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
  555.             if (theAction == 'out') {
  556.                 if (c % 2) {
  557.                     newColor              = theDefaultColor1;
  558.                 } else {
  559.                     newColor              = theDefaultColor2;
  560.                 }
  561.             }
  562.             else if (theAction == 'click' && theMarkColor != '') {
  563.                 newColor              = theMarkColor;
  564.                 marked_row[theRowNum] = true;
  565.             }
  566.         }
  567.         // 4.1.3 Current color is the marker one
  568.         else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
  569.             if (theAction == 'click') {
  570.                 newColor              = (thePointerColor != '')
  571.                                       ? thePointerColor
  572.                                       : ((c % 2) ? theDefaultColor1 : theDefaultColor2);
  573.                 marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
  574.                                       ? true
  575.                                       : null;
  576.             }
  577.         } // end 4
  578.  
  579.         // 5. Sets the new color...
  580.         if (newColor) {
  581.             if (domDetect) {
  582.                 theCells[c].setAttribute('bgcolor', newColor, 0);
  583.             }
  584.             // 5.2 ... with other browsers
  585.             else {
  586.                 theCells[c].style.backgroundColor = newColor;
  587.             }
  588.         } // end 5
  589.     } // end for
  590.  
  591.      return true;
  592.  } // end of the 'setVerticalPointer()' function
  593.  
  594. /**
  595.  * Checks/unchecks all tables
  596.  *
  597.  * @param   string   the form name
  598.  * @param   boolean  whether to check or to uncheck the element
  599.  *
  600.  * @return  boolean  always true
  601.  */
  602. function setCheckboxes(the_form, do_check)
  603. {
  604.     var elts      = (typeof(document.forms[the_form].elements['selected_db[]']) != 'undefined')
  605.                   ? document.forms[the_form].elements['selected_db[]']
  606.                   : (typeof(document.forms[the_form].elements['selected_tbl[]']) != 'undefined')
  607.           ? document.forms[the_form].elements['selected_tbl[]']
  608.           : document.forms[the_form].elements['selected_fld[]'];
  609.     var elts_cnt  = (typeof(elts.length) != 'undefined')
  610.                   ? elts.length
  611.                   : 0;
  612.  
  613.     if (elts_cnt) {
  614.         for (var i = 0; i < elts_cnt; i++) {
  615.             elts[i].checked = do_check;
  616.         } // end for
  617.     } else {
  618.         elts.checked        = do_check;
  619.     } // end if... else
  620.  
  621.     return true;
  622. } // end of the 'setCheckboxes()' function
  623.  
  624.  
  625. /**
  626.   * Checks/unchecks all options of a <select> element
  627.   *
  628.   * @param   string   the form name
  629.   * @param   string   the element name
  630.   * @param   boolean  whether to check or to uncheck the element
  631.   *
  632.   * @return  boolean  always true
  633.   */
  634. function setSelectOptions(the_form, the_select, do_check)
  635. {
  636.     var selectObject = document.forms[the_form].elements[the_select];
  637.     var selectCount  = selectObject.length;
  638.  
  639.     for (var i = 0; i < selectCount; i++) {
  640.         selectObject.options[i].selected = do_check;
  641.     } // end for
  642.  
  643.     return true;
  644. } // end of the 'setSelectOptions()' function
  645.  
  646. /**
  647.   * Allows moving around inputs/select by Ctrl+arrows
  648.   *
  649.   * @param   object   event data
  650.   */
  651. function onKeyDownArrowsHandler(e) {
  652.     e = e||window.event;
  653.     var o = (e.srcElement||e.target);
  654.     if (!o) return;
  655.     if (o.tagName != "TEXTAREA" && o.tagName != "INPUT" && o.tagName != "SELECT") return;
  656.     if (!e.ctrlKey) return;
  657.     if (!o.id) return;
  658.  
  659.     var pos = o.id.split("_");
  660.     if (pos[0] != "field" || typeof pos[2] == "undefined") return;
  661.  
  662.     var x = pos[2], y=pos[1];
  663.  
  664.     // skip non existent fields
  665.     for (i=0; i<10; i++)
  666.     {
  667.         switch(e.keyCode) {
  668.             case 38: y--; break; // up
  669.             case 40: y++; break; // down
  670.             case 37: x--; break; // left
  671.             case 39: x++; break; // right
  672.             default: return;
  673.         }
  674.  
  675.         var id = "field_" + y + "_" + x;
  676.         var nO = document.getElementById(id);
  677.         if (nO) break;
  678.     }
  679.  
  680.     if (!nO) return;
  681.     nO.focus();
  682.     if (nO.tagName != 'SELECT') {
  683.         nO.select();
  684.     }
  685.     e.returnValue = false;
  686. }
  687.  
  688. /**
  689.   * Inserts multiple fields.
  690.   *
  691.   */
  692. function insertValueQuery() {
  693.     var myQuery = document.sqlform.sql_query;
  694.     var myListBox = document.sqlform.dummy;
  695.  
  696.     if(myListBox.options.length > 0) {
  697.         var chaineAj = "";
  698.         var NbSelect = 0;
  699.         for(var i=0; i<myListBox.options.length; i++) {
  700.             if (myListBox.options[i].selected){
  701.                 NbSelect++;
  702.                 if (NbSelect > 1)
  703.                     chaineAj += ", ";
  704.                 chaineAj += myListBox.options[i].value;
  705.             }
  706.         }
  707.  
  708.         //IE support
  709.         if (document.selection) {
  710.             myQuery.focus();
  711.             sel = document.selection.createRange();
  712.             sel.text = chaineAj;
  713.             document.sqlform.insert.focus();
  714.         }
  715.         //MOZILLA/NETSCAPE support
  716.         else if (document.sqlform.sql_query.selectionStart || document.sqlform.sql_query.selectionStart == "0") {
  717.             var startPos = document.sqlform.sql_query.selectionStart;
  718.             var endPos = document.sqlform.sql_query.selectionEnd;
  719.             var chaineSql = document.sqlform.sql_query.value;
  720.  
  721.             myQuery.value = chaineSql.substring(0, startPos) + chaineAj + chaineSql.substring(endPos, chaineSql.length);
  722.         } else {
  723.             myQuery.value += chaineAj;
  724.         }
  725.     }
  726. }
  727.  
  728. /**
  729.   * listbox redirection
  730.   */
  731. function goToUrl(selObj, goToLocation){
  732.     eval("document.location.href = '" + goToLocation + "pos=" + selObj.options[selObj.selectedIndex].value + "'");
  733. }
  734.  
  735. /**
  736.  * getElement
  737.  */
  738. function getElement(e,f){
  739.     if(document.layers){
  740.         f=(f)?f:self;
  741.         if(f.document.layers[e]) {
  742.             return f.document.layers[e];
  743.         }
  744.         for(W=0;i<f.document.layers.length;W++) {
  745.             return(getElement(e,fdocument.layers[W]));
  746.         }
  747.     }
  748.     if(document.all) {
  749.         return document.all[e];
  750.     }
  751.     return document.getElementById(e);
  752. }
  753.  
  754. /**
  755.   * Refresh the WYSIWYG-PDF scratchboard after changes have been made
  756.   */
  757. function refreshDragOption(e) {
  758.     myid = getElement(e);
  759.     if (myid.style.visibility == 'visible') {
  760.         refreshLayout();
  761.     }
  762. }
  763.  
  764. /**
  765.   * Refresh/resize the WYSIWYG-PDF scratchboard
  766.   */
  767. function refreshLayout() {
  768.         myid = getElement('pdflayout');
  769.  
  770.         if (document.pdfoptions.orientation.value == 'P') {
  771.             posa = 'x';
  772.             posb = 'y';
  773.         } else {
  774.             posa = 'y';
  775.             posb = 'x';
  776.         }
  777.  
  778.         myid.style.width = pdfPaperSize(document.pdfoptions.paper.value, posa) + 'px';
  779.         myid.style.height = pdfPaperSize(document.pdfoptions.paper.value, posb) + 'px';
  780. }
  781.  
  782. /**
  783.   * Show/hide the WYSIWYG-PDF scratchboard
  784.   */
  785. function ToggleDragDrop(e) {
  786.     myid = getElement(e);
  787.  
  788.     if (myid.style.visibility == 'hidden') {
  789.         init();
  790.         myid.style.visibility = 'visible';
  791.         myid.style.display = 'block';
  792.         document.edcoord.showwysiwyg.value = '1';
  793.     } else {
  794.         myid.style.visibility = 'hidden';
  795.         myid.style.display = 'none';
  796.         document.edcoord.showwysiwyg.value = '0';
  797.     }
  798. }
  799.  
  800. /**
  801.   * PDF scratchboard: When a position is entered manually, update
  802.   * the fields inside the scratchboard.
  803.   */
  804. function dragPlace(no, axis, value) {
  805.     if (axis == 'x') {
  806.         getElement("table_" + no).style.left = value + 'px';
  807.     } else {
  808.         getElement("table_" + no).style.top  = value + 'px';
  809.     }
  810. }
  811.  
  812. /**
  813.   * Returns paper sizes for a given format
  814.   */
  815. function pdfPaperSize(format, axis) {
  816.     switch (format.toUpperCase()) {
  817.         case '4A0':
  818.             if (axis == 'x') return 4767.87; else return 6740.79;
  819.             break;
  820.         case '2A0':
  821.             if (axis == 'x') return 3370.39; else return 4767.87;
  822.             break;
  823.         case 'A0':
  824.             if (axis == 'x') return 2383.94; else return 3370.39;
  825.             break;
  826.         case 'A1':
  827.             if (axis == 'x') return 1683.78; else return 2383.94;
  828.             break;
  829.         case 'A2':
  830.             if (axis == 'x') return 1190.55; else return 1683.78;
  831.             break;
  832.         case 'A3':
  833.             if (axis == 'x') return 841.89; else return 1190.55;
  834.             break;
  835.         case 'A4':
  836.             if (axis == 'x') return 595.28; else return 841.89;
  837.             break;
  838.         case 'A5':
  839.             if (axis == 'x') return 419.53; else return 595.28;
  840.             break;
  841.         case 'A6':
  842.             if (axis == 'x') return 297.64; else return 419.53;
  843.             break;
  844.         case 'A7':
  845.             if (axis == 'x') return 209.76; else return 297.64;
  846.             break;
  847.         case 'A8':
  848.             if (axis == 'x') return 147.40; else return 209.76;
  849.             break;
  850.         case 'A9':
  851.             if (axis == 'x') return 104.88; else return 147.40;
  852.             break;
  853.         case 'A10':
  854.             if (axis == 'x') return 73.70; else return 104.88;
  855.             break;
  856.         case 'B0':
  857.             if (axis == 'x') return 2834.65; else return 4008.19;
  858.             break;
  859.         case 'B1':
  860.             if (axis == 'x') return 2004.09; else return 2834.65;
  861.             break;
  862.         case 'B2':
  863.             if (axis == 'x') return 1417.32; else return 2004.09;
  864.             break;
  865.         case 'B3':
  866.             if (axis == 'x') return 1000.63; else return 1417.32;
  867.             break;
  868.         case 'B4':
  869.             if (axis == 'x') return 708.66; else return 1000.63;
  870.             break;
  871.         case 'B5':
  872.             if (axis == 'x') return 498.90; else return 708.66;
  873.             break;
  874.         case 'B6':
  875.             if (axis == 'x') return 354.33; else return 498.90;
  876.             break;
  877.         case 'B7':
  878.             if (axis == 'x') return 249.45; else return 354.33;
  879.             break;
  880.         case 'B8':
  881.             if (axis == 'x') return 175.75; else return 249.45;
  882.             break;
  883.         case 'B9':
  884.             if (axis == 'x') return 124.72; else return 175.75;
  885.             break;
  886.         case 'B10':
  887.             if (axis == 'x') return 87.87; else return 124.72;
  888.             break;
  889.         case 'C0':
  890.             if (axis == 'x') return 2599.37; else return 3676.54;
  891.             break;
  892.         case 'C1':
  893.             if (axis == 'x') return 1836.85; else return 2599.37;
  894.             break;
  895.         case 'C2':
  896.             if (axis == 'x') return 1298.27; else return 1836.85;
  897.             break;
  898.         case 'C3':
  899.             if (axis == 'x') return 918.43; else return 1298.27;
  900.             break;
  901.         case 'C4':
  902.             if (axis == 'x') return 649.13; else return 918.43;
  903.             break;
  904.         case 'C5':
  905.             if (axis == 'x') return 459.21; else return 649.13;
  906.             break;
  907.         case 'C6':
  908.             if (axis == 'x') return 323.15; else return 459.21;
  909.             break;
  910.         case 'C7':
  911.             if (axis == 'x') return 229.61; else return 323.15;
  912.             break;
  913.         case 'C8':
  914.             if (axis == 'x') return 161.57; else return 229.61;
  915.             break;
  916.         case 'C9':
  917.             if (axis == 'x') return 113.39; else return 161.57;
  918.             break;
  919.         case 'C10':
  920.             if (axis == 'x') return 79.37; else return 113.39;
  921.             break;
  922.         case 'RA0':
  923.             if (axis == 'x') return 2437.80; else return 3458.27;
  924.             break;
  925.         case 'RA1':
  926.             if (axis == 'x') return 1729.13; else return 2437.80;
  927.             break;
  928.         case 'RA2':
  929.             if (axis == 'x') return 1218.90; else return 1729.13;
  930.             break;
  931.         case 'RA3':
  932.             if (axis == 'x') return 864.57; else return 1218.90;
  933.             break;
  934.         case 'RA4':
  935.             if (axis == 'x') return 609.45; else return 864.57;
  936.             break;
  937.         case 'SRA0':
  938.             if (axis == 'x') return 2551.18; else return 3628.35;
  939.             break;
  940.         case 'SRA1':
  941.             if (axis == 'x') return 1814.17; else return 2551.18;
  942.             break;
  943.         case 'SRA2':
  944.             if (axis == 'x') return 1275.59; else return 1814.17;
  945.             break;
  946.         case 'SRA3':
  947.             if (axis == 'x') return 907.09; else return 1275.59;
  948.             break;
  949.         case 'SRA4':
  950.             if (axis == 'x') return 637.80; else return 907.09;
  951.             break;
  952.         case 'LETTER':
  953.             if (axis == 'x') return 612.00; else return 792.00;
  954.             break;
  955.         case 'LEGAL':
  956.             if (axis == 'x') return 612.00; else return 1008.00;
  957.             break;
  958.         case 'EXECUTIVE':
  959.             if (axis == 'x') return 521.86; else return 756.00;
  960.             break;
  961.         case 'FOLIO':
  962.             if (axis == 'x') return 612.00; else return 936.00;
  963.             break;
  964.     } // end switch
  965. }
  966.