/** * Create a new application * @param string $programShortName * @param string $cycleName * @return null */ public function actionNew() { if ($this->_application->isByInvitationOnly()) { $this->addMessage('error', 'This application is by invitation only. You cannot create an account.'); $this->redirectApplyPath(''); } $form = new \Foundation\Form(); $form->setCSRFToken($this->getCSRFToken()); $form->setAction($this->applyPath('applicant/new')); $field = new \Foundation\Form\Field($form); $field->setLegend('Create New Application'); $form->addField($field); $element = $field->newElement('TextInput', 'first'); $element->setLabel('First Name'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $element = $field->newElement('TextInput', 'middle'); $element->setLabel('Middle Name'); $element = $field->newElement('TextInput', 'last'); $element->setLabel('Last Name'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $element = $field->newElement('TextInput', 'suffix'); $element->setLabel('Suffix'); $element->setFormat('Example: Jr., III'); $element = $field->newElement('TextInput', 'email'); $element->setLabel('Email Address'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $element->addValidator(new \Foundation\Form\Validator\EmailAddress($element)); $element->addFilter(new \Foundation\Form\Filter\Lowercase($element)); $element = $field->newElement('PasswordInput', 'password'); $element->setLabel('Password'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $element = $field->newElement('PasswordInput', 'confirm-password'); $element->setLabel('Confirm Password'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $element->addValidator(new \Foundation\Form\Validator\SameAs($element, 'password')); if ($this->_config->getRecaptchaPrivateKey()) { //setup recaptcha element keys \Foundation\Form\Element\Captcha::setKeys($this->_config->getRecaptchaPrivateKey(), $this->_config->getRecaptchaPublicKey()); $element = $field->newElement('Captcha', 'captcha'); } $form->newButton('submit', 'Create Account'); if ($input = $form->processInput($this->post)) { $duplicate = $this->_em->getRepository('Jazzee\\Entity\\Applicant')->findOneByEmailAndApplication($input->get('email'), $this->_application); if ($duplicate) { $this->addMessage('error', 'You have already started a ' . $this->_application->getProgram()->getName() . ' application. Please login to retrieve it.'); $this->redirectApplyPath('applicant/login'); } $applicant = new \Jazzee\Entity\Applicant(); $applicant->setApplication($this->_application); $applicant->setEmail($input->get('email')); $applicant->setPassword($input->get('password')); $applicant->setFirstName($input->get('first')); $applicant->setMiddleName($input->get('middle')); $applicant->setLastName($input->get('last')); $applicant->setSuffix($input->get('suffix')); $applicant->login(); $this->_em->persist($applicant); //flush here to get the ID $this->_em->flush(); $this->_store->expire(); $this->_store->touchAuthentication(); $this->_store->applicantID = $applicant->getId(); $this->_authLog->info('New account login for applicant ' . $applicant->getId() . ' from ' . $_SERVER['REMOTE_ADDR']); $this->addMessage('success', 'Welcome to the ' . $this->_application->getProgram()->getName() . ' application.'); $this->redirectApplyFirstPage(); } $this->setVar('form', $form); if ($this->_config->getLoginMessage()) { $this->addMessage('error', $this->_config->getLoginMessage()); } }
/** * Bulk create applicants from a csv file */ public function actionBulk() { $form = new \Foundation\Form(); $form->setCSRFToken($this->getCSRFToken()); $form->setAction($this->path('applicants/create/bulk')); $field = $form->newField(); $field->setLegend('Create Applicants From File'); $element = $field->newElement('FileInput', 'file'); $element->setLabel('File'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $element->addFilter(new \Foundation\Form\Filter\CSVArray($element)); $element = $field->newElement('TextInput', 'notificationSubject'); $element->setLabel('Subject for Notification Email'); $element->setValue('New Application Account'); $element = $field->newElement('Textarea', 'notificationMessage'); $element->setLabel('Notification Email Message'); $element->setFormat('Leave this blank if you do not want to notify the applicant of their new account'); $notificationMessagereplacements = array('_Applicant_Name_', '_Deadline_', '_Link_', '_Email_', '_Password_'); $element->setInstructions('You can use these tokens in the text, they will be replaced automatically: <br />' . implode('</br />', $notificationMessagereplacements)); $element->setValue($this->_defaultEmail); $element = $field->newElement('DateInput', 'deadlineExtension'); $element->setLabel('Deadline'); $element->setFormat('If you wish to extend this applicants deadline past the application deadline enter it here.'); if ($this->_application->getClose()) { $element->addValidator(new \Foundation\Form\Validator\DateAfter($element, $this->_application->getClose()->format('c'))); } $form->newButton('submit', 'Upload File and create applicants'); if ($input = $form->processInput($this->post)) { $newApplicants = $input->get('file'); $first = $newApplicants[0]; $requiredHeaders = array('External ID', 'First Name', 'Middle Name', 'Last Name', 'Suffix', 'Email Address', 'Password'); $error = false; foreach ($requiredHeaders as $value) { if (!in_array($value, $first)) { $form->getElementByName('file')->addMessage("The uploaded file must contain a column '{$value}'"); $error = true; } } if (!$error) { $headers = array_shift($newApplicants); $byKey = array(); foreach ($newApplicants as $newApplicant) { $arr = array(); foreach ($headers as $key => $value) { $arr[$value] = $newApplicant[$key]; } $byKey[] = $arr; } $newApplicants = $byKey; $results = array(); foreach ($newApplicants as $newApplicant) { $result = array('messages' => array(), 'applicant' => null, 'plainTextPassword' => ''); $duplicate = $this->_em->getRepository('Jazzee\\Entity\\Applicant')->findOneByEmailAndApplication($newApplicant['Email Address'], $this->_application); if ($duplicate) { $result['status'] = 'duplicate'; $result['messages'][] = 'An applicant with that email address already exists.'; $result['applicant'] = $duplicate; } else { if (!empty($newApplicant['External ID']) and !$this->_application->validateExternalId($newApplicant['External ID'])) { $result['status'] = 'badExternalId'; $result['messages'][] = $newApplicant['External ID'] . ' is not a valid external ID for this program'; $result['applicantName'] = "{$newApplicant['First Name']} {$newApplicant['Last Name']}"; $result['applicantEmail'] = $newApplicant['Email Address']; } else { $result['status'] = 'success'; $applicant = new \Jazzee\Entity\Applicant(); $applicant->setApplication($this->_application); $applicant->setEmail($newApplicant['Email Address']); if ($newApplicant['Password']) { $applicant->setPassword($newApplicant['Password']); $plainTextPassword = $newApplicant['Password']; } else { $plainTextPassword = $applicant->generatePassword(); } $applicant->setFirstName($newApplicant['First Name']); $applicant->setMiddleName($newApplicant['Middle Name']); $applicant->setLastName($newApplicant['Last Name']); $applicant->setSuffix($newApplicant['Suffix']); $applicant->setExternalId($newApplicant['External ID']); if ($input->get('deadlineExtension')) { $applicant->setDeadlineExtension($input->get('deadlineExtension')); } $this->_em->persist($applicant); $result['applicant'] = $applicant; $result['plainTextPassword'] = $plainTextPassword; $result['messages'][] = 'Applicant Created Successfully'; if ($input->get('notificationMessage')) { $replace = array($applicant->getFullName(), $applicant->getDeadline() ? $applicant->getDeadline()->format('l F jS Y g:ia') : '', $this->absoluteApplyPath("apply/{$this->_application->getProgram()->getShortName()}/{$this->_application->getCycle()->getName()}/applicant/login"), $applicant->getEmail(), $plainTextPassword); $body = str_ireplace($notificationMessagereplacements, $replace, $input->get('notificationMessage')); $subject = $input->get('notificationSubject') ? $input->get('notificationSubject') : 'New Application Account'; $email = $this->newMailMessage(); $email->AddCustomHeader('X-Jazzee-Applicant-ID:' . $applicant->getId()); $email->AddAddress($applicant->getEmail(), $applicant->getFullName()); $email->setFrom($this->_application->getContactEmail(), $this->_application->getContactName()); $email->Subject = $subject; $email->Body = $body; $email->Send(); $thread = new \Jazzee\Entity\Thread(); $thread->setSubject($subject); $thread->setApplicant($applicant); $message = new \Jazzee\Entity\Message(); $message->setSender(\Jazzee\Entity\Message::PROGRAM); $message->setText(nl2br($body)); $message->read(); $thread->addMessage($message); $this->_em->persist($thread); $this->_em->persist($message); $result['messages'][] = 'New account email sent'; } } } $results[] = $result; } $this->setVar('results', $results); $this->_em->flush(); } } $this->setVar('form', $form); }
/** * Preview a page * * We use a fake page to construct a preview */ public function actionPreviewPage() { $data = json_decode($this->post['data']); $page = new \Jazzee\Entity\Page(); $this->genericPage($page, $data); $this->layout = 'blank'; $applicant = new \Jazzee\Entity\Applicant(); $applicant->setFirstName('John'); $applicant->setLastName('Smith'); $applicant->setMiddleName('T'); $applicant->setSuffix('Jr.'); $applicant->setEmail('*****@*****.**'); $application = is_null($this->_application) ? new \Jazzee\Entity\Application() : $this->_application; $applicant->setApplication($application); $applicationPage = new \Jazzee\Entity\ApplicationPage(); $applicationPage->setPage($page); $applicationPage->setApplication($application); $applicationPage->getJazzeePage()->setController($this); $applicationPage->getJazzeePage()->setApplicant($applicant); $this->setVar('page', $applicationPage); $this->setVar('applicant', $applicant); }