<?php
$to = (isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) 
        ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $_GET['emailAddress']) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : "");

$from = "arac@u.washington.edu"; 
$subject = '';
$body = '';
$headers = 'From: '.$from;

if(isset($_GET['update'])){
	$jobTitle = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $_GET['jobTitle']) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));
	$jobNumber = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $_GET['jobNumber']) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));
	$status = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $_GET['status']) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));
	
	if(isset($_GET['formType'])){
		$formType = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $_GET['formType']) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));
		$jobId = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $_GET['id']) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));
		if($_GET['approved'] == "No"){
			$subject = "[AR Job] $jobTitle Job Update";
			$body = "
Thank you for submitting your job description for $jobTitle. The position description has not been approved and has not been posted on our site. 
For additional information about the Work Study hiring and payment process please review our web pages.
http://www.washington.edu/students/osfa/ugaid/employer.info.html";
		} else {
			$subject = "[AR Job] $jobTitle Job Description";
			$body = "	
Thank you for submitting your job description for $jobTitle.  
The position description has been approved and if the position is open it will be posted on our site. 
Please notify our office when the position has been filled so we can remove it from our listing.  
You can view your listing at: http://www.washington.edu/students/osfa/workstudy/ar_uwlist.php
						
You can view a pdf of the job description at: 
http://www.washington.edu/students/osfa/workstudy/ar_report.php?id=" . $jobId . "&table=americaReads

Job Title:  $jobTitle
Job ID:  $jobId
Status:  $status
Type: $formType

For additional information about the Work Study hiring and payment process please review our web pages.
http://www.washington.edu/students/osfa/ugaid/employer.info.html";	
		}
		mail($to,$subject,$body,$headers);
		echo("$to, $subject, $body, $headers");
	} elseif (isset($_GET['category']) || isset($_GET['orgName'])) { //For Work study emails
		if(isset($_GET['category'])){
			$from = "uworkstu@uw.edu";
			$headers = 'From: '.$from;
		} else {
			$from = "workstdy@uw.edu";
			$headers = 'From: '.$from;
		}
		$program = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $_GET['program']) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));
		$subject = "[WS Job] $jobTitle Job Description";
		$body = "	
Thank you for submitting your job description for $jobTitle.  
The position description has been approved and if the position is open it will be posted on our site. 
Please notify our office when the position has been filled so we can remove it from our listing.  
You can view your listing at: 

http://www.washington.edu/students/osfa/ugaid/workstudy.positions.html

Job Title:  $jobTitle
Job Number:  $jobNumber
Status:  $status
Program:  $program

For additional information about the Work Study hiring and payment process please review our web pages.
http://www.washington.edu/students/osfa/ugaid/employer.info.html";	
		mail($to,$subject,$body,$headers);
		echo("$to, $subject, $body, $headers");
	} else{ //Neither Workstudy nor America Reads
		$subject = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $_GET['subject']) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));
		$body = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $_GET['body']) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));
		$to = explode(", ", $to);
		for($i = 0; $i <= count($to); $i++) {
			mail($to[$i],$subject,$body,$headers);
		}
	}
}		
		
?>
