1 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 * general function, usally for data manipulation pages
8 * @var sql_box_locked lock for the sqlbox textarea in the querybox/querywindow
10 var sql_box_locked = false;
13 * @var array holds elements which content should only selected once
15 var only_once_elements = new Array();
18 * @var ajax_message_init boolean boolean that stores status of
19 * notification for PMA_ajaxShowNotification
21 var ajax_message_init = false;
24 * Generate a new password and copy it to the password input areas
26 * @param object the form that holds the password fields
28 * @return boolean always true
30 function suggestPassword(passwd_form) {
31 // restrict the password to just letters and numbers to avoid problems:
32 // "editors and viewers regard the password as multiple words and
33 // things like double click no longer work"
34 var pwchars = "abcdefhjmnpqrstuvwxyz23456789ABCDEFGHJKLMNPQRSTUVWYXZ";
35 var passwordlength = 16; // do we want that to be dynamic? no, keep it simple :)
36 var passwd = passwd_form.generated_pw;
39 for ( i = 0; i < passwordlength; i++ ) {
40 passwd.value += pwchars.charAt( Math.floor( Math.random() * pwchars.length ) )
42 passwd_form.text_pma_pw.value = passwd.value;
43 passwd_form.text_pma_pw2.value = passwd.value;
48 * for libraries/display_change_password.lib.php
49 * libraries/user_password.php
53 function displayPasswordGenerateButton() {
54 $('#tr_element_before_generate_password').parent().append('<tr><td>' + PMA_messages['strGeneratePassword'] + '</td><td><input type="button" id="button_generate_password" value="' + PMA_messages['strGenerate'] + '" onclick="suggestPassword(this.form)" /><input type="text" name="generated_pw" id="generated_pw" /></td></tr>');
55 $('#div_element_before_generate_password').parent().append('<div class="item"><label for="button_generate_password">' + PMA_messages['strGeneratePassword'] + ':</label><span class="options"><input type="button" id="button_generate_password" value="' + PMA_messages['strGenerate'] + '" onclick="suggestPassword(this.form)" /></span><input type="text" name="generated_pw" id="generated_pw" /></div>');
60 * selects the content of a given object, f.e. a textarea
62 * @param object element element of which the content will be selected
63 * @param var lock variable which holds the lock for this element
64 * or true, if no lock exists
65 * @param boolean only_once if true this is only done once
66 * f.e. only on first focus
68 function selectContent( element, lock, only_once ) {
69 if ( only_once && only_once_elements[element.name] ) {
73 only_once_elements[element.name] = true;
83 * Displays a confirmation box before submitting a "DROP DATABASE" query.
84 * This function is called while clicking links
86 * @param object the link
87 * @param object the sql query to submit
89 * @return boolean whether to run the query or not
91 function confirmLinkDropDB(theLink, theSqlQuery)
93 // Confirmation is not required in the configuration file
94 // or browser is Opera (crappy js implementation)
95 if (PMA_messages['strDoYouReally'] == '' || typeof(window.opera) != 'undefined') {
99 var is_confirmed = confirm(PMA_messages['strDropDatabaseStrongWarning'] + '\n' + PMA_messages['strDoYouReally'] + ' :\n' + theSqlQuery);
101 theLink.href += '&is_js_confirmed=1';
105 } // end of the 'confirmLinkDropDB()' function
108 * Displays a confirmation box before to submit a "DROP/DELETE/ALTER" query.
109 * This function is called while clicking links
111 * @param object the link
112 * @param object the sql query to submit
114 * @return boolean whether to run the query or not
116 function confirmLink(theLink, theSqlQuery)
118 // Confirmation is not required in the configuration file
119 // or browser is Opera (crappy js implementation)
120 if (PMA_messages['strDoYouReally'] == '' || typeof(window.opera) != 'undefined') {
124 var is_confirmed = confirm(PMA_messages['strDoYouReally'] + ' :\n' + theSqlQuery);
126 if ( typeof(theLink.href) != 'undefined' ) {
127 theLink.href += '&is_js_confirmed=1';
128 } else if ( typeof(theLink.form) != 'undefined' ) {
129 theLink.form.action += '?is_js_confirmed=1';
134 } // end of the 'confirmLink()' function
138 * Displays a confirmation box before doing some action
140 * @param object the message to display
142 * @return boolean whether to run the query or not
144 * @todo used only by libraries/display_tbl.lib.php. figure out how it is used
145 * and replace with a jQuery equivalent
147 function confirmAction(theMessage)
149 // TODO: Confirmation is not required in the configuration file
150 // or browser is Opera (crappy js implementation)
151 if (typeof(window.opera) != 'undefined') {
155 var is_confirmed = confirm(theMessage);
158 } // end of the 'confirmAction()' function
162 * Displays an error message if a "DROP DATABASE" statement is submitted
163 * while it isn't allowed, else confirms a "DROP/DELETE/ALTER" query before
164 * sumitting it if required.
165 * This function is called by the 'checkSqlQuery()' js function.
167 * @param object the form
168 * @param object the sql query textarea
170 * @return boolean whether to run the query or not
172 * @see checkSqlQuery()
174 function confirmQuery(theForm1, sqlQuery1)
176 // Confirmation is not required in the configuration file
177 if (PMA_messages['strDoYouReally'] == '') {
181 // The replace function (js1.2) isn't supported
182 else if (typeof(sqlQuery1.value.replace) == 'undefined') {
186 // js1.2+ -> validation with regular expressions
188 // "DROP DATABASE" statement isn't allowed
189 if (PMA_messages['strNoDropDatabases'] != '') {
190 var drop_re = new RegExp('(^|;)\\s*DROP\\s+(IF EXISTS\\s+)?DATABASE\\s', 'i');
191 if (drop_re.test(sqlQuery1.value)) {
192 alert(PMA_messages['strNoDropDatabases']);
199 // Confirms a "DROP/DELETE/ALTER/TRUNCATE" statement
201 // TODO: find a way (if possible) to use the parser-analyser
202 // for this kind of verification
203 // For now, I just added a ^ to check for the statement at
204 // beginning of expression
206 var do_confirm_re_0 = new RegExp('^\\s*DROP\\s+(IF EXISTS\\s+)?(TABLE|DATABASE|PROCEDURE)\\s', 'i');
207 var do_confirm_re_1 = new RegExp('^\\s*ALTER\\s+TABLE\\s+((`[^`]+`)|([A-Za-z0-9_$]+))\\s+DROP\\s', 'i');
208 var do_confirm_re_2 = new RegExp('^\\s*DELETE\\s+FROM\\s', 'i');
209 var do_confirm_re_3 = new RegExp('^\\s*TRUNCATE\\s', 'i');
211 if (do_confirm_re_0.test(sqlQuery1.value)
212 || do_confirm_re_1.test(sqlQuery1.value)
213 || do_confirm_re_2.test(sqlQuery1.value)
214 || do_confirm_re_3.test(sqlQuery1.value)) {
215 var message = (sqlQuery1.value.length > 100)
216 ? sqlQuery1.value.substr(0, 100) + '\n ...'
218 var is_confirmed = confirm(PMA_messages['strDoYouReally'] + ' :\n' + message);
219 // statement is confirmed -> update the
220 // "is_js_confirmed" form field so the confirm test won't be
221 // run on the server side and allows to submit the form
223 theForm1.elements['is_js_confirmed'].value = 1;
226 // statement is rejected -> do not submit the form
231 } // end if (handle confirm box result)
232 } // end if (display confirm box)
233 } // end confirmation stuff
236 } // end of the 'confirmQuery()' function
240 * Displays a confirmation box before disabling the BLOB repository for a given database.
241 * This function is called while clicking links
243 * @param object the database
245 * @return boolean whether to disable the repository or not
247 function confirmDisableRepository(theDB)
249 // Confirmation is not required in the configuration file
250 // or browser is Opera (crappy js implementation)
251 if (PMA_messages['strDoYouReally'] == '' || typeof(window.opera) != 'undefined') {
255 var is_confirmed = confirm(PMA_messages['strBLOBRepositoryDisableStrongWarning'] + '\n' + PMA_messages['strBLOBRepositoryDisableAreYouSure']);
258 } // end of the 'confirmDisableBLOBRepository()' function
262 * Displays an error message if the user submitted the sql query form with no
263 * sql query, else checks for "DROP/DELETE/ALTER" statements
265 * @param object the form
267 * @return boolean always false
269 * @see confirmQuery()
271 function checkSqlQuery(theForm)
273 var sqlQuery = theForm.elements['sql_query'];
276 // The replace function (js1.2) isn't supported -> basic tests
277 if (typeof(sqlQuery.value.replace) == 'undefined') {
278 isEmpty = (sqlQuery.value == '') ? 1 : 0;
279 if (isEmpty && typeof(theForm.elements['sql_file']) != 'undefined') {
280 isEmpty = (theForm.elements['sql_file'].value == '') ? 1 : 0;
282 if (isEmpty && typeof(theForm.elements['sql_localfile']) != 'undefined') {
283 isEmpty = (theForm.elements['sql_localfile'].value == '') ? 1 : 0;
285 if (isEmpty && typeof(theForm.elements['id_bookmark']) != 'undefined') {
286 isEmpty = (theForm.elements['id_bookmark'].value == null || theForm.elements['id_bookmark'].value == '');
289 // js1.2+ -> validation with regular expressions
291 var space_re = new RegExp('\\s+');
292 if (typeof(theForm.elements['sql_file']) != 'undefined' &&
293 theForm.elements['sql_file'].value.replace(space_re, '') != '') {
296 if (typeof(theForm.elements['sql_localfile']) != 'undefined' &&
297 theForm.elements['sql_localfile'].value.replace(space_re, '') != '') {
300 if (isEmpty && typeof(theForm.elements['id_bookmark']) != 'undefined' &&
301 (theForm.elements['id_bookmark'].value != null || theForm.elements['id_bookmark'].value != '') &&
302 theForm.elements['id_bookmark'].selectedIndex != 0
306 // Checks for "DROP/DELETE/ALTER" statements
307 if (sqlQuery.value.replace(space_re, '') != '') {
308 if (confirmQuery(theForm, sqlQuery)) {
320 alert(PMA_messages['strFormEmpty']);
326 } // end of the 'checkSqlQuery()' function
328 // Global variable row_class is set to even
329 var row_class = 'even';
332 * Generates a row dynamically in the differences table displaying
333 * the complete statistics of difference in table like number of
334 * rows to be updated, number of rows to be inserted, number of
335 * columns to be added, number of columns to be removed, etc.
337 * @param index index of matching table
338 * @param update_size number of rows/column to be updated
339 * @param insert_size number of rows/coulmns to be inserted
340 * @param remove_size number of columns to be removed
341 * @param insert_index number of indexes to be inserted
342 * @param remove_index number of indexes to be removed
343 * @param img_obj image object
344 * @param table_name name of the table
347 function showDetails(i, update_size, insert_size, remove_size, insert_index, remove_index, img_obj, table_name)
349 // The path of the image is split to facilitate comparison
350 var relative_path = (img_obj.src).split("themes/");
352 // The image source is changed when the showDetails function is called.
353 if (relative_path[1] == 'original/img/new_data_hovered.jpg') {
354 img_obj.src = "./themes/original/img/new_data_selected_hovered.jpg";
355 img_obj.alt = PMA_messages['strClickToUnselect']; //only for IE browser
356 } else if (relative_path[1] == 'original/img/new_struct_hovered.jpg') {
357 img_obj.src = "./themes/original/img/new_struct_selected_hovered.jpg";
358 img_obj.alt = PMA_messages['strClickToUnselect'];
359 } else if (relative_path[1] == 'original/img/new_struct_selected_hovered.jpg') {
360 img_obj.src = "./themes/original/img/new_struct_hovered.jpg";
361 img_obj.alt = PMA_messages['strClickToSelect'];
362 } else if (relative_path[1] == 'original/img/new_data_selected_hovered.jpg') {
363 img_obj.src = "./themes/original/img/new_data_hovered.jpg";
364 img_obj.alt = PMA_messages['strClickToSelect'];
367 var div = document.getElementById("list");
368 var table = div.getElementsByTagName("table")[0];
369 var table_body = table.getElementsByTagName("tbody")[0];
371 //Global variable row_class is being used
372 if (row_class == 'even') {
377 // 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.
378 if ((relative_path[1] != 'original/img/new_struct_selected_hovered.jpg') && (relative_path[1] != 'original/img/new_data_selected_hovered.jpg')) {
380 var newRow = document.createElement("tr");
381 newRow.setAttribute("class", row_class);
382 newRow.className = row_class;
383 // Id assigned to this row element is same as the index of this table name in the matching_tables/source_tables_uncommon array
384 newRow.setAttribute("id" , i);
386 var table_name_cell = document.createElement("td");
387 table_name_cell.align = "center";
388 table_name_cell.innerHTML = table_name ;
390 newRow.appendChild(table_name_cell);
392 var create_table = document.createElement("td");
393 create_table.align = "center";
395 var add_cols = document.createElement("td");
396 add_cols.align = "center";
398 var remove_cols = document.createElement("td");
399 remove_cols.align = "center";
401 var alter_cols = document.createElement("td");
402 alter_cols.align = "center";
404 var add_index = document.createElement("td");
405 add_index.align = "center";
407 var delete_index = document.createElement("td");
408 delete_index.align = "center";
410 var update_rows = document.createElement("td");
411 update_rows.align = "center";
413 var insert_rows = document.createElement("td");
414 insert_rows.align = "center";
416 var tick_image = document.createElement("img");
417 tick_image.src = "./themes/original/img/s_success.png";
419 if (update_size == '' && insert_size == '' && remove_size == '') {
421 This is the case when the table needs to be created in target database.
423 create_table.appendChild(tick_image);
424 add_cols.innerHTML = "--";
425 remove_cols.innerHTML = "--";
426 alter_cols.innerHTML = "--";
427 delete_index.innerHTML = "--";
428 add_index.innerHTML = "--";
429 update_rows.innerHTML = "--";
430 insert_rows.innerHTML = "--";
432 newRow.appendChild(create_table);
433 newRow.appendChild(add_cols);
434 newRow.appendChild(remove_cols);
435 newRow.appendChild(alter_cols);
436 newRow.appendChild(delete_index);
437 newRow.appendChild(add_index);
438 newRow.appendChild(update_rows);
439 newRow.appendChild(insert_rows);
441 } else if (update_size == '' && remove_size == '') {
443 This is the case when data difference is displayed in the
444 table which is present in source but absent from target database
446 create_table.innerHTML = "--";
447 add_cols.innerHTML = "--";
448 remove_cols.innerHTML = "--";
449 alter_cols.innerHTML = "--";
450 add_index.innerHTML = "--";
451 delete_index.innerHTML = "--";
452 update_rows.innerHTML = "--";
453 insert_rows.innerHTML = insert_size;
455 newRow.appendChild(create_table);
456 newRow.appendChild(add_cols);
457 newRow.appendChild(remove_cols);
458 newRow.appendChild(alter_cols);
459 newRow.appendChild(delete_index);
460 newRow.appendChild(add_index);
461 newRow.appendChild(update_rows);
462 newRow.appendChild(insert_rows);
464 } else if (remove_size == '') {
466 This is the case when data difference between matching_tables is displayed.
468 create_table.innerHTML = "--";
469 add_cols.innerHTML = "--";
470 remove_cols.innerHTML = "--";
471 alter_cols.innerHTML = "--";
472 add_index.innerHTML = "--";
473 delete_index.innerHTML = "--";
474 update_rows.innerHTML = update_size;
475 insert_rows.innerHTML = insert_size;
477 newRow.appendChild(create_table);
478 newRow.appendChild(add_cols);
479 newRow.appendChild(remove_cols);
480 newRow.appendChild(alter_cols);
481 newRow.appendChild(delete_index);
482 newRow.appendChild(add_index);
483 newRow.appendChild(update_rows);
484 newRow.appendChild(insert_rows);
488 This is the case when structure difference between matching_tables id displayed
490 create_table.innerHTML = "--";
491 add_cols.innerHTML = insert_size;
492 remove_cols.innerHTML = remove_size;
493 alter_cols.innerHTML = update_size;
494 delete_index.innerHTML = remove_index;
495 add_index.innerHTML = insert_index;
496 update_rows.innerHTML = "--";
497 insert_rows.innerHTML = "--";
499 newRow.appendChild(create_table);
500 newRow.appendChild(add_cols);
501 newRow.appendChild(remove_cols);
502 newRow.appendChild(alter_cols);
503 newRow.appendChild(delete_index);
504 newRow.appendChild(add_index);
505 newRow.appendChild(update_rows);
506 newRow.appendChild(insert_rows);
508 table_body.appendChild(newRow);
510 } else if ((relative_path[1] != 'original/img/new_struct_hovered.jpg') && (relative_path[1] != 'original/img/new_data_hovered.jpg')) {
511 //The case when the row showing the details need to be removed from the table i.e. the difference button is deselected now.
512 var table_rows = table_body.getElementsByTagName("tr");
515 for (j=0; j < table_rows.length; j++)
517 if (table_rows[j].id == i) {
519 table_rows[j].parentNode.removeChild(table_rows[j]);
522 //The table row css is being adjusted. Class "odd" for odd rows and "even" for even rows should be maintained.
523 for(index = 0; index < table_rows.length; index++)
525 row_class_element = table_rows[index].getAttribute('class');
526 if (row_class_element == "even") {
527 table_rows[index].setAttribute("class","odd"); // for Mozilla firefox
528 table_rows[index].className = "odd"; // for IE browser
530 table_rows[index].setAttribute("class","even"); // for Mozilla firefox
531 table_rows[index].className = "even"; // for IE browser
538 * Changes the image on hover effects
540 * @param img_obj the image object whose source needs to be changed
543 function change_Image(img_obj)
545 var relative_path = (img_obj.src).split("themes/");
547 if (relative_path[1] == 'original/img/new_data.jpg') {
548 img_obj.src = "./themes/original/img/new_data_hovered.jpg";
549 } else if (relative_path[1] == 'original/img/new_struct.jpg') {
550 img_obj.src = "./themes/original/img/new_struct_hovered.jpg";
551 } else if (relative_path[1] == 'original/img/new_struct_hovered.jpg') {
552 img_obj.src = "./themes/original/img/new_struct.jpg";
553 } else if (relative_path[1] == 'original/img/new_data_hovered.jpg') {
554 img_obj.src = "./themes/original/img/new_data.jpg";
555 } else if (relative_path[1] == 'original/img/new_data_selected.jpg') {
556 img_obj.src = "./themes/original/img/new_data_selected_hovered.jpg";
557 } else if(relative_path[1] == 'original/img/new_struct_selected.jpg') {
558 img_obj.src = "./themes/original/img/new_struct_selected_hovered.jpg";
559 } else if (relative_path[1] == 'original/img/new_struct_selected_hovered.jpg') {
560 img_obj.src = "./themes/original/img/new_struct_selected.jpg";
561 } else if (relative_path[1] == 'original/img/new_data_selected_hovered.jpg') {
562 img_obj.src = "./themes/original/img/new_data_selected.jpg";
567 * Generates the URL containing the list of selected table ids for synchronization and
568 * a variable checked for confirmation of deleting previous rows from target tables
570 * @param token the token generated for each PMA form
573 function ApplySelectedChanges(token)
575 var div = document.getElementById("list");
576 var table = div.getElementsByTagName('table')[0];
577 var table_body = table.getElementsByTagName('tbody')[0];
578 // Get all the rows from the details table
579 var table_rows = table_body.getElementsByTagName('tr');
580 var x = table_rows.length;
583 Append the token at the beginning of the query string followed by
584 Table_ids that shows that "Apply Selected Changes" button is pressed
586 var append_string = "?token="+token+"&Table_ids="+1;
588 append_string += "&";
589 append_string += i+"="+table_rows[i].id;
592 // Getting the value of checkbox delete_rows
593 var checkbox = document.getElementById("delete_rows");
594 if (checkbox.checked){
595 append_string += "&checked=true";
597 append_string += "&checked=false";
599 //Appending the token and list of table ids in the URL
600 location.href += token;
601 location.href += append_string;
605 * Displays an error message if any text field
606 * is left empty other than the port field.
608 * @param string the form name
609 * @param object the form
611 * @return boolean whether the form field is empty or not
613 function validateConnection(form_name, form_obj)
616 var src_hostfilled = true;
617 var trg_hostfilled = true;
619 for (var i=1; i<form_name.elements.length; i++)
621 // All the text fields are checked excluding the port field because the default port can be used.
622 if ((form_name.elements[i].type == 'text') && (form_name.elements[i].name != 'src_port') && (form_name.elements[i].name != 'trg_port')) {
623 check = emptyFormElements(form_obj, form_name.elements[i].name);
625 element = form_name.elements[i].name;
626 if (form_name.elements[i].name == 'src_host') {
627 src_hostfilled = false;
630 if (form_name.elements[i].name == 'trg_host') {
631 trg_hostfilled = false;
634 if ((form_name.elements[i].name == 'src_socket' && src_hostfilled==false) || (form_name.elements[i].name == 'trg_socket' && trg_hostfilled==false))
644 alert(PMA_messages['strFormEmpty']);
651 * Check if a form's element is empty.
652 * An element containing only spaces is also considered empty
654 * @param object the form
655 * @param string the name of the form field to put the focus on
657 * @return boolean whether the form field is empty or not
659 function emptyCheckTheField(theForm, theFieldName)
662 var theField = theForm.elements[theFieldName];
663 // Whether the replace function (js1.2) is supported or not
664 var isRegExp = (typeof(theField.value.replace) != 'undefined');
667 isEmpty = (theField.value == '') ? 1 : 0;
669 var space_re = new RegExp('\\s+');
670 isEmpty = (theField.value.replace(space_re, '') == '') ? 1 : 0;
674 } // end of the 'emptyCheckTheField()' function
678 * Check whether a form field is empty or not
680 * @param object the form
681 * @param string the name of the form field to put the focus on
683 * @return boolean whether the form field is empty or not
685 function emptyFormElements(theForm, theFieldName)
687 var theField = theForm.elements[theFieldName];
688 var isEmpty = emptyCheckTheField(theForm, theFieldName);
692 } // end of the 'emptyFormElements()' function
696 * Ensures a value submitted in a form is numeric and is in a range
698 * @param object the form
699 * @param string the name of the form field to check
700 * @param integer the minimum authorized value
701 * @param integer the maximum authorized value
703 * @return boolean whether a valid number has been submitted or not
705 function checkFormElementInRange(theForm, theFieldName, message, min, max)
707 var theField = theForm.elements[theFieldName];
708 var val = parseInt(theField.value);
710 if (typeof(min) == 'undefined') {
713 if (typeof(max) == 'undefined') {
714 max = Number.MAX_VALUE;
720 alert(PMA_messages['strNotNumber']);
724 // It's a number but it is not between min and max
725 else if (val < min || val > max) {
727 alert(message.replace('%d', val));
731 // It's a valid number
733 theField.value = val;
737 } // end of the 'checkFormElementInRange()' function
740 function checkTableEditForm(theForm, fieldsCnt)
742 // TODO: avoid sending a message if user just wants to add a line
743 // on the form but has not completed at least one field name
745 var atLeastOneField = 0;
746 var i, elm, elm2, elm3, val, id;
748 for (i=0; i<fieldsCnt; i++)
750 id = "#field_" + i + "_2";
753 if (val == 'VARCHAR' || val == 'CHAR' || val == 'BIT' || val == 'VARBINARY' || val == 'BINARY') {
754 elm2 = $("#field_" + i + "_3");
755 val = parseInt(elm2.val());
756 elm3 = $("#field_" + i + "_1");
757 if (isNaN(val) && elm3.val() != "") {
759 alert(PMA_messages['strNotNumber']);
765 if (atLeastOneField == 0) {
766 id = "field_" + i + "_1";
767 if (!emptyCheckTheField(theForm, id)) {
772 if (atLeastOneField == 0) {
773 var theField = theForm.elements["field_0_1"];
774 alert(PMA_messages['strFormEmpty']);
780 } // enf of the 'checkTableEditForm()' function
784 * Ensures the choice between 'transmit', 'zipped', 'gzipped' and 'bzipped'
785 * checkboxes is consistant
787 * @param object the form
788 * @param string a code for the action that causes this function to be run
790 * @return boolean always true
792 function checkTransmitDump(theForm, theAction)
794 var formElts = theForm.elements;
796 // 'zipped' option has been checked
797 if (theAction == 'zip' && formElts['zip'].checked) {
798 if (!formElts['asfile'].checked) {
799 theForm.elements['asfile'].checked = true;
801 if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) {
802 theForm.elements['gzip'].checked = false;
804 if (typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked) {
805 theForm.elements['bzip'].checked = false;
808 // 'gzipped' option has been checked
809 else if (theAction == 'gzip' && formElts['gzip'].checked) {
810 if (!formElts['asfile'].checked) {
811 theForm.elements['asfile'].checked = true;
813 if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
814 theForm.elements['zip'].checked = false;
816 if (typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked) {
817 theForm.elements['bzip'].checked = false;
820 // 'bzipped' option has been checked
821 else if (theAction == 'bzip' && formElts['bzip'].checked) {
822 if (!formElts['asfile'].checked) {
823 theForm.elements['asfile'].checked = true;
825 if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
826 theForm.elements['zip'].checked = false;
828 if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) {
829 theForm.elements['gzip'].checked = false;
832 // 'transmit' option has been unchecked
833 else if (theAction == 'transmit' && !formElts['asfile'].checked) {
834 if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
835 theForm.elements['zip'].checked = false;
837 if ((typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked)) {
838 theForm.elements['gzip'].checked = false;
840 if ((typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked)) {
841 theForm.elements['bzip'].checked = false;
846 } // end of the 'checkTransmitDump()' function
849 * Row marking in horizontal mode (use "live" so that it works also for
850 * next pages reached via AJAX); a tr may have the class noclick to remove
853 $(document).ready(function() {
854 $('tr.odd:not(.noclick), tr.even:not(.noclick)').live('click',function() {
856 $tr.toggleClass('marked');
857 $tr.children().toggleClass('marked');
862 * Row highlighting in horizontal mode (use "live"
863 * so that it works also for pages reached via AJAX)
865 $(document).ready(function() {
866 $('tr.odd, tr.even').live('hover',function() {
868 $tr.toggleClass('hover');
869 $tr.children().toggleClass('hover');
874 * This array is used to remember mark status of rows in browse mode
876 var marked_row = new Array;
879 * marks all rows and selects its first checkbox inside the given element
880 * the given element is usaly a table or a div containing the table or tables
882 * @param container DOM element
884 function markAllRows( container_id ) {
886 $("#"+container_id).find("input:checkbox:enabled").attr('checked', 'checked')
887 .parents("tr").addClass("marked");
892 * marks all rows and selects its first checkbox inside the given element
893 * the given element is usaly a table or a div containing the table or tables
895 * @param container DOM element
897 function unMarkAllRows( container_id ) {
899 $("#"+container_id).find("input:checkbox:enabled").removeAttr('checked')
900 .parents("tr").removeClass("marked");
905 * Checks/unchecks all checkbox in given conainer (f.e. a form, fieldset or div)
907 * @param string container_id the container id
908 * @param boolean state new value for checkbox (true or false)
909 * @return boolean always true
911 function setCheckboxes( container_id, state ) {
914 $("#"+container_id).find("input:checkbox").attr('checked', 'checked');
917 $("#"+container_id).find("input:checkbox").removeAttr('checked');
921 } // end of the 'setCheckboxes()' function
924 * Checks/unchecks all options of a <select> element
926 * @param string the form name
927 * @param string the element name
928 * @param boolean whether to check or to uncheck the element
930 * @return boolean always true
932 function setSelectOptions(the_form, the_select, do_check)
936 $("form[name='"+ the_form +"']").find("select[name='"+the_select+"']").find("option").attr('selected', 'selected');
939 $("form[name='"+ the_form +"']").find("select[name="+the_select+"]").find("option").removeAttr('selected');
942 } // end of the 'setSelectOptions()' function
946 * Create quick sql statements.
949 function insertQuery(queryType) {
950 var myQuery = document.sqlform.sql_query;
951 var myListBox = document.sqlform.dummy;
953 var table = document.sqlform.table.value;
955 if (myListBox.options.length > 0) {
956 sql_box_locked = true;
961 for (var i=0; i < myListBox.options.length; i++) {
968 chaineAj += myListBox.options[i].value;
969 valDis += "[value-" + NbSelect + "]";
970 editDis += myListBox.options[i].value + "=[value-" + NbSelect + "]";
972 if (queryType == "selectall") {
973 query = "SELECT * FROM `" + table + "` WHERE 1";
974 } else if (queryType == "select") {
975 query = "SELECT " + chaineAj + " FROM `" + table + "` WHERE 1";
976 } else if (queryType == "insert") {
977 query = "INSERT INTO `" + table + "`(" + chaineAj + ") VALUES (" + valDis + ")";
978 } else if (queryType == "update") {
979 query = "UPDATE `" + table + "` SET " + editDis + " WHERE 1";
980 } else if(queryType == "delete") {
981 query = "DELETE FROM `" + table + "` WHERE 1";
983 document.sqlform.sql_query.value = query;
984 sql_box_locked = false;
990 * Inserts multiple fields.
993 function insertValueQuery() {
994 var myQuery = document.sqlform.sql_query;
995 var myListBox = document.sqlform.dummy;
997 if(myListBox.options.length > 0) {
998 sql_box_locked = true;
1001 for(var i=0; i<myListBox.options.length; i++) {
1002 if (myListBox.options[i].selected){
1006 chaineAj += myListBox.options[i].value;
1011 if (document.selection) {
1013 sel = document.selection.createRange();
1014 sel.text = chaineAj;
1015 document.sqlform.insert.focus();
1017 //MOZILLA/NETSCAPE support
1018 else if (document.sqlform.sql_query.selectionStart || document.sqlform.sql_query.selectionStart == "0") {
1019 var startPos = document.sqlform.sql_query.selectionStart;
1020 var endPos = document.sqlform.sql_query.selectionEnd;
1021 var chaineSql = document.sqlform.sql_query.value;
1023 myQuery.value = chaineSql.substring(0, startPos) + chaineAj + chaineSql.substring(endPos, chaineSql.length);
1025 myQuery.value += chaineAj;
1027 sql_box_locked = false;
1032 * listbox redirection
1034 function goToUrl(selObj, goToLocation) {
1035 eval("document.location.href = '" + goToLocation + "pos=" + selObj.options[selObj.selectedIndex].value + "'");
1041 function getElement(e,f){
1042 if(document.layers){
1044 if(f.document.layers[e]) {
1045 return f.document.layers[e];
1047 for(W=0;W<f.document.layers.length;W++) {
1048 return(getElement(e,f.document.layers[W]));
1052 return document.all[e];
1054 return document.getElementById(e);
1058 * Refresh the WYSIWYG scratchboard after changes have been made
1060 function refreshDragOption(e) {
1061 var elm = $('#' + e);
1062 if (elm.css('visibility') == 'visible') {
1069 * Refresh/resize the WYSIWYG scratchboard
1071 function refreshLayout() {
1072 var elm = $('#pdflayout')
1073 var orientation = $('#orientation_opt').val();
1074 if($('#paper_opt').length==1){
1075 var paper = $('#paper_opt').val();
1079 if (orientation == 'P') {
1086 elm.css('width', pdfPaperSize(paper, posa) + 'px');
1087 elm.css('height', pdfPaperSize(paper, posb) + 'px');
1091 * Show/hide the WYSIWYG scratchboard
1093 function ToggleDragDrop(e) {
1094 var elm = $('#' + e);
1095 if (elm.css('visibility') == 'hidden') {
1096 PDFinit(); /* Defined in pdf_pages.php */
1097 elm.css('visibility', 'visible');
1098 elm.css('display', 'block');
1099 $('#showwysiwyg').val('1')
1101 elm.css('visibility', 'hidden');
1102 elm.css('display', 'none');
1103 $('#showwysiwyg').val('0')
1108 * PDF scratchboard: When a position is entered manually, update
1109 * the fields inside the scratchboard.
1111 function dragPlace(no, axis, value) {
1112 var elm = $('#table_' + no);
1114 elm.css('left', value + 'px');
1116 elm.css('top', value + 'px');
1121 * Returns paper sizes for a given format
1123 function pdfPaperSize(format, axis) {
1124 switch (format.toUpperCase()) {
1126 if (axis == 'x') return 4767.87; else return 6740.79;
1129 if (axis == 'x') return 3370.39; else return 4767.87;
1132 if (axis == 'x') return 2383.94; else return 3370.39;
1135 if (axis == 'x') return 1683.78; else return 2383.94;
1138 if (axis == 'x') return 1190.55; else return 1683.78;
1141 if (axis == 'x') return 841.89; else return 1190.55;
1144 if (axis == 'x') return 595.28; else return 841.89;
1147 if (axis == 'x') return 419.53; else return 595.28;
1150 if (axis == 'x') return 297.64; else return 419.53;
1153 if (axis == 'x') return 209.76; else return 297.64;
1156 if (axis == 'x') return 147.40; else return 209.76;
1159 if (axis == 'x') return 104.88; else return 147.40;
1162 if (axis == 'x') return 73.70; else return 104.88;
1165 if (axis == 'x') return 2834.65; else return 4008.19;
1168 if (axis == 'x') return 2004.09; else return 2834.65;
1171 if (axis == 'x') return 1417.32; else return 2004.09;
1174 if (axis == 'x') return 1000.63; else return 1417.32;
1177 if (axis == 'x') return 708.66; else return 1000.63;
1180 if (axis == 'x') return 498.90; else return 708.66;
1183 if (axis == 'x') return 354.33; else return 498.90;
1186 if (axis == 'x') return 249.45; else return 354.33;
1189 if (axis == 'x') return 175.75; else return 249.45;
1192 if (axis == 'x') return 124.72; else return 175.75;
1195 if (axis == 'x') return 87.87; else return 124.72;
1198 if (axis == 'x') return 2599.37; else return 3676.54;
1201 if (axis == 'x') return 1836.85; else return 2599.37;
1204 if (axis == 'x') return 1298.27; else return 1836.85;
1207 if (axis == 'x') return 918.43; else return 1298.27;
1210 if (axis == 'x') return 649.13; else return 918.43;
1213 if (axis == 'x') return 459.21; else return 649.13;
1216 if (axis == 'x') return 323.15; else return 459.21;
1219 if (axis == 'x') return 229.61; else return 323.15;
1222 if (axis == 'x') return 161.57; else return 229.61;
1225 if (axis == 'x') return 113.39; else return 161.57;
1228 if (axis == 'x') return 79.37; else return 113.39;
1231 if (axis == 'x') return 2437.80; else return 3458.27;
1234 if (axis == 'x') return 1729.13; else return 2437.80;
1237 if (axis == 'x') return 1218.90; else return 1729.13;
1240 if (axis == 'x') return 864.57; else return 1218.90;
1243 if (axis == 'x') return 609.45; else return 864.57;
1246 if (axis == 'x') return 2551.18; else return 3628.35;
1249 if (axis == 'x') return 1814.17; else return 2551.18;
1252 if (axis == 'x') return 1275.59; else return 1814.17;
1255 if (axis == 'x') return 907.09; else return 1275.59;
1258 if (axis == 'x') return 637.80; else return 907.09;
1261 if (axis == 'x') return 612.00; else return 792.00;
1264 if (axis == 'x') return 612.00; else return 1008.00;
1267 if (axis == 'x') return 521.86; else return 756.00;
1270 if (axis == 'x') return 612.00; else return 936.00;
1278 * for playing media from the BLOB repository
1281 * @param var url_params main purpose is to pass the token
1282 * @param var bs_ref BLOB repository reference
1283 * @param var m_type type of BLOB repository media
1284 * @param var w_width width of popup window
1285 * @param var w_height height of popup window
1287 function popupBSMedia(url_params, bs_ref, m_type, is_cust_type, w_width, w_height)
1289 // if width not specified, use default
1290 if (w_width == undefined)
1293 // if height not specified, use default
1294 if (w_height == undefined)
1297 // open popup window (for displaying video/playing audio)
1298 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');
1302 * popups a request for changing MIME types for files in the BLOB repository
1304 * @param var db database name
1305 * @param var table table name
1306 * @param var reference BLOB repository reference
1307 * @param var current_mime_type current MIME type associated with BLOB repository reference
1309 function requestMIMETypeChange(db, table, reference, current_mime_type)
1311 // no mime type specified, set to default (nothing)
1312 if (undefined == current_mime_type)
1313 current_mime_type = "";
1315 // prompt user for new mime type
1316 var new_mime_type = prompt("Enter custom MIME type", current_mime_type);
1318 // if new mime_type is specified and is not the same as the previous type, request for mime type change
1319 if (new_mime_type && new_mime_type != current_mime_type)
1320 changeMIMEType(db, table, reference, new_mime_type);
1324 * changes MIME types for files in the BLOB repository
1326 * @param var db database name
1327 * @param var table table name
1328 * @param var reference BLOB repository reference
1329 * @param var mime_type new MIME type to be associated with BLOB repository reference
1331 function changeMIMEType(db, table, reference, mime_type)
1333 // specify url and parameters for jQuery POST
1334 var mime_chg_url = 'bs_change_mime_type.php';
1335 var params = {bs_db: db, bs_table: table, bs_reference: reference, bs_new_mime_type: mime_type};
1338 jQuery.post(mime_chg_url, params);
1342 * Jquery Coding for inline editing SQL_QUERY
1344 $(document).ready(function(){
1345 var oldText,db,table,token,sql_query;
1346 oldText=$(".inner_sql").html();
1347 $("#inline_edit").click(function(){
1348 db=$("input[name='db']").val();
1349 table=$("input[name='table']").val();
1350 token=$("input[name='token']").val();
1351 sql_query=$("input[name='sql_query']").val();
1352 $(".inner_sql").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'] + "\">");
1356 $("#btnSave").live("click",function(){
1357 window.location.replace("import.php?db=" + db +"&table=" + table + "&sql_query=" + $("#sql_query_edit").val()+"&show_query=1&token=" + token + "");
1360 $("#btnDiscard").live("click",function(){
1361 $(".sql").html("<span class=\"syntax\"><span class=\"inner_sql\">" + oldText + "</span></span>");
1364 $('.sqlbutton').click(function(evt){
1365 insertQuery(evt.target.id);
1369 $("#export_type").change(function(){
1370 if($("#export_type").val()=='svg'){
1371 $("#show_grid_opt").attr("disabled","disabled");
1372 $("#orientation_opt").attr("disabled","disabled");
1373 $("#with_doc").attr("disabled","disabled");
1374 $("#show_table_dim_opt").removeAttr("disabled");
1375 $("#all_table_same_wide").removeAttr("disabled");
1376 $("#paper_opt").removeAttr("disabled","disabled");
1377 $("#show_color_opt").removeAttr("disabled","disabled");
1378 //$(this).css("background-color","yellow");
1379 }else if($("#export_type").val()=='dia'){
1380 $("#show_grid_opt").attr("disabled","disabled");
1381 $("#with_doc").attr("disabled","disabled");
1382 $("#show_table_dim_opt").attr("disabled","disabled");
1383 $("#all_table_same_wide").attr("disabled","disabled");
1384 $("#paper_opt").removeAttr("disabled","disabled");
1385 $("#show_color_opt").removeAttr("disabled","disabled");
1386 $("#orientation_opt").removeAttr("disabled","disabled");
1387 }else if($("#export_type").val()=='eps'){
1388 $("#show_grid_opt").attr("disabled","disabled");
1389 $("#orientation_opt").removeAttr("disabled");
1390 $("#with_doc").attr("disabled","disabled");
1391 $("#show_table_dim_opt").attr("disabled","disabled");
1392 $("#all_table_same_wide").attr("disabled","disabled");
1393 $("#paper_opt").attr("disabled","disabled");
1394 $("#show_color_opt").attr("disabled","disabled");
1396 }else if($("#export_type").val()=='pdf'){
1397 $("#show_grid_opt").removeAttr("disabled");
1398 $("#orientation_opt").removeAttr("disabled");
1399 $("#with_doc").removeAttr("disabled","disabled");
1400 $("#show_table_dim_opt").removeAttr("disabled","disabled");
1401 $("#all_table_same_wide").removeAttr("disabled","disabled");
1402 $("#paper_opt").removeAttr("disabled","disabled");
1403 $("#show_color_opt").removeAttr("disabled","disabled");
1409 $('#sqlquery').focus();
1410 if ($('#input_username')) {
1411 if ($('#input_username').val() == '') {
1412 $('#input_username').focus();
1414 $('#input_password').focus();
1420 * Function to process the plain HTML response from an Ajax request. Inserts
1421 * the various HTML divisions from the response at the proper locations. The
1422 * array relates the divisions to be inserted to their placeholders.
1424 * @param var divisions_map an associative array of id names
1427 * PMA_ajaxInsertResponse({'resultsTable':'resultsTable_response',
1428 * 'profilingData':'profilingData_response'});
1433 function PMA_ajaxInsertResponse(divisions_map) {
1434 $.each(divisions_map, function(key, value) {
1435 var content_div = '#'+value;
1436 var target_div = '#'+key;
1437 var content = $(content_div).html();
1439 //replace content of target_div with that from the response
1440 $(target_div).html(content);
1445 * Show a message on the top of the page for an Ajax request
1447 * @param var message string containing the message to be shown.
1448 * optional, defaults to 'Loading...'
1449 * @param var timeout number of milliseconds for the message to be visible
1450 * optional, defaults to 5000
1453 function PMA_ajaxShowMessage(message, timeout) {
1455 //Handle the case when a empty data.message is passed. We don't want the empty message
1461 * @var msg String containing the message that has to be displayed
1462 * @default PMA_messages['strLoading']
1465 var msg = PMA_messages['strLoading'];
1472 * @var timeout Number of milliseconds for which {@link msg} will be visible
1482 if( !ajax_message_init) {
1483 //For the first time this function is called, append a new div
1485 $('<div id="loading_parent"></div>')
1486 .insertBefore("#serverinfo");
1488 $('<span id="loading" class="ajax_notification"></span>')
1489 .appendTo("#loading_parent")
1491 .slideDown('medium')
1493 .slideUp('medium', function(){
1495 .html("") //Clear the message
1498 }, 'top.frame_content');
1499 ajax_message_init = true;
1502 //Otherwise, just show the div again after inserting the message
1506 .slideDown('medium')
1508 .slideUp('medium', function() {
1517 * Hides/shows the "Open in ENUM/SET editor" message, depending on the data type of the column currently selected
1519 function toggle_enum_notice(selectElement) {
1520 var enum_notice_id = selectElement.attr("id").split("_")[1];
1521 enum_notice_id += "_" + (parseInt(selectElement.attr("id").split("_")[2]) + 1);
1522 var selectedType = selectElement.attr("value");
1523 if(selectedType == "ENUM" || selectedType == "SET") {
1524 $("p[id='enum_notice_" + enum_notice_id + "']").show();
1526 $("p[id='enum_notice_" + enum_notice_id + "']").hide();
1531 * jQuery function that uses jQueryUI's dialogs to confirm with user. Does not
1532 * return a jQuery object yet and hence cannot be chained
1534 * @param string question
1535 * @param string url URL to be passed to the callbackFn to make
1537 * @param function callbackFn callback to execute after user clicks on OK
1540 jQuery.fn.PMA_confirm = function(question, url, callbackFn) {
1541 if (PMA_messages['strDoYouReally'] == '') {
1546 * @var button_options Object that stores the options passed to jQueryUI
1549 var button_options = {};
1550 button_options[PMA_messages['strOK']] = function(){
1551 $(this).dialog("close").remove();
1553 if($.isFunction(callbackFn)) {
1554 callbackFn.call(this, url);
1557 button_options[PMA_messages['strCancel']] = function() {$(this).dialog("close").remove();}
1559 $('<div id="confirm_dialog"></div>')
1561 .dialog({buttons: button_options});
1565 * jQuery function to sort a table's body after a new row has been appended to it.
1566 * Also fixes the even/odd classes of the table rows at the end.
1568 * @param string text_selector string to select the sortKey's text
1570 * @return jQuery Object for chaining purposes
1572 jQuery.fn.PMA_sort_table = function(text_selector) {
1573 return this.each(function() {
1576 * @var table_body Object referring to the table's <tbody> element
1578 var table_body = $(this);
1580 * @var rows Object referring to the collection of rows in {@link table_body}
1582 var rows = $(this).find('tr').get();
1584 //get the text of the field that we will sort by
1585 $.each(rows, function(index, row) {
1586 row.sortKey = $.trim($(row).find(text_selector).text().toLowerCase());
1589 //get the sorted order
1590 rows.sort(function(a,b) {
1591 if(a.sortKey < b.sortKey) {
1594 if(a.sortKey > b.sortKey) {
1600 //pull out each row from the table and then append it according to it's order
1601 $.each(rows, function(index, row) {
1602 $(table_body).append(row);
1606 //Re-check the classes of each row
1607 $(this).find('tr:odd')
1608 .removeClass('even').addClass('odd')
1611 .removeClass('odd').addClass('even');
1616 * jQuery coding for 'Create Table'. Used on db_operations.php,
1617 * db_structure.php and db_tracking.php (i.e., wherever
1618 * libraries/display_create_table.lib.php is used)
1620 * Attach Ajax Event handlers for Create Table
1622 $(document).ready(function() {
1625 * Attach event handler to the submit action of the create table minimal form
1626 * and retrieve the full table form and display it in a dialog
1628 * @uses PMA_ajaxShowMessage()
1630 $("#create_table_form_minimal").live('submit', function(event) {
1631 event.preventDefault();
1634 /* @todo Validate this form! */
1637 * @var button_options Object that stores the options passed to jQueryUI
1640 var button_options = {};
1641 // in the following function we need to use $(this)
1642 button_options[PMA_messages['strCancel']] = function() {$(this).dialog('close').remove();}
1644 PMA_ajaxShowMessage();
1645 if (! $form.find('input:hidden').is('#ajax_request_hidden')) {
1646 $form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
1649 $.get($form.attr('action'), $form.serialize(), function(data) {
1650 $('<div id="create_table_dialog"></div>')
1653 title: PMA_messages['strCreateTable'],
1655 buttons : button_options
1656 }); // end dialog options
1659 // empty table name and number of columns from the minimal form
1660 $form.find('input[name=table],input[name=num_fields]').val('');
1664 * Attach event handler for submission of create table form (save)
1666 * @uses PMA_ajaxShowMessage()
1667 * @uses $.PMA_sort_table()
1670 // .live() must be called after a selector, see http://api.jquery.com/live
1671 $("#create_table_form input[name=do_save_data]").live('click', function(event) {
1672 event.preventDefault();
1675 * @var the_form object referring to the create table form
1677 var $form = $("#create_table_form");
1679 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
1680 if (! $form.find('input:hidden').is('#ajax_request_hidden')) {
1681 $form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
1683 //User wants to submit the form
1684 $.post($form.attr('action'), $form.serialize() + "&do_save_data=" + $(this).val(), function(data) {
1685 if(data.success == true) {
1686 PMA_ajaxShowMessage(data.message);
1687 $("#create_table_dialog").dialog("close").remove();
1690 * @var tables_table Object referring to the <tbody> element that holds the list of tables
1692 var tables_table = $("#tablesForm").find("tbody").not("#tbl_summary_row");
1693 // this is the first table created in this db
1694 if (tables_table.length == 0) {
1695 if (window.parent && window.parent.frame_content) {
1696 window.parent.frame_content.location.reload();
1700 * @var curr_last_row Object referring to the last <tr> element in {@link tables_table}
1702 var curr_last_row = $(tables_table).find('tr:last');
1704 * @var curr_last_row_index_string String containing the index of {@link curr_last_row}
1706 var curr_last_row_index_string = $(curr_last_row).find('input:checkbox').attr('id').match(/\d+/)[0];
1708 * @var curr_last_row_index Index of {@link curr_last_row}
1710 var curr_last_row_index = parseFloat(curr_last_row_index_string);
1712 * @var new_last_row_index Index of the new row to be appended to {@link tables_table}
1714 var new_last_row_index = curr_last_row_index + 1;
1716 * @var new_last_row_id String containing the id of the row to be appended to {@link tables_table}
1718 var new_last_row_id = 'checkbox_tbl_' + new_last_row_index;
1721 $(data.new_table_string)
1722 .find('input:checkbox')
1723 .val(new_last_row_id)
1725 .appendTo(tables_table);
1728 $(tables_table).PMA_sort_table('th');
1731 //Refresh navigation frame as a new table has been added
1732 if (window.parent && window.parent.frame_navigation) {
1733 window.parent.frame_navigation.location.reload();
1737 PMA_ajaxShowMessage(data.error);
1740 }) // end create table form (save)
1743 * Attach event handler for create table form (add fields)
1745 * @uses PMA_ajaxShowMessage()
1746 * @uses $.PMA_sort_table()
1747 * @uses window.parent.refreshNavigation()
1750 // .live() must be called after a selector, see http://api.jquery.com/live
1751 $("#create_table_form input[name=submit_num_fields]").live('click', function(event) {
1752 event.preventDefault();
1755 * @var the_form object referring to the create table form
1757 var $form = $("#create_table_form");
1759 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
1760 if (! $form.find('input:hidden').is('#ajax_request_hidden')) {
1761 $form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
1764 //User wants to add more fields to the table
1765 $.post($form.attr('action'), $form.serialize() + "&submit_num_fields=" + $(this).val(), function(data) {
1766 $("#create_table_dialog").html(data);
1769 }) // end create table form (add fields)
1771 }, 'top.frame_content'); //end $(document).ready for 'Create Table'
1774 * Attach event handlers for Empty Table and Drop Table. Used wherever libraries/
1775 * tbl_links.inc.php is used.
1777 $(document).ready(function() {
1780 * Attach Ajax event handlers for Empty Table
1782 * @uses PMA_ajaxShowMessage()
1783 * @uses $.PMA_confirm()
1785 $("#empty_table_anchor").live('click', function(event) {
1786 event.preventDefault();
1789 * @var question String containing the question to be asked for confirmation
1791 var question = 'TRUNCATE TABLE ' + window.parent.table;
1793 $(this).PMA_confirm(question, $(this).attr('href'), function(url) {
1795 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
1796 $.get(url, {'is_js_confirmed': 1, 'ajax_request': true}, function(data) {
1797 if(data.success == true) {
1798 PMA_ajaxShowMessage(data.message);
1799 $("#topmenucontainer")
1803 .after(data.sql_query);
1806 PMA_ajaxShowMessage(data.error);
1809 }) // end $.PMA_confirm()
1810 }) // end Empty Table
1813 * Attach Ajax event handler for Drop Table
1815 * @uses PMA_ajaxShowMessage()
1816 * @uses $.PMA_confirm()
1817 * @uses window.parent.refreshNavigation()
1819 $("#drop_table_anchor").live('click', function(event) {
1820 event.preventDefault();
1823 * @var question String containing the question to be asked for confirmation
1825 var question = 'DROP TABLE/VIEW ' + window.parent.table;
1826 $(this).PMA_confirm(question, $(this).attr('href'), function(url) {
1828 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
1829 $.get(url, {'is_js_confirmed': 1, 'ajax_request': true}, function(data) {
1830 if(data.success == true) {
1831 PMA_ajaxShowMessage(data.message);
1832 $("#topmenucontainer")
1836 .after(data.sql_query);
1837 window.parent.table = '';
1838 if (window.parent && window.parent.frame_navigation) {
1839 window.parent.frame_navigation.location.reload();
1843 PMA_ajaxShowMessage(data.error);
1846 }) // end $.PMA_confirm()
1847 }) // end $().live()
1848 }, 'top.frame_content'); //end $(document).ready() for libraries/tbl_links.inc.php
1851 * Attach Ajax event handlers for Drop Trigger. Used on tbl_structure.php
1853 $(document).ready(function() {
1855 $(".drop_trigger_anchor").live('click', function(event) {
1856 event.preventDefault();
1859 * @var curr_row Object reference to the current trigger's <tr>
1861 var curr_row = $(this).parents('tr');
1863 * @var question String containing the question to be asked for confirmation
1865 var question = 'DROP TRIGGER IF EXISTS `' + $(curr_row).children('td:first').text() + '`';
1867 $(this).PMA_confirm(question, $(this).attr('href'), function(url) {
1869 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
1870 $.get(url, {'is_js_confirmed': 1, 'ajax_request': true}, function(data) {
1871 if(data.success == true) {
1872 PMA_ajaxShowMessage(data.message);
1873 $("#topmenucontainer")
1877 .after(data.sql_query);
1878 $(curr_row).hide("medium").remove();
1881 PMA_ajaxShowMessage(data.error);
1884 }) // end $.PMA_confirm()
1885 }) // end $().live()
1886 }, 'top.frame_content'); //end $(document).ready() for Drop Trigger
1889 * Attach Ajax event handlers for Drop Database. Moved here from db_structure.js
1890 * as it was also required on db_create.php
1892 * @uses $.PMA_confirm()
1893 * @uses PMA_ajaxShowMessage()
1894 * @uses window.parent.refreshNavigation()
1895 * @uses window.parent.refreshMain()
1897 $(document).ready(function() {
1898 $("#drop_db_anchor").live('click', function(event) {
1899 event.preventDefault();
1901 //context is top.frame_content, so we need to use window.parent.db to access the db var
1903 * @var question String containing the question to be asked for confirmation
1905 var question = PMA_messages['strDropDatabaseStrongWarning'] + '\n' + PMA_messages['strDoYouReally'] + ' :\n' + 'DROP DATABASE ' + window.parent.db;
1907 $(this).PMA_confirm(question, $(this).attr('href') ,function(url) {
1909 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
1910 $.get(url, {'is_js_confirmed': '1', 'ajax_request': true}, function(data) {
1911 //Database deleted successfully, refresh both the frames
1912 window.parent.refreshNavigation();
1913 window.parent.refreshMain();
1915 }); // end $.PMA_confirm()
1916 }); //end of Drop Database Ajax action
1917 }) // end of $(document).ready() for Drop Database
1920 * Attach Ajax event handlers for 'Create Database'. Used wherever libraries/
1921 * display_create_database.lib.php is used, ie main.php and server_databases.php
1923 * @uses PMA_ajaxShowMessage()
1925 $(document).ready(function() {
1927 $('#create_database_form').live('submit', function(event) {
1928 event.preventDefault();
1932 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
1934 if (! $form.find('input:hidden').is('#ajax_request_hidden')) {
1935 $form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
1938 $.post($form.attr('action'), $form.serialize(), function(data) {
1939 if(data.success == true) {
1940 PMA_ajaxShowMessage(data.message);
1942 //Append database's row to table
1943 $("#tabledatabases")
1945 .append(data.new_db_string)
1946 .PMA_sort_table('.name')
1947 .find('#db_summary_row')
1948 .appendTo('#tabledatabases tbody')
1949 .removeClass('odd even');
1951 var $databases_count_object = $('#databases_count');
1952 var databases_count = parseInt($databases_count_object.text());
1953 $databases_count_object.text(++databases_count);
1954 //Refresh navigation frame as a new database has been added
1955 if (window.parent && window.parent.frame_navigation) {
1956 window.parent.frame_navigation.location.reload();
1960 PMA_ajaxShowMessage(data.error);
1963 }) // end $().live()
1964 }) // end $(document).ready() for Create Database
1967 * Attach Ajax event handlers for 'Change Password' on main.php
1969 $(document).ready(function() {
1972 * Attach Ajax event handler on the change password anchor
1974 $('#change_password_anchor').live('click', function(event) {
1975 event.preventDefault();
1978 * @var button_options Object containing options to be passed to jQueryUI's dialog
1980 var button_options = {};
1982 button_options[PMA_messages['strCancel']] = function() {$(this).dialog('close').remove();}
1984 $.get($(this).attr('href'), {'ajax_request': true}, function(data) {
1985 $('<div id="change_password_dialog></div>')
1987 title: PMA_messages['strChangePassword'],
1989 buttons : button_options
1992 displayPasswordGenerateButton();
1994 }) // end handler for change password anchor
1997 * Attach Ajax event handler for Change Password form submission
1999 * @uses PMA_ajaxShowMessage()
2001 $("#change_password_form").find('input[name=change_pw]').live('click', function(event) {
2002 event.preventDefault();
2005 * @var the_form Object referring to the change password form
2007 var the_form = $("#change_password_form");
2010 * @var this_value String containing the value of the submit button.
2011 * Need to append this for the change password form on Server Privileges
2014 var this_value = $(this).val();
2016 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
2017 $(the_form).append('<input type="hidden" name="ajax_request" value="true" />');
2019 $.post($(the_form).attr('action'), $(the_form).serialize() + '&change_pw='+ this_value, function(data) {
2020 if(data.success == true) {
2022 PMA_ajaxShowMessage(data.message);
2024 $("#topmenucontainer").after(data.sql_query);
2026 $("#change_password_dialog").hide().remove();
2027 $("#edit_user_dialog").dialog("close").remove();
2030 PMA_ajaxShowMessage(data.error);
2033 }) // end handler for Change Password form submission
2034 }) // end $(document).ready() for Change Password
2037 * Toggle the hiding/showing of the "Open in ENUM/SET editor" message when
2038 * the page loads and when the selected data type changes
2040 $(document).ready(function() {
2041 $.each($("select[class='column_type']"), function() {
2042 toggle_enum_notice($(this));
2044 $("select[class='column_type']").change(function() {
2045 toggle_enum_notice($(this));
2050 * Closes the ENUM/SET editor and removes the data in it
2052 function disable_popup() {
2053 $("#popup_background").fadeOut("fast");
2054 $("#enum_editor").fadeOut("fast");
2055 // clear the data from the text boxes
2056 $("#enum_editor #values input").remove();
2057 $("#enum_editor input[type='hidden']").remove();
2061 * Opens the ENUM/SET editor and controls its functions
2063 $(document).ready(function() {
2064 $("a[class='open_enum_editor']").click(function() {
2066 var windowWidth = document.documentElement.clientWidth;
2067 var windowHeight = document.documentElement.clientHeight;
2068 var popupWidth = windowWidth/2;
2069 var popupHeight = windowHeight*0.8;
2070 var popupOffsetTop = windowHeight/2 - popupHeight/2;
2071 var popupOffsetLeft = windowWidth/2 - popupWidth/2;
2072 $("#enum_editor").css({"position":"absolute", "top": popupOffsetTop, "left": popupOffsetLeft, "width": popupWidth, "height": popupHeight});
2075 $("#popup_background").css({"opacity":"0.7"});
2076 $("#popup_background").fadeIn("fast");
2077 $("#enum_editor").fadeIn("fast");
2080 var values = $(this).parent().prev("input").attr("value").split(",");
2081 $.each(values, function(index, val) {
2082 if(jQuery.trim(val) != "") {
2083 // enclose the string in single quotes if it's not already
2084 if(val.substr(0, 1) != "'") {
2087 if(val.substr(val.length-1, val.length) != "'") {
2090 // escape the single quotes, except the mandatory ones enclosing the entire string
2091 val = val.substr(1, val.length-2).replace(/''/g, "'").replace(/\\\\/g, '\\').replace(/\\'/g, "'").replace(/'/g, "'");
2092 // escape the greater-than symbol
2093 val = val.replace(/>/g, ">");
2094 $("#enum_editor #values").append("<input type='text' value=" + val + " />");
2097 // So we know which column's data is being edited
2098 $("#enum_editor").append("<input type='hidden' value='" + $(this).parent().prev("input").attr("id") + "' />");
2102 // If the "close" link is clicked, close the enum editor
2103 $("a[class='close_enum_editor']").click(function() {
2107 // If the "cancel" link is clicked, close the enum editor
2108 $("a[class='cancel_enum_editor']").click(function() {
2112 // When "add a new value" is clicked, append an empty text field
2113 $("a[class='add_value']").click(function() {
2114 $("#enum_editor #values").append("<input type='text' />");
2117 // When the submit button is clicked, put the data back into the original form
2118 $("#enum_editor input[type='submit']").click(function() {
2119 var value_array = new Array();
2120 $.each($("#enum_editor #values input"), function(index, input_element) {
2121 val = jQuery.trim(input_element.value);
2123 value_array.push("'" + val.replace(/\\/g, '\\\\').replace(/'/g, "''") + "'");
2126 // get the Length/Values text field where this value belongs
2127 var values_id = $("#enum_editor input[type='hidden']").attr("value");
2128 $("input[id='" + values_id + "']").attr("value", value_array.join(","));
2133 * Hides certain table structure actions, replacing them with the word "More". They are displayed
2134 * in a dropdown menu when the user hovers over the word "More."
2136 // Remove the actions from the table cells (they are available by default for JavaScript-disabled browsers)
2137 // if the table is not a view or information_schema (otherwise there is only one action to hide and there's no point)
2138 if($("input[type='hidden'][name='table_type']").attr("value") == "table") {
2139 $("table[id='tablestructure'] td[class='browse']").remove();
2140 $("table[id='tablestructure'] td[class='primary']").remove();
2141 $("table[id='tablestructure'] td[class='unique']").remove();
2142 $("table[id='tablestructure'] td[class='index']").remove();
2143 $("table[id='tablestructure'] td[class='fulltext']").remove();
2144 $("table[id='tablestructure'] th[class='action']").attr("colspan", 3);
2146 // Display the "more" text
2147 $("table[id='tablestructure'] td[class='more_opts']").show()
2149 // Position the dropdown
2150 $.each($(".structure_actions_dropdown"), function() {
2151 // The top offset must be set for IE even if it didn't change
2152 var cell_right_edge_offset = $(this).parent().offset().left + $(this).parent().innerWidth();
2153 var left_offset = cell_right_edge_offset - $(this).innerWidth();
2154 var top_offset = $(this).parent().offset().top + $(this).parent().innerHeight();
2155 $(this).offset({ top: top_offset, left: left_offset });
2158 // A hack for IE6 to prevent the after_field select element from being displayed on top of the dropdown by
2159 // positioning an iframe directly on top of it
2160 $("iframe[class='IE_hack']").width($("select[name='after_field']").width());
2161 $("iframe[class='IE_hack']").height($("select[name='after_field']").height());
2162 $("iframe[class='IE_hack']").offset({ top: $("select[name='after_field']").offset().top, left: $("select[name='after_field']").offset().left });
2164 // When "more" is hovered over, show the hidden actions
2165 $("table[id='tablestructure'] td[class='more_opts']").mouseenter(
2167 if($.browser.msie && $.browser.version == "6.0") {
2168 $("iframe[class='IE_hack']").show();
2169 $("iframe[class='IE_hack']").width($("select[name='after_field']").width()+4);
2170 $("iframe[class='IE_hack']").height($("select[name='after_field']").height()+4);
2171 $("iframe[class='IE_hack']").offset({ top: $("select[name='after_field']").offset().top, left: $("select[name='after_field']").offset().left});
2173 $(".structure_actions_dropdown").hide(); // Hide all the other ones that may be open
2174 $(this).children(".structure_actions_dropdown").show();
2175 // Need to do this again for IE otherwise the offset is wrong
2176 if($.browser.msie) {
2177 var left_offset_IE = $(this).offset().left + $(this).innerWidth() - $(this).children(".structure_actions_dropdown").innerWidth();
2178 var top_offset_IE = $(this).offset().top + $(this).innerHeight();
2179 $(this).children(".structure_actions_dropdown").offset({ top: top_offset_IE, left: left_offset_IE });
2182 $(".structure_actions_dropdown").mouseleave(function() {
2184 if($.browser.msie && $.browser.version == "6.0") {
2185 $("iframe[class='IE_hack']").hide();
2191 /* Displays tooltips */
2192 $(document).ready(function() {
2193 // Hide the footnotes from the footer (which are displayed for
2194 // JavaScript-disabled browsers) since the tooltip is sufficient
2195 $(".footnotes").hide();
2196 $(".footnotes span").each(function() {
2197 $(this).children("sup").remove();
2199 // The border and padding must be removed otherwise a thin yellow box remains visible
2200 $(".footnotes").css("border", "none");
2201 $(".footnotes").css("padding", "0px");
2203 // Replace the superscripts with the help icon
2204 $("sup[class='footnotemarker']").hide();
2205 $("img[class='footnotemarker']").show();
2207 $("img[class='footnotemarker']").each(function() {
2208 var span_id = $(this).attr("id");
2209 span_id = span_id.split("_")[1];
2210 var tooltip_text = $(".footnotes span[id='footnote_" + span_id + "']").html();
2212 content: tooltip_text,
2214 hide: { when: 'unfocus', delay: 0 },
2215 style: { background: '#ffffcc' }
2220 function menuResize()
2222 var cnt = $('#topmenu');
2223 var wmax = cnt.width() - 5; // 5 px margin for jumping menu in Chrome
2224 var submenu = cnt.find('.submenu');
2225 var submenu_w = submenu.outerWidth(true);
2226 var submenu_ul = submenu.find('ul');
2227 var li = cnt.find('> li');
2228 var li2 = submenu_ul.find('li');
2229 var more_shown = li2.length > 0;
2230 var w = more_shown ? submenu_w : 0;
2234 for (var i = 0; i < li.length-1; i++) { // li.length-1: skip .submenu element
2236 var el_width = el.outerWidth(true);
2237 el.data('width', el_width);
2241 if (w + submenu_w < wmax) {
2245 w -= $(li[i-1]).data('width');
2251 if (hide_start > 0) {
2252 for (var i = hide_start; i < li.length-1; i++) {
2253 $(li[i])[more_shown ? 'prependTo' : 'appendTo'](submenu_ul);
2256 } else if (more_shown) {
2258 // nothing hidden, maybe something can be restored
2259 for (var i = 0; i < li2.length; i++) {
2260 //console.log(li2[i], submenu_w);
2261 w += $(li2[i]).data('width');
2262 // item fits or (it is the last item and it would fit if More got removed)
2263 if (w+submenu_w < wmax || (i == li2.length-1 && w < wmax)) {
2264 $(li2[i]).insertBefore(submenu);
2265 if (i == li2.length-1) {
2273 if (submenu.find('.tabactive').length) {
2274 submenu.addClass('active').find('> a').removeClass('tab').addClass('tabactive');
2276 submenu.removeClass('active').find('> a').addClass('tab').removeClass('tabactive');
2281 var topmenu = $('#topmenu');
2282 if (topmenu.length == 0) {
2285 // create submenu container
2286 var link = $('<a />', {href: '#', 'class': 'tab'})
2287 .text(PMA_messages['strMore'])
2288 .click(function(e) {
2291 var img = topmenu.find('li:first-child img');
2293 img.clone().attr('src', img.attr('src').replace(/\/[^\/]+$/, '/b_more.png')).prependTo(link);
2295 var submenu = $('<li />', {'class': 'submenu'})
2297 .append($('<ul />'))
2298 .mouseenter(function() {
2299 if ($(this).find('ul .tabactive').length == 0) {
2300 $(this).addClass('submenuhover').find('> a').addClass('tabactive');
2303 .mouseleave(function() {
2304 if ($(this).find('ul .tabactive').length == 0) {
2305 $(this).removeClass('submenuhover').find('> a').removeClass('tabactive');
2309 topmenu.append(submenu);
2311 // populate submenu and register resize event
2312 $(window).resize(menuResize);
2317 * For the checkboxes in browse mode, handles the shift/click (only works
2318 * in horizontal mode) and propagates the click to the "companion" checkbox
2319 * (in both horizontal and vertical). Works also for pages reached via AJAX.
2321 $(document).ready(function() {
2322 $('.multi_checkbox').live('click',function(e) {
2323 var current_checkbox_id = this.id;
2324 var left_checkbox_id = current_checkbox_id.replace('_right', '_left');
2325 var right_checkbox_id = current_checkbox_id.replace('_left', '_right');
2326 var other_checkbox_id = '';
2327 if (current_checkbox_id == left_checkbox_id) {
2328 other_checkbox_id = right_checkbox_id;
2330 other_checkbox_id = left_checkbox_id;
2333 var $current_checkbox = $('#' + current_checkbox_id);
2334 var $other_checkbox = $('#' + other_checkbox_id);
2337 var index_of_current_checkbox = $('.multi_checkbox').index($current_checkbox);
2338 var $last_checkbox = $('.multi_checkbox').filter('.last_clicked');
2339 var index_of_last_click = $('.multi_checkbox').index($last_checkbox);
2340 $('.multi_checkbox')
2341 .filter(function(index) {
2342 // the first clicked row can be on a row above or below the
2343 // shift-clicked row
2344 return (index_of_current_checkbox > index_of_last_click && index > index_of_last_click && index < index_of_current_checkbox)
2345 || (index_of_last_click > index_of_current_checkbox && index < index_of_last_click && index > index_of_current_checkbox);
2347 .each(function(index) {
2348 var $intermediate_checkbox = $(this);
2349 if ($current_checkbox.is(':checked')) {
2350 $intermediate_checkbox.attr('checked', true);
2352 $intermediate_checkbox.attr('checked', false);
2357 $('.multi_checkbox').removeClass('last_clicked');
2358 $current_checkbox.addClass('last_clicked');
2360 // When there is a checkbox on both ends of the row, propagate the
2361 // click on one of them to the other one.
2362 // (the default action has not been prevented so if we have
2363 // just clicked, this "if" is true)
2364 if ($current_checkbox.is(':checked')) {
2365 $other_checkbox.attr('checked', true);
2367 $other_checkbox.attr('checked', false);
2370 }) // end of $(document).ready() for multi checkbox
2373 * Get the row number from the classlist (for example, row_1)
2375 function PMA_getRowNumber(classlist) {
2376 return parseInt(classlist.split(/row_/)[1]);
2382 $(document).ready(function() {
2383 $('.vpointer').live('hover',
2386 var $this_td = $(this);
2387 var row_num = PMA_getRowNumber($this_td.attr('class'));
2388 // for all td of the same vertical row, toggle hover
2389 $('.vpointer').filter('.row_' + row_num).toggleClass('hover');
2392 }) // end of $(document).ready() for vertical pointer
2394 $(document).ready(function() {
2398 $('.vmarker').live('click', function(e) {
2399 var $this_td = $(this);
2400 var row_num = PMA_getRowNumber($this_td.attr('class'));
2401 // for all td of the same vertical row, toggle the marked class
2402 $('.vmarker').filter('.row_' + row_num).toggleClass('marked');
2406 * Reveal visual builder anchor
2409 $('#visual_builder_anchor').show();
2410 }) // end of $(document).ready()