コード例 #1
0
 private function onAdd()
 {
     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 company ID. */
     if (!$this->isRequiredIDValid('companyID', $_POST)) {
         CommonErrors::fatal(COMMONERROR_BADINDEX, $this, 'Invalid company 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->isRequiredIDValid('owner', $_POST)) {
         CommonErrors::fatal(COMMONERROR_BADINDEX, $this, 'Invalid owner user ID.');
     }
     /* Bail out if we don't have a valid number of openings. */
     if (!$this->isRequiredIDValid('openings', $_POST)) {
         CommonErrors::fatal(COMMONERROR_MISSINGFIELDS, $this, 'Invalid number of openings.');
     }
     /* Bail out if we don't have a valid contact ID. */
     if (!$this->isOptionalIDValid('contactID', $_POST)) {
         CommonErrors::fatal(COMMONERROR_BADINDEX, $this, 'Invalid contact ID.');
     }
     if (isset($_POST['openings']) && !empty($_POST['openings']) && !ctype_digit((string) $_POST['openings'])) {
         CommonErrors::fatal(COMMONERROR_MISSINGFIELDS, $this, 'Invalid number of openings.');
     }
     /* 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.');
         }
         /* Convert start_date to something MySQL can understand. */
         $startDate = DateUtility::convert('-', $startDate, DATE_FORMAT_MMDDYY, DATE_FORMAT_YYYYMMDD);
     }
     /* Hot job? */
     $isHot = $this->isChecked('isHot', $_POST);
     /* Public Job? */
     $isPublic = $this->isChecked('public', $_POST);
     /* If it is public, is a questionnaire attached? */
     $questionnaireID = isset($_POST['questionnaire']) && !empty($_POST['questionnaire']) && strcmp($_POST['questionnaire'], 'none') && $isPublic ? intval($_POST['questionnaire']) : false;
     $companyID = $_POST['companyID'];
     $contactID = $_POST['contactID'];
     $recruiter = $_POST['recruiter'];
     $owner = $_POST['owner'];
     $openings = $_POST['openings'];
     $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);
     $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_ADD'))) {
         return;
     }
     $jobOrders = new JobOrders($this->_siteID);
     $jobOrderID = $jobOrders->add($title, $companyID, $contactID, $description, $notes, $duration, $maxRate, $type, $isHot, $isPublic, $openings, $companyJobID, $salary, $city, $state, $startDate, $this->_userID, $recruiter, $owner, $department, $questionnaireID);
     if ($jobOrderID <= 0) {
         CommonErrors::fatal(COMMONERROR_RECORDERROR, $this, 'Failed to add job order.');
     }
     /* Update extra fields. */
     $jobOrders->extraFields->setValuesOnEdit($jobOrderID);
     if (!eval(Hooks::get('JO_ON_ADD_POST'))) {
         return;
     }
     CATSUtility::transferRelativeURI('m=joborders&a=show&jobOrderID=' . $jobOrderID);
 }