<?
//validation
function error_bool($error, $field) {
if($error[$field]) {
print("<td style=color:red>");
}
else {
print("<td>");
}
}
function show_form() {
global $HTTP_POST_VARS, $print_again, $error;
include 'erf_html.php';
}
if(isset($_POST["Submit"])) {
check_form();
} else {
show_form();
}
function check_email_address($contactmail) {
if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $contactmail)) {
return false;
}
$email_array = explode("@", $contactmail);
$local_array = explode(".", $email_array[0]);
for ($i = 0; $i < sizeof($local_array); $i++) {
if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {
return false;
}
}
if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) {
$domain_array = explode(".", $email_array[1]);
if (sizeof($domain_array) < 2) {
return false;
}
for ($i = 0; $i < sizeof($domain_array); $i++) {
if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {
return false;
}
}
}
return true;
}
function check_form()
{
global $HTTP_POST_VARS, $error, $print_again;
// validate constant fields
$error['address'] = false;
if (strlen($_POST['address']) < 4) {
$error['address'] = true;
$print_again = true;
}
$error['lognumber'] = false;
if (strlen($_POST['lognumber']) < 6) {
$error['lognumber'] = true;
$print_again = true;
}
$error['contactname'] = false;
if (strlen($_POST['contactname']) < 3) {
$error['contactname'] = true;
$print_again = true;
}
$error['theitem'][$key] = false;
foreach($_POST['theitem'] as $key => $value) {
if ($value=="n/a") {
} else {
$error['theitem'][$key] = true;
$print_again = true;
}
}
$error['quantity'][$key] = false;
foreach($_POST['quantity'] as $key => $value) {
if (is_numeric($value)) {
} else {
$error['quantity'][$key] = true;
$print_again = true;
}
}
$error['reason'][$key] = false;
foreach($_POST['reason'] as $key => $value) {
if (strlen($value < 10)) {
$error['reason'][$key] = true;
$print_again = true;
}
}
$error['thetype'][$key] = false;
foreach($_POST['thetype'] as $key => $value) {
if ($value=="") {
$error['thetype'][$key] = true;
$print_again = true;
}
}
foreach($_POST['asset'] as $key => $value) {
if ($_POST["asset"][$key]=="") {
$error['asset'][$key] = true;
$print_again = true;
}
}
// validate email address
if (!check_email_address($_POST['contactmail'])) {
$error['contactmail'] = true;
$print_again = true;
}
if ($print_again) {
show_form();
} else {
// get the PCT contact name from the address
$theaddress = $_POST['address'];
if (strpos($theaddress, 'ESDW') !== false) {
$subto = 'Richard West';
$subtopct = 'ESDW';
} else if (strpos($theaddress, 'HR') !== false) {
$subto = 'Teresa Freeman';
$subtopct = 'HR';
} else if (strpos($theaddress, 'BH') !== false) {
$subto = 'Natasha Darby';
$subtopct = 'BH';
} else if (strpos($theaddress, 'WSX') !== false) {
$subto = 'Carl Bolger / Tina Hayes / Elaine Wakeham / Tracy Witham';
$subtopct = 'WSX';
}
// get the doctors name from the address
$getgpname = $_POST['address'];
$getgpname = substr($getgpname,strpos($getgpname,'-')+1);
$getgpname = substr($getgpname,0,strpos($getgpname,','));
$getgpname = trim($getgpname);
// define variables
$erfref = DATE('Ymd-His') . " " . $getgpname . " ERF";
$date = DATE('d/m/Y');
$subby = $_POST['username'];
$deladdress = $_POST['address'];
$logno = $_POST['lognumber'];
$contactname = $_POST['contactname'];
$contactmail = $_POST['contactmail'];
$notes = $_POST['notes'];
// if the form is submitted, show some output
if ($_POST['submit'] == true)
{
foreach($_POST['theitem'] as $key => $value) {
if ($value<>"") {
$itemlist = $value . '<br \>';
}
}
foreach($_POST['quantity'] as $key => $value) {
if ($value<>"") {
$itemlist = $value . '<br \>';
}
}
foreach($_POST['reason'] as $key => $value) {
if ($value<>"") {
$itemlist = $value . '<br \>';
}
}
foreach($_POST['thetype'] as $key => $value) {
if ($value<>"") {
$itemlist = $value . '<br \>';
}
}
}
// header('Location: http://10.179.255.10/doku.php?id=erf:submitted');
show_form();
}
echo "<strong>** Please fill out the required fields to proceed.</strong>";
}
?>