function testExtractPhoneNumber() { $phoneNumbersToExtract = array(array('(+01)9094444444extension 15', '909-444-4444 x 15'), array('1-800-444-3899 x 90', '800-444-3899 x 90'), array('+019094444444', '909-444-4444'), array('7706675085', '770-667-5085'), array('770-667-5085 extension 15', '770-667-5085 x 15'), array('(770) 667/5085', '770-667-5085'), array('(770) 667.5085', '770-667-5085'), array('my phone number is (770) 667.5085extension 15, it is.', '770-667-5085 x 15'), array('+420466052932', '+420466052932'), array('+17706675085', '770-667-5085')); foreach ($phoneNumbersToExtract as $key => $value) { $formattedPhoneNumber = StringUtility::extractPhoneNumber($value[0]); $this->assertTrue($formattedPhoneNumber === $value[1], sprintf("Extracting phone number from '%s' should result in '%s'", $value[0], $value[1])); } }
private function onEdit() { if ($this->_accessLevel < ACCESS_LEVEL_EDIT) { $this->listByView('Invalid user level for action.'); return; } $companies = new Companies($this->_siteID); /* Bail out if we don't have a valid company ID. */ if (!$this->isRequiredIDValid('companyID', $_POST)) { $this->listByView('Invalid company ID.'); return; } /* Bail out if we don't have a valid owner user ID. */ if (!$this->isOptionalIDValid('owner', $_POST)) { $this->listByView('Invalid owner user ID.'); return; } /* Bail out if we don't have a valid billing contact ID. */ if (!$this->isOptionalIDValid('billingContact', $_POST)) { $this->listByView('Invalid billing contact ID.'); return; } $formattedPhone1 = StringUtility::extractPhoneNumber($this->getTrimmedInput('phone1', $_POST)); if (!empty($formattedPhone1)) { $phone1 = $formattedPhone1; } else { $phone1 = $this->getTrimmedInput('phone1', $_POST); } $formattedPhone2 = StringUtility::extractPhoneNumber($this->getTrimmedInput('phone2', $_POST)); if (!empty($formattedPhone2)) { $phone2 = $formattedPhone2; } else { $phone2 = $this->getTrimmedInput('phone2', $_POST); } $formattedFaxNumber = StringUtility::extractPhoneNumber($this->getTrimmedInput('faxNumber', $_POST)); if (!empty($formattedFaxNumber)) { $faxNumber = $formattedFaxNumber; } else { $faxNumber = $this->getTrimmedInput('faxNumber', $_POST); } $url = $this->getTrimmedInput('url', $_POST); if (!empty($url)) { $formattedURL = StringUtility::extractURL($url); if (!empty($formattedURL)) { $url = $formattedURL; } } /* Hot company? */ $isHot = $this->isChecked('isHot', $_POST); $companyID = $_POST['companyID']; $owner = $_POST['owner']; $billingContact = $_POST['billingContact']; /* Change ownership email? */ if ($this->isChecked('ownershipChange', $_POST) && $owner > 0) { $companyDetails = $companies->get($companyID); $users = new Users($this->_siteID); $ownerDetails = $users->get($_POST['owner']); if (!empty($ownerDetails)) { $emailAddress = $ownerDetails['email']; /* Get the change status email template. */ $emailTemplates = new EmailTemplates($this->_siteID); $statusChangeTemplateRS = $emailTemplates->getByTag('EMAIL_TEMPLATE_OWNERSHIPASSIGNCLIENT'); if (empty($statusChangeTemplateRS) || empty($statusChangeTemplateRS['textReplaced'])) { $statusChangeTemplate = ''; } else { $statusChangeTemplate = $statusChangeTemplateRS['textReplaced']; } /* Replace e-mail template variables. */ $stringsToFind = array('%CLNTOWNER%', '%CLNTNAME%', '%CLNTCATSURL%'); $replacementStrings = array($ownerDetails['fullName'], $companyDetails['name'], '<a href="http://' . $_SERVER['HTTP_HOST'] . substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], '?')) . '?m=companies&a=show&companyID=' . $companyID . '">' . 'http://' . $_SERVER['HTTP_HOST'] . substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], '?')) . '?m=companies&a=show&companyID=' . $companyID . '</a>'); $statusChangeTemplate = str_replace($stringsToFind, $replacementStrings, $statusChangeTemplate); $email = $statusChangeTemplate; } else { $email = ''; $emailAddress = ''; } } else { $email = ''; $emailAddress = ''; } $name = $this->getTrimmedInput('name', $_POST); $address = $this->getTrimmedInput('address', $_POST); $city = $this->getTrimmedInput('city', $_POST); $state = $this->getTrimmedInput('state', $_POST); $zip = $this->getTrimmedInput('zip', $_POST); $keyTechnologies = $this->getTrimmedInput('keyTechnologies', $_POST); $notes = $this->getTrimmedInput('notes', $_POST); /* Departments list editor. */ $departmentsCSV = $this->getTrimmedInput('departmentsCSV', $_POST); /* Bail out if any of the required fields are empty. */ if (empty($name)) { $this->listByView('Required fields are missing.'); return; } if (!eval(Hooks::get('CLIENTS_ON_EDIT_PRE'))) { return; } $departments = $companies->getDepartments($companyID); $departmentsDifferences = ListEditor::getDifferencesFromList($departments, 'name', 'departmentID', $departmentsCSV); $companies->updateDepartments($companyID, $departmentsDifferences); if (!$companies->update($companyID, $name, $address, $city, $state, $zip, $phone1, $phone2, $faxNumber, $url, $keyTechnologies, $isHot, $notes, $owner, $billingContact, $email, $emailAddress)) { CommonErrors::fatal(COMMONERROR_RECORDERROR, $this, 'Failed to update company.'); } if (!eval(Hooks::get('CLIENTS_ON_EDIT_POST'))) { return; } /* Update extra fields. */ $companies->extraFields->setValuesOnEdit($companyID); /* Update contacts? */ if (isset($_POST['updateContacts'])) { if ($_POST['updateContacts'] == 'yes') { $contacts = new Contacts($this->_siteID); $contacts->updateByCompany($companyID, $address, $city, $state, $zip); } } CATSUtility::transferRelativeURI('m=companies&a=show&companyID=' . $companyID); }
protected function _getPhoneNumbers() { /* Sanity check. It is possible that the only line of the address * block has been removed during e-mail address extraction. */ if (empty($this->_addressBlock)) { return array(); } $unknownNumbers = array(); $numbers = array(); /* Loop through each line of the address block and attempt to extract * and identify phone numbers. */ foreach ($this->_addressBlock as $lineNumber => $line) { /* Skip lines that don't contain phone numbers. */ if (!StringUtility::containsPhoneNumber($line)) { continue; } /* Regular expressions to help identify phone number types. */ $cell = '/cell|[\\x28\\x5b][CM][\\x29\\x5d]|mob(:?ile|\\b)|\\bc[:\\x5d]|\\bm[:\\x5d]/i'; $home = '/[\\x28\\x5b]H[\\x29\\x5d]|home|evening|night|house/i'; $work = '/work|off(:?ice|\\b)|[\\x28\\x5b][WO][\\x29\\x5d]|direct|day(?:time)?|job/i'; $general = '/[\\x28\\x5b]PH?[\\x29\\x5d]|primary|voice|main|toll|ph(:?one|\\b)/i'; $fax = '/[\\x28\\x5b]FX?[\\x29\\x5d]|fax|facsimile|\\bFX?[:\\x5d]/i'; $tty = '/\\bTT[YD]\\b/i'; $pager = '/pager|beeper/i'; /* Look for keywords that might tell us what type of number it is. * First check to see if the line is ONLY a phone number. If not, * try do identify what kind of phone number it is. * * \x28 is a '(', \x5b is a '[', \x29 is a ')', \x5d is a ']'. */ if (preg_match($cell, $line)) { $numbers[] = array('number' => StringUtility::extractPhoneNumber($line), 'type' => 'cell'); } else { if (preg_match($home, $line)) { $numbers[] = array('number' => StringUtility::extractPhoneNumber($line), 'type' => 'home'); } else { if (preg_match($work, $line)) { $numbers[] = array('number' => StringUtility::extractPhoneNumber($line), 'type' => 'work'); } else { if (preg_match($general, $line)) { if ($this->_mode != ADDRESSPARSER_MODE_COMPANY) { $unknownNumbers[] = StringUtility::extractPhoneNumber($line); } else { $numbers[] = array('number' => StringUtility::extractPhoneNumber($line), 'type' => 'general'); } } else { if (preg_match($fax, $line)) { $numbers[] = array('number' => StringUtility::extractPhoneNumber($line), 'type' => 'fax'); } else { if (preg_match($tty, $line)) { $numbers[] = array('number' => StringUtility::extractPhoneNumber($line), 'type' => 'tty'); } else { if (preg_match($pager, $line)) { $numbers[] = array('number' => StringUtility::extractPhoneNumber($line), 'type' => 'pager'); } else { if (StringUtility::isPhoneNumber($line)) { /* In this case, the line contains only a phone number, and is * truely unknown. */ $unknownNumbers[] = StringUtility::extractPhoneNumber($line); } else { /* In this case, the line contains other data besides just a * phone number. We just can't identify it as anything. */ $unknownNumbers[] = StringUtility::extractPhoneNumber($line); } } } } } } } } } /* Figure out which phone number types we've already found. We'll * use this below. */ $homePhoneRow = ResultSetUtility::findRowByColumnValue($numbers, 'type', 'home'); $workPhoneRow = ResultSetUtility::findRowByColumnValue($numbers, 'type', 'work'); $cellPhoneRow = ResultSetUtility::findRowByColumnValue($numbers, 'type', 'cell'); /* Did we find any unknown phone numbers? If so, we have to try to * guess their types. */ $unknownCount = count($unknownNumbers); if ($unknownCount == 1) { /* If we're only missing one of the three phone number types, and we * found a number on a line by itself, we will assume that the extra * number is one of the missing ones. * * If we don't have a work number, but we have a home number * and a cell number, this is probably a work number. */ if ($workPhoneRow === false && $homePhoneRow !== false && $cellPhoneRow !== false) { $numbers[] = array('number' => $unknownNumbers[0], 'type' => 'work'); } else { if ($homePhoneRow === false && $workPhoneRow !== false && $cellPhoneRow !== false) { $numbers[] = array('number' => $unknownNumbers[0], 'type' => 'home'); } else { if ($cellPhoneRow === false && $workPhoneRow !== false && $homePhoneRow !== false) { $numbers[] = array('number' => $unknownNumbers[0], 'type' => 'cell'); } else { if ($cellPhoneRow !== false && $workPhoneRow !== false && $homePhoneRow !== false) { /* We already know all the phone numbers we need to know, and * it's probably not a fax number, as fax numbers are usually * labeled. Nothing to do except mark it as unknown. */ $numbers[] = array('number' => $unknownNumbers[0], 'type' => 'unknown'); } else { /* We have more than one phone number missing. We will make a * "best guess" according to the mode we are in. */ switch ($this->_mode) { case ADDRESSPARSER_MODE_PERSON: if ($homePhoneRow === false) { $type = 'home'; } else { if ($cellPhoneRow === false) { $type = 'cell'; } else { if ($workPhoneRow === false) { $type = 'work'; } else { $type = 'unknown'; } } } break; case ADDRESSPARSER_MODE_CONTACT: /* 'Contacts' are more likely to list a work or cell * number than a home number. */ if ($workPhoneRow === false) { $type = 'work'; } else { if ($cellPhoneRow === false) { $type = 'cell'; } else { if ($homePhoneRow === false) { $type = 'home'; } else { $type = 'unknown'; } } } break; case ADDRESSPARSER_MODE_COMPANY: // FIXME: Here we should be looking for "general". // We could also have two phone phone numbers. $type = 'general'; break; default: /* Error! Invalid mode. */ $type = 'unknown'; break; } $numbers[] = array('number' => $unknownNumbers[0], 'type' => $type); } } } } } else { if ($unknownCount > 1) { // FIXME } } return $numbers; }
private function onEdit() { if ($this->_accessLevel < ACCESS_LEVEL_EDIT) { CommonErrors::fatal(COMMONERROR_PERMISSION, $this, 'Invalid user level for action.'); } /* Bail out if we don't have a valid contact ID. */ if (!$this->isRequiredIDValid('contactID', $_POST)) { CommonErrors::fatal(COMMONERROR_BADINDEX, $this, 'Invalid contact ID.'); } /* Bail out if we don't have a valid company ID. */ if (!$this->isRequiredIDValid('companyID', $_POST)) { CommonErrors::fatal(COMMONERROR_BADINDEX, $this, 'Invalid company ID.'); } /* Bail out if we don't have a valid owner user ID. */ if (!$this->isOptionalIDValid('owner', $_POST)) { CommonErrors::fatal(COMMONERROR_BADINDEX, $this, 'Invalid owner user ID.'); } $contactID = $_POST['contactID']; $companyID = $_POST['companyID']; $owner = $_POST['owner']; $formattedPhoneWork = StringUtility::extractPhoneNumber($this->getTrimmedInput('phoneWork', $_POST)); if (!empty($formattedPhoneWork)) { $phoneWork = $formattedPhoneWork; } else { $phoneWork = $this->getTrimmedInput('phoneWork', $_POST); } $formattedPhoneCell = StringUtility::extractPhoneNumber($this->getTrimmedInput('phoneCell', $_POST)); if (!empty($formattedPhoneCell)) { $phoneCell = $formattedPhoneCell; } else { $phoneCell = $this->getTrimmedInput('phoneCell', $_POST); } $formattedPhoneOther = StringUtility::extractPhoneNumber($this->getTrimmedInput('phoneOther', $_POST)); if (!empty($formattedPhoneOther)) { $phoneOther = $formattedPhoneOther; } else { $phoneOther = $this->getTrimmedInput('phoneOther', $_POST); } $contacts = new Contacts($this->_siteID); if ($this->isChecked('ownershipChange', $_POST) && $owner > 0) { $contactDetails = $contacts->get($contactID); $users = new Users($this->_siteID); $ownerDetails = $users->get($owner); if (!empty($ownerDetails)) { $emailAddress = $ownerDetails['email']; /* Get the change status email template. */ $emailTemplates = new EmailTemplates($this->_siteID); $statusChangeTemplateRS = $emailTemplates->getByTag('EMAIL_TEMPLATE_OWNERSHIPASSIGNCONTACT'); if (empty($statusChangeTemplateRS) || empty($statusChangeTemplateRS['textReplaced'])) { $statusChangeTemplate = ''; } else { $statusChangeTemplate = $statusChangeTemplateRS['textReplaced']; } /* Replace e-mail template variables. */ $stringsToFind = array('%CONTOWNER%', '%CONTFIRSTNAME%', '%CONTFULLNAME%', '%CONTCLIENTNAME%', '%CONTCATSURL%'); $replacementStrings = array($ownerDetails['fullName'], $contactDetails['firstName'], $contactDetails['firstName'] . ' ' . $contactDetails['lastName'], $contactDetails['companyName'], '<a href="http://' . $_SERVER['HTTP_HOST'] . substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], '?')) . '?m=contacts&a=show&contactID=' . $contactID . '">' . 'http://' . $_SERVER['HTTP_HOST'] . substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], '?')) . '?m=contacts&a=show&contactID=' . $contactID . '</a>'); $statusChangeTemplate = str_replace($stringsToFind, $replacementStrings, $statusChangeTemplate); $email = $statusChangeTemplate; } else { $email = ''; $emailAddress = ''; } } else { $email = ''; $emailAddress = ''; } $firstName = $this->getTrimmedInput('firstName', $_POST); $lastName = $this->getTrimmedInput('lastName', $_POST); $title = $this->getTrimmedInput('title', $_POST); $department = $this->getTrimmedInput('department', $_POST); $reportsTo = $this->getTrimmedInput('reportsTo', $_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); $notes = $this->getTrimmedInput('notes', $_POST); $isHot = $this->isChecked('isHot', $_POST); $leftCompany = $this->isChecked('leftCompany', $_POST); /* Departments list editor. */ $departmentsCSV = $this->getTrimmedInput('departmentsCSV', $_POST); /* Bail out if any of the required fields are empty. */ if (empty($firstName) || empty($lastName) || empty($title)) { CommonErrors::fatal(COMMONERROR_MISSINGFIELDS, $this, 'Required fields are missing.'); } if (!eval(Hooks::get('CONTACTS_ON_EDIT_PRE'))) { return; } /* Update departments. */ $companies = new Companies($this->_siteID); $departments = $companies->getDepartments($companyID); $departmentsDifferences = ListEditor::getDifferencesFromList($departments, 'name', 'departmentID', $departmentsCSV); $companies->updateDepartments($companyID, $departmentsDifferences); if (!$contacts->update($contactID, $companyID, $firstName, $lastName, $title, $department, $reportsTo, $email1, $email2, $phoneWork, $phoneCell, $phoneOther, $address, $city, $state, $zip, $isHot, $leftCompany, $notes, $owner, $email, $emailAddress)) { CommonErrors::fatal(COMMONERROR_RECORDERROR, $this, 'Failed to update contact.'); } /* Update extra fields. */ $contacts->extraFields->setValuesOnEdit($contactID); if (!eval(Hooks::get('CONTACTS_ON_EDIT_POST'))) { return; } CATSUtility::transferRelativeURI('m=contacts&a=show&contactID=' . $contactID); }
/** * 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; }