/** * Create a new virtual file */ public function actionNew() { $form = new \Foundation\Form(); $form->setAction($this->path("manage/virtualfiles/new")); $form->setCSRFToken($this->getCSRFToken()); $field = $form->newField(); $field->setLegend('New Virtual File'); $element = $field->newElement('TextInput', 'name'); $element->setLabel('File Name'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $element->addFilter(new \Foundation\Form\Filter\UrlSafe($element)); $element->addFilter(new \Foundation\Form\Filter\Safe($element)); $element = $field->newElement('FileInput', 'contents'); $element->setLabel('File'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $element->addFilter(new \Foundation\Form\Filter\Blob($element)); $form->newButton('submit', 'Add File'); $this->setVar('form', $form); if ($input = $form->processInput($this->post)) { $file = new \Jazzee\Entity\VirtualFile(); $file->setName($input->get('name')); $file->setContents($input->get('contents')); $this->_em->persist($file); $this->addMessage('success', "New Virtual File Saved"); $this->redirectPath('manage/virtualfiles'); } }
/** * Create a new pagetype */ public function actionNew() { $form = new \Foundation\Form(); $form->setCSRFToken($this->getCSRFToken()); $form->setAction($this->path("manage/elementtypes/new")); $field = $form->newField(); $field->setLegend('New element type'); $element = $field->newElement('TextInput', 'name'); $element->setLabel('Name'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $element->addFilter(new \Foundation\Form\Filter\Safe($element)); $element = $field->newElement('TextInput', 'class'); $element->setLabel('Class'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $form->newButton('submit', 'Add Element'); $this->setVar('form', $form); if ($input = $form->processInput($this->post)) { //class_exists causes doctrine to try and load the class which fails so we look first if doctrine can load it and then //if that fails we use class exists with no auto_load so it just looks in existing includes if (\Doctrine\Common\ClassLoader::classExists(ltrim($input->get('class'), '\\')) or class_exists($input->get('class'), false)) { $elementType = new \Jazzee\Entity\ElementType(); $elementType->setName($input->get('name')); $elementType->setClass($input->get('class')); $this->addMessage('success', $input->get('name') . " saved."); $this->_em->persist($elementType); $this->redirectPath('manage/elementtypes'); } else { $this->addMessage('error', "That is not a valid class name. The class must eithier by loadable by a Doctrine::classLoader registered in the autoload stack or already be included."); } } }
/** * Remove a tag from all applicants and add a new tag in its place * @param $tagId */ public function actionEdit($tagId) { if ($tag = $this->_em->getRepository('Jazzee\\Entity\\Tag')->find($tagId)) { $applicants = $this->_em->getRepository('Jazzee\\Entity\\Applicant')->findTaggedByApplication($this->_application, $tag); $form = new \Foundation\Form(); $form->setCSRFToken($this->getCSRFToken()); $form->setAction($this->path("setup/tags/edit/{$tagId}")); $field = $form->newField(); $field->setLegend('Change "' . $tag->getTitle() . '" Tag for ' . count($applicants) . ' applicants'); $element = $field->newElement('TextInput', 'title'); $element->setLabel('New Tag'); $element->setValue($tag->getTitle()); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $applications = $this->_em->getRepository('\\Jazzee\\Entity\\Application')->findByProgram($this->_program); $form->newButton('submit', 'Change Tag'); if ($input = $form->processInput($this->post)) { $newTag = $this->_em->getRepository('\\Jazzee\\Entity\\Tag')->findOneBy(array('title' => $input->get('title'))); if (!$newTag) { $newTag = new \Jazzee\Entity\Tag(); $newTag->setTitle($input->get('title')); $this->_em->persist($newTag); } foreach ($applicants as $applicant) { $applicant->removeTag($tag); $applicant->addTag($newTag); $this->_em->persist($applicant); } $this->addMessage('success', 'Changed tag for ' . count($applicants) . ' applicants'); $this->redirectPath('setup/tags'); } $this->setVar('form', $form); } }
public function testProcessInput() { $form = new \Foundation\Form(); $this->assertFalse($form->processInput(array())); $form->setCSRFToken('testtoken'); $this->assertFalse($form->processInput(array('test' => null))); $form = new \Foundation\Form(); $element = $this->getMock('\\Foundation\\Form\\Element'); $element->expects($this->once())->method('processInput')->will($this->returnValue(false)); $field = $this->getMockBuilder('\\Foundation\\Form\\Field')->disableOriginalConstructor()->getMock(); $field->expects($this->once())->method('getElements')->will($this->returnValue(array('fakename' => $element))); $form->addField($field); $this->assertFalse($form->processInput(array('test' => null))); $form = new \Foundation\Form(); $element = $this->getMock('\\Foundation\\Form\\Element'); $element->expects($this->once())->method('processInput')->will($this->returnValue(true)); $field = $this->getMockBuilder('\\Foundation\\Form\\Field')->disableOriginalConstructor()->getMock(); $field->expects($this->once())->method('getElements')->will($this->returnValue(array('fakename' => $element))); $form->addField($field); $arr = array('test1' => 'test1' . uniqid(), 'test2' => 'test2' . uniqid()); $input = $form->processInput($arr); $this->assertInstanceOf('\\Foundation\\Form\\Input', $input); foreach ($arr as $key => $value) { $this->assertSame($value, $input->get($key)); } }
/** * View the current Setup or setup a new app */ public function actionIndex() { $form = new \Foundation\Form(); $form->setCSRFToken($this->getCSRFToken()); $form->setAction($this->path("setup/removeapplication")); $field = $form->newField(); $field->setLegend('Remove Application'); $element = $field->newElement('TextInput', 'confirm'); $element->setLabel('Type CONFIRM in the box to remove application'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $element->addValidator(new \Foundation\Form\Validator\SpecificString($element, 'CONFIRM')); if ($this->_application->getApplicants()->count() > 0) { $applicants = $this->_application->getApplicants(); $element = $field->newElement('CheckboxList', 'deleteApps'); $element->setLabel('The following applicants will be deleted as well. Confirm each one by checking the box.'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $element->addValidator(new \Foundation\Form\Validator\AllChecked($element)); foreach ($applicants as $applicant) { $element->newItem($applicant->getId(), $applicant->getFullName()); } } $form->newButton('submit', 'Remove Application'); $this->setVar('form', $form); if ($input = $form->processInput($this->post)) { $this->_em->remove($this->_application); unset($this->_store->AdminControllerGetNavigation); $this->addMessage('success', 'Application Removed.'); $this->redirectPath('setup/application'); } $this->loadView($this->controllerName . '/form'); }
/** * Prune Old scores not mathced to any applicant */ public function actionPrune() { $form = new \Foundation\Form(); $form->setCSRFToken($this->getCSRFToken()); $form->setAction($this->path('manage/scores/prune')); $field = $form->newField(); $field->setLegend('Remove Old Scores'); $element = $field->newElement('SelectList', 'type'); $element->setLabel('Score Type'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $element->newItem('etsgre', 'GRE Scores'); $element->newItem('etstoefl', 'TOEFL Scores'); $element = $field->newElement('ShortDateInput', 'olderthan'); $element->setLabel('Older Than'); $element->setValue('5 years ago'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $element->addValidator(new \Foundation\Form\Validator\DateBefore($element, 'last year')); $form->newButton('submit', 'Remove Scores'); $this->setVar('form', $form); if ($input = $form->processInput($this->post)) { switch ($input->get('type')) { case 'etsgre': $count = $this->_em->getRepository('Jazzee\\Entity\\GREScore')->pruneUnmatchedScores(new \DateTime($input->get('olderthan'))); $this->addMessage('success', "{$count} GRE scores deleted."); $this->redirectPath('manage/scores'); break; case 'etstoefl': $count = $this->_em->getRepository('Jazzee\\Entity\\TOEFLScore')->pruneUnmatchedScores(new \DateTime($input->get('olderthan'))); $this->addMessage('success', "{$count} TOEFL scores deleted."); $this->redirectPath('manage/scores'); break; } } }
/** * Create a new program */ public function actionNew() { $form = new \Foundation\Form(); $form->setCSRFToken($this->getCSRFToken()); $form->setAction($this->path("manage/programs/new")); $field = $form->newField(); $field->setLegend('New Program'); $element = $field->newElement('TextInput', 'name'); $element->setLabel('Program Name'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $element->addFilter(new \Foundation\Form\Filter\Safe($element)); $element = $field->newElement('TextInput', 'shortName'); $element->setLabel('Short Name'); $element->setInstructions('Forms the URL for accessing this program, must be unique'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $element->addFilter(new \Foundation\Form\Filter\UrlSafe($element)); $element->addFilter(new \Foundation\Form\Filter\Safe($element)); $form->newButton('submit', 'Save Changes'); $this->setVar('form', $form); if ($input = $form->processInput($this->post)) { $program = new \Jazzee\Entity\Program(); $program->setName($input->get('name')); $program->setShortName($input->get('shortName')); $this->addMessage('success', "New Program Saved"); $this->_em->persist($program); //if the user isn't in a program then make this one their default if (!$this->_program) { $this->_user->setDefaultProgram($program); $this->_em->persist($this->_user); } $this->redirectPath('manage/programs'); } }
/** * Create a new pagetype */ public function actionNew() { $form = new \Foundation\Form(); $form->setCSRFToken($this->getCSRFToken()); $form->setAction($this->path("manage/pagetypes/new")); $field = $form->newField(); $field->setLegend('New page type'); $element = $field->newElement('TextInput', 'name'); $element->setLabel('Name'); $element->addFilter(new \Foundation\Form\Filter\Safe($element)); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $element = $field->newElement('TextInput', 'class'); $element->setLabel('Class'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $form->newButton('submit', 'Add Page'); $this->setVar('form', $form); if ($input = $form->processInput($this->post)) { if (!class_exists($input->get('class'))) { $this->addMessage('error', "That is not a valid class name"); } else { $pageType = new \Jazzee\Entity\PageType(); $pageType->setName($input->get('name')); $pageType->setClass($input->get('class')); $this->addMessage('success', $input->get('name') . " added."); $this->_em->persist($pageType); $this->redirectPath('manage/pagetypes'); } } }
/** * The payment type and the amount are selected first * then we display the form for the payment type * @see StandardPage::makeForm() */ protected function makeForm() { $allowedTypes = explode(',', $this->_applicationPage->getPage()->getVar('allowedPaymentTypes')); $allowedTypesCount = count($allowedTypes); $amounts = $this->_applicationPage->getPage()->getVar('amounts'); if ($allowedTypesCount == 1 and $amounts == 1) { $paymentType = $this->_controller->getEntityManager()->getRepository('\\Jazzee\\Entity\\PaymentType')->findOneBy(array('id' => $allowedTypes[0], 'isExpired' => false)); $form = $paymentType->getJazzeePaymentType($this->_controller)->paymentForm($this->_applicant, $this->_applicationPage->getPage()->getVar('amount1')); $form->setCSRFToken($this->_controller->getCSRFToken()); $form->newHiddenElement('level', 2); $form->newHiddenElement('paymentType', $paymentType->getId()); return $form; } $form = new \Foundation\Form(); $form->setAction($this->_controller->getActionPath()); $form->setCSRFToken($this->_controller->getCSRFToken()); $field = $form->newField(); $field->setLegend($this->_applicationPage->getTitle()); $field->setInstructions($this->_applicationPage->getInstructions()); if ($allowedTypesCount == 1 and !$this->_controller instanceof \Jazzee\AdminController) { $paymentType = $this->_controller->getEntityManager()->getRepository('\\Jazzee\\Entity\\PaymentType')->findOneBy(array('id' => $allowedTypes[0], 'isExpired' => false)); $element = $field->newElement('Plaintext', 'paymentTypeName'); $element->setLabel('Payment Method'); $element->setValue($paymentType->getName()); $form->newHiddenElement('paymentType', $paymentType->getId()); } else { $element = $field->newElement('SelectList', 'paymentType'); $element->setLabel('Payment Method'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $paymentTypes = $this->_controller->getEntityManager()->getRepository('\\Jazzee\\Entity\\PaymentType')->findBy(array('isExpired' => false), array('name' => 'ASC')); foreach ($paymentTypes as $type) { if ($this->_controller instanceof \Jazzee\AdminController or in_array($type->getId(), $allowedTypes)) { $element->newItem($type->getId(), $type->getName()); } } } if ($amounts == 1) { $element = $field->newElement('Plaintext', 'amountText'); $element->setLabel('Type of payment'); $element->setValue($this->_applicationPage->getPage()->getVar('description1')); $form->newHiddenElement('amount', $this->_applicationPage->getPage()->getVar('amount1')); } else { $element = $field->newElement('RadioList', 'amount'); $element->setLabel('Type of payment'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); for ($i = 1; $i <= $amounts; $i++) { $element->newItem($this->_applicationPage->getPage()->getVar('amount' . $i), $this->_applicationPage->getPage()->getVar('description' . $i)); } $element->setValue($this->_applicationPage->getPage()->getVar('amount1')); } $form->newHiddenElement('level', 1); $form->newButton('submit', 'Select'); return $form; }
/** * Search GRE Scores */ public function actionIndex() { $form = new \Foundation\Form(); $form->setCSRFToken($this->getCSRFToken()); $form->setAction($this->path('scores/gre')); $field = $form->newField(); $field->setLegend('Search GRE Scores'); $element = $field->newElement('TextInput', 'firstName'); $element->setLabel('First Name'); $element = $field->newElement('TextInput', 'lastName'); $element->setLabel('Last Name'); $form->newButton('submit', 'Search'); $this->setVar('form', $form); if ($input = $form->processInput($this->post)) { $results = $this->_em->getRepository('\\Jazzee\\Entity\\GREScore')->findByName($input->get('firstName') . '%', $input->get('lastName') . '%'); $this->setVar('results', $results); } }
/** * Display index */ public function actionIndex() { $form = new \Foundation\Form(); $form->setCSRFToken($this->getCSRFToken()); $form->setAction($this->path('changeprogram')); $field = $form->newField(); $field->setLegend('Select Program'); $element = $field->newElement('SelectList', 'program'); $element->setLabel('Program'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $programs = $this->_em->getRepository('\\Jazzee\\Entity\\Program')->findBy(array('isExpired' => false), array('name' => 'ASC')); $userPrograms = $this->_user->getPrograms(); foreach ($programs as $program) { if ($this->checkIsAllowed($this->controllerName, 'anyProgram') or in_array($program->getId(), $userPrograms)) { $element->newItem($program->getId(), $program->getName()); } } if ($this->_program) { $element->setValue($this->_program->getId()); } //only ask if the user already has a default cycle if ($this->_user->getDefaultProgram()) { $element = $field->newElement('RadioList', 'default'); $element->setLabel('Set as your default'); $element->newItem(0, 'No'); $element->newItem(1, 'Yes'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); } $form->newButton('submit', 'Change Program'); if ($input = $form->processInput($this->post)) { $this->_program = $this->_em->getRepository('\\Jazzee\\Entity\\Program')->find($input->get('program')); //if they wish it, or if the user has no default cycle if (!$this->_user->getDefaultProgram() or $input->get('default')) { $this->_user->setDefaultProgram($this->_program); $this->_em->persist($this->_user); $this->addMessage('success', 'Default program changed to ' . $this->_program->getName()); } unset($this->_store->AdminControllerGetNavigation); $this->addMessage('success', 'Program changed to ' . $this->_program->getName()); $this->redirectPath('welcome'); } $this->setVar('form', $form); }
/** * Edit a user * @param integer $userID */ public function actionEdit($userID) { if ($user = $this->_em->getRepository('\\Jazzee\\Entity\\User')->find($userID)) { $form = new \Foundation\Form(); $form->setCSRFToken($this->getCSRFToken()); $form->setAction($this->path('setup/users/edit/' . $userID)); $field = $form->newField(); $field->setLegend('Roles for ' . $user->getFirstName() . ' ' . $user->getLastName()); $element = $field->newElement('CheckboxList', 'roles'); $element->setLabel('Program Roles'); foreach ($this->_em->getRepository('\\Jazzee\\Entity\\Role')->findBy(array('program' => $this->_program->getId())) as $role) { $element->newItem($role->getId(), $role->getName()); } $values = array(); foreach ($user->getRoles() as $role) { $values[] = $role->getId(); } $element->setValue($values); $form->newButton('submit', 'Save Changes'); $this->setVar('form', $form); if ($input = $form->processInput($this->post)) { //clear out all current program roles foreach ($user->getRoles() as $role) { if ($role->getProgram() == $this->_program) { $user->getRoles()->removeElement($role); } } $roles = $input->get('roles'); if (!empty($roles)) { foreach ($input->get('roles') as $roleID) { if ($role = $this->_em->getRepository('\\Jazzee\\Entity\\Role')->findOneBy(array('id' => $roleID, 'program' => $this->_program->getId()))) { $user->addRole($role); } } } $this->_em->persist($user); $this->addMessage('success', "Changes Saved Successfully"); $this->redirectPath('setup/users'); } } else { $this->addMessage('error', "Error: User #{$userID} does not exist."); } }
/** * Advanced Search Form */ public function actionAdvanced() { $form = new \Foundation\Form(); $form->setCSRFToken($this->getCSRFToken()); $form->setAction($this->path('applicants/search/advanced')); $field = $form->newField(); $field->setLegend('Advanced Search'); $element = $field->newElement('Textarea', 'query'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $element->addValidator(new \Foundation\Form\Validator\Json($element)); $element->setLabel('Query'); $form->newButton('submit', 'Search'); if ($input = $form->processInput($this->post)) { $obj = json_decode($input->get('query')); $applicants = $this->_em->getRepository('\\Jazzee\\Entity\\Applicant')->findApplicantsByQuery($obj, $this, $this->_application); $this->setVar('applicants', $applicants); } $this->setVar('form', $form); $this->loadView('applicants_search/index'); }
/** * Create a new virtual file */ public function actionNew() { $form = new \Foundation\Form(); $form->setAction($this->path("manage/answerstatus/new")); $form->setCSRFToken($this->getCSRFToken()); $field = $form->newField(); $field->setLegend('New Answer Status'); $element = $field->newElement('TextInput', 'name'); $element->setLabel('Name'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $element->addFilter(new \Foundation\Form\Filter\Safe($element)); $form->newButton('submit', 'Save'); $this->setVar('form', $form); if ($input = $form->processInput($this->post)) { $status = new \Jazzee\Entity\AnswerStatusType(); $status->setName($input->get('name')); $this->_em->persist($status); $this->addMessage('success', "New Answer Status Saved"); $this->redirectPath('manage/answerstatus'); } }
/** * Display index */ public function actionIndex() { $form = new \Foundation\Form(); $form->setAction($this->path('changecycle')); $form->setCSRFToken($this->getCSRFToken()); $field = $form->newField(); $field->setLegend('Select Cycle'); $element = $field->newElement('SelectList', 'cycle'); $element->setLabel('Cycle'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $cycles = $this->_em->getRepository('\\Jazzee\\Entity\\Cycle')->findAll(); foreach ($cycles as $cycle) { $element->newItem($cycle->getId(), $cycle->getName()); } if ($this->_cycle) { $element->setValue($this->_cycle->getId()); } //only ask if the user already has a default cycle if ($this->_user->getDefaultCycle()) { $element = $field->newElement('RadioList', 'default'); $element->setLabel('Set as your default'); $element->newItem(0, 'No'); $element->newItem(1, 'Yes'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); } $form->newButton('submit', 'Change Cycle'); if ($input = $form->processInput($this->post)) { $this->_cycle = $this->_em->getRepository('\\Jazzee\\Entity\\Cycle')->find($input->get('cycle')); //if they wish it, or if the user has no default cycle if (!$this->_user->getDefaultCycle() or $input->get('default')) { $this->_user->setDefaultCycle($this->_cycle); $this->_em->persist($this->_user); $this->addMessage('success', 'Default cycle changed to ' . $this->_cycle->getName()); } unset($this->_store->AdminControllerGetNavigation); $this->addMessage('success', 'Cycle changed to ' . $this->_cycle->getName()); $this->redirectPath('welcome'); } $this->setVar('form', $form); }
/** * Test Email Communication */ public function actionTest() { $form = new \Foundation\Form(); $form->setCSRFToken($this->getCSRFToken()); $form->setAction($this->path('manage/mail/test')); $field = $form->newField(); $field->setLegend('Send Test Email'); $element = $field->newElement('TextInput', 'address'); $element->setLabel('To'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $element->addValidator(new \Foundation\Form\Validator\EmailAddress($element)); $form->newButton('submit', 'Send Test'); $this->setVar('form', $form); if ($input = $form->processInput($this->post)) { $message = $this->newMailMessage(); $message->AddAddress($input->get('address')); $message->Subject = 'Test Email'; $message->Body = 'This is a test email from the application system.'; $message->Send(); $this->addMessage('success', "Test Email Sent"); $this->redirectPath('manage/mail'); } }
/** * Create a new preview */ public function actionNew() { $form = new \Foundation\Form(); $form->setCSRFToken($this->getCSRFToken()); $form->setAction($this->path("setup/previewapplication/new")); $field = $form->newField(); $field->setLegend('Create New Preview'); $element = $field->newElement('SelectList', 'adminRole'); $element->setLabel('Admin Role'); $element->setInstructions('If you specifiy and admin role then anyone using the preview will be able to access the administrator functions using this role. They will only be able to see applicants in the prevew application.'); $element->newItem('', 'No access'); foreach ($this->_em->getRepository('\\Jazzee\\Entity\\Role')->findByProgram($this->_program->getId()) as $role) { $element->newItem($role->getId(), $role->getName()); } $form->newButton('submit', 'Create Preview'); if ($input = $form->processInput($this->post)) { if ($input->get('adminRole')) { $adminRole = $this->_em->getRepository('\\Jazzee\\Entity\\Role')->findOneBy(array('program' => $this->_program->getId(), 'id' => $input->get('adminRole'))); } else { $adminRole = new \Jazzee\Entity\Role(); $adminRole->setName('No Access'); } $prefix = substr(md5(mt_rand() * mt_rand()), rand(0, 24), rand(6, 8)); //clean out any wierd chars in program or cycle name $key = preg_replace("/[^a-z0-9\\._-]/i", '', $this->_program->getShortName() . $this->_cycle->getName()) . '-' . time() . '-' . \uniqid($prefix); $path = $this->getPathString($key); $doctrineConfig = $this->_em->getConfiguration(); $connectionParams = array('driver' => 'pdo_sqlite', 'path' => $path); $previewEntityManager = \Doctrine\ORM\EntityManager::create($connectionParams, $doctrineConfig); $this->buildTemporaryDatabase($previewEntityManager); $this->createPreviewApplication($previewEntityManager, $adminRole); $this->addMessage('success', 'Created preview'); $this->redirectPath('setup/previewapplication'); } $this->setVar('form', $form); }
/** * 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()); } }
/** * Create a new cycle */ public function actionNew() { $form = new \Foundation\Form(); $form->setCSRFToken($this->getCSRFToken()); $form->setAction($this->path("manage/cycles/new")); $field = $form->newField(); $field->setLegend('New cycle'); $element = $field->newElement('TextInput', 'name'); $element->setLabel('Cycle Name'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $element->addFilter(new \Foundation\Form\Filter\UrlSafe($element)); $element->addFilter(new \Foundation\Form\Filter\Safe($element)); $element = $field->newElement('DateInput', 'start'); $element->setLabel('Start Date'); $element->addValidator(new \Foundation\Form\Validator\DateBeforeElement($element, 'end')); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $element = $field->newElement('DateInput', 'end'); $element->setLabel('End Date'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $form->newButton('submit', 'Save Changes'); $this->setVar('form', $form); if ($input = $form->processInput($this->post)) { if (count($this->_em->getRepository('\\Jazzee\\Entity\\Cycle')->findBy(array('name' => $input->get('name'))))) { $this->addMessage('error', "A cycle with that name already exists"); } else { $cycle = new \Jazzee\Entity\Cycle(); $cycle->setName($input->get('name')); $cycle->setStart($input->get('start')); $cycle->setEnd($input->get('end')); $this->_em->persist($cycle); $this->_em->flush(); $this->addMessage('success', "New Cycle Saved"); $this->redirectPath("manage/cycles/edit/{$cycle->getId()}"); } } }
/** * List all applicants */ public function actionIndex() { $form = new \Foundation\Form(); $form->setCSRFToken($this->getCSRFToken()); $form->setAction($this->path('applicants/download')); $field = $form->newField(); $field->setLegend('Download Applicants'); $element = $field->newElement('RadioList', 'type'); $element->setLabel('Type of Download'); $element->newItem('xls', 'Excel'); $element->newItem('xml', 'XML'); $element->newItem('json', 'JSON'); $element->newItem('pdfarchive', 'Archive of Multiple PDFs'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $element = $field->newElement('CheckboxList', 'filters'); $element->setLabel('Types of applicants'); $element->newItem('unlocked', 'Incomplete'); $element->newItem('locked', 'Locked'); $element->newItem('admitted', 'Admitted'); $element->newItem('denied', 'Denied'); $element->newItem('accepted', 'Accepted'); $element->newItem('declined', 'Declined'); $tags = $this->_em->getRepository('\\Jazzee\\Entity\\Tag')->findByApplication($this->_application); foreach ($tags as $tag) { $element->newItem($tag->getId(), $tag->getTitle()); } $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $element = $field->newElement('RadioList', 'display'); $element->setLabel('Display'); $displays = array(); foreach ($this->listDisplays() as $key => $display) { $displays[$key] = $display; $element->newItem($key, $display['name']); } $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $form->newButton('submit', 'Download Applicants'); if ($input = $form->processInput($this->post)) { $filters = $input->get('filters'); $applicationPages = array(); foreach ($this->_application->getApplicationPages(\Jazzee\Entity\ApplicationPage::APPLICATION) as $pageEntity) { $pageEntity->getJazzeePage()->setController($this); $applicationPages[$pageEntity->getId()] = $pageEntity; } $applicantsArray = array(); $minimalDisplay = new \Jazzee\Display\Minimal($this->_application); $ids = $this->_em->getRepository('\\Jazzee\\Entity\\Applicant')->findIdsByApplication($this->_application); foreach ($ids as $id) { $applicant = $this->_em->getRepository('\\Jazzee\\Entity\\Applicant')->findArray($id, $minimalDisplay); $selected = false; if (!$applicant['isLocked'] and in_array('unlocked', $filters)) { $selected = true; } if ($applicant['isLocked']) { if (in_array('locked', $filters)) { $selected = true; } if ($applicant['decision']['finalAdmit'] and in_array('admitted', $filters)) { $selected = true; } if ($applicant['decision']['finalDeny'] and in_array('denied', $filters)) { $selected = true; } if ($applicant['decision']['acceptOffer'] and in_array('accepted', $filters)) { $selected = true; } if ($applicant['decision']['declineOffer'] and in_array('declined', $filters)) { $selected = true; } } if (!$selected) { $tagIds = array(); foreach ($applicant['tags'] as $arr) { $tagIds[] = $arr['id']; } foreach ($filters as $value) { if (array_key_exists($value, $tags)) { $tag = $tags[$value]; if (in_array($tag->getId(), $tagIds)) { $selected = true; } } } } if ($selected) { $applicantsArray[] = $applicant['id']; } } //end foreach applicants //use a full applicant display where display is needed $display = $this->getDisplay($displays[$input->get('display')]); unset($ids); switch ($input->get('type')) { case 'xls': $this->makeXls($applicantsArray, $display); break; case 'xml': $this->makeXml($applicantsArray); break; case 'json': $this->makeJson($applicantsArray, $display); break; case 'pdfarchive': $this->makePdfArchive($applicantsArray, $display); break; } } $this->setVar('form', $form); }
/** * 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); }
/** * Make the form for the page * @return \Foundation\Form */ public function makeForm() { $form = new \Foundation\Form(); $form->setCSRFToken($this->_controller->getCSRFToken()); $form->setAction($this->_controller->getActionPath()); $field = $form->newField(); $field->setLegend($this->_applicationPage->getTitle()); $field->setInstructions($this->_applicationPage->getInstructions()); $element = $field->newElement('TextInput', 'externalId'); $element->setLabel($this->_applicationPage->getPage()->getVar('externalIdLabel')); $element->setValue($this->_applicant->getExternalId()); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $element->addValidator(new \Foundation\Form\Validator\SpecialObject($element, array('object' => $this->_applicationPage->getApplication(), 'method' => 'validateExternalId', 'errorMessage' => 'This is not a valid External ID.'))); $form->newButton('submit', 'Save'); return $form; }
/** * Decline Applicants */ public function actionDeclineOffer() { $form = new \Foundation\Form(); $form->setCSRFToken($this->getCSRFToken()); $form->setAction($this->path('applicants/decisions/declineOffer')); $field = $form->newField(); $field->setLegend('Decline Offer for applicants'); $element = $field->newElement('CheckboxList', 'applicants'); $element->setLabel('Select applicants to mark as declined'); foreach ($this->_em->getRepository('\\Jazzee\\Entity\\Applicant')->findApplicantsByName('%', '%', $this->_application) as $applicant) { if ($applicant->isLocked() and $applicant->getDecision()->can('declineOffer')) { $element->newItem($applicant->getId(), $applicant->getLastName() . ', ' . $applicant->getFirstName()); } } $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $form->newButton('submit', 'Submit'); if ($input = $form->processInput($this->post)) { $count = 0; foreach ($input->get('applicants') as $id) { $applicant = $this->getApplicantById($id); $applicant->getDecision()->declineOffer(); $this->_em->persist($applicant); $this->auditLog($applicant, 'Decline Offer'); $count++; if ($count > 100) { $this->_em->flush(); $count = 0; } } $this->addMessage('success', count($this->post['applicants']) . ' applicant(s) declined.'); $this->redirectPath('applicants/decisions'); } $this->setVar('form', $form); $this->loadView('applicants_decisions/form'); }
/** * Setup the current application and cycle */ public function actionIndex() { $form = new \Foundation\Form(); $form->setCSRFToken($this->getCSRFToken()); $form->setAction($this->path("setup/copyapplication")); $field = $form->newField(); $field->setLegend('Import Application'); $element = $field->newElement('SelectList', 'application'); $element->setLabel('Cycle to Copy'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $applications = $this->_em->getRepository('\\Jazzee\\Entity\\Application')->findByProgram($this->_program); foreach ($applications as $application) { $element->newItem($application->getId(), $application->getCycle()->getName()); } $form->newButton('submit', 'Copy'); if ($input = $form->processInput($this->post)) { $previousApplication = $this->_em->getRepository('\\Jazzee\\Entity\\Application')->find($input->get('application')); $this->_application = new \Jazzee\Entity\Application(); $this->_application->setProgram($this->_program); $this->_application->setCycle($this->_cycle); $this->_application->inVisible(); $this->_application->unPublish(); if ($previousApplication->isByInvitationOnly()) { $this->_application->byInvitationOnly(); } $this->_application->setContactName($previousApplication->getContactName()); $this->_application->setContactEmail($previousApplication->getContactEmail()); $this->_application->setWelcome($previousApplication->getWelcome()); $this->_application->setOpen($previousApplication->getOpen()->format('c')); $this->_application->setClose($previousApplication->getClose()->format('c')); $this->_application->setBegin($previousApplication->getBegin()->format('c')); $this->_application->setStatusIncompleteText($previousApplication->getStatusIncompleteText()); $this->_application->setStatusNoDecisionText($previousApplication->getStatusNoDecisionText()); $this->_application->setStatusAdmitText($previousApplication->getStatusAdmitText()); $this->_application->setStatusDenyText($previousApplication->getStatusDenyText()); $this->_application->setStatusAcceptText($previousApplication->getStatusAcceptText()); $this->_application->setStatusDeclineText($previousApplication->getStatusDeclineText()); foreach ($previousApplication->getApplicationPages() as $previousPage) { $page = $this->addPage($previousPage->getPage()); $applicationPage = new \Jazzee\Entity\ApplicationPage(); $applicationPage->setApplication($this->_application); $applicationPage->setPage($page); $applicationPage->setKind($previousPage->getKind()); $applicationPage->setTitle($previousPage->getTitle()); $applicationPage->setMin($previousPage->getMin()); $applicationPage->setMax($previousPage->getMax()); $applicationPage->setName($previousPage->getName()); if ($previousPage->isRequired()) { $applicationPage->required(); } else { $applicationPage->optional(); } if ($previousPage->answerStatusDisplay()) { $applicationPage->showAnswerStatus(); } else { $applicationPage->hideAnswerStatus(); } $applicationPage->setInstructions($previousPage->getInstructions()); $applicationPage->setLeadingText($previousPage->getLeadingText()); $applicationPage->setTrailingText($previousPage->getTrailingText()); $applicationPage->setWeight($previousPage->getWeight()); $this->_em->persist($applicationPage); } $templates = $this->_em->getRepository('Jazzee\\Entity\\Template')->findBy(array('application' => $previousApplication)); foreach ($templates as $previousTemplate) { $template = new \Jazzee\Entity\Template($previousTemplate->getType()); $template->setApplication($this->_application); $template->setTitle($previousTemplate->getTitle()); $template->setText($previousTemplate->getText()); $this->_em->persist($template); } $this->_em->persist($this->_application); $this->addMessage('success', 'Application copied successfully'); unset($this->_store->AdminControllerGetNavigation); $this->redirectPath('setup/application'); } $this->setVar('form', $form); }
/** * Create a new pagetype */ public function actionNew() { $form = new \Foundation\Form(); $form->setCSRFToken($this->getCSRFToken()); $form->setAction($this->path('setup/roles/new')); $field = $form->newField(); $field->setLegend('New program role'); $element = $field->newElement('TextInput', 'name'); $element->setLabel('Role Name'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $element->addFilter(new \Foundation\Form\Filter\Safe($element)); $form->newButton('submit', 'Add Role'); $this->setVar('form', $form); if ($input = $form->processInput($this->post)) { $role = new \Jazzee\Entity\Role(); $role->notGLobal(); $role->setProgram($this->_program); $role->setName($input->get('name')); $this->_em->persist($role); $display = new \Jazzee\Entity\Display('role'); $display->setRole($role); $display->setApplication($this->_application); $display->setName($role->getName() . ' display'); foreach ($this->_user->getMaximumDisplayForApplication($this->_application)->listElements() as $userDisplayElement) { $displayElement = \Jazzee\Entity\DisplayElement::createFromDisplayElement($userDisplayElement, $this->_application); $display->addElement($displayElement); $this->getEntityManager()->persist($displayElement); } $this->_em->persist($display); $this->_em->flush(); $this->addMessage('success', "Role Saved Successfully"); $this->redirectPath('setup/roles'); } }
/** * List all the pending payments in the system */ public function actionIndex() { $this->setLayoutVar('pageTitle', 'Payment Report'); $form = new \Foundation\Form(); $form->setCSRFToken($this->getCSRFToken()); $form->setAction($this->path('payments/report')); $field = $form->newField(); $field->setLegend('Search'); $element = $field->newElement('CheckboxList', 'types'); $element->setLabel('Payment Type'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $paymentTypes = array(); foreach ($this->_em->getRepository('Jazzee\\Entity\\PaymentType')->findWithPayment() as $type) { $paymentTypes[$type->getId()] = $type; } foreach ($paymentTypes as $type) { $element->newItem($type->getId(), $type->getName()); } $element = $field->newElement('DateInput', 'from'); $element->setLabel('From'); $element = $field->newElement('DateInput', 'to'); $element->setLabel('To'); $element->addValidator(new \Foundation\Form\Validator\DateAfterElement($element, 'from')); $element = $field->newElement('SelectList', 'program'); $element->setLabel('Program'); $element->newItem(null, ''); $programs = array(); foreach ($this->_em->getRepository('\\Jazzee\\Entity\\Program')->findBy(array('isExpired' => false), array('name' => 'ASC')) as $program) { $programs[$program->getId()] = $program; } foreach ($programs as $program) { $element->newItem($program->getId(), $program->getName()); } $element = $field->newElement('SelectList', 'cycle'); $element->setLabel('Cycle'); $element->newItem(null, ''); $cycles = array(); foreach ($this->_em->getRepository('\\Jazzee\\Entity\\Cycle')->findAll() as $cycle) { $cycles[$cycle->getId()] = $cycle; } foreach ($cycles as $cycle) { $element->newItem($cycle->getId(), $cycle->getName()); } $payments = array(); $form->newButton('submit', 'Search'); if (empty($this->post)) { $from = new \DateTime('midnight yesterday'); $to = new \DateTime('now'); $payments = $this->_em->getRepository('\\Jazzee\\Entity\\Payment')->findByStatusArray(\Jazzee\Entity\Payment::SETTLED, array(), $from, $to); $this->setVar('resultsDescription', ''); $description = sprintf('%s payments since midnight yesterday', count($payments)); $this->setVar('searchResultsDescription', $description); $form->getElementByName('types')->setValue(array_keys($paymentTypes)); } else { if ($input = $form->processInput($this->post)) { set_time_limit(120); $types = array(); foreach ($input->get('types') as $id) { $types[] = $paymentTypes[$id]; } $program = $input->get('program') ? $programs[$input->get('program')] : null; $cycle = $input->get('cycle') ? $cycles[$input->get('cycle')] : null; $from = $input->get('from') ? new \DateTime($input->get('from')) : null; $to = $input->get('to') ? new \DateTime($input->get('to')) : null; $payments = $this->_em->getRepository('\\Jazzee\\Entity\\Payment')->findByStatusArray(\Jazzee\Entity\Payment::SETTLED, $types, $from, $to, $program, $cycle); // $description = sprintf('%s results from search', count($payments)); $this->setVar('searchResultsDescription', ''); } else { $this->setVar('searchResultsDescription', ''); } } foreach ($payments as &$payment) { $paymentType = $paymentTypes[$payment['type']['id']]->getJazzeePaymentType($this); $payment['notes'] = $paymentType->getPaymentNotesFromArray($payment); } $this->setVar('payments', $payments); $this->setVar('form', $form); }
/** * Change applicant password */ public function actionChangePassword() { $form = new \Foundation\Form(); $form->setCSRFToken($this->getCSRFToken()); $form->setAction($this->applyPath('account/changePassword')); $field = new \Foundation\Form\Field($form); $field->setLegend('Change Password'); $form->addField($field); $element = $field->newElement('PasswordInput', 'password'); $element->setLabel('Current Password'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $element = $field->newElement('PasswordInput', 'newpassword'); $element->setLabel('New Password'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $element = $field->newElement('PasswordInput', 'confirm'); $element->setLabel('Confirm Password'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $element->addValidator(new \Foundation\Form\Validator\SameAs($element, 'newpassword')); $form->newButton('submit', 'Change Password'); if ($input = $form->processInput($this->post)) { if ($this->_applicant->checkPassword($input->get('password'))) { $this->_applicant->setPassword($input->get('newpassword')); $this->_em->persist($this->_applicant); $this->addMessage('success', 'Your password was changed successfully.'); $this->redirectApplyPath('account'); } else { $form->getElementByName('password')->addMessage('Password Incorrect'); } } $this->setVar('form', $form); $this->loadView($this->controllerName . '/form'); }
/** * New Decision letter template */ public function actionNew() { $form = new \Foundation\Form(); $form->setCSRFToken($this->getCSRFToken()); $form->setAction($this->path("setup/decisionletters/new")); $field = $form->newField(); $field->setLegend('New Template'); $element = $field->newElement('RadioList', 'type'); $element->setLabel('Type'); $element->newItem(\Jazzee\Entity\Template::DECISION_ADMIT, 'Admit Letter'); $element->newItem(\Jazzee\Entity\Template::DECISION_DENY, 'Deny Letter'); $element->setValue(\Jazzee\Entity\Template::DECISION_ADMIT); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $element = $field->newElement('TextInput', 'title'); $element->setLabel('Title'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $element->addFilter(new \Foundation\Form\Filter\SafeHTML($element)); $form->newButton('submit', 'Create'); if ($input = $form->processInput($this->post)) { $template = new \Jazzee\Entity\Template($input->get('type')); $template->setTitle($input->get('title')); $template->setApplication($this->_application); $this->_em->persist($template); $this->_em->flush(); $this->addMessage('success', $template->getTitle() . ' created.'); $this->redirectPath('setup/decisionletters/edit/' . $template->getId()); } $this->setVar('form', $form); }
/** * Get a form for a specific status text var * @param string $status * @return \Foundation\Form */ protected function getStatusForm($status) { $form = new \Foundation\Form(); $form->setCSRFToken($this->getCSRFToken()); $form->setAction($this->path("setup/application/editStatus{$status}")); $field = $form->newField(); $field->setLegend("Edit {$status} Page"); $search = array('_Applicant_Name_', '_Application_Deadline_', '_Offer_Response_Deadline_', '_SIR_Link_', '_Admit_Letter_', '_Deny_Letter_', '_Admit_Date_', '_Deny_Date_', '_Accept_Date_', '_Decline_Date_'); $field->setInstructions('You can use these tokens in the text, they will be replaced automatically: <br />' . implode('</br />', $search)); $element = $field->newElement('Textarea', 'message'); $element->setLabel('Message'); $func = "getStatus{$status}Text"; $element->setValue($this->_application->{$func}()); $element->addFilter(new \Foundation\Form\Filter\SafeHTML($element)); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $form->newButton('submit', 'Save'); return $form; }
/** * Edit a template */ public function actionEdit($id) { if ($template = $this->_application->getTemplateById($id)) { $pdfLib = new PDFLib(); $pdfLib->set_option("errorpolicy=exception"); $tmpFile = tempnam($this->_config->getVarPath() . '/tmp/', 'pdftemplate'); $document = $pdfLib->open_pdi_document($template->getTmpFilePath(), ""); $pagecount = $pdfLib->pcos_get_number($document, "length:pages"); $blocks = array(); for ($pageNum = 0; $pageNum < $pagecount; $pageNum++) { $blockcount = $pdfLib->pcos_get_number($document, "length:pages[{$pageNum}]/blocks"); for ($blockNum = 0; $blockNum < $blockcount; $blockNum++) { $blocks[] = $pdfLib->pcos_get_string($document, "pages[{$pageNum}]/blocks[{$blockNum}]/Name"); } } $blocks = array_unique($blocks); $form = new \Foundation\Form(); $form->setCSRFToken($this->getCSRFToken()); $form->setAction($this->path("setup/pdftemplates/edit/" . $template->getId())); $field = $form->newField(); $field->setLegend('Edit Template Blocks'); $element = $field->newElement('TextInput', 'title'); $element->setLabel('Title'); $element->setValue($template->getTitle()); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $blockElements = array('applicant-firstName' => 'Applicant: First Name', 'applicant-lastName' => 'Applicant: Last Name', 'applicant-middleName' => 'Applicant: Middle Name', 'applicant-suffix' => 'Applicant: Suffix', 'applicant-fullName' => 'Applicant: Full Name', 'applicant-email' => 'Applicant: Email', 'applicant-id' => 'Applicant: ID', 'applicant-externalid' => 'Applicant: External ID'); foreach ($this->_application->getApplicationPages() as $applicationPage) { if ($applicationPage->getJazzeePage() instanceof \Jazzee\Interfaces\PdfPage) { foreach ($applicationPage->getJazzeePage()->listPdfTemplateElements() as $key => $title) { $blockElements[$key] = $title; } } } foreach ($blocks as $blockName) { $element = $field->newElement('SelectList', 'block_' . $blockName); $element->setLabel("Block {$blockName}"); $element->newItem(null, ''); foreach ($blockElements as $id => $title) { $element->newItem($id, $title); } if ($template->hasBlock($blockName)) { $blockData = $template->getBlock($blockName); switch ($blockData['type']) { case 'applicant': $element->setValue('applicant-' . $blockData['element']); break; case 'page': $element->setValue('page-' . $blockData['pageId'] . '-element-' . $blockData['elementId']); break; } } } if ($input = $form->processInput($this->post)) { $template->setTitle($input->get('title')); $template->clearBlocks(); $matches = array(); //initialize for use in preg_match foreach ($blocks as $blockName) { if ($blockElement = $input->get('block_' . $blockName)) { if (preg_match('#applicant-([a-z]+)#i', $blockElement, $matches)) { $template->addBlock($blockName, array('type' => 'applicant', 'element' => $matches[1])); } else { if (preg_match('#page-([0-9]+)-element-([0-9]+)#i', $blockElement, $matches)) { $template->addBlock($blockName, array('type' => 'page', 'pageId' => $matches[1], 'elementId' => $matches[2])); } } } } $this->getEntityManager()->persist($template); $this->addMessage('success', 'Template Saved Successfully'); $this->redirectPath('setup/pdftemplates'); } $form->newButton('submit', 'Save'); $this->setVar('form', $form); } else { $this->addMessage('error', 'Unable to edit template. It is not associated with this application.'); $this->redirectPath('setup/pdftemplates'); } }