/* vim: set expandtab sw=4 ts=4 sts=4: */ /** * @fileoverview function used in table data manipulation pages * * @requires jQuery * @requires jQueryUI * @requires js/functions.js * */ /** * Modify form controls when the "NULL" checkbox is checked * * @param theType string the MySQL field type * @param urlField string the urlencoded field name - OBSOLETE * @param md5Field string the md5 hashed field name * @param multi_edit string the multi_edit row sequence number * * @return boolean always true */ function nullify(theType, urlField, md5Field, multi_edit) { var rowForm = document.forms['insertForm']; if (typeof(rowForm.elements['funcs' + multi_edit + '[' + md5Field + ']']) != 'undefined') { rowForm.elements['funcs' + multi_edit + '[' + md5Field + ']'].selectedIndex = -1; } // "SET" field , "ENUM" field with more than 20 characters // or foreign key field (drop-down) if (theType == 1 || theType == 3 || theType == 4) { rowForm.elements['field_' + md5Field + multi_edit + '[]'].selectedIndex = -1; } // Other "ENUM" field else if (theType == 2) { var elts = rowForm.elements['field_' + md5Field + multi_edit + '[]']; // when there is just one option in ENUM: if (elts.checked) { elts.checked = false; } else { var elts_cnt = elts.length; for (var i = 0; i < elts_cnt; i++ ) { elts[i].checked = false; } // end for } // end if } // foreign key field (with browsing icon for foreign values) else if (theType == 6) { rowForm.elements['field_' + md5Field + multi_edit + '[]'].value = ''; } // Other field types else /*if (theType == 5)*/ { rowForm.elements['fields' + multi_edit + '[' + md5Field + ']'].value = ''; } // end if... else if... else return true; } // end of the 'nullify()' function /** * javascript DateTime format validation. * its used to prevent adding default (0000-00-00 00:00:00) to database when user enter wrong values * Start of validation part */ //function checks the number of days in febuary function daysInFebruary (year){ return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 ); } //function to convert single digit to double digit function fractionReplace(num) { num=parseInt(num); var res="00"; switch(num) { case 1:res= "01";break; case 2:res= "02";break; case 3:res= "03";break; case 4:res= "04";break; case 5:res= "05";break; case 6:res= "06";break; case 7:res= "07";break; case 8:res= "08";break; case 9:res= "09";break; } return res; } /* function to check the validity of date * The following patterns are accepted in this validation (accepted in mysql as well) * 1) 2001-12-23 * 2) 2001-1-2 * 3) 02-12-23 * 4) And instead of using '-' the following punctuations can be used (+,.,*,^,@,/) All these are accepted by mysql as well. Therefore no issues */ function isDate(val,tmstmp) { val=val.replace(/[.|*|^|+|//|@]/g,'-'); var arrayVal=val.split("-"); for(var a=0;adaysInFebruary(year)) return false; if(val.substring(0,pos+2).length==2) { if(val.substring(0,pos+2).length==2) year=parseInt("20"+val.substring(0,pos+2)); else year=parseInt("19"+val.substring(0,pos+2)); } if(tmstmp==true) { if(year<1978) return false; if(year>2038||(year>2037&&day>19&&month>=1)||(year>2037&&month>1)) return false; } } else return false; return true; } /* function to check the validity of time * The following patterns are accepted in this validation (accepted in mysql as well) * 1) 2:3:4 * 2) 2:23:43 */ function isTime(val) { var arrayVal=val.split(":"); for(var a=0;a