bug #2491017 [operations] ANSI mode not supported (db rename and table move)
[phpmyadmin/crack.git] / js / tbl_change.js
blobcc6338999b26c49c4190f9086cf26707f438b76d
1 /* vim: set expandtab sw=4 ts=4 sts=4: */
2 /**
3 * function used in table data manipulation pages
5 * @version $Id$
6 */
8 /**
9 * Modify from controls when the "NULL" checkbox is selected
11 * @param string the MySQL field type
12 * @param string the urlencoded field name
13 * @param string the md5 hashed field name
15 * @return boolean always true
17 function nullify(theType, urlField, md5Field, multi_edit)
19 var rowForm = document.forms['insertForm'];
21 if (typeof(rowForm.elements['funcs' + multi_edit + '[' + urlField + ']']) != 'undefined') {
22 rowForm.elements['funcs' + multi_edit + '[' + urlField + ']'].selectedIndex = -1;
25 // "SET" field , "ENUM" field with more than 20 characters
26 // or foreign key field (drop-down)
27 if (theType == 1 || theType == 3 || theType == 4) {
28 rowForm.elements['field_' + md5Field + multi_edit + '[]'].selectedIndex = -1;
30 // Other "ENUM" field
31 else if (theType == 2) {
32 var elts = rowForm.elements['field_' + md5Field + multi_edit + '[]'];
33 // when there is just one option in ENUM:
34 if (elts.checked) {
35 elts.checked = false;
36 } else {
37 var elts_cnt = elts.length;
38 for (var i = 0; i < elts_cnt; i++ ) {
39 elts[i].checked = false;
40 } // end for
42 } // end if
44 // foreign key field (with browsing icon for foreign values)
45 else if (theType == 6) {
46 rowForm.elements['field_' + md5Field + multi_edit + '[]'].value = '';
48 // Other field types
49 else /*if (theType == 5)*/ {
50 rowForm.elements['fields' + multi_edit + '[' + urlField + ']'].value = '';
51 } // end if... else if... else
53 return true;
54 } // end of the 'nullify()' function
57 /**
58 * Unchecks the "NULL" control when a function has been selected or a value
59 * entered
61 * @param string the urlencoded field name
63 * @return boolean always true
65 function unNullify(urlField, multi_edit)
67 var rowForm = document.forms['insertForm'];
69 if (typeof(rowForm.elements['fields_null[multi_edit][' + multi_edit + '][' + urlField + ']']) != 'undefined') {
70 rowForm.elements['fields_null[multi_edit][' + multi_edit + '][' + urlField + ']'].checked = false
71 } // end if
73 if (typeof(rowForm.elements['insert_ignore_' + multi_edit]) != 'undefined') {
74 rowForm.elements['insert_ignore_' + multi_edit].checked = false
75 } // end if
77 return true;
78 } // end of the 'unNullify()' function
80 var day;
81 var month;
82 var year;
83 var hour;
84 var minute;
85 var second;
86 var clock_set = 0;
88 /**
89 * Opens calendar window.
91 * @param string calendar.php parameters
92 * @param string form name
93 * @param string field name
94 * @param string edit type - date/timestamp
96 function openCalendar(params, form, field, type) {
97 window.open("./calendar.php?" + params, "calendar", "width=400,height=200,status=yes");
98 dateField = eval("document." + form + "." + field);
99 dateType = type;
103 * Formats number to two digits.
105 * @param int number to format.
106 * @param string type of number
108 function formatNum2(i, valtype) {
109 f = (i < 10 ? '0' : '') + i;
110 if (valtype && valtype != '') {
111 switch(valtype) {
112 case 'month':
113 f = (f > 12 ? 12 : f);
114 break;
116 case 'day':
117 f = (f > 31 ? 31 : f);
118 break;
120 case 'hour':
121 f = (f > 24 ? 24 : f);
122 break;
124 default:
125 case 'second':
126 case 'minute':
127 f = (f > 59 ? 59 : f);
128 break;
132 return f;
136 * Formats number to two digits.
138 * @param int number to format.
139 * @param int default value
140 * @param string type of number
142 function formatNum2d(i, default_v, valtype) {
143 i = parseInt(i, 10);
144 if (isNaN(i)) return default_v;
145 return formatNum2(i, valtype)
149 * Formats number to four digits.
151 * @param int number to format.
153 function formatNum4(i) {
154 i = parseInt(i, 10)
155 return (i < 1000 ? i < 100 ? i < 10 ? '000' : '00' : '0' : '') + i;
159 * Initializes calendar window.
161 function initCalendar() {
162 if (!year && !month && !day) {
163 /* Called for first time */
164 if (window.opener.dateField.value) {
165 value = window.opener.dateField.value;
166 if (window.opener.dateType == 'datetime' || window.opener.dateType == 'date') {
167 if (window.opener.dateType == 'datetime') {
168 parts = value.split(' ');
169 value = parts[0];
171 if (parts[1]) {
172 time = parts[1].split(':');
173 hour = parseInt(time[0],10);
174 minute = parseInt(time[1],10);
175 second = parseInt(time[2],10);
178 date = value.split("-");
179 day = parseInt(date[2],10);
180 month = parseInt(date[1],10) - 1;
181 year = parseInt(date[0],10);
182 } else {
183 year = parseInt(value.substr(0,4),10);
184 month = parseInt(value.substr(4,2),10) - 1;
185 day = parseInt(value.substr(6,2),10);
186 hour = parseInt(value.substr(8,2),10);
187 minute = parseInt(value.substr(10,2),10);
188 second = parseInt(value.substr(12,2),10);
191 if (isNaN(year) || isNaN(month) || isNaN(day) || day == 0) {
192 dt = new Date();
193 year = dt.getFullYear();
194 month = dt.getMonth();
195 day = dt.getDate();
197 if (isNaN(hour) || isNaN(minute) || isNaN(second)) {
198 dt = new Date();
199 hour = dt.getHours();
200 minute = dt.getMinutes();
201 second = dt.getSeconds();
203 } else {
204 /* Moving in calendar */
205 if (month > 11) {
206 month = 0;
207 year++;
209 if (month < 0) {
210 month = 11;
211 year--;
215 if (document.getElementById) {
216 cnt = document.getElementById("calendar_data");
217 } else if (document.all) {
218 cnt = document.all["calendar_data"];
221 cnt.innerHTML = "";
223 str = ""
225 //heading table
226 str += '<table class="calendar"><tr><th width="50%">';
227 str += '<form method="NONE" onsubmit="return 0">';
228 str += '<a href="javascript:month--; initCalendar();">&laquo;</a> ';
229 str += '<select id="select_month" name="monthsel" onchange="month = parseInt(document.getElementById(\'select_month\').value); initCalendar();">';
230 for (i =0; i < 12; i++) {
231 if (i == month) selected = ' selected="selected"';
232 else selected = '';
233 str += '<option value="' + i + '" ' + selected + '>' + month_names[i] + '</option>';
235 str += '</select>';
236 str += ' <a href="javascript:month++; initCalendar();">&raquo;</a>';
237 str += '</form>';
238 str += '</th><th width="50%">';
239 str += '<form method="NONE" onsubmit="return 0">';
240 str += '<a href="javascript:year--; initCalendar();">&laquo;</a> ';
241 str += '<select id="select_year" name="yearsel" onchange="year = parseInt(document.getElementById(\'select_year\').value); initCalendar();">';
242 for (i = year - 25; i < year + 25; i++) {
243 if (i == year) selected = ' selected="selected"';
244 else selected = '';
245 str += '<option value="' + i + '" ' + selected + '>' + i + '</option>';
247 str += '</select>';
248 str += ' <a href="javascript:year++; initCalendar();">&raquo;</a>';
249 str += '</form>';
250 str += '</th></tr></table>';
252 str += '<table class="calendar"><tr>';
253 for (i = 0; i < 7; i++) {
254 str += "<th>" + day_names[i] + "</th>";
256 str += "</tr>";
258 var firstDay = new Date(year, month, 1).getDay();
259 var lastDay = new Date(year, month + 1, 0).getDate();
261 str += "<tr>";
263 dayInWeek = 0;
264 for (i = 0; i < firstDay; i++) {
265 str += "<td>&nbsp;</td>";
266 dayInWeek++;
268 for (i = 1; i <= lastDay; i++) {
269 if (dayInWeek == 7) {
270 str += "</tr><tr>";
271 dayInWeek = 0;
274 dispmonth = 1 + month;
276 if (window.opener.dateType == 'datetime' || window.opener.dateType == 'date') {
277 actVal = "" + formatNum4(year) + "-" + formatNum2(dispmonth, 'month') + "-" + formatNum2(i, 'day');
278 } else {
279 actVal = "" + formatNum4(year) + formatNum2(dispmonth, 'month') + formatNum2(i, 'day');
281 if (i == day) {
282 style = ' class="selected"';
283 current_date = actVal;
284 } else {
285 style = '';
287 str += "<td" + style + "><a href=\"javascript:returnDate('" + actVal + "');\">" + i + "</a></td>"
288 dayInWeek++;
290 for (i = dayInWeek; i < 7; i++) {
291 str += "<td>&nbsp;</td>";
294 str += "</tr></table>";
296 cnt.innerHTML = str;
298 // Should we handle time also?
299 if (window.opener.dateType != 'date' && !clock_set) {
301 if (document.getElementById) {
302 cnt = document.getElementById("clock_data");
303 } else if (document.all) {
304 cnt = document.all["clock_data"];
307 str = '';
308 init_hour = hour;
309 init_minute = minute;
310 init_second = second;
311 str += '<fieldset>';
312 str += '<form method="NONE" class="clock" onsubmit="returnDate(\'' + current_date + '\')">';
313 str += '<input id="hour" type="text" size="2" maxlength="2" onblur="this.value=formatNum2d(this.value, init_hour, \'hour\'); init_hour = this.value;" value="' + formatNum2(hour, 'hour') + '" />:';
314 str += '<input id="minute" type="text" size="2" maxlength="2" onblur="this.value=formatNum2d(this.value, init_minute, \'minute\'); init_minute = this.value;" value="' + formatNum2(minute, 'minute') + '" />:';
315 str += '<input id="second" type="text" size="2" maxlength="2" onblur="this.value=formatNum2d(this.value, init_second, \'second\'); init_second = this.value;" value="' + formatNum2(second, 'second') + '" />';
316 str += '&nbsp;&nbsp;';
317 str += '<input type="submit" value="' + submit_text + '"/>';
318 str += '</form>';
319 str += '</fieldset>';
321 cnt.innerHTML = str;
322 clock_set = 1;
328 * Returns date from calendar.
330 * @param string date text
332 function returnDate(d) {
333 txt = d;
334 if (window.opener.dateType != 'date') {
335 // need to get time
336 h = parseInt(document.getElementById('hour').value,10);
337 m = parseInt(document.getElementById('minute').value,10);
338 s = parseInt(document.getElementById('second').value,10);
339 if (window.opener.dateType == 'datetime') {
340 txt += ' ' + formatNum2(h, 'hour') + ':' + formatNum2(m, 'minute') + ':' + formatNum2(s, 'second');
341 } else {
342 // timestamp
343 txt += formatNum2(h, 'hour') + formatNum2(m, 'minute') + formatNum2(s, 'second');
347 window.opener.dateField.value = txt;
348 window.close();