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 * Version string to integer conversion.
50 function parseVersionString (str) {
51 if (typeof(str) != 'string') { return false; }
53 // Parse possible alpha/beta/rc/
54 var state = str.split('-');
55 if (state.length >= 2) {
56 if (state[1].substr(0, 2) == 'rc') {
57 add = - 20 - parseInt(state[1].substr(2));
58 } else if (state[1].substr(0, 4) == 'beta') {
59 add = - 40 - parseInt(state[1].substr(4));
60 } else if (state[1].substr(0, 5) == 'alpha') {
61 add = - 60 - parseInt(state[1].substr(5));
62 } else if (state[1].substr(0, 3) == 'dev') {
63 /* We don't handle dev, it's git snapshot */
68 var x = str.split('.');
69 // Use 0 for non existing parts
70 var maj = parseInt(x[0]) || 0;
71 var min = parseInt(x[1]) || 0;
72 var pat = parseInt(x[2]) || 0;
73 var hotfix = parseInt(x[3]) || 0;
74 return maj * 100000000 + min * 1000000 + pat * 10000 + hotfix * 100 + add;
78 * Indicates current available version on main page.
80 function PMA_current_version() {
81 var current = parseVersionString('3.4.0'/*pmaversion*/);
82 var latest = parseVersionString(PMA_latest_version);
83 $('#li_pma_version').append(PMA_messages['strLatestAvailable'] + ' ' + PMA_latest_version);
84 if (latest > current) {
85 var message = $.sprintf(PMA_messages['strNewerVersion'], PMA_latest_version, PMA_latest_date);
86 if (Math.floor(latest / 10000) == Math.floor(current / 10000)) {
92 $('#maincontainer').after('<div class="' + klass + '">' + message + '</div>');
97 * for libraries/display_change_password.lib.php
98 * libraries/user_password.php
102 function displayPasswordGenerateButton() {
103 $('#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>');
104 $('#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>');
108 * Adds a date/time picker to an element
110 * @param object $this_element a jQuery object pointing to the element
112 function PMA_addDatepicker($this_element) {
113 var showTimeOption = false;
114 if ($this_element.is('.datetimefield')) {
115 showTimeOption = true;
121 buttonImage: themeCalendarImage, // defined in js/messages.php
122 buttonImageOnly: true,
127 showTime: showTimeOption,
128 dateFormat: 'yy-mm-dd', // yy means year with four digits
130 beforeShow: function(input, inst) {
131 // Remember that we came from the datepicker; this is used
132 // in tbl_change.js by verificationsAfterFieldChange()
133 $this_element.data('comes_from', 'datepicker');
135 constrainInput: false
140 * selects the content of a given object, f.e. a textarea
142 * @param object element element of which the content will be selected
143 * @param var lock variable which holds the lock for this element
144 * or true, if no lock exists
145 * @param boolean only_once if true this is only done once
146 * f.e. only on first focus
148 function selectContent( element, lock, only_once ) {
149 if ( only_once && only_once_elements[element.name] ) {
153 only_once_elements[element.name] = true;
163 * Displays a confirmation box before to submit a "DROP/DELETE/ALTER" query.
164 * This function is called while clicking links
166 * @param object the link
167 * @param object the sql query to submit
169 * @return boolean whether to run the query or not
171 function confirmLink(theLink, theSqlQuery)
173 // Confirmation is not required in the configuration file
174 // or browser is Opera (crappy js implementation)
175 if (PMA_messages['strDoYouReally'] == '' || typeof(window.opera) != 'undefined') {
179 var is_confirmed = confirm(PMA_messages['strDoYouReally'] + ' :\n' + theSqlQuery);
181 if ( typeof(theLink.href) != 'undefined' ) {
182 theLink.href += '&is_js_confirmed=1';
183 } else if ( typeof(theLink.form) != 'undefined' ) {
184 theLink.form.action += '?is_js_confirmed=1';
189 } // end of the 'confirmLink()' function
193 * Displays a confirmation box before doing some action
195 * @param object the message to display
197 * @return boolean whether to run the query or not
199 * @todo used only by libraries/display_tbl.lib.php. figure out how it is used
200 * and replace with a jQuery equivalent
202 function confirmAction(theMessage)
204 // TODO: Confirmation is not required in the configuration file
205 // or browser is Opera (crappy js implementation)
206 if (typeof(window.opera) != 'undefined') {
210 var is_confirmed = confirm(theMessage);
213 } // end of the 'confirmAction()' function
217 * Displays an error message if a "DROP DATABASE" statement is submitted
218 * while it isn't allowed, else confirms a "DROP/DELETE/ALTER" query before
219 * sumitting it if required.
220 * This function is called by the 'checkSqlQuery()' js function.
222 * @param object the form
223 * @param object the sql query textarea
225 * @return boolean whether to run the query or not
227 * @see checkSqlQuery()
229 function confirmQuery(theForm1, sqlQuery1)
231 // Confirmation is not required in the configuration file
232 if (PMA_messages['strDoYouReally'] == '') {
236 // The replace function (js1.2) isn't supported
237 else if (typeof(sqlQuery1.value.replace) == 'undefined') {
241 // js1.2+ -> validation with regular expressions
243 // "DROP DATABASE" statement isn't allowed
244 if (PMA_messages['strNoDropDatabases'] != '') {
245 var drop_re = new RegExp('(^|;)\\s*DROP\\s+(IF EXISTS\\s+)?DATABASE\\s', 'i');
246 if (drop_re.test(sqlQuery1.value)) {
247 alert(PMA_messages['strNoDropDatabases']);
254 // Confirms a "DROP/DELETE/ALTER/TRUNCATE" statement
256 // TODO: find a way (if possible) to use the parser-analyser
257 // for this kind of verification
258 // For now, I just added a ^ to check for the statement at
259 // beginning of expression
261 var do_confirm_re_0 = new RegExp('^\\s*DROP\\s+(IF EXISTS\\s+)?(TABLE|DATABASE|PROCEDURE)\\s', 'i');
262 var do_confirm_re_1 = new RegExp('^\\s*ALTER\\s+TABLE\\s+((`[^`]+`)|([A-Za-z0-9_$]+))\\s+DROP\\s', 'i');
263 var do_confirm_re_2 = new RegExp('^\\s*DELETE\\s+FROM\\s', 'i');
264 var do_confirm_re_3 = new RegExp('^\\s*TRUNCATE\\s', 'i');
266 if (do_confirm_re_0.test(sqlQuery1.value)
267 || do_confirm_re_1.test(sqlQuery1.value)
268 || do_confirm_re_2.test(sqlQuery1.value)
269 || do_confirm_re_3.test(sqlQuery1.value)) {
270 var message = (sqlQuery1.value.length > 100)
271 ? sqlQuery1.value.substr(0, 100) + '\n ...'
273 var is_confirmed = confirm(PMA_messages['strDoYouReally'] + ' :\n' + message);
274 // statement is confirmed -> update the
275 // "is_js_confirmed" form field so the confirm test won't be
276 // run on the server side and allows to submit the form
278 theForm1.elements['is_js_confirmed'].value = 1;
281 // statement is rejected -> do not submit the form
286 } // end if (handle confirm box result)
287 } // end if (display confirm box)
288 } // end confirmation stuff
291 } // end of the 'confirmQuery()' function
295 * Displays a confirmation box before disabling the BLOB repository for a given database.
296 * This function is called while clicking links
298 * @param object the database
300 * @return boolean whether to disable the repository or not
302 function confirmDisableRepository(theDB)
304 // Confirmation is not required in the configuration file
305 // or browser is Opera (crappy js implementation)
306 if (PMA_messages['strDoYouReally'] == '' || typeof(window.opera) != 'undefined') {
310 var is_confirmed = confirm(PMA_messages['strBLOBRepositoryDisableStrongWarning'] + '\n' + PMA_messages['strBLOBRepositoryDisableAreYouSure']);
313 } // end of the 'confirmDisableBLOBRepository()' function
317 * Displays an error message if the user submitted the sql query form with no
318 * sql query, else checks for "DROP/DELETE/ALTER" statements
320 * @param object the form
322 * @return boolean always false
324 * @see confirmQuery()
326 function checkSqlQuery(theForm)
328 var sqlQuery = theForm.elements['sql_query'];
331 // The replace function (js1.2) isn't supported -> basic tests
332 if (typeof(sqlQuery.value.replace) == 'undefined') {
333 isEmpty = (sqlQuery.value == '') ? 1 : 0;
334 if (isEmpty && typeof(theForm.elements['sql_file']) != 'undefined') {
335 isEmpty = (theForm.elements['sql_file'].value == '') ? 1 : 0;
337 if (isEmpty && typeof(theForm.elements['sql_localfile']) != 'undefined') {
338 isEmpty = (theForm.elements['sql_localfile'].value == '') ? 1 : 0;
340 if (isEmpty && typeof(theForm.elements['id_bookmark']) != 'undefined') {
341 isEmpty = (theForm.elements['id_bookmark'].value == null || theForm.elements['id_bookmark'].value == '');
344 // js1.2+ -> validation with regular expressions
346 var space_re = new RegExp('\\s+');
347 if (typeof(theForm.elements['sql_file']) != 'undefined' &&
348 theForm.elements['sql_file'].value.replace(space_re, '') != '') {
351 if (typeof(theForm.elements['sql_localfile']) != 'undefined' &&
352 theForm.elements['sql_localfile'].value.replace(space_re, '') != '') {
355 if (isEmpty && typeof(theForm.elements['id_bookmark']) != 'undefined' &&
356 (theForm.elements['id_bookmark'].value != null || theForm.elements['id_bookmark'].value != '') &&
357 theForm.elements['id_bookmark'].selectedIndex != 0
361 // Checks for "DROP/DELETE/ALTER" statements
362 if (sqlQuery.value.replace(space_re, '') != '') {
363 if (confirmQuery(theForm, sqlQuery)) {
375 alert(PMA_messages['strFormEmpty']);
381 } // end of the 'checkSqlQuery()' function
384 * Check if a form's element is empty.
385 * An element containing only spaces is also considered empty
387 * @param object the form
388 * @param string the name of the form field to put the focus on
390 * @return boolean whether the form field is empty or not
392 function emptyCheckTheField(theForm, theFieldName)
395 var theField = theForm.elements[theFieldName];
396 // Whether the replace function (js1.2) is supported or not
397 var isRegExp = (typeof(theField.value.replace) != 'undefined');
400 isEmpty = (theField.value == '') ? 1 : 0;
402 var space_re = new RegExp('\\s+');
403 isEmpty = (theField.value.replace(space_re, '') == '') ? 1 : 0;
407 } // end of the 'emptyCheckTheField()' function
411 * Check whether a form field is empty or not
413 * @param object the form
414 * @param string the name of the form field to put the focus on
416 * @return boolean whether the form field is empty or not
418 function emptyFormElements(theForm, theFieldName)
420 var theField = theForm.elements[theFieldName];
421 var isEmpty = emptyCheckTheField(theForm, theFieldName);
425 } // end of the 'emptyFormElements()' function
429 * Ensures a value submitted in a form is numeric and is in a range
431 * @param object the form
432 * @param string the name of the form field to check
433 * @param integer the minimum authorized value
434 * @param integer the maximum authorized value
436 * @return boolean whether a valid number has been submitted or not
438 function checkFormElementInRange(theForm, theFieldName, message, min, max)
440 var theField = theForm.elements[theFieldName];
441 var val = parseInt(theField.value);
443 if (typeof(min) == 'undefined') {
446 if (typeof(max) == 'undefined') {
447 max = Number.MAX_VALUE;
453 alert(PMA_messages['strNotNumber']);
457 // It's a number but it is not between min and max
458 else if (val < min || val > max) {
460 alert(message.replace('%d', val));
464 // It's a valid number
466 theField.value = val;
470 } // end of the 'checkFormElementInRange()' function
473 function checkTableEditForm(theForm, fieldsCnt)
475 // TODO: avoid sending a message if user just wants to add a line
476 // on the form but has not completed at least one field name
478 var atLeastOneField = 0;
479 var i, elm, elm2, elm3, val, id;
481 for (i=0; i<fieldsCnt; i++)
483 id = "#field_" + i + "_2";
486 if (val == 'VARCHAR' || val == 'CHAR' || val == 'BIT' || val == 'VARBINARY' || val == 'BINARY') {
487 elm2 = $("#field_" + i + "_3");
488 val = parseInt(elm2.val());
489 elm3 = $("#field_" + i + "_1");
490 if (isNaN(val) && elm3.val() != "") {
492 alert(PMA_messages['strNotNumber']);
498 if (atLeastOneField == 0) {
499 id = "field_" + i + "_1";
500 if (!emptyCheckTheField(theForm, id)) {
505 if (atLeastOneField == 0) {
506 var theField = theForm.elements["field_0_1"];
507 alert(PMA_messages['strFormEmpty']);
512 // at least this section is under jQuery
513 if ($("input.textfield[name='table']").val() == "") {
514 alert(PMA_messages['strFormEmpty']);
515 $("input.textfield[name='table']").focus();
521 } // enf of the 'checkTableEditForm()' function
525 * Ensures the choice between 'transmit', 'zipped', 'gzipped' and 'bzipped'
526 * checkboxes is consistant
528 * @param object the form
529 * @param string a code for the action that causes this function to be run
531 * @return boolean always true
533 function checkTransmitDump(theForm, theAction)
535 var formElts = theForm.elements;
537 // 'zipped' option has been checked
538 if (theAction == 'zip' && formElts['zip'].checked) {
539 if (!formElts['asfile'].checked) {
540 theForm.elements['asfile'].checked = true;
542 if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) {
543 theForm.elements['gzip'].checked = false;
545 if (typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked) {
546 theForm.elements['bzip'].checked = false;
549 // 'gzipped' option has been checked
550 else if (theAction == 'gzip' && formElts['gzip'].checked) {
551 if (!formElts['asfile'].checked) {
552 theForm.elements['asfile'].checked = true;
554 if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
555 theForm.elements['zip'].checked = false;
557 if (typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked) {
558 theForm.elements['bzip'].checked = false;
561 // 'bzipped' option has been checked
562 else if (theAction == 'bzip' && formElts['bzip'].checked) {
563 if (!formElts['asfile'].checked) {
564 theForm.elements['asfile'].checked = true;
566 if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
567 theForm.elements['zip'].checked = false;
569 if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) {
570 theForm.elements['gzip'].checked = false;
573 // 'transmit' option has been unchecked
574 else if (theAction == 'transmit' && !formElts['asfile'].checked) {
575 if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
576 theForm.elements['zip'].checked = false;
578 if ((typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked)) {
579 theForm.elements['gzip'].checked = false;
581 if ((typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked)) {
582 theForm.elements['bzip'].checked = false;
587 } // end of the 'checkTransmitDump()' function
589 $(document).ready(function() {
591 * Row marking in horizontal mode (use "live" so that it works also for
592 * next pages reached via AJAX); a tr may have the class noclick to remove
595 $('tr.odd:not(.noclick), tr.even:not(.noclick)').live('click',function(e) {
596 // do not trigger when clicked on anchor
597 if ($(e.target).is('a, a *')) {
600 // XXX: FF fires two click events for <label> (label and checkbox), so we need to handle this differently
602 var $checkbox = $tr.find(':checkbox');
603 if ($checkbox.length) {
604 // checkbox in a row, add or remove class depending on checkbox state
605 var checked = $checkbox.attr('checked');
606 if (!$(e.target).is(':checkbox, label')) {
608 $checkbox.attr('checked', checked);
611 $tr.addClass('marked');
613 $tr.removeClass('marked');
616 // normaln data table, just toggle class
617 $tr.toggleClass('marked');
622 * Add a date/time picker to each element that needs it
624 $('.datefield, .datetimefield').each(function() {
625 PMA_addDatepicker($(this));
630 * Row highlighting in horizontal mode (use "live"
631 * so that it works also for pages reached via AJAX)
633 $(document).ready(function() {
634 $('tr.odd, tr.even').live('hover',function() {
636 $tr.toggleClass('hover');
637 $tr.children().toggleClass('hover');
642 * This array is used to remember mark status of rows in browse mode
644 var marked_row = new Array;
647 * marks all rows and selects its first checkbox inside the given element
648 * the given element is usaly a table or a div containing the table or tables
650 * @param container DOM element
652 function markAllRows( container_id ) {
654 $("#"+container_id).find("input:checkbox:enabled").attr('checked', 'checked')
655 .parents("tr").addClass("marked");
660 * marks all rows and selects its first checkbox inside the given element
661 * the given element is usaly a table or a div containing the table or tables
663 * @param container DOM element
665 function unMarkAllRows( container_id ) {
667 $("#"+container_id).find("input:checkbox:enabled").removeAttr('checked')
668 .parents("tr").removeClass("marked");
673 * Checks/unchecks all checkbox in given conainer (f.e. a form, fieldset or div)
675 * @param string container_id the container id
676 * @param boolean state new value for checkbox (true or false)
677 * @return boolean always true
679 function setCheckboxes( container_id, state ) {
682 $("#"+container_id).find("input:checkbox").attr('checked', 'checked');
685 $("#"+container_id).find("input:checkbox").removeAttr('checked');
689 } // end of the 'setCheckboxes()' function
692 * Checks/unchecks all options of a <select> element
694 * @param string the form name
695 * @param string the element name
696 * @param boolean whether to check or to uncheck the element
698 * @return boolean always true
700 function setSelectOptions(the_form, the_select, do_check)
704 $("form[name='"+ the_form +"']").find("select[name='"+the_select+"']").find("option").attr('selected', 'selected');
707 $("form[name='"+ the_form +"']").find("select[name="+the_select+"]").find("option").removeAttr('selected');
710 } // end of the 'setSelectOptions()' function
714 * Create quick sql statements.
717 function insertQuery(queryType) {
718 var myQuery = document.sqlform.sql_query;
719 var myListBox = document.sqlform.dummy;
721 var table = document.sqlform.table.value;
723 if (myListBox.options.length > 0) {
724 sql_box_locked = true;
729 for (var i=0; i < myListBox.options.length; i++) {
736 chaineAj += myListBox.options[i].value;
737 valDis += "[value-" + NbSelect + "]";
738 editDis += myListBox.options[i].value + "=[value-" + NbSelect + "]";
740 if (queryType == "selectall") {
741 query = "SELECT * FROM `" + table + "` WHERE 1";
742 } else if (queryType == "select") {
743 query = "SELECT " + chaineAj + " FROM `" + table + "` WHERE 1";
744 } else if (queryType == "insert") {
745 query = "INSERT INTO `" + table + "`(" + chaineAj + ") VALUES (" + valDis + ")";
746 } else if (queryType == "update") {
747 query = "UPDATE `" + table + "` SET " + editDis + " WHERE 1";
748 } else if(queryType == "delete") {
749 query = "DELETE FROM `" + table + "` WHERE 1";
750 } else if(queryType == "clear") {
753 document.sqlform.sql_query.value = query;
754 sql_box_locked = false;
760 * Inserts multiple fields.
763 function insertValueQuery() {
764 var myQuery = document.sqlform.sql_query;
765 var myListBox = document.sqlform.dummy;
767 if(myListBox.options.length > 0) {
768 sql_box_locked = true;
771 for(var i=0; i<myListBox.options.length; i++) {
772 if (myListBox.options[i].selected){
776 chaineAj += myListBox.options[i].value;
781 if (document.selection) {
783 sel = document.selection.createRange();
785 document.sqlform.insert.focus();
787 //MOZILLA/NETSCAPE support
788 else if (document.sqlform.sql_query.selectionStart || document.sqlform.sql_query.selectionStart == "0") {
789 var startPos = document.sqlform.sql_query.selectionStart;
790 var endPos = document.sqlform.sql_query.selectionEnd;
791 var chaineSql = document.sqlform.sql_query.value;
793 myQuery.value = chaineSql.substring(0, startPos) + chaineAj + chaineSql.substring(endPos, chaineSql.length);
795 myQuery.value += chaineAj;
797 sql_box_locked = false;
802 * listbox redirection
804 function goToUrl(selObj, goToLocation) {
805 eval("document.location.href = '" + goToLocation + "pos=" + selObj.options[selObj.selectedIndex].value + "'");
811 function getElement(e,f){
814 if(f.document.layers[e]) {
815 return f.document.layers[e];
817 for(W=0;W<f.document.layers.length;W++) {
818 return(getElement(e,f.document.layers[W]));
822 return document.all[e];
824 return document.getElementById(e);
828 * Refresh the WYSIWYG scratchboard after changes have been made
830 function refreshDragOption(e) {
831 var elm = $('#' + e);
832 if (elm.css('visibility') == 'visible') {
839 * Refresh/resize the WYSIWYG scratchboard
841 function refreshLayout() {
842 var elm = $('#pdflayout')
843 var orientation = $('#orientation_opt').val();
844 if($('#paper_opt').length==1){
845 var paper = $('#paper_opt').val();
849 if (orientation == 'P') {
856 elm.css('width', pdfPaperSize(paper, posa) + 'px');
857 elm.css('height', pdfPaperSize(paper, posb) + 'px');
861 * Show/hide the WYSIWYG scratchboard
863 function ToggleDragDrop(e) {
864 var elm = $('#' + e);
865 if (elm.css('visibility') == 'hidden') {
866 PDFinit(); /* Defined in pdf_pages.php */
867 elm.css('visibility', 'visible');
868 elm.css('display', 'block');
869 $('#showwysiwyg').val('1')
871 elm.css('visibility', 'hidden');
872 elm.css('display', 'none');
873 $('#showwysiwyg').val('0')
878 * PDF scratchboard: When a position is entered manually, update
879 * the fields inside the scratchboard.
881 function dragPlace(no, axis, value) {
882 var elm = $('#table_' + no);
884 elm.css('left', value + 'px');
886 elm.css('top', value + 'px');
891 * Returns paper sizes for a given format
893 function pdfPaperSize(format, axis) {
894 switch (format.toUpperCase()) {
896 if (axis == 'x') return 4767.87; else return 6740.79;
899 if (axis == 'x') return 3370.39; else return 4767.87;
902 if (axis == 'x') return 2383.94; else return 3370.39;
905 if (axis == 'x') return 1683.78; else return 2383.94;
908 if (axis == 'x') return 1190.55; else return 1683.78;
911 if (axis == 'x') return 841.89; else return 1190.55;
914 if (axis == 'x') return 595.28; else return 841.89;
917 if (axis == 'x') return 419.53; else return 595.28;
920 if (axis == 'x') return 297.64; else return 419.53;
923 if (axis == 'x') return 209.76; else return 297.64;
926 if (axis == 'x') return 147.40; else return 209.76;
929 if (axis == 'x') return 104.88; else return 147.40;
932 if (axis == 'x') return 73.70; else return 104.88;
935 if (axis == 'x') return 2834.65; else return 4008.19;
938 if (axis == 'x') return 2004.09; else return 2834.65;
941 if (axis == 'x') return 1417.32; else return 2004.09;
944 if (axis == 'x') return 1000.63; else return 1417.32;
947 if (axis == 'x') return 708.66; else return 1000.63;
950 if (axis == 'x') return 498.90; else return 708.66;
953 if (axis == 'x') return 354.33; else return 498.90;
956 if (axis == 'x') return 249.45; else return 354.33;
959 if (axis == 'x') return 175.75; else return 249.45;
962 if (axis == 'x') return 124.72; else return 175.75;
965 if (axis == 'x') return 87.87; else return 124.72;
968 if (axis == 'x') return 2599.37; else return 3676.54;
971 if (axis == 'x') return 1836.85; else return 2599.37;
974 if (axis == 'x') return 1298.27; else return 1836.85;
977 if (axis == 'x') return 918.43; else return 1298.27;
980 if (axis == 'x') return 649.13; else return 918.43;
983 if (axis == 'x') return 459.21; else return 649.13;
986 if (axis == 'x') return 323.15; else return 459.21;
989 if (axis == 'x') return 229.61; else return 323.15;
992 if (axis == 'x') return 161.57; else return 229.61;
995 if (axis == 'x') return 113.39; else return 161.57;
998 if (axis == 'x') return 79.37; else return 113.39;
1001 if (axis == 'x') return 2437.80; else return 3458.27;
1004 if (axis == 'x') return 1729.13; else return 2437.80;
1007 if (axis == 'x') return 1218.90; else return 1729.13;
1010 if (axis == 'x') return 864.57; else return 1218.90;
1013 if (axis == 'x') return 609.45; else return 864.57;
1016 if (axis == 'x') return 2551.18; else return 3628.35;
1019 if (axis == 'x') return 1814.17; else return 2551.18;
1022 if (axis == 'x') return 1275.59; else return 1814.17;
1025 if (axis == 'x') return 907.09; else return 1275.59;
1028 if (axis == 'x') return 637.80; else return 907.09;
1031 if (axis == 'x') return 612.00; else return 792.00;
1034 if (axis == 'x') return 612.00; else return 1008.00;
1037 if (axis == 'x') return 521.86; else return 756.00;
1040 if (axis == 'x') return 612.00; else return 936.00;
1048 * for playing media from the BLOB repository
1051 * @param var url_params main purpose is to pass the token
1052 * @param var bs_ref BLOB repository reference
1053 * @param var m_type type of BLOB repository media
1054 * @param var w_width width of popup window
1055 * @param var w_height height of popup window
1057 function popupBSMedia(url_params, bs_ref, m_type, is_cust_type, w_width, w_height)
1059 // if width not specified, use default
1060 if (w_width == undefined)
1063 // if height not specified, use default
1064 if (w_height == undefined)
1067 // open popup window (for displaying video/playing audio)
1068 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');
1072 * popups a request for changing MIME types for files in the BLOB repository
1074 * @param var db database name
1075 * @param var table table name
1076 * @param var reference BLOB repository reference
1077 * @param var current_mime_type current MIME type associated with BLOB repository reference
1079 function requestMIMETypeChange(db, table, reference, current_mime_type)
1081 // no mime type specified, set to default (nothing)
1082 if (undefined == current_mime_type)
1083 current_mime_type = "";
1085 // prompt user for new mime type
1086 var new_mime_type = prompt("Enter custom MIME type", current_mime_type);
1088 // if new mime_type is specified and is not the same as the previous type, request for mime type change
1089 if (new_mime_type && new_mime_type != current_mime_type)
1090 changeMIMEType(db, table, reference, new_mime_type);
1094 * changes MIME types for files in the BLOB repository
1096 * @param var db database name
1097 * @param var table table name
1098 * @param var reference BLOB repository reference
1099 * @param var mime_type new MIME type to be associated with BLOB repository reference
1101 function changeMIMEType(db, table, reference, mime_type)
1103 // specify url and parameters for jQuery POST
1104 var mime_chg_url = 'bs_change_mime_type.php';
1105 var params = {bs_db: db, bs_table: table, bs_reference: reference, bs_new_mime_type: mime_type};
1108 jQuery.post(mime_chg_url, params);
1112 * Jquery Coding for inline editing SQL_QUERY
1114 $(document).ready(function(){
1115 var oldText,db,table,token,sql_query;
1116 oldText=$(".inner_sql").html();
1117 $("#inline_edit").click(function(){
1118 db=$("input[name='db']").val();
1119 table=$("input[name='table']").val();
1120 token=$("input[name='token']").val();
1121 sql_query=$("input[name='sql_query']").val();
1122 $(".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'] + "\">");
1126 $("#btnSave").live("click",function(){
1127 window.location.replace("import.php?db=" + db +"&table=" + table + "&sql_query=" + $("#sql_query_edit").val()+"&show_query=1&token=" + token + "");
1130 $("#btnDiscard").live("click",function(){
1131 $(".sql").html("<span class=\"syntax\"><span class=\"inner_sql\">" + oldText + "</span></span>");
1134 $('.sqlbutton').click(function(evt){
1135 insertQuery(evt.target.id);
1139 $("#export_type").change(function(){
1140 if($("#export_type").val()=='svg'){
1141 $("#show_grid_opt").attr("disabled","disabled");
1142 $("#orientation_opt").attr("disabled","disabled");
1143 $("#with_doc").attr("disabled","disabled");
1144 $("#show_table_dim_opt").removeAttr("disabled");
1145 $("#all_table_same_wide").removeAttr("disabled");
1146 $("#paper_opt").removeAttr("disabled","disabled");
1147 $("#show_color_opt").removeAttr("disabled","disabled");
1148 //$(this).css("background-color","yellow");
1149 }else if($("#export_type").val()=='dia'){
1150 $("#show_grid_opt").attr("disabled","disabled");
1151 $("#with_doc").attr("disabled","disabled");
1152 $("#show_table_dim_opt").attr("disabled","disabled");
1153 $("#all_table_same_wide").attr("disabled","disabled");
1154 $("#paper_opt").removeAttr("disabled","disabled");
1155 $("#show_color_opt").removeAttr("disabled","disabled");
1156 $("#orientation_opt").removeAttr("disabled","disabled");
1157 }else if($("#export_type").val()=='eps'){
1158 $("#show_grid_opt").attr("disabled","disabled");
1159 $("#orientation_opt").removeAttr("disabled");
1160 $("#with_doc").attr("disabled","disabled");
1161 $("#show_table_dim_opt").attr("disabled","disabled");
1162 $("#all_table_same_wide").attr("disabled","disabled");
1163 $("#paper_opt").attr("disabled","disabled");
1164 $("#show_color_opt").attr("disabled","disabled");
1166 }else if($("#export_type").val()=='pdf'){
1167 $("#show_grid_opt").removeAttr("disabled");
1168 $("#orientation_opt").removeAttr("disabled");
1169 $("#with_doc").removeAttr("disabled","disabled");
1170 $("#show_table_dim_opt").removeAttr("disabled","disabled");
1171 $("#all_table_same_wide").removeAttr("disabled","disabled");
1172 $("#paper_opt").removeAttr("disabled","disabled");
1173 $("#show_color_opt").removeAttr("disabled","disabled");
1179 $('#sqlquery').focus();
1180 if ($('#input_username')) {
1181 if ($('#input_username').val() == '') {
1182 $('#input_username').focus();
1184 $('#input_password').focus();
1190 * Show a message on the top of the page for an Ajax request
1192 * @param var message string containing the message to be shown.
1193 * optional, defaults to 'Loading...'
1194 * @param var timeout number of milliseconds for the message to be visible
1195 * optional, defaults to 5000
1198 function PMA_ajaxShowMessage(message, timeout) {
1200 //Handle the case when a empty data.message is passed. We don't want the empty message
1206 * @var msg String containing the message that has to be displayed
1207 * @default PMA_messages['strLoading']
1210 var msg = PMA_messages['strLoading'];
1217 * @var timeout Number of milliseconds for which {@link msg} will be visible
1227 if( !ajax_message_init) {
1228 //For the first time this function is called, append a new div
1230 $('<div id="loading_parent"></div>')
1231 .insertBefore("#serverinfo");
1233 $('<span id="loading" class="ajax_notification"></span>')
1234 .appendTo("#loading_parent")
1236 .slideDown('medium')
1238 .slideUp('medium', function(){
1240 .html("") //Clear the message
1243 }, 'top.frame_content');
1244 ajax_message_init = true;
1247 //Otherwise, just show the div again after inserting the message
1251 .slideDown('medium')
1253 .slideUp('medium', function() {
1262 * Hides/shows the "Open in ENUM/SET editor" message, depending on the data type of the column currently selected
1264 function PMA_showNoticeForEnum(selectElement) {
1265 var enum_notice_id = selectElement.attr("id").split("_")[1];
1266 enum_notice_id += "_" + (parseInt(selectElement.attr("id").split("_")[2]) + 1);
1267 var selectedType = selectElement.attr("value");
1268 if (selectedType == "ENUM" || selectedType == "SET") {
1269 $("p[id='enum_notice_" + enum_notice_id + "']").show();
1271 $("p[id='enum_notice_" + enum_notice_id + "']").hide();
1276 * jQuery function that uses jQueryUI's dialogs to confirm with user. Does not
1277 * return a jQuery object yet and hence cannot be chained
1279 * @param string question
1280 * @param string url URL to be passed to the callbackFn to make
1282 * @param function callbackFn callback to execute after user clicks on OK
1285 jQuery.fn.PMA_confirm = function(question, url, callbackFn) {
1286 if (PMA_messages['strDoYouReally'] == '') {
1291 * @var button_options Object that stores the options passed to jQueryUI
1294 var button_options = {};
1295 button_options[PMA_messages['strOK']] = function(){
1296 $(this).dialog("close").remove();
1298 if($.isFunction(callbackFn)) {
1299 callbackFn.call(this, url);
1302 button_options[PMA_messages['strCancel']] = function() {$(this).dialog("close").remove();}
1304 $('<div id="confirm_dialog"></div>')
1306 .dialog({buttons: button_options});
1310 * jQuery function to sort a table's body after a new row has been appended to it.
1311 * Also fixes the even/odd classes of the table rows at the end.
1313 * @param string text_selector string to select the sortKey's text
1315 * @return jQuery Object for chaining purposes
1317 jQuery.fn.PMA_sort_table = function(text_selector) {
1318 return this.each(function() {
1321 * @var table_body Object referring to the table's <tbody> element
1323 var table_body = $(this);
1325 * @var rows Object referring to the collection of rows in {@link table_body}
1327 var rows = $(this).find('tr').get();
1329 //get the text of the field that we will sort by
1330 $.each(rows, function(index, row) {
1331 row.sortKey = $.trim($(row).find(text_selector).text().toLowerCase());
1334 //get the sorted order
1335 rows.sort(function(a,b) {
1336 if(a.sortKey < b.sortKey) {
1339 if(a.sortKey > b.sortKey) {
1345 //pull out each row from the table and then append it according to it's order
1346 $.each(rows, function(index, row) {
1347 $(table_body).append(row);
1351 //Re-check the classes of each row
1352 $(this).find('tr:odd')
1353 .removeClass('even').addClass('odd')
1356 .removeClass('odd').addClass('even');
1361 * jQuery coding for 'Create Table'. Used on db_operations.php,
1362 * db_structure.php and db_tracking.php (i.e., wherever
1363 * libraries/display_create_table.lib.php is used)
1365 * Attach Ajax Event handlers for Create Table
1367 $(document).ready(function() {
1370 * Attach event handler to the submit action of the create table minimal form
1371 * and retrieve the full table form and display it in a dialog
1373 * @uses PMA_ajaxShowMessage()
1375 $("#create_table_form_minimal.ajax").live('submit', function(event) {
1376 event.preventDefault();
1379 /* @todo Validate this form! */
1382 * @var button_options Object that stores the options passed to jQueryUI
1385 var button_options = {};
1386 // in the following function we need to use $(this)
1387 button_options[PMA_messages['strCancel']] = function() {$(this).dialog('close').remove();}
1389 var button_options_error = {};
1390 button_options_error[PMA_messages['strOK']] = function() {$(this).dialog('close').remove();}
1392 PMA_ajaxShowMessage();
1393 if (! $form.find('input:hidden').is('#ajax_request_hidden')) {
1394 $form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
1397 $.get($form.attr('action'), $form.serialize(), function(data) {
1398 //in the case of an error, show the error message returned.
1399 if (data.success != undefined && data.success == false) {
1400 $('<div id="create_table_dialog"></div>')
1403 title: PMA_messages['strCreateTable'],
1406 open: PMA_verifyTypeOfAllColumns,
1407 buttons : button_options_error
1408 })// end dialog options
1409 //remove the redundant [Back] link in the error message.
1410 .find('fieldset').remove();
1412 $('<div id="create_table_dialog"></div>')
1415 title: PMA_messages['strCreateTable'],
1418 open: PMA_verifyTypeOfAllColumns,
1419 buttons : button_options
1420 }); // end dialog options
1424 // empty table name and number of columns from the minimal form
1425 $form.find('input[name=table],input[name=num_fields]').val('');
1429 * Attach event handler for submission of create table form (save)
1431 * @uses PMA_ajaxShowMessage()
1432 * @uses $.PMA_sort_table()
1435 // .live() must be called after a selector, see http://api.jquery.com/live
1436 $("#create_table_form input[name=do_save_data]").live('click', function(event) {
1437 event.preventDefault();
1440 * @var the_form object referring to the create table form
1442 var $form = $("#create_table_form");
1445 * First validate the form; if there is a problem, avoid submitting it
1447 * checkTableEditForm() needs a pure element and not a jQuery object,
1448 * this is why we pass $form[0] as a parameter (the jQuery object
1449 * is actually an array of DOM elements)
1452 if (checkTableEditForm($form[0], $form.find('input[name=orig_num_fields]').val())) {
1453 // OK, form passed validation step
1454 if ($form.hasClass('ajax')) {
1455 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
1456 if (! $form.find('input:hidden').is('#ajax_request_hidden')) {
1457 $form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
1459 //User wants to submit the form
1460 $.post($form.attr('action'), $form.serialize() + "&do_save_data=" + $(this).val(), function(data) {
1461 if(data.success == true) {
1462 $('#properties_message')
1463 .removeClass('error')
1465 PMA_ajaxShowMessage(data.message);
1466 // Only if the create table dialog (distinct panel) exists
1467 if ($("#create_table_dialog").length > 0) {
1468 $("#create_table_dialog").dialog("close").remove();
1472 * @var tables_table Object referring to the <tbody> element that holds the list of tables
1474 var tables_table = $("#tablesForm").find("tbody").not("#tbl_summary_row");
1475 // this is the first table created in this db
1476 if (tables_table.length == 0) {
1477 if (window.parent && window.parent.frame_content) {
1478 window.parent.frame_content.location.reload();
1482 * @var curr_last_row Object referring to the last <tr> element in {@link tables_table}
1484 var curr_last_row = $(tables_table).find('tr:last');
1486 * @var curr_last_row_index_string String containing the index of {@link curr_last_row}
1488 var curr_last_row_index_string = $(curr_last_row).find('input:checkbox').attr('id').match(/\d+/)[0];
1490 * @var curr_last_row_index Index of {@link curr_last_row}
1492 var curr_last_row_index = parseFloat(curr_last_row_index_string);
1494 * @var new_last_row_index Index of the new row to be appended to {@link tables_table}
1496 var new_last_row_index = curr_last_row_index + 1;
1498 * @var new_last_row_id String containing the id of the row to be appended to {@link tables_table}
1500 var new_last_row_id = 'checkbox_tbl_' + new_last_row_index;
1502 data.new_table_string = data.new_table_string.replace(/checkbox_tbl_/, new_last_row_id);
1504 $(data.new_table_string)
1505 .appendTo(tables_table);
1508 $(tables_table).PMA_sort_table('th');
1511 //Refresh navigation frame as a new table has been added
1512 if (window.parent && window.parent.frame_navigation) {
1513 window.parent.frame_navigation.location.reload();
1516 $('#properties_message')
1519 // scroll to the div containing the error message
1520 $('#properties_message')[0].scrollIntoView();
1523 } // end if ($form.hasClass('ajax')
1526 $form.append('<input type="hidden" name="do_save_data" value="save" />');
1529 } // end if (checkTableEditForm() )
1530 }) // end create table form (save)
1533 * Attach event handler for create table form (add fields)
1535 * @uses PMA_ajaxShowMessage()
1536 * @uses $.PMA_sort_table()
1537 * @uses window.parent.refreshNavigation()
1540 // .live() must be called after a selector, see http://api.jquery.com/live
1541 $("#create_table_form.ajax input[name=submit_num_fields]").live('click', function(event) {
1542 event.preventDefault();
1545 * @var the_form object referring to the create table form
1547 var $form = $("#create_table_form");
1549 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
1550 if (! $form.find('input:hidden').is('#ajax_request_hidden')) {
1551 $form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
1554 //User wants to add more fields to the table
1555 $.post($form.attr('action'), $form.serialize() + "&submit_num_fields=" + $(this).val(), function(data) {
1556 // if 'create_table_dialog' exists
1557 if ($("#create_table_dialog").length > 0) {
1558 $("#create_table_dialog").html(data);
1560 // if 'create_table_div' exists
1561 if ($("#create_table_div").length > 0) {
1562 $("#create_table_div").html(data);
1564 PMA_verifyTypeOfAllColumns();
1567 }) // end create table form (add fields)
1569 }, 'top.frame_content'); //end $(document).ready for 'Create Table'
1572 * Attach Ajax event handlers for Drop Trigger. Used on tbl_structure.php
1573 * @see $cfg['AjaxEnable']
1575 $(document).ready(function() {
1577 $(".drop_trigger_anchor").live('click', function(event) {
1578 event.preventDefault();
1582 * @var curr_row Object reference to the current trigger's <tr>
1584 var $curr_row = $anchor.parents('tr');
1586 * @var question String containing the question to be asked for confirmation
1588 var question = 'DROP TRIGGER IF EXISTS `' + $curr_row.children('td:first').text() + '`';
1590 $anchor.PMA_confirm(question, $anchor.attr('href'), function(url) {
1592 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
1593 $.get(url, {'is_js_confirmed': 1, 'ajax_request': true}, function(data) {
1594 if(data.success == true) {
1595 PMA_ajaxShowMessage(data.message);
1596 $("#topmenucontainer")
1600 .after(data.sql_query);
1601 $curr_row.hide("medium").remove();
1604 PMA_ajaxShowMessage(data.error);
1607 }) // end $.PMA_confirm()
1608 }) // end $().live()
1609 }, 'top.frame_content'); //end $(document).ready() for Drop Trigger
1612 * Attach Ajax event handlers for Drop Database. Moved here from db_structure.js
1613 * as it was also required on db_create.php
1615 * @uses $.PMA_confirm()
1616 * @uses PMA_ajaxShowMessage()
1617 * @uses window.parent.refreshNavigation()
1618 * @uses window.parent.refreshMain()
1619 * @see $cfg['AjaxEnable']
1621 $(document).ready(function() {
1622 $("#drop_db_anchor").live('click', function(event) {
1623 event.preventDefault();
1625 //context is top.frame_content, so we need to use window.parent.db to access the db var
1627 * @var question String containing the question to be asked for confirmation
1629 var question = PMA_messages['strDropDatabaseStrongWarning'] + '\n' + PMA_messages['strDoYouReally'] + ' :\n' + 'DROP DATABASE ' + window.parent.db;
1631 $(this).PMA_confirm(question, $(this).attr('href') ,function(url) {
1633 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
1634 $.get(url, {'is_js_confirmed': '1', 'ajax_request': true}, function(data) {
1635 //Database deleted successfully, refresh both the frames
1636 window.parent.refreshNavigation();
1637 window.parent.refreshMain();
1639 }); // end $.PMA_confirm()
1640 }); //end of Drop Database Ajax action
1641 }) // end of $(document).ready() for Drop Database
1644 * Attach Ajax event handlers for 'Create Database'. Used wherever libraries/
1645 * display_create_database.lib.php is used, ie main.php and server_databases.php
1647 * @uses PMA_ajaxShowMessage()
1648 * @see $cfg['AjaxEnable']
1650 $(document).ready(function() {
1652 $('#create_database_form.ajax').live('submit', function(event) {
1653 event.preventDefault();
1657 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
1659 if (! $form.find('input:hidden').is('#ajax_request_hidden')) {
1660 $form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
1663 $.post($form.attr('action'), $form.serialize(), function(data) {
1664 if(data.success == true) {
1665 PMA_ajaxShowMessage(data.message);
1667 //Append database's row to table
1668 $("#tabledatabases")
1670 .append(data.new_db_string)
1671 .PMA_sort_table('.name')
1672 .find('#db_summary_row')
1673 .appendTo('#tabledatabases tbody')
1674 .removeClass('odd even');
1676 var $databases_count_object = $('#databases_count');
1677 var databases_count = parseInt($databases_count_object.text());
1678 $databases_count_object.text(++databases_count);
1679 //Refresh navigation frame as a new database has been added
1680 if (window.parent && window.parent.frame_navigation) {
1681 window.parent.frame_navigation.location.reload();
1685 PMA_ajaxShowMessage(data.error);
1688 }) // end $().live()
1689 }) // end $(document).ready() for Create Database
1692 * Attach Ajax event handlers for 'Change Password' on main.php
1694 $(document).ready(function() {
1697 * Attach Ajax event handler on the change password anchor
1698 * @see $cfg['AjaxEnable']
1700 $('#change_password_anchor.dialog_active').live('click',function(event) {
1701 event.preventDefault();
1704 $('#change_password_anchor.ajax').live('click', function(event) {
1705 event.preventDefault();
1706 $(this).removeClass('ajax').addClass('dialog_active');
1708 * @var button_options Object containing options to be passed to jQueryUI's dialog
1710 var button_options = {};
1711 button_options[PMA_messages['strCancel']] = function() {$(this).dialog('close').remove();}
1712 $.get($(this).attr('href'), {'ajax_request': true}, function(data) {
1713 $('<div id="change_password_dialog"></div>')
1715 title: PMA_messages['strChangePassword'],
1717 close: function(ev,ui) {$(this).remove();},
1718 buttons : button_options,
1719 beforeClose: function(ev,ui){ $('#change_password_anchor.dialog_active').removeClass('dialog_active').addClass('ajax')}
1722 displayPasswordGenerateButton();
1724 }) // end handler for change password anchor
1727 * Attach Ajax event handler for Change Password form submission
1729 * @uses PMA_ajaxShowMessage()
1730 * @see $cfg['AjaxEnable']
1732 $("#change_password_form.ajax").find('input[name=change_pw]').live('click', function(event) {
1733 event.preventDefault();
1736 * @var the_form Object referring to the change password form
1738 var the_form = $("#change_password_form");
1741 * @var this_value String containing the value of the submit button.
1742 * Need to append this for the change password form on Server Privileges
1745 var this_value = $(this).val();
1747 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
1748 $(the_form).append('<input type="hidden" name="ajax_request" value="true" />');
1750 $.post($(the_form).attr('action'), $(the_form).serialize() + '&change_pw='+ this_value, function(data) {
1751 if(data.success == true) {
1752 $("#topmenucontainer").after(data.sql_query);
1753 $("#change_password_dialog").hide().remove();
1754 $("#edit_user_dialog").dialog("close").remove();
1755 $('#change_password_anchor.dialog_active').removeClass('dialog_active').addClass('ajax');
1758 PMA_ajaxShowMessage(data.error);
1761 }) // end handler for Change Password form submission
1762 }) // end $(document).ready() for Change Password
1765 * Toggle the hiding/showing of the "Open in ENUM/SET editor" message when
1766 * the page loads and when the selected data type changes
1768 $(document).ready(function() {
1769 // is called here for normal page loads and also when opening
1770 // the Create table dialog
1771 PMA_verifyTypeOfAllColumns();
1773 // needs live() to work also in the Create Table dialog
1774 $("select[class='column_type']").live('change', function() {
1775 PMA_showNoticeForEnum($(this));
1779 function PMA_verifyTypeOfAllColumns() {
1780 $("select[class='column_type']").each(function() {
1781 PMA_showNoticeForEnum($(this));
1786 * Closes the ENUM/SET editor and removes the data in it
1788 function disable_popup() {
1789 $("#popup_background").fadeOut("fast");
1790 $("#enum_editor").fadeOut("fast");
1791 // clear the data from the text boxes
1792 $("#enum_editor #values input").remove();
1793 $("#enum_editor input[type='hidden']").remove();
1797 * Opens the ENUM/SET editor and controls its functions
1799 $(document).ready(function() {
1800 // Needs live() to work also in the Create table dialog
1801 $("a[class='open_enum_editor']").live('click', function() {
1803 var windowWidth = document.documentElement.clientWidth;
1804 var windowHeight = document.documentElement.clientHeight;
1805 var popupWidth = windowWidth/2;
1806 var popupHeight = windowHeight*0.8;
1807 var popupOffsetTop = windowHeight/2 - popupHeight/2;
1808 var popupOffsetLeft = windowWidth/2 - popupWidth/2;
1809 $("#enum_editor").css({"position":"absolute", "top": popupOffsetTop, "left": popupOffsetLeft, "width": popupWidth, "height": popupHeight});
1812 $("#popup_background").css({"opacity":"0.7"});
1813 $("#popup_background").fadeIn("fast");
1814 $("#enum_editor").fadeIn("fast");
1817 var values = $(this).parent().prev("input").attr("value").split(",");
1818 $.each(values, function(index, val) {
1819 if(jQuery.trim(val) != "") {
1820 // enclose the string in single quotes if it's not already
1821 if(val.substr(0, 1) != "'") {
1824 if(val.substr(val.length-1, val.length) != "'") {
1827 // escape the single quotes, except the mandatory ones enclosing the entire string
1828 val = val.substr(1, val.length-2).replace(/''/g, "'").replace(/\\\\/g, '\\').replace(/\\'/g, "'").replace(/'/g, "'");
1829 // escape the greater-than symbol
1830 val = val.replace(/>/g, ">");
1831 $("#enum_editor #values").append("<input type='text' value=" + val + " />");
1834 // So we know which column's data is being edited
1835 $("#enum_editor").append("<input type='hidden' value='" + $(this).parent().prev("input").attr("id") + "' />");
1839 // If the "close" link is clicked, close the enum editor
1840 // Needs live() to work also in the Create table dialog
1841 $("a[class='close_enum_editor']").live('click', function() {
1845 // If the "cancel" link is clicked, close the enum editor
1846 // Needs live() to work also in the Create table dialog
1847 $("a[class='cancel_enum_editor']").live('click', function() {
1851 // When "add a new value" is clicked, append an empty text field
1852 // Needs live() to work also in the Create table dialog
1853 $("a[class='add_value']").live('click', function() {
1854 $("#enum_editor #values").append("<input type='text' />");
1857 // When the submit button is clicked, put the data back into the original form
1858 // Needs live() to work also in the Create table dialog
1859 $("#enum_editor input[type='submit']").live('click', function() {
1860 var value_array = new Array();
1861 $.each($("#enum_editor #values input"), function(index, input_element) {
1862 val = jQuery.trim(input_element.value);
1864 value_array.push("'" + val.replace(/\\/g, '\\\\').replace(/'/g, "''") + "'");
1867 // get the Length/Values text field where this value belongs
1868 var values_id = $("#enum_editor input[type='hidden']").attr("value");
1869 $("input[id='" + values_id + "']").attr("value", value_array.join(","));
1874 * Hides certain table structure actions, replacing them with the word "More". They are displayed
1875 * in a dropdown menu when the user hovers over the word "More."
1877 // Remove the actions from the table cells (they are available by default for JavaScript-disabled browsers)
1878 // if the table is not a view or information_schema (otherwise there is only one action to hide and there's no point)
1879 if($("input[type='hidden'][name='table_type']").val() == "table") {
1880 var $table = $("table[id='tablestructure']");
1881 $table.find("td[class='browse']").remove();
1882 $table.find("td[class='primary']").remove();
1883 $table.find("td[class='unique']").remove();
1884 $table.find("td[class='index']").remove();
1885 $table.find("td[class='fulltext']").remove();
1886 $table.find("th[class='action']").attr("colspan", 3);
1888 // Display the "more" text
1889 $table.find("td[class='more_opts']").show();
1891 // Position the dropdown
1892 $(".structure_actions_dropdown").each(function() {
1893 // Optimize DOM querying
1894 var $this_dropdown = $(this);
1895 // The top offset must be set for IE even if it didn't change
1896 var cell_right_edge_offset = $this_dropdown.parent().offset().left + $this_dropdown.parent().innerWidth();
1897 var left_offset = cell_right_edge_offset - $this_dropdown.innerWidth();
1898 var top_offset = $this_dropdown.parent().offset().top + $this_dropdown.parent().innerHeight();
1899 $this_dropdown.offset({ top: top_offset, left: left_offset });
1902 // A hack for IE6 to prevent the after_field select element from being displayed on top of the dropdown by
1903 // positioning an iframe directly on top of it
1904 var $after_field = $("select[name='after_field']");
1905 $("iframe[class='IE_hack']")
1906 .width($after_field.width())
1907 .height($after_field.height())
1909 top: $after_field.offset().top,
1910 left: $after_field.offset().left
1913 // When "more" is hovered over, show the hidden actions
1914 $table.find("td[class='more_opts']")
1915 .mouseenter(function() {
1916 if($.browser.msie && $.browser.version == "6.0") {
1917 $("iframe[class='IE_hack']")
1919 .width($after_field.width()+4)
1920 .height($after_field.height()+4)
1922 top: $after_field.offset().top,
1923 left: $after_field.offset().left
1926 $(".structure_actions_dropdown").hide(); // Hide all the other ones that may be open
1927 $(this).children(".structure_actions_dropdown").show();
1928 // Need to do this again for IE otherwise the offset is wrong
1929 if($.browser.msie) {
1930 var left_offset_IE = $(this).offset().left + $(this).innerWidth() - $(this).children(".structure_actions_dropdown").innerWidth();
1931 var top_offset_IE = $(this).offset().top + $(this).innerHeight();
1932 $(this).children(".structure_actions_dropdown").offset({
1934 left: left_offset_IE });
1937 .mouseleave(function() {
1938 $(this).children(".structure_actions_dropdown").hide();
1939 if($.browser.msie && $.browser.version == "6.0") {
1940 $("iframe[class='IE_hack']").hide();
1946 /* Displays tooltips */
1947 $(document).ready(function() {
1948 // Hide the footnotes from the footer (which are displayed for
1949 // JavaScript-disabled browsers) since the tooltip is sufficient
1950 $(".footnotes").hide();
1951 $(".footnotes span").each(function() {
1952 $(this).children("sup").remove();
1954 // The border and padding must be removed otherwise a thin yellow box remains visible
1955 $(".footnotes").css("border", "none");
1956 $(".footnotes").css("padding", "0px");
1958 // Replace the superscripts with the help icon
1959 $("sup[class='footnotemarker']").hide();
1960 $("img[class='footnotemarker']").show();
1962 $("img[class='footnotemarker']").each(function() {
1963 var span_id = $(this).attr("id");
1964 span_id = span_id.split("_")[1];
1965 var tooltip_text = $(".footnotes span[id='footnote_" + span_id + "']").html();
1967 content: tooltip_text,
1969 hide: { when: 'unfocus', delay: 0 },
1970 style: { background: '#ffffcc' }
1975 function menuResize()
1977 var cnt = $('#topmenu');
1978 var wmax = cnt.innerWidth() - 5; // 5 px margin for jumping menu in Chrome
1979 var submenu = cnt.find('.submenu');
1980 var submenu_w = submenu.outerWidth(true);
1981 var submenu_ul = submenu.find('ul');
1982 var li = cnt.find('> li');
1983 var li2 = submenu_ul.find('li');
1984 var more_shown = li2.length > 0;
1985 var w = more_shown ? submenu_w : 0;
1989 for (var i = 0; i < li.length-1; i++) { // li.length-1: skip .submenu element
1991 var el_width = el.outerWidth(true);
1992 el.data('width', el_width);
1996 if (w + submenu_w < wmax) {
2000 w -= $(li[i-1]).data('width');
2006 if (hide_start > 0) {
2007 for (var i = hide_start; i < li.length-1; i++) {
2008 $(li[i])[more_shown ? 'prependTo' : 'appendTo'](submenu_ul);
2010 submenu.addClass('shown');
2011 } else if (more_shown) {
2013 // nothing hidden, maybe something can be restored
2014 for (var i = 0; i < li2.length; i++) {
2015 //console.log(li2[i], submenu_w);
2016 w += $(li2[i]).data('width');
2017 // item fits or (it is the last item and it would fit if More got removed)
2018 if (w+submenu_w < wmax || (i == li2.length-1 && w < wmax)) {
2019 $(li2[i]).insertBefore(submenu);
2020 if (i == li2.length-1) {
2021 submenu.removeClass('shown');
2028 if (submenu.find('.tabactive').length) {
2029 submenu.addClass('active').find('> a').removeClass('tab').addClass('tabactive');
2031 submenu.removeClass('active').find('> a').addClass('tab').removeClass('tabactive');
2036 var topmenu = $('#topmenu');
2037 if (topmenu.length == 0) {
2040 // create submenu container
2041 var link = $('<a />', {href: '#', 'class': 'tab'})
2042 .text(PMA_messages['strMore'])
2043 .click(function(e) {
2046 var img = topmenu.find('li:first-child img');
2048 img.clone().attr('src', img.attr('src').replace(/\/[^\/]+$/, '/b_more.png')).prependTo(link);
2050 var submenu = $('<li />', {'class': 'submenu'})
2052 .append($('<ul />'))
2053 .mouseenter(function() {
2054 if ($(this).find('ul .tabactive').length == 0) {
2055 $(this).addClass('submenuhover').find('> a').addClass('tabactive');
2058 .mouseleave(function() {
2059 if ($(this).find('ul .tabactive').length == 0) {
2060 $(this).removeClass('submenuhover').find('> a').removeClass('tabactive');
2063 topmenu.append(submenu);
2065 // populate submenu and register resize event
2066 $(window).resize(menuResize);
2071 * For the checkboxes in browse mode, handles the shift/click (only works
2072 * in horizontal mode) and propagates the click to the "companion" checkbox
2073 * (in both horizontal and vertical). Works also for pages reached via AJAX.
2075 $(document).ready(function() {
2076 $('.multi_checkbox').live('click',function(e) {
2077 var current_checkbox_id = this.id;
2078 var left_checkbox_id = current_checkbox_id.replace('_right', '_left');
2079 var right_checkbox_id = current_checkbox_id.replace('_left', '_right');
2080 var other_checkbox_id = '';
2081 if (current_checkbox_id == left_checkbox_id) {
2082 other_checkbox_id = right_checkbox_id;
2084 other_checkbox_id = left_checkbox_id;
2087 var $current_checkbox = $('#' + current_checkbox_id);
2088 var $other_checkbox = $('#' + other_checkbox_id);
2091 var index_of_current_checkbox = $('.multi_checkbox').index($current_checkbox);
2092 var $last_checkbox = $('.multi_checkbox').filter('.last_clicked');
2093 var index_of_last_click = $('.multi_checkbox').index($last_checkbox);
2094 $('.multi_checkbox')
2095 .filter(function(index) {
2096 // the first clicked row can be on a row above or below the
2097 // shift-clicked row
2098 return (index_of_current_checkbox > index_of_last_click && index > index_of_last_click && index < index_of_current_checkbox)
2099 || (index_of_last_click > index_of_current_checkbox && index < index_of_last_click && index > index_of_current_checkbox);
2101 .each(function(index) {
2102 var $intermediate_checkbox = $(this);
2103 if ($current_checkbox.is(':checked')) {
2104 $intermediate_checkbox.attr('checked', true);
2106 $intermediate_checkbox.attr('checked', false);
2111 $('.multi_checkbox').removeClass('last_clicked');
2112 $current_checkbox.addClass('last_clicked');
2114 // When there is a checkbox on both ends of the row, propagate the
2115 // click on one of them to the other one.
2116 // (the default action has not been prevented so if we have
2117 // just clicked, this "if" is true)
2118 if ($current_checkbox.is(':checked')) {
2119 $other_checkbox.attr('checked', true);
2121 $other_checkbox.attr('checked', false);
2124 }) // end of $(document).ready() for multi checkbox
2127 * Get the row number from the classlist (for example, row_1)
2129 function PMA_getRowNumber(classlist) {
2130 return parseInt(classlist.split(/row_/)[1]);
2134 * Changes status of slider
2136 function PMA_set_status_label(id) {
2137 if ($('#' + id).css('display') == 'none') {
2138 $('#anchor_status_' + id).text('+ ');
2140 $('#anchor_status_' + id).text('- ');
2145 * Initializes slider effect.
2147 function PMA_init_slider() {
2148 $('.pma_auto_slider').each(function(idx, e) {
2149 if ($(e).hasClass('slider_init_done')) return;
2150 $(e).addClass('slider_init_done');
2151 $('<span id="anchor_status_' + e.id + '"></span>')
2153 PMA_set_status_label(e.id);
2155 $('<a href="#' + e.id + '" id="anchor_' + e.id + '">' + e.title + '</a>')
2158 $('#' + e.id).toggle('clip', function() {
2159 PMA_set_status_label(e.id);
2169 $(document).ready(function() {
2170 $('.vpointer').live('hover',
2173 var $this_td = $(this);
2174 var row_num = PMA_getRowNumber($this_td.attr('class'));
2175 // for all td of the same vertical row, toggle hover
2176 $('.vpointer').filter('.row_' + row_num).toggleClass('hover');
2179 }) // end of $(document).ready() for vertical pointer
2181 $(document).ready(function() {
2185 $('.vmarker').live('click', function(e) {
2186 var $this_td = $(this);
2187 var row_num = PMA_getRowNumber($this_td.attr('class'));
2188 // for all td of the same vertical row, toggle the marked class
2189 $('.vmarker').filter('.row_' + row_num).toggleClass('marked');
2193 * Reveal visual builder anchor
2196 $('#visual_builder_anchor').show();
2199 * Page selector in db Structure (non-AJAX)
2201 $('#tableslistcontainer').find('#pageselector').live('change', function() {
2202 $(this).parent("form").submit();
2206 * Page selector in navi panel (non-AJAX)
2208 $('#navidbpageselector').find('#pageselector').live('change', function() {
2209 $(this).parent("form").submit();
2213 * Page selector in browse_foreigners windows (non-AJAX)
2215 $('#body_browse_foreigners').find('#pageselector').live('change', function() {
2216 $(this).closest("form").submit();
2220 * Load version information asynchronously.
2222 if ($('.jsversioncheck').length > 0) {
2224 var s = document.createElement('script');
2225 s.type = 'text/javascript';
2227 s.src = 'http://www.phpmyadmin.net/home_page/version.js';
2228 s.onload = PMA_current_version;
2229 var x = document.getElementsByTagName('script')[0];
2230 x.parentNode.insertBefore(s, x);
2240 * Enables the text generated by PMA_linkOrButton() to be clickable
2242 $('.clickprevimage')
2243 .css('color', function(index) {
2244 return $('a').css('color');
2246 .css('cursor', function(index) {
2247 return $('a').css('cursor');
2248 }) //todo: hover effect
2249 .live('click',function(e) {
2250 $this_span = $(this);
2251 if ($this_span.closest('td').is('.inline_edit_anchor')) {
2252 // this would bind a second click event to the inline edit
2253 // anchor and would disturb its behavior
2255 $this_span.parent().find('input:image').click();
2259 }) // end of $(document).ready()