private function onEdit() { if ($this->_accessLevel < ACCESS_LEVEL_EDIT) { CommonErrors::fatal(COMMONERROR_PERMISSION, $this, 'Invalid user level for action.'); } $jobOrders = new JobOrders($this->_siteID); /* Bail out if we don't have a valid job order ID. */ if (!$this->isRequiredIDValid('jobOrderID', $_POST)) { CommonErrors::fatal(COMMONERROR_BADINDEX, $this, 'Invalid job order ID.'); } $jobOrderID = $_POST['jobOrderID']; /* 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 contact ID. */ if (!$this->isOptionalIDValid('contactID', $_POST)) { CommonErrors::fatal(COMMONERROR_BADINDEX, $this, 'Invalid contact ID.'); } /* Bail out if we don't have a valid recruiter user ID. */ if (!$this->isRequiredIDValid('recruiter', $_POST)) { CommonErrors::fatal(COMMONERROR_BADINDEX, $this, 'Invalid recruiter user 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.'); } /* Bail out if we received an invalid start date; if not, go ahead and * convert the date to MySQL format. */ $startDate = $this->getTrimmedInput('startDate', $_POST); if (!empty($startDate)) { if (!DateUtility::validate('-', $startDate, DATE_FORMAT_MMDDYY)) { CommonErrors::fatal(COMMONERROR_MISSINGFIELDS, $this, 'Invalid start date.'); return; } /* Convert start_date to something MySQL can understand. */ $startDate = DateUtility::convert('-', $startDate, DATE_FORMAT_MMDDYY, DATE_FORMAT_YYYYMMDD); } /* Bail out if we received an invalid status. */ /* FIXME: Check actual status codes. */ if (!isset($_POST['status']) || empty($_POST['status'])) { CommonErrors::fatal(COMMONERROR_BADINDEX, $this, 'Invalid status.'); } if (isset($_POST['openings']) && !empty($_POST['openings']) && !ctype_digit((string) $_POST['openings'])) { CommonErrors::fatal(COMMONERROR_MISSINGFIELDS, $this, 'Invalid number of openings.'); } /* Hot job? */ $isHot = $this->isChecked('isHot', $_POST); /* Public Job? */ $public = $this->isChecked('public', $_POST); /* If it is public, is a questionnaire attached? */ $questionnaireID = isset($_POST['questionnaire']) && !empty($_POST['questionnaire']) && strcmp($_POST['questionnaire'], 'none') && $public ? intval($_POST['questionnaire']) : false; $companyID = $_POST['companyID']; $contactID = $_POST['contactID']; $owner = $_POST['owner']; $recruiter = $_POST['recruiter']; $openings = $_POST['openings']; $openingsAvailable = $_POST['openingsAvailable']; /* Change ownership email? */ if ($this->isChecked('ownershipChange', $_POST) && $owner > 0) { $jobOrderDetails = $jobOrders->get($jobOrderID); $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_OWNERSHIPASSIGNJOBORDER'); if (empty($statusChangeTemplateRS) || empty($statusChangeTemplateRS['textReplaced'])) { $statusChangeTemplate = ''; } else { $statusChangeTemplate = $statusChangeTemplateRS['textReplaced']; } /* Replace e-mail template variables. */ $stringsToFind = array('%JBODOWNER%', '%JBODTITLE%', '%JBODCLIENT%', '%JBODID%', '%JBODCATSURL%'); $replacementStrings = array($ownerDetails['fullName'], $jobOrderDetails['title'], $jobOrderDetails['companyName'], $jobOrderID, '<a href="http://' . $_SERVER['HTTP_HOST'] . substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], '?')) . '?m=joborders&a=show&jobOrderID=' . $jobOrderID . '">' . 'http://' . $_SERVER['HTTP_HOST'] . substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], '?')) . '?m=joborders&a=show&jobOrderID=' . $jobOrderID . '</a>'); $statusChangeTemplate = str_replace($stringsToFind, $replacementStrings, $statusChangeTemplate); $email = $statusChangeTemplate; } else { $email = ''; $emailAddress = ''; } } else { $email = ''; $emailAddress = ''; } $title = $this->getTrimmedInput('title', $_POST); $companyJobID = $this->getTrimmedInput('companyJobID', $_POST); $type = $this->getTrimmedInput('type', $_POST); $city = $this->getTrimmedInput('city', $_POST); $state = $this->getTrimmedInput('state', $_POST); $status = $this->getTrimmedInput('status', $_POST); $duration = $this->getTrimmedInput('duration', $_POST); $department = $this->getTrimmedInput('department', $_POST); $maxRate = $this->getTrimmedInput('maxRate', $_POST); $salary = $this->getTrimmedInput('salary', $_POST); $description = $this->getTrimmedInput('description', $_POST); $notes = $this->getTrimmedInput('notes', $_POST); /* Bail out if any of the required fields are empty. */ if (empty($title) || empty($type) || empty($city) || empty($state)) { CommonErrors::fatal(COMMONERROR_MISSINGFIELDS, $this, 'Required fields are missing.'); } if (!eval(Hooks::get('JO_ON_EDIT_PRE'))) { return; } if (!$jobOrders->update($jobOrderID, $title, $companyJobID, $companyID, $contactID, $description, $notes, $duration, $maxRate, $type, $isHot, $openings, $openingsAvailable, $salary, $city, $state, $startDate, $status, $recruiter, $owner, $public, $email, $emailAddress, $department, $questionnaireID)) { CommonErrors::fatal(COMMONERROR_RECORDERROR, $this, 'Failed to update job order.'); } /* Update extra fields. */ $jobOrders->extraFields->setValuesOnEdit($jobOrderID); if (!eval(Hooks::get('JO_ON_EDIT_POST'))) { return; } CATSUtility::transferRelativeURI('m=joborders&a=show&jobOrderID=' . $jobOrderID); }