<?php
namespace App\Controller;
use App\Entity\Applicant;
use App\Form\ApplicantType;
use App\Repository\ApplicantRepository;
use App\Repository\RefrenceRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Routing\Annotation\Route;
use App\Entity\Refrence;
//PHPMailer Package
//Import PHPMailer classes into the global namespace
//These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
//Load Composer's autoloader
//require 'vendor/autoload.php';
/**
* @Route("/applicant")
*/
class ApplicantController extends AbstractController
{
/* protected function sendrefmail($mail,$refEmail,$subject, $message)
{
//Create an instance; passing `true` enables exceptions
//Email Ref1
$mail->addAddress($refEmail, 'Reference Email'); //Add a recipient
// $mail->addAddress('ellen@example.com'); //Name is optional
// $mail->addReplyTo('info@example.com', 'Information');
// $mail->addCC('mndang@health.ucsd.edu');
//$mail->addBCC('bcc@example.com');
//Attachments
// $mail->addAttachment('/var/tmp/file.tar.gz'); //Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); //Optional name
//Content
$mail->Subject = $subject;
$mail->Body = $message;
// $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
}
*/
/**
* @Route("/", name="app_applicant_index", methods={"GET"})
*/
public function index(ApplicantRepository $applicantRepository): Response
{
if ($this->container->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
$user = $this->container->get('security.token_storage')->getToken()->getUser();
$username = $user->getUsername();
// $useremail = $user->getEmail();
$UserRoles = $user->getRoles();
}
if (in_array("ROLE_ADMIN",$UserRoles))
{
$applicants = $applicantRepository->findAll();
} elseif (in_array("ROLE_BODY",$UserRoles)) {
$applicants = $applicantRepository->findByDivision('Body');
} elseif (in_array("ROLE_MSK",$UserRoles)) {
$applicants = $applicantRepository->findByDivision('MSK');
} elseif (in_array("ROLE_MRI",$UserRoles)) {
$applicants = $applicantRepository->findByDivision('MRI');
} elseif (in_array("ROLE_WOMEN",$UserRoles)) {
$applicants = $applicantRepository->findByDivision('Women');
} elseif (in_array("ROLE_BREAST",$UserRoles)) {
$applicants = $applicantRepository->findByDivision('Breast');
}elseif (in_array("ROLE_CHEST",$UserRoles)) {
$applicants = $applicantRepository->findByDivision('Chest');
}
for ($i=0; $i<count($applicants);$i++)
{
$refs = $applicants[$i]->getRef();
$num = 0;
foreach ($refs as $ref)
{
if ($ref->getRefLetter() == 'Please upload')
{
}else {
$num = $num+1;
}
}
$applicants[$i]->setRefLtNum($num);
}
return $this->render('applicant/index.html.twig', [
'applicants' => $applicants,
]);
}
/**
* @Route("/new", name="app_applicant_new", methods={"GET", "POST"})
*/
public function new(Request $request, ApplicantRepository $applicantRepository, RefrenceRepository $refrenceRepository): Response
{
$applicant = new Applicant();
$form = $this->createForm(ApplicantType::class, $applicant);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
//get App Form File name
$appFile = $form->get('appForm')->getData();
print $appFile;
if ($appFile){
$newAFilename = md5(uniqid()).'.'.$appFile->guessClientExtension();
// Move the file to the directory where brochures are stored
try {
$appFile->move(
$this->getParameter('brochures_directory'),
$newAFilename
);
} catch (FileException $e) {
// ... handle exception if something happens during file upload
}
}
$applicant->setApplicationForm($newAFilename);
//get personal statment filename
$psFile = $form->get('PersonalStat')->getData();
if ($psFile){
$newpsFilename = md5(uniqid()).'.'.$psFile->guessClientExtension();
// Move the file to the directory where brochures are stored
try {
$psFile->move(
$this->getParameter('brochures_directory'),
$newpsFilename
);
} catch (FileException $e) {
// ... handle exception if something happens during file upload
}
}
$applicant->setPersonal($newpsFilename);
//get CV filename
$cvFile = $form->get('CVLink')->getData();
if ($cvFile){
$newcvFilename = md5(uniqid()).'.'.$cvFile->guessClientExtension();
// Move the file to the directory where brochures are stored
try {
$cvFile->move(
$this->getParameter('brochures_directory'),
$newcvFilename
);
} catch (FileException $e) {
// ... handle exception if something happens during file upload
}
}
$applicant->setCV($newcvFilename);
//get Dean's letter filename
$dlFile = $form->get('dlFile')->getData();
if ($dlFile){
$newdlFilename = md5(uniqid()).'.'.$dlFile->guessClientExtension();
// Move the file to the directory where brochures are stored
try {
$dlFile->move(
$this->getParameter('brochures_directory'),
$newdlFilename
);
} catch (FileException $e) {
// ... handle exception if something happens during file upload
}
}
$applicant->setDeanLetter($newdlFilename);
//get Medical School Diploma filename
$mdFile = $form->get('mdFile')->getData();
if ($mdFile){
$newmdFilename = md5(uniqid()).'.'.$mdFile->guessClientExtension();
// Move the file to the directory where brochures are stored
try {
$mdFile->move(
$this->getParameter('brochures_directory'),
$newmdFilename
);
} catch (FileException $e) {
// ... handle exception if something happens during file upload
}
}
$applicant->setMedSchoolD($newmdFilename);
//get USMLE file name
$usmleFile = $form->get('usfile')->getData();
if ($usmleFile){
$newusmleFilename = md5(uniqid()).'.'.$usmleFile->guessClientExtension();
// Move the file to the directory where brochures are stored
try {
$usmleFile->move(
$this->getParameter('brochures_directory'),
$newusmleFilename
);
} catch (FileException $e) {
// ... handle exception if something happens during file upload
}
}
$applicant->setUSMLE($newusmleFilename);
$refrence = new Refrence();
$refrence->setName($form->get('Ref1Name')->getData());
$refrence->setEmail($form->get('Ref1Email')->getData());
$refrence->setJobTitle($form->get('Ref1Letter')->getData());
$refrence->setAffiliation('Please add');
$refrence->setPhone('Please add');
$refrence->setAddress('Please add');
$refrence->setRefLetter('Please upload');
$refrenceRepository->add($refrence, true);
// add applicant to database
$applicantRepository->add($applicant, true);
$applicant->addRef($refrence);
$refID = $refrence->getId();
//local URL
//$url = 'http://127.0.0.1:8000/refrence/'.$refID.'/edit';
$url = 'http://rad-sdsc.ucsd.edu/refrence/'.$refID.'/edit';
$to = $form->get('Ref1Email')->getData();
$headers = 'From: eghobrial@ucsd.edu' . '\r\n' . 'CC: eghobrial@ucsd.edu';
$appName = $form->get('Name')->getData();
$appEmail = $form->get('Email')->getData();
$appDiv = $form->get('Division')->getData();
$ref1Name = $form->get('Ref1Name')->getData();
$ref1Email = $form->get('Ref1Email')->getData();
$ref2Name = $form->get('Ref2Name')->getData();
$ref2Email = $form->get('Ref2Email')->getData();
$ref3Name = $form->get('Ref3Name')->getData();
$ref3Email = $form->get('Ref3Email')->getData();
$refrence2 = new Refrence();
$refrence2->setName($form->get('Ref2Name')->getData());
$refrence2->setEmail($form->get('Ref2Email')->getData());
$refrence2->setJobTitle($form->get('Ref2Letter')->getData());
$refrence2->setAffiliation('Please add');
$refrence2->setPhone('Please add');
$refrence2->setAddress('Please add');
$refrence2->setRefLetter('Please upload');
$refrenceRepository->add($refrence2, true);
$applicant->addRef($refrence2);
$refID2 = $refrence2->getId();
//local URL
// $url2 = 'http://127.0.0.1:8000/refrence/'.$refID2.'/edit';
$url2 = 'http://rad-sdsc.ucsd.edu/refrence/'.$refID2.'/edit';
$refrence3 = new Refrence();
$refrence3->setName($form->get('Ref3Name')->getData());
$refrence3->setEmail($form->get('Ref3Email')->getData());
$refrence3->setJobTitle($form->get('Ref3Letter')->getData());
$refrence3->setAffiliation('Please add');
$refrence3->setPhone('Please add');
$refrence3->setAddress('Please add');
$refrence3->setRefLetter('Please upload');
$refrenceRepository->add($refrence3, true);
$applicant->addRef($refrence3);
$refID3 = $refrence3->getId();
//local URL
// $url3 = 'http://127.0.0.1:8000/refrence/'.$refID3.'/edit';
$url3 = 'http://rad-sdsc.ucsd.edu/refrence/'.$refID3.'/edit';
$subject = 'Recommendation Letter Request -- UCSD Radiology -- '.$appDiv.' Division Fellowship for Dr. '.$appName;
$message = $appName.' has selected you to provide a letter of recommendation as they apply for a fellowship position with
the Department of Radiology at UCSD '. $appDiv.'. Please submit a letter of recommendation as a PDF to the following URL: '.$url.' Feel free to reach out to
Myra Dang (mndang@health.ucsd.edu), Radiology Fellowship Coordinator, if you have any questions. * Reference #1*, '. $ref1Email.' ';
$message2 = $appName.' has selected you to provide a letter of recommendation as they apply for a fellowship position with
the Department of Radiology at UCSD'. $appDiv.'. Please submit a letter of recommendation as a PDF to the following URL: '.$url2.' Feel free to reach out to
Myra Dang (mndang@health.ucsd.edu), Radiology Fellowship Coordinator, if you have any questions. *Reference #2*, '. $ref2Email.' ';
$message3 = $appName.' has selected you to provide a letter of recommendation as they apply for a fellowship position with
the Department of Radiology at UCSD'. $appDiv.'. Please submit a letter of recommendation as a PDF to the following URL: '.$url3.' Feel free to reach out to
Myra Dang (mndang@health.ucsd.edu), Radiology Fellowship Coordinator, if you have any questions. *Reference #3*, '. $ref3Email.' ';
// $mailsent = mail($to,$subject,$message);
/* $mail = new PHPMailer(true);
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
$mail->isSMTP(); //Send using SMTP
$mail->Host = 'smtp.ucsd.edu'; //Set the SMTP server to send through
$mail->SMTPAuth = true; //Enable SMTP authentication
$mail->Username = 'eghobrial@ucsd.edu'; //SMTP username
$mail->Password = 'Secret'; //SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption
$mail->Port = 465; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
//Recipients
$mail->setFrom('eghobrial@ucsd.edu', 'UCSD Radiology Dept Reference Request');
$mail->isHTML(true);
$this->sendrefmail($mail,$ref1Email,$subject, $message);
$this->sendrefmail($mail,$ref2Email,$subject, $message2);
$this->sendrefmail($mail,$ref3Email,$subject, $message3);*/
$mailref1 = mail($ref1Email,$subject, $message);
$mailref2 = mail($ref2Email,$subject, $message2);
$mailref3 = mail($ref3Email,$subject, $message3);
$mailrefa1 = mail('eghobrial@ucsd.edu',$subject, $message);
$mailrefa2 = mail('eghobrial@ucsd.edu',$subject, $message2);
$mailrefa3 = mail('eghobrial@ucsd.edu',$subject, $message3);
if ($appDiv == 'MSK')
{
//send a confirmation message
$appSub = 'UCSD MSK Fellowship Application has been received';
$appmessage = 'We appreciate your interest in our Musculoskeletal Imaging Fellowship and received your application. Please be patient as we process all applications,
and we will keep you updated on your status as we start scheduling our virtual interviews for January 2025.';
$mailapp = mail($appEmail,$appSub, $appmessage);
} elseif ($appDiv == 'Body')
{
//send a confirmation message
$appSub = 'UCSD Body Fellowship Application has been received';
$appmessage = 'We appreciate your interest in our Body Imaging Fellowship and received your application. Please be patient as we process all applications,
and we will keep you updated on your status as we start scheduling our virtual interviews for January 2025.';
$mailapp = mail($appEmail,$appSub, $appmessage);
}elseif ($appDiv == 'Breast')
{
//send a confirmation message
$appSub = 'UCSD Breast Fellowship Application has been received';
$appmessage = 'We appreciate your interest in our Breast Imaging Fellowship and received your application. Please be patient as we process all applications,
and we will keep you updated on your status as we start scheduling our virtual interviews for January 2025.';
$mailapp = mail($appEmail,$appSub, $appmessage);
//replace email address
$subjectapp = 'We received Dr. '.$appName.' for '.$appDiv. ' Division';
$mailsentApp = mail('eghobrial@ucsd.edu',$subjectapp,'Application received and ready to be viewed on the portal');
}elseif ($appDiv == 'Women')
{
//send a confirmation message
$appSub = 'UCSD Women Imaging Fellowship Application has been received';
$appmessage = 'We appreciate your interest in our Women Imaging Fellowship and received your application. Please be patient as we process all applications,
and we will keep you updated on your status as we start scheduling our virtual interviews for January 2025.';
$mailapp = mail($appEmail,$appSub, $appmessage);
//replace email address
$subjectapp = 'We received Dr. '.$appName.' for '.$appDiv. ' Division';
$mailsentApp = mail('eghobrial@ucsd.edu',$subjectapp,'Application received and ready to be viewed on the portal');
}elseif ($appDiv == 'Chest')
{
//send a confirmation message
$appSub = 'UCSD Cardiothoracic Fellowship Application has been received';
$appmessage = 'We appreciate your interest in our Cardiothoracic Imaging Fellowship and received your application. Please be patient as we process all applications,
and we will keep you updated on your status as we start scheduling our virtual interviews for January 2025.';
$mailapp = mail($appEmail,$appSub, $appmessage);
//replace email address
$subjectapp = 'We received Dr. '.$appName.' for '.$appDiv. ' Division';
$mailsentApp = mail('eghobrial@ucsd.edu',$subjectapp,'Application received and ready to be viewed on the portal');
} elseif ($appDiv == 'MRI')
{
//send a confirmation message
$appSub = 'UCSD MRI Fellowship Application has been received';
$appmessage = 'We appreciate your interest in our MRI Imaging Fellowship and received your application. Please be patient as we process all applications,
and we will keep you updated on your status as we start scheduling our virtual interviews for January 2025.';
$mailapp = mail($appEmail,$appSub, $appmessage);
//replace email address
$subjectapp = 'We received Dr. '.$appName.' for '.$appDiv. ' Division';
$mailsentApp = mail('eghobrial@ucsd.edu',$subjectapp,'Application received and ready to be viewed on the portal');
}
return $this->redirectToRoute('app_applicant_sucess', [], Response::HTTP_SEE_OTHER);
}
return $this->renderForm('applicant/new.html.twig', [
'applicant' => $applicant,
'form' => $form,
]);
}
/**
* @Route("/sucess", name="app_applicant_sucess", methods={"GET"})
*/
public function showsucess(): Response
{
return $this->render('applicant/sucess.html.twig');
}
/**
* @Route("/{id}", name="app_applicant_show", methods={"GET"})
*/
public function show(Applicant $applicant): Response
{
return $this->render('applicant/show.html.twig', [
'applicant' => $applicant,
'References' => $applicant->getRef(),
]);
}
/**
* @Route("/{id}/edit", name="app_applicant_edit", methods={"GET", "POST"})
*/
public function edit(Request $request, Applicant $applicant, ApplicantRepository $applicantRepository): Response
{
$form = $this->createForm(ApplicantType::class, $applicant);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
//get USMLE letter filename
/*$usmleFile = $form->get('usfile')->getData();
if ($usmleFile){
$newusmleFilename = md5(uniqid()).'.'.$usmleFile->guessClientExtension();
// Move the file to the directory where brochures are stored
try {
$usmleFile->move(
$this->getParameter('brochures_directory'),
$newusmleFilename
);
} catch (FileException $e) {
// ... handle exception if something happens during file upload
}
}
$applicant->setUSMLE($newusmleFilename);*/
//get Dean's letter filename
$dlFile = $form->get('dlFile')->getData();
if ($dlFile){
$newdlFilename = md5(uniqid()).'.'.$dlFile->guessClientExtension();
// Move the file to the directory where brochures are stored
try {
$dlFile->move(
$this->getParameter('brochures_directory'),
$newdlFilename
);
} catch (FileException $e) {
// ... handle exception if something happens during file upload
}
}
$applicant->setDeanLetter($newdlFilename);
$applicantRepository->add($applicant, true);
return $this->redirectToRoute('app_applicant_index', [], Response::HTTP_SEE_OTHER);
}
return $this->renderForm('applicant/edit.html.twig', [
'applicant' => $applicant,
'form' => $form,
]);
}
/**
* @Route("/{id}/review", name="app_applicant_review", methods={"GET", "POST"})
*/
public function review(Request $request, Applicant $applicant, ApplicantRepository $applicantRepository): Response
{
/* $form = $this->createFormBuilder()
->add('status', TextType::class,[
'label' => 'Status'])
->add('status', TextType::class,[
'label' => 'Status'])
->add('Review', SubmitType::class)
->getForm();
$form->handleRequest($request);
*/
if ($this->container->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
$user = $this->container->get('security.token_storage')->getToken()->getUser();
$username = $user->getUsername();
// $useremail = $user->getEmail();
$UserRoles = $user->getRoles();
}
$form = $this->createForm(ApplicantType::class, $applicant);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$mynotes = $form->get('Notes')->getData()." added by ".$username." on ".date("m-d-Y");
$applicant->setNotes($mynotes);
$applicantRepository->add($applicant, true);
// return $this->redirectToRoute('app_applicant_index', [], Response::HTTP_SEE_OTHER);
}
return $this->renderForm('applicant/review.html.twig', [
'applicant' => $applicant,
'form' => $form,
]);
}
/**
* @Route("/{id}", name="app_applicant_delete", methods={"POST"})
*/
/* public function delete(Request $request, Applicant $applicant, ApplicantRepository $applicantRepository): Response
{
if ($this->isCsrfTokenValid('delete'.$applicant->getId(), $request->request->get('_token'))) {
$applicantRepository->remove($applicant, true);
}
return $this->redirectToRoute('app_applicant_index', [], Response::HTTP_SEE_OTHER);
}
*/
}