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 (drop-down)
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;
44 // foreign key field (with browsing icon for foreign values)
45 else if (theType
== 6) {
46 rowForm
.elements
['field_' + md5Field
+ multi_edit
+ '[]'].value
= '';
49 else /*if (theType == 5)*/ {
50 rowForm
.elements
['fields' + multi_edit
+ '[' + urlField
+ ']'].value
= '';
51 } // end if... else if... else
54 } // end of the 'nullify()' function
58 * Unchecks the "NULL" control when a function has been selected or a value
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
73 if (typeof(rowForm
.elements
['insert_ignore_' + multi_edit
]) != 'undefined') {
74 rowForm
.elements
['insert_ignore_' + multi_edit
].checked
= false
78 } // end of the 'unNullify()' function
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
);
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
!= '') {
113 f
= (f
> 12 ? 12 : f
);
117 f
= (f
> 31 ? 31 : f
);
121 f
= (f
> 24 ? 24 : f
);
127 f
= (f
> 59 ? 59 : 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
) {
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
) {
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(' ');
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);
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) {
193 year
= dt
.getFullYear();
194 month
= dt
.getMonth();
197 if (isNaN(hour
) || isNaN(minute
) || isNaN(second
)) {
199 hour
= dt
.getHours();
200 minute
= dt
.getMinutes();
201 second
= dt
.getSeconds();
204 /* Moving in calendar */
215 if (document
.getElementById
) {
216 cnt
= document
.getElementById("calendar_data");
217 } else if (document
.all
) {
218 cnt
= document
.all
["calendar_data"];
226 str
+= '<table class="calendar"><tr><th width="50%">';
227 str
+= '<form method="NONE" onsubmit="return 0">';
228 str
+= '<a href="javascript:month--; initCalendar();">«</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"';
233 str
+= '<option value="' + i
+ '" ' + selected
+ '>' + month_names
[i
] + '</option>';
236 str
+= ' <a href="javascript:month++; initCalendar();">»</a>';
238 str
+= '</th><th width="50%">';
239 str
+= '<form method="NONE" onsubmit="return 0">';
240 str
+= '<a href="javascript:year--; initCalendar();">«</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"';
245 str
+= '<option value="' + i
+ '" ' + selected
+ '>' + i
+ '</option>';
248 str
+= ' <a href="javascript:year++; initCalendar();">»</a>';
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>";
258 var firstDay
= new Date(year
, month
, 1).getDay();
259 var lastDay
= new Date(year
, month
+ 1, 0).getDate();
264 for (i
= 0; i
< firstDay
; i
++) {
265 str
+= "<td> </td>";
268 for (i
= 1; i
<= lastDay
; i
++) {
269 if (dayInWeek
== 7) {
274 dispmonth
= 1 + month
;
276 if (window
.opener
.dateType
== 'datetime' || window
.opener
.dateType
== 'date') {
277 actVal
= "" + formatNum4(year
) + "-" + formatNum2(dispmonth
, 'month') + "-" + formatNum2(i
, 'day');
279 actVal
= "" + formatNum4(year
) + formatNum2(dispmonth
, 'month') + formatNum2(i
, 'day');
282 style
= ' class="selected"';
283 current_date
= actVal
;
287 str
+= "<td" + style
+ "><a href=\"javascript:returnDate('" + actVal
+ "');\">" + i
+ "</a></td>"
290 for (i
= dayInWeek
; i
< 7; i
++) {
291 str
+= "<td> </td>";
294 str
+= "</tr></table>";
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"];
309 init_minute
= minute
;
310 init_second
= second
;
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
+= ' ';
317 str
+= '<input type="submit" value="' + submit_text
+ '"/>';
319 str
+= '</fieldset>';
328 * Returns date from calendar.
330 * @param string date text
332 function returnDate(d
) {
334 if (window
.opener
.dateType
!= 'date') {
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');
343 txt
+= formatNum2(h
, 'hour') + formatNum2(m
, 'minute') + formatNum2(s
, 'second');
347 window
.opener
.dateField
.value
= txt
;