home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / phpMyAdmin / js / functions.js < prev    next >
Encoding:
JavaScript  |  2008-06-23  |  39.9 KB  |  1,220 lines

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