Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2014
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.73 KB | None | 0 0
  1. <?php
  2.     // Include some files
  3.     require_once("class.db.php");
  4.     require_once('class.email.php');
  5.     require_once('includes/global.php');
  6.    
  7.     // Get post data from AJAX Call
  8.     $statusID = $_POST['status'];
  9.     $submissionID = $_POST['submission'];
  10.     $action = $_POST['action'];
  11.     $denial = $_POST['denial'];
  12.    
  13.     // Fetch some details of the submission for the email
  14.     $objDB = new DB;
  15.     $fetchData = $objDB
  16.         -> setStoredProc('empowermentFetchSubmissions')
  17.         -> setParam( "submissionID", $submissionID )
  18.         -> setParam( "action", 'single' )                  
  19.         -> execStoredProc()
  20.         -> parseXML();
  21.    
  22.     // Define the vars that we will need for the email.
  23.     $submitterFirst = $fetchData->data->submitterFirst;
  24.     $submitterLast = $fetchData->data->submitterLast;
  25.     $submitterEmail = $fetchData->data->submitEmail;
  26.     $submitterSupEmail = $fetchData->data->supEmail;
  27.     $submitterSupFirst = $fetchData->data->submitterSupFirst;
  28.     $submitterSupLast = $fetchData->data->submitterSupLast;
  29.     $nomineeFirst = $fetchData->data->nomineeFirst;
  30.     $nomineeEmail = $fetchData->data->nomineeEmail;
  31.     $nomineeLast = $fetchData->data->nomineeLast;
  32.     $approvalLink = $toolURL.'pending.php?submission='.$submissionID;
  33.     $submissionLink = $toolURL.'submissions.php?submissionID='.$submissionID;
  34.     $proxy = $fetchData->data->proxy;
  35.     $localeID = $fetchData->data->locationID;
  36.     $proxyFirst = $fetchData->data->proxyFirst;
  37.     $proxyLast = $fetchData->data->proxyLast;
  38.     $proxyEmail = $fetchData->data->proxyEmail;
  39.    
  40.    
  41.     // Set up the body of the email
  42.     switch($statusID){
  43.         case '1': //Pending
  44.             // If the sup of submitter has a proxy
  45.             if($proxy){
  46.                 $emailTo = $proxyEmail;
  47.             }else{
  48.                 $emailTo = $submitterSupEmail;
  49.             }
  50.             sendEmail('pendingEmail', $emailTo, '', $toolURL);         
  51.         break;
  52.         case '2': //Denied
  53.             $emailTo = $submitterEmail;
  54.             // If the sup of submitter has a proxy
  55.             if($proxy){
  56.                 $emailCC = $proxyEmail;
  57.             }else{
  58.                 $emailCC = $submitterSupEmail;
  59.             }
  60.             sendEmail('deniedEmail', $emailTo, $emailCC, $toolURL);        
  61.         break;
  62.         case '3': //Approved
  63.             $emailTo = $submitterEmail;
  64.             // If the sup of submitter has a proxy
  65.             if($proxy){
  66.                 $emailCC = $proxyEmail;
  67.             }else{
  68.                 $emailCC = $submitterSupEmail;
  69.             }  
  70.             sendEmail('approvedEmail', $emailTo, $emailCC, $toolURL);
  71.             sendEmail('nomineeEmail', $nomineeEmail, '', $toolURL);
  72.         break;
  73.     }
  74.    
  75.     function sendEmail($theTemplate, $emailTo, $emailCC, $toolURL){
  76.  
  77.         // Get the email template for this locale
  78.         $objDB = new DB;
  79.         $fetchTemplate = $objDB
  80.             -> setStoredProc('empowermentGetTemplates')
  81.             -> setParam( "locale", $localeID )
  82.             -> setParam( "templateName", $theTemplate )
  83.             -> setParam( "action", 'locale' )                  
  84.             -> execStoredProc()
  85.             -> parseXML(); 
  86.        
  87.         // Replace all of the tags with the values
  88.         $template = $fetchTemplate->templates->content;
  89.        
  90.         // If the sup of submitter has a proxy
  91.         if($proxy){
  92.             $template = str_replace('[SubmitterSupFirst]', $proxyFirst, $template);
  93.             $template = str_replace('[SubmitterSupLast]', $proxyLast, $template);
  94.         }else{
  95.             $template = str_replace('[SubmitterSupFirst]', $submitterSupFirst, $template);
  96.             $template = str_replace('[SubmitterSupLast]', $submitterSupLast, $template);
  97.         }          
  98.         $template = str_replace('[SubmitterFirst]', $submitterFirst, $template);
  99.         $template = str_replace('[SubmitterLast]', $submitterLast, $template);
  100.         $template = str_replace('[NomineeFirst]', $nomineeFirst, $template);
  101.         $template = str_replace('[NomineeLast]', $nomineeLast, $template);
  102.         $template = str_replace('[ApprovalLink]', $approvalLink, $template);
  103.         $template = str_replace('[DenialLink]', $approvalLink, $template);
  104.         $template = str_replace('[SubmissionLink]', $submissionLink, $template);
  105.         $template = str_replace('[DenialReason]', $denial, $template);
  106.        
  107.         // Set the replaced content to the body tag
  108.         $body = $template;
  109.        
  110.         //Proxy Footer
  111.         if($proxy){
  112.             $body .= '<br />' . '[Designated Proxy for '.$submitterSupFirst . ' ' . $submitterSupLast.']<br />';
  113.         }
  114.        
  115.         // Email Details
  116.         $subject = 'Empowerment Submssion';
  117.         $emailFrom = 'donotreply@website.com';
  118.  
  119.         // Send email to the correct peoples
  120.         $objEmail = new SendMail;
  121.         $objEmail
  122.             -> setTo($emailTo)
  123.             -> setCC($emailCC)
  124.             -> setFrom($emailFrom)
  125.             -> setSubject($subject)
  126.             -> sendHTMLEmail($body);
  127.        
  128.     }
  129.        
  130.     // Update the status of the submission if we are not changing it to pending (not sure why they would do that anyway)
  131.     if($statusID != '1'){  
  132.         $objDB = new DB;
  133.         $update = $objDB   
  134.             -> setStoredProc('empowermentUpdateStatus')
  135.             -> setParam( "submissionID", $submissionID )
  136.             -> setParam( "statusID", $statusID )
  137.             -> setParam( "denialReason", $denial )         
  138.             -> setParam( "qid", $_COOKIE['QID'] )          
  139.             -> execStoredProc()
  140.             -> parseXML();
  141.     }  
  142. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement