1 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 * function used in table data manipulation pages
9 * Modify from controls when the "NULL" checkbox is selected
11 * @param string the MySQL field type
12 * @param string the urlencoded field name - OBSOLETE
13 * @param string the md5 hashed field name
14 * @param string the multi_edit row sequence number
16 * @return boolean always true
18 function nullify(theType, urlField, md5Field, multi_edit)
20 var rowForm = document.forms['insertForm'];
22 if (typeof(rowForm.elements['funcs' + multi_edit + '[' + md5Field + ']']) != 'undefined') {
23 rowForm.elements['funcs' + multi_edit + '[' + md5Field + ']'].selectedIndex = -1;
26 // "SET" field , "ENUM" field with more than 20 characters
27 // or foreign key field (drop-down)
28 if (theType == 1 || theType == 3 || theType == 4) {
29 rowForm.elements['field_' + md5Field + multi_edit + '[]'].selectedIndex = -1;
32 else if (theType == 2) {
33 var elts = rowForm.elements['field_' + md5Field + multi_edit + '[]'];
34 // when there is just one option in ENUM:
38 var elts_cnt = elts.length;
39 for (var i = 0; i < elts_cnt; i++ ) {
40 elts[i].checked = false;
45 // foreign key field (with browsing icon for foreign values)
46 else if (theType == 6) {
47 rowForm.elements['field_' + md5Field + multi_edit + '[]'].value = '';
50 else /*if (theType == 5)*/ {
51 rowForm.elements['fields' + multi_edit + '[' + md5Field + ']'].value = '';
52 } // end if... else if... else
55 } // end of the 'nullify()' function
59 * Unchecks the "NULL" control when a function has been selected or a value
62 * @param string the urlencoded field name
63 * @param string the multi_edit row sequence number
65 * @return boolean always true
67 function unNullify(urlField, multi_edit)
69 var rowForm = document.forms['insertForm'];
71 if (typeof(rowForm.elements['fields_null[multi_edit][' + multi_edit + '][' + urlField + ']']) != 'undefined') {
72 rowForm.elements['fields_null[multi_edit][' + multi_edit + '][' + urlField + ']'].checked = false
75 if (typeof(rowForm.elements['insert_ignore_' + multi_edit]) != 'undefined') {
76 rowForm.elements['insert_ignore_' + multi_edit].checked = false
80 } // end of the 'unNullify()' function
91 * Opens calendar window.
93 * @param string calendar.php parameters
94 * @param string form name
95 * @param string id of field name
96 * @param string edit type - date/timestamp
97 * @param string id of the corresponding checkbox for NULL
99 function openCalendar(params, form, field, type, fieldNull) {
100 window.open("./calendar.php?" + params, "calendar", "width=400,height=200,status=yes");
101 dateField = eval("document." + form + "." + field);
103 if (fieldNull != '') {
104 dateFieldNull = eval("document." + form + "." + fieldNull);
109 * Formats number to two digits.
111 * @param int number to format.
112 * @param string type of number
114 function formatNum2(i, valtype) {
115 f = (i < 10 ? '0' : '') + i;
116 if (valtype && valtype != '') {
119 f = (f > 12 ? 12 : f);
123 f = (f > 31 ? 31 : f);
127 f = (f > 24 ? 24 : f);
133 f = (f > 59 ? 59 : f);
142 * Formats number to two digits.
144 * @param int number to format.
145 * @param int default value
146 * @param string type of number
148 function formatNum2d(i, default_v, valtype) {
150 if (isNaN(i)) return default_v;
151 return formatNum2(i, valtype)
155 * Formats number to four digits.
157 * @param int number to format.
159 function formatNum4(i) {
161 return (i < 1000 ? i < 100 ? i < 10 ? '000' : '00' : '0' : '') + i;
165 * Initializes calendar window.
167 function initCalendar() {
168 if (!year && !month && !day) {
169 /* Called for first time */
170 if (window.opener.dateField.value) {
171 value = window.opener.dateField.value;
172 if (window.opener.dateType == 'datetime' || window.opener.dateType == 'date') {
173 if (window.opener.dateType == 'datetime') {
174 parts = value.split(' ');
178 time = parts[1].split(':');
179 hour = parseInt(time[0],10);
180 minute = parseInt(time[1],10);
181 second = parseInt(time[2],10);
184 date = value.split("-");
185 day = parseInt(date[2],10);
186 month = parseInt(date[1],10) - 1;
187 year = parseInt(date[0],10);
189 year = parseInt(value.substr(0,4),10);
190 month = parseInt(value.substr(4,2),10) - 1;
191 day = parseInt(value.substr(6,2),10);
192 hour = parseInt(value.substr(8,2),10);
193 minute = parseInt(value.substr(10,2),10);
194 second = parseInt(value.substr(12,2),10);
197 if (isNaN(year) || isNaN(month) || isNaN(day) || day == 0) {
199 year = dt.getFullYear();
200 month = dt.getMonth();
203 if (isNaN(hour) || isNaN(minute) || isNaN(second)) {
205 hour = dt.getHours();
206 minute = dt.getMinutes();
207 second = dt.getSeconds();
210 /* Moving in calendar */
221 if (document.getElementById) {
222 cnt = document.getElementById("calendar_data");
223 } else if (document.all) {
224 cnt = document.all["calendar_data"];
232 str += '<table class="calendar"><tr><th width="50%">';
233 str += '<form method="NONE" onsubmit="return 0">';
234 str += '<a href="javascript:month--; initCalendar();">«</a> ';
235 str += '<select id="select_month" name="monthsel" onchange="month = parseInt(document.getElementById(\'select_month\').value); initCalendar();">';
236 for (i =0; i < 12; i++) {
237 if (i == month) selected = ' selected="selected"';
239 str += '<option value="' + i + '" ' + selected + '>' + month_names[i] + '</option>';
242 str += ' <a href="javascript:month++; initCalendar();">»</a>';
244 str += '</th><th width="50%">';
245 str += '<form method="NONE" onsubmit="return 0">';
246 str += '<a href="javascript:year--; initCalendar();">«</a> ';
247 str += '<select id="select_year" name="yearsel" onchange="year = parseInt(document.getElementById(\'select_year\').value); initCalendar();">';
248 for (i = year - 25; i < year + 25; i++) {
249 if (i == year) selected = ' selected="selected"';
251 str += '<option value="' + i + '" ' + selected + '>' + i + '</option>';
254 str += ' <a href="javascript:year++; initCalendar();">»</a>';
256 str += '</th></tr></table>';
258 str += '<table class="calendar"><tr>';
259 for (i = 0; i < 7; i++) {
260 str += "<th>" + day_names[i] + "</th>";
264 var firstDay = new Date(year, month, 1).getDay();
265 var lastDay = new Date(year, month + 1, 0).getDate();
270 for (i = 0; i < firstDay; i++) {
271 str += "<td> </td>";
274 for (i = 1; i <= lastDay; i++) {
275 if (dayInWeek == 7) {
280 dispmonth = 1 + month;
282 if (window.opener.dateType == 'datetime' || window.opener.dateType == 'date') {
283 actVal = "" + formatNum4(year) + "-" + formatNum2(dispmonth, 'month') + "-" + formatNum2(i, 'day');
285 actVal = "" + formatNum4(year) + formatNum2(dispmonth, 'month') + formatNum2(i, 'day');
288 style = ' class="selected"';
289 current_date = actVal;
293 str += "<td" + style + "><a href=\"javascript:returnDate('" + actVal + "');\">" + i + "</a></td>"
296 for (i = dayInWeek; i < 7; i++) {
297 str += "<td> </td>";
300 str += "</tr></table>";
304 // Should we handle time also?
305 if (window.opener.dateType != 'date' && !clock_set) {
307 if (document.getElementById) {
308 cnt = document.getElementById("clock_data");
309 } else if (document.all) {
310 cnt = document.all["clock_data"];
315 init_minute = minute;
316 init_second = second;
318 str += '<form method="NONE" class="clock" onsubmit="returnDate(\'' + current_date + '\')">';
319 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') + '" />:';
320 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') + '" />:';
321 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') + '" />';
322 str += ' ';
323 str += '<input type="submit" value="' + submit_text + '"/>';
325 str += '</fieldset>';
334 * Returns date from calendar.
336 * @param string date text
338 function returnDate(d) {
340 if (window.opener.dateType != 'date') {
342 h = parseInt(document.getElementById('hour').value,10);
343 m = parseInt(document.getElementById('minute').value,10);
344 s = parseInt(document.getElementById('second').value,10);
345 if (window.opener.dateType == 'datetime') {
346 txt += ' ' + formatNum2(h, 'hour') + ':' + formatNum2(m, 'minute') + ':' + formatNum2(s, 'second');
349 txt += formatNum2(h, 'hour') + formatNum2(m, 'minute') + formatNum2(s, 'second');
353 window.opener.dateField.value = txt;
354 if (typeof(window.opener.dateFieldNull) != 'undefined') {
355 window.opener.dateFieldNull.checked = false;