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