Location: PHPKode > projects > Clinical Handover Database > output/include/commonfunctions.php
<?php 

////////////////////////////////////////////////////////////////////////////////
// table and field info functions
////////////////////////////////////////////////////////////////////////////////

// return field label
function Label($field,$table="")
{
	global $strTableName;
	if(!$table)
		$table=$strTableName;

//	jobs
	if($table=="jobs" && $field=="Primary") return "Primary";
	if($table=="jobs" && $field=="Patient Name") return "Patient Name";
	if($table=="jobs" && $field=="Date") return "Date";
	if($table=="jobs" && $field=="Type") return "Type";
	if($table=="jobs" && $field=="Status") return "Status";
	if($table=="jobs" && $field=="Name") return "Name";
	if($table=="jobs" && $field=="Result") return "Result";
	if($table=="jobs" && $field=="Notes") return "Notes";
	if($table=="jobs" && $field=="Consultant") return "Consultant";

//	patients
	if($table=="patients" && $field=="Primary") return "Primary";
	if($table=="patients" && $field=="Patient Name") return "Patient Name";
	if($table=="patients" && $field=="Date of Birth") return "Date of Birth";
	if($table=="patients" && $field=="Unit Number") return "Unit Number";
	if($table=="patients" && $field=="Sex") return "Sex";
	if($table=="patients" && $field=="Ward") return "Ward";
	if($table=="patients" && $field=="Bed") return "Bed";
	if($table=="patients" && $field=="Consultant") return "Consultant";
	if($table=="patients" && $field=="Code") return "Code";
	if($table=="patients" && $field=="Category") return "Category";
	if($table=="patients" && $field=="Admission Date") return "Admission Date";
	if($table=="patients" && $field=="Diagnosis") return "Diagnosis";
	if($table=="patients" && $field=="Allergies") return "Allergies";
	if($table=="patients" && $field=="Notes") return "Notes";
	if($table=="patients" && $field=="Nurses") return "Nurses";
	if($table=="patients" && $field=="Social Services") return "Social Services";
	if($table=="patients" && $field=="Team") return "Team";
	if($table=="patients" && $field=="Ward Round Notes") return "Ward Round Notes";

//	Nursing Handover
	if($table=="Nursing Handover" && $field=="Primary") return "Primary";
	if($table=="Nursing Handover" && $field=="Patient Name") return "Patient Name";
	if($table=="Nursing Handover" && $field=="Date of Birth") return "Date of Birth";
	if($table=="Nursing Handover" && $field=="Unit Number") return "Unit Number";
	if($table=="Nursing Handover" && $field=="Sex") return "Sex";
	if($table=="Nursing Handover" && $field=="Ward") return "Ward";
	if($table=="Nursing Handover" && $field=="Bed") return "Bed";
	if($table=="Nursing Handover" && $field=="Consultant") return "Consultant";
	if($table=="Nursing Handover" && $field=="Code") return "Code";
	if($table=="Nursing Handover" && $field=="Category") return "Category";
	if($table=="Nursing Handover" && $field=="Admission Date") return "Admission Date";
	if($table=="Nursing Handover" && $field=="Diagnosis") return "Diagnosis";
	if($table=="Nursing Handover" && $field=="Allergies") return "Allergies";
	if($table=="Nursing Handover" && $field=="Notes") return "Notes";
	if($table=="Nursing Handover" && $field=="Nurses") return "Nurses";
	if($table=="Nursing Handover" && $field=="Social Services") return "Social Services";
	if($table=="Nursing Handover" && $field=="Team") return "Team";
	if($table=="Nursing Handover" && $field=="Ward Round Notes") return "Ward Round Notes";

//	Current Patients
	if($table=="Current Patients" && $field=="Primary") return "Primary";
	if($table=="Current Patients" && $field=="Patient Name") return "Patient Name";
	if($table=="Current Patients" && $field=="Date of Birth") return "Date of Birth";
	if($table=="Current Patients" && $field=="Unit Number") return "Unit Number";
	if($table=="Current Patients" && $field=="Sex") return "Sex";
	if($table=="Current Patients" && $field=="Ward") return "Ward";
	if($table=="Current Patients" && $field=="Bed") return "Bed";
	if($table=="Current Patients" && $field=="Consultant") return "Consultant";
	if($table=="Current Patients" && $field=="Code") return "Code";
	if($table=="Current Patients" && $field=="Category") return "Category";
	if($table=="Current Patients" && $field=="Admission Date") return "Admission Date";
	if($table=="Current Patients" && $field=="Diagnosis") return "Diagnosis";
	if($table=="Current Patients" && $field=="Allergies") return "Allergies";
	if($table=="Current Patients" && $field=="Notes") return "Notes";
	if($table=="Current Patients" && $field=="Nurses") return "Nurses";
	if($table=="Current Patients" && $field=="Social Services") return "Social Services";
	if($table=="Current Patients" && $field=="Team") return "Team";
	if($table=="Current Patients" && $field=="Ward Round Notes") return "Ward Round Notes";

//	Current Jobs
	if($table=="Current Jobs" && $field=="Primary") return "Primary";
	if($table=="Current Jobs" && $field=="Patient Name") return "Patient Name";
	if($table=="Current Jobs" && $field=="Date") return "Date";
	if($table=="Current Jobs" && $field=="Type") return "Type";
	if($table=="Current Jobs" && $field=="Status") return "Status";
	if($table=="Current Jobs" && $field=="Name") return "Name";
	if($table=="Current Jobs" && $field=="Result") return "Result";
	if($table=="Current Jobs" && $field=="Notes") return "Notes";
	if($table=="Current Jobs" && $field=="Consultant") return "Consultant";

//	Ward Round Sheet
	if($table=="Ward Round Sheet" && $field=="Primary") return "Primary";
	if($table=="Ward Round Sheet" && $field=="Consultant") return "Consultant";
	if($table=="Ward Round Sheet" && $field=="Patient Name") return "Patient Name";
	if($table=="Ward Round Sheet" && $field=="Date of Birth") return "Date of Birth";
	if($table=="Ward Round Sheet" && $field=="Unit Number") return "Unit Number";
	if($table=="Ward Round Sheet" && $field=="Sex") return "Sex";
	if($table=="Ward Round Sheet" && $field=="Ward") return "Ward";
	if($table=="Ward Round Sheet" && $field=="Bed") return "Bed";
	if($table=="Ward Round Sheet" && $field=="Code") return "Code";
	if($table=="Ward Round Sheet" && $field=="Category") return "Category";
	if($table=="Ward Round Sheet" && $field=="Admission Date") return "Admission Date";
	if($table=="Ward Round Sheet" && $field=="Diagnosis") return "Diagnosis";
	if($table=="Ward Round Sheet" && $field=="Allergies") return "Allergies";
	if($table=="Ward Round Sheet" && $field=="Notes") return "Notes";
	if($table=="Ward Round Sheet" && $field=="Nurses") return "Nurses";
	if($table=="Ward Round Sheet" && $field=="Social Services") return "Social Services";
	if($table=="Ward Round Sheet" && $field=="Team") return "Team";
	if($table=="Ward Round Sheet" && $field=="Ward Round Notes") return "Ward Round Notes";

//	Sign-Out Sheet
	if($table=="Sign-Out Sheet" && $field=="Primary") return "Primary";
	if($table=="Sign-Out Sheet" && $field=="Patient Name") return "Patient Name";
	if($table=="Sign-Out Sheet" && $field=="Date of Birth") return "Date of Birth";
	if($table=="Sign-Out Sheet" && $field=="Unit Number") return "Unit Number";
	if($table=="Sign-Out Sheet" && $field=="Sex") return "Sex";
	if($table=="Sign-Out Sheet" && $field=="Ward") return "Ward";
	if($table=="Sign-Out Sheet" && $field=="Bed") return "Bed";
	if($table=="Sign-Out Sheet" && $field=="Consultant") return "Consultant";
	if($table=="Sign-Out Sheet" && $field=="Code") return "Code";
	if($table=="Sign-Out Sheet" && $field=="Category") return "Category";
	if($table=="Sign-Out Sheet" && $field=="Admission Date") return "Admission Date";
	if($table=="Sign-Out Sheet" && $field=="Diagnosis") return "Diagnosis";
	if($table=="Sign-Out Sheet" && $field=="Allergies") return "Allergies";
	if($table=="Sign-Out Sheet" && $field=="Notes") return "Notes";
	if($table=="Sign-Out Sheet" && $field=="Nurses") return "Nurses";
	if($table=="Sign-Out Sheet" && $field=="Social Services") return "Social Services";
	if($table=="Sign-Out Sheet" && $field=="Team") return "Team";
	if($table=="Sign-Out Sheet" && $field=="Ward Round Notes") return "Ward Round Notes";

//	users
	if($table=="users" && $field=="Primary") return "Primary";
	if($table=="users" && $field=="Login") return "Login";
	if($table=="users" && $field=="Name") return "Name";
	if($table=="users" && $field=="Password") return "Password";
	if($table=="users" && $field=="User Type") return "User Type";

//	consultants
	if($table=="consultants" && $field=="Primary") return "Primary";
	if($table=="consultants" && $field=="Consultant") return "Consultant";

//	ward list
	if($table=="ward list" && $field=="Primary") return "Primary";
	if($table=="ward list" && $field=="Ward") return "Ward";
	return $field;
}

// return filename field if any
function GetFilenameField($field,$table="")
{
	global $strTableName;
	if(!$table)
		$table=$strTableName;

//	jobs
	if($table=="jobs" && $field=="Primary") return "";
	if($table=="jobs" && $field=="Patient Name") return "";
	if($table=="jobs" && $field=="Date") return "";
	if($table=="jobs" && $field=="Type") return "";
	if($table=="jobs" && $field=="Status") return "";
	if($table=="jobs" && $field=="Name") return "";
	if($table=="jobs" && $field=="Result") return "";
	if($table=="jobs" && $field=="Notes") return "";
	if($table=="jobs" && $field=="Consultant") return "";

//	patients
	if($table=="patients" && $field=="Primary") return "";
	if($table=="patients" && $field=="Patient Name") return "";
	if($table=="patients" && $field=="Date of Birth") return "";
	if($table=="patients" && $field=="Unit Number") return "";
	if($table=="patients" && $field=="Sex") return "";
	if($table=="patients" && $field=="Ward") return "";
	if($table=="patients" && $field=="Bed") return "";
	if($table=="patients" && $field=="Consultant") return "";
	if($table=="patients" && $field=="Code") return "";
	if($table=="patients" && $field=="Category") return "";
	if($table=="patients" && $field=="Admission Date") return "";
	if($table=="patients" && $field=="Diagnosis") return "";
	if($table=="patients" && $field=="Allergies") return "";
	if($table=="patients" && $field=="Notes") return "";
	if($table=="patients" && $field=="Nurses") return "";
	if($table=="patients" && $field=="Social Services") return "";
	if($table=="patients" && $field=="Team") return "";
	if($table=="patients" && $field=="Ward Round Notes") return "";

//	Nursing Handover
	if($table=="Nursing Handover" && $field=="Primary") return "";
	if($table=="Nursing Handover" && $field=="Patient Name") return "";
	if($table=="Nursing Handover" && $field=="Date of Birth") return "";
	if($table=="Nursing Handover" && $field=="Unit Number") return "";
	if($table=="Nursing Handover" && $field=="Sex") return "";
	if($table=="Nursing Handover" && $field=="Ward") return "";
	if($table=="Nursing Handover" && $field=="Bed") return "";
	if($table=="Nursing Handover" && $field=="Consultant") return "";
	if($table=="Nursing Handover" && $field=="Code") return "";
	if($table=="Nursing Handover" && $field=="Category") return "";
	if($table=="Nursing Handover" && $field=="Admission Date") return "";
	if($table=="Nursing Handover" && $field=="Diagnosis") return "";
	if($table=="Nursing Handover" && $field=="Allergies") return "";
	if($table=="Nursing Handover" && $field=="Notes") return "";
	if($table=="Nursing Handover" && $field=="Nurses") return "";
	if($table=="Nursing Handover" && $field=="Social Services") return "";
	if($table=="Nursing Handover" && $field=="Team") return "";
	if($table=="Nursing Handover" && $field=="Ward Round Notes") return "";

//	Current Patients
	if($table=="Current Patients" && $field=="Primary") return "";
	if($table=="Current Patients" && $field=="Patient Name") return "";
	if($table=="Current Patients" && $field=="Date of Birth") return "";
	if($table=="Current Patients" && $field=="Unit Number") return "";
	if($table=="Current Patients" && $field=="Sex") return "";
	if($table=="Current Patients" && $field=="Ward") return "";
	if($table=="Current Patients" && $field=="Bed") return "";
	if($table=="Current Patients" && $field=="Consultant") return "";
	if($table=="Current Patients" && $field=="Code") return "";
	if($table=="Current Patients" && $field=="Category") return "";
	if($table=="Current Patients" && $field=="Admission Date") return "";
	if($table=="Current Patients" && $field=="Diagnosis") return "";
	if($table=="Current Patients" && $field=="Allergies") return "";
	if($table=="Current Patients" && $field=="Notes") return "";
	if($table=="Current Patients" && $field=="Nurses") return "";
	if($table=="Current Patients" && $field=="Social Services") return "";
	if($table=="Current Patients" && $field=="Team") return "";
	if($table=="Current Patients" && $field=="Ward Round Notes") return "";

//	Current Jobs
	if($table=="Current Jobs" && $field=="Primary") return "";
	if($table=="Current Jobs" && $field=="Patient Name") return "";
	if($table=="Current Jobs" && $field=="Date") return "";
	if($table=="Current Jobs" && $field=="Type") return "";
	if($table=="Current Jobs" && $field=="Status") return "";
	if($table=="Current Jobs" && $field=="Name") return "";
	if($table=="Current Jobs" && $field=="Result") return "";
	if($table=="Current Jobs" && $field=="Notes") return "";
	if($table=="Current Jobs" && $field=="Consultant") return "";

//	Ward Round Sheet
	if($table=="Ward Round Sheet" && $field=="Primary") return "";
	if($table=="Ward Round Sheet" && $field=="Consultant") return "";
	if($table=="Ward Round Sheet" && $field=="Patient Name") return "";
	if($table=="Ward Round Sheet" && $field=="Date of Birth") return "";
	if($table=="Ward Round Sheet" && $field=="Unit Number") return "";
	if($table=="Ward Round Sheet" && $field=="Sex") return "";
	if($table=="Ward Round Sheet" && $field=="Ward") return "";
	if($table=="Ward Round Sheet" && $field=="Bed") return "";
	if($table=="Ward Round Sheet" && $field=="Code") return "";
	if($table=="Ward Round Sheet" && $field=="Category") return "";
	if($table=="Ward Round Sheet" && $field=="Admission Date") return "";
	if($table=="Ward Round Sheet" && $field=="Diagnosis") return "";
	if($table=="Ward Round Sheet" && $field=="Allergies") return "";
	if($table=="Ward Round Sheet" && $field=="Notes") return "";
	if($table=="Ward Round Sheet" && $field=="Nurses") return "";
	if($table=="Ward Round Sheet" && $field=="Social Services") return "";
	if($table=="Ward Round Sheet" && $field=="Team") return "";
	if($table=="Ward Round Sheet" && $field=="Ward Round Notes") return "";

//	Sign-Out Sheet
	if($table=="Sign-Out Sheet" && $field=="Primary") return "";
	if($table=="Sign-Out Sheet" && $field=="Patient Name") return "";
	if($table=="Sign-Out Sheet" && $field=="Date of Birth") return "";
	if($table=="Sign-Out Sheet" && $field=="Unit Number") return "";
	if($table=="Sign-Out Sheet" && $field=="Sex") return "";
	if($table=="Sign-Out Sheet" && $field=="Ward") return "";
	if($table=="Sign-Out Sheet" && $field=="Bed") return "";
	if($table=="Sign-Out Sheet" && $field=="Consultant") return "";
	if($table=="Sign-Out Sheet" && $field=="Code") return "";
	if($table=="Sign-Out Sheet" && $field=="Category") return "";
	if($table=="Sign-Out Sheet" && $field=="Admission Date") return "";
	if($table=="Sign-Out Sheet" && $field=="Diagnosis") return "";
	if($table=="Sign-Out Sheet" && $field=="Allergies") return "";
	if($table=="Sign-Out Sheet" && $field=="Notes") return "";
	if($table=="Sign-Out Sheet" && $field=="Nurses") return "";
	if($table=="Sign-Out Sheet" && $field=="Social Services") return "";
	if($table=="Sign-Out Sheet" && $field=="Team") return "";
	if($table=="Sign-Out Sheet" && $field=="Ward Round Notes") return "";

//	users
	if($table=="users" && $field=="Primary") return "";
	if($table=="users" && $field=="Login") return "";
	if($table=="users" && $field=="Name") return "";
	if($table=="users" && $field=="Password") return "";
	if($table=="users" && $field=="User Type") return "";

//	consultants
	if($table=="consultants" && $field=="Primary") return "";
	if($table=="consultants" && $field=="Consultant") return "";

//	ward list
	if($table=="ward list" && $field=="Primary") return "";
	if($table=="ward list" && $field=="Ward") return "";
	return "";
}

//	return hyperlink prefix
function GetLinkPrefix($field,$table="")
{
	global $strTableName;
	if(!$table)
		$table=$strTableName;

//	jobs
	if($table=="jobs" && $field=="Primary") return "";
	if($table=="jobs" && $field=="Patient Name") return "";
	if($table=="jobs" && $field=="Date") return "";
	if($table=="jobs" && $field=="Type") return "";
	if($table=="jobs" && $field=="Status") return "";
	if($table=="jobs" && $field=="Name") return "";
	if($table=="jobs" && $field=="Result") return "";
	if($table=="jobs" && $field=="Notes") return "";
	if($table=="jobs" && $field=="Consultant") return "";

//	patients
	if($table=="patients" && $field=="Primary") return "";
	if($table=="patients" && $field=="Patient Name") return "";
	if($table=="patients" && $field=="Date of Birth") return "";
	if($table=="patients" && $field=="Unit Number") return "";
	if($table=="patients" && $field=="Sex") return "";
	if($table=="patients" && $field=="Ward") return "";
	if($table=="patients" && $field=="Bed") return "";
	if($table=="patients" && $field=="Consultant") return "";
	if($table=="patients" && $field=="Code") return "";
	if($table=="patients" && $field=="Category") return "";
	if($table=="patients" && $field=="Admission Date") return "";
	if($table=="patients" && $field=="Diagnosis") return "";
	if($table=="patients" && $field=="Allergies") return "";
	if($table=="patients" && $field=="Notes") return "";
	if($table=="patients" && $field=="Nurses") return "";
	if($table=="patients" && $field=="Social Services") return "";
	if($table=="patients" && $field=="Team") return "";
	if($table=="patients" && $field=="Ward Round Notes") return "";

//	Nursing Handover
	if($table=="Nursing Handover" && $field=="Primary") return "";
	if($table=="Nursing Handover" && $field=="Patient Name") return "";
	if($table=="Nursing Handover" && $field=="Date of Birth") return "";
	if($table=="Nursing Handover" && $field=="Unit Number") return "";
	if($table=="Nursing Handover" && $field=="Sex") return "";
	if($table=="Nursing Handover" && $field=="Ward") return "";
	if($table=="Nursing Handover" && $field=="Bed") return "";
	if($table=="Nursing Handover" && $field=="Consultant") return "";
	if($table=="Nursing Handover" && $field=="Code") return "";
	if($table=="Nursing Handover" && $field=="Category") return "";
	if($table=="Nursing Handover" && $field=="Admission Date") return "";
	if($table=="Nursing Handover" && $field=="Diagnosis") return "";
	if($table=="Nursing Handover" && $field=="Allergies") return "";
	if($table=="Nursing Handover" && $field=="Notes") return "";
	if($table=="Nursing Handover" && $field=="Nurses") return "";
	if($table=="Nursing Handover" && $field=="Social Services") return "";
	if($table=="Nursing Handover" && $field=="Team") return "";
	if($table=="Nursing Handover" && $field=="Ward Round Notes") return "";

//	Current Patients
	if($table=="Current Patients" && $field=="Primary") return "";
	if($table=="Current Patients" && $field=="Patient Name") return "";
	if($table=="Current Patients" && $field=="Date of Birth") return "";
	if($table=="Current Patients" && $field=="Unit Number") return "";
	if($table=="Current Patients" && $field=="Sex") return "";
	if($table=="Current Patients" && $field=="Ward") return "";
	if($table=="Current Patients" && $field=="Bed") return "";
	if($table=="Current Patients" && $field=="Consultant") return "";
	if($table=="Current Patients" && $field=="Code") return "";
	if($table=="Current Patients" && $field=="Category") return "";
	if($table=="Current Patients" && $field=="Admission Date") return "";
	if($table=="Current Patients" && $field=="Diagnosis") return "";
	if($table=="Current Patients" && $field=="Allergies") return "";
	if($table=="Current Patients" && $field=="Notes") return "";
	if($table=="Current Patients" && $field=="Nurses") return "";
	if($table=="Current Patients" && $field=="Social Services") return "";
	if($table=="Current Patients" && $field=="Team") return "";
	if($table=="Current Patients" && $field=="Ward Round Notes") return "";

//	Current Jobs
	if($table=="Current Jobs" && $field=="Primary") return "";
	if($table=="Current Jobs" && $field=="Patient Name") return "";
	if($table=="Current Jobs" && $field=="Date") return "";
	if($table=="Current Jobs" && $field=="Type") return "";
	if($table=="Current Jobs" && $field=="Status") return "";
	if($table=="Current Jobs" && $field=="Name") return "";
	if($table=="Current Jobs" && $field=="Result") return "";
	if($table=="Current Jobs" && $field=="Notes") return "";
	if($table=="Current Jobs" && $field=="Consultant") return "";

//	Ward Round Sheet
	if($table=="Ward Round Sheet" && $field=="Primary") return "";
	if($table=="Ward Round Sheet" && $field=="Consultant") return "";
	if($table=="Ward Round Sheet" && $field=="Patient Name") return "";
	if($table=="Ward Round Sheet" && $field=="Date of Birth") return "";
	if($table=="Ward Round Sheet" && $field=="Unit Number") return "";
	if($table=="Ward Round Sheet" && $field=="Sex") return "";
	if($table=="Ward Round Sheet" && $field=="Ward") return "";
	if($table=="Ward Round Sheet" && $field=="Bed") return "";
	if($table=="Ward Round Sheet" && $field=="Code") return "";
	if($table=="Ward Round Sheet" && $field=="Category") return "";
	if($table=="Ward Round Sheet" && $field=="Admission Date") return "";
	if($table=="Ward Round Sheet" && $field=="Diagnosis") return "";
	if($table=="Ward Round Sheet" && $field=="Allergies") return "";
	if($table=="Ward Round Sheet" && $field=="Notes") return "";
	if($table=="Ward Round Sheet" && $field=="Nurses") return "";
	if($table=="Ward Round Sheet" && $field=="Social Services") return "";
	if($table=="Ward Round Sheet" && $field=="Team") return "";
	if($table=="Ward Round Sheet" && $field=="Ward Round Notes") return "";

//	Sign-Out Sheet
	if($table=="Sign-Out Sheet" && $field=="Primary") return "";
	if($table=="Sign-Out Sheet" && $field=="Patient Name") return "";
	if($table=="Sign-Out Sheet" && $field=="Date of Birth") return "";
	if($table=="Sign-Out Sheet" && $field=="Unit Number") return "";
	if($table=="Sign-Out Sheet" && $field=="Sex") return "";
	if($table=="Sign-Out Sheet" && $field=="Ward") return "";
	if($table=="Sign-Out Sheet" && $field=="Bed") return "";
	if($table=="Sign-Out Sheet" && $field=="Consultant") return "";
	if($table=="Sign-Out Sheet" && $field=="Code") return "";
	if($table=="Sign-Out Sheet" && $field=="Category") return "";
	if($table=="Sign-Out Sheet" && $field=="Admission Date") return "";
	if($table=="Sign-Out Sheet" && $field=="Diagnosis") return "";
	if($table=="Sign-Out Sheet" && $field=="Allergies") return "";
	if($table=="Sign-Out Sheet" && $field=="Notes") return "";
	if($table=="Sign-Out Sheet" && $field=="Nurses") return "";
	if($table=="Sign-Out Sheet" && $field=="Social Services") return "";
	if($table=="Sign-Out Sheet" && $field=="Team") return "";
	if($table=="Sign-Out Sheet" && $field=="Ward Round Notes") return "";

//	users
	if($table=="users" && $field=="Primary") return "";
	if($table=="users" && $field=="Login") return "";
	if($table=="users" && $field=="Name") return "";
	if($table=="users" && $field=="Password") return "";
	if($table=="users" && $field=="User Type") return "";

//	consultants
	if($table=="consultants" && $field=="Primary") return "";
	if($table=="consultants" && $field=="Consultant") return "";

//	ward list
	if($table=="ward list" && $field=="Primary") return "";
	if($table=="ward list" && $field=="Ward") return "";
	return "";
}

//	return database field type
//	using ADO DataTypeEnum constants
//	the full list available at:
//	http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdcstdatatypeenum.asp
function GetFieldType($field,$table="")
{
	global $strTableName;
	if(!$table)
		$table=$strTableName;

//	jobs
	if($table=="jobs" && $field=="Primary") return 2;
	if($table=="jobs" && $field=="Patient Name") return 201;
	if($table=="jobs" && $field=="Date") return 7;
	if($table=="jobs" && $field=="Type") return 201;
	if($table=="jobs" && $field=="Status") return 201;
	if($table=="jobs" && $field=="Name") return 201;
	if($table=="jobs" && $field=="Result") return 201;
	if($table=="jobs" && $field=="Notes") return 201;
	if($table=="jobs" && $field=="Consultant") return 201;

//	patients
	if($table=="patients" && $field=="Primary") return 2;
	if($table=="patients" && $field=="Patient Name") return 201;
	if($table=="patients" && $field=="Date of Birth") return 7;
	if($table=="patients" && $field=="Unit Number") return 201;
	if($table=="patients" && $field=="Sex") return 201;
	if($table=="patients" && $field=="Ward") return 201;
	if($table=="patients" && $field=="Bed") return 201;
	if($table=="patients" && $field=="Consultant") return 201;
	if($table=="patients" && $field=="Code") return 201;
	if($table=="patients" && $field=="Category") return 201;
	if($table=="patients" && $field=="Admission Date") return 7;
	if($table=="patients" && $field=="Diagnosis") return 201;
	if($table=="patients" && $field=="Allergies") return 201;
	if($table=="patients" && $field=="Notes") return 201;
	if($table=="patients" && $field=="Nurses") return 201;
	if($table=="patients" && $field=="Social Services") return 201;
	if($table=="patients" && $field=="Team") return 201;
	if($table=="patients" && $field=="Ward Round Notes") return 201;

//	Nursing Handover
	if($table=="Nursing Handover" && $field=="Primary") return 2;
	if($table=="Nursing Handover" && $field=="Patient Name") return 201;
	if($table=="Nursing Handover" && $field=="Date of Birth") return 7;
	if($table=="Nursing Handover" && $field=="Unit Number") return 201;
	if($table=="Nursing Handover" && $field=="Sex") return 201;
	if($table=="Nursing Handover" && $field=="Ward") return 201;
	if($table=="Nursing Handover" && $field=="Bed") return 201;
	if($table=="Nursing Handover" && $field=="Consultant") return 201;
	if($table=="Nursing Handover" && $field=="Code") return 201;
	if($table=="Nursing Handover" && $field=="Category") return 201;
	if($table=="Nursing Handover" && $field=="Admission Date") return 7;
	if($table=="Nursing Handover" && $field=="Diagnosis") return 201;
	if($table=="Nursing Handover" && $field=="Allergies") return 201;
	if($table=="Nursing Handover" && $field=="Notes") return 201;
	if($table=="Nursing Handover" && $field=="Nurses") return 201;
	if($table=="Nursing Handover" && $field=="Social Services") return 201;
	if($table=="Nursing Handover" && $field=="Team") return 201;
	if($table=="Nursing Handover" && $field=="Ward Round Notes") return 201;

//	Current Patients
	if($table=="Current Patients" && $field=="Primary") return 2;
	if($table=="Current Patients" && $field=="Patient Name") return 201;
	if($table=="Current Patients" && $field=="Date of Birth") return 7;
	if($table=="Current Patients" && $field=="Unit Number") return 201;
	if($table=="Current Patients" && $field=="Sex") return 201;
	if($table=="Current Patients" && $field=="Ward") return 201;
	if($table=="Current Patients" && $field=="Bed") return 201;
	if($table=="Current Patients" && $field=="Consultant") return 201;
	if($table=="Current Patients" && $field=="Code") return 201;
	if($table=="Current Patients" && $field=="Category") return 201;
	if($table=="Current Patients" && $field=="Admission Date") return 7;
	if($table=="Current Patients" && $field=="Diagnosis") return 201;
	if($table=="Current Patients" && $field=="Allergies") return 201;
	if($table=="Current Patients" && $field=="Notes") return 201;
	if($table=="Current Patients" && $field=="Nurses") return 201;
	if($table=="Current Patients" && $field=="Social Services") return 201;
	if($table=="Current Patients" && $field=="Team") return 201;
	if($table=="Current Patients" && $field=="Ward Round Notes") return 201;

//	Current Jobs
	if($table=="Current Jobs" && $field=="Primary") return 2;
	if($table=="Current Jobs" && $field=="Patient Name") return 201;
	if($table=="Current Jobs" && $field=="Date") return 7;
	if($table=="Current Jobs" && $field=="Type") return 201;
	if($table=="Current Jobs" && $field=="Status") return 201;
	if($table=="Current Jobs" && $field=="Name") return 201;
	if($table=="Current Jobs" && $field=="Result") return 201;
	if($table=="Current Jobs" && $field=="Notes") return 201;
	if($table=="Current Jobs" && $field=="Consultant") return 201;

//	Ward Round Sheet
	if($table=="Ward Round Sheet" && $field=="Primary") return 2;
	if($table=="Ward Round Sheet" && $field=="Consultant") return 201;
	if($table=="Ward Round Sheet" && $field=="Patient Name") return 201;
	if($table=="Ward Round Sheet" && $field=="Date of Birth") return 7;
	if($table=="Ward Round Sheet" && $field=="Unit Number") return 201;
	if($table=="Ward Round Sheet" && $field=="Sex") return 201;
	if($table=="Ward Round Sheet" && $field=="Ward") return 201;
	if($table=="Ward Round Sheet" && $field=="Bed") return 201;
	if($table=="Ward Round Sheet" && $field=="Code") return 201;
	if($table=="Ward Round Sheet" && $field=="Category") return 201;
	if($table=="Ward Round Sheet" && $field=="Admission Date") return 7;
	if($table=="Ward Round Sheet" && $field=="Diagnosis") return 201;
	if($table=="Ward Round Sheet" && $field=="Allergies") return 201;
	if($table=="Ward Round Sheet" && $field=="Notes") return 201;
	if($table=="Ward Round Sheet" && $field=="Nurses") return 201;
	if($table=="Ward Round Sheet" && $field=="Social Services") return 201;
	if($table=="Ward Round Sheet" && $field=="Team") return 201;
	if($table=="Ward Round Sheet" && $field=="Ward Round Notes") return 201;

//	Sign-Out Sheet
	if($table=="Sign-Out Sheet" && $field=="Primary") return 2;
	if($table=="Sign-Out Sheet" && $field=="Patient Name") return 201;
	if($table=="Sign-Out Sheet" && $field=="Date of Birth") return 7;
	if($table=="Sign-Out Sheet" && $field=="Unit Number") return 201;
	if($table=="Sign-Out Sheet" && $field=="Sex") return 201;
	if($table=="Sign-Out Sheet" && $field=="Ward") return 201;
	if($table=="Sign-Out Sheet" && $field=="Bed") return 201;
	if($table=="Sign-Out Sheet" && $field=="Consultant") return 201;
	if($table=="Sign-Out Sheet" && $field=="Code") return 201;
	if($table=="Sign-Out Sheet" && $field=="Category") return 201;
	if($table=="Sign-Out Sheet" && $field=="Admission Date") return 7;
	if($table=="Sign-Out Sheet" && $field=="Diagnosis") return 201;
	if($table=="Sign-Out Sheet" && $field=="Allergies") return 201;
	if($table=="Sign-Out Sheet" && $field=="Notes") return 201;
	if($table=="Sign-Out Sheet" && $field=="Nurses") return 201;
	if($table=="Sign-Out Sheet" && $field=="Social Services") return 201;
	if($table=="Sign-Out Sheet" && $field=="Team") return 201;
	if($table=="Sign-Out Sheet" && $field=="Ward Round Notes") return 201;

//	users
	if($table=="users" && $field=="Primary") return 2;
	if($table=="users" && $field=="Login") return 201;
	if($table=="users" && $field=="Name") return 201;
	if($table=="users" && $field=="Password") return 201;
	if($table=="users" && $field=="User Type") return 201;

//	consultants
	if($table=="consultants" && $field=="Primary") return 2;
	if($table=="consultants" && $field=="Consultant") return 201;

//	ward list
	if($table=="ward list" && $field=="Primary") return 2;
	if($table=="ward list" && $field=="Ward") return 201;
	return "";
}

//	return Edit format
function GetEditFormat($field,$table="")
{
	global $strTableName;
	if(!$table)
		$table=$strTableName;

//	jobs
	if($table=="jobs" && $field=="Primary") return "Text field";
	if($table=="jobs" && $field=="Patient Name") return "Text area";
	if($table=="jobs" && $field=="Date") return "Date";
	if($table=="jobs" && $field=="Type") return "Text area";
	if($table=="jobs" && $field=="Status") return "Text area";
	if($table=="jobs" && $field=="Name") return "Text area";
	if($table=="jobs" && $field=="Result") return "Text area";
	if($table=="jobs" && $field=="Notes") return "Text area";
	if($table=="jobs" && $field=="Consultant") return "Text area";

//	patients
	if($table=="patients" && $field=="Primary") return "Text field";
	if($table=="patients" && $field=="Patient Name") return "Text area";
	if($table=="patients" && $field=="Date of Birth") return "Date";
	if($table=="patients" && $field=="Unit Number") return "Text area";
	if($table=="patients" && $field=="Sex") return "Text area";
	if($table=="patients" && $field=="Ward") return "Text area";
	if($table=="patients" && $field=="Bed") return "Text area";
	if($table=="patients" && $field=="Consultant") return "Text area";
	if($table=="patients" && $field=="Code") return "Text area";
	if($table=="patients" && $field=="Category") return "Text area";
	if($table=="patients" && $field=="Admission Date") return "Date";
	if($table=="patients" && $field=="Diagnosis") return "Text area";
	if($table=="patients" && $field=="Allergies") return "Text area";
	if($table=="patients" && $field=="Notes") return "Text area";
	if($table=="patients" && $field=="Nurses") return "Text area";
	if($table=="patients" && $field=="Social Services") return "Text area";
	if($table=="patients" && $field=="Team") return "Text area";
	if($table=="patients" && $field=="Ward Round Notes") return "Text area";

//	Nursing Handover
	if($table=="Nursing Handover" && $field=="Primary") return "Text field";
	if($table=="Nursing Handover" && $field=="Patient Name") return "Text field";
	if($table=="Nursing Handover" && $field=="Date of Birth") return "Date";
	if($table=="Nursing Handover" && $field=="Unit Number") return "Text field";
	if($table=="Nursing Handover" && $field=="Sex") return "Lookup wizard";
	if($table=="Nursing Handover" && $field=="Ward") return "Lookup wizard";
	if($table=="Nursing Handover" && $field=="Bed") return "Text field";
	if($table=="Nursing Handover" && $field=="Consultant") return "Lookup wizard";
	if($table=="Nursing Handover" && $field=="Code") return "Lookup wizard";
	if($table=="Nursing Handover" && $field=="Category") return "Text area";
	if($table=="Nursing Handover" && $field=="Admission Date") return "Date";
	if($table=="Nursing Handover" && $field=="Diagnosis") return "Text area";
	if($table=="Nursing Handover" && $field=="Allergies") return "Text field";
	if($table=="Nursing Handover" && $field=="Notes") return "Text area";
	if($table=="Nursing Handover" && $field=="Nurses") return "Text field";
	if($table=="Nursing Handover" && $field=="Social Services") return "Text field";
	if($table=="Nursing Handover" && $field=="Team") return "Text field";
	if($table=="Nursing Handover" && $field=="Ward Round Notes") return "Text area";

//	Current Patients
	if($table=="Current Patients" && $field=="Primary") return "Text field";
	if($table=="Current Patients" && $field=="Patient Name") return "Text field";
	if($table=="Current Patients" && $field=="Date of Birth") return "Date";
	if($table=="Current Patients" && $field=="Unit Number") return "Text field";
	if($table=="Current Patients" && $field=="Sex") return "Lookup wizard";
	if($table=="Current Patients" && $field=="Ward") return "Lookup wizard";
	if($table=="Current Patients" && $field=="Bed") return "Text field";
	if($table=="Current Patients" && $field=="Consultant") return "Lookup wizard";
	if($table=="Current Patients" && $field=="Code") return "Lookup wizard";
	if($table=="Current Patients" && $field=="Category") return "Lookup wizard";
	if($table=="Current Patients" && $field=="Admission Date") return "Date";
	if($table=="Current Patients" && $field=="Diagnosis") return "Text area";
	if($table=="Current Patients" && $field=="Allergies") return "Text field";
	if($table=="Current Patients" && $field=="Notes") return "Text area";
	if($table=="Current Patients" && $field=="Nurses") return "Text field";
	if($table=="Current Patients" && $field=="Social Services") return "Text field";
	if($table=="Current Patients" && $field=="Team") return "Text field";
	if($table=="Current Patients" && $field=="Ward Round Notes") return "Text area";

//	Current Jobs
	if($table=="Current Jobs" && $field=="Primary") return "Text field";
	if($table=="Current Jobs" && $field=="Patient Name") return "Readonly";
	if($table=="Current Jobs" && $field=="Date") return "Date";
	if($table=="Current Jobs" && $field=="Type") return "Lookup wizard";
	if($table=="Current Jobs" && $field=="Status") return "Lookup wizard";
	if($table=="Current Jobs" && $field=="Name") return "Text field";
	if($table=="Current Jobs" && $field=="Result") return "Text area";
	if($table=="Current Jobs" && $field=="Notes") return "Text area";
	if($table=="Current Jobs" && $field=="Consultant") return "Lookup wizard";

//	Ward Round Sheet
	if($table=="Ward Round Sheet" && $field=="Primary") return "Text field";
	if($table=="Ward Round Sheet" && $field=="Consultant") return "Text area";
	if($table=="Ward Round Sheet" && $field=="Patient Name") return "Text area";
	if($table=="Ward Round Sheet" && $field=="Date of Birth") return "Date";
	if($table=="Ward Round Sheet" && $field=="Unit Number") return "Text area";
	if($table=="Ward Round Sheet" && $field=="Sex") return "Text area";
	if($table=="Ward Round Sheet" && $field=="Ward") return "Text area";
	if($table=="Ward Round Sheet" && $field=="Bed") return "Text area";
	if($table=="Ward Round Sheet" && $field=="Code") return "Text area";
	if($table=="Ward Round Sheet" && $field=="Category") return "Text area";
	if($table=="Ward Round Sheet" && $field=="Admission Date") return "Date";
	if($table=="Ward Round Sheet" && $field=="Diagnosis") return "Text area";
	if($table=="Ward Round Sheet" && $field=="Allergies") return "Text area";
	if($table=="Ward Round Sheet" && $field=="Notes") return "Text area";
	if($table=="Ward Round Sheet" && $field=="Nurses") return "Text area";
	if($table=="Ward Round Sheet" && $field=="Social Services") return "Text area";
	if($table=="Ward Round Sheet" && $field=="Team") return "Text area";
	if($table=="Ward Round Sheet" && $field=="Ward Round Notes") return "Text area";

//	Sign-Out Sheet
	if($table=="Sign-Out Sheet" && $field=="Primary") return "Text field";
	if($table=="Sign-Out Sheet" && $field=="Patient Name") return "Text area";
	if($table=="Sign-Out Sheet" && $field=="Date of Birth") return "Date";
	if($table=="Sign-Out Sheet" && $field=="Unit Number") return "Text area";
	if($table=="Sign-Out Sheet" && $field=="Sex") return "Text area";
	if($table=="Sign-Out Sheet" && $field=="Ward") return "Text area";
	if($table=="Sign-Out Sheet" && $field=="Bed") return "Text area";
	if($table=="Sign-Out Sheet" && $field=="Consultant") return "Text area";
	if($table=="Sign-Out Sheet" && $field=="Code") return "Text area";
	if($table=="Sign-Out Sheet" && $field=="Category") return "Text area";
	if($table=="Sign-Out Sheet" && $field=="Admission Date") return "Date";
	if($table=="Sign-Out Sheet" && $field=="Diagnosis") return "Text area";
	if($table=="Sign-Out Sheet" && $field=="Allergies") return "Text area";
	if($table=="Sign-Out Sheet" && $field=="Notes") return "Text area";
	if($table=="Sign-Out Sheet" && $field=="Nurses") return "Text area";
	if($table=="Sign-Out Sheet" && $field=="Social Services") return "Text area";
	if($table=="Sign-Out Sheet" && $field=="Team") return "Text area";
	if($table=="Sign-Out Sheet" && $field=="Ward Round Notes") return "Text area";

//	users
	if($table=="users" && $field=="Primary") return "Text field";
	if($table=="users" && $field=="Login") return "Text field";
	if($table=="users" && $field=="Name") return "Text field";
	if($table=="users" && $field=="Password") return "Text field";
	if($table=="users" && $field=="User Type") return "Lookup wizard";

//	consultants
	if($table=="consultants" && $field=="Primary") return "Text field";
	if($table=="consultants" && $field=="Consultant") return "Text field";

//	ward list
	if($table=="ward list" && $field=="Primary") return "Text field";
	if($table=="ward list" && $field=="Ward") return "Text field";
	return "";
}

//	return View format
function Format($field,$table="")
{
	global $strTableName;
	if(!$table)
		$table=$strTableName;

//	jobs
	if($table=="jobs" && $field=="Primary") return "";
	if($table=="jobs" && $field=="Patient Name") return "";
	if($table=="jobs" && $field=="Date") return "Short Date";
	if($table=="jobs" && $field=="Type") return "";
	if($table=="jobs" && $field=="Status") return "";
	if($table=="jobs" && $field=="Name") return "";
	if($table=="jobs" && $field=="Result") return "";
	if($table=="jobs" && $field=="Notes") return "";
	if($table=="jobs" && $field=="Consultant") return "";

//	patients
	if($table=="patients" && $field=="Primary") return "";
	if($table=="patients" && $field=="Patient Name") return "";
	if($table=="patients" && $field=="Date of Birth") return "Short Date";
	if($table=="patients" && $field=="Unit Number") return "";
	if($table=="patients" && $field=="Sex") return "";
	if($table=="patients" && $field=="Ward") return "";
	if($table=="patients" && $field=="Bed") return "";
	if($table=="patients" && $field=="Consultant") return "";
	if($table=="patients" && $field=="Code") return "";
	if($table=="patients" && $field=="Category") return "";
	if($table=="patients" && $field=="Admission Date") return "Short Date";
	if($table=="patients" && $field=="Diagnosis") return "";
	if($table=="patients" && $field=="Allergies") return "";
	if($table=="patients" && $field=="Notes") return "";
	if($table=="patients" && $field=="Nurses") return "";
	if($table=="patients" && $field=="Social Services") return "";
	if($table=="patients" && $field=="Team") return "";
	if($table=="patients" && $field=="Ward Round Notes") return "";

//	Nursing Handover
	if($table=="Nursing Handover" && $field=="Primary") return "";
	if($table=="Nursing Handover" && $field=="Patient Name") return "";
	if($table=="Nursing Handover" && $field=="Date of Birth") return "Short Date";
	if($table=="Nursing Handover" && $field=="Unit Number") return "";
	if($table=="Nursing Handover" && $field=="Sex") return "";
	if($table=="Nursing Handover" && $field=="Ward") return "";
	if($table=="Nursing Handover" && $field=="Bed") return "";
	if($table=="Nursing Handover" && $field=="Consultant") return "";
	if($table=="Nursing Handover" && $field=="Code") return "";
	if($table=="Nursing Handover" && $field=="Category") return "";
	if($table=="Nursing Handover" && $field=="Admission Date") return "Short Date";
	if($table=="Nursing Handover" && $field=="Diagnosis") return "";
	if($table=="Nursing Handover" && $field=="Allergies") return "";
	if($table=="Nursing Handover" && $field=="Notes") return "";
	if($table=="Nursing Handover" && $field=="Nurses") return "";
	if($table=="Nursing Handover" && $field=="Social Services") return "";
	if($table=="Nursing Handover" && $field=="Team") return "";
	if($table=="Nursing Handover" && $field=="Ward Round Notes") return "";

//	Current Patients
	if($table=="Current Patients" && $field=="Primary") return "";
	if($table=="Current Patients" && $field=="Patient Name") return "";
	if($table=="Current Patients" && $field=="Date of Birth") return "Short Date";
	if($table=="Current Patients" && $field=="Unit Number") return "";
	if($table=="Current Patients" && $field=="Sex") return "";
	if($table=="Current Patients" && $field=="Ward") return "";
	if($table=="Current Patients" && $field=="Bed") return "";
	if($table=="Current Patients" && $field=="Consultant") return "";
	if($table=="Current Patients" && $field=="Code") return "";
	if($table=="Current Patients" && $field=="Category") return "";
	if($table=="Current Patients" && $field=="Admission Date") return "Short Date";
	if($table=="Current Patients" && $field=="Diagnosis") return "";
	if($table=="Current Patients" && $field=="Allergies") return "";
	if($table=="Current Patients" && $field=="Notes") return "";
	if($table=="Current Patients" && $field=="Nurses") return "";
	if($table=="Current Patients" && $field=="Social Services") return "";
	if($table=="Current Patients" && $field=="Team") return "";
	if($table=="Current Patients" && $field=="Ward Round Notes") return "";

//	Current Jobs
	if($table=="Current Jobs" && $field=="Primary") return "";
	if($table=="Current Jobs" && $field=="Patient Name") return "";
	if($table=="Current Jobs" && $field=="Date") return "Short Date";
	if($table=="Current Jobs" && $field=="Type") return "";
	if($table=="Current Jobs" && $field=="Status") return "";
	if($table=="Current Jobs" && $field=="Name") return "";
	if($table=="Current Jobs" && $field=="Result") return "";
	if($table=="Current Jobs" && $field=="Notes") return "";
	if($table=="Current Jobs" && $field=="Consultant") return "";

//	Ward Round Sheet
	if($table=="Ward Round Sheet" && $field=="Primary") return "";
	if($table=="Ward Round Sheet" && $field=="Consultant") return "";
	if($table=="Ward Round Sheet" && $field=="Patient Name") return "";
	if($table=="Ward Round Sheet" && $field=="Date of Birth") return "Short Date";
	if($table=="Ward Round Sheet" && $field=="Unit Number") return "";
	if($table=="Ward Round Sheet" && $field=="Sex") return "";
	if($table=="Ward Round Sheet" && $field=="Ward") return "";
	if($table=="Ward Round Sheet" && $field=="Bed") return "";
	if($table=="Ward Round Sheet" && $field=="Code") return "";
	if($table=="Ward Round Sheet" && $field=="Category") return "";
	if($table=="Ward Round Sheet" && $field=="Admission Date") return "Short Date";
	if($table=="Ward Round Sheet" && $field=="Diagnosis") return "";
	if($table=="Ward Round Sheet" && $field=="Allergies") return "";
	if($table=="Ward Round Sheet" && $field=="Notes") return "";
	if($table=="Ward Round Sheet" && $field=="Nurses") return "";
	if($table=="Ward Round Sheet" && $field=="Social Services") return "";
	if($table=="Ward Round Sheet" && $field=="Team") return "";
	if($table=="Ward Round Sheet" && $field=="Ward Round Notes") return "";

//	Sign-Out Sheet
	if($table=="Sign-Out Sheet" && $field=="Primary") return "";
	if($table=="Sign-Out Sheet" && $field=="Patient Name") return "";
	if($table=="Sign-Out Sheet" && $field=="Date of Birth") return "Short Date";
	if($table=="Sign-Out Sheet" && $field=="Unit Number") return "";
	if($table=="Sign-Out Sheet" && $field=="Sex") return "";
	if($table=="Sign-Out Sheet" && $field=="Ward") return "";
	if($table=="Sign-Out Sheet" && $field=="Bed") return "";
	if($table=="Sign-Out Sheet" && $field=="Consultant") return "";
	if($table=="Sign-Out Sheet" && $field=="Code") return "";
	if($table=="Sign-Out Sheet" && $field=="Category") return "";
	if($table=="Sign-Out Sheet" && $field=="Admission Date") return "Short Date";
	if($table=="Sign-Out Sheet" && $field=="Diagnosis") return "";
	if($table=="Sign-Out Sheet" && $field=="Allergies") return "";
	if($table=="Sign-Out Sheet" && $field=="Notes") return "";
	if($table=="Sign-Out Sheet" && $field=="Nurses") return "";
	if($table=="Sign-Out Sheet" && $field=="Social Services") return "";
	if($table=="Sign-Out Sheet" && $field=="Team") return "";
	if($table=="Sign-Out Sheet" && $field=="Ward Round Notes") return "";

//	users
	if($table=="users" && $field=="Primary") return "";
	if($table=="users" && $field=="Login") return "";
	if($table=="users" && $field=="Name") return "";
	if($table=="users" && $field=="Password") return "";
	if($table=="users" && $field=="User Type") return "";

//	consultants
	if($table=="consultants" && $field=="Primary") return "";
	if($table=="consultants" && $field=="Consultant") return "";

//	ward list
	if($table=="ward list" && $field=="Primary") return "";
	if($table=="ward list" && $field=="Ward") return "";
	return "";
}

//	show time in datepicker or not
function DateEditShowTime($field,$table="")
{
	global $strTableName;
	if(!$table)
		$table=$strTableName;

//	jobs
	if($table=="jobs" && $field=="Primary") 
				return false;

	if($table=="jobs" && $field=="Patient Name") 
				return false;

	if($table=="jobs" && $field=="Date") 
				return false;

	if($table=="jobs" && $field=="Type") 
				return false;

	if($table=="jobs" && $field=="Status") 
				return false;

	if($table=="jobs" && $field=="Name") 
				return false;

	if($table=="jobs" && $field=="Result") 
				return false;

	if($table=="jobs" && $field=="Notes") 
				return false;

	if($table=="jobs" && $field=="Consultant") 
				return false;


//	patients
	if($table=="patients" && $field=="Primary") 
				return false;

	if($table=="patients" && $field=="Patient Name") 
				return false;

	if($table=="patients" && $field=="Date of Birth") 
				return false;

	if($table=="patients" && $field=="Unit Number") 
				return false;

	if($table=="patients" && $field=="Sex") 
				return false;

	if($table=="patients" && $field=="Ward") 
				return false;

	if($table=="patients" && $field=="Bed") 
				return false;

	if($table=="patients" && $field=="Consultant") 
				return false;

	if($table=="patients" && $field=="Code") 
				return false;

	if($table=="patients" && $field=="Category") 
				return false;

	if($table=="patients" && $field=="Admission Date") 
				return false;

	if($table=="patients" && $field=="Diagnosis") 
				return false;

	if($table=="patients" && $field=="Allergies") 
				return false;

	if($table=="patients" && $field=="Notes") 
				return false;

	if($table=="patients" && $field=="Nurses") 
				return false;

	if($table=="patients" && $field=="Social Services") 
				return false;

	if($table=="patients" && $field=="Team") 
				return false;

	if($table=="patients" && $field=="Ward Round Notes") 
				return false;


//	Nursing Handover
	if($table=="Nursing Handover" && $field=="Primary") 
				return false;

	if($table=="Nursing Handover" && $field=="Patient Name") 
				return false;

	if($table=="Nursing Handover" && $field=="Date of Birth") 
				return false;

	if($table=="Nursing Handover" && $field=="Unit Number") 
				return false;

	if($table=="Nursing Handover" && $field=="Sex") 
				return false;

	if($table=="Nursing Handover" && $field=="Ward") 
				return false;

	if($table=="Nursing Handover" && $field=="Bed") 
				return false;

	if($table=="Nursing Handover" && $field=="Consultant") 
				return false;

	if($table=="Nursing Handover" && $field=="Code") 
				return false;

	if($table=="Nursing Handover" && $field=="Category") 
				return false;

	if($table=="Nursing Handover" && $field=="Admission Date") 
				return false;

	if($table=="Nursing Handover" && $field=="Diagnosis") 
				return false;

	if($table=="Nursing Handover" && $field=="Allergies") 
				return false;

	if($table=="Nursing Handover" && $field=="Notes") 
				return false;

	if($table=="Nursing Handover" && $field=="Nurses") 
				return false;

	if($table=="Nursing Handover" && $field=="Social Services") 
				return false;

	if($table=="Nursing Handover" && $field=="Team") 
				return false;

	if($table=="Nursing Handover" && $field=="Ward Round Notes") 
				return false;


//	Current Patients
	if($table=="Current Patients" && $field=="Primary") 
				return false;

	if($table=="Current Patients" && $field=="Patient Name") 
				return false;

	if($table=="Current Patients" && $field=="Date of Birth") 
				return false;

	if($table=="Current Patients" && $field=="Unit Number") 
				return false;

	if($table=="Current Patients" && $field=="Sex") 
				return false;

	if($table=="Current Patients" && $field=="Ward") 
				return false;

	if($table=="Current Patients" && $field=="Bed") 
				return false;

	if($table=="Current Patients" && $field=="Consultant") 
				return false;

	if($table=="Current Patients" && $field=="Code") 
				return false;

	if($table=="Current Patients" && $field=="Category") 
				return false;

	if($table=="Current Patients" && $field=="Admission Date") 
				return false;

	if($table=="Current Patients" && $field=="Diagnosis") 
				return false;

	if($table=="Current Patients" && $field=="Allergies") 
				return false;

	if($table=="Current Patients" && $field=="Notes") 
				return false;

	if($table=="Current Patients" && $field=="Nurses") 
				return false;

	if($table=="Current Patients" && $field=="Social Services") 
				return false;

	if($table=="Current Patients" && $field=="Team") 
				return false;

	if($table=="Current Patients" && $field=="Ward Round Notes") 
				return false;


//	Current Jobs
	if($table=="Current Jobs" && $field=="Primary") 
				return false;

	if($table=="Current Jobs" && $field=="Patient Name") 
				return false;

	if($table=="Current Jobs" && $field=="Date") 
				return false;

	if($table=="Current Jobs" && $field=="Type") 
				return false;

	if($table=="Current Jobs" && $field=="Status") 
				return false;

	if($table=="Current Jobs" && $field=="Name") 
				return false;

	if($table=="Current Jobs" && $field=="Result") 
				return false;

	if($table=="Current Jobs" && $field=="Notes") 
				return false;

	if($table=="Current Jobs" && $field=="Consultant") 
				return false;


//	Ward Round Sheet
	if($table=="Ward Round Sheet" && $field=="Primary") 
				return false;

	if($table=="Ward Round Sheet" && $field=="Consultant") 
				return false;

	if($table=="Ward Round Sheet" && $field=="Patient Name") 
				return false;

	if($table=="Ward Round Sheet" && $field=="Date of Birth") 
				return false;

	if($table=="Ward Round Sheet" && $field=="Unit Number") 
				return false;

	if($table=="Ward Round Sheet" && $field=="Sex") 
				return false;

	if($table=="Ward Round Sheet" && $field=="Ward") 
				return false;

	if($table=="Ward Round Sheet" && $field=="Bed") 
				return false;

	if($table=="Ward Round Sheet" && $field=="Code") 
				return false;

	if($table=="Ward Round Sheet" && $field=="Category") 
				return false;

	if($table=="Ward Round Sheet" && $field=="Admission Date") 
				return false;

	if($table=="Ward Round Sheet" && $field=="Diagnosis") 
				return false;

	if($table=="Ward Round Sheet" && $field=="Allergies") 
				return false;

	if($table=="Ward Round Sheet" && $field=="Notes") 
				return false;

	if($table=="Ward Round Sheet" && $field=="Nurses") 
				return false;

	if($table=="Ward Round Sheet" && $field=="Social Services") 
				return false;

	if($table=="Ward Round Sheet" && $field=="Team") 
				return false;

	if($table=="Ward Round Sheet" && $field=="Ward Round Notes") 
				return false;


//	Sign-Out Sheet
	if($table=="Sign-Out Sheet" && $field=="Primary") 
				return false;

	if($table=="Sign-Out Sheet" && $field=="Patient Name") 
				return false;

	if($table=="Sign-Out Sheet" && $field=="Date of Birth") 
				return false;

	if($table=="Sign-Out Sheet" && $field=="Unit Number") 
				return false;

	if($table=="Sign-Out Sheet" && $field=="Sex") 
				return false;

	if($table=="Sign-Out Sheet" && $field=="Ward") 
				return false;

	if($table=="Sign-Out Sheet" && $field=="Bed") 
				return false;

	if($table=="Sign-Out Sheet" && $field=="Consultant") 
				return false;

	if($table=="Sign-Out Sheet" && $field=="Code") 
				return false;

	if($table=="Sign-Out Sheet" && $field=="Category") 
				return false;

	if($table=="Sign-Out Sheet" && $field=="Admission Date") 
				return false;

	if($table=="Sign-Out Sheet" && $field=="Diagnosis") 
				return false;

	if($table=="Sign-Out Sheet" && $field=="Allergies") 
				return false;

	if($table=="Sign-Out Sheet" && $field=="Notes") 
				return false;

	if($table=="Sign-Out Sheet" && $field=="Nurses") 
				return false;

	if($table=="Sign-Out Sheet" && $field=="Social Services") 
				return false;

	if($table=="Sign-Out Sheet" && $field=="Team") 
				return false;

	if($table=="Sign-Out Sheet" && $field=="Ward Round Notes") 
				return false;


//	users
	if($table=="users" && $field=="Primary") 
				return false;

	if($table=="users" && $field=="Login") 
				return false;

	if($table=="users" && $field=="Name") 
				return false;

	if($table=="users" && $field=="Password") 
				return false;

	if($table=="users" && $field=="User Type") 
				return false;


//	consultants
	if($table=="consultants" && $field=="Primary") 
				return false;

	if($table=="consultants" && $field=="Consultant") 
				return false;


//	ward list
	if($table=="ward list" && $field=="Primary") 
				return false;

	if($table=="ward list" && $field=="Ward") 
				return false;

	return "";
}

//	return field name
function GetFieldByGoodFieldName($field,$table="")
{
	global $strTableName;
	if(!$table)
		$table=$strTableName;
	// jobs
	if($table=="jobs" && $field=="Primary") 
		return "Primary";
	if($table=="jobs" && $field=="Patient_Name") 
		return "Patient Name";
	if($table=="jobs" && $field=="Date") 
		return "Date";
	if($table=="jobs" && $field=="Type") 
		return "Type";
	if($table=="jobs" && $field=="Status") 
		return "Status";
	if($table=="jobs" && $field=="Name") 
		return "Name";
	if($table=="jobs" && $field=="Result") 
		return "Result";
	if($table=="jobs" && $field=="Notes") 
		return "Notes";
	if($table=="jobs" && $field=="Consultant") 
		return "Consultant";
	// patients
	if($table=="patients" && $field=="Primary") 
		return "Primary";
	if($table=="patients" && $field=="Patient_Name") 
		return "Patient Name";
	if($table=="patients" && $field=="Date_of_Birth") 
		return "Date of Birth";
	if($table=="patients" && $field=="Unit_Number") 
		return "Unit Number";
	if($table=="patients" && $field=="Sex") 
		return "Sex";
	if($table=="patients" && $field=="Ward") 
		return "Ward";
	if($table=="patients" && $field=="Bed") 
		return "Bed";
	if($table=="patients" && $field=="Consultant") 
		return "Consultant";
	if($table=="patients" && $field=="Code") 
		return "Code";
	if($table=="patients" && $field=="Category") 
		return "Category";
	if($table=="patients" && $field=="Admission_Date") 
		return "Admission Date";
	if($table=="patients" && $field=="Diagnosis") 
		return "Diagnosis";
	if($table=="patients" && $field=="Allergies") 
		return "Allergies";
	if($table=="patients" && $field=="Notes") 
		return "Notes";
	if($table=="patients" && $field=="Nurses") 
		return "Nurses";
	if($table=="patients" && $field=="Social_Services") 
		return "Social Services";
	if($table=="patients" && $field=="Team") 
		return "Team";
	if($table=="patients" && $field=="Ward_Round_Notes") 
		return "Ward Round Notes";
	// Nursing Handover
	if($table=="Nursing Handover" && $field=="Primary") 
		return "Primary";
	if($table=="Nursing Handover" && $field=="Patient_Name") 
		return "Patient Name";
	if($table=="Nursing Handover" && $field=="Date_of_Birth") 
		return "Date of Birth";
	if($table=="Nursing Handover" && $field=="Unit_Number") 
		return "Unit Number";
	if($table=="Nursing Handover" && $field=="Sex") 
		return "Sex";
	if($table=="Nursing Handover" && $field=="Ward") 
		return "Ward";
	if($table=="Nursing Handover" && $field=="Bed") 
		return "Bed";
	if($table=="Nursing Handover" && $field=="Consultant") 
		return "Consultant";
	if($table=="Nursing Handover" && $field=="Code") 
		return "Code";
	if($table=="Nursing Handover" && $field=="Category") 
		return "Category";
	if($table=="Nursing Handover" && $field=="Admission_Date") 
		return "Admission Date";
	if($table=="Nursing Handover" && $field=="Diagnosis") 
		return "Diagnosis";
	if($table=="Nursing Handover" && $field=="Allergies") 
		return "Allergies";
	if($table=="Nursing Handover" && $field=="Notes") 
		return "Notes";
	if($table=="Nursing Handover" && $field=="Nurses") 
		return "Nurses";
	if($table=="Nursing Handover" && $field=="Social_Services") 
		return "Social Services";
	if($table=="Nursing Handover" && $field=="Team") 
		return "Team";
	if($table=="Nursing Handover" && $field=="Ward_Round_Notes") 
		return "Ward Round Notes";
	// Current Patients
	if($table=="Current Patients" && $field=="Primary") 
		return "Primary";
	if($table=="Current Patients" && $field=="Patient_Name") 
		return "Patient Name";
	if($table=="Current Patients" && $field=="Date_of_Birth") 
		return "Date of Birth";
	if($table=="Current Patients" && $field=="Unit_Number") 
		return "Unit Number";
	if($table=="Current Patients" && $field=="Sex") 
		return "Sex";
	if($table=="Current Patients" && $field=="Ward") 
		return "Ward";
	if($table=="Current Patients" && $field=="Bed") 
		return "Bed";
	if($table=="Current Patients" && $field=="Consultant") 
		return "Consultant";
	if($table=="Current Patients" && $field=="Code") 
		return "Code";
	if($table=="Current Patients" && $field=="Category") 
		return "Category";
	if($table=="Current Patients" && $field=="Admission_Date") 
		return "Admission Date";
	if($table=="Current Patients" && $field=="Diagnosis") 
		return "Diagnosis";
	if($table=="Current Patients" && $field=="Allergies") 
		return "Allergies";
	if($table=="Current Patients" && $field=="Notes") 
		return "Notes";
	if($table=="Current Patients" && $field=="Nurses") 
		return "Nurses";
	if($table=="Current Patients" && $field=="Social_Services") 
		return "Social Services";
	if($table=="Current Patients" && $field=="Team") 
		return "Team";
	if($table=="Current Patients" && $field=="Ward_Round_Notes") 
		return "Ward Round Notes";
	// Current Jobs
	if($table=="Current Jobs" && $field=="Primary") 
		return "Primary";
	if($table=="Current Jobs" && $field=="Patient_Name") 
		return "Patient Name";
	if($table=="Current Jobs" && $field=="Date") 
		return "Date";
	if($table=="Current Jobs" && $field=="Type") 
		return "Type";
	if($table=="Current Jobs" && $field=="Status") 
		return "Status";
	if($table=="Current Jobs" && $field=="Name") 
		return "Name";
	if($table=="Current Jobs" && $field=="Result") 
		return "Result";
	if($table=="Current Jobs" && $field=="Notes") 
		return "Notes";
	if($table=="Current Jobs" && $field=="Consultant") 
		return "Consultant";
	// Ward Round Sheet
	if($table=="Ward Round Sheet" && $field=="Primary") 
		return "Primary";
	if($table=="Ward Round Sheet" && $field=="Consultant") 
		return "Consultant";
	if($table=="Ward Round Sheet" && $field=="Patient_Name") 
		return "Patient Name";
	if($table=="Ward Round Sheet" && $field=="Date_of_Birth") 
		return "Date of Birth";
	if($table=="Ward Round Sheet" && $field=="Unit_Number") 
		return "Unit Number";
	if($table=="Ward Round Sheet" && $field=="Sex") 
		return "Sex";
	if($table=="Ward Round Sheet" && $field=="Ward") 
		return "Ward";
	if($table=="Ward Round Sheet" && $field=="Bed") 
		return "Bed";
	if($table=="Ward Round Sheet" && $field=="Code") 
		return "Code";
	if($table=="Ward Round Sheet" && $field=="Category") 
		return "Category";
	if($table=="Ward Round Sheet" && $field=="Admission_Date") 
		return "Admission Date";
	if($table=="Ward Round Sheet" && $field=="Diagnosis") 
		return "Diagnosis";
	if($table=="Ward Round Sheet" && $field=="Allergies") 
		return "Allergies";
	if($table=="Ward Round Sheet" && $field=="Notes") 
		return "Notes";
	if($table=="Ward Round Sheet" && $field=="Nurses") 
		return "Nurses";
	if($table=="Ward Round Sheet" && $field=="Social_Services") 
		return "Social Services";
	if($table=="Ward Round Sheet" && $field=="Team") 
		return "Team";
	if($table=="Ward Round Sheet" && $field=="Ward_Round_Notes") 
		return "Ward Round Notes";
	// Sign-Out Sheet
	if($table=="Sign-Out Sheet" && $field=="Primary") 
		return "Primary";
	if($table=="Sign-Out Sheet" && $field=="Patient_Name") 
		return "Patient Name";
	if($table=="Sign-Out Sheet" && $field=="Date_of_Birth") 
		return "Date of Birth";
	if($table=="Sign-Out Sheet" && $field=="Unit_Number") 
		return "Unit Number";
	if($table=="Sign-Out Sheet" && $field=="Sex") 
		return "Sex";
	if($table=="Sign-Out Sheet" && $field=="Ward") 
		return "Ward";
	if($table=="Sign-Out Sheet" && $field=="Bed") 
		return "Bed";
	if($table=="Sign-Out Sheet" && $field=="Consultant") 
		return "Consultant";
	if($table=="Sign-Out Sheet" && $field=="Code") 
		return "Code";
	if($table=="Sign-Out Sheet" && $field=="Category") 
		return "Category";
	if($table=="Sign-Out Sheet" && $field=="Admission_Date") 
		return "Admission Date";
	if($table=="Sign-Out Sheet" && $field=="Diagnosis") 
		return "Diagnosis";
	if($table=="Sign-Out Sheet" && $field=="Allergies") 
		return "Allergies";
	if($table=="Sign-Out Sheet" && $field=="Notes") 
		return "Notes";
	if($table=="Sign-Out Sheet" && $field=="Nurses") 
		return "Nurses";
	if($table=="Sign-Out Sheet" && $field=="Social_Services") 
		return "Social Services";
	if($table=="Sign-Out Sheet" && $field=="Team") 
		return "Team";
	if($table=="Sign-Out Sheet" && $field=="Ward_Round_Notes") 
		return "Ward Round Notes";
	// users
	if($table=="users" && $field=="Primary") 
		return "Primary";
	if($table=="users" && $field=="Login") 
		return "Login";
	if($table=="users" && $field=="Name") 
		return "Name";
	if($table=="users" && $field=="Password") 
		return "Password";
	if($table=="users" && $field=="User_Type") 
		return "User Type";
	// consultants
	if($table=="consultants" && $field=="Primary") 
		return "Primary";
	if($table=="consultants" && $field=="Consultant") 
		return "Consultant";
	// ward list
	if($table=="ward list" && $field=="Primary") 
		return "Primary";
	if($table=="ward list" && $field=="Ward") 
		return "Ward";
	return "";
}

//	return the full database field original name
function GetFullFieldName($field,$table="")
{
	global $strTableName;
	if(!$table)
		$table=$strTableName;

	// jobs
	if($table=="jobs" && $field=="Primary") 
			return "`jobs`.`Primary`";
	if($table=="jobs" && $field=="Patient Name") 
			return "`jobs`.`Patient Name`";
	if($table=="jobs" && $field=="Date") 
			return "`jobs`.`Date`";
	if($table=="jobs" && $field=="Type") 
			return "`jobs`.`Type`";
	if($table=="jobs" && $field=="Status") 
			return "`jobs`.`Status`";
	if($table=="jobs" && $field=="Name") 
			return "`jobs`.`Name`";
	if($table=="jobs" && $field=="Result") 
			return "`jobs`.`Result`";
	if($table=="jobs" && $field=="Notes") 
			return "`jobs`.`Notes`";
	if($table=="jobs" && $field=="Consultant") 
			return "`jobs`.`Consultant`";
	// patients
	if($table=="patients" && $field=="Primary") 
			return "`patients`.`Primary`";
	if($table=="patients" && $field=="Patient Name") 
			return "`patients`.`Patient Name`";
	if($table=="patients" && $field=="Date of Birth") 
			return "`patients`.`Date of Birth`";
	if($table=="patients" && $field=="Unit Number") 
			return "`patients`.`Unit Number`";
	if($table=="patients" && $field=="Sex") 
			return "`patients`.`Sex`";
	if($table=="patients" && $field=="Ward") 
			return "`patients`.`Ward`";
	if($table=="patients" && $field=="Bed") 
			return "`patients`.`Bed`";
	if($table=="patients" && $field=="Consultant") 
			return "`patients`.`Consultant`";
	if($table=="patients" && $field=="Code") 
			return "`patients`.`Code`";
	if($table=="patients" && $field=="Category") 
			return "`patients`.`Category`";
	if($table=="patients" && $field=="Admission Date") 
			return "`patients`.`Admission Date`";
	if($table=="patients" && $field=="Diagnosis") 
			return "`patients`.`Diagnosis`";
	if($table=="patients" && $field=="Allergies") 
			return "`patients`.`Allergies`";
	if($table=="patients" && $field=="Notes") 
			return "`patients`.`Notes`";
	if($table=="patients" && $field=="Nurses") 
			return "`patients`.`Nurses`";
	if($table=="patients" && $field=="Social Services") 
			return "`patients`.`Social Services`";
	if($table=="patients" && $field=="Team") 
			return "`patients`.`Team`";
	if($table=="patients" && $field=="Ward Round Notes") 
			return "`patients`.`Ward Round Notes`";
	// Nursing Handover
	if($table=="Nursing Handover" && $field=="Primary") 
			return "`patients`.`Primary`";
	if($table=="Nursing Handover" && $field=="Patient Name") 
			return "`patients`.`Patient Name`";
	if($table=="Nursing Handover" && $field=="Date of Birth") 
			return "`patients`.`Date of Birth`";
	if($table=="Nursing Handover" && $field=="Unit Number") 
			return "`patients`.`Unit Number`";
	if($table=="Nursing Handover" && $field=="Sex") 
			return "`patients`.`Sex`";
	if($table=="Nursing Handover" && $field=="Ward") 
			return "`patients`.`Ward`";
	if($table=="Nursing Handover" && $field=="Bed") 
			return "`patients`.`Bed`";
	if($table=="Nursing Handover" && $field=="Consultant") 
			return "`patients`.`Consultant`";
	if($table=="Nursing Handover" && $field=="Code") 
			return "`patients`.`Code`";
	if($table=="Nursing Handover" && $field=="Category") 
			return "`patients`.`Category`";
	if($table=="Nursing Handover" && $field=="Admission Date") 
			return "`patients`.`Admission Date`";
	if($table=="Nursing Handover" && $field=="Diagnosis") 
			return "`patients`.`Diagnosis`";
	if($table=="Nursing Handover" && $field=="Allergies") 
			return "`patients`.`Allergies`";
	if($table=="Nursing Handover" && $field=="Notes") 
			return "`patients`.`Notes`";
	if($table=="Nursing Handover" && $field=="Nurses") 
			return "`patients`.`Nurses`";
	if($table=="Nursing Handover" && $field=="Social Services") 
			return "`patients`.`Social Services`";
	if($table=="Nursing Handover" && $field=="Team") 
			return "`patients`.`Team`";
	if($table=="Nursing Handover" && $field=="Ward Round Notes") 
			return "`patients`.`Ward Round Notes`";
	// Current Patients
	if($table=="Current Patients" && $field=="Primary") 
			return "`patients`.`Primary`";
	if($table=="Current Patients" && $field=="Patient Name") 
			return "`patients`.`Patient Name`";
	if($table=="Current Patients" && $field=="Date of Birth") 
			return "`patients`.`Date of Birth`";
	if($table=="Current Patients" && $field=="Unit Number") 
			return "`patients`.`Unit Number`";
	if($table=="Current Patients" && $field=="Sex") 
			return "`patients`.`Sex`";
	if($table=="Current Patients" && $field=="Ward") 
			return "`patients`.`Ward`";
	if($table=="Current Patients" && $field=="Bed") 
			return "`patients`.`Bed`";
	if($table=="Current Patients" && $field=="Consultant") 
			return "`patients`.`Consultant`";
	if($table=="Current Patients" && $field=="Code") 
			return "`patients`.`Code`";
	if($table=="Current Patients" && $field=="Category") 
			return "`patients`.`Category`";
	if($table=="Current Patients" && $field=="Admission Date") 
			return "`patients`.`Admission Date`";
	if($table=="Current Patients" && $field=="Diagnosis") 
			return "`patients`.`Diagnosis`";
	if($table=="Current Patients" && $field=="Allergies") 
			return "`patients`.`Allergies`";
	if($table=="Current Patients" && $field=="Notes") 
			return "`patients`.`Notes`";
	if($table=="Current Patients" && $field=="Nurses") 
			return "`patients`.`Nurses`";
	if($table=="Current Patients" && $field=="Social Services") 
			return "`patients`.`Social Services`";
	if($table=="Current Patients" && $field=="Team") 
			return "`patients`.`Team`";
	if($table=="Current Patients" && $field=="Ward Round Notes") 
			return "`patients`.`Ward Round Notes`";
	// Current Jobs
	if($table=="Current Jobs" && $field=="Primary") 
			return "`jobs`.`Primary`";
	if($table=="Current Jobs" && $field=="Patient Name") 
			return "`jobs`.`Patient Name`";
	if($table=="Current Jobs" && $field=="Date") 
			return "`jobs`.`Date`";
	if($table=="Current Jobs" && $field=="Type") 
			return "`jobs`.`Type`";
	if($table=="Current Jobs" && $field=="Status") 
			return "`jobs`.`Status`";
	if($table=="Current Jobs" && $field=="Name") 
			return "`jobs`.`Name`";
	if($table=="Current Jobs" && $field=="Result") 
			return "`jobs`.`Result`";
	if($table=="Current Jobs" && $field=="Notes") 
			return "`jobs`.`Notes`";
	if($table=="Current Jobs" && $field=="Consultant") 
			return "`jobs`.`Consultant`";
	// Ward Round Sheet
	if($table=="Ward Round Sheet" && $field=="Primary") 
			return "`consultants`.`Primary`";
	if($table=="Ward Round Sheet" && $field=="Consultant") 
			return "`consultants`.`Consultant`";
	if($table=="Ward Round Sheet" && $field=="Patient Name") 
			return "`consultants`.`Patient Name`";
	if($table=="Ward Round Sheet" && $field=="Date of Birth") 
			return "`consultants`.`Date of Birth`";
	if($table=="Ward Round Sheet" && $field=="Unit Number") 
			return "`consultants`.`Unit Number`";
	if($table=="Ward Round Sheet" && $field=="Sex") 
			return "`consultants`.`Sex`";
	if($table=="Ward Round Sheet" && $field=="Ward") 
			return "`consultants`.`Ward`";
	if($table=="Ward Round Sheet" && $field=="Bed") 
			return "`consultants`.`Bed`";
	if($table=="Ward Round Sheet" && $field=="Code") 
			return "`consultants`.`Code`";
	if($table=="Ward Round Sheet" && $field=="Category") 
			return "`consultants`.`Category`";
	if($table=="Ward Round Sheet" && $field=="Admission Date") 
			return "`consultants`.`Admission Date`";
	if($table=="Ward Round Sheet" && $field=="Diagnosis") 
			return "`consultants`.`Diagnosis`";
	if($table=="Ward Round Sheet" && $field=="Allergies") 
			return "`consultants`.`Allergies`";
	if($table=="Ward Round Sheet" && $field=="Notes") 
			return "`consultants`.`Notes`";
	if($table=="Ward Round Sheet" && $field=="Nurses") 
			return "`consultants`.`Nurses`";
	if($table=="Ward Round Sheet" && $field=="Social Services") 
			return "`consultants`.`Social Services`";
	if($table=="Ward Round Sheet" && $field=="Team") 
			return "`consultants`.`Team`";
	if($table=="Ward Round Sheet" && $field=="Ward Round Notes") 
			return "`consultants`.`Ward Round Notes`";
	// Sign-Out Sheet
	if($table=="Sign-Out Sheet" && $field=="Primary") 
			return "`patients`.`Primary`";
	if($table=="Sign-Out Sheet" && $field=="Patient Name") 
			return "`patients`.`Patient Name`";
	if($table=="Sign-Out Sheet" && $field=="Date of Birth") 
			return "`patients`.`Date of Birth`";
	if($table=="Sign-Out Sheet" && $field=="Unit Number") 
			return "`patients`.`Unit Number`";
	if($table=="Sign-Out Sheet" && $field=="Sex") 
			return "`patients`.`Sex`";
	if($table=="Sign-Out Sheet" && $field=="Ward") 
			return "`patients`.`Ward`";
	if($table=="Sign-Out Sheet" && $field=="Bed") 
			return "`patients`.`Bed`";
	if($table=="Sign-Out Sheet" && $field=="Consultant") 
			return "`patients`.`Consultant`";
	if($table=="Sign-Out Sheet" && $field=="Code") 
			return "`patients`.`Code`";
	if($table=="Sign-Out Sheet" && $field=="Category") 
			return "`patients`.`Category`";
	if($table=="Sign-Out Sheet" && $field=="Admission Date") 
			return "`patients`.`Admission Date`";
	if($table=="Sign-Out Sheet" && $field=="Diagnosis") 
			return "`patients`.`Diagnosis`";
	if($table=="Sign-Out Sheet" && $field=="Allergies") 
			return "`patients`.`Allergies`";
	if($table=="Sign-Out Sheet" && $field=="Notes") 
			return "`patients`.`Notes`";
	if($table=="Sign-Out Sheet" && $field=="Nurses") 
			return "`patients`.`Nurses`";
	if($table=="Sign-Out Sheet" && $field=="Social Services") 
			return "`patients`.`Social Services`";
	if($table=="Sign-Out Sheet" && $field=="Team") 
			return "`patients`.`Team`";
	if($table=="Sign-Out Sheet" && $field=="Ward Round Notes") 
			return "`patients`.`Ward Round Notes`";
	// users
	if($table=="users" && $field=="Primary") 
			return "`users`.`Primary`";
	if($table=="users" && $field=="Login") 
			return "`users`.`Login`";
	if($table=="users" && $field=="Name") 
			return "`users`.`Name`";
	if($table=="users" && $field=="Password") 
			return "`users`.`Password`";
	if($table=="users" && $field=="User Type") 
			return "`users`.`User Type`";
	// consultants
	if($table=="consultants" && $field=="Primary") 
			return "`consultants`.`Primary`";
	if($table=="consultants" && $field=="Consultant") 
			return "`consultants`.`Consultant`";
	// ward list
	if($table=="ward list" && $field=="Primary") 
			return "`ward list`.`Primary`";
	if($table=="ward list" && $field=="Ward") 
			return "`ward list`.`Ward`";
	return "";
}

//	return number of chars to show before More... link
function GetNumberOfChars($table="")
{
	global $strTableName;
	if(!$table)
		$table=$strTableName;
	if("jobs"==$table) 
			return 80;
	if("patients"==$table) 
			return 80;
	if("Nursing Handover"==$table) 
			return 80;
	if("Current Patients"==$table) 
			return 80;
	if("Current Jobs"==$table) 
			return 80;
	if("Ward Round Sheet"==$table) 
			return 80;
	if("Sign-Out Sheet"==$table) 
			return 80;
	if("users"==$table) 
			return 80;
	if("consultants"==$table) 
			return 80;
	if("ward list"==$table) 
			return 80;
}

//	return table short name
function GetTableURL($table="")
{
	global $strTableName;
	if(!$table)
		$table=$strTableName;
	if("jobs"==$table) 
		return "jobs";
	if("patients"==$table) 
		return "patients";
	if("Nursing Handover"==$table) 
		return "Nursing_Handover";
	if("Current Patients"==$table) 
		return "Current_Patients";
	if("Current Jobs"==$table) 
		return "Current_Jobs";
	if("Ward Round Sheet"==$table) 
		return "Ward_Round_Sheet";
	if("Sign-Out Sheet"==$table) 
		return "Sign_Out_Sheet";
	if("users"==$table) 
		return "users";
	if("consultants"==$table) 
		return "consultants";
	if("ward list"==$table) 
		return "ward_list";
}

//	return table Owner ID field
function GetTableOwnerID($table="")
{
	global $strTableName;
	if(!$table)
		$table=$strTableName;
	if("jobs"==$table) 
		return "";
	if("patients"==$table) 
		return "";
	if("Nursing Handover"==$table) 
		return "";
	if("Current Patients"==$table) 
		return "";
	if("Current Jobs"==$table) 
		return "";
	if("Ward Round Sheet"==$table) 
		return "";
	if("Sign-Out Sheet"==$table) 
		return "";
	if("users"==$table) 
		return "Login";
	if("consultants"==$table) 
		return "";
	if("ward list"==$table) 
		return "";
}

//	is field marked as required
function IsRequired($field,$table="")
{
	global $strTableName;
	if(!$table)
		$table=$strTableName;


	// jobs
	if($table=="jobs" && $field=="Primary") 
			return true;
	if($table=="jobs" && $field=="Patient Name") 
			return false;
	if($table=="jobs" && $field=="Date") 
			return false;
	if($table=="jobs" && $field=="Type") 
			return false;
	if($table=="jobs" && $field=="Status") 
			return false;
	if($table=="jobs" && $field=="Name") 
			return false;
	if($table=="jobs" && $field=="Result") 
			return false;
	if($table=="jobs" && $field=="Notes") 
			return false;
	if($table=="jobs" && $field=="Consultant") 
			return false;

	// patients
	if($table=="patients" && $field=="Primary") 
			return true;
	if($table=="patients" && $field=="Patient Name") 
			return false;
	if($table=="patients" && $field=="Date of Birth") 
			return true;
	if($table=="patients" && $field=="Unit Number") 
			return false;
	if($table=="patients" && $field=="Sex") 
			return false;
	if($table=="patients" && $field=="Ward") 
			return false;
	if($table=="patients" && $field=="Bed") 
			return false;
	if($table=="patients" && $field=="Consultant") 
			return false;
	if($table=="patients" && $field=="Code") 
			return false;
	if($table=="patients" && $field=="Category") 
			return false;
	if($table=="patients" && $field=="Admission Date") 
			return false;
	if($table=="patients" && $field=="Diagnosis") 
			return false;
	if($table=="patients" && $field=="Allergies") 
			return false;
	if($table=="patients" && $field=="Notes") 
			return false;
	if($table=="patients" && $field=="Nurses") 
			return false;
	if($table=="patients" && $field=="Social Services") 
			return false;
	if($table=="patients" && $field=="Team") 
			return false;
	if($table=="patients" && $field=="Ward Round Notes") 
			return false;

	// Nursing Handover
	if($table=="Nursing Handover" && $field=="Primary") 
			return true;
	if($table=="Nursing Handover" && $field=="Patient Name") 
			return true;
	if($table=="Nursing Handover" && $field=="Date of Birth") 
			return true;
	if($table=="Nursing Handover" && $field=="Unit Number") 
			return true;
	if($table=="Nursing Handover" && $field=="Sex") 
			return true;
	if($table=="Nursing Handover" && $field=="Ward") 
			return true;
	if($table=="Nursing Handover" && $field=="Bed") 
			return true;
	if($table=="Nursing Handover" && $field=="Consultant") 
			return true;
	if($table=="Nursing Handover" && $field=="Code") 
			return false;
	if($table=="Nursing Handover" && $field=="Category") 
			return false;
	if($table=="Nursing Handover" && $field=="Admission Date") 
			return false;
	if($table=="Nursing Handover" && $field=="Diagnosis") 
			return false;
	if($table=="Nursing Handover" && $field=="Allergies") 
			return false;
	if($table=="Nursing Handover" && $field=="Notes") 
			return false;
	if($table=="Nursing Handover" && $field=="Nurses") 
			return false;
	if($table=="Nursing Handover" && $field=="Social Services") 
			return false;
	if($table=="Nursing Handover" && $field=="Team") 
			return false;
	if($table=="Nursing Handover" && $field=="Ward Round Notes") 
			return false;

	// Current Patients
	if($table=="Current Patients" && $field=="Primary") 
			return true;
	if($table=="Current Patients" && $field=="Patient Name") 
			return true;
	if($table=="Current Patients" && $field=="Date of Birth") 
			return true;
	if($table=="Current Patients" && $field=="Unit Number") 
			return true;
	if($table=="Current Patients" && $field=="Sex") 
			return true;
	if($table=="Current Patients" && $field=="Ward") 
			return true;
	if($table=="Current Patients" && $field=="Bed") 
			return false;
	if($table=="Current Patients" && $field=="Consultant") 
			return true;
	if($table=="Current Patients" && $field=="Code") 
			return false;
	if($table=="Current Patients" && $field=="Category") 
			return true;
	if($table=="Current Patients" && $field=="Admission Date") 
			return true;
	if($table=="Current Patients" && $field=="Diagnosis") 
			return false;
	if($table=="Current Patients" && $field=="Allergies") 
			return false;
	if($table=="Current Patients" && $field=="Notes") 
			return false;
	if($table=="Current Patients" && $field=="Nurses") 
			return false;
	if($table=="Current Patients" && $field=="Social Services") 
			return false;
	if($table=="Current Patients" && $field=="Team") 
			return false;
	if($table=="Current Patients" && $field=="Ward Round Notes") 
			return false;

	// Current Jobs
	if($table=="Current Jobs" && $field=="Primary") 
			return true;
	if($table=="Current Jobs" && $field=="Patient Name") 
			return false;
	if($table=="Current Jobs" && $field=="Date") 
			return true;
	if($table=="Current Jobs" && $field=="Type") 
			return true;
	if($table=="Current Jobs" && $field=="Status") 
			return true;
	if($table=="Current Jobs" && $field=="Name") 
			return false;
	if($table=="Current Jobs" && $field=="Result") 
			return false;
	if($table=="Current Jobs" && $field=="Notes") 
			return false;
	if($table=="Current Jobs" && $field=="Consultant") 
			return true;

	// Ward Round Sheet
	if($table=="Ward Round Sheet" && $field=="Primary") 
			return true;
	if($table=="Ward Round Sheet" && $field=="Consultant") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Patient Name") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Date of Birth") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Unit Number") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Sex") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Ward") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Bed") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Code") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Category") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Admission Date") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Diagnosis") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Allergies") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Notes") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Nurses") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Social Services") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Team") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Ward Round Notes") 
			return false;

	// Sign-Out Sheet
	if($table=="Sign-Out Sheet" && $field=="Primary") 
			return true;
	if($table=="Sign-Out Sheet" && $field=="Patient Name") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Date of Birth") 
			return true;
	if($table=="Sign-Out Sheet" && $field=="Unit Number") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Sex") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Ward") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Bed") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Consultant") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Code") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Category") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Admission Date") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Diagnosis") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Allergies") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Notes") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Nurses") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Social Services") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Team") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Ward Round Notes") 
			return false;

	// users
	if($table=="users" && $field=="Primary") 
			return true;
	if($table=="users" && $field=="Login") 
			return true;
	if($table=="users" && $field=="Name") 
			return true;
	if($table=="users" && $field=="Password") 
			return true;
	if($table=="users" && $field=="User Type") 
			return true;

	// consultants
	if($table=="consultants" && $field=="Primary") 
			return true;
	if($table=="consultants" && $field=="Consultant") 
			return true;

	// ward list
	if($table=="ward list" && $field=="Primary") 
			return true;
	if($table=="ward list" && $field=="Ward") 
			return true;
	return false;
}

//	use Rich Text Editor or not
function UseRTE($field,$table="")
{
	global $strTableName;
	if(!$table)
		$table=$strTableName;


	// jobs
	if($table=="jobs" && $field=="Primary") 
			return false;
	if($table=="jobs" && $field=="Patient Name") 
			return false;
	if($table=="jobs" && $field=="Date") 
			return false;
	if($table=="jobs" && $field=="Type") 
			return false;
	if($table=="jobs" && $field=="Status") 
			return false;
	if($table=="jobs" && $field=="Name") 
			return false;
	if($table=="jobs" && $field=="Result") 
			return false;
	if($table=="jobs" && $field=="Notes") 
			return false;
	if($table=="jobs" && $field=="Consultant") 
			return false;

	// patients
	if($table=="patients" && $field=="Primary") 
			return false;
	if($table=="patients" && $field=="Patient Name") 
			return false;
	if($table=="patients" && $field=="Date of Birth") 
			return false;
	if($table=="patients" && $field=="Unit Number") 
			return false;
	if($table=="patients" && $field=="Sex") 
			return false;
	if($table=="patients" && $field=="Ward") 
			return false;
	if($table=="patients" && $field=="Bed") 
			return false;
	if($table=="patients" && $field=="Consultant") 
			return false;
	if($table=="patients" && $field=="Code") 
			return false;
	if($table=="patients" && $field=="Category") 
			return false;
	if($table=="patients" && $field=="Admission Date") 
			return false;
	if($table=="patients" && $field=="Diagnosis") 
			return false;
	if($table=="patients" && $field=="Allergies") 
			return false;
	if($table=="patients" && $field=="Notes") 
			return false;
	if($table=="patients" && $field=="Nurses") 
			return false;
	if($table=="patients" && $field=="Social Services") 
			return false;
	if($table=="patients" && $field=="Team") 
			return false;
	if($table=="patients" && $field=="Ward Round Notes") 
			return false;

	// Nursing Handover
	if($table=="Nursing Handover" && $field=="Primary") 
			return false;
	if($table=="Nursing Handover" && $field=="Patient Name") 
			return false;
	if($table=="Nursing Handover" && $field=="Date of Birth") 
			return false;
	if($table=="Nursing Handover" && $field=="Unit Number") 
			return false;
	if($table=="Nursing Handover" && $field=="Sex") 
			return false;
	if($table=="Nursing Handover" && $field=="Ward") 
			return false;
	if($table=="Nursing Handover" && $field=="Bed") 
			return false;
	if($table=="Nursing Handover" && $field=="Consultant") 
			return false;
	if($table=="Nursing Handover" && $field=="Code") 
			return false;
	if($table=="Nursing Handover" && $field=="Category") 
			return false;
	if($table=="Nursing Handover" && $field=="Admission Date") 
			return false;
	if($table=="Nursing Handover" && $field=="Diagnosis") 
			return false;
	if($table=="Nursing Handover" && $field=="Allergies") 
			return false;
	if($table=="Nursing Handover" && $field=="Notes") 
			return false;
	if($table=="Nursing Handover" && $field=="Nurses") 
			return false;
	if($table=="Nursing Handover" && $field=="Social Services") 
			return false;
	if($table=="Nursing Handover" && $field=="Team") 
			return false;
	if($table=="Nursing Handover" && $field=="Ward Round Notes") 
			return false;

	// Current Patients
	if($table=="Current Patients" && $field=="Primary") 
			return false;
	if($table=="Current Patients" && $field=="Patient Name") 
			return false;
	if($table=="Current Patients" && $field=="Date of Birth") 
			return false;
	if($table=="Current Patients" && $field=="Unit Number") 
			return false;
	if($table=="Current Patients" && $field=="Sex") 
			return false;
	if($table=="Current Patients" && $field=="Ward") 
			return false;
	if($table=="Current Patients" && $field=="Bed") 
			return false;
	if($table=="Current Patients" && $field=="Consultant") 
			return false;
	if($table=="Current Patients" && $field=="Code") 
			return false;
	if($table=="Current Patients" && $field=="Category") 
			return false;
	if($table=="Current Patients" && $field=="Admission Date") 
			return false;
	if($table=="Current Patients" && $field=="Diagnosis") 
			return false;
	if($table=="Current Patients" && $field=="Allergies") 
			return false;
	if($table=="Current Patients" && $field=="Notes") 
			return false;
	if($table=="Current Patients" && $field=="Nurses") 
			return false;
	if($table=="Current Patients" && $field=="Social Services") 
			return false;
	if($table=="Current Patients" && $field=="Team") 
			return false;
	if($table=="Current Patients" && $field=="Ward Round Notes") 
			return false;

	// Current Jobs
	if($table=="Current Jobs" && $field=="Primary") 
			return false;
	if($table=="Current Jobs" && $field=="Patient Name") 
			return false;
	if($table=="Current Jobs" && $field=="Date") 
			return false;
	if($table=="Current Jobs" && $field=="Type") 
			return false;
	if($table=="Current Jobs" && $field=="Status") 
			return false;
	if($table=="Current Jobs" && $field=="Name") 
			return false;
	if($table=="Current Jobs" && $field=="Result") 
			return false;
	if($table=="Current Jobs" && $field=="Notes") 
			return false;
	if($table=="Current Jobs" && $field=="Consultant") 
			return false;

	// Ward Round Sheet
	if($table=="Ward Round Sheet" && $field=="Primary") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Consultant") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Patient Name") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Date of Birth") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Unit Number") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Sex") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Ward") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Bed") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Code") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Category") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Admission Date") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Diagnosis") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Allergies") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Notes") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Nurses") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Social Services") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Team") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Ward Round Notes") 
			return false;

	// Sign-Out Sheet
	if($table=="Sign-Out Sheet" && $field=="Primary") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Patient Name") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Date of Birth") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Unit Number") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Sex") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Ward") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Bed") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Consultant") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Code") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Category") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Admission Date") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Diagnosis") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Allergies") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Notes") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Nurses") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Social Services") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Team") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Ward Round Notes") 
			return false;

	// users
	if($table=="users" && $field=="Primary") 
			return false;
	if($table=="users" && $field=="Login") 
			return false;
	if($table=="users" && $field=="Name") 
			return false;
	if($table=="users" && $field=="Password") 
			return false;
	if($table=="users" && $field=="User Type") 
			return false;

	// consultants
	if($table=="consultants" && $field=="Primary") 
			return false;
	if($table=="consultants" && $field=="Consultant") 
			return false;

	// ward list
	if($table=="ward list" && $field=="Primary") 
			return false;
	if($table=="ward list" && $field=="Ward") 
			return false;
	return false;
}

//	add timestamp to filename when uploading files or not
function UseTimestamp($field,$table="")
{
	global $strTableName;
	if(!$table)
		$table=$strTableName;


	// jobs
	if($table=="jobs" && $field=="Primary") 
			return false;
	if($table=="jobs" && $field=="Patient Name") 
			return false;
	if($table=="jobs" && $field=="Date") 
			return false;
	if($table=="jobs" && $field=="Type") 
			return false;
	if($table=="jobs" && $field=="Status") 
			return false;
	if($table=="jobs" && $field=="Name") 
			return false;
	if($table=="jobs" && $field=="Result") 
			return false;
	if($table=="jobs" && $field=="Notes") 
			return false;
	if($table=="jobs" && $field=="Consultant") 
			return false;

	// patients
	if($table=="patients" && $field=="Primary") 
			return false;
	if($table=="patients" && $field=="Patient Name") 
			return false;
	if($table=="patients" && $field=="Date of Birth") 
			return false;
	if($table=="patients" && $field=="Unit Number") 
			return false;
	if($table=="patients" && $field=="Sex") 
			return false;
	if($table=="patients" && $field=="Ward") 
			return false;
	if($table=="patients" && $field=="Bed") 
			return false;
	if($table=="patients" && $field=="Consultant") 
			return false;
	if($table=="patients" && $field=="Code") 
			return false;
	if($table=="patients" && $field=="Category") 
			return false;
	if($table=="patients" && $field=="Admission Date") 
			return false;
	if($table=="patients" && $field=="Diagnosis") 
			return false;
	if($table=="patients" && $field=="Allergies") 
			return false;
	if($table=="patients" && $field=="Notes") 
			return false;
	if($table=="patients" && $field=="Nurses") 
			return false;
	if($table=="patients" && $field=="Social Services") 
			return false;
	if($table=="patients" && $field=="Team") 
			return false;
	if($table=="patients" && $field=="Ward Round Notes") 
			return false;

	// Nursing Handover
	if($table=="Nursing Handover" && $field=="Primary") 
			return false;
	if($table=="Nursing Handover" && $field=="Patient Name") 
			return false;
	if($table=="Nursing Handover" && $field=="Date of Birth") 
			return false;
	if($table=="Nursing Handover" && $field=="Unit Number") 
			return false;
	if($table=="Nursing Handover" && $field=="Sex") 
			return false;
	if($table=="Nursing Handover" && $field=="Ward") 
			return false;
	if($table=="Nursing Handover" && $field=="Bed") 
			return false;
	if($table=="Nursing Handover" && $field=="Consultant") 
			return false;
	if($table=="Nursing Handover" && $field=="Code") 
			return false;
	if($table=="Nursing Handover" && $field=="Category") 
			return false;
	if($table=="Nursing Handover" && $field=="Admission Date") 
			return false;
	if($table=="Nursing Handover" && $field=="Diagnosis") 
			return false;
	if($table=="Nursing Handover" && $field=="Allergies") 
			return false;
	if($table=="Nursing Handover" && $field=="Notes") 
			return false;
	if($table=="Nursing Handover" && $field=="Nurses") 
			return false;
	if($table=="Nursing Handover" && $field=="Social Services") 
			return false;
	if($table=="Nursing Handover" && $field=="Team") 
			return false;
	if($table=="Nursing Handover" && $field=="Ward Round Notes") 
			return false;

	// Current Patients
	if($table=="Current Patients" && $field=="Primary") 
			return false;
	if($table=="Current Patients" && $field=="Patient Name") 
			return false;
	if($table=="Current Patients" && $field=="Date of Birth") 
			return false;
	if($table=="Current Patients" && $field=="Unit Number") 
			return false;
	if($table=="Current Patients" && $field=="Sex") 
			return false;
	if($table=="Current Patients" && $field=="Ward") 
			return false;
	if($table=="Current Patients" && $field=="Bed") 
			return false;
	if($table=="Current Patients" && $field=="Consultant") 
			return false;
	if($table=="Current Patients" && $field=="Code") 
			return false;
	if($table=="Current Patients" && $field=="Category") 
			return false;
	if($table=="Current Patients" && $field=="Admission Date") 
			return false;
	if($table=="Current Patients" && $field=="Diagnosis") 
			return false;
	if($table=="Current Patients" && $field=="Allergies") 
			return false;
	if($table=="Current Patients" && $field=="Notes") 
			return false;
	if($table=="Current Patients" && $field=="Nurses") 
			return false;
	if($table=="Current Patients" && $field=="Social Services") 
			return false;
	if($table=="Current Patients" && $field=="Team") 
			return false;
	if($table=="Current Patients" && $field=="Ward Round Notes") 
			return false;

	// Current Jobs
	if($table=="Current Jobs" && $field=="Primary") 
			return false;
	if($table=="Current Jobs" && $field=="Patient Name") 
			return false;
	if($table=="Current Jobs" && $field=="Date") 
			return false;
	if($table=="Current Jobs" && $field=="Type") 
			return false;
	if($table=="Current Jobs" && $field=="Status") 
			return false;
	if($table=="Current Jobs" && $field=="Name") 
			return false;
	if($table=="Current Jobs" && $field=="Result") 
			return false;
	if($table=="Current Jobs" && $field=="Notes") 
			return false;
	if($table=="Current Jobs" && $field=="Consultant") 
			return false;

	// Ward Round Sheet
	if($table=="Ward Round Sheet" && $field=="Primary") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Consultant") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Patient Name") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Date of Birth") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Unit Number") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Sex") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Ward") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Bed") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Code") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Category") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Admission Date") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Diagnosis") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Allergies") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Notes") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Nurses") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Social Services") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Team") 
			return false;
	if($table=="Ward Round Sheet" && $field=="Ward Round Notes") 
			return false;

	// Sign-Out Sheet
	if($table=="Sign-Out Sheet" && $field=="Primary") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Patient Name") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Date of Birth") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Unit Number") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Sex") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Ward") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Bed") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Consultant") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Code") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Category") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Admission Date") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Diagnosis") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Allergies") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Notes") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Nurses") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Social Services") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Team") 
			return false;
	if($table=="Sign-Out Sheet" && $field=="Ward Round Notes") 
			return false;

	// users
	if($table=="users" && $field=="Primary") 
			return false;
	if($table=="users" && $field=="Login") 
			return false;
	if($table=="users" && $field=="Name") 
			return false;
	if($table=="users" && $field=="Password") 
			return false;
	if($table=="users" && $field=="User Type") 
			return false;

	// consultants
	if($table=="consultants" && $field=="Primary") 
			return false;
	if($table=="consultants" && $field=="Consultant") 
			return false;

	// ward list
	if($table=="ward list" && $field=="Primary") 
			return false;
	if($table=="ward list" && $field=="Ward") 
			return false;
	return false;
}

function GetUploadFolder($field, $table="")
{
	global $strTableName;
	if(!$table)
		$table=$strTableName;

	$path="";

	// jobs

	// patients

	// Nursing Handover

	// Current Patients

	// Current Jobs

	// Ward Round Sheet

	// Sign-Out Sheet

	// users

	// consultants

	// ward list
	if(strlen($path) && substr($path,strlen($path)-1) != "/")
		$path.="/";
	return $path;
}

function GetFieldIndex($field, $table="")
{
	global $strTableName;
	if(!$table)
		$table=$strTableName;

	// jobs
	if($table=="jobs" && $field=="Primary")	return 1;
	if($table=="jobs" && $field=="Patient Name")	return 2;
	if($table=="jobs" && $field=="Date")	return 3;
	if($table=="jobs" && $field=="Type")	return 4;
	if($table=="jobs" && $field=="Status")	return 5;
	if($table=="jobs" && $field=="Name")	return 6;
	if($table=="jobs" && $field=="Result")	return 7;
	if($table=="jobs" && $field=="Notes")	return 8;
	if($table=="jobs" && $field=="Consultant")	return 9;

	// patients
	if($table=="patients" && $field=="Primary")	return 1;
	if($table=="patients" && $field=="Patient Name")	return 2;
	if($table=="patients" && $field=="Date of Birth")	return 3;
	if($table=="patients" && $field=="Unit Number")	return 4;
	if($table=="patients" && $field=="Sex")	return 5;
	if($table=="patients" && $field=="Ward")	return 6;
	if($table=="patients" && $field=="Bed")	return 7;
	if($table=="patients" && $field=="Consultant")	return 8;
	if($table=="patients" && $field=="Code")	return 9;
	if($table=="patients" && $field=="Category")	return 10;
	if($table=="patients" && $field=="Admission Date")	return 11;
	if($table=="patients" && $field=="Diagnosis")	return 12;
	if($table=="patients" && $field=="Allergies")	return 13;
	if($table=="patients" && $field=="Notes")	return 14;
	if($table=="patients" && $field=="Nurses")	return 15;
	if($table=="patients" && $field=="Social Services")	return 16;
	if($table=="patients" && $field=="Team")	return 17;
	if($table=="patients" && $field=="Ward Round Notes")	return 18;

	// Nursing Handover
	if($table=="Nursing Handover" && $field=="Primary")	return 1;
	if($table=="Nursing Handover" && $field=="Patient Name")	return 2;
	if($table=="Nursing Handover" && $field=="Date of Birth")	return 3;
	if($table=="Nursing Handover" && $field=="Unit Number")	return 4;
	if($table=="Nursing Handover" && $field=="Sex")	return 5;
	if($table=="Nursing Handover" && $field=="Ward")	return 6;
	if($table=="Nursing Handover" && $field=="Bed")	return 7;
	if($table=="Nursing Handover" && $field=="Consultant")	return 8;
	if($table=="Nursing Handover" && $field=="Code")	return 9;
	if($table=="Nursing Handover" && $field=="Category")	return 10;
	if($table=="Nursing Handover" && $field=="Admission Date")	return 11;
	if($table=="Nursing Handover" && $field=="Diagnosis")	return 12;
	if($table=="Nursing Handover" && $field=="Allergies")	return 13;
	if($table=="Nursing Handover" && $field=="Notes")	return 14;
	if($table=="Nursing Handover" && $field=="Nurses")	return 15;
	if($table=="Nursing Handover" && $field=="Social Services")	return 16;
	if($table=="Nursing Handover" && $field=="Team")	return 17;
	if($table=="Nursing Handover" && $field=="Ward Round Notes")	return 18;

	// Current Patients
	if($table=="Current Patients" && $field=="Primary")	return 1;
	if($table=="Current Patients" && $field=="Patient Name")	return 2;
	if($table=="Current Patients" && $field=="Date of Birth")	return 3;
	if($table=="Current Patients" && $field=="Unit Number")	return 4;
	if($table=="Current Patients" && $field=="Sex")	return 5;
	if($table=="Current Patients" && $field=="Ward")	return 6;
	if($table=="Current Patients" && $field=="Bed")	return 7;
	if($table=="Current Patients" && $field=="Consultant")	return 8;
	if($table=="Current Patients" && $field=="Code")	return 9;
	if($table=="Current Patients" && $field=="Category")	return 10;
	if($table=="Current Patients" && $field=="Admission Date")	return 11;
	if($table=="Current Patients" && $field=="Diagnosis")	return 12;
	if($table=="Current Patients" && $field=="Allergies")	return 13;
	if($table=="Current Patients" && $field=="Notes")	return 14;
	if($table=="Current Patients" && $field=="Nurses")	return 15;
	if($table=="Current Patients" && $field=="Social Services")	return 16;
	if($table=="Current Patients" && $field=="Team")	return 17;
	if($table=="Current Patients" && $field=="Ward Round Notes")	return 18;

	// Current Jobs
	if($table=="Current Jobs" && $field=="Primary")	return 1;
	if($table=="Current Jobs" && $field=="Patient Name")	return 2;
	if($table=="Current Jobs" && $field=="Date")	return 3;
	if($table=="Current Jobs" && $field=="Type")	return 4;
	if($table=="Current Jobs" && $field=="Status")	return 5;
	if($table=="Current Jobs" && $field=="Name")	return 6;
	if($table=="Current Jobs" && $field=="Result")	return 7;
	if($table=="Current Jobs" && $field=="Notes")	return 8;
	if($table=="Current Jobs" && $field=="Consultant")	return 9;

	// Ward Round Sheet
	if($table=="Ward Round Sheet" && $field=="Primary")	return 1;
	if($table=="Ward Round Sheet" && $field=="Consultant")	return 2;
	if($table=="Ward Round Sheet" && $field=="Patient Name")	return 3;
	if($table=="Ward Round Sheet" && $field=="Date of Birth")	return 4;
	if($table=="Ward Round Sheet" && $field=="Unit Number")	return 5;
	if($table=="Ward Round Sheet" && $field=="Sex")	return 6;
	if($table=="Ward Round Sheet" && $field=="Ward")	return 7;
	if($table=="Ward Round Sheet" && $field=="Bed")	return 8;
	if($table=="Ward Round Sheet" && $field=="Code")	return 9;
	if($table=="Ward Round Sheet" && $field=="Category")	return 10;
	if($table=="Ward Round Sheet" && $field=="Admission Date")	return 11;
	if($table=="Ward Round Sheet" && $field=="Diagnosis")	return 12;
	if($table=="Ward Round Sheet" && $field=="Allergies")	return 13;
	if($table=="Ward Round Sheet" && $field=="Notes")	return 14;
	if($table=="Ward Round Sheet" && $field=="Nurses")	return 15;
	if($table=="Ward Round Sheet" && $field=="Social Services")	return 16;
	if($table=="Ward Round Sheet" && $field=="Team")	return 17;
	if($table=="Ward Round Sheet" && $field=="Ward Round Notes")	return 18;

	// Sign-Out Sheet
	if($table=="Sign-Out Sheet" && $field=="Primary")	return 1;
	if($table=="Sign-Out Sheet" && $field=="Patient Name")	return 2;
	if($table=="Sign-Out Sheet" && $field=="Date of Birth")	return 3;
	if($table=="Sign-Out Sheet" && $field=="Unit Number")	return 4;
	if($table=="Sign-Out Sheet" && $field=="Sex")	return 5;
	if($table=="Sign-Out Sheet" && $field=="Ward")	return 6;
	if($table=="Sign-Out Sheet" && $field=="Bed")	return 7;
	if($table=="Sign-Out Sheet" && $field=="Consultant")	return 8;
	if($table=="Sign-Out Sheet" && $field=="Code")	return 9;
	if($table=="Sign-Out Sheet" && $field=="Category")	return 10;
	if($table=="Sign-Out Sheet" && $field=="Admission Date")	return 11;
	if($table=="Sign-Out Sheet" && $field=="Diagnosis")	return 12;
	if($table=="Sign-Out Sheet" && $field=="Allergies")	return 13;
	if($table=="Sign-Out Sheet" && $field=="Notes")	return 14;
	if($table=="Sign-Out Sheet" && $field=="Nurses")	return 15;
	if($table=="Sign-Out Sheet" && $field=="Social Services")	return 16;
	if($table=="Sign-Out Sheet" && $field=="Team")	return 17;
	if($table=="Sign-Out Sheet" && $field=="Ward Round Notes")	return 18;

	// users
	if($table=="users" && $field=="Primary")	return 1;
	if($table=="users" && $field=="Login")	return 2;
	if($table=="users" && $field=="Name")	return 3;
	if($table=="users" && $field=="Password")	return 4;
	if($table=="users" && $field=="User Type")	return 5;

	// consultants
	if($table=="consultants" && $field=="Primary")	return 1;
	if($table=="consultants" && $field=="Consultant")	return 2;

	// ward list
	if($table=="ward list" && $field=="Primary")	return 1;
	if($table=="ward list" && $field=="Ward")	return 2;
	return 0;
}



//	return Date field edit type
function DateEditType($field,$table="")
{
	global $strTableName;
	if(!$table)
		$table=$strTableName;


	// jobs
	if($table=="jobs" && $field=="Primary") 
		return 0;
	if($table=="jobs" && $field=="Patient Name") 
		return 0;
	if($table=="jobs" && $field=="Date") 
		return 11;
	if($table=="jobs" && $field=="Type") 
		return 0;
	if($table=="jobs" && $field=="Status") 
		return 0;
	if($table=="jobs" && $field=="Name") 
		return 0;
	if($table=="jobs" && $field=="Result") 
		return 0;
	if($table=="jobs" && $field=="Notes") 
		return 0;
	if($table=="jobs" && $field=="Consultant") 
		return 0;

	// patients
	if($table=="patients" && $field=="Primary") 
		return 0;
	if($table=="patients" && $field=="Patient Name") 
		return 0;
	if($table=="patients" && $field=="Date of Birth") 
		return 13;
	if($table=="patients" && $field=="Unit Number") 
		return 0;
	if($table=="patients" && $field=="Sex") 
		return 0;
	if($table=="patients" && $field=="Ward") 
		return 0;
	if($table=="patients" && $field=="Bed") 
		return 0;
	if($table=="patients" && $field=="Consultant") 
		return 0;
	if($table=="patients" && $field=="Code") 
		return 0;
	if($table=="patients" && $field=="Category") 
		return 0;
	if($table=="patients" && $field=="Admission Date") 
		return 13;
	if($table=="patients" && $field=="Diagnosis") 
		return 0;
	if($table=="patients" && $field=="Allergies") 
		return 0;
	if($table=="patients" && $field=="Notes") 
		return 0;
	if($table=="patients" && $field=="Nurses") 
		return 0;
	if($table=="patients" && $field=="Social Services") 
		return 0;
	if($table=="patients" && $field=="Team") 
		return 0;
	if($table=="patients" && $field=="Ward Round Notes") 
		return 0;

	// Nursing Handover
	if($table=="Nursing Handover" && $field=="Primary") 
		return 0;
	if($table=="Nursing Handover" && $field=="Patient Name") 
		return 0;
	if($table=="Nursing Handover" && $field=="Date of Birth") 
		return 11;
	if($table=="Nursing Handover" && $field=="Unit Number") 
		return 0;
	if($table=="Nursing Handover" && $field=="Sex") 
		return 0;
	if($table=="Nursing Handover" && $field=="Ward") 
		return 0;
	if($table=="Nursing Handover" && $field=="Bed") 
		return 0;
	if($table=="Nursing Handover" && $field=="Consultant") 
		return 0;
	if($table=="Nursing Handover" && $field=="Code") 
		return 0;
	if($table=="Nursing Handover" && $field=="Category") 
		return 0;
	if($table=="Nursing Handover" && $field=="Admission Date") 
		return 13;
	if($table=="Nursing Handover" && $field=="Diagnosis") 
		return 0;
	if($table=="Nursing Handover" && $field=="Allergies") 
		return 0;
	if($table=="Nursing Handover" && $field=="Notes") 
		return 0;
	if($table=="Nursing Handover" && $field=="Nurses") 
		return 0;
	if($table=="Nursing Handover" && $field=="Social Services") 
		return 0;
	if($table=="Nursing Handover" && $field=="Team") 
		return 0;
	if($table=="Nursing Handover" && $field=="Ward Round Notes") 
		return 0;

	// Current Patients
	if($table=="Current Patients" && $field=="Primary") 
		return 0;
	if($table=="Current Patients" && $field=="Patient Name") 
		return 0;
	if($table=="Current Patients" && $field=="Date of Birth") 
		return 11;
	if($table=="Current Patients" && $field=="Unit Number") 
		return 0;
	if($table=="Current Patients" && $field=="Sex") 
		return 0;
	if($table=="Current Patients" && $field=="Ward") 
		return 0;
	if($table=="Current Patients" && $field=="Bed") 
		return 0;
	if($table=="Current Patients" && $field=="Consultant") 
		return 0;
	if($table=="Current Patients" && $field=="Code") 
		return 0;
	if($table=="Current Patients" && $field=="Category") 
		return 0;
	if($table=="Current Patients" && $field=="Admission Date") 
		return 11;
	if($table=="Current Patients" && $field=="Diagnosis") 
		return 0;
	if($table=="Current Patients" && $field=="Allergies") 
		return 0;
	if($table=="Current Patients" && $field=="Notes") 
		return 0;
	if($table=="Current Patients" && $field=="Nurses") 
		return 0;
	if($table=="Current Patients" && $field=="Social Services") 
		return 0;
	if($table=="Current Patients" && $field=="Team") 
		return 0;
	if($table=="Current Patients" && $field=="Ward Round Notes") 
		return 0;

	// Current Jobs
	if($table=="Current Jobs" && $field=="Primary") 
		return 0;
	if($table=="Current Jobs" && $field=="Patient Name") 
		return 0;
	if($table=="Current Jobs" && $field=="Date") 
		return 11;
	if($table=="Current Jobs" && $field=="Type") 
		return 0;
	if($table=="Current Jobs" && $field=="Status") 
		return 0;
	if($table=="Current Jobs" && $field=="Name") 
		return 0;
	if($table=="Current Jobs" && $field=="Result") 
		return 0;
	if($table=="Current Jobs" && $field=="Notes") 
		return 0;
	if($table=="Current Jobs" && $field=="Consultant") 
		return 0;

	// Ward Round Sheet
	if($table=="Ward Round Sheet" && $field=="Primary") 
		return 0;
	if($table=="Ward Round Sheet" && $field=="Consultant") 
		return 0;
	if($table=="Ward Round Sheet" && $field=="Patient Name") 
		return 0;
	if($table=="Ward Round Sheet" && $field=="Date of Birth") 
		return 13;
	if($table=="Ward Round Sheet" && $field=="Unit Number") 
		return 0;
	if($table=="Ward Round Sheet" && $field=="Sex") 
		return 0;
	if($table=="Ward Round Sheet" && $field=="Ward") 
		return 0;
	if($table=="Ward Round Sheet" && $field=="Bed") 
		return 0;
	if($table=="Ward Round Sheet" && $field=="Code") 
		return 0;
	if($table=="Ward Round Sheet" && $field=="Category") 
		return 0;
	if($table=="Ward Round Sheet" && $field=="Admission Date") 
		return 13;
	if($table=="Ward Round Sheet" && $field=="Diagnosis") 
		return 0;
	if($table=="Ward Round Sheet" && $field=="Allergies") 
		return 0;
	if($table=="Ward Round Sheet" && $field=="Notes") 
		return 0;
	if($table=="Ward Round Sheet" && $field=="Nurses") 
		return 0;
	if($table=="Ward Round Sheet" && $field=="Social Services") 
		return 0;
	if($table=="Ward Round Sheet" && $field=="Team") 
		return 0;
	if($table=="Ward Round Sheet" && $field=="Ward Round Notes") 
		return 0;

	// Sign-Out Sheet
	if($table=="Sign-Out Sheet" && $field=="Primary") 
		return 0;
	if($table=="Sign-Out Sheet" && $field=="Patient Name") 
		return 0;
	if($table=="Sign-Out Sheet" && $field=="Date of Birth") 
		return 13;
	if($table=="Sign-Out Sheet" && $field=="Unit Number") 
		return 0;
	if($table=="Sign-Out Sheet" && $field=="Sex") 
		return 0;
	if($table=="Sign-Out Sheet" && $field=="Ward") 
		return 0;
	if($table=="Sign-Out Sheet" && $field=="Bed") 
		return 0;
	if($table=="Sign-Out Sheet" && $field=="Consultant") 
		return 0;
	if($table=="Sign-Out Sheet" && $field=="Code") 
		return 0;
	if($table=="Sign-Out Sheet" && $field=="Category") 
		return 0;
	if($table=="Sign-Out Sheet" && $field=="Admission Date") 
		return 13;
	if($table=="Sign-Out Sheet" && $field=="Diagnosis") 
		return 0;
	if($table=="Sign-Out Sheet" && $field=="Allergies") 
		return 0;
	if($table=="Sign-Out Sheet" && $field=="Notes") 
		return 0;
	if($table=="Sign-Out Sheet" && $field=="Nurses") 
		return 0;
	if($table=="Sign-Out Sheet" && $field=="Social Services") 
		return 0;
	if($table=="Sign-Out Sheet" && $field=="Team") 
		return 0;
	if($table=="Sign-Out Sheet" && $field=="Ward Round Notes") 
		return 0;

	// users
	if($table=="users" && $field=="Primary") 
		return 0;
	if($table=="users" && $field=="Login") 
		return 0;
	if($table=="users" && $field=="Name") 
		return 0;
	if($table=="users" && $field=="Password") 
		return 0;
	if($table=="users" && $field=="User Type") 
		return 0;

	// consultants
	if($table=="consultants" && $field=="Primary") 
		return 0;
	if($table=="consultants" && $field=="Consultant") 
		return 0;

	// ward list
	if($table=="ward list" && $field=="Primary") 
		return 0;
	if($table=="ward list" && $field=="Ward") 
		return 0;
	return false;
}

// returns text edit parameters
function GetEditParams($field, $table="")
{
	global $strTableName;
	if(!$table)
		$table=$strTableName;

//	jobs

	if($table=="jobs" && $field=="Primary") 
	{
		$ret="";
							return $ret;
	} 
	if($table=="jobs" && $field=="Patient Name") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="jobs" && $field=="Type") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="jobs" && $field=="Status") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="jobs" && $field=="Name") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="jobs" && $field=="Result") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="jobs" && $field=="Notes") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="jobs" && $field=="Consultant") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 

//	patients

	if($table=="patients" && $field=="Primary") 
	{
		$ret="";
							return $ret;
	} 
	if($table=="patients" && $field=="Patient Name") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="patients" && $field=="Unit Number") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="patients" && $field=="Sex") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="patients" && $field=="Ward") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="patients" && $field=="Bed") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="patients" && $field=="Consultant") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="patients" && $field=="Code") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="patients" && $field=="Category") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="patients" && $field=="Diagnosis") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="patients" && $field=="Allergies") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="patients" && $field=="Notes") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="patients" && $field=="Nurses") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="patients" && $field=="Social Services") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="patients" && $field=="Team") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="patients" && $field=="Ward Round Notes") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 

//	Nursing Handover

	if($table=="Nursing Handover" && $field=="Primary") 
	{
		$ret="";
							return $ret;
	} 
	if($table=="Nursing Handover" && $field=="Patient Name") 
	{
		$ret="";
							return $ret;
	} 
	if($table=="Nursing Handover" && $field=="Unit Number") 
	{
		$ret="";
							return $ret;
	} 
	if($table=="Nursing Handover" && $field=="Bed") 
	{
		$ret="";
							return $ret;
	} 
	if($table=="Nursing Handover" && $field=="Category") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="Nursing Handover" && $field=="Diagnosis") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="Nursing Handover" && $field=="Allergies") 
	{
		$ret="";
							return $ret;
	} 
	if($table=="Nursing Handover" && $field=="Notes") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="Nursing Handover" && $field=="Nurses") 
	{
		$ret="";
							return $ret;
	} 
	if($table=="Nursing Handover" && $field=="Social Services") 
	{
		$ret="";
							return $ret;
	} 
	if($table=="Nursing Handover" && $field=="Team") 
	{
		$ret="";
							return $ret;
	} 
	if($table=="Nursing Handover" && $field=="Ward Round Notes") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 

//	Current Patients

	if($table=="Current Patients" && $field=="Primary") 
	{
		$ret="";
							return $ret;
	} 
	if($table=="Current Patients" && $field=="Patient Name") 
	{
		$ret="";
							return $ret;
	} 
	if($table=="Current Patients" && $field=="Unit Number") 
	{
		$ret="";
							return $ret;
	} 
	if($table=="Current Patients" && $field=="Bed") 
	{
		$ret="";
							return $ret;
	} 
	if($table=="Current Patients" && $field=="Diagnosis") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="Current Patients" && $field=="Allergies") 
	{
		$ret="";
							return $ret;
	} 
	if($table=="Current Patients" && $field=="Notes") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="Current Patients" && $field=="Nurses") 
	{
		$ret="";
							return $ret;
	} 
	if($table=="Current Patients" && $field=="Social Services") 
	{
		$ret="";
							return $ret;
	} 
	if($table=="Current Patients" && $field=="Team") 
	{
		$ret="";
							return $ret;
	} 
	if($table=="Current Patients" && $field=="Ward Round Notes") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 

//	Current Jobs

	if($table=="Current Jobs" && $field=="Primary") 
	{
		$ret="";
							return $ret;
	} 
	if($table=="Current Jobs" && $field=="Name") 
	{
		$ret="";
							return $ret;
	} 
	if($table=="Current Jobs" && $field=="Result") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="Current Jobs" && $field=="Notes") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 

//	Ward Round Sheet

	if($table=="Ward Round Sheet" && $field=="Primary") 
	{
		$ret="";
							return $ret;
	} 
	if($table=="Ward Round Sheet" && $field=="Consultant") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="Ward Round Sheet" && $field=="Patient Name") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="Ward Round Sheet" && $field=="Unit Number") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="Ward Round Sheet" && $field=="Sex") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="Ward Round Sheet" && $field=="Ward") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="Ward Round Sheet" && $field=="Bed") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="Ward Round Sheet" && $field=="Code") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="Ward Round Sheet" && $field=="Category") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="Ward Round Sheet" && $field=="Diagnosis") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="Ward Round Sheet" && $field=="Allergies") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="Ward Round Sheet" && $field=="Notes") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="Ward Round Sheet" && $field=="Nurses") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="Ward Round Sheet" && $field=="Social Services") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="Ward Round Sheet" && $field=="Team") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="Ward Round Sheet" && $field=="Ward Round Notes") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 

//	Sign-Out Sheet

	if($table=="Sign-Out Sheet" && $field=="Primary") 
	{
		$ret="";
							return $ret;
	} 
	if($table=="Sign-Out Sheet" && $field=="Patient Name") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="Sign-Out Sheet" && $field=="Unit Number") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="Sign-Out Sheet" && $field=="Sex") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="Sign-Out Sheet" && $field=="Ward") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="Sign-Out Sheet" && $field=="Bed") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="Sign-Out Sheet" && $field=="Consultant") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="Sign-Out Sheet" && $field=="Code") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="Sign-Out Sheet" && $field=="Category") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="Sign-Out Sheet" && $field=="Diagnosis") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="Sign-Out Sheet" && $field=="Allergies") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="Sign-Out Sheet" && $field=="Notes") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="Sign-Out Sheet" && $field=="Nurses") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="Sign-Out Sheet" && $field=="Social Services") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="Sign-Out Sheet" && $field=="Team") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 
	if($table=="Sign-Out Sheet" && $field=="Ward Round Notes") 
	{
		$ret="";
					$ret.=" rows=5";
				$ret.=" cols=60";
		return $ret;
	} 

//	users

	if($table=="users" && $field=="Primary") 
	{
		$ret="";
							return $ret;
	} 
	if($table=="users" && $field=="Login") 
	{
		$ret="";
							return $ret;
	} 
	if($table=="users" && $field=="Name") 
	{
		$ret="";
							return $ret;
	} 
	if($table=="users" && $field=="Password") 
	{
		$ret="";
							return $ret;
	} 

//	consultants

	if($table=="consultants" && $field=="Primary") 
	{
		$ret="";
							return $ret;
	} 
	if($table=="consultants" && $field=="Consultant") 
	{
		$ret="";
							return $ret;
	} 

//	ward list

	if($table=="ward list" && $field=="Primary") 
	{
		$ret="";
							return $ret;
	} 
	if($table=="ward list" && $field=="Ward") 
	{
		$ret="";
							return $ret;
	} 
	return "";
}


////////////////////////////////////////////////////////////////////////////////
// data output functions
////////////////////////////////////////////////////////////////////////////////

//	format field value for output
function GetData($data,$field, $format)
{
	global $thumbnail_fields,$thumbnail_prefixes,$thumbnail_maxsize, $strTableName;
	$ret="";
// long binary data?
	if(IsBinaryType(GetFieldType($field)))
	{
		$ret="LONG BINARY DATA - CANNOT BE DISPLAYED";
	} else
		$ret = $data[$field];
	if($ret===false)
		return "";
	
	if($format == FORMAT_DATE_SHORT) 
		$ret = format_shortdate(db2time($data[$field]));
	else if($format == FORMAT_DATE_LONG) 
		$ret = format_longdate(db2time($data[$field]));
	else if($format == FORMAT_DATE_TIME) 
		$ret = format_datetime(db2time($data[$field]));
	else if($format == FORMAT_TIME) 
	{
		if(IsDateFieldType(GetFieldType($field)))
			$ret = format_time(db2time($data[$field]));
		else
		{
			$numbers=parsenumbers($data[$field]);
			if(!count($numbers))
				return "";
			while(count($numbers)<3)
				$numbers[]=0;
			$ret = format_time(array(0,0,0,$numbers[0],$numbers[1],$numbers[2]));
		}
	}
	else if($format == FORMAT_NUMBER) 
		$ret = format_number($data[$field]);
	else if($format == FORMAT_CURRENCY) 
		$ret = format_currency($data[$field]);
	else if($format == FORMAT_CHECKBOX) 
	{
		$ret="<img src=\"images/check_";
		if($data[$field] && $data[$field]!=0)
			$ret.="yes";
		else
			$ret.="no";
		$ret.=".gif\" border=0>";
	}
	else if($format == FORMAT_PERCENT) 
		$ret = ($data[$field]*100)."%";
	else if($format == FORMAT_PHONE_NUMBER)
	{
		if(strlen($ret)==7)
			$ret=substr($ret,0,3)."-".substr($ret,3);
		else if(strlen($ret)==10)
			$ret="(".substr($ret,0,3).") ".substr($ret,3,3)."-".substr($ret,6);
	}
	else if($format == FORMAT_FILE_IMAGE)
	{
		if(!CheckImageExtension($ret))
			return "";
//	thumbnails ?
		$thumbnailed=false;
		if(!(array_search($field,$thumbnail_fields)===FALSE))
		{
		 	// show thumbnail
			$thumbname=$ret;
			$lasti = my_strrpos($thumbname,".");
			if(!($lasti===false))
				$thumbname=substr($thumbname,0,$lasti);
			$thumbname.=".gif";
			$thumbname=$thumbnail_prefixes[$field].$thumbname;
			if(file_exists(GetUploadFolder($field).$thumbname))
			{
				$ret = "<a target=_blank href=\"".AddLinkPrefix($field,$ret)."\"><img border=0 src=\"".AddLinkPrefix($field,$thumbname)."\"></a>";
				$thumbnailed=true;
			}
		}
		if(!$thumbnailed)
			$ret='<img src="'.AddLinkPrefix($field,$ret).'" border=0>';
	}
	else if($format == FORMAT_HYPERLINK)
	{
		$ret=GetHyperlink($ret,$field,$data);
	}
	else if($format==FORMAT_EMAILHYPERLINK)
	{
		$link=$ret;
		$title=$ret;
		if(substr($ret,0,7)=="mailto:")
			$title=substr($ret,8);
		else
			$link="mailto:".$link;
		$ret='<a href="'.$link.'">'.$title.'</a>';
	}
	else if($format==FORMAT_FILE)
	{
		$iquery="field=".urlencode($field);
		if($strTableName=="jobs")
		{
			$iquery.="&key1=".urlencode($data["Primary"]);
		}
		if($strTableName=="patients")
		{
			$iquery.="&key1=".urlencode($data["Primary"]);
		}
		if($strTableName=="Nursing Handover")
		{
			$iquery.="&key1=".urlencode($data["Primary"]);
		}
		if($strTableName=="Current Patients")
		{
			$iquery.="&key1=".urlencode($data["Primary"]);
		}
		if($strTableName=="Current Jobs")
		{
			$iquery.="&key1=".urlencode($data["Primary"]);
		}
		if($strTableName=="Ward Round Sheet")
		{
			$iquery.="&key1=".urlencode($data["Primary"]);
		}
		if($strTableName=="Sign-Out Sheet")
		{
			$iquery.="&key1=".urlencode($data["Primary"]);
		}
		if($strTableName=="users")
		{
			$iquery.="&key1=".urlencode($data["Primary"]);
		}
		if($strTableName=="consultants")
		{
			$iquery.="&key1=".urlencode($data["Primary"]);
		}
		if($strTableName=="ward list")
		{
			$iquery.="&key1=".urlencode($data["Primary"]);
		}
		return 	'<a href="'.GetTableURL($strTableName).'_download.php?'.$iquery.'".>'.$ret.'</a>';
	}
	else if(GetEditFormat($field)==EDIT_FORMAT_CHECKBOX && $format==FORMAT_NONE)
	{
		if($ret && $ret!=0)
			$ret="Yes";
		else
			$ret="No";
	}
	else if($format == FORMAT_CUSTOM) 
		$ret = CustomExpression($data,$field);
	return $ret;
}

//	return custom expression
function CustomExpression($data,$field,$table="")
{
	global $strTableName;
	if(!$table)
		$table=$strTableName;
	$value=$data[$field];
	return $value;
}


function ProcessLargeText($strValue,$iquery="",$table="", $mode=MODE_LIST)
{
	global $strTableName;

	$cNumberOfChars = GetNumberOfChars($table);
	if(substr($strValue,0,8)=="<a href=")
		return $strValue;
	if(substr($strValue,0,23)=="<img src=\"images/check_")
		return $strValue;
	if($cNumberOfChars>0 && strlen($strValue)>$cNumberOfChars && (strlen($strValue)<200 || !strlen($iquery)) && $mode==MODE_LIST)
	{
		$ret = substr($strValue,0,$cNumberOfChars );
		$ret=htmlspecialchars($ret);
		$ret.=" <a href=\"#\" onClick=\"javascript: pwin = window.open('',null,'height=300,width=400,status=yes,resizable=yes,toolbar=no,menubar=no,location=no,left=150,top=200,scrollbars=yes'); ";
		$ind = 1;
		$ret.="pwin.document.write('" . jsreplace(str_replace("\r\n","<br>",htmlspecialchars(substr($strValue,0, 801)))) ."');";
//		$ret.="pwin.document.write('" . db_addslashes(str_replace("\r\n","<br>",htmlspecialchars(substr($strValue,0, 801)))) ."');";
		$ret.="pwin.document.write('<br><hr size=1 noshade><a href=# onClick=\\'window.close();return false;\\'>"."Close window"."</a>');";
		$ret.="return false;\">"."More"." ...</a>";
	}
	else if($cNumberOfChars>0 && strlen($strValue)>$cNumberOfChars && $mode==MODE_LIST)
	{
		$table = GetTableURL($table);
		$ret = substr($strValue,0,$cNumberOfChars );
		$ret=htmlspecialchars($ret);
		$ret.=" <a href=#  onClick=\"javascript: pwin = window.open('',null,'height=300,width=400,status=yes,resizable=yes,toolbar=no,menubar=no,location=no,left=150,top=200,scrollbars=yes');";
		$ret.=" pwin.location='".$table."_fulltext.php?".$iquery."'; return false;\">"."More"." ...</a>";
	}
	else if($cNumberOfChars>0 && strlen($strValue)>$cNumberOfChars && $mode==MODE_PRINT)
	{
		$ret = substr($strValue,0,$cNumberOfChars );
		if(strlen($strValue)>$cNumberOfChars)
			$ret.=" ...";
	}
	else
		$ret= htmlspecialchars($strValue);

/*
//	highlight search results
	if ($mode==MODE_LIST && $_SESSION[$strTableName."_search"]==1)
	{
		$ind = 0;
		$searchopt=$_SESSION[$strTableName."_searchoption"];
		$searchfor=$_SESSION[$strTableName."_searchfor"];
//		highlight Contains search
		if($searchopt=="Contains")
		{
			while ( ($ind = my_stripos($ret, $searchfor, $ind)) !== false )
			{
				$ret = substr($ret, 0, $ind) . "<span class=highlight>". substr($ret, $ind, strlen($searchfor)) ."</span>" . substr($ret, $ind + strlen($searchfor));
				$ind+= strlen("<span class=highlight>") + strlen($searchfor) + strlen("</span>");
			}
		}
//		highlight Starts with search
		elseif($searchopt=="Starts with ...")
		{
			if( !strncasecmp($ret, $searchfor,strlen($searchfor)) )
				$ret = "<span class=highlight>". substr($ret, 0, strlen($searchfor)) ."</span>" . substr($ret, strlen($searchfor));
		}
		elseif($searchopt=="Equals")
		{
			if( !strcasecmp($ret, $searchfor) )
				$ret = "<span class=highlight>". $ret ."</span>";
		}
		elseif($searchopt=="More than ...")
		{
			if( strtoupper($ret)>strtoupper($searchfor) )
				$ret = "<span class=highlight>". $ret ."</span>";
		}
		elseif($searchopt=="Less than ...")
		{
			if( strtoupper($ret)<strtoupper($searchfor) )
				$ret = "<span class=highlight>". $ret ."</span>";
		}
		elseif($searchopt=="Equal or more than ...")
		{
			if( strtoupper($ret)>=strtoupper($searchfor) )
				$ret = "<span class=highlight>". $ret ."</span>";
		}
		elseif($searchopt=="Equal or less than ...")
		{
			if( strtoupper($ret)<=strtoupper($searchfor) )
				$ret = "<span class=highlight>". $ret ."</span>";
		}
	}
*/
	return nl2br($ret);
}

//	construct hyperlink
function GetHyperlink($str, $field,$data,$table="")
{
	global $strTableName;
	if(!strlen($table))
		$table=$strTableName;
	if(!strlen($str))
		return "";
	$ret=$str;
	$title=$ret;
	$link=$ret;
	if(substr($ret,strlen($ret)-1)=='#')
	{
		$i=strpos($ret,'#');
		$title=substr($ret,0,$i);
		$link=substr($ret,$i+1,strlen($ret)-$i-2);
		if(!$title)
			$title=$link;
	}
	$target="";
	
	if("jobs"==$table) {
	} 
	if("patients"==$table) {
	} 
	if("Nursing Handover"==$table) {
	} 
	if("Current Patients"==$table) {
	} 
	if("Current Jobs"==$table) {
	} 
	if("Ward Round Sheet"==$table) {
	} 
	if("Sign-Out Sheet"==$table) {
	} 
	if("users"==$table) {
	} 
	if("consultants"==$table) {
	} 
	if("ward list"==$table) {
	} 
	if(strpos($link,"://")===false && substr($link,0,7)!="mailto:")
		$link=$prefix.$link;
	$ret='<a href="'.$link.'"'.$target.'>'.$title.'</a>';
	return $ret;
}

//	add prefix to the URL
function AddLinkPrefix($field,$link,$table="")
{
	if(strpos($link,"://")===false && substr($link,0,7)!="mailto:")
		return GetLinkPrefix($field,$table).$link;
	return $link;
}

//	return Totals string
function GetTotals($value, $stype, $iNumberOfRows,$sFormat)
{
	if($stype=="AVERAGE")
	{
		if($iNumberOfRows)
			$value=$value/$iNumberOfRows;
		else
			return "";
	}
	if($sFormat == FORMAT_CURRENCY)
	 	$value = format_currency($value);
	else if($sFormat == FORMAT_NUMBER)
 		$value = format_number($value);

	if($stype=="COUNT") 
		return $iNumberOfRows;
	if($stype=="TOTAL") 
		return $value;
	if($stype=="AVERAGE") 
		return $value;
	return "";
}


////////////////////////////////////////////////////////////////////////////////
// miscellaneous functions
////////////////////////////////////////////////////////////////////////////////


//	refine value passed by POST or GET method
function refine($str)
{
	$ret=$str;
	if(get_magic_quotes_gpc())
		$ret=stripslashes($str);
	return html_special_decode($ret);
}

//	return refined POST or GET value - single value or array
function postvalue($name)
{
	if(array_key_exists($name,$_POST))
		$value=$_POST[$name];
	else if(array_key_exists($name,$_GET))
		$value=$_GET[$name];
	else
		return "";
	if(!is_array($value))
		return refine($value);
	$ret=array();
	foreach($value as $key=>$val)
		$ret[$key]=refine($val);
	return $ret;
}

//	analog of strrpos function
function my_strrpos($haystack, $needle) {
   $index = strpos(strrev($haystack), strrev($needle));
   if($index === false) {
       return false;
   }
   $index = strlen($haystack) - strlen($needle) - $index;
   return $index;
}

//	utf-8 analog of strlen function
function strlen_utf8($str)
{
	$len=0;
	$i=0;
	$olen=strlen($str);
	while($i<$olen)
	{
		$c=ord($str[$i]);
		if($c<128)
			$i++;
		else if($i<$olen-1 && $c>=192 && $c<=223)
			$i+=2;
		else if($i<$olen-2 && $c>=224 && $c<=239)
			$i+=3;
		else if($i<$olen-3 && $c>=240)
			$i+=4;
		else
			break;
		$len++;
	}
	return $len;
}

//	utf-8 analog of substr function
function substr_utf8($str,$index,$strlen)
{
	if($strlen<=0)
		return "";
	$len=0;
	$i=0;
	$olen=strlen($str);
	$oindex=-1;
	while($i<$olen)
	{
		if($len==$index)
			$oindex=$i;
		
		$c=ord($str[$i]);
		if($c<128)
			$i++;
		else if($i<$olen-1 && $c>=192 && $c<=223)
			$i+=2;
		else if($i<$olen-2 && $c>=224 && $c<=239)
			$i+=3;
		else if($i<$olen-3 && $c>=240)
			$i+=4;
		else
			break;
		$len++;
		if($oindex>=0 && $len==$index+$strlen)
			return substr($str,$oindex,$i-$oindex);
	}
	if($oindex>0)
		return substr($str,$oindex,$olen-$oindex);
	return "";
}

//	read the whole file and return contents
function myfile_get_contents($filename)
{
	if(!file_exists($filename))
		return false;
	$handle = fopen($filename, "rb");
	if(!$handle)
		return false;
	fseek($handle, 0 , SEEK_END);
	$fsize = ftell($handle);
	fseek($handle, 0 , SEEK_SET);
	
	if($fsize)
		$contents = fread($handle, $fsize);
	else
		$contents="";
	fclose($handle);
	return $contents;
}

//	construct "good" field name
function GoodFieldName($field)
{
	for($i=0;$i<strlen($field);$i++)
	{
		$t=ord($field[$i]);
		if(($t<ord('a') || $t>ord('z')) && ($t<ord('A') || $t>ord('Z')) && ($t<ord('0') || $t>ord('9')))
			$field[$i]='_';
	}
	return $field;
}

//	prepare string for JavaScript. Replace ' with \' and linebreaks with \r\n
function jsreplace($str)
{
	return str_replace(array("'","\r","\n","\\"),array("\\'","\\r","\\n","\\\\"),$str);
}

//	display error message
function error_handler($errno, $errstr, $errfile, $errline)
{
	global $strSQL;
	if($errno==8 && !strncmp($errstr,"Undefined index",15))
		return 0;
	if(strpos($errstr,"It is not safe to rely on the system's timezone settings."))
		return 0;
//////////////////////////////////////////////////////////////////////////////////////////////
	class XMLParser 
	{
		var $filename;
		var $xml;
		var $data;
   
		function XMLParser($xml_file)
		{
			$this->filename = $xml_file;
			$this->xml = xml_parser_create();
			xml_set_object($this->xml, $this);
			xml_set_element_handler($this->xml, 'startHandler', 'endHandler');
			xml_set_character_data_handler($this->xml, 'dataHandler');
			$this->parse($xml_file);
		}
   
		function parse($xml_file)
		{
			if (!($fp = fopen($xml_file, 'r'))) 
			{
				die('Cannot open XML data file: '.$xml_file);
            return false;
			}

			$bytes_to_parse = 512;

			while ($data = fread($fp, $bytes_to_parse)) 
			{
				$parse = xml_parse($this->xml, $data, feof($fp));
           
				if (!$parse) 
				{
					die(sprintf("XML error: %s at line %d",
					xml_error_string(xml_get_error_code($this->xml)),
                       xml_get_current_line_number($this->xml)));
                    xml_parser_free($this->xml);
				}
			}

			return true;
		}
   
		function startHandler($parser, $name, $attributes)
		{
			$data['name'] = $name;
			if ($attributes) 
			{
				$data['attributes'] = $attributes; 
			}
			$this->data[] = $data;
		}

		function dataHandler($parser, $data)
		{
			if ($data = trim($data)) 
			{
				$index = count($this->data) - 1;
				if(isset($this->data[$index]['content'])) 
				$this->data[$index]['content'] .= $data;
				else $this->data[$index]['content'] = $data;
			}
		}

		function endHandler($parser, $name)
		{
			if (count($this->data) > 1) 
			{
				$data = array_pop($this->data);
				$index = count($this->data) - 1; 
				$this->data[$index]['child'][] = $data;
			}
		}
	}
	//////////////////////////////////////////////////////////////////////////////

	$solution = "";
	$i = 0;

	$path_to_file = "include/errors.xml";
	$myFile = new XMLParser($path_to_file);
	$size = sizeof($myFile->data[0]['child'])-1;
	for ($i=0; $i<=$size; $i++)
	{
		$keywords = $myFile->data[0]['child'][$i]['child'][1]['content'];
		
		$keys = split(" ",$keywords);
		
		for ($j=0; $j<sizeof($keys)-1; $j++)
		$pos[$j] = strpos(strtoupper($errstr), strtoupper($keys[$j]));
		$nullfound=false;
		foreach($pos as $val)
			if($val===false)
			{
				$nullfound=true;	
				break;
			}
		if(!$nullfound)
			{ 
				$solution = $myFile->data[0]['child'][$i]['child'][5]['content'];
			}

	}
?>
</form>
<p align=center><font size=+2>PHP <?php echo "error happened";?></font></p>
<table border="0" cellpadding="3" cellspacing="1" width="700" bgcolor="#000000" align="center">
<tr><td bgcolor="#ccccff" colspan=2 align=middle><font size=+1><b><?php echo "Technical information";?></b></font></td></tr>
<tr bgcolor="#cccccc"><td bgcolor="#ccccff"><b><?php echo "Error type";?></b></td><td align="left"><?php echo $errno; ?></td></tr>
<tr bgcolor="#cccccc"><td bgcolor="#ccccff"><b><?php echo "Error description";?></b></td><td align="left"><font color=#cc3300><?php echo $errstr?></font></td></tr>
<tr bgcolor="#cccccc"><td bgcolor="#ccccff"><b>URL</b></td><td align="left"><?php echo $_SERVER["SERVER_NAME"].$_SERVER["SCRIPT_NAME"]; if(array_key_exists("QUERY_STRING",$_SERVER)) echo "?".$_SERVER["QUERY_STRING"];?> </td></tr>
<tr bgcolor="#cccccc"><td bgcolor="#ccccff"><b><?php echo "Error file";?></b></td><td align="left"><?php echo $errfile;?></td></tr>
<tr bgcolor="#cccccc"><td bgcolor="#ccccff"><b><?php echo "Error line";?></b></td><td align="left"><?php echo $errline;?></td></tr>
<tr bgcolor="#cccccc"><td bgcolor="#ccccff" ><b><?php echo "SQL query";?></b></td><td align="left"><?php if(isset($strSQL)) echo substr($strSQL,0,1024);?></td></tr>
<?php if ($solution) 
{?>
<tr bgcolor="#cccccc"><td bgcolor="#ccccff"><b>Solution</b></td><td align="left"><font color=#cc3300><?php echo $solution?></font></td></tr>
<?php } ?>
</table>
<?php
  exit(0);
}

function LogInfo($SQL)
{
	global $dSQL,$dDebug;
	$dSQL=$SQL;
	if($dDebug)
	{
		echo $dSQL;
		echo "<br>";
	}
}

//	suggest image type by extension
function SupposeImageType($file)
{
	if(strlen($file)>1 && $file[0]=='B' && $file[1]=='M')
		return "image/bmp";
	if(strlen($file)>2 &&  $file[0]=='G' && $file[1]=='I' && $file[2]=='F')
		return "image/gif";
	if(strlen($file)>6 &&  $file[2]=='J' && $file[3]=='F' && $file[4]=='I' && $file[5]=='F')
		return "image/jpeg";
	if(strlen($file)>10 &&  $file[6]=='J' && $file[7]=='F' && $file[8]=='I' && $file[9]=='F')
		return "image/jpeg";
	if(strlen($file)>10 &&  $file[6]=='E' && $file[7]=='x' && $file[8]=='i' && $file[9]=='f')
		return "image/jpeg";
}

//	check if file extension is image extension
function CheckImageExtension($filename)
{
	if(strlen($filename)<4)
		return false;
	$ext=strtoupper(substr($filename,strlen($filename)-4));
	if($ext==".GIF" || $ext==".JPG" || $ext=="JPEG" || $ext==".PNG" || $ext==".BMP")
		return true;
	return false;
} 


function RTESafe($strText)
{
//	returns safe code for preloading in the RTE
	$tmpString="";
	
	$tmpString = trim($strText);
	if(!$tmpString) return "";
	
//	convert all types of single quotes
	$tmpString = str_replace( chr(145), chr(39),$tmpString);
	$tmpString = str_replace( chr(146), chr(39),$tmpString);
	$tmpString = str_replace("'", "&#39;",$tmpString);
	
//	convert all types of double quotes
	$tmpString = str_replace(chr(147), chr(34),$tmpString);
	$tmpString = str_replace(chr(148), chr(34),$tmpString);
	
//	replace carriage returns & line feeds
	$tmpString = str_replace(chr(10), " ",$tmpString);
	$tmpString = str_replace(chr(13), " ",$tmpString);
	
	return $tmpString;
}


function now()
{
	return strftime("%Y-%m-%d %H:%M:%S");
}

function html_special_decode($str)
{
	$ret=$str;
	$ret=str_replace("&gt;",">",$ret);
	$ret=str_replace("&lt;","<",$ret);
	$ret=str_replace("&quot;","\"",$ret);
	$ret=str_replace("&#039;","'",$ret);
	$ret=str_replace("&amp;","&",$ret);
	return $ret;
}

////////////////////////////////////////////////////////////////////////////////
// database and SQL related functions
////////////////////////////////////////////////////////////////////////////////

//	add WHERE clause to SQL string
function AddWhere($sql,$where)
{
	if(!strlen($where))
		return $sql;
	$sql=str_replace(array("\r\n","\n","\t")," ",$sql);
	$tsql = strtolower($sql);
	$n = my_strrpos($tsql," where ");
	$n1 = my_strrpos($tsql," group by ");
	if($n1===false)
		$n1=strlen($tsql);
	if($n===false)
		return substr($sql,0,$n1)." where ".$where.substr($sql,$n1);
	else
		return substr($sql,0,$n+strlen(" where "))."(".substr($sql,$n+strlen(" where "),$n1-$n-strlen(" where ")).") and (".$where.")".substr($sql,$n1);
}

//	construct WHERE clause with key values
function KeyWhere(&$keys, $table="")
{
	global $strTableName;
	if(!$table)
		$table=$strTableName;
	$strWhere="";

//	jobs
	if($table=="jobs")
	{
			$value=make_db_value("Primary",$keys["Primary"]);
		if($value==="null")
			$strWhere.=GetFullFieldName("Primary")." is null";
		else
			$strWhere.=GetFullFieldName("Primary")."=".make_db_value("Primary",$keys["Primary"]);
	}

//	patients
	if($table=="patients")
	{
			$value=make_db_value("Primary",$keys["Primary"]);
		if($value==="null")
			$strWhere.=GetFullFieldName("Primary")." is null";
		else
			$strWhere.=GetFullFieldName("Primary")."=".make_db_value("Primary",$keys["Primary"]);
	}

//	Nursing Handover
	if($table=="Nursing Handover")
	{
			$value=make_db_value("Primary",$keys["Primary"]);
		if($value==="null")
			$strWhere.=GetFullFieldName("Primary")." is null";
		else
			$strWhere.=GetFullFieldName("Primary")."=".make_db_value("Primary",$keys["Primary"]);
	}

//	Current Patients
	if($table=="Current Patients")
	{
			$value=make_db_value("Primary",$keys["Primary"]);
		if($value==="null")
			$strWhere.=GetFullFieldName("Primary")." is null";
		else
			$strWhere.=GetFullFieldName("Primary")."=".make_db_value("Primary",$keys["Primary"]);
	}

//	Current Jobs
	if($table=="Current Jobs")
	{
			$value=make_db_value("Primary",$keys["Primary"]);
		if($value==="null")
			$strWhere.=GetFullFieldName("Primary")." is null";
		else
			$strWhere.=GetFullFieldName("Primary")."=".make_db_value("Primary",$keys["Primary"]);
	}

//	Ward Round Sheet
	if($table=="Ward Round Sheet")
	{
			$value=make_db_value("Primary",$keys["Primary"]);
		if($value==="null")
			$strWhere.=GetFullFieldName("Primary")." is null";
		else
			$strWhere.=GetFullFieldName("Primary")."=".make_db_value("Primary",$keys["Primary"]);
	}

//	Sign-Out Sheet
	if($table=="Sign-Out Sheet")
	{
			$value=make_db_value("Primary",$keys["Primary"]);
		if($value==="null")
			$strWhere.=GetFullFieldName("Primary")." is null";
		else
			$strWhere.=GetFullFieldName("Primary")."=".make_db_value("Primary",$keys["Primary"]);
	}

//	users
	if($table=="users")
	{
			$value=make_db_value("Primary",$keys["Primary"]);
		if($value==="null")
			$strWhere.=GetFullFieldName("Primary")." is null";
		else
			$strWhere.=GetFullFieldName("Primary")."=".make_db_value("Primary",$keys["Primary"]);
	}

//	consultants
	if($table=="consultants")
	{
			$value=make_db_value("Primary",$keys["Primary"]);
		if($value==="null")
			$strWhere.=GetFullFieldName("Primary")." is null";
		else
			$strWhere.=GetFullFieldName("Primary")."=".make_db_value("Primary",$keys["Primary"]);
	}

//	ward list
	if($table=="ward list")
	{
			$value=make_db_value("Primary",$keys["Primary"]);
		if($value==="null")
			$strWhere.=GetFullFieldName("Primary")." is null";
		else
			$strWhere.=GetFullFieldName("Primary")."=".make_db_value("Primary",$keys["Primary"]);
	}
	return $strWhere;
}

//	consctruct SQL WHERE clause for simple search
function StrWhere($strField, $SearchFor, $strSearchOption, $SearchFor2)
{
	global $strTableName;
	$type=GetFieldType($strField);
	if($strSearchOption=='Empty')
	{
		if(ischartype($type))
			return "(".GetFullFieldName($strField)." is null or ".GetFullFieldName($strField)."='')";
		else
			return GetFullFieldName($strField)." is null";
	}
	$strQuote="";
	if(NeedQuotes($type))
		$strQuote = "'";
//	return none if trying to compare numeric field and string value
	$sSearchFor=$SearchFor;
	$sSearchFor2=$SearchFor2;
	if(IsBinaryType($type))
		return "";
	
	if(IsDateFieldType($type) && $strSearchOption!="Contains" && $strSearchOption!="Starts with ..." )
	{
		$time=localdatetime2db($SearchFor);
		if($time=="null")
			return "";
		$sSearchFor=db_datequotes($time);
		if($strSearchOption=="Between")
		{
			$time=localdatetime2db($SearchFor2);
			if($time=="null")
				$sSearchFor2="";
			else
				$sSearchFor2=db_datequotes($time);
		}
	}
	
	if(!$strQuote && !is_numeric($sSearchFor) && !is_numeric($sSearchFor))
		return "";
	else if(!$strQuote && $strSearchOption!="Contains" && $strSearchOption!="Starts with ...")
	{
		$sSearchFor = 0+$sSearchFor;
		$sSearchFor2 = 0+$sSearchFor2;
	}
	else if(!IsDateFieldType($type) && $strSearchOption!="Contains" && $strSearchOption!="Starts with ...")
	{
		{
			$sSearchFor=db_upper($strQuote.db_addslashes($sSearchFor).$strQuote);
			if($strSearchOption=="Between" && $sSearchFor2)
				$sSearchFor2=db_upper($strQuote.db_addslashes($sSearchFor2).$strQuote);
		}
	}
	else if(!IsDateFieldType($type))
		$sSearchFor=db_addslashes($sSearchFor);
		
	if(IsCharType($type) )
		$strField=db_upper(GetFullFieldName($strField));
	else
		$strField=GetFullFieldName($strField);
	$ret="";
	if($strSearchOption=="Contains")
	{
		if(IsCharType($type) )
			return $strField." like ".db_upper("'%".$sSearchFor."%'");
		else
			return $strField." like '%".$sSearchFor."%'";
	}
	else if($strSearchOption=="Equals") return $strField."=".$sSearchFor;
	else if($strSearchOption=="Starts with ...")
	{
		if(IsCharType($type) )
			return $strField." like ".db_upper("'".$sSearchFor."%'");
		else
			return $strField." like '".$sSearchFor."%'";
	}
	else if($strSearchOption=="More than ...") return $strField.">".$sSearchFor;
	else if($strSearchOption=="Less than ...") return $strField."<".$sSearchFor;
	else if($strSearchOption=="Equal or more than ...") return $strField.">=".$sSearchFor;
	else if($strSearchOption=="Equal or less than ...") return $strField."<=".$sSearchFor;
	else if($strSearchOption=="Between")
	{
		$ret=$strField.">=".$sSearchFor;
		if($sSearchFor2) $ret.=" and ".$strField."<=".$sSearchFor2;
			return $ret;
	}
	return "";
}

//	construct SQL WHERE clause for Advanced search
function StrWhereAdv($strField, $SearchFor, $strSearchOption, $SearchFor2, $etype)
{
	global $strTableName;
	$type=GetFieldType($strField);
	if(IsBinaryType($type))
		return "";
	if($strSearchOption=='Empty')
	{
		if(ischartype($type))
			return "(".GetFullFieldName($strField)." is null or ".GetFullFieldName($strField)."='')";
		else
			return GetFullFieldName($strField)." is null";
	}
	if(GetEditFormat($strField)==EDIT_FORMAT_LOOKUP_WIZARD)
	{
		$SearchFor=splitvalues($SearchFor);
		$ret="";
		foreach($SearchFor as $value)
		{
			if(!($value=="null" || $value=="Null" || $value==""))
			{
				if(strlen($ret))
					$ret.=" or ";
				if($strSearchOption=="Equals")
				{
					$value=make_db_value($strField,$value);
					if(!($value=="null" || $value=="Null"))
						$ret.=GetFullFieldName($strField).'='.$value;
				}
				else
					$ret.=GetFullFieldName($strField)." like '%".$value."%'";
			}
		}
		if(strlen($ret))
			$ret="(".$ret.")";
		return $ret;
	}
	$value1=make_db_value($strField,$SearchFor,$etype);
	$value2=false;
	if($strSearchOption=="Between")
		$value2=make_db_value($strField,$SearchFor2,$etype);
	if($strSearchOption!="Contains" && $strSearchOption!="Starts with ..." && ($value1==="null" || $value2==="null" ))
		return "";
	if(ischartype($type) )
	{
		$value1=db_upper($value1);
		$value2=db_upper($value2);
		$strField=db_upper(GetFullFieldName($strField));
	}
	else
		$strField=GetFullFieldName($strField);
	$ret="";
	if($strSearchOption=="Contains")
	{
		if(ischartype($type) )
			return $strField." like ".db_upper("'%".db_addslashes($SearchFor)."%'");
		else
			return $strField." like '%".db_addslashes($SearchFor)."%'";
	}
	else if($strSearchOption=="Equals") return $strField."=".$value1;
	else if($strSearchOption=="Starts with ...")
	{
		if(ischartype($type) )
			return $strField." like ".db_upper("'".db_addslashes($SearchFor)."%'");
		else
			return $strField." like '".db_addslashes($SearchFor)."%'";
	}
	else if($strSearchOption=="More than ...") return $strField.">".$value1;
	else if($strSearchOption=="Less than ...") return $strField."<".$value1;
	else if($strSearchOption=="Equal or more than ...") return $strField.">=".$value1;
	else if($strSearchOption=="Equal or less than ...") return $strField."<=".$value1;
	else if($strSearchOption=="Between")
	{
		$ret=$strField.">=".$value1;
		$ret.=" and ".$strField."<=".$value2;
		return $ret;
	}
	return "";
}

//	get count of rows from the query
function GetRowCount($strSQL)
{
	global $conn;
	$strSQL=str_replace(array("\r\n","\n","\t")," ",$strSQL);
	$tstr = strtoupper($strSQL);
	$ind1 = strpos($tstr,"SELECT ");
	$ind2 = my_strrpos($tstr," FROM ");
	$ind3 = my_strrpos($tstr," GROUP BY ");
	if($ind3===false)
	{
		$ind3 = strpos($tstr," ORDER BY ");
		if($ind3===false)
			$ind3=strlen($strSQL);
	}
	$countstr=substr($strSQL,0,$ind1+6)." count(*) ".substr($strSQL,$ind2+1,$ind3-$ind2);
	$countrs = db_query($countstr,$conn);
	$countdata = db_fetch_numarray($countrs);
	return $countdata[0];
}

//	add MSSQL Server TOP clause
function AddTop($strSQL, $n)
{
	$tstr = strtoupper($strSQL);
	$ind1 = strpos($tstr,"SELECT");
	return substr($strSQL,0,$ind1+6)." top $n ".substr($strSQL,$ind1+6);
}

//	add Oracle ROWNUMBER checking
function AddRowNumber($strSQL, $n)
{
	return "select * from (".$strSQL.") where rownum<".($n+1);
}

// test database type if values need to be quoted
function NeedQuotesNumeric($type)
{
    if($type == 203 || $type == 8 || $type == 129 || $type == 130 || 
		$type == 7 || $type == 133 || $type == 134 || $type == 135 ||
		$type == 201 || $type == 205 || $type == 200 || $type == 202 || $type==72 || $type==13)
		return true;
	else
		return false;
}

//	using ADO DataTypeEnum constants
//	the full list available at:
//	http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdcstdatatypeenum.asp

function IsNumberType($type)
{
	if($type==20 || $type==6 || $type==14 || $type==5 || $type==10 
	|| $type==3 || $type==131 || $type==4 || $type==2 || $type==16
	|| $type==21 || $type==19 || $type==18 || $type==17 || $type==139
	|| $type==11)
		return true;
	return false;
}

function NeedQuotes($type)
{
	return !IsNumberType($type);
}

function IsBinaryType($type)
{
	if($type==128 || $type==205 || $type==204)
		return true;
	return false;
}

function IsDateFieldType($type)
{
	if($type==7 || $type==133 || $type==135)
		return true;
	return false;
}

function IsCharType($type)	
{
	if(IsTextType($type) || $type==8 || $type==129 || $type==200 || $type==202 || $type==130)
		return true;
	return false;
}

function IsTextType($type)
{
	if($type==201 || $type==203)
		return true;
	return false;
}

////////////////////////////////////////////////////////////////////////////////
// security functions
////////////////////////////////////////////////////////////////////////////////

//	returns the list of tables available to currently logged user
function GetTables()
{
	if($_SESSION["AccessLevel"] == ACCESS_LEVEL_ADMIN)
		return array(		// admin sees all
			 "jobs"
			,  "patients"
			,  "Nursing Handover"
			,  "Current Patients"
			,  "Current Jobs"
			,  "Ward Round Sheet"
			,  "Sign-Out Sheet"
			,  "users"
			,  "consultants"
			,  "ward list"
		);
	$sUserGroup=@$_SESSION["GroupID"];
	switch($sUserGroup)
	{
		case "admin":
				return array(		// admin sees all
			 "jobs"
			,  "patients"
			,  "Nursing Handover"
			,  "Current Patients"
			,  "Current Jobs"
			,  "Ward Round Sheet"
			,  "Sign-Out Sheet"
			,  "users"
			,  "consultants"
			,  "ward list"
		);
		case "user":
				return array(		// admin sees all
			 "jobs"
			,  "patients"
			,  "Nursing Handover"
			,  "Current Patients"
			,  "Current Jobs"
			,  "Ward Round Sheet"
			,  "Sign-Out Sheet"
			,  "users"
			,  "consultants"
			,  "ward list"
		);
	}
//	default permissions	
	return array();		// grant nothing by default
}



//	return user permissions on the table
//	A - Add
//	D - Delete
//	E - Edit
//	S - List/View/Search
//	P - Print/Export

function GetUserPermissions($table="")
{
	global $strTableName;
	if(!$table)
		$table=$strTableName;
	if($_SESSION["AccessLevel"] == ACCESS_LEVEL_ADMIN)
			return "ADESP";

	$sUserGroup=@$_SESSION["GroupID"];
	if($table=="jobs" && $sUserGroup=="admin")
				return "AEDSP";
	if($table=="jobs" && $sUserGroup=="user")
				return "S";
//	default permissions	
	if($table=="jobs")
		return "";		// grant nothing by default
	if($table=="patients" && $sUserGroup=="admin")
				return "AEDSP";
	if($table=="patients" && $sUserGroup=="user")
				return "S";
//	default permissions	
	if($table=="patients")
		return "";		// grant nothing by default
	if($table=="Nursing Handover" && $sUserGroup=="admin")
				return "AEDSP";
	if($table=="Nursing Handover" && $sUserGroup=="user")
				return "AESP";
//	default permissions	
	if($table=="Nursing Handover")
		return "";		// grant nothing by default
	if($table=="Current Patients" && $sUserGroup=="admin")
				return "AEDSP";
	if($table=="Current Patients" && $sUserGroup=="user")
				return "AESP";
//	default permissions	
	if($table=="Current Patients")
		return "";		// grant nothing by default
	if($table=="Current Jobs" && $sUserGroup=="admin")
				return "AEDSP";
	if($table=="Current Jobs" && $sUserGroup=="user")
				return "AESP";
//	default permissions	
	if($table=="Current Jobs")
		return "";		// grant nothing by default
	if($table=="Ward Round Sheet" && $sUserGroup=="admin")
				return "AEDSP";
	if($table=="Ward Round Sheet" && $sUserGroup=="user")
				return "AESP";
//	default permissions	
	if($table=="Ward Round Sheet")
		return "";		// grant nothing by default
	if($table=="Sign-Out Sheet" && $sUserGroup=="admin")
				return "AEDSP";
	if($table=="Sign-Out Sheet" && $sUserGroup=="user")
				return "AESP";
//	default permissions	
	if($table=="Sign-Out Sheet")
		return "";		// grant nothing by default
	if($table=="users" && $sUserGroup=="admin")
				return "AEDSP";
	if($table=="users" && $sUserGroup=="user")
				return "";
//	default permissions	
	if($table=="users")
		return "";		// grant nothing by default
	if($table=="consultants" && $sUserGroup=="admin")
				return "AEDSP";
	if($table=="consultants" && $sUserGroup=="user")
				return "S";
//	default permissions	
	if($table=="consultants")
		return "";		// grant nothing by default
	if($table=="ward list" && $sUserGroup=="admin")
				return "AEDSP";
	if($table=="ward list" && $sUserGroup=="user")
				return "S";
//	default permissions	
	if($table=="ward list")
		return "";		// grant nothing by default
}


//	check whether field is viewable
function CheckFieldPermissions($field, $table="")
{
	global $strTableName;
	if(!$table)
		$table=$strTableName;

//	jobs
	
	if($table=="jobs" && $field=="Patient Name") return true;
	if($table=="jobs" && $field=="Date") return true;
	if($table=="jobs" && $field=="Type") return true;
	if($table=="jobs" && $field=="Status") return true;
	if($table=="jobs" && $field=="Name") return true;
	if($table=="jobs" && $field=="Result") return true;
	if($table=="jobs" && $field=="Notes") return true;
	if($table=="jobs" && $field=="Consultant") return true;
	if($table=="jobs") return false;

//	patients
	
	if($table=="patients" && $field=="Primary") return true;
	if($table=="patients" && $field=="Patient Name") return true;
	if($table=="patients" && $field=="Date of Birth") return true;
	if($table=="patients" && $field=="Unit Number") return true;
	if($table=="patients" && $field=="Sex") return true;
	if($table=="patients" && $field=="Ward") return true;
	if($table=="patients" && $field=="Bed") return true;
	if($table=="patients" && $field=="Consultant") return true;
	if($table=="patients" && $field=="Code") return true;
	if($table=="patients" && $field=="Category") return true;
	if($table=="patients" && $field=="Admission Date") return true;
	if($table=="patients" && $field=="Diagnosis") return true;
	if($table=="patients" && $field=="Allergies") return true;
	if($table=="patients" && $field=="Notes") return true;
	if($table=="patients" && $field=="Nurses") return true;
	if($table=="patients" && $field=="Social Services") return true;
	if($table=="patients" && $field=="Team") return true;
	if($table=="patients" && $field=="Ward Round Notes") return true;
	if($table=="patients") return false;

//	Nursing Handover
	
	if($table=="Nursing Handover" && $field=="Patient Name") return true;
	if($table=="Nursing Handover" && $field=="Date of Birth") return true;
	if($table=="Nursing Handover" && $field=="Unit Number") return true;
	if($table=="Nursing Handover" && $field=="Sex") return true;
	if($table=="Nursing Handover" && $field=="Ward") return true;
	if($table=="Nursing Handover" && $field=="Bed") return true;
	if($table=="Nursing Handover" && $field=="Consultant") return true;
	if($table=="Nursing Handover" && $field=="Code") return true;
	if($table=="Nursing Handover" && $field=="Diagnosis") return true;
	if($table=="Nursing Handover" && $field=="Allergies") return true;
	if($table=="Nursing Handover" && $field=="Notes") return true;
	if($table=="Nursing Handover" && $field=="Nurses") return true;
	if($table=="Nursing Handover" && $field=="Social Services") return true;
	if($table=="Nursing Handover" && $field=="Team") return true;
	if($table=="Nursing Handover") return false;

//	Current Patients
	
	if($table=="Current Patients" && $field=="Patient Name") return true;
	if($table=="Current Patients" && $field=="Date of Birth") return true;
	if($table=="Current Patients" && $field=="Unit Number") return true;
	if($table=="Current Patients" && $field=="Sex") return true;
	if($table=="Current Patients" && $field=="Ward") return true;
	if($table=="Current Patients" && $field=="Bed") return true;
	if($table=="Current Patients" && $field=="Consultant") return true;
	if($table=="Current Patients" && $field=="Code") return true;
	if($table=="Current Patients" && $field=="Category") return true;
	if($table=="Current Patients" && $field=="Admission Date") return true;
	if($table=="Current Patients" && $field=="Diagnosis") return true;
	if($table=="Current Patients" && $field=="Allergies") return true;
	if($table=="Current Patients" && $field=="Notes") return true;
	if($table=="Current Patients" && $field=="Nurses") return true;
	if($table=="Current Patients" && $field=="Social Services") return true;
	if($table=="Current Patients" && $field=="Team") return true;
	if($table=="Current Patients") return false;

//	Current Jobs
	
	if($table=="Current Jobs" && $field=="Patient Name") return true;
	if($table=="Current Jobs" && $field=="Date") return true;
	if($table=="Current Jobs" && $field=="Type") return true;
	if($table=="Current Jobs" && $field=="Status") return true;
	if($table=="Current Jobs" && $field=="Name") return true;
	if($table=="Current Jobs" && $field=="Result") return true;
	if($table=="Current Jobs" && $field=="Notes") return true;
	if($table=="Current Jobs" && $field=="Consultant") return true;
	if($table=="Current Jobs") return false;

//	Ward Round Sheet
	
	if($table=="Ward Round Sheet" && $field=="Consultant") return true;
	if($table=="Ward Round Sheet" && $field=="Patient Name") return true;
	if($table=="Ward Round Sheet" && $field=="Date of Birth") return true;
	if($table=="Ward Round Sheet" && $field=="Unit Number") return true;
	if($table=="Ward Round Sheet" && $field=="Sex") return true;
	if($table=="Ward Round Sheet" && $field=="Ward") return true;
	if($table=="Ward Round Sheet" && $field=="Bed") return true;
	if($table=="Ward Round Sheet" && $field=="Admission Date") return true;
	if($table=="Ward Round Sheet" && $field=="Diagnosis") return true;
	if($table=="Ward Round Sheet" && $field=="Allergies") return true;
	if($table=="Ward Round Sheet" && $field=="Notes") return true;
	if($table=="Ward Round Sheet" && $field=="Ward Round Notes") return true;
	if($table=="Ward Round Sheet") return false;

//	Sign-Out Sheet
	
	if($table=="Sign-Out Sheet" && $field=="Patient Name") return true;
	if($table=="Sign-Out Sheet" && $field=="Date of Birth") return true;
	if($table=="Sign-Out Sheet" && $field=="Unit Number") return true;
	if($table=="Sign-Out Sheet" && $field=="Sex") return true;
	if($table=="Sign-Out Sheet" && $field=="Ward") return true;
	if($table=="Sign-Out Sheet" && $field=="Bed") return true;
	if($table=="Sign-Out Sheet" && $field=="Consultant") return true;
	if($table=="Sign-Out Sheet" && $field=="Code") return true;
	if($table=="Sign-Out Sheet" && $field=="Diagnosis") return true;
	if($table=="Sign-Out Sheet" && $field=="Allergies") return true;
	if($table=="Sign-Out Sheet" && $field=="Notes") return true;
	if($table=="Sign-Out Sheet") return false;

//	users
	
	if($table=="users" && $field=="Login") return true;
	if($table=="users" && $field=="Name") return true;
	if($table=="users" && $field=="Password") return true;
	if($table=="users" && $field=="User Type") return true;
	if($table=="users") return false;

//	consultants
	
	if($table=="consultants" && $field=="Consultant") return true;
	if($table=="consultants") return false;

//	ward list
	
	if($table=="ward list" && $field=="Ward") return true;
	if($table=="ward list") return false;
	return false;
}

// 
function CheckSecurity($strValue, $strAction)
{
global $cAdvSecurityMethod, $strTableName;
	if($_SESSION["AccessLevel"]==ACCESS_LEVEL_ADMIN)
		return true;

	if($strTableName=="users")
	{
			if(!((string)$_SESSION["OwnerID"]===(string)$strValue))
			return false;
	}
	//	 check user group permissions
	$strPerm = GetUserPermissions();
	if($strAction=="Add" && !(strpos($strPerm, "A")===false) ||
	   $strAction=="Edit" && !(strpos($strPerm, "E")===false) ||
	   $strAction=="Delete" && !(strpos($strPerm, "D")===false) ||
	   $strAction=="Search" && !(strpos($strPerm, "S")===false) ||
	   $strAction=="Export" && !(strpos($strPerm, "P")===false) )
		return true;
	else
		return false;
	return true;
}


//	add security WHERE clause to SELECT SQL command
function SecuritySQL($strAction)
{
global $cAdvSecurityMethod,$strTableName;
   	$ownerid=@$_SESSION["OwnerID"];
	$ret="";
	if(@$_SESSION["AccessLevel"]==ACCESS_LEVEL_ADMIN)
		return "";
	$ret="";

	if($strTableName=="users")
	{
			$ret=GetFullFieldName(GetTableOwnerID())."=".make_db_value(GetTableOwnerID(),$ownerid);
	}

/*
	if($cAdvSecurityMethod == ADVSECURITY_VIEW_OWN ||
	   $cAdvSecurityMethod == ADVSECURITY_EDIT_OWN && ($strAction=="Edit" || $strAction=="Delete"))
		$ret=GetFullFieldName(GetTableOwnerID())."=".make_db_value(GetTableOwnerID(),$ownerid);
*/

	$strPerm = GetUserPermissions();
	if($strAction=="Edit" && !(strpos($strPerm, "E")===false) ||
	   $strAction=="Delete" && !(strpos($strPerm, "D")===false) ||
	   $strAction=="Search" && !(strpos($strPerm, "S")===false) ||
	   $strAction=="Export" && !(strpos($strPerm, "P")===false) )
		return $ret;
	else
		return "1=0";
	return "";
}

////////////////////////////////////////////////////////////////////////////////
// editing functions
////////////////////////////////////////////////////////////////////////////////

function make_db_value($field,$value,$controltype="",$postfilename="")
{
	$ret=prepare_for_db($field,$value,$controltype,$postfilename);
	if($ret===false)
		return $ret;
	return add_db_quotes($field,$ret);
}

function add_db_quotes($field,$value)
{
	global $strTableName;
	$type=GetFieldType($field);
	if(IsBinaryType($type))
		return db_addslashesbinary($value);
	if(($value==="" || $value===FALSE) && !ischartype($type))
		return "null";
	if(NeedQuotes($type))
	{
		if(!IsDateFieldType($type))
			$value="'".db_addslashes($value)."'";
		else
			$value=db_datequotes($value);
	}
	else
	{
		$strvalue = (string)$value;
		$strvalue = str_replace(",",".",$strvalue);
		$value=0+$strvalue;
	}
	return $value;
}


function prepare_for_db($field,$value,$controltype="",$postfilename="")
{
	global $strTableName,$filename,$files_delete,$files_move,$thumbnail_fields,$thumbnail_prefixes,$thumbnail_maxsize;
	$filename="";
	$type=GetFieldType($field);
	if(!$controltype)
	{
		if(is_array($value))
			$value=combinevalues($value);
		if(($value==="" || $value===FALSE) && !ischartype($type))
			return "";
		return $value;
	}
	else if(substr($controltype,0,4)=="file")
	{
		$file=&$_FILES["value_".GoodFieldName($field)];
		if($file["error"] && $file["error"]!=4)
			return false;
		if(trim($postfilename))
			$filename=refine(trim($postfilename));
		else
			$filename=$file['name'];
		if(substr($controltype,4,1)=="1")
			return "";
		if(substr($controltype,4,1)=="0")
			return false;
		$ret=myfile_get_contents($file['tmp_name']);
		if($ret===false)
			return false;
		return $ret;
	}
	else if(substr($controltype,0,6)=="upload")
	{
		$file=&$_FILES["file_".GoodFieldName($field)];
		if($file["error"] && $file["error"]!=4)
			return false;
		if(substr($controltype,6,1)=="1")
		{
			$files_delete[]=GetUploadFolder($field).$postfilename;
			return "";
		}
		if(substr($controltype,6,1)=="0")
			return false;
		$file_move = array($file['tmp_name'],GetUploadFolder($field).$value);
		$files_move[] = $file_move;
		//	create and write thumbnail
		if(!(array_search($field,$thumbnail_fields)===FALSE))
		{
			$thumbname=$file_move[1];
			$path="";
			$lasti = my_strrpos($thumbname,"/");
			if(!($lasti===false))
			{
				$thumbname=substr($thumbname,$lasti+1);
				$path=substr($file_move[1],0,$lasti+1);
			}
			$thumbname = $thumbnail_prefixes[$field].$thumbname;
			$lasti = my_strrpos($thumbname,".");
			if(!($lasti===false))
				$thumbname=substr($thumbname,0,$lasti);
			$thumbname.=".gif";
			$img = imagecreatefromstring(myfile_get_contents($file_move[0]));
			$sx = imagesx($img);
			$sy = imagesy($img);
			if($sx>$thumbnail_maxsize || $sy>$thumbnail_maxsize)
			{
				if($sx>=$sy)
				{
					$nsy=(integer)($sy*$thumbnail_maxsize/$sx);
					$nsx=$thumbnail_maxsize;
				}
				else
				{
					$nsx=(integer)($sx*$thumbnail_maxsize/$sy);
					$nsy=$thumbnail_maxsize;
				}
				$thumb = imagecreatetruecolor($nsx,$nsy);
				imagecopyresized($thumb,$img,0,0,0,0,$nsx,$nsy,$sx,$sy);
				imagegif($thumb,$path.$thumbname);
			}
		}
		return $value;
	}
	else if(substr($controltype,0,4)=="date")
	{
		$dformat=substr($controltype,4);
		if($dformat==EDIT_DATE_SIMPLE || $dformat==EDIT_DATE_SIMPLE_DP)
		{
			$time=localdatetime2db($value);
			if($time=="null")
				return "";
			return $time;
		}
		else if($dformat==EDIT_DATE_DD || $dformat==EDIT_DATE_DD_DP)
		{
			$a=explode("-",$value);
			if(count($a)<3)
				return "";
			else
				list($y,$m,$d)=$a;
			if($y<100)
			{
				if($y<70)
					$y+=2000;
				else
					$y+=1900;
			}
			return sprintf("%04d-%02d-%02d",$y,$m,$d);
		}
		else
			return "";
	}
	else if(substr($controltype,0,8)=="checkbox")
	{
		if($value=="on")
			$ret=1;
		else if($value=="none")
			return "";
		else 
			$ret=0;
		return $ret;
	}
	else
		return false;
}

//	delete uploaded files when deleting the record
function DeleteUploadedFiles($where)
{
	global $conn,$strOriginalTableName;
	$rs = db_query("select * from ".AddTableWrappers($strOriginalTableName)." where ".$where,$conn);
	if($data=db_fetch_array($rs))
	{
		foreach($data as $field=>$value)
		{
			if(GetEditFormat($field)==EDIT_FORMAT_FILE)
			{
				if(strlen($value) && file_exists(GetUploadFolder($field).$value))
				@unlink(GetUploadFolder($field).$value);
			}
		}
	}
}

//	combine checked values from multi-select list box
function combinevalues($arr)
{
	$ret="";
	foreach($arr as $val)
	{
		if(strlen($ret))
			$ret.=",";
		if(strpos($val,",")===false && strpos($val,'"')===false)
			$ret.=$val;
		else
		{
			$val=str_replace('"','""',$val);
			$ret.='"'.$val.'"';
		}
	}
	return $ret;
}

//	split values for multi-select list box
function splitvalues($str)
{
	$arr=array();
	$start=0;
	$i=0;
	$inquot=false;
	while($i<=strlen($str))
	{
		if($i<strlen($str) && $str{$i}=='"')
			$inquot=!$inquot;
		else if($i==strlen($str) || !$inquot && $str{$i}==',')
		{
			$val=substr($str,$start,$i-$start);
			$start=$i+1;
			if(strlen($val) && $val{0}=='"')
			{
				$val=substr($val,1,strlen($val)-2);
				$val=str_replace('""','"',$val);
			}
			$arr[]=$val;
		}
		$i++;
	}
	return $arr;
}


////////////////////////////////////////////////////////////////////////////////
// edit controls creation functions
////////////////////////////////////////////////////////////////////////////////


//	write days dropdown
function WriteDays($d)
{
	$ret='<option value=""> </option>';
	for($i=1;$i<=31;$i++)
		$ret.='<option value="'.$i.'" '.($i==$d?"selected":"").'>'.$i."</option>\r\n";
	return $ret;
}

//	write months dropdown
function WriteMonths($m)
{
	$monthnames=array();
	$monthnames[1]="January";
	$monthnames[2]="February";
	$monthnames[3]="March";
	$monthnames[4]="April";
	$monthnames[5]="May";
	$monthnames[6]="June";
	$monthnames[7]="July";
	$monthnames[8]="August";
	$monthnames[9]="September";
	$monthnames[10]="October";
	$monthnames[11]="November";
	$monthnames[12]="December";
	$ret='<option value=""></option>';
	for($i=1;$i<=12;$i++)
		$ret.='<option value="'.$i.'" '.($i==$m?"selected":"").'>'.$monthnames[$i]."</option>\r\n";
	return $ret;
}

//	write years dropdown
function WriteYears($y)
{
	$tm=localtime(time(),true);
	$ret='<option value=""> </option>';
	$firstyear=$tm["tm_year"]+1900-100;
	if($y && $firstyear>$y-5)
		$firstyear=$y-10;
	$lastyear=$tm["tm_year"]+1900+10;
	if($y && $lastyear<$y+5)
		$lastyear=$y+10;
	for($i=$firstyear;$i<=$lastyear;$i++)
		$ret.='<option value="'.$i.'" '.($i==$y?"selected":"").'>'.$i."</option>\r\n";
	return $ret;
}

//	returns HTML code that represents required Date edit control
function GetDateEdit($field, $value, $type, $secondfield=false,$search=MODE_EDIT)
{	
	global $cYearRadius, $locale_info;
	$cfieldname=GoodFieldName($field);
	$cfield="value_".GoodFieldName($field);
	$ctype="type_".GoodFieldName($field);
	if($secondfield)
	{
		$cfield="value1_".GoodFieldName($field);
		$ctype="type1_".GoodFieldName($field);
	}
	$iname=$cfield;
	$tvalue=$value;
	if($search==MODE_SEARCH && ($type==EDIT_DATE_SIMPLE || $type==EDIT_DATE_SIMPLE_DP))
		$tvalue=localdatetime2db($value);
	$time=db2time($tvalue);
	if(!count($time))
		$time=array(0,0,0,0,0,0);
	$dp=0;
	switch($type)
	{
		case EDIT_DATE_SIMPLE_DP:
			$ovalue=$value;
			if($locale_info["LOCALE_IDATE"]==1)
			{
				$fmt="dd".$locale_info["LOCALE_SDATE"]."MM".$locale_info["LOCALE_SDATE"]."yyyy";
				$sundayfirst="false";
			}
			else if($locale_info["LOCALE_IDATE"]==0)
			{
				$fmt="MM".$locale_info["LOCALE_SDATE"]."dd".$locale_info["LOCALE_SDATE"]."yyyy";
				$sundayfirst="true";
			}
			else
			{
				$fmt="yyyy".$locale_info["LOCALE_SDATE"]."MM".$locale_info["LOCALE_SDATE"]."dd";
				$sundayfirst="false";
			}
			if(DateEditShowTime($field) )
			{
				if($time[5])
					$fmt.=" HH:mm:ss";
				else if($time[3] || $time[4])
					$fmt.=" HH:mm";
			}
			if($time)
				$ovalue=format_datetime_custom($time,$fmt);
			$ovalue1=$time[2]."-".$time[1]."-".$time[0];
			$showtime="false";
			if(DateEditShowTime($field))
			{
				$showtime="true";
				$ovalue1.=" ".$time[3].":".$time[4].":".$time[5];
			}
			$onblur="var dt=parse_datetime(this.value,".$locale_info["LOCALE_IDATE"]."); if(dt!=null) editform.ts".$iname.".value=print_datetime(dt,-1,".$showtime."); else editform.ts".$iname.".value='';";
			$ret='<input type="Text" name="'.$iname.'" size = "20" value="'.$ovalue.'" onblur="'.$onblur.'">'; 
			$ret.='<input type="Hidden" name="ts'.$iname.'" value="'.$ovalue1.'">&nbsp;&nbsp;';
			$ret.='<a href="#" onclick="javascript:var v=show_calendar(\'update'.$iname.'\', document.editform.ts'.$iname.'.value,'.$showtime.','.$sundayfirst.'); return false;">'.
				'<img src="images/cal.gif" width=16 height=16 border=0 alt="'."Click Here to Pick up the date".'"></a>';
			$ret.="\r\n<script language=JavaScript>".
				"	function update".$iname."(newDate) ".
				"{ ";
			$ret.="		document.forms.editform.".$iname.".value =  print_datetime(newDate,".$locale_info["LOCALE_IDATE"].",".$showtime.");";
			$ret.="		document.forms.editform.ts".$iname.".value =  print_datetime(newDate,-1,".$showtime.");";
			$ret.="	}".	"</script>\r\n\r\n";
			echo $ret;
			return;
		case EDIT_DATE_DD_DP:
			$dp=1;
		case EDIT_DATE_DD:
			$ovalue=$value;
			if($time)
				$ovalue=format_datetime_custom($time,"yyyy-MM-dd");
			$retday='<select class=selects name="day'.$iname.'" onchange="javascript: SetDate'.$iname.'(); return true;">'.
				WriteDays($time[2])."</select>";
			
			$retmonth='<select class=selectm name="month'.$iname.'" onchange="javascript: SetDate'.$iname.'(); return true;">'.
				WriteMonths($time[1])."</select>";
			$retyear='<select class=selects name="year'.$iname.'" onchange="javascript: SetDate'.$iname.'(); return true;">'.
				WriteYears($time[0])."</select>";
			$sundayfirst="false";
			if($locale_info["LOCALE_ILONGDATE"]==1)
				$ret=$retday."&nbsp;".$retmonth."&nbsp;".$retyear;
			else if($locale_info["LOCALE_ILONGDATE"]==0)
			{
				$ret=$retmonth."&nbsp;".$retday."&nbsp;".$retyear;
				$sundayfirst="true";
			}
			else
				$ret=$retyear."&nbsp;".$retmonth."&nbsp;".$retday;
				
			if($dp)
			{
				$ret.="&nbsp;".
					"<a href=\"#\" onclick=\"javascript:var v=show_calendar('update".$iname."', document.editform.ts".$iname.".value,false,".$sundayfirst."); return false;\">".
					"<img src=images/cal.gif width=16 height=16 border=0 alt=\""."Click Here to Pick up the date"."\"></a>".
					"<input type=hidden name=\"ts".$iname."\" value=\"".$time[2]."-".$time[1]."-".$time[0]."\">";
			}
			if($time[0] && $time[1] && $time[2])
				$ret.="<input type=hidden name=\"".$iname."\" value=\"".$time[0]."-".$time[1]."-".$time[2]."\">";
			else
				$ret.="<input type=hidden name=\"".$iname."\" value=\"\">";
				
			$ret.="<script language=JavaScript>"."\r\n".
				"function SetDate".$iname."()"."\r\n".
				"{ "."\r\n".
				"  if (document.forms.editform.month".$iname.".value!='' && document.forms.editform.day".$iname.".value!='' && document.forms.editform.year".$iname.".value!='') {"."\r\n".
				"	document.forms.editform.".$iname.".value= ''+document.forms.editform.year".$iname.".value + "."\r\n".
				" 	'-' + document.forms.editform.month".$iname.".value + '-' + document.forms.editform.day".$iname.".value; "."\r\n";
			if($dp)
				$ret.="   document.forms.editform.ts".$iname.".value='' + document.forms.editform.day".$iname.".value+'-'+document.forms.editform.month".$iname.".value+'-'+document.forms.editform.year".$iname.".value;"."\r\n";
			$ret.="  } else {"."\r\n";
			if($dp)
				$ret.="	document.forms.editform.ts".$iname.".value= '".$time[2]."-".$time[1]."-".$time[0]."';"."\r\n";
			$ret.="	document.forms.editform.".$iname.".value= '';"."\r\n".
				"   } "."\r\n".
				" } "."\r\n".
				" SetDate".$iname."(); "."\r\n".
				"\r\n";
			if($dp)
				$ret.="	function update".$iname."(newDate) "."\r\n".
				"{ "."\r\n".
				"	var dt_datetime; "."\r\n".
				" 	var curdate = new Date(); "."\r\n".
				"		dt_datetime = newDate;"."\r\n".
				"		document.forms.editform.".$iname.".value =  dt_datetime.getFullYear() + '-' + (dt_datetime.getMonth()+1) + '-' + dt_datetime.getDate();"."\r\n".
				"		document.forms.editform.day".$iname.".selectedIndex = dt_datetime.getDate();"."\r\n".
				"		document.forms.editform.month".$iname.".selectedIndex = dt_datetime.getMonth()+1;"."\r\n".
				"		for(i=0; i<document.forms.editform.year" .$iname.".options.length;i++)".
				"			if(document.forms.editform.year" .$iname. ".options[i].value==dt_datetime.getFullYear())".
				"			{".
				"				document.forms.editform.year" .$iname. ".selectedIndex=i;".
				"				break;".
				"			}".
				"  	document.editform.ts".$iname.".value = dt_datetime.getDate() + '-' + (dt_datetime.getMonth()+1) + '-' + dt_datetime.getFullYear();"."\r\n".
				"	}"."\r\n";
			$ret.=" </script>\r\n";
			echo $ret;
			return;
		case EDIT_DATE_SIMPLE:
		default:
			$ovalue=$value;
			if($time)
			{
				if($time[3] || $time[4] || $time[5])
					$ovalue=format_datetime($time);
				else
					$ovalue=format_shortdate($time);
			}
			echo '<input type=text name="'.$iname.'" size = "20" value="'.htmlspecialchars($ovalue).'">';
	}
}

//	create javascript array with values for dependent dropdowns
function BuildSecondDropdownArray( $arrName, $strSQL)
{
	global $conn;

	echo $arrName . "=new Array();\r\n";
	$i=0;
	$rs = db_query($strSQL,$conn);
	while($row=db_fetch_numarray($rs))
	{
		echo $arrName."[".($i*3)."]='".jsreplace($row[0]). "';\r\n";
		echo $arrName."[".($i*3 + 1)."]='".jsreplace($row[1]). "';\r\n";
		echo $arrName."[".($i*3 + 2)."]='".jsreplace($row[2]). "';\r\n";
		$i++;
	}
}

//	create Lookup wizard control
function BuildSelectControl($field, $value, $values="", $secondfield=false, $mode)
{
	global $conn,$LookupSQL,$strTableName;
	$LookupSQL ="";
	$strSize = 1;
	$cfieldname=GoodFieldName($field);
	$cfield="value_".GoodFieldName($field);
	$ctype="type_".GoodFieldName($field);
	if($secondfield)
	{
		$cfield="value1_".GoodFieldName($field);
		$ctype="type1_".GoodFieldName($field);
	}
	if($values)
		$arr=&$values;
	$addnewitem=false;

	$script="";
		if($strTableName=="Nursing Handover" && $field=="Sex") 
		{
			$addnewitem= false ;
			$LinkField="";
			$DisplayField="";
			$LookupTable="";
			$strSize=1;

			$arr=array(
				 "Male" 
				,  "Female" 
			);
		}
		if($strTableName=="Nursing Handover" && $field=="Ward") 
		{
			$addnewitem= true ;
			$LinkField="Ward";
			$DisplayField="Ward";
			$LookupTable="ward list";
			$strSize=1;

			
			$LookupSQL = "select ";
						$LookupSQL .= "`Ward`";
						$LookupSQL .= ",`Ward`";
						$LookupSQL .= " from `ward list` ";
			
						
						$LookupSQL.=" ORDER BY `ward list`.`Ward`";
			
		}
		if($strTableName=="Nursing Handover" && $field=="Consultant") 
		{
			$addnewitem= true ;
			$LinkField="Consultant";
			$DisplayField="Consultant";
			$LookupTable="consultants";
			$strSize=1;

			
			$LookupSQL = "select ";
						$LookupSQL .= "`Consultant`";
						$LookupSQL .= ",`Consultant`";
						$LookupSQL .= " from `consultants` ";
			
						
						
		}
		if($strTableName=="Nursing Handover" && $field=="Code") 
		{
			$addnewitem= false ;
			$LinkField="";
			$DisplayField="";
			$LookupTable="";
			$strSize=1;

			$arr=array(
				 "DNAR" 
				,  "Full" 
			);
		}
		if($strTableName=="Current Patients" && $field=="Sex") 
		{
			$addnewitem= false ;
			$LinkField="";
			$DisplayField="";
			$LookupTable="";
			$strSize=1;

			$arr=array(
				 "Male" 
				,  "Female" 
			);
		}
		if($strTableName=="Current Patients" && $field=="Ward") 
		{
			$addnewitem= true ;
			$LinkField="Ward";
			$DisplayField="Ward";
			$LookupTable="ward list";
			$strSize=1;

			
			$LookupSQL = "select ";
						$LookupSQL .= "`Ward`";
						$LookupSQL .= ",`Ward`";
						$LookupSQL .= " from `ward list` ";
			
						
						
		}
		if($strTableName=="Current Patients" && $field=="Consultant") 
		{
			$addnewitem= true ;
			$LinkField="Consultant";
			$DisplayField="Consultant";
			$LookupTable="consultants";
			$strSize=1;

			
			$LookupSQL = "select ";
						$LookupSQL .= "`Consultant`";
						$LookupSQL .= ",`Consultant`";
						$LookupSQL .= " from `consultants` ";
			
						
						
		}
		if($strTableName=="Current Patients" && $field=="Code") 
		{
			$addnewitem= false ;
			$LinkField="";
			$DisplayField="";
			$LookupTable="";
			$strSize=1;

			$arr=array(
				 "DNAR" 
				,  "Full" 
			);
		}
		if($strTableName=="Current Patients" && $field=="Category") 
		{
			$addnewitem= false ;
			$LinkField="";
			$DisplayField="";
			$LookupTable="";
			$strSize=1;

			$arr=array(
				 "Inpatient" 
				,  "Discharged" 
				,  "Died" 
			);
		}
		if($strTableName=="Current Jobs" && $field=="Type") 
		{
			$addnewitem= false ;
			$LinkField="";
			$DisplayField="";
			$LookupTable="";
			$strSize=1;

			$arr=array(
				 "Bloods" 
				,  "Microbiology" 
				,  "Pathology" 
				,  "Radiology" 
				,  "TTO/TTA" 
				,  "Clinical Measurement" 
				,  "Procedure" 
				,  "Referral" 
				,  "Consultation" 
				,  "Admin" 
				,  "Problem" 
				,  "Other" 
			);
		}
		if($strTableName=="Current Jobs" && $field=="Status") 
		{
			$addnewitem= false ;
			$LinkField="";
			$DisplayField="";
			$LookupTable="";
			$strSize=1;

			$arr=array(
				 "To do" 
				,  "Requested" 
				,  "In progress" 
				,  "Awaiting Results" 
				,  "Completed" 
			);
		}
		if($strTableName=="Current Jobs" && $field=="Consultant") 
		{
			$addnewitem= true ;
			$LinkField="Consultant";
			$DisplayField="Consultant";
			$LookupTable="consultants";
			$strSize=1;

			
			$LookupSQL = "select ";
						$LookupSQL .= "`Consultant`";
						$LookupSQL .= ",`Consultant`";
						$LookupSQL .= " from `consultants` ";
			
						
						$LookupSQL.=" ORDER BY `consultants`.`Consultant`";
			
		}
		if($strTableName=="users" && $field=="User Type") 
		{
			$addnewitem= false ;
			$LinkField="";
			$DisplayField="";
			$LookupTable="";
			$strSize=1;

			$arr=array(
				 "admin" 
				,  "user" 
			);
		}
	
//	multi-select
	$multiple="";
	$postfix="";
	if($strSize>1)
	{
		$avalue=splitvalues($value);
		$multiple=" multiple";
		$postfix="[]";
	}
	else 
		$avalue=array((string)$value);
	
	if($LookupSQL)
	{
      	LogInfo($LookupSQL);
		$rs=db_query($LookupSQL,$conn);
//		if(!db_numrows($rs))
//			return "";
		$onchange="";
   		if($onchange)
			$onchange="onchange=\"".$onchange."\"";
      	echo '<select size = "'.$strSize.'" name="'.$cfield.$postfix.'"'.$multiple.' '.$onchange.'>';
		$count = db_numrows($rs);
		if($strSize<2)
			echo '<option value="">'."Please select".'</option>';
		else if($mode==MODE_SEARCH)
			echo '<option value=""> </option>';

      	while($data=db_fetch_numarray($rs))
		{
//			if((string)$data[0]===(string)$value)
			$res=array_search((string)$data[0],$avalue,true);
			if(!($res===NULL || $res===FALSE))
      			echo '<option value="'.htmlspecialchars($data[0]).'" selected>'.htmlspecialchars($data[1]).'</option>';
      		else
      			echo '<option value="'.htmlspecialchars($data[0]).'">'.htmlspecialchars($data[1]).'</option>';
		}
		echo "</select>";
//	add new item
		if($addnewitem &&  $mode!=MODE_SEARCH)
		{
			echo "<a href=# onclick=\"window.open('".GetTableURL($strTableName)."_addnewitem.php?field=".jsreplace(htmlspecialchars(urlencode($field)))."',\r\n".
			"'AddNewItem', 'width=250,height=100,status=no,resizable=yes,top=200,left=200');\">\r\n".
			"Add new"."</a>";
		}
	}
	else
	{
		echo '<select size = "'.$strSize.'" name="'.$cfield.$postfix.'" '.$multiple.'>';
		if($strSize<2 )
			echo '<option value="">'."Please select".'</option>';
		else if($mode==MODE_SEARCH)
			echo '<option value=""> </option>';
		foreach($arr as $opt)
		{
			$res=array_search((string)$opt,$avalue,true);
			if(!($res===NULL || $res===FALSE))
      			echo '<option value="'.htmlspecialchars($opt).'" selected>'.htmlspecialchars($opt).'</option>';
			else
      			echo '<option value="'.htmlspecialchars($opt).'">'.htmlspecialchars($opt).'</option>';
		}
		echo "</select>";
	}
	return;
}

function BuildRadioControl($field, $value,$secondfield=false)
{
	global $conn,$LookupSQL,$strTableName;
	$cfieldname=GoodFieldName($field);
	$cfield="value_".GoodFieldName($field);
	$ctype="type_".GoodFieldName($field);
	if($secondfield)
	{
		$cfield="value1_".GoodFieldName($field);
		$ctype="type1_".GoodFieldName($field);
	}
	$LookupSQL ="";
	if($LookupSQL)
	{
      	LogInfo($LookupSQL);
		$rs=db_query($LookupSQL,$conn);
		if(!db_numrows($rs))
			return "";
		echo '<input type=hidden name="'.$cfield.'" value="'.htmlspecialchars($value).'">';
      	while($data=db_fetch_numarray($rs))
		{
			if($data[0]==$value)
				echo '<input type="Radio" name="radio_'.$cfieldname.'" onclick="javascript: '.$├▒field.".value='".db_addslashes($data[0]).'\'; return true;" checked>'.htmlspecialchars($data[1])."<br>";
			else
				echo '<input type="Radio" name="radio_'.$cfieldname.'" onclick="javascript: '.$cfield.".value='".db_addslashes($data[0]).'\'; return true;">'.htmlspecialchars($data[1])."<br>";
		}
	}
	else
	{
		echo '<input type=hidden name="'.$cfield.'" value="'.htmlspecialchars($value).'">';
		foreach($arr as $opt)
		{
			if($opt==$value)
				echo '<input type="Radio" name="radio_'.$cfieldname.'" onclick="javascript: '.$cfield.".value='".db_addslashes($opt).'\'; return true;" checked>'.htmlspecialchars($opt)."<br>";
			else
				echo '<input type="Radio" name="radio_'.$cfieldname.'" onclick="javascript: '.$cfield.".value='".db_addslashes($opt).'\'; return true;">'.htmlspecialchars($opt)."<br>";
		}
	}
	return;

}


function BuildEditControl($field , $value, $format, $edit, $secondfield=false)
{
	global $rs,$data,$strTableName,$cMaxUploadFileSize,$max_filesize_set,$filenamelist,$keys;
	$cfieldname=GoodFieldName($field);
	$cfield="value_".GoodFieldName($field);
	$ctype="type_".GoodFieldName($field);
	if($secondfield)
	{
		$cfield="value1_".GoodFieldName($field);
		$ctype="type1_".GoodFieldName($field);
	}
	$type=GetFieldType($field);
	$arr="";
	if($format==EDIT_FORMAT_FILE && $edit==MODE_SEARCH)
		$format="";
	if($format==EDIT_FORMAT_TEXT_FIELD || $format==EDIT_FORMAT_TIME)
	{
		if(IsDateFieldType($type))
			echo '<input type="hidden" name="'.$ctype.'" value="date'.EDIT_DATE_SIMPLE.'">'.GetDateEdit($field,$value,0,$secondfield,$edit);
		else
			echo '<input type="text" name="'.$cfield.'" '.GetEditParams($field).' value="'.htmlspecialchars($value).'">';
	}
	else if($format==EDIT_FORMAT_TEXT_AREA)
	{
		if(UseRTE($field))
		{
			$value = RTESafe($value);
			echo "<script language=\"JavaScript\" type=\"text/javascript\">\r\n".
			"writeRichText('".$cfield."', '".$value."', 520, 200, true, false);\r\n".
			"</script>";
		}
		else
			echo '<textarea name="'.$cfield.'" '.GetEditParams($field).'>'.htmlspecialchars($value).'</textarea>';
	}
	else if($format==EDIT_FORMAT_PASSWORD)
		echo '<input type="Password" name="'.$cfield.'" '.GetEditParams($field).' value="'.htmlspecialchars($value).'">';
	else if($format==EDIT_FORMAT_DATE)
		echo '<input type="hidden" name="'.$ctype.'" value="date'.DateEditType($field).'">'.GetDateEdit($field,$value,DateEditType($field),$secondfield,$edit);
	else if($format==EDIT_FORMAT_RADIO)
		BuildRadioControl($field,$value,$secondfield);
	else if($format==EDIT_FORMAT_CHECKBOX)
	{
		if($edit==MODE_ADD || $edit==MODE_EDIT)
		{
			$checked="";
			if($data[$field] && $data[$field]!=0)
				$checked=" checked";
			echo '<input type="hidden" name="'.$ctype.'" value="checkbox"><input type="Checkbox" name="'.$cfield.'" '.$checked.'>';
		}
		else
		{
			echo '<input type="hidden" name="'.$ctype.'" value="checkbox">';
			echo '<select name="'.$cfield.'">';
			$val=array("none","on","off");
			$show=array("","True","False");
			foreach($val as $i=>$v)
			{
				$sel="";
				if($value===$v)
					$sel=" selected";
				echo '<option value="'.$v.'"'.$sel.'>'.$show[$i].'</option>';
			}
			echo "</select>";
		}
	}
	else if($format==EDIT_FORMAT_DATABASE_IMAGE || $format==EDIT_FORMAT_DATABASE_FILE)
	{
		$iquery="field=".urlencode($field);

		$iquery="field=".urlencode($field);
		if($strTableName=="jobs")
		{
			$iquery.="&key1=".urlencode($keys["Primary"]);
		}
		if($strTableName=="patients")
		{
			$iquery.="&key1=".urlencode($keys["Primary"]);
		}
		if($strTableName=="Nursing Handover")
		{
			$iquery.="&key1=".urlencode($keys["Primary"]);
		}
		if($strTableName=="Current Patients")
		{
			$iquery.="&key1=".urlencode($keys["Primary"]);
		}
		if($strTableName=="Current Jobs")
		{
			$iquery.="&key1=".urlencode($keys["Primary"]);
		}
		if($strTableName=="Ward Round Sheet")
		{
			$iquery.="&key1=".urlencode($keys["Primary"]);
		}
		if($strTableName=="Sign-Out Sheet")
		{
			$iquery.="&key1=".urlencode($keys["Primary"]);
		}
		if($strTableName=="users")
		{
			$iquery.="&key1=".urlencode($keys["Primary"]);
		}
		if($strTableName=="consultants")
		{
			$iquery.="&key1=".urlencode($keys["Primary"]);
		}
		if($strTableName=="ward list")
		{
			$iquery.="&key1=".urlencode($keys["Primary"]);
		}
		$disp="";
		$strfilename="";
		$onchangefile="";
		if($edit==MODE_EDIT)
		{
			$value=db_stripslashesbinary($value);
			$itype=SupposeImageType($value);
			if($itype)
				$disp='<img border=0 src="'.GetTableURL($strTableName).'_imager.php?'.$iquery.'">';
			else
			{
				if(strlen($value))
					$disp='<img border=0 src="images/file.gif">';
				else
					$disp='<img border=0 src="images/no_image.gif">';
			}
//	filename
			if($format==EDIT_FORMAT_DATABASE_FILE && !$itype && strlen($value))
			{
				if(!($filename=@$data[GetFilenameField($field)]))
					$filename="file.bin";
				$disp='<a href="'.GetTableURL($strTableName).'_getfile.php?filename='.htmlspecialchars($filename).'&'.$iquery.'".>'.$disp.'</a>';
			}
//	filename edit
			if($format==EDIT_FORMAT_DATABASE_FILE && GetFilenameField($field))
			{
				if(!($filename=@$data[GetFilenameField($field)]))
					$filename="";
				$strfilename='<br>'."Filename".'&nbsp;&nbsp;<input name="filename_'.$cfieldname.'" size="20" maxlength="50" value="'.htmlspecialchars($filename).'">';
				$onchangefile.="var path=this.form.elements['".addslashes($cfield)."'].value; var wpos=path.lastIndexOf('\\\\'); var upos=path.lastIndexOf('/'); var pos=wpos; if(upos>wpos) pos=upos; this.form.elements['filename_".addslashes($cfieldname)."'].value=path.substr(pos+1);";
			}
			$strtype='<br><input type="Radio" name="'.$ctype.'" value="file0" checked>'."Keep";
			if(strlen($value) && !IsRequired($field))
			{
				$strtype.='<input type="Radio" name="'.$ctype.'" value="file1">'."Delete";
				$onchangefile.='this.form.elements[\''.addslashes($ctype).'\'][2].checked=true;';
			}
			else
				$onchangefile.='this.form.elements[\''.addslashes($ctype).'\'][1].checked=true;';
			
			$strtype.='<input type="Radio" name="'.$ctype.'" value="file2">'."Update";
		}
		else
		{
			$strtype='<input type="hidden" name="'.$ctype.'" value="file2">';
			if($format==EDIT_FORMAT_DATABASE_FILE && GetFilenameField($field))
			{
				$strfilename='<br>'."Filename".'&nbsp;&nbsp;<input name="filename_'.$cfieldname.'" size="20" maxlength="50">';
				$onchangefile.="var path=this.form.elements['".addslashes($cfield)."'].value; var wpos=path.lastIndexOf('\\\\'); var upos=path.lastIndexOf('/'); var pos=wpos; if(upos>wpos) pos=upos; this.form.elements['filename_".addslashes($cfieldname)."'].value=path.substr(pos+1);";
			}
		}
		$maxsize="";
		if(!$max_filesize_set)
		{
			$maxsize='<input type="hidden" name="MAX_FILE_SIZE" value="'.$cMaxUploadFileSize.'">';
			$max_filesize_set=1;
		}
		if($onchangefile)
			$onchangefile='onChange="'.$onchangefile.'"';
		echo $disp.$strtype.$maxsize.'<br><input type="File" name="'.$cfield.'" '.$onchangefile.'>'.$strfilename;
	}
	else if($format==EDIT_FORMAT_LOOKUP_WIZARD)
			BuildSelectControl($field, $value, $arr, $secondfield, $edit);
	else if($format==EDIT_FORMAT_HIDDEN)
			echo '<input type="Hidden" name="'.$cfield.'" value="'.htmlspecialchars($value).'">';
	else if($format==EDIT_FORMAT_READONLY)
			echo '<input type="Hidden" name="'.$cfield.'" value="'.htmlspecialchars($value).'">';
	else if($format==EDIT_FORMAT_FILE)
	{
		$disp="";
		$strfilename="";
		$onchangefile="";
		$function="";
		if($edit==MODE_EDIT)
		{
//	show current file
			if(Format($field)==FORMAT_FILE || Format($field)==FORMAT_FILE_IMAGE)
			{
				$disp=GetData($data,$field,Format($field))."<br>";
			}
			$filename=$value;
			$function='<script language="Javascript">
			function controlfilename'.$cfieldname.'(enable)
			{
				if(enable)
				{
					document.forms.editform.'.$cfield.'.style.backgroundColor="white";
					document.forms.editform.'.$cfield.'.disabled=false;
				}
				else
				{
					document.forms.editform.'.$cfield.'.style.backgroundColor="gainsboro";
					document.forms.editform.'.$cfield.'.disabled=true;
				}
			}
			</script>';
//	filename edit
			$filename_size=30;
			if(UseTimestamp($field))
				$filename_size=50;
			$strfilename='<input type=hidden name="filename_'.$cfieldname.'" value="'.htmlspecialchars($filename).'"><br>'."Filename".'&nbsp;&nbsp;<input style="background-color:gainsboro" disabled name="'.$cfield.'" size="'.$filename_size.'" maxlength="100" value="'.htmlspecialchars($filename).'">';
			$onchangefile.="var path=this.form.file_".$cfieldname.".value; var wpos=path.lastIndexOf('\\\\'); var upos=path.lastIndexOf('/'); var pos=wpos; if(upos>wpos) pos=upos; controlfilename".$cfieldname."(true);";
			if(UseTimestamp($field))
				$onchangefile.="this.form.".$cfield.".value=addTimestamp(path.substr(pos+1)); ";
			else
				$onchangefile.="this.form.".$cfield.".value=path.substr(pos+1); ";
			$strtype='<br><input type="Radio" name="'.$ctype.'" value="upload0" checked onclick="controlfilename'.$cfieldname.'(false)">'."Keep";
			if(strlen($value) && !IsRequired($field))
			{
				$strtype.='<input type="Radio" name="'.$ctype.'" value="upload1" onclick="controlfilename'.$cfieldname.'(false)">'."Delete";
				$onchangefile.='this.form.'.$ctype.'[2].checked=true;';
			}
			else
				$onchangefile.='this.form.'.$ctype.'[1].checked=true;';
			$strtype.='<input type="Radio" name="'.$ctype.'" value="upload2" onclick="controlfilename'.$cfieldname.'(true)">'."Update";
		}
		else
		{
			$filename_size=30;
			if(UseTimestamp($field))
				$filename_size=50;
			$strtype='<input type="hidden" name="'.$ctype.'" value="upload2">';
			$strfilename='<br>'."Filename".'&nbsp;&nbsp;<input name="'.$cfield.'" size="'.$filename_size.'" maxlength="100">';
			$onchangefile.="var path=this.form.file_".$cfieldname.".value; var wpos=path.lastIndexOf('\\\\'); var upos=path.lastIndexOf('/'); var pos=wpos; if(upos>wpos) pos=upos;";
			if(UseTimestamp($field))
				$onchangefile.=" this.form.".$cfield.".value=addTimestamp(path.substr(pos+1));";
			else
				$onchangefile.=" this.form.".$cfield.".value=path.substr(pos+1);";
		}
		$maxsize="";
/*		if(!$max_filesize_set)
		{
			$maxsize='<input type="hidden" name="MAX_FILE_SIZE" value="'.$cMaxUploadFileSize.'">';
			$max_filesize_set=1;
		}
*/		
		if($onchangefile)
			$onchangefile='onChange="'.$onchangefile.'"';
		echo $function.$disp.$strtype.$maxsize.'<br><input type="File" name="file_'.$cfieldname.'" '.$onchangefile.'>'.$strfilename;
	}
}
function my_stripos($str,$needle, $offest)
{
    if (strlen($needle)==0 || strlen($str)==0)
		return false;
	return strpos(strtolower($str),strtolower($needle), $offest);
} 


?>
Return current item: Clinical Handover Database