diff --git a/admin/registration_receivedforms.php b/admin/registration_receivedforms.php index 6b229d06..7bad9218 100644 --- a/admin/registration_receivedforms.php +++ b/admin/registration_receivedforms.php @@ -203,42 +203,80 @@ echo mysql_Error(); AND registrations.year='{$config['FAIRYEAR']}'"); $checkNumResults=mysql_fetch_object($checkNumQuery); $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) { - $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); - 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))); } + else + $projectnumber=$projectnum; + if($_POST['action']=="receivedyes") { //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! - email_send("register_participants_received",$to,$subsub,$subbod); - echo happy(i18n("Registration of form %1 successfully completed",array($registration_number))); - - + //get all students with this registration number + $recipients=getEmailRecipientsForRegistration($reg_id); + + 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") { //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! - email_send("register_participants_paymentpending",$to,$subsub,$subbod); - echo happy(i18n("Registration of form %1 marked as payment pending",array($registration_number))); + //get all students with this registration number + $recipients=getEmailRecipientsForRegistration($reg_id); + + 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']) { - 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(); ?> - - - - - - - - - - - - - - - - - - - - diff --git a/common.inc.php b/common.inc.php index 1693b037..2a81860a 100644 --- a/common.inc.php +++ b/common.inc.php @@ -794,14 +794,21 @@ function outputStatus($status) 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()) { global $config; //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)) - return; + if(!isEmailAddress($to)) + return false; $q=mysql_query("SELECT * FROM emails WHERE val='$val'"); 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 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); } 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) { global $config; diff --git a/register_participants.php b/register_participants.php index 89f2755b..7d47bd98 100644 --- a/register_participants.php +++ b/register_participants.php @@ -319,7 +319,7 @@ 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 - if(eregi('[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})', $_SESSION['email'])) + if(isEmailAddress($_SESSION['email'])) { $regnum=0;