Hi M@tt,
if nhs_mail = yes it will send 2 email one to nhs address and 1 to admin, If no it will just send to admin.
I will enter all the code over 2 posts (too big for one) any help gratefully received.
[php]<?php
require_once(“config.php”);
$data_submission_type_id = 0;
$menu_option = “submit_data”;
$defibrillator_id = fsSafeNum(“login_id”);
if($_REQUEST[‘action’] == “allow_instant_check” && $defibrillator_id > 0 && $_REQUEST[‘type’] > 0){
mysql_query("delete from data_submission_date where data_id = “.$_REQUEST[‘type’].” and user_id = ".$defibrillator_id);
$_SESSION[‘msg’] = “Instant check added successfully”;
header(“location:”.$_SERVER[‘PHP_SELF’]);
exit;
}
if(frSafeNum(‘data_submission_type’) > 0)
{
$data_submission_type_id = frSafeNum(‘data_submission_type’);
}
$rsDataType = mysql_query(“select data_submission_type from data_submission_type where data_submission_type_id = “.$data_submission_type_id);
if(mysql_num_rows($rsDataType) == 0 && $data_submission_type_id > 0)
{
$_SESSION[‘wmsg’] = “Wrong data submission type selected”;
ob_clean();
header(“location:”.$_SERVER[‘PHP_SELF’]);
exit;
}
if($_REQUEST[‘cmdSubmit’] != “”){
$data_submission_type_id = frSafeNum(‘data_submission_type_id’);
$rsDataType = mysql_query(“select data_submission_type from data_submission_type where data_submission_type_id = “.$data_submission_type_id);
if(mysql_num_rows($rsDataType) > 0)
{
$rowDataType = mysql_fetch_array($rsDataType);
$data_submission_type = $rowDataType[‘data_submission_type’];
}
mysql_free_result($rsDataType);
$rsRecord = mysql_query(“SELECT ff.form_field_id,data_submission_type_id
,label,extra_data,fft.field_id, fft.field_label, fft.field_type
FROM form_fields ff
JOIN form_fields_type fft ON fft.field_id = ff.field_id
WHERE data_submission_type_id = $data_submission_type_id
order by form_field_id
“);
if(mysql_num_rows($rsRecord) > 0)
{
$data_id = ‘’;
$form_data = “”;
$cm_gp = rand(1111111111,9999999999);
while($rowRecord = mysql_fetch_array($rsRecord))
{
if($rowRecord[‘field_type’] == “checkbox”)
{
$value_arr = array();
if(is_array($REQUEST["name”.lowercase_un($rowRecord[‘label’])]))
{
$value_arr = implode(”, “,$REQUEST["name”.lowercase_un($rowRecord[‘label’])]);
$sql = “insert into user_form_data (user_id,form_field_id,data_submission_type_id,label,value,cm_gp) values
($defibrillator_id,”.$rowRecord[‘form_field_id’].”,$data_submission_type_id,
'”.$rowRecord[‘label’].”’,’”.$value_arr."’,’$cm_gp’)";
//echo $sql;
mysql_query($sql) or die(“Error2: “.mysql_error());
$form_data .= “”.$rowRecord[‘label’].”: “.$value_arr.”
”;
}
}
else
{
$sql = “insert into user_form_data (user_id,form_field_id,data_submission_type_id,label,value,cm_gp) values
($defibrillator_id,”.$rowRecord[‘form_field_id’].",$data_submission_type_id,
‘".$rowRecord[‘label’]."’,’".$REQUEST["name".lowercase_un($rowRecord[‘label’])]."’,’$cm_gp’)";
mysql_query($sql) or die(“Error2: “.mysql_error());
$form_data .= “”.$rowRecord[‘label’].”: “.$REQUEST["name”.lowercase_un($rowRecord[‘label’])].”
";
}
$data_id = mysql_insert_id();
}
$_SESSION['msg'] = "User data updated successfully";
//mysql_query("delete from data_submission_date where data_id = $data_submission_type_id and user_id = $defibrillator_id");
if($data_submission_type_id == 1) $days = "week";
if($data_submission_type_id == 2) $days = "month";
if($data_submission_type_id == 3) $days = "year";
if($data_submission_type_id == 4) $days = "day";
$next_date = date("Y-m-d",strtotime("+1 $days"));
// Insert entries for all 4 types
// ============================================================================================================
// 1) week
$next_date_w = date("Y-m-d",strtotime("+1 week"));
mysql_query("insert into data_submission_date (data_id,user_id,submission_type_id,next_date) values ($data_id, $defibrillator_id, 1,'$next_date_w')");
// 2) month
$next_date_m = date("Y-m-d",strtotime("+1 month"));
mysql_query("insert into data_submission_date (data_id,user_id,submission_type_id,next_date) values ($data_id, $defibrillator_id, 2,'$next_date_m')");
// 3) year
$next_date_y = date("Y-m-d",strtotime("+1 year"));
mysql_query("insert into data_submission_date (data_id,user_id,submission_type_id,next_date) values ($data_id, $defibrillator_id, 3,'$next_date_y')");
// 4) day
$next_date_d = date("Y-m-d",strtotime("+1 day"));
mysql_query("insert into data_submission_date (data_id,user_id,submission_type_id,next_date) values ($data_id, $defibrillator_id, 4,'$next_date_d')");
// ============================================================================================================
$next_date_1 = date("d/m/Y",strtotime($next_date));
$rsDef = mysql_query("select n.email as nhs_email,d.email as def_email,n.mail as nhs_mail,d.username,d.site_name,d.region from defibrillator d join nhs_department n on d.region=n.region where defibrillator_id = ".fsSafeNum("login_id"));
$rowDef = mysql_fetch_array($rsDef);
if($rowDef(“nhs_mail”) == ‘Yes’)
{
$message = “Dear Admin,
”;
$message .= ‘A Defibrillator user with username "’.$rowDef[‘username’].’" and site name “’.$rowDef[‘site_name’].’” has submitted ‘.$data_submission_type.’ data as follows:
’;
$message .= “Submission Date: “.date(“d/m/Y”).”
”;
$message .= $form_data."
";
$message .= “Your next $data_submission_type data submission date is $next_date_1
”;
$footer = str_replace($admin_email_address_var,$admin_email_address,$footer_email_template);
$footer = str_replace($current_year_var,date("Y"),$footer);
sendMail($admin_email_address,"$data_submission_type Data submitted by $rowDef[site_name]",$message,$footer,$rowDef['def_email']);
ob_clean();
header("location:".$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']);
exit;
}
$message = “Dear Admin,
”;
$message .= ‘A Defibrillator user with username "’.$rowDef[‘username’].’" and site name “’.$rowDef[‘site_name’].’” has submitted ‘.$data_submission_type.’ data as follows:
’;
$message .= “Submission Date: “.date(“d/m/Y”).”
”;
$message .= $form_data."
";
$message .= “Your next $data_submission_type data submission date is $next_date_1
”;
$footer = str_replace($admin_email_address_var,$admin_email_address,$footer_email_template);
$footer = str_replace($current_year_var,date("Y"),$footer);
sendMail($admin_email_address,"$data_submission_type Data submitted by $rowDef[site_name]",$message,$footer,$rowDef['nhs_email']);
ob_clean();
header("location:".$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']);
exit;
}
mysql_free_result($rsRecord);
}else{
$data_submission_type = frSafeNum(‘data_submission_type’);
$rsDataType = mysql_query("select data_submission_type from data_submission_type where data_submission_type_id = ".$data_submission_type);
if(mysql_num_rows($rsDataType) > 0)
{
$rowDataType = mysql_fetch_array($rsDataType);
$data_submission_type_text = $rowDataType[‘data_submission_type’];
}
mysql_free_result($rsDataType);
}
[/php]