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")
1238 .fadeOut('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
1253 .fadeOut('medium', function() {
1260 return $("#loading");
1264 * Removes the message shown for an Ajax operation when it's completed
1266 function PMA_ajaxRemoveMessage($this_msgbox
) {
1269 .fadeOut('medium', function() {
1270 $this_msgbox
.hide();
1275 * Hides/shows the "Open in ENUM/SET editor" message, depending on the data type of the column currently selected
1277 function PMA_showNoticeForEnum(selectElement
) {
1278 var enum_notice_id
= selectElement
.attr("id").split("_")[1];
1279 enum_notice_id
+= "_" + (parseInt(selectElement
.attr("id").split("_")[2]) + 1);
1280 var selectedType
= selectElement
.attr("value");
1281 if (selectedType
== "ENUM" || selectedType
== "SET") {
1282 $("p[id='enum_notice_" + enum_notice_id
+ "']").show();
1284 $("p[id='enum_notice_" + enum_notice_id
+ "']").hide();
1289 * jQuery function that uses jQueryUI's dialogs to confirm with user. Does not
1290 * return a jQuery object yet and hence cannot be chained
1292 * @param string question
1293 * @param string url URL to be passed to the callbackFn to make
1295 * @param function callbackFn callback to execute after user clicks on OK
1298 jQuery
.fn
.PMA_confirm = function(question
, url
, callbackFn
) {
1299 if (PMA_messages
['strDoYouReally'] == '') {
1304 * @var button_options Object that stores the options passed to jQueryUI
1307 var button_options
= {};
1308 button_options
[PMA_messages
['strOK']] = function(){
1309 $(this).dialog("close").remove();
1311 if($.isFunction(callbackFn
)) {
1312 callbackFn
.call(this, url
);
1315 button_options
[PMA_messages
['strCancel']] = function() {$(this).dialog("close").remove();}
1317 $('<div id="confirm_dialog"></div>')
1319 .dialog({buttons
: button_options
});
1323 * jQuery function to sort a table's body after a new row has been appended to it.
1324 * Also fixes the even/odd classes of the table rows at the end.
1326 * @param string text_selector string to select the sortKey's text
1328 * @return jQuery Object for chaining purposes
1330 jQuery
.fn
.PMA_sort_table = function(text_selector
) {
1331 return this.each(function() {
1334 * @var table_body Object referring to the table's <tbody> element
1336 var table_body
= $(this);
1338 * @var rows Object referring to the collection of rows in {@link table_body}
1340 var rows
= $(this).find('tr').get();
1342 //get the text of the field that we will sort by
1343 $.each(rows
, function(index
, row
) {
1344 row
.sortKey
= $.trim($(row
).find(text_selector
).text().toLowerCase());
1347 //get the sorted order
1348 rows
.sort(function(a
,b
) {
1349 if(a
.sortKey
< b
.sortKey
) {
1352 if(a
.sortKey
> b
.sortKey
) {
1358 //pull out each row from the table and then append it according to it's order
1359 $.each(rows
, function(index
, row
) {
1360 $(table_body
).append(row
);
1364 //Re-check the classes of each row
1365 $(this).find('tr:odd')
1366 .removeClass('even').addClass('odd')
1369 .removeClass('odd').addClass('even');
1374 * jQuery coding for 'Create Table'. Used on db_operations.php,
1375 * db_structure.php and db_tracking.php (i.e., wherever
1376 * libraries/display_create_table.lib.php is used)
1378 * Attach Ajax Event handlers for Create Table
1380 $(document
).ready(function() {
1383 * Attach event handler to the submit action of the create table minimal form
1384 * and retrieve the full table form and display it in a dialog
1386 * @uses PMA_ajaxShowMessage()
1388 $("#create_table_form_minimal.ajax").live('submit', function(event
) {
1389 event
.preventDefault();
1392 /* @todo Validate this form! */
1395 * @var button_options Object that stores the options passed to jQueryUI
1398 var button_options
= {};
1399 // in the following function we need to use $(this)
1400 button_options
[PMA_messages
['strCancel']] = function() {$(this).dialog('close').remove();}
1402 var button_options_error
= {};
1403 button_options_error
[PMA_messages
['strOK']] = function() {$(this).dialog('close').remove();}
1405 var $msgbox
= PMA_ajaxShowMessage();
1406 if (! $form
.find('input:hidden').is('#ajax_request_hidden')) {
1407 $form
.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
1410 $.get($form
.attr('action'), $form
.serialize(), function(data
) {
1411 //in the case of an error, show the error message returned.
1412 if (data
.success
!= undefined && data
.success
== false) {
1413 $('<div id="create_table_dialog"></div>')
1416 title
: PMA_messages
['strCreateTable'],
1419 open
: PMA_verifyTypeOfAllColumns
,
1420 buttons
: button_options_error
1421 })// end dialog options
1422 //remove the redundant [Back] link in the error message.
1423 .find('fieldset').remove();
1425 $('<div id="create_table_dialog"></div>')
1428 title
: PMA_messages
['strCreateTable'],
1431 open
: PMA_verifyTypeOfAllColumns
,
1432 buttons
: button_options
1433 }); // end dialog options
1435 PMA_ajaxRemoveMessage($msgbox
);
1438 // empty table name and number of columns from the minimal form
1439 $form
.find('input[name=table],input[name=num_fields]').val('');
1443 * Attach event handler for submission of create table form (save)
1445 * @uses PMA_ajaxShowMessage()
1446 * @uses $.PMA_sort_table()
1449 // .live() must be called after a selector, see http://api.jquery.com/live
1450 $("#create_table_form input[name=do_save_data]").live('click', function(event
) {
1451 event
.preventDefault();
1454 * @var the_form object referring to the create table form
1456 var $form
= $("#create_table_form");
1459 * First validate the form; if there is a problem, avoid submitting it
1461 * checkTableEditForm() needs a pure element and not a jQuery object,
1462 * this is why we pass $form[0] as a parameter (the jQuery object
1463 * is actually an array of DOM elements)
1466 if (checkTableEditForm($form
[0], $form
.find('input[name=orig_num_fields]').val())) {
1467 // OK, form passed validation step
1468 if ($form
.hasClass('ajax')) {
1469 PMA_ajaxShowMessage(PMA_messages
['strProcessingRequest']);
1470 if (! $form
.find('input:hidden').is('#ajax_request_hidden')) {
1471 $form
.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
1473 //User wants to submit the form
1474 $.post($form
.attr('action'), $form
.serialize() + "&do_save_data=" + $(this).val(), function(data
) {
1475 if(data
.success
== true) {
1476 $('#properties_message')
1477 .removeClass('error')
1479 PMA_ajaxShowMessage(data
.message
);
1480 // Only if the create table dialog (distinct panel) exists
1481 if ($("#create_table_dialog").length
> 0) {
1482 $("#create_table_dialog").dialog("close").remove();
1486 * @var tables_table Object referring to the <tbody> element that holds the list of tables
1488 var tables_table
= $("#tablesForm").find("tbody").not("#tbl_summary_row");
1489 // this is the first table created in this db
1490 if (tables_table
.length
== 0) {
1491 if (window
.parent
&& window
.parent
.frame_content
) {
1492 window
.parent
.frame_content
.location
.reload();
1496 * @var curr_last_row Object referring to the last <tr> element in {@link tables_table}
1498 var curr_last_row
= $(tables_table
).find('tr:last');
1500 * @var curr_last_row_index_string String containing the index of {@link curr_last_row}
1502 var curr_last_row_index_string
= $(curr_last_row
).find('input:checkbox').attr('id').match(/\d+/)[0];
1504 * @var curr_last_row_index Index of {@link curr_last_row}
1506 var curr_last_row_index
= parseFloat(curr_last_row_index_string
);
1508 * @var new_last_row_index Index of the new row to be appended to {@link tables_table}
1510 var new_last_row_index
= curr_last_row_index
+ 1;
1512 * @var new_last_row_id String containing the id of the row to be appended to {@link tables_table}
1514 var new_last_row_id
= 'checkbox_tbl_' + new_last_row_index
;
1516 data
.new_table_string
= data
.new_table_string
.replace(/checkbox_tbl_/, new_last_row_id
);
1518 $(data
.new_table_string
)
1519 .appendTo(tables_table
);
1522 $(tables_table
).PMA_sort_table('th');
1525 //Refresh navigation frame as a new table has been added
1526 if (window
.parent
&& window
.parent
.frame_navigation
) {
1527 window
.parent
.frame_navigation
.location
.reload();
1530 $('#properties_message')
1533 // scroll to the div containing the error message
1534 $('#properties_message')[0].scrollIntoView();
1537 } // end if ($form.hasClass('ajax')
1540 $form
.append('<input type="hidden" name="do_save_data" value="save" />');
1543 } // end if (checkTableEditForm() )
1544 }) // end create table form (save)
1547 * Attach event handler for create table form (add fields)
1549 * @uses PMA_ajaxShowMessage()
1550 * @uses $.PMA_sort_table()
1551 * @uses window.parent.refreshNavigation()
1554 // .live() must be called after a selector, see http://api.jquery.com/live
1555 $("#create_table_form.ajax input[name=submit_num_fields]").live('click', function(event
) {
1556 event
.preventDefault();
1559 * @var the_form object referring to the create table form
1561 var $form
= $("#create_table_form");
1563 var $msgbox
= PMA_ajaxShowMessage(PMA_messages
['strProcessingRequest']);
1564 if (! $form
.find('input:hidden').is('#ajax_request_hidden')) {
1565 $form
.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
1568 //User wants to add more fields to the table
1569 $.post($form
.attr('action'), $form
.serialize() + "&submit_num_fields=" + $(this).val(), function(data
) {
1570 // if 'create_table_dialog' exists
1571 if ($("#create_table_dialog").length
> 0) {
1572 $("#create_table_dialog").html(data
);
1574 // if 'create_table_div' exists
1575 if ($("#create_table_div").length
> 0) {
1576 $("#create_table_div").html(data
);
1578 PMA_verifyTypeOfAllColumns();
1579 PMA_ajaxRemoveMessage($msgbox
);
1582 }) // end create table form (add fields)
1584 }, 'top.frame_content'); //end $(document).ready for 'Create Table'
1587 * Attach Ajax event handlers for Drop Trigger. Used on tbl_structure.php
1588 * @see $cfg['AjaxEnable']
1590 $(document
).ready(function() {
1592 $(".drop_trigger_anchor").live('click', function(event
) {
1593 event
.preventDefault();
1597 * @var curr_row Object reference to the current trigger's <tr>
1599 var $curr_row
= $anchor
.parents('tr');
1601 * @var question String containing the question to be asked for confirmation
1603 var question
= 'DROP TRIGGER IF EXISTS `' + $curr_row
.children('td:first').text() + '`';
1605 $anchor
.PMA_confirm(question
, $anchor
.attr('href'), function(url
) {
1607 PMA_ajaxShowMessage(PMA_messages
['strProcessingRequest']);
1608 $.get(url
, {'is_js_confirmed': 1, 'ajax_request': true}, function(data
) {
1609 if(data
.success
== true) {
1610 PMA_ajaxShowMessage(data
.message
);
1611 $("#topmenucontainer")
1615 .after(data
.sql_query
);
1616 $curr_row
.hide("medium").remove();
1619 PMA_ajaxShowMessage(data
.error
);
1622 }) // end $.PMA_confirm()
1623 }) // end $().live()
1624 }, 'top.frame_content'); //end $(document).ready() for Drop Trigger
1627 * Attach Ajax event handlers for Drop Database. Moved here from db_structure.js
1628 * as it was also required on db_create.php
1630 * @uses $.PMA_confirm()
1631 * @uses PMA_ajaxShowMessage()
1632 * @uses window.parent.refreshNavigation()
1633 * @uses window.parent.refreshMain()
1634 * @see $cfg['AjaxEnable']
1636 $(document
).ready(function() {
1637 $("#drop_db_anchor").live('click', function(event
) {
1638 event
.preventDefault();
1640 //context is top.frame_content, so we need to use window.parent.db to access the db var
1642 * @var question String containing the question to be asked for confirmation
1644 var question
= PMA_messages
['strDropDatabaseStrongWarning'] + '\n' + PMA_messages
['strDoYouReally'] + ' :\n' + 'DROP DATABASE ' + window
.parent
.db
;
1646 $(this).PMA_confirm(question
, $(this).attr('href') ,function(url
) {
1648 PMA_ajaxShowMessage(PMA_messages
['strProcessingRequest']);
1649 $.get(url
, {'is_js_confirmed': '1', 'ajax_request': true}, function(data
) {
1650 //Database deleted successfully, refresh both the frames
1651 window
.parent
.refreshNavigation();
1652 window
.parent
.refreshMain();
1654 }); // end $.PMA_confirm()
1655 }); //end of Drop Database Ajax action
1656 }) // end of $(document).ready() for Drop Database
1659 * Attach Ajax event handlers for 'Create Database'. Used wherever libraries/
1660 * display_create_database.lib.php is used, ie main.php and server_databases.php
1662 * @uses PMA_ajaxShowMessage()
1663 * @see $cfg['AjaxEnable']
1665 $(document
).ready(function() {
1667 $('#create_database_form.ajax').live('submit', function(event
) {
1668 event
.preventDefault();
1672 PMA_ajaxShowMessage(PMA_messages
['strProcessingRequest']);
1674 if (! $form
.find('input:hidden').is('#ajax_request_hidden')) {
1675 $form
.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
1678 $.post($form
.attr('action'), $form
.serialize(), function(data
) {
1679 if(data
.success
== true) {
1680 PMA_ajaxShowMessage(data
.message
);
1682 //Append database's row to table
1683 $("#tabledatabases")
1685 .append(data
.new_db_string
)
1686 .PMA_sort_table('.name')
1687 .find('#db_summary_row')
1688 .appendTo('#tabledatabases tbody')
1689 .removeClass('odd even');
1691 var $databases_count_object
= $('#databases_count');
1692 var databases_count
= parseInt($databases_count_object
.text());
1693 $databases_count_object
.text(++databases_count
);
1694 //Refresh navigation frame as a new database has been added
1695 if (window
.parent
&& window
.parent
.frame_navigation
) {
1696 window
.parent
.frame_navigation
.location
.reload();
1700 PMA_ajaxShowMessage(data
.error
);
1703 }) // end $().live()
1704 }) // end $(document).ready() for Create Database
1707 * Attach Ajax event handlers for 'Change Password' on main.php
1709 $(document
).ready(function() {
1712 * Attach Ajax event handler on the change password anchor
1713 * @see $cfg['AjaxEnable']
1715 $('#change_password_anchor.dialog_active').live('click',function(event
) {
1716 event
.preventDefault();
1719 $('#change_password_anchor.ajax').live('click', function(event
) {
1720 event
.preventDefault();
1721 $(this).removeClass('ajax').addClass('dialog_active');
1723 * @var button_options Object containing options to be passed to jQueryUI's dialog
1725 var button_options
= {};
1726 button_options
[PMA_messages
['strCancel']] = function() {$(this).dialog('close').remove();}
1727 $.get($(this).attr('href'), {'ajax_request': true}, function(data
) {
1728 $('<div id="change_password_dialog"></div>')
1730 title
: PMA_messages
['strChangePassword'],
1732 close: function(ev
,ui
) {$(this).remove();},
1733 buttons
: button_options
,
1734 beforeClose: function(ev
,ui
){ $('#change_password_anchor.dialog_active').removeClass('dialog_active').addClass('ajax')}
1737 displayPasswordGenerateButton();
1739 }) // end handler for change password anchor
1742 * Attach Ajax event handler for Change Password form submission
1744 * @uses PMA_ajaxShowMessage()
1745 * @see $cfg['AjaxEnable']
1747 $("#change_password_form.ajax").find('input[name=change_pw]').live('click', function(event
) {
1748 event
.preventDefault();
1751 * @var the_form Object referring to the change password form
1753 var the_form
= $("#change_password_form");
1756 * @var this_value String containing the value of the submit button.
1757 * Need to append this for the change password form on Server Privileges
1760 var this_value
= $(this).val();
1762 var $msgbox
= PMA_ajaxShowMessage(PMA_messages
['strProcessingRequest']);
1763 $(the_form
).append('<input type="hidden" name="ajax_request" value="true" />');
1765 $.post($(the_form
).attr('action'), $(the_form
).serialize() + '&change_pw='+ this_value
, function(data
) {
1766 if(data
.success
== true) {
1767 $("#topmenucontainer").after(data
.sql_query
);
1768 $("#change_password_dialog").hide().remove();
1769 $("#edit_user_dialog").dialog("close").remove();
1770 $('#change_password_anchor.dialog_active').removeClass('dialog_active').addClass('ajax');
1771 PMA_ajaxRemoveMessage($msgbox
);
1774 PMA_ajaxShowMessage(data
.error
);
1777 }) // end handler for Change Password form submission
1778 }) // end $(document).ready() for Change Password
1781 * Toggle the hiding/showing of the "Open in ENUM/SET editor" message when
1782 * the page loads and when the selected data type changes
1784 $(document
).ready(function() {
1785 // is called here for normal page loads and also when opening
1786 // the Create table dialog
1787 PMA_verifyTypeOfAllColumns();
1789 // needs live() to work also in the Create Table dialog
1790 $("select[class='column_type']").live('change', function() {
1791 PMA_showNoticeForEnum($(this));
1795 function PMA_verifyTypeOfAllColumns() {
1796 $("select[class='column_type']").each(function() {
1797 PMA_showNoticeForEnum($(this));
1802 * Closes the ENUM/SET editor and removes the data in it
1804 function disable_popup() {
1805 $("#popup_background").fadeOut("fast");
1806 $("#enum_editor").fadeOut("fast");
1807 // clear the data from the text boxes
1808 $("#enum_editor #values input").remove();
1809 $("#enum_editor input[type='hidden']").remove();
1813 * Opens the ENUM/SET editor and controls its functions
1815 $(document
).ready(function() {
1816 // Needs live() to work also in the Create table dialog
1817 $("a[class='open_enum_editor']").live('click', function() {
1819 var windowWidth
= document
.documentElement
.clientWidth
;
1820 var windowHeight
= document
.documentElement
.clientHeight
;
1821 var popupWidth
= windowWidth
/2;
1822 var popupHeight
= windowHeight
*0.8;
1823 var popupOffsetTop
= windowHeight
/2 - popupHeight/2;
1824 var popupOffsetLeft
= windowWidth
/2 - popupWidth/2;
1825 $("#enum_editor").css({"position":"absolute", "top": popupOffsetTop
, "left": popupOffsetLeft
, "width": popupWidth
, "height": popupHeight
});
1828 $("#popup_background").css({"opacity":"0.7"});
1829 $("#popup_background").fadeIn("fast");
1830 $("#enum_editor").fadeIn("fast");
1833 var values
= $(this).parent().prev("input").attr("value").split(",");
1834 $.each(values
, function(index
, val
) {
1835 if(jQuery
.trim(val
) != "") {
1836 // enclose the string in single quotes if it's not already
1837 if(val
.substr(0, 1) != "'") {
1840 if(val
.substr(val
.length
-1, val
.length
) != "'") {
1843 // escape the single quotes, except the mandatory ones enclosing the entire string
1844 val
= val
.substr(1, val
.length
-2).replace(/''/g, "'").replace(/\\\\/g, '\\').replace(/\\'/g, "'").replace(/'/g, "'");
1845 // escape the greater-than symbol
1846 val = val.replace(/>/g, ">
;");
1847 $("#enum_editor
#values
").append("<input type
='text' value
=" + val + " />");
1850 // So we know which column's data is being edited
1851 $("#enum_editor
").append("<input type
='hidden' value
='" + $(this).parent().prev("input").attr("id") + "' />");
1855 // If the "close
" link is clicked, close the enum editor
1856 // Needs live() to work also in the Create table dialog
1857 $("a
[class='close_enum_editor']").live('click', function() {
1861 // If the "cancel
" link is clicked, close the enum editor
1862 // Needs live() to work also in the Create table dialog
1863 $("a
[class='cancel_enum_editor']").live('click', function() {
1867 // When "add a
new value
" is clicked, append an empty text field
1868 // Needs live() to work also in the Create table dialog
1869 $("a
[class='add_value']").live('click', function() {
1870 $("#enum_editor
#values
").append("<input type
='text' />");
1873 // When the submit button is clicked, put the data back into the original form
1874 // Needs live() to work also in the Create table dialog
1875 $("#enum_editor input
[type
='submit']").live('click', function() {
1876 var value_array = new Array();
1877 $.each($("#enum_editor
#values input
"), function(index, input_element) {
1878 val = jQuery.trim(input_element.value);
1880 value_array.push("'" + val.replace(/\\/g, '\\\\').replace(/'/g
, "''") + "'");
1883 // get the Length/Values text field where this value belongs
1884 var values_id
= $("#enum_editor input[type='hidden']").attr("value");
1885 $("input[id='" + values_id
+ "']").attr("value", value_array
.join(","));
1890 * Hides certain table structure actions, replacing them with the word "More". They are displayed
1891 * in a dropdown menu when the user hovers over the word "More."
1893 // Remove the actions from the table cells (they are available by default for JavaScript-disabled browsers)
1894 // if the table is not a view or information_schema (otherwise there is only one action to hide and there's no point)
1895 if($("input[type='hidden'][name='table_type']").val() == "table") {
1896 var $table
= $("table[id='tablestructure']");
1897 $table
.find("td[class='browse']").remove();
1898 $table
.find("td[class='primary']").remove();
1899 $table
.find("td[class='unique']").remove();
1900 $table
.find("td[class='index']").remove();
1901 $table
.find("td[class='fulltext']").remove();
1902 $table
.find("th[class='action']").attr("colspan", 3);
1904 // Display the "more" text
1905 $table
.find("td[class='more_opts']").show();
1907 // Position the dropdown
1908 $(".structure_actions_dropdown").each(function() {
1909 // Optimize DOM querying
1910 var $this_dropdown
= $(this);
1911 // The top offset must be set for IE even if it didn't change
1912 var cell_right_edge_offset
= $this_dropdown
.parent().offset().left
+ $this_dropdown
.parent().innerWidth();
1913 var left_offset
= cell_right_edge_offset
- $this_dropdown
.innerWidth();
1914 var top_offset
= $this_dropdown
.parent().offset().top
+ $this_dropdown
.parent().innerHeight();
1915 $this_dropdown
.offset({ top
: top_offset
, left
: left_offset
});
1918 // A hack for IE6 to prevent the after_field select element from being displayed on top of the dropdown by
1919 // positioning an iframe directly on top of it
1920 var $after_field
= $("select[name='after_field']");
1921 $("iframe[class='IE_hack']")
1922 .width($after_field
.width())
1923 .height($after_field
.height())
1925 top
: $after_field
.offset().top
,
1926 left
: $after_field
.offset().left
1929 // When "more" is hovered over, show the hidden actions
1930 $table
.find("td[class='more_opts']")
1931 .mouseenter(function() {
1932 if($.browser
.msie
&& $.browser
.version
== "6.0") {
1933 $("iframe[class='IE_hack']")
1935 .width($after_field
.width()+4)
1936 .height($after_field
.height()+4)
1938 top
: $after_field
.offset().top
,
1939 left
: $after_field
.offset().left
1942 $(".structure_actions_dropdown").hide(); // Hide all the other ones that may be open
1943 $(this).children(".structure_actions_dropdown").show();
1944 // Need to do this again for IE otherwise the offset is wrong
1945 if($.browser
.msie
) {
1946 var left_offset_IE
= $(this).offset().left
+ $(this).innerWidth() - $(this).children(".structure_actions_dropdown").innerWidth();
1947 var top_offset_IE
= $(this).offset().top
+ $(this).innerHeight();
1948 $(this).children(".structure_actions_dropdown").offset({
1950 left
: left_offset_IE
});
1953 .mouseleave(function() {
1954 $(this).children(".structure_actions_dropdown").hide();
1955 if($.browser
.msie
&& $.browser
.version
== "6.0") {
1956 $("iframe[class='IE_hack']").hide();
1962 /* Displays tooltips */
1963 $(document
).ready(function() {
1964 // Hide the footnotes from the footer (which are displayed for
1965 // JavaScript-disabled browsers) since the tooltip is sufficient
1966 $(".footnotes").hide();
1967 $(".footnotes span").each(function() {
1968 $(this).children("sup").remove();
1970 // The border and padding must be removed otherwise a thin yellow box remains visible
1971 $(".footnotes").css("border", "none");
1972 $(".footnotes").css("padding", "0px");
1974 // Replace the superscripts with the help icon
1975 $("sup[class='footnotemarker']").hide();
1976 $("img[class='footnotemarker']").show();
1978 $("img[class='footnotemarker']").each(function() {
1979 var span_id
= $(this).attr("id");
1980 span_id
= span_id
.split("_")[1];
1981 var tooltip_text
= $(".footnotes span[id='footnote_" + span_id
+ "']").html();
1983 content
: tooltip_text
,
1985 hide
: { when
: 'unfocus', delay
: 0 },
1986 style
: { background
: '#ffffcc' }
1991 function menuResize()
1993 var cnt
= $('#topmenu');
1994 var wmax
= cnt
.innerWidth() - 5; // 5 px margin for jumping menu in Chrome
1995 var submenu
= cnt
.find('.submenu');
1996 var submenu_w
= submenu
.outerWidth(true);
1997 var submenu_ul
= submenu
.find('ul');
1998 var li
= cnt
.find('> li');
1999 var li2
= submenu_ul
.find('li');
2000 var more_shown
= li2
.length
> 0;
2001 var w
= more_shown
? submenu_w
: 0;
2005 for (var i
= 0; i
< li
.length
-1; i
++) { // li.length-1: skip .submenu element
2007 var el_width
= el
.outerWidth(true);
2008 el
.data('width', el_width
);
2012 if (w
+ submenu_w
< wmax
) {
2016 w
-= $(li
[i
-1]).data('width');
2022 if (hide_start
> 0) {
2023 for (var i
= hide_start
; i
< li
.length
-1; i
++) {
2024 $(li
[i
])[more_shown
? 'prependTo' : 'appendTo'](submenu_ul
);
2026 submenu
.addClass('shown');
2027 } else if (more_shown
) {
2029 // nothing hidden, maybe something can be restored
2030 for (var i
= 0; i
< li2
.length
; i
++) {
2031 //console.log(li2[i], submenu_w);
2032 w
+= $(li2
[i
]).data('width');
2033 // item fits or (it is the last item and it would fit if More got removed)
2034 if (w
+submenu_w
< wmax
|| (i
== li2
.length
-1 && w
< wmax
)) {
2035 $(li2
[i
]).insertBefore(submenu
);
2036 if (i
== li2
.length
-1) {
2037 submenu
.removeClass('shown');
2044 if (submenu
.find('.tabactive').length
) {
2045 submenu
.addClass('active').find('> a').removeClass('tab').addClass('tabactive');
2047 submenu
.removeClass('active').find('> a').addClass('tab').removeClass('tabactive');
2052 var topmenu
= $('#topmenu');
2053 if (topmenu
.length
== 0) {
2056 // create submenu container
2057 var link
= $('<a />', {href
: '#', 'class': 'tab'})
2058 .text(PMA_messages
['strMore'])
2059 .click(function(e
) {
2062 var img
= topmenu
.find('li:first-child img');
2064 img
.clone().attr('src', img
.attr('src').replace(/\/[^\/]+$/, '/b_more.png')).prependTo(link
);
2066 var submenu
= $('<li />', {'class': 'submenu'})
2068 .append($('<ul />'))
2069 .mouseenter(function() {
2070 if ($(this).find('ul .tabactive').length
== 0) {
2071 $(this).addClass('submenuhover').find('> a').addClass('tabactive');
2074 .mouseleave(function() {
2075 if ($(this).find('ul .tabactive').length
== 0) {
2076 $(this).removeClass('submenuhover').find('> a').removeClass('tabactive');
2079 topmenu
.append(submenu
);
2081 // populate submenu and register resize event
2082 $(window
).resize(menuResize
);
2087 * For the checkboxes in browse mode, handles the shift/click (only works
2088 * in horizontal mode) and propagates the click to the "companion" checkbox
2089 * (in both horizontal and vertical). Works also for pages reached via AJAX.
2091 $(document
).ready(function() {
2092 $('.multi_checkbox').live('click',function(e
) {
2093 var current_checkbox_id
= this.id
;
2094 var left_checkbox_id
= current_checkbox_id
.replace('_right', '_left');
2095 var right_checkbox_id
= current_checkbox_id
.replace('_left', '_right');
2096 var other_checkbox_id
= '';
2097 if (current_checkbox_id
== left_checkbox_id
) {
2098 other_checkbox_id
= right_checkbox_id
;
2100 other_checkbox_id
= left_checkbox_id
;
2103 var $current_checkbox
= $('#' + current_checkbox_id
);
2104 var $other_checkbox
= $('#' + other_checkbox_id
);
2107 var index_of_current_checkbox
= $('.multi_checkbox').index($current_checkbox
);
2108 var $last_checkbox
= $('.multi_checkbox').filter('.last_clicked');
2109 var index_of_last_click
= $('.multi_checkbox').index($last_checkbox
);
2110 $('.multi_checkbox')
2111 .filter(function(index
) {
2112 // the first clicked row can be on a row above or below the
2113 // shift-clicked row
2114 return (index_of_current_checkbox
> index_of_last_click
&& index
> index_of_last_click
&& index
< index_of_current_checkbox
)
2115 || (index_of_last_click
> index_of_current_checkbox
&& index
< index_of_last_click
&& index
> index_of_current_checkbox
);
2117 .each(function(index
) {
2118 var $intermediate_checkbox
= $(this);
2119 if ($current_checkbox
.is(':checked')) {
2120 $intermediate_checkbox
.attr('checked', true);
2122 $intermediate_checkbox
.attr('checked', false);
2127 $('.multi_checkbox').removeClass('last_clicked');
2128 $current_checkbox
.addClass('last_clicked');
2130 // When there is a checkbox on both ends of the row, propagate the
2131 // click on one of them to the other one.
2132 // (the default action has not been prevented so if we have
2133 // just clicked, this "if" is true)
2134 if ($current_checkbox
.is(':checked')) {
2135 $other_checkbox
.attr('checked', true);
2137 $other_checkbox
.attr('checked', false);
2140 }) // end of $(document).ready() for multi checkbox
2143 * Get the row number from the classlist (for example, row_1)
2145 function PMA_getRowNumber(classlist
) {
2146 return parseInt(classlist
.split(/row_/)[1]);
2150 * Changes status of slider
2152 function PMA_set_status_label(id
) {
2153 if ($('#' + id
).css('display') == 'none') {
2154 $('#anchor_status_' + id
).text('+ ');
2156 $('#anchor_status_' + id
).text('- ');
2161 * Initializes slider effect.
2163 function PMA_init_slider() {
2164 $('.pma_auto_slider').each(function(idx
, e
) {
2165 if ($(e
).hasClass('slider_init_done')) return;
2166 $(e
).addClass('slider_init_done');
2167 $('<span id="anchor_status_' + e
.id
+ '"></span>')
2169 PMA_set_status_label(e
.id
);
2171 $('<a href="#' + e
.id
+ '" id="anchor_' + e
.id
+ '">' + e
.title
+ '</a>')
2174 $('#' + e
.id
).toggle('clip', function() {
2175 PMA_set_status_label(e
.id
);
2185 $(document
).ready(function() {
2186 $('.vpointer').live('hover',
2189 var $this_td
= $(this);
2190 var row_num
= PMA_getRowNumber($this_td
.attr('class'));
2191 // for all td of the same vertical row, toggle hover
2192 $('.vpointer').filter('.row_' + row_num
).toggleClass('hover');
2195 }) // end of $(document).ready() for vertical pointer
2197 $(document
).ready(function() {
2201 $('.vmarker').live('click', function(e
) {
2202 var $this_td
= $(this);
2203 var row_num
= PMA_getRowNumber($this_td
.attr('class'));
2204 // for all td of the same vertical row, toggle the marked class
2205 $('.vmarker').filter('.row_' + row_num
).toggleClass('marked');
2209 * Reveal visual builder anchor
2212 $('#visual_builder_anchor').show();
2215 * Page selector in db Structure (non-AJAX)
2217 $('#tableslistcontainer').find('#pageselector').live('change', function() {
2218 $(this).parent("form").submit();
2222 * Page selector in navi panel (non-AJAX)
2224 $('#navidbpageselector').find('#pageselector').live('change', function() {
2225 $(this).parent("form").submit();
2229 * Page selector in browse_foreigners windows (non-AJAX)
2231 $('#body_browse_foreigners').find('#pageselector').live('change', function() {
2232 $(this).closest("form").submit();
2236 * Load version information asynchronously.
2238 if ($('.jsversioncheck').length
> 0) {
2240 var s
= document
.createElement('script');
2241 s
.type
= 'text/javascript';
2243 s
.src
= 'http://www.phpmyadmin.net/home_page/version.js';
2244 s
.onload
= PMA_current_version
;
2245 var x
= document
.getElementsByTagName('script')[0];
2246 x
.parentNode
.insertBefore(s
, x
);
2256 * Enables the text generated by PMA_linkOrButton() to be clickable
2258 $('.clickprevimage')
2259 .css('color', function(index
) {
2260 return $('a').css('color');
2262 .css('cursor', function(index
) {
2263 return $('a').css('cursor');
2264 }) //todo: hover effect
2265 .live('click',function(e
) {
2266 $this_span
= $(this);
2267 if ($this_span
.closest('td').is('.inline_edit_anchor')) {
2268 // this would bind a second click event to the inline edit
2269 // anchor and would disturb its behavior
2271 $this_span
.parent().find('input:image').click();
2275 }) // end of $(document).ready()