Esempio n. 1
0
 private function addCandidateModal($contents = '', $fields = array())
 {
     /* Bail out if we don't have a valid job order ID. */
     if (!$this->isRequiredIDValid('jobOrderID', $_GET)) {
         CommonErrors::fatalModal(COMMONERROR_BADINDEX, $this, 'Invalid job order ID.');
     }
     $jobOrderID = $_GET['jobOrderID'];
     $candidates = new Candidates($this->_siteID);
     /* Get possible sources. */
     $sourcesRS = $candidates->getPossibleSources();
     $sourcesString = ListEditor::getStringFromList($sourcesRS, 'name');
     /* Get extra fields. */
     $extraFieldRS = $candidates->extraFields->getValuesForAdd();
     $associatedAttachment = 0;
     $associatedAttachmentRS = array();
     $EEOSettings = new EEOSettings($this->_siteID);
     $EEOSettingsRS = $EEOSettings->getAll();
     if (is_array($parsingStatus = LicenseUtility::getParsingStatus()) && isset($parsingStatus['parseLimit'])) {
         $parsingStatus['parseLimit'] = $parsingStatus['parseLimit'] - 1;
     }
     $careerPortalSettings = new CareerPortalSettings($this->_siteID);
     $careerPortalSettingsRS = $careerPortalSettings->getAll();
     $careerPortalEnabled = intval($careerPortalSettingsRS['enabled']) ? true : false;
     /* Get questionnaires to attach (if public) */
     $questionnaire = new Questionnaire($this->_siteID);
     $questionnaires = $questionnaire->getAll(false);
     $this->_template->assign('careerPortalEnabled', $careerPortalEnabled);
     $this->_template->assign('questionnaires', $questionnaires);
     $this->_template->assign('contents', $contents);
     $this->_template->assign('isParsingEnabled', $tmp = LicenseUtility::isParsingEnabled());
     $this->_template->assign('parsingStatus', $parsingStatus);
     $this->_template->assign('extraFieldRS', $extraFieldRS);
     $this->_template->assign('sourcesRS', $sourcesRS);
     $this->_template->assign('isModal', true);
     $this->_template->assign('jobOrderID', $jobOrderID);
     $this->_template->assign('sourcesString', $sourcesString);
     $this->_template->assign('preassignedFields', $fields);
     $this->_template->assign('associatedAttachment', $associatedAttachment);
     $this->_template->assign('associatedAttachmentRS', $associatedAttachmentRS);
     $this->_template->assign('associatedTextResume', false);
     $this->_template->assign('associatedFileResume', false);
     $this->_template->assign('EEOSettingsRS', $EEOSettingsRS);
     if (!eval(Hooks::get('JO_ADD_CANDIDATE_MODAL'))) {
         return;
     }
     /* REMEMBER TO ALSO UPDATE CandidatesUI::add() IF APPLICABLE. */
     $this->_template->display('./modules/candidates/Add.tpl');
 }
Esempio n. 2
0
 /**
  * Adds a candidate. This is factored out for code clarity.
  *
  * @param boolean is modal window
  * @param string module directory
  * @return integer candidate ID
  */
 private function _addCandidate($isModal, $directoryOverride = '')
 {
     /* Module directory override for fatal() calls. */
     if ($directoryOverride != '') {
         $moduleDirectory = $directoryOverride;
     } else {
         $moduleDirectory = $this->_moduleDirectory;
     }
     /* Modal override for fatal() calls. */
     if ($isModal) {
         $fatal = 'fatalModal';
     } else {
         $fatal = 'fatal';
     }
     /* Bail out if we received an invalid availability date; if not, go
      * ahead and convert the date to MySQL format.
      */
     $dateAvailable = $this->getTrimmedInput('dateAvailable', $_POST);
     if (!empty($dateAvailable)) {
         if (!DateUtility::validate('-', $dateAvailable, DATE_FORMAT_MMDDYY)) {
             $this->{$fatal}('Invalid availability date.', $moduleDirectory);
         }
         /* Convert start_date to something MySQL can understand. */
         $dateAvailable = DateUtility::convert('-', $dateAvailable, DATE_FORMAT_MMDDYY, DATE_FORMAT_YYYYMMDD);
     }
     $formattedPhoneHome = StringUtility::extractPhoneNumber($this->getTrimmedInput('phoneHome', $_POST));
     if (!empty($formattedPhoneHome)) {
         $phoneHome = $formattedPhoneHome;
     } else {
         $phoneHome = $this->getTrimmedInput('phoneHome', $_POST);
     }
     $formattedPhoneCell = StringUtility::extractPhoneNumber($this->getTrimmedInput('phoneCell', $_POST));
     if (!empty($formattedPhoneCell)) {
         $phoneCell = $formattedPhoneCell;
     } else {
         $phoneCell = $this->getTrimmedInput('phoneCell', $_POST);
     }
     $formattedPhoneWork = StringUtility::extractPhoneNumber($this->getTrimmedInput('phoneWork', $_POST));
     if (!empty($formattedPhoneWork)) {
         $phoneWork = $formattedPhoneWork;
     } else {
         $phoneWork = $this->getTrimmedInput('phoneWork', $_POST);
     }
     /* Can Relocate */
     $canRelocate = $this->isChecked('canRelocate', $_POST);
     $lastName = $this->getTrimmedInput('lastName', $_POST);
     $middleName = $this->getTrimmedInput('middleName', $_POST);
     $firstName = $this->getTrimmedInput('firstName', $_POST);
     $email1 = $this->getTrimmedInput('email1', $_POST);
     $email2 = $this->getTrimmedInput('email2', $_POST);
     $address = $this->getTrimmedInput('address', $_POST);
     $city = $this->getTrimmedInput('city', $_POST);
     $state = $this->getTrimmedInput('state', $_POST);
     $zip = $this->getTrimmedInput('zip', $_POST);
     $source = $this->getTrimmedInput('source', $_POST);
     $keySkills = $this->getTrimmedInput('keySkills', $_POST);
     $currentEmployer = $this->getTrimmedInput('currentEmployer', $_POST);
     $currentPay = $this->getTrimmedInput('currentPay', $_POST);
     $desiredPay = $this->getTrimmedInput('desiredPay', $_POST);
     $notes = $this->getTrimmedInput('notes', $_POST);
     $webSite = $this->getTrimmedInput('webSite', $_POST);
     $bestTimeToCall = $this->getTrimmedInput('bestTimeToCall', $_POST);
     $gender = $this->getTrimmedInput('gender', $_POST);
     $race = $this->getTrimmedInput('race', $_POST);
     $veteran = $this->getTrimmedInput('veteran', $_POST);
     $disability = $this->getTrimmedInput('disability', $_POST);
     /* Candidate source list editor. */
     $sourceCSV = $this->getTrimmedInput('sourceCSV', $_POST);
     /* Text resume. */
     $textResumeBlock = $this->getTrimmedInput('textResumeBlock', $_POST);
     $textResumeFilename = $this->getTrimmedInput('textResumeFilename', $_POST);
     /* File resume. */
     $associatedFileResumeID = $this->getTrimmedInput('associatedbFileResumeID', $_POST);
     /* Bail out if any of the required fields are empty. */
     if (empty($firstName) || empty($lastName)) {
         CommonErrors::fatal(COMMONERROR_MISSINGFIELDS, $this);
     }
     if (!eval(Hooks::get('CANDIDATE_ON_ADD_PRE'))) {
         return;
     }
     $candidates = new Candidates($this->_siteID);
     $candidateID = $candidates->add($firstName, $middleName, $lastName, $email1, $email2, $phoneHome, $phoneCell, $phoneWork, $address, $city, $state, $zip, $source, $keySkills, $dateAvailable, $currentEmployer, $canRelocate, $currentPay, $desiredPay, $notes, $webSite, $bestTimeToCall, $this->_userID, $this->_userID, $gender, $race, $veteran, $disability);
     if ($candidateID <= 0) {
         return $candidateID;
     }
     /* Update extra fields. */
     $candidates->extraFields->setValuesOnEdit($candidateID);
     /* Update possible source list. */
     $sources = $candidates->getPossibleSources();
     $sourcesDifferences = ListEditor::getDifferencesFromList($sources, 'name', 'sourceID', $sourceCSV);
     $candidates->updatePossibleSources($sourcesDifferences);
     /* Associate an exsisting resume if the user created a candidate with one. (Bulk) */
     if (isset($_POST['associatedAttachment'])) {
         $attachmentID = $_POST['associatedAttachment'];
         $attachments = new Attachments($this->_siteID);
         $attachments->setDataItemID($attachmentID, $candidateID, DATA_ITEM_CANDIDATE);
     } else {
         if (isset($_FILES['file']) && !empty($_FILES['file']['name'])) {
             if (!eval(Hooks::get('CANDIDATE_ON_CREATE_ATTACHMENT_PRE'))) {
                 return;
             }
             $attachmentCreator = new AttachmentCreator($this->_siteID);
             $attachmentCreator->createFromUpload(DATA_ITEM_CANDIDATE, $candidateID, 'file', false, true);
             if ($attachmentCreator->isError()) {
                 CommonErrors::fatal(COMMONERROR_FILEERROR, $this, $attachmentCreator->getError());
             }
             if ($attachmentCreator->duplicatesOccurred()) {
                 $this->listByView('This attachment has already been added to this candidate.');
                 return;
             }
             $isTextExtractionError = $attachmentCreator->isTextExtractionError();
             $textExtractionErrorMessage = $attachmentCreator->getTextExtractionError();
             // FIXME: Show parse errors!
             if (!eval(Hooks::get('CANDIDATE_ON_CREATE_ATTACHMENT_POST'))) {
                 return;
             }
         } else {
             if (LicenseUtility::isParsingEnabled()) {
                 /**
                  * Description: User clicks "browse" and selects a resume file. User doesn't click
                  * upload. The resume file is STILL uploaded.
                  * Controversial: User uploads a resume, parses, etc. User selects a new file with
                  * "Browse" but doesn't click "Upload". New file is accepted.
                  * It's technically correct either way, I'm opting for the "use whats in "file"
                  * box over what's already uploaded method to avoid losing resumes on candidate
                  * additions.
                  */
                 $newFile = FileUtility::getUploadFileFromPost($this->_siteID, 'addcandidate', 'documentFile');
                 if ($newFile !== false) {
                     $newFilePath = FileUtility::getUploadFilePath($this->_siteID, 'addcandidate', $newFile);
                     $tempFile = $newFile;
                     $tempFullPath = $newFilePath;
                 } else {
                     $attachmentCreated = false;
                     $tempFile = false;
                     $tempFullPath = false;
                     if (isset($_POST['documentTempFile']) && !empty($_POST['documentTempFile'])) {
                         $tempFile = $_POST['documentTempFile'];
                         // Get the path of the file they uploaded already to attach
                         $tempFullPath = FileUtility::getUploadFilePath($this->_siteID, 'addcandidate', $tempFile);
                     }
                 }
                 if ($tempFile !== false && $tempFullPath !== false) {
                     if (!eval(Hooks::get('CANDIDATE_ON_CREATE_ATTACHMENT_PRE'))) {
                         return;
                     }
                     $attachmentCreator = new AttachmentCreator($this->_siteID);
                     $attachmentCreator->createFromFile(DATA_ITEM_CANDIDATE, $candidateID, $tempFullPath, $tempFile, '', true, true);
                     if ($attachmentCreator->isError()) {
                         CommonErrors::fatal(COMMONERROR_FILEERROR, $this, $attachmentCreator->getError());
                     }
                     if ($attachmentCreator->duplicatesOccurred()) {
                         $this->listByView('This attachment has already been added to this candidate.');
                         return;
                     }
                     $isTextExtractionError = $attachmentCreator->isTextExtractionError();
                     $textExtractionErrorMessage = $attachmentCreator->getTextExtractionError();
                     if (!eval(Hooks::get('CANDIDATE_ON_CREATE_ATTACHMENT_POST'))) {
                         return;
                     }
                     // Remove the cleanup cookie since the file no longer exists
                     setcookie('CATS_SP_TEMP_FILE', '');
                     $attachmentCreated = true;
                 }
                 if (!$attachmentCreated && isset($_POST['documentText']) && !empty($_POST['documentText'])) {
                     // Resume was pasted into the form and not uploaded from a file
                     if (!eval(Hooks::get('CANDIDATE_ON_CREATE_ATTACHMENT_PRE'))) {
                         return;
                     }
                     $attachmentCreator = new AttachmentCreator($this->_siteID);
                     $attachmentCreator->createFromText(DATA_ITEM_CANDIDATE, $candidateID, $_POST['documentText'], 'MyResume.txt', true);
                     if ($attachmentCreator->isError()) {
                         CommonErrors::fatal(COMMONERROR_FILEERROR, $this, $attachmentCreator->getError());
                     }
                     if ($attachmentCreator->duplicatesOccurred()) {
                         $this->listByView('This attachment has already been added to this candidate.');
                         return;
                     }
                     if (!eval(Hooks::get('CANDIDATE_ON_CREATE_ATTACHMENT_POST'))) {
                         return;
                     }
                 }
             } else {
                 if (!empty($textResumeBlock)) {
                     $attachmentCreator = new AttachmentCreator($this->_siteID);
                     $attachmentCreator->createFromText(DATA_ITEM_CANDIDATE, $candidateID, $textResumeBlock, $textResumeFilename, true);
                     if ($attachmentCreator->isError()) {
                         CommonErrors::fatal(COMMONERROR_FILEERROR, $this, $attachmentCreator->getError());
                         return;
                         //$this->fatal($attachmentCreator->getError());
                     }
                     $isTextExtractionError = $attachmentCreator->isTextExtractionError();
                     $textExtractionErrorMessage = $attachmentCreator->getTextExtractionError();
                     // FIXME: Show parse errors!
                 }
             }
         }
     }
     if (!eval(Hooks::get('CANDIDATE_ON_ADD_POST'))) {
         return;
     }
     return $candidateID;
 }