<?php 
session_start();
require '../dao/Mail.php';
$response = 0;
$staff = '';
$parent = '';
$parents = '';
if (isset($_POST['parent'])) {
	$parent = $_POST['parent'];
	$subject = $_POST['subject'];
	$msgBody = 	 $_POST['msgBody'];
require '../mailer/PHPMailerAutoload.php';
date_default_timezone_set('Africa/Accra');
$mail = new PHPMailer;
//$mail->SMTPDebug = 3;
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'millsabeiku2@gmail.com';                 // SMTP username
    $mail->Password = 'Mills0555733180@';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;                                    // TCP port to connect to
foreach ($parent as $parent) {
	//Set who the message is to be sent from
$mail->setFrom('team_support@newlook.com', 'New Look Administration');
//Set an alternative reply-to address
$mail->addReplyTo('noreply@newlook.com', 'New Look Support team');
//Set who the message is to be sent to
$mail->addAddress($parent,'Parent');
    $mail->isHTML(true);
    $mail->Subject = $subject;
    $mail->Body    = $msgBody;
    $mail->AltBody = 'This is a mail from New Look.';
}
if (!$mail->send()) {
	$response = 1;
   echo $response;
} else {
	$response = 2;
    echo $response;
}
	}else{
	//echo $response = 3;
}
//End of parent code

if (isset($_POST['staff'])) {
		$staff = $_POST['staff'];
			$subject = $_POST['subject'];
			$attachment = $_POST['Attachments'];
			$len = strlen($_POST['Attachments']);
			$attachment = substr($attachment, 0,$len-1);
			
	// 		for ($i=0; $i < sizeof($attachment) ; $i++) { 
	// 	if ($i==sizeof($attachment)-1) {
	// 		$single2 = $attachment['phone3'];
	// 	}else{
	// 		$single = $attachment['phone1'].','.$attachment['phone2'].',';
	// 	}
		
	// }
	$msgBody = $_POST['msgBody'];
	foreach ($staff as $one) {
		$data = array("user_to"=>$one,"user_from"=>$_SESSION['staff_id'],
				  "msg"=>$msgBody,"subject"=>$subject,"attatchment"=>$attachment);
		$success = $mail->compose($data);
	}
	
	
	if ($success) {
		echo $response = 200;
	}else{
		echo $response = 500;
	}
	}else{

	}
	//end of staff Code


	if (isset($_POST['parents'])) {
	$parents = $_POST['parents'];
	$subject = $_POST['subject'];
	$msgBody = 	$msgBody = $_POST['msgBody'];;
		require '../mailer/PHPMailerAutoload.php';
date_default_timezone_set('Africa/Accra');
$mail = new PHPMailer;
//$mail->SMTPDebug = 3;
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'millsabeiku2@gmail.com';                 // SMTP username
    $mail->Password = 'Mills0555733180@';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;                                    // TCP port to connect to
foreach ($parents as $parent) {
	//Set who the message is to be sent from
$mail->setFrom('team_support@newlook.com', 'New Look Administration');
//Set an alternative reply-to address
$mail->addReplyTo('noreply@newlook.com', 'New Look Support team');
//Set who the message is to be sent to
$mail->addAddress($parent,'Parent');
    $mail->isHTML(true);
    $mail->Subject = $subject;
    $mail->Body    = $msgBody;
    $mail->AltBody = 'This is a mail from New Look.';
}
if (!$mail->send()) {
	$response = 1;
   echo $response;
} else {
	$response = 2;
    echo $response;
}
	}else{

	}

	// End of Parents code

	if (isset($_POST['staff'])&&isset($_POST['parents'])&&isset($_POST['parent'])) {
		# code...
	}

	if (isset($_POST['del_mail_id'])) {
		$mail_id = $_POST['del_mail_id'];
		$data = array("deleted"=>"yes");
		$success = $mail->update_deleted($data,$mail_id);
		if($success){
			echo 1;
		}else{
			echo 2;
		}
	}
 ?>