forked from science-ation/science-ation
Add an email address verification function so we dont need to keep duplicating the regex everywhere
Add a function to get the email recipients for a given registration id, for now, it just gets the students, but downt eh road it should check if teachers, parents, emergency contacts, mentors, etc should receive fair updates as well. Implement the code/replacement tags for the two new emails, one for 'forms received, with payment' and the other for 'forms received, without payment'
This commit is contained in:
parent
cc4f9b5356
commit
4378f966ce
@ -203,42 +203,80 @@ echo mysql_Error();
|
|||||||
AND registrations.year='{$config['FAIRYEAR']}'");
|
AND registrations.year='{$config['FAIRYEAR']}'");
|
||||||
$checkNumResults=mysql_fetch_object($checkNumQuery);
|
$checkNumResults=mysql_fetch_object($checkNumQuery);
|
||||||
$projectnum=$checkNumResults->projectnumber;
|
$projectnum=$checkNumResults->projectnumber;
|
||||||
|
|
||||||
|
$q=mysql_query("SELECT id FROM registrations WHERE num='$regnum' AND year='{$config['FAIRYEAR']}'");
|
||||||
|
$r=mysql_fetch_object($q);
|
||||||
|
$reg_id = $r->id;
|
||||||
|
|
||||||
if($projectnum == null)
|
if($projectnum == null)
|
||||||
{
|
{
|
||||||
$q=mysql_query("SELECT id FROM registrations WHERE num='$regnum' AND year='{$config['FAIRYEAR']}'");
|
|
||||||
$r=mysql_fetch_object($q);
|
|
||||||
$reg_id = $r->id;
|
|
||||||
|
|
||||||
$projectnumber = generateProjectNumber($reg_id);
|
$projectnumber = generateProjectNumber($reg_id);
|
||||||
|
|
||||||
mysql_query("UPDATE projects SET projectnumber='$projectnumber' WHERE registrations_id='$reg_id' AND year='{$config['FAIRYEAR']}'");
|
mysql_query("UPDATE projects SET projectnumber='$projectnumber' WHERE registrations_id='$reg_id' AND year='{$config['FAIRYEAR']}'");
|
||||||
echo happy(i18n("Assigned Project Number: %1",array($projectnumber)));
|
echo happy(i18n("Assigned Project Number: %1",array($projectnumber)));
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
$projectnumber=$projectnum;
|
||||||
|
|
||||||
if($_POST['action']=="receivedyes")
|
if($_POST['action']=="receivedyes")
|
||||||
{
|
{
|
||||||
//actually set it to 'complete'
|
//actually set it to 'complete'
|
||||||
mysql_query("UPDATE registrations SET status='complete' WHERE num='".$_POST['registration_number']."'");
|
mysql_query("UPDATE registrations SET status='complete' WHERE num='$regnum' AND year='{$config['FAIRYEAR']}'");
|
||||||
|
|
||||||
//FIXME: set the to, subsub and subbod!
|
//get all students with this registration number
|
||||||
email_send("register_participants_received",$to,$subsub,$subbod);
|
$recipients=getEmailRecipientsForRegistration($reg_id);
|
||||||
echo happy(i18n("Registration of form %1 successfully completed",array($registration_number)));
|
|
||||||
|
foreach($recipients AS $recip) {
|
||||||
|
$to=$recip['to'];
|
||||||
|
$subsub=array(
|
||||||
|
"FAIRNAME"=>$config['fairname']
|
||||||
|
);
|
||||||
|
$subbod=array(
|
||||||
|
"TO"=>$recip['to'],
|
||||||
|
"EMAIL"=>$recip['email'],
|
||||||
|
"FIRSTNAME"=>$recip['firstname'],
|
||||||
|
"LASTNAME"=>$recip['lastname'],
|
||||||
|
"NAME"=>$recip['firstname']." ".$recip['lastname'],
|
||||||
|
"REGNUM"=>$regnum,
|
||||||
|
"PROJECTNUMBER"=>$projectnumber,
|
||||||
|
"FAIRNAME"=>$config['fairname']
|
||||||
|
);
|
||||||
|
email_send("register_participants_received",$to,$subsub,$subbod);
|
||||||
|
}
|
||||||
|
|
||||||
|
echo happy(i18n("Registration of form %1 successfully completed",array($regnum)));
|
||||||
}
|
}
|
||||||
else if($_POST['action']=="receivedyesnocash")
|
else if($_POST['action']=="receivedyesnocash")
|
||||||
{
|
{
|
||||||
//actually set it to 'paymentpending'
|
//actually set it to 'paymentpending'
|
||||||
mysql_query("UPDATE registrations SET status='paymentpending' WHERE num='".$_POST['registration_number']."'");
|
mysql_query("UPDATE registrations SET status='paymentpending' WHERE num='$regnum' AND year='{$config['FAIRYEAR']}'");
|
||||||
|
|
||||||
//FIXME: set the to, subsub and subbod!
|
//get all students with this registration number
|
||||||
email_send("register_participants_paymentpending",$to,$subsub,$subbod);
|
$recipients=getEmailRecipientsForRegistration($reg_id);
|
||||||
echo happy(i18n("Registration of form %1 marked as payment pending",array($registration_number)));
|
|
||||||
|
foreach($recipients AS $recip) {
|
||||||
|
$to=$recip['to'];
|
||||||
|
$subsub=array(
|
||||||
|
"FAIRNAME"=>$config['fairname']
|
||||||
|
);
|
||||||
|
$subbod=array(
|
||||||
|
"TO"=>$recip['to'],
|
||||||
|
"EMAIL"=>$recip['email'],
|
||||||
|
"FIRSTNAME"=>$recip['firstname'],
|
||||||
|
"LASTNAME"=>$recip['lastname'],
|
||||||
|
"NAME"=>$recip['firstname']." ".$recip['lastname'],
|
||||||
|
"REGNUM"=>$regnum,
|
||||||
|
"PROJECTNUMBER"=>$projectnumber,
|
||||||
|
"FAIRNAME"=>$config['fairname']
|
||||||
|
);
|
||||||
|
|
||||||
|
email_send("register_participants_paymentpending",$to,$subsub,$subbod);
|
||||||
|
}
|
||||||
|
echo happy(i18n("Registration of form %1 marked as payment pending",array($regnum)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if($_POST['action']=="receivedno" && $_POST['registration_number'])
|
else if($_POST['action']=="receivedno" && $_POST['registration_number'])
|
||||||
{
|
{
|
||||||
echo notice(i18n("Registration of form %1 cancelled",array($registration_number)));
|
echo notice(i18n("Registration of form %1 cancelled",array($_POST['registration_number'])));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,23 +299,3 @@ echo mysql_Error();
|
|||||||
|
|
||||||
send_footer();
|
send_footer();
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -794,14 +794,21 @@ function outputStatus($status)
|
|||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//returns true if its a valid email address, false if its not
|
||||||
|
function isEmailAddress($str) {
|
||||||
|
if(eregi('[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})', $str))
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
function email_send($val,$to,$sub_subject=array(),$sub_body=array())
|
function email_send($val,$to,$sub_subject=array(),$sub_body=array())
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
//if our "to" doesnt look like a valid email, then forget about sending it.
|
//if our "to" doesnt look like a valid email, then forget about sending it.
|
||||||
if(!eregi('[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})', $to))
|
if(!isEmailAddress($to))
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
$q=mysql_query("SELECT * FROM emails WHERE val='$val'");
|
$q=mysql_query("SELECT * FROM emails WHERE val='$val'");
|
||||||
if($r=mysql_fetch_object($q))
|
if($r=mysql_fetch_object($q))
|
||||||
@ -852,7 +859,7 @@ function email_send($val,$to,$sub_subject=array(),$sub_body=array())
|
|||||||
|
|
||||||
//only send the email if we have a from
|
//only send the email if we have a from
|
||||||
if($fr) {
|
if($fr) {
|
||||||
$extraheaders="From: $fr\r\bReply-To: $fr\r\nREturn-Path: $fr";
|
$extraheaders="From: $fr\r\nReply-To: $fr\r\nReturn-Path: $fr";
|
||||||
mail($to,$subject,$body,$extraheaders);
|
mail($to,$subject,$body,$extraheaders);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -864,6 +871,44 @@ function email_send($val,$to,$sub_subject=array(),$sub_body=array())
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
returns an array of arrays
|
||||||
|
[ 0 ] = array ( to, firstname, lastname, email )
|
||||||
|
[ 1 ] = array ( to, firstname, lastname, email )
|
||||||
|
...etc
|
||||||
|
|
||||||
|
*/
|
||||||
|
function getEmailRecipientsForRegistration($reg_id)
|
||||||
|
{
|
||||||
|
global $config;
|
||||||
|
//okay first grab the registration record, to see if we should email the kids, the teacher, and/or the parents
|
||||||
|
$q=mysql_query("SELECT * FROM registrations WHERE id='$reg_id' AND year='{$config['FAIRYEAR']}'");
|
||||||
|
$registration=mysql_fetch_object($q);
|
||||||
|
|
||||||
|
//FIXME: right now it only emails the kids! add fields to registrations table to store who it should email
|
||||||
|
//and write a way for that info to be updated, especially on the teacher invitation screen to have emails
|
||||||
|
//go to the teacher.
|
||||||
|
|
||||||
|
$sq=mysql_query("SELECT * FROM students WHERE registrations_id='$reg_id' AND year='{$config['FAIRYEAR']}'");
|
||||||
|
$ret=array();
|
||||||
|
while($sr=mysql_fetch_object($sq)) {
|
||||||
|
if($sr->email && isEmailAddress($sr->email)) {
|
||||||
|
if($sr->firstname && $sr->lastname)
|
||||||
|
$to=$sr->firstname." ".$sr->lastname." <".$sr->email.">";
|
||||||
|
else if($sr->firstname)
|
||||||
|
$to=$sr->firstname." <".$sr->email.">";
|
||||||
|
else if($sr->lastname)
|
||||||
|
$to=$sr->lastname." <".$sr->email.">";
|
||||||
|
$ret[]=array("to"=>$to,
|
||||||
|
"firstname"=>$sr->firstname,
|
||||||
|
"lastname"=>$sr->lastname,
|
||||||
|
"email"=>$sr->email,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
function output_page_text($textname)
|
function output_page_text($textname)
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
|
@ -319,7 +319,7 @@
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
//they can only create a new registraiton if they have a valid email address, so lets do a quick ereg check on their email
|
//they can only create a new registraiton if they have a valid email address, so lets do a quick ereg check on their email
|
||||||
if(eregi('[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})', $_SESSION['email']))
|
if(isEmailAddress($_SESSION['email']))
|
||||||
{
|
{
|
||||||
|
|
||||||
$regnum=0;
|
$regnum=0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user