bug#3212720 Show error message on error.
[phpmyadmin/ayax.git] / js / functions.js
blobdbdc646fc49ac4f6bc6803147246606026ae55a1
1 /* vim: set expandtab sw=4 ts=4 sts=4: */
2 /**
3  * general function, usally for data manipulation pages
4  *
5  */
7 /**
8  * @var sql_box_locked lock for the sqlbox textarea in the querybox/querywindow
9  */
10 var sql_box_locked = false;
12 /**
13  * @var array holds elements which content should only selected once
14  */
15 var only_once_elements = new Array();
17 /**
18  * @var ajax_message_init   boolean boolean that stores status of
19  *      notification for PMA_ajaxShowNotification
20  */
21 var ajax_message_init = false;
23 /**
24  * Generate a new password and copy it to the password input areas
25  *
26  * @param   object   the form that holds the password fields
27  *
28  * @return  boolean  always true
29  */
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;
37     passwd.value = '';
39     for ( i = 0; i < passwordlength; i++ ) {
40         passwd.value += pwchars.charAt( Math.floor( Math.random() * pwchars.length ) )
41     }
42     passwd_form.text_pma_pw.value = passwd.value;
43     passwd_form.text_pma_pw2.value = passwd.value;
44     return true;
47 /**
48  * Version string to integer conversion.
49  */
50 function parseVersionString (str) {
51     if (typeof(str) != 'string') { return false; }
52     var add = 0;
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 */
64             add = 0;
65         }
66     }
67     // Parse version
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;
77 /**
78  * Indicates current available version on main page.
79  */
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)) {
87             /* Security update */
88             klass = 'warning';
89         } else {
90             klass = 'notice';
91         }
92         $('#maincontainer').after('<div class="' + klass + '">' + message + '</div>');
93     }
96 /**
97  * for libraries/display_change_password.lib.php
98  *     libraries/user_password.php
99  *
100  */
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
111  */
112 function PMA_addDatepicker($this_element) {
113     var showTimeOption = false;
114     if ($this_element.is('.datetimefield')) {
115         showTimeOption = true;
116     }
118     $this_element
119         .datepicker({
120         showOn: 'button',
121         buttonImage: themeCalendarImage, // defined in js/messages.php
122         buttonImageOnly: true,
123         duration: '',
124         time24h: true,
125         stepMinutes: 1,
126         stepHours: 1,
127         showTime: showTimeOption,
128         dateFormat: 'yy-mm-dd', // yy means year with four digits
129         altTimeField: '',
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');
134         },
135         constrainInput: false
136      });
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
147  */
148 function selectContent( element, lock, only_once ) {
149     if ( only_once && only_once_elements[element.name] ) {
150         return;
151     }
153     only_once_elements[element.name] = true;
155     if ( lock  ) {
156         return;
157     }
159     element.select();
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
170  */
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') {
176         return true;
177     }
179     var is_confirmed = confirm(PMA_messages['strDoYouReally'] + ' :\n' + theSqlQuery);
180     if (is_confirmed) {
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';
185         }
186     }
188     return is_confirmed;
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
201  */
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') {
207         return true;
208     }
210     var is_confirmed = confirm(theMessage);
212     return is_confirmed;
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()
228  */
229 function confirmQuery(theForm1, sqlQuery1)
231     // Confirmation is not required in the configuration file
232     if (PMA_messages['strDoYouReally'] == '') {
233         return true;
234     }
236     // The replace function (js1.2) isn't supported
237     else if (typeof(sqlQuery1.value.replace) == 'undefined') {
238         return true;
239     }
241     // js1.2+ -> validation with regular expressions
242     else {
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']);
248                 theForm1.reset();
249                 sqlQuery1.focus();
250                 return false;
251             } // end if
252         } // end if
254         // Confirms a "DROP/DELETE/ALTER/TRUNCATE" statement
255         //
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    ...'
272                              : sqlQuery1.value;
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
277             if (is_confirmed) {
278                 theForm1.elements['is_js_confirmed'].value = 1;
279                 return true;
280             }
281             // statement is rejected -> do not submit the form
282             else {
283                 window.focus();
284                 sqlQuery1.focus();
285                 return false;
286             } // end if (handle confirm box result)
287         } // end if (display confirm box)
288     } // end confirmation stuff
290     return true;
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
301  */
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') {
307         return true;
308     }
310     var is_confirmed = confirm(PMA_messages['strBLOBRepositoryDisableStrongWarning'] + '\n' + PMA_messages['strBLOBRepositoryDisableAreYouSure']);
312     return is_confirmed;
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()
325  */
326 function checkSqlQuery(theForm)
328     var sqlQuery = theForm.elements['sql_query'];
329     var isEmpty  = 1;
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;
336         }
337         if (isEmpty && typeof(theForm.elements['sql_localfile']) != 'undefined') {
338             isEmpty  = (theForm.elements['sql_localfile'].value == '') ? 1 : 0;
339         }
340         if (isEmpty && typeof(theForm.elements['id_bookmark']) != 'undefined') {
341             isEmpty  = (theForm.elements['id_bookmark'].value == null || theForm.elements['id_bookmark'].value == '');
342         }
343     }
344     // js1.2+ -> validation with regular expressions
345     else {
346         var space_re = new RegExp('\\s+');
347         if (typeof(theForm.elements['sql_file']) != 'undefined' &&
348                 theForm.elements['sql_file'].value.replace(space_re, '') != '') {
349             return true;
350         }
351         if (typeof(theForm.elements['sql_localfile']) != 'undefined' &&
352                 theForm.elements['sql_localfile'].value.replace(space_re, '') != '') {
353             return true;
354         }
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
358                 ) {
359             return true;
360         }
361         // Checks for "DROP/DELETE/ALTER" statements
362         if (sqlQuery.value.replace(space_re, '') != '') {
363             if (confirmQuery(theForm, sqlQuery)) {
364                 return true;
365             } else {
366                 return false;
367             }
368         }
369         theForm.reset();
370         isEmpty = 1;
371     }
373     if (isEmpty) {
374         sqlQuery.select();
375         alert(PMA_messages['strFormEmpty']);
376         sqlQuery.focus();
377         return false;
378     }
380     return true;
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
391  */
392 function emptyCheckTheField(theForm, theFieldName)
394     var isEmpty  = 1;
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');
399     if (!isRegExp) {
400         isEmpty      = (theField.value == '') ? 1 : 0;
401     } else {
402         var space_re = new RegExp('\\s+');
403         isEmpty      = (theField.value.replace(space_re, '') == '') ? 1 : 0;
404     }
406     return isEmpty;
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
417  */
418 function emptyFormElements(theForm, theFieldName)
420     var theField = theForm.elements[theFieldName];
421     var isEmpty = emptyCheckTheField(theForm, theFieldName);
424     return isEmpty;
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
437  */
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') {
444         min = 0;
445     }
446     if (typeof(max) == 'undefined') {
447         max = Number.MAX_VALUE;
448     }
450     // It's not a number
451     if (isNaN(val)) {
452         theField.select();
453         alert(PMA_messages['strNotNumber']);
454         theField.focus();
455         return false;
456     }
457     // It's a number but it is not between min and max
458     else if (val < min || val > max) {
459         theField.select();
460         alert(message.replace('%d', val));
461         theField.focus();
462         return false;
463     }
464     // It's a valid number
465     else {
466         theField.value = val;
467     }
468     return true;
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++)
482     {
483         id = "#field_" + i + "_2";
484         elm = $(id);
485         val = elm.val()
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() != "") {
491                 elm2.select();
492                 alert(PMA_messages['strNotNumber']);
493                 elm2.focus();
494                 return false;
495             }
496         }
498         if (atLeastOneField == 0) {
499             id = "field_" + i + "_1";
500             if (!emptyCheckTheField(theForm, id)) {
501                 atLeastOneField = 1;
502             }
503         }
504     }
505     if (atLeastOneField == 0) {
506         var theField = theForm.elements["field_0_1"];
507         alert(PMA_messages['strFormEmpty']);
508         theField.focus();
509         return false;
510     }
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();
516         return false;
517     }
520     return true;
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
532  */
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;
541         }
542         if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) {
543             theForm.elements['gzip'].checked = false;
544         }
545         if (typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked) {
546             theForm.elements['bzip'].checked = false;
547         }
548     }
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;
553         }
554         if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
555             theForm.elements['zip'].checked = false;
556         }
557         if (typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked) {
558             theForm.elements['bzip'].checked = false;
559         }
560     }
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;
565         }
566         if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
567             theForm.elements['zip'].checked = false;
568         }
569         if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) {
570             theForm.elements['gzip'].checked = false;
571         }
572     }
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;
577         }
578         if ((typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked)) {
579             theForm.elements['gzip'].checked = false;
580         }
581         if ((typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked)) {
582             theForm.elements['bzip'].checked = false;
583         }
584     }
586     return true;
587 } // end of the 'checkTransmitDump()' function
589 $(document).ready(function() {
590     /**
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
593      * this behavior.
594      */
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 *')) {
598             return;
599         }
600         // XXX: FF fires two click events for <label> (label and checkbox), so we need to handle this differently
601         var $tr = $(this);
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')) {
607                 checked = !checked;
608                 $checkbox.attr('checked', checked);
609             }
610             if (checked) {
611                 $tr.addClass('marked');
612             } else {
613                 $tr.removeClass('marked');
614             }
615         } else {
616             // normaln data table, just toggle class
617             $tr.toggleClass('marked');
618         }
619     });
621     /**
622      * Add a date/time picker to each element that needs it
623      */
624     $('.datefield, .datetimefield').each(function() {
625         PMA_addDatepicker($(this));
626         });
630  * Row highlighting in horizontal mode (use "live"
631  * so that it works also for pages reached via AJAX)
632  */
633 $(document).ready(function() {
634     $('tr.odd, tr.even').live('hover',function() {
635         var $tr = $(this);
636         $tr.toggleClass('hover');
637         $tr.children().toggleClass('hover');
638     });
642  * This array is used to remember mark status of rows in browse mode
643  */
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
651  */
652 function markAllRows( container_id ) {
654     $("#"+container_id).find("input:checkbox:enabled").attr('checked', 'checked')
655     .parents("tr").addClass("marked");
656     return true;
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
664  */
665 function unMarkAllRows( container_id ) {
667     $("#"+container_id).find("input:checkbox:enabled").removeAttr('checked')
668     .parents("tr").removeClass("marked");
669     return true;
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
678  */
679 function setCheckboxes( container_id, state ) {
681     if(state) {
682         $("#"+container_id).find("input:checkbox").attr('checked', 'checked');
683     }
684     else {
685         $("#"+container_id).find("input:checkbox").removeAttr('checked');
686     }
688     return true;
689 } // end of the 'setCheckboxes()' function
692   * Checks/unchecks all options of a <select> element
693   *
694   * @param   string   the form name
695   * @param   string   the element name
696   * @param   boolean  whether to check or to uncheck the element
697   *
698   * @return  boolean  always true
699   */
700 function setSelectOptions(the_form, the_select, do_check)
703     if( do_check ) {
704         $("form[name='"+ the_form +"']").find("select[name='"+the_select+"']").find("option").attr('selected', 'selected');
705     }
706     else {
707         $("form[name='"+ the_form +"']").find("select[name="+the_select+"]").find("option").removeAttr('selected');
708     }
709     return true;
710 } // end of the 'setSelectOptions()' function
714   * Create quick sql statements.
715   *
716   */
717 function insertQuery(queryType) {
718     var myQuery = document.sqlform.sql_query;
719     var myListBox = document.sqlform.dummy;
720     var query = "";
721     var table = document.sqlform.table.value;
723     if (myListBox.options.length > 0) {
724         sql_box_locked = true;
725         var chaineAj = "";
726         var valDis = "";
727         var editDis = "";
728         var NbSelect = 0;
729         for (var i=0; i < myListBox.options.length; i++) {
730             NbSelect++;
731             if (NbSelect > 1) {
732                 chaineAj += ", ";
733                 valDis += ",";
734                 editDis += ",";
735             }
736             chaineAj += myListBox.options[i].value;
737             valDis += "[value-" + NbSelect + "]";
738             editDis += myListBox.options[i].value + "=[value-" + NbSelect + "]";
739         }
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") {
751         query = '';
752     }
753     document.sqlform.sql_query.value = query;
754     sql_box_locked = false;
755     }
760   * Inserts multiple fields.
761   *
762   */
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;
769         var chaineAj = "";
770         var NbSelect = 0;
771         for(var i=0; i<myListBox.options.length; i++) {
772             if (myListBox.options[i].selected){
773                 NbSelect++;
774                 if (NbSelect > 1)
775                     chaineAj += ", ";
776                 chaineAj += myListBox.options[i].value;
777             }
778         }
780         //IE support
781         if (document.selection) {
782             myQuery.focus();
783             sel = document.selection.createRange();
784             sel.text = chaineAj;
785             document.sqlform.insert.focus();
786         }
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);
794         } else {
795             myQuery.value += chaineAj;
796         }
797         sql_box_locked = false;
798     }
802   * listbox redirection
803   */
804 function goToUrl(selObj, goToLocation) {
805     eval("document.location.href = '" + goToLocation + "pos=" + selObj.options[selObj.selectedIndex].value + "'");
809  * getElement
810  */
811 function getElement(e,f){
812     if(document.layers){
813         f=(f)?f:self;
814         if(f.document.layers[e]) {
815             return f.document.layers[e];
816         }
817         for(W=0;W<f.document.layers.length;W++) {
818             return(getElement(e,f.document.layers[W]));
819         }
820     }
821     if(document.all) {
822         return document.all[e];
823     }
824     return document.getElementById(e);
828   * Refresh the WYSIWYG scratchboard after changes have been made
829   */
830 function refreshDragOption(e) {
831     var elm = $('#' + e);
832     if (elm.css('visibility') == 'visible') {
833         refreshLayout();
834         TableDragInit();
835     }
839   * Refresh/resize the WYSIWYG scratchboard
840   */
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();
846     }else{
847         var paper = 'A4';
848     }
849     if (orientation == 'P') {
850         posa = 'x';
851         posb = 'y';
852     } else {
853         posa = 'y';
854         posb = 'x';
855     }
856     elm.css('width', pdfPaperSize(paper, posa) + 'px');
857     elm.css('height', pdfPaperSize(paper, posb) + 'px');
861   * Show/hide the WYSIWYG scratchboard
862   */
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')
870     } else {
871         elm.css('visibility', 'hidden');
872         elm.css('display', 'none');
873         $('#showwysiwyg').val('0')
874     }
878   * PDF scratchboard: When a position is entered manually, update
879   * the fields inside the scratchboard.
880   */
881 function dragPlace(no, axis, value) {
882     var elm = $('#table_' + no);
883     if (axis == 'x') {
884         elm.css('left', value + 'px');
885     } else {
886         elm.css('top', value + 'px');
887     }
891  * Returns paper sizes for a given format
892  */
893 function pdfPaperSize(format, axis) {
894     switch (format.toUpperCase()) {
895         case '4A0':
896             if (axis == 'x') return 4767.87; else return 6740.79;
897             break;
898         case '2A0':
899             if (axis == 'x') return 3370.39; else return 4767.87;
900             break;
901         case 'A0':
902             if (axis == 'x') return 2383.94; else return 3370.39;
903             break;
904         case 'A1':
905             if (axis == 'x') return 1683.78; else return 2383.94;
906             break;
907         case 'A2':
908             if (axis == 'x') return 1190.55; else return 1683.78;
909             break;
910         case 'A3':
911             if (axis == 'x') return 841.89; else return 1190.55;
912             break;
913         case 'A4':
914             if (axis == 'x') return 595.28; else return 841.89;
915             break;
916         case 'A5':
917             if (axis == 'x') return 419.53; else return 595.28;
918             break;
919         case 'A6':
920             if (axis == 'x') return 297.64; else return 419.53;
921             break;
922         case 'A7':
923             if (axis == 'x') return 209.76; else return 297.64;
924             break;
925         case 'A8':
926             if (axis == 'x') return 147.40; else return 209.76;
927             break;
928         case 'A9':
929             if (axis == 'x') return 104.88; else return 147.40;
930             break;
931         case 'A10':
932             if (axis == 'x') return 73.70; else return 104.88;
933             break;
934         case 'B0':
935             if (axis == 'x') return 2834.65; else return 4008.19;
936             break;
937         case 'B1':
938             if (axis == 'x') return 2004.09; else return 2834.65;
939             break;
940         case 'B2':
941             if (axis == 'x') return 1417.32; else return 2004.09;
942             break;
943         case 'B3':
944             if (axis == 'x') return 1000.63; else return 1417.32;
945             break;
946         case 'B4':
947             if (axis == 'x') return 708.66; else return 1000.63;
948             break;
949         case 'B5':
950             if (axis == 'x') return 498.90; else return 708.66;
951             break;
952         case 'B6':
953             if (axis == 'x') return 354.33; else return 498.90;
954             break;
955         case 'B7':
956             if (axis == 'x') return 249.45; else return 354.33;
957             break;
958         case 'B8':
959             if (axis == 'x') return 175.75; else return 249.45;
960             break;
961         case 'B9':
962             if (axis == 'x') return 124.72; else return 175.75;
963             break;
964         case 'B10':
965             if (axis == 'x') return 87.87; else return 124.72;
966             break;
967         case 'C0':
968             if (axis == 'x') return 2599.37; else return 3676.54;
969             break;
970         case 'C1':
971             if (axis == 'x') return 1836.85; else return 2599.37;
972             break;
973         case 'C2':
974             if (axis == 'x') return 1298.27; else return 1836.85;
975             break;
976         case 'C3':
977             if (axis == 'x') return 918.43; else return 1298.27;
978             break;
979         case 'C4':
980             if (axis == 'x') return 649.13; else return 918.43;
981             break;
982         case 'C5':
983             if (axis == 'x') return 459.21; else return 649.13;
984             break;
985         case 'C6':
986             if (axis == 'x') return 323.15; else return 459.21;
987             break;
988         case 'C7':
989             if (axis == 'x') return 229.61; else return 323.15;
990             break;
991         case 'C8':
992             if (axis == 'x') return 161.57; else return 229.61;
993             break;
994         case 'C9':
995             if (axis == 'x') return 113.39; else return 161.57;
996             break;
997         case 'C10':
998             if (axis == 'x') return 79.37; else return 113.39;
999             break;
1000         case 'RA0':
1001             if (axis == 'x') return 2437.80; else return 3458.27;
1002             break;
1003         case 'RA1':
1004             if (axis == 'x') return 1729.13; else return 2437.80;
1005             break;
1006         case 'RA2':
1007             if (axis == 'x') return 1218.90; else return 1729.13;
1008             break;
1009         case 'RA3':
1010             if (axis == 'x') return 864.57; else return 1218.90;
1011             break;
1012         case 'RA4':
1013             if (axis == 'x') return 609.45; else return 864.57;
1014             break;
1015         case 'SRA0':
1016             if (axis == 'x') return 2551.18; else return 3628.35;
1017             break;
1018         case 'SRA1':
1019             if (axis == 'x') return 1814.17; else return 2551.18;
1020             break;
1021         case 'SRA2':
1022             if (axis == 'x') return 1275.59; else return 1814.17;
1023             break;
1024         case 'SRA3':
1025             if (axis == 'x') return 907.09; else return 1275.59;
1026             break;
1027         case 'SRA4':
1028             if (axis == 'x') return 637.80; else return 907.09;
1029             break;
1030         case 'LETTER':
1031             if (axis == 'x') return 612.00; else return 792.00;
1032             break;
1033         case 'LEGAL':
1034             if (axis == 'x') return 612.00; else return 1008.00;
1035             break;
1036         case 'EXECUTIVE':
1037             if (axis == 'x') return 521.86; else return 756.00;
1038             break;
1039         case 'FOLIO':
1040             if (axis == 'x') return 612.00; else return 936.00;
1041             break;
1042     } // end switch
1044     return 0;
1048  * for playing media from the BLOB repository
1050  * @param   var
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
1056  */
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)
1061         w_width = 640;
1063     // if height not specified, use default
1064     if (w_height == undefined)
1065         w_height = 480;
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
1078  */
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
1100  */
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};
1107     // jQuery POST
1108     jQuery.post(mime_chg_url, params);
1112  * Jquery Coding for inline editing SQL_QUERY
1113  */
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'] + "\">");
1123         return false;
1124     });
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 + "");
1128     });
1130     $("#btnDiscard").live("click",function(){
1131         $(".sql").html("<span class=\"syntax\"><span class=\"inner_sql\">" + oldText + "</span></span>");
1132     });
1134     $('.sqlbutton').click(function(evt){
1135         insertQuery(evt.target.id);
1136         return false;
1137     });
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");
1174         }else{
1175             // nothing
1176         }
1177     });
1179     $('#sqlquery').focus();
1180     if ($('#input_username')) {
1181         if ($('#input_username').val() == '') {
1182             $('#input_username').focus();
1183         } else {
1184             $('#input_password').focus();
1185         }
1186     }
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
1196  */
1198 function PMA_ajaxShowMessage(message, timeout) {
1200     //Handle the case when a empty data.message is passed.  We don't want the empty message
1201     if(message == '') {
1202         return true;
1203     }
1205     /**
1206      * @var msg String containing the message that has to be displayed
1207      * @default PMA_messages['strLoading']
1208      */
1209     if(!message) {
1210         var msg = PMA_messages['strLoading'];
1211     }
1212     else {
1213         var msg = message;
1214     }
1216     /**
1217      * @var timeout Number of milliseconds for which {@link msg} will be visible
1218      * @default 5000 ms
1219      */
1220     if(!timeout) {
1221         var to = 5000;
1222     }
1223     else {
1224         var to = timeout;
1225     }
1227     if( !ajax_message_init) {
1228         //For the first time this function is called, append a new div
1229         $(function(){
1230             $('<div id="loading_parent"></div>')
1231             .insertBefore("#serverinfo");
1233             $('<span id="loading" class="ajax_notification"></span>')
1234             .appendTo("#loading_parent")
1235             .html(msg)
1236             .slideDown('medium')
1237             .delay(to)
1238             .slideUp('medium', function(){
1239                 $(this)
1240                 .html("") //Clear the message
1241                 .hide();
1242             });
1243         }, 'top.frame_content');
1244         ajax_message_init = true;
1245     }
1246     else {
1247         //Otherwise, just show the div again after inserting the message
1248         $("#loading")
1249         .clearQueue()
1250         .html(msg)
1251         .slideDown('medium')
1252         .delay(to)
1253         .slideUp('medium', function() {
1254             $(this)
1255             .html("")
1256             .hide();
1257         })
1258     }
1262  * Hides/shows the "Open in ENUM/SET editor" message, depending on the data type of the column currently selected
1263  */
1264 function PMA_showNoticeForEnum(selectElement) {
1265     var enum_notice_id = selectElement.attr("id").split("_")[1];
1266     enum_notice_id += "_" + (parseInt(selectElement.attr("id").split("_")[2]) + 1);
1267     var selectedType = selectElement.attr("value");
1268     if (selectedType == "ENUM" || selectedType == "SET") {
1269         $("p[id='enum_notice_" + enum_notice_id + "']").show();
1270     } else {
1271         $("p[id='enum_notice_" + enum_notice_id + "']").hide();
1272     }
1276  * jQuery function that uses jQueryUI's dialogs to confirm with user. Does not
1277  *  return a jQuery object yet and hence cannot be chained
1279  * @param   string      question
1280  * @param   string      url         URL to be passed to the callbackFn to make
1281  *                                  an Ajax call to
1282  * @param   function    callbackFn  callback to execute after user clicks on OK
1283  */
1285 jQuery.fn.PMA_confirm = function(question, url, callbackFn) {
1286     if (PMA_messages['strDoYouReally'] == '') {
1287         return true;
1288     }
1290     /**
1291      *  @var    button_options  Object that stores the options passed to jQueryUI
1292      *                          dialog
1293      */
1294     var button_options = {};
1295     button_options[PMA_messages['strOK']] = function(){
1296                                                 $(this).dialog("close").remove();
1298                                                 if($.isFunction(callbackFn)) {
1299                                                     callbackFn.call(this, url);
1300                                                 }
1301                                             };
1302     button_options[PMA_messages['strCancel']] = function() {$(this).dialog("close").remove();}
1304     $('<div id="confirm_dialog"></div>')
1305     .prepend(question)
1306     .dialog({buttons: button_options});
1310  * jQuery function to sort a table's body after a new row has been appended to it.
1311  * Also fixes the even/odd classes of the table rows at the end.
1313  * @param   string      text_selector   string to select the sortKey's text
1315  * @return  jQuery Object for chaining purposes
1316  */
1317 jQuery.fn.PMA_sort_table = function(text_selector) {
1318     return this.each(function() {
1320         /**
1321          * @var table_body  Object referring to the table's <tbody> element
1322          */
1323         var table_body = $(this);
1324         /**
1325          * @var rows    Object referring to the collection of rows in {@link table_body}
1326          */
1327         var rows = $(this).find('tr').get();
1329         //get the text of the field that we will sort by
1330         $.each(rows, function(index, row) {
1331             row.sortKey = $.trim($(row).find(text_selector).text().toLowerCase());
1332         })
1334         //get the sorted order
1335         rows.sort(function(a,b) {
1336             if(a.sortKey < b.sortKey) {
1337                 return -1;
1338             }
1339             if(a.sortKey > b.sortKey) {
1340                 return 1;
1341             }
1342             return 0;
1343         })
1345         //pull out each row from the table and then append it according to it's order
1346         $.each(rows, function(index, row) {
1347             $(table_body).append(row);
1348             row.sortKey = null;
1349         })
1351         //Re-check the classes of each row
1352         $(this).find('tr:odd')
1353         .removeClass('even').addClass('odd')
1354         .end()
1355         .find('tr:even')
1356         .removeClass('odd').addClass('even');
1357     })
1361  * jQuery coding for 'Create Table'.  Used on db_operations.php,
1362  * db_structure.php and db_tracking.php (i.e., wherever
1363  * libraries/display_create_table.lib.php is used)
1365  * Attach Ajax Event handlers for Create Table
1366  */
1367 $(document).ready(function() {
1369     /**
1370      * Attach event handler to the submit action of the create table minimal form
1371      * and retrieve the full table form and display it in a dialog
1372      *
1373      * @uses    PMA_ajaxShowMessage()
1374      */
1375     $("#create_table_form_minimal.ajax").live('submit', function(event) {
1376         event.preventDefault();
1377         $form = $(this);
1379         /* @todo Validate this form! */
1381         /**
1382          *  @var    button_options  Object that stores the options passed to jQueryUI
1383          *                          dialog
1384          */
1385         var button_options = {};
1386         // in the following function we need to use $(this)
1387         button_options[PMA_messages['strCancel']] = function() {$(this).dialog('close').remove();}
1389         var button_options_error = {};
1390         button_options_error[PMA_messages['strOK']] = function() {$(this).dialog('close').remove();}
1392         PMA_ajaxShowMessage();
1393         if (! $form.find('input:hidden').is('#ajax_request_hidden')) {
1394             $form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
1395         }
1397         $.get($form.attr('action'), $form.serialize(), function(data) {
1398             //in the case of an error, show the error message returned.
1399             if (data.success != undefined && data.success == false) {
1400                 $('<div id="create_table_dialog"></div>')
1401                 .append(data.error)
1402                 .dialog({
1403                     title: PMA_messages['strCreateTable'],
1404                     height: 230,
1405                     width: 900,
1406                     open: PMA_verifyTypeOfAllColumns,
1407                     buttons : button_options_error
1408                 })// end dialog options
1409                 //remove the redundant [Back] link in the error message.
1410                 .find('fieldset').remove();
1411             } else {
1412                 $('<div id="create_table_dialog"></div>')
1413                 .append(data)
1414                 .dialog({
1415                     title: PMA_messages['strCreateTable'],
1416                     height: 600,
1417                     width: 900,
1418                     open: PMA_verifyTypeOfAllColumns,
1419                     buttons : button_options
1420                 }); // end dialog options
1421             }
1422         }) // end $.get()
1424         // empty table name and number of columns from the minimal form
1425         $form.find('input[name=table],input[name=num_fields]').val('');
1426     });
1428     /**
1429      * Attach event handler for submission of create table form (save)
1430      *
1431      * @uses    PMA_ajaxShowMessage()
1432      * @uses    $.PMA_sort_table()
1433      *
1434      */
1435     // .live() must be called after a selector, see http://api.jquery.com/live
1436     $("#create_table_form input[name=do_save_data]").live('click', function(event) {
1437         event.preventDefault();
1439         /**
1440          *  @var    the_form    object referring to the create table form
1441          */
1442         var $form = $("#create_table_form");
1444         /*
1445          * First validate the form; if there is a problem, avoid submitting it
1446          *
1447          * checkTableEditForm() needs a pure element and not a jQuery object,
1448          * this is why we pass $form[0] as a parameter (the jQuery object
1449          * is actually an array of DOM elements)
1450          */
1452         if (checkTableEditForm($form[0], $form.find('input[name=orig_num_fields]').val())) {
1453             // OK, form passed validation step
1454             if ($form.hasClass('ajax')) {
1455                 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
1456                 if (! $form.find('input:hidden').is('#ajax_request_hidden')) {
1457                     $form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
1458                 }
1459                 //User wants to submit the form
1460                 $.post($form.attr('action'), $form.serialize() + "&do_save_data=" + $(this).val(), function(data) {
1461                     if(data.success == true) {
1462                         $('#properties_message')
1463                          .removeClass('error')
1464                          .html('');
1465                         PMA_ajaxShowMessage(data.message);
1466                         // Only if the create table dialog (distinct panel) exists
1467                         if ($("#create_table_dialog").length > 0) {
1468                             $("#create_table_dialog").dialog("close").remove();
1469                         }
1471                         /**
1472                          * @var tables_table    Object referring to the <tbody> element that holds the list of tables
1473                          */
1474                         var tables_table = $("#tablesForm").find("tbody").not("#tbl_summary_row");
1475                         // this is the first table created in this db
1476                         if (tables_table.length == 0) {
1477                             if (window.parent && window.parent.frame_content) {
1478                                 window.parent.frame_content.location.reload();
1479                             }
1480                         } else {
1481                             /**
1482                              * @var curr_last_row   Object referring to the last <tr> element in {@link tables_table}
1483                              */
1484                             var curr_last_row = $(tables_table).find('tr:last');
1485                             /**
1486                              * @var curr_last_row_index_string   String containing the index of {@link curr_last_row}
1487                              */
1488                             var curr_last_row_index_string = $(curr_last_row).find('input:checkbox').attr('id').match(/\d+/)[0];
1489                             /**
1490                              * @var curr_last_row_index Index of {@link curr_last_row}
1491                              */
1492                             var curr_last_row_index = parseFloat(curr_last_row_index_string);
1493                             /**
1494                              * @var new_last_row_index   Index of the new row to be appended to {@link tables_table}
1495                              */
1496                             var new_last_row_index = curr_last_row_index + 1;
1497                             /**
1498                              * @var new_last_row_id String containing the id of the row to be appended to {@link tables_table}
1499                              */
1500                             var new_last_row_id = 'checkbox_tbl_' + new_last_row_index;
1502                             data.new_table_string = data.new_table_string.replace(/checkbox_tbl_/, new_last_row_id);
1503                             //append to table
1504                             $(data.new_table_string)
1505                              .appendTo(tables_table);
1507                             //Sort the table
1508                             $(tables_table).PMA_sort_table('th');
1509                         }
1511                         //Refresh navigation frame as a new table has been added
1512                         if (window.parent && window.parent.frame_navigation) {
1513                             window.parent.frame_navigation.location.reload();
1514                         }
1515                     } else {
1516                         $('#properties_message')
1517                          .addClass('error')
1518                          .html(data.error);
1519                         // scroll to the div containing the error message
1520                         $('#properties_message')[0].scrollIntoView();
1521                     }
1522                 }) // end $.post()
1523             } // end if ($form.hasClass('ajax')
1524             else {
1525                 // non-Ajax submit
1526                 $form.append('<input type="hidden" name="do_save_data" value="save" />');
1527                 $form.submit();
1528             }
1529         } // end if (checkTableEditForm() )
1530     }) // end create table form (save)
1532     /**
1533      * Attach event handler for create table form (add fields)
1534      *
1535      * @uses    PMA_ajaxShowMessage()
1536      * @uses    $.PMA_sort_table()
1537      * @uses    window.parent.refreshNavigation()
1538      *
1539      */
1540     // .live() must be called after a selector, see http://api.jquery.com/live
1541     $("#create_table_form.ajax input[name=submit_num_fields]").live('click', function(event) {
1542         event.preventDefault();
1544         /**
1545          *  @var    the_form    object referring to the create table form
1546          */
1547         var $form = $("#create_table_form");
1549         PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
1550         if (! $form.find('input:hidden').is('#ajax_request_hidden')) {
1551             $form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
1552         }
1554         //User wants to add more fields to the table
1555         $.post($form.attr('action'), $form.serialize() + "&submit_num_fields=" + $(this).val(), function(data) {
1556             // if 'create_table_dialog' exists
1557             if ($("#create_table_dialog").length > 0) {
1558                 $("#create_table_dialog").html(data);
1559             }
1560             // if 'create_table_div' exists
1561             if ($("#create_table_div").length > 0) {
1562                 $("#create_table_div").html(data);
1563             }
1564             PMA_verifyTypeOfAllColumns();
1565         }) //end $.post()
1567     }) // end create table form (add fields)
1569 }, 'top.frame_content'); //end $(document).ready for 'Create Table'
1572  * Attach Ajax event handlers for Drop Trigger.  Used on tbl_structure.php
1573  * @see $cfg['AjaxEnable']
1574  */
1575 $(document).ready(function() {
1577     $(".drop_trigger_anchor").live('click', function(event) {
1578         event.preventDefault();
1580         $anchor = $(this);
1581         /**
1582          * @var curr_row    Object reference to the current trigger's <tr>
1583          */
1584         var $curr_row = $anchor.parents('tr');
1585         /**
1586          * @var question    String containing the question to be asked for confirmation
1587          */
1588         var question = 'DROP TRIGGER IF EXISTS `' + $curr_row.children('td:first').text() + '`';
1590         $anchor.PMA_confirm(question, $anchor.attr('href'), function(url) {
1592             PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
1593             $.get(url, {'is_js_confirmed': 1, 'ajax_request': true}, function(data) {
1594                 if(data.success == true) {
1595                     PMA_ajaxShowMessage(data.message);
1596                     $("#topmenucontainer")
1597                     .next('div')
1598                     .remove()
1599                     .end()
1600                     .after(data.sql_query);
1601                     $curr_row.hide("medium").remove();
1602                 }
1603                 else {
1604                     PMA_ajaxShowMessage(data.error);
1605                 }
1606             }) // end $.get()
1607         }) // end $.PMA_confirm()
1608     }) // end $().live()
1609 }, 'top.frame_content'); //end $(document).ready() for Drop Trigger
1612  * Attach Ajax event handlers for Drop Database. Moved here from db_structure.js
1613  * as it was also required on db_create.php
1615  * @uses    $.PMA_confirm()
1616  * @uses    PMA_ajaxShowMessage()
1617  * @uses    window.parent.refreshNavigation()
1618  * @uses    window.parent.refreshMain()
1619  * @see $cfg['AjaxEnable']
1620  */
1621 $(document).ready(function() {
1622     $("#drop_db_anchor").live('click', function(event) {
1623         event.preventDefault();
1625         //context is top.frame_content, so we need to use window.parent.db to access the db var
1626         /**
1627          * @var question    String containing the question to be asked for confirmation
1628          */
1629         var question = PMA_messages['strDropDatabaseStrongWarning'] + '\n' + PMA_messages['strDoYouReally'] + ' :\n' + 'DROP DATABASE ' + window.parent.db;
1631         $(this).PMA_confirm(question, $(this).attr('href') ,function(url) {
1633             PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
1634             $.get(url, {'is_js_confirmed': '1', 'ajax_request': true}, function(data) {
1635                 //Database deleted successfully, refresh both the frames
1636                 window.parent.refreshNavigation();
1637                 window.parent.refreshMain();
1638             }) // end $.get()
1639         }); // end $.PMA_confirm()
1640     }); //end of Drop Database Ajax action
1641 }) // end of $(document).ready() for Drop Database
1644  * Attach Ajax event handlers for 'Create Database'.  Used wherever libraries/
1645  * display_create_database.lib.php is used, ie main.php and server_databases.php
1647  * @uses    PMA_ajaxShowMessage()
1648  * @see $cfg['AjaxEnable']
1649  */
1650 $(document).ready(function() {
1652     $('#create_database_form.ajax').live('submit', function(event) {
1653         event.preventDefault();
1655         $form = $(this);
1657         PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
1659         if (! $form.find('input:hidden').is('#ajax_request_hidden')) {
1660             $form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
1661         }
1663         $.post($form.attr('action'), $form.serialize(), function(data) {
1664             if(data.success == true) {
1665                 PMA_ajaxShowMessage(data.message);
1667                 //Append database's row to table
1668                 $("#tabledatabases")
1669                 .find('tbody')
1670                 .append(data.new_db_string)
1671                 .PMA_sort_table('.name')
1672                 .find('#db_summary_row')
1673                 .appendTo('#tabledatabases tbody')
1674                 .removeClass('odd even');
1676                 var $databases_count_object = $('#databases_count');
1677                 var databases_count = parseInt($databases_count_object.text());
1678                 $databases_count_object.text(++databases_count);
1679                 //Refresh navigation frame as a new database has been added
1680                 if (window.parent && window.parent.frame_navigation) {
1681                     window.parent.frame_navigation.location.reload();
1682                 }
1683             }
1684             else {
1685                 PMA_ajaxShowMessage(data.error);
1686             }
1687         }) // end $.post()
1688     }) // end $().live()
1689 })  // end $(document).ready() for Create Database
1692  * Attach Ajax event handlers for 'Change Password' on main.php
1693  */
1694 $(document).ready(function() {
1696     /**
1697      * Attach Ajax event handler on the change password anchor
1698      * @see $cfg['AjaxEnable']
1699      */
1700     $('#change_password_anchor.dialog_active').live('click',function(event) {
1701         event.preventDefault();
1702         return false;
1703         });
1704     $('#change_password_anchor.ajax').live('click', function(event) {
1705         event.preventDefault();
1706         $(this).removeClass('ajax').addClass('dialog_active');
1707         /**
1708          * @var button_options  Object containing options to be passed to jQueryUI's dialog
1709          */
1710         var button_options = {};
1711         button_options[PMA_messages['strCancel']] = function() {$(this).dialog('close').remove();}
1712         $.get($(this).attr('href'), {'ajax_request': true}, function(data) {
1713             $('<div id="change_password_dialog"></div>')
1714             .dialog({
1715                 title: PMA_messages['strChangePassword'],
1716                 width: 600,
1717                 close: function(ev,ui) {$(this).remove();}, 
1718                 buttons : button_options,
1719                 beforeClose: function(ev,ui){ $('#change_password_anchor.dialog_active').removeClass('dialog_active').addClass('ajax')}
1720             })
1721             .append(data);
1722             displayPasswordGenerateButton();
1723         }) // end $.get()
1724     }) // end handler for change password anchor
1726     /**
1727      * Attach Ajax event handler for Change Password form submission
1728      *
1729      * @uses    PMA_ajaxShowMessage()
1730      * @see $cfg['AjaxEnable']
1731      */
1732     $("#change_password_form.ajax").find('input[name=change_pw]').live('click', function(event) {
1733         event.preventDefault();
1735         /**
1736          * @var the_form    Object referring to the change password form
1737          */
1738         var the_form = $("#change_password_form");
1740         /**
1741          * @var this_value  String containing the value of the submit button.
1742          * Need to append this for the change password form on Server Privileges
1743          * page to work
1744          */
1745         var this_value = $(this).val();
1747         PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
1748         $(the_form).append('<input type="hidden" name="ajax_request" value="true" />');
1750         $.post($(the_form).attr('action'), $(the_form).serialize() + '&change_pw='+ this_value, function(data) {
1751             if(data.success == true) {
1752                 $("#topmenucontainer").after(data.sql_query);
1753                 $("#change_password_dialog").hide().remove();
1754                 $("#edit_user_dialog").dialog("close").remove();
1755                 $('#change_password_anchor.dialog_active').removeClass('dialog_active').addClass('ajax');
1756             }
1757             else {
1758                 PMA_ajaxShowMessage(data.error);
1759             }
1760         }) // end $.post()
1761     }) // end handler for Change Password form submission
1762 }) // end $(document).ready() for Change Password
1765  * Toggle the hiding/showing of the "Open in ENUM/SET editor" message when
1766  * the page loads and when the selected data type changes
1767  */
1768 $(document).ready(function() {
1769     // is called here for normal page loads and also when opening
1770     // the Create table dialog
1771     PMA_verifyTypeOfAllColumns();
1772     //
1773     // needs live() to work also in the Create Table dialog
1774     $("select[class='column_type']").live('change', function() {
1775         PMA_showNoticeForEnum($(this));
1776     });
1779 function PMA_verifyTypeOfAllColumns() {
1780     $("select[class='column_type']").each(function() {
1781         PMA_showNoticeForEnum($(this));
1782     });
1786  * Closes the ENUM/SET editor and removes the data in it
1787  */
1788 function disable_popup() {
1789     $("#popup_background").fadeOut("fast");
1790     $("#enum_editor").fadeOut("fast");
1791     // clear the data from the text boxes
1792     $("#enum_editor #values input").remove();
1793     $("#enum_editor input[type='hidden']").remove();
1797  * Opens the ENUM/SET editor and controls its functions
1798  */
1799 $(document).ready(function() {
1800     // Needs live() to work also in the Create table dialog
1801     $("a[class='open_enum_editor']").live('click', function() {
1802         // Center the popup
1803         var windowWidth = document.documentElement.clientWidth;
1804         var windowHeight = document.documentElement.clientHeight;
1805         var popupWidth = windowWidth/2;
1806         var popupHeight = windowHeight*0.8;
1807         var popupOffsetTop = windowHeight/2 - popupHeight/2;
1808         var popupOffsetLeft = windowWidth/2 - popupWidth/2;
1809         $("#enum_editor").css({"position":"absolute", "top": popupOffsetTop, "left": popupOffsetLeft, "width": popupWidth, "height": popupHeight});
1811         // Make it appear
1812         $("#popup_background").css({"opacity":"0.7"});
1813         $("#popup_background").fadeIn("fast");
1814         $("#enum_editor").fadeIn("fast");
1816         // Get the values
1817         var values = $(this).parent().prev("input").attr("value").split(",");
1818         $.each(values, function(index, val) {
1819             if(jQuery.trim(val) != "") {
1820                  // enclose the string in single quotes if it's not already
1821                  if(val.substr(0, 1) != "'") {
1822                       val = "'" + val;
1823                  }
1824                  if(val.substr(val.length-1, val.length) != "'") {
1825                       val = val + "'";
1826                  }
1827                 // escape the single quotes, except the mandatory ones enclosing the entire string
1828                 val = val.substr(1, val.length-2).replace(/''/g, "'").replace(/\\\\/g, '\\').replace(/\\'/g, "'").replace(/'/g, "&#039;");
1829                 // escape the greater-than symbol
1830                 val = val.replace(/>/g, "&gt;");
1831                 $("#enum_editor #values").append("<input type='text' value=" + val + " />");
1832             }
1833         });
1834         // So we know which column's data is being edited
1835         $("#enum_editor").append("<input type='hidden' value='" + $(this).parent().prev("input").attr("id") + "' />");
1836         return false;
1837     });
1839     // If the "close" link is clicked, close the enum editor
1840     // Needs live() to work also in the Create table dialog
1841     $("a[class='close_enum_editor']").live('click', function() {
1842         disable_popup();
1843     });
1845     // If the "cancel" link is clicked, close the enum editor
1846     // Needs live() to work also in the Create table dialog
1847     $("a[class='cancel_enum_editor']").live('click', function() {
1848         disable_popup();
1849     });
1851     // When "add a new value" is clicked, append an empty text field
1852     // Needs live() to work also in the Create table dialog
1853     $("a[class='add_value']").live('click', function() {
1854         $("#enum_editor #values").append("<input type='text' />");
1855     });
1857     // When the submit button is clicked, put the data back into the original form
1858     // Needs live() to work also in the Create table dialog
1859     $("#enum_editor input[type='submit']").live('click', function() {
1860         var value_array = new Array();
1861         $.each($("#enum_editor #values input"), function(index, input_element) {
1862             val = jQuery.trim(input_element.value);
1863             if(val != "") {
1864                 value_array.push("'" + val.replace(/\\/g, '\\\\').replace(/'/g, "''") + "'");
1865             }
1866         });
1867         // get the Length/Values text field where this value belongs
1868         var values_id = $("#enum_editor input[type='hidden']").attr("value");
1869         $("input[id='" + values_id + "']").attr("value", value_array.join(","));
1870         disable_popup();
1871      });
1873     /**
1874      * Hides certain table structure actions, replacing them with the word "More". They are displayed
1875      * in a dropdown menu when the user hovers over the word "More."
1876      */
1877     // Remove the actions from the table cells (they are available by default for JavaScript-disabled browsers)
1878     // if the table is not a view or information_schema (otherwise there is only one action to hide and there's no point)
1879     if($("input[type='hidden'][name='table_type']").val() == "table") {
1880         var $table = $("table[id='tablestructure']");
1881         $table.find("td[class='browse']").remove();
1882         $table.find("td[class='primary']").remove();
1883         $table.find("td[class='unique']").remove();
1884         $table.find("td[class='index']").remove();
1885         $table.find("td[class='fulltext']").remove();
1886         $table.find("th[class='action']").attr("colspan", 3);
1888         // Display the "more" text
1889         $table.find("td[class='more_opts']").show();
1891         // Position the dropdown
1892         $(".structure_actions_dropdown").each(function() {
1893             // Optimize DOM querying
1894             var $this_dropdown = $(this);
1895              // The top offset must be set for IE even if it didn't change
1896             var cell_right_edge_offset = $this_dropdown.parent().offset().left + $this_dropdown.parent().innerWidth();
1897             var left_offset = cell_right_edge_offset - $this_dropdown.innerWidth();
1898             var top_offset = $this_dropdown.parent().offset().top + $this_dropdown.parent().innerHeight();
1899             $this_dropdown.offset({ top: top_offset, left: left_offset });
1900         });
1902         // A hack for IE6 to prevent the after_field select element from being displayed on top of the dropdown by
1903         // positioning an iframe directly on top of it
1904         var $after_field = $("select[name='after_field']");
1905         $("iframe[class='IE_hack']")
1906             .width($after_field.width())
1907             .height($after_field.height())
1908             .offset({
1909                 top: $after_field.offset().top,
1910                 left: $after_field.offset().left
1911             });
1913         // When "more" is hovered over, show the hidden actions
1914         $table.find("td[class='more_opts']")
1915             .mouseenter(function() {
1916                 if($.browser.msie && $.browser.version == "6.0") {
1917                     $("iframe[class='IE_hack']")
1918                         .show()
1919                         .width($after_field.width()+4)
1920                         .height($after_field.height()+4)
1921                         .offset({
1922                             top: $after_field.offset().top,
1923                             left: $after_field.offset().left
1924                         });
1925                 }
1926                 $(".structure_actions_dropdown").hide(); // Hide all the other ones that may be open
1927                 $(this).children(".structure_actions_dropdown").show();
1928                 // Need to do this again for IE otherwise the offset is wrong
1929                 if($.browser.msie) {
1930                     var left_offset_IE = $(this).offset().left + $(this).innerWidth() - $(this).children(".structure_actions_dropdown").innerWidth();
1931                     var top_offset_IE = $(this).offset().top + $(this).innerHeight();
1932                     $(this).children(".structure_actions_dropdown").offset({
1933                         top: top_offset_IE,
1934                         left: left_offset_IE });
1935                 }
1936             })
1937             .mouseleave(function() {
1938                 $(this).children(".structure_actions_dropdown").hide();
1939                 if($.browser.msie && $.browser.version == "6.0") {
1940                     $("iframe[class='IE_hack']").hide();
1941                 }
1942             });
1943     }
1946 /* Displays tooltips */
1947 $(document).ready(function() {
1948     // Hide the footnotes from the footer (which are displayed for
1949     // JavaScript-disabled browsers) since the tooltip is sufficient
1950     $(".footnotes").hide();
1951     $(".footnotes span").each(function() {
1952         $(this).children("sup").remove();
1953     });
1954     // The border and padding must be removed otherwise a thin yellow box remains visible
1955     $(".footnotes").css("border", "none");
1956     $(".footnotes").css("padding", "0px");
1958     // Replace the superscripts with the help icon
1959     $("sup[class='footnotemarker']").hide();
1960     $("img[class='footnotemarker']").show();
1962     $("img[class='footnotemarker']").each(function() {
1963         var span_id = $(this).attr("id");
1964         span_id = span_id.split("_")[1];
1965         var tooltip_text = $(".footnotes span[id='footnote_" + span_id + "']").html();
1966         $(this).qtip({
1967             content: tooltip_text,
1968             show: { delay: 0 },
1969             hide: { when: 'unfocus', delay: 0 },
1970             style: { background: '#ffffcc' }
1971         });
1972     });
1975 function menuResize()
1977     var cnt = $('#topmenu');
1978     var wmax = cnt.innerWidth() - 5; // 5 px margin for jumping menu in Chrome
1979     var submenu = cnt.find('.submenu');
1980     var submenu_w = submenu.outerWidth(true);
1981     var submenu_ul = submenu.find('ul');
1982     var li = cnt.find('> li');
1983     var li2 = submenu_ul.find('li');
1984     var more_shown = li2.length > 0;
1985     var w = more_shown ? submenu_w : 0;
1987     // hide menu items
1988     var hide_start = 0;
1989     for (var i = 0; i < li.length-1; i++) { // li.length-1: skip .submenu element
1990         var el = $(li[i]);
1991         var el_width = el.outerWidth(true);
1992         el.data('width', el_width);
1993         w += el_width;
1994         if (w > wmax) {
1995             w -= el_width;
1996             if (w + submenu_w < wmax) {
1997                 hide_start = i;
1998             } else {
1999                 hide_start = i-1;
2000                 w -= $(li[i-1]).data('width');
2001             }
2002             break;
2003         }
2004     }
2006     if (hide_start > 0) {
2007         for (var i = hide_start; i < li.length-1; i++) {
2008             $(li[i])[more_shown ? 'prependTo' : 'appendTo'](submenu_ul);
2009         }
2010         submenu.addClass('shown');
2011     } else if (more_shown) {
2012         w -= submenu_w;
2013         // nothing hidden, maybe something can be restored
2014         for (var i = 0; i < li2.length; i++) {
2015             //console.log(li2[i], submenu_w);
2016             w += $(li2[i]).data('width');
2017             // item fits or (it is the last item and it would fit if More got removed)
2018             if (w+submenu_w < wmax || (i == li2.length-1 && w < wmax)) {
2019                 $(li2[i]).insertBefore(submenu);
2020                 if (i == li2.length-1) {
2021                     submenu.removeClass('shown');
2022                 }
2023                 continue;
2024             }
2025             break;
2026         }
2027     }
2028     if (submenu.find('.tabactive').length) {
2029         submenu.addClass('active').find('> a').removeClass('tab').addClass('tabactive');
2030     } else {
2031         submenu.removeClass('active').find('> a').addClass('tab').removeClass('tabactive');
2032     }
2035 $(function() {
2036     var topmenu = $('#topmenu');
2037     if (topmenu.length == 0) {
2038         return;
2039     }
2040     // create submenu container
2041     var link = $('<a />', {href: '#', 'class': 'tab'})
2042         .text(PMA_messages['strMore'])
2043         .click(function(e) {
2044             e.preventDefault();
2045         });
2046     var img = topmenu.find('li:first-child img');
2047     if (img.length) {
2048         img.clone().attr('src', img.attr('src').replace(/\/[^\/]+$/, '/b_more.png')).prependTo(link);
2049     }
2050     var submenu = $('<li />', {'class': 'submenu'})
2051         .append(link)
2052         .append($('<ul />'))
2053         .mouseenter(function() {
2054             if ($(this).find('ul .tabactive').length == 0) {
2055                 $(this).addClass('submenuhover').find('> a').addClass('tabactive');
2056             }
2057         })
2058         .mouseleave(function() {
2059             if ($(this).find('ul .tabactive').length == 0) {
2060                 $(this).removeClass('submenuhover').find('> a').removeClass('tabactive');
2061             }
2062         });
2063     topmenu.append(submenu);
2065     // populate submenu and register resize event
2066     $(window).resize(menuResize);
2067     menuResize();
2071  * For the checkboxes in browse mode, handles the shift/click (only works
2072  * in horizontal mode) and propagates the click to the "companion" checkbox
2073  * (in both horizontal and vertical). Works also for pages reached via AJAX.
2074  */
2075 $(document).ready(function() {
2076     $('.multi_checkbox').live('click',function(e) {
2077         var current_checkbox_id = this.id;
2078         var left_checkbox_id = current_checkbox_id.replace('_right', '_left');
2079         var right_checkbox_id = current_checkbox_id.replace('_left', '_right');
2080         var other_checkbox_id = '';
2081         if (current_checkbox_id == left_checkbox_id) {
2082             other_checkbox_id = right_checkbox_id;
2083         } else {
2084             other_checkbox_id = left_checkbox_id;
2085         }
2087         var $current_checkbox = $('#' + current_checkbox_id);
2088         var $other_checkbox = $('#' + other_checkbox_id);
2090         if (e.shiftKey) {
2091             var index_of_current_checkbox = $('.multi_checkbox').index($current_checkbox);
2092             var $last_checkbox = $('.multi_checkbox').filter('.last_clicked');
2093             var index_of_last_click = $('.multi_checkbox').index($last_checkbox);
2094             $('.multi_checkbox')
2095                 .filter(function(index) {
2096                     // the first clicked row can be on a row above or below the
2097                     // shift-clicked row
2098                     return (index_of_current_checkbox > index_of_last_click && index > index_of_last_click && index < index_of_current_checkbox)
2099                      || (index_of_last_click > index_of_current_checkbox && index < index_of_last_click && index > index_of_current_checkbox);
2100                 })
2101                 .each(function(index) {
2102                     var $intermediate_checkbox = $(this);
2103                     if ($current_checkbox.is(':checked')) {
2104                         $intermediate_checkbox.attr('checked', true);
2105                     } else {
2106                         $intermediate_checkbox.attr('checked', false);
2107                     }
2108                 });
2109         }
2111         $('.multi_checkbox').removeClass('last_clicked');
2112         $current_checkbox.addClass('last_clicked');
2114         // When there is a checkbox on both ends of the row, propagate the
2115         // click on one of them to the other one.
2116         // (the default action has not been prevented so if we have
2117         // just clicked, this "if" is true)
2118         if ($current_checkbox.is(':checked')) {
2119             $other_checkbox.attr('checked', true);
2120         } else {
2121             $other_checkbox.attr('checked', false);
2122         }
2123     });
2124 }) // end of $(document).ready() for multi checkbox
2127  * Get the row number from the classlist (for example, row_1)
2128  */
2129 function PMA_getRowNumber(classlist) {
2130     return parseInt(classlist.split(/row_/)[1]);
2134  * Changes status of slider
2135  */
2136 function PMA_set_status_label(id) {
2137     if ($('#' + id).css('display') == 'none') {
2138         $('#anchor_status_' + id).text('+ ');
2139     } else {
2140         $('#anchor_status_' + id).text('- ');
2141     }
2145  * Initializes slider effect.
2146  */
2147 function PMA_init_slider() {
2148     $('.pma_auto_slider').each(function(idx, e) {
2149         if ($(e).hasClass('slider_init_done')) return;
2150         $(e).addClass('slider_init_done');
2151         $('<span id="anchor_status_' + e.id + '"></span>')
2152             .insertBefore(e);
2153         PMA_set_status_label(e.id);
2155         $('<a href="#' + e.id + '" id="anchor_' + e.id + '">' + e.title + '</a>')
2156             .insertBefore(e)
2157             .click(function() {
2158                 $('#' + e.id).toggle('clip', function() {
2159                     PMA_set_status_label(e.id);
2160                 });
2161                 return false;
2162             });
2163     });
2167  * Vertical pointer
2168  */
2169 $(document).ready(function() {
2170     $('.vpointer').live('hover',
2171         //handlerInOut
2172         function(e) {
2173         var $this_td = $(this);
2174         var row_num = PMA_getRowNumber($this_td.attr('class'));
2175         // for all td of the same vertical row, toggle hover
2176         $('.vpointer').filter('.row_' + row_num).toggleClass('hover');
2177         }
2178         );
2179 }) // end of $(document).ready() for vertical pointer
2181 $(document).ready(function() {
2182     /**
2183      * Vertical marker
2184      */
2185     $('.vmarker').live('click', function(e) {
2186         var $this_td = $(this);
2187         var row_num = PMA_getRowNumber($this_td.attr('class'));
2188         // for all td of the same vertical row, toggle the marked class
2189         $('.vmarker').filter('.row_' + row_num).toggleClass('marked');
2190         });
2192     /**
2193      * Reveal visual builder anchor
2194      */
2196     $('#visual_builder_anchor').show();
2198     /**
2199      * Page selector in db Structure (non-AJAX)
2200      */
2201     $('#tableslistcontainer').find('#pageselector').live('change', function() {
2202         $(this).parent("form").submit();
2203     });
2205     /**
2206      * Page selector in navi panel (non-AJAX)
2207      */
2208     $('#navidbpageselector').find('#pageselector').live('change', function() {
2209         $(this).parent("form").submit();
2210     });
2212     /**
2213      * Page selector in browse_foreigners windows (non-AJAX)
2214      */
2215     $('#body_browse_foreigners').find('#pageselector').live('change', function() {
2216         $(this).closest("form").submit();
2217     });
2219     /**
2220      * Load version information asynchronously.
2221      */
2222     if ($('.jsversioncheck').length > 0) {
2223         (function() {
2224             var s = document.createElement('script');
2225             s.type = 'text/javascript';
2226             s.async = true;
2227             s.src = 'http://www.phpmyadmin.net/home_page/version.js';
2228             s.onload = PMA_current_version;
2229             var x = document.getElementsByTagName('script')[0];
2230             x.parentNode.insertBefore(s, x);
2231         })();
2232     }
2234     /**
2235      * Slider effect.
2236      */
2237     PMA_init_slider();
2239     /**
2240      * Enables the text generated by PMA_linkOrButton() to be clickable
2241      */
2242     $('.clickprevimage')
2243         .css('color', function(index) {
2244             return $('a').css('color');
2245         })
2246         .css('cursor', function(index) {
2247             return $('a').css('cursor');
2248         }) //todo: hover effect
2249         .live('click',function(e) {
2250             $this_span = $(this);
2251             if ($this_span.closest('td').is('.inline_edit_anchor')) {
2252             // this would bind a second click event to the inline edit
2253             // anchor and would disturb its behavior
2254             } else {
2255                 $this_span.parent().find('input:image').click();
2256             }
2257         });
2259 }) // end of $(document).ready()