home *** CD-ROM | disk | FTP | other *** search
/ Freelog 70 / Freelog070.iso / Internet / EasyPHP / easyphp1-8_setup.exe / {app} / phpmyadmin / libraries / functions.js < prev    next >
Encoding:
JavaScript  |  2005-01-07  |  34.5 KB  |  1,026 lines

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