Menu

[r15]: / includes / phpmyadmin / functions.js  Maximize  Restore  History

Download this file

350 lines (312 with data), 11.2 kB

  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
/* $Id: functions.js,v 1.1 2003/07/02 14:47:06 fullo Exp $ */
/**
* Displays an confirmation box beforme to submit a "DROP/DELETE/ALTER" query.
* This function is called while clicking links
*
* @param object the link
* @param object the sql query to submit
*
* @return boolean whether to run the query or not
*/
function confirmLink(theLink, theSqlQuery)
{
// Confirmation is not required in the configuration file
if (confirmMsg == '') {
return true;
}
var is_confirmed = confirm(confirmMsg + ' :\n' + theSqlQuery);
if (is_confirmed) {
theLink.href += '&is_js_confirmed=1';
}
return is_confirmed;
} // end of the 'confirmLink()' function
/**
* Displays an error message if a "DROP DATABASE" statement is submitted
* while it isn't allowed, else confirms a "DROP/DELETE/ALTER" query before
* sumitting it if required.
* This function is called by the 'checkSqlQuery()' js function.
*
* @param object the form
* @param object the sql query textarea
*
* @return boolean whether to run the query or not
*
* @see checkSqlQuery()
*/
function confirmQuery(theForm1, sqlQuery1)
{
// Confirmation is not required in the configuration file
if (confirmMsg == '') {
return true;
}
// The replace function (js1.2) isn't supported
else if (typeof(sqlQuery1.value.replace) == 'undefined') {
return true;
}
// js1.2+ -> validation with regular expressions
else {
// "DROP DATABASE" statement isn't allowed
if (noDropDbMsg) {
var drop_re = new RegExp('DROP\\s+(IF EXISTS\\s+)?DATABASE', 'i');
if (drop_re.test(sqlQuery1.value)) {
alert(noDropDbMsg);
theForm1.reset();
sqlQuery1.focus();
return false;
} // end if
} // end if
// Confirms a "DROP/DELETE/ALTER" statement
var do_confirm_re_0 = new RegExp('DROP\\s+(IF EXISTS\\s+)?(TABLE|DATABASE)', 'i');
var do_confirm_re_1 = new RegExp('ALTER TABLE\\s+((`[^`]+`)|([A-Za-z0-9_$]+))\\s+DROP', 'i');
var do_confirm_re_2 = new RegExp('DELETE FROM', 'i');
if (do_confirm_re_0.test(sqlQuery1.value)
|| do_confirm_re_1.test(sqlQuery1.value)
|| do_confirm_re_2.test(sqlQuery1.value)) {
var message = (sqlQuery1.value.length > 100)
? sqlQuery1.value.substr(0, 100) + '\n ...'
: sqlQuery1.value;
var is_confirmed = confirm(confirmMsg + ' :\n' + message);
// drop/delete/alter 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 (is_confirmed) {
theForm1.elements['is_js_confirmed'].value = 1;
return true;
}
// "DROP/DELETE/ALTER" statement is rejected -> do not submit
// the form
else {
window.focus();
sqlQuery1.focus();
return false;
} // end if (handle confirm box result)
} // end if (display confirm box)
} // end confirmation stuff
return true;
} // end of the 'confirmQuery()' function
/**
* Displays an error message if the user submitted the sql query form with no
* sql query, else checks for "DROP/DELETE/ALTER" statements
*
* @param object the form
*
* @return boolean always false
*
* @see confirmQuery()
*/
function checkSqlQuery(theForm)
{
var sqlQuery = theForm.elements['sql_query'];
// The replace function (js1.2) isn't supported -> basic tests
if (typeof(sqlQuery.value.replace) == 'undefined') {
var isEmpty = (sqlQuery.value == '') ? 1 : 0;
if (isEmpty && typeof(theForm.elements['sql_file']) != 'undefined') {
isEmpty = (theForm.elements['sql_file'].value == '') ? 1 : 0;
}
if (isEmpty && typeof(theForm.elements['id_bookmark']) != 'undefined') {
isEmpty = (theForm.elements['id_bookmark'].value == null || theForm.elements['id_bookmark'].value == '');
}
}
// js1.2+ -> validation with regular expressions
else {
var space_re = new RegExp('\\s+');
var isEmpty = (sqlQuery.value.replace(space_re, '') == '') ? 1 : 0;
// Checks for "DROP/DELETE/ALTER" statements
if (!isEmpty && !confirmQuery(theForm, sqlQuery)) {
return false;
}
if (isEmpty && typeof(theForm.elements['sql_file']) != 'undefined') {
isEmpty = (theForm.elements['sql_file'].value.replace(space_re, '') == '') ? 1 : 0;
}
if (isEmpty && typeof(theForm.elements['id_bookmark']) != 'undefined') {
isEmpty = (theForm.elements['id_bookmark'].value == null || theForm.elements['id_bookmark'].value == '');
isEmpty = (theForm.elements['id_bookmark'].selectedIndex == 0);
}
if (isEmpty) {
theForm.reset();
}
}
if (isEmpty) {
sqlQuery.select();
alert(errorMsg0);
sqlQuery.focus();
return false;
}
return true;
} // end of the 'checkSqlQuery()' function
/**
* Displays an error message if an element of a form hasn't been completed and
* should be
*
* @param object the form
* @param string the name of the form field to put the focus on
*
* @return boolean whether the form field is empty or not
*/
function emptyFormElements(theForm, theFieldName)
{
var theField = theForm.elements[theFieldName];
// Whether the replace function (js1.2) is supported or not
var isRegExp = (typeof(theField.value.replace) != 'undefined');
if (!isRegExp) {
var isEmpty = (theField.value == '') ? 1 : 0;
} else {
var space_re = new RegExp('\\s+');
var isEmpty = (theField.value.replace(space_re, '') == '') ? 1 : 0;
}
if (isEmpty) {
theForm.reset();
theField.select();
alert(errorMsg0);
theField.focus();
return false;
}
return true;
} // end of the 'emptyFormElements()' function
/**
* 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
*/
function checkFormElementInRange(theForm, theFieldName, min, max)
{
var theField = theForm.elements[theFieldName];
var val = parseInt(theField.value);
if (typeof(min) == 'undefined') {
min = 0;
}
if (typeof(max) == 'undefined') {
max = Number.MAX_VALUE;
}
// It's not a number
if (isNaN(val)) {
theField.select();
alert(errorMsg1);
theField.focus();
return false;
}
// It's a number but it is not between min and max
else if (val < min || val > max) {
theField.select();
alert(val + errorMsg2);
theField.focus();
return false;
}
// It's a valid number
else {
theField.value = val;
}
return true;
} // end of the 'checkFormElementInRange()' function
/**
* Ensures the choice between 'transmit', 'zipped', 'gzipped' and 'bzipped'
* checkboxes is consistant
*
* @param object the form
* @param string a code for the action that causes this function to be run
*
* @return boolean always true
*/
function checkTransmitDump(theForm, theAction)
{
var formElts = theForm.elements;
// 'zipped' option has been checked
if (theAction == 'zip' && formElts['zip'].checked) {
if (!formElts['asfile'].checked) {
theForm.elements['asfile'].checked = true;
}
if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) {
theForm.elements['gzip'].checked = false;
}
if (typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked) {
theForm.elements['bzip'].checked = false;
}
}
// 'gzipped' option has been checked
else if (theAction == 'gzip' && formElts['gzip'].checked) {
if (!formElts['asfile'].checked) {
theForm.elements['asfile'].checked = true;
}
if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
theForm.elements['zip'].checked = false;
}
if (typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked) {
theForm.elements['bzip'].checked = false;
}
}
// 'bzipped' option has been checked
else if (theAction == 'bzip' && formElts['bzip'].checked) {
if (!formElts['asfile'].checked) {
theForm.elements['asfile'].checked = true;
}
if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
theForm.elements['zip'].checked = false;
}
if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) {
theForm.elements['gzip'].checked = false;
}
}
// 'transmit' option has been unchecked
else if (theAction == 'transmit' && !formElts['asfile'].checked) {
if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
theForm.elements['zip'].checked = false;
}
if ((typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked)) {
theForm.elements['gzip'].checked = false;
}
if ((typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked)) {
theForm.elements['bzip'].checked = false;
}
}
return true;
} // end of the 'checkTransmitDump()' function
/**
* Sets/unsets the pointer in browse mode
*
* @param object the table row
* @param object the color to use for this row
*
* @return boolean whether pointer is set or not
*/
function setPointer(theRow, thePointerColor)
{
if (thePointerColor == '' || typeof(theRow.style) == 'undefined') {
return false;
}
if (typeof(document.getElementsByTagName) != 'undefined') {
var theCells = theRow.getElementsByTagName('td');
}
else if (typeof(theRow.cells) != 'undefined') {
var theCells = theRow.cells;
}
else {
return false;
}
var rowCellsCnt = theCells.length;
for (var c = 0; c < rowCellsCnt; c++) {
theCells[c].style.backgroundColor = thePointerColor;
}
return true;
} // end of the 'setPointer()' function
/**
* Checks/unchecks all tables
*
* @param string the form name
* @param boolean whether to check or to uncheck the element
*
* @return boolean always true
*/
function setCheckboxes(the_form, do_check)
{
var elts = document.forms[the_form].elements['selected_tbl[]'];
var elts_cnt = elts.length;
for (var i = 0; i < elts_cnt; i++) {
elts[i].checked = do_check;
} // end for
return true;
} // end of the 'setCheckboxes()' function
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.