<?php
/**
* Created by PhpStorm.
* User: dardennj
* Date: 30/05/18
* Time: 16:28
*/
namespace App\Controller\Frontend;
use App\Entity\RecCandidat;
use App\Entity\RecContratVacataire;
use App\Entity\RecDocumentVacataire;
use App\Entity\RecDossierVacataire;
use App\Entity\RecEtatLiquidationVacataire;
use App\Entity\RecEtatLiquidationDocVacataire;
use App\Entity\RecLogDossierVacataire;
use App\Entity\RecParameters;
use App\Entity\RecServiceComposanteVacation;
use App\Entity\RecTypeDocumentVacataire;
use App\Entity\RecTypeVacataire;
use App\Entity\RecVacation;
use App\Entity\RecVacationEtatDossier;
use App\Entity\RecVacationStatut;
use App\Entity\RecVacationStatutContrat;
use App\Entity\RecVacationStatutAC;
use App\Entity\RecVacationStatutCP;
use App\Entity\RecVacationStatutEtatLiquidation;
use App\Form\RecCandidatType;
use App\Form\RecCandidatProfilType;
use App\Form\RecCandidatPwdType;
use App\Form\RecDocumentType;
use App\Form\Model\Registration;
use App\Form\Type\RegistrationType;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use APY\DataGridBundle\Grid\Source\Entity;
use APY\DataGridBundle\Grid\Action\RowAction;
use APY\DataGridBundle\Grid\Column\ActionsColumn;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class VacataireController extends AbstractController
{
/**
* @Route("/login", name="frontend_vacataire_login", host="%vacataire_subdomain%", methods={"GET"})
*/
public function login()
{
return $this->redirect($this->generateUrl('frontend_vacataire'));
}
/**
* @Route("/", name="frontend_vacataire", host="%vacataire_subdomain%", methods={"GET","POST"})
*/
public function index(AuthenticationUtils $authenticationUtils, EncoderFactoryInterface $encoderFactory, MailerInterface $mailer)
{
$type="";
$message="";
// Gestion du login
$request = Request::createFromGlobals();
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
$form = $this->createForm(RecCandidatType::class);
$em = $this->getDoctrine()->getManager();
$parameters = $em->getRepository(RecParameters::class)->find(1);
if ($request->getMethod() == 'POST') {
$form->handleRequest($request);
if ($form->isValid()) {
$user = $form->getData();
$user_exist = $em->getRepository(RecCandidat::class)->findUser($user->getEmail());
if(!$user_exist)
{
$passmail = $user->getPassword();
$encoder = $encoderFactory->getEncoder($user);
$password = $encoder->encodePassword($user->getPassword(), $user->getSalt());
$user->setPassword($password);
$user->setNom(strtoupper($user->getNom()));
$user->setPrenom(ucfirst(strtolower($user->getPrenom())));
$user->setAdresse(ucwords(strtolower($user->getAdresse())));
$user->setVille(ucwords(strtolower($user->getVille())));
$user->setPays(ucwords(strtolower($user->getPays())));
$em->persist($user);
$em->flush();
$mail_noreply = $this->container->get('parameter_bag')->get('mail_noreply');
$site_short_name = $this->container->get('parameter_bag')->get('site_short_name');
$mail = (new TemplatedEmail())
->from($mail_noreply)
->to($user->getEmail())
->subject('['.$site_short_name.'] Votre création de compte pour le dépôt de votre dossier de vacataire')
->htmlTemplate('Courriel/create_vacation.html.twig')
->context(['user' => $user,'passmail'=>$passmail,'serveur'=>$_SERVER['HTTP_HOST']]);
try{
$mailer->send($mail);
$error = false;
}catch(TransportExceptionInterface $e) {
$response = $e->getMessage();
$error = true;
}
return $this->render('Frontend/Candidat/vacation.html.twig', array('form' => $form->createView(),'last_username' => $lastUsername,
'error' => $error,'poste'=> false,'message'=>"Un courriel vient d'être envoyé à l'adresse : ".$user->getEmail()." afin de valider votre compte.","message_type"=>"success","parameters"=>$parameters));
}
else
return $this->render('Frontend/Candidat/vacation.html.twig', array('form' => $form->createView(),'last_username' => $lastUsername,
'error' => $error,'message'=>"Vous disposez déjà d'un compte à cette adresse !","message_type"=>"danger","parameters"=>$parameters));
}
else
{
$post = $request->request->get('rec_candidat');
$password = $post['password']['password'];
$confirmation = $post['password']['confirmation'];
if($password!=$confirmation)
{
$message = "Le mots de passe et la confirmation doivent correspondre";
$type="danger";
}
else if(strlen($password)<7)
{
$message = "Mot de passe inférieur à 7 caractères";
$type="danger";
}
}
}
return $this->render('Frontend/Candidat/vacation.html.twig', array('form' => $form->createView(),'last_username' => $lastUsername, 'error' => $error,'message'=>$message,"message_type"=>$type,"parameters"=>$parameters));
}
/**
* @Route("/activate/{id}", name="frontend_vacataire_activate", host="%vacataire_subdomain%", methods={"GET"})
*/
public function activate(AuthenticationUtils $authenticationUtils, $id)
{
$em = $this->getDoctrine()->getManager();
$parameters = $em->getRepository(RecParameters::class)->find(1);
$request = Request::createFromGlobals();
$error = false;
$lastUsername=false;
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
$form = $this->createForm(RecCandidatType::class);
$entity = $em->getRepository(RecCandidat::class);
$q = $entity
->createQueryBuilder('u')
->where('u.saltEmail = :salt')
->setParameter('salt', $id)
->getQuery();
$user = $q->getSingleResult();
if($user)
{
$user->setIsActive(true);
$em->persist($user);
$em->flush();
}
return $this->render('Frontend/Candidat/vacation.html.twig', array('form' => $form->createView(),'last_username' => $lastUsername, 'error' => $error,'poste'=> false,'message'=>"Votre compte a été validé. Vous pouvez maintenant accéder à votre espace personnel en vous identifiant ci-dessous.","message_type"=>"success","parameters"=>$parameters));
}
/**
* @Route("/vacataire/profil", name="frontend_vacataire_profil", host="%vacataire_subdomain%", methods={"GET","POST"})
*/
public function profil()
{
$user = $this->get('security.token_storage')->getToken()->getUser();
$formProfil = $this->createForm(RecCandidatProfilType::class,$user);
$request = Request::createFromGlobals();
if ($request->getMethod() == 'POST') {
$formProfil->handleRequest($request);
if ($formProfil->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($user);
$em->flush();
return $this->redirect($this->generateUrl('frontend_vacataire_view'));
}
}
return $this->render('Frontend/Vacataire/profil.html.twig',array("formProfil"=>$formProfil->createView()));
}
/**
* @Route("/reset-pwd", name="frontend_vacataire_mdp", host="%vacataire_subdomain%", methods={"POST"})
*/
public function resetPwd(UserPasswordEncoderInterface $encoder, MailerInterface $mailer)
{
$request = Request::createFromGlobals();
$email = trim($request->request->get('mail'));
$em = $this->getDoctrine()->getManager();
$user = $em->getRepository(RecCandidat::class)->findUser($email);
$site_short_name = $this->container->get('parameter_bag')->get('site_short_name');
if($user)
{
$passmail = $this->getPasswordRandom(7);
$password = $encoder->encodePassword($user,$passmail);
$user->setPassword($password);
$em->persist($user);
$em->flush();
$mail_noreply = $this->container->get('parameter_bag')->get('mail_noreply');
$mail = (new TemplatedEmail())
->from($mail_noreply)
->to($user->getEmail())
->subject('['.$site_short_name.'] Mise à jour de votre mot de passe')
->htmlTemplate('Courriel/reset_pwd_vacataire.html.twig')
->context(['user' => $user,'passmail'=>$passmail,'serveur'=>$_SERVER['HTTP_HOST']]);
try{
$mailer->send($mail);
$error = false;
}catch(TransportExceptionInterface $e) {
$response = $e->getMessage();
$error = true;
}
$data = array("success"=>1,"message"=>"Un nouveau mot de passe vient d'être envoyé à l'adresse : ".$user->getEmail(),"password"=>$password);
return new JsonResponse($data);
}
else
{
$data = array("success"=>0,"message"=>"L'adresse de messagerie ne correspond à aucun compte.");
return new JsonResponse($data);
}
}
protected function getPasswordRandom($nb_caractere = 12)
{
$mot_de_passe = "";
$chaine = "abcdefghjkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ023456789";
$longeur_chaine = strlen($chaine);
for($i = 1; $i <= $nb_caractere; $i++)
{
$place_aleatoire = mt_rand(0,($longeur_chaine-1));
$mot_de_passe .= $chaine[$place_aleatoire];
}
return $mot_de_passe;
}
/**
* @Route("/activate-account", name="frontend_vacataire_activate_account", host="%vacataire_subdomain%", methods={"POST"})
*/
public function sendMailActivateAccount(MailerInterface $mailer)
{
$request = Request::createFromGlobals();
$email = $request->request->get('mail');
$em = $this->getDoctrine()->getManager();
$user = $em->getRepository(RecCandidat::class)->findUser($email);
$site_short_name = $this->container->get('parameter_bag')->get('site_short_name');
$signature_rh_recrutement = $this->container->get('parameter_bag')->get('signature_rh_recrutement');
if($user)
{
$mail_noreply = $this->container->get('parameter_bag')->get('mail_noreply');
$mail = (new TemplatedEmail())
->from($mail_noreply)
->to($user->getEmail())
->subject('['.$site_short_name.'] Votre création de compte pour le dépôt de votre dossier')
->htmlTemplate('Courriel/resend_mail_activate_account_vacataire.html.twig')
->context(['user' => $user,'serveur'=>$_SERVER['HTTP_HOST'],'signature_rh_recrutement'=>$signature_rh_recrutement]);
try{
$mailer->send($mail);
$error = false;
}catch(TransportExceptionInterface $e) {
$response = $e->getMessage();
$error = true;
}
$data = array("success"=>1,"message"=>"Un nouveau courriel d'activation vient d'être envoyé à l'adresse : ".$user->getEmail());
$response = new JsonResponse($data);
return $response;
}
else
{
$data = array("success"=>0,"message"=>"L'adresse de messagerie ne correspond à aucun compte.");
$response = new JsonResponse($data);
return $response;
}
}
/**
* @Route("/vacataire", name="frontend_vacataire_view", host="%vacataire_subdomain%", methods={"GET"})
*/
public function view()
{
$user = $this->get('security.token_storage')->getToken()->getUser();
$em = $this->getDoctrine()->getManager();
$formPwd = $this->createForm(RecCandidatPwdType::class);
$dossiers = $em->getRepository(RecDossierVacataire::class)->findByCandidat($user->getId());
$dossiersID = array();
$dossiersVac = array();
foreach ($dossiers as $d)
{
$dossiersID[]=$d->getVacation()->getId();
$dossiersVac[$d->getVacation()->getId()]=$d;
}
$vacations = $em->getRepository(RecVacation::class)->findBy(["archive"=>false],['title'=>'DESC']);
foreach ($vacations as $v)
{
if(in_array($v->getId(),$dossiersID))
$v->setDossier($dossiersVac[$v->getId()]);
}
return $this->render('Frontend/Vacataire/view.html.twig',array("vacations"=>$vacations,"dossiersID"=>$dossiersID,"formPwd"=>$formPwd->createView()));
}
/**
* @Route("/vacataire/create/{id}", name="frontend_vacation_create", host="%vacataire_subdomain%", methods={"GET"})
*/
public function create($id)
{
$user = $this->get('security.token_storage')->getToken()->getUser();
$em = $this->getDoctrine()->getManager();
$vacation = $em->getRepository(RecVacation::class)->find($id);
$dossier = $em->getRepository(RecDossierVacataire::class)->findByCandidat($user->getId(),$id);
if(!$dossier) {
$dossierNmoins1 = $em->getRepository(RecDossierVacataire::class)->findByCandidat($user->getId(),false,$vacation->getYear()-1);
$dossier = new RecDossierVacataire();
$dossier->setCandidat($user);
$dossier->setVacation($vacation);
$entity = $em->getRepository(RecVacationStatut::class);
$q = $entity
->createQueryBuilder('p')
->where('p.id = :id')
->setParameter('id', 1)
->getQuery();
$statut = $q->getOneOrNullResult();
if ($statut)
$dossier->setVacationStatut($statut);
$entity = $em->getRepository(RecVacationEtatDossier::class);
$q = $entity
->createQueryBuilder('p')
->where('p.id = :id')
->setParameter('id', 1)
->getQuery();
$etatDossier = $q->getOneOrNullResult();
if ($etatDossier)
$dossier->setVacationEtatDossier($etatDossier);
$entity = $em->getRepository(RecVacationStatutCP::class);
$q = $entity
->createQueryBuilder('p')
->where('p.id = :id')
->setParameter('id', 1)
->getQuery();
$statutCP = $q->getOneOrNullResult();
if ($statutCP)
$dossier->setVacationStatutCP($statutCP);
$entity = $em->getRepository(RecVacationStatutAC::class);
$q = $entity
->createQueryBuilder('p')
->where('p.id = :id')
->setParameter('id', 1)
->getQuery();
$statutAC = $q->getOneOrNullResult();
if ($statutAC)
$dossier->setVacationStatutAC($statutAC);
$user->addDossier($dossier);
$vacation->addDossier($dossier);
$em->persist($dossier);
$em->persist($user);
$em->persist($vacation);
$em->flush();
if($dossierNmoins1)
{
foreach($dossierNmoins1->getDocuments() as $document)
{
if($document->getTypeDocument()->getTransfer() and $document->getTypeDocument()->getTransferDuration()>=$document->getNbTransfer() and $document->getVisaAC() and $document->getValidateCP()) {
$dossier->setCommentaire($dossierNmoins1->getCommentaire());
$dossier->setTypeVacataire($dossierNmoins1->getTypeVacataire());
$newDocument = clone $document;
$filePath = $document->getAbsolutePath().'/'.$document->getHiddenName();
if(file_exists($filePath)) {
$newFilename = sha1(uniqid(mt_rand(), true));
$tmp = explode(".", $document->getHiddenName());
$extension = end($tmp);
$newHiddenname = "vac_" . $newFilename . '.' . $extension;
$newDocument->setHiddenName($newHiddenname);
$newDocument->setNbTransfer($document->getNbTransfer()+1);
$newFilePath = $document->getAbsolutePath() . '/' . $newHiddenname;
copy($filePath, $newFilePath);
}
$dossier->addDocument($newDocument);
$newDocument->setDossier($dossier);
$em->persist($newDocument);
}
}
$em->persist($dossier);
$em->flush();
}
$this->addLog($dossier, "success", "Création du dossier");
}
return $this->redirect($this->generateUrl('frontend_vacation_dossier',array("id"=>$dossier->getId())));
}
/**
* @Route("/vacataire/desactive-popup/{id}", name="frontend_vacation_dossier_desactive_popup", host="%vacataire_subdomain%", methods={"POST"})
*/
public function desactivePopup($id)
{
$em = $this->getDoctrine()->getManager();
$user = $this->get('security.token_storage')->getToken()->getUser();
$dossier = $em->getRepository(RecDossierVacataire::class)->find($id);
if($user->getId()==$dossier->getCandidat()->getId() && $dossier)
{
$dossier->setPopup(false);
$em->persist($dossier);
$em->flush();
}
return new JsonResponse();
}
/**
* @Route("/vacataire/dossier/{id}", name="frontend_vacation_dossier", host="%vacataire_subdomain%", methods={"GET"})
*/
public function dossier($id)
{
$user = $this->get('security.token_storage')->getToken()->getUser();
$em = $this->getDoctrine()->getManager();
$dossier = $em->getRepository(RecDossierVacataire::class)->find($id);
$candidat = $em->getRepository(RecCandidat::class)->findUser($user->getEmail());
if($dossier->getVacation()->isArchive())
return $this->redirect($this->generateUrl('frontend_vacataire_view'));
if($dossier->getCandidat()->getId()!=$candidat->getId())
return $this->redirect($this->generateUrl('frontend_vacataire_view'));
$typeDocuments = $em->getRepository(RecTypeDocumentVacataire::class)->findAll();
$typeVacataires = $em->getRepository(RecTypeVacataire::class)->findBy(array('private'=>false));
$servcomps = $em->getRepository(RecServiceComposanteVacation::class)->findAll();
$servcompsAffected = array();
foreach ($dossier->getServicesOrComposantes() as $s)
{
$servcompsAffected[]=$s->getId();
}
$typeDocAffected = array();
$typeDocNotAffected = array();
if($dossier->getTypeVacataire()) {
foreach ($dossier->getTypeVacataire()->getTypeDocuments() as $td)
$typeDocAffected[] = $td->getId();
foreach ($typeDocuments as $td) {
if (!in_array($td->getId(), $typeDocAffected))
$typeDocNotAffected[] = $td->getId();
}
}
return $this->render('Frontend/Vacataire/dossier.html.twig',array("dossier"=>$dossier, "servcomps"=>$servcomps,"servcompsAffected"=>$servcompsAffected,"typeDocuments"=>$typeDocuments,"typeVacataires"=>$typeVacataires, "typeDocNotAffected"=>$typeDocNotAffected));
}
/**
* @Route("/vacataire/dossier/{id}/upload/doc/{idDoc}", name="frontend_dossier_upload_doc", host="%vacataire_subdomain%", methods={"POST"})
*/
public function uploadDoc(MailerInterface $mailer, $id, $idDoc)
{
$request = Request::createFromGlobals();
$files = $request->files;
$user = $this->get('security.token_storage')->getToken()->getUser();
$em = $this->getDoctrine()->getManager();
$dossier = $em->getRepository(RecDossierVacataire::class)->find($id);
$typeDoc = $em->getRepository(RecTypeDocumentVacataire::class)->find($idDoc);
$extensions_authorized = array('pdf');
$mail_noreply = $this->container->get('parameter_bag')->get('mail_noreply');
if($user->getId()==$dossier->getCandidat()->getId()) {
$uploadedFile = $files->get("file");
$extension = $uploadedFile->guessExtension();
if (!in_array($extension, $extensions_authorized)) {
$response = new JsonResponse(array("error" => 1, "message" => "Type de fichier non autorisé ! <br> Format autorisé : pdf"));
return $response;
}
if($dossier->isPieceRefuse($idDoc) and trim($dossier->getGestMail())!="")
{
$mail = (new TemplatedEmail())
->from($mail_noreply)
->to($dossier->getGestMail())
->subject('Ajout d\'une nouvelle pièce au dossier')
->htmlTemplate('Courriel/send_new_piece_gest.html.twig')
->context(['dossier'=>$dossier,'serveur'=>$_SERVER['HTTP_HOST']]);
try{
$mailer->send($mail);
$error = false;
}catch(TransportExceptionInterface $e) {
$response = $e->getMessage();
$error = true;
}
}
if($dossier->isPieceRefuseByACOrCP($idDoc))
{
$destMailsAC=$this->container->get('parameter_bag')->get('mail_rh_agence_comptable');
$destMailsCP=$this->container->get('parameter_bag')->get('mail_rh_controle_paye');
$destMails = array_merge($destMailsAC, $destMailsCP);
$mail = (new TemplatedEmail())
->from($mail_noreply)
->to($destMails)
->subject('Ajout d\'une nouvelle pièce au dossier après refus')
->htmlTemplate('Courriel/send_new_piece_cpac.html.twig')
->context(['dossier'=>$dossier,'serveur'=>$_SERVER['HTTP_HOST']]);
try{
$mailer->send($mail);
$error = false;
}catch(TransportExceptionInterface $e) {
$response = $e->getMessage();
$error = true;
}
}
$name = $uploadedFile->getClientOriginalName();
$filename = sha1(uniqid(mt_rand(), true));
$hiddenname= "vac_".$filename.'.'.$extension;
$upload = new RecDocumentVacataire();
$file = $uploadedFile->move($upload->getAbsolutePath(), $hiddenname);
$dossier->addDocument($upload);
$upload->setDossier($dossier);
$upload->setTypeDocument($typeDoc);
$upload->setName($name);
$upload->setHiddenName($hiddenname);
$upload->setValidate(false);
$em->persist($dossier);
$em->persist($upload);
$em->flush();
$this->addLog($dossier,"info"," Pièce ajouté : ".$upload->getName());
return new JsonResponse(array("id"=>$upload->getId(),"name"=>$name." (déposé le ".$upload->getDateInit()->format("d-m-Y à H:i").")",'error'=>0));
}
else
return new JsonResponse(array('error'=>'user'));
}
/**
* @Route("/vacataire/dossier/download/doc/{id}", name="frontend_dossier_download_doc", host="%vacataire_subdomain%", methods={"GET"})
*/
public function downloadDoc($id)
{
$em = $this->getDoctrine()->getManager();
$document = $em->getRepository(RecDocumentVacataire::class)->find($id);
$user = $this->get('security.token_storage')->getToken()->getUser();
$dossier = $document->getDossier();
if($document and $dossier && $user->getId()==$dossier->getCandidat()->getId())
return $this->file($document->getAbsolutePath().'/'.$document->getHiddenName(), $document->getName(), ResponseHeaderBag::DISPOSITION_INLINE);
else
return $this->redirectToRoute('frontend_candidat');
}
/**
* @Route("/vacataire/dossier/download/contrat/{id}", name="frontend_dossier_download_contrat", host="%vacataire_subdomain%", methods={"GET"})
*/
public function downloadContrat($id)
{
$em = $this->getDoctrine()->getManager();
$document = $em->getRepository(RecContratVacataire::class)->find($id);
$user = $this->get('security.token_storage')->getToken()->getUser();
$dossier = $document->getDossier();
if($document && $dossier && $user->getId()==$dossier->getCandidat()->getId())
return $this->file($document->getAbsolutePath().'/'.$document->getHiddenName(), $document->getName(), ResponseHeaderBag::DISPOSITION_INLINE);
else
return $this->redirectToRoute('frontend_candidat');
}
/**
* @Route("/vacataire/dossier/download/etat_liquid/{id}", name="frontend_dossier_download_etat_liquid_doc", host="%vacataire_subdomain%", methods={"GET"})
*/
public function downloadEtatLiquidationDoc($id)
{
$em = $this->getDoctrine()->getManager();
$document = $em->getRepository(RecEtatLiquidationDocVacataire::class)->find($id);
$user = $this->get('security.token_storage')->getToken()->getUser();
$dossier = $document->getEtatLiquidation()->getDossier();
if($document && $dossier && $user->getId()==$dossier->getCandidat()->getId())
return $this->file($document->getAbsolutePath().'/'.$document->getHiddenName(), $document->getName(), ResponseHeaderBag::DISPOSITION_INLINE);
else
return $this->redirectToRoute('frontend_candidat');
}
/**
* @Route("/vacataire/dossier/{id}/upload/contrat", name="frontend_dossier_upload_contrat", host="%vacataire_subdomain%", methods={"POST"})
*/
public function uploadContrat(MailerInterface $mailer, $id)
{
$request = Request::createFromGlobals();
$files = $request->files;
$user = $this->get('security.token_storage')->getToken()->getUser();
$em = $this->getDoctrine()->getManager();
$dossier = $em->getRepository(RecDossierVacataire::class)->find($id);
$mail_noreply = $this->container->get('parameter_bag')->get('mail_noreply');
$mail_rh_vacataire = $this->container->get('parameter_bag')->get('mail_rh_vacataire');
$initStatutContrat = $em->getRepository(RecVacationStatutContrat::class)->find(4);
$extensions_authorized = array('pdf');
$result=array();
if($user->getId()==$dossier->getCandidat()->getId()) {
$uploadedFile = $files->get("file");
$extension = $uploadedFile->guessExtension();
if (!in_array($extension, $extensions_authorized)) {
$response = new JsonResponse(array("error" => 1, "message" => "Type de fichier non autorisé ! <br> Format autorisé : pdf"));
return $response;
}
$name = $uploadedFile->getClientOriginalName();
$filename = sha1(uniqid(mt_rand(), true));
$hiddenname= "vac_".$filename.'.'.$extension;
$upload = new RecContratVacataire();
$file = $uploadedFile->move($upload->getAbsolutePath(), $hiddenname);
$dossier->addContrat($upload);
$upload->setDossier($dossier);
$upload->setStatutContrat($initStatutContrat);
$upload->setName($name);
$upload->setHiddenName($hiddenname);
$upload->setPublic(true);
$em->persist($dossier);
$em->persist($upload);
$em->flush();
foreach ($dossier->getServicesOrComposantes() as $servComp) {
$mail = (new TemplatedEmail())
->from($mail_noreply)
->to($mail_rh_vacataire)
->cc(...explode(";", $servComp->getMails()))
->subject('Nouveau contrat signé')
->htmlTemplate('Courriel/mail_contrat_cand.html.twig')
->context(['dossier' => $dossier, 'serveur' => $_SERVER['HTTP_HOST']]);
try {
$mailer->send($mail);
$error = false;
} catch (TransportExceptionInterface $e) {
$response = $e->getMessage();
$error = true;
}
}
$this->addLog($dossier,"success"," Contrat ajouté : ".$upload->getName());
$result[] = array("id"=>$upload->getId(),"name"=>$name." (déposé le ".$upload->getDateInit()->format("d-m-Y à H:i").")",'error'=>0);
}
$response = new JsonResponse($result);
return $response;
}
/**
* @Route("/vacataire/dossier/{id}/upload/etat_liquid", name="frontend_dossier_upload_etat_liquid_doc", host="%vacataire_subdomain%", methods={"POST"})
*/
public function uploadEtatLiquidationDoc(MailerInterface $mailer, $id)
{
$request = Request::createFromGlobals();
$files = $request->files;
$user = $this->get('security.token_storage')->getToken()->getUser();
$em = $this->getDoctrine()->getManager();
$etatLiquid = $em->getRepository(RecEtatLiquidationVacataire::class)->find($id);
$initStatutEtatLiquidation = $em->getRepository(RecVacationStatutEtatLiquidation::class)->find(4);
$mail_noreply = $this->container->get('parameter_bag')->get('mail_noreply');
$extensions_authorized = array('pdf');
$result=array();
if($user->getId()==$etatLiquid->getDossier()->getCandidat()->getId()) {
$uploadedFile = $files->get("file");
$extension = $uploadedFile->guessExtension();
if (!in_array($extension, $extensions_authorized)) {
$response = new JsonResponse(array("error" => 1, "message" => "Type de fichier non autorisé ! <br> Format autorisé : pdf"));
return $response;
}
$name = $uploadedFile->getClientOriginalName();
$filename = sha1(uniqid(mt_rand(), true));
$hiddenname= "vac_".$filename.'.'.$extension;
$upload = new RecEtatLiquidationDocVacataire();
$file = $uploadedFile->move($upload->getAbsolutePath(), $hiddenname);
$etatLiquid->addDocument($upload);
$upload->setEtatLiquidation($etatLiquid);
$upload->setStatutEtatLiquidation($initStatutEtatLiquidation);
$upload->setName($name);
$upload->setHiddenName($hiddenname);
$upload->setPublic(true);
$em->persist($etatLiquid);
$em->persist($upload);
$em->flush();
$mails = explode(";", $etatLiquid->getServComp()->getMails());
$mail = (new TemplatedEmail())
->from($mail_noreply);
foreach ($mails as $d)
$mail->addTo($d);
$mail->subject('Nouvel Etat de liquidation signé')
->htmlTemplate('Courriel/mail_etat_liquidation_cand.html.twig')
->context(['dossier' =>$etatLiquid->getDossier(),'mailGest'=>$etatLiquid->getServComp()->getMails(),'serveur'=>$_SERVER['HTTP_HOST']]);
try{
$mailer->send($mail);
$error = false;
}catch(TransportExceptionInterface $e) {
$response = $e->getMessage();
$error = true;
}
$this->addLog($etatLiquid->getDossier(),"success"," Etat de liquidation ajouté : ".$upload->getName());
$result[] = array("id"=>$upload->getId(),"name"=>$name." (déposé le ".$upload->getDateInit()->format("d-m-Y à H:i").")",'error'=>0,'mailGest'=>$etatLiquid->getServComp()->getMails());
}
$response = new JsonResponse($result);
return $response;
}
/**
* @Route("/vacataire/dossier/remove-contrat/{id}", name="frontend_dossier_remove_contrat", host="%vacataire_subdomain%", methods={"POST"})
*/
public function removeContrat($id)
{
$em = $this->getDoctrine()->getManager();
$contrat = $em->getRepository(RecContratVacataire::class)->find($id);
if (!$contrat) {
throw $this->createNotFoundException('Unable to find Client entity.');
}
$user = $this->get('security.token_storage')->getToken()->getUser();
$dossier = $contrat->getDossier();
if($user->getId()==$dossier->getCandidat()->getId() and !$contrat->getAdmin() and $contrat->getStatutContrat()->getPublic())
{
$contrat->removeFile();
$em->remove($contrat);
$em->flush();
$this->addLog($dossier,"alert"," Contrat supprimée : ".$contrat->getName());
}
$response = new JsonResponse(array('error'=>0));
return $response;
}
/**
* @Route("/vacataire/dossier/remove-etat-liquid/{id}", name="frontend_dossier_remove_etat_liquid_doc", host="%vacataire_subdomain%", methods={"POST"})
*/
public function removeEtatLiquidationDoc($id)
{
$em = $this->getDoctrine()->getManager();
$etatLiquidDoc = $em->getRepository(RecEtatLiquidationDocVacataire::class)->find($id);
if (!$etatLiquidDoc) {
throw $this->createNotFoundException('Unable to find Client entity.');
}
$user = $this->get('security.token_storage')->getToken()->getUser();
$dossier = $etatLiquidDoc->getEtatLiquidation()->getDossier();
if($user->getId()==$dossier->getCandidat()->getId() and $etatLiquidDoc->getStatuEtatLiquidation()->getPublic())
{
$etatLiquidDoc->removeFile();
$em->remove($etatLiquidDoc);
$em->flush();
$this->addLog($dossier,"alert"," Etat liquidation (document) supprimée : ".$etatLiquidDoc->getName());
}
$response = new JsonResponse(array('error'=>0));
return $response;
}
/**
* @Route("/vacataire/dossier/remove-doc/{id}", name="frontend_dossier_remove_doc", host="%vacataire_subdomain%", methods={"POST"})
*/
public function removeDoc($id)
{
$em = $this->getDoctrine()->getManager();
$document = $em->getRepository(RecDocumentVacataire::class)->find($id);
if (!$document) {
throw $this->createNotFoundException('Unable to find Client entity.');
}
$user = $this->get('security.token_storage')->getToken()->getUser();
$dossier = $document->getDossier();
$this->addLog($dossier,"alert"," Pièce supprimée : ".$document->getName());
if($dossier && !$dossier->getValidate())
{
if($user->getId()==$dossier->getCandidat()->getId())
{
$document->removeFile();
$em->remove($document);
$em->flush();
}
}
$response = new JsonResponse(array('error'=>0));
return $response;
}
/**
* @Route("/vacataire/dossier/{id}/add-affectation", name="frontend_dossier_add_affectation", host="%vacataire_subdomain%", methods={"POST"})
*/
public function addAffectation(MailerInterface $mailer, $id)
{
$user = $this->get('security.token_storage')->getToken()->getUser();
$em = $this->getDoctrine()->getManager();
$dossier = $em->getRepository(RecDossierVacataire::class)->find($id);
$request = Request::createFromGlobals();
$selected = $request->request->get('selected');
$servComps = "";
$servCompsAffected = array();
$mail_noreply = $this->container->get('parameter_bag')->get('mail_noreply');
foreach($dossier->getServicesOrComposantes() as $s)
{
$servCompsAffected[$s->getId()]=$s;
}
if($user->getId()==$dossier->getCandidat()->getId())
{
$dossier->cleanServicesOrComposantes();
if(is_array($selected)) {
foreach ($selected as $s) {
$servComp = $em->getRepository(RecServiceComposanteVacation::class)->find($s);
$dossier->addServicesOrComposante($servComp);
if(!isset($servCompsAffected[$servComp->getId()]))
{
$mail = (new TemplatedEmail())
->from($mail_noreply)
->to(...explode(";",$servComp->getMails()))
->subject('Affecation dossier vacataire')
->htmlTemplate('Courriel/send_affectation_gest.html.twig')
->context(['dossier'=>$dossier,'serveur'=>$_SERVER['HTTP_HOST']]);
try{
$mailer->send($mail);
$error = false;
}catch(TransportExceptionInterface $e) {
$response = $e->getMessage();
$error = true;
}
}
$servComps.=$servComp->getName().", ";
}
}
$em->persist($dossier);
$em->flush();
}
$this->addLog($dossier,"info","Choix de l'affectation : ".$servComps);
$response = new JsonResponse(array('error'=>0,'servCompsAffected'=>$servCompsAffected));
return $response;
}
/**
* @Route("/vacataire/dossier/{id}/set/statut/{idType}", name="frontend_vacataire_set_statut", host="%vacataire_subdomain%", methods={"POST"})
*/
public function setStatut($id,$idType)
{
$user = $this->get('security.token_storage')->getToken()->getUser();
$em = $this->getDoctrine()->getManager();
$dossier = $em->getRepository(RecDossierVacataire::class)->find($id);
$type = $em->getRepository(RecTypeVacataire::class)->find($idType);
if($user->getId()==$dossier->getCandidat()->getId())
{
$dossier->setTypeVacataire($type);
$em->persist($dossier);
$em->flush();
}
$typeDocs=array();
foreach($type->getTypeDocuments() as $td)
{
$typeDocs[] = $td->getId();
}
$this->addLog($dossier,"info","Choix du statut : ".$type->getName());
$response = new JsonResponse(array('error'=>0,'typeDocs'=>$typeDocs));
return $response;
}
/**
* @Route("/vacataire/dossier/{id}/request_in/{status}", name="frontend_dossier_request_in", host="%vacataire_subdomain%", methods={"POST"})
*/
public function requestIN($id,$status)
{
$em = $this->getDoctrine()->getManager();
$user = $this->get('security.token_storage')->getToken()->getUser();
$dossier = $em->getRepository(RecDossierVacataire::class)->find($id);
if($user->getId()==$dossier->getCandidat()->getId()) {
$dossier->setRequestIN($status);
$em->persist($dossier);
$em->flush();
}
$response = new JsonResponse(array('status'=>$status));
return $response;
}
/**
* @Route("/vacataire/validate/{id}", name="frontend_dossier_validate", host="%vacataire_subdomain%", methods={"POST"})
*/
public function validate(MailerInterface $mailer, $id)
{
$em = $this->getDoctrine()->getManager();
$user = $this->get('security.token_storage')->getToken()->getUser();
$dossier = $em->getRepository(RecDossierVacataire::class)->find($id);
$mail_noreply = $this->container->get('parameter_bag')->get('mail_noreply');
if($user->getId()==$dossier->getCandidat()->getId())
{
$now = new \DateTime('now');
if($now>=$dossier->getVacation()->getOpenDate() && $now<=$dossier->getVacation()->getCloseDate())
{
$dossier->setValidate(true);
$dossier->setDateValidate(new \DateTime('now'));
$em->persist($dossier);
$em->flush();
$this->addLog($dossier,"success","Dossier validé");
foreach ($dossier->getServicesOrComposantes() as $servComp)
{
$mail = (new TemplatedEmail())
->from($mail_noreply)
->to(...explode(";",$servComp->getMails()))
->subject('Validation dossier vacataire')
->htmlTemplate('Courriel/send_validate_gest.html.twig')
->context(['dossier'=>$dossier,'serveur'=>$_SERVER['HTTP_HOST']]);
try{
$mailer->send($mail);
$error = false;
}catch(TransportExceptionInterface $e) {
$response = $e->getMessage();
$error = true;
}
}
}
}
$response = new JsonResponse(array('error'=>0));
return $response;
}
/**
* @Route("/vacataire/delete/{id}", name="frontend_vacation_delete", host="%vacataire_subdomain%", methods={"GET"})
*/
public function delete($id)
{
$em = $this->getDoctrine()->getManager();
$candidature = $em->getRepository(RecDossierVacataire::class)->find($id);
if (!$candidature) {
throw $this->createNotFoundException('Unable to find candidature entity.');
}
$user = $this->get('security.token_storage')->getToken()->getUser();
if($candidature)
{
if($user->getId()==$candidature->getCandidat()->getId())
{
foreach($candidature->getDocuments() as $document)
{
$document->removeFile();
$em->remove($document);
}
$em->flush();
$em->remove($candidature);
$em->flush();
}
}
return $this->redirect($this->generateUrl('frontend_vacataire_view'));
}
protected function addLog(\App\Entity\RecDossierVacataire $dossier, $status, $description)
{
$user = $this->get('security.token_storage')->getToken()->getUser();
$em = $this->getDoctrine()->getManager();
$log = new RecLogDossierVacataire();
$log->setDossier($dossier);
$log->setUsername($user->getUserName());
$log->setStatus($status);
$log->setDescription($description);
$em->persist($log);
$em->flush();
return;
}
/**
* @Route("/vacataire/mod-pwd", name="frontend_vacataire_mod_pwd", host="%vacataire_subdomain%", methods={"POST"})
*/
public function modifyPwd(EncoderFactoryInterface $encoderFactory)
{
$request = Request::createFromGlobals();
$password = $request->request->get("password");
$confirm = $request->request->get("confirm");
$user = $this->get('security.token_storage')->getToken()->getUser();
$em = $this->getDoctrine()->getManager();
$encoder = $encoderFactory->getEncoder($user);
if($password==$confirm)
{
$password = $encoder->encodePassword($password, $user->getSalt());
$user->setPassword($password);
$em->persist($user);
$em->flush();
}
$data = array("success"=>1);
$response = new JsonResponse($data);
return $response;
}
/**
* @Route("/vacataire/send-msg", name="frontend_vacataire_send_msg", host="%vacataire_subdomain%", methods={"POST"})
*/
public function sendMsg(MailerInterface $mailer)
{
$request = Request::createFromGlobals();
$title = $request->request->get("title");
$message = $request->request->get("message");
$output=false;
$user = $this->get('security.token_storage')->getToken()->getUser();
$mail_noreply = $this->container->get('parameter_bag')->get('mail_noreply');
$mail_admin = $this->container->get('parameter_bag')->get('mail_admin');
$mail_rh_vacataire = $this->container->get('parameter_bag')->get('mail_rh_vacataire');
$mail = (new TemplatedEmail())
->from($mail_noreply)
->to($mail_rh_vacataire)
->cc($mail_admin)
->subject("Nouveau commentaire d'un utilisateur pour l'application de recrutement")
->htmlTemplate('Courriel/candidat_msg.html.twig')
->context(['user' => $user, 'title'=>$title, 'message'=>$message]);
try{
$mailer->send($mail);
$error = false;
}catch(TransportExceptionInterface $e) {
$response = $e->getMessage();
$error = true;
}
$data = array("success"=>$output);
$response = new JsonResponse($data);
return $response;
}
}