1 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 * general function, usally for data manipulation pages
8 * @var sql_box_locked lock for the sqlbox textarea in the querybox/querywindow
10 var sql_box_locked
= false;
13 * @var array holds elements which content should only selected once
15 var only_once_elements
= new Array();
18 * @var int ajax_message_count Number of AJAX messages shown since page load
20 var ajax_message_count
= 0;
23 * @var codemirror_editor object containing CodeMirror editor
25 var codemirror_editor
= false;
28 * @var chart_activeTimeouts object active timeouts that refresh the charts. When disabling a realtime chart, this can be used to stop the continuous ajax requests
30 var chart_activeTimeouts
= new Object();
34 * Add a hidden field to the form to indicate that this will be an
35 * Ajax request (only if this hidden field does not exist)
37 * @param object the form
39 function PMA_prepareForAjaxRequest($form
) {
40 if (! $form
.find('input:hidden').is('#ajax_request_hidden')) {
41 $form
.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
46 * Generate a new password and copy it to the password input areas
48 * @param object the form that holds the password fields
50 * @return boolean always true
52 function suggestPassword(passwd_form
) {
53 // restrict the password to just letters and numbers to avoid problems:
54 // "editors and viewers regard the password as multiple words and
55 // things like double click no longer work"
56 var pwchars
= "abcdefhjmnpqrstuvwxyz23456789ABCDEFGHJKLMNPQRSTUVWYXZ";
57 var passwordlength
= 16; // do we want that to be dynamic? no, keep it simple :)
58 var passwd
= passwd_form
.generated_pw
;
61 for ( i
= 0; i
< passwordlength
; i
++ ) {
62 passwd
.value
+= pwchars
.charAt( Math
.floor( Math
.random() * pwchars
.length
) )
64 passwd_form
.text_pma_pw
.value
= passwd
.value
;
65 passwd_form
.text_pma_pw2
.value
= passwd
.value
;
70 * Version string to integer conversion.
72 function parseVersionString (str
) {
73 if (typeof(str
) != 'string') { return false; }
75 // Parse possible alpha/beta/rc/
76 var state
= str
.split('-');
77 if (state
.length
>= 2) {
78 if (state
[1].substr(0, 2) == 'rc') {
79 add
= - 20 - parseInt(state
[1].substr(2));
80 } else if (state
[1].substr(0, 4) == 'beta') {
81 add
= - 40 - parseInt(state
[1].substr(4));
82 } else if (state
[1].substr(0, 5) == 'alpha') {
83 add
= - 60 - parseInt(state
[1].substr(5));
84 } else if (state
[1].substr(0, 3) == 'dev') {
85 /* We don't handle dev, it's git snapshot */
90 var x
= str
.split('.');
91 // Use 0 for non existing parts
92 var maj
= parseInt(x
[0]) || 0;
93 var min
= parseInt(x
[1]) || 0;
94 var pat
= parseInt(x
[2]) || 0;
95 var hotfix
= parseInt(x
[3]) || 0;
96 return maj
* 100000000 + min
* 1000000 + pat
* 10000 + hotfix
* 100 + add
;
100 * Indicates current available version on main page.
102 function PMA_current_version() {
103 var current
= parseVersionString(pmaversion
);
104 var latest
= parseVersionString(PMA_latest_version
);
105 var version_information_message
= PMA_messages
['strLatestAvailable'] + ' ' + PMA_latest_version
;
106 if (latest
> current
) {
107 var message
= $.sprintf(PMA_messages
['strNewerVersion'], PMA_latest_version
, PMA_latest_date
);
108 if (Math
.floor(latest
/ 10000) == Math
.floor(current
/ 10000)) {
109 /* Security update */
114 $('#maincontainer').after('<div class="' + klass
+ '">' + message
+ '</div>');
116 if (latest
== current
) {
117 version_information_message
= ' (' + PMA_messages
['strUpToDate'] + ')';
119 $('#li_pma_version').append(version_information_message
);
123 * for libraries/display_change_password.lib.php
124 * libraries/user_password.php
128 function displayPasswordGenerateButton() {
129 $('#tr_element_before_generate_password').parent().append('<tr><td>' + PMA_messages
['strGeneratePassword'] + '</td><td><input type="button" id="button_generate_password" value="' + PMA_messages
['strGenerate'] + '" onclick="suggestPassword(this.form)" /><input type="text" name="generated_pw" id="generated_pw" /></td></tr>');
130 $('#div_element_before_generate_password').parent().append('<div class="item"><label for="button_generate_password">' + PMA_messages
['strGeneratePassword'] + ':</label><span class="options"><input type="button" id="button_generate_password" value="' + PMA_messages
['strGenerate'] + '" onclick="suggestPassword(this.form)" /></span><input type="text" name="generated_pw" id="generated_pw" /></div>');
134 * Adds a date/time picker to an element
136 * @param object $this_element a jQuery object pointing to the element
138 function PMA_addDatepicker($this_element
) {
139 var showTimeOption
= false;
140 if ($this_element
.is('.datetimefield')) {
141 showTimeOption
= true;
147 buttonImage
: themeCalendarImage
, // defined in js/messages.php
148 buttonImageOnly
: true,
153 showTime
: showTimeOption
,
154 dateFormat
: 'yy-mm-dd', // yy means year with four digits
156 beforeShow: function(input
, inst
) {
157 // Remember that we came from the datepicker; this is used
158 // in tbl_change.js by verificationsAfterFieldChange()
159 $this_element
.data('comes_from', 'datepicker');
161 // Fix wrong timepicker z-index, doesn't work without timeout
162 setTimeout(function() {
163 $('#ui-timepicker-div').css('z-index',$('#ui-datepicker-div').css('z-index'))
166 constrainInput
: false
171 * selects the content of a given object, f.e. a textarea
173 * @param object element element of which the content will be selected
174 * @param var lock variable which holds the lock for this element
175 * or true, if no lock exists
176 * @param boolean only_once if true this is only done once
177 * f.e. only on first focus
179 function selectContent( element
, lock
, only_once
) {
180 if ( only_once
&& only_once_elements
[element
.name
] ) {
184 only_once_elements
[element
.name
] = true;
194 * Displays a confirmation box before to submit a "DROP/DELETE/ALTER" query.
195 * This function is called while clicking links
197 * @param object the link
198 * @param object the sql query to submit
200 * @return boolean whether to run the query or not
202 function confirmLink(theLink
, theSqlQuery
)
204 // Confirmation is not required in the configuration file
205 // or browser is Opera (crappy js implementation)
206 if (PMA_messages
['strDoYouReally'] == '' || typeof(window
.opera
) != 'undefined') {
210 var is_confirmed
= confirm(PMA_messages
['strDoYouReally'] + ' :\n' + theSqlQuery
);
212 if ( typeof(theLink
.href
) != 'undefined' ) {
213 theLink
.href
+= '&is_js_confirmed=1';
214 } else if ( typeof(theLink
.form
) != 'undefined' ) {
215 theLink
.form
.action
+= '?is_js_confirmed=1';
220 } // end of the 'confirmLink()' function
224 * Displays a confirmation box before doing some action
226 * @param object the message to display
228 * @return boolean whether to run the query or not
230 * @todo used only by libraries/display_tbl.lib.php. figure out how it is used
231 * and replace with a jQuery equivalent
233 function confirmAction(theMessage
)
235 // TODO: Confirmation is not required in the configuration file
236 // or browser is Opera (crappy js implementation)
237 if (typeof(window
.opera
) != 'undefined') {
241 var is_confirmed
= confirm(theMessage
);
244 } // end of the 'confirmAction()' function
248 * Displays an error message if a "DROP DATABASE" statement is submitted
249 * while it isn't allowed, else confirms a "DROP/DELETE/ALTER" query before
250 * sumitting it if required.
251 * This function is called by the 'checkSqlQuery()' js function.
253 * @param object the form
254 * @param object the sql query textarea
256 * @return boolean whether to run the query or not
258 * @see checkSqlQuery()
260 function confirmQuery(theForm1
, sqlQuery1
)
262 // Confirmation is not required in the configuration file
263 if (PMA_messages
['strDoYouReally'] == '') {
267 // The replace function (js1.2) isn't supported
268 else if (typeof(sqlQuery1
.value
.replace
) == 'undefined') {
272 // js1.2+ -> validation with regular expressions
274 // "DROP DATABASE" statement isn't allowed
275 if (PMA_messages
['strNoDropDatabases'] != '') {
276 var drop_re
= new RegExp('(^|;)\\s*DROP\\s+(IF EXISTS\\s+)?DATABASE\\s', 'i');
277 if (drop_re
.test(sqlQuery1
.value
)) {
278 alert(PMA_messages
['strNoDropDatabases']);
285 // Confirms a "DROP/DELETE/ALTER/TRUNCATE" statement
287 // TODO: find a way (if possible) to use the parser-analyser
288 // for this kind of verification
289 // For now, I just added a ^ to check for the statement at
290 // beginning of expression
292 var do_confirm_re_0
= new RegExp('^\\s*DROP\\s+(IF EXISTS\\s+)?(TABLE|DATABASE|PROCEDURE)\\s', 'i');
293 var do_confirm_re_1
= new RegExp('^\\s*ALTER\\s+TABLE\\s+((`[^`]+`)|([A-Za-z0-9_$]+))\\s+DROP\\s', 'i');
294 var do_confirm_re_2
= new RegExp('^\\s*DELETE\\s+FROM\\s', 'i');
295 var do_confirm_re_3
= new RegExp('^\\s*TRUNCATE\\s', 'i');
297 if (do_confirm_re_0
.test(sqlQuery1
.value
)
298 || do_confirm_re_1
.test(sqlQuery1
.value
)
299 || do_confirm_re_2
.test(sqlQuery1
.value
)
300 || do_confirm_re_3
.test(sqlQuery1
.value
)) {
301 var message
= (sqlQuery1
.value
.length
> 100)
302 ? sqlQuery1
.value
.substr(0, 100) + '\n ...'
304 var is_confirmed
= confirm(PMA_messages
['strDoYouReally'] + ' :\n' + message
);
305 // statement is confirmed -> update the
306 // "is_js_confirmed" form field so the confirm test won't be
307 // run on the server side and allows to submit the form
309 theForm1
.elements
['is_js_confirmed'].value
= 1;
312 // statement is rejected -> do not submit the form
317 } // end if (handle confirm box result)
318 } // end if (display confirm box)
319 } // end confirmation stuff
322 } // end of the 'confirmQuery()' function
326 * Displays a confirmation box before disabling the BLOB repository for a given database.
327 * This function is called while clicking links
329 * @param object the database
331 * @return boolean whether to disable the repository or not
333 function confirmDisableRepository(theDB
)
335 // Confirmation is not required in the configuration file
336 // or browser is Opera (crappy js implementation)
337 if (PMA_messages
['strDoYouReally'] == '' || typeof(window
.opera
) != 'undefined') {
341 var is_confirmed
= confirm(PMA_messages
['strBLOBRepositoryDisableStrongWarning'] + '\n' + PMA_messages
['strBLOBRepositoryDisableAreYouSure']);
344 } // end of the 'confirmDisableBLOBRepository()' function
348 * Displays an error message if the user submitted the sql query form with no
349 * sql query, else checks for "DROP/DELETE/ALTER" statements
351 * @param object the form
353 * @return boolean always false
355 * @see confirmQuery()
357 function checkSqlQuery(theForm
)
359 var sqlQuery
= theForm
.elements
['sql_query'];
362 // The replace function (js1.2) isn't supported -> basic tests
363 if (typeof(sqlQuery
.value
.replace
) == 'undefined') {
364 isEmpty
= (sqlQuery
.value
== '') ? 1 : 0;
365 if (isEmpty
&& typeof(theForm
.elements
['sql_file']) != 'undefined') {
366 isEmpty
= (theForm
.elements
['sql_file'].value
== '') ? 1 : 0;
368 if (isEmpty
&& typeof(theForm
.elements
['sql_localfile']) != 'undefined') {
369 isEmpty
= (theForm
.elements
['sql_localfile'].value
== '') ? 1 : 0;
371 if (isEmpty
&& typeof(theForm
.elements
['id_bookmark']) != 'undefined') {
372 isEmpty
= (theForm
.elements
['id_bookmark'].value
== null || theForm
.elements
['id_bookmark'].value
== '');
375 // js1.2+ -> validation with regular expressions
377 var space_re
= new RegExp('\\s+');
378 if (typeof(theForm
.elements
['sql_file']) != 'undefined' &&
379 theForm
.elements
['sql_file'].value
.replace(space_re
, '') != '') {
382 if (typeof(theForm
.elements
['sql_localfile']) != 'undefined' &&
383 theForm
.elements
['sql_localfile'].value
.replace(space_re
, '') != '') {
386 if (isEmpty
&& typeof(theForm
.elements
['id_bookmark']) != 'undefined' &&
387 (theForm
.elements
['id_bookmark'].value
!= null || theForm
.elements
['id_bookmark'].value
!= '') &&
388 theForm
.elements
['id_bookmark'].selectedIndex
!= 0
392 // Checks for "DROP/DELETE/ALTER" statements
393 if (sqlQuery
.value
.replace(space_re
, '') != '') {
394 if (confirmQuery(theForm
, sqlQuery
)) {
406 alert(PMA_messages
['strFormEmpty']);
412 } // end of the 'checkSqlQuery()' function
415 * Check if a form's element is empty.
416 * An element containing only spaces is also considered empty
418 * @param object the form
419 * @param string the name of the form field to put the focus on
421 * @return boolean whether the form field is empty or not
423 function emptyCheckTheField(theForm
, theFieldName
)
426 var theField
= theForm
.elements
[theFieldName
];
427 // Whether the replace function (js1.2) is supported or not
428 var isRegExp
= (typeof(theField
.value
.replace
) != 'undefined');
431 isEmpty
= (theField
.value
== '') ? 1 : 0;
433 var space_re
= new RegExp('\\s+');
434 isEmpty
= (theField
.value
.replace(space_re
, '') == '') ? 1 : 0;
438 } // end of the 'emptyCheckTheField()' function
442 * Check whether a form field is empty or not
444 * @param object the form
445 * @param string the name of the form field to put the focus on
447 * @return boolean whether the form field is empty or not
449 function emptyFormElements(theForm
, theFieldName
)
451 var theField
= theForm
.elements
[theFieldName
];
452 var isEmpty
= emptyCheckTheField(theForm
, theFieldName
);
456 } // end of the 'emptyFormElements()' function
460 * Ensures a value submitted in a form is numeric and is in a range
462 * @param object the form
463 * @param string the name of the form field to check
464 * @param integer the minimum authorized value
465 * @param integer the maximum authorized value
467 * @return boolean whether a valid number has been submitted or not
469 function checkFormElementInRange(theForm
, theFieldName
, message
, min
, max
)
471 var theField
= theForm
.elements
[theFieldName
];
472 var val
= parseInt(theField
.value
);
474 if (typeof(min
) == 'undefined') {
477 if (typeof(max
) == 'undefined') {
478 max
= Number
.MAX_VALUE
;
484 alert(PMA_messages
['strNotNumber']);
488 // It's a number but it is not between min and max
489 else if (val
< min
|| val
> max
) {
491 alert(message
.replace('%d', val
));
495 // It's a valid number
497 theField
.value
= val
;
501 } // end of the 'checkFormElementInRange()' function
504 function checkTableEditForm(theForm
, fieldsCnt
)
506 // TODO: avoid sending a message if user just wants to add a line
507 // on the form but has not completed at least one field name
509 var atLeastOneField
= 0;
510 var i
, elm
, elm2
, elm3
, val
, id
;
512 for (i
=0; i
<fieldsCnt
; i
++)
514 id
= "#field_" + i
+ "_2";
517 if (val
== 'VARCHAR' || val
== 'CHAR' || val
== 'BIT' || val
== 'VARBINARY' || val
== 'BINARY') {
518 elm2
= $("#field_" + i
+ "_3");
519 val
= parseInt(elm2
.val());
520 elm3
= $("#field_" + i
+ "_1");
521 if (isNaN(val
) && elm3
.val() != "") {
523 alert(PMA_messages
['strNotNumber']);
529 if (atLeastOneField
== 0) {
530 id
= "field_" + i
+ "_1";
531 if (!emptyCheckTheField(theForm
, id
)) {
536 if (atLeastOneField
== 0) {
537 var theField
= theForm
.elements
["field_0_1"];
538 alert(PMA_messages
['strFormEmpty']);
543 // at least this section is under jQuery
544 if ($("input.textfield[name='table']").val() == "") {
545 alert(PMA_messages
['strFormEmpty']);
546 $("input.textfield[name='table']").focus();
552 } // enf of the 'checkTableEditForm()' function
556 * Ensures the choice between 'transmit', 'zipped', 'gzipped' and 'bzipped'
557 * checkboxes is consistant
559 * @param object the form
560 * @param string a code for the action that causes this function to be run
562 * @return boolean always true
564 function checkTransmitDump(theForm
, theAction
)
566 var formElts
= theForm
.elements
;
568 // 'zipped' option has been checked
569 if (theAction
== 'zip' && formElts
['zip'].checked
) {
570 if (!formElts
['asfile'].checked
) {
571 theForm
.elements
['asfile'].checked
= true;
573 if (typeof(formElts
['gzip']) != 'undefined' && formElts
['gzip'].checked
) {
574 theForm
.elements
['gzip'].checked
= false;
576 if (typeof(formElts
['bzip']) != 'undefined' && formElts
['bzip'].checked
) {
577 theForm
.elements
['bzip'].checked
= false;
580 // 'gzipped' option has been checked
581 else if (theAction
== 'gzip' && formElts
['gzip'].checked
) {
582 if (!formElts
['asfile'].checked
) {
583 theForm
.elements
['asfile'].checked
= true;
585 if (typeof(formElts
['zip']) != 'undefined' && formElts
['zip'].checked
) {
586 theForm
.elements
['zip'].checked
= false;
588 if (typeof(formElts
['bzip']) != 'undefined' && formElts
['bzip'].checked
) {
589 theForm
.elements
['bzip'].checked
= false;
592 // 'bzipped' option has been checked
593 else if (theAction
== 'bzip' && formElts
['bzip'].checked
) {
594 if (!formElts
['asfile'].checked
) {
595 theForm
.elements
['asfile'].checked
= true;
597 if (typeof(formElts
['zip']) != 'undefined' && formElts
['zip'].checked
) {
598 theForm
.elements
['zip'].checked
= false;
600 if (typeof(formElts
['gzip']) != 'undefined' && formElts
['gzip'].checked
) {
601 theForm
.elements
['gzip'].checked
= false;
604 // 'transmit' option has been unchecked
605 else if (theAction
== 'transmit' && !formElts
['asfile'].checked
) {
606 if (typeof(formElts
['zip']) != 'undefined' && formElts
['zip'].checked
) {
607 theForm
.elements
['zip'].checked
= false;
609 if ((typeof(formElts
['gzip']) != 'undefined' && formElts
['gzip'].checked
)) {
610 theForm
.elements
['gzip'].checked
= false;
612 if ((typeof(formElts
['bzip']) != 'undefined' && formElts
['bzip'].checked
)) {
613 theForm
.elements
['bzip'].checked
= false;
618 } // end of the 'checkTransmitDump()' function
620 $(document
).ready(function() {
622 * Row marking in horizontal mode (use "live" so that it works also for
623 * next pages reached via AJAX); a tr may have the class noclick to remove
626 $('tr.odd:not(.noclick), tr.even:not(.noclick)').live('click',function(e
) {
627 // do not trigger when clicked on anchor
628 if ($(e
.target
).is('a, img, a *')) {
633 // make the table unselectable (to prevent default highlighting when shift+click)
634 $tr
.parents('table').noSelect();
636 if (!e
.shiftKey
|| last_clicked_row
== -1) {
639 // XXX: FF fires two click events for <label> (label and checkbox), so we need to handle this differently
640 var $checkbox
= $tr
.find(':checkbox');
641 if ($checkbox
.length
) {
642 // checkbox in a row, add or remove class depending on checkbox state
643 var checked
= $checkbox
.attr('checked');
644 if (!$(e
.target
).is(':checkbox, label')) {
646 $checkbox
.attr('checked', checked
);
649 $tr
.addClass('marked');
651 $tr
.removeClass('marked');
653 last_click_checked
= checked
;
655 // normaln data table, just toggle class
656 $tr
.toggleClass('marked');
657 last_click_checked
= false;
660 // remember the last clicked row
661 last_clicked_row
= last_click_checked
? $('tr.odd:not(.noclick), tr.even:not(.noclick)').index(this) : -1;
662 last_shift_clicked_row
= -1;
664 // handle the shift click
667 // clear last shift click result
668 if (last_shift_clicked_row
>= 0) {
669 if (last_shift_clicked_row
>= last_clicked_row
) {
670 start
= last_clicked_row
;
671 end
= last_shift_clicked_row
;
673 start
= last_shift_clicked_row
;
674 end
= last_clicked_row
;
676 $tr
.parent().find('tr.odd:not(.noclick), tr.even:not(.noclick)')
677 .slice(start
, end
+ 1)
678 .removeClass('marked')
680 .attr('checked', false);
683 // handle new shift click
684 var curr_row
= $('tr.odd:not(.noclick), tr.even:not(.noclick)').index(this);
685 if (curr_row
>= last_clicked_row
) {
686 start
= last_clicked_row
;
690 end
= last_clicked_row
;
692 $tr
.parent().find('tr.odd:not(.noclick), tr.even:not(.noclick)')
693 .slice(start
, end
+ 1)
696 .attr('checked', true);
698 // remember the last shift clicked row
699 last_shift_clicked_row
= curr_row
;
704 * Add a date/time picker to each element that needs it
706 $('.datefield, .datetimefield').each(function() {
707 PMA_addDatepicker($(this));
712 * True if last click is to check a row.
714 var last_click_checked
= false;
717 * Zero-based index of last clicked row.
718 * Used to handle the shift + click event in the code above.
720 var last_clicked_row
= -1;
723 * Zero-based index of last shift clicked row.
725 var last_shift_clicked_row
= -1;
728 * Row highlighting in horizontal mode (use "live"
729 * so that it works also for pages reached via AJAX)
731 /*$(document).ready(function() {
732 $('tr.odd, tr.even').live('hover',function(event) {
734 $tr.toggleClass('hover',event.type=='mouseover');
735 $tr.children().toggleClass('hover',event.type=='mouseover');
740 * This array is used to remember mark status of rows in browse mode
742 var marked_row
= new Array
;
745 * marks all rows and selects its first checkbox inside the given element
746 * the given element is usaly a table or a div containing the table or tables
748 * @param container DOM element
750 function markAllRows( container_id
) {
752 $("#"+container_id
).find("input:checkbox:enabled").attr('checked', 'checked')
753 .parents("tr").addClass("marked");
758 * marks all rows and selects its first checkbox inside the given element
759 * the given element is usaly a table or a div containing the table or tables
761 * @param container DOM element
763 function unMarkAllRows( container_id
) {
765 $("#"+container_id
).find("input:checkbox:enabled").removeAttr('checked')
766 .parents("tr").removeClass("marked");
771 * Checks/unchecks all checkbox in given conainer (f.e. a form, fieldset or div)
773 * @param string container_id the container id
774 * @param boolean state new value for checkbox (true or false)
775 * @return boolean always true
777 function setCheckboxes( container_id
, state
) {
780 $("#"+container_id
).find("input:checkbox").attr('checked', 'checked');
783 $("#"+container_id
).find("input:checkbox").removeAttr('checked');
787 } // end of the 'setCheckboxes()' function
790 * Checks/unchecks all options of a <select> element
792 * @param string the form name
793 * @param string the element name
794 * @param boolean whether to check or to uncheck options
796 * @return boolean always true
798 function setSelectOptions(the_form
, the_select
, do_check
)
800 $("form[name='"+ the_form
+"'] select[name='"+the_select
+"']").find("option").attr('selected', do_check
);
802 } // end of the 'setSelectOptions()' function
805 * Sets current value for query box.
807 function setQuery(query
) {
808 if (codemirror_editor
) {
809 codemirror_editor
.setValue(query
);
811 document
.sqlform
.sql_query
.value
= query
;
817 * Create quick sql statements.
820 function insertQuery(queryType
) {
821 if (queryType
== "clear") {
826 var myQuery
= document
.sqlform
.sql_query
;
828 var myListBox
= document
.sqlform
.dummy
;
829 var table
= document
.sqlform
.table
.value
;
831 if (myListBox
.options
.length
> 0) {
832 sql_box_locked
= true;
837 for (var i
=0; i
< myListBox
.options
.length
; i
++) {
844 chaineAj
+= myListBox
.options
[i
].value
;
845 valDis
+= "[value-" + NbSelect
+ "]";
846 editDis
+= myListBox
.options
[i
].value
+ "=[value-" + NbSelect
+ "]";
848 if (queryType
== "selectall") {
849 query
= "SELECT * FROM `" + table
+ "` WHERE 1";
850 } else if (queryType
== "select") {
851 query
= "SELECT " + chaineAj
+ " FROM `" + table
+ "` WHERE 1";
852 } else if (queryType
== "insert") {
853 query
= "INSERT INTO `" + table
+ "`(" + chaineAj
+ ") VALUES (" + valDis
+ ")";
854 } else if (queryType
== "update") {
855 query
= "UPDATE `" + table
+ "` SET " + editDis
+ " WHERE 1";
856 } else if(queryType
== "delete") {
857 query
= "DELETE FROM `" + table
+ "` WHERE 1";
860 sql_box_locked
= false;
866 * Inserts multiple fields.
869 function insertValueQuery() {
870 var myQuery
= document
.sqlform
.sql_query
;
871 var myListBox
= document
.sqlform
.dummy
;
873 if(myListBox
.options
.length
> 0) {
874 sql_box_locked
= true;
877 for(var i
=0; i
<myListBox
.options
.length
; i
++) {
878 if (myListBox
.options
[i
].selected
){
882 chaineAj
+= myListBox
.options
[i
].value
;
886 /* CodeMirror support */
887 if (codemirror_editor
) {
888 codemirror_editor
.replaceSelection(chaineAj
);
890 } else if (document
.selection
) {
892 sel
= document
.selection
.createRange();
894 document
.sqlform
.insert
.focus();
896 //MOZILLA/NETSCAPE support
897 else if (document
.sqlform
.sql_query
.selectionStart
|| document
.sqlform
.sql_query
.selectionStart
== "0") {
898 var startPos
= document
.sqlform
.sql_query
.selectionStart
;
899 var endPos
= document
.sqlform
.sql_query
.selectionEnd
;
900 var chaineSql
= document
.sqlform
.sql_query
.value
;
902 myQuery
.value
= chaineSql
.substring(0, startPos
) + chaineAj
+ chaineSql
.substring(endPos
, chaineSql
.length
);
904 myQuery
.value
+= chaineAj
;
906 sql_box_locked
= false;
911 * listbox redirection
913 function goToUrl(selObj
, goToLocation
) {
914 eval("document.location.href = '" + goToLocation
+ "pos=" + selObj
.options
[selObj
.selectedIndex
].value
+ "'");
920 function getElement(e
,f
){
923 if(f
.document
.layers
[e
]) {
924 return f
.document
.layers
[e
];
926 for(W
=0;W
<f
.document
.layers
.length
;W
++) {
927 return(getElement(e
,f
.document
.layers
[W
]));
931 return document
.all
[e
];
933 return document
.getElementById(e
);
937 * Refresh the WYSIWYG scratchboard after changes have been made
939 function refreshDragOption(e
) {
940 var elm
= $('#' + e
);
941 if (elm
.css('visibility') == 'visible') {
948 * Refresh/resize the WYSIWYG scratchboard
950 function refreshLayout() {
951 var elm
= $('#pdflayout')
952 var orientation
= $('#orientation_opt').val();
953 if($('#paper_opt').length
==1){
954 var paper
= $('#paper_opt').val();
958 if (orientation
== 'P') {
965 elm
.css('width', pdfPaperSize(paper
, posa
) + 'px');
966 elm
.css('height', pdfPaperSize(paper
, posb
) + 'px');
970 * Show/hide the WYSIWYG scratchboard
972 function ToggleDragDrop(e
) {
973 var elm
= $('#' + e
);
974 if (elm
.css('visibility') == 'hidden') {
975 PDFinit(); /* Defined in pdf_pages.php */
976 elm
.css('visibility', 'visible');
977 elm
.css('display', 'block');
978 $('#showwysiwyg').val('1')
980 elm
.css('visibility', 'hidden');
981 elm
.css('display', 'none');
982 $('#showwysiwyg').val('0')
987 * PDF scratchboard: When a position is entered manually, update
988 * the fields inside the scratchboard.
990 function dragPlace(no
, axis
, value
) {
991 var elm
= $('#table_' + no
);
993 elm
.css('left', value
+ 'px');
995 elm
.css('top', value
+ 'px');
1000 * Returns paper sizes for a given format
1002 function pdfPaperSize(format
, axis
) {
1003 switch (format
.toUpperCase()) {
1005 if (axis
== 'x') return 4767.87; else return 6740.79;
1008 if (axis
== 'x') return 3370.39; else return 4767.87;
1011 if (axis
== 'x') return 2383.94; else return 3370.39;
1014 if (axis
== 'x') return 1683.78; else return 2383.94;
1017 if (axis
== 'x') return 1190.55; else return 1683.78;
1020 if (axis
== 'x') return 841.89; else return 1190.55;
1023 if (axis
== 'x') return 595.28; else return 841.89;
1026 if (axis
== 'x') return 419.53; else return 595.28;
1029 if (axis
== 'x') return 297.64; else return 419.53;
1032 if (axis
== 'x') return 209.76; else return 297.64;
1035 if (axis
== 'x') return 147.40; else return 209.76;
1038 if (axis
== 'x') return 104.88; else return 147.40;
1041 if (axis
== 'x') return 73.70; else return 104.88;
1044 if (axis
== 'x') return 2834.65; else return 4008.19;
1047 if (axis
== 'x') return 2004.09; else return 2834.65;
1050 if (axis
== 'x') return 1417.32; else return 2004.09;
1053 if (axis
== 'x') return 1000.63; else return 1417.32;
1056 if (axis
== 'x') return 708.66; else return 1000.63;
1059 if (axis
== 'x') return 498.90; else return 708.66;
1062 if (axis
== 'x') return 354.33; else return 498.90;
1065 if (axis
== 'x') return 249.45; else return 354.33;
1068 if (axis
== 'x') return 175.75; else return 249.45;
1071 if (axis
== 'x') return 124.72; else return 175.75;
1074 if (axis
== 'x') return 87.87; else return 124.72;
1077 if (axis
== 'x') return 2599.37; else return 3676.54;
1080 if (axis
== 'x') return 1836.85; else return 2599.37;
1083 if (axis
== 'x') return 1298.27; else return 1836.85;
1086 if (axis
== 'x') return 918.43; else return 1298.27;
1089 if (axis
== 'x') return 649.13; else return 918.43;
1092 if (axis
== 'x') return 459.21; else return 649.13;
1095 if (axis
== 'x') return 323.15; else return 459.21;
1098 if (axis
== 'x') return 229.61; else return 323.15;
1101 if (axis
== 'x') return 161.57; else return 229.61;
1104 if (axis
== 'x') return 113.39; else return 161.57;
1107 if (axis
== 'x') return 79.37; else return 113.39;
1110 if (axis
== 'x') return 2437.80; else return 3458.27;
1113 if (axis
== 'x') return 1729.13; else return 2437.80;
1116 if (axis
== 'x') return 1218.90; else return 1729.13;
1119 if (axis
== 'x') return 864.57; else return 1218.90;
1122 if (axis
== 'x') return 609.45; else return 864.57;
1125 if (axis
== 'x') return 2551.18; else return 3628.35;
1128 if (axis
== 'x') return 1814.17; else return 2551.18;
1131 if (axis
== 'x') return 1275.59; else return 1814.17;
1134 if (axis
== 'x') return 907.09; else return 1275.59;
1137 if (axis
== 'x') return 637.80; else return 907.09;
1140 if (axis
== 'x') return 612.00; else return 792.00;
1143 if (axis
== 'x') return 612.00; else return 1008.00;
1146 if (axis
== 'x') return 521.86; else return 756.00;
1149 if (axis
== 'x') return 612.00; else return 936.00;
1157 * for playing media from the BLOB repository
1160 * @param var url_params main purpose is to pass the token
1161 * @param var bs_ref BLOB repository reference
1162 * @param var m_type type of BLOB repository media
1163 * @param var w_width width of popup window
1164 * @param var w_height height of popup window
1166 function popupBSMedia(url_params
, bs_ref
, m_type
, is_cust_type
, w_width
, w_height
)
1168 // if width not specified, use default
1169 if (w_width
== undefined)
1172 // if height not specified, use default
1173 if (w_height
== undefined)
1176 // open popup window (for displaying video/playing audio)
1177 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');
1181 * popups a request for changing MIME types for files in the BLOB repository
1183 * @param var db database name
1184 * @param var table table name
1185 * @param var reference BLOB repository reference
1186 * @param var current_mime_type current MIME type associated with BLOB repository reference
1188 function requestMIMETypeChange(db
, table
, reference
, current_mime_type
)
1190 // no mime type specified, set to default (nothing)
1191 if (undefined == current_mime_type
)
1192 current_mime_type
= "";
1194 // prompt user for new mime type
1195 var new_mime_type
= prompt("Enter custom MIME type", current_mime_type
);
1197 // if new mime_type is specified and is not the same as the previous type, request for mime type change
1198 if (new_mime_type
&& new_mime_type
!= current_mime_type
)
1199 changeMIMEType(db
, table
, reference
, new_mime_type
);
1203 * changes MIME types for files in the BLOB repository
1205 * @param var db database name
1206 * @param var table table name
1207 * @param var reference BLOB repository reference
1208 * @param var mime_type new MIME type to be associated with BLOB repository reference
1210 function changeMIMEType(db
, table
, reference
, mime_type
)
1212 // specify url and parameters for jQuery POST
1213 var mime_chg_url
= 'bs_change_mime_type.php';
1214 var params
= {bs_db
: db
, bs_table
: table
, bs_reference
: reference
, bs_new_mime_type
: mime_type
};
1217 jQuery
.post(mime_chg_url
, params
);
1221 * Jquery Coding for inline editing SQL_QUERY
1223 $(document
).ready(function(){
1224 $(".inline_edit_sql").live('click', function(){
1225 var server
= $(this).prev().find("input[name='server']").val();
1226 var db
= $(this).prev().find("input[name='db']").val();
1227 var table
= $(this).prev().find("input[name='table']").val();
1228 var token
= $(this).prev().find("input[name='token']").val();
1229 var sql_query
= $(this).prev().find("input[name='sql_query']").val();
1230 var $inner_sql
= $(this).parent().prev().find('.inner_sql');
1231 var old_text
= $inner_sql
.html();
1233 var new_content
= "<textarea name=\"sql_query_edit\" id=\"sql_query_edit\">" + sql_query
+ "</textarea>\n";
1234 new_content
+= "<input type=\"button\" class=\"btnSave\" value=\"" + PMA_messages
['strGo'] + "\">\n";
1235 new_content
+= "<input type=\"button\" class=\"btnDiscard\" value=\"" + PMA_messages
['strCancel'] + "\">\n";
1236 $inner_sql
.replaceWith(new_content
);
1237 $(".btnSave").each(function(){
1238 $(this).click(function(){
1239 sql_query
= $(this).prev().val();
1240 window
.location
.replace("import.php"
1241 + "?server=" + encodeURIComponent(server
)
1242 + "&db=" + encodeURIComponent(db
)
1243 + "&table=" + encodeURIComponent(table
)
1244 + "&sql_query=" + encodeURIComponent(sql_query
)
1246 + "&token=" + token
);
1249 $(".btnDiscard").each(function(){
1250 $(this).click(function(){
1251 $(this).closest(".sql").html("<span class=\"syntax\"><span class=\"inner_sql\">" + old_text
+ "</span></span>");
1257 $('.sqlbutton').click(function(evt
){
1258 insertQuery(evt
.target
.id
);
1262 $("#export_type").change(function(){
1263 if($("#export_type").val()=='svg'){
1264 $("#show_grid_opt").attr("disabled","disabled");
1265 $("#orientation_opt").attr("disabled","disabled");
1266 $("#with_doc").attr("disabled","disabled");
1267 $("#show_table_dim_opt").removeAttr("disabled");
1268 $("#all_table_same_wide").removeAttr("disabled");
1269 $("#paper_opt").removeAttr("disabled","disabled");
1270 $("#show_color_opt").removeAttr("disabled","disabled");
1271 //$(this).css("background-color","yellow");
1272 }else if($("#export_type").val()=='dia'){
1273 $("#show_grid_opt").attr("disabled","disabled");
1274 $("#with_doc").attr("disabled","disabled");
1275 $("#show_table_dim_opt").attr("disabled","disabled");
1276 $("#all_table_same_wide").attr("disabled","disabled");
1277 $("#paper_opt").removeAttr("disabled","disabled");
1278 $("#show_color_opt").removeAttr("disabled","disabled");
1279 $("#orientation_opt").removeAttr("disabled","disabled");
1280 }else if($("#export_type").val()=='eps'){
1281 $("#show_grid_opt").attr("disabled","disabled");
1282 $("#orientation_opt").removeAttr("disabled");
1283 $("#with_doc").attr("disabled","disabled");
1284 $("#show_table_dim_opt").attr("disabled","disabled");
1285 $("#all_table_same_wide").attr("disabled","disabled");
1286 $("#paper_opt").attr("disabled","disabled");
1287 $("#show_color_opt").attr("disabled","disabled");
1289 }else if($("#export_type").val()=='pdf'){
1290 $("#show_grid_opt").removeAttr("disabled");
1291 $("#orientation_opt").removeAttr("disabled");
1292 $("#with_doc").removeAttr("disabled","disabled");
1293 $("#show_table_dim_opt").removeAttr("disabled","disabled");
1294 $("#all_table_same_wide").removeAttr("disabled","disabled");
1295 $("#paper_opt").removeAttr("disabled","disabled");
1296 $("#show_color_opt").removeAttr("disabled","disabled");
1302 $('#sqlquery').focus().keydown(function (e
) {
1303 if (e
.ctrlKey
&& e
.keyCode
== 13) {
1304 $("#sqlqueryform").submit();
1308 if ($('#input_username')) {
1309 if ($('#input_username').val() == '') {
1310 $('#input_username').focus();
1312 $('#input_password').focus();
1318 * Show a message on the top of the page for an Ajax request
1320 * @param var message string containing the message to be shown.
1321 * optional, defaults to 'Loading...'
1322 * @param var timeout number of milliseconds for the message to be visible
1323 * optional, defaults to 5000
1324 * @return jQuery object jQuery Element that holds the message div
1326 function PMA_ajaxShowMessage(message
, timeout
) {
1328 //Handle the case when a empty data.message is passed. We don't want the empty message
1329 if (message
== '') {
1331 } else if (! message
) {
1332 // If the message is undefined, show the default
1333 message
= PMA_messages
['strLoading'];
1337 * @var timeout Number of milliseconds for which the message will be visible
1344 // Create a parent element for the AJAX messages, if necessary
1345 if ($('#loading_parent').length
== 0) {
1346 $('<div id="loading_parent"></div>')
1347 .insertBefore("#serverinfo");
1350 // Update message count to create distinct message elements every time
1351 ajax_message_count
++;
1353 // Remove all old messages, if any
1354 $(".ajax_notification[id^=ajax_message_num]").remove();
1357 * @var $retval a jQuery object containing the reference
1358 * to the created AJAX message
1360 var $retval
= $('<span class="ajax_notification" id="ajax_message_num_' + ajax_message_count
+ '"></span>')
1362 .appendTo("#loading_parent")
1366 .fadeOut('medium', function() {
1374 * Removes the message shown for an Ajax operation when it's completed
1376 function PMA_ajaxRemoveMessage($this_msgbox
) {
1377 if ($this_msgbox
!= undefined && $this_msgbox
instanceof jQuery
) {
1385 * Hides/shows the "Open in ENUM/SET editor" message, depending on the data type of the column currently selected
1387 function PMA_showNoticeForEnum(selectElement
) {
1388 var enum_notice_id
= selectElement
.attr("id").split("_")[1];
1389 enum_notice_id
+= "_" + (parseInt(selectElement
.attr("id").split("_")[2]) + 1);
1390 var selectedType
= selectElement
.attr("value");
1391 if (selectedType
== "ENUM" || selectedType
== "SET") {
1392 $("p[id='enum_notice_" + enum_notice_id
+ "']").show();
1394 $("p[id='enum_notice_" + enum_notice_id
+ "']").hide();
1399 * Generates a dialog box to pop up the create_table form
1401 function PMA_createTableDialog( div
, url
, target
) {
1403 * @var button_options Object that stores the options passed to jQueryUI
1406 var button_options
= {};
1407 // in the following function we need to use $(this)
1408 button_options
[PMA_messages
['strCancel']] = function() {$(this).parent().dialog('close').remove();}
1410 var button_options_error
= {};
1411 button_options_error
[PMA_messages
['strOK']] = function() {$(this).parent().dialog('close').remove();}
1413 var $msgbox
= PMA_ajaxShowMessage();
1415 $.get( target
, url
, function(data
) {
1416 //in the case of an error, show the error message returned.
1417 if (data
.success
!= undefined && data
.success
== false) {
1421 title
: PMA_messages
['strCreateTable'],
1424 open
: PMA_verifyTypeOfAllColumns
,
1425 buttons
: button_options_error
1426 })// end dialog options
1427 //remove the redundant [Back] link in the error message.
1428 .find('fieldset').remove();
1433 title
: PMA_messages
['strCreateTable'],
1436 open
: PMA_verifyTypeOfAllColumns
,
1437 buttons
: button_options
1438 }); // end dialog options
1440 PMA_ajaxRemoveMessage($msgbox
);
1446 * Creates a highcharts chart in the given container
1448 * @param var settings object with highcharts properties that should be applied. (See also http://www.highcharts.com/ref/)
1449 * requires at least settings.chart.renderTo and settings.series to be set.
1450 * In addition there may be an additional property object 'realtime' that allows for realtime charting:
1452 * url: adress to get the data from (will always add token, ajax_request=1 and chart_data=1 to the GET request)
1453 * type: the GET request will also add type=[value of the type property] to the request
1454 * callback: Callback function that should draw the point, it's called with 4 parameters in this order:
1455 * - the chart object
1456 * - the current response value of the GET request, JSON parsed
1457 * - the previous response value of the GET request, JSON parsed
1458 * - the number of added points
1460 * @return object The created highcharts instance
1462 function PMA_createChart(passedSettings
) {
1463 var container
= passedSettings
.chart
.renderTo
;
1469 backgroundColor
: 'transparent',
1471 /* Live charting support */
1473 var thisChart
= this;
1474 var lastValue
= null, curValue
= null;
1475 var numLoadedPoints
= 0, otherSum
= 0;
1478 // No realtime updates for graphs that are being exported, and disabled when realtime is not set
1479 // Also don't do live charting if we don't have the server time
1480 if(thisChart
.options
.chart
.forExport
== true ||
1481 ! thisChart
.options
.realtime
||
1482 ! thisChart
.options
.realtime
.callback
||
1483 ! server_time_diff
) return;
1485 thisChart
.options
.realtime
.timeoutCallBack = function() {
1486 thisChart
.options
.realtime
.postRequest
= $.post(
1487 thisChart
.options
.realtime
.url
,
1488 thisChart
.options
.realtime
.postData
,
1490 curValue
= jQuery
.parseJSON(data
);
1492 if(lastValue
==null) diff
= curValue
.x
- thisChart
.xAxis
[0].getExtremes().max
;
1493 else diff
= parseInt(curValue
.x
- lastValue
.x
);
1495 thisChart
.xAxis
[0].setExtremes(
1496 thisChart
.xAxis
[0].getExtremes().min
+diff
,
1497 thisChart
.xAxis
[0].getExtremes().max
+diff
,
1501 thisChart
.options
.realtime
.callback(thisChart
,curValue
,lastValue
,numLoadedPoints
);
1503 lastValue
= curValue
;
1506 // Timeout has been cleared => don't start a new timeout
1507 if(chart_activeTimeouts
[container
] == null) return;
1509 chart_activeTimeouts
[container
] = setTimeout(
1510 thisChart
.options
.realtime
.timeoutCallBack
,
1511 thisChart
.options
.realtime
.refreshRate
1516 chart_activeTimeouts
[container
] = setTimeout(thisChart
.options
.realtime
.timeoutCallBack
, 5);
1536 text
: PMA_messages
['strTotalCount']
1545 formatter: function() {
1546 return '<b>' + this.series
.name
+'</b><br/>' +
1547 Highcharts
.dateFormat('%Y-%m-%d %H:%M:%S', this.x
) + '<br/>' +
1548 Highcharts
.numberFormat(this.y
, 2);
1557 /* Set/Get realtime chart default values */
1558 if(passedSettings.realtime) {
1559 if(!passedSettings.realtime.refreshRate)
1560 passedSettings.realtime.refreshRate = 5000;
1562 if(!passedSettings.realtime.numMaxPoints)
1563 passedSettings.realtime.numMaxPoints = 30;
1565 // Allow custom POST vars to be added
1566 passedSettings.realtime.postData = $.extend(false,{ ajax_request: true, chart_data: 1, type: passedSettings.realtime.type },passedSettings.realtime.postData);
1568 if(server_time_diff) {
1569 settings.xAxis.min = new Date().getTime() - server_time_diff - passedSettings.realtime.numMaxPoints * passedSettings.realtime.refreshRate;
1570 settings.xAxis.max = new Date().getTime() - server_time_diff + passedSettings.realtime.refreshRate;
1574 // Overwrite/Merge default settings with passedsettings
1575 $.extend(true,settings,passedSettings);
1577 return new Highcharts.Chart(settings);
1581 * jQuery function that uses jQueryUI's dialogs to confirm with user. Does not
1582 * return a jQuery object yet and hence cannot be chained
1584 * @param string question
1585 * @param string url URL to be passed to the callbackFn to make
1587 * @param function callbackFn callback to execute after user clicks on OK
1590 jQuery
.fn
.PMA_confirm = function(question
, url
, callbackFn
) {
1591 if (PMA_messages
['strDoYouReally'] == '') {
1596 * @var button_options Object that stores the options passed to jQueryUI
1599 var button_options
= {};
1600 button_options
[PMA_messages
['strOK']] = function(){
1601 $(this).dialog("close").remove();
1603 if($.isFunction(callbackFn
)) {
1604 callbackFn
.call(this, url
);
1607 button_options
[PMA_messages
['strCancel']] = function() {$(this).dialog("close").remove();}
1609 $('<div id="confirm_dialog"></div>')
1611 .dialog({buttons
: button_options
});
1615 * jQuery function to sort a table's body after a new row has been appended to it.
1616 * Also fixes the even/odd classes of the table rows at the end.
1618 * @param string text_selector string to select the sortKey's text
1620 * @return jQuery Object for chaining purposes
1622 jQuery
.fn
.PMA_sort_table = function(text_selector
) {
1623 return this.each(function() {
1626 * @var table_body Object referring to the table's <tbody> element
1628 var table_body
= $(this);
1630 * @var rows Object referring to the collection of rows in {@link table_body}
1632 var rows
= $(this).find('tr').get();
1634 //get the text of the field that we will sort by
1635 $.each(rows
, function(index
, row
) {
1636 row
.sortKey
= $.trim($(row
).find(text_selector
).text().toLowerCase());
1639 //get the sorted order
1640 rows
.sort(function(a
,b
) {
1641 if(a
.sortKey
< b
.sortKey
) {
1644 if(a
.sortKey
> b
.sortKey
) {
1650 //pull out each row from the table and then append it according to it's order
1651 $.each(rows
, function(index
, row
) {
1652 $(table_body
).append(row
);
1656 //Re-check the classes of each row
1657 $(this).find('tr:odd')
1658 .removeClass('even').addClass('odd')
1661 .removeClass('odd').addClass('even');
1666 * jQuery coding for 'Create Table'. Used on db_operations.php,
1667 * db_structure.php and db_tracking.php (i.e., wherever
1668 * libraries/display_create_table.lib.php is used)
1670 * Attach Ajax Event handlers for Create Table
1672 $(document
).ready(function() {
1675 * Attach event handler to the submit action of the create table minimal form
1676 * and retrieve the full table form and display it in a dialog
1678 * @uses PMA_ajaxShowMessage()
1680 $("#create_table_form_minimal.ajax").live('submit', function(event
) {
1681 event
.preventDefault();
1683 PMA_prepareForAjaxRequest($form
);
1685 /*variables which stores the common attributes*/
1686 var url
= $form
.serialize();
1687 var action
= $form
.attr('action');
1688 var div
= $('<div id="create_table_dialog"></div>');
1690 /*Calling to the createTableDialog function*/
1691 PMA_createTableDialog(div
, url
, action
);
1693 // empty table name and number of columns from the minimal form
1694 $form
.find('input[name=table],input[name=num_fields]').val('');
1698 * Attach event handler for submission of create table form (save)
1700 * @uses PMA_ajaxShowMessage()
1701 * @uses $.PMA_sort_table()
1704 // .live() must be called after a selector, see http://api.jquery.com/live
1705 $("#create_table_form input[name=do_save_data]").live('click', function(event
) {
1706 event
.preventDefault();
1709 * @var the_form object referring to the create table form
1711 var $form
= $("#create_table_form");
1714 * First validate the form; if there is a problem, avoid submitting it
1716 * checkTableEditForm() needs a pure element and not a jQuery object,
1717 * this is why we pass $form[0] as a parameter (the jQuery object
1718 * is actually an array of DOM elements)
1721 if (checkTableEditForm($form
[0], $form
.find('input[name=orig_num_fields]').val())) {
1722 // OK, form passed validation step
1723 if ($form
.hasClass('ajax')) {
1724 PMA_ajaxShowMessage(PMA_messages
['strProcessingRequest']);
1725 PMA_prepareForAjaxRequest($form
);
1726 //User wants to submit the form
1727 $.post($form
.attr('action'), $form
.serialize() + "&do_save_data=" + $(this).val(), function(data
) {
1728 if(data
.success
== true) {
1729 $('#properties_message')
1730 .removeClass('error')
1732 PMA_ajaxShowMessage(data
.message
);
1733 // Only if the create table dialog (distinct panel) exists
1734 if ($("#create_table_dialog").length
> 0) {
1735 $("#create_table_dialog").dialog("close").remove();
1739 * @var tables_table Object referring to the <tbody> element that holds the list of tables
1741 var tables_table
= $("#tablesForm").find("tbody").not("#tbl_summary_row");
1742 // this is the first table created in this db
1743 if (tables_table
.length
== 0) {
1744 if (window
.parent
&& window
.parent
.frame_content
) {
1745 window
.parent
.frame_content
.location
.reload();
1749 * @var curr_last_row Object referring to the last <tr> element in {@link tables_table}
1751 var curr_last_row
= $(tables_table
).find('tr:last');
1753 * @var curr_last_row_index_string String containing the index of {@link curr_last_row}
1755 var curr_last_row_index_string
= $(curr_last_row
).find('input:checkbox').attr('id').match(/\d+/)[0];
1757 * @var curr_last_row_index Index of {@link curr_last_row}
1759 var curr_last_row_index
= parseFloat(curr_last_row_index_string
);
1761 * @var new_last_row_index Index of the new row to be appended to {@link tables_table}
1763 var new_last_row_index
= curr_last_row_index
+ 1;
1765 * @var new_last_row_id String containing the id of the row to be appended to {@link tables_table}
1767 var new_last_row_id
= 'checkbox_tbl_' + new_last_row_index
;
1769 data
.new_table_string
= data
.new_table_string
.replace(/checkbox_tbl_/, new_last_row_id
);
1771 $(data
.new_table_string
)
1772 .appendTo(tables_table
);
1775 $(tables_table
).PMA_sort_table('th');
1778 //Refresh navigation frame as a new table has been added
1779 if (window
.parent
&& window
.parent
.frame_navigation
) {
1780 window
.parent
.frame_navigation
.location
.reload();
1783 $('#properties_message')
1786 // scroll to the div containing the error message
1787 $('#properties_message')[0].scrollIntoView();
1790 } // end if ($form.hasClass('ajax')
1793 $form
.append('<input type="hidden" name="do_save_data" value="save" />');
1796 } // end if (checkTableEditForm() )
1797 }) // end create table form (save)
1800 * Attach event handler for create table form (add fields)
1802 * @uses PMA_ajaxShowMessage()
1803 * @uses $.PMA_sort_table()
1804 * @uses window.parent.refreshNavigation()
1807 // .live() must be called after a selector, see http://api.jquery.com/live
1808 $("#create_table_form.ajax input[name=submit_num_fields]").live('click', function(event
) {
1809 event
.preventDefault();
1812 * @var the_form object referring to the create table form
1814 var $form
= $("#create_table_form");
1816 var $msgbox
= PMA_ajaxShowMessage(PMA_messages
['strProcessingRequest']);
1817 PMA_prepareForAjaxRequest($form
);
1819 //User wants to add more fields to the table
1820 $.post($form
.attr('action'), $form
.serialize() + "&submit_num_fields=" + $(this).val(), function(data
) {
1821 // if 'create_table_dialog' exists
1822 if ($("#create_table_dialog").length
> 0) {
1823 $("#create_table_dialog").html(data
);
1825 // if 'create_table_div' exists
1826 if ($("#create_table_div").length
> 0) {
1827 $("#create_table_div").html(data
);
1829 PMA_verifyTypeOfAllColumns();
1830 PMA_ajaxRemoveMessage($msgbox
);
1833 }) // end create table form (add fields)
1835 }, 'top.frame_content'); //end $(document).ready for 'Create Table'
1838 * jQuery coding for 'Change Table'. Used on tbl_structure.php *
1839 * Attach Ajax Event handlers for Change Table
1841 $(document
).ready(function() {
1843 *Ajax action for submitting the column change form
1845 $("#append_fields_form input[name=do_save_data]").live('click', function(event
) {
1846 event
.preventDefault();
1848 * @var the_form object referring to the export form
1850 var $form
= $("#append_fields_form");
1853 * First validate the form; if there is a problem, avoid submitting it
1855 * checkTableEditForm() needs a pure element and not a jQuery object,
1856 * this is why we pass $form[0] as a parameter (the jQuery object
1857 * is actually an array of DOM elements)
1859 if (checkTableEditForm($form
[0], $form
.find('input[name=orig_num_fields]').val())) {
1860 // OK, form passed validation step
1861 if ($form
.hasClass('ajax')) {
1862 PMA_prepareForAjaxRequest($form
);
1863 //User wants to submit the form
1864 $.post($form
.attr('action'), $form
.serialize()+"&do_save_data=Save", function(data
) {
1865 if ($("#sqlqueryresults").length
!= 0) {
1866 $("#sqlqueryresults").remove();
1867 } else if ($(".error").length
!= 0) {
1868 $(".error").remove();
1870 if (data
.success
== true) {
1871 PMA_ajaxShowMessage(data
.message
);
1872 $("<div id='sqlqueryresults'></div>").insertAfter("#topmenucontainer");
1873 $("#sqlqueryresults").html(data
.sql_query
);
1874 $("#result_query .notice").remove();
1875 $("#result_query").prepend((data
.message
));
1876 if ($("#change_column_dialog").length
> 0) {
1877 $("#change_column_dialog").dialog("close").remove();
1879 /*Reload the field form*/
1880 $.post($("#fieldsForm").attr('action'), $("#fieldsForm").serialize()+"&ajax_request=true", function(form_data
) {
1881 $("#fieldsForm").remove();
1882 var $temp_div
= $("<div id='temp_div'><div>").append(form_data
);
1883 if ($("#sqlqueryresults").length
!= 0) {
1884 $temp_div
.find("#fieldsForm").insertAfter("#sqlqueryresults");
1886 $temp_div
.find("#fieldsForm").insertAfter(".error");
1888 /*Call the function to display the more options in table*/
1889 displayMoreTableOpts();
1892 var $temp_div
= $("<div id='temp_div'><div>").append(data
);
1893 var $error
= $temp_div
.find(".error code").addClass("error");
1894 PMA_ajaxShowMessage($error
);
1899 $form
.append('<input type="hidden" name="do_save_data" value="Save" />');
1903 }) // end change table button "do_save_data"
1905 }, 'top.frame_content'); //end $(document).ready for 'Change Table'
1908 * Attach Ajax event handlers for Drop Database. Moved here from db_structure.js
1909 * as it was also required on db_create.php
1911 * @uses $.PMA_confirm()
1912 * @uses PMA_ajaxShowMessage()
1913 * @uses window.parent.refreshNavigation()
1914 * @uses window.parent.refreshMain()
1915 * @see $cfg['AjaxEnable']
1917 $(document
).ready(function() {
1918 $("#drop_db_anchor").live('click', function(event
) {
1919 event
.preventDefault();
1921 //context is top.frame_content, so we need to use window.parent.db to access the db var
1923 * @var question String containing the question to be asked for confirmation
1925 var question
= PMA_messages
['strDropDatabaseStrongWarning'] + '\n' + PMA_messages
['strDoYouReally'] + ' :\n' + 'DROP DATABASE ' + window
.parent
.db
;
1927 $(this).PMA_confirm(question
, $(this).attr('href') ,function(url
) {
1929 PMA_ajaxShowMessage(PMA_messages
['strProcessingRequest']);
1930 $.get(url
, {'is_js_confirmed': '1', 'ajax_request': true}, function(data
) {
1931 //Database deleted successfully, refresh both the frames
1932 window
.parent
.refreshNavigation();
1933 window
.parent
.refreshMain();
1935 }); // end $.PMA_confirm()
1936 }); //end of Drop Database Ajax action
1937 }) // end of $(document).ready() for Drop Database
1940 * Attach Ajax event handlers for 'Create Database'. Used wherever libraries/
1941 * display_create_database.lib.php is used, ie main.php and server_databases.php
1943 * @uses PMA_ajaxShowMessage()
1944 * @see $cfg['AjaxEnable']
1946 $(document
).ready(function() {
1948 $('#create_database_form.ajax').live('submit', function(event
) {
1949 event
.preventDefault();
1953 PMA_ajaxShowMessage(PMA_messages
['strProcessingRequest']);
1954 PMA_prepareForAjaxRequest($form
);
1956 $.post($form
.attr('action'), $form
.serialize(), function(data
) {
1957 if(data
.success
== true) {
1958 PMA_ajaxShowMessage(data
.message
);
1960 //Append database's row to table
1961 $("#tabledatabases")
1963 .append(data
.new_db_string
)
1964 .PMA_sort_table('.name')
1965 .find('#db_summary_row')
1966 .appendTo('#tabledatabases tbody')
1967 .removeClass('odd even');
1969 var $databases_count_object
= $('#databases_count');
1970 var databases_count
= parseInt($databases_count_object
.text());
1971 $databases_count_object
.text(++databases_count
);
1972 //Refresh navigation frame as a new database has been added
1973 if (window
.parent
&& window
.parent
.frame_navigation
) {
1974 window
.parent
.frame_navigation
.location
.reload();
1978 PMA_ajaxShowMessage(data
.error
);
1981 }) // end $().live()
1982 }) // end $(document).ready() for Create Database
1985 * Attach Ajax event handlers for 'Change Password' on main.php
1987 $(document
).ready(function() {
1990 * Attach Ajax event handler on the change password anchor
1991 * @see $cfg['AjaxEnable']
1993 $('#change_password_anchor.dialog_active').live('click',function(event
) {
1994 event
.preventDefault();
1997 $('#change_password_anchor.ajax').live('click', function(event
) {
1998 event
.preventDefault();
1999 $(this).removeClass('ajax').addClass('dialog_active');
2001 * @var button_options Object containing options to be passed to jQueryUI's dialog
2003 var button_options
= {};
2004 button_options
[PMA_messages
['strCancel']] = function() {$(this).dialog('close').remove();}
2005 $.get($(this).attr('href'), {'ajax_request': true}, function(data
) {
2006 $('<div id="change_password_dialog"></div>')
2008 title
: PMA_messages
['strChangePassword'],
2010 close: function(ev
,ui
) {$(this).remove();},
2011 buttons
: button_options
,
2012 beforeClose: function(ev
,ui
){ $('#change_password_anchor.dialog_active').removeClass('dialog_active').addClass('ajax')}
2015 displayPasswordGenerateButton();
2017 }) // end handler for change password anchor
2020 * Attach Ajax event handler for Change Password form submission
2022 * @uses PMA_ajaxShowMessage()
2023 * @see $cfg['AjaxEnable']
2025 $("#change_password_form.ajax").find('input[name=change_pw]').live('click', function(event
) {
2026 event
.preventDefault();
2029 * @var the_form Object referring to the change password form
2031 var the_form
= $("#change_password_form");
2034 * @var this_value String containing the value of the submit button.
2035 * Need to append this for the change password form on Server Privileges
2038 var this_value
= $(this).val();
2040 var $msgbox
= PMA_ajaxShowMessage(PMA_messages
['strProcessingRequest']);
2041 $(the_form
).append('<input type="hidden" name="ajax_request" value="true" />');
2043 $.post($(the_form
).attr('action'), $(the_form
).serialize() + '&change_pw='+ this_value
, function(data
) {
2044 if(data
.success
== true) {
2045 $("#topmenucontainer").after(data
.sql_query
);
2046 $("#change_password_dialog").hide().remove();
2047 $("#edit_user_dialog").dialog("close").remove();
2048 $('#change_password_anchor.dialog_active').removeClass('dialog_active').addClass('ajax');
2049 PMA_ajaxRemoveMessage($msgbox
);
2052 PMA_ajaxShowMessage(data
.error
);
2055 }) // end handler for Change Password form submission
2056 }) // end $(document).ready() for Change Password
2059 * Toggle the hiding/showing of the "Open in ENUM/SET editor" message when
2060 * the page loads and when the selected data type changes
2062 $(document
).ready(function() {
2063 // is called here for normal page loads and also when opening
2064 // the Create table dialog
2065 PMA_verifyTypeOfAllColumns();
2067 // needs live() to work also in the Create Table dialog
2068 $("select[class='column_type']").live('change', function() {
2069 PMA_showNoticeForEnum($(this));
2073 function PMA_verifyTypeOfAllColumns() {
2074 $("select[class='column_type']").each(function() {
2075 PMA_showNoticeForEnum($(this));
2080 * Closes the ENUM/SET editor and removes the data in it
2082 function disable_popup() {
2083 $("#popup_background").fadeOut("fast");
2084 $("#enum_editor").fadeOut("fast");
2085 // clear the data from the text boxes
2086 $("#enum_editor #values input").remove();
2087 $("#enum_editor input[type='hidden']").remove();
2091 * Opens the ENUM/SET editor and controls its functions
2093 $(document
).ready(function() {
2094 // Needs live() to work also in the Create table dialog
2095 $("a[class='open_enum_editor']").live('click', function() {
2097 var windowWidth
= document
.documentElement
.clientWidth
;
2098 var windowHeight
= document
.documentElement
.clientHeight
;
2099 var popupWidth
= windowWidth
/2;
2100 var popupHeight
= windowHeight
*0.8;
2101 var popupOffsetTop
= windowHeight
/2 - popupHeight/2;
2102 var popupOffsetLeft
= windowWidth
/2 - popupWidth/2;
2103 $("#enum_editor").css({"position":"absolute", "top": popupOffsetTop
, "left": popupOffsetLeft
, "width": popupWidth
, "height": popupHeight
});
2106 $("#popup_background").css({"opacity":"0.7"});
2107 $("#popup_background").fadeIn("fast");
2108 $("#enum_editor").fadeIn("fast");
2111 var values
= $(this).parent().prev("input").attr("value").split(",");
2112 $.each(values
, function(index
, val
) {
2113 if(jQuery
.trim(val
) != "") {
2114 // enclose the string in single quotes if it's not already
2115 if(val
.substr(0, 1) != "'") {
2118 if(val
.substr(val
.length
-1, val
.length
) != "'") {
2121 // escape the single quotes, except the mandatory ones enclosing the entire string
2122 val
= val
.substr(1, val
.length
-2).replace(/''/g, "'").replace(/\\\\/g, '\\').replace(/\\'/g, "'").replace(/'/g, "'");
2123 // escape the greater-than symbol
2124 val = val.replace(/>/g, ">
;");
2125 $("#enum_editor
#values
").append("<input type
='text' value
=" + val + " />");
2128 // So we know which column's data is being edited
2129 $("#enum_editor
").append("<input type
='hidden' value
='" + $(this).parent().prev("input").attr("id") + "' />");
2133 // If the "close
" link is clicked, close the enum editor
2134 // Needs live() to work also in the Create table dialog
2135 $("a
[class='close_enum_editor']").live('click', function() {
2139 // If the "cancel
" link is clicked, close the enum editor
2140 // Needs live() to work also in the Create table dialog
2141 $("a
[class='cancel_enum_editor']").live('click', function() {
2145 // When "add a
new value
" is clicked, append an empty text field
2146 // Needs live() to work also in the Create table dialog
2147 $("a
[class='add_value']").live('click', function() {
2148 $("#enum_editor
#values
").append("<input type
='text' />");
2151 // When the submit button is clicked, put the data back into the original form
2152 // Needs live() to work also in the Create table dialog
2153 $("#enum_editor input
[type
='submit']").live('click', function() {
2154 var value_array = new Array();
2155 $.each($("#enum_editor
#values input
"), function(index, input_element) {
2156 val = jQuery.trim(input_element.value);
2158 value_array.push("'" + val.replace(/\\/g, '\\\\').replace(/'/g
, "''") + "'");
2161 // get the Length/Values text field where this value belongs
2162 var values_id
= $("#enum_editor input[type='hidden']").attr("value");
2163 $("input[id='" + values_id
+ "']").attr("value", value_array
.join(","));
2168 * Hides certain table structure actions, replacing them with the word "More". They are displayed
2169 * in a dropdown menu when the user hovers over the word "More."
2171 displayMoreTableOpts();
2174 function displayMoreTableOpts() {
2175 // Remove the actions from the table cells (they are available by default for JavaScript-disabled browsers)
2176 // if the table is not a view or information_schema (otherwise there is only one action to hide and there's no point)
2177 if($("input[type='hidden'][name='table_type']").val() == "table") {
2178 var $table
= $("table[id='tablestructure']");
2179 $table
.find("td[class='browse']").remove();
2180 $table
.find("td[class='primary']").remove();
2181 $table
.find("td[class='unique']").remove();
2182 $table
.find("td[class='index']").remove();
2183 $table
.find("td[class='fulltext']").remove();
2184 $table
.find("td[class='spatial']").remove();
2185 $table
.find("th[class='action']").attr("colspan", 3);
2187 // Display the "more" text
2188 $table
.find("td[class='more_opts']").show();
2190 // Position the dropdown
2191 $(".structure_actions_dropdown").each(function() {
2192 // Optimize DOM querying
2193 var $this_dropdown
= $(this);
2194 // The top offset must be set for IE even if it didn't change
2195 var cell_right_edge_offset
= $this_dropdown
.parent().position().left
+ $this_dropdown
.parent().innerWidth();
2196 var left_offset
= cell_right_edge_offset
- $this_dropdown
.innerWidth();
2197 var top_offset
= $this_dropdown
.parent().position().top
+ $this_dropdown
.parent().innerHeight();
2198 $this_dropdown
.offset({ top
: top_offset
, left
: left_offset
});
2201 // A hack for IE6 to prevent the after_field select element from being displayed on top of the dropdown by
2202 // positioning an iframe directly on top of it
2203 var $after_field
= $("select[name='after_field']");
2204 $("iframe[class='IE_hack']")
2205 .width($after_field
.width())
2206 .height($after_field
.height())
2208 top
: $after_field
.offset().top
,
2209 left
: $after_field
.offset().left
2212 // When "more" is hovered over, show the hidden actions
2213 $table
.find("td[class='more_opts']")
2214 .mouseenter(function() {
2215 if($.browser
.msie
&& $.browser
.version
== "6.0") {
2216 $("iframe[class='IE_hack']")
2218 .width($after_field
.width()+4)
2219 .height($after_field
.height()+4)
2221 top
: $after_field
.offset().top
,
2222 left
: $after_field
.offset().left
2225 $(".structure_actions_dropdown").hide(); // Hide all the other ones that may be open
2226 $(this).children(".structure_actions_dropdown").show();
2227 // Need to do this again for IE otherwise the offset is wrong
2228 if($.browser
.msie
) {
2229 var left_offset_IE
= $(this).offset().left
+ $(this).innerWidth() - $(this).children(".structure_actions_dropdown").innerWidth();
2230 var top_offset_IE
= $(this).offset().top
+ $(this).innerHeight();
2231 $(this).children(".structure_actions_dropdown").offset({
2233 left
: left_offset_IE
});
2236 .mouseleave(function() {
2237 $(this).children(".structure_actions_dropdown").hide();
2238 if($.browser
.msie
&& $.browser
.version
== "6.0") {
2239 $("iframe[class='IE_hack']").hide();
2245 $(document
).ready(initTooltips
);
2248 * Ensures indexes names are valid according to their type and, for a primary
2249 * key, lock index name to 'PRIMARY'
2250 * @param string form_id Variable which parses the form name as
2252 * @return boolean false if there is no index form, true else
2254 function checkIndexName(form_id
)
2256 if ($("#"+form_id
).length
== 0) {
2260 // Gets the elements pointers
2261 var $the_idx_name
= $("#input_index_name");
2262 var $the_idx_type
= $("#select_index_type");
2264 // Index is a primary key
2265 if ($the_idx_type
.find("option:selected").attr("value") == 'PRIMARY') {
2266 $the_idx_name
.attr("value", 'PRIMARY');
2267 $the_idx_name
.attr("disabled", true);
2272 if ($the_idx_name
.attr("value") == 'PRIMARY') {
2273 $the_idx_name
.attr("value", '');
2275 $the_idx_name
.attr("disabled", false);
2279 } // end of the 'checkIndexName()' function
2282 /* Displays tooltips */
2283 function initTooltips() {
2284 // Hide the footnotes from the footer (which are displayed for
2285 // JavaScript-disabled browsers) since the tooltip is sufficient
2286 $(".footnotes").hide();
2287 $(".footnotes span").each(function() {
2288 $(this).children("sup").remove();
2290 // The border and padding must be removed otherwise a thin yellow box remains visible
2291 $(".footnotes").css("border", "none");
2292 $(".footnotes").css("padding", "0px");
2294 // Replace the superscripts with the help icon
2295 $("sup[class='footnotemarker']").hide();
2296 $("img[class='footnotemarker']").show();
2298 $("img[class='footnotemarker']").each(function() {
2299 var span_id
= $(this).attr("id");
2300 span_id
= span_id
.split("_")[1];
2301 var tooltip_text
= $(".footnotes span[id='footnote_" + span_id
+ "']").html();
2303 content
: tooltip_text
,
2305 hide
: { delay
: 1000 },
2306 style
: { background
: '#ffffcc' }
2311 function menuResize()
2313 var cnt
= $('#topmenu');
2314 var wmax
= cnt
.innerWidth() - 5; // 5 px margin for jumping menu in Chrome
2315 var submenu
= cnt
.find('.submenu');
2316 var submenu_w
= submenu
.outerWidth(true);
2317 var submenu_ul
= submenu
.find('ul');
2318 var li
= cnt
.find('> li');
2319 var li2
= submenu_ul
.find('li');
2320 var more_shown
= li2
.length
> 0;
2321 var w
= more_shown
? submenu_w
: 0;
2325 for (var i
= 0; i
< li
.length
-1; i
++) { // li.length-1: skip .submenu element
2327 var el_width
= el
.outerWidth(true);
2328 el
.data('width', el_width
);
2332 if (w
+ submenu_w
< wmax
) {
2336 w
-= $(li
[i
-1]).data('width');
2342 if (hide_start
> 0) {
2343 for (var i
= hide_start
; i
< li
.length
-1; i
++) {
2344 $(li
[i
])[more_shown
? 'prependTo' : 'appendTo'](submenu_ul
);
2346 submenu
.addClass('shown');
2347 } else if (more_shown
) {
2349 // nothing hidden, maybe something can be restored
2350 for (var i
= 0; i
< li2
.length
; i
++) {
2351 //console.log(li2[i], submenu_w);
2352 w
+= $(li2
[i
]).data('width');
2353 // item fits or (it is the last item and it would fit if More got removed)
2354 if (w
+submenu_w
< wmax
|| (i
== li2
.length
-1 && w
< wmax
)) {
2355 $(li2
[i
]).insertBefore(submenu
);
2356 if (i
== li2
.length
-1) {
2357 submenu
.removeClass('shown');
2364 if (submenu
.find('.tabactive').length
) {
2365 submenu
.addClass('active').find('> a').removeClass('tab').addClass('tabactive');
2367 submenu
.removeClass('active').find('> a').addClass('tab').removeClass('tabactive');
2372 var topmenu
= $('#topmenu');
2373 if (topmenu
.length
== 0) {
2376 // create submenu container
2377 var link
= $('<a />', {href
: '#', 'class': 'tab'})
2378 .text(PMA_messages
['strMore'])
2379 .click(function(e
) {
2382 var img
= topmenu
.find('li:first-child img');
2384 img
.clone().attr('src', img
.attr('src').replace(/\/[^\/]+$/, '/b_more.png')).prependTo(link
);
2386 var submenu
= $('<li />', {'class': 'submenu'})
2388 .append($('<ul />'))
2389 .mouseenter(function() {
2390 if ($(this).find('ul .tabactive').length
== 0) {
2391 $(this).addClass('submenuhover').find('> a').addClass('tabactive');
2394 .mouseleave(function() {
2395 if ($(this).find('ul .tabactive').length
== 0) {
2396 $(this).removeClass('submenuhover').find('> a').removeClass('tabactive');
2399 topmenu
.append(submenu
);
2401 // populate submenu and register resize event
2402 $(window
).resize(menuResize
);
2407 * Get the row number from the classlist (for example, row_1)
2409 function PMA_getRowNumber(classlist
) {
2410 return parseInt(classlist
.split(/\s+row_/)[1]);
2414 * Changes status of slider
2416 function PMA_set_status_label(id
) {
2417 if ($('#' + id
).css('display') == 'none') {
2418 $('#anchor_status_' + id
).text('+ ');
2420 $('#anchor_status_' + id
).text('- ');
2425 * Initializes slider effect.
2427 function PMA_init_slider() {
2428 $('.pma_auto_slider').each(function(idx
, e
) {
2429 if ($(e
).hasClass('slider_init_done')) return;
2430 $(e
).addClass('slider_init_done');
2431 $('<span id="anchor_status_' + e
.id
+ '"></span>')
2433 PMA_set_status_label(e
.id
);
2435 $('<a href="#' + e
.id
+ '" id="anchor_' + e
.id
+ '">' + e
.title
+ '</a>')
2438 $('#' + e
.id
).toggle('clip', function() {
2439 PMA_set_status_label(e
.id
);
2447 * var toggleButton This is a function that creates a toggle
2448 * sliding button given a jQuery reference
2449 * to the correct DOM element
2451 var toggleButton = function ($obj
) {
2452 // In rtl mode the toggle switch is flipped horizontally
2453 // so we need to take that into account
2454 if ($('.text_direction', $obj
).text() == 'ltr') {
2455 var right
= 'right';
2460 * var h Height of the button, used to scale the
2461 * background image and position the layers
2463 var h
= $obj
.height();
2464 $('img', $obj
).height(h
);
2465 $('table', $obj
).css('bottom', h
-1);
2467 * var on Width of the "ON" part of the toggle switch
2468 * var off Width of the "OFF" part of the toggle switch
2470 var on
= $('.toggleOn', $obj
).width();
2471 var off
= $('.toggleOff', $obj
).width();
2472 // Make the "ON" and "OFF" parts of the switch the same size
2473 $('.toggleOn > div', $obj
).width(Math
.max(on
, off
));
2474 $('.toggleOff > div', $obj
).width(Math
.max(on
, off
));
2476 * var w Width of the central part of the switch
2478 var w
= parseInt(($('img', $obj
).height() / 16) * 22, 10);
2479 // Resize the central part of the switch on the top
2480 // layer to match the background
2481 $('table td:nth-child(2) > div', $obj
).width(w
);
2483 * var imgw Width of the background image
2484 * var tblw Width of the foreground layer
2485 * var offset By how many pixels to move the background
2486 * image, so that it matches the top layer
2488 var imgw
= $('img', $obj
).width();
2489 var tblw
= $('table', $obj
).width();
2490 var offset
= parseInt(((imgw
- tblw
) / 2), 10);
2491 // Move the background to match the layout of the top layer
2492 $obj
.find('img').css(right
, offset
);
2494 * var offw Outer width of the "ON" part of the toggle switch
2495 * var btnw Outer width of the central part of the switch
2497 var offw
= $('.toggleOff', $obj
).outerWidth();
2498 var btnw
= $('table td:nth-child(2)', $obj
).outerWidth();
2499 // Resize the main div so that exactly one side of
2500 // the switch plus the central part fit into it.
2501 $obj
.width(offw
+ btnw
+ 2);
2503 * var move How many pixels to move the
2504 * switch by when toggling
2506 var move = $('.toggleOff', $obj
).outerWidth();
2507 // If the switch is initialized to the
2508 // OFF state we need to move it now.
2509 if ($('.container', $obj
).hasClass('off')) {
2510 if (right
== 'right') {
2511 $('table, img', $obj
).animate({'left': '-=' + move + 'px'}, 0);
2513 $('table, img', $obj
).animate({'left': '+=' + move + 'px'}, 0);
2516 // Attach an 'onclick' event to the switch
2517 $('.container', $obj
).click(function () {
2518 if ($(this).hasClass('isActive')) {
2521 $(this).addClass('isActive');
2523 var $msg
= PMA_ajaxShowMessage(PMA_messages
['strLoading']);
2524 var $container
= $(this);
2525 var callback
= $('.callback', this).text();
2526 // Perform the actual toggle
2527 if ($(this).hasClass('on')) {
2528 if (right
== 'right') {
2529 var operator
= '-=';
2531 var operator
= '+=';
2533 var url
= $(this).find('.toggleOff > span').text();
2534 var removeClass
= 'on';
2535 var addClass
= 'off';
2537 if (right
== 'right') {
2538 var operator
= '+=';
2540 var operator
= '-=';
2542 var url
= $(this).find('.toggleOn > span').text();
2543 var removeClass
= 'off';
2544 var addClass
= 'on';
2546 $.post(url
, {'ajax_request': true}, function(data
) {
2547 if(data
.success
== true) {
2548 PMA_ajaxRemoveMessage($msg
);
2550 .removeClass(removeClass
)
2552 .animate({'left': operator
+ move + 'px'}, function () {
2553 $container
.removeClass('isActive');
2557 PMA_ajaxShowMessage(data
.error
);
2558 $container
.removeClass('isActive');
2565 * Initialise all toggle buttons
2567 $(window
).load(function () {
2568 $('.toggleAjax').each(function () {
2571 .find('.toggleButton')
2572 toggleButton($(this));
2579 $(document
).ready(function() {
2580 $('.vpointer').live('hover',
2583 var $this_td
= $(this);
2584 var row_num
= PMA_getRowNumber($this_td
.attr('class'));
2585 // for all td of the same vertical row, toggle hover
2586 $('.vpointer').filter('.row_' + row_num
).toggleClass('hover');
2589 }) // end of $(document).ready() for vertical pointer
2591 $(document
).ready(function() {
2595 $('.vmarker').live('click', function(e
) {
2596 // do not trigger when clicked on anchor
2597 if ($(e
.target
).is('a, img, a *')) {
2601 var $this_td
= $(this);
2602 var row_num
= PMA_getRowNumber($this_td
.attr('class'));
2604 // XXX: FF fires two click events for <label> (label and checkbox), so we need to handle this differently
2606 var $checkbox
= $('.vmarker').filter('.row_' + row_num
+ ':first').find(':checkbox');
2607 if ($checkbox
.length
) {
2608 // checkbox in a row, add or remove class depending on checkbox state
2609 var checked
= $checkbox
.attr('checked');
2610 if (!$(e
.target
).is(':checkbox, label')) {
2612 $checkbox
.attr('checked', checked
);
2614 // for all td of the same vertical row, toggle the marked class
2616 $('.vmarker').filter('.row_' + row_num
).addClass('marked');
2618 $('.vmarker').filter('.row_' + row_num
).removeClass('marked');
2621 // normaln data table, just toggle class
2622 $('.vmarker').filter('.row_' + row_num
).toggleClass('marked');
2627 * Reveal visual builder anchor
2630 $('#visual_builder_anchor').show();
2633 * Page selector in db Structure (non-AJAX)
2635 $('#tableslistcontainer').find('#pageselector').live('change', function() {
2636 $(this).parent("form").submit();
2640 * Page selector in navi panel (non-AJAX)
2642 $('#navidbpageselector').find('#pageselector').live('change', function() {
2643 $(this).parent("form").submit();
2647 * Page selector in browse_foreigners windows (non-AJAX)
2649 $('#body_browse_foreigners').find('#pageselector').live('change', function() {
2650 $(this).closest("form").submit();
2654 * Load version information asynchronously.
2656 if ($('.jsversioncheck').length
> 0) {
2658 var s
= document
.createElement('script');
2659 s
.type
= 'text/javascript';
2661 s
.src
= 'http://www.phpmyadmin.net/home_page/version.js';
2662 s
.onload
= PMA_current_version
;
2663 var x
= document
.getElementsByTagName('script')[0];
2664 x
.parentNode
.insertBefore(s
, x
);
2674 * Enables the text generated by PMA_linkOrButton() to be clickable
2676 $('.clickprevimage')
2677 .css('color', function(index
) {
2678 return $('a').css('color');
2680 .css('cursor', function(index
) {
2681 return $('a').css('cursor');
2682 }) //todo: hover effect
2683 .live('click',function(e
) {
2684 $this_span
= $(this);
2685 if ($this_span
.closest('td').is('.inline_edit_anchor')) {
2686 // this would bind a second click event to the inline edit
2687 // anchor and would disturb its behavior
2689 $this_span
.parent().find('input:image').click();
2693 $('#update_recent_tables').ready(function() {
2694 if (window
.parent
.frame_navigation
!= undefined
2695 && window
.parent
.frame_navigation
.PMA_reloadRecentTable
!= undefined)
2697 window
.parent
.frame_navigation
.PMA_reloadRecentTable();
2701 }) // end of $(document).ready()
2704 * Creates a message inside an object with a sliding effect
2706 * @param msg A string containing the text to display
2707 * @param $obj a jQuery object containing the reference
2708 * to the element where to put the message
2709 * This is optional, if no element is
2710 * provided, one will be created below the
2711 * navigation links at the top of the page
2713 * @return bool True on success, false on failure
2715 function PMA_slidingMessage(msg
, $obj
) {
2716 if (msg
== undefined || msg
.length
== 0) {
2717 // Don't show an empty message
2720 if ($obj
== undefined || ! $obj
instanceof jQuery
|| $obj
.length
== 0) {
2721 // If the second argument was not supplied,
2722 // we might have to create a new DOM node.
2723 if ($('#PMA_slidingMessage').length
== 0) {
2724 $('#topmenucontainer')
2725 .after('<span id="PMA_slidingMessage" '
2726 + 'style="display: inline-block;"></span>');
2728 $obj
= $('#PMA_slidingMessage');
2730 if ($obj
.has('div').length
> 0) {
2731 // If there already is a message inside the
2732 // target object, we must get rid of it
2736 .fadeOut(function () {
2741 .append('<div style="display: none;">' + msg
+ '</div>')
2743 height
: $obj
.find('div').first().height()
2750 // Object does not already have a message
2751 // inside it, so we simply slide it down
2754 .html('<div style="display: none;">' + msg
+ '</div>')
2766 // Set the height of the parent
2767 // to the height of the child
2778 } // end PMA_slidingMessage()
2781 * Attach Ajax event handlers for Drop Table.
2783 * @uses $.PMA_confirm()
2784 * @uses PMA_ajaxShowMessage()
2785 * @uses window.parent.refreshNavigation()
2786 * @uses window.parent.refreshMain()
2787 * @see $cfg['AjaxEnable']
2789 $(document
).ready(function() {
2790 $("#drop_tbl_anchor").live('click', function(event
) {
2791 event
.preventDefault();
2793 //context is top.frame_content, so we need to use window.parent.db to access the db var
2795 * @var question String containing the question to be asked for confirmation
2797 var question
= PMA_messages
['strDropTableStrongWarning'] + '\n' + PMA_messages
['strDoYouReally'] + ' :\n' + 'DROP TABLE ' + window
.parent
.table
;
2799 $(this).PMA_confirm(question
, $(this).attr('href') ,function(url
) {
2801 PMA_ajaxShowMessage(PMA_messages
['strProcessingRequest']);
2802 $.get(url
, {'is_js_confirmed': '1', 'ajax_request': true}, function(data
) {
2803 //Database deleted successfully, refresh both the frames
2804 window
.parent
.refreshNavigation();
2805 window
.parent
.refreshMain();
2807 }); // end $.PMA_confirm()
2808 }); //end of Drop Table Ajax action
2809 }) // end of $(document).ready() for Drop Table
2812 * Attach Ajax event handlers for Truncate Table.
2814 * @uses $.PMA_confirm()
2815 * @uses PMA_ajaxShowMessage()
2816 * @uses window.parent.refreshNavigation()
2817 * @uses window.parent.refreshMain()
2818 * @see $cfg['AjaxEnable']
2820 $(document
).ready(function() {
2821 $("#truncate_tbl_anchor").live('click', function(event
) {
2822 event
.preventDefault();
2824 //context is top.frame_content, so we need to use window.parent.db to access the db var
2826 * @var question String containing the question to be asked for confirmation
2828 var question
= PMA_messages
['strTruncateTableStrongWarning'] + '\n' + PMA_messages
['strDoYouReally'] + ' :\n' + 'TRUNCATE TABLE ' + window
.parent
.table
;
2830 $(this).PMA_confirm(question
, $(this).attr('href') ,function(url
) {
2832 PMA_ajaxShowMessage(PMA_messages
['strProcessingRequest']);
2833 $.get(url
, {'is_js_confirmed': '1', 'ajax_request': true}, function(data
) {
2834 //Database deleted successfully, refresh both the frames
2835 window
.parent
.refreshNavigation();
2836 window
.parent
.refreshMain();
2838 }); // end $.PMA_confirm()
2839 }); //end of Drop Table Ajax action
2840 }) // end of $(document).ready() for Drop Table
2843 * Attach CodeMirror2 editor to SQL edit area.
2845 $(document
).ready(function() {
2846 var elm
= $('#sqlquery');
2847 if (elm
.length
> 0) {
2848 codemirror_editor
= CodeMirror
.fromTextArea(elm
[0], {lineNumbers
: true, matchBrackets
: true, indentUnit
: 4, mode
: "text/x-mysql"});
2853 * jQuery plugin to cancel selection in HTML code.
2856 $.fn
.noSelect = function (p
) { //no select plugin by Paulo P.Marinas
2857 var prevent
= (p
== null) ? true : p
;
2859 return this.each(function () {
2860 if ($.browser
.msie
|| $.browser
.safari
) $(this).bind('selectstart', function () {
2863 else if ($.browser
.mozilla
) {
2864 $(this).css('MozUserSelect', 'none');
2865 $('body').trigger('focus');
2866 } else if ($.browser
.opera
) $(this).bind('mousedown', function () {
2869 else $(this).attr('unselectable', 'on');
2872 return this.each(function () {
2873 if ($.browser
.msie
|| $.browser
.safari
) $(this).unbind('selectstart');
2874 else if ($.browser
.mozilla
) $(this).css('MozUserSelect', 'inherit');
2875 else if ($.browser
.opera
) $(this).unbind('mousedown');
2876 else $(this).removeAttr('unselectable', 'on');
2883 * Create default PMA tooltip for the element specified. The default appearance
2884 * can be overriden by specifying optional "options" parameter (see qTip options).
2886 function PMA_createqTip($elements
, content
, options
) {
2900 corner
: { target
: 'rightMiddle', tooltip
: 'leftMiddle' },
2918 $elements
.qtip($.extend(true, o
, options
));