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 * Add a hidden field to the form to indicate that this will be an
25 * Ajax request (only if this hidden field does not exist)
27 * @param object the form
29 function PMA_prepareForAjaxRequest($form) {
30 if (! $form.find('input:hidden').is('#ajax_request_hidden')) {
31 $form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
36 * Generate a new password and copy it to the password input areas
38 * @param object the form that holds the password fields
40 * @return boolean always true
42 function suggestPassword(passwd_form) {
43 // restrict the password to just letters and numbers to avoid problems:
44 // "editors and viewers regard the password as multiple words and
45 // things like double click no longer work"
46 var pwchars = "abcdefhjmnpqrstuvwxyz23456789ABCDEFGHJKLMNPQRSTUVWYXZ";
47 var passwordlength = 16; // do we want that to be dynamic? no, keep it simple :)
48 var passwd = passwd_form.generated_pw;
51 for ( i = 0; i < passwordlength; i++ ) {
52 passwd.value += pwchars.charAt( Math.floor( Math.random() * pwchars.length ) )
54 passwd_form.text_pma_pw.value = passwd.value;
55 passwd_form.text_pma_pw2.value = passwd.value;
60 * Version string to integer conversion.
62 function parseVersionString (str) {
63 if (typeof(str) != 'string') { return false; }
65 // Parse possible alpha/beta/rc/
66 var state = str.split('-');
67 if (state.length >= 2) {
68 if (state[1].substr(0, 2) == 'rc') {
69 add = - 20 - parseInt(state[1].substr(2));
70 } else if (state[1].substr(0, 4) == 'beta') {
71 add = - 40 - parseInt(state[1].substr(4));
72 } else if (state[1].substr(0, 5) == 'alpha') {
73 add = - 60 - parseInt(state[1].substr(5));
74 } else if (state[1].substr(0, 3) == 'dev') {
75 /* We don't handle dev, it's git snapshot */
80 var x = str.split('.');
81 // Use 0 for non existing parts
82 var maj = parseInt(x[0]) || 0;
83 var min = parseInt(x[1]) || 0;
84 var pat = parseInt(x[2]) || 0;
85 var hotfix = parseInt(x[3]) || 0;
86 return maj * 100000000 + min * 1000000 + pat * 10000 + hotfix * 100 + add;
90 * Indicates current available version on main page.
92 function PMA_current_version() {
93 var current = parseVersionString('3.4.0'/*pmaversion*/);
94 var latest = parseVersionString(PMA_latest_version);
95 $('#li_pma_version').append(PMA_messages['strLatestAvailable'] + ' ' + PMA_latest_version);
96 if (latest > current) {
97 var message = $.sprintf(PMA_messages['strNewerVersion'], PMA_latest_version, PMA_latest_date);
98 if (Math.floor(latest / 10000) == Math.floor(current / 10000)) {
104 $('#maincontainer').after('<div class="' + klass + '">' + message + '</div>');
109 * for libraries/display_change_password.lib.php
110 * libraries/user_password.php
114 function displayPasswordGenerateButton() {
115 $('#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>');
116 $('#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>');
120 * Adds a date/time picker to an element
122 * @param object $this_element a jQuery object pointing to the element
124 function PMA_addDatepicker($this_element) {
125 var showTimeOption = false;
126 if ($this_element.is('.datetimefield')) {
127 showTimeOption = true;
133 buttonImage: themeCalendarImage, // defined in js/messages.php
134 buttonImageOnly: true,
139 showTime: showTimeOption,
140 dateFormat: 'yy-mm-dd', // yy means year with four digits
142 beforeShow: function(input, inst) {
143 // Remember that we came from the datepicker; this is used
144 // in tbl_change.js by verificationsAfterFieldChange()
145 $this_element.data('comes_from', 'datepicker');
147 constrainInput: false
152 * selects the content of a given object, f.e. a textarea
154 * @param object element element of which the content will be selected
155 * @param var lock variable which holds the lock for this element
156 * or true, if no lock exists
157 * @param boolean only_once if true this is only done once
158 * f.e. only on first focus
160 function selectContent( element, lock, only_once ) {
161 if ( only_once && only_once_elements[element.name] ) {
165 only_once_elements[element.name] = true;
175 * Displays a confirmation box before to submit a "DROP/DELETE/ALTER" query.
176 * This function is called while clicking links
178 * @param object the link
179 * @param object the sql query to submit
181 * @return boolean whether to run the query or not
183 function confirmLink(theLink, theSqlQuery)
185 // Confirmation is not required in the configuration file
186 // or browser is Opera (crappy js implementation)
187 if (PMA_messages['strDoYouReally'] == '' || typeof(window.opera) != 'undefined') {
191 var is_confirmed = confirm(PMA_messages['strDoYouReally'] + ' :\n' + theSqlQuery);
193 if ( typeof(theLink.href) != 'undefined' ) {
194 theLink.href += '&is_js_confirmed=1';
195 } else if ( typeof(theLink.form) != 'undefined' ) {
196 theLink.form.action += '?is_js_confirmed=1';
201 } // end of the 'confirmLink()' function
205 * Displays a confirmation box before doing some action
207 * @param object the message to display
209 * @return boolean whether to run the query or not
211 * @todo used only by libraries/display_tbl.lib.php. figure out how it is used
212 * and replace with a jQuery equivalent
214 function confirmAction(theMessage)
216 // TODO: Confirmation is not required in the configuration file
217 // or browser is Opera (crappy js implementation)
218 if (typeof(window.opera) != 'undefined') {
222 var is_confirmed = confirm(theMessage);
225 } // end of the 'confirmAction()' function
229 * Displays an error message if a "DROP DATABASE" statement is submitted
230 * while it isn't allowed, else confirms a "DROP/DELETE/ALTER" query before
231 * sumitting it if required.
232 * This function is called by the 'checkSqlQuery()' js function.
234 * @param object the form
235 * @param object the sql query textarea
237 * @return boolean whether to run the query or not
239 * @see checkSqlQuery()
241 function confirmQuery(theForm1, sqlQuery1)
243 // Confirmation is not required in the configuration file
244 if (PMA_messages['strDoYouReally'] == '') {
248 // The replace function (js1.2) isn't supported
249 else if (typeof(sqlQuery1.value.replace) == 'undefined') {
253 // js1.2+ -> validation with regular expressions
255 // "DROP DATABASE" statement isn't allowed
256 if (PMA_messages['strNoDropDatabases'] != '') {
257 var drop_re = new RegExp('(^|;)\\s*DROP\\s+(IF EXISTS\\s+)?DATABASE\\s', 'i');
258 if (drop_re.test(sqlQuery1.value)) {
259 alert(PMA_messages['strNoDropDatabases']);
266 // Confirms a "DROP/DELETE/ALTER/TRUNCATE" statement
268 // TODO: find a way (if possible) to use the parser-analyser
269 // for this kind of verification
270 // For now, I just added a ^ to check for the statement at
271 // beginning of expression
273 var do_confirm_re_0 = new RegExp('^\\s*DROP\\s+(IF EXISTS\\s+)?(TABLE|DATABASE|PROCEDURE)\\s', 'i');
274 var do_confirm_re_1 = new RegExp('^\\s*ALTER\\s+TABLE\\s+((`[^`]+`)|([A-Za-z0-9_$]+))\\s+DROP\\s', 'i');
275 var do_confirm_re_2 = new RegExp('^\\s*DELETE\\s+FROM\\s', 'i');
276 var do_confirm_re_3 = new RegExp('^\\s*TRUNCATE\\s', 'i');
278 if (do_confirm_re_0.test(sqlQuery1.value)
279 || do_confirm_re_1.test(sqlQuery1.value)
280 || do_confirm_re_2.test(sqlQuery1.value)
281 || do_confirm_re_3.test(sqlQuery1.value)) {
282 var message = (sqlQuery1.value.length > 100)
283 ? sqlQuery1.value.substr(0, 100) + '\n ...'
285 var is_confirmed = confirm(PMA_messages['strDoYouReally'] + ' :\n' + message);
286 // statement is confirmed -> update the
287 // "is_js_confirmed" form field so the confirm test won't be
288 // run on the server side and allows to submit the form
290 theForm1.elements['is_js_confirmed'].value = 1;
293 // statement is rejected -> do not submit the form
298 } // end if (handle confirm box result)
299 } // end if (display confirm box)
300 } // end confirmation stuff
303 } // end of the 'confirmQuery()' function
307 * Displays a confirmation box before disabling the BLOB repository for a given database.
308 * This function is called while clicking links
310 * @param object the database
312 * @return boolean whether to disable the repository or not
314 function confirmDisableRepository(theDB)
316 // Confirmation is not required in the configuration file
317 // or browser is Opera (crappy js implementation)
318 if (PMA_messages['strDoYouReally'] == '' || typeof(window.opera) != 'undefined') {
322 var is_confirmed = confirm(PMA_messages['strBLOBRepositoryDisableStrongWarning'] + '\n' + PMA_messages['strBLOBRepositoryDisableAreYouSure']);
325 } // end of the 'confirmDisableBLOBRepository()' function
329 * Displays an error message if the user submitted the sql query form with no
330 * sql query, else checks for "DROP/DELETE/ALTER" statements
332 * @param object the form
334 * @return boolean always false
336 * @see confirmQuery()
338 function checkSqlQuery(theForm)
340 var sqlQuery = theForm.elements['sql_query'];
343 // The replace function (js1.2) isn't supported -> basic tests
344 if (typeof(sqlQuery.value.replace) == 'undefined') {
345 isEmpty = (sqlQuery.value == '') ? 1 : 0;
346 if (isEmpty && typeof(theForm.elements['sql_file']) != 'undefined') {
347 isEmpty = (theForm.elements['sql_file'].value == '') ? 1 : 0;
349 if (isEmpty && typeof(theForm.elements['sql_localfile']) != 'undefined') {
350 isEmpty = (theForm.elements['sql_localfile'].value == '') ? 1 : 0;
352 if (isEmpty && typeof(theForm.elements['id_bookmark']) != 'undefined') {
353 isEmpty = (theForm.elements['id_bookmark'].value == null || theForm.elements['id_bookmark'].value == '');
356 // js1.2+ -> validation with regular expressions
358 var space_re = new RegExp('\\s+');
359 if (typeof(theForm.elements['sql_file']) != 'undefined' &&
360 theForm.elements['sql_file'].value.replace(space_re, '') != '') {
363 if (typeof(theForm.elements['sql_localfile']) != 'undefined' &&
364 theForm.elements['sql_localfile'].value.replace(space_re, '') != '') {
367 if (isEmpty && typeof(theForm.elements['id_bookmark']) != 'undefined' &&
368 (theForm.elements['id_bookmark'].value != null || theForm.elements['id_bookmark'].value != '') &&
369 theForm.elements['id_bookmark'].selectedIndex != 0
373 // Checks for "DROP/DELETE/ALTER" statements
374 if (sqlQuery.value.replace(space_re, '') != '') {
375 if (confirmQuery(theForm, sqlQuery)) {
387 alert(PMA_messages['strFormEmpty']);
393 } // end of the 'checkSqlQuery()' function
396 * Check if a form's element is empty.
397 * An element containing only spaces is also considered empty
399 * @param object the form
400 * @param string the name of the form field to put the focus on
402 * @return boolean whether the form field is empty or not
404 function emptyCheckTheField(theForm, theFieldName)
407 var theField = theForm.elements[theFieldName];
408 // Whether the replace function (js1.2) is supported or not
409 var isRegExp = (typeof(theField.value.replace) != 'undefined');
412 isEmpty = (theField.value == '') ? 1 : 0;
414 var space_re = new RegExp('\\s+');
415 isEmpty = (theField.value.replace(space_re, '') == '') ? 1 : 0;
419 } // end of the 'emptyCheckTheField()' function
423 * Check whether a form field is empty or not
425 * @param object the form
426 * @param string the name of the form field to put the focus on
428 * @return boolean whether the form field is empty or not
430 function emptyFormElements(theForm, theFieldName)
432 var theField = theForm.elements[theFieldName];
433 var isEmpty = emptyCheckTheField(theForm, theFieldName);
437 } // end of the 'emptyFormElements()' function
441 * Ensures a value submitted in a form is numeric and is in a range
443 * @param object the form
444 * @param string the name of the form field to check
445 * @param integer the minimum authorized value
446 * @param integer the maximum authorized value
448 * @return boolean whether a valid number has been submitted or not
450 function checkFormElementInRange(theForm, theFieldName, message, min, max)
452 var theField = theForm.elements[theFieldName];
453 var val = parseInt(theField.value);
455 if (typeof(min) == 'undefined') {
458 if (typeof(max) == 'undefined') {
459 max = Number.MAX_VALUE;
465 alert(PMA_messages['strNotNumber']);
469 // It's a number but it is not between min and max
470 else if (val < min || val > max) {
472 alert(message.replace('%d', val));
476 // It's a valid number
478 theField.value = val;
482 } // end of the 'checkFormElementInRange()' function
485 function checkTableEditForm(theForm, fieldsCnt)
487 // TODO: avoid sending a message if user just wants to add a line
488 // on the form but has not completed at least one field name
490 var atLeastOneField = 0;
491 var i, elm, elm2, elm3, val, id;
493 for (i=0; i<fieldsCnt; i++)
495 id = "#field_" + i + "_2";
498 if (val == 'VARCHAR' || val == 'CHAR' || val == 'BIT' || val == 'VARBINARY' || val == 'BINARY') {
499 elm2 = $("#field_" + i + "_3");
500 val = parseInt(elm2.val());
501 elm3 = $("#field_" + i + "_1");
502 if (isNaN(val) && elm3.val() != "") {
504 alert(PMA_messages['strNotNumber']);
510 if (atLeastOneField == 0) {
511 id = "field_" + i + "_1";
512 if (!emptyCheckTheField(theForm, id)) {
517 if (atLeastOneField == 0) {
518 var theField = theForm.elements["field_0_1"];
519 alert(PMA_messages['strFormEmpty']);
524 // at least this section is under jQuery
525 if ($("input.textfield[name='table']").val() == "") {
526 alert(PMA_messages['strFormEmpty']);
527 $("input.textfield[name='table']").focus();
533 } // enf of the 'checkTableEditForm()' function
537 * Ensures the choice between 'transmit', 'zipped', 'gzipped' and 'bzipped'
538 * checkboxes is consistant
540 * @param object the form
541 * @param string a code for the action that causes this function to be run
543 * @return boolean always true
545 function checkTransmitDump(theForm, theAction)
547 var formElts = theForm.elements;
549 // 'zipped' option has been checked
550 if (theAction == 'zip' && formElts['zip'].checked) {
551 if (!formElts['asfile'].checked) {
552 theForm.elements['asfile'].checked = true;
554 if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) {
555 theForm.elements['gzip'].checked = false;
557 if (typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked) {
558 theForm.elements['bzip'].checked = false;
561 // 'gzipped' option has been checked
562 else if (theAction == 'gzip' && formElts['gzip'].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['bzip']) != 'undefined' && formElts['bzip'].checked) {
570 theForm.elements['bzip'].checked = false;
573 // 'bzipped' option has been checked
574 else if (theAction == 'bzip' && formElts['bzip'].checked) {
575 if (!formElts['asfile'].checked) {
576 theForm.elements['asfile'].checked = true;
578 if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
579 theForm.elements['zip'].checked = false;
581 if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) {
582 theForm.elements['gzip'].checked = false;
585 // 'transmit' option has been unchecked
586 else if (theAction == 'transmit' && !formElts['asfile'].checked) {
587 if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
588 theForm.elements['zip'].checked = false;
590 if ((typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked)) {
591 theForm.elements['gzip'].checked = false;
593 if ((typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked)) {
594 theForm.elements['bzip'].checked = false;
599 } // end of the 'checkTransmitDump()' function
601 $(document).ready(function() {
603 * Row marking in horizontal mode (use "live" so that it works also for
604 * next pages reached via AJAX); a tr may have the class noclick to remove
607 $('tr.odd:not(.noclick), tr.even:not(.noclick)').live('click',function(e) {
608 // do not trigger when clicked on anchor
609 if ($(e.target).is('a, a *')) {
612 // XXX: FF fires two click events for <label> (label and checkbox), so we need to handle this differently
614 var $checkbox = $tr.find(':checkbox');
615 if ($checkbox.length) {
616 // checkbox in a row, add or remove class depending on checkbox state
617 var checked = $checkbox.attr('checked');
618 if (!$(e.target).is(':checkbox, label')) {
620 $checkbox.attr('checked', checked);
623 $tr.addClass('marked');
625 $tr.removeClass('marked');
628 // normaln data table, just toggle class
629 $tr.toggleClass('marked');
634 * Add a date/time picker to each element that needs it
636 $('.datefield, .datetimefield').each(function() {
637 PMA_addDatepicker($(this));
642 * Row highlighting in horizontal mode (use "live"
643 * so that it works also for pages reached via AJAX)
645 $(document).ready(function() {
646 $('tr.odd, tr.even').live('hover',function() {
648 $tr.toggleClass('hover');
649 $tr.children().toggleClass('hover');
654 * This array is used to remember mark status of rows in browse mode
656 var marked_row = new Array;
659 * marks all rows and selects its first checkbox inside the given element
660 * the given element is usaly a table or a div containing the table or tables
662 * @param container DOM element
664 function markAllRows( container_id ) {
666 $("#"+container_id).find("input:checkbox:enabled").attr('checked', 'checked')
667 .parents("tr").addClass("marked");
672 * marks all rows and selects its first checkbox inside the given element
673 * the given element is usaly a table or a div containing the table or tables
675 * @param container DOM element
677 function unMarkAllRows( container_id ) {
679 $("#"+container_id).find("input:checkbox:enabled").removeAttr('checked')
680 .parents("tr").removeClass("marked");
685 * Checks/unchecks all checkbox in given conainer (f.e. a form, fieldset or div)
687 * @param string container_id the container id
688 * @param boolean state new value for checkbox (true or false)
689 * @return boolean always true
691 function setCheckboxes( container_id, state ) {
694 $("#"+container_id).find("input:checkbox").attr('checked', 'checked');
697 $("#"+container_id).find("input:checkbox").removeAttr('checked');
701 } // end of the 'setCheckboxes()' function
704 * Checks/unchecks all options of a <select> element
706 * @param string the form name
707 * @param string the element name
708 * @param boolean whether to check or to uncheck the element
710 * @return boolean always true
712 function setSelectOptions(the_form, the_select, do_check)
716 $("form[name='"+ the_form +"']").find("select[name='"+the_select+"']").find("option").attr('selected', 'selected');
719 $("form[name='"+ the_form +"']").find("select[name="+the_select+"]").find("option").removeAttr('selected');
722 } // end of the 'setSelectOptions()' function
726 * Create quick sql statements.
729 function insertQuery(queryType) {
730 var myQuery = document.sqlform.sql_query;
731 var myListBox = document.sqlform.dummy;
733 var table = document.sqlform.table.value;
735 if (myListBox.options.length > 0) {
736 sql_box_locked = true;
741 for (var i=0; i < myListBox.options.length; i++) {
748 chaineAj += myListBox.options[i].value;
749 valDis += "[value-" + NbSelect + "]";
750 editDis += myListBox.options[i].value + "=[value-" + NbSelect + "]";
752 if (queryType == "selectall") {
753 query = "SELECT * FROM `" + table + "` WHERE 1";
754 } else if (queryType == "select") {
755 query = "SELECT " + chaineAj + " FROM `" + table + "` WHERE 1";
756 } else if (queryType == "insert") {
757 query = "INSERT INTO `" + table + "`(" + chaineAj + ") VALUES (" + valDis + ")";
758 } else if (queryType == "update") {
759 query = "UPDATE `" + table + "` SET " + editDis + " WHERE 1";
760 } else if(queryType == "delete") {
761 query = "DELETE FROM `" + table + "` WHERE 1";
762 } else if(queryType == "clear") {
765 document.sqlform.sql_query.value = query;
766 sql_box_locked = false;
772 * Inserts multiple fields.
775 function insertValueQuery() {
776 var myQuery = document.sqlform.sql_query;
777 var myListBox = document.sqlform.dummy;
779 if(myListBox.options.length > 0) {
780 sql_box_locked = true;
783 for(var i=0; i<myListBox.options.length; i++) {
784 if (myListBox.options[i].selected){
788 chaineAj += myListBox.options[i].value;
793 if (document.selection) {
795 sel = document.selection.createRange();
797 document.sqlform.insert.focus();
799 //MOZILLA/NETSCAPE support
800 else if (document.sqlform.sql_query.selectionStart || document.sqlform.sql_query.selectionStart == "0") {
801 var startPos = document.sqlform.sql_query.selectionStart;
802 var endPos = document.sqlform.sql_query.selectionEnd;
803 var chaineSql = document.sqlform.sql_query.value;
805 myQuery.value = chaineSql.substring(0, startPos) + chaineAj + chaineSql.substring(endPos, chaineSql.length);
807 myQuery.value += chaineAj;
809 sql_box_locked = false;
814 * listbox redirection
816 function goToUrl(selObj, goToLocation) {
817 eval("document.location.href = '" + goToLocation + "pos=" + selObj.options[selObj.selectedIndex].value + "'");
823 function getElement(e,f){
826 if(f.document.layers[e]) {
827 return f.document.layers[e];
829 for(W=0;W<f.document.layers.length;W++) {
830 return(getElement(e,f.document.layers[W]));
834 return document.all[e];
836 return document.getElementById(e);
840 * Refresh the WYSIWYG scratchboard after changes have been made
842 function refreshDragOption(e) {
843 var elm = $('#' + e);
844 if (elm.css('visibility') == 'visible') {
851 * Refresh/resize the WYSIWYG scratchboard
853 function refreshLayout() {
854 var elm = $('#pdflayout')
855 var orientation = $('#orientation_opt').val();
856 if($('#paper_opt').length==1){
857 var paper = $('#paper_opt').val();
861 if (orientation == 'P') {
868 elm.css('width', pdfPaperSize(paper, posa) + 'px');
869 elm.css('height', pdfPaperSize(paper, posb) + 'px');
873 * Show/hide the WYSIWYG scratchboard
875 function ToggleDragDrop(e) {
876 var elm = $('#' + e);
877 if (elm.css('visibility') == 'hidden') {
878 PDFinit(); /* Defined in pdf_pages.php */
879 elm.css('visibility', 'visible');
880 elm.css('display', 'block');
881 $('#showwysiwyg').val('1')
883 elm.css('visibility', 'hidden');
884 elm.css('display', 'none');
885 $('#showwysiwyg').val('0')
890 * PDF scratchboard: When a position is entered manually, update
891 * the fields inside the scratchboard.
893 function dragPlace(no, axis, value) {
894 var elm = $('#table_' + no);
896 elm.css('left', value + 'px');
898 elm.css('top', value + 'px');
903 * Returns paper sizes for a given format
905 function pdfPaperSize(format, axis) {
906 switch (format.toUpperCase()) {
908 if (axis == 'x') return 4767.87; else return 6740.79;
911 if (axis == 'x') return 3370.39; else return 4767.87;
914 if (axis == 'x') return 2383.94; else return 3370.39;
917 if (axis == 'x') return 1683.78; else return 2383.94;
920 if (axis == 'x') return 1190.55; else return 1683.78;
923 if (axis == 'x') return 841.89; else return 1190.55;
926 if (axis == 'x') return 595.28; else return 841.89;
929 if (axis == 'x') return 419.53; else return 595.28;
932 if (axis == 'x') return 297.64; else return 419.53;
935 if (axis == 'x') return 209.76; else return 297.64;
938 if (axis == 'x') return 147.40; else return 209.76;
941 if (axis == 'x') return 104.88; else return 147.40;
944 if (axis == 'x') return 73.70; else return 104.88;
947 if (axis == 'x') return 2834.65; else return 4008.19;
950 if (axis == 'x') return 2004.09; else return 2834.65;
953 if (axis == 'x') return 1417.32; else return 2004.09;
956 if (axis == 'x') return 1000.63; else return 1417.32;
959 if (axis == 'x') return 708.66; else return 1000.63;
962 if (axis == 'x') return 498.90; else return 708.66;
965 if (axis == 'x') return 354.33; else return 498.90;
968 if (axis == 'x') return 249.45; else return 354.33;
971 if (axis == 'x') return 175.75; else return 249.45;
974 if (axis == 'x') return 124.72; else return 175.75;
977 if (axis == 'x') return 87.87; else return 124.72;
980 if (axis == 'x') return 2599.37; else return 3676.54;
983 if (axis == 'x') return 1836.85; else return 2599.37;
986 if (axis == 'x') return 1298.27; else return 1836.85;
989 if (axis == 'x') return 918.43; else return 1298.27;
992 if (axis == 'x') return 649.13; else return 918.43;
995 if (axis == 'x') return 459.21; else return 649.13;
998 if (axis == 'x') return 323.15; else return 459.21;
1001 if (axis == 'x') return 229.61; else return 323.15;
1004 if (axis == 'x') return 161.57; else return 229.61;
1007 if (axis == 'x') return 113.39; else return 161.57;
1010 if (axis == 'x') return 79.37; else return 113.39;
1013 if (axis == 'x') return 2437.80; else return 3458.27;
1016 if (axis == 'x') return 1729.13; else return 2437.80;
1019 if (axis == 'x') return 1218.90; else return 1729.13;
1022 if (axis == 'x') return 864.57; else return 1218.90;
1025 if (axis == 'x') return 609.45; else return 864.57;
1028 if (axis == 'x') return 2551.18; else return 3628.35;
1031 if (axis == 'x') return 1814.17; else return 2551.18;
1034 if (axis == 'x') return 1275.59; else return 1814.17;
1037 if (axis == 'x') return 907.09; else return 1275.59;
1040 if (axis == 'x') return 637.80; else return 907.09;
1043 if (axis == 'x') return 612.00; else return 792.00;
1046 if (axis == 'x') return 612.00; else return 1008.00;
1049 if (axis == 'x') return 521.86; else return 756.00;
1052 if (axis == 'x') return 612.00; else return 936.00;
1060 * for playing media from the BLOB repository
1063 * @param var url_params main purpose is to pass the token
1064 * @param var bs_ref BLOB repository reference
1065 * @param var m_type type of BLOB repository media
1066 * @param var w_width width of popup window
1067 * @param var w_height height of popup window
1069 function popupBSMedia(url_params, bs_ref, m_type, is_cust_type, w_width, w_height)
1071 // if width not specified, use default
1072 if (w_width == undefined)
1075 // if height not specified, use default
1076 if (w_height == undefined)
1079 // open popup window (for displaying video/playing audio)
1080 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');
1084 * popups a request for changing MIME types for files in the BLOB repository
1086 * @param var db database name
1087 * @param var table table name
1088 * @param var reference BLOB repository reference
1089 * @param var current_mime_type current MIME type associated with BLOB repository reference
1091 function requestMIMETypeChange(db, table, reference, current_mime_type)
1093 // no mime type specified, set to default (nothing)
1094 if (undefined == current_mime_type)
1095 current_mime_type = "";
1097 // prompt user for new mime type
1098 var new_mime_type = prompt("Enter custom MIME type", current_mime_type);
1100 // if new mime_type is specified and is not the same as the previous type, request for mime type change
1101 if (new_mime_type && new_mime_type != current_mime_type)
1102 changeMIMEType(db, table, reference, new_mime_type);
1106 * changes MIME types for files in the BLOB repository
1108 * @param var db database name
1109 * @param var table table name
1110 * @param var reference BLOB repository reference
1111 * @param var mime_type new MIME type to be associated with BLOB repository reference
1113 function changeMIMEType(db, table, reference, mime_type)
1115 // specify url and parameters for jQuery POST
1116 var mime_chg_url = 'bs_change_mime_type.php';
1117 var params = {bs_db: db, bs_table: table, bs_reference: reference, bs_new_mime_type: mime_type};
1120 jQuery.post(mime_chg_url, params);
1124 * Jquery Coding for inline editing SQL_QUERY
1126 $(document).ready(function(){
1127 var oldText,db,table,token,sql_query;
1128 oldText=$(".inner_sql").html();
1129 $("#inline_edit").live('click',function(){
1130 db=$("input[name='db']").val();
1131 table=$("input[name='table']").val();
1132 token=$("input[name='token']").val();
1133 sql_query=$("input[name='sql_query']").val();
1134 $(".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'] + "\">");
1138 $("#btnSave").live("click",function(){
1139 window.location.replace("import.php?db=" + db +"&table=" + table + "&sql_query=" + $("#sql_query_edit").val()+"&show_query=1&token=" + token + "");
1142 $("#btnDiscard").live("click",function(){
1143 $(".sql").html("<span class=\"syntax\"><span class=\"inner_sql\">" + oldText + "</span></span>");
1146 $('.sqlbutton').click(function(evt){
1147 insertQuery(evt.target.id);
1151 $("#export_type").change(function(){
1152 if($("#export_type").val()=='svg'){
1153 $("#show_grid_opt").attr("disabled","disabled");
1154 $("#orientation_opt").attr("disabled","disabled");
1155 $("#with_doc").attr("disabled","disabled");
1156 $("#show_table_dim_opt").removeAttr("disabled");
1157 $("#all_table_same_wide").removeAttr("disabled");
1158 $("#paper_opt").removeAttr("disabled","disabled");
1159 $("#show_color_opt").removeAttr("disabled","disabled");
1160 //$(this).css("background-color","yellow");
1161 }else if($("#export_type").val()=='dia'){
1162 $("#show_grid_opt").attr("disabled","disabled");
1163 $("#with_doc").attr("disabled","disabled");
1164 $("#show_table_dim_opt").attr("disabled","disabled");
1165 $("#all_table_same_wide").attr("disabled","disabled");
1166 $("#paper_opt").removeAttr("disabled","disabled");
1167 $("#show_color_opt").removeAttr("disabled","disabled");
1168 $("#orientation_opt").removeAttr("disabled","disabled");
1169 }else if($("#export_type").val()=='eps'){
1170 $("#show_grid_opt").attr("disabled","disabled");
1171 $("#orientation_opt").removeAttr("disabled");
1172 $("#with_doc").attr("disabled","disabled");
1173 $("#show_table_dim_opt").attr("disabled","disabled");
1174 $("#all_table_same_wide").attr("disabled","disabled");
1175 $("#paper_opt").attr("disabled","disabled");
1176 $("#show_color_opt").attr("disabled","disabled");
1178 }else if($("#export_type").val()=='pdf'){
1179 $("#show_grid_opt").removeAttr("disabled");
1180 $("#orientation_opt").removeAttr("disabled");
1181 $("#with_doc").removeAttr("disabled","disabled");
1182 $("#show_table_dim_opt").removeAttr("disabled","disabled");
1183 $("#all_table_same_wide").removeAttr("disabled","disabled");
1184 $("#paper_opt").removeAttr("disabled","disabled");
1185 $("#show_color_opt").removeAttr("disabled","disabled");
1191 $('#sqlquery').focus();
1192 if ($('#input_username')) {
1193 if ($('#input_username').val() == '') {
1194 $('#input_username').focus();
1196 $('#input_password').focus();
1202 * Show a message on the top of the page for an Ajax request
1204 * @param var message string containing the message to be shown.
1205 * optional, defaults to 'Loading...'
1206 * @param var timeout number of milliseconds for the message to be visible
1207 * optional, defaults to 5000
1210 function PMA_ajaxShowMessage(message, timeout) {
1212 //Handle the case when a empty data.message is passed. We don't want the empty message
1218 * @var msg String containing the message that has to be displayed
1219 * @default PMA_messages['strLoading']
1222 var msg = PMA_messages['strLoading'];
1229 * @var timeout Number of milliseconds for which {@link msg} will be visible
1239 if( !ajax_message_init) {
1240 //For the first time this function is called, append a new div
1242 $('<div id="loading_parent"></div>')
1243 .insertBefore("#serverinfo");
1245 $('<span id="loading" class="ajax_notification"></span>')
1246 .appendTo("#loading_parent")
1250 .fadeOut('medium', function(){
1252 .html("") //Clear the message
1255 }, 'top.frame_content');
1256 ajax_message_init = true;
1259 //Otherwise, just show the div again after inserting the message
1265 .fadeOut('medium', function() {
1272 return $("#loading");
1276 * Removes the message shown for an Ajax operation when it's completed
1278 function PMA_ajaxRemoveMessage($this_msgbox) {
1281 .fadeOut('medium', function() {
1282 $this_msgbox.hide();
1287 * Hides/shows the "Open in ENUM/SET editor" message, depending on the data type of the column currently selected
1289 function PMA_showNoticeForEnum(selectElement) {
1290 var enum_notice_id = selectElement.attr("id").split("_")[1];
1291 enum_notice_id += "_" + (parseInt(selectElement.attr("id").split("_")[2]) + 1);
1292 var selectedType = selectElement.attr("value");
1293 if (selectedType == "ENUM" || selectedType == "SET") {
1294 $("p[id='enum_notice_" + enum_notice_id + "']").show();
1296 $("p[id='enum_notice_" + enum_notice_id + "']").hide();
1301 * jQuery function that uses jQueryUI's dialogs to confirm with user. Does not
1302 * return a jQuery object yet and hence cannot be chained
1304 * @param string question
1305 * @param string url URL to be passed to the callbackFn to make
1307 * @param function callbackFn callback to execute after user clicks on OK
1310 jQuery.fn.PMA_confirm = function(question, url, callbackFn) {
1311 if (PMA_messages['strDoYouReally'] == '') {
1316 * @var button_options Object that stores the options passed to jQueryUI
1319 var button_options = {};
1320 button_options[PMA_messages['strOK']] = function(){
1321 $(this).dialog("close").remove();
1323 if($.isFunction(callbackFn)) {
1324 callbackFn.call(this, url);
1327 button_options[PMA_messages['strCancel']] = function() {$(this).dialog("close").remove();}
1329 $('<div id="confirm_dialog"></div>')
1331 .dialog({buttons: button_options});
1335 * jQuery function to sort a table's body after a new row has been appended to it.
1336 * Also fixes the even/odd classes of the table rows at the end.
1338 * @param string text_selector string to select the sortKey's text
1340 * @return jQuery Object for chaining purposes
1342 jQuery.fn.PMA_sort_table = function(text_selector) {
1343 return this.each(function() {
1346 * @var table_body Object referring to the table's <tbody> element
1348 var table_body = $(this);
1350 * @var rows Object referring to the collection of rows in {@link table_body}
1352 var rows = $(this).find('tr').get();
1354 //get the text of the field that we will sort by
1355 $.each(rows, function(index, row) {
1356 row.sortKey = $.trim($(row).find(text_selector).text().toLowerCase());
1359 //get the sorted order
1360 rows.sort(function(a,b) {
1361 if(a.sortKey < b.sortKey) {
1364 if(a.sortKey > b.sortKey) {
1370 //pull out each row from the table and then append it according to it's order
1371 $.each(rows, function(index, row) {
1372 $(table_body).append(row);
1376 //Re-check the classes of each row
1377 $(this).find('tr:odd')
1378 .removeClass('even').addClass('odd')
1381 .removeClass('odd').addClass('even');
1386 * jQuery coding for 'Create Table'. Used on db_operations.php,
1387 * db_structure.php and db_tracking.php (i.e., wherever
1388 * libraries/display_create_table.lib.php is used)
1390 * Attach Ajax Event handlers for Create Table
1392 $(document).ready(function() {
1395 * Attach event handler to the submit action of the create table minimal form
1396 * and retrieve the full table form and display it in a dialog
1398 * @uses PMA_ajaxShowMessage()
1400 $("#create_table_form_minimal.ajax").live('submit', function(event) {
1401 event.preventDefault();
1404 /* @todo Validate this form! */
1407 * @var button_options Object that stores the options passed to jQueryUI
1410 var button_options = {};
1411 // in the following function we need to use $(this)
1412 button_options[PMA_messages['strCancel']] = function() {$(this).dialog('close').remove();}
1414 var button_options_error = {};
1415 button_options_error[PMA_messages['strOK']] = function() {$(this).dialog('close').remove();}
1417 var $msgbox = PMA_ajaxShowMessage();
1418 PMA_prepareForAjaxRequest($form);
1420 $.get($form.attr('action'), $form.serialize(), function(data) {
1421 //in the case of an error, show the error message returned.
1422 if (data.success != undefined && data.success == false) {
1423 $('<div id="create_table_dialog"></div>')
1426 title: PMA_messages['strCreateTable'],
1429 open: PMA_verifyTypeOfAllColumns,
1430 buttons : button_options_error
1431 })// end dialog options
1432 //remove the redundant [Back] link in the error message.
1433 .find('fieldset').remove();
1435 $('<div id="create_table_dialog"></div>')
1438 title: PMA_messages['strCreateTable'],
1441 open: PMA_verifyTypeOfAllColumns,
1442 buttons : button_options
1443 }); // end dialog options
1445 PMA_ajaxRemoveMessage($msgbox);
1448 // empty table name and number of columns from the minimal form
1449 $form.find('input[name=table],input[name=num_fields]').val('');
1453 * Attach event handler for submission of create table form (save)
1455 * @uses PMA_ajaxShowMessage()
1456 * @uses $.PMA_sort_table()
1459 // .live() must be called after a selector, see http://api.jquery.com/live
1460 $("#create_table_form input[name=do_save_data]").live('click', function(event) {
1461 event.preventDefault();
1464 * @var the_form object referring to the create table form
1466 var $form = $("#create_table_form");
1469 * First validate the form; if there is a problem, avoid submitting it
1471 * checkTableEditForm() needs a pure element and not a jQuery object,
1472 * this is why we pass $form[0] as a parameter (the jQuery object
1473 * is actually an array of DOM elements)
1476 if (checkTableEditForm($form[0], $form.find('input[name=orig_num_fields]').val())) {
1477 // OK, form passed validation step
1478 if ($form.hasClass('ajax')) {
1479 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
1480 PMA_prepareForAjaxRequest($form);
1481 //User wants to submit the form
1482 $.post($form.attr('action'), $form.serialize() + "&do_save_data=" + $(this).val(), function(data) {
1483 if(data.success == true) {
1484 $('#properties_message')
1485 .removeClass('error')
1487 PMA_ajaxShowMessage(data.message);
1488 // Only if the create table dialog (distinct panel) exists
1489 if ($("#create_table_dialog").length > 0) {
1490 $("#create_table_dialog").dialog("close").remove();
1494 * @var tables_table Object referring to the <tbody> element that holds the list of tables
1496 var tables_table = $("#tablesForm").find("tbody").not("#tbl_summary_row");
1497 // this is the first table created in this db
1498 if (tables_table.length == 0) {
1499 if (window.parent && window.parent.frame_content) {
1500 window.parent.frame_content.location.reload();
1504 * @var curr_last_row Object referring to the last <tr> element in {@link tables_table}
1506 var curr_last_row = $(tables_table).find('tr:last');
1508 * @var curr_last_row_index_string String containing the index of {@link curr_last_row}
1510 var curr_last_row_index_string = $(curr_last_row).find('input:checkbox').attr('id').match(/\d+/)[0];
1512 * @var curr_last_row_index Index of {@link curr_last_row}
1514 var curr_last_row_index = parseFloat(curr_last_row_index_string);
1516 * @var new_last_row_index Index of the new row to be appended to {@link tables_table}
1518 var new_last_row_index = curr_last_row_index + 1;
1520 * @var new_last_row_id String containing the id of the row to be appended to {@link tables_table}
1522 var new_last_row_id = 'checkbox_tbl_' + new_last_row_index;
1524 data.new_table_string = data.new_table_string.replace(/checkbox_tbl_/, new_last_row_id);
1526 $(data.new_table_string)
1527 .appendTo(tables_table);
1530 $(tables_table).PMA_sort_table('th');
1533 //Refresh navigation frame as a new table has been added
1534 if (window.parent && window.parent.frame_navigation) {
1535 window.parent.frame_navigation.location.reload();
1538 $('#properties_message')
1541 // scroll to the div containing the error message
1542 $('#properties_message')[0].scrollIntoView();
1545 } // end if ($form.hasClass('ajax')
1548 $form.append('<input type="hidden" name="do_save_data" value="save" />');
1551 } // end if (checkTableEditForm() )
1552 }) // end create table form (save)
1555 * Attach event handler for create table form (add fields)
1557 * @uses PMA_ajaxShowMessage()
1558 * @uses $.PMA_sort_table()
1559 * @uses window.parent.refreshNavigation()
1562 // .live() must be called after a selector, see http://api.jquery.com/live
1563 $("#create_table_form.ajax input[name=submit_num_fields]").live('click', function(event) {
1564 event.preventDefault();
1567 * @var the_form object referring to the create table form
1569 var $form = $("#create_table_form");
1571 var $msgbox = PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
1572 PMA_prepareForAjaxRequest($form);
1574 //User wants to add more fields to the table
1575 $.post($form.attr('action'), $form.serialize() + "&submit_num_fields=" + $(this).val(), function(data) {
1576 // if 'create_table_dialog' exists
1577 if ($("#create_table_dialog").length > 0) {
1578 $("#create_table_dialog").html(data);
1580 // if 'create_table_div' exists
1581 if ($("#create_table_div").length > 0) {
1582 $("#create_table_div").html(data);
1584 PMA_verifyTypeOfAllColumns();
1585 PMA_ajaxRemoveMessage($msgbox);
1588 }) // end create table form (add fields)
1590 }, 'top.frame_content'); //end $(document).ready for 'Create Table'
1593 * Attach Ajax event handlers for Drop Trigger. Used on tbl_structure.php
1594 * @see $cfg['AjaxEnable']
1596 $(document).ready(function() {
1598 $(".drop_trigger_anchor").live('click', function(event) {
1599 event.preventDefault();
1603 * @var curr_row Object reference to the current trigger's <tr>
1605 var $curr_row = $anchor.parents('tr');
1607 * @var question String containing the question to be asked for confirmation
1609 var question = 'DROP TRIGGER IF EXISTS `' + $curr_row.children('td:first').text() + '`';
1611 $anchor.PMA_confirm(question, $anchor.attr('href'), function(url) {
1613 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
1614 $.get(url, {'is_js_confirmed': 1, 'ajax_request': true}, function(data) {
1615 if(data.success == true) {
1616 PMA_ajaxShowMessage(data.message);
1617 $("#topmenucontainer")
1621 .after(data.sql_query);
1622 $curr_row.hide("medium").remove();
1625 PMA_ajaxShowMessage(data.error);
1628 }) // end $.PMA_confirm()
1629 }) // end $().live()
1630 }, 'top.frame_content'); //end $(document).ready() for Drop Trigger
1633 * Attach Ajax event handlers for Drop Database. Moved here from db_structure.js
1634 * as it was also required on db_create.php
1636 * @uses $.PMA_confirm()
1637 * @uses PMA_ajaxShowMessage()
1638 * @uses window.parent.refreshNavigation()
1639 * @uses window.parent.refreshMain()
1640 * @see $cfg['AjaxEnable']
1642 $(document).ready(function() {
1643 $("#drop_db_anchor").live('click', function(event) {
1644 event.preventDefault();
1646 //context is top.frame_content, so we need to use window.parent.db to access the db var
1648 * @var question String containing the question to be asked for confirmation
1650 var question = PMA_messages['strDropDatabaseStrongWarning'] + '\n' + PMA_messages['strDoYouReally'] + ' :\n' + 'DROP DATABASE ' + window.parent.db;
1652 $(this).PMA_confirm(question, $(this).attr('href') ,function(url) {
1654 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
1655 $.get(url, {'is_js_confirmed': '1', 'ajax_request': true}, function(data) {
1656 //Database deleted successfully, refresh both the frames
1657 window.parent.refreshNavigation();
1658 window.parent.refreshMain();
1660 }); // end $.PMA_confirm()
1661 }); //end of Drop Database Ajax action
1662 }) // end of $(document).ready() for Drop Database
1665 * Attach Ajax event handlers for 'Create Database'. Used wherever libraries/
1666 * display_create_database.lib.php is used, ie main.php and server_databases.php
1668 * @uses PMA_ajaxShowMessage()
1669 * @see $cfg['AjaxEnable']
1671 $(document).ready(function() {
1673 $('#create_database_form.ajax').live('submit', function(event) {
1674 event.preventDefault();
1678 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
1679 PMA_prepareForAjaxRequest($form);
1681 $.post($form.attr('action'), $form.serialize(), function(data) {
1682 if(data.success == true) {
1683 PMA_ajaxShowMessage(data.message);
1685 //Append database's row to table
1686 $("#tabledatabases")
1688 .append(data.new_db_string)
1689 .PMA_sort_table('.name')
1690 .find('#db_summary_row')
1691 .appendTo('#tabledatabases tbody')
1692 .removeClass('odd even');
1694 var $databases_count_object = $('#databases_count');
1695 var databases_count = parseInt($databases_count_object.text());
1696 $databases_count_object.text(++databases_count);
1697 //Refresh navigation frame as a new database has been added
1698 if (window.parent && window.parent.frame_navigation) {
1699 window.parent.frame_navigation.location.reload();
1703 PMA_ajaxShowMessage(data.error);
1706 }) // end $().live()
1707 }) // end $(document).ready() for Create Database
1710 * Attach Ajax event handlers for 'Change Password' on main.php
1712 $(document).ready(function() {
1715 * Attach Ajax event handler on the change password anchor
1716 * @see $cfg['AjaxEnable']
1718 $('#change_password_anchor.dialog_active').live('click',function(event) {
1719 event.preventDefault();
1722 $('#change_password_anchor.ajax').live('click', function(event) {
1723 event.preventDefault();
1724 $(this).removeClass('ajax').addClass('dialog_active');
1726 * @var button_options Object containing options to be passed to jQueryUI's dialog
1728 var button_options = {};
1729 button_options[PMA_messages['strCancel']] = function() {$(this).dialog('close').remove();}
1730 $.get($(this).attr('href'), {'ajax_request': true}, function(data) {
1731 $('<div id="change_password_dialog"></div>')
1733 title: PMA_messages['strChangePassword'],
1735 close: function(ev,ui) {$(this).remove();},
1736 buttons : button_options,
1737 beforeClose: function(ev,ui){ $('#change_password_anchor.dialog_active').removeClass('dialog_active').addClass('ajax')}
1740 displayPasswordGenerateButton();
1742 }) // end handler for change password anchor
1745 * Attach Ajax event handler for Change Password form submission
1747 * @uses PMA_ajaxShowMessage()
1748 * @see $cfg['AjaxEnable']
1750 $("#change_password_form.ajax").find('input[name=change_pw]').live('click', function(event) {
1751 event.preventDefault();
1754 * @var the_form Object referring to the change password form
1756 var the_form = $("#change_password_form");
1759 * @var this_value String containing the value of the submit button.
1760 * Need to append this for the change password form on Server Privileges
1763 var this_value = $(this).val();
1765 var $msgbox = PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
1766 $(the_form).append('<input type="hidden" name="ajax_request" value="true" />');
1768 $.post($(the_form).attr('action'), $(the_form).serialize() + '&change_pw='+ this_value, function(data) {
1769 if(data.success == true) {
1770 $("#topmenucontainer").after(data.sql_query);
1771 $("#change_password_dialog").hide().remove();
1772 $("#edit_user_dialog").dialog("close").remove();
1773 $('#change_password_anchor.dialog_active').removeClass('dialog_active').addClass('ajax');
1774 PMA_ajaxRemoveMessage($msgbox);
1777 PMA_ajaxShowMessage(data.error);
1780 }) // end handler for Change Password form submission
1781 }) // end $(document).ready() for Change Password
1784 * Toggle the hiding/showing of the "Open in ENUM/SET editor" message when
1785 * the page loads and when the selected data type changes
1787 $(document).ready(function() {
1788 // is called here for normal page loads and also when opening
1789 // the Create table dialog
1790 PMA_verifyTypeOfAllColumns();
1792 // needs live() to work also in the Create Table dialog
1793 $("select[class='column_type']").live('change', function() {
1794 PMA_showNoticeForEnum($(this));
1798 function PMA_verifyTypeOfAllColumns() {
1799 $("select[class='column_type']").each(function() {
1800 PMA_showNoticeForEnum($(this));
1805 * Closes the ENUM/SET editor and removes the data in it
1807 function disable_popup() {
1808 $("#popup_background").fadeOut("fast");
1809 $("#enum_editor").fadeOut("fast");
1810 // clear the data from the text boxes
1811 $("#enum_editor #values input").remove();
1812 $("#enum_editor input[type='hidden']").remove();
1816 * Opens the ENUM/SET editor and controls its functions
1818 $(document).ready(function() {
1819 // Needs live() to work also in the Create table dialog
1820 $("a[class='open_enum_editor']").live('click', function() {
1822 var windowWidth = document.documentElement.clientWidth;
1823 var windowHeight = document.documentElement.clientHeight;
1824 var popupWidth = windowWidth/2;
1825 var popupHeight = windowHeight*0.8;
1826 var popupOffsetTop = windowHeight/2 - popupHeight/2;
1827 var popupOffsetLeft = windowWidth/2 - popupWidth/2;
1828 $("#enum_editor").css({"position":"absolute", "top": popupOffsetTop, "left": popupOffsetLeft, "width": popupWidth, "height": popupHeight});
1831 $("#popup_background").css({"opacity":"0.7"});
1832 $("#popup_background").fadeIn("fast");
1833 $("#enum_editor").fadeIn("fast");
1836 var values = $(this).parent().prev("input").attr("value").split(",");
1837 $.each(values, function(index, val) {
1838 if(jQuery.trim(val) != "") {
1839 // enclose the string in single quotes if it's not already
1840 if(val.substr(0, 1) != "'") {
1843 if(val.substr(val.length-1, val.length) != "'") {
1846 // escape the single quotes, except the mandatory ones enclosing the entire string
1847 val = val.substr(1, val.length-2).replace(/''/g, "'").replace(/\\\\/g, '\\').replace(/\\'/g, "'").replace(/'/g, "'");
1848 // escape the greater-than symbol
1849 val = val.replace(/>/g, ">");
1850 $("#enum_editor #values").append("<input type='text' value=" + val + " />");
1853 // So we know which column's data is being edited
1854 $("#enum_editor").append("<input type='hidden' value='" + $(this).parent().prev("input").attr("id") + "' />");
1858 // If the "close" link is clicked, close the enum editor
1859 // Needs live() to work also in the Create table dialog
1860 $("a[class='close_enum_editor']").live('click', function() {
1864 // If the "cancel" link is clicked, close the enum editor
1865 // Needs live() to work also in the Create table dialog
1866 $("a[class='cancel_enum_editor']").live('click', function() {
1870 // When "add a new value" is clicked, append an empty text field
1871 // Needs live() to work also in the Create table dialog
1872 $("a[class='add_value']").live('click', function() {
1873 $("#enum_editor #values").append("<input type='text' />");
1876 // When the submit button is clicked, put the data back into the original form
1877 // Needs live() to work also in the Create table dialog
1878 $("#enum_editor input[type='submit']").live('click', function() {
1879 var value_array = new Array();
1880 $.each($("#enum_editor #values input"), function(index, input_element) {
1881 val = jQuery.trim(input_element.value);
1883 value_array.push("'" + val.replace(/\\/g, '\\\\').replace(/'/g, "''") + "'");
1886 // get the Length/Values text field where this value belongs
1887 var values_id = $("#enum_editor input[type='hidden']").attr("value");
1888 $("input[id='" + values_id + "']").attr("value", value_array.join(","));
1893 * Hides certain table structure actions, replacing them with the word "More". They are displayed
1894 * in a dropdown menu when the user hovers over the word "More."
1896 // Remove the actions from the table cells (they are available by default for JavaScript-disabled browsers)
1897 // if the table is not a view or information_schema (otherwise there is only one action to hide and there's no point)
1898 if($("input[type='hidden'][name='table_type']").val() == "table") {
1899 var $table = $("table[id='tablestructure']");
1900 $table.find("td[class='browse']").remove();
1901 $table.find("td[class='primary']").remove();
1902 $table.find("td[class='unique']").remove();
1903 $table.find("td[class='index']").remove();
1904 $table.find("td[class='fulltext']").remove();
1905 $table.find("th[class='action']").attr("colspan", 3);
1907 // Display the "more" text
1908 $table.find("td[class='more_opts']").show();
1910 // Position the dropdown
1911 $(".structure_actions_dropdown").each(function() {
1912 // Optimize DOM querying
1913 var $this_dropdown = $(this);
1914 // The top offset must be set for IE even if it didn't change
1915 var cell_right_edge_offset = $this_dropdown.parent().offset().left + $this_dropdown.parent().innerWidth();
1916 var left_offset = cell_right_edge_offset - $this_dropdown.innerWidth();
1917 var top_offset = $this_dropdown.parent().offset().top + $this_dropdown.parent().innerHeight();
1918 $this_dropdown.offset({ top: top_offset, left: left_offset });
1921 // A hack for IE6 to prevent the after_field select element from being displayed on top of the dropdown by
1922 // positioning an iframe directly on top of it
1923 var $after_field = $("select[name='after_field']");
1924 $("iframe[class='IE_hack']")
1925 .width($after_field.width())
1926 .height($after_field.height())
1928 top: $after_field.offset().top,
1929 left: $after_field.offset().left
1932 // When "more" is hovered over, show the hidden actions
1933 $table.find("td[class='more_opts']")
1934 .mouseenter(function() {
1935 if($.browser.msie && $.browser.version == "6.0") {
1936 $("iframe[class='IE_hack']")
1938 .width($after_field.width()+4)
1939 .height($after_field.height()+4)
1941 top: $after_field.offset().top,
1942 left: $after_field.offset().left
1945 $(".structure_actions_dropdown").hide(); // Hide all the other ones that may be open
1946 $(this).children(".structure_actions_dropdown").show();
1947 // Need to do this again for IE otherwise the offset is wrong
1948 if($.browser.msie) {
1949 var left_offset_IE = $(this).offset().left + $(this).innerWidth() - $(this).children(".structure_actions_dropdown").innerWidth();
1950 var top_offset_IE = $(this).offset().top + $(this).innerHeight();
1951 $(this).children(".structure_actions_dropdown").offset({
1953 left: left_offset_IE });
1956 .mouseleave(function() {
1957 $(this).children(".structure_actions_dropdown").hide();
1958 if($.browser.msie && $.browser.version == "6.0") {
1959 $("iframe[class='IE_hack']").hide();
1965 /* Displays tooltips */
1966 $(document).ready(function() {
1967 // Hide the footnotes from the footer (which are displayed for
1968 // JavaScript-disabled browsers) since the tooltip is sufficient
1969 $(".footnotes").hide();
1970 $(".footnotes span").each(function() {
1971 $(this).children("sup").remove();
1973 // The border and padding must be removed otherwise a thin yellow box remains visible
1974 $(".footnotes").css("border", "none");
1975 $(".footnotes").css("padding", "0px");
1977 // Replace the superscripts with the help icon
1978 $("sup[class='footnotemarker']").hide();
1979 $("img[class='footnotemarker']").show();
1981 $("img[class='footnotemarker']").each(function() {
1982 var span_id = $(this).attr("id");
1983 span_id = span_id.split("_")[1];
1984 var tooltip_text = $(".footnotes span[id='footnote_" + span_id + "']").html();
1986 content: tooltip_text,
1988 hide: { when: 'unfocus', delay: 0 },
1989 style: { background: '#ffffcc' }
1994 function menuResize()
1996 var cnt = $('#topmenu');
1997 var wmax = cnt.innerWidth() - 5; // 5 px margin for jumping menu in Chrome
1998 var submenu = cnt.find('.submenu');
1999 var submenu_w = submenu.outerWidth(true);
2000 var submenu_ul = submenu.find('ul');
2001 var li = cnt.find('> li');
2002 var li2 = submenu_ul.find('li');
2003 var more_shown = li2.length > 0;
2004 var w = more_shown ? submenu_w : 0;
2008 for (var i = 0; i < li.length-1; i++) { // li.length-1: skip .submenu element
2010 var el_width = el.outerWidth(true);
2011 el.data('width', el_width);
2015 if (w + submenu_w < wmax) {
2019 w -= $(li[i-1]).data('width');
2025 if (hide_start > 0) {
2026 for (var i = hide_start; i < li.length-1; i++) {
2027 $(li[i])[more_shown ? 'prependTo' : 'appendTo'](submenu_ul);
2029 submenu.addClass('shown');
2030 } else if (more_shown) {
2032 // nothing hidden, maybe something can be restored
2033 for (var i = 0; i < li2.length; i++) {
2034 //console.log(li2[i], submenu_w);
2035 w += $(li2[i]).data('width');
2036 // item fits or (it is the last item and it would fit if More got removed)
2037 if (w+submenu_w < wmax || (i == li2.length-1 && w < wmax)) {
2038 $(li2[i]).insertBefore(submenu);
2039 if (i == li2.length-1) {
2040 submenu.removeClass('shown');
2047 if (submenu.find('.tabactive').length) {
2048 submenu.addClass('active').find('> a').removeClass('tab').addClass('tabactive');
2050 submenu.removeClass('active').find('> a').addClass('tab').removeClass('tabactive');
2055 var topmenu = $('#topmenu');
2056 if (topmenu.length == 0) {
2059 // create submenu container
2060 var link = $('<a />', {href: '#', 'class': 'tab'})
2061 .text(PMA_messages['strMore'])
2062 .click(function(e) {
2065 var img = topmenu.find('li:first-child img');
2067 img.clone().attr('src', img.attr('src').replace(/\/[^\/]+$/, '/b_more.png')).prependTo(link);
2069 var submenu = $('<li />', {'class': 'submenu'})
2071 .append($('<ul />'))
2072 .mouseenter(function() {
2073 if ($(this).find('ul .tabactive').length == 0) {
2074 $(this).addClass('submenuhover').find('> a').addClass('tabactive');
2077 .mouseleave(function() {
2078 if ($(this).find('ul .tabactive').length == 0) {
2079 $(this).removeClass('submenuhover').find('> a').removeClass('tabactive');
2082 topmenu.append(submenu);
2084 // populate submenu and register resize event
2085 $(window).resize(menuResize);
2090 * For the checkboxes in browse mode, handles the shift/click (only works
2091 * in horizontal mode) and propagates the click to the "companion" checkbox
2092 * (in both horizontal and vertical). Works also for pages reached via AJAX.
2094 $(document).ready(function() {
2095 $('.multi_checkbox').live('click',function(e) {
2096 var current_checkbox_id = this.id;
2097 var left_checkbox_id = current_checkbox_id.replace('_right', '_left');
2098 var right_checkbox_id = current_checkbox_id.replace('_left', '_right');
2099 var other_checkbox_id = '';
2100 if (current_checkbox_id == left_checkbox_id) {
2101 other_checkbox_id = right_checkbox_id;
2103 other_checkbox_id = left_checkbox_id;
2106 var $current_checkbox = $('#' + current_checkbox_id);
2107 var $other_checkbox = $('#' + other_checkbox_id);
2110 var index_of_current_checkbox = $('.multi_checkbox').index($current_checkbox);
2111 var $last_checkbox = $('.multi_checkbox').filter('.last_clicked');
2112 var index_of_last_click = $('.multi_checkbox').index($last_checkbox);
2113 $('.multi_checkbox')
2114 .filter(function(index) {
2115 // the first clicked row can be on a row above or below the
2116 // shift-clicked row
2117 return (index_of_current_checkbox > index_of_last_click && index > index_of_last_click && index < index_of_current_checkbox)
2118 || (index_of_last_click > index_of_current_checkbox && index < index_of_last_click && index > index_of_current_checkbox);
2120 .each(function(index) {
2121 var $intermediate_checkbox = $(this);
2122 if ($current_checkbox.is(':checked')) {
2123 $intermediate_checkbox.attr('checked', true);
2125 $intermediate_checkbox.attr('checked', false);
2130 $('.multi_checkbox').removeClass('last_clicked');
2131 $current_checkbox.addClass('last_clicked');
2133 // When there is a checkbox on both ends of the row, propagate the
2134 // click on one of them to the other one.
2135 // (the default action has not been prevented so if we have
2136 // just clicked, this "if" is true)
2137 if ($current_checkbox.is(':checked')) {
2138 $other_checkbox.attr('checked', true);
2140 $other_checkbox.attr('checked', false);
2143 }) // end of $(document).ready() for multi checkbox
2146 * Get the row number from the classlist (for example, row_1)
2148 function PMA_getRowNumber(classlist) {
2149 return parseInt(classlist.split(/row_/)[1]);
2153 * Changes status of slider
2155 function PMA_set_status_label(id) {
2156 if ($('#' + id).css('display') == 'none') {
2157 $('#anchor_status_' + id).text('+ ');
2159 $('#anchor_status_' + id).text('- ');
2164 * Initializes slider effect.
2166 function PMA_init_slider() {
2167 $('.pma_auto_slider').each(function(idx, e) {
2168 if ($(e).hasClass('slider_init_done')) return;
2169 $(e).addClass('slider_init_done');
2170 $('<span id="anchor_status_' + e.id + '"></span>')
2172 PMA_set_status_label(e.id);
2174 $('<a href="#' + e.id + '" id="anchor_' + e.id + '">' + e.title + '</a>')
2177 $('#' + e.id).toggle('clip', function() {
2178 PMA_set_status_label(e.id);
2188 $(document).ready(function() {
2189 $('.vpointer').live('hover',
2192 var $this_td = $(this);
2193 var row_num = PMA_getRowNumber($this_td.attr('class'));
2194 // for all td of the same vertical row, toggle hover
2195 $('.vpointer').filter('.row_' + row_num).toggleClass('hover');
2198 }) // end of $(document).ready() for vertical pointer
2200 $(document).ready(function() {
2204 $('.vmarker').live('click', function(e) {
2205 var $this_td = $(this);
2206 var row_num = PMA_getRowNumber($this_td.attr('class'));
2207 // for all td of the same vertical row, toggle the marked class
2208 $('.vmarker').filter('.row_' + row_num).toggleClass('marked');
2212 * Reveal visual builder anchor
2215 $('#visual_builder_anchor').show();
2218 * Page selector in db Structure (non-AJAX)
2220 $('#tableslistcontainer').find('#pageselector').live('change', function() {
2221 $(this).parent("form").submit();
2225 * Page selector in navi panel (non-AJAX)
2227 $('#navidbpageselector').find('#pageselector').live('change', function() {
2228 $(this).parent("form").submit();
2232 * Page selector in browse_foreigners windows (non-AJAX)
2234 $('#body_browse_foreigners').find('#pageselector').live('change', function() {
2235 $(this).closest("form").submit();
2239 * Load version information asynchronously.
2241 if ($('.jsversioncheck').length > 0) {
2243 var s = document.createElement('script');
2244 s.type = 'text/javascript';
2246 s.src = 'http://www.phpmyadmin.net/home_page/version.js';
2247 s.onload = PMA_current_version;
2248 var x = document.getElementsByTagName('script')[0];
2249 x.parentNode.insertBefore(s, x);
2259 * Enables the text generated by PMA_linkOrButton() to be clickable
2261 $('.clickprevimage')
2262 .css('color', function(index) {
2263 return $('a').css('color');
2265 .css('cursor', function(index) {
2266 return $('a').css('cursor');
2267 }) //todo: hover effect
2268 .live('click',function(e) {
2269 $this_span = $(this);
2270 if ($this_span.closest('td').is('.inline_edit_anchor')) {
2271 // this would bind a second click event to the inline edit
2272 // anchor and would disturb its behavior
2274 $this_span.parent().find('input:image').click();
2278 }) // end of $(document).ready()