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