Location: PHPKode > projects > HypatiaDB > hypatiadb/js/tblcreate.php
<?php header("Content-Type: text/javascript");
include('../common_db.php');
include('../functions.php');
dbconnect($host, $username, $password);
$strings = loadStrings($lang, 'TBLC1');
?>

function validate(frm) {
   return true;
}

function validateColumnName() {
	var v = this.value;
	var invalid = "/.\\*?";

	if(v.length > 64) {
		alert("<?php echo($strings['TBLC_1_TOOLONG']); ?>");
		return false;
	}

	for(i = 0; i < invalid.length; i++) {
		var c = invalid.charAt(i);
		if(v.indexOf(c,0) > -1) {
			//invalid
			alert("<?php echo($strings['TBLC1_ERR_BADCOLNAME']); ?>");
			return false;
		}
	}
	return true;
}

function validateLength() {
	var v = this.value;
	var valid = "1234567890"; //todo:l10n??

	for(i = 0; i < v.length; i++) {
		c = v[i];
		if(valid.indexOf(c) == -1) {
			alert("<?php echo($strings['TBLC1_ERR_NONNUMLENGTH']); ?>");
			return false;
		}
	}
	return true;
}

function init() {
	var inputs = document.getElementsByTagName('input');
	for(var i = 0; i < inputs.length; i++) { //>
		var ip = inputs[i];
		setValidationFunc(ip);
	}
}

function setValidationFunc(e) {
	var eid = e.getAttribute("id");
	if(eid) {
	if(eid.substring(0, 5) == "field") {
		e.addEventListener('blur', validateColumnName, false);
	} else if(eid.substring(0, 6) == "length") {
		e.addEventListener('blur', validateLength, false);
	}
	}
}

function validTblName(tblForm) {
	invalidChars = "/.\\*?"

	if(tblForm.tbl_name.value.length > 64) {
		alert("<?php echo($strings['TBLC_1_TOOLONG']); ?>");
		return false;
	}

	if(tblForm.tbl_name.value == "") {
		alert("<?php echo($strings['TBLC_1_NONAME']); ?>");
		return false;
	}

	for(i=0; i<invalidChars.length; i++) {
		badChar = invalidChars.charAt(i)
		if(tblForm.tbl_name.value.indexOf(badChar,0) > -1) {
			alert("<?php printf($strings['TBLC_1_INVALIDCHAR'], '" + badChar + "'); ?>");
			return false;
		}
	}

	if(tblForm.field_number.value == "") {
		alert("<?php echo($strings['TBLC_1_BADFIELDS']) ?>");
		return false;
	}

	for(i=0; i<tblForm.field_number.value.length; i++) {
		if(tblForm.field_number.value.charAt(i) < "0" ||
		 tblForm.field_number.value.charAt(i) > "9") {
			alert("<?php echo($strings['TBLC_1_NAN']) ?>");
			return false;
		}
	} 

		return true;
}

function alterForm(e) {
	cnt = e.parentNode.parentNode.getAttribute("id").substring(1);
	if(cnt == 'rc')
		cnt = 0;		//src
	if(e.value == 'VARCHAR' || e.value == 'TEXT') {
		document.getElementById('ld' + cnt).style.display = 'block';
		document.getElementById('nul' + cnt).style.display = 'block';
		document.getElementById('def' + cnt).style.display = 'block';
		document.getElementById('idx' + cnt).style.display = 'none';
		document.getElementById('bin' + cnt).style.display = 'block';
	} else if(e.value == 'INTEGER') {
		document.getElementById('ld' + cnt).style.display = 'none';
		document.getElementById('nul' + cnt).style.display = 'block';
		document.getElementById('def' + cnt).style.display = 'block';
		document.getElementById('idx' + cnt).style.display = 'block';
		document.getElementById('bin' + cnt).style.display = 'none';
	} else if(e.value == 'DATE' || e.value == 'TIME' || e.value == 'DATETIME') {
		document.getElementById('ld' + cnt).style.display = 'none';
		document.getElementById('nul' + cnt).style.display = 'block';
		document.getElementById('def' + cnt).style.display = 'block';
		document.getElementById('idx' + cnt).style.display = 'block';
		document.getElementById('bin' + cnt).style.display = 'none';
	} else if(e.value == 'ENUM') {
		document.getElementById('ld' + cnt).style.display = 'none';
		document.getElementById('nul' + cnt).style.display = 'block';
		document.getElementById('def' + cnt).style.display = 'block';
		document.getElementById('idx' + cnt).style.display = 'block';
		document.getElementById('bin' + cnt).style.display = 'none';
	} else {
		document.getElementById('ld' + cnt).style.display = 'none';
		document.getElementById('nul' + cnt).style.display = 'none';
		document.getElementById('def' + cnt).style.display = 'none';
		document.getElementById('idx' + cnt).style.display = 'none';
		document.getElementById('bin' + cnt).style.display = 'none';
		document.getElementById('pkwarning').style.display = 'none';
	}
}
Return current item: HypatiaDB