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 an confirmation box before to submit 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 an 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 an 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
544 function change_Image(img_obj)
546 var relative_path = (img_obj.src).split("themes/");
548 if (relative_path[1] == 'original/img/new_data.jpg') {
549 img_obj.src = "./themes/original/img/new_data_hovered.jpg";
550 } else if (relative_path[1] == 'original/img/new_struct.jpg') {
551 img_obj.src = "./themes/original/img/new_struct_hovered.jpg";
552 } else if (relative_path[1] == 'original/img/new_struct_hovered.jpg') {
553 img_obj.src = "./themes/original/img/new_struct.jpg";
554 } else if (relative_path[1] == 'original/img/new_data_hovered.jpg') {
555 img_obj.src = "./themes/original/img/new_data.jpg";
556 } else if (relative_path[1] == 'original/img/new_data_selected.jpg') {
557 img_obj.src = "./themes/original/img/new_data_selected_hovered.jpg";
558 } else if(relative_path[1] == 'original/img/new_struct_selected.jpg') {
559 img_obj.src = "./themes/original/img/new_struct_selected_hovered.jpg";
560 } else if (relative_path[1] == 'original/img/new_struct_selected_hovered.jpg') {
561 img_obj.src = "./themes/original/img/new_struct_selected.jpg";
562 } else if (relative_path[1] == 'original/img/new_data_selected_hovered.jpg') {
563 img_obj.src = "./themes/original/img/new_data_selected.jpg";
568 * Generates the URL containing the list of selected table ids for synchronization and
569 * a variable checked for confirmation of deleting previous rows from target tables
571 * @param token the token generated for each PMA form
575 function ApplySelectedChanges(token)
577 var div = document.getElementById("list");
578 var table = div.getElementsByTagName('table')[0];
579 var table_body = table.getElementsByTagName('tbody')[0];
580 // Get all the rows from the details table
581 var table_rows = table_body.getElementsByTagName('tr');
582 var x = table_rows.length;
585 Append the token at the beginning of the query string followed by
586 Table_ids that shows that "Apply Selected Changes" button is pressed
588 var append_string = "?token="+token+"&Table_ids="+1;
590 append_string += "&";
591 append_string += i+"="+table_rows[i].id;
594 // Getting the value of checkbox delete_rows
595 var checkbox = document.getElementById("delete_rows");
596 if (checkbox.checked){
597 append_string += "&checked=true";
599 append_string += "&checked=false";
601 //Appending the token and list of table ids in the URL
602 location.href += token;
603 location.href += append_string;
607 * Displays error message if any text field
608 * is left empty other than port field.
610 * @param string the form name
611 * @param object the form
613 * @return boolean whether the form field is empty or not
615 function validateConnection(form_name, form_obj)
618 var src_hostfilled = true;
619 var trg_hostfilled = true;
621 for (var i=1; i<form_name.elements.length; i++)
623 // All the text fields are checked excluding the port field because the default port can be used.
624 if ((form_name.elements[i].type == 'text') && (form_name.elements[i].name != 'src_port') && (form_name.elements[i].name != 'trg_port')) {
625 check = emptyFormElements(form_obj, form_name.elements[i].name);
627 element = form_name.elements[i].name;
628 if (form_name.elements[i].name == 'src_host') {
629 src_hostfilled = false;
632 if (form_name.elements[i].name == 'trg_host') {
633 trg_hostfilled = false;
636 if ((form_name.elements[i].name == 'src_socket' && src_hostfilled==false) || (form_name.elements[i].name == 'trg_socket' && trg_hostfilled==false))
646 alert(PMA_messages['strFormEmpty']);
653 * Check if a form's element is empty
656 * @param object the form
657 * @param string the name of the form field to put the focus on
659 * @return boolean whether the form field is empty or not
661 function emptyCheckTheField(theForm, theFieldName)
664 var theField = theForm.elements[theFieldName];
665 // Whether the replace function (js1.2) is supported or not
666 var isRegExp = (typeof(theField.value.replace) != 'undefined');
669 isEmpty = (theField.value == '') ? 1 : 0;
671 var space_re = new RegExp('\\s+');
672 isEmpty = (theField.value.replace(space_re, '') == '') ? 1 : 0;
676 } // end of the 'emptyCheckTheField()' function
681 * @param object the form
682 * @param string the name of the form field to put the focus on
684 * @return boolean whether the form field is empty or not
686 function emptyFormElements(theForm, theFieldName)
688 var theField = theForm.elements[theFieldName];
689 var isEmpty = emptyCheckTheField(theForm, theFieldName);
693 } // end of the 'emptyFormElements()' function
697 * Ensures a value submitted in a form is numeric and is in a range
699 * @param object the form
700 * @param string the name of the form field to check
701 * @param integer the minimum authorized value
702 * @param integer the maximum authorized value
704 * @return boolean whether a valid number has been submitted or not
706 function checkFormElementInRange(theForm, theFieldName, message, min, max)
708 var theField = theForm.elements[theFieldName];
709 var val = parseInt(theField.value);
711 if (typeof(min) == 'undefined') {
714 if (typeof(max) == 'undefined') {
715 max = Number.MAX_VALUE;
721 alert(PMA_messages['strNotNumber']);
725 // It's a number but it is not between min and max
726 else if (val < min || val > max) {
728 alert(message.replace('%d', val));
732 // It's a valid number
734 theField.value = val;
738 } // end of the 'checkFormElementInRange()' function
741 function checkTableEditForm(theForm, fieldsCnt)
743 // TODO: avoid sending a message if user just wants to add a line
744 // on the form but has not completed at least one field name
746 var atLeastOneField = 0;
747 var i, elm, elm2, elm3, val, id;
749 for (i=0; i<fieldsCnt; i++)
751 id = "#field_" + i + "_2";
754 if (val == 'VARCHAR' || val == 'CHAR' || val == 'BIT' || val == 'VARBINARY' || val == 'BINARY') {
755 elm2 = $("#field_" + i + "_3");
756 val = parseInt(elm2.val());
757 elm3 = $("#field_" + i + "_1");
758 if (isNaN(val) && elm3.val() != "") {
760 alert(PMA_messages['strNotNumber']);
766 if (atLeastOneField == 0) {
767 id = "field_" + i + "_1";
768 if (!emptyCheckTheField(theForm, id)) {
773 if (atLeastOneField == 0) {
774 var theField = theForm.elements["field_0_1"];
775 alert(PMA_messages['strFormEmpty']);
781 } // enf of the 'checkTableEditForm()' function
785 * Ensures the choice between 'transmit', 'zipped', 'gzipped' and 'bzipped'
786 * checkboxes is consistant
788 * @param object the form
789 * @param string a code for the action that causes this function to be run
791 * @return boolean always true
793 function checkTransmitDump(theForm, theAction)
795 var formElts = theForm.elements;
797 // 'zipped' option has been checked
798 if (theAction == 'zip' && formElts['zip'].checked) {
799 if (!formElts['asfile'].checked) {
800 theForm.elements['asfile'].checked = true;
802 if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) {
803 theForm.elements['gzip'].checked = false;
805 if (typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked) {
806 theForm.elements['bzip'].checked = false;
809 // 'gzipped' option has been checked
810 else if (theAction == 'gzip' && formElts['gzip'].checked) {
811 if (!formElts['asfile'].checked) {
812 theForm.elements['asfile'].checked = true;
814 if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
815 theForm.elements['zip'].checked = false;
817 if (typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked) {
818 theForm.elements['bzip'].checked = false;
821 // 'bzipped' option has been checked
822 else if (theAction == 'bzip' && formElts['bzip'].checked) {
823 if (!formElts['asfile'].checked) {
824 theForm.elements['asfile'].checked = true;
826 if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
827 theForm.elements['zip'].checked = false;
829 if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) {
830 theForm.elements['gzip'].checked = false;
833 // 'transmit' option has been unchecked
834 else if (theAction == 'transmit' && !formElts['asfile'].checked) {
835 if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
836 theForm.elements['zip'].checked = false;
838 if ((typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked)) {
839 theForm.elements['gzip'].checked = false;
841 if ((typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked)) {
842 theForm.elements['bzip'].checked = false;
847 } // end of the 'checkTransmitDump()' function
850 * Row marking in horizontal mode (use "live" so that it works also for
851 * next pages reached via AJAX); a tr may have the class noclick to remove
854 $(document).ready(function() {
855 $('tr.odd:not(.noclick), tr.even:not(.noclick)').live('click',function() {
857 $tr.toggleClass('marked');
858 $tr.children().toggleClass('marked');
863 * Row highlighting in horizontal mode (use "live"
864 * so that it works also for pages reached via AJAX)
866 $(document).ready(function() {
867 $('tr.odd, tr.even').live('hover',function() {
869 $tr.toggleClass('hover');
870 $tr.children().toggleClass('hover');
875 * This array is used to remember mark status of rows in browse mode
877 var marked_row = new Array;
880 * marks all rows and selects its first checkbox inside the given element
881 * the given element is usaly a table or a div containing the table or tables
883 * @param container DOM element
885 function markAllRows( container_id ) {
887 $("#"+container_id).find("input:checkbox:enabled").attr('checked', 'checked')
888 .parents("tr").addClass("marked");
893 * marks all rows and selects its first checkbox inside the given element
894 * the given element is usaly a table or a div containing the table or tables
896 * @param container DOM element
898 function unMarkAllRows( container_id ) {
900 $("#"+container_id).find("input:checkbox:enabled").removeAttr('checked')
901 .parents("tr").removeClass("marked");
906 * Checks/unchecks all checkbox in given conainer (f.e. a form, fieldset or div)
908 * @param string container_id the container id
909 * @param boolean state new value for checkbox (true or false)
910 * @return boolean always true
912 function setCheckboxes( container_id, state ) {
915 $("#"+container_id).find("input:checkbox").attr('checked', 'checked');
918 $("#"+container_id).find("input:checkbox").removeAttr('checked');
922 } // end of the 'setCheckboxes()' function
925 * Checks/unchecks all options of a <select> element
927 * @param string the form name
928 * @param string the element name
929 * @param boolean whether to check or to uncheck the element
931 * @return boolean always true
933 function setSelectOptions(the_form, the_select, do_check)
937 $("form[name='"+ the_form +"']").find("select[name='"+the_select+"']").find("option").attr('selected', 'selected');
940 $("form[name='"+ the_form +"']").find("select[name="+the_select+"]").find("option").removeAttr('selected');
943 } // end of the 'setSelectOptions()' function
947 * Create quick sql statements.
950 function insertQuery(queryType) {
951 var myQuery = document.sqlform.sql_query;
952 var myListBox = document.sqlform.dummy;
954 var table = document.sqlform.table.value;
956 if (myListBox.options.length > 0) {
957 sql_box_locked = true;
962 for (var i=0; i < myListBox.options.length; i++) {
969 chaineAj += myListBox.options[i].value;
970 valDis += "[value-" + NbSelect + "]";
971 editDis += myListBox.options[i].value + "=[value-" + NbSelect + "]";
973 if (queryType == "selectall") {
974 query = "SELECT * FROM `" + table + "` WHERE 1";
975 } else if (queryType == "select") {
976 query = "SELECT " + chaineAj + " FROM `" + table + "` WHERE 1";
977 } else if (queryType == "insert") {
978 query = "INSERT INTO `" + table + "`(" + chaineAj + ") VALUES (" + valDis + ")";
979 } else if (queryType == "update") {
980 query = "UPDATE `" + table + "` SET " + editDis + " WHERE 1";
981 } else if(queryType == "delete") {
982 query = "DELETE FROM `" + table + "` WHERE 1";
984 document.sqlform.sql_query.value = query;
985 sql_box_locked = false;
991 * Inserts multiple fields.
994 function insertValueQuery() {
995 var myQuery = document.sqlform.sql_query;
996 var myListBox = document.sqlform.dummy;
998 if(myListBox.options.length > 0) {
999 sql_box_locked = true;
1002 for(var i=0; i<myListBox.options.length; i++) {
1003 if (myListBox.options[i].selected){
1007 chaineAj += myListBox.options[i].value;
1012 if (document.selection) {
1014 sel = document.selection.createRange();
1015 sel.text = chaineAj;
1016 document.sqlform.insert.focus();
1018 //MOZILLA/NETSCAPE support
1019 else if (document.sqlform.sql_query.selectionStart || document.sqlform.sql_query.selectionStart == "0") {
1020 var startPos = document.sqlform.sql_query.selectionStart;
1021 var endPos = document.sqlform.sql_query.selectionEnd;
1022 var chaineSql = document.sqlform.sql_query.value;
1024 myQuery.value = chaineSql.substring(0, startPos) + chaineAj + chaineSql.substring(endPos, chaineSql.length);
1026 myQuery.value += chaineAj;
1028 sql_box_locked = false;
1033 * listbox redirection
1035 function goToUrl(selObj, goToLocation) {
1036 eval("document.location.href = '" + goToLocation + "pos=" + selObj.options[selObj.selectedIndex].value + "'");
1042 function getElement(e,f){
1043 if(document.layers){
1045 if(f.document.layers[e]) {
1046 return f.document.layers[e];
1048 for(W=0;W<f.document.layers.length;W++) {
1049 return(getElement(e,f.document.layers[W]));
1053 return document.all[e];
1055 return document.getElementById(e);
1059 * Refresh the WYSIWYG scratchboard after changes have been made
1061 function refreshDragOption(e) {
1062 var elm = $('#' + e);
1063 if (elm.css('visibility') == 'visible') {
1070 * Refresh/resize the WYSIWYG scratchboard
1072 function refreshLayout() {
1073 var elm = $('#pdflayout')
1074 var orientation = $('#orientation_opt').val();
1075 if($('#paper_opt').length==1){
1076 var paper = $('#paper_opt').val();
1080 if (orientation == 'P') {
1087 elm.css('width', pdfPaperSize(paper, posa) + 'px');
1088 elm.css('height', pdfPaperSize(paper, posb) + 'px');
1092 * Show/hide the WYSIWYG scratchboard
1094 function ToggleDragDrop(e) {
1095 var elm = $('#' + e);
1096 if (elm.css('visibility') == 'hidden') {
1097 PDFinit(); /* Defined in pdf_pages.php */
1098 elm.css('visibility', 'visible');
1099 elm.css('display', 'block');
1100 $('#showwysiwyg').val('1')
1102 elm.css('visibility', 'hidden');
1103 elm.css('display', 'none');
1104 $('#showwysiwyg').val('0')
1109 * PDF scratchboard: When a position is entered manually, update
1110 * the fields inside the scratchboard.
1112 function dragPlace(no, axis, value) {
1113 var elm = $('#table_' + no);
1115 elm.css('left', value + 'px');
1117 elm.css('top', value + 'px');
1122 * Returns paper sizes for a given format
1124 function pdfPaperSize(format, axis) {
1125 switch (format.toUpperCase()) {
1127 if (axis == 'x') return 4767.87; else return 6740.79;
1130 if (axis == 'x') return 3370.39; else return 4767.87;
1133 if (axis == 'x') return 2383.94; else return 3370.39;
1136 if (axis == 'x') return 1683.78; else return 2383.94;
1139 if (axis == 'x') return 1190.55; else return 1683.78;
1142 if (axis == 'x') return 841.89; else return 1190.55;
1145 if (axis == 'x') return 595.28; else return 841.89;
1148 if (axis == 'x') return 419.53; else return 595.28;
1151 if (axis == 'x') return 297.64; else return 419.53;
1154 if (axis == 'x') return 209.76; else return 297.64;
1157 if (axis == 'x') return 147.40; else return 209.76;
1160 if (axis == 'x') return 104.88; else return 147.40;
1163 if (axis == 'x') return 73.70; else return 104.88;
1166 if (axis == 'x') return 2834.65; else return 4008.19;
1169 if (axis == 'x') return 2004.09; else return 2834.65;
1172 if (axis == 'x') return 1417.32; else return 2004.09;
1175 if (axis == 'x') return 1000.63; else return 1417.32;
1178 if (axis == 'x') return 708.66; else return 1000.63;
1181 if (axis == 'x') return 498.90; else return 708.66;
1184 if (axis == 'x') return 354.33; else return 498.90;
1187 if (axis == 'x') return 249.45; else return 354.33;
1190 if (axis == 'x') return 175.75; else return 249.45;
1193 if (axis == 'x') return 124.72; else return 175.75;
1196 if (axis == 'x') return 87.87; else return 124.72;
1199 if (axis == 'x') return 2599.37; else return 3676.54;
1202 if (axis == 'x') return 1836.85; else return 2599.37;
1205 if (axis == 'x') return 1298.27; else return 1836.85;
1208 if (axis == 'x') return 918.43; else return 1298.27;
1211 if (axis == 'x') return 649.13; else return 918.43;
1214 if (axis == 'x') return 459.21; else return 649.13;
1217 if (axis == 'x') return 323.15; else return 459.21;
1220 if (axis == 'x') return 229.61; else return 323.15;
1223 if (axis == 'x') return 161.57; else return 229.61;
1226 if (axis == 'x') return 113.39; else return 161.57;
1229 if (axis == 'x') return 79.37; else return 113.39;
1232 if (axis == 'x') return 2437.80; else return 3458.27;
1235 if (axis == 'x') return 1729.13; else return 2437.80;
1238 if (axis == 'x') return 1218.90; else return 1729.13;
1241 if (axis == 'x') return 864.57; else return 1218.90;
1244 if (axis == 'x') return 609.45; else return 864.57;
1247 if (axis == 'x') return 2551.18; else return 3628.35;
1250 if (axis == 'x') return 1814.17; else return 2551.18;
1253 if (axis == 'x') return 1275.59; else return 1814.17;
1256 if (axis == 'x') return 907.09; else return 1275.59;
1259 if (axis == 'x') return 637.80; else return 907.09;
1262 if (axis == 'x') return 612.00; else return 792.00;
1265 if (axis == 'x') return 612.00; else return 1008.00;
1268 if (axis == 'x') return 521.86; else return 756.00;
1271 if (axis == 'x') return 612.00; else return 936.00;
1279 * for playing media from the BLOB repository
1282 * @param var url_params main purpose is to pass the token
1283 * @param var bs_ref BLOB repository reference
1284 * @param var m_type type of BLOB repository media
1285 * @param var w_width width of popup window
1286 * @param var w_height height of popup window
1288 function popupBSMedia(url_params, bs_ref, m_type, is_cust_type, w_width, w_height)
1290 // if width not specified, use default
1291 if (w_width == undefined)
1294 // if height not specified, use default
1295 if (w_height == undefined)
1298 // open popup window (for displaying video/playing audio)
1299 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');
1303 * popups a request for changing MIME types for files in the BLOB repository
1305 * @param var db database name
1306 * @param var table table name
1307 * @param var reference BLOB repository reference
1308 * @param var current_mime_type current MIME type associated with BLOB repository reference
1310 function requestMIMETypeChange(db, table, reference, current_mime_type)
1312 // no mime type specified, set to default (nothing)
1313 if (undefined == current_mime_type)
1314 current_mime_type = "";
1316 // prompt user for new mime type
1317 var new_mime_type = prompt("Enter custom MIME type", current_mime_type);
1319 // if new mime_type is specified and is not the same as the previous type, request for mime type change
1320 if (new_mime_type && new_mime_type != current_mime_type)
1321 changeMIMEType(db, table, reference, new_mime_type);
1325 * changes MIME types for files in the BLOB repository
1327 * @param var db database name
1328 * @param var table table name
1329 * @param var reference BLOB repository reference
1330 * @param var mime_type new MIME type to be associated with BLOB repository reference
1332 function changeMIMEType(db, table, reference, mime_type)
1334 // specify url and parameters for jQuery POST
1335 var mime_chg_url = 'bs_change_mime_type.php';
1336 var params = {bs_db: db, bs_table: table, bs_reference: reference, bs_new_mime_type: mime_type};
1339 jQuery.post(mime_chg_url, params);
1343 * Jquery Coding for inline editing SQL_QUERY
1345 $(document).ready(function(){
1346 var oldText,db,table,token,sql_query;
1347 oldText=$(".inner_sql").html();
1348 $("#inline_edit").click(function(){
1349 db=$("input[name='db']").val();
1350 table=$("input[name='table']").val();
1351 token=$("input[name='token']").val();
1352 sql_query=$("input[name='sql_query']").val();
1353 $(".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'] + "\">");
1357 $("#btnSave").live("click",function(){
1358 window.location.replace("import.php?db=" + db +"&table=" + table + "&sql_query=" + $("#sql_query_edit").val()+"&show_query=1&token=" + token + "");
1361 $("#btnDiscard").live("click",function(){
1362 $(".sql").html("<span class=\"syntax\"><span class=\"inner_sql\">" + oldText + "</span></span>");
1365 $('.sqlbutton').click(function(evt){
1366 insertQuery(evt.target.id);
1370 $("#export_type").change(function(){
1371 if($("#export_type").val()=='svg'){
1372 $("#show_grid_opt").attr("disabled","disabled");
1373 $("#orientation_opt").attr("disabled","disabled");
1374 $("#with_doc").attr("disabled","disabled");
1375 $("#show_table_dim_opt").removeAttr("disabled");
1376 $("#all_table_same_wide").removeAttr("disabled");
1377 $("#paper_opt").removeAttr("disabled","disabled");
1378 $("#show_color_opt").removeAttr("disabled","disabled");
1379 //$(this).css("background-color","yellow");
1380 }else if($("#export_type").val()=='dia'){
1381 $("#show_grid_opt").attr("disabled","disabled");
1382 $("#with_doc").attr("disabled","disabled");
1383 $("#show_table_dim_opt").attr("disabled","disabled");
1384 $("#all_table_same_wide").attr("disabled","disabled");
1385 $("#paper_opt").removeAttr("disabled","disabled");
1386 $("#show_color_opt").removeAttr("disabled","disabled");
1387 $("#orientation_opt").removeAttr("disabled","disabled");
1388 }else if($("#export_type").val()=='eps'){
1389 $("#show_grid_opt").attr("disabled","disabled");
1390 $("#orientation_opt").removeAttr("disabled");
1391 $("#with_doc").attr("disabled","disabled");
1392 $("#show_table_dim_opt").attr("disabled","disabled");
1393 $("#all_table_same_wide").attr("disabled","disabled");
1394 $("#paper_opt").attr("disabled","disabled");
1395 $("#show_color_opt").attr("disabled","disabled");
1397 }else if($("#export_type").val()=='pdf'){
1398 $("#show_grid_opt").removeAttr("disabled");
1399 $("#orientation_opt").removeAttr("disabled");
1400 $("#with_doc").removeAttr("disabled","disabled");
1401 $("#show_table_dim_opt").removeAttr("disabled","disabled");
1402 $("#all_table_same_wide").removeAttr("disabled","disabled");
1403 $("#paper_opt").removeAttr("disabled","disabled");
1404 $("#show_color_opt").removeAttr("disabled","disabled");
1410 $('#sqlquery').focus();
1411 if ($('#input_username')) {
1412 if ($('#input_username').val() == '') {
1413 $('#input_username').focus();
1415 $('#input_password').focus();
1421 * Function to process the plain HTML response from an Ajax request. Inserts
1422 * the various HTML divisions from the response at the proper locations. The
1423 * array relates the divisions to be inserted to their placeholders.
1425 * @param var divisions_map an associative array of id names
1428 * PMA_ajaxInsertResponse({'resultsTable':'resultsTable_response',
1429 * 'profilingData':'profilingData_response'});
1434 function PMA_ajaxInsertResponse(divisions_map) {
1435 $.each(divisions_map, function(key, value) {
1436 var content_div = '#'+value;
1437 var target_div = '#'+key;
1438 var content = $(content_div).html();
1440 //replace content of target_div with that from the response
1441 $(target_div).html(content);
1446 * Show a message on the top of the page for an Ajax request
1448 * @param var message string containing the message to be shown.
1449 * optional, defaults to 'Loading...'
1450 * @param var timeout number of milliseconds for the message to be visible
1451 * optional, defaults to 5000
1454 function PMA_ajaxShowMessage(message, timeout) {
1456 //Handle the case when a empty data.message is passed. We don't want the empty message
1462 * @var msg String containing the message that has to be displayed
1463 * @default PMA_messages['strLoading']
1466 var msg = PMA_messages['strLoading'];
1473 * @var timeout Number of milliseconds for which {@link msg} will be visible
1483 if( !ajax_message_init) {
1484 //For the first time this function is called, append a new div
1486 $('<div id="loading_parent"></div>')
1487 .insertBefore("#serverinfo");
1489 $('<span id="loading" class="ajax_notification"></span>')
1490 .appendTo("#loading_parent")
1492 .slideDown('medium')
1494 .slideUp('medium', function(){
1496 .html("") //Clear the message
1499 }, 'top.frame_content');
1500 ajax_message_init = true;
1503 //Otherwise, just show the div again after inserting the message
1507 .slideDown('medium')
1509 .slideUp('medium', function() {
1518 * Hides/shows the "Open in ENUM/SET editor" message, depending on the data type of the column currently selected
1520 function toggle_enum_notice(selectElement) {
1521 var enum_notice_id = selectElement.attr("id").split("_")[1];
1522 enum_notice_id += "_" + (parseInt(selectElement.attr("id").split("_")[2]) + 1);
1523 var selectedType = selectElement.attr("value");
1524 if(selectedType == "ENUM" || selectedType == "SET") {
1525 $("p[id='enum_notice_" + enum_notice_id + "']").show();
1527 $("p[id='enum_notice_" + enum_notice_id + "']").hide();
1532 * jQuery function that uses jQueryUI's dialogs to confirm with user. Does not
1533 * return a jQuery object yet and hence cannot be chained
1535 * @param string question
1536 * @param string url URL to be passed to the callbackFn to make
1538 * @param function callbackFn callback to execute after user clicks on OK
1541 jQuery.fn.PMA_confirm = function(question, url, callbackFn) {
1542 if (PMA_messages['strDoYouReally'] == '') {
1547 * @var button_options Object that stores the options passed to jQueryUI
1550 var button_options = {};
1551 button_options[PMA_messages['strOK']] = function(){
1552 $(this).dialog("close").remove();
1554 if($.isFunction(callbackFn)) {
1555 callbackFn.call(this, url);
1558 button_options[PMA_messages['strCancel']] = function() {$(this).dialog("close").remove();}
1560 $('<div id="confirm_dialog"></div>')
1562 .dialog({buttons: button_options});
1566 * jQuery function to sort a table's body after a new row has been appended to it.
1567 * Also fixes the even/odd classes of the table rows at the end.
1569 * @param string text_selector string to select the sortKey's text
1571 * @return jQuery Object for chaining purposes
1573 jQuery.fn.PMA_sort_table = function(text_selector) {
1574 return this.each(function() {
1577 * @var table_body Object referring to the table's <tbody> element
1579 var table_body = $(this);
1581 * @var rows Object referring to the collection of rows in {@link table_body}
1583 var rows = $(this).find('tr').get();
1585 //get the text of the field that we will sort by
1586 $.each(rows, function(index, row) {
1587 row.sortKey = $.trim($(row).find(text_selector).text().toLowerCase());
1590 //get the sorted order
1591 rows.sort(function(a,b) {
1592 if(a.sortKey < b.sortKey) {
1595 if(a.sortKey > b.sortKey) {
1601 //pull out each row from the table and then append it according to it's order
1602 $.each(rows, function(index, row) {
1603 $(table_body).append(row);
1607 //Re-check the classes of each row
1608 $(this).find('tr:odd')
1609 .removeClass('even').addClass('odd')
1612 .removeClass('odd').addClass('even');
1617 * jQuery coding for 'Create Table'. Used on db_operations.php,
1618 * db_structure.php and db_tracking.php (i.e., wherever
1619 * libraries/display_create_table.lib.php is used)
1621 * Attach Ajax Event handlers for Create Table
1623 $(document).ready(function() {
1626 * Attach event handler to the submit action of the create table minimal form
1627 * and retrieve the full table form and display it in a dialog
1629 * @uses PMA_ajaxShowMessage()
1631 $("#create_table_form_minimal").live('submit', function(event) {
1632 event.preventDefault();
1635 /* @todo Validate this form! */
1638 * @var button_options Object that stores the options passed to jQueryUI
1641 var button_options = {};
1642 // in the following function we need to use $(this)
1643 button_options[PMA_messages['strCancel']] = function() {$(this).dialog('close').remove();}
1645 PMA_ajaxShowMessage();
1646 if (! $form.find('input:hidden').is('#ajax_request_hidden')) {
1647 $form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
1650 $.get($form.attr('action'), $form.serialize(), function(data) {
1651 $('<div id="create_table_dialog"></div>')
1654 title: PMA_messages['strCreateTable'],
1656 buttons : button_options
1657 }); // end dialog options
1660 // empty table name and number of columns from the minimal form
1661 $form.find('input[name=table],input[name=num_fields]').val('');
1665 * Attach event handler for submission of create table form (save)
1667 * @uses PMA_ajaxShowMessage()
1668 * @uses $.PMA_sort_table()
1671 // .live() must be called after a selector, see http://api.jquery.com/live
1672 $("#create_table_form input[name=do_save_data]").live('click', function(event) {
1673 event.preventDefault();
1676 * @var the_form object referring to the create table form
1678 var $form = $("#create_table_form");
1680 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
1681 if (! $form.find('input:hidden').is('#ajax_request_hidden')) {
1682 $form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
1684 //User wants to submit the form
1685 $.post($form.attr('action'), $form.serialize() + "&do_save_data=" + $(this).val(), function(data) {
1686 if(data.success == true) {
1687 PMA_ajaxShowMessage(data.message);
1688 $("#create_table_dialog").dialog("close").remove();
1691 * @var tables_table Object referring to the <tbody> element that holds the list of tables
1693 var tables_table = $("#tablesForm").find("tbody").not("#tbl_summary_row");
1694 // this is the first table created in this db
1695 if (tables_table.length == 0) {
1696 if (window.parent && window.parent.frame_content) {
1697 window.parent.frame_content.location.reload();
1701 * @var curr_last_row Object referring to the last <tr> element in {@link tables_table}
1703 var curr_last_row = $(tables_table).find('tr:last');
1705 * @var curr_last_row_index_string String containing the index of {@link curr_last_row}
1707 var curr_last_row_index_string = $(curr_last_row).find('input:checkbox').attr('id').match(/\d+/)[0];
1709 * @var curr_last_row_index Index of {@link curr_last_row}
1711 var curr_last_row_index = parseFloat(curr_last_row_index_string);
1713 * @var new_last_row_index Index of the new row to be appended to {@link tables_table}
1715 var new_last_row_index = curr_last_row_index + 1;
1717 * @var new_last_row_id String containing the id of the row to be appended to {@link tables_table}
1719 var new_last_row_id = 'checkbox_tbl_' + new_last_row_index;
1722 $(data.new_table_string)
1723 .find('input:checkbox')
1724 .val(new_last_row_id)
1726 .appendTo(tables_table);
1729 $(tables_table).PMA_sort_table('th');
1732 //Refresh navigation frame as a new table has been added
1733 if (window.parent && window.parent.frame_navigation) {
1734 window.parent.frame_navigation.location.reload();
1738 PMA_ajaxShowMessage(data.error);
1741 }) // end create table form (save)
1744 * Attach event handler for create table form (add fields)
1746 * @uses PMA_ajaxShowMessage()
1747 * @uses $.PMA_sort_table()
1748 * @uses window.parent.refreshNavigation()
1751 // .live() must be called after a selector, see http://api.jquery.com/live
1752 $("#create_table_form input[name=submit_num_fields]").live('click', function(event) {
1753 event.preventDefault();
1756 * @var the_form object referring to the create table form
1758 var $form = $("#create_table_form");
1760 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
1761 if (! $form.find('input:hidden').is('#ajax_request_hidden')) {
1762 $form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
1765 //User wants to add more fields to the table
1766 $.post($form.attr('action'), $form.serialize() + "&submit_num_fields=" + $(this).val(), function(data) {
1767 $("#create_table_dialog").html(data);
1770 }) // end create table form (add fields)
1772 }, 'top.frame_content'); //end $(document).ready for 'Create Table'
1775 * Attach event handlers for Empty Table and Drop Table. Used wherever libraries/
1776 * tbl_links.inc.php is used.
1778 $(document).ready(function() {
1781 * Attach Ajax event handlers for Empty Table
1783 * @uses PMA_ajaxShowMessage()
1784 * @uses $.PMA_confirm()
1786 $("#empty_table_anchor").live('click', function(event) {
1787 event.preventDefault();
1790 * @var question String containing the question to be asked for confirmation
1792 var question = 'TRUNCATE TABLE ' + window.parent.table;
1794 $(this).PMA_confirm(question, $(this).attr('href'), function(url) {
1796 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
1797 $.get(url, {'is_js_confirmed': 1, 'ajax_request': true}, function(data) {
1798 if(data.success == true) {
1799 PMA_ajaxShowMessage(data.message);
1800 $("#topmenucontainer")
1804 .after(data.sql_query);
1807 PMA_ajaxShowMessage(data.error);
1810 }) // end $.PMA_confirm()
1811 }) // end Empty Table
1814 * Attach Ajax event handler for Drop Table
1816 * @uses PMA_ajaxShowMessage()
1817 * @uses $.PMA_confirm()
1818 * @uses window.parent.refreshNavigation()
1820 $("#drop_table_anchor").live('click', function(event) {
1821 event.preventDefault();
1824 * @var question String containing the question to be asked for confirmation
1826 var question = 'DROP TABLE/VIEW ' + window.parent.table;
1827 $(this).PMA_confirm(question, $(this).attr('href'), function(url) {
1829 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
1830 $.get(url, {'is_js_confirmed': 1, 'ajax_request': true}, function(data) {
1831 if(data.success == true) {
1832 PMA_ajaxShowMessage(data.message);
1833 $("#topmenucontainer")
1837 .after(data.sql_query);
1838 window.parent.table = '';
1839 if (window.parent && window.parent.frame_navigation) {
1840 window.parent.frame_navigation.location.reload();
1844 PMA_ajaxShowMessage(data.error);
1847 }) // end $.PMA_confirm()
1848 }) // end $().live()
1849 }, 'top.frame_content'); //end $(document).ready() for libraries/tbl_links.inc.php
1852 * Attach Ajax event handlers for Drop Trigger. Used on tbl_structure.php
1854 $(document).ready(function() {
1856 $(".drop_trigger_anchor").live('click', function(event) {
1857 event.preventDefault();
1860 * @var curr_row Object reference to the current trigger's <tr>
1862 var curr_row = $(this).parents('tr');
1864 * @var question String containing the question to be asked for confirmation
1866 var question = 'DROP TRIGGER IF EXISTS `' + $(curr_row).children('td:first').text() + '`';
1868 $(this).PMA_confirm(question, $(this).attr('href'), function(url) {
1870 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
1871 $.get(url, {'is_js_confirmed': 1, 'ajax_request': true}, function(data) {
1872 if(data.success == true) {
1873 PMA_ajaxShowMessage(data.message);
1874 $("#topmenucontainer")
1878 .after(data.sql_query);
1879 $(curr_row).hide("medium").remove();
1882 PMA_ajaxShowMessage(data.error);
1885 }) // end $.PMA_confirm()
1886 }) // end $().live()
1887 }, 'top.frame_content'); //end $(document).ready() for Drop Trigger
1890 * Attach Ajax event handlers for Drop Database. Moved here from db_structure.js
1891 * as it was also required on db_create.php
1893 * @uses $.PMA_confirm()
1894 * @uses PMA_ajaxShowMessage()
1895 * @uses window.parent.refreshNavigation()
1896 * @uses window.parent.refreshMain()
1898 $(document).ready(function() {
1899 $("#drop_db_anchor").live('click', function(event) {
1900 event.preventDefault();
1902 //context is top.frame_content, so we need to use window.parent.db to access the db var
1904 * @var question String containing the question to be asked for confirmation
1906 var question = PMA_messages['strDropDatabaseStrongWarning'] + '\n' + PMA_messages['strDoYouReally'] + ' :\n' + 'DROP DATABASE ' + window.parent.db;
1908 $(this).PMA_confirm(question, $(this).attr('href') ,function(url) {
1910 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
1911 $.get(url, {'is_js_confirmed': '1', 'ajax_request': true}, function(data) {
1912 //Database deleted successfully, refresh both the frames
1913 window.parent.refreshNavigation();
1914 window.parent.refreshMain();
1916 }); // end $.PMA_confirm()
1917 }); //end of Drop Database Ajax action
1918 }) // end of $(document).ready() for Drop Database
1921 * Attach Ajax event handlers for 'Create Database'. Used wherever libraries/
1922 * display_create_database.lib.php is used, ie main.php and server_databases.php
1924 * @uses PMA_ajaxShowMessage()
1926 $(document).ready(function() {
1928 $('#create_database_form').live('submit', function(event) {
1929 event.preventDefault();
1933 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
1935 if (! $form.find('input:hidden').is('#ajax_request_hidden')) {
1936 $form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
1939 $.post($form.attr('action'), $form.serialize(), function(data) {
1940 if(data.success == true) {
1941 PMA_ajaxShowMessage(data.message);
1943 //Append database's row to table
1944 $("#tabledatabases")
1946 .append(data.new_db_string)
1947 .PMA_sort_table('.name')
1948 .find('#db_summary_row')
1949 .appendTo('#tabledatabases tbody')
1950 .removeClass('odd even');
1952 var $databases_count_object = $('#databases_count');
1953 var databases_count = parseInt($databases_count_object.text());
1954 $databases_count_object.text(++databases_count);
1955 //Refresh navigation frame as a new database has been added
1956 if (window.parent && window.parent.frame_navigation) {
1957 window.parent.frame_navigation.location.reload();
1961 PMA_ajaxShowMessage(data.error);
1964 }) // end $().live()
1965 }) // end $(document).ready() for Create Database
1968 * Attach Ajax event handlers for 'Change Password' on main.php
1970 $(document).ready(function() {
1973 * Attach Ajax event handler on the change password anchor
1975 $('#change_password_anchor').live('click', function(event) {
1976 event.preventDefault();
1979 * @var button_options Object containing options to be passed to jQueryUI's dialog
1981 var button_options = {};
1983 button_options[PMA_messages['strCancel']] = function() {$(this).dialog('close').remove();}
1985 $.get($(this).attr('href'), {'ajax_request': true}, function(data) {
1986 $('<div id="change_password_dialog></div>')
1988 title: PMA_messages['strChangePassword'],
1990 buttons : button_options
1993 displayPasswordGenerateButton();
1995 }) // end handler for change password anchor
1998 * Attach Ajax event handler for Change Password form submission
2000 * @uses PMA_ajaxShowMessage()
2002 $("#change_password_form").find('input[name=change_pw]').live('click', function(event) {
2003 event.preventDefault();
2006 * @var the_form Object referring to the change password form
2008 var the_form = $("#change_password_form");
2011 * @var this_value String containing the value of the submit button.
2012 * Need to append this for the change password form on Server Privileges
2015 var this_value = $(this).val();
2017 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
2018 $(the_form).append('<input type="hidden" name="ajax_request" value="true" />');
2020 $.post($(the_form).attr('action'), $(the_form).serialize() + '&change_pw='+ this_value, function(data) {
2021 if(data.success == true) {
2023 PMA_ajaxShowMessage(data.message);
2025 $("#topmenucontainer").after(data.sql_query);
2027 $("#change_password_dialog").hide().remove();
2028 $("#edit_user_dialog").dialog("close").remove();
2031 PMA_ajaxShowMessage(data.error);
2034 }) // end handler for Change Password form submission
2035 }) // end $(document).ready() for Change Password
2038 * Toggle the hiding/showing of the "Open in ENUM/SET editor" message when
2039 * the page loads and when the selected data type changes
2041 $(document).ready(function() {
2042 $.each($("select[class='column_type']"), function() {
2043 toggle_enum_notice($(this));
2045 $("select[class='column_type']").change(function() {
2046 toggle_enum_notice($(this));
2051 * Closes the ENUM/SET editor and removes the data in it
2053 function disable_popup() {
2054 $("#popup_background").fadeOut("fast");
2055 $("#enum_editor").fadeOut("fast");
2056 // clear the data from the text boxes
2057 $("#enum_editor #values input").remove();
2058 $("#enum_editor input[type='hidden']").remove();
2062 * Opens the ENUM/SET editor and controls its functions
2064 $(document).ready(function() {
2065 $("a[class='open_enum_editor']").click(function() {
2067 var windowWidth = document.documentElement.clientWidth;
2068 var windowHeight = document.documentElement.clientHeight;
2069 var popupWidth = windowWidth/2;
2070 var popupHeight = windowHeight*0.8;
2071 var popupOffsetTop = windowHeight/2 - popupHeight/2;
2072 var popupOffsetLeft = windowWidth/2 - popupWidth/2;
2073 $("#enum_editor").css({"position":"absolute", "top": popupOffsetTop, "left": popupOffsetLeft, "width": popupWidth, "height": popupHeight});
2076 $("#popup_background").css({"opacity":"0.7"});
2077 $("#popup_background").fadeIn("fast");
2078 $("#enum_editor").fadeIn("fast");
2081 var values = $(this).parent().prev("input").attr("value").split(",");
2082 $.each(values, function(index, val) {
2083 if(jQuery.trim(val) != "") {
2084 // enclose the string in single quotes if it's not already
2085 if(val.substr(0, 1) != "'") {
2088 if(val.substr(val.length-1, val.length) != "'") {
2091 // escape the single quotes, except the mandatory ones enclosing the entire string
2092 val = val.substr(1, val.length-2).replace(/''/g, "'").replace(/\\\\/g, '\\').replace(/\\'/g, "'").replace(/'/g, "'");
2093 // escape the greater-than symbol
2094 val = val.replace(/>/g, ">");
2095 $("#enum_editor #values").append("<input type='text' value=" + val + " />");
2098 // So we know which column's data is being edited
2099 $("#enum_editor").append("<input type='hidden' value='" + $(this).parent().prev("input").attr("id") + "' />");
2103 // If the "close" link is clicked, close the enum editor
2104 $("a[class='close_enum_editor']").click(function() {
2108 // If the "cancel" link is clicked, close the enum editor
2109 $("a[class='cancel_enum_editor']").click(function() {
2113 // When "add a new value" is clicked, append an empty text field
2114 $("a[class='add_value']").click(function() {
2115 $("#enum_editor #values").append("<input type='text' />");
2118 // When the submit button is clicked, put the data back into the original form
2119 $("#enum_editor input[type='submit']").click(function() {
2120 var value_array = new Array();
2121 $.each($("#enum_editor #values input"), function(index, input_element) {
2122 val = jQuery.trim(input_element.value);
2124 value_array.push("'" + val.replace(/\\/g, '\\\\').replace(/'/g, "''") + "'");
2127 // get the Length/Values text field where this value belongs
2128 var values_id = $("#enum_editor input[type='hidden']").attr("value");
2129 $("input[id='" + values_id + "']").attr("value", value_array.join(","));
2134 * Hides certain table structure actions, replacing them with the word "More". They are displayed
2135 * in a dropdown menu when the user hovers over the word "More."
2137 // Remove the actions from the table cells (they are available by default for JavaScript-disabled browsers)
2138 // if the table is not a view or information_schema (otherwise there is only one action to hide and there's no point)
2139 if($("input[type='hidden'][name='table_type']").attr("value") == "table") {
2140 $("table[id='tablestructure'] td[class='browse']").remove();
2141 $("table[id='tablestructure'] td[class='primary']").remove();
2142 $("table[id='tablestructure'] td[class='unique']").remove();
2143 $("table[id='tablestructure'] td[class='index']").remove();
2144 $("table[id='tablestructure'] td[class='fulltext']").remove();
2145 $("table[id='tablestructure'] th[class='action']").attr("colspan", 3);
2147 // Display the "more" text
2148 $("table[id='tablestructure'] td[class='more_opts']").show()
2150 // Position the dropdown
2151 $.each($(".structure_actions_dropdown"), function() {
2152 // The top offset must be set for IE even if it didn't change
2153 var cell_right_edge_offset = $(this).parent().offset().left + $(this).parent().innerWidth();
2154 var left_offset = cell_right_edge_offset - $(this).innerWidth();
2155 var top_offset = $(this).parent().offset().top + $(this).parent().innerHeight();
2156 $(this).offset({ top: top_offset, left: left_offset });
2159 // A hack for IE6 to prevent the after_field select element from being displayed on top of the dropdown by
2160 // positioning an iframe directly on top of it
2161 $("iframe[class='IE_hack']").width($("select[name='after_field']").width());
2162 $("iframe[class='IE_hack']").height($("select[name='after_field']").height());
2163 $("iframe[class='IE_hack']").offset({ top: $("select[name='after_field']").offset().top, left: $("select[name='after_field']").offset().left });
2165 // When "more" is hovered over, show the hidden actions
2166 $("table[id='tablestructure'] td[class='more_opts']").mouseenter(
2168 if($.browser.msie && $.browser.version == "6.0") {
2169 $("iframe[class='IE_hack']").show();
2170 $("iframe[class='IE_hack']").width($("select[name='after_field']").width()+4);
2171 $("iframe[class='IE_hack']").height($("select[name='after_field']").height()+4);
2172 $("iframe[class='IE_hack']").offset({ top: $("select[name='after_field']").offset().top, left: $("select[name='after_field']").offset().left});
2174 $(".structure_actions_dropdown").hide(); // Hide all the other ones that may be open
2175 $(this).children(".structure_actions_dropdown").show();
2176 // Need to do this again for IE otherwise the offset is wrong
2177 if($.browser.msie) {
2178 var left_offset_IE = $(this).offset().left + $(this).innerWidth() - $(this).children(".structure_actions_dropdown").innerWidth();
2179 var top_offset_IE = $(this).offset().top + $(this).innerHeight();
2180 $(this).children(".structure_actions_dropdown").offset({ top: top_offset_IE, left: left_offset_IE });
2183 $(".structure_actions_dropdown").mouseleave(function() {
2185 if($.browser.msie && $.browser.version == "6.0") {
2186 $("iframe[class='IE_hack']").hide();
2192 /* Displays tooltips */
2193 $(document).ready(function() {
2194 // Hide the footnotes from the footer (which are displayed for
2195 // JavaScript-disabled browsers) since the tooltip is sufficient
2196 $(".footnotes").hide();
2197 $(".footnotes span").each(function() {
2198 $(this).children("sup").remove();
2200 // The border and padding must be removed otherwise a thin yellow box remains visible
2201 $(".footnotes").css("border", "none");
2202 $(".footnotes").css("padding", "0px");
2204 // Replace the superscripts with the help icon
2205 $("sup[class='footnotemarker']").hide();
2206 $("img[class='footnotemarker']").show();
2208 $("img[class='footnotemarker']").each(function() {
2209 var span_id = $(this).attr("id");
2210 span_id = span_id.split("_")[1];
2211 var tooltip_text = $(".footnotes span[id='footnote_" + span_id + "']").html();
2213 content: tooltip_text,
2215 hide: { when: 'unfocus', delay: 0 },
2216 style: { background: '#ffffcc' }
2221 function menuResize()
2223 var cnt = $('#topmenu');
2224 var wmax = cnt.width() - 5; // 5 px margin for jumping menu in Chrome
2225 var submenu = cnt.find('.submenu');
2226 var submenu_w = submenu.outerWidth(true);
2227 var submenu_ul = submenu.find('ul');
2228 var li = cnt.find('> li');
2229 var li2 = submenu_ul.find('li');
2230 var more_shown = li2.length > 0;
2231 var w = more_shown ? submenu_w : 0;
2235 for (var i = 0; i < li.length-1; i++) { // li.length-1: skip .submenu element
2237 var el_width = el.outerWidth(true);
2238 el.data('width', el_width);
2242 if (w + submenu_w < wmax) {
2246 w -= $(li[i-1]).data('width');
2252 if (hide_start > 0) {
2253 for (var i = hide_start; i < li.length-1; i++) {
2254 $(li[i])[more_shown ? 'prependTo' : 'appendTo'](submenu_ul);
2257 } else if (more_shown) {
2259 // nothing hidden, maybe something can be restored
2260 for (var i = 0; i < li2.length; i++) {
2261 //console.log(li2[i], submenu_w);
2262 w += $(li2[i]).data('width');
2263 // item fits or (it is the last item and it would fit if More got removed)
2264 if (w+submenu_w < wmax || (i == li2.length-1 && w < wmax)) {
2265 $(li2[i]).insertBefore(submenu);
2266 if (i == li2.length-1) {
2274 if (submenu.find('.tabactive').length) {
2275 submenu.addClass('active').find('> a').removeClass('tab').addClass('tabactive');
2277 submenu.removeClass('active').find('> a').addClass('tab').removeClass('tabactive');
2282 var topmenu = $('#topmenu');
2283 if (topmenu.length == 0) {
2286 // create submenu container
2287 var link = $('<a />', {href: '#', 'class': 'tab'})
2288 .text(PMA_messages['strMore'])
2289 .click(function(e) {
2292 var img = topmenu.find('li:first-child img');
2294 img.clone().attr('src', img.attr('src').replace(/\/[^\/]+$/, '/b_more.png')).prependTo(link);
2296 var submenu = $('<li />', {'class': 'submenu'})
2298 .append($('<ul />'))
2299 .mouseenter(function() {
2300 if ($(this).find('ul .tabactive').length == 0) {
2301 $(this).addClass('submenuhover').find('> a').addClass('tabactive');
2304 .mouseleave(function() {
2305 if ($(this).find('ul .tabactive').length == 0) {
2306 $(this).removeClass('submenuhover').find('> a').removeClass('tabactive');
2310 topmenu.append(submenu);
2312 // populate submenu and register resize event
2313 $(window).resize(menuResize);
2318 * For the checkboxes in browse mode, handles the shift/click (only works
2319 * in horizontal mode) and propagates the click to the "companion" checkbox
2320 * (in both horizontal and vertical). Works also for pages reached via AJAX.
2322 $(document).ready(function() {
2323 $('.multi_checkbox').live('click',function(e) {
2324 var current_checkbox_id = this.id;
2325 var left_checkbox_id = current_checkbox_id.replace('_right', '_left');
2326 var right_checkbox_id = current_checkbox_id.replace('_left', '_right');
2327 var other_checkbox_id = '';
2328 if (current_checkbox_id == left_checkbox_id) {
2329 other_checkbox_id = right_checkbox_id;
2331 other_checkbox_id = left_checkbox_id;
2334 var $current_checkbox = $('#' + current_checkbox_id);
2335 var $other_checkbox = $('#' + other_checkbox_id);
2338 var index_of_current_checkbox = $('.multi_checkbox').index($current_checkbox);
2339 var $last_checkbox = $('.multi_checkbox').filter('.last_clicked');
2340 var index_of_last_click = $('.multi_checkbox').index($last_checkbox);
2341 $('.multi_checkbox')
2342 .filter(function(index) {
2343 // the first clicked row can be on a row above or below the
2344 // shift-clicked row
2345 return (index_of_current_checkbox > index_of_last_click && index > index_of_last_click && index < index_of_current_checkbox)
2346 || (index_of_last_click > index_of_current_checkbox && index < index_of_last_click && index > index_of_current_checkbox);
2348 .each(function(index) {
2349 var $intermediate_checkbox = $(this);
2350 if ($current_checkbox.is(':checked')) {
2351 $intermediate_checkbox.attr('checked', true);
2353 $intermediate_checkbox.attr('checked', false);
2358 $('.multi_checkbox').removeClass('last_clicked');
2359 $current_checkbox.addClass('last_clicked');
2361 // When there is a checkbox on both ends of the row, propagate the
2362 // click on one of them to the other one.
2363 // (the default action has not been prevented so if we have
2364 // just clicked, this "if" is true)
2365 if ($current_checkbox.is(':checked')) {
2366 $other_checkbox.attr('checked', true);
2368 $other_checkbox.attr('checked', false);
2371 }) // end of $(document).ready() for multi checkbox
2374 * Get the row number from the classlist (for example, row_1)
2376 function PMA_getRowNumber(classlist) {
2377 return parseInt(classlist.split(/row_/)[1]);
2383 $(document).ready(function() {
2384 $('.vpointer').live('hover',
2387 var $this_td = $(this);
2388 var row_num = PMA_getRowNumber($this_td.attr('class'));
2389 // for all td of the same vertical row, toggle hover
2390 $('.vpointer').filter('.row_' + row_num).toggleClass('hover');
2393 }) // end of $(document).ready() for vertical pointer
2395 $(document).ready(function() {
2399 $('.vmarker').live('click', function(e) {
2400 var $this_td = $(this);
2401 var row_num = PMA_getRowNumber($this_td.attr('class'));
2402 // for all td of the same vertical row, toggle the marked class
2403 $('.vmarker').filter('.row_' + row_num).toggleClass('marked');
2407 * Reveal visual builder anchor
2410 $('#visual_builder_anchor').show();
2411 }) // end of $(document).ready()