Revert initial commit
[phpmyadmin/blinky.git] / js / functions.js
blob908ced29f6c200266ac964ccb9ecbab89636d032
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
282 // Global variable row_class is set to even
283 var row_class = 'even';
285 /** 
286 * Generates a row dynamically in the differences table displaying
287 * the complete statistics of difference in  table like number of 
288 * rows to be updated, number of rows to be inserted, number of 
289 * columns to be added, number of columns to be removed, etc.
291 * @param  index         index of matching table
292 * @param  update_size   number of rows/column to be updated
293 * @param  insert_size   number of rows/coulmns to be inserted
294 * @param  remove_size   number of columns to be removed
295 * @param  insert_index  number of indexes to be inserted
296 * @param  remove_index  number of indexes to be removed
297 * @param  img_obj       image object 
298 * @param  table_name    name of the table
301 function showDetails(i, update_size, insert_size, remove_size, insert_index, remove_index, img_obj, table_name)
302 {   
303     // The path of the image is split to facilitate comparison
304     var relative_path = (img_obj.src).split("themes/"); 
305     
306     // The image source is changed when the showDetails function is called.
307     if (relative_path[1] == 'original/img/new_data_hovered.jpg') {    
308         img_obj.src = "./themes/original/img/new_data_selected_hovered.jpg";
309         img_obj.alt = PMA_messages['strClickToUnselect'];  //only for IE browser
310     } else if (relative_path[1] == 'original/img/new_struct_hovered.jpg') {
311         img_obj.src = "./themes/original/img/new_struct_selected_hovered.jpg";
312         img_obj.alt = PMA_messages['strClickToUnselect'];
313     } else if (relative_path[1] == 'original/img/new_struct_selected_hovered.jpg') {
314         img_obj.src = "./themes/original/img/new_struct_hovered.jpg";
315         img_obj.alt = PMA_messages['strClickToSelect'];
316     } else if (relative_path[1] == 'original/img/new_data_selected_hovered.jpg') {    
317         img_obj.src = "./themes/original/img/new_data_hovered.jpg";
318         img_obj.alt = PMA_messages['strClickToSelect'];
319     } 
320     
321     var div = document.getElementById("list");    
322     var table = div.getElementsByTagName("table")[0]; 
323     var table_body = table.getElementsByTagName("tbody")[0];
324     
325     //Global variable row_class is being used
326     if (row_class == 'even') {
327         row_class = 'odd';
328     } else {
329         row_class = 'even'; 
330     }
331     // If the red or green button against a table name is pressed then append a new row to show the details of differences of this table. 
332     if ((relative_path[1] != 'original/img/new_struct_selected_hovered.jpg') && (relative_path[1] != 'original/img/new_data_selected_hovered.jpg')) { 
333         
334         var newRow = document.createElement("tr");    
335         newRow.setAttribute("class", row_class);
336         newRow.className = row_class; 
337         // Id assigned to this row element is same as the index of this table name in the  matching_tables/source_tables_uncommon array  
338         newRow.setAttribute("id" , i);
339             
340         var table_name_cell = document.createElement("td");
341         table_name_cell.align = "center";
342         table_name_cell.innerHTML = table_name ;
343         
344         newRow.appendChild(table_name_cell);
345        
346         var create_table = document.createElement("td");
347         create_table.align = "center";
348            
349         var add_cols = document.createElement("td");
350         add_cols.align = "center";
351         
352         var remove_cols = document.createElement("td");
353         remove_cols.align = "center";
354         
355         var alter_cols = document.createElement("td");
356         alter_cols.align = "center";
357         
358         var add_index = document.createElement("td");
359         add_index.align = "center";
360         
361         var delete_index = document.createElement("td");
362         delete_index.align = "center";
363         
364         var update_rows = document.createElement("td");
365         update_rows.align = "center";
366         
367         var insert_rows = document.createElement("td");
368         insert_rows.align = "center";
369         
370         var tick_image = document.createElement("img");
371         tick_image.src = "./themes/original/img/s_success.png"; 
373         if (update_size == '' && insert_size == '' && remove_size == '') {
374           /**
375           This is the case when the table needs to be created in target database. 
376           */
377             create_table.appendChild(tick_image);
378             add_cols.innerHTML = "--";
379             remove_cols.innerHTML = "--";         
380             alter_cols.innerHTML = "--";
381             delete_index.innerHTML = "--";
382             add_index.innerHTML = "--";
383             update_rows.innerHTML = "--";
384             insert_rows.innerHTML = "--";
386             newRow.appendChild(create_table);
387             newRow.appendChild(add_cols);
388             newRow.appendChild(remove_cols);
389             newRow.appendChild(alter_cols);
390             newRow.appendChild(delete_index);
391             newRow.appendChild(add_index);
392             newRow.appendChild(update_rows);
393             newRow.appendChild(insert_rows);
394             
395         } else if (update_size == '' && remove_size == '') {
396            /**
397            This is the case when data difference is displayed in the 
398            table which is present in source but absent from target database 
399           */
400             create_table.innerHTML = "--";
401             add_cols.innerHTML = "--";
402             remove_cols.innerHTML = "--";         
403             alter_cols.innerHTML = "--";
404             add_index.innerHTML = "--";
405             delete_index.innerHTML = "--";
406             update_rows.innerHTML = "--";
407             insert_rows.innerHTML = insert_size;
408             
409             newRow.appendChild(create_table);
410             newRow.appendChild(add_cols);
411             newRow.appendChild(remove_cols);
412             newRow.appendChild(alter_cols);
413             newRow.appendChild(delete_index); 
414             newRow.appendChild(add_index);
415             newRow.appendChild(update_rows);
416             newRow.appendChild(insert_rows);
417             
418         } else if (remove_size == '') {
419             /**
420              This is the case when data difference between matching_tables is displayed. 
421             */
422             create_table.innerHTML = "--";
423             add_cols.innerHTML = "--";
424             remove_cols.innerHTML = "--";         
425             alter_cols.innerHTML = "--";
426             add_index.innerHTML = "--";
427             delete_index.innerHTML = "--";
428             update_rows.innerHTML = update_size;
429             insert_rows.innerHTML = insert_size;
430             
431             newRow.appendChild(create_table);
432             newRow.appendChild(add_cols);
433             newRow.appendChild(remove_cols);
434             newRow.appendChild(alter_cols);
435             newRow.appendChild(delete_index);
436             newRow.appendChild(add_index);
437             newRow.appendChild(update_rows);
438             newRow.appendChild(insert_rows);
439             
440         } else {
441             /**
442             This is the case when structure difference between matching_tables id displayed
443             */
444             create_table.innerHTML = "--";
445             add_cols.innerHTML = insert_size;
446             remove_cols.innerHTML = remove_size;         
447             alter_cols.innerHTML = update_size;
448             delete_index.innerHTML = remove_index;
449             add_index.innerHTML = insert_index;
450             update_rows.innerHTML = "--";
451             insert_rows.innerHTML = "--";
452            
453             newRow.appendChild(create_table);
454             newRow.appendChild(add_cols);
455             newRow.appendChild(remove_cols);
456             newRow.appendChild(alter_cols); 
457             newRow.appendChild(delete_index);
458             newRow.appendChild(add_index);
459             newRow.appendChild(update_rows);
460             newRow.appendChild(insert_rows);
461         }
462         table_body.appendChild(newRow);
463       
464     } else if ((relative_path[1] != 'original/img/new_struct_hovered.jpg') && (relative_path[1] != 'original/img/new_data_hovered.jpg')) {
465       //The case when the row showing the details need to be removed from the table i.e. the difference button is deselected now.
466         var table_rows = table_body.getElementsByTagName("tr");
467         var j;
468         var index = 0;
469         for (j=0; j < table_rows.length; j++) 
470         {   
471             if (table_rows[j].id == i) { 
472                 index = j;
473                 table_rows[j].parentNode.removeChild(table_rows[j]);     
474             }
475         }
476         //The table row css is being adjusted. Class "odd" for odd rows and "even" for even rows should be maintained.
477         for(index; index < table_rows.length; index++)
478         {
479             row_class_element = table_rows[index].getAttribute('class');
480             if (row_class_element == "even") {
481                 table_rows[index].setAttribute("class","odd");  // for Mozilla firefox
482                 table_rows[index].className = "odd";            // for IE browser
483             } else {
484                 table_rows[index].setAttribute("class","even"); // for Mozilla firefox  
485                 table_rows[index].className = "even";           // for IE browser       
486             }
487         }    
488     }     
492  * Changes the image on hover effects
494  * @param   img_obj   the image object whose source needs to be changed
496  */
498 function change_Image(img_obj)
500      var relative_path = (img_obj.src).split("themes/"); 
501     
502     if (relative_path[1] == 'original/img/new_data.jpg') {    
503         img_obj.src = "./themes/original/img/new_data_hovered.jpg";  
504     } else if (relative_path[1] == 'original/img/new_struct.jpg') {
505         img_obj.src = "./themes/original/img/new_struct_hovered.jpg";
506     } else if (relative_path[1] == 'original/img/new_struct_hovered.jpg') {
507         img_obj.src = "./themes/original/img/new_struct.jpg";
508     } else if (relative_path[1] == 'original/img/new_data_hovered.jpg') {    
509         img_obj.src = "./themes/original/img/new_data.jpg";  
510     } else if (relative_path[1] == 'original/img/new_data_selected.jpg') {    
511         img_obj.src = "./themes/original/img/new_data_selected_hovered.jpg";  
512     } else if(relative_path[1] == 'original/img/new_struct_selected.jpg') {    
513         img_obj.src = "./themes/original/img/new_struct_selected_hovered.jpg";  
514     } else if (relative_path[1] == 'original/img/new_struct_selected_hovered.jpg') {    
515         img_obj.src = "./themes/original/img/new_struct_selected.jpg";  
516     } else if (relative_path[1] == 'original/img/new_data_selected_hovered.jpg') {    
517         img_obj.src = "./themes/original/img/new_data_selected.jpg";  
518     }
522  * Generates the URL containing the list of selected table ids for synchronization and 
523  * a variable checked for confirmation of deleting previous rows from target tables 
525  * @param   token   the token generated for each PMA form 
527  */
529 function ApplySelectedChanges(token)
531     var div =  document.getElementById("list");
532     var table = div.getElementsByTagName('table')[0];
533     var table_body = table.getElementsByTagName('tbody')[0];
534     // Get all the rows from the details table
535     var table_rows = table_body.getElementsByTagName('tr');
536     var x = table_rows.length;
537     var i;
538     /**
539      Append the token at the beginning of the query string followed by  
540     Table_ids that shows that "Apply Selected Changes" button is pressed            
541     */
542     var append_string = "?token="+token+"&Table_ids="+1;
543     for(i=0; i<x; i++){
544            append_string += "&";    
545            append_string += i+"="+table_rows[i].id; 
546     }
547     
548     // Getting the value of checkbox delete_rows
549     var checkbox = document.getElementById("delete_rows");
550     if (checkbox.checked){
551         append_string += "&checked=true";
552     } else {
553          append_string += "&checked=false";
554     }
555     //Appending the token and list of table ids in the URL 
556     location.href += token;
557     location.href += append_string;
560 /** 
561 * Displays error message if any text field 
562 * is left empty other than port field.
564 * @param  string   the form name
565 * @param  object   the form
567 * @return  boolean  whether the form field is empty or not
569 function validateConnection(form_name, form_obj)
570 {   
571     var check = true;
572     var src_hostfilled = true;
573     var trg_hostfilled = true;
575     for (var i=1; i<form_name.elements.length; i++)
576     {
577         // All the text fields are checked excluding the port field because the default port can be used.
578         if ((form_name.elements[i].type == 'text') && (form_name.elements[i].name != 'src_port') && (form_name.elements[i].name != 'trg_port')) {
579             check = emptyFormElements(form_obj, form_name.elements[i].name);
580             if (check==false) {
581                 element = form_name.elements[i].name;
582                 if (form_name.elements[i].name == 'src_host') {
583                     src_hostfilled = false;
584                     continue;
585                 }
586                 if (form_name.elements[i].name == 'trg_host') {
587                     trg_hostfilled = false;
588                     continue;
589                 }
590                 if ((form_name.elements[i].name == 'src_socket' && src_hostfilled==false) || (form_name.elements[i].name == 'trg_socket' && trg_hostfilled==false))
591                     break;
592                 else
593                     continue;
594             }
595         }
596     }
597     if (!check) {
598         form_obj.reset();
599         element.select();
600         alert(PMA_messages['strFormEmpty']);
601         element.focus();
602     }
603     return check;
605     
607  * Check if a form's element is empty
608  * should be
610  * @param   object   the form
611  * @param   string   the name of the form field to put the focus on
613  * @return  boolean  whether the form field is empty or not
614  */
615 function emptyCheckTheField(theForm, theFieldName)
617     var isEmpty  = 1;
618     var theField = theForm.elements[theFieldName];
619     // Whether the replace function (js1.2) is supported or not
620     var isRegExp = (typeof(theField.value.replace) != 'undefined');
622     if (!isRegExp) {
623         isEmpty      = (theField.value == '') ? 1 : 0;
624     } else {
625         var space_re = new RegExp('\\s+');
626         isEmpty      = (theField.value.replace(space_re, '') == '') ? 1 : 0;
627     }
629     return isEmpty;
630 } // end of the 'emptyCheckTheField()' function
635  * @param   object   the form
636  * @param   string   the name of the form field to put the focus on
638  * @return  boolean  whether the form field is empty or not
639  */
640 function emptyFormElements(theForm, theFieldName)
642     var theField = theForm.elements[theFieldName];
643     var isEmpty = emptyCheckTheField(theForm, theFieldName);
646     return isEmpty;
647 } // end of the 'emptyFormElements()' function
651  * Ensures a value submitted in a form is numeric and is in a range
653  * @param   object   the form
654  * @param   string   the name of the form field to check
655  * @param   integer  the minimum authorized value
656  * @param   integer  the maximum authorized value
658  * @return  boolean  whether a valid number has been submitted or not
659  */
660 function checkFormElementInRange(theForm, theFieldName, message, min, max)
662     var theField         = theForm.elements[theFieldName];
663     var val              = parseInt(theField.value);
665     if (typeof(min) == 'undefined') {
666         min = 0;
667     }
668     if (typeof(max) == 'undefined') {
669         max = Number.MAX_VALUE;
670     }
672     // It's not a number
673     if (isNaN(val)) {
674         theField.select();
675         alert(PMA_messages['strNotNumber']);
676         theField.focus();
677         return false;
678     }
679     // It's a number but it is not between min and max
680     else if (val < min || val > max) {
681         theField.select();
682         alert(message.replace('%d', val));
683         theField.focus();
684         return false;
685     }
686     // It's a valid number
687     else {
688         theField.value = val;
689     }
690     return true;
692 } // end of the 'checkFormElementInRange()' function
695 function checkTableEditForm(theForm, fieldsCnt)
697     // TODO: avoid sending a message if user just wants to add a line
698     // on the form but has not completed at least one field name
700     var atLeastOneField = 0;
701     var i, elm, elm2, elm3, val, id;
703     for (i=0; i<fieldsCnt; i++)
704     {
705         id = "#field_" + i + "_2";
706         elm = $(id);
707         val = elm.val()
708         if (val == 'VARCHAR' || val == 'CHAR' || val == 'BIT' || val == 'VARBINARY' || val == 'BINARY') {
709             elm2 = $("#field_" + i + "_3");
710             val = parseInt(elm2.val());
711             elm3 = $("#field_" + i + "_1");
712             if (isNaN(val) && elm3.val() != "") {
713                 elm2.select();
714                 alert(PMA_messages['strNotNumber']);
715                 elm2.focus();
716                 return false;
717             }
718         }
720         if (atLeastOneField == 0) {
721             id = "field_" + i + "_1";
722             if (!emptyCheckTheField(theForm, id)) {
723                 atLeastOneField = 1;
724             }
725         }
726     }
727     if (atLeastOneField == 0) {
728         var theField = theForm.elements["field_0_1"];
729         alert(PMA_messages['strFormEmpty']);
730         theField.focus();
731         return false;
732     }
734     return true;
735 } // enf of the 'checkTableEditForm()' function
739  * Ensures the choice between 'transmit', 'zipped', 'gzipped' and 'bzipped'
740  * checkboxes is consistant
742  * @param   object   the form
743  * @param   string   a code for the action that causes this function to be run
745  * @return  boolean  always true
746  */
747 function checkTransmitDump(theForm, theAction)
749     var formElts = theForm.elements;
751     // 'zipped' option has been checked
752     if (theAction == 'zip' && formElts['zip'].checked) {
753         if (!formElts['asfile'].checked) {
754             theForm.elements['asfile'].checked = true;
755         }
756         if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) {
757             theForm.elements['gzip'].checked = false;
758         }
759         if (typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked) {
760             theForm.elements['bzip'].checked = false;
761         }
762     }
763     // 'gzipped' option has been checked
764     else if (theAction == 'gzip' && formElts['gzip'].checked) {
765         if (!formElts['asfile'].checked) {
766             theForm.elements['asfile'].checked = true;
767         }
768         if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
769             theForm.elements['zip'].checked = false;
770         }
771         if (typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked) {
772             theForm.elements['bzip'].checked = false;
773         }
774     }
775     // 'bzipped' option has been checked
776     else if (theAction == 'bzip' && formElts['bzip'].checked) {
777         if (!formElts['asfile'].checked) {
778             theForm.elements['asfile'].checked = true;
779         }
780         if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
781             theForm.elements['zip'].checked = false;
782         }
783         if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) {
784             theForm.elements['gzip'].checked = false;
785         }
786     }
787     // 'transmit' option has been unchecked
788     else if (theAction == 'transmit' && !formElts['asfile'].checked) {
789         if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
790             theForm.elements['zip'].checked = false;
791         }
792         if ((typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked)) {
793             theForm.elements['gzip'].checked = false;
794         }
795         if ((typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked)) {
796             theForm.elements['bzip'].checked = false;
797         }
798     }
800     return true;
801 } // end of the 'checkTransmitDump()' function
805  * This array is used to remember mark status of rows in browse mode
806  */
807 var marked_row = new Array;
810  * enables highlight and marking of rows in data tables
812  */
813 function PMA_markRowsInit() {
814     // for every table row ...
815     var rows = document.getElementsByTagName('tr');
816     for ( var i = 0; i < rows.length; i++ ) {
817         // ... with the class 'odd' or 'even' ...
818         if ( 'odd' != rows[i].className.substr(0,3) && 'even' != rows[i].className.substr(0,4) ) {
819             continue;
820         }
821         // ... add event listeners ...
822         // ... to highlight the row on mouseover ...
823         if ( navigator.appName == 'Microsoft Internet Explorer' ) {
824             // but only for IE, other browsers are handled by :hover in css
825             rows[i].onmouseover = function() {
826                 this.className += ' hover';
827             }
828             rows[i].onmouseout = function() {
829                 this.className = this.className.replace( ' hover', '' );
830             }
831         }
832         // Do not set click events if not wanted
833         if (rows[i].className.search(/noclick/) != -1) {
834             continue;
835         }
836         // ... and to mark the row on click ...
837         $(rows[i]).bind('mousedown', function(event) {
838             var unique_id;
839             var checkbox;
840             var table;
842             // Somehow IE8 has this not set
843             if (!event) var event = window.event
845             checkbox = this.getElementsByTagName( 'input' )[0];
846             if ( checkbox && checkbox.type == 'checkbox' ) {
847                 unique_id = checkbox.name + checkbox.value;
848             } else if ( this.id.length > 0 ) {
849                 unique_id = this.id;
850             } else {
851                 return;
852             }
854             if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] ) {
855                 marked_row[unique_id] = true;
856             } else {
857                 marked_row[unique_id] = false;
858             }
860             if ( marked_row[unique_id] ) {
861                 this.className += ' marked';
862             } else {
863                 this.className = this.className.replace(' marked', '');
864             }
866             if ( checkbox && checkbox.disabled == false ) {
867                 checkbox.checked = marked_row[unique_id];
868                 if (typeof(event) == 'object') {
869                     table = this.parentNode;
870                     i = 0;
871                     while (table.tagName.toLowerCase() != 'table' && i < 20) {
872                         i++;
873                         table = table.parentNode;
874                     }
876                     if (event.shiftKey == true && table.lastClicked != undefined) {
877                         if (event.preventDefault) { event.preventDefault(); } else { event.returnValue = false; }
878                         i = table.lastClicked;
880                         if (i < this.rowIndex) {
881                             i++;
882                         } else {
883                             i--;
884                         }
886                         while (i != this.rowIndex) {
887                             table.rows[i].onmousedown();
888                             if (i < this.rowIndex) {
889                                 i++;
890                             } else {
891                                 i--;
892                             }
893                         }
894                     }
896                     table.lastClicked = this.rowIndex;
897                 }
898             }
899         });
901         // ... and disable label ...
902         var labeltag = rows[i].getElementsByTagName('label')[0];
903         if ( labeltag ) {
904             labeltag.onclick = function() {
905                 return false;
906             }
907         }
908         // .. and checkbox clicks
909         var checkbox = rows[i].getElementsByTagName('input')[0];
910         if ( checkbox ) {
911             checkbox.onclick = function() {
912                 // opera does not recognize return false;
913                 this.checked = ! this.checked;
914             }
915         }
916     }
918 $(document).ready(PMA_markRowsInit);
921  * marks all rows and selects its first checkbox inside the given element
922  * the given element is usaly a table or a div containing the table or tables
924  * @param    container    DOM element
925  */
926 function markAllRows( container_id ) {
927     var rows = document.getElementById(container_id).getElementsByTagName('tr');
928     var unique_id;
929     var checkbox;
931     for ( var i = 0; i < rows.length; i++ ) {
933         checkbox = rows[i].getElementsByTagName( 'input' )[0];
935         if ( checkbox && checkbox.type == 'checkbox' ) {
936             unique_id = checkbox.name + checkbox.value;
937             if ( checkbox.disabled == false ) {
938                 checkbox.checked = true;
939                 if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] ) {
940                     rows[i].className += ' marked';
941                     marked_row[unique_id] = true;
942                 }
943             }
944         }
945     }
947     return true;
951  * marks all rows and selects its first checkbox inside the given element
952  * the given element is usaly a table or a div containing the table or tables
954  * @param    container    DOM element
955  */
956 function unMarkAllRows( container_id ) {
957     var rows = document.getElementById(container_id).getElementsByTagName('tr');
958     var unique_id;
959     var checkbox;
961     for ( var i = 0; i < rows.length; i++ ) {
963         checkbox = rows[i].getElementsByTagName( 'input' )[0];
965         if ( checkbox && checkbox.type == 'checkbox' ) {
966             unique_id = checkbox.name + checkbox.value;
967             checkbox.checked = false;
968             rows[i].className = rows[i].className.replace(' marked', '');
969             marked_row[unique_id] = false;
970         }
971     }
973     return true;
977  * Sets/unsets the pointer and marker in browse mode
979  * @param   object    the table row
980  * @param   integer  the row number
981  * @param   string    the action calling this script (over, out or click)
982  * @param   string    the default background color
983  * @param   string    the color to use for mouseover
984  * @param   string    the color to use for marking a row
986  * @return  boolean  whether pointer is set or not
987  */
988 function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
990     var theCells = null;
992     // 1. Pointer and mark feature are disabled or the browser can't get the
993     //    row -> exits
994     if ((thePointerColor == '' && theMarkColor == '')
995         || typeof(theRow.style) == 'undefined') {
996         return false;
997     }
999     // 1.1 Sets the mouse pointer to pointer on mouseover and back to normal otherwise.
1000     if (theAction == "over" || theAction == "click") {
1001         theRow.style.cursor='pointer';
1002     } else {
1003         theRow.style.cursor='default';
1004     }
1006     // 2. Gets the current row and exits if the browser can't get it
1007     if (typeof(document.getElementsByTagName) != 'undefined') {
1008         theCells = theRow.getElementsByTagName('td');
1009     }
1010     else if (typeof(theRow.cells) != 'undefined') {
1011         theCells = theRow.cells;
1012     }
1013     else {
1014         return false;
1015     }
1017     // 3. Gets the current color...
1018     var rowCellsCnt  = theCells.length;
1019     var domDetect    = null;
1020     var currentColor = null;
1021     var newColor     = null;
1022     // 3.1 ... with DOM compatible browsers except Opera that does not return
1023     //         valid values with "getAttribute"
1024     if (typeof(window.opera) == 'undefined'
1025         && typeof(theCells[0].getAttribute) != 'undefined') {
1026         currentColor = theCells[0].getAttribute('bgcolor');
1027         domDetect    = true;
1028     }
1029     // 3.2 ... with other browsers
1030     else {
1031         currentColor = theCells[0].style.backgroundColor;
1032         domDetect    = false;
1033     } // end 3
1035     // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
1036     if (currentColor.indexOf("rgb") >= 0)
1037     {
1038         var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
1039                                      currentColor.indexOf(')'));
1040         var rgbValues = rgbStr.split(",");
1041         currentColor = "#";
1042         var hexChars = "0123456789ABCDEF";
1043         for (var i = 0; i < 3; i++)
1044         {
1045             var v = rgbValues[i].valueOf();
1046             currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
1047         }
1048     }
1050     // 4. Defines the new color
1051     // 4.1 Current color is the default one
1052     if (currentColor == ''
1053         || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
1054         if (theAction == 'over' && thePointerColor != '') {
1055             newColor              = thePointerColor;
1056         }
1057         else if (theAction == 'click' && theMarkColor != '') {
1058             newColor              = theMarkColor;
1059             marked_row[theRowNum] = true;
1060             // Garvin: deactivated onclick marking of the checkbox because it's also executed
1061             // when an action (like edit/delete) on a single item is performed. Then the checkbox
1062             // would get deactived, even though we need it activated. Maybe there is a way
1063             // to detect if the row was clicked, and not an item therein...
1064             // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
1065         }
1066     }
1067     // 4.1.2 Current color is the pointer one
1068     else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
1069              && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
1070         if (theAction == 'out') {
1071             newColor              = theDefaultColor;
1072         }
1073         else if (theAction == 'click' && theMarkColor != '') {
1074             newColor              = theMarkColor;
1075             marked_row[theRowNum] = true;
1076             // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
1077         }
1078     }
1079     // 4.1.3 Current color is the marker one
1080     else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
1081         if (theAction == 'click') {
1082             newColor              = (thePointerColor != '')
1083                                   ? thePointerColor
1084                                   : theDefaultColor;
1085             marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
1086                                   ? true
1087                                   : null;
1088             // document.getElementById('id_rows_to_delete' + theRowNum).checked = false;
1089         }
1090     } // end 4
1092     // 5. Sets the new color...
1093     if (newColor) {
1094         var c = null;
1095         // 5.1 ... with DOM compatible browsers except Opera
1096         if (domDetect) {
1097             for (c = 0; c < rowCellsCnt; c++) {
1098                 theCells[c].setAttribute('bgcolor', newColor, 0);
1099             } // end for
1100         }
1101         // 5.2 ... with other browsers
1102         else {
1103             for (c = 0; c < rowCellsCnt; c++) {
1104                 theCells[c].style.backgroundColor = newColor;
1105             }
1106         }
1107     } // end 5
1109     return true;
1110 } // end of the 'setPointer()' function
1113  * Sets/unsets the pointer and marker in vertical browse mode
1115  * @param   object    the table row
1116  * @param   integer   the column number
1117  * @param   string    the action calling this script (over, out or click)
1118  * @param   string    the default background Class
1119  * @param   string    the Class to use for mouseover
1120  * @param   string    the Class to use for marking a row
1122  * @return  boolean  whether pointer is set or not
1124  */
1125 function setVerticalPointer(theRow, theColNum, theAction, theDefaultClass1, theDefaultClass2, thePointerClass, theMarkClass) {
1126     // 1. Pointer and mark feature are disabled or the browser can't get the
1127     //    row -> exits
1128     if ((thePointerClass == '' && theMarkClass == '')
1129         || typeof(theRow.style) == 'undefined') {
1130         return false;
1131     }
1133     var tagSwitch = null;
1135     // 2. Gets the current row and exits if the browser can't get it
1136     if (typeof(document.getElementsByTagName) != 'undefined') {
1137         tagSwitch = 'tag';
1138     } else if (typeof(document.getElementById('table_results')) != 'undefined') {
1139         tagSwitch = 'cells';
1140     } else {
1141         return false;
1142     }
1144     var theCells = null;
1146     if (tagSwitch == 'tag') {
1147         theRows     = document.getElementById('table_results').getElementsByTagName('tr');
1148         theCells    = theRows[1].getElementsByTagName('td');
1149     } else if (tagSwitch == 'cells') {
1150         theRows     = document.getElementById('table_results').rows;
1151         theCells    = theRows[1].cells;
1152     }
1154     // 3. Gets the current Class...
1155     var currentClass   = null;
1156     var newClass       = null;
1158     // 3.1 ... with DOM compatible browsers except Opera that does not return
1159     //         valid values with "getAttribute"
1160     if (typeof(window.opera) == 'undefined'
1161         && typeof(theCells[theColNum].getAttribute) != 'undefined') {
1162         currentClass = theCells[theColNum].className;
1163     } // end 3
1165     // 4. Defines the new Class
1166     // 4.1 Current Class is the default one
1167     if (currentClass == ''
1168         || currentClass.toLowerCase() == theDefaultClass1.toLowerCase()
1169         || currentClass.toLowerCase() == theDefaultClass2.toLowerCase()) {
1170         if (theAction == 'over' && thePointerClass != '') {
1171             newClass              = thePointerClass;
1172         } else if (theAction == 'click' && theMarkClass != '') {
1173             newClass              = theMarkClass;
1174             marked_row[theColNum] = true;
1175         }
1176     }
1177     // 4.1.2 Current Class is the pointer one
1178     else if (currentClass.toLowerCase() == thePointerClass.toLowerCase() &&
1179              (typeof(marked_row[theColNum]) == 'undefined' || !marked_row[theColNum]) || marked_row[theColNum] == false) {
1180             if (theAction == 'out') {
1181                 if (theColNum % 2) {
1182                     newClass              = theDefaultClass1;
1183                 } else {
1184                     newClass              = theDefaultClass2;
1185                 }
1186             }
1187             else if (theAction == 'click' && theMarkClass != '') {
1188                 newClass              = theMarkClass;
1189                 marked_row[theColNum] = true;
1190             }
1191     }
1192     // 4.1.3 Current Class is the marker one
1193     else if (currentClass.toLowerCase() == theMarkClass.toLowerCase()) {
1194         if (theAction == 'click') {
1195             newClass              = (thePointerClass != '')
1196                                   ? thePointerClass
1197                                   : ((theColNum % 2) ? theDefaultClass2 : theDefaultClass1);
1198             marked_row[theColNum] = false;
1199         }
1200     } // end 4
1202     // 5 ... with DOM compatible browsers except Opera
1204     if (newClass) {
1205         var c = null;
1206         var rowCnt = theRows.length;
1207         for (c = 0; c < rowCnt; c++) {
1208             if (tagSwitch == 'tag') {
1209                 Cells = theRows[c].getElementsByTagName('td');
1210             } else if (tagSwitch == 'cells') {
1211                 Cells = theRows[c].cells;
1212             }
1214             Cell  = Cells[theColNum];
1216             // 5.1 Sets the new Class...
1217             Cell.className = Cell.className.replace(currentClass, newClass);
1218         } // end for
1219     } // end 5
1221      return true;
1222  } // end of the 'setVerticalPointer()' function
1225  * Checks/unchecks all checkbox in given conainer (f.e. a form, fieldset or div)
1227  * @param   string   container_id  the container id
1228  * @param   boolean  state         new value for checkbox (true or false)
1229  * @return  boolean  always true
1230  */
1231 function setCheckboxes( container_id, state ) {
1232     var checkboxes = document.getElementById(container_id).getElementsByTagName('input');
1234     for ( var i = 0; i < checkboxes.length; i++ ) {
1235         if ( checkboxes[i].type == 'checkbox' ) {
1236             checkboxes[i].checked = state;
1237         }
1238     }
1240     return true;
1241 } // end of the 'setCheckboxes()' function
1244 // added 2004-05-08 by Michael Keck <mail_at_michaelkeck_dot_de>
1245 //   copy the checked from left to right or from right to left
1246 //   so it's easier for users to see, if $cfg['ModifyAtRight']=true, what they've checked ;)
1247 function copyCheckboxesRange(the_form, the_name, the_clicked)
1249     if (typeof(document.forms[the_form].elements[the_name]) != 'undefined' && typeof(document.forms[the_form].elements[the_name + 'r']) != 'undefined') {
1250         if (the_clicked !== 'r') {
1251             if (document.forms[the_form].elements[the_name].checked == true) {
1252                 document.forms[the_form].elements[the_name + 'r'].checked = true;
1253             }else {
1254                 document.forms[the_form].elements[the_name + 'r'].checked = false;
1255             }
1256         } else if (the_clicked == 'r') {
1257             if (document.forms[the_form].elements[the_name + 'r'].checked == true) {
1258                 document.forms[the_form].elements[the_name].checked = true;
1259             }else {
1260                 document.forms[the_form].elements[the_name].checked = false;
1261             }
1262        }
1263     }
1267 // added 2004-05-08 by Michael Keck <mail_at_michaelkeck_dot_de>
1268 //  - this was directly written to each td, so why not a function ;)
1269 //  setCheckboxColumn(\'id_rows_to_delete' . $row_no . ''\');
1270 function setCheckboxColumn(theCheckbox){
1271     if (document.getElementById(theCheckbox)) {
1272         document.getElementById(theCheckbox).checked = (document.getElementById(theCheckbox).checked ? false : true);
1273         if (document.getElementById(theCheckbox + 'r')) {
1274             document.getElementById(theCheckbox + 'r').checked = document.getElementById(theCheckbox).checked;
1275         }
1276     } else {
1277         if (document.getElementById(theCheckbox + 'r')) {
1278             document.getElementById(theCheckbox + 'r').checked = (document.getElementById(theCheckbox +'r').checked ? false : true);
1279             if (document.getElementById(theCheckbox)) {
1280                 document.getElementById(theCheckbox).checked = document.getElementById(theCheckbox + 'r').checked;
1281             }
1282         }
1283     }
1288   * Checks/unchecks all options of a <select> element
1289   *
1290   * @param   string   the form name
1291   * @param   string   the element name
1292   * @param   boolean  whether to check or to uncheck the element
1293   *
1294   * @return  boolean  always true
1295   */
1296 function setSelectOptions(the_form, the_select, do_check)
1298     var selectObject = document.forms[the_form].elements[the_select];
1299     var selectCount  = selectObject.length;
1301     for (var i = 0; i < selectCount; i++) {
1302         selectObject.options[i].selected = do_check;
1303     } // end for
1305     return true;
1306 } // end of the 'setSelectOptions()' function
1310   * Create quick sql statements.
1311   *
1312   */
1313 function insertQuery(queryType) {
1314     var myQuery = document.sqlform.sql_query;
1315     var myListBox = document.sqlform.dummy;
1316     var query = "";
1317     var table = document.sqlform.table.value;
1319     if (myListBox.options.length > 0) {
1320         sql_box_locked = true;
1321         var chaineAj = "";
1322         var valDis = "";
1323         var editDis = "";
1324         var NbSelect = 0;
1325         for (var i=0; i < myListBox.options.length; i++) {
1326             NbSelect++;
1327             if (NbSelect > 1) {
1328                 chaineAj += ", ";
1329                 valDis += ",";
1330                 editDis += ",";
1331             }
1332             chaineAj += myListBox.options[i].value;
1333             valDis += "[value-" + NbSelect + "]";
1334             editDis += myListBox.options[i].value + "=[value-" + NbSelect + "]";
1335         }
1336     if (queryType == "selectall") {
1337         query = "SELECT * FROM `" + table + "` WHERE 1";
1338     } else if (queryType == "select") {
1339         query = "SELECT " + chaineAj + " FROM `" + table + "` WHERE 1";
1340     } else if (queryType == "insert") {
1341            query = "INSERT INTO `" + table + "`(" + chaineAj + ") VALUES (" + valDis + ")";
1342     } else if (queryType == "update") {
1343         query = "UPDATE `" + table + "` SET " + editDis + " WHERE 1";
1344     } else if(queryType == "delete") {
1345         query = "DELETE FROM `" + table + "` WHERE 1";
1346     }
1347     document.sqlform.sql_query.value = query;
1348     sql_box_locked = false;
1349     }
1354   * Inserts multiple fields.
1355   *
1356   */
1357 function insertValueQuery() {
1358     var myQuery = document.sqlform.sql_query;
1359     var myListBox = document.sqlform.dummy;
1361     if(myListBox.options.length > 0) {
1362         sql_box_locked = true;
1363         var chaineAj = "";
1364         var NbSelect = 0;
1365         for(var i=0; i<myListBox.options.length; i++) {
1366             if (myListBox.options[i].selected){
1367                 NbSelect++;
1368                 if (NbSelect > 1)
1369                     chaineAj += ", ";
1370                 chaineAj += myListBox.options[i].value;
1371             }
1372         }
1374         //IE support
1375         if (document.selection) {
1376             myQuery.focus();
1377             sel = document.selection.createRange();
1378             sel.text = chaineAj;
1379             document.sqlform.insert.focus();
1380         }
1381         //MOZILLA/NETSCAPE support
1382         else if (document.sqlform.sql_query.selectionStart || document.sqlform.sql_query.selectionStart == "0") {
1383             var startPos = document.sqlform.sql_query.selectionStart;
1384             var endPos = document.sqlform.sql_query.selectionEnd;
1385             var chaineSql = document.sqlform.sql_query.value;
1387             myQuery.value = chaineSql.substring(0, startPos) + chaineAj + chaineSql.substring(endPos, chaineSql.length);
1388         } else {
1389             myQuery.value += chaineAj;
1390         }
1391         sql_box_locked = false;
1392     }
1396   * listbox redirection
1397   */
1398 function goToUrl(selObj, goToLocation) {
1399     eval("document.location.href = '" + goToLocation + "pos=" + selObj.options[selObj.selectedIndex].value + "'");
1403  * getElement
1404  */
1405 function getElement(e,f){
1406     if(document.layers){
1407         f=(f)?f:self;
1408         if(f.document.layers[e]) {
1409             return f.document.layers[e];
1410         }
1411         for(W=0;W<f.document.layers.length;W++) {
1412             return(getElement(e,f.document.layers[W]));
1413         }
1414     }
1415     if(document.all) {
1416         return document.all[e];
1417     }
1418     return document.getElementById(e);
1422   * Refresh the WYSIWYG-PDF scratchboard after changes have been made
1423   */
1424 function refreshDragOption(e) {
1425     var elm = $('#' + e);
1426     if (elm.css('visibility') == 'visible') {
1427         refreshLayout();
1428     }
1432   * Refresh/resize the WYSIWYG-PDF scratchboard
1433   */
1434 function refreshLayout() {
1435     var elm = $('#pdflayout')
1436     var orientation = $('#orientation_opt').val();
1437     var paper = $('#paper_opt').val();
1439     if (orientation == 'P') {
1440         posa = 'x';
1441         posb = 'y';
1442     } else {
1443         posa = 'y';
1444         posb = 'x';
1445     }
1446     elm.css('width', pdfPaperSize(paper, posa) + 'px');
1447     elm.css('height', pdfPaperSize(paper, posb) + 'px');
1451   * Show/hide the WYSIWYG-PDF scratchboard
1452   */
1453 function ToggleDragDrop(e) {
1454     var elm = $('#' + e);
1455     if (elm.css('visibility') == 'hidden') {
1456         PDFinit(); /* Defined in pdf_pages.php */
1457         elm.css('visibility', 'visible');
1458         elm.css('display', 'block');
1459         $('#showwysiwyg').val('1')
1460     } else {
1461         elm.css('visibility', 'hidden');
1462         elm.css('display', 'none');
1463         $('#showwysiwyg').val('0')
1464     }
1468   * PDF scratchboard: When a position is entered manually, update
1469   * the fields inside the scratchboard.
1470   */
1471 function dragPlace(no, axis, value) {
1472     var elm = $('#table_' + no);
1473     if (axis == 'x') {
1474         elm.css('left', value + 'px');
1475     } else {
1476         elm.css('top', value + 'px');
1477     }
1481  * Returns paper sizes for a given format
1482  */
1483 function pdfPaperSize(format, axis) {
1484     switch (format.toUpperCase()) {
1485         case '4A0':
1486             if (axis == 'x') return 4767.87; else return 6740.79;
1487             break;
1488         case '2A0':
1489             if (axis == 'x') return 3370.39; else return 4767.87;
1490             break;
1491         case 'A0':
1492             if (axis == 'x') return 2383.94; else return 3370.39;
1493             break;
1494         case 'A1':
1495             if (axis == 'x') return 1683.78; else return 2383.94;
1496             break;
1497         case 'A2':
1498             if (axis == 'x') return 1190.55; else return 1683.78;
1499             break;
1500         case 'A3':
1501             if (axis == 'x') return 841.89; else return 1190.55;
1502             break;
1503         case 'A4':
1504             if (axis == 'x') return 595.28; else return 841.89;
1505             break;
1506         case 'A5':
1507             if (axis == 'x') return 419.53; else return 595.28;
1508             break;
1509         case 'A6':
1510             if (axis == 'x') return 297.64; else return 419.53;
1511             break;
1512         case 'A7':
1513             if (axis == 'x') return 209.76; else return 297.64;
1514             break;
1515         case 'A8':
1516             if (axis == 'x') return 147.40; else return 209.76;
1517             break;
1518         case 'A9':
1519             if (axis == 'x') return 104.88; else return 147.40;
1520             break;
1521         case 'A10':
1522             if (axis == 'x') return 73.70; else return 104.88;
1523             break;
1524         case 'B0':
1525             if (axis == 'x') return 2834.65; else return 4008.19;
1526             break;
1527         case 'B1':
1528             if (axis == 'x') return 2004.09; else return 2834.65;
1529             break;
1530         case 'B2':
1531             if (axis == 'x') return 1417.32; else return 2004.09;
1532             break;
1533         case 'B3':
1534             if (axis == 'x') return 1000.63; else return 1417.32;
1535             break;
1536         case 'B4':
1537             if (axis == 'x') return 708.66; else return 1000.63;
1538             break;
1539         case 'B5':
1540             if (axis == 'x') return 498.90; else return 708.66;
1541             break;
1542         case 'B6':
1543             if (axis == 'x') return 354.33; else return 498.90;
1544             break;
1545         case 'B7':
1546             if (axis == 'x') return 249.45; else return 354.33;
1547             break;
1548         case 'B8':
1549             if (axis == 'x') return 175.75; else return 249.45;
1550             break;
1551         case 'B9':
1552             if (axis == 'x') return 124.72; else return 175.75;
1553             break;
1554         case 'B10':
1555             if (axis == 'x') return 87.87; else return 124.72;
1556             break;
1557         case 'C0':
1558             if (axis == 'x') return 2599.37; else return 3676.54;
1559             break;
1560         case 'C1':
1561             if (axis == 'x') return 1836.85; else return 2599.37;
1562             break;
1563         case 'C2':
1564             if (axis == 'x') return 1298.27; else return 1836.85;
1565             break;
1566         case 'C3':
1567             if (axis == 'x') return 918.43; else return 1298.27;
1568             break;
1569         case 'C4':
1570             if (axis == 'x') return 649.13; else return 918.43;
1571             break;
1572         case 'C5':
1573             if (axis == 'x') return 459.21; else return 649.13;
1574             break;
1575         case 'C6':
1576             if (axis == 'x') return 323.15; else return 459.21;
1577             break;
1578         case 'C7':
1579             if (axis == 'x') return 229.61; else return 323.15;
1580             break;
1581         case 'C8':
1582             if (axis == 'x') return 161.57; else return 229.61;
1583             break;
1584         case 'C9':
1585             if (axis == 'x') return 113.39; else return 161.57;
1586             break;
1587         case 'C10':
1588             if (axis == 'x') return 79.37; else return 113.39;
1589             break;
1590         case 'RA0':
1591             if (axis == 'x') return 2437.80; else return 3458.27;
1592             break;
1593         case 'RA1':
1594             if (axis == 'x') return 1729.13; else return 2437.80;
1595             break;
1596         case 'RA2':
1597             if (axis == 'x') return 1218.90; else return 1729.13;
1598             break;
1599         case 'RA3':
1600             if (axis == 'x') return 864.57; else return 1218.90;
1601             break;
1602         case 'RA4':
1603             if (axis == 'x') return 609.45; else return 864.57;
1604             break;
1605         case 'SRA0':
1606             if (axis == 'x') return 2551.18; else return 3628.35;
1607             break;
1608         case 'SRA1':
1609             if (axis == 'x') return 1814.17; else return 2551.18;
1610             break;
1611         case 'SRA2':
1612             if (axis == 'x') return 1275.59; else return 1814.17;
1613             break;
1614         case 'SRA3':
1615             if (axis == 'x') return 907.09; else return 1275.59;
1616             break;
1617         case 'SRA4':
1618             if (axis == 'x') return 637.80; else return 907.09;
1619             break;
1620         case 'LETTER':
1621             if (axis == 'x') return 612.00; else return 792.00;
1622             break;
1623         case 'LEGAL':
1624             if (axis == 'x') return 612.00; else return 1008.00;
1625             break;
1626         case 'EXECUTIVE':
1627             if (axis == 'x') return 521.86; else return 756.00;
1628             break;
1629         case 'FOLIO':
1630             if (axis == 'x') return 612.00; else return 936.00;
1631             break;
1632     } // end switch
1634     return 0;
1638  * for playing media from the BLOB repository
1640  * @param   var     
1641  * @param   var     url_params  main purpose is to pass the token 
1642  * @param   var     bs_ref      BLOB repository reference
1643  * @param   var     m_type      type of BLOB repository media
1644  * @param   var     w_width     width of popup window
1645  * @param   var     w_height    height of popup window
1646  */
1647 function popupBSMedia(url_params, bs_ref, m_type, is_cust_type, w_width, w_height)
1649     // if width not specified, use default
1650     if (w_width == undefined)
1651         w_width = 640;
1653     // if height not specified, use default
1654     if (w_height == undefined)
1655         w_height = 480;
1657     // open popup window (for displaying video/playing audio)
1658     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');
1662  * popups a request for changing MIME types for files in the BLOB repository
1664  * @param   var     db                      database name
1665  * @param   var     table                   table name
1666  * @param   var     reference               BLOB repository reference
1667  * @param   var     current_mime_type       current MIME type associated with BLOB repository reference
1668  */
1669 function requestMIMETypeChange(db, table, reference, current_mime_type)
1671     // no mime type specified, set to default (nothing)
1672     if (undefined == current_mime_type)
1673         current_mime_type = "";
1675     // prompt user for new mime type
1676     var new_mime_type = prompt("Enter custom MIME type", current_mime_type);
1678     // if new mime_type is specified and is not the same as the previous type, request for mime type change
1679     if (new_mime_type && new_mime_type != current_mime_type)
1680         changeMIMEType(db, table, reference, new_mime_type);
1684  * changes MIME types for files in the BLOB repository
1686  * @param   var     db              database name
1687  * @param   var     table           table name
1688  * @param   var     reference       BLOB repository reference
1689  * @param   var     mime_type       new MIME type to be associated with BLOB repository reference
1690  */
1691 function changeMIMEType(db, table, reference, mime_type)
1693     // specify url and parameters for jQuery POST 
1694     var mime_chg_url = 'bs_change_mime_type.php';
1695     var params = { bs_db: db, bs_table: table, bs_reference: reference, bs_new_mime_type: mime_type };
1697     // jQuery POST
1698     jQuery.post(mime_chg_url, params); 
1702  * Jquery Coding for inline editing SQL_QUERY
1703  */
1704 $(document).ready(function(){
1705     var $oldText,$db,$table,$token,$sql_query;
1706     $oldText=$(".syntax").html();
1707     $("#inline_edit").click(function(){
1708         $db=$("input[name='db']").val();
1709         $table=$("input[name='table']").val();
1710         $token=$("input[name='token']").val();
1711         $sql_query=$("input[name='sql_query']").val();
1712         $(".syntax").replaceWith("<textarea name=\"sql_query_edit\" id=\"sql_query_edit\">"+ $sql_query +"</textarea><input type=\"button\" id=\"btnSave\" value=\"" + PMA_messages['strGo'] + "\"><input type=\"button\" id=\"btnDiscard\" value=\"" + PMA_messages['strCancel'] + "\">");
1713         return false;
1714     });
1716     $("#btnSave").live("click",function(){
1717         window.location.replace("import.php?db="+$db+"&table="+$table+"&sql_query="+$("#sql_query_edit").val()+"&show_query=1&token="+$token+"");
1718     });
1720     $("#btnDiscard").live("click",function(){
1721         $(".sql").html("<span class=\"syntax\">"+$oldText+"</span>");
1722     });
1724     $('.sqlbutton').click(function(evt){
1725         insertQuery(evt.target.id);
1726         return false;
1727     });