/** * Save job * * @return void */ public function savejobTask() { // Incoming $employerid = Request::getInt('employerid', 0); $min = ($this->_task == 'confirmjob' or $this->_task == 'unpublish' or $this->_task == 'reopen' or $this->_task == 'remove') ? 1 : 0; $code = $this->_jobCode ? $this->_jobCode : Request::getVar('code', ''); // Login required if (User::isGuest()) { \Notify::warning(Lang::txt('COM_JOBS_PLEASE_LOGIN_ACCESS_EMPLOYER')); $this->login(); return; } // Do we need admin approval for job publications? $autoapprove = $this->config->get('autoapprove', 1); $job = new Job($this->database); $jobadmin = new JobAdmin($this->database); $employer = new Employer($this->database); if ($code) { if (!$job->loadJob($code)) { App::abort(404, Lang::txt('COM_JOBS_ERROR_JOB_NOT_FOUND')); } // check if user is authorized to edit if ($this->_admin or $jobadmin->isAdmin(User::get('id'), $job->id) or User::get('id') == $job->employerid) { // we are editing $code = $job->code; } else { App::abort(403, Lang::txt('COM_JOBS_ALERTNOTAUTH')); } $job->editedBy = User::get('id'); $job->edited = Date::toSql(); } else { $job->added = Date::toSql(); $job->addedBy = User::get('id'); } $employerid = $code ? $job->employerid : $employerid; $job->employerid = $employerid; // load Employer if (!$employer->loadEmployer($employerid)) { App::abort(404, Lang::txt('COM_JOBS_ERROR_EMPLOYER_NOT_FOUND')); } // check validity of subscription if (User::get('id') == $job->employerid && !$this->_emp && !$this->_masterAdmin) { App::redirect(Route::url('index.php?option=com_jobs&task=dashboard'), Lang::txt('COM_JOBS_WARNING_SUBSCRIPTION_INVALID'), 'warning'); return; } if (!$min) { $job->description = rtrim(stripslashes($_POST['description'])); $job->title = rtrim(stripslashes($_POST['title'])); $job->companyName = rtrim(stripslashes($_POST['companyName'])); $job->companyLocation = rtrim(stripslashes($_POST['companyLocation'])); $applyInternal = Request::getInt('applyInternal', 0); $applyExternalUrl = Request::getVar('applyExternalUrl', ''); // missing required information if (!$job->description or !$job->title or !$job->companyName or !$job->companyLocation) { $job->bind($_POST); $this->_job = $job; $this->_jobCode = $code; $this->setError(Lang::txt('COM_JOBS_ERROR_MISSING_INFORMATION')); $this->editjobTask(); return; } } $job->companyLocationCountry = $job->companyLocationCountry ? $job->companyLocationCountry : NULL; // Save new information if (!$min) { $job->bind($_POST); $job->description = rtrim(stripslashes($_POST['description'])); $job->title = rtrim(stripslashes($_POST['title'])); $job->companyName = rtrim(stripslashes($_POST['companyName'])); $job->companyLocation = rtrim(stripslashes($_POST['companyLocation'])); $job->applyInternal = Request::getInt('applyInternal', 0); $job->applyExternalUrl = Request::getVar('applyExternalUrl', ''); } else { if ($job->status == 4 && $this->_task == 'confirmjob') { // make sure we aren't over quota $allowedAds = $this->_masterAdmin && $employerid == 1 ? 1 : $this->_checkQuota($job); if ($allowedAds <= 0) { $this->setError(Lang::txt('COM_JOBS_ERROR_JOB_CANT_PUBLISH_OVER_LIMIT')); } else { // confirm $job->status = !$autoapprove && !$this->_masterAdmin ? 0 : 1; $job->opendate = !$autoapprove && !$this->_masterAdmin ? '' : Date::toSql(); // set open date as of now, if confirming new ad publication $this->_msg = !$autoapprove && !$this->_masterAdmin ? Lang::txt('COM_JOBS_MSG_SUCCESS_JOB_PENDING_APPROVAL') : Lang::txt('COM_JOBS_MSG_SUCCESS_JOB_POSTED'); \Notify::success($this->_msg); } } elseif ($job->status == 1 && $this->_task == 'unpublish') { $job->status = 3; \Notify::warning(Lang::txt('COM_JOBS_MSG_JOB_UNPUBLISHED')); } elseif ($job->status == 3 && $this->_task == 'reopen') { // make sure we aren't over quota $allowedAds = $this->_masterAdmin && $employerid == 1 ? 1 : $this->_checkQuota($job); if ($allowedAds <= 0) { $this->setError(Lang::txt('COM_JOBS_ERROR_JOB_CANT_REOPEN_OVER_LIMIT')); } else { $job->status = 1; \Notify::success(Lang::txt('COM_JOBS_MSG_JOB_REOPENED')); } } elseif ($this->_task == 'remove') { $job->status = 2; } } // get unique number code for this new job posting if (!$code) { $subscription = new Subscription($this->database); $code = $subscription->generateCode(8, 8, 0, 1, 0); $job->code = $code; } if (!$job->store()) { throw new Exception($job->getError(), 500); } if (!$job->id) { $job->checkin(); } if ($this->_task == 'remove') { App::redirect(Route::url('index.php?option=com_jobs&task=dashboard'), Lang::txt('COM_JOBS_MSG_JOB_REMOVED')); return; } // Set any errors if ($this->getError()) { \Notify::error($this->getError()); } App::redirect(Route::url('index.php?option=com_jobs&task=job&code=' . $job->code)); }