patch #2561433 [structure] Display true number of rows in a view if it contains less...
[phpmyadmin/crack.git] / js / functions.js
blobbf1b5913cea1686fb2b14705456b9b575f1f27f8
1 /* vim: set expandtab sw=4 ts=4 sts=4: */
2 /**
3  * general function, usally for data manipulation pages
4  *
5  * @version $Id$
6  */
8 /**
9  * @var sql_box_locked lock for the sqlbox textarea in the querybox/querywindow
10  */
11 var sql_box_locked = false;
13 /**
14  * @var array holds elements which content should only selected once
15  */
16 var only_once_elements = new Array();
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     }
32     only_once_elements[element.name] = true;
34     if ( lock  ) {
35         return;
36     }
38     element.select();
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)
52     // Confirmation is not required in the configuration file
53     // or browser is Opera (crappy js implementation)
54     if (PMA_messages['strDoYouReally'] == '' || typeof(window.opera) != 'undefined') {
55         return true;
56     }
58     var is_confirmed = confirm(PMA_messages['strDropDatabaseStrongWarning'] + '\n' + PMA_messages['strDoYouReally'] + ' :\n' + theSqlQuery);
59     if (is_confirmed) {
60         theLink.href += '&is_js_confirmed=1';
61     }
63     return is_confirmed;
64 } // end of the 'confirmLinkDropDB()' function
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)
77     // Confirmation is not required in the configuration file
78     // or browser is Opera (crappy js implementation)
79     if (PMA_messages['strDoYouReally'] == '' || typeof(window.opera) != 'undefined') {
80         return true;
81     }
83     var is_confirmed = confirm(PMA_messages['strDoYouReally'] + ' :\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     }
92     return is_confirmed;
93 } // end of the 'confirmLink()' function
96 /**
97  * Displays an confirmation box before doing some action
98  *
99  * @param   object   the message to display
101  * @return  boolean  whether to run the query or not
102  */
103 function confirmAction(theMessage)
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     }
111     var is_confirmed = confirm(theMessage);
113     return is_confirmed;
114 } // end of the 'confirmAction()' function
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.
123  * @param   object   the form
124  * @param   object   the sql query textarea
126  * @return  boolean  whether to run the query or not
128  * @see     checkSqlQuery()
129  */
130 function confirmQuery(theForm1, sqlQuery1)
132     // Confirmation is not required in the configuration file
133     if (PMA_messages['strDoYouReally'] == '') {
134         return true;
135     }
137     // The replace function (js1.2) isn't supported
138     else if (typeof(sqlQuery1.value.replace) == 'undefined') {
139         return true;
140     }
142     // js1.2+ -> validation with regular expressions
143     else {
144         // "DROP DATABASE" statement isn't allowed
145         if (PMA_messages['strNoDropDatabases'] != '') {
146             var drop_re = new RegExp('(^|;)\\s*DROP\\s+(IF EXISTS\\s+)?DATABASE\\s', 'i');
147             if (drop_re.test(sqlQuery1.value)) {
148                 alert(PMA_messages['strNoDropDatabases']);
149                 theForm1.reset();
150                 sqlQuery1.focus();
151                 return false;
152             } // end if
153         } // end if
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
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(PMA_messages['strDoYouReally'] + ' :\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
189     return true;
190 } // end of the 'confirmQuery()' function
194  * Displays a confirmation box before disabling the BLOB repository for a given database.
195  * This function is called while clicking links
197  * @param   object   the database 
199  * @return  boolean  whether to disable the repository or not
200  */
201 function confirmDisableRepository(theDB)
203     // Confirmation is not required in the configuration file
204     // or browser is Opera (crappy js implementation)
205     if (PMA_messages['strDoYouReally'] == '' || typeof(window.opera) != 'undefined') {
206         return true;
207     }
209     var is_confirmed = confirm(PMA_messages['strBLOBRepositoryDisableStrongWarning'] + '\n' + PMA_messages['strBLOBRepositoryDisableAreYouSure']);
211     return is_confirmed;
212 } // end of the 'confirmDisableBLOBRepository()' function
216  * Displays an error message if the user submitted the sql query form with no
217  * sql query, else checks for "DROP/DELETE/ALTER" statements
219  * @param   object   the form
221  * @return  boolean  always false
223  * @see     confirmQuery()
224  */
225 function checkSqlQuery(theForm)
227     var sqlQuery = theForm.elements['sql_query'];
228     var isEmpty  = 1;
230     // The replace function (js1.2) isn't supported -> basic tests
231     if (typeof(sqlQuery.value.replace) == 'undefined') {
232         isEmpty      = (sqlQuery.value == '') ? 1 : 0;
233         if (isEmpty && typeof(theForm.elements['sql_file']) != 'undefined') {
234             isEmpty  = (theForm.elements['sql_file'].value == '') ? 1 : 0;
235         }
236         if (isEmpty && typeof(theForm.elements['sql_localfile']) != 'undefined') {
237             isEmpty  = (theForm.elements['sql_localfile'].value == '') ? 1 : 0;
238         }
239         if (isEmpty && typeof(theForm.elements['id_bookmark']) != 'undefined') {
240             isEmpty  = (theForm.elements['id_bookmark'].value == null || theForm.elements['id_bookmark'].value == '');
241         }
242     }
243     // js1.2+ -> validation with regular expressions
244     else {
245         var space_re = new RegExp('\\s+');
246         if (typeof(theForm.elements['sql_file']) != 'undefined' &&
247                 theForm.elements['sql_file'].value.replace(space_re, '') != '') {
248             return true;
249         }
250         if (typeof(theForm.elements['sql_localfile']) != 'undefined' &&
251                 theForm.elements['sql_localfile'].value.replace(space_re, '') != '') {
252             return true;
253         }
254         if (isEmpty && typeof(theForm.elements['id_bookmark']) != 'undefined' &&
255                 (theForm.elements['id_bookmark'].value != null || theForm.elements['id_bookmark'].value != '') &&
256                 theForm.elements['id_bookmark'].selectedIndex != 0
257                 ) {
258             return true;
259         }
260         // Checks for "DROP/DELETE/ALTER" statements
261         if (sqlQuery.value.replace(space_re, '') != '') {
262             if (confirmQuery(theForm, sqlQuery)) {
263                 return true;
264             } else {
265                 return false;
266             }
267         }
268         theForm.reset();
269         isEmpty = 1;
270     }
272     if (isEmpty) {
273         sqlQuery.select();
274         alert(PMA_messages['strFormEmpty']);
275         sqlQuery.focus();
276         return false;
277     }
279     return true;
280 } // end of the 'checkSqlQuery()' function
284  * Check if a form's element is empty
285  * should be
287  * @param   object   the form
288  * @param   string   the name of the form field to put the focus on
290  * @return  boolean  whether the form field is empty or not
291  */
292 function emptyCheckTheField(theForm, theFieldName)
294     var isEmpty  = 1;
295     var theField = theForm.elements[theFieldName];
296     // Whether the replace function (js1.2) is supported or not
297     var isRegExp = (typeof(theField.value.replace) != 'undefined');
299     if (!isRegExp) {
300         isEmpty      = (theField.value == '') ? 1 : 0;
301     } else {
302         var space_re = new RegExp('\\s+');
303         isEmpty      = (theField.value.replace(space_re, '') == '') ? 1 : 0;
304     }
306     return isEmpty;
307 } // end of the 'emptyCheckTheField()' function
311  * Displays an error message if an element of a form hasn't been completed and
312  * should be
314  * @param   object   the form
315  * @param   string   the name of the form field to put the focus on
317  * @return  boolean  whether the form field is empty or not
318  */
319 function emptyFormElements(theForm, theFieldName)
321     var theField = theForm.elements[theFieldName];
322     var isEmpty = emptyCheckTheField(theForm, theFieldName);
324     if (isEmpty) {
325         theForm.reset();
326         theField.select();
327         alert(PMA_messages['strFormEmpty']);
328         theField.focus();
329         return false;
330     }
332     return true;
333 } // end of the 'emptyFormElements()' function
337  * Ensures a value submitted in a form is numeric and is in a range
339  * @param   object   the form
340  * @param   string   the name of the form field to check
341  * @param   integer  the minimum authorized value
342  * @param   integer  the maximum authorized value
344  * @return  boolean  whether a valid number has been submitted or not
345  */
346 function checkFormElementInRange(theForm, theFieldName, message, min, max)
348     var theField         = theForm.elements[theFieldName];
349     var val              = parseInt(theField.value);
351     if (typeof(min) == 'undefined') {
352         min = 0;
353     }
354     if (typeof(max) == 'undefined') {
355         max = Number.MAX_VALUE;
356     }
358     // It's not a number
359     if (isNaN(val)) {
360         theField.select();
361         alert(PMA_messages['strNotNumber']);
362         theField.focus();
363         return false;
364     }
365     // It's a number but it is not between min and max
366     else if (val < min || val > max) {
367         theField.select();
368         alert(message.replace('%d', val));
369         theField.focus();
370         return false;
371     }
372     // It's a valid number
373     else {
374         theField.value = val;
375     }
376     return true;
378 } // end of the 'checkFormElementInRange()' function
381 function checkTableEditForm(theForm, fieldsCnt)
383     // TODO: avoid sending a message if user just wants to add a line
384     // on the form but has not completed at least one field name
386     var atLeastOneField = 0;
387     var i, elm, elm2, elm3, val, id;
389     for (i=0; i<fieldsCnt; i++)
390     {
391         id = "field_" + i + "_2";
392         elm = getElement(id);
393         if (elm.value == 'VARCHAR' || elm.value == 'CHAR' || elm.value == 'BIT') {
394             elm2 = getElement("field_" + i + "_3");
395             val = parseInt(elm2.value);
396             elm3 = getElement("field_" + i + "_1");
397             if (isNaN(val) && elm3.value != "") {
398                 elm2.select();
399                 alert(PMA_messages['strNotNumber']);
400                 elm2.focus();
401                 return false;
402             }
403         }
405         if (atLeastOneField == 0) {
406             id = "field_" + i + "_1";
407             if (!emptyCheckTheField(theForm, id)) {
408                 atLeastOneField = 1;
409             }
410         }
411     }
412     if (atLeastOneField == 0) {
413         var theField = theForm.elements["field_0_1"];
414         alert(PMA_messages['strFormEmpty']);
415         theField.focus();
416         return false;
417     }
419     return true;
420 } // enf of the 'checkTableEditForm()' function
424  * Ensures the choice between 'transmit', 'zipped', 'gzipped' and 'bzipped'
425  * checkboxes is consistant
427  * @param   object   the form
428  * @param   string   a code for the action that causes this function to be run
430  * @return  boolean  always true
431  */
432 function checkTransmitDump(theForm, theAction)
434     var formElts = theForm.elements;
436     // 'zipped' option has been checked
437     if (theAction == 'zip' && formElts['zip'].checked) {
438         if (!formElts['asfile'].checked) {
439             theForm.elements['asfile'].checked = true;
440         }
441         if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) {
442             theForm.elements['gzip'].checked = false;
443         }
444         if (typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked) {
445             theForm.elements['bzip'].checked = false;
446         }
447     }
448     // 'gzipped' option has been checked
449     else if (theAction == 'gzip' && formElts['gzip'].checked) {
450         if (!formElts['asfile'].checked) {
451             theForm.elements['asfile'].checked = true;
452         }
453         if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
454             theForm.elements['zip'].checked = false;
455         }
456         if (typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked) {
457             theForm.elements['bzip'].checked = false;
458         }
459     }
460     // 'bzipped' option has been checked
461     else if (theAction == 'bzip' && formElts['bzip'].checked) {
462         if (!formElts['asfile'].checked) {
463             theForm.elements['asfile'].checked = true;
464         }
465         if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
466             theForm.elements['zip'].checked = false;
467         }
468         if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) {
469             theForm.elements['gzip'].checked = false;
470         }
471     }
472     // 'transmit' option has been unchecked
473     else if (theAction == 'transmit' && !formElts['asfile'].checked) {
474         if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
475             theForm.elements['zip'].checked = false;
476         }
477         if ((typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked)) {
478             theForm.elements['gzip'].checked = false;
479         }
480         if ((typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked)) {
481             theForm.elements['bzip'].checked = false;
482         }
483     }
485     return true;
486 } // end of the 'checkTransmitDump()' function
490  * This array is used to remember mark status of rows in browse mode
491  */
492 var marked_row = new Array;
495  * enables highlight and marking of rows in data tables
497  */
498 function PMA_markRowsInit() {
499     // for every table row ...
500     var rows = document.getElementsByTagName('tr');
501     for ( var i = 0; i < rows.length; i++ ) {
502         // ... with the class 'odd' or 'even' ...
503         if ( 'odd' != rows[i].className.substr(0,3) && 'even' != rows[i].className.substr(0,4) ) {
504             continue;
505         }
506         // ... add event listeners ...
507         // ... to highlight the row on mouseover ...
508         if ( navigator.appName == 'Microsoft Internet Explorer' ) {
509             // but only for IE, other browsers are handled by :hover in css
510             rows[i].onmouseover = function() {
511                 this.className += ' hover';
512             }
513             rows[i].onmouseout = function() {
514                 this.className = this.className.replace( ' hover', '' );
515             }
516         }
517         // Do not set click events if not wanted
518         if (rows[i].className.search(/noclick/) != -1) {
519             continue;
520         }
521         // ... and to mark the row on click ...
522         rows[i].onmousedown = function() {
523             var unique_id;
524             var checkbox;
526             checkbox = this.getElementsByTagName( 'input' )[0];
527             if ( checkbox && checkbox.type == 'checkbox' ) {
528                 unique_id = checkbox.name + checkbox.value;
529             } else if ( this.id.length > 0 ) {
530                 unique_id = this.id;
531             } else {
532                 return;
533             }
535             if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] ) {
536                 marked_row[unique_id] = true;
537             } else {
538                 marked_row[unique_id] = false;
539             }
541             if ( marked_row[unique_id] ) {
542                 this.className += ' marked';
543             } else {
544                 this.className = this.className.replace(' marked', '');
545             }
547             if ( checkbox && checkbox.disabled == false ) {
548                 checkbox.checked = marked_row[unique_id];
549             }
550         }
552         // ... and disable label ...
553         var labeltag = rows[i].getElementsByTagName('label')[0];
554         if ( labeltag ) {
555             labeltag.onclick = function() {
556                 return false;
557             }
558         }
559         // .. and checkbox clicks
560         var checkbox = rows[i].getElementsByTagName('input')[0];
561         if ( checkbox ) {
562             checkbox.onclick = function() {
563                 // opera does not recognize return false;
564                 this.checked = ! this.checked;
565             }
566         }
567     }
569 window.onload=PMA_markRowsInit;
572  * marks all rows and selects its first checkbox inside the given element
573  * the given element is usaly a table or a div containing the table or tables
575  * @param    container    DOM element
576  */
577 function markAllRows( container_id ) {
578     var rows = document.getElementById(container_id).getElementsByTagName('tr');
579     var unique_id;
580     var checkbox;
582     for ( var i = 0; i < rows.length; i++ ) {
584         checkbox = rows[i].getElementsByTagName( 'input' )[0];
586         if ( checkbox && checkbox.type == 'checkbox' ) {
587             unique_id = checkbox.name + checkbox.value;
588             if ( checkbox.disabled == false ) {
589                 checkbox.checked = true;
590                 if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] ) {
591                     rows[i].className += ' marked';
592                     marked_row[unique_id] = true;
593                 }
594             }
595         }
596     }
598     return true;
602  * marks all rows and selects its first checkbox inside the given element
603  * the given element is usaly a table or a div containing the table or tables
605  * @param    container    DOM element
606  */
607 function unMarkAllRows( container_id ) {
608     var rows = document.getElementById(container_id).getElementsByTagName('tr');
609     var unique_id;
610     var checkbox;
612     for ( var i = 0; i < rows.length; i++ ) {
614         checkbox = rows[i].getElementsByTagName( 'input' )[0];
616         if ( checkbox && checkbox.type == 'checkbox' ) {
617             unique_id = checkbox.name + checkbox.value;
618             checkbox.checked = false;
619             rows[i].className = rows[i].className.replace(' marked', '');
620             marked_row[unique_id] = false;
621         }
622     }
624     return true;
628  * Sets/unsets the pointer and marker in browse mode
630  * @param   object    the table row
631  * @param   integer  the row number
632  * @param   string    the action calling this script (over, out or click)
633  * @param   string    the default background color
634  * @param   string    the color to use for mouseover
635  * @param   string    the color to use for marking a row
637  * @return  boolean  whether pointer is set or not
638  */
639 function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
641     var theCells = null;
643     // 1. Pointer and mark feature are disabled or the browser can't get the
644     //    row -> exits
645     if ((thePointerColor == '' && theMarkColor == '')
646         || typeof(theRow.style) == 'undefined') {
647         return false;
648     }
650     // 1.1 Sets the mouse pointer to pointer on mouseover and back to normal otherwise.
651     if (theAction == "over" || theAction == "click") {
652         theRow.style.cursor='pointer';
653     } else {
654         theRow.style.cursor='default';
655     }
657     // 2. Gets the current row and exits if the browser can't get it
658     if (typeof(document.getElementsByTagName) != 'undefined') {
659         theCells = theRow.getElementsByTagName('td');
660     }
661     else if (typeof(theRow.cells) != 'undefined') {
662         theCells = theRow.cells;
663     }
664     else {
665         return false;
666     }
668     // 3. Gets the current color...
669     var rowCellsCnt  = theCells.length;
670     var domDetect    = null;
671     var currentColor = null;
672     var newColor     = null;
673     // 3.1 ... with DOM compatible browsers except Opera that does not return
674     //         valid values with "getAttribute"
675     if (typeof(window.opera) == 'undefined'
676         && typeof(theCells[0].getAttribute) != 'undefined') {
677         currentColor = theCells[0].getAttribute('bgcolor');
678         domDetect    = true;
679     }
680     // 3.2 ... with other browsers
681     else {
682         currentColor = theCells[0].style.backgroundColor;
683         domDetect    = false;
684     } // end 3
686     // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
687     if (currentColor.indexOf("rgb") >= 0)
688     {
689         var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
690                                      currentColor.indexOf(')'));
691         var rgbValues = rgbStr.split(",");
692         currentColor = "#";
693         var hexChars = "0123456789ABCDEF";
694         for (var i = 0; i < 3; i++)
695         {
696             var v = rgbValues[i].valueOf();
697             currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
698         }
699     }
701     // 4. Defines the new color
702     // 4.1 Current color is the default one
703     if (currentColor == ''
704         || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
705         if (theAction == 'over' && thePointerColor != '') {
706             newColor              = thePointerColor;
707         }
708         else if (theAction == 'click' && theMarkColor != '') {
709             newColor              = theMarkColor;
710             marked_row[theRowNum] = true;
711             // Garvin: deactivated onclick marking of the checkbox because it's also executed
712             // when an action (like edit/delete) on a single item is performed. Then the checkbox
713             // would get deactived, even though we need it activated. Maybe there is a way
714             // to detect if the row was clicked, and not an item therein...
715             // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
716         }
717     }
718     // 4.1.2 Current color is the pointer one
719     else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
720              && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
721         if (theAction == 'out') {
722             newColor              = theDefaultColor;
723         }
724         else if (theAction == 'click' && theMarkColor != '') {
725             newColor              = theMarkColor;
726             marked_row[theRowNum] = true;
727             // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
728         }
729     }
730     // 4.1.3 Current color is the marker one
731     else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
732         if (theAction == 'click') {
733             newColor              = (thePointerColor != '')
734                                   ? thePointerColor
735                                   : theDefaultColor;
736             marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
737                                   ? true
738                                   : null;
739             // document.getElementById('id_rows_to_delete' + theRowNum).checked = false;
740         }
741     } // end 4
743     // 5. Sets the new color...
744     if (newColor) {
745         var c = null;
746         // 5.1 ... with DOM compatible browsers except Opera
747         if (domDetect) {
748             for (c = 0; c < rowCellsCnt; c++) {
749                 theCells[c].setAttribute('bgcolor', newColor, 0);
750             } // end for
751         }
752         // 5.2 ... with other browsers
753         else {
754             for (c = 0; c < rowCellsCnt; c++) {
755                 theCells[c].style.backgroundColor = newColor;
756             }
757         }
758     } // end 5
760     return true;
761 } // end of the 'setPointer()' function
764  * Sets/unsets the pointer and marker in vertical browse mode
766  * @param   object    the table row
767  * @param   integer   the column number
768  * @param   string    the action calling this script (over, out or click)
769  * @param   string    the default background Class
770  * @param   string    the Class to use for mouseover
771  * @param   string    the Class to use for marking a row
773  * @return  boolean  whether pointer is set or not
775  * @author Garvin Hicking <me@supergarv.de> (rewrite of setPointer.)
776  */
777 function setVerticalPointer(theRow, theColNum, theAction, theDefaultClass1, theDefaultClass2, thePointerClass, theMarkClass) {
778     // 1. Pointer and mark feature are disabled or the browser can't get the
779     //    row -> exits
780     if ((thePointerClass == '' && theMarkClass == '')
781         || typeof(theRow.style) == 'undefined') {
782         return false;
783     }
785     var tagSwitch = null;
787     // 2. Gets the current row and exits if the browser can't get it
788     if (typeof(document.getElementsByTagName) != 'undefined') {
789         tagSwitch = 'tag';
790     } else if (typeof(document.getElementById('table_results')) != 'undefined') {
791         tagSwitch = 'cells';
792     } else {
793         return false;
794     }
796     var theCells = null;
798     if (tagSwitch == 'tag') {
799         theRows     = document.getElementById('table_results').getElementsByTagName('tr');
800         theCells    = theRows[1].getElementsByTagName('td');
801     } else if (tagSwitch == 'cells') {
802         theRows     = document.getElementById('table_results').rows;
803         theCells    = theRows[1].cells;
804     }
806     // 3. Gets the current Class...
807     var currentClass   = null;
808     var newClass       = null;
810     // 3.1 ... with DOM compatible browsers except Opera that does not return
811     //         valid values with "getAttribute"
812     if (typeof(window.opera) == 'undefined'
813         && typeof(theCells[theColNum].getAttribute) != 'undefined') {
814         currentClass = theCells[theColNum].className;
815     } // end 3
817     // 4. Defines the new Class
818     // 4.1 Current Class is the default one
819     if (currentClass == ''
820         || currentClass.toLowerCase() == theDefaultClass1.toLowerCase()
821         || currentClass.toLowerCase() == theDefaultClass2.toLowerCase()) {
822         if (theAction == 'over' && thePointerClass != '') {
823             newClass              = thePointerClass;
824         } else if (theAction == 'click' && theMarkClass != '') {
825             newClass              = theMarkClass;
826             marked_row[theColNum] = true;
827         }
828     }
829     // 4.1.2 Current Class is the pointer one
830     else if (currentClass.toLowerCase() == thePointerClass.toLowerCase() &&
831              (typeof(marked_row[theColNum]) == 'undefined' || !marked_row[theColNum]) || marked_row[theColNum] == false) {
832             if (theAction == 'out') {
833                 if (theColNum % 2) {
834                     newClass              = theDefaultClass1;
835                 } else {
836                     newClass              = theDefaultClass2;
837                 }
838             }
839             else if (theAction == 'click' && theMarkClass != '') {
840                 newClass              = theMarkClass;
841                 marked_row[theColNum] = true;
842             }
843     }
844     // 4.1.3 Current Class is the marker one
845     else if (currentClass.toLowerCase() == theMarkClass.toLowerCase()) {
846         if (theAction == 'click') {
847             newClass              = (thePointerClass != '')
848                                   ? thePointerClass
849                                   : ((theColNum % 2) ? theDefaultClass2 : theDefaultClass1);
850             marked_row[theColNum] = false;
851         }
852     } // end 4
854     // 5 ... with DOM compatible browsers except Opera
856     if (newClass) {
857         var c = null;
858         var rowCnt = theRows.length;
859         for (c = 0; c < rowCnt; c++) {
860             if (tagSwitch == 'tag') {
861                 Cells = theRows[c].getElementsByTagName('td');
862             } else if (tagSwitch == 'cells') {
863                 Cells = theRows[c].cells;
864             }
866             Cell  = Cells[theColNum];
868             // 5.1 Sets the new Class...
869             Cell.className = Cell.className.replace(currentClass, newClass);
870         } // end for
871     } // end 5
873      return true;
874  } // end of the 'setVerticalPointer()' function
877  * Checks/unchecks all checkbox in given conainer (f.e. a form, fieldset or div)
879  * @param   string   container_id  the container id
880  * @param   boolean  state         new value for checkbox (true or false)
881  * @return  boolean  always true
882  */
883 function setCheckboxes( container_id, state ) {
884     var checkboxes = document.getElementById(container_id).getElementsByTagName('input');
886     for ( var i = 0; i < checkboxes.length; i++ ) {
887         if ( checkboxes[i].type == 'checkbox' ) {
888             checkboxes[i].checked = state;
889         }
890     }
892     return true;
893 } // end of the 'setCheckboxes()' function
896 // added 2004-05-08 by Michael Keck <mail_at_michaelkeck_dot_de>
897 //   copy the checked from left to right or from right to left
898 //   so it's easier for users to see, if $cfg['ModifyAtRight']=true, what they've checked ;)
899 function copyCheckboxesRange(the_form, the_name, the_clicked)
901     if (typeof(document.forms[the_form].elements[the_name]) != 'undefined' && typeof(document.forms[the_form].elements[the_name + 'r']) != 'undefined') {
902         if (the_clicked !== 'r') {
903             if (document.forms[the_form].elements[the_name].checked == true) {
904                 document.forms[the_form].elements[the_name + 'r'].checked = true;
905             }else {
906                 document.forms[the_form].elements[the_name + 'r'].checked = false;
907             }
908         } else if (the_clicked == 'r') {
909             if (document.forms[the_form].elements[the_name + 'r'].checked == true) {
910                 document.forms[the_form].elements[the_name].checked = true;
911             }else {
912                 document.forms[the_form].elements[the_name].checked = false;
913             }
914        }
915     }
919 // added 2004-05-08 by Michael Keck <mail_at_michaelkeck_dot_de>
920 //  - this was directly written to each td, so why not a function ;)
921 //  setCheckboxColumn(\'id_rows_to_delete' . $row_no . ''\');
922 function setCheckboxColumn(theCheckbox){
923     if (document.getElementById(theCheckbox)) {
924         document.getElementById(theCheckbox).checked = (document.getElementById(theCheckbox).checked ? false : true);
925         if (document.getElementById(theCheckbox + 'r')) {
926             document.getElementById(theCheckbox + 'r').checked = document.getElementById(theCheckbox).checked;
927         }
928     } else {
929         if (document.getElementById(theCheckbox + 'r')) {
930             document.getElementById(theCheckbox + 'r').checked = (document.getElementById(theCheckbox +'r').checked ? false : true);
931             if (document.getElementById(theCheckbox)) {
932                 document.getElementById(theCheckbox).checked = document.getElementById(theCheckbox + 'r').checked;
933             }
934         }
935     }
940   * Checks/unchecks all options of a <select> element
941   *
942   * @param   string   the form name
943   * @param   string   the element name
944   * @param   boolean  whether to check or to uncheck the element
945   *
946   * @return  boolean  always true
947   */
948 function setSelectOptions(the_form, the_select, do_check)
950     var selectObject = document.forms[the_form].elements[the_select];
951     var selectCount  = selectObject.length;
953     for (var i = 0; i < selectCount; i++) {
954         selectObject.options[i].selected = do_check;
955     } // end for
957     return true;
958 } // end of the 'setSelectOptions()' function
961   * Inserts multiple fields.
962   *
963   */
964 function insertValueQuery() {
965     var myQuery = document.sqlform.sql_query;
966     var myListBox = document.sqlform.dummy;
968     if(myListBox.options.length > 0) {
969         sql_box_locked = true;
970         var chaineAj = "";
971         var NbSelect = 0;
972         for(var i=0; i<myListBox.options.length; i++) {
973             if (myListBox.options[i].selected){
974                 NbSelect++;
975                 if (NbSelect > 1)
976                     chaineAj += ", ";
977                 chaineAj += myListBox.options[i].value;
978             }
979         }
981         //IE support
982         if (document.selection) {
983             myQuery.focus();
984             sel = document.selection.createRange();
985             sel.text = chaineAj;
986             document.sqlform.insert.focus();
987         }
988         //MOZILLA/NETSCAPE support
989         else if (document.sqlform.sql_query.selectionStart || document.sqlform.sql_query.selectionStart == "0") {
990             var startPos = document.sqlform.sql_query.selectionStart;
991             var endPos = document.sqlform.sql_query.selectionEnd;
992             var chaineSql = document.sqlform.sql_query.value;
994             myQuery.value = chaineSql.substring(0, startPos) + chaineAj + chaineSql.substring(endPos, chaineSql.length);
995         } else {
996             myQuery.value += chaineAj;
997         }
998         sql_box_locked = false;
999     }
1003   * listbox redirection
1004   */
1005 function goToUrl(selObj, goToLocation) {
1006     eval("document.location.href = '" + goToLocation + "pos=" + selObj.options[selObj.selectedIndex].value + "'");
1010  * getElement
1011  */
1012 function getElement(e,f){
1013     if(document.layers){
1014         f=(f)?f:self;
1015         if(f.document.layers[e]) {
1016             return f.document.layers[e];
1017         }
1018         for(W=0;W<f.document.layers.length;W++) {
1019             return(getElement(e,f.document.layers[W]));
1020         }
1021     }
1022     if(document.all) {
1023         return document.all[e];
1024     }
1025     return document.getElementById(e);
1029   * Refresh the WYSIWYG-PDF scratchboard after changes have been made
1030   */
1031 function refreshDragOption(e) {
1032     myid = getElement(e);
1033     if (myid.style.visibility == 'visible') {
1034         refreshLayout();
1035     }
1039   * Refresh/resize the WYSIWYG-PDF scratchboard
1040   */
1041 function refreshLayout() {
1042         myid = getElement('pdflayout');
1044         if (document.pdfoptions.orientation.value == 'P') {
1045             posa = 'x';
1046             posb = 'y';
1047         } else {
1048             posa = 'y';
1049             posb = 'x';
1050         }
1052         myid.style.width = pdfPaperSize(document.pdfoptions.paper.value, posa) + 'px';
1053         myid.style.height = pdfPaperSize(document.pdfoptions.paper.value, posb) + 'px';
1057   * Show/hide the WYSIWYG-PDF scratchboard
1058   */
1059 function ToggleDragDrop(e) {
1060     myid = getElement(e);
1062     if (myid.style.visibility == 'hidden') {
1063         init();
1064         myid.style.visibility = 'visible';
1065         myid.style.display = 'block';
1066         document.edcoord.showwysiwyg.value = '1';
1067     } else {
1068         myid.style.visibility = 'hidden';
1069         myid.style.display = 'none';
1070         document.edcoord.showwysiwyg.value = '0';
1071     }
1075   * PDF scratchboard: When a position is entered manually, update
1076   * the fields inside the scratchboard.
1077   */
1078 function dragPlace(no, axis, value) {
1079     if (axis == 'x') {
1080         getElement("table_" + no).style.left = value + 'px';
1081     } else {
1082         getElement("table_" + no).style.top  = value + 'px';
1083     }
1087  * Returns paper sizes for a given format
1088  */
1089 function pdfPaperSize(format, axis) {
1090     switch (format.toUpperCase()) {
1091         case '4A0':
1092             if (axis == 'x') return 4767.87; else return 6740.79;
1093             break;
1094         case '2A0':
1095             if (axis == 'x') return 3370.39; else return 4767.87;
1096             break;
1097         case 'A0':
1098             if (axis == 'x') return 2383.94; else return 3370.39;
1099             break;
1100         case 'A1':
1101             if (axis == 'x') return 1683.78; else return 2383.94;
1102             break;
1103         case 'A2':
1104             if (axis == 'x') return 1190.55; else return 1683.78;
1105             break;
1106         case 'A3':
1107             if (axis == 'x') return 841.89; else return 1190.55;
1108             break;
1109         case 'A4':
1110             if (axis == 'x') return 595.28; else return 841.89;
1111             break;
1112         case 'A5':
1113             if (axis == 'x') return 419.53; else return 595.28;
1114             break;
1115         case 'A6':
1116             if (axis == 'x') return 297.64; else return 419.53;
1117             break;
1118         case 'A7':
1119             if (axis == 'x') return 209.76; else return 297.64;
1120             break;
1121         case 'A8':
1122             if (axis == 'x') return 147.40; else return 209.76;
1123             break;
1124         case 'A9':
1125             if (axis == 'x') return 104.88; else return 147.40;
1126             break;
1127         case 'A10':
1128             if (axis == 'x') return 73.70; else return 104.88;
1129             break;
1130         case 'B0':
1131             if (axis == 'x') return 2834.65; else return 4008.19;
1132             break;
1133         case 'B1':
1134             if (axis == 'x') return 2004.09; else return 2834.65;
1135             break;
1136         case 'B2':
1137             if (axis == 'x') return 1417.32; else return 2004.09;
1138             break;
1139         case 'B3':
1140             if (axis == 'x') return 1000.63; else return 1417.32;
1141             break;
1142         case 'B4':
1143             if (axis == 'x') return 708.66; else return 1000.63;
1144             break;
1145         case 'B5':
1146             if (axis == 'x') return 498.90; else return 708.66;
1147             break;
1148         case 'B6':
1149             if (axis == 'x') return 354.33; else return 498.90;
1150             break;
1151         case 'B7':
1152             if (axis == 'x') return 249.45; else return 354.33;
1153             break;
1154         case 'B8':
1155             if (axis == 'x') return 175.75; else return 249.45;
1156             break;
1157         case 'B9':
1158             if (axis == 'x') return 124.72; else return 175.75;
1159             break;
1160         case 'B10':
1161             if (axis == 'x') return 87.87; else return 124.72;
1162             break;
1163         case 'C0':
1164             if (axis == 'x') return 2599.37; else return 3676.54;
1165             break;
1166         case 'C1':
1167             if (axis == 'x') return 1836.85; else return 2599.37;
1168             break;
1169         case 'C2':
1170             if (axis == 'x') return 1298.27; else return 1836.85;
1171             break;
1172         case 'C3':
1173             if (axis == 'x') return 918.43; else return 1298.27;
1174             break;
1175         case 'C4':
1176             if (axis == 'x') return 649.13; else return 918.43;
1177             break;
1178         case 'C5':
1179             if (axis == 'x') return 459.21; else return 649.13;
1180             break;
1181         case 'C6':
1182             if (axis == 'x') return 323.15; else return 459.21;
1183             break;
1184         case 'C7':
1185             if (axis == 'x') return 229.61; else return 323.15;
1186             break;
1187         case 'C8':
1188             if (axis == 'x') return 161.57; else return 229.61;
1189             break;
1190         case 'C9':
1191             if (axis == 'x') return 113.39; else return 161.57;
1192             break;
1193         case 'C10':
1194             if (axis == 'x') return 79.37; else return 113.39;
1195             break;
1196         case 'RA0':
1197             if (axis == 'x') return 2437.80; else return 3458.27;
1198             break;
1199         case 'RA1':
1200             if (axis == 'x') return 1729.13; else return 2437.80;
1201             break;
1202         case 'RA2':
1203             if (axis == 'x') return 1218.90; else return 1729.13;
1204             break;
1205         case 'RA3':
1206             if (axis == 'x') return 864.57; else return 1218.90;
1207             break;
1208         case 'RA4':
1209             if (axis == 'x') return 609.45; else return 864.57;
1210             break;
1211         case 'SRA0':
1212             if (axis == 'x') return 2551.18; else return 3628.35;
1213             break;
1214         case 'SRA1':
1215             if (axis == 'x') return 1814.17; else return 2551.18;
1216             break;
1217         case 'SRA2':
1218             if (axis == 'x') return 1275.59; else return 1814.17;
1219             break;
1220         case 'SRA3':
1221             if (axis == 'x') return 907.09; else return 1275.59;
1222             break;
1223         case 'SRA4':
1224             if (axis == 'x') return 637.80; else return 907.09;
1225             break;
1226         case 'LETTER':
1227             if (axis == 'x') return 612.00; else return 792.00;
1228             break;
1229         case 'LEGAL':
1230             if (axis == 'x') return 612.00; else return 1008.00;
1231             break;
1232         case 'EXECUTIVE':
1233             if (axis == 'x') return 521.86; else return 756.00;
1234             break;
1235         case 'FOLIO':
1236             if (axis == 'x') return 612.00; else return 936.00;
1237             break;
1238     } // end switch
1240     return 0;
1244  * rajk - for playing media from the BLOB repository
1246  * @param   var     
1247  * @param   var     url_params  main purpose is to pass the token 
1248  * @param   var     bs_ref      BLOB repository reference
1249  * @param   var     m_type      type of BLOB repository media
1250  * @param   var     w_width     width of popup window
1251  * @param   var     w_height    height of popup window
1252  */
1253 function popupBSMedia(url_params, bs_ref, m_type, is_cust_type, w_width, w_height)
1255     // if width not specified, use default
1256     if (w_width == undefined)
1257         w_width = 640;
1259     // if height not specified, use default
1260     if (w_height == undefined)
1261         w_height = 480;
1263     // open popup window (for displaying video/playing audio)
1264     var mediaWin = window.open('bs_play_media.php?' + url_params + '&bs_reference=' + bs_ref + '&media_type=' + m_type + '&custom_type=' + is_cust_type, 'viewBSMedia', 'width=' + w_width + ', height=' + w_height + ', resizable=1, scrollbars=1, status=0');
1268  * rajk - popups a request for changing MIME types for files in the BLOB repository
1270  * @param   var     db                      database name
1271  * @param   var     table                   table name
1272  * @param   var     reference               BLOB repository reference
1273  * @param   var     current_mime_type       current MIME type associated with BLOB repository reference
1274  */
1275 function requestMIMETypeChange(db, table, reference, current_mime_type)
1277     // no mime type specified, set to default (nothing)
1278     if (undefined == current_mime_type)
1279         current_mime_type == "";
1281     // prompt user for new mime type
1282     var new_mime_type = prompt("Enter custom MIME type", current_mime_type);
1284     // if new mime_type is specified and is not the same as the previous type, request for mime type change
1285     if (new_mime_type && new_mime_type != current_mime_type)
1286         changeMIMEType(db, table, reference, new_mime_type);
1290  * rajk - changes MIME types for files in the BLOB repository
1292  * @param   var     db              database name
1293  * @param   var     table           table name
1294  * @param   var     reference       BLOB repository reference
1295  * @param   var     mime_type       new MIME type to be associated with BLOB repository reference
1296  */
1297 function changeMIMEType(db, table, reference, mime_type)
1299     // specify url and parameters for mootools AJAx request
1300     var mime_chg_url = 'bs_change_mime_type.php';
1301     var params = { bs_db: db, bs_table: table, bs_reference: reference, bs_new_mime_type: mime_type };
1303     // create AJAX object with above options and execute request
1304     var chgRequest = new Request({ method: 'post', url: mime_chg_url, data: params, evalScripts: true });
1305     chgRequest.send();