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 int ajax_message_count Number of AJAX messages shown since page load
20 var ajax_message_count = 0;
23 * @var codemirror_editor object containing CodeMirror editor
25 var codemirror_editor = false;
28 * @var chart_activeTimeouts object active timeouts that refresh the charts. When disabling a realtime chart, this can be used to stop the continuous ajax requests
30 var chart_activeTimeouts = new Object();
34 * Add a hidden field to the form to indicate that this will be an
35 * Ajax request (only if this hidden field does not exist)
37 * @param object the form
39 function PMA_prepareForAjaxRequest($form) {
40 if (! $form.find('input:hidden').is('#ajax_request_hidden')) {
41 $form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
46 * Generate a new password and copy it to the password input areas
48 * @param object the form that holds the password fields
50 * @return boolean always true
52 function suggestPassword(passwd_form) {
53 // restrict the password to just letters and numbers to avoid problems:
54 // "editors and viewers regard the password as multiple words and
55 // things like double click no longer work"
56 var pwchars = "abcdefhjmnpqrstuvwxyz23456789ABCDEFGHJKLMNPQRSTUVWYXZ";
57 var passwordlength = 16; // do we want that to be dynamic? no, keep it simple :)
58 var passwd = passwd_form.generated_pw;
61 for ( i = 0; i < passwordlength; i++ ) {
62 passwd.value += pwchars.charAt( Math.floor( Math.random() * pwchars.length ) )
64 passwd_form.text_pma_pw.value = passwd.value;
65 passwd_form.text_pma_pw2.value = passwd.value;
70 * Version string to integer conversion.
72 function parseVersionString (str) {
73 if (typeof(str) != 'string') { return false; }
75 // Parse possible alpha/beta/rc/
76 var state = str.split('-');
77 if (state.length >= 2) {
78 if (state[1].substr(0, 2) == 'rc') {
79 add = - 20 - parseInt(state[1].substr(2));
80 } else if (state[1].substr(0, 4) == 'beta') {
81 add = - 40 - parseInt(state[1].substr(4));
82 } else if (state[1].substr(0, 5) == 'alpha') {
83 add = - 60 - parseInt(state[1].substr(5));
84 } else if (state[1].substr(0, 3) == 'dev') {
85 /* We don't handle dev, it's git snapshot */
90 var x = str.split('.');
91 // Use 0 for non existing parts
92 var maj = parseInt(x[0]) || 0;
93 var min = parseInt(x[1]) || 0;
94 var pat = parseInt(x[2]) || 0;
95 var hotfix = parseInt(x[3]) || 0;
96 return maj * 100000000 + min * 1000000 + pat * 10000 + hotfix * 100 + add;
100 * Indicates current available version on main page.
102 function PMA_current_version() {
103 var current = parseVersionString(pmaversion);
104 var latest = parseVersionString(PMA_latest_version);
105 var version_information_message = PMA_messages['strLatestAvailable'] + ' ' + PMA_latest_version;
106 if (latest > current) {
107 var message = $.sprintf(PMA_messages['strNewerVersion'], PMA_latest_version, PMA_latest_date);
108 if (Math.floor(latest / 10000) == Math.floor(current / 10000)) {
109 /* Security update */
114 $('#maincontainer').after('<div class="' + klass + '">' + message + '</div>');
116 if (latest == current) {
117 version_information_message = ' (' + PMA_messages['strUpToDate'] + ')';
119 $('#li_pma_version').append(version_information_message);
123 * for libraries/display_change_password.lib.php
124 * libraries/user_password.php
128 function displayPasswordGenerateButton() {
129 $('#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>');
130 $('#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>');
134 * Adds a date/time picker to an element
136 * @param object $this_element a jQuery object pointing to the element
138 function PMA_addDatepicker($this_element, options) {
139 var showTimeOption = false;
140 if ($this_element.is('.datetimefield')) {
141 showTimeOption = true;
144 var defaultOptions = {
146 buttonImage: themeCalendarImage, // defined in js/messages.php
147 buttonImageOnly: true,
152 showTime: showTimeOption,
153 dateFormat: 'yy-mm-dd', // yy means year with four digits
155 beforeShow: function(input, inst) {
156 // Remember that we came from the datepicker; this is used
157 // in tbl_change.js by verificationsAfterFieldChange()
158 $this_element.data('comes_from', 'datepicker');
160 // Fix wrong timepicker z-index, doesn't work without timeout
161 setTimeout(function() {
162 $('#ui-timepicker-div').css('z-index',$('#ui-datepicker-div').css('z-index'))
165 constrainInput: false
168 $this_element.datepicker($.extend(defaultOptions, options));
172 * selects the content of a given object, f.e. a textarea
174 * @param object element element of which the content will be selected
175 * @param var lock variable which holds the lock for this element
176 * or true, if no lock exists
177 * @param boolean only_once if true this is only done once
178 * f.e. only on first focus
180 function selectContent( element, lock, only_once ) {
181 if ( only_once && only_once_elements[element.name] ) {
185 only_once_elements[element.name] = true;
195 * Displays a confirmation box before to submit a "DROP/DELETE/ALTER" query.
196 * This function is called while clicking links
198 * @param object the link
199 * @param object the sql query to submit
201 * @return boolean whether to run the query or not
203 function confirmLink(theLink, theSqlQuery)
205 // Confirmation is not required in the configuration file
206 // or browser is Opera (crappy js implementation)
207 if (PMA_messages['strDoYouReally'] == '' || typeof(window.opera) != 'undefined') {
211 var is_confirmed = confirm(PMA_messages['strDoYouReally'] + ' :\n' + theSqlQuery);
213 if ( $(theLink).hasClass('formLinkSubmit') ) {
214 var name = 'is_js_confirmed';
215 if($(theLink).attr('href').indexOf('usesubform') != -1)
216 name = 'subform[' + $(theLink).attr('href').substr('#').match(/usesubform\[(\d+)\]/i)[1] + '][is_js_confirmed]';
218 $(theLink).parents('form').append('<input type="hidden" name="' + name + '" value="1" />');
219 } else if ( typeof(theLink.href) != 'undefined' ) {
220 theLink.href += '&is_js_confirmed=1';
221 } else if ( typeof(theLink.form) != 'undefined' ) {
222 theLink.form.action += '?is_js_confirmed=1';
227 } // end of the 'confirmLink()' function
231 * Displays a confirmation box before doing some action
233 * @param object the message to display
235 * @return boolean whether to run the query or not
237 * @todo used only by libraries/display_tbl.lib.php. figure out how it is used
238 * and replace with a jQuery equivalent
240 function confirmAction(theMessage)
242 // TODO: Confirmation is not required in the configuration file
243 // or browser is Opera (crappy js implementation)
244 if (typeof(window.opera) != 'undefined') {
248 var is_confirmed = confirm(theMessage);
251 } // end of the 'confirmAction()' function
255 * Displays an error message if a "DROP DATABASE" statement is submitted
256 * while it isn't allowed, else confirms a "DROP/DELETE/ALTER" query before
257 * sumitting it if required.
258 * This function is called by the 'checkSqlQuery()' js function.
260 * @param object the form
261 * @param object the sql query textarea
263 * @return boolean whether to run the query or not
265 * @see checkSqlQuery()
267 function confirmQuery(theForm1, sqlQuery1)
269 // Confirmation is not required in the configuration file
270 if (PMA_messages['strDoYouReally'] == '') {
274 // "DROP DATABASE" statement isn't allowed
275 if (PMA_messages['strNoDropDatabases'] != '') {
276 var drop_re = new RegExp('(^|;)\\s*DROP\\s+(IF EXISTS\\s+)?DATABASE\\s', 'i');
277 if (drop_re.test(sqlQuery1.value)) {
278 alert(PMA_messages['strNoDropDatabases']);
285 // Confirms a "DROP/DELETE/ALTER/TRUNCATE" statement
287 // TODO: find a way (if possible) to use the parser-analyser
288 // for this kind of verification
289 // For now, I just added a ^ to check for the statement at
290 // beginning of expression
292 var do_confirm_re_0 = new RegExp('^\\s*DROP\\s+(IF EXISTS\\s+)?(TABLE|DATABASE|PROCEDURE)\\s', 'i');
293 var do_confirm_re_1 = new RegExp('^\\s*ALTER\\s+TABLE\\s+((`[^`]+`)|([A-Za-z0-9_$]+))\\s+DROP\\s', 'i');
294 var do_confirm_re_2 = new RegExp('^\\s*DELETE\\s+FROM\\s', 'i');
295 var do_confirm_re_3 = new RegExp('^\\s*TRUNCATE\\s', 'i');
297 if (do_confirm_re_0.test(sqlQuery1.value)
298 || do_confirm_re_1.test(sqlQuery1.value)
299 || do_confirm_re_2.test(sqlQuery1.value)
300 || do_confirm_re_3.test(sqlQuery1.value)) {
301 var message = (sqlQuery1.value.length > 100)
302 ? sqlQuery1.value.substr(0, 100) + '\n ...'
304 var is_confirmed = confirm(PMA_messages['strDoYouReally'] + ' :\n' + message);
305 // statement is confirmed -> update the
306 // "is_js_confirmed" form field so the confirm test won't be
307 // run on the server side and allows to submit the form
309 theForm1.elements['is_js_confirmed'].value = 1;
312 // statement is rejected -> do not submit the form
317 } // end if (handle confirm box result)
318 } // end if (display confirm box)
321 } // end of the 'confirmQuery()' function
325 * Displays a confirmation box before disabling the BLOB repository for a given database.
326 * This function is called while clicking links
328 * @param object the database
330 * @return boolean whether to disable the repository or not
332 function confirmDisableRepository(theDB)
334 // Confirmation is not required in the configuration file
335 // or browser is Opera (crappy js implementation)
336 if (PMA_messages['strDoYouReally'] == '' || typeof(window.opera) != 'undefined') {
340 var is_confirmed = confirm(PMA_messages['strBLOBRepositoryDisableStrongWarning'] + '\n' + PMA_messages['strBLOBRepositoryDisableAreYouSure']);
343 } // end of the 'confirmDisableBLOBRepository()' function
347 * Displays an error message if the user submitted the sql query form with no
348 * sql query, else checks for "DROP/DELETE/ALTER" statements
350 * @param object the form
352 * @return boolean always false
354 * @see confirmQuery()
356 function checkSqlQuery(theForm)
358 var sqlQuery = theForm.elements['sql_query'];
361 var space_re = new RegExp('\\s+');
362 if (typeof(theForm.elements['sql_file']) != 'undefined' &&
363 theForm.elements['sql_file'].value.replace(space_re, '') != '') {
366 if (typeof(theForm.elements['sql_localfile']) != 'undefined' &&
367 theForm.elements['sql_localfile'].value.replace(space_re, '') != '') {
370 if (isEmpty && typeof(theForm.elements['id_bookmark']) != 'undefined' &&
371 (theForm.elements['id_bookmark'].value != null || theForm.elements['id_bookmark'].value != '') &&
372 theForm.elements['id_bookmark'].selectedIndex != 0
376 // Checks for "DROP/DELETE/ALTER" statements
377 if (sqlQuery.value.replace(space_re, '') != '') {
378 if (confirmQuery(theForm, sqlQuery)) {
389 alert(PMA_messages['strFormEmpty']);
395 } // end of the 'checkSqlQuery()' function
398 * Check if a form's element is empty.
399 * An element containing only spaces is also considered empty
401 * @param object the form
402 * @param string the name of the form field to put the focus on
404 * @return boolean whether the form field is empty or not
406 function emptyCheckTheField(theForm, theFieldName)
408 var theField = theForm.elements[theFieldName];
409 var space_re = new RegExp('\\s+');
410 return (theField.value.replace(space_re, '') == '') ? 1 : 0;
411 } // end of the 'emptyCheckTheField()' function
415 * Check whether a form field is empty or not
417 * @param object the form
418 * @param string the name of the form field to put the focus on
420 * @return boolean whether the form field is empty or not
422 function emptyFormElements(theForm, theFieldName)
424 var theField = theForm.elements[theFieldName];
425 var isEmpty = emptyCheckTheField(theForm, theFieldName);
429 } // end of the 'emptyFormElements()' function
433 * Ensures a value submitted in a form is numeric and is in a range
435 * @param object the form
436 * @param string the name of the form field to check
437 * @param integer the minimum authorized value
438 * @param integer the maximum authorized value
440 * @return boolean whether a valid number has been submitted or not
442 function checkFormElementInRange(theForm, theFieldName, message, min, max)
444 var theField = theForm.elements[theFieldName];
445 var val = parseInt(theField.value);
447 if (typeof(min) == 'undefined') {
450 if (typeof(max) == 'undefined') {
451 max = Number.MAX_VALUE;
457 alert(PMA_messages['strNotNumber']);
461 // It's a number but it is not between min and max
462 else if (val < min || val > max) {
464 alert(message.replace('%d', val));
468 // It's a valid number
470 theField.value = val;
474 } // end of the 'checkFormElementInRange()' function
477 function checkTableEditForm(theForm, fieldsCnt)
479 // TODO: avoid sending a message if user just wants to add a line
480 // on the form but has not completed at least one field name
482 var atLeastOneField = 0;
483 var i, elm, elm2, elm3, val, id;
485 for (i=0; i<fieldsCnt; i++)
487 id = "#field_" + i + "_2";
490 if (val == 'VARCHAR' || val == 'CHAR' || val == 'BIT' || val == 'VARBINARY' || val == 'BINARY') {
491 elm2 = $("#field_" + i + "_3");
492 val = parseInt(elm2.val());
493 elm3 = $("#field_" + i + "_1");
494 if (isNaN(val) && elm3.val() != "") {
496 alert(PMA_messages['strNotNumber']);
502 if (atLeastOneField == 0) {
503 id = "field_" + i + "_1";
504 if (!emptyCheckTheField(theForm, id)) {
509 if (atLeastOneField == 0) {
510 var theField = theForm.elements["field_0_1"];
511 alert(PMA_messages['strFormEmpty']);
516 // at least this section is under jQuery
517 if ($("input.textfield[name='table']").val() == "") {
518 alert(PMA_messages['strFormEmpty']);
519 $("input.textfield[name='table']").focus();
525 } // enf of the 'checkTableEditForm()' function
529 * Ensures the choice between 'transmit', 'zipped', 'gzipped' and 'bzipped'
530 * checkboxes is consistant
532 * @param object the form
533 * @param string a code for the action that causes this function to be run
535 * @return boolean always true
537 function checkTransmitDump(theForm, theAction)
539 var formElts = theForm.elements;
541 // 'zipped' option has been checked
542 if (theAction == 'zip' && formElts['zip'].checked) {
543 if (!formElts['asfile'].checked) {
544 theForm.elements['asfile'].checked = true;
546 if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) {
547 theForm.elements['gzip'].checked = false;
549 if (typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked) {
550 theForm.elements['bzip'].checked = false;
553 // 'gzipped' option has been checked
554 else if (theAction == 'gzip' && formElts['gzip'].checked) {
555 if (!formElts['asfile'].checked) {
556 theForm.elements['asfile'].checked = true;
558 if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
559 theForm.elements['zip'].checked = false;
561 if (typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked) {
562 theForm.elements['bzip'].checked = false;
565 // 'bzipped' option has been checked
566 else if (theAction == 'bzip' && formElts['bzip'].checked) {
567 if (!formElts['asfile'].checked) {
568 theForm.elements['asfile'].checked = true;
570 if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
571 theForm.elements['zip'].checked = false;
573 if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) {
574 theForm.elements['gzip'].checked = false;
577 // 'transmit' option has been unchecked
578 else if (theAction == 'transmit' && !formElts['asfile'].checked) {
579 if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
580 theForm.elements['zip'].checked = false;
582 if ((typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked)) {
583 theForm.elements['gzip'].checked = false;
585 if ((typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked)) {
586 theForm.elements['bzip'].checked = false;
591 } // end of the 'checkTransmitDump()' function
593 $(document).ready(function() {
595 * Row marking in horizontal mode (use "live" so that it works also for
596 * next pages reached via AJAX); a tr may have the class noclick to remove
599 $('tr.odd:not(.noclick), tr.even:not(.noclick)').live('click',function(e) {
600 // do not trigger when clicked on anchor
601 if ($(e.target).is('a, img, a *')) {
606 // make the table unselectable (to prevent default highlighting when shift+click)
607 $tr.parents('table').noSelect();
609 if (!e.shiftKey || last_clicked_row == -1) {
612 // XXX: FF fires two click events for <label> (label and checkbox), so we need to handle this differently
613 var $checkbox = $tr.find(':checkbox');
614 if ($checkbox.length) {
615 // checkbox in a row, add or remove class depending on checkbox state
616 var checked = $checkbox.attr('checked');
617 if (!$(e.target).is(':checkbox, label')) {
619 $checkbox.attr('checked', checked);
622 $tr.addClass('marked');
624 $tr.removeClass('marked');
626 last_click_checked = checked;
628 // normaln data table, just toggle class
629 $tr.toggleClass('marked');
630 last_click_checked = false;
633 // remember the last clicked row
634 last_clicked_row = last_click_checked ? $('tr.odd:not(.noclick), tr.even:not(.noclick)').index(this) : -1;
635 last_shift_clicked_row = -1;
637 // handle the shift click
640 // clear last shift click result
641 if (last_shift_clicked_row >= 0) {
642 if (last_shift_clicked_row >= last_clicked_row) {
643 start = last_clicked_row;
644 end = last_shift_clicked_row;
646 start = last_shift_clicked_row;
647 end = last_clicked_row;
649 $tr.parent().find('tr.odd:not(.noclick), tr.even:not(.noclick)')
650 .slice(start, end + 1)
651 .removeClass('marked')
653 .attr('checked', false);
656 // handle new shift click
657 var curr_row = $('tr.odd:not(.noclick), tr.even:not(.noclick)').index(this);
658 if (curr_row >= last_clicked_row) {
659 start = last_clicked_row;
663 end = last_clicked_row;
665 $tr.parent().find('tr.odd:not(.noclick), tr.even:not(.noclick)')
666 .slice(start, end + 1)
669 .attr('checked', true);
671 // remember the last shift clicked row
672 last_shift_clicked_row = curr_row;
677 * Add a date/time picker to each element that needs it
679 $('.datefield, .datetimefield').each(function() {
680 PMA_addDatepicker($(this));
685 * True if last click is to check a row.
687 var last_click_checked = false;
690 * Zero-based index of last clicked row.
691 * Used to handle the shift + click event in the code above.
693 var last_clicked_row = -1;
696 * Zero-based index of last shift clicked row.
698 var last_shift_clicked_row = -1;
701 * Row highlighting in horizontal mode (use "live"
702 * so that it works also for pages reached via AJAX)
704 /*$(document).ready(function() {
705 $('tr.odd, tr.even').live('hover',function(event) {
707 $tr.toggleClass('hover',event.type=='mouseover');
708 $tr.children().toggleClass('hover',event.type=='mouseover');
713 * This array is used to remember mark status of rows in browse mode
715 var marked_row = new Array;
718 * marks all rows and selects its first checkbox inside the given element
719 * the given element is usaly a table or a div containing the table or tables
721 * @param container DOM element
723 function markAllRows( container_id ) {
725 $("#"+container_id).find("input:checkbox:enabled").attr('checked', 'checked')
726 .parents("tr").addClass("marked");
731 * marks all rows and selects its first checkbox inside the given element
732 * the given element is usaly a table or a div containing the table or tables
734 * @param container DOM element
736 function unMarkAllRows( container_id ) {
738 $("#"+container_id).find("input:checkbox:enabled").removeAttr('checked')
739 .parents("tr").removeClass("marked");
744 * Checks/unchecks all checkbox in given conainer (f.e. a form, fieldset or div)
746 * @param string container_id the container id
747 * @param boolean state new value for checkbox (true or false)
748 * @return boolean always true
750 function setCheckboxes( container_id, state ) {
753 $("#"+container_id).find("input:checkbox").attr('checked', 'checked');
756 $("#"+container_id).find("input:checkbox").removeAttr('checked');
760 } // end of the 'setCheckboxes()' function
763 * Checks/unchecks all options of a <select> element
765 * @param string the form name
766 * @param string the element name
767 * @param boolean whether to check or to uncheck options
769 * @return boolean always true
771 function setSelectOptions(the_form, the_select, do_check)
773 $("form[name='"+ the_form +"'] select[name='"+the_select+"']").find("option").attr('selected', do_check);
775 } // end of the 'setSelectOptions()' function
778 * Sets current value for query box.
780 function setQuery(query) {
781 if (codemirror_editor) {
782 codemirror_editor.setValue(query);
784 document.sqlform.sql_query.value = query;
790 * Create quick sql statements.
793 function insertQuery(queryType) {
794 if (queryType == "clear") {
799 var myQuery = document.sqlform.sql_query;
801 var myListBox = document.sqlform.dummy;
802 var table = document.sqlform.table.value;
804 if (myListBox.options.length > 0) {
805 sql_box_locked = true;
810 for (var i=0; i < myListBox.options.length; i++) {
817 chaineAj += myListBox.options[i].value;
818 valDis += "[value-" + NbSelect + "]";
819 editDis += myListBox.options[i].value + "=[value-" + NbSelect + "]";
821 if (queryType == "selectall") {
822 query = "SELECT * FROM `" + table + "` WHERE 1";
823 } else if (queryType == "select") {
824 query = "SELECT " + chaineAj + " FROM `" + table + "` WHERE 1";
825 } else if (queryType == "insert") {
826 query = "INSERT INTO `" + table + "`(" + chaineAj + ") VALUES (" + valDis + ")";
827 } else if (queryType == "update") {
828 query = "UPDATE `" + table + "` SET " + editDis + " WHERE 1";
829 } else if(queryType == "delete") {
830 query = "DELETE FROM `" + table + "` WHERE 1";
833 sql_box_locked = false;
839 * Inserts multiple fields.
842 function insertValueQuery() {
843 var myQuery = document.sqlform.sql_query;
844 var myListBox = document.sqlform.dummy;
846 if(myListBox.options.length > 0) {
847 sql_box_locked = true;
850 for(var i=0; i<myListBox.options.length; i++) {
851 if (myListBox.options[i].selected){
855 chaineAj += myListBox.options[i].value;
859 /* CodeMirror support */
860 if (codemirror_editor) {
861 codemirror_editor.replaceSelection(chaineAj);
863 } else if (document.selection) {
865 sel = document.selection.createRange();
867 document.sqlform.insert.focus();
869 //MOZILLA/NETSCAPE support
870 else if (document.sqlform.sql_query.selectionStart || document.sqlform.sql_query.selectionStart == "0") {
871 var startPos = document.sqlform.sql_query.selectionStart;
872 var endPos = document.sqlform.sql_query.selectionEnd;
873 var chaineSql = document.sqlform.sql_query.value;
875 myQuery.value = chaineSql.substring(0, startPos) + chaineAj + chaineSql.substring(endPos, chaineSql.length);
877 myQuery.value += chaineAj;
879 sql_box_locked = false;
884 * listbox redirection
886 function goToUrl(selObj, goToLocation) {
887 eval("document.location.href = '" + goToLocation + "pos=" + selObj.options[selObj.selectedIndex].value + "'");
893 function getElement(e,f){
896 if(f.document.layers[e]) {
897 return f.document.layers[e];
899 for(W=0;W<f.document.layers.length;W++) {
900 return(getElement(e,f.document.layers[W]));
904 return document.all[e];
906 return document.getElementById(e);
910 * Refresh the WYSIWYG scratchboard after changes have been made
912 function refreshDragOption(e) {
913 var elm = $('#' + e);
914 if (elm.css('visibility') == 'visible') {
921 * Refresh/resize the WYSIWYG scratchboard
923 function refreshLayout() {
924 var elm = $('#pdflayout')
925 var orientation = $('#orientation_opt').val();
926 if($('#paper_opt').length==1){
927 var paper = $('#paper_opt').val();
931 if (orientation == 'P') {
938 elm.css('width', pdfPaperSize(paper, posa) + 'px');
939 elm.css('height', pdfPaperSize(paper, posb) + 'px');
943 * Show/hide the WYSIWYG scratchboard
945 function ToggleDragDrop(e) {
946 var elm = $('#' + e);
947 if (elm.css('visibility') == 'hidden') {
948 PDFinit(); /* Defined in pdf_pages.php */
949 elm.css('visibility', 'visible');
950 elm.css('display', 'block');
951 $('#showwysiwyg').val('1')
953 elm.css('visibility', 'hidden');
954 elm.css('display', 'none');
955 $('#showwysiwyg').val('0')
960 * PDF scratchboard: When a position is entered manually, update
961 * the fields inside the scratchboard.
963 function dragPlace(no, axis, value) {
964 var elm = $('#table_' + no);
966 elm.css('left', value + 'px');
968 elm.css('top', value + 'px');
973 * Returns paper sizes for a given format
975 function pdfPaperSize(format, axis) {
976 switch (format.toUpperCase()) {
978 if (axis == 'x') return 4767.87; else return 6740.79;
981 if (axis == 'x') return 3370.39; else return 4767.87;
984 if (axis == 'x') return 2383.94; else return 3370.39;
987 if (axis == 'x') return 1683.78; else return 2383.94;
990 if (axis == 'x') return 1190.55; else return 1683.78;
993 if (axis == 'x') return 841.89; else return 1190.55;
996 if (axis == 'x') return 595.28; else return 841.89;
999 if (axis == 'x') return 419.53; else return 595.28;
1002 if (axis == 'x') return 297.64; else return 419.53;
1005 if (axis == 'x') return 209.76; else return 297.64;
1008 if (axis == 'x') return 147.40; else return 209.76;
1011 if (axis == 'x') return 104.88; else return 147.40;
1014 if (axis == 'x') return 73.70; else return 104.88;
1017 if (axis == 'x') return 2834.65; else return 4008.19;
1020 if (axis == 'x') return 2004.09; else return 2834.65;
1023 if (axis == 'x') return 1417.32; else return 2004.09;
1026 if (axis == 'x') return 1000.63; else return 1417.32;
1029 if (axis == 'x') return 708.66; else return 1000.63;
1032 if (axis == 'x') return 498.90; else return 708.66;
1035 if (axis == 'x') return 354.33; else return 498.90;
1038 if (axis == 'x') return 249.45; else return 354.33;
1041 if (axis == 'x') return 175.75; else return 249.45;
1044 if (axis == 'x') return 124.72; else return 175.75;
1047 if (axis == 'x') return 87.87; else return 124.72;
1050 if (axis == 'x') return 2599.37; else return 3676.54;
1053 if (axis == 'x') return 1836.85; else return 2599.37;
1056 if (axis == 'x') return 1298.27; else return 1836.85;
1059 if (axis == 'x') return 918.43; else return 1298.27;
1062 if (axis == 'x') return 649.13; else return 918.43;
1065 if (axis == 'x') return 459.21; else return 649.13;
1068 if (axis == 'x') return 323.15; else return 459.21;
1071 if (axis == 'x') return 229.61; else return 323.15;
1074 if (axis == 'x') return 161.57; else return 229.61;
1077 if (axis == 'x') return 113.39; else return 161.57;
1080 if (axis == 'x') return 79.37; else return 113.39;
1083 if (axis == 'x') return 2437.80; else return 3458.27;
1086 if (axis == 'x') return 1729.13; else return 2437.80;
1089 if (axis == 'x') return 1218.90; else return 1729.13;
1092 if (axis == 'x') return 864.57; else return 1218.90;
1095 if (axis == 'x') return 609.45; else return 864.57;
1098 if (axis == 'x') return 2551.18; else return 3628.35;
1101 if (axis == 'x') return 1814.17; else return 2551.18;
1104 if (axis == 'x') return 1275.59; else return 1814.17;
1107 if (axis == 'x') return 907.09; else return 1275.59;
1110 if (axis == 'x') return 637.80; else return 907.09;
1113 if (axis == 'x') return 612.00; else return 792.00;
1116 if (axis == 'x') return 612.00; else return 1008.00;
1119 if (axis == 'x') return 521.86; else return 756.00;
1122 if (axis == 'x') return 612.00; else return 936.00;
1130 * for playing media from the BLOB repository
1133 * @param var url_params main purpose is to pass the token
1134 * @param var bs_ref BLOB repository reference
1135 * @param var m_type type of BLOB repository media
1136 * @param var w_width width of popup window
1137 * @param var w_height height of popup window
1139 function popupBSMedia(url_params, bs_ref, m_type, is_cust_type, w_width, w_height)
1141 // if width not specified, use default
1142 if (w_width == undefined)
1145 // if height not specified, use default
1146 if (w_height == undefined)
1149 // open popup window (for displaying video/playing audio)
1150 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');
1154 * popups a request for changing MIME types for files in the BLOB repository
1156 * @param var db database name
1157 * @param var table table name
1158 * @param var reference BLOB repository reference
1159 * @param var current_mime_type current MIME type associated with BLOB repository reference
1161 function requestMIMETypeChange(db, table, reference, current_mime_type)
1163 // no mime type specified, set to default (nothing)
1164 if (undefined == current_mime_type)
1165 current_mime_type = "";
1167 // prompt user for new mime type
1168 var new_mime_type = prompt("Enter custom MIME type", current_mime_type);
1170 // if new mime_type is specified and is not the same as the previous type, request for mime type change
1171 if (new_mime_type && new_mime_type != current_mime_type)
1172 changeMIMEType(db, table, reference, new_mime_type);
1176 * changes MIME types for files in the BLOB repository
1178 * @param var db database name
1179 * @param var table table name
1180 * @param var reference BLOB repository reference
1181 * @param var mime_type new MIME type to be associated with BLOB repository reference
1183 function changeMIMEType(db, table, reference, mime_type)
1185 // specify url and parameters for jQuery POST
1186 var mime_chg_url = 'bs_change_mime_type.php';
1187 var params = {bs_db: db, bs_table: table, bs_reference: reference, bs_new_mime_type: mime_type};
1190 jQuery.post(mime_chg_url, params);
1194 * Jquery Coding for inline editing SQL_QUERY
1196 $(document).ready(function(){
1197 $(".inline_edit_sql").live('click', function(){
1198 var server = $(this).prev().find("input[name='server']").val();
1199 var db = $(this).prev().find("input[name='db']").val();
1200 var table = $(this).prev().find("input[name='table']").val();
1201 var token = $(this).prev().find("input[name='token']").val();
1202 var sql_query = $(this).prev().find("input[name='sql_query']").val();
1203 var $inner_sql = $(this).parent().prev().find('.inner_sql');
1204 var old_text = $inner_sql.html();
1206 var new_content = "<textarea name=\"sql_query_edit\" id=\"sql_query_edit\">" + sql_query + "</textarea>\n";
1207 new_content += "<input type=\"button\" class=\"btnSave\" value=\"" + PMA_messages['strGo'] + "\">\n";
1208 new_content += "<input type=\"button\" class=\"btnDiscard\" value=\"" + PMA_messages['strCancel'] + "\">\n";
1209 $inner_sql.replaceWith(new_content);
1210 $(".btnSave").each(function(){
1211 $(this).click(function(){
1212 sql_query = $(this).prev().val();
1213 window.location.replace("import.php"
1214 + "?server=" + encodeURIComponent(server)
1215 + "&db=" + encodeURIComponent(db)
1216 + "&table=" + encodeURIComponent(table)
1217 + "&sql_query=" + encodeURIComponent(sql_query)
1219 + "&token=" + token);
1222 $(".btnDiscard").each(function(){
1223 $(this).click(function(){
1224 $(this).closest(".sql").html("<span class=\"syntax\"><span class=\"inner_sql\">" + old_text + "</span></span>");
1230 $('.sqlbutton').click(function(evt){
1231 insertQuery(evt.target.id);
1235 $("#export_type").change(function(){
1236 if($("#export_type").val()=='svg'){
1237 $("#show_grid_opt").attr("disabled","disabled");
1238 $("#orientation_opt").attr("disabled","disabled");
1239 $("#with_doc").attr("disabled","disabled");
1240 $("#show_table_dim_opt").removeAttr("disabled");
1241 $("#all_table_same_wide").removeAttr("disabled");
1242 $("#paper_opt").removeAttr("disabled","disabled");
1243 $("#show_color_opt").removeAttr("disabled","disabled");
1244 //$(this).css("background-color","yellow");
1245 }else if($("#export_type").val()=='dia'){
1246 $("#show_grid_opt").attr("disabled","disabled");
1247 $("#with_doc").attr("disabled","disabled");
1248 $("#show_table_dim_opt").attr("disabled","disabled");
1249 $("#all_table_same_wide").attr("disabled","disabled");
1250 $("#paper_opt").removeAttr("disabled","disabled");
1251 $("#show_color_opt").removeAttr("disabled","disabled");
1252 $("#orientation_opt").removeAttr("disabled","disabled");
1253 }else if($("#export_type").val()=='eps'){
1254 $("#show_grid_opt").attr("disabled","disabled");
1255 $("#orientation_opt").removeAttr("disabled");
1256 $("#with_doc").attr("disabled","disabled");
1257 $("#show_table_dim_opt").attr("disabled","disabled");
1258 $("#all_table_same_wide").attr("disabled","disabled");
1259 $("#paper_opt").attr("disabled","disabled");
1260 $("#show_color_opt").attr("disabled","disabled");
1262 }else if($("#export_type").val()=='pdf'){
1263 $("#show_grid_opt").removeAttr("disabled");
1264 $("#orientation_opt").removeAttr("disabled");
1265 $("#with_doc").removeAttr("disabled","disabled");
1266 $("#show_table_dim_opt").removeAttr("disabled","disabled");
1267 $("#all_table_same_wide").removeAttr("disabled","disabled");
1268 $("#paper_opt").removeAttr("disabled","disabled");
1269 $("#show_color_opt").removeAttr("disabled","disabled");
1275 $('#sqlquery').focus().keydown(function (e) {
1276 if (e.ctrlKey && e.keyCode == 13) {
1277 $("#sqlqueryform").submit();
1281 if ($('#input_username')) {
1282 if ($('#input_username').val() == '') {
1283 $('#input_username').focus();
1285 $('#input_password').focus();
1291 * Show a message on the top of the page for an Ajax request
1293 * @param var message string containing the message to be shown.
1294 * optional, defaults to 'Loading...'
1295 * @param var timeout number of milliseconds for the message to be visible
1296 * optional, defaults to 5000
1297 * @return jQuery object jQuery Element that holds the message div
1299 function PMA_ajaxShowMessage(message, timeout) {
1301 //Handle the case when a empty data.message is passed. We don't want the empty message
1302 if (message == '') {
1304 } else if (! message) {
1305 // If the message is undefined, show the default
1306 message = PMA_messages['strLoading'];
1310 * @var timeout Number of milliseconds for which the message will be visible
1317 // Create a parent element for the AJAX messages, if necessary
1318 if ($('#loading_parent').length == 0) {
1319 $('<div id="loading_parent"></div>')
1320 .insertBefore("#serverinfo");
1323 // Update message count to create distinct message elements every time
1324 ajax_message_count++;
1326 // Remove all old messages, if any
1327 $(".ajax_notification[id^=ajax_message_num]").remove();
1330 * @var $retval a jQuery object containing the reference
1331 * to the created AJAX message
1333 var $retval = $('<span class="ajax_notification" id="ajax_message_num_' + ajax_message_count + '"></span>')
1335 .appendTo("#loading_parent")
1339 .fadeOut('medium', function() {
1347 * Removes the message shown for an Ajax operation when it's completed
1349 function PMA_ajaxRemoveMessage($this_msgbox) {
1350 if ($this_msgbox != undefined && $this_msgbox instanceof jQuery) {
1358 * Hides/shows the "Open in ENUM/SET editor" message, depending on the data type of the column currently selected
1360 function PMA_showNoticeForEnum(selectElement) {
1361 var enum_notice_id = selectElement.attr("id").split("_")[1];
1362 enum_notice_id += "_" + (parseInt(selectElement.attr("id").split("_")[2]) + 1);
1363 var selectedType = selectElement.attr("value");
1364 if (selectedType == "ENUM" || selectedType == "SET") {
1365 $("p[id='enum_notice_" + enum_notice_id + "']").show();
1367 $("p[id='enum_notice_" + enum_notice_id + "']").hide();
1372 * Generates a dialog box to pop up the create_table form
1374 function PMA_createTableDialog( div, url , target) {
1376 * @var button_options Object that stores the options passed to jQueryUI
1379 var button_options = {};
1380 // in the following function we need to use $(this)
1381 button_options[PMA_messages['strCancel']] = function() {$(this).parent().dialog('close').remove();}
1383 var button_options_error = {};
1384 button_options_error[PMA_messages['strOK']] = function() {$(this).parent().dialog('close').remove();}
1386 var $msgbox = PMA_ajaxShowMessage();
1388 $.get( target , url , function(data) {
1389 //in the case of an error, show the error message returned.
1390 if (data.success != undefined && data.success == false) {
1394 title: PMA_messages['strCreateTable'],
1397 open: PMA_verifyTypeOfAllColumns,
1398 buttons : button_options_error
1399 })// end dialog options
1400 //remove the redundant [Back] link in the error message.
1401 .find('fieldset').remove();
1406 title: PMA_messages['strCreateTable'],
1409 open: PMA_verifyTypeOfAllColumns,
1410 buttons : button_options
1411 }); // end dialog options
1413 PMA_ajaxRemoveMessage($msgbox);
1419 * Creates a highcharts chart in the given container
1421 * @param var settings object with highcharts properties that should be applied. (See also http://www.highcharts.com/ref/)
1422 * requires at least settings.chart.renderTo and settings.series to be set.
1423 * In addition there may be an additional property object 'realtime' that allows for realtime charting:
1425 * url: adress to get the data from (will always add token, ajax_request=1 and chart_data=1 to the GET request)
1426 * type: the GET request will also add type=[value of the type property] to the request
1427 * callback: Callback function that should draw the point, it's called with 4 parameters in this order:
1428 * - the chart object
1429 * - the current response value of the GET request, JSON parsed
1430 * - the previous response value of the GET request, JSON parsed
1431 * - the number of added points
1432 * error: Callback function when the get request fails. TODO: Apply callback on timeouts aswell
1435 * @return object The created highcharts instance
1437 function PMA_createChart(passedSettings) {
1438 var container = passedSettings.chart.renderTo;
1444 backgroundColor: 'none',
1446 /* Live charting support */
1448 var thisChart = this;
1449 var lastValue = null, curValue = null;
1450 var numLoadedPoints = 0, otherSum = 0;
1453 // No realtime updates for graphs that are being exported, and disabled when realtime is not set
1454 // Also don't do live charting if we don't have the server time
1455 if(thisChart.options.chart.forExport == true ||
1456 ! thisChart.options.realtime ||
1457 ! thisChart.options.realtime.callback ||
1458 ! server_time_diff) return;
1460 thisChart.options.realtime.timeoutCallBack = function() {
1461 thisChart.options.realtime.postRequest = $.post(
1462 thisChart.options.realtime.url,
1463 thisChart.options.realtime.postData,
1466 curValue = jQuery.parseJSON(data);
1468 if(thisChart.options.realtime.error)
1469 thisChart.options.realtime.error(err);
1473 if(lastValue==null) diff = curValue.x - thisChart.xAxis[0].getExtremes().max;
1474 else diff = parseInt(curValue.x - lastValue.x);
1476 thisChart.xAxis[0].setExtremes(
1477 thisChart.xAxis[0].getExtremes().min+diff,
1478 thisChart.xAxis[0].getExtremes().max+diff,
1482 thisChart.options.realtime.callback(thisChart,curValue,lastValue,numLoadedPoints);
1484 lastValue = curValue;
1487 // Timeout has been cleared => don't start a new timeout
1488 if(chart_activeTimeouts[container] == null) return;
1490 chart_activeTimeouts[container] = setTimeout(
1491 thisChart.options.realtime.timeoutCallBack,
1492 thisChart.options.realtime.refreshRate
1497 chart_activeTimeouts[container] = setTimeout(thisChart.options.realtime.timeoutCallBack, 5);
1517 text: PMA_messages['strTotalCount']
1526 formatter: function() {
1527 return '<b>' + this.series.name +'</b><br/>' +
1528 Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) + '<br/>' +
1529 Highcharts.numberFormat(this.y, 2);
1538 /* Set/Get realtime chart default values */
1539 if(passedSettings.realtime) {
1540 if(!passedSettings.realtime.refreshRate)
1541 passedSettings.realtime.refreshRate = 5000;
1543 if(!passedSettings.realtime.numMaxPoints)
1544 passedSettings.realtime.numMaxPoints = 30;
1546 // Allow custom POST vars to be added
1547 passedSettings.realtime.postData = $.extend(false,{ ajax_request: true, chart_data: 1, type: passedSettings.realtime.type },passedSettings.realtime.postData);
1549 if(server_time_diff) {
1550 settings.xAxis.min = new Date().getTime() - server_time_diff - passedSettings.realtime.numMaxPoints * passedSettings.realtime.refreshRate;
1551 settings.xAxis.max = new Date().getTime() - server_time_diff + passedSettings.realtime.refreshRate;
1555 // Overwrite/Merge default settings with passedsettings
1556 $.extend(true,settings,passedSettings);
1558 return new Highcharts.Chart(settings);
1563 * Creates a Profiling Chart. Used in sql.php and server_status.js
1565 function PMA_createProfilingChart(data, options) {
1566 return PMA_createChart($.extend(true, {
1568 renderTo: 'profilingchart',
1571 title: { text:'', margin:0 },
1574 name: PMA_messages['strQueryExecutionTime'],
1579 allowPointSelect: true,
1584 formatter: function() {
1585 return '<b>'+ this.point.name +'</b><br/>'+ Highcharts.numberFormat(this.percentage, 2) +' %';
1591 formatter: function() {
1592 return '<b>'+ this.point.name +'</b><br/>'+PMA_prettyProfilingNum(this.y)+'<br/>('+Highcharts.numberFormat(this.percentage, 2) +' %)';
1598 // Formats a profiling duration nicely. Used in PMA_createProfilingChart() and server_status.js
1599 function PMA_prettyProfilingNum(num, acc) {
1601 acc = Math.pow(10,acc);
1602 if(num*1000 < 0.1) num = Math.round(acc*(num*1000*1000))/acc + 'µ'
1603 else if(num < 0.1) num = Math.round(acc*(num*1000))/acc + 'm'
1609 * jQuery function that uses jQueryUI's dialogs to confirm with user. Does not
1610 * return a jQuery object yet and hence cannot be chained
1612 * @param string question
1613 * @param string url URL to be passed to the callbackFn to make
1615 * @param function callbackFn callback to execute after user clicks on OK
1618 jQuery.fn.PMA_confirm = function(question, url, callbackFn) {
1619 if (PMA_messages['strDoYouReally'] == '') {
1624 * @var button_options Object that stores the options passed to jQueryUI
1627 var button_options = {};
1628 button_options[PMA_messages['strOK']] = function(){
1629 $(this).dialog("close").remove();
1631 if($.isFunction(callbackFn)) {
1632 callbackFn.call(this, url);
1635 button_options[PMA_messages['strCancel']] = function() {$(this).dialog("close").remove();}
1637 $('<div id="confirm_dialog"></div>')
1639 .dialog({buttons: button_options});
1643 * jQuery function to sort a table's body after a new row has been appended to it.
1644 * Also fixes the even/odd classes of the table rows at the end.
1646 * @param string text_selector string to select the sortKey's text
1648 * @return jQuery Object for chaining purposes
1650 jQuery.fn.PMA_sort_table = function(text_selector) {
1651 return this.each(function() {
1654 * @var table_body Object referring to the table's <tbody> element
1656 var table_body = $(this);
1658 * @var rows Object referring to the collection of rows in {@link table_body}
1660 var rows = $(this).find('tr').get();
1662 //get the text of the field that we will sort by
1663 $.each(rows, function(index, row) {
1664 row.sortKey = $.trim($(row).find(text_selector).text().toLowerCase());
1667 //get the sorted order
1668 rows.sort(function(a,b) {
1669 if(a.sortKey < b.sortKey) {
1672 if(a.sortKey > b.sortKey) {
1678 //pull out each row from the table and then append it according to it's order
1679 $.each(rows, function(index, row) {
1680 $(table_body).append(row);
1684 //Re-check the classes of each row
1685 $(this).find('tr:odd')
1686 .removeClass('even').addClass('odd')
1689 .removeClass('odd').addClass('even');
1694 * jQuery coding for 'Create Table'. Used on db_operations.php,
1695 * db_structure.php and db_tracking.php (i.e., wherever
1696 * libraries/display_create_table.lib.php is used)
1698 * Attach Ajax Event handlers for Create Table
1700 $(document).ready(function() {
1703 * Attach event handler to the submit action of the create table minimal form
1704 * and retrieve the full table form and display it in a dialog
1706 * @uses PMA_ajaxShowMessage()
1708 $("#create_table_form_minimal.ajax").live('submit', function(event) {
1709 event.preventDefault();
1711 PMA_prepareForAjaxRequest($form);
1713 /*variables which stores the common attributes*/
1714 var url = $form.serialize();
1715 var action = $form.attr('action');
1716 var div = $('<div id="create_table_dialog"></div>');
1718 /*Calling to the createTableDialog function*/
1719 PMA_createTableDialog(div, url, action);
1721 // empty table name and number of columns from the minimal form
1722 $form.find('input[name=table],input[name=num_fields]').val('');
1726 * Attach event handler for submission of create table form (save)
1728 * @uses PMA_ajaxShowMessage()
1729 * @uses $.PMA_sort_table()
1732 // .live() must be called after a selector, see http://api.jquery.com/live
1733 $("#create_table_form input[name=do_save_data]").live('click', function(event) {
1734 event.preventDefault();
1737 * @var the_form object referring to the create table form
1739 var $form = $("#create_table_form");
1742 * First validate the form; if there is a problem, avoid submitting it
1744 * checkTableEditForm() needs a pure element and not a jQuery object,
1745 * this is why we pass $form[0] as a parameter (the jQuery object
1746 * is actually an array of DOM elements)
1749 if (checkTableEditForm($form[0], $form.find('input[name=orig_num_fields]').val())) {
1750 // OK, form passed validation step
1751 if ($form.hasClass('ajax')) {
1752 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
1753 PMA_prepareForAjaxRequest($form);
1754 //User wants to submit the form
1755 $.post($form.attr('action'), $form.serialize() + "&do_save_data=" + $(this).val(), function(data) {
1756 if(data.success == true) {
1757 $('#properties_message')
1758 .removeClass('error')
1760 PMA_ajaxShowMessage(data.message);
1761 // Only if the create table dialog (distinct panel) exists
1762 if ($("#create_table_dialog").length > 0) {
1763 $("#create_table_dialog").dialog("close").remove();
1767 * @var tables_table Object referring to the <tbody> element that holds the list of tables
1769 var tables_table = $("#tablesForm").find("tbody").not("#tbl_summary_row");
1770 // this is the first table created in this db
1771 if (tables_table.length == 0) {
1772 if (window.parent && window.parent.frame_content) {
1773 window.parent.frame_content.location.reload();
1777 * @var curr_last_row Object referring to the last <tr> element in {@link tables_table}
1779 var curr_last_row = $(tables_table).find('tr:last');
1781 * @var curr_last_row_index_string String containing the index of {@link curr_last_row}
1783 var curr_last_row_index_string = $(curr_last_row).find('input:checkbox').attr('id').match(/\d+/)[0];
1785 * @var curr_last_row_index Index of {@link curr_last_row}
1787 var curr_last_row_index = parseFloat(curr_last_row_index_string);
1789 * @var new_last_row_index Index of the new row to be appended to {@link tables_table}
1791 var new_last_row_index = curr_last_row_index + 1;
1793 * @var new_last_row_id String containing the id of the row to be appended to {@link tables_table}
1795 var new_last_row_id = 'checkbox_tbl_' + new_last_row_index;
1797 data.new_table_string = data.new_table_string.replace(/checkbox_tbl_/, new_last_row_id);
1799 $(data.new_table_string)
1800 .appendTo(tables_table);
1803 $(tables_table).PMA_sort_table('th');
1806 //Refresh navigation frame as a new table has been added
1807 if (window.parent && window.parent.frame_navigation) {
1808 window.parent.frame_navigation.location.reload();
1811 $('#properties_message')
1814 // scroll to the div containing the error message
1815 $('#properties_message')[0].scrollIntoView();
1818 } // end if ($form.hasClass('ajax')
1821 $form.append('<input type="hidden" name="do_save_data" value="save" />');
1824 } // end if (checkTableEditForm() )
1825 }) // end create table form (save)
1828 * Attach event handler for create table form (add fields)
1830 * @uses PMA_ajaxShowMessage()
1831 * @uses $.PMA_sort_table()
1832 * @uses window.parent.refreshNavigation()
1835 // .live() must be called after a selector, see http://api.jquery.com/live
1836 $("#create_table_form.ajax input[name=submit_num_fields]").live('click', function(event) {
1837 event.preventDefault();
1840 * @var the_form object referring to the create table form
1842 var $form = $("#create_table_form");
1844 var $msgbox = PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
1845 PMA_prepareForAjaxRequest($form);
1847 //User wants to add more fields to the table
1848 $.post($form.attr('action'), $form.serialize() + "&submit_num_fields=" + $(this).val(), function(data) {
1849 // if 'create_table_dialog' exists
1850 if ($("#create_table_dialog").length > 0) {
1851 $("#create_table_dialog").html(data);
1853 // if 'create_table_div' exists
1854 if ($("#create_table_div").length > 0) {
1855 $("#create_table_div").html(data);
1857 PMA_verifyTypeOfAllColumns();
1858 PMA_ajaxRemoveMessage($msgbox);
1861 }) // end create table form (add fields)
1863 }, 'top.frame_content'); //end $(document).ready for 'Create Table'
1866 * jQuery coding for 'Change Table' and 'Add Column'. Used on tbl_structure.php *
1867 * Attach Ajax Event handlers for Change Table
1869 $(document).ready(function() {
1871 *Ajax action for submitting the "Column Change" and "Add Column" form
1873 $("#append_fields_form input[name=do_save_data]").live('click', function(event) {
1874 event.preventDefault();
1876 * @var the_form object referring to the export form
1878 var $form = $("#append_fields_form");
1881 * First validate the form; if there is a problem, avoid submitting it
1883 * checkTableEditForm() needs a pure element and not a jQuery object,
1884 * this is why we pass $form[0] as a parameter (the jQuery object
1885 * is actually an array of DOM elements)
1887 if (checkTableEditForm($form[0], $form.find('input[name=orig_num_fields]').val())) {
1888 // OK, form passed validation step
1889 if ($form.hasClass('ajax')) {
1890 PMA_prepareForAjaxRequest($form);
1891 //User wants to submit the form
1892 $.post($form.attr('action'), $form.serialize()+"&do_save_data=Save", function(data) {
1893 if ($("#sqlqueryresults").length != 0) {
1894 $("#sqlqueryresults").remove();
1895 } else if ($(".error").length != 0) {
1896 $(".error").remove();
1898 if (data.success == true) {
1899 PMA_ajaxShowMessage(data.message);
1900 $("<div id='sqlqueryresults'></div>").insertAfter("#topmenucontainer");
1901 $("#sqlqueryresults").html(data.sql_query);
1902 $("#result_query .notice").remove();
1903 $("#result_query").prepend((data.message));
1904 if ($("#change_column_dialog").length > 0) {
1905 $("#change_column_dialog").dialog("close").remove();
1906 } else if ($("#add_columns").length > 0) {
1907 $("#add_columns").dialog("close").remove();
1909 /*Reload the field form*/
1910 $.post($("#fieldsForm").attr('action'), $("#fieldsForm").serialize()+"&ajax_request=true", function(form_data) {
1911 $("#fieldsForm").remove();
1912 $("#addColumns").remove();
1913 var $temp_div = $("<div id='temp_div'><div>").append(form_data);
1914 if ($("#sqlqueryresults").length != 0) {
1915 $temp_div.find("#fieldsForm").insertAfter("#sqlqueryresults");
1917 $temp_div.find("#fieldsForm").insertAfter(".error");
1919 $temp_div.find("#addColumns").insertBefore("iframe.IE_hack");
1920 /*Call the function to display the more options in table*/
1921 displayMoreTableOpts();
1924 var $temp_div = $("<div id='temp_div'><div>").append(data);
1925 var $error = $temp_div.find(".error code").addClass("error");
1926 PMA_ajaxShowMessage($error);
1931 $form.append('<input type="hidden" name="do_save_data" value="Save" />');
1935 }) // end change table button "do_save_data"
1937 }, 'top.frame_content'); //end $(document).ready for 'Change Table'
1940 * jQuery coding for 'Table operations'. Used on tbl_operations.php
1941 * Attach Ajax Event handlers for Table operations
1943 $(document).ready(function() {
1945 *Ajax action for submitting the "Alter table order by"
1947 $("#alterTableOrderby.ajax").live('submit', function(event) {
1948 event.preventDefault();
1951 PMA_prepareForAjaxRequest($form);
1952 /*variables which stores the common attributes*/
1953 $.post($form.attr('action'), $form.serialize()+"&submitorderby=Go", function(data) {
1954 if ($("#sqlqueryresults").length != 0) {
1955 $("#sqlqueryresults").remove();
1957 if (data.success == true) {
1958 PMA_ajaxShowMessage(data.message);
1959 $("<div id='sqlqueryresults'></div>").insertAfter("#topmenucontainer");
1960 $("#sqlqueryresults").html(data.sql_query);
1961 $("#result_query .notice").remove();
1962 $("#result_query").prepend((data.message));
1964 PMA_ajaxShowMessage(data.error);
1967 });//end of alterTableOrderby ajax submit
1968 }, 'top.frame_content'); //end $(document).ready for 'Table operations'
1972 * Attach Ajax event handlers for Drop Database. Moved here from db_structure.js
1973 * as it was also required on db_create.php
1975 * @uses $.PMA_confirm()
1976 * @uses PMA_ajaxShowMessage()
1977 * @uses window.parent.refreshNavigation()
1978 * @uses window.parent.refreshMain()
1979 * @see $cfg['AjaxEnable']
1981 $(document).ready(function() {
1982 $("#drop_db_anchor").live('click', function(event) {
1983 event.preventDefault();
1985 //context is top.frame_content, so we need to use window.parent.db to access the db var
1987 * @var question String containing the question to be asked for confirmation
1989 var question = PMA_messages['strDropDatabaseStrongWarning'] + '\n' + PMA_messages['strDoYouReally'] + ' :\n' + 'DROP DATABASE ' + window.parent.db;
1991 $(this).PMA_confirm(question, $(this).attr('href') ,function(url) {
1993 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
1994 $.get(url, {'is_js_confirmed': '1', 'ajax_request': true}, function(data) {
1995 //Database deleted successfully, refresh both the frames
1996 window.parent.refreshNavigation();
1997 window.parent.refreshMain();
1999 }); // end $.PMA_confirm()
2000 }); //end of Drop Database Ajax action
2001 }) // end of $(document).ready() for Drop Database
2004 * Attach Ajax event handlers for 'Create Database'. Used wherever libraries/
2005 * display_create_database.lib.php is used, ie main.php and server_databases.php
2007 * @uses PMA_ajaxShowMessage()
2008 * @see $cfg['AjaxEnable']
2010 $(document).ready(function() {
2012 $('#create_database_form.ajax').live('submit', function(event) {
2013 event.preventDefault();
2017 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
2018 PMA_prepareForAjaxRequest($form);
2020 $.post($form.attr('action'), $form.serialize(), function(data) {
2021 if(data.success == true) {
2022 PMA_ajaxShowMessage(data.message);
2024 //Append database's row to table
2025 $("#tabledatabases")
2027 .append(data.new_db_string)
2028 .PMA_sort_table('.name')
2029 .find('#db_summary_row')
2030 .appendTo('#tabledatabases tbody')
2031 .removeClass('odd even');
2033 var $databases_count_object = $('#databases_count');
2034 var databases_count = parseInt($databases_count_object.text());
2035 $databases_count_object.text(++databases_count);
2036 //Refresh navigation frame as a new database has been added
2037 if (window.parent && window.parent.frame_navigation) {
2038 window.parent.frame_navigation.location.reload();
2042 PMA_ajaxShowMessage(data.error);
2045 }) // end $().live()
2046 }) // end $(document).ready() for Create Database
2049 * Attach Ajax event handlers for 'Change Password' on main.php
2051 $(document).ready(function() {
2054 * Attach Ajax event handler on the change password anchor
2055 * @see $cfg['AjaxEnable']
2057 $('#change_password_anchor.dialog_active').live('click',function(event) {
2058 event.preventDefault();
2061 $('#change_password_anchor.ajax').live('click', function(event) {
2062 event.preventDefault();
2063 $(this).removeClass('ajax').addClass('dialog_active');
2065 * @var button_options Object containing options to be passed to jQueryUI's dialog
2067 var button_options = {};
2068 button_options[PMA_messages['strCancel']] = function() {$(this).dialog('close').remove();}
2069 $.get($(this).attr('href'), {'ajax_request': true}, function(data) {
2070 $('<div id="change_password_dialog"></div>')
2072 title: PMA_messages['strChangePassword'],
2074 close: function(ev,ui) {$(this).remove();},
2075 buttons : button_options,
2076 beforeClose: function(ev,ui){ $('#change_password_anchor.dialog_active').removeClass('dialog_active').addClass('ajax')}
2079 displayPasswordGenerateButton();
2081 }) // end handler for change password anchor
2084 * Attach Ajax event handler for Change Password form submission
2086 * @uses PMA_ajaxShowMessage()
2087 * @see $cfg['AjaxEnable']
2089 $("#change_password_form.ajax").find('input[name=change_pw]').live('click', function(event) {
2090 event.preventDefault();
2093 * @var the_form Object referring to the change password form
2095 var the_form = $("#change_password_form");
2098 * @var this_value String containing the value of the submit button.
2099 * Need to append this for the change password form on Server Privileges
2102 var this_value = $(this).val();
2104 var $msgbox = PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
2105 $(the_form).append('<input type="hidden" name="ajax_request" value="true" />');
2107 $.post($(the_form).attr('action'), $(the_form).serialize() + '&change_pw='+ this_value, function(data) {
2108 if(data.success == true) {
2109 $("#topmenucontainer").after(data.sql_query);
2110 $("#change_password_dialog").hide().remove();
2111 $("#edit_user_dialog").dialog("close").remove();
2112 $('#change_password_anchor.dialog_active').removeClass('dialog_active').addClass('ajax');
2113 PMA_ajaxRemoveMessage($msgbox);
2116 PMA_ajaxShowMessage(data.error);
2119 }) // end handler for Change Password form submission
2120 }) // end $(document).ready() for Change Password
2123 * Toggle the hiding/showing of the "Open in ENUM/SET editor" message when
2124 * the page loads and when the selected data type changes
2126 $(document).ready(function() {
2127 // is called here for normal page loads and also when opening
2128 // the Create table dialog
2129 PMA_verifyTypeOfAllColumns();
2131 // needs live() to work also in the Create Table dialog
2132 $("select[class='column_type']").live('change', function() {
2133 PMA_showNoticeForEnum($(this));
2137 function PMA_verifyTypeOfAllColumns() {
2138 $("select[class='column_type']").each(function() {
2139 PMA_showNoticeForEnum($(this));
2144 * Closes the ENUM/SET editor and removes the data in it
2146 function disable_popup() {
2147 $("#popup_background").fadeOut("fast");
2148 $("#enum_editor").fadeOut("fast");
2149 // clear the data from the text boxes
2150 $("#enum_editor #values input").remove();
2151 $("#enum_editor input[type='hidden']").remove();
2155 * Opens the ENUM/SET editor and controls its functions
2157 $(document).ready(function() {
2158 // Needs live() to work also in the Create table dialog
2159 $("a[class='open_enum_editor']").live('click', function() {
2161 var windowWidth = document.documentElement.clientWidth;
2162 var windowHeight = document.documentElement.clientHeight;
2163 var popupWidth = windowWidth/2;
2164 var popupHeight = windowHeight*0.8;
2165 var popupOffsetTop = windowHeight/2 - popupHeight/2;
2166 var popupOffsetLeft = windowWidth/2 - popupWidth/2;
2167 $("#enum_editor").css({"position":"absolute", "top": popupOffsetTop, "left": popupOffsetLeft, "width": popupWidth, "height": popupHeight});
2170 $("#popup_background").css({"opacity":"0.7"});
2171 $("#popup_background").fadeIn("fast");
2172 $("#enum_editor").fadeIn("fast");
2173 /**Replacing the column name in the enum editor header*/
2174 var column_name = $("#append_fields_form").find("input[id=field_0_1]").attr("value");
2175 var h3_text = $("#enum_editor h3").html();
2176 $("#enum_editor h3").html(h3_text.split('"')[0]+'"'+column_name+'"');
2179 var values = $(this).parent().prev("input").attr("value").split(",");
2180 $.each(values, function(index, val) {
2181 if(jQuery.trim(val) != "") {
2182 // enclose the string in single quotes if it's not already
2183 if(val.substr(0, 1) != "'") {
2186 if(val.substr(val.length-1, val.length) != "'") {
2189 // escape the single quotes, except the mandatory ones enclosing the entire string
2190 val = val.substr(1, val.length-2).replace(/''/g, "'").replace(/\\\\/g, '\\').replace(/\\'/g, "'").replace(/'/g, "'");
2191 // escape the greater-than symbol
2192 val = val.replace(/>/g, ">");
2193 $("#enum_editor #values").append("<input type='text' value=" + val + " />");
2196 // So we know which column's data is being edited
2197 $("#enum_editor").append("<input type='hidden' value='" + $(this).parent().prev("input").attr("id") + "' />");
2201 // If the "close" link is clicked, close the enum editor
2202 // Needs live() to work also in the Create table dialog
2203 $("a[class='close_enum_editor']").live('click', function() {
2207 // If the "cancel" link is clicked, close the enum editor
2208 // Needs live() to work also in the Create table dialog
2209 $("a[class='cancel_enum_editor']").live('click', function() {
2213 // When "add a new value" is clicked, append an empty text field
2214 // Needs live() to work also in the Create table dialog
2215 $("a[class='add_value']").live('click', function() {
2216 $("#enum_editor #values").append("<input type='text' />");
2219 // When the submit button is clicked, put the data back into the original form
2220 // Needs live() to work also in the Create table dialog
2221 $("#enum_editor input[type='submit']").live('click', function() {
2222 var value_array = new Array();
2223 $.each($("#enum_editor #values input"), function(index, input_element) {
2224 val = jQuery.trim(input_element.value);
2226 value_array.push("'" + val.replace(/\\/g, '\\\\').replace(/'/g, "''") + "'");
2229 // get the Length/Values text field where this value belongs
2230 var values_id = $("#enum_editor input[type='hidden']").attr("value");
2231 $("input[id='" + values_id + "']").attr("value", value_array.join(","));
2236 * Hides certain table structure actions, replacing them with the word "More". They are displayed
2237 * in a dropdown menu when the user hovers over the word "More."
2239 displayMoreTableOpts();
2242 function displayMoreTableOpts() {
2243 // Remove the actions from the table cells (they are available by default for JavaScript-disabled browsers)
2244 // if the table is not a view or information_schema (otherwise there is only one action to hide and there's no point)
2245 if($("input[type='hidden'][name='table_type']").val() == "table") {
2246 var $table = $("table[id='tablestructure']");
2247 $table.find("td[class='browse']").remove();
2248 $table.find("td[class='primary']").remove();
2249 $table.find("td[class='unique']").remove();
2250 $table.find("td[class='index']").remove();
2251 $table.find("td[class='fulltext']").remove();
2252 $table.find("td[class='spatial']").remove();
2253 $table.find("th[class='action']").attr("colspan", 3);
2255 // Display the "more" text
2256 $table.find("td[class='more_opts']").show();
2258 // Position the dropdown
2259 $(".structure_actions_dropdown").each(function() {
2260 // Optimize DOM querying
2261 var $this_dropdown = $(this);
2262 // The top offset must be set for IE even if it didn't change
2263 var cell_right_edge_offset = $this_dropdown.parent().position().left + $this_dropdown.parent().innerWidth();
2264 var left_offset = cell_right_edge_offset - $this_dropdown.innerWidth();
2265 var top_offset = $this_dropdown.parent().position().top + $this_dropdown.parent().innerHeight();
2266 $this_dropdown.offset({ top: top_offset, left: left_offset });
2269 // A hack for IE6 to prevent the after_field select element from being displayed on top of the dropdown by
2270 // positioning an iframe directly on top of it
2271 var $after_field = $("select[name='after_field']");
2272 $("iframe[class='IE_hack']")
2273 .width($after_field.width())
2274 .height($after_field.height())
2276 top: $after_field.offset().top,
2277 left: $after_field.offset().left
2280 // When "more" is hovered over, show the hidden actions
2281 $table.find("td[class='more_opts']")
2282 .mouseenter(function() {
2283 if($.browser.msie && $.browser.version == "6.0") {
2284 $("iframe[class='IE_hack']")
2286 .width($after_field.width()+4)
2287 .height($after_field.height()+4)
2289 top: $after_field.offset().top,
2290 left: $after_field.offset().left
2293 $(".structure_actions_dropdown").hide(); // Hide all the other ones that may be open
2294 $(this).children(".structure_actions_dropdown").show();
2295 // Need to do this again for IE otherwise the offset is wrong
2296 if($.browser.msie) {
2297 var left_offset_IE = $(this).offset().left + $(this).innerWidth() - $(this).children(".structure_actions_dropdown").innerWidth();
2298 var top_offset_IE = $(this).offset().top + $(this).innerHeight();
2299 $(this).children(".structure_actions_dropdown").offset({
2301 left: left_offset_IE });
2304 .mouseleave(function() {
2305 $(this).children(".structure_actions_dropdown").hide();
2306 if($.browser.msie && $.browser.version == "6.0") {
2307 $("iframe[class='IE_hack']").hide();
2313 $(document).ready(function(){
2314 PMA_convertFootnotesToTooltips();
2318 * Ensures indexes names are valid according to their type and, for a primary
2319 * key, lock index name to 'PRIMARY'
2320 * @param string form_id Variable which parses the form name as
2322 * @return boolean false if there is no index form, true else
2324 function checkIndexName(form_id)
2326 if ($("#"+form_id).length == 0) {
2330 // Gets the elements pointers
2331 var $the_idx_name = $("#input_index_name");
2332 var $the_idx_type = $("#select_index_type");
2334 // Index is a primary key
2335 if ($the_idx_type.find("option:selected").attr("value") == 'PRIMARY') {
2336 $the_idx_name.attr("value", 'PRIMARY');
2337 $the_idx_name.attr("disabled", true);
2342 if ($the_idx_name.attr("value") == 'PRIMARY') {
2343 $the_idx_name.attr("value", '');
2345 $the_idx_name.attr("disabled", false);
2349 } // end of the 'checkIndexName()' function
2352 * function to convert the footnotes to tooltips
2354 * @param jquery-Object $div a div jquery object which specifies the
2355 * domain for searching footnootes. If we
2356 * ommit this parameter the function searches
2357 * the footnotes in the whole body
2359 function PMA_convertFootnotesToTooltips($div) {
2360 // Hide the footnotes from the footer (which are displayed for
2361 // JavaScript-disabled browsers) since the tooltip is sufficient
2363 if ($div == undefined || ! $div instanceof jQuery || $div.length == 0) {
2364 $div = $("#serverinfo").parent();
2367 $footnotes = $div.find(".footnotes");
2370 $footnotes.find('span').each(function() {
2371 $(this).children("sup").remove();
2373 // The border and padding must be removed otherwise a thin yellow box remains visible
2374 $footnotes.css("border", "none");
2375 $footnotes.css("padding", "0px");
2377 // Replace the superscripts with the help icon
2378 $div.find("sup.footnotemarker").hide();
2379 $div.find("img.footnotemarker").show();
2381 $div.find("img.footnotemarker").each(function() {
2382 var img_class = $(this).attr("class");
2383 /** img contains two classes, as example "footnotemarker footnote_1".
2384 * We split it by second class and take it for the id of span
2386 img_class = img_class.split(" ");
2387 for (i = 0; i < img_class.length; i++) {
2388 if (img_class[i].split("_")[0] == "footnote") {
2389 var span_id = img_class[i].split("_")[1];
2393 * Now we get the #id of the span with span_id variable. As an example if we
2394 * initially get the img class as "footnotemarker footnote_2", now we get
2395 * #2 as the span_id. Using that we can find footnote_2 in footnotes.
2397 var tooltip_text = $footnotes.find("span[id='footnote_" + span_id + "']").html();
2399 content: tooltip_text,
2401 hide: { delay: 1000 },
2402 style: { background: '#ffffcc' }
2407 function menuResize()
2409 var cnt = $('#topmenu');
2410 var wmax = cnt.innerWidth() - 5; // 5 px margin for jumping menu in Chrome
2411 var submenu = cnt.find('.submenu');
2412 var submenu_w = submenu.outerWidth(true);
2413 var submenu_ul = submenu.find('ul');
2414 var li = cnt.find('> li');
2415 var li2 = submenu_ul.find('li');
2416 var more_shown = li2.length > 0;
2417 var w = more_shown ? submenu_w : 0;
2421 for (var i = 0; i < li.length-1; i++) { // li.length-1: skip .submenu element
2423 var el_width = el.outerWidth(true);
2424 el.data('width', el_width);
2428 if (w + submenu_w < wmax) {
2432 w -= $(li[i-1]).data('width');
2438 if (hide_start > 0) {
2439 for (var i = hide_start; i < li.length-1; i++) {
2440 $(li[i])[more_shown ? 'prependTo' : 'appendTo'](submenu_ul);
2442 submenu.addClass('shown');
2443 } else if (more_shown) {
2445 // nothing hidden, maybe something can be restored
2446 for (var i = 0; i < li2.length; i++) {
2447 //console.log(li2[i], submenu_w);
2448 w += $(li2[i]).data('width');
2449 // item fits or (it is the last item and it would fit if More got removed)
2450 if (w+submenu_w < wmax || (i == li2.length-1 && w < wmax)) {
2451 $(li2[i]).insertBefore(submenu);
2452 if (i == li2.length-1) {
2453 submenu.removeClass('shown');
2460 if (submenu.find('.tabactive').length) {
2461 submenu.addClass('active').find('> a').removeClass('tab').addClass('tabactive');
2463 submenu.removeClass('active').find('> a').addClass('tab').removeClass('tabactive');
2468 var topmenu = $('#topmenu');
2469 if (topmenu.length == 0) {
2472 // create submenu container
2473 var link = $('<a />', {href: '#', 'class': 'tab'})
2474 .text(PMA_messages['strMore'])
2475 .click(function(e) {
2478 var img = topmenu.find('li:first-child img');
2480 img.clone().attr('class', 'icon ic_b_more').prependTo(link);
2482 var submenu = $('<li />', {'class': 'submenu'})
2484 .append($('<ul />'))
2485 .mouseenter(function() {
2486 if ($(this).find('ul .tabactive').length == 0) {
2487 $(this).addClass('submenuhover').find('> a').addClass('tabactive');
2490 .mouseleave(function() {
2491 if ($(this).find('ul .tabactive').length == 0) {
2492 $(this).removeClass('submenuhover').find('> a').removeClass('tabactive');
2495 topmenu.append(submenu);
2497 // populate submenu and register resize event
2498 $(window).resize(menuResize);
2503 * Get the row number from the classlist (for example, row_1)
2505 function PMA_getRowNumber(classlist) {
2506 return parseInt(classlist.split(/\s+row_/)[1]);
2510 * Changes status of slider
2512 function PMA_set_status_label(id) {
2513 if ($('#' + id).css('display') == 'none') {
2514 $('#anchor_status_' + id).text('+ ');
2516 $('#anchor_status_' + id).text('- ');
2521 * Initializes slider effect.
2523 function PMA_init_slider() {
2524 $('.pma_auto_slider').each(function(idx, e) {
2525 if ($(e).hasClass('slider_init_done')) return;
2526 $(e).addClass('slider_init_done');
2527 $('<span id="anchor_status_' + e.id + '"></span>')
2529 PMA_set_status_label(e.id);
2531 $('<a href="#' + e.id + '" id="anchor_' + e.id + '">' + e.title + '</a>')
2534 $('#' + e.id).toggle('clip', function() {
2535 PMA_set_status_label(e.id);
2543 * var toggleButton This is a function that creates a toggle
2544 * sliding button given a jQuery reference
2545 * to the correct DOM element
2547 var toggleButton = function ($obj) {
2548 // In rtl mode the toggle switch is flipped horizontally
2549 // so we need to take that into account
2550 if ($('.text_direction', $obj).text() == 'ltr') {
2551 var right = 'right';
2556 * var h Height of the button, used to scale the
2557 * background image and position the layers
2559 var h = $obj.height();
2560 $('img', $obj).height(h);
2561 $('table', $obj).css('bottom', h-1);
2563 * var on Width of the "ON" part of the toggle switch
2564 * var off Width of the "OFF" part of the toggle switch
2566 var on = $('.toggleOn', $obj).width();
2567 var off = $('.toggleOff', $obj).width();
2568 // Make the "ON" and "OFF" parts of the switch the same size
2569 $('.toggleOn > div', $obj).width(Math.max(on, off));
2570 $('.toggleOff > div', $obj).width(Math.max(on, off));
2572 * var w Width of the central part of the switch
2574 var w = parseInt(($('img', $obj).height() / 16) * 22, 10);
2575 // Resize the central part of the switch on the top
2576 // layer to match the background
2577 $('table td:nth-child(2) > div', $obj).width(w);
2579 * var imgw Width of the background image
2580 * var tblw Width of the foreground layer
2581 * var offset By how many pixels to move the background
2582 * image, so that it matches the top layer
2584 var imgw = $('img', $obj).width();
2585 var tblw = $('table', $obj).width();
2586 var offset = parseInt(((imgw - tblw) / 2), 10);
2587 // Move the background to match the layout of the top layer
2588 $obj.find('img').css(right, offset);
2590 * var offw Outer width of the "ON" part of the toggle switch
2591 * var btnw Outer width of the central part of the switch
2593 var offw = $('.toggleOff', $obj).outerWidth();
2594 var btnw = $('table td:nth-child(2)', $obj).outerWidth();
2595 // Resize the main div so that exactly one side of
2596 // the switch plus the central part fit into it.
2597 $obj.width(offw + btnw + 2);
2599 * var move How many pixels to move the
2600 * switch by when toggling
2602 var move = $('.toggleOff', $obj).outerWidth();
2603 // If the switch is initialized to the
2604 // OFF state we need to move it now.
2605 if ($('.container', $obj).hasClass('off')) {
2606 if (right == 'right') {
2607 $('table, img', $obj).animate({'left': '-=' + move + 'px'}, 0);
2609 $('table, img', $obj).animate({'left': '+=' + move + 'px'}, 0);
2612 // Attach an 'onclick' event to the switch
2613 $('.container', $obj).click(function () {
2614 if ($(this).hasClass('isActive')) {
2617 $(this).addClass('isActive');
2619 var $msg = PMA_ajaxShowMessage(PMA_messages['strLoading']);
2620 var $container = $(this);
2621 var callback = $('.callback', this).text();
2622 // Perform the actual toggle
2623 if ($(this).hasClass('on')) {
2624 if (right == 'right') {
2625 var operator = '-=';
2627 var operator = '+=';
2629 var url = $(this).find('.toggleOff > span').text();
2630 var removeClass = 'on';
2631 var addClass = 'off';
2633 if (right == 'right') {
2634 var operator = '+=';
2636 var operator = '-=';
2638 var url = $(this).find('.toggleOn > span').text();
2639 var removeClass = 'off';
2640 var addClass = 'on';
2642 $.post(url, {'ajax_request': true}, function(data) {
2643 if(data.success == true) {
2644 PMA_ajaxRemoveMessage($msg);
2646 .removeClass(removeClass)
2648 .animate({'left': operator + move + 'px'}, function () {
2649 $container.removeClass('isActive');
2653 PMA_ajaxShowMessage(data.error);
2654 $container.removeClass('isActive');
2661 * Initialise all toggle buttons
2663 $(window).load(function () {
2664 $('.toggleAjax').each(function () {
2667 .find('.toggleButton')
2668 toggleButton($(this));
2675 $(document).ready(function() {
2676 $('.vpointer').live('hover',
2679 var $this_td = $(this);
2680 var row_num = PMA_getRowNumber($this_td.attr('class'));
2681 // for all td of the same vertical row, toggle hover
2682 $('.vpointer').filter('.row_' + row_num).toggleClass('hover');
2685 }) // end of $(document).ready() for vertical pointer
2687 $(document).ready(function() {
2691 $('.vmarker').live('click', function(e) {
2692 // do not trigger when clicked on anchor
2693 if ($(e.target).is('a, img, a *')) {
2697 var $this_td = $(this);
2698 var row_num = PMA_getRowNumber($this_td.attr('class'));
2700 // XXX: FF fires two click events for <label> (label and checkbox), so we need to handle this differently
2702 var $checkbox = $('.vmarker').filter('.row_' + row_num + ':first').find(':checkbox');
2703 if ($checkbox.length) {
2704 // checkbox in a row, add or remove class depending on checkbox state
2705 var checked = $checkbox.attr('checked');
2706 if (!$(e.target).is(':checkbox, label')) {
2708 $checkbox.attr('checked', checked);
2710 // for all td of the same vertical row, toggle the marked class
2712 $('.vmarker').filter('.row_' + row_num).addClass('marked');
2714 $('.vmarker').filter('.row_' + row_num).removeClass('marked');
2717 // normaln data table, just toggle class
2718 $('.vmarker').filter('.row_' + row_num).toggleClass('marked');
2723 * Reveal visual builder anchor
2726 $('#visual_builder_anchor').show();
2729 * Page selector in db Structure (non-AJAX)
2731 $('#tableslistcontainer').find('#pageselector').live('change', function() {
2732 $(this).parent("form").submit();
2736 * Page selector in navi panel (non-AJAX)
2738 $('#navidbpageselector').find('#pageselector').live('change', function() {
2739 $(this).parent("form").submit();
2743 * Page selector in browse_foreigners windows (non-AJAX)
2745 $('#body_browse_foreigners').find('#pageselector').live('change', function() {
2746 $(this).closest("form").submit();
2750 * Load version information asynchronously.
2752 if ($('.jsversioncheck').length > 0) {
2754 var s = document.createElement('script');
2755 s.type = 'text/javascript';
2757 s.src = 'http://www.phpmyadmin.net/home_page/version.js';
2758 s.onload = PMA_current_version;
2759 var x = document.getElementsByTagName('script')[0];
2760 x.parentNode.insertBefore(s, x);
2770 * Enables the text generated by PMA_linkOrButton() to be clickable
2772 $('a[class~="formLinkSubmit"]').live('click',function(e) {
2774 if($(this).attr('href').indexOf('=') != -1) {
2775 var data = $(this).attr('href').substr($(this).attr('href').indexOf('#')+1).split('=',2);
2776 $(this).parents('form').append('<input type="hidden" name="' + data[0] + '" value="' + data[1] + '"/>');
2778 $(this).parents('form').submit();
2782 $('#update_recent_tables').ready(function() {
2783 if (window.parent.frame_navigation != undefined
2784 && window.parent.frame_navigation.PMA_reloadRecentTable != undefined)
2786 window.parent.frame_navigation.PMA_reloadRecentTable();
2790 }) // end of $(document).ready()
2793 * Creates a message inside an object with a sliding effect
2795 * @param msg A string containing the text to display
2796 * @param $obj a jQuery object containing the reference
2797 * to the element where to put the message
2798 * This is optional, if no element is
2799 * provided, one will be created below the
2800 * navigation links at the top of the page
2802 * @return bool True on success, false on failure
2804 function PMA_slidingMessage(msg, $obj) {
2805 if (msg == undefined || msg.length == 0) {
2806 // Don't show an empty message
2809 if ($obj == undefined || ! $obj instanceof jQuery || $obj.length == 0) {
2810 // If the second argument was not supplied,
2811 // we might have to create a new DOM node.
2812 if ($('#PMA_slidingMessage').length == 0) {
2813 $('#topmenucontainer')
2814 .after('<span id="PMA_slidingMessage" '
2815 + 'style="display: inline-block;"></span>');
2817 $obj = $('#PMA_slidingMessage');
2819 if ($obj.has('div').length > 0) {
2820 // If there already is a message inside the
2821 // target object, we must get rid of it
2825 .fadeOut(function () {
2830 .append('<div style="display: none;">' + msg + '</div>')
2832 height: $obj.find('div').first().height()
2839 // Object does not already have a message
2840 // inside it, so we simply slide it down
2843 .html('<div style="display: none;">' + msg + '</div>')
2855 // Set the height of the parent
2856 // to the height of the child
2867 } // end PMA_slidingMessage()
2870 * Attach Ajax event handlers for Drop Table.
2872 * @uses $.PMA_confirm()
2873 * @uses PMA_ajaxShowMessage()
2874 * @uses window.parent.refreshNavigation()
2875 * @uses window.parent.refreshMain()
2876 * @see $cfg['AjaxEnable']
2878 $(document).ready(function() {
2879 $("#drop_tbl_anchor").live('click', function(event) {
2880 event.preventDefault();
2882 //context is top.frame_content, so we need to use window.parent.db to access the db var
2884 * @var question String containing the question to be asked for confirmation
2886 var question = PMA_messages['strDropTableStrongWarning'] + '\n' + PMA_messages['strDoYouReally'] + ' :\n' + 'DROP TABLE ' + window.parent.table;
2888 $(this).PMA_confirm(question, $(this).attr('href') ,function(url) {
2890 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
2891 $.get(url, {'is_js_confirmed': '1', 'ajax_request': true}, function(data) {
2892 //Database deleted successfully, refresh both the frames
2893 window.parent.refreshNavigation();
2894 window.parent.refreshMain();
2896 }); // end $.PMA_confirm()
2897 }); //end of Drop Table Ajax action
2898 }) // end of $(document).ready() for Drop Table
2901 * Attach Ajax event handlers for Truncate Table.
2903 * @uses $.PMA_confirm()
2904 * @uses PMA_ajaxShowMessage()
2905 * @uses window.parent.refreshNavigation()
2906 * @uses window.parent.refreshMain()
2907 * @see $cfg['AjaxEnable']
2909 $(document).ready(function() {
2910 $("#truncate_tbl_anchor").live('click', function(event) {
2911 event.preventDefault();
2913 //context is top.frame_content, so we need to use window.parent.db to access the db var
2915 * @var question String containing the question to be asked for confirmation
2917 var question = PMA_messages['strTruncateTableStrongWarning'] + '\n' + PMA_messages['strDoYouReally'] + ' :\n' + 'TRUNCATE TABLE ' + window.parent.table;
2919 $(this).PMA_confirm(question, $(this).attr('href') ,function(url) {
2921 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
2922 $.get(url, {'is_js_confirmed': '1', 'ajax_request': true}, function(data) {
2923 //Database deleted successfully, refresh both the frames
2924 window.parent.refreshNavigation();
2925 window.parent.refreshMain();
2927 }); // end $.PMA_confirm()
2928 }); //end of Drop Table Ajax action
2929 }) // end of $(document).ready() for Drop Table
2932 * Attach CodeMirror2 editor to SQL edit area.
2934 $(document).ready(function() {
2935 var elm = $('#sqlquery');
2936 if (elm.length > 0) {
2937 codemirror_editor = CodeMirror.fromTextArea(elm[0], {lineNumbers: true, matchBrackets: true, indentUnit: 4, mode: "text/x-mysql"});
2942 * jQuery plugin to cancel selection in HTML code.
2945 $.fn.noSelect = function (p) { //no select plugin by Paulo P.Marinas
2946 var prevent = (p == null) ? true : p;
2948 return this.each(function () {
2949 if ($.browser.msie || $.browser.safari) $(this).bind('selectstart', function () {
2952 else if ($.browser.mozilla) {
2953 $(this).css('MozUserSelect', 'none');
2954 $('body').trigger('focus');
2955 } else if ($.browser.opera) $(this).bind('mousedown', function () {
2958 else $(this).attr('unselectable', 'on');
2961 return this.each(function () {
2962 if ($.browser.msie || $.browser.safari) $(this).unbind('selectstart');
2963 else if ($.browser.mozilla) $(this).css('MozUserSelect', 'inherit');
2964 else if ($.browser.opera) $(this).unbind('mousedown');
2965 else $(this).removeAttr('unselectable', 'on');
2972 * Create default PMA tooltip for the element specified. The default appearance
2973 * can be overriden by specifying optional "options" parameter (see qTip options).
2975 function PMA_createqTip($elements, content, options) {
2989 corner: { target: 'rightMiddle', tooltip: 'leftMiddle' },
3007 $elements.qtip($.extend(true, o, options));