Esempio n. 1
0
    public function onApplyToJobOrder($siteID, $candidateID = false)
    {
        $jobOrders = new JobOrders($siteID);
        $careerPortalSettings = new CareerPortalSettings($siteID);

        if (!$this->isRequiredIDValid('ID', $_POST))
        {
            CommonErrors::fatal(COMMONERROR_BADINDEX, $this, 'Invalid job order ID.');
            return;
        }

        $jobOrderID = $_POST['ID'];

        $jobOrderData = $jobOrders->get($jobOrderID);
        if (!isset($jobOrderData['public']) || $jobOrderData['public'] == 0)
        {
            CommonErrors::fatal(COMMONERROR_BADINDEX, $this, 'The specified job order could not be found.');
            return;
        }

        $lastName       = $this->getTrimmedInput('lastName', $_POST);
        $middleName     = $this->getTrimmedInput('middleName', $_POST);
        $firstName      = $this->getTrimmedInput('firstName', $_POST);
        $email          = $this->getTrimmedInput('email', $_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);
        $phone          = $this->getTrimmedInput('phone', $_POST);
        $phoneHome      = $this->getTrimmedInput('phoneHome', $_POST);
        $phoneCell      = $this->getTrimmedInput('phoneCell', $_POST);
        $bestTimeToCall = $this->getTrimmedInput('bestTimeToCall', $_POST);
        $keySkills      = $this->getTrimmedInput('keySkills', $_POST);
        $extraNotes     = $this->getTrimmedInput('extraNotes', $_POST);
        $employer       = $this->getTrimmedInput('employer', $_POST);

        $gender         = $this->getTrimmedInput('eeogender', $_POST);
        $race           = $this->getTrimmedInput('eeorace', $_POST);
        $veteran        = $this->getTrimmedInput('eeoveteran', $_POST);
        $disability     = $this->getTrimmedInput('eeodisability', $_POST);

        if (empty($firstName))
        {
            CommonErrors::fatal(COMMONERROR_MISSINGFIELDS, $this, 'First Name is a required field - please have your administrator edit your templates to include the first name field.');
        }

        if (empty($lastName))
        {
            CommonErrors::fatal(COMMONERROR_MISSINGFIELDS, $this, 'Last Name is a required field - please have your administrator edit your templates to include the last name field.');
        }

        if (empty($email))
        {
            CommonErrors::fatal(COMMONERROR_MISSINGFIELDS, $this, 'E-Mail address is a required field - please have your administrator edit your templates to include the email field.');
        }

        if (empty($source))
        {
            $source = 'Online Careers Website';
        }

        $users = new Users(CATS_ADMIN_SITE);
        $automatedUser = $users->getAutomatedUser();

        /* Find if another user with same e-mail exists. If so, update the user
         * to contain the new information.
         */
        $candidates = new Candidates($siteID);

        /**
         * Save basic information in a cookie in case the site is using registration to
         * process repeated postings, etc.
         */
        $fields = array('firstName', 'lastName', 'email', 'address', 'city', 'state', 'zip', 'phone',
            'phoneHome', 'phoneCell'
        );
        $storedVal = '';
        foreach ($fields as $field)
        {
            eval('$tmp = sprintf(\'"%s"="%s"\', $field, urlencode($' . $field . '));');
            $storedVal .= $tmp;
        }
        // Store their information for an hour only (about 1 session), if they return they can log in again and
        // specify "remember me" which stores it for 2 weeks.
        @setcookie($this->getCareerPortalCookieName($siteID), $storedVal, time()+60*60);

        if ($candidateID !== false)
        {
            $candidate = $candidates->get($candidateID);

            // Candidate exists and registered. Update their profile with new values (if provided)
            $candidates->update(
                $candidateID, $candidate['isActive'] ? true : false, $firstName, $middleName,
                $lastName, $email, $email2, $phoneHome, $phoneCell, $phone, $address, $city,
                $state, $zip, $source, $keySkills, '', $employer, '', '', '', $candidate['notes'],
                '', $bestTimeToCall, $automatedUser['userID'], $automatedUser['userID'], $gender,
                $race, $veteran, $disability
            );

            /* Update extra feilds */
            $candidates->extraFields->setValuesOnEdit($candidateID);
        }
        else
        {
            // Lookup the candidate by e-mail, use that candidate instead if found (but don't update profile)
            $candidateID = $candidates->getIDByEmail($email);
        }

        if ($candidateID === false || $candidateID < 0)
        {
            /* New candidate. */
            $candidateID = $candidates->add(
                $firstName,
                $middleName,
                $lastName,
                $email,
                $email2,
                $phoneHome,
                $phoneCell,
                $phone,
                $address,
                $city,
                $state,
                $zip,
                $source,
                $keySkills,
                '',
                $employer,
                '',
                '',
                '',
                'Candidate submitted these notes with first application: '
                . "\n\n" . $extraNotes,
                '',
                $bestTimeToCall,
                $automatedUser['userID'],
                $automatedUser['userID'],
                $gender,
                $race,
                $veteran,
                $disability
            );

            /* Update extra fields. */
            $candidates->extraFields->setValuesOnEdit($candidateID);
        }

        // If the candidate was added and a questionnaire exists for the job order
        if ($candidateID > 0 && ($questionnaireID = $jobOrderData['questionnaireID']))
        {
            $questionnaireLib = new Questionnaire($siteID);
            // Perform any actions specified by the questionnaire
            $questionnaireLib->doActions($questionnaireID, $candidateID, $_POST);
        }

        $fileUploaded = false;

        /* Upload resume (no questionnaire) */
        if (isset($_FILES['file']) && !empty($_FILES['file']['name']))
        {
            $attachmentCreator = new AttachmentCreator($siteID);
            $attachmentCreator->createFromUpload(
                DATA_ITEM_CANDIDATE, $candidateID, 'file', false, true
            );

            if ($attachmentCreator->isError())
            {
                CommonErrors::fatal(COMMONERROR_FILEERROR, $this, $attachmentCreator->getError());
                return;
            }

            $duplicatesOccurred = $attachmentCreator->duplicatesOccurred();

            $isTextExtractionError = $attachmentCreator->isTextExtractionError();
            $textExtractionErrorMessage = $attachmentCreator->getTextExtractionError();

            // FIXME: Show parse errors!

            $fileUploaded = true;
            $resumePath = $attachmentCreator->getNewFilePath();
        }
        /* Upload resume (with questionnaire) */
        else if (isset($_POST['file']) && !empty($_POST['file']))
        {
            $resumePath = '';

            $newFilePath = FileUtility::getUploadFilePath($siteID, 'careerportaladd', $_POST['file']);

            if ($newFilePath !== false)
            {
                $attachmentCreator = new AttachmentCreator($siteID);
                $attachmentCreator->createFromFile(
                    DATA_ITEM_CANDIDATE, $candidateID, $newFilePath, false, '', true, true
                );

                if ($attachmentCreator->isError())
                {
                    CommonErrors::fatal(COMMONERROR_FILEERROR, $this, $attachmentCreator->getError());
                    return;
                }

                $duplicatesOccurred = $attachmentCreator->duplicatesOccurred();

                $isTextExtractionError = $attachmentCreator->isTextExtractionError();
                $textExtractionErrorMessage = $attachmentCreator->getTextExtractionError();

                // FIXME: Show parse errors!

                $fileUploaded = true;
                $resumePath = $attachmentCreator->getNewFilePath();
            }
        }

        $pipelines = new Pipelines($siteID);
        $activityEntries = new ActivityEntries($siteID);

        /* Is the candidate already in the pipeline for this job order? */
        $rs = $pipelines->get($candidateID, $jobOrderID);
        if (count($rs) == 0)
        {
            /* Attempt to add the candidate to the pipeline. */
            if (!$pipelines->add($candidateID, $jobOrderID))
            {
                CommonErrors::fatal(COMMONERROR_RECORDERROR, $this, 'Failed to add candidate to pipeline.');
            }

            // FIXME: For some reason, pipeline entries like to disappear between
            //        the above add() and this get(). WTF?
            $rs = $pipelines->get($candidateID, $jobOrderID);
            if (isset($rs['candidateJobOrderID']))
                $pipelines->updateRatingValue($rs['candidateJobOrderID'], -1);

            $newApplication = true;
        }
        else
        {
            $newApplication = false;
        }

        /* Build activity note. */
        if (!$newApplication)
        {
            $activityNote = 'User re-applied through candidate portal';
        }
        else
        {
            $activityNote = 'User applied through candidate portal';
        }

        if ($fileUploaded)
        {
            if (!$duplicatesOccurred)
            {
                $activityNote .= ' <span style="font-weight: bold;">and'
                    . ' attached a new resume (<a href="' . $resumePath
                    . '">Download</a>)</span>';
            }
            else
            {
                $activityNote .= ' and attached an existing resume (<a href="'
                    . $resumePath . '">Download</a>)';
            }
        }

		if (!empty($extraNotes))
		{
        	$activityNote .= '; added these notes: ' . $extraNotes;
		}

        /* Add the activity note. */
        $activityID = $activityEntries->add(
            $candidateID,
            DATA_ITEM_CANDIDATE,
            ACTIVITY_OTHER,
            $activityNote,
            $automatedUser['userID'],
            $jobOrderID
        );

        /* Send an E-Mail describing what happened. */
        $emailTemplates = new EmailTemplates($siteID);
        $candidatesEmailTemplateRS = $emailTemplates->getByTag(
            'EMAIL_TEMPLATE_CANDIDATEAPPLY'
        );

        if (!isset($candidatesEmailTemplateRS['textReplaced']) ||
            empty($candidatesEmailTemplateRS['textReplaced']) ||
            $candidatesEmailTemplateRS['disabled'] == 1)
        {
            $candidatesEmailTemplate = '';
        }
        else
        {
            $candidatesEmailTemplate = $candidatesEmailTemplateRS['textReplaced'];
        }

        /* Replace e-mail template variables. */
        /* E-Mail #1 - to candidate */
        $stringsToFind = array(
            '%CANDFIRSTNAME%',
            '%CANDFULLNAME%',
            '%JBODOWNER%',
            '%JBODTITLE%',
            '%JBODCLIENT%'
        );
        $replacementStrings = array(
            $firstName,
            $firstName . ' ' . $lastName,
            $jobOrderData['ownerFullName'],
            $jobOrderData['title'],
            $jobOrderData['companyName']

            //'<a href="http://' . $_SERVER['HTTP_HOST'] . substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], '?')) . '?m=candidates&amp;a=show&amp;candidateID=' . $candidateID . '">'.
              //  'http://' . $_SERVER['HTTP_HOST'] . substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], '?')) . '?m=candidates&amp;a=show&amp;candidateID=' . $candidateID . '</a>'
        );
        $candidatesEmailTemplate = str_replace(
            $stringsToFind,
            $replacementStrings,
            $candidatesEmailTemplate
        );

        $emailContents = $candidatesEmailTemplate;

        if (!empty($emailContents))
        {
            if(!$candidates->isLoaded())
            {
                $candidates->load($candidateID);
            }
            $candidates->sendEMail(
                $automatedUser['userID'],
                $email,
                CAREERS_CANDIDATEAPPLY_SUBJECT,
                $emailContents
            );
        }

        /* E-Mail #2 - to owner */

        $candidatesEmailTemplateRS = $emailTemplates->getByTag(
            'EMAIL_TEMPLATE_CANDIDATEPORTALNEW'
        );

        if (!isset($candidatesEmailTemplateRS['textReplaced']) ||
            empty($candidatesEmailTemplateRS['textReplaced']) ||
            $candidatesEmailTemplateRS['disabled'] == 1)
        {
            $candidatesEmailTemplate = '';
        }
        else
        {
            $candidatesEmailTemplate = $candidatesEmailTemplateRS['textReplaced'];
        }

        // FIXME: This will break if 'http' is elsewhere in the URL.
        $uri = str_replace('employment', '', $_SERVER['REQUEST_URI']);
        $uri = str_replace('http://', 'http', $uri);
        $uri = str_replace('//', '/', $uri);
        $uri = str_replace('http', 'http://', $uri);
        $uri = str_replace('/careers', '', $uri);

        /* Replace e-mail template variables. */
        $stringsToFind = array(
            '%CANDFIRSTNAME%',
            '%CANDFULLNAME%',
            '%JBODOWNER%',
            '%CANDOWNER%',     // Because the candidate was just added, we assume
            '%JBODTITLE%',     // the candidate owner = job order owner.
            '%JBODCLIENT%',
            '%CANDCATSURL%',
            '%JBODID%',
            '%JBODCATSURL%'
        );
        $replacementStrings = array(
            $firstName,
            $firstName . ' ' . $lastName,
            $jobOrderData['ownerFullName'],
            $jobOrderData['ownerFullName'],
            $jobOrderData['title'],
            $jobOrderData['companyName'],
            '<a href="http://' . $_SERVER['HTTP_HOST'] . substr($uri, 0, strpos($uri, '?')) . '?m=candidates&amp;a=show&amp;candidateID=' . $candidateID . '">'.
                'http://' . $_SERVER['HTTP_HOST'] . substr($uri, 0, strpos($uri, '?')) . '?m=candidates&amp;a=show&amp;candidateID=' . $candidateID . '</a>',
            $jobOrderData['jobOrderID'],
            '<a href="http://' . $_SERVER['HTTP_HOST'] . substr($uri, 0, strpos($uri, '?')) . '?m=joborders&amp;a=show&amp;jobOrderID=' . $jobOrderData['jobOrderID'] . '">'.
                'http://' . $_SERVER['HTTP_HOST'] . substr($uri, 0, strpos($uri, '?')) . '?m=joborders&amp;a=show&amp;jobOrderID=' . $jobOrderData['jobOrderID'] . '</a>',
        );
        $candidatesEmailTemplate = str_replace(
            $stringsToFind,
            $replacementStrings,
            $candidatesEmailTemplate
        );

        $emailContents = $candidatesEmailTemplate;

        if (!empty($emailContents))
        {
            if(!$jobOrders->isLoaded())
            {
                $jobOrders->load($jobOrderID);
            }
            $jobOrders->sendEmail(
                $automatedUser['userID'],
                $jobOrderData['owner_email'],
                CAREERS_OWNERAPPLY_SUBJECT,
                $emailContents
            );


            if ($jobOrderData['owner_email'] != $jobOrderData['recruiter_email'])
            {
                $jobOrders->sendEmail(
                    $automatedUser['userID'],
                    $jobOrderData['recruiter_email'],
                    CAREERS_OWNERAPPLY_SUBJECT,
                    $emailContents
                );
            }
        }
    }
Esempio n. 2
0
 private function getMassImportCandidates()
 {
     $db = DatabaseConnection::getInstance();
     // Find the files the user has uploaded and put them in an array
     if (isset($_SESSION['CATS']) && !empty($_SESSION['CATS'])) {
         $siteID = $_SESSION['CATS']->getSiteID();
         $userID = $_SESSION['CATS']->getUserID();
     } else {
         CommonErrors::fatal(COMMONERROR_NOTLOGGEDIN, $this);
     }
     list($documents, $success, $failed) = $this->getMassImportDocuments();
     if (!count($documents)) {
         return array(array(), array(), array(), array());
     }
     $importedCandidates = array();
     $importedDocuments = array();
     $importedFailed = array();
     $importedDuplicates = array();
     for ($ind = 0; $ind < count($_SESSION['CATS_PARSE_TEMP']); $ind++) {
         $doc = $_SESSION['CATS_PARSE_TEMP'][$ind];
         // Get parsed information instead (if available)
         for ($ind2 = 0; $ind2 < count($documents); $ind2++) {
             if ($documents[$ind2]['id'] == $ind) {
                 $doc = $documents[$ind2];
             }
         }
         if (isset($doc['success']) && $doc['success']) {
             $candidateAdded = false;
             if (isset($doc['lastName']) && $doc['lastName'] != '' && isset($doc['firstName']) && $doc['firstName'] != '') {
                 $isCandidateUnique = true;
                 /**
                  * We need to check for duplicate candidate entries before adding a new
                  * candidate into CATS. The criteria is as follows:
                  * - if email is present, does it match an existing e-mail
                  * - if last name and zip code or last name and phone numbers are present, do they match likewise
                  */
                 if (strpos($doc['email'], '@') !== false) {
                     $sql = sprintf('SELECT count(*) ' . 'FROM candidate ' . 'WHERE (candidate.email1 = %s OR candidate.email2 = %s) ' . 'AND candidate.site_id = %d', $db->makeQueryString($doc['email']), $db->makeQueryString($doc['email']), $this->_siteID);
                     if ($db->getColumn($sql, 0, 0) > 0) {
                         $isCandidateUnique = false;
                     }
                 }
                 if (strlen($doc['lastName']) > 3 && isset($doc['phone']) && strlen($doc['phone']) >= 10) {
                     $sql = sprintf('SELECT count(*) ' . 'FROM candidate ' . 'WHERE candidate.last_name = %s ' . 'AND (candidate.phone_home = %s ' . 'OR candidate.phone_work = "%s ' . 'OR candidate.phone_cell = "%s) ' . 'AND candidate.site_id = %d', $db->makeQueryString($doc['lastName']), $db->makeQueryString($doc['phone']), $db->makeQueryString($doc['phone']), $db->makeQueryString($doc['phone']), $this->_siteID);
                     if ($db->getColumn($sql, 0, 0) > 0) {
                         $isCandidateUnique = false;
                     }
                 }
                 if (strlen($doc['lastName']) > 3 && isset($doc['zip']) && strlen($doc['zip']) >= 5) {
                     $sql = sprintf('SELECT count(*) ' . 'FROM candidate ' . 'WHERE candidate.last_name = %s ' . 'AND candidate.zip = %s ' . 'AND candidate.site_id = %d', $db->makeQueryString($doc['lastName']), $db->makeQueryString($doc['zipCode']), $this->_siteID);
                     if ($db->getColumn($sql, 0, 0) > 0) {
                         $isCandidateUnique = false;
                     }
                 }
                 if ($isCandidateUnique) {
                     // This was parsed data
                     $candidates = new Candidates($siteID);
                     $candidateID = $candidates->add($doc['firstName'], '', $doc['lastName'], $doc['email'], '', $doc['phone'], '', '', $doc['address'], $doc['city'], $doc['state'], $doc['zipCode'], '', $doc['skills'], NULL, '', false, '', '', 'This resume was parsed automatically. You should review it for errors.', '', '', $userID, $userID, '', 0, 0, '', true);
                     if ($candidateID > 0) {
                         $candidateAdded = true;
                         // set the date created to the file modification date
                         $db->query(sprintf('UPDATE candidate SET date_created = "%s", date_modified = "%s" ' . 'WHERE candidate_id = %d AND site_id = %d', date('c', $doc['cTime']), date('c', $doc['cTime']), $candidateID, $siteID));
                         // Success, attach resume to candidate as attachment
                         $ac = new AttachmentCreator($siteID);
                         if ($ac->createFromFile(DATA_ITEM_CANDIDATE, $candidateID, $doc['name'], $doc['realName'], '', true, true)) {
                             // FIXME: error checking on fail?
                         }
                         $importedCandidates[] = array('name' => trim($doc['firstName'] . ' ' . $doc['lastName']), 'resume' => $doc['realName'], 'url' => sprintf('%s?m=candidates&a=show&candidateID=%d', CATSUtility::getIndexName(), $candidateID), 'location' => trim($doc['city'] . ' ' . $doc['state'] . ' ' . $doc['zipCode']));
                     }
                 } else {
                     $importedDuplicates[] = array('name' => trim($doc['firstName'] . ' ' . $doc['lastName']), 'resume' => $doc['realName']);
                     @unlink($doc['name']);
                     $candidateAdded = true;
                 }
             }
             /**
              * A candidate was unable to be automatically added, add them as a
              * bulk resume document which is still searchable and can be manually
              * converted into a candidate later.
              */
             if (!$candidateAdded) {
                 $brExists = false;
                 $error = false;
                 /**
                  * Bulk resumes can be "rescanned", make sure this particular file isn't a
                  * rescan before adding another copy.
                  */
                 if (preg_match('/^_BulkResume_(.*)\\.txt$/', $doc['realName'], $matches)) {
                     $attachments = new Attachments($this->_siteID);
                     $bulkResumes = $attachments->getBulkAttachments();
                     foreach ($bulkResumes as $bulkResume) {
                         $mp = explode('.', $bulkResume['originalFileName']);
                         $fileName = implode('.', array_slice($mp, 0, -1));
                         if (!strcmp($fileName, $matches[1])) {
                             $brExists = true;
                             if (FileUtility::isUploadFileSafe($siteID, 'massimport', $doc['name'])) {
                                 @unlink($doc['name']);
                             }
                             break;
                         }
                     }
                 }
                 if (!$brExists) {
                     $error = false;
                     $attachmentCreator = new AttachmentCreator($siteID);
                     $attachmentCreator->createFromFile(DATA_ITEM_BULKRESUME, 0, $doc['name'], $doc['realName'], '', true, true);
                     if ($attachmentCreator->isError()) {
                         $error = true;
                     }
                     if ($attachmentCreator->duplicatesOccurred()) {
                         $error = true;
                     }
                 }
                 // For use later on debugging
                 //$isTextExtractionError = $attachmentCreator->isTextExtractionError();
                 //$textExtractionErrorMessage = $attachmentCreator->getTextExtractionError();
                 if (!$error || $brExists) {
                     $importedDocuments[] = array('name' => $doc['realName']);
                 } else {
                     $importedFailed[] = array('name' => $doc['realName']);
                 }
             } else {
                 if (preg_match('/^_BulkResume_(.*)\\.txt$/', $doc['realName'], $matches)) {
                     $attachments = new Attachments($this->_siteID);
                     $bulkResumes = $attachments->getBulkAttachments();
                     foreach ($bulkResumes as $bulkResume) {
                         $mp = explode('.', $bulkResume['originalFileName']);
                         $fileName = implode('.', array_slice($mp, 0, -1));
                         if (!strcmp($fileName, $matches[1])) {
                             // Delete the permanent file
                             $attachments->delete($bulkResume['attachmentID'], true);
                             // Delete the temporary file
                             if (FileUtility::isUploadFileSafe($siteID, 'massimport', $doc['name'])) {
                                 @unlink($doc['name']);
                             }
                             break;
                         }
                     }
                 }
             }
         } else {
             // This document failed to convert to a text-format using doc2text
             $importedFailed[] = array('name' => $doc['realName']);
             // Make sure it's a safe filename to delete and located in the site's upload directory
             if (FileUtility::isUploadFileSafe($siteID, 'massimport', $doc['name'])) {
                 @unlink($doc['name']);
             }
         }
     }
     return array($importedCandidates, $importedDocuments, $importedFailed, $importedDuplicates);
 }
Esempio n. 3
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;
 }