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
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
27 if (theType == 1 || theType == 3 || theType == 4) {
28 rowForm.elements['field_' + md5Field + multi_edit + '[]'].selectedIndex = -1;
31 else if (theType == 2) {
32 var elts = rowForm.elements['field_' + md5Field + multi_edit + '[]'];
33 // when there is just one option in ENUM:
37 var elts_cnt = elts.length;
38 for (var i = 0; i < elts_cnt; i++ ) {
39 elts[i].checked = false;
45 else /*if (theType == 5)*/ {
46 rowForm.elements['fields' + multi_edit + '[' + urlField + ']'].value = '';
47 } // end if... else if... else
50 } // end of the 'nullify()' function
54 * Unchecks the "NULL" control when a function has been selected or a value
57 * @param string the urlencoded field name
59 * @return boolean always true
61 function unNullify(urlField, multi_edit)
63 var rowForm = document.forms['insertForm'];
65 if (typeof(rowForm.elements['fields_null[multi_edit][' + multi_edit + '][' + urlField + ']']) != 'undefined') {
66 rowForm.elements['fields_null[multi_edit][' + multi_edit + '][' + urlField + ']'].checked = false
69 if (typeof(rowForm.elements['insert_ignore_' + multi_edit]) != 'undefined') {
70 rowForm.elements['insert_ignore_' + multi_edit].checked = false
74 } // end of the 'unNullify()' function
85 * Opens calendar window.
87 * @param string calendar.php parameters
88 * @param string form name
89 * @param string field name
90 * @param string edit type - date/timestamp
92 function openCalendar(params, form, field, type) {
93 window.open("./calendar.php?" + params, "calendar", "width=400,height=200,status=yes");
94 dateField = eval("document." + form + "." + field);
99 * Formats number to two digits.
101 * @param int number to format.
102 * @param string type of number
104 function formatNum2(i, valtype) {
105 f = (i < 10 ? '0' : '') + i;
106 if (valtype && valtype != '') {
109 f = (f > 12 ? 12 : f);
113 f = (f > 31 ? 31 : f);
117 f = (f > 24 ? 24 : f);
123 f = (f > 59 ? 59 : f);
132 * Formats number to two digits.
134 * @param int number to format.
135 * @param int default value
136 * @param string type of number
138 function formatNum2d(i, default_v, valtype) {
140 if (isNaN(i)) return default_v;
141 return formatNum2(i, valtype)
145 * Formats number to four digits.
147 * @param int number to format.
149 function formatNum4(i) {
151 return (i < 1000 ? i < 100 ? i < 10 ? '000' : '00' : '0' : '') + i;
155 * Initializes calendar window.
157 function initCalendar() {
158 if (!year && !month && !day) {
159 /* Called for first time */
160 if (window.opener.dateField.value) {
161 value = window.opener.dateField.value;
162 if (window.opener.dateType == 'datetime' || window.opener.dateType == 'date') {
163 if (window.opener.dateType == 'datetime') {
164 parts = value.split(' ');
168 time = parts[1].split(':');
169 hour = parseInt(time[0],10);
170 minute = parseInt(time[1],10);
171 second = parseInt(time[2],10);
174 date = value.split("-");
175 day = parseInt(date[2],10);
176 month = parseInt(date[1],10) - 1;
177 year = parseInt(date[0],10);
179 year = parseInt(value.substr(0,4),10);
180 month = parseInt(value.substr(4,2),10) - 1;
181 day = parseInt(value.substr(6,2),10);
182 hour = parseInt(value.substr(8,2),10);
183 minute = parseInt(value.substr(10,2),10);
184 second = parseInt(value.substr(12,2),10);
187 if (isNaN(year) || isNaN(month) || isNaN(day) || day == 0) {
189 year = dt.getFullYear();
190 month = dt.getMonth();
193 if (isNaN(hour) || isNaN(minute) || isNaN(second)) {
195 hour = dt.getHours();
196 minute = dt.getMinutes();
197 second = dt.getSeconds();
200 /* Moving in calendar */
211 if (document.getElementById) {
212 cnt = document.getElementById("calendar_data");
213 } else if (document.all) {
214 cnt = document.all["calendar_data"];
222 str += '<table class="calendar"><tr><th width="50%">';
223 str += '<form method="NONE" onsubmit="return 0">';
224 str += '<a href="javascript:month--; initCalendar();">«</a> ';
225 str += '<select id="select_month" name="monthsel" onchange="month = parseInt(document.getElementById(\'select_month\').value); initCalendar();">';
226 for (i =0; i < 12; i++) {
227 if (i == month) selected = ' selected="selected"';
229 str += '<option value="' + i + '" ' + selected + '>' + month_names[i] + '</option>';
232 str += ' <a href="javascript:month++; initCalendar();">»</a>';
234 str += '</th><th width="50%">';
235 str += '<form method="NONE" onsubmit="return 0">';
236 str += '<a href="javascript:year--; initCalendar();">«</a> ';
237 str += '<select id="select_year" name="yearsel" onchange="year = parseInt(document.getElementById(\'select_year\').value); initCalendar();">';
238 for (i = year - 25; i < year + 25; i++) {
239 if (i == year) selected = ' selected="selected"';
241 str += '<option value="' + i + '" ' + selected + '>' + i + '</option>';
244 str += ' <a href="javascript:year++; initCalendar();">»</a>';
246 str += '</th></tr></table>';
248 str += '<table class="calendar"><tr>';
249 for (i = 0; i < 7; i++) {
250 str += "<th>" + day_names[i] + "</th>";
254 var firstDay = new Date(year, month, 1).getDay();
255 var lastDay = new Date(year, month + 1, 0).getDate();
260 for (i = 0; i < firstDay; i++) {
261 str += "<td> </td>";
264 for (i = 1; i <= lastDay; i++) {
265 if (dayInWeek == 7) {
270 dispmonth = 1 + month;
272 if (window.opener.dateType == 'datetime' || window.opener.dateType == 'date') {
273 actVal = "" + formatNum4(year) + "-" + formatNum2(dispmonth, 'month') + "-" + formatNum2(i, 'day');
275 actVal = "" + formatNum4(year) + formatNum2(dispmonth, 'month') + formatNum2(i, 'day');
278 style = ' class="selected"';
279 current_date = actVal;
283 str += "<td" + style + "><a href=\"javascript:returnDate('" + actVal + "');\">" + i + "</a></td>"
286 for (i = dayInWeek; i < 7; i++) {
287 str += "<td> </td>";
290 str += "</tr></table>";
294 // Should we handle time also?
295 if (window.opener.dateType != 'date' && !clock_set) {
297 if (document.getElementById) {
298 cnt = document.getElementById("clock_data");
299 } else if (document.all) {
300 cnt = document.all["clock_data"];
305 init_minute = minute;
306 init_second = second;
308 str += '<form method="NONE" class="clock" onsubmit="returnDate(\'' + current_date + '\')">';
309 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') + '" />:';
310 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') + '" />:';
311 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') + '" />';
312 str += ' ';
313 str += '<input type="submit" value="' + submit_text + '"/>';
315 str += '</fieldset>';
324 * Returns date from calendar.
326 * @param string date text
328 function returnDate(d) {
330 if (window.opener.dateType != 'date') {
332 h = parseInt(document.getElementById('hour').value,10);
333 m = parseInt(document.getElementById('minute').value,10);
334 s = parseInt(document.getElementById('second').value,10);
335 if (window.opener.dateType == 'datetime') {
336 txt += ' ' + formatNum2(h, 'hour') + ':' + formatNum2(m, 'minute') + ':' + formatNum2(s, 'second');
339 txt += formatNum2(h, 'hour') + formatNum2(m, 'minute') + formatNum2(s, 'second');
343 window.opener.dateField.value = txt;