'APPLICATION-FORM', 'label' => 'Letter of Intent')); $Form->add(new FormHidden(array('id' => 'guid', 'value' => _REQUEST('guid')))); $Form->add(new FormHidden(array('id' => 'Active', 'value' => '1'))); $Form->add(new FormHtml(array( 'html' => 'The letter of intent must be submitted before applicants can access the full grant application. The information that it contains allows the foundation to determine if the project fits with the funding priorities and allows us to estimate the potential review workload. Please note that where appropriate, the text field will automatically expand. If you have questions, please consult our FAQs.' ))); $Form->add(new FormHidden(array( 'id' => 'CNF', 'value' => $isCNF ))); $Form->add(new FormText(array( 'id' => 'FirstName', 'label' => 'First Name', 'style' => 'width: 300px;', 'containerStyle' => 'display: inline-block;', 'rules' => array( 'required' => true, 'maxlength' => 50 ) ))); $Form->add(new FormText(array( 'id' => 'LastName', 'label' => 'Last Name', 'style' => 'width: 300px;', 'containerStyle' => 'display: inline-block;', 'rules' => array( 'required' => true, 'maxlength' => 50 ) ))); $Form->addNewLine(); $Form->add(new FormText(array( 'id' => 'UserName', 'label' => 'Email Address', 'confirm' => true, 'style' => 'width: 300px;', 'containerStyle' => 'display: inline-block;', 'rules' => array( 'required' => true, 'email' => true ) ))); $Form->addNewLine(); if($isCNF) { $Form->add(new FormText(array( 'id' => 'Organization', 'label' => 'Mentor', 'style' => 'width: 300px;', 'rules' => array( 'required' => true, 'maxlength' => 100 ) ))); $Form->add(new FormTinyMce(array( 'id' => 'Description', 'label' => 'Brief Description of Goals / Research Plan', 'maxLength' => 600, 'rules' => array( 'required' => true ) ))); $Form->addNewLine(); $Form->add(new FormCombobox(array( 'id' => 'ProjectTypeId', 'label' => 'Research Focus', 'style' => 'width: 300px;', 'containerStyle' => 'display: inline-block;', 'options' => array_merge(array('' => ''), DB::to_array("SELECT ProjectType, ProjectTypeId FROM projecttype WHERE Active = 1 AND ProjectType LIKE '%Research%' ORDER BY Sort ASC")), 'rules' => array( 'required' => true ), 'onChange' => "projectTypeChange" ))); $Form->add(new FormCombobox(array( 'id' => 'ProjectFocusId', 'label' => 'Area of Expertise', 'style' => 'width: 300px;', 'containerStyle' => 'display: inline-block;', 'options' => array('Select Research Focus' => '0'),//, DB::to_array("SELECT ProjectFocus, ProjectFocusId FROM projectfocus WHERE Active = 1 ORDER BY Sort ASC")), 'rules' => array( 'required' => true ) ))); } else { $Form->add(new FormText(array( 'id' => 'Organization', 'label' => 'Organization', 'style' => 'width: 300px;', 'rules' => array( 'required' => true, 'maxlength' => 100 ) ))); $Form->add(new FormTinyMce(array( 'id' => 'Description', 'label' => 'Brief Description of Project', 'maxLength' => 300, 'rules' => array( 'required' => true ) ))); $Form->addNewLine(); $Form->add(new FormCombobox(array( 'id' => 'ProjectTypeId', 'label' => 'Project Type', 'style' => 'width: 300px;', 'containerStyle' => 'display: inline-block;', 'options' => array_merge(array('' => ''), DB::to_array("SELECT ProjectType, ProjectTypeId FROM projecttype WHERE Active = 1 ORDER BY Sort ASC")), 'rules' => array( 'required' => true ), 'onChange' => "projectTypeChange" ))); $Form->add(new FormCombobox(array( 'id' => 'ProjectFocusId', 'label' => 'Project Focus', 'style' => 'width: 300px;', 'containerStyle' => 'display: inline-block;', 'options' => array('Select Project Type' => '0'),//, DB::to_array("SELECT ProjectFocus, ProjectFocusId FROM projectfocus WHERE Active = 1 ORDER BY Sort ASC")), 'rules' => array( 'required' => true ) ))); $Form->add(new FormDollar(array( 'id' => 'Amount', 'label' => 'Approximate Amount Requested From Firland', 'style' => 'width: 300px;', 'rules' => array( 'required' => true ) ))); } $Form->add(new FormText(array( 'id' => 'Consent', 'label' => 'By typing your name here, you take responsibility for this content', 'style' => 'width: 300px;', 'rules' => array( 'required' => true, 'maxlength' => 50 ) ))); $Form->add(new FormHtml(array('html' => '
'))); $Form->addSubmit(array('value' => 'Submit Application')); $Form->addNewLine(); $guid = _REQUEST('guid'); $Grant = null; if($guid) { $Grant = Grant::findByGUID($guid); $Letter = new Letter($Grant->LetterId); $Form->bind(array( 'FirstName' => $Grant->Owner->FirstName, 'LastName' => $Grant->Owner->LastName, 'UserName' => $Grant->Owner->UserName, 'Organization' => $Grant->Letter->Organization, 'Description' => $Grant->Letter->Description, 'ProjectTypeId' => $Grant->Letter->ProjectTypeId, 'ProjectFocusId' => $Grant->Letter->ProjectFocusId, 'Amount' => $Grant->Letter->Amount )); } if($Form->posted()) { $userName = $Form->postedValue('UserName'); $fullName = $Form->postedValue('FirstName') . ' ' . $Form->postedValue('LastName'); if($User = User::findByUserName($userName)) { $userId = $User->id; } else { $User = new User(); $User->update(array( 'UserName' => $userName, 'FirstName' => $Form->postedValue('FirstName'), 'LastName' => $Form->postedValue('LastName'), 'AccessId' => Access::$USER, 'RoleId' => Role::$APPLICANT, 'Active' => 0 )); $userId = $User->write(); } if(!$Grant) { $Grant = new Grant(); $Letter = new Letter(); $guid = strtoupper(uniqid()); } $Letter->update($Form->getValues(array( 'Organization', 'Description', 'Amount', 'ProjectTypeId', 'ProjectFocusId', 'Consent', 'CNF' ))); $letterId = $Letter->write(); $Uploader = new Uploader('Upload'); $Uploader->saveFiles(APP_PATH . '/grants/uploads/', $userId); $Grant->update(array( 'LetterId' => $letterId, 'OwnerId' => $userId, 'StatusId' => 0, 'GUID' => $guid )); $grantId = $Grant->write(); if(date("Y") > 2015) { $yearCount = DB::num_rows("SELECT GrantId FROM `grant` WHERE Created > '" . date('Y') . "-01-01'"); $yearGrantId = $yearCount + 1; } else { $yearGrantId = $grantId; } $Grant->update(array('GrantNumber' => date("Y") . str_pad($yearGrantId, 4, "0", STR_PAD_LEFT) . ($Form->postedValue('CNF') ? 'C' : ''))); $Grant->write(); if(sizeof($Uploader->Files)) { foreach($Uploader->Files as $fileId => $File) { $Grant->addFile($File); } } $Grant->changeStatus(Status::$LOI_SUBMITTED); echo json_encode(array( 'Valid' => 1, 'Redirect' => 'letter_success.php' )); die; } FIRLAND::renderHeader(); if(SETTING_DEBUG && !$guid && SETTING_DEBUG_PREFILL) { $firstName = Random::getData(Random::$FIRSTNAME); $lastName = Random::getData(Random::$LASTNAME); $data = $Form->getRandomizedData(); $data = array_merge($data, array( 'Active' => 1, 'FirstName' => $firstName, 'LastName' => $lastName, 'UserName' => str_replace("'", "", $firstName . '_' . $lastName) . '@' . DEBUG_EMAIL_DOMAIN, 'Organization' => Random::getData(Random::$COMPANY), 'Amount' => Random::getData(Random::$INTEGER, 7), 'Consent' => $firstName . ' ' . $lastName )); // unset($data['ProjectTypeId']); // unset($data['ProjectFocusId']); $Form->bind($data); } $Form->render(); FIRLAND::renderFooter(); ?>