public function getLogoAction() { $util = new Util($this->container, $this->getDoctrine()); $committee_logourl = $util->getConfiguration("committee.logourl"); if (!empty($committee_logourl)) { return new Response($committee_logourl); } return new Response(); }
/** * @Route("/public/contact", name="crud_contact_list") * @Template() */ public function listContactAction() { $output = array(); $request = $this->getRequest(); $session = $request->getSession(); $translator = $this->get('translator'); $em = $this->getDoctrine()->getManager(); $util = new Util($this->container, $this->getDoctrine()); $user = $this->get('security.token_storage')->getToken()->getUser(); $output['committee_prefix'] = $util->getConfiguration('committee.prefix'); $output['committee_name'] = $util->getConfiguration('committee.name'); $output['committee_email'] = $util->getConfiguration('committee.email'); $output['committee_address'] = $util->getConfiguration('committee.address'); $output['committee_phones'] = $util->getConfiguration('committee.phones'); // checking if was a post request if ($this->getRequest()->isMethod('POST')) { // getting post data $post_data = $request->request->all(); // checking required files foreach (array('name', 'email', 'subject', 'message') as $field) { if (!isset($post_data[$field]) or empty($post_data[$field])) { $session->getFlashBag()->add('error', $translator->trans("Field '%field%' is required.", array("%field%" => $field))); return $output; } } $message = \Swift_Message::newInstance()->setSubject("[proethos2] " . $translator->trans("Message from plataform."))->setFrom($output['committee_email'])->setTo($output['committee_email'])->setBody($translator->trans("Hello! A message was sent to proethos2 administrator from plataform.") . "<br>" . "<br><b>User</b>: " . $post_data['name'] . " (" . $post_data['email'] . ")" . "<br><b>Subject</b>: " . $post_data['subject'] . "<br><b>Message</b>:<br>" . nl2br($post_data['message']), 'text/html'); $send = $this->get('mailer')->send($message); $session->getFlashBag()->add('success', $translator->trans("Message sent to administrators.")); return $this->redirectToRoute('crud_contact_list', array(), 301); } return $output; }
/** * @Route("/protocol/{protocol_id}/monitoring/{monitoring_action_id}", name="protocol_new_monitoring_that_not_amendment") * @Template() */ public function monitoringCreateThatNotAmendmentAction($protocol_id, $monitoring_action_id) { $output = array(); $request = $this->getRequest(); $session = $request->getSession(); $translator = $this->get('translator'); $em = $this->getDoctrine()->getManager(); $user = $this->get('security.token_storage')->getToken()->getUser(); $util = new Util($this->container, $this->getDoctrine()); $protocol_repository = $em->getRepository('Proethos2ModelBundle:Protocol'); $monitoring_action_repository = $em->getRepository('Proethos2ModelBundle:MonitoringAction'); $upload_type_repository = $em->getRepository('Proethos2ModelBundle:UploadType'); $submission_upload_repository = $em->getRepository('Proethos2ModelBundle:SubmissionUpload'); $user_repository = $em->getRepository('Proethos2ModelBundle:User'); // getting the current submission $protocol = $protocol_repository->find($protocol_id); $output['protocol'] = $protocol; if (!$protocol) { throw $this->createNotFoundException($translator->trans('No protocol found')); } if (!$protocol->getMainSubmission()->isOwner($user)) { throw $this->createNotFoundException($translator->trans('You don\'t have access to do this')); } $monitoring_action = $monitoring_action_repository->find($monitoring_action_id); $output['monitoring_action'] = $monitoring_action; $submission = $protocol->getMainSubmission(); $output['submission'] = $submission; $upload_types = $upload_type_repository->findByStatus(true); $output['upload_types'] = $upload_types; if (!$monitoring_action) { throw $this->createNotFoundException($translator->trans('Monitoring action does not exist')); } // checking if was a post request if ($this->getRequest()->isMethod('POST')) { // getting post data $post_data = $request->request->all(); $file = $request->files->get('new-atachment-file'); if (!empty($file)) { if (!isset($post_data['new-atachment-type']) or empty($post_data['new-atachment-type'])) { $session->getFlashBag()->add('error', $translator->trans("Field 'new-atachment-type' is required.")); return $output; } $upload_type = $upload_type_repository->find($post_data['new-atachment-type']); if (!$upload_type) { throw $this->createNotFoundException($translator->trans('No upload type found')); return $output; } $submission_upload = new SubmissionUpload(); $submission_upload->setSubmission($submission); $submission_upload->setUploadType($upload_type); $submission_upload->setUser($user); $submission_upload->setFile($file); $submission_upload->setSubmissionNumber($submission->getNumber()); $submission_upload->setIsMonitoringAction(true); $em = $this->getDoctrine()->getManager(); $em->persist($submission_upload); $em->flush(); $submission->addAttachment($submission_upload); $em = $this->getDoctrine()->getManager(); $em->persist($submission); $em->flush(); $session->getFlashBag()->add('success', $translator->trans("File uploaded with sucess.")); return $this->redirectToRoute('protocol_new_monitoring_that_not_amendment', array('protocol_id' => $protocol_id, 'monitoring_action_id' => $monitoring_action_id), 301); } if (isset($post_data['delete-attachment-id']) and !empty($post_data['delete-attachment-id'])) { $submission_upload = $submission_upload_repository->find($post_data['delete-attachment-id']); if ($submission_upload) { $em->remove($submission_upload); $em->flush(); $session->getFlashBag()->add('success', $translator->trans("File removed with sucess.")); return $output; } } // checking required files foreach (array('monitoring-action', 'justification') as $field) { if (!isset($post_data[$field]) or empty($post_data[$field])) { $session->getFlashBag()->add('error', $translator->trans("Field '%field%' is required.", array("%field%" => $field))); return $output; } } foreach ($protocol->getMainSubmission()->getAttachments() as $submission_upload) { $submission_upload->setIsMonitoringAction(false); $em->persist($submission_upload); $em->flush(); } $protocol->setMonitoringAction($monitoring_action); $em->persist($protocol); $em->flush(); // setting the Rejected status $protocol->setStatus("S"); $protocol->setUpdatedIn(new \DateTime()); // setting protocool history $message = $translator->trans("New amendment submited by"); $message .= ' "' . $user . '" '; $message .= $translator->trans("with this justification:"); $message .= ' "' . $post_data['justification'] . '"'; $protocol_history = new ProtocolHistory(); $protocol_history->setProtocol($protocol); $protocol_history->setMessage($message); $em->persist($protocol_history); $em->flush(); // sending email $baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath(); $url = $baseurl . $this->generateUrl('protocol_show_protocol', array("protocol_id" => $protocol->getId())); $recipients = array(); foreach ($user_repository->findAll() as $secretary) { if (in_array("secretary", $secretary->getRolesSlug())) { $recipients[] = $secretary; } } foreach ($recipients as $recipient) { $message = \Swift_Message::newInstance()->setSubject("[proethos2] " . $translator->trans("A new monitoring action has been submitted."))->setFrom($util->getConfiguration('committee.email'))->setTo($recipient->getEmail())->setBody($translator->trans("Hello!") . "<br>" . "<br>" . $translator->trans("A new monitoring action has been submitted. Access the link below for more details") . ":" . "<br>" . "<br>{$url}" . "<br>" . "<br>" . $translator->trans("Regards") . "," . "<br>" . $translator->trans("Proethos2 Team"), 'text/html'); $send = $this->get('mailer')->send($message); } $session->getFlashBag()->add('success', $translator->trans("Amendment submitted with success!")); return $this->redirectToRoute('crud_investigator_protocol_list', array(), 301); } return $output; }
/** * @Route("/public/account/new", name="security_new_user") * @Template() */ public function newUserAction() { $output = array(); $request = $this->getRequest(); $session = $request->getSession(); $translator = $this->get('translator'); $em = $this->getDoctrine()->getManager(); $util = new Util($this->container, $this->getDoctrine()); // getting post data $post_data = $request->request->all(); $user_repository = $em->getRepository('Proethos2ModelBundle:User'); $country_repository = $em->getRepository('Proethos2ModelBundle:Country'); $countries = $country_repository->findBy(array(), array('name' => 'asc')); $output['countries'] = $countries; $output['content'] = array(); $output['recaptcha_secret'] = $util->getConfiguration('recaptcha.secret'); // checking if was a post request if ($this->getRequest()->isMethod('POST')) { // getting post data $post_data = $request->request->all(); $output['content'] = $post_data; // checking required fields foreach (array('name', 'username', 'email', 'country', 'password', 'confirm-password') as $field) { if (!isset($post_data[$field]) or empty($post_data[$field])) { $session->getFlashBag()->add('error', $translator->trans("Field '%field%' is required.", array("%field%" => $field))); return $output; } } // only check captcha if not in dev $secret = $output['recaptcha_secret']; if (!empty($secret) and strpos($_SERVER['HTTP_HOST'], 'localhost') < 0) { // RECAPTCHA // params to send to recapctha api $data = array("secret" => $secret, "response" => $post_data['g-recaptcha-response'], "remoteip" => $_SERVER['REMOTE_ADDR']); // options from file_Get_contents $options = array('http' => array('header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => http_build_query($data))); // making the POST request to API $context = stream_context_create($options); $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify", false, $context); $response = json_decode($response); // if has problems, stop if (!$response->success) { $session->getFlashBag()->add('error', $translator->trans("Have an error with captcha. Please try again.")); return $output; } } if ($post_data['password'] != $post_data['confirm-password']) { $session->getFlashBag()->add('error', $translator->trans("Passwords don't match.")); return $output; } $country = $country_repository->find($post_data['country']); $user = new User(); $user->setCountry($country); $user->setName($post_data['name']); $user->setUsername($post_data['username']); $user->setEmail($post_data['email']); $user->setInstitution($post_data['institution']); $user->setFirstAccess(false); $user->setIsActive(false); $encoderFactory = $this->get('security.encoder_factory'); $encoder = $encoderFactory->getEncoder($user); $salt = $user->getSalt(); // this should be different for every user $password = $encoder->encodePassword($post_data['password'], $salt); $user->setPassword($password); $user->cleanHashcode(); $baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath(); // send email to the user $message = \Swift_Message::newInstance()->setSubject("[proethos2] " . $translator->trans("Welcome to the Proethos2 platform!"))->setFrom($util->getConfiguration('committee.email'))->setTo($post_data['email'])->setBody($translator->trans("Hello! You have been registered in the Proethos2 platform.") . "<br>" . "<br>" . $translator->trans("Please wait until your access has been validated. We will send you an email.") . "<br>" . "<br>" . $translator->trans("Regards") . "," . "<br>" . $translator->trans("Proethos2 Team"), 'text/html'); $send = $this->get('mailer')->send($message); // send email to the secreataries $secretaries_emails = array(); foreach ($user_repository->findAll() as $secretary) { if (in_array('secretary', $secretary->getRolesSlug())) { $secretaries_emails[] = $secretary->getEmail(); } } $message = \Swift_Message::newInstance()->setSubject("[proethos2] " . $translator->trans("New user on Proethos2 platform"))->setFrom($util->getConfiguration('committee.email'))->setTo($secretaries_emails)->setBody($translator->trans("Hello! There is a new user registered in the Proethos2 platform.") . "<br>" . "<br>" . $translator->trans("Please check and authorize this access.") . "<br>" . "<br>" . $baseurl . "<br>" . "<br>" . $translator->trans("Regards") . "," . "<br>" . $translator->trans("Proethos2 Team"), 'text/html'); $send = $this->get('mailer')->send($message); $em->persist($user); $em->flush(); $session->getFlashBag()->add('success', $translator->trans("User created with success. Wait for approval.")); return $this->redirectToRoute('home', array(), 301); } return $output; }
/** * @Route("/submission/new/{submission_id}/seventh", name="submission_new_seventh_step") * @Template() */ public function SeventhStepAction($submission_id) { $output = array(); $request = $this->getRequest(); $session = $request->getSession(); $translator = $this->get('translator'); $em = $this->getDoctrine()->getManager(); $user = $this->get('security.token_storage')->getToken()->getUser(); $util = new Util($this->container, $this->getDoctrine()); $submission_repository = $em->getRepository('Proethos2ModelBundle:Submission'); $upload_type_repository = $em->getRepository('Proethos2ModelBundle:UploadType'); $user_repository = $em->getRepository('Proethos2ModelBundle:User'); // getting the current submission $submission = $submission_repository->find($submission_id); $output['submission'] = $submission; if (!$submission or $submission->getIsSended()) { throw $this->createNotFoundException($translator->trans('No submission found')); } $allow_to_edit_submission = true; $user = $this->get('security.token_storage')->getToken()->getUser(); // if current user is not owner, check the team if ($user != $submission->getOwner()) { $allow_to_edit_submission = false; foreach ($submission->getTeam() as $team_member) { // if current user = some team member, than it allows to edit if ($user == $team_member) { $allow_to_edit_submission = true; } } } if (!$allow_to_edit_submission) { throw $this->createNotFoundException($translator->trans('No submission found')); } // Revisions $revisions = array(); $final_status = true; $text = $translator->trans('Team') . " (" . count($submission->getTeam()) + 1 . " " . $translator->trans('member(s)') . ")"; $item = array('text' => $text, 'status' => true); $revisions[] = $item; // $text = $translator->trans('Files Submited') . " (" . count($submission->getAttachments()) . " " . $translator->trans('files(s)') . ")"; // $item = array('text' => $text, 'status' => true); // if(count($submission->getAttachments()) == 0) { // $item = array('text' => $text, 'status' => false); // $final_status = false; // } // $revisions[] = $item; $text = $translator->trans('Abstract'); $item = array('text' => $text, 'status' => true); if (empty($submission->getAbstract())) { $item = array('text' => $text, 'status' => false); $final_status = false; } $revisions[] = $item; $text = $translator->trans('Keywords'); $item = array('text' => $text, 'status' => true); if (empty($submission->getKeywords())) { $item = array('text' => $text, 'status' => false); $final_status = false; } $revisions[] = $item; $text = $translator->trans('Introduction'); $item = array('text' => $text, 'status' => true); if (empty($submission->getIntroduction())) { $item = array('text' => $text, 'status' => false); $final_status = false; } $revisions[] = $item; $text = $translator->trans('Justification'); $item = array('text' => $text, 'status' => true); if (empty($submission->getJustification())) { $item = array('text' => $text, 'status' => false); $final_status = false; } $revisions[] = $item; $text = $translator->trans('Goals'); $item = array('text' => $text, 'status' => true); if (empty($submission->getGoals())) { $item = array('text' => $text, 'status' => false); $final_status = false; } $revisions[] = $item; $text = $translator->trans('Study Design'); $item = array('text' => $text, 'status' => true); if (empty($submission->getStudyDesign())) { $item = array('text' => $text, 'status' => false); $final_status = false; } $revisions[] = $item; $text = $translator->trans('Gender'); $item = array('text' => $text, 'status' => true); if (empty($submission->getGender())) { $item = array('text' => $text, 'status' => false); $final_status = false; } $revisions[] = $item; $text = $translator->trans('Minimum Age'); $item = array('text' => $text, 'status' => true); if (empty($submission->getMinimumAge())) { $item = array('text' => $text, 'status' => false); $final_status = false; } $revisions[] = $item; $text = $translator->trans('Maximum Age'); $item = array('text' => $text, 'status' => true); if (empty($submission->getMaximumAge())) { $item = array('text' => $text, 'status' => false); $final_status = false; } $revisions[] = $item; $text = $translator->trans('Inclusion Criteria'); $item = array('text' => $text, 'status' => true); if (empty($submission->getInclusionCriteria())) { $item = array('text' => $text, 'status' => false); $final_status = false; } $revisions[] = $item; $text = $translator->trans('Exclusion Criteria'); $item = array('text' => $text, 'status' => true); if (empty($submission->getExclusionCriteria())) { $item = array('text' => $text, 'status' => false); $final_status = false; } $revisions[] = $item; $text = $translator->trans('Inicial recruitment estimated date'); $item = array('text' => $text, 'status' => true); if (empty($submission->getRecruitmentInitDate())) { $item = array('text' => $text, 'status' => false); $final_status = false; } $revisions[] = $item; $text = $translator->trans('Interventions'); $item = array('text' => $text, 'status' => true); if (empty($submission->getInterventions())) { $item = array('text' => $text, 'status' => false); $final_status = false; } $revisions[] = $item; $text = $translator->trans('Primary Outcome'); $item = array('text' => $text, 'status' => true); if (empty($submission->getPrimaryOutcome())) { $item = array('text' => $text, 'status' => false); $final_status = false; } $revisions[] = $item; $text = $translator->trans('Funding Source'); $item = array('text' => $text, 'status' => true); if (empty($submission->getFundingSource())) { $item = array('text' => $text, 'status' => false); $final_status = false; } $revisions[] = $item; $text = $translator->trans('Primary Sponsor'); $item = array('text' => $text, 'status' => true); if (empty($submission->getPrimarySponsor())) { $item = array('text' => $text, 'status' => false); $final_status = false; } $revisions[] = $item; $text = $translator->trans('Bibliography'); $item = array('text' => $text, 'status' => true); if (empty($submission->getBibliography())) { $item = array('text' => $text, 'status' => false); $final_status = false; } $revisions[] = $item; $text = $translator->trans('Scientific Contact'); $item = array('text' => $text, 'status' => true); if (empty($submission->getSscientificContact())) { $item = array('text' => $text, 'status' => false); $final_status = false; } $revisions[] = $item; $output['revisions'] = $revisions; $output['final_status'] = $final_status; // checking if was a post request if ($this->getRequest()->isMethod('POST')) { // getting post data $post_data = $request->request->all(); if ($final_status) { if ($post_data['accept-terms'] == 'on') { // gerando um novo pdf try { $html = $this->renderView('Proethos2CoreBundle:NewSubmission:showPdf.html.twig', $output); $pdf = $this->get('knp_snappy.pdf'); // setting margins $pdf->getInternalGenerator()->setOption('margin-top', '50px'); $pdf->getInternalGenerator()->setOption('margin-bottom', '50px'); $pdf->getInternalGenerator()->setOption('margin-left', '20px'); $pdf->getInternalGenerator()->setOption('margin-right', '20px'); // adding pdf to tmp file $filepath = "/tmp/" . date("Y-m-d") . "-submission.pdf"; file_put_contents($filepath, $pdf->getOutputFromHtml($html)); $submission_number = count($submission->getProtocol()->getSubmission()); $upload_type = $upload_type_repository->findOneBy(array("slug" => "protocol")); // send tmp file to upload class and save $pdfFile = new SubmissionUpload(); $pdfFile->setSubmission($submission); $pdfFile->setSimpleFile($filepath); $pdfFile->setUploadType($upload_type); $pdfFile->setUser($user); $pdfFile->setSubmissionNumber($submission->getNumber()); $em->persist($pdfFile); $em->flush(); } catch (\RuntimeException $e) { $session->getFlashBag()->add('error', $translator->trans('Problems generating PDF. Please contact the administrator.')); return $output; } // updating protocol and setting status $protocol = $submission->getProtocol(); $protocol->setStatus("S"); $protocol->setDateInformed(new \DateTime()); $protocol->setUpdatedIn(new \DateTime()); $em->persist($protocol); $em->flush(); $submission->setIsSended(true); $em->persist($submission); $em->flush(); $protocol_history = new ProtocolHistory(); $protocol_history->setProtocol($protocol); $protocol_history->setMessage($translator->trans("Submission of protocol.")); $em->persist($protocol_history); $em->flush(); if ($protocol->getMonitoringAction()) { // sending email $baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath(); $url = $baseurl . $this->generateUrl('protocol_show_protocol', array("protocol_id" => $protocol->getId())); $recipients = array(); foreach ($user_repository->findAll() as $secretary) { if (in_array("secretary", $secretary->getRolesSlug())) { $recipients[] = $secretary; } } foreach ($recipients as $recipient) { $message = \Swift_Message::newInstance()->setSubject("[proethos2] " . $translator->trans("A new monitoring action has been submitted."))->setFrom($util->getConfiguration('committee.email'))->setTo($recipient->getEmail())->setBody($translator->trans("Hello!") . "<br>" . "<br>" . $translator->trans("A new monitoring action has been submitted. Access the link below for more details") . ":" . "<br>" . "<br>{$url}" . "<br>" . "<br>" . $translator->trans("Regards") . "," . "<br>" . $translator->trans("Proethos2 Team"), 'text/html'); $send = $this->get('mailer')->send($message); } $session->getFlashBag()->add('success', $translator->trans("Amendment submitted with success!")); } else { $session->getFlashBag()->add('success', $translator->trans("Protocol submitted with sucess!")); } return $this->redirectToRoute('protocol_show_protocol', array('protocol_id' => $protocol->getId()), 301); } else { $session->getFlashBag()->add('error', $translator->trans("You must accept the terms and conditions.")); } } else { $session->getFlashBag()->add('error', $translator->trans('You have pending reviews.')); } } return $output; }