FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
phpmyadmin/js/src/functions.js at master · saurass/phpmyadmin · GitHub
phpmyadmin/js/src/functions.js at master · saurass/phpmyadmin · GitHub
Skip to content
Navigation Menu
Sign in
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Events
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
saurass
phpmyadmin
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
phpmyadmin
/
js
/
src
/
functions.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
5198 lines (4865 loc) · 176 KB
Breadcrumbs
phpmyadmin
/
js
/
src
/
functions.js
Copy path
File metadata and controls
5198 lines (4865 loc) · 176 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* global isStorageSupported */
// js/config.js
/* global ChartType, ColumnType, DataTable, JQPlotChartFactory */
// js/chart.js
/* global DatabaseStructure */
// js/database/structure.js
/* global mysqlDocBuiltin, mysqlDocKeyword */
// js/doclinks.js
/* global Indexes */
// js/indexes.js
/* global firstDayOfCalendar, maxInputVars, mysqlDocTemplate, themeImagePath */
// templates/javascript/variables.twig
/* global MicroHistory */
// js/microhistory.js
/* global sprintf */
// js/vendor/sprintf.js
/* global zxcvbn */
// js/vendor/zxcvbn.js
/**
* general function, usually for data manipulation pages
*
*/
var
Functions
=
{
}
;
/**
*
@var
sqlBoxLocked lock for the sqlbox textarea in the querybox
*/
var
sqlBoxLocked
=
false
;
/**
*
@var
{array} holds elements which content should only selected once
*/
var
onlyOnceElements
=
[
]
;
/**
*
@var
{int} ajaxMessageCount Number of AJAX messages shown since page load
*/
var
ajaxMessageCount
=
0
;
/**
*
@var
codeMirrorEditor object containing CodeMirror editor of the query editor in SQL tab
*/
var
codeMirrorEditor
=
false
;
/**
*
@var
codeMirrorInlineEditor object containing CodeMirror editor of the inline query editor
*/
var
codeMirrorInlineEditor
=
false
;
/**
*
@var
{boolean} sqlAutoCompleteInProgress shows if Table/Column name autocomplete AJAX is in progress
*/
var
sqlAutoCompleteInProgress
=
false
;
/**
*
@var
sqlAutoComplete object containing list of columns in each table
*/
var
sqlAutoComplete
=
false
;
/**
*
@var
{string} sqlAutoCompleteDefaultTable string containing default table to autocomplete columns
*/
var
sqlAutoCompleteDefaultTable
=
''
;
/**
*
@var
{array} centralColumnList array to hold the columns in central list per db.
*/
var
centralColumnList
=
[
]
;
/**
*
@var
{array} primaryIndexes array to hold 'Primary' index columns.
*/
// eslint-disable-next-line no-unused-vars
var
primaryIndexes
=
[
]
;
/**
*
@var
{array} uniqueIndexes array to hold 'Unique' index columns.
*/
// eslint-disable-next-line no-unused-vars
var
uniqueIndexes
=
[
]
;
/**
*
@var
{array} indexes array to hold 'Index' columns.
*/
// eslint-disable-next-line no-unused-vars
var
indexes
=
[
]
;
/**
*
@var
{array} fulltextIndexes array to hold 'Fulltext' columns.
*/
// eslint-disable-next-line no-unused-vars
var
fulltextIndexes
=
[
]
;
/**
*
@var
{array} spatialIndexes array to hold 'Spatial' columns.
*/
// eslint-disable-next-line no-unused-vars
var
spatialIndexes
=
[
]
;
/**
* Make sure that ajax requests will not be cached
* by appending a random variable to their parameters
*/
$
.
ajaxPrefilter
(
function
(
options
,
originalOptions
)
{
var
nocache
=
new
Date
(
)
.
getTime
(
)
+
''
+
Math
.
floor
(
Math
.
random
(
)
*
1000000
)
;
if
(
typeof
options
.
data
===
'string'
)
{
options
.
data
+=
'&_nocache='
+
nocache
+
'&token='
+
encodeURIComponent
(
CommonParams
.
get
(
'token'
)
)
;
}
else
if
(
typeof
options
.
data
===
'object'
)
{
options
.
data
=
$
.
extend
(
originalOptions
.
data
,
{
'_nocache'
:
nocache
,
'token'
:
CommonParams
.
get
(
'token'
)
}
)
;
}
}
)
;
/**
* Adds a date/time picker to an element
*
*
@param
{
object
} $thisElement a jQuery object pointing to the element
*/
Functions
.
addDatepicker
=
function
(
$thisElement
,
type
,
options
)
{
if
(
type
!==
'date'
&&
type
!==
'time'
&&
type
!==
'datetime'
&&
type
!==
'timestamp'
)
{
return
;
}
var
showTimepicker
=
true
;
if
(
type
===
'date'
)
{
showTimepicker
=
false
;
}
// Getting the current Date and time
var
currentDateTime
=
new
Date
(
)
;
var
defaultOptions
=
{
timeInput
:
true
,
hour
:
currentDateTime
.
getHours
(
)
,
minute
:
currentDateTime
.
getMinutes
(
)
,
second
:
currentDateTime
.
getSeconds
(
)
,
showOn
:
'button'
,
buttonImage
:
themeImagePath
+
'b_calendar.png'
,
buttonImageOnly
:
true
,
stepMinutes
:
1
,
stepHours
:
1
,
showSecond
:
true
,
showMillisec
:
true
,
showMicrosec
:
true
,
showTimepicker
:
showTimepicker
,
showButtonPanel
:
false
,
changeYear
:
true
,
dateFormat
:
'yy-mm-dd'
,
// yy means year with four digits
timeFormat
:
'HH:mm:ss.lc'
,
constrainInput
:
false
,
altFieldTimeOnly
:
false
,
showAnim
:
''
,
beforeShow
:
function
(
input
,
inst
)
{
// Remember that we came from the datepicker; this is used
// in table/change.js by verificationsAfterFieldChange()
$thisElement
.
data
(
'comes_from'
,
'datepicker'
)
;
if
(
$
(
input
)
.
closest
(
'.cEdit'
)
.
length
>
0
)
{
setTimeout
(
function
(
)
{
inst
.
dpDiv
.
css
(
{
top
:
0
,
left
:
0
,
position
:
'relative'
}
)
;
}
,
0
)
;
}
setTimeout
(
function
(
)
{
// Fix wrong timepicker z-index, doesn't work without timeout
$
(
'#ui-timepicker-div'
)
.
css
(
'z-index'
,
$
(
'#ui-datepicker-div'
)
.
css
(
'z-index'
)
)
;
// Integrate tooltip text into dialog
var
tooltip
=
$thisElement
.
tooltip
(
'instance'
)
;
if
(
typeof
tooltip
!==
'undefined'
)
{
tooltip
.
disable
(
)
;
var
$note
=
$
(
'<p class="note"></div>'
)
;
$note
.
text
(
tooltip
.
option
(
'content'
)
)
;
$
(
'div.ui-datepicker'
)
.
append
(
$note
)
;
}
}
,
0
)
;
}
,
onSelect
:
function
(
)
{
$thisElement
.
data
(
'datepicker'
)
.
inline
=
true
;
}
,
onClose
:
function
(
)
{
// The value is no more from the date picker
$thisElement
.
data
(
'comes_from'
,
''
)
;
if
(
typeof
$thisElement
.
data
(
'datepicker'
)
!==
'undefined'
)
{
$thisElement
.
data
(
'datepicker'
)
.
inline
=
false
;
}
var
tooltip
=
$thisElement
.
tooltip
(
'instance'
)
;
if
(
typeof
tooltip
!==
'undefined'
)
{
tooltip
.
enable
(
)
;
}
}
}
;
if
(
type
===
'time'
)
{
$thisElement
.
timepicker
(
$
.
extend
(
defaultOptions
,
options
)
)
;
// Add a tip regarding entering MySQL allowed-values for TIME data-type
Functions
.
tooltip
(
$thisElement
,
'input'
,
Messages
.
strMysqlAllowedValuesTipTime
)
;
}
else
{
$thisElement
.
datetimepicker
(
$
.
extend
(
defaultOptions
,
options
)
)
;
}
}
;
/**
* Add a date/time picker to each element that needs it
* (only when jquery-ui-timepicker-addon.js is loaded)
*/
Functions
.
addDateTimePicker
=
function
(
)
{
if
(
$
.
timepicker
!==
undefined
)
{
$
(
'input.timefield, input.datefield, input.datetimefield'
)
.
each
(
function
(
)
{
var
decimals
=
$
(
this
)
.
parent
(
)
.
attr
(
'data-decimals'
)
;
var
type
=
$
(
this
)
.
parent
(
)
.
attr
(
'data-type'
)
;
var
showMillisec
=
false
;
var
showMicrosec
=
false
;
var
timeFormat
=
'HH:mm:ss'
;
var
hourMax
=
23
;
// check for decimal places of seconds
if
(
decimals
>
0
&&
type
.
indexOf
(
'time'
)
!==
-
1
)
{
if
(
decimals
>
3
)
{
showMillisec
=
true
;
showMicrosec
=
true
;
timeFormat
=
'HH:mm:ss.lc'
;
}
else
{
showMillisec
=
true
;
timeFormat
=
'HH:mm:ss.l'
;
}
}
if
(
type
===
'time'
)
{
hourMax
=
99
;
}
Functions
.
addDatepicker
(
$
(
this
)
,
type
,
{
showMillisec
:
showMillisec
,
showMicrosec
:
showMicrosec
,
timeFormat
:
timeFormat
,
hourMax
:
hourMax
,
firstDay
:
firstDayOfCalendar
}
)
;
// Add a tip regarding entering MySQL allowed-values
// for TIME and DATE data-type
if
(
$
(
this
)
.
hasClass
(
'timefield'
)
)
{
Functions
.
tooltip
(
$
(
this
)
,
'input'
,
Messages
.
strMysqlAllowedValuesTipTime
)
;
}
else
if
(
$
(
this
)
.
hasClass
(
'datefield'
)
)
{
Functions
.
tooltip
(
$
(
this
)
,
'input'
,
Messages
.
strMysqlAllowedValuesTipDate
)
;
}
}
)
;
}
}
;
/**
* Handle redirect and reload flags sent as part of AJAX requests
*
*
@param
data ajax response data
*/
Functions
.
handleRedirectAndReload
=
function
(
data
)
{
if
(
parseInt
(
data
.
redirect_flag
)
===
1
)
{
// add one more GET param to display session expiry msg
if
(
window
.
location
.
href
.
indexOf
(
'?'
)
===
-
1
)
{
window
.
location
.
href
+=
'?session_expired=1'
;
}
else
{
window
.
location
.
href
+=
CommonParams
.
get
(
'arg_separator'
)
+
'session_expired=1'
;
}
window
.
location
.
reload
(
)
;
}
else
if
(
parseInt
(
data
.
reload_flag
)
===
1
)
{
window
.
location
.
reload
(
)
;
}
}
;
/**
* Creates an SQL editor which supports auto completing etc.
*
*
@param
$textarea jQuery object wrapping the textarea to be made the editor
*
@param
options optional options for CodeMirror
*
@param
resize optional resizing ('vertical', 'horizontal', 'both')
*
@param
lintOptions additional options for lint
*/
Functions
.
getSqlEditor
=
function
(
$textarea
,
options
,
resize
,
lintOptions
)
{
var
resizeType
=
resize
;
if
(
$textarea
.
length
>
0
&&
typeof
CodeMirror
!==
'undefined'
)
{
// merge options for CodeMirror
var
defaults
=
{
lineNumbers
:
true
,
matchBrackets
:
true
,
extraKeys
:
{
'Ctrl-Space'
:
'autocomplete'
}
,
hintOptions
:
{
'completeSingle'
:
false
,
'completeOnSingleClick'
:
true
}
,
indentUnit
:
4
,
mode
:
'text/x-mysql'
,
lineWrapping
:
true
}
;
if
(
CodeMirror
.
sqlLint
)
{
$
.
extend
(
defaults
,
{
gutters
:
[
'CodeMirror-lint-markers'
]
,
lint
:
{
'getAnnotations'
:
CodeMirror
.
sqlLint
,
'async'
:
true
,
'lintOptions'
:
lintOptions
}
}
)
;
}
$
.
extend
(
true
,
defaults
,
options
)
;
// create CodeMirror editor
var
codemirrorEditor
=
CodeMirror
.
fromTextArea
(
$textarea
[
0
]
,
defaults
)
;
// allow resizing
if
(
!
resizeType
)
{
resizeType
=
'vertical'
;
}
var
handles
=
''
;
if
(
resizeType
===
'vertical'
)
{
handles
=
's'
;
}
if
(
resizeType
===
'both'
)
{
handles
=
'all'
;
}
if
(
resizeType
===
'horizontal'
)
{
handles
=
'e, w'
;
}
$
(
codemirrorEditor
.
getWrapperElement
(
)
)
.
css
(
'resize'
,
resizeType
)
.
resizable
(
{
handles
:
handles
,
resize
:
function
(
)
{
codemirrorEditor
.
setSize
(
$
(
this
)
.
width
(
)
,
$
(
this
)
.
height
(
)
)
;
}
}
)
;
// enable autocomplete
codemirrorEditor
.
on
(
'inputRead'
,
Functions
.
codeMirrorAutoCompleteOnInputRead
)
;
// page locking
codemirrorEditor
.
on
(
'change'
,
function
(
e
)
{
e
.
data
=
{
value
:
3
,
content
:
codemirrorEditor
.
isClean
(
)
,
}
;
AJAX
.
lockPageHandler
(
e
)
;
}
)
;
return
codemirrorEditor
;
}
return
null
;
}
;
/**
* Clear text selection
*/
Functions
.
clearSelection
=
function
(
)
{
if
(
document
.
selection
&&
document
.
selection
.
empty
)
{
document
.
selection
.
empty
(
)
;
}
else
if
(
window
.
getSelection
)
{
var
sel
=
window
.
getSelection
(
)
;
if
(
sel
.
empty
)
{
sel
.
empty
(
)
;
}
if
(
sel
.
removeAllRanges
)
{
sel
.
removeAllRanges
(
)
;
}
}
}
;
/**
* Create a jQuery UI tooltip
*
*
@param
$elements jQuery object representing the elements
*
@param
item the item
* (see https://api.jqueryui.com/tooltip/#option-items)
*
@param
myContent content of the tooltip
*
@param
additionalOptions to override the default options
*
*/
Functions
.
tooltip
=
function
(
$elements
,
item
,
myContent
,
additionalOptions
)
{
if
(
$
(
'#no_hint'
)
.
length
>
0
)
{
return
;
}
var
defaultOptions
=
{
content
:
myContent
,
items
:
item
,
tooltipClass
:
'tooltip'
,
track
:
true
,
show
:
false
,
hide
:
false
}
;
$elements
.
tooltip
(
$
.
extend
(
true
,
defaultOptions
,
additionalOptions
)
)
;
}
;
/**
* HTML escaping
*/
Functions
.
escapeHtml
=
function
(
unsafe
)
{
if
(
typeof
(
unsafe
)
!==
'undefined'
)
{
return
unsafe
.
toString
(
)
.
replace
(
/
&
/
g
,
'&'
)
.
replace
(
/
<
/
g
,
'<'
)
.
replace
(
/
>
/
g
,
'>'
)
.
replace
(
/
"
/
g
,
'"'
)
.
replace
(
/
'
/
g
,
'''
)
;
}
else
{
return
false
;
}
}
;
Functions
.
escapeJsString
=
function
(
unsafe
)
{
if
(
typeof
(
unsafe
)
!==
'undefined'
)
{
return
unsafe
.
toString
(
)
.
replace
(
'\x00'
,
''
)
.
replace
(
'\\'
,
'\\\\'
)
.
replace
(
'\''
,
'\\\''
)
.
replace
(
'''
,
'\\''
)
.
replace
(
'"'
,
'\\"'
)
.
replace
(
'"'
,
'\\"'
)
.
replace
(
'\n'
,
'\n'
)
.
replace
(
'\r'
,
'\r'
)
.
replace
(
/
<
\/
s
c
r
i
p
t
/
gi
,
'</\' + \'script'
)
;
}
else
{
return
false
;
}
}
;
Functions
.
escapeBacktick
=
function
(
s
)
{
return
s
.
replace
(
'`'
,
'``'
)
;
}
;
Functions
.
escapeSingleQuote
=
function
(
s
)
{
return
s
.
replace
(
'\\'
,
'\\\\'
)
.
replace
(
'\''
,
'\\\''
)
;
}
;
Functions
.
sprintf
=
function
(
)
{
return
sprintf
.
apply
(
this
,
arguments
)
;
}
;
/**
* Hides/shows the default value input field, depending on the default type
* Ticks the NULL checkbox if NULL is chosen as default value.
*/
Functions
.
hideShowDefaultValue
=
function
(
$defaultType
)
{
if
(
$defaultType
.
val
(
)
===
'USER_DEFINED'
)
{
$defaultType
.
siblings
(
'.default_value'
)
.
show
(
)
.
trigger
(
'focus'
)
;
}
else
{
$defaultType
.
siblings
(
'.default_value'
)
.
hide
(
)
;
if
(
$defaultType
.
val
(
)
===
'NULL'
)
{
var
$nullCheckbox
=
$defaultType
.
closest
(
'tr'
)
.
find
(
'.allow_null'
)
;
$nullCheckbox
.
prop
(
'checked'
,
true
)
;
}
}
}
;
/**
* Hides/shows the input field for column expression based on whether
* VIRTUAL/PERSISTENT is selected
*
*
@param
$virtuality virtuality dropdown
*/
Functions
.
hideShowExpression
=
function
(
$virtuality
)
{
if
(
$virtuality
.
val
(
)
===
''
)
{
$virtuality
.
siblings
(
'.expression'
)
.
hide
(
)
;
}
else
{
$virtuality
.
siblings
(
'.expression'
)
.
show
(
)
;
}
}
;
/**
* Show notices for ENUM columns; add/hide the default value
*
*/
Functions
.
verifyColumnsProperties
=
function
(
)
{
$
(
'select.column_type'
)
.
each
(
function
(
)
{
Functions
.
showNoticeForEnum
(
$
(
this
)
)
;
}
)
;
$
(
'select.default_type'
)
.
each
(
function
(
)
{
Functions
.
hideShowDefaultValue
(
$
(
this
)
)
;
}
)
;
$
(
'select.virtuality'
)
.
each
(
function
(
)
{
Functions
.
hideShowExpression
(
$
(
this
)
)
;
}
)
;
}
;
/**
* Add a hidden field to the form to indicate that this will be an
* Ajax request (only if this hidden field does not exist)
*
*
@param
$form object the form
*/
Functions
.
prepareForAjaxRequest
=
function
(
$form
)
{
if
(
!
$form
.
find
(
'input:hidden'
)
.
is
(
'#ajax_request_hidden'
)
)
{
$form
.
append
(
'<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true">'
)
;
}
}
;
Functions
.
checkPasswordStrength
=
function
(
value
,
meterObject
,
meterObjectLabel
,
username
)
{
// List of words we don't want to appear in the password
var
customDict
=
[
'phpmyadmin'
,
'mariadb'
,
'mysql'
,
'php'
,
'my'
,
'admin'
,
]
;
if
(
username
!==
null
)
{
customDict
.
push
(
username
)
;
}
var
zxcvbnObject
=
zxcvbn
(
value
,
customDict
)
;
var
strength
=
zxcvbnObject
.
score
;
strength
=
parseInt
(
strength
)
;
meterObject
.
val
(
strength
)
;
switch
(
strength
)
{
case
0
:
meterObjectLabel
.
html
(
Messages
.
strExtrWeak
)
;
break
;
case
1
:
meterObjectLabel
.
html
(
Messages
.
strVeryWeak
)
;
break
;
case
2
:
meterObjectLabel
.
html
(
Messages
.
strWeak
)
;
break
;
case
3
:
meterObjectLabel
.
html
(
Messages
.
strGood
)
;
break
;
case
4
:
meterObjectLabel
.
html
(
Messages
.
strStrong
)
;
}
}
;
/**
* Generate a new password and copy it to the password input areas
*
*
@param
{
object
} passwordForm the form that holds the password fields
*
*
@return
{
boolean
} always true
*/
Functions
.
suggestPassword
=
function
(
passwordForm
)
{
// restrict the password to just letters and numbers to avoid problems:
// "editors and viewers regard the password as multiple words and
// things like double click no longer work"
var
pwchars
=
'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWYXZ@!_.*/()[]-'
;
var
passwordlength
=
16
;
// do we want that to be dynamic? no, keep it simple :)
var
passwd
=
passwordForm
.
generated_pw
;
// eslint-disable-next-line compat/compat
var
randomWords
=
new
Int32Array
(
passwordlength
)
;
passwd
.
value
=
''
;
var
i
;
// First we're going to try to use a built-in CSPRNG
// eslint-disable-next-line compat/compat
if
(
window
.
crypto
&&
window
.
crypto
.
getRandomValues
)
{
// eslint-disable-next-line compat/compat
window
.
crypto
.
getRandomValues
(
randomWords
)
;
}
else
if
(
window
.
msCrypto
&&
window
.
msCrypto
.
getRandomValues
)
{
// Because of course IE calls it msCrypto instead of being standard
window
.
msCrypto
.
getRandomValues
(
randomWords
)
;
}
else
{
// Fallback to Math.random
for
(
i
=
0
;
i
<
passwordlength
;
i
++
)
{
randomWords
[
i
]
=
Math
.
floor
(
Math
.
random
(
)
*
pwchars
.
length
)
;
}
}
for
(
i
=
0
;
i
<
passwordlength
;
i
++
)
{
passwd
.
value
+=
pwchars
.
charAt
(
Math
.
abs
(
randomWords
[
i
]
)
%
pwchars
.
length
)
;
}
var
$jQueryPasswordForm
=
$
(
passwordForm
)
;
passwordForm
.
elements
.
pma_pw
.
value
=
passwd
.
value
;
passwordForm
.
elements
.
pma_pw2
.
value
=
passwd
.
value
;
var
meterObj
=
$jQueryPasswordForm
.
find
(
'meter[name="pw_meter"]'
)
.
first
(
)
;
var
meterObjLabel
=
$jQueryPasswordForm
.
find
(
'span[name="pw_strength"]'
)
.
first
(
)
;
Functions
.
checkPasswordStrength
(
passwd
.
value
,
meterObj
,
meterObjLabel
)
;
return
true
;
}
;
/**
* Version string to integer conversion.
*/
Functions
.
parseVersionString
=
function
(
str
)
{
if
(
typeof
(
str
)
!==
'string'
)
{
return
false
;
}
var
add
=
0
;
// Parse possible alpha/beta/rc/
var
state
=
str
.
split
(
'-'
)
;
if
(
state
.
length
>=
2
)
{
if
(
state
[
1
]
.
substr
(
0
,
2
)
===
'rc'
)
{
add
=
-
20
-
parseInt
(
state
[
1
]
.
substr
(
2
)
,
10
)
;
}
else
if
(
state
[
1
]
.
substr
(
0
,
4
)
===
'beta'
)
{
add
=
-
40
-
parseInt
(
state
[
1
]
.
substr
(
4
)
,
10
)
;
}
else
if
(
state
[
1
]
.
substr
(
0
,
5
)
===
'alpha'
)
{
add
=
-
60
-
parseInt
(
state
[
1
]
.
substr
(
5
)
,
10
)
;
}
else
if
(
state
[
1
]
.
substr
(
0
,
3
)
===
'dev'
)
{
/* We don't handle dev, it's git snapshot */
add
=
0
;
}
}
// Parse version
var
x
=
str
.
split
(
'.'
)
;
// Use 0 for non existing parts
var
maj
=
parseInt
(
x
[
0
]
,
10
)
||
0
;
var
min
=
parseInt
(
x
[
1
]
,
10
)
||
0
;
var
pat
=
parseInt
(
x
[
2
]
,
10
)
||
0
;
var
hotfix
=
parseInt
(
x
[
3
]
,
10
)
||
0
;
return
maj
*
100000000
+
min
*
1000000
+
pat
*
10000
+
hotfix
*
100
+
add
;
}
;
/**
* Indicates current available version on main page.
*/
Functions
.
currentVersion
=
function
(
data
)
{
if
(
data
&&
data
.
version
&&
data
.
date
)
{
var
current
=
Functions
.
parseVersionString
(
$
(
'span.version'
)
.
text
(
)
)
;
var
latest
=
Functions
.
parseVersionString
(
data
.
version
)
;
var
url
=
'https://www.phpmyadmin.net/files/'
+
Functions
.
escapeHtml
(
encodeURIComponent
(
data
.
version
)
)
+
'/'
;
var
versionInformationMessage
=
document
.
createElement
(
'span'
)
;
versionInformationMessage
.
className
=
'latest'
;
var
versionInformationMessageLink
=
document
.
createElement
(
'a'
)
;
versionInformationMessageLink
.
href
=
url
;
versionInformationMessageLink
.
className
=
'disableAjax'
;
var
versionInformationMessageLinkText
=
document
.
createTextNode
(
data
.
version
)
;
versionInformationMessageLink
.
appendChild
(
versionInformationMessageLinkText
)
;
var
prefixMessage
=
document
.
createTextNode
(
Messages
.
strLatestAvailable
+
' '
)
;
versionInformationMessage
.
appendChild
(
prefixMessage
)
;
versionInformationMessage
.
appendChild
(
versionInformationMessageLink
)
;
if
(
latest
>
current
)
{
var
message
=
Functions
.
sprintf
(
Messages
.
strNewerVersion
,
Functions
.
escapeHtml
(
data
.
version
)
,
Functions
.
escapeHtml
(
data
.
date
)
)
;
var
htmlClass
=
'alert alert-primary'
;
if
(
Math
.
floor
(
latest
/
10000
)
===
Math
.
floor
(
current
/
10000
)
)
{
/* Security update */
htmlClass
=
'alert alert-danger'
;
}
$
(
'#newer_version_notice'
)
.
remove
(
)
;
var
mainContainerDiv
=
document
.
createElement
(
'div'
)
;
mainContainerDiv
.
id
=
'newer_version_notice'
;
mainContainerDiv
.
className
=
htmlClass
;
var
mainContainerDivLink
=
document
.
createElement
(
'a'
)
;
mainContainerDivLink
.
href
=
url
;
mainContainerDivLink
.
className
=
'disableAjax'
;
var
mainContainerDivLinkText
=
document
.
createTextNode
(
message
)
;
mainContainerDivLink
.
appendChild
(
mainContainerDivLinkText
)
;
mainContainerDiv
.
appendChild
(
mainContainerDivLink
)
;
$
(
'#maincontainer'
)
.
append
(
$
(
mainContainerDiv
)
)
;
}
if
(
latest
===
current
)
{
versionInformationMessage
=
document
.
createTextNode
(
' ('
+
Messages
.
strUpToDate
+
')'
)
;
}
/* Remove extra whitespace */
var
versionInfo
=
$
(
'#li_pma_version'
)
.
contents
(
)
.
get
(
2
)
;
if
(
typeof
versionInfo
!==
'undefined'
)
{
versionInfo
.
textContent
=
versionInfo
.
textContent
.
trim
(
)
;
}
var
$liPmaVersion
=
$
(
'#li_pma_version'
)
;
$liPmaVersion
.
find
(
'span.latest'
)
.
remove
(
)
;
$liPmaVersion
.
append
(
$
(
versionInformationMessage
)
)
;
}
}
;
/**
* Loads Git revision data from ajax for index.php
*/
Functions
.
displayGitRevision
=
function
(
)
{
$
(
'#is_git_revision'
)
.
remove
(
)
;
$
(
'#li_pma_version_git'
)
.
remove
(
)
;
$
.
get
(
'index.php?route=/git-revision'
,
{
'server'
:
CommonParams
.
get
(
'server'
)
,
'ajax_request'
:
true
,
'no_debug'
:
true
}
,
function
(
data
)
{
if
(
typeof
data
!==
'undefined'
&&
data
.
success
===
true
)
{
$
(
data
.
message
)
.
insertAfter
(
'#li_pma_version'
)
;
}
}
)
;
}
;
/**
* for PhpMyAdmin\Display\ChangePassword and /user-password
*/
Functions
.
displayPasswordGenerateButton
=
function
(
)
{
var
generatePwdRow
=
$
(
'<tr></tr>'
)
.
addClass
(
'vmiddle'
)
;
$
(
'<td></td>'
)
.
html
(
Messages
.
strGeneratePassword
)
.
appendTo
(
generatePwdRow
)
;
var
pwdCell
=
$
(
'<td></td>'
)
.
appendTo
(
generatePwdRow
)
;
var
pwdButton
=
$
(
'<input>'
)
.
attr
(
{
type
:
'button'
,
id
:
'button_generate_password'
,
value
:
Messages
.
strGenerate
}
)
.
addClass
(
'btn btn-secondary button'
)
.
on
(
'click'
,
function
(
)
{
Functions
.
suggestPassword
(
this
.
form
)
;
}
)
;
var
pwdTextbox
=
$
(
'<input>'
)
.
attr
(
{
type
:
'text'
,
name
:
'generated_pw'
,
id
:
'generated_pw'
}
)
;
pwdCell
.
append
(
pwdButton
)
.
append
(
pwdTextbox
)
;
if
(
document
.
getElementById
(
'button_generate_password'
)
===
null
)
{
$
(
'#tr_element_before_generate_password'
)
.
parent
(
)
.
append
(
generatePwdRow
)
;
}
var
generatePwdDiv
=
$
(
'<div></div>'
)
.
addClass
(
'item'
)
;
$
(
'<label></label>'
)
.
attr
(
{
for
:
'button_generate_password'
}
)
.
html
(
Messages
.
strGeneratePassword
+
':'
)
.
appendTo
(
generatePwdDiv
)
;
var
optionsSpan
=
$
(
'<span></span>'
)
.
addClass
(
'options'
)
.
appendTo
(
generatePwdDiv
)
;
pwdButton
.
clone
(
true
)
.
appendTo
(
optionsSpan
)
;
pwdTextbox
.
clone
(
true
)
.
appendTo
(
generatePwdDiv
)
;
if
(
document
.
getElementById
(
'button_generate_password'
)
===
null
)
{
$
(
'#div_element_before_generate_password'
)
.
parent
(
)
.
append
(
generatePwdDiv
)
;
}
}
;
/**
* selects the content of a given object, f.e. a textarea
*
*
@param
{
object
} element element of which the content will be selected
*
@param
{
var
} lock variable which holds the lock for this element or true, if no lock exists
*
@param
{
boolean
} onlyOnce boolean if true this is only done once f.e. only on first focus
*/
Functions
.
selectContent
=
function
(
element
,
lock
,
onlyOnce
)
{
if
(
onlyOnce
&&
onlyOnceElements
[
element
.
name
]
)
{
return
;
}
onlyOnceElements
[
element
.
name
]
=
true
;
if
(
lock
)
{
return
;
}
element
.
select
(
)
;
}
;
/**
* Displays a confirmation box before submitting a "DROP/DELETE/ALTER" query.
* This function is called while clicking links
*
*
@param
theLink object the link
*
@param
theSqlQuery object the sql query to submit
*
*
@return
boolean whether to run the query or not
*/
Functions
.
confirmLink
=
function
(
theLink
,
theSqlQuery
)
{
// Confirmation is not required in the configuration file
// or browser is Opera (crappy js implementation)
if
(
Messages
.
strDoYouReally
===
''
||
typeof
(
window
.
opera
)
!==
'undefined'
)
{
return
true
;
}
var
isConfirmed
=
confirm
(
Functions
.
sprintf
(
Messages
.
strDoYouReally
,
theSqlQuery
)
)
;
if
(
isConfirmed
)
{
if
(
typeof
(
theLink
.
href
)
!==
'undefined'
)
{
theLink
.
href
+=
CommonParams
.
get
(
'arg_separator'
)
+
'is_js_confirmed=1'
;
}
else
if
(
typeof
(
theLink
.
form
)
!==
'undefined'
)
{
theLink
.
form
.
action
+=
'?is_js_confirmed=1'
;
}
}
return
isConfirmed
;
}
;
/**
* Confirms a "DROP/DELETE/ALTER" query before
* submitting it if required.
* This function is called by the 'Functions.checkSqlQuery()' js function.
*
*
@param
theForm1 object the form
*
@param
sqlQuery1 string the sql query string
*
*
@return
boolean whether to run the query or not
*
*
@see
Functions.checkSqlQuery()
*/
Functions
.
confirmQuery
=
function
(
theForm1
,
sqlQuery1
)
{
// Confirmation is not required in the configuration file
if
(
Messages
.
strDoYouReally
===
''
)
{
return
true
;
}
// Confirms a "DROP/DELETE/ALTER/TRUNCATE" statement
//
// TODO: find a way (if possible) to use the parser-analyser
// for this kind of verification
// For now, I just added a ^ to check for the statement at
// beginning of expression
var
doConfirmRegExp0
=
new
RegExp
(
'^\\s*DROP\\s+(IF EXISTS\\s+)?(TABLE|PROCEDURE)\\s'
,
'i'
)
;
var
doConfirmRegExp1
=
new
RegExp
(
'^\\s*ALTER\\s+TABLE\\s+((`[^`]+`)|([A-Za-z0-9_$]+))\\s+DROP\\s'
,
'i'
)
;
var
doConfirmRegExp2
=
new
RegExp
(
'^\\s*DELETE\\s+FROM\\s'
,
'i'
)
;
var
doConfirmRegExp3
=
new
RegExp
(
'^\\s*TRUNCATE\\s'
,
'i'
)
;
var
doConfirmRegExp4
=
new
RegExp
(
'^(?=.*UPDATE\\b)^((?!WHERE).)*$'
,
'i'
)
;
if
(
doConfirmRegExp0
.
test
(
sqlQuery1
)
||
doConfirmRegExp1
.
test
(
sqlQuery1
)
||
doConfirmRegExp2
.
test
(
sqlQuery1
)
||
doConfirmRegExp3
.
test
(
sqlQuery1
)
||
doConfirmRegExp4
.
test
(
sqlQuery1
)
)
{
var
message
;
if
(
sqlQuery1
.
length
>
100
)
{
message
=
sqlQuery1
.
substr
(
0
,
100
)
+
'\n ...'
;
}
else
{
message
=
sqlQuery1
;
}
var
isConfirmed
=
confirm
(
Functions
.
sprintf
(
Messages
.
strDoYouReally
,
message
)
)
;
// statement is confirmed -> update the
// "is_js_confirmed" form field so the confirm test won't be
// run on the server side and allows to submit the form
if
(
isConfirmed
)
{
theForm1
.
elements
.
is_js_confirmed
.
value
=
1
;
return
true
;
}
else
{
// statement is rejected -> do not submit the form
window
.
focus
(
)
;
return
false
;
}
// end if (handle confirm box result)
}
// end if (display confirm box)
return
true
;
}
;
/**
* Displays an error message if the user submitted the sql query form with no
* sql query, else checks for "DROP/DELETE/ALTER" statements
*
*
@param
theForm object the form
*
*
@return
boolean always false
*
*
@see
Functions.confirmQuery()
*/
Functions
.
checkSqlQuery
=
function
(
theForm
)
{
// get the textarea element containing the query
var
sqlQuery
;
if
(
codeMirrorEditor
)
{
codeMirrorEditor
.
save
(
)
;
sqlQuery
=
codeMirrorEditor
.
getValue
(
)
;
}
else
{
sqlQuery
=
theForm
.
elements
.
sql_query
.
value
;
}
var
spaceRegExp
=
new
RegExp
(
'\\s+'
)
;
if
(
typeof
(
theForm
.
elements
.
sql_file
)
!==
'undefined'
&&
theForm
.
elements
.
sql_file
.
value
.
replace
(
spaceRegExp
,
''
)
!==
''
)
{
return
true
;
}
if
(
typeof
(
theForm
.
elements
.
id_bookmark
)
!==
'undefined'
&&
(
theForm
.
elements
.
id_bookmark
.
value
!==
null
||
theForm
.
elements
.
id_bookmark
.
value
!==
''
)
&&
theForm
.
elements
.
id_bookmark
.
selectedIndex
!==
0
)
{
return
true
;
}
var
result
=
false
;
// Checks for "DROP/DELETE/ALTER" statements
if
(
sqlQuery
.
replace
(
spaceRegExp
,
''
)
!==
''
)
{
result
=
Functions
.
confirmQuery
(
theForm
,
sqlQuery
)
;
}
else
{
alert
(
Messages
.
strFormEmpty
)
;
}
if
(
codeMirrorEditor
)
{
codeMirrorEditor
.
focus
(
)
;
}
else
if
(
codeMirrorInlineEditor
)
{
codeMirrorInlineEditor
.
focus
(
)
;
}
return
result
;
}
;
/**
* Check if a form's element is empty.
* An element containing only spaces is also considered empty
*
*
@param
{
object
} theForm the form
*
@param
{
string
} theFieldName the name of the form field to put the focus on
*
*
@return
{
boolean
} whether the form field is empty or not
*/
Functions
.
emptyCheckTheField
=
function
(
theForm
,
theFieldName
)
{
var
theField
=
theForm
.
elements
[
theFieldName
]
;
var
spaceRegExp
=
new
RegExp
(
'\\s+'
)
;
return
theField
.
value
.
replace
(
spaceRegExp
,
''
)
===
''
;
}
;
/**
* Ensures a value submitted in a form is numeric and is in a range
*
*
@param
object the form
*
@param
string the name of the form field to check
*
@param
integer the minimum authorized value
*
@param
integer the maximum authorized value
*
*
@return
boolean whether a valid number has been submitted or not
*/
Functions
.
checkFormElementInRange
=
function
(
theForm
,
theFieldName
,
message
,
minimum
,
maximum
)
{
var
theField
=
theForm
.
elements
[
theFieldName
]
;
var
val
=
parseInt
(
theField
.
value
,
10
)
;
var
min
=
0
;
var
max
=
Number
.
MAX_VALUE
;
if
(
typeof
(
minimum
)
!==
'undefined'
)
{
min
=
minimum
;
}
if
(
typeof
(
maximum
)
!==
'undefined'
&&
maximum
!==
null
)
{
max
=
maximum
;
}
if
(
isNaN
(
val
)
)
{
theField
.
select
(
)
;
alert
(
Messages
.
strEnterValidNumber
)
;
theField
.
focus
(
)
;
return
false
;
}
else
if
(
val
<
min
||
val
>
max
)
{
theField
.
select
(
)
;
alert
(
Functions
.
sprintf
(
message
,
val
)
)
;
theField
.
focus
(
)
;
return
false
;
}
else
{
theField
.
value
=
val
;
}
return
true
;
}
;
Functions
.
checkTableEditForm
=
function
(
theForm
,
fieldsCnt
)
{
// TODO: avoid sending a message if user just wants to add a line
// on the form but has not completed at least one field name
var
atLeastOneField
=
0
;
var
i
;
var
elm
;
var
elm2
;
var
elm3
;
var
val
;
var
id
;
for
(
i
=
0
;
i
<
fieldsCnt
;
i
++
)
{
id
=
'#field_'
+
i
+
'_2'
;
elm
=
$
(
id
)
;
val
=
elm
.
val
(
)
;
if
(
val
===
'VARCHAR'
||
val
===
'CHAR'
||
val
===
'BIT'
||
val
===
'VARBINARY'
||
val
===
'BINARY'
)
{
elm2
=
$
(
'#field_'
+
i
+
'_3'
)
;
val
=
parseInt
(
elm2
.
val
(
)
,
10
)
;
elm3
=
$
(
'#field_'
+
i
+
'_1'
)
;
if
(
isNaN
(
val
)
&&
elm3
.
val
(
)
!==
''
)
{
elm2
.
select
(
)
;
alert
(
Messages
.
strEnterValidLength
)
;
elm2
.
focus
(
)
;
return
false
;
}
}
if
(
atLeastOneField
===
0
)
{
id
=
'field_'
+
i
+
'_1'
;
if
(
!
Functions
.
emptyCheckTheField
(
theForm
,
id
)
)
{
atLeastOneField
=
1
;
}
}
}
if
(
atLeastOneField
===
0
)
{
var
theField
=
theForm
.
elements
.
field_0_1
;
alert
(
Messages
.
strFormEmpty
)
;
theField
.
focus
(
)
;
return
false
;
}
// at least this section is under jQuery
var
$input
=
$
(
'input.textfield[name=\'table\']'
)
;
if
(
$input
.
val
(
)
===
''
)
{
alert
(
Messages
.
strFormEmpty
)
;
$input
.
trigger
(
'focus'
)
;
return
false
;
}
return
true
;
}
;
/**
* True if last click is to check a row.
*/
var
lastClickChecked
=
false
;
/**
* Zero-based index of last clicked row.
* Used to handle the shift + click event in the code above.
*/
var
lastClickedRow
=
-
1
;
/**
* Zero-based index of last shift clicked row.
*/
var
lastShiftClickedRow
=
-
1
;
var
idleSecondsCounter
=
0
;
var
incInterval
;
var
updateTimeout
;
AJAX
.
registerTeardown
(
'functions.js'
,
function
(
)
{
clearTimeout
(
updateTimeout
)
;
clearInterval
(
incInterval
)
;
$
(
document
)
.
off
(
'mousemove'
)
;
}
)
;
AJAX
.
registerOnload
(
'functions.js'
,
function
(
)
{
document
.
onclick
=
function
(
)
{
idleSecondsCounter
=
0
;
}
;
$
(
document
)
.
on
(
'mousemove'
,
function
(
)
{
idleSecondsCounter
=
0
;
}
)
;
document
.
onkeypress
=
function
(
)
{
View remainder of file in raw view
Footer
© 2026 GitHub, Inc.
Footer navigation
Terms
Privacy
Security
Status
Community
Docs
Contact
You can’t perform that action at this time.
Back
|
FazBrowse Home
|
New Git URL