Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Include some files
- require_once("class.db.php");
- require_once('class.email.php');
- require_once('includes/global.php');
- // Get post data from AJAX Call
- $statusID = $_POST['status'];
- $submissionID = $_POST['submission'];
- $action = $_POST['action'];
- $denial = $_POST['denial'];
- // Fetch some details of the submission for the email
- $objDB = new DB;
- $fetchData = $objDB
- -> setStoredProc('empowermentFetchSubmissions')
- -> setParam( "submissionID", $submissionID )
- -> setParam( "action", 'single' )
- -> execStoredProc()
- -> parseXML();
- // Define the vars that we will need for the email.
- $submitterFirst = $fetchData->data->submitterFirst;
- $submitterLast = $fetchData->data->submitterLast;
- $submitterEmail = $fetchData->data->submitEmail;
- $submitterSupEmail = $fetchData->data->supEmail;
- $submitterSupFirst = $fetchData->data->submitterSupFirst;
- $submitterSupLast = $fetchData->data->submitterSupLast;
- $nomineeFirst = $fetchData->data->nomineeFirst;
- $nomineeEmail = $fetchData->data->nomineeEmail;
- $nomineeLast = $fetchData->data->nomineeLast;
- $approvalLink = $toolURL.'pending.php?submission='.$submissionID;
- $submissionLink = $toolURL.'submissions.php?submissionID='.$submissionID;
- $proxy = $fetchData->data->proxy;
- $localeID = $fetchData->data->locationID;
- $proxyFirst = $fetchData->data->proxyFirst;
- $proxyLast = $fetchData->data->proxyLast;
- $proxyEmail = $fetchData->data->proxyEmail;
- // Set up the body of the email
- switch($statusID){
- case '1': //Pending
- // If the sup of submitter has a proxy
- if($proxy){
- $emailTo = $proxyEmail;
- }else{
- $emailTo = $submitterSupEmail;
- }
- sendEmail('pendingEmail', $emailTo, '', $toolURL);
- break;
- case '2': //Denied
- $emailTo = $submitterEmail;
- // If the sup of submitter has a proxy
- if($proxy){
- $emailCC = $proxyEmail;
- }else{
- $emailCC = $submitterSupEmail;
- }
- sendEmail('deniedEmail', $emailTo, $emailCC, $toolURL);
- break;
- case '3': //Approved
- $emailTo = $submitterEmail;
- // If the sup of submitter has a proxy
- if($proxy){
- $emailCC = $proxyEmail;
- }else{
- $emailCC = $submitterSupEmail;
- }
- sendEmail('approvedEmail', $emailTo, $emailCC, $toolURL);
- sendEmail('nomineeEmail', $nomineeEmail, '', $toolURL);
- break;
- }
- function sendEmail($theTemplate, $emailTo, $emailCC, $toolURL){
- // Get the email template for this locale
- $objDB = new DB;
- $fetchTemplate = $objDB
- -> setStoredProc('empowermentGetTemplates')
- -> setParam( "locale", $localeID )
- -> setParam( "templateName", $theTemplate )
- -> setParam( "action", 'locale' )
- -> execStoredProc()
- -> parseXML();
- // Replace all of the tags with the values
- $template = $fetchTemplate->templates->content;
- // If the sup of submitter has a proxy
- if($proxy){
- $template = str_replace('[SubmitterSupFirst]', $proxyFirst, $template);
- $template = str_replace('[SubmitterSupLast]', $proxyLast, $template);
- }else{
- $template = str_replace('[SubmitterSupFirst]', $submitterSupFirst, $template);
- $template = str_replace('[SubmitterSupLast]', $submitterSupLast, $template);
- }
- $template = str_replace('[SubmitterFirst]', $submitterFirst, $template);
- $template = str_replace('[SubmitterLast]', $submitterLast, $template);
- $template = str_replace('[NomineeFirst]', $nomineeFirst, $template);
- $template = str_replace('[NomineeLast]', $nomineeLast, $template);
- $template = str_replace('[ApprovalLink]', $approvalLink, $template);
- $template = str_replace('[DenialLink]', $approvalLink, $template);
- $template = str_replace('[SubmissionLink]', $submissionLink, $template);
- $template = str_replace('[DenialReason]', $denial, $template);
- // Set the replaced content to the body tag
- $body = $template;
- //Proxy Footer
- if($proxy){
- $body .= '<br />' . '[Designated Proxy for '.$submitterSupFirst . ' ' . $submitterSupLast.']<br />';
- }
- // Email Details
- $subject = 'Empowerment Submssion';
- $emailFrom = 'donotreply@website.com';
- // Send email to the correct peoples
- $objEmail = new SendMail;
- $objEmail
- -> setTo($emailTo)
- -> setCC($emailCC)
- -> setFrom($emailFrom)
- -> setSubject($subject)
- -> sendHTMLEmail($body);
- }
- // Update the status of the submission if we are not changing it to pending (not sure why they would do that anyway)
- if($statusID != '1'){
- $objDB = new DB;
- $update = $objDB
- -> setStoredProc('empowermentUpdateStatus')
- -> setParam( "submissionID", $submissionID )
- -> setParam( "statusID", $statusID )
- -> setParam( "denialReason", $denial )
- -> setParam( "qid", $_COOKIE['QID'] )
- -> execStoredProc()
- -> parseXML();
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement