5 * Modify from controls when the "NULL" checkbox is selected
7 * @param string the MySQL field type
8 * @param string the urlencoded field name
9 * @param string the md5 hashed field name
11 * @return boolean always true
13 function nullify(theType, urlField, md5Field, multi_edit)
15 var rowForm = document.forms['insertForm'];
17 if (typeof(rowForm.elements['funcs' + multi_edit + '[' + urlField + ']']) != 'undefined') {
18 rowForm.elements['funcs' + multi_edit + '[' + urlField + ']'].selectedIndex = -1;
21 // "SET" field , "ENUM" field with more than 20 characters
22 // or foreign key field
23 if (theType == 1 || theType == 3 || theType == 4) {
24 rowForm.elements['field_' + md5Field + multi_edit + '[]'].selectedIndex = -1;
27 else if (theType == 2) {
28 var elts = rowForm.elements['field_' + md5Field + multi_edit + '[]'];
29 // when there is just one option in ENUM:
33 var elts_cnt = elts.length;
34 for (var i = 0; i < elts_cnt; i++ ) {
35 elts[i].checked = false;
41 else /*if (theType == 5)*/ {
42 rowForm.elements['fields' + multi_edit + '[' + urlField + ']'].value = '';
43 } // end if... else if... else
46 } // end of the 'nullify()' function
50 * Unchecks the "NULL" control when a function has been selected or a value
53 * @param string the urlencoded field name
55 * @return boolean always true
57 function unNullify(urlField, multi_edit)
59 var rowForm = document.forms['insertForm'];
61 if (typeof(rowForm.elements['fields_null[multi_edit][' + multi_edit + '][' + urlField + ']']) != 'undefined') {
62 rowForm.elements['fields_null[multi_edit][' + multi_edit + '][' + urlField + ']'].checked = false
65 if (typeof(rowForm.elements['insert_ignore_' + multi_edit]) != 'undefined') {
66 rowForm.elements['insert_ignore_' + multi_edit].checked = false
70 } // end of the 'unNullify()' function
81 * Opens calendar window.
83 * @param string calendar.php parameters
84 * @param string form name
85 * @param string field name
86 * @param string edit type - date/timestamp
88 function openCalendar(params, form, field, type) {
89 window.open("./calendar.php?" + params, "calendar", "width=400,height=200,status=yes");
90 dateField = eval("document." + form + "." + field);
95 * Formats number to two digits.
97 * @param int number to format.
98 * @param string type of number
100 function formatNum2(i, valtype) {
101 f = (i < 10 ? '0' : '') + i;
102 if (valtype && valtype != '') {
105 f = (f > 12 ? 12 : f);
109 f = (f > 31 ? 31 : f);
113 f = (f > 24 ? 24 : f);
119 f = (f > 59 ? 59 : f);
128 * Formats number to two digits.
130 * @param int number to format.
131 * @param int default value
132 * @param string type of number
134 function formatNum2d(i, default_v, valtype) {
136 if (isNaN(i)) return default_v;
137 return formatNum2(i, valtype)
141 * Formats number to four digits.
143 * @param int number to format.
145 function formatNum4(i) {
147 return (i < 1000 ? i < 100 ? i < 10 ? '000' : '00' : '0' : '') + i;
151 * Initializes calendar window.
153 function initCalendar() {
154 if (!year && !month && !day) {
155 /* Called for first time */
156 if (window.opener.dateField.value) {
157 value = window.opener.dateField.value;
158 if (window.opener.dateType == 'datetime' || window.opener.dateType == 'date') {
159 if (window.opener.dateType == 'datetime') {
160 parts = value.split(' ');
164 time = parts[1].split(':');
165 hour = parseInt(time[0],10);
166 minute = parseInt(time[1],10);
167 second = parseInt(time[2],10);
170 date = value.split("-");
171 day = parseInt(date[2],10);
172 month = parseInt(date[1],10) - 1;
173 year = parseInt(date[0],10);
175 year = parseInt(value.substr(0,4),10);
176 month = parseInt(value.substr(4,2),10) - 1;
177 day = parseInt(value.substr(6,2),10);
178 hour = parseInt(value.substr(8,2),10);
179 minute = parseInt(value.substr(10,2),10);
180 second = parseInt(value.substr(12,2),10);
183 if (isNaN(year) || isNaN(month) || isNaN(day) || day == 0) {
185 year = dt.getFullYear();
186 month = dt.getMonth();
189 if (isNaN(hour) || isNaN(minute) || isNaN(second)) {
191 hour = dt.getHours();
192 minute = dt.getMinutes();
193 second = dt.getSeconds();
196 /* Moving in calendar */
207 if (document.getElementById) {
208 cnt = document.getElementById("calendar_data");
209 } else if (document.all) {
210 cnt = document.all["calendar_data"];
218 str += '<table class="calendar"><tr><th width="50%">';
219 str += '<form method="NONE" onsubmit="return 0">';
220 str += '<a href="javascript:month--; initCalendar();">«</a> ';
221 str += '<select id="select_month" name="monthsel" onchange="month = parseInt(document.getElementById(\'select_month\').value); initCalendar();">';
222 for (i =0; i < 12; i++) {
223 if (i == month) selected = ' selected="selected"';
225 str += '<option value="' + i + '" ' + selected + '>' + month_names[i] + '</option>';
228 str += ' <a href="javascript:month++; initCalendar();">»</a>';
230 str += '</th><th width="50%">';
231 str += '<form method="NONE" onsubmit="return 0">';
232 str += '<a href="javascript:year--; initCalendar();">«</a> ';
233 str += '<select id="select_year" name="yearsel" onchange="year = parseInt(document.getElementById(\'select_year\').value); initCalendar();">';
234 for (i = year - 25; i < year + 25; i++) {
235 if (i == year) selected = ' selected="selected"';
237 str += '<option value="' + i + '" ' + selected + '>' + i + '</option>';
240 str += ' <a href="javascript:year++; initCalendar();">»</a>';
242 str += '</th></tr></table>';
244 str += '<table class="calendar"><tr>';
245 for (i = 0; i < 7; i++) {
246 str += "<th>" + day_names[i] + "</th>";
250 var firstDay = new Date(year, month, 1).getDay();
251 var lastDay = new Date(year, month + 1, 0).getDate();
256 for (i = 0; i < firstDay; i++) {
257 str += "<td> </td>";
260 for (i = 1; i <= lastDay; i++) {
261 if (dayInWeek == 7) {
266 dispmonth = 1 + month;
268 if (window.opener.dateType == 'datetime' || window.opener.dateType == 'date') {
269 actVal = "" + formatNum4(year) + "-" + formatNum2(dispmonth, 'month') + "-" + formatNum2(i, 'day');
271 actVal = "" + formatNum4(year) + formatNum2(dispmonth, 'month') + formatNum2(i, 'day');
274 style = ' class="selected"';
275 current_date = actVal;
279 str += "<td" + style + "><a href=\"javascript:returnDate('" + actVal + "');\">" + i + "</a></td>"
282 for (i = dayInWeek; i < 7; i++) {
283 str += "<td> </td>";
286 str += "</tr></table>";
290 // Should we handle time also?
291 if (window.opener.dateType != 'date' && !clock_set) {
293 if (document.getElementById) {
294 cnt = document.getElementById("clock_data");
295 } else if (document.all) {
296 cnt = document.all["clock_data"];
301 init_minute = minute;
302 init_second = second;
303 str += '<form method="NONE" class="clock" onsubmit="returnDate(\'' + current_date + '\')">';
304 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') + '" />:';
305 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') + '" />:';
306 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') + '" />';
308 str += '<input type="submit" value="' + submit_text + '"/>';
318 * Returns date from calendar.
320 * @param string date text
322 function returnDate(d) {
324 if (window.opener.dateType != 'date') {
326 h = parseInt(document.getElementById('hour').value,10);
327 m = parseInt(document.getElementById('minute').value,10);
328 s = parseInt(document.getElementById('second').value,10);
329 if (window.opener.dateType == 'datetime') {
330 txt += ' ' + formatNum2(h, 'hour') + ':' + formatNum2(m, 'minute') + ':' + formatNum2(s, 'second');
333 txt += formatNum2(h, 'hour') + formatNum2(m, 'minute') + formatNum2(s, 'second');
337 window.opener.dateField.value = txt;