/** * 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)); }
/** * Save Job Posting * * @return void */ public function saveTask() { // Check for request forgeries Request::checkToken(); // Incoming $data = array_map('trim', $_POST); $action = Request::getVar('action', ''); $message = Request::getVar('message', ''); $id = Request::getInt('id', 0); $employerid = Request::getInt('employerid', 0); $emailbody = ''; $statusmsg = ''; $job = new Job($this->database); $employer = new Employer($this->database); if ($id) { if (!$job->load($id)) { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_JOBS_ERROR_MISSING_JOB'), 'error'); return; } } else { // saving new job include_once PATH_CORE . DS . 'components' . DS . 'com_services' . DS . 'tables' . DS . 'subscription.php'; $subscription = new \Components\Services\Tables\Subscription($this->database); $code = $subscription->generateCode(8, 8, 0, 1, 0); $job->code = $code; $job->added = Date::toSql(); $job->addedBy = User::get('id'); } $subject = $id ? Lang::txt('COM_JOBS_MESSAGE_SUBJECT', $job->code) : ''; $job->bind($_POST); // some clean-up $job->description = rtrim(stripslashes($job->description)); $job->title = rtrim(stripslashes($job->title)); $job->companyName = rtrim(stripslashes($job->companyName)); $job->companyLocation = rtrim(stripslashes($job->companyLocation)); // admin actions if ($id) { switch ($action) { case 'publish': // make sure we aren't over quota $allowed_ads = $employerid == 1 ? 1 : $this->_checkQuota($job, $employerid, $this->database); if ($allowed_ads <= 0) { $statusmsg .= Lang::txt('COM_JOBS_ERROR_OVER_LIMIT'); $action = ''; } else { $job->status = 1; $job->opendate = Date::toSql(); $statusmsg .= Lang::txt('COM_JOBS_MESSAGE_JOB_APPROVED'); } break; case 'unpublish': $job->status = 3; $statusmsg .= Lang::txt('COM_JOBS_MESSAGE_JOB_UNPUBLISHED'); break; case 'message': break; case 'delete': $job->status = 2; $statusmsg .= Lang::txt('COM_JOBS_MESSAGE_JOB_DELETED'); break; } $job->editedBy = User::get('id'); $job->edited = Date::toSql(); } if (!$job->store()) { throw new Exception($job->getError(), 500); } if (!$job->id) { $job->checkin(); } if ($message && $action == 'message' && $id || $action && $action != 'message') { // E-mail "from" info $from = array('email' => Config::get('mailfrom'), 'name' => Config::get('sitename') . ' ' . Lang::txt('COM_JOBS_JOBS')); $base = rtrim(Request::base(), '/'); if (substr($base, -13) == 'administrator') { $base = substr($base, 0, strlen($base) - 13); } $sef = 'jobs/job/' . $job->code; $link = rtrim($base, '/') . '/' . trim($sef, '/'); // start email message $emailbody .= $subject . ':' . "\r\n"; $emailbody .= $statusmsg . "\r\n"; $emailbody .= Lang::txt('COM_JOBS_MESSAGE_JOB') . ': ' . $link . "\r\n"; if ($message) { $emailbody .= "\n"; $emailbody .= '----------------------------------------------------------' . "\r\n"; $emailbody .= "\n" . Lang::txt('COM_JOBS_MESSAGE_FROM_ADMIN:') . "\n"; $emailbody .= $message; } if (!Event::trigger('xmessage.onSendMessage', array('jobs_ad_status_changed', $subject, $emailbody, $from, array($job->addedBy), $this->_option))) { Notify::error(Lang::txt('COM_JOBS_ERROR_FAILED_TO_MESSAGE_USERS')); } } // Redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_JOBS_ITEM_SAVED') . ($statusmsg ? ' ' . $statusmsg : '')); }